diff --git a/Exemple/Content/Content.mgcb b/Exemple/Content/Content.mgcb
index a14ef62..de2134b 100644
--- a/Exemple/Content/Content.mgcb
+++ b/Exemple/Content/Content.mgcb
@@ -1,7 +1,9 @@
-#----------------------------- Global Properties ----------------------------#
+
+#----------------------------- Global Properties ----------------------------#
/outputDir:bin/$(Platform)
/intermediateDir:obj/$(Platform)
+/platform:Windows
/config:
/profile:Reach
/compress:False
@@ -10,3 +12,16 @@
#---------------------------------- Content ---------------------------------#
+
+#begin Fonts/Title.spritefont
+/importer:FontDescriptionImporter
+/processor:FontDescriptionProcessor
+/processorParam:TextureFormat=Compressed
+/build:Fonts/Title.spritefont
+
+#begin Fonts/Normal.spritefont
+/importer:FontDescriptionImporter
+/processor:FontDescriptionProcessor
+/processorParam:TextureFormat=Compressed
+/build:Fonts/Normal.spritefont
+
diff --git a/Exemple/Content/Fonts/Normal.spritefont b/Exemple/Content/Fonts/Normal.spritefont
new file mode 100644
index 0000000..684206d
--- /dev/null
+++ b/Exemple/Content/Fonts/Normal.spritefont
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+ Cantarell
+
+
+ 12
+
+
+ 0
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+ ~
+
+
+
+
diff --git a/Exemple/Content/Fonts/Title.spritefont b/Exemple/Content/Fonts/Title.spritefont
new file mode 100644
index 0000000..9495683
--- /dev/null
+++ b/Exemple/Content/Fonts/Title.spritefont
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+ Cantarell
+
+
+ 32
+
+
+ 0
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+ ~
+
+
+
+
diff --git a/Exemple/Content/Textures/Background.jpg b/Exemple/Content/Textures/Background.jpg
deleted file mode 100755
index ddfdb74..0000000
Binary files a/Exemple/Content/Textures/Background.jpg and /dev/null differ
diff --git a/Exemple/Content/Textures/Background.png b/Exemple/Content/Textures/Background.png
new file mode 100755
index 0000000..42ee4f9
Binary files /dev/null and b/Exemple/Content/Textures/Background.png differ
diff --git a/Exemple/Content/Textures/Boxes/0/bottomCenter.png b/Exemple/Content/Textures/Boxes/0/bottomCenter.png
deleted file mode 100755
index ba3882c..0000000
Binary files a/Exemple/Content/Textures/Boxes/0/bottomCenter.png and /dev/null differ
diff --git a/Exemple/Content/Textures/Boxes/0/bottomLeft.png b/Exemple/Content/Textures/Boxes/0/bottomLeft.png
deleted file mode 100755
index 0565eb6..0000000
Binary files a/Exemple/Content/Textures/Boxes/0/bottomLeft.png and /dev/null differ
diff --git a/Exemple/Content/Textures/Boxes/0/bottomRight.png b/Exemple/Content/Textures/Boxes/0/bottomRight.png
deleted file mode 100755
index f4030d1..0000000
Binary files a/Exemple/Content/Textures/Boxes/0/bottomRight.png and /dev/null differ
diff --git a/Exemple/Content/Textures/Boxes/0/centerCenter.png b/Exemple/Content/Textures/Boxes/0/centerCenter.png
deleted file mode 100755
index cfff390..0000000
Binary files a/Exemple/Content/Textures/Boxes/0/centerCenter.png and /dev/null differ
diff --git a/Exemple/Content/Textures/Boxes/0/centerLeft.png b/Exemple/Content/Textures/Boxes/0/centerLeft.png
deleted file mode 100755
index 0904246..0000000
Binary files a/Exemple/Content/Textures/Boxes/0/centerLeft.png and /dev/null differ
diff --git a/Exemple/Content/Textures/Boxes/0/centerRight.png b/Exemple/Content/Textures/Boxes/0/centerRight.png
deleted file mode 100755
index 9547c0a..0000000
Binary files a/Exemple/Content/Textures/Boxes/0/centerRight.png and /dev/null differ
diff --git a/Exemple/Content/Textures/Boxes/0/topCenter.png b/Exemple/Content/Textures/Boxes/0/topCenter.png
deleted file mode 100755
index af78ce6..0000000
Binary files a/Exemple/Content/Textures/Boxes/0/topCenter.png and /dev/null differ
diff --git a/Exemple/Content/Textures/Boxes/0/topLeft.png b/Exemple/Content/Textures/Boxes/0/topLeft.png
deleted file mode 100755
index 3fb9dc2..0000000
Binary files a/Exemple/Content/Textures/Boxes/0/topLeft.png and /dev/null differ
diff --git a/Exemple/Content/Textures/Boxes/0/topRight.png b/Exemple/Content/Textures/Boxes/0/topRight.png
deleted file mode 100755
index e581211..0000000
Binary files a/Exemple/Content/Textures/Boxes/0/topRight.png and /dev/null differ
diff --git a/Exemple/Exemple.csproj b/Exemple/Exemple.csproj
index 0b0d5e1..37cb0fb 100644
--- a/Exemple/Exemple.csproj
+++ b/Exemple/Exemple.csproj
@@ -37,12 +37,42 @@
-
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ Always
+
@@ -85,6 +115,16 @@
PreserveNewest
+
+
+ {FF4B3F52-D94E-4F54-A829-C1492B875267}
+ MyMonoGameAddin
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Exemple/MainGame.cs b/Exemple/MainGame.cs
index 6634476..ab7f1a4 100644
--- a/Exemple/MainGame.cs
+++ b/Exemple/MainGame.cs
@@ -1,107 +1,123 @@
using System;
using MyMonoGameAddin;
-using MyMonoGameAddin.UI;
-using MyMonoGameAddin.Inputs;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
-using Microsoft.Xna.Framework.Input;
+using System.Diagnostics;
namespace Exemple
{
- ///
- /// This is the main type for your game.
- ///
- public class Game1 : Game
+ public class MainGame : Game
{
+ enum GameState { Menu, Credit }
+
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
ResourcesManager resources;
- InputsManager inputs = new InputsManager();
+ InputsManager inputs;
+ UIManager ui;
- Layout canvas = new Layout();
- Image pointer;
+ GameState state = GameState.Menu;
- const int ScreenWidth = 800;
- const int ScreenHeight = 600;
+ string Github;
- public Game1()
+ public MainGame()
{
graphics = new GraphicsDeviceManager(this);
- graphics.PreferredBackBufferWidth = ScreenWidth;
- graphics.PreferredBackBufferHeight = ScreenHeight;
- graphics.ApplyChanges();
+
+ Window.AllowUserResizing = true;
+ Window.AllowUserResizing = true;
+ Window.ClientSizeChanged += delegate
+ {
+ graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
+ graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
+ graphics.ApplyChanges();
+ };
+
Content.RootDirectory = "Content";
+
+ inputs = new InputsManager();
resources = new ResourcesManager(Content, GraphicsDevice);
}
- ///
- /// Allows the game to perform any initialization it needs to before starting to run.
- /// This is where it can query for any required services and load any non-graphic
- /// related content. Calling base.Initialize will enumerate through any components
- /// and initialize them as well.
- ///
protected override void Initialize()
{
+ graphics.PreferredBackBufferWidth = 800;
+ graphics.PreferredBackBufferHeight = 600;
+ graphics.IsFullScreen = false;
+ graphics.ApplyChanges();
+
+ IsMouseVisible = true;
+
base.Initialize();
}
- ///
- /// LoadContent will be called once per game and is the place to load
- /// all of your content.
- ///
protected override void LoadContent()
{
- // Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
- //resources.LoadFont("basic");
+ resources.LoadFont("Normal");
+ resources.LoadFont("Title");
//resources.LoadSound("bip");
resources.LoadTexture("Background");
resources.LoadBox("Button");
-
-
- BuildCanvas();
- //TODO: use this.Content to load your game content here
+ ui = new UIManager(spriteBatch, inputs, new Skin(resources.Boxes["Button"], resources.Fonts["Normal"], new Colors(Color.White, Color.LightGray, Color.DarkGray), new Colors(Color.Black, Color.Black, Color.White)));
}
- ///
- /// Allows the game to run logic such as updating the world,
- /// checking for collisions, gathering input, and playing audio.
- ///
- /// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
inputs.Update();
- // TODO: Add your update logic here
+ ui.Update();
base.Update(gameTime);
}
- ///
- /// This is called when the game should draw itself.
- ///
- /// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
- pointer.Transform.Position = inputs.Mouse.Position;
+ graphics.GraphicsDevice.Clear(Color.DarkGray);
- graphics.GraphicsDevice.Clear(Color.Black);
-
- //TODO: Add your drawing code here
spriteBatch.Begin();
+ ui.Texture(new Rectangle(10, 10, 200, 150), resources.Textures["Background"]);
+ switch (state)
+ {
+ case GameState.Credit:
+ ui.Box(new Rectangle(200, 100, graphics.PreferredBackBufferWidth - 400, graphics.PreferredBackBufferWidth - 200), new Colors(Color.LightGray, Color.White));
+ ui.Label(new Vector(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 4), "By Sheychen", new Colors(Color.Red, Color.OrangeRed), null, UIManager.textAlign.centerCenter);
+ if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 2 - 100, 200, 40), "My website"))
+ {
+ Process.Start("https://sheychen.shost.ca");
+ }
+ if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 2 - 50, 200, 40), "Show on GitHub"))
+ {
+ Process.Start("https://github.com/sheychen290/MyMonoGame");
+ }
+ if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 2, 200, 40), "Back"))
+ {
+ state = GameState.Menu;
+ }
+ break;
- canvas.Draw(spriteBatch, new Transform());
-
+ case GameState.Menu:
+ ui.Label(new Vector(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 4), "MyMonoGameAddin", new Colors(Color.Black, Color.Green), resources.Fonts["Title"], UIManager.textAlign.centerCenter);
+ if (ui.TextField(new Vector(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2), ref Github, new Colors(Color.White, Color.WhiteSmoke, Color.LightGray), null, UIManager.textAlign.centerCenter, "Search on Github"))
+ {
+ Process.Start("https://github.com/search?q=" + Github);
+ Github = null;
+ }
+ if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight * 3 / 4 + 50, 200, 40), "About", null, new Colors(Color.Black, Color.Green)))
+ {
+ state = GameState.Credit;
+ }
+ break;
+ }
spriteBatch.End();
base.Draw(gameTime);
}
- private void BuildCanvas()
+ protected override void OnExiting(object sender, EventArgs args)
{
- canvas.Children.Add(new Box(resources.Boxes["Button"], new Vector(10, 10), new Vector(100, 20), Color.White));
- pointer = new Image(resources.Textures["Background"], new Vector(0, 0), new Vector(10, 10), Color.White);
- canvas.Children.Add(pointer);
+ Process.GetCurrentProcess().Kill();
+ base.OnExiting(sender, args);
}
}
}
diff --git a/Exemple/Program.cs b/Exemple/Program.cs
index 1967bdc..95d878a 100644
--- a/Exemple/Program.cs
+++ b/Exemple/Program.cs
@@ -20,11 +20,11 @@ namespace Exemple
static class Program
#endif
{
- private static Game1 game;
+ private static MainGame game;
internal static void RunGame()
{
- game = new Game1();
+ game = new MainGame();
game.Run();
#if !__IOS__ && !__TVOS__
game.Dispose();
diff --git a/License.md b/License.md
new file mode 100644
index 0000000..0c375bf
--- /dev/null
+++ b/License.md
@@ -0,0 +1,15 @@
+Copyright (c) 2017, Clement Bois
+
+Copyright © 2017 Clement Bois
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see
\ No newline at end of file
diff --git a/MyMonoGameAddin.sln b/MyMonoGameAddin.sln
index c992d50..97a804a 100644
--- a/MyMonoGameAddin.sln
+++ b/MyMonoGameAddin.sln
@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exemple", "Exemple\Exemple.csproj", "{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyMonoGameAddin", "MyMonoGameAddin\MyMonoGameAddin.csproj", "{FF4B3F52-D94E-4F54-A829-C1492B875267}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@@ -13,5 +15,9 @@ Global
{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}.Debug|x86.Build.0 = Debug|x86
{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}.Release|x86.ActiveCfg = Release|x86
{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}.Release|x86.Build.0 = Release|x86
+ {FF4B3F52-D94E-4F54-A829-C1492B875267}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {FF4B3F52-D94E-4F54-A829-C1492B875267}.Debug|x86.Build.0 = Debug|Any CPU
+ {FF4B3F52-D94E-4F54-A829-C1492B875267}.Release|x86.ActiveCfg = Release|Any CPU
+ {FF4B3F52-D94E-4F54-A829-C1492B875267}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
diff --git a/MyMonoGameAddin/BoxTexture.cs b/MyMonoGameAddin/BoxTexture.cs
index e6a097a..34d303a 100644
--- a/MyMonoGameAddin/BoxTexture.cs
+++ b/MyMonoGameAddin/BoxTexture.cs
@@ -4,8 +4,124 @@ using Microsoft.Xna.Framework.Graphics;
namespace MyMonoGameAddin
{
- public struct BoxSprite
+ public class BoxTexture
{
- public
+ public Texture2D[,] Textures = new Texture2D[3, 3];
+
+ public Texture2D top_left
+ {
+ get
+ {
+ return Textures[0, 0];
+ }
+ set
+ {
+ Textures[0, 0] = value;
+ }
+ }
+ public Texture2D top_middle
+ {
+ get
+ {
+ return Textures[0, 1];
+ }
+ set
+ {
+ Textures[0, 1] = value;
+ }
+ }
+ public Texture2D top_right
+ {
+ get
+ {
+ return Textures[0, 2];
+ }
+ set
+ {
+ Textures[0, 2] = value;
+ }
+ }
+ public Texture2D middle_left
+ {
+ get
+ {
+ return Textures[1, 0];
+ }
+ set
+ {
+ Textures[1, 0] = value;
+ }
+ }
+ public Texture2D middle_middle
+ {
+ get
+ {
+ return Textures[1, 1];
+ }
+ set
+ {
+ Textures[1, 1] = value;
+ }
+ }
+ public Texture2D middle_right
+ {
+ get
+ {
+ return Textures[1, 2];
+ }
+ set
+ {
+ Textures[1, 2] = value;
+ }
+ }
+ public Texture2D bottom_left
+ {
+ get
+ {
+ return Textures[2, 0];
+ }
+ set
+ {
+ Textures[2, 0] = value;
+ }
+ }
+ public Texture2D bottom_middle
+ {
+ get
+ {
+ return Textures[2, 1];
+ }
+ set
+ {
+ Textures[2, 1] = value;
+ }
+ }
+ public Texture2D bottom_right
+ {
+ get
+ {
+ return Textures[2, 2];
+ }
+ set
+ {
+ Textures[2, 2] = value;
+ }
+ }
+
+ public bool IsCorrect()
+ {
+ if (Textures.GetLength(0) != 3 || Textures.GetLength(1) != 3)
+ return false;
+
+ for (int x = 0; x < 3; x++)
+ {
+ for (int y = 0; y < 3; y++)
+ {
+ if (Textures[x, y] == null)
+ return false;
+ }
+ }
+ return true;
+ }
}
}
diff --git a/MyMonoGameAddin/Colors.cs b/MyMonoGameAddin/Colors.cs
index bdb30fc..79e41d8 100644
--- a/MyMonoGameAddin/Colors.cs
+++ b/MyMonoGameAddin/Colors.cs
@@ -1,10 +1,48 @@
-using System;
+using Microsoft.Xna.Framework;
+
namespace MyMonoGameAddin
{
public class Colors
{
- public Colors()
+ public Color Normal;
+ public Color Hover;
+ public Color Focus;
+
+ public Colors(Color color)
{
+ Normal = color;
+ Hover = color;
+ Focus = color;
+ }
+
+ public Colors(Color normal, Color hover)
+ {
+ Normal = normal;
+ Hover = hover;
+ Focus = hover;
+ }
+
+ public Colors(Color normal, Color hover, Color focus)
+ {
+ Normal = normal;
+ Hover = hover;
+ Focus = focus;
+ }
+
+ internal Color Get(UIManager.State status)
+ {
+ switch (status)
+ {
+ case UIManager.State.Hover:
+ return Hover;
+
+ case UIManager.State.Focus:
+ case UIManager.State.Active:
+ return Focus;
+
+ default:
+ return Normal;
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/MyMonoGameAddin/GUIManager.cs b/MyMonoGameAddin/GUIManager.cs
deleted file mode 100644
index 8d16158..0000000
--- a/MyMonoGameAddin/GUIManager.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System;
-namespace MyMonoGameAddin
-{
- public class GUIManager
- {
- public GUIManager()
- {
- }
- }
-}
diff --git a/MyMonoGameAddin/InputsManager.cs b/MyMonoGameAddin/InputsManager.cs
index 6382f51..313a2c4 100644
--- a/MyMonoGameAddin/InputsManager.cs
+++ b/MyMonoGameAddin/InputsManager.cs
@@ -1,10 +1,185 @@
-using System;
+using System.Collections.Generic;
+using Input = Microsoft.Xna.Framework.Input;
+
namespace MyMonoGameAddin
{
+ public enum ButtonState { Released, Pressing, Pressed, Releasing }
+
public class InputsManager
{
- public InputsManager()
+ public MouseManager Mouse;
+ public KeyboardManager Keyboard;
+
+ public InputsManager(bool mouse = true, bool keyboard = true)
{
+ Mouse = new MouseManager(mouse);
+ Keyboard = new KeyboardManager(keyboard);
+
+ }
+
+ public void Update()
+ {
+ Mouse.Update();
+ Keyboard.Update();
+ }
+ }
+
+ public class KeyboardManager
+ {
+ public enum SpecialKeys { Control, Alt, Shift, Windows }
+
+ public bool Enable;
+
+ public KeyboardManager(bool enable = true) { Enable = enable; }
+
+ public Input.KeyboardState State { get { return nowKeyboardState; } }
+ Input.KeyboardState oldKeyboardState;
+ Input.KeyboardState nowKeyboardState;
+
+ public Input.Keys FirstKey { get { return nowKeyboardState.GetPressedKeys().Length > 0 ? nowKeyboardState.GetPressedKeys()[0] : Input.Keys.None; } }
+
+ public List Keys { get { return nowKeys; } }
+ List nowKeys = new List();
+ List oldKeys = new List();
+
+ public List PressingKeys { get { return _PressingKeys; } }
+ List _PressingKeys = new List();
+
+ public List ReleassingKeys { get { return _ReleassingKeys; } }
+ List _ReleassingKeys = new List();
+
+ public void Update()
+ {
+ if (Enable)
+ {
+ oldKeyboardState = nowKeyboardState;
+ nowKeyboardState = Input.Keyboard.GetState();
+
+ oldKeys = nowKeys;
+ nowKeys = new List(nowKeyboardState.GetPressedKeys());
+
+ _PressingKeys.Clear();
+ foreach (Input.Keys newKey in nowKeys)
+ {
+ if (!oldKeys.Contains(newKey))
+ _PressingKeys.Add(newKey);
+ }
+
+ _ReleassingKeys.Clear();
+ foreach (Input.Keys oldKey in oldKeys)
+ {
+ if (!nowKeys.Contains(oldKey))
+ _ReleassingKeys.Add(oldKey);
+ }
+ }
+ }
+
+ public bool IsPressed(Input.Keys key)
+ {
+ return nowKeyboardState.IsKeyDown(key);
+ }
+
+ public bool IsPressed(SpecialKeys key)
+ {
+ switch (key)
+ {
+ case SpecialKeys.Control:
+ return IsPressed(Input.Keys.LeftControl) || IsPressed(Input.Keys.RightControl);
+
+ case SpecialKeys.Alt:
+ return IsPressed(Input.Keys.LeftAlt) || IsPressed(Input.Keys.RightAlt);
+
+ case SpecialKeys.Shift:
+ return IsPressed(Input.Keys.LeftShift) || IsPressed(Input.Keys.RightShift);
+
+ case SpecialKeys.Windows:
+ return IsPressed(Input.Keys.LeftWindows) || IsPressed(Input.Keys.RightWindows);
+
+ default:
+ return false;
+ }
+ }
+
+ public ButtonState GetKeyState(Input.Keys key)
+ {
+ if (nowKeyboardState.IsKeyDown(key))
+ {
+ if (oldKeyboardState.IsKeyUp(key))
+ return ButtonState.Pressing;
+
+ return ButtonState.Pressed;
+ }
+ else
+ {
+ if (oldKeyboardState.IsKeyDown(key))
+ return ButtonState.Releasing;
+
+ return ButtonState.Released;
+ }
+ }
+ }
+
+ public class MouseManager
+ {
+ public bool Enable;
+
+ public MouseManager(bool enable = true) { Enable = enable; }
+
+ public Input.MouseState State { get { return nowMouseState; } }
+ Input.MouseState oldMouseState;
+ Input.MouseState nowMouseState;
+
+ public Vector Position { get { return new Vector(nowMouseState.X, nowMouseState.Y); } }
+ public int X { get { return nowMouseState.X; } }
+ public int Y { get { return nowMouseState.Y; } }
+
+ public bool LeftPressed { get { return nowMouseState.LeftButton == Input.ButtonState.Pressed; } }
+ public ButtonState LeftState { get { return GetState(nowMouseState.LeftButton, oldMouseState.LeftButton); } }
+
+ public bool RightPressed { get { return nowMouseState.RightButton == Input.ButtonState.Pressed; } }
+ public ButtonState RightState { get { return GetState(nowMouseState.RightButton, oldMouseState.RightButton); } }
+
+ public bool MiddlePressed { get { return nowMouseState.MiddleButton == Input.ButtonState.Pressed; } }
+ public ButtonState MiddleState { get { return GetState(nowMouseState.MiddleButton, oldMouseState.MiddleButton); } }
+
+ public int RelativeScroolWheel { get { return nowMouseState.ScrollWheelValue - oldMouseState.ScrollWheelValue; } }
+ public int AbsoluteScroolWheel { get { return nowMouseState.ScrollWheelValue; } }
+
+ public void Update()
+ {
+ if (Enable)
+ {
+ oldMouseState = nowMouseState;
+ nowMouseState = Input.Mouse.GetState();
+ }
+ }
+
+ public void SetPosition(Vector v)
+ {
+ SetPositon(v.X, v.Y);
+ }
+
+ public void SetPositon(int x, int y)
+ {
+ Input.Mouse.SetPosition(x, y);
+ }
+
+ private ButtonState GetState(Input.ButtonState now, Input.ButtonState old)
+ {
+ if (now == Input.ButtonState.Pressed)
+ {
+ if (old == Input.ButtonState.Released)
+ return ButtonState.Pressing;
+
+ return ButtonState.Pressed;
+ }
+ else
+ {
+ if (old == Input.ButtonState.Pressed)
+ return ButtonState.Releasing;
+
+ return ButtonState.Released;
+ }
}
}
}
diff --git a/MyMonoGameAddin/KeyChar.cs b/MyMonoGameAddin/KeyChar.cs
new file mode 100644
index 0000000..72cfa5b
--- /dev/null
+++ b/MyMonoGameAddin/KeyChar.cs
@@ -0,0 +1,212 @@
+using System;
+using System.Collections.Generic;
+using Microsoft.Xna.Framework.Input;
+
+namespace MyMonoGameAddin
+{
+ public static class KeyChar
+ {
+ public enum Layout { QWERTY, AZERTY }
+
+ static readonly Dictionary[] Data = new Dictionary[2]
+ {
+ new Dictionary() //QWERTY
+ {
+ {Keys.OemTilde, new CharPair('`','~')},
+ {Keys.D1, new CharPair('1','!')},
+ {Keys.D2, new CharPair('2','@')},
+ {Keys.D3, new CharPair('3','#')},
+ {Keys.D4, new CharPair('4','$')},
+ {Keys.D5, new CharPair('5','%')},
+ {Keys.D6, new CharPair('6','^')},
+ {Keys.D7, new CharPair('7','&')},
+ {Keys.D8, new CharPair('8','*')},
+ {Keys.D9, new CharPair('9','(')},
+ {Keys.D0, new CharPair('0',')')},
+ {Keys.OemMinus, new CharPair('-','_')},
+ {Keys.OemPlus, new CharPair('=','+')},
+
+ {Keys.Q, new CharPair('q','Q')},
+ {Keys.W, new CharPair('w','W')},
+ {Keys.E, new CharPair('e','E')},
+ {Keys.R, new CharPair('r','R')},
+ {Keys.T, new CharPair('t','T')},
+ {Keys.Y, new CharPair('y','Y')},
+ {Keys.U, new CharPair('u','U')},
+ {Keys.I, new CharPair('i','i')},
+ {Keys.O, new CharPair('o','O')},
+ {Keys.P, new CharPair('p','P')},
+ {Keys.OemOpenBrackets, new CharPair('[','{')},
+ {Keys.OemCloseBrackets, new CharPair(']','}')},
+ {Keys.OemPipe, new CharPair('\\','|')},
+
+ {Keys.A, new CharPair('a','A')},
+ {Keys.S, new CharPair('s','S')},
+ {Keys.D, new CharPair('d','D')},
+ {Keys.F, new CharPair('f','F')},
+ {Keys.G, new CharPair('g','G')},
+ {Keys.H, new CharPair('h','H')},
+ {Keys.J, new CharPair('j','J')},
+ {Keys.K, new CharPair('k','K')},
+ {Keys.L, new CharPair('l','L')},
+ {Keys.OemSemicolon, new CharPair(';',':')},
+ {Keys.OemQuotes, new CharPair('\'','"')},
+
+ {Keys.Z, new CharPair('z','Z')},
+ {Keys.X, new CharPair('x','X')},
+ {Keys.C, new CharPair('c','C')},
+ {Keys.V, new CharPair('v','V')},
+ {Keys.B, new CharPair('b','B')},
+ {Keys.N, new CharPair('n','N')},
+ {Keys.M, new CharPair('m','M')},
+ {Keys.OemComma, new CharPair(',','<')},
+ {Keys.OemPeriod, new CharPair('.','>')},
+ {Keys.OemQuestion, new CharPair('/','?')},
+
+ {Keys.NumPad1, new CharPair('1')},
+ {Keys.NumPad2, new CharPair('2')},
+ {Keys.NumPad3, new CharPair('3')},
+ {Keys.NumPad4, new CharPair('4')},
+ {Keys.NumPad5, new CharPair('5')},
+ {Keys.NumPad6, new CharPair('6')},
+ {Keys.NumPad7, new CharPair('7')},
+ {Keys.NumPad8, new CharPair('8')},
+ {Keys.NumPad9, new CharPair('9')},
+ {Keys.NumPad0, new CharPair('0')},
+ {Keys.Add, new CharPair('+')},
+ {Keys.Divide, new CharPair('/')},
+ {Keys.Multiply, new CharPair('*')},
+ {Keys.Subtract, new CharPair('-')},
+ {Keys.Decimal, new CharPair('.')},
+
+ {Keys.Space, new CharPair(' ')}
+ },
+
+ new Dictionary() //AZERTY
+ {
+ {Keys.OemTilde, new CharPair('²')},
+ {Keys.D1, new CharPair('&','1')},
+ {Keys.D2, new CharPair('é','2','~')},
+ {Keys.D3, new CharPair('"','3','#')},
+ {Keys.D4, new CharPair('\'','4','\'')},
+ {Keys.D5, new CharPair('(','5','[')},
+ {Keys.D6, new CharPair('-','6','|')},
+ {Keys.D7, new CharPair('è','7','`')},
+ {Keys.D8, new CharPair('_','8','\\')},
+ {Keys.D9, new CharPair('ç','9','^')},
+ {Keys.D0, new CharPair('Ã ','0','@')},
+ {Keys.OemMinus, new CharPair(')','°',']')},
+ {Keys.OemPlus, new CharPair('=','+','}')},
+
+ {Keys.Q, new CharPair('a','A')},
+ {Keys.W, new CharPair('z','Z')},
+ {Keys.E, new CharPair('e','E')},
+ {Keys.R, new CharPair('r','R')},
+ {Keys.T, new CharPair('t','T')},
+ {Keys.Y, new CharPair('y','Y')},
+ {Keys.U, new CharPair('u','U')},
+ {Keys.I, new CharPair('i','i')},
+ {Keys.O, new CharPair('o','O')},
+ {Keys.P, new CharPair('p','P')},
+ {Keys.OemOpenBrackets, new CharPair('^','"')},
+ {Keys.OemCloseBrackets, new CharPair('$','£','ø')},
+
+ {Keys.A, new CharPair('q','Q')},
+ {Keys.S, new CharPair('s','S')},
+ {Keys.D, new CharPair('d','D')},
+ {Keys.F, new CharPair('f','F')},
+ {Keys.G, new CharPair('g','G')},
+ {Keys.H, new CharPair('h','H')},
+ {Keys.J, new CharPair('j','J')},
+ {Keys.K, new CharPair('k','K')},
+ {Keys.L, new CharPair('l','L')},
+ {Keys.OemSemicolon, new CharPair('m','M')},
+ {Keys.OemQuotes, new CharPair('ù','%')},
+ {Keys.OemPipe, new CharPair('*','µ')},
+
+ {Keys.Z, new CharPair('w','W')},
+ {Keys.X, new CharPair('x','X')},
+ {Keys.C, new CharPair('c','C')},
+ {Keys.V, new CharPair('v','V')},
+ {Keys.B, new CharPair('b','B')},
+ {Keys.N, new CharPair('n','N')},
+ {Keys.M, new CharPair(',','?')},
+ {Keys.OemComma, new CharPair(';','.')},
+ {Keys.OemPeriod, new CharPair(':','/')},
+ {Keys.OemQuestion, new CharPair('!','§')},
+
+ {Keys.NumPad1, new CharPair('1')},
+ {Keys.NumPad2, new CharPair('2')},
+ {Keys.NumPad3, new CharPair('3')},
+ {Keys.NumPad4, new CharPair('4')},
+ {Keys.NumPad5, new CharPair('5')},
+ {Keys.NumPad6, new CharPair('6')},
+ {Keys.NumPad7, new CharPair('7')},
+ {Keys.NumPad8, new CharPair('8')},
+ {Keys.NumPad9, new CharPair('9')},
+ {Keys.NumPad0, new CharPair('0')},
+ {Keys.Add, new CharPair('+')},
+ {Keys.Divide, new CharPair('/')},
+ {Keys.Multiply, new CharPair('*')},
+ {Keys.Subtract, new CharPair('-')},
+ {Keys.Decimal, new CharPair('.')},
+
+ {Keys.Space, new CharPair(' ')}
+ }
+ };
+
+ class CharPair
+ {
+ public CharPair(char normalChar, Nullable shiftChar = null, Nullable altChar = null)
+ {
+ NormalChar = normalChar;
+ ShiftChar = shiftChar;
+ AltChar = altChar;
+ }
+
+ public char NormalChar;
+ public Nullable ShiftChar;
+ public Nullable AltChar;
+ }
+
+ public static bool KeyToChar(Keys key, bool shitKeyPressed, out Nullable character, Layout layout = Layout.QWERTY, bool altKeyPressed = false)
+ {
+ bool result = false;
+ character = null;
+ CharPair charPair;
+
+ if (Data[(int)layout].TryGetValue(key, out charPair))
+ {
+ if (shitKeyPressed)
+ {
+ if (!altKeyPressed)
+ {
+ if (charPair.ShiftChar.HasValue)
+ {
+ character = charPair.ShiftChar.Value;
+ result = true;
+ }
+ }
+ }
+ else
+ {
+ if (altKeyPressed)
+ {
+ if (charPair.AltChar.HasValue)
+ {
+ character = charPair.AltChar.Value;
+ result = true;
+ }
+ }
+ else
+ {
+ character = charPair.NormalChar;
+ result = true;
+ }
+ }
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/MyMonoGameAddin/MyMonoGameAddin.csproj b/MyMonoGameAddin/MyMonoGameAddin.csproj
index de1addf..51e3705 100644
--- a/MyMonoGameAddin/MyMonoGameAddin.csproj
+++ b/MyMonoGameAddin/MyMonoGameAddin.csproj
@@ -28,10 +28,21 @@
+
+ ..\..\..\..\..\..\..\usr\lib\mono\xbuild\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll
+
+
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MyMonoGameAddin/ResourcesManager.cs b/MyMonoGameAddin/ResourcesManager.cs
index b7e8924..ef53d6e 100644
--- a/MyMonoGameAddin/ResourcesManager.cs
+++ b/MyMonoGameAddin/ResourcesManager.cs
@@ -1,10 +1,169 @@
using System;
+using System.IO;
+using System.Collections.Generic;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Audio;
+using Microsoft.Xna.Framework.Graphics;
+
namespace MyMonoGameAddin
{
- public class MyClass
+ public class ResourcesManager
{
- public MyClass()
+ public enum KeyMode { path, file }
+
+ public Dictionary Fonts = new Dictionary();
+ public Dictionary Textures = new Dictionary();
+ public Dictionary Sounds = new Dictionary();
+ public Dictionary Boxes = new Dictionary();
+
+ ContentManager Content;
+ GraphicsDevice Graphics;
+
+ public ResourcesManager(ContentManager content, GraphicsDevice graphics)
{
+ Content = content;
+ Graphics = graphics;
+ }
+
+ public void LoadFont(string assetname, KeyMode keymode = KeyMode.file, bool fullpath = false)
+ {
+ string keyname;
+ if (keymode == KeyMode.file)
+ {
+ string[] split = assetname.Split('/');
+ keyname = split[split.Length - 1];
+ }
+ else
+ {
+ keyname = assetname;
+ }
+ LoadFont(keyname, assetname, fullpath);
+ }
+
+ public void LoadFont(string keyname, string path, bool fullpath = false)
+ {
+ Fonts.Add(keyname, Content.Load((fullpath ? "" : "Fonts/") + path));
+ }
+
+ public bool TryLoadTextureFile(string keyname, string path)
+ {
+ try
+ {
+ if (File.Exists(path))
+ {
+ using (FileStream fileStream = new FileStream(path, FileMode.Open))
+ {
+ Textures.Add(keyname, Texture2D.FromStream(Graphics, fileStream));
+ }
+ return true;
+ }
+ return false;
+ }
+ catch { }
+ return false;
+ }
+
+ public void LoadTexture(string assetname, KeyMode keymode = KeyMode.file, bool fullpath = false)
+ {
+ string keyname;
+ if (keymode == KeyMode.file)
+ {
+ string[] split = assetname.Split('/');
+ keyname = split[split.Length - 1];
+ }
+ else
+ {
+ keyname = assetname;
+ }
+ LoadTexture(keyname, assetname, fullpath);
+ }
+
+ public void LoadTexture(string keyname, string path, bool fullpath = false)
+ {
+ Textures.Add(keyname, Content.Load((fullpath ? "" : "Textures/") + path));
+ }
+
+ public bool TryLoadSoundFile(string keyname, string path)
+ {
+ try
+ {
+ if (File.Exists(path))
+ {
+ using (FileStream fileStream = new FileStream(path, FileMode.Open))
+ {
+ Sounds.Add(keyname, SoundEffect.FromStream(fileStream));
+ }
+ }
+ return false;
+ }
+ catch { }
+ return false;
+ }
+
+ public void LoadSound(string assetname, KeyMode keymode = KeyMode.file, bool fullpath = false)
+ {
+ string keyname;
+ if (keymode == KeyMode.file)
+ {
+ string[] split = assetname.Split('/');
+ keyname = split[split.Length - 1];
+ }
+ else
+ {
+ keyname = assetname;
+ }
+ LoadSound(keyname, assetname, fullpath);
+ }
+
+ public void LoadSound(string keyname, string path, bool fullpath = false)
+ {
+ Sounds.Add(keyname, Content.Load((fullpath ? "" : "Sounds/") + path));
+ }
+
+ public void LoadBox(string foldername, KeyMode keymode = KeyMode.file, bool textname = false, bool fullpath = false)
+ {
+ string keyname;
+ if (keymode == KeyMode.file)
+ {
+ string[] split = foldername.Split('/');
+ keyname = split[split.Length - 1];
+ }
+ else
+ {
+ keyname = foldername;
+ }
+ LoadBox(keyname, foldername, textname, fullpath);
+ }
+
+ public void LoadBox(string keyname, string path, bool textname = false, bool fullpath = false)
+ {
+ BoxTexture box = new BoxTexture();
+ string folderpath = (fullpath ? "" : "Textures/Boxes/") + path + "/";
+ if (textname)
+ {
+ box.top_left = Content.Load(folderpath + "top_left");
+ box.top_middle = Content.Load(folderpath + "top_middle");
+ box.top_right = Content.Load(folderpath + "top_right");
+ box.middle_left = Content.Load(folderpath + "middle_left");
+ box.middle_middle = Content.Load(folderpath + "middle_middle");
+ box.middle_right = Content.Load(folderpath + "middle_right");
+ box.bottom_left = Content.Load(folderpath + "bottom_left");
+ box.bottom_middle = Content.Load(folderpath + "bottom_middle");
+ box.bottom_right = Content.Load(folderpath + "bottom_right");
+ }
+ else
+ {
+ for (int x = 0; x < 3; x++)
+ {
+ for (int y = 0; y < 3; y++)
+ {
+ box.Textures[x, y] = Content.Load(folderpath + x + "_" + y); //0_0.png
+ }
+ }
+ }
+ if (!box.IsCorrect())
+ throw new Exception("Incorrect Box");
+ Boxes.Add(keyname, box);
}
}
}
diff --git a/MyMonoGameAddin/Skin.cs b/MyMonoGameAddin/Skin.cs
new file mode 100644
index 0000000..5c3552d
--- /dev/null
+++ b/MyMonoGameAddin/Skin.cs
@@ -0,0 +1,22 @@
+using System;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace MyMonoGameAddin
+{
+ public struct Skin
+ {
+ public Colors backColors;
+ public Colors foreColors;
+ public BoxTexture texture;
+ public SpriteFont font;
+
+ public Skin(BoxTexture text, SpriteFont fon, Colors back, Colors fore)
+ {
+ texture = text;
+ font = fon;
+ backColors = back;
+ foreColors = fore;
+ }
+ }
+}
\ No newline at end of file
diff --git a/MyMonoGameAddin/UIManager.cs b/MyMonoGameAddin/UIManager.cs
new file mode 100644
index 0000000..6a89494
--- /dev/null
+++ b/MyMonoGameAddin/UIManager.cs
@@ -0,0 +1,414 @@
+using System;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace MyMonoGameAddin
+{
+ public class UIManager
+ {
+ public enum State { Normal, Hover, Focus, Active }
+ public enum textAlign { topLeft, topCenter, topRight, centerLeft, centerCenter, centerRight, bottomLeft, bottomCenter, bottomRight };
+
+ SpriteBatch spriteBatch;
+ InputsManager inputs;
+ public KeyChar.Layout layout = KeyChar.Layout.QWERTY;
+ bool moved = false;
+
+ public Vector focus;
+
+ public Skin skin;
+
+ public UIManager(SpriteBatch batch, InputsManager input, Skin defaultSkin)
+ {
+ spriteBatch = batch;
+ inputs = input;
+ skin = defaultSkin;
+ }
+
+ public void SetBatch(SpriteBatch batch)
+ {
+ spriteBatch = batch;
+ }
+
+ public void Update()
+ {
+ moved = false;
+
+ if (inputs.Mouse.LeftState == ButtonState.Releasing)
+ {
+ focus = inputs.Mouse.Position;
+ }
+ }
+
+ public void ResetFocus()
+ {
+ focus = null;
+ }
+
+ public State GetState(Rectangle rect)
+ {
+ bool contain = rect.Contains(inputs.Mouse.X, inputs.Mouse.Y);
+
+ if (inputs.Mouse.LeftPressed)
+ return contain ? State.Active : State.Normal;
+
+ if (focus != null)
+ if (rect.Contains(focus.X, focus.Y))
+ return State.Focus;
+
+ return contain ? State.Hover : State.Normal;
+ }
+
+ Vector GetLabelPos(Vector _pos, textAlign _align, SpriteFont _font, string _text)
+ {
+ switch (_align)
+ {
+ case textAlign.topLeft:
+ return new Vector(_pos.X - (int)_font.MeasureString(_text).X, _pos.Y - (int)_font.MeasureString(_text).Y);
+
+ case textAlign.topCenter:
+ return new Vector(_pos.X - (int)_font.MeasureString(_text).X / 2, _pos.Y - (int)_font.MeasureString(_text).Y);
+
+ case textAlign.topRight:
+ return new Vector(_pos.X, _pos.Y - (int)_font.MeasureString(_text).Y);
+
+ case textAlign.centerLeft:
+ return new Vector(_pos.X - (int)_font.MeasureString(_text).X, _pos.Y - (int)_font.MeasureString(_text).Y / 2);
+
+ case textAlign.centerCenter:
+ return new Vector(_pos.X - (int)_font.MeasureString(_text).X / 2, _pos.Y - (int)_font.MeasureString(_text).Y / 2);
+
+ case textAlign.centerRight:
+ return new Vector(_pos.X, _pos.Y - (int)_font.MeasureString(_text).Y / 2);
+
+ case textAlign.bottomLeft:
+ return new Vector(_pos.X - (int)_font.MeasureString(_text).X, _pos.Y);
+
+ case textAlign.bottomCenter:
+ return new Vector(_pos.X - (int)_font.MeasureString(_text).X / 2, _pos.Y);
+
+ case textAlign.bottomRight:
+ return new Vector(_pos.X, _pos.Y);
+
+ default:
+ return new Vector(_pos.X, _pos.Y);
+ }
+ }
+
+ Vector GetLabelPos(Rectangle _pos, textAlign _align, SpriteFont _font, string _text)
+ {
+ switch (_align)
+ {
+ case textAlign.topLeft:
+ return new Vector(_pos.X, _pos.Y);
+
+ case textAlign.topCenter:
+ return new Vector(_pos.X + _pos.Width / 2 - (int)_font.MeasureString(_text).X / 2, _pos.Y);
+
+ case textAlign.topRight:
+ return new Vector(_pos.X + _pos.Width - (int)_font.MeasureString(_text).X, _pos.Y);
+
+ case textAlign.centerLeft:
+ return new Vector(_pos.X, _pos.Y + _pos.Height / 2 - (int)_font.MeasureString(_text).Y / 2);
+
+ case textAlign.centerCenter:
+ return new Vector(_pos.X + _pos.Width / 2 - (int)_font.MeasureString(_text).X / 2, _pos.Y + _pos.Height / 2 - (int)_font.MeasureString(_text).Y / 2);
+
+ case textAlign.centerRight:
+ return new Vector(_pos.X + _pos.Width - (int)_font.MeasureString(_text).X, _pos.Y + _pos.Height / 2 - (int)_font.MeasureString(_text).Y / 2);
+
+ case textAlign.bottomLeft:
+ return new Vector(_pos.X, _pos.Y + _pos.Height - (int)_font.MeasureString(_text).Y);
+
+ case textAlign.bottomCenter:
+ return new Vector(_pos.X + _pos.Width / 2 - (int)_font.MeasureString(_text).X / 2, _pos.Y + _pos.Height - (int)_font.MeasureString(_text).Y);
+
+ case textAlign.bottomRight:
+ return new Vector(_pos.X + _pos.Width - (int)_font.MeasureString(_text).X, _pos.Y + _pos.Height - (int)_font.MeasureString(_text).Y);
+
+ default:
+ return new Vector(_pos.X, _pos.Y);
+ }
+ }
+
+ void Next(Vector next, Rectangle pos)
+ {
+ if (next != null)
+ {
+ if (focus != null)
+ {
+ if (!moved)
+ {
+ if (inputs.Keyboard.GetKeyState(Microsoft.Xna.Framework.Input.Keys.Tab) == ButtonState.Pressing)
+ {
+ if (GetState(pos) == State.Focus)
+ {
+ moved = true;
+ focus = next;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public void Texture(Rectangle pos, Texture2D texture, Color color, Vector next = null)
+ {
+ Next(next, pos);
+ spriteBatch.Draw(texture, pos, color);
+ }
+
+ public void Texture(Rectangle pos, Texture2D texture, Colors color = null, Vector next = null)
+ {
+ if (color == null)
+ color = skin.backColors;
+
+ Texture(pos, texture, color.Get(GetState(pos)), next);
+ }
+
+ public void Box(Rectangle pos, Color backColor, BoxTexture backSprites = null, Vector next = null)
+ {
+ if (backSprites == null)
+ backSprites = skin.texture;
+
+ Next(next, pos);
+ int leftWidth = backSprites.top_left.Width;
+ int rightWidth = backSprites.top_right.Width;
+ int centerWidth = pos.Width - leftWidth - rightWidth;
+
+ int topHeight = backSprites.top_left.Height;
+ int bottomHeight = backSprites.bottom_left.Height;
+ int centerHeight = pos.Height - topHeight - bottomHeight;
+
+ spriteBatch.Draw(backSprites.top_left, new Rectangle(pos.X, pos.Y, leftWidth, topHeight), backColor);
+ spriteBatch.Draw(backSprites.top_middle, new Rectangle(pos.X + leftWidth, pos.Y, centerWidth, topHeight), backColor);
+ spriteBatch.Draw(backSprites.top_right, new Rectangle(pos.X + pos.Width - rightWidth, pos.Y, rightWidth, topHeight), backColor);
+ spriteBatch.Draw(backSprites.middle_left, new Rectangle(pos.X, pos.Y + topHeight, leftWidth, centerHeight), backColor);
+ spriteBatch.Draw(backSprites.middle_middle, new Rectangle(pos.X + leftWidth, pos.Y + topHeight, centerWidth, centerHeight), backColor);
+ spriteBatch.Draw(backSprites.middle_right, new Rectangle(pos.X + pos.Width - rightWidth, pos.Y + topHeight, rightWidth, centerHeight), backColor);
+ spriteBatch.Draw(backSprites.bottom_left, new Rectangle(pos.X, pos.Y + pos.Height - bottomHeight, leftWidth, bottomHeight), backColor);
+ spriteBatch.Draw(backSprites.bottom_middle, new Rectangle(pos.X + leftWidth, pos.Y + pos.Height - bottomHeight, centerWidth, bottomHeight), backColor);
+ spriteBatch.Draw(backSprites.bottom_right, new Rectangle(pos.X + pos.Width - rightWidth, pos.Y + pos.Height - bottomHeight, rightWidth, bottomHeight), backColor);
+ }
+
+ public void Box(Rectangle pos, Colors backColor = null, BoxTexture backSprites = null, Vector next = null)
+ {
+ if (backColor == null)
+ backColor = skin.backColors;
+
+ Box(pos, backColor.Get(GetState(pos)), backSprites, next);
+ }
+
+ public void Label(Rectangle pos, string text, Color color, SpriteFont font = null, textAlign align = textAlign.centerCenter, Vector next = null)
+ {
+ if (font == null)
+ font = skin.font;
+
+ Next(next, pos);
+ Vector v = GetLabelPos(pos, align, font, text);
+ spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), color);
+ }
+
+ public void Label(Rectangle pos, string text, Colors colors = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, Vector next = null)
+ {
+ if (colors == null)
+ colors = skin.foreColors;
+
+ Label(pos, text, colors.Get(GetState(pos)), font, align, next);
+ }
+
+ public void Label(Vector vector, string text, Color color, SpriteFont font = null, textAlign align = textAlign.bottomRight, Vector next = null)
+ {
+ if (font == null)
+ font = skin.font;
+
+ Vector v = GetLabelPos(vector, align, font, text);
+
+ if (next != null)
+ Next(next, new Rectangle(v.X, v.Y, (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y));
+
+ spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), color);
+ }
+
+ public void Label(Vector vector, string text, Colors colors = null, SpriteFont font = null, textAlign align = textAlign.bottomRight, Vector next = null)
+ {
+ if (colors == null)
+ colors = skin.foreColors;
+
+ if (font == null)
+ font = skin.font;
+
+ Vector v = GetLabelPos(vector, align, font, text);
+
+ if (next != null)
+ Next(next, new Rectangle(v.X, v.Y, (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y));
+
+ spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), colors.Get(GetState(new Rectangle(v.X, v.Y, (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y))));
+ }
+
+ bool Button(State state)
+ {
+ switch (state)
+ {
+ case State.Active:
+ return true;
+
+ case State.Focus:
+ return inputs.Keyboard.IsPressed(Microsoft.Xna.Framework.Input.Keys.Enter);
+
+ default:
+ return false;
+ }
+ }
+
+ public bool Button(Rectangle pos, Texture2D texture, Color color, Vector next = null)
+ {
+ Texture(pos, texture, color, next);
+ return Button(GetState(pos));
+ }
+
+ public bool Button(Rectangle pos, Texture2D texture, Colors color = null, Vector next = null)
+ {
+ if (color == null)
+ color = skin.backColors;
+
+ return Button(pos, texture, color.Get(GetState(pos)), next);
+ }
+
+ public bool Button(Rectangle pos, Color color, BoxTexture texture = null, Vector next = null)
+ {
+ if (texture == null)
+ texture = skin.texture;
+
+ Box(pos, color, texture, next);
+ return Button(GetState(pos));
+ }
+
+ public bool Button(Rectangle pos, Colors color = null, BoxTexture texture = null, Vector next = null)
+ {
+ if (color == null)
+ color = skin.backColors;
+
+ return Button(pos, color.Get(GetState(pos)), texture, next);
+ }
+
+ public bool Button(Rectangle pos, string text, Color backcolor, Color forecolor, BoxTexture texture = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, Vector next = null)
+ {
+ Box(pos, backcolor, texture, next);
+ Label(pos, text, forecolor, font, align);
+ return Button(GetState(pos));
+ }
+
+ public bool Button(Rectangle pos, String text, Colors backcolor = null, Colors forecolor = null, BoxTexture texture = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, Vector next = null)
+ {
+ if (backcolor == null)
+ backcolor = skin.backColors;
+
+ if (forecolor == null)
+ forecolor = skin.foreColors;
+
+ State state = GetState(pos);
+ return Button(pos, text, backcolor.Get(state), forecolor.Get(state), texture, font, align, next);
+ }
+
+ string fieldText(string value, string placeHolder)
+ {
+ return (placeHolder != null && (value == null || value == "")) ? placeHolder : value;
+ }
+
+ public bool TextField(Rectangle pos, ref string value, Color color, SpriteFont font = null, textAlign align = textAlign.centerCenter, string placeHolder = null, Vector next = null)
+ {
+ string _text = fieldText(value, placeHolder);
+ if (inputs.Keyboard.PressingKeys.Count > 0)
+ {
+ if (GetState(pos) == State.Focus)
+ {
+ if (inputs.Keyboard.PressingKeys[0] == Microsoft.Xna.Framework.Input.Keys.Back)
+ {
+ if (value != null)
+ {
+ if (value.Length > 0)
+ {
+ value = value.Remove(value.Length - 1);
+ _text = fieldText(value, placeHolder);
+ }
+ }
+ }
+ else
+ {
+ Nullable ch;
+ if (KeyChar.KeyToChar(inputs.Keyboard.PressingKeys[0], inputs.Keyboard.IsPressed(KeyboardManager.SpecialKeys.Shift), out ch, layout, inputs.Keyboard.IsPressed(Microsoft.Xna.Framework.Input.Keys.RightAlt)))
+ {
+ if (ch.HasValue)
+ {
+ value += ch.Value;
+ _text = fieldText(value, placeHolder);
+ }
+ }
+ }
+ }
+ }
+ Label(pos, _text, color, font, align, next);
+ return inputs.Keyboard.GetKeyState(Microsoft.Xna.Framework.Input.Keys.Enter) == ButtonState.Pressing;
+ }
+
+ public bool TextField(Rectangle pos, ref string value, Colors color = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, string placeHolder = null, Vector next = null)
+ {
+ if (color == null)
+ color = skin.foreColors;
+
+ return TextField(pos, ref value, color.Get(GetState(pos)), font, align, placeHolder, next);
+ }
+
+ public bool TextField(Vector vector, ref string value, Color color, SpriteFont font = null, textAlign align = textAlign.centerCenter, string placeHolder = null, Vector next = null)
+ {
+ if (font == null)
+ font = skin.font;
+
+ string _text = fieldText(value, placeHolder);
+ if (inputs.Keyboard.PressingKeys.Count > 0)
+ {
+ if (GetState(new Rectangle(vector.X, vector.Y, (int)font.MeasureString(_text).X, (int)font.MeasureString(_text).Y)) == State.Focus)
+ {
+ if (inputs.Keyboard.PressingKeys[0] == Microsoft.Xna.Framework.Input.Keys.Back)
+ {
+ if (value != null)
+ {
+ if (value.Length > 0)
+ {
+ value = value.Remove(value.Length - 1);
+ _text = fieldText(value, placeHolder);
+ }
+ }
+ }
+ else
+ {
+ Nullable ch;
+ if (KeyChar.KeyToChar(inputs.Keyboard.PressingKeys[0], inputs.Keyboard.IsPressed(KeyboardManager.SpecialKeys.Shift), out ch, layout, inputs.Keyboard.IsPressed(Microsoft.Xna.Framework.Input.Keys.RightAlt)))
+ {
+ if (ch.HasValue)
+ {
+ value += ch.Value;
+ _text = fieldText(value, placeHolder);
+ }
+ }
+ }
+ }
+ }
+ Label(vector, _text, color, font, align, next);
+ return inputs.Keyboard.GetKeyState(Microsoft.Xna.Framework.Input.Keys.Enter) == ButtonState.Pressing;
+ }
+
+ public bool TextField(Vector vector, ref string value, Colors color = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, string placeHolder = null, Vector next = null)
+ {
+ if (color == null)
+ color = skin.foreColors;
+
+ if (font == null)
+ font = skin.font;
+
+ string _text = fieldText(value, placeHolder);
+ return TextField(vector, ref value, color.Get(GetState(new Rectangle(vector.X, vector.Y, (int)font.MeasureString(_text).X, (int)font.MeasureString(_text).Y))), font, align, placeHolder, next);
+ }
+ }
+}
diff --git a/MyMonoGameAddin/Vector.cs b/MyMonoGameAddin/Vector.cs
index 8636eac..44100be 100644
--- a/MyMonoGameAddin/Vector.cs
+++ b/MyMonoGameAddin/Vector.cs
@@ -11,12 +11,18 @@
Y = y;
}
+ public static Vector Add(Vector v1, Vector v2)
+ {
+ return new Vector(v1.X + v2.X, v1.Y + v2.Y);
+ }
+
public void Add(Vector v)
{
X += v.X;
Y += v.Y;
}
- public static Vector Zero { get { return new Vector(0, 0); } }
+ public static Vector Zero = new Vector(0, 0);
+ public static Vector One = new Vector(1, 1);
}
}
diff --git a/README.md b/README.md
deleted file mode 100644
index 21b1fb6..0000000
--- a/README.md
+++ /dev/null
@@ -1 +0,0 @@
-MyMonoGameAddin
diff --git a/Readme.md b/Readme.md
new file mode 100755
index 0000000..35bfca3
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1,36 @@
+# My Monogame Addin
+
+MyMonogameAddin is a simple library from [Monogame](https://github.com/MonoGame/MonoGame)
+
+### Prerequisities
+
+* .NET/[Mono](https://github.com/mono/mono) 4.5+
+* [Monogame](https://github.com/MonoGame/MonoGame) 3.5+
+
+### Installing
+
+1. Download last version
+
+2. Copy Exemple/MainGame.cs
+
+3. Let's Go
+
+## Test With
+
+* Windows 10 x64
+* Linux Manjaro 16.10.3 x64
+
+## Contributing
+
+Get [Monogame](https://github.com/MonoGame/MonoGame).
+As you wish, I am opened to new ideas.
+
+## Author
+
+* **[Sheychen](https://sheychen.shost.ca)** - *Initial work*
+
+See also the list of [contributors](https://github.com/sheychen290/Galactic_Colors_Control/contributors) who participated in this project.
+
+### License
+
+This software comes under the terms of the GPLv3+. See the [License.md](License.md) file for the complete text of the license.