Creation du projet
This commit is contained in:
parent
c91d76c9c2
commit
b26e919746
|
@ -0,0 +1,22 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.24720.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyMonoGame", "MyMonoGameGUI\MyMonoGame.csproj", "{7A776114-65C0-4443-82A6-0A16425A8398}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7A776114-65C0-4443-82A6-0A16425A8398}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7A776114-65C0-4443-82A6-0A16425A8398}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7A776114-65C0-4443-82A6-0A16425A8398}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7A776114-65C0-4443-82A6-0A16425A8398}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,43 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class Box : Element
|
||||
{
|
||||
protected boxSprites _backSprites;
|
||||
protected Colors _colors;
|
||||
|
||||
public Box() { }
|
||||
|
||||
public Box(Rectangle pos, boxSprites backSprites, Colors colors)
|
||||
{
|
||||
_pos = pos;
|
||||
_backSprites = backSprites;
|
||||
_colors = colors;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Color backColor = _isFocus ? _colors._focus : (_isHover ? _colors._hover : _colors._normal);
|
||||
|
||||
int leftWidth = _backSprites.topLeft.Width;
|
||||
int rightWidth = _backSprites.topRight.Width;
|
||||
int centerWidth = _pos.Width - leftWidth - rightWidth;
|
||||
|
||||
int topHeight = _backSprites.topLeft.Height;
|
||||
int bottomHeight = _backSprites.bottomLeft.Height;
|
||||
int centerHeight = _pos.Height - topHeight - bottomHeight;
|
||||
|
||||
spriteBatch.Draw(_backSprites.topLeft, new Rectangle(_pos.X, _pos.Y, leftWidth, topHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.topCenter, new Rectangle(_pos.X + leftWidth, _pos.Y, centerWidth, topHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.topRight, new Rectangle(_pos.X + _pos.Width - rightWidth, _pos.Y, rightWidth, topHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.centerLeft, new Rectangle(_pos.X, _pos.Y + topHeight, leftWidth, centerHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.centerCenter, new Rectangle(_pos.X + leftWidth, _pos.Y + topHeight, centerWidth, centerHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.centerRight, new Rectangle(_pos.X + _pos.Width - rightWidth, _pos.Y + topHeight, rightWidth, centerHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.bottomLeft, new Rectangle(_pos.X, _pos.Y + _pos.Height - bottomHeight, leftWidth, bottomHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.bottomCenter, new Rectangle(_pos.X + leftWidth, _pos.Y + _pos.Height - bottomHeight, centerWidth, bottomHeight), backColor);
|
||||
spriteBatch.Draw(_backSprites.bottomRight, new Rectangle(_pos.X + _pos.Width - rightWidth, _pos.Y + _pos.Height - bottomHeight, rightWidth, bottomHeight), backColor);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class BoxButton : Box
|
||||
{
|
||||
protected Button _button;
|
||||
private int _unFocusTime;
|
||||
|
||||
public BoxButton() { }
|
||||
|
||||
public BoxButton(Rectangle pos, boxSprites backSprites, Colors colors, EventHandler click = null)
|
||||
{
|
||||
_pos = pos;
|
||||
_backSprites = backSprites;
|
||||
_colors = colors;
|
||||
_button = new Button(pos, click);
|
||||
}
|
||||
|
||||
public override void Update(int x, int y, Mouse mouse, Keys key, bool isMaj, EventArgs e)
|
||||
{
|
||||
base.Update(x, y, mouse, key, isMaj, e);
|
||||
_button.Update(x, y, mouse, key, isMaj, e);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (_isFocus)
|
||||
{
|
||||
if (_unFocusTime < 10)
|
||||
{
|
||||
_unFocusTime++;
|
||||
}
|
||||
else {
|
||||
_isFocus = false;
|
||||
_unFocusTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_button.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class BoxLabel : Box
|
||||
{
|
||||
protected Label _label;
|
||||
|
||||
public BoxLabel() { }
|
||||
|
||||
public BoxLabel(Rectangle pos, boxSprites backSprites, Colors colors, string text, SpriteFont font, Colors textColors, Label.textAlign align = Label.textAlign.centerCenter)
|
||||
{
|
||||
_pos = pos;
|
||||
_backSprites = backSprites;
|
||||
_colors = colors;
|
||||
_label = new Label(pos, text, font, textColors, align);
|
||||
}
|
||||
|
||||
public override void Update(int x, int y, Mouse mouse, Keys key, bool isMaj, EventArgs e)
|
||||
{
|
||||
base.Update(x, y, mouse, key, isMaj, e);
|
||||
_label.Update(x, y, mouse, key, isMaj, e);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
_label.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class BoxLabelButton : BoxLabel
|
||||
{
|
||||
protected Button _button;
|
||||
private int _unFocusTime;
|
||||
|
||||
public BoxLabelButton(Rectangle pos, boxSprites backSprites, Colors colors, string text, SpriteFont font, Colors textColors, Label.textAlign align = Label.textAlign.centerCenter, EventHandler click = null)
|
||||
{
|
||||
_pos = pos;
|
||||
_backSprites = backSprites;
|
||||
_colors = colors;
|
||||
_button = new Button(pos, click);
|
||||
_label = new Label(pos, text, font, textColors, align);
|
||||
}
|
||||
|
||||
public override void Update(int x, int y, Mouse mouse, Keys key, bool isMaj, EventArgs e)
|
||||
{
|
||||
base.Update(x, y, mouse, key, isMaj, e);
|
||||
_button.Update(x, y, mouse, key, isMaj, e);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (_isFocus)
|
||||
{
|
||||
if (_unFocusTime < 10)
|
||||
{
|
||||
_unFocusTime++;
|
||||
}
|
||||
else {
|
||||
_isFocus = false;
|
||||
_label._isFocus = false;
|
||||
_unFocusTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_button.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class Button : Element
|
||||
{
|
||||
protected event EventHandler _click;
|
||||
protected int _unFocusTime = 0;
|
||||
|
||||
public Button() { }
|
||||
|
||||
public Button(Rectangle pos, EventHandler click = null)
|
||||
{
|
||||
_pos = pos;
|
||||
_click = click;
|
||||
}
|
||||
|
||||
public override void Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_click != null)
|
||||
{
|
||||
_click.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (_isFocus)
|
||||
{
|
||||
if (_unFocusTime < 10)
|
||||
{
|
||||
_unFocusTime++;
|
||||
}
|
||||
else {
|
||||
_isFocus = false;
|
||||
_unFocusTime = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace MyMonoGame
|
||||
{
|
||||
public class 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class Element
|
||||
{
|
||||
protected Rectangle _pos;
|
||||
public bool _isHover;
|
||||
public bool _isFocus;
|
||||
|
||||
public virtual bool Contain(int x, int y)
|
||||
{
|
||||
return _pos.Contains(x, y);
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Update(int x, int y, Mouse mouse, Keys key, bool isMaj, EventArgs e)
|
||||
{
|
||||
if (mouse.leftPress)
|
||||
{
|
||||
if (Contain(x, y))
|
||||
{
|
||||
_isFocus = true;
|
||||
Click(this, e);
|
||||
}
|
||||
else { _isFocus = false; }
|
||||
}
|
||||
else { _isHover = Contain(x, y); }
|
||||
}
|
||||
|
||||
public virtual void Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MyMonoGame
|
||||
{
|
||||
public static class KeyString
|
||||
{
|
||||
private static Dictionary<Keys, CharPair> Data = new Dictionary<Keys, CharPair>();
|
||||
|
||||
class CharPair
|
||||
{
|
||||
public CharPair(char normalChar, Nullable<char> shiftChar)
|
||||
{
|
||||
this.NormalChar = normalChar;
|
||||
this.ShiftChar = shiftChar;
|
||||
}
|
||||
|
||||
public char NormalChar;
|
||||
public Nullable<char> ShiftChar;
|
||||
}
|
||||
|
||||
public static bool KeyToString(Keys key, bool shitKeyPressed, out char character)
|
||||
{
|
||||
bool result = false;
|
||||
character = ' ';
|
||||
CharPair charPair;
|
||||
|
||||
if ((Keys.A <= key && key <= Keys.Z) || key == Keys.Space)
|
||||
{
|
||||
// Use as is if it is A~Z, or Space key.
|
||||
character = (shitKeyPressed) ? (char)key : Char.ToLower((char)key);
|
||||
result = true;
|
||||
}
|
||||
else if (Data.TryGetValue(key, out charPair))
|
||||
{
|
||||
// Otherwise, convert by key map.
|
||||
if (!shitKeyPressed)
|
||||
{
|
||||
character = charPair.NormalChar;
|
||||
result = true;
|
||||
}
|
||||
else if (charPair.ShiftChar.HasValue)
|
||||
{
|
||||
character = charPair.ShiftChar.Value;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void AddKeyMap(Keys key, string charPair)
|
||||
{
|
||||
char char1 = charPair[0];
|
||||
Nullable<char> char2 = null;
|
||||
if (charPair.Length > 1)
|
||||
char2 = charPair[1];
|
||||
|
||||
Data.Add(key, new CharPair(char1, char2));
|
||||
}
|
||||
|
||||
public static void InitializeKeyString()
|
||||
{
|
||||
// First row of US keyboard.
|
||||
AddKeyMap(Keys.OemTilde, "`~");
|
||||
AddKeyMap(Keys.D1, "1!");
|
||||
AddKeyMap(Keys.D2, "2@");
|
||||
AddKeyMap(Keys.D3, "3#");
|
||||
AddKeyMap(Keys.D4, "4$");
|
||||
AddKeyMap(Keys.D5, "5%");
|
||||
AddKeyMap(Keys.D6, "6^");
|
||||
AddKeyMap(Keys.D7, "7&");
|
||||
AddKeyMap(Keys.D8, "8*");
|
||||
AddKeyMap(Keys.D9, "9(");
|
||||
AddKeyMap(Keys.D0, "0)");
|
||||
AddKeyMap(Keys.OemMinus, "-_");
|
||||
AddKeyMap(Keys.OemPlus, "=+");
|
||||
|
||||
// Second row of US keyboard.
|
||||
AddKeyMap(Keys.OemOpenBrackets, "[{");
|
||||
AddKeyMap(Keys.OemCloseBrackets, "]}");
|
||||
AddKeyMap(Keys.OemPipe, "\\|");
|
||||
|
||||
// Third row of US keyboard.
|
||||
AddKeyMap(Keys.OemSemicolon, ";:");
|
||||
AddKeyMap(Keys.OemQuotes, "'\"");
|
||||
AddKeyMap(Keys.OemComma, ",<");
|
||||
AddKeyMap(Keys.OemPeriod, ".>");
|
||||
AddKeyMap(Keys.OemQuestion, "/?");
|
||||
|
||||
// Keypad keys of US keyboard.
|
||||
AddKeyMap(Keys.NumPad1, "1");
|
||||
AddKeyMap(Keys.NumPad2, "2");
|
||||
AddKeyMap(Keys.NumPad3, "3");
|
||||
AddKeyMap(Keys.NumPad4, "4");
|
||||
AddKeyMap(Keys.NumPad5, "5");
|
||||
AddKeyMap(Keys.NumPad6, "6");
|
||||
AddKeyMap(Keys.NumPad7, "7");
|
||||
AddKeyMap(Keys.NumPad8, "8");
|
||||
AddKeyMap(Keys.NumPad9, "9");
|
||||
AddKeyMap(Keys.NumPad0, "0");
|
||||
AddKeyMap(Keys.Add, "+");
|
||||
AddKeyMap(Keys.Divide, "/");
|
||||
AddKeyMap(Keys.Multiply, "*");
|
||||
AddKeyMap(Keys.Subtract, "-");
|
||||
AddKeyMap(Keys.Decimal, ".");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class Label : Element
|
||||
{
|
||||
public enum textAlign { topLeft, topCenter, topRight, centerLeft, centerCenter, centerRight, bottomLeft, bottomCenter, bottomRight };
|
||||
protected textAlign _align;
|
||||
protected string _text;
|
||||
protected SpriteFont _font;
|
||||
protected Colors _colors;
|
||||
protected Vector _vector;
|
||||
|
||||
public Label() { }
|
||||
|
||||
public Label(Rectangle pos, string text, SpriteFont font, Colors colors, textAlign align = textAlign.centerCenter)
|
||||
{
|
||||
_pos = pos;
|
||||
_text = text;
|
||||
_font = font;
|
||||
_colors = colors;
|
||||
_align = align;
|
||||
OnTextChange();
|
||||
}
|
||||
|
||||
public Label(Vector vector, string text, SpriteFont font, Colors colors, textAlign align = textAlign.bottomRight)
|
||||
{
|
||||
_pos = new Rectangle(vector.X, vector.Y, 0, 0);
|
||||
_text = text;
|
||||
_font = font;
|
||||
_colors = colors;
|
||||
_align = align;
|
||||
OnTextChange();
|
||||
}
|
||||
|
||||
public override bool Contain(int x, int y)
|
||||
{
|
||||
bool isVector = (_pos.Height == 0 && _pos.Width == 0);
|
||||
if (isVector)
|
||||
{
|
||||
return new Rectangle(_vector.X, _vector.Y, (int)_font.MeasureString(_text).X, (int)_font.MeasureString(_text).Y).Contains(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.Contain(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnTextChange()
|
||||
{
|
||||
bool isVector = (_pos.Height == 0 && _pos.Width == 0);
|
||||
switch (_align)
|
||||
{
|
||||
case textAlign.topLeft:
|
||||
if (isVector)
|
||||
{
|
||||
_vector = new Vector(_pos.X - (int)_font.MeasureString(_text).X, _pos.Y - (int)_font.MeasureString(_text).Y);
|
||||
}
|
||||
else {
|
||||
_vector = new Vector(_pos.X, _pos.Y);
|
||||
}
|
||||
break;
|
||||
|
||||
case textAlign.topCenter:
|
||||
if (isVector)
|
||||
{
|
||||
_vector = new Vector(_pos.X - (int)_font.MeasureString(_text).X / 2, _pos.Y - (int)_font.MeasureString(_text).Y);
|
||||
}
|
||||
else {
|
||||
_vector = new Vector(_pos.X + _pos.Width / 2 - (int)_font.MeasureString(_text).X / 2, _pos.Y);
|
||||
}
|
||||
break;
|
||||
|
||||
case textAlign.topRight:
|
||||
if (isVector)
|
||||
{
|
||||
_vector = new Vector(_pos.X, _pos.Y - (int)_font.MeasureString(_text).Y);
|
||||
}
|
||||
else {
|
||||
_vector = new Vector(_pos.X + _pos.Width - (int)_font.MeasureString(_text).X, _pos.Y);
|
||||
}
|
||||
break;
|
||||
|
||||
case textAlign.centerLeft:
|
||||
if (isVector)
|
||||
{
|
||||
_vector = new Vector(_pos.X - (int)_font.MeasureString(_text).X, _pos.Y - (int)_font.MeasureString(_text).Y / 2);
|
||||
}
|
||||
else {
|
||||
_vector = new Vector(_pos.X, _pos.Y + _pos.Height / 2 - (int)_font.MeasureString(_text).Y / 2);
|
||||
}
|
||||
break;
|
||||
|
||||
case textAlign.centerCenter:
|
||||
if (isVector)
|
||||
{
|
||||
_vector = new Vector(_pos.X - (int)_font.MeasureString(_text).X / 2, _pos.Y - (int)_font.MeasureString(_text).Y / 2);
|
||||
}
|
||||
else {
|
||||
_vector = new Vector(_pos.X + _pos.Width / 2 - (int)_font.MeasureString(_text).X / 2, _pos.Y + _pos.Height / 2 - (int)_font.MeasureString(_text).Y / 2);
|
||||
}
|
||||
break;
|
||||
|
||||
case textAlign.centerRight:
|
||||
if (isVector)
|
||||
{
|
||||
_vector = new Vector(_pos.X, _pos.Y - (int)_font.MeasureString(_text).Y / 2);
|
||||
}
|
||||
else {
|
||||
_vector = new Vector(_pos.X + _pos.Width - (int)_font.MeasureString(_text).X, _pos.Y + _pos.Height / 2 - (int)_font.MeasureString(_text).Y / 2);
|
||||
}
|
||||
break;
|
||||
|
||||
case textAlign.bottomLeft:
|
||||
if (isVector)
|
||||
{
|
||||
_vector = new Vector(_pos.X - (int)_font.MeasureString(_text).X, _pos.Y);
|
||||
}
|
||||
else {
|
||||
_vector = new Vector(_pos.X, _pos.Y + _pos.Height - (int)_font.MeasureString(_text).Y);
|
||||
}
|
||||
break;
|
||||
|
||||
case textAlign.bottomCenter:
|
||||
if (isVector)
|
||||
{
|
||||
_vector = new Vector(_pos.X - (int)_font.MeasureString(_text).X / 2, _pos.Y);
|
||||
}
|
||||
else {
|
||||
_vector = new Vector(_pos.X + _pos.Width / 2 - (int)_font.MeasureString(_text).X / 2, _pos.Y + _pos.Height - (int)_font.MeasureString(_text).Y);
|
||||
}
|
||||
break;
|
||||
|
||||
case textAlign.bottomRight:
|
||||
if (isVector)
|
||||
{
|
||||
_vector = new Vector(_pos.X, _pos.Y);
|
||||
}
|
||||
else {
|
||||
_vector = new Vector(_pos.X + _pos.Width - (int)_font.MeasureString(_text).X, _pos.Y + _pos.Height - (int)_font.MeasureString(_text).Y);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Color color = _isFocus ? _colors._focus : (_isHover ? _colors._hover : _colors._normal);
|
||||
spriteBatch.DrawString(_font, _text, new Vector2(_vector.X, _vector.Y), color);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public struct Mouse
|
||||
{
|
||||
public bool leftPress;
|
||||
public bool leftRelease;
|
||||
public bool rightPress;
|
||||
public bool rightRelease;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{7A776114-65C0-4443-82A6-0A16425A8398}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MyMonoGame</RootNamespace>
|
||||
<AssemblyName>MyMonoGame</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MonoGame.Framework, Version=3.5.1.1679, Culture=neutral, processorArchitecture=MSIL" />
|
||||
<Reference Include="NVorbis, Version=0.8.4.0, Culture=neutral, processorArchitecture=MSIL" />
|
||||
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Box.cs" />
|
||||
<Compile Include="BoxButton.cs" />
|
||||
<Compile Include="BoxLabel.cs" />
|
||||
<Compile Include="BoxLabelButton.cs" />
|
||||
<Compile Include="boxSprites.cs" />
|
||||
<Compile Include="Button.cs" />
|
||||
<Compile Include="Colors.cs" />
|
||||
<Compile Include="Element.cs" />
|
||||
<Compile Include="KeyString.cs" />
|
||||
<Compile Include="Label.cs" />
|
||||
<Compile Include="Mouse.cs" />
|
||||
<Compile Include="TextField.cs" />
|
||||
<Compile Include="Texture.cs" />
|
||||
<Compile Include="TexturedButton.cs" />
|
||||
<Compile Include="Vector.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Les informations générales relatives à un assembly dépendent de
|
||||
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
|
||||
// associées à un assembly.
|
||||
[assembly: AssemblyTitle("MyMonoGameGUI")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MyMonoGameGUI")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
|
||||
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
|
||||
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
|
||||
[assembly: Guid("7a776114-65c0-4443-82a6-0a16425a8398")]
|
||||
|
||||
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
|
||||
//
|
||||
// Version principale
|
||||
// Version secondaire
|
||||
// Numéro de build
|
||||
// Révision
|
||||
//
|
||||
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
|
||||
// en utilisant '*', comme indiqué ci-dessous :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.1.1")]
|
||||
[assembly: AssemblyFileVersion("1.0.1.1")]
|
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class TextField : Label
|
||||
{
|
||||
protected string _placeHolder;
|
||||
protected string _value;
|
||||
public string output { get { return _value; } set { _value = value; _text = (_placeHolder != null && _value == null) ? _placeHolder : _value; OnTextChange(); } }
|
||||
protected event EventHandler _validate;
|
||||
|
||||
public TextField(Rectangle pos, string value, SpriteFont font, Colors colors, textAlign align = textAlign.centerCenter, string placeHolder = null, EventHandler validate = null)
|
||||
{
|
||||
_value = value;
|
||||
_font = font;
|
||||
_colors = colors;
|
||||
_align = align;
|
||||
_placeHolder = placeHolder;
|
||||
_validate = validate;
|
||||
_text = (placeHolder != null && value == null) ? placeHolder : value;
|
||||
OnTextChange();
|
||||
}
|
||||
|
||||
public TextField(Vector vector, string value, SpriteFont font, Colors colors, textAlign align = textAlign.bottomRight, string placeHolder = null, EventHandler validate = null)
|
||||
{
|
||||
_pos = new Rectangle(vector.X, vector.Y, 0, 0);
|
||||
_value = value;
|
||||
_font = font;
|
||||
_colors = colors;
|
||||
_align = align;
|
||||
_placeHolder = placeHolder;
|
||||
_validate = validate;
|
||||
_text = (placeHolder != null && value == null) ? placeHolder : value;
|
||||
OnTextChange();
|
||||
}
|
||||
|
||||
public override void Update(int x, int y, Mouse mouse, Keys key, bool isMaj, EventArgs e)
|
||||
{
|
||||
base.Update(x, y, mouse, key, isMaj, e);
|
||||
|
||||
if (_isFocus)
|
||||
{
|
||||
//Only QWERTY support wait monogame 4.6 (https://github.com/MonoGame/MonoGame/issues/3836)
|
||||
switch (key)
|
||||
{
|
||||
case Keys.Back:
|
||||
if (_value.Length > 0) { _value = _value.Remove(_value.Length - 1); _text = (_placeHolder != null && _value == null) ? _placeHolder : _value; OnTextChange(); }
|
||||
break;
|
||||
|
||||
case Keys.Enter:
|
||||
Validate(this, e);
|
||||
break;
|
||||
|
||||
default:
|
||||
char ch;
|
||||
if (KeyString.KeyToString(key, isMaj, out ch)) { _value += ch; _text = (_placeHolder != null && _value == null) ? _placeHolder : _value; OnTextChange(); }
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Validate(object sender, EventArgs e)
|
||||
{
|
||||
if (_validate != null)
|
||||
{
|
||||
_validate.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class Texture : Element
|
||||
{
|
||||
protected Colors _colors;
|
||||
protected Texture2D _sprite;
|
||||
|
||||
public Texture() { }
|
||||
|
||||
public Texture(Rectangle pos, Texture2D sprite, Colors colors)
|
||||
{
|
||||
_pos = pos;
|
||||
_sprite = sprite;
|
||||
_colors = colors;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Color backColor = _isFocus ? _colors._focus : (_isHover ? _colors._hover : _colors._normal);
|
||||
spriteBatch.Draw(_sprite, _pos, backColor);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public class TexturedButton : Texture
|
||||
{
|
||||
Button button;
|
||||
private int _unFocusTime;
|
||||
|
||||
public TexturedButton(Rectangle pos, Texture2D sprite, Colors colors, EventHandler click = null)
|
||||
{
|
||||
_pos = pos;
|
||||
_sprite = sprite;
|
||||
_colors = colors;
|
||||
button = new Button(pos, click);
|
||||
}
|
||||
|
||||
public override void Update(int x, int y, Mouse mouse, Keys key, bool isMaj, EventArgs e)
|
||||
{
|
||||
base.Update(x, y, mouse, key, isMaj, e);
|
||||
button.Update(x, y, mouse, key, isMaj, e);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (_isFocus)
|
||||
{
|
||||
if (_unFocusTime < 10)
|
||||
{
|
||||
_unFocusTime++;
|
||||
}
|
||||
else {
|
||||
_isFocus = false;
|
||||
_unFocusTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
button.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
namespace MyMonoGame
|
||||
{
|
||||
public class Vector
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
|
||||
public Vector(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace MyMonoGame.GUI
|
||||
{
|
||||
public struct boxSprites
|
||||
{
|
||||
public Texture2D topLeft;
|
||||
public Texture2D topCenter;
|
||||
public Texture2D topRight;
|
||||
public Texture2D centerLeft;
|
||||
public Texture2D centerCenter;
|
||||
public Texture2D centerRight;
|
||||
public Texture2D bottomLeft;
|
||||
public Texture2D bottomCenter;
|
||||
public Texture2D bottomRight;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue