MyMonoGame devient une librairie externe
https://github.com/sheychen290/MyMonoGame
This commit is contained in:
parent
2599564de5
commit
26ecdf4754
|
@ -1,43 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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, ".");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
public struct Mouse
|
||||
{
|
||||
public bool leftPress;
|
||||
public bool leftRelease;
|
||||
public bool rightPress;
|
||||
public bool rightRelease;
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.GUI
|
||||
{
|
||||
public class Vector
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
|
||||
public Vector(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Galactic_Colors_Control_GUI.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;
|
||||
}
|
||||
}
|
|
@ -39,26 +39,14 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Game1.cs" />
|
||||
<Compile Include="GUI\Box.cs" />
|
||||
<Compile Include="GUI\BoxButton.cs" />
|
||||
<Compile Include="GUI\BoxLabel.cs" />
|
||||
<Compile Include="GUI\BoxLabelButton.cs" />
|
||||
<Compile Include="GUI\Button.cs" />
|
||||
<Compile Include="GUI\boxSprites.cs" />
|
||||
<Compile Include="GUI\Colors.cs" />
|
||||
<Compile Include="GUI\KeyString.cs" />
|
||||
<Compile Include="GUI\Label.cs" />
|
||||
<Compile Include="GUI\Mouse.cs" />
|
||||
<Compile Include="GUI\TextField.cs" />
|
||||
<Compile Include="GUI\Texture.cs" />
|
||||
<Compile Include="GUI\TexturedButton.cs" />
|
||||
<Compile Include="GUI\Element.cs" />
|
||||
<Compile Include="GUI\Vector.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MyMonoGame">
|
||||
<HintPath>..\..\MonoGame\MyMonoGameGUI\MyMonoGameGUI\bin\Release\MyMonoGame.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OpenTK">
|
||||
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
@ -28,9 +28,9 @@ namespace Galactic_Colors_Control_GUI
|
|||
|
||||
internal static Texture2D nullSprite;
|
||||
private Texture2D[] pointerSprites = new Texture2D[1];
|
||||
private GUI.boxSprites[] buttonsSprites = new GUI.boxSprites[1];
|
||||
private MyMonoGame.GUI.boxSprites[] buttonsSprites = new MyMonoGame.GUI.boxSprites[1];
|
||||
|
||||
private List<GUI.Element> elements = new List<GUI.Element>();
|
||||
private List<MyMonoGame.GUI.Element> elements = new List<MyMonoGame.GUI.Element>();
|
||||
|
||||
Version version;
|
||||
|
||||
|
@ -72,7 +72,7 @@ namespace Galactic_Colors_Control_GUI
|
|||
nullSprite = new Texture2D(GraphicsDevice, 1, 1);
|
||||
nullSprite.SetData(new Color[1 * 1] { Color.White });
|
||||
|
||||
GUI.KeyString.InitializeKeyString();
|
||||
MyMonoGame.KeyString.InitializeKeyString();
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ namespace Galactic_Colors_Control_GUI
|
|||
newState = Mouse.GetState();
|
||||
mouseX = newState.X;
|
||||
mouseY = newState.Y;
|
||||
GUI.Mouse nowState;
|
||||
MyMonoGame.GUI.Mouse nowState;
|
||||
nowState.leftPress = (oldState.LeftButton == ButtonState.Released && newState.LeftButton == ButtonState.Pressed);
|
||||
nowState.leftRelease = (oldState.LeftButton == ButtonState.Pressed && newState.LeftButton == ButtonState.Released);
|
||||
nowState.rightPress = (oldState.LeftButton == ButtonState.Released && newState.LeftButton == ButtonState.Pressed);
|
||||
|
@ -196,7 +196,7 @@ namespace Galactic_Colors_Control_GUI
|
|||
if (IsActive)
|
||||
{
|
||||
EventArgs e = new EventArgs();
|
||||
foreach(GUI.Element element in elements.ToArray())
|
||||
foreach(MyMonoGame.GUI.Element element in elements.ToArray())
|
||||
{
|
||||
element.Update(mouseX, mouseY, nowState, key, Keyboard.GetState().IsKeyDown(Keys.LeftShift) || Keyboard.GetState().IsKeyDown(Keys.RightShift),e);
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ namespace Galactic_Colors_Control_GUI
|
|||
}
|
||||
*/
|
||||
|
||||
foreach (GUI.Element element in elements)
|
||||
foreach (MyMonoGame.GUI.Element element in elements)
|
||||
{
|
||||
element.Draw(spriteBatch);
|
||||
}
|
||||
|
@ -319,10 +319,10 @@ namespace Galactic_Colors_Control_GUI
|
|||
switch (newGameStatus)
|
||||
{
|
||||
case GameStatus.Home:
|
||||
elements.Add(new GUI.Label(new GUI.Vector(ScreenWidth / 2, ScreenHeight / 4), "Galactic Colors Control", titleFont, new GUI.Colors(Color.DarkRed, Color.Green), GUI.Label.textAlign.centerCenter));
|
||||
elements.Add(new GUI.TextField(new GUI.Vector(ScreenWidth / 2, ScreenHeight / 2), null, basicFont, new GUI.Colors(Color.White, Color.WhiteSmoke, Color.LightGray), GUI.Label.textAlign.centerCenter, "Server address", ConnectClick));
|
||||
//elements.Add(new GUI.BoxButton(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight * 3 / 4, 200, 40), buttonsSprites[0], new GUI.Colors(Color.White, Color.LightGray, Color.DarkGray), ConnectClick));
|
||||
elements.Add(new GUI.BoxLabelButton(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight * 3 / 4,200,40),buttonsSprites[0], new GUI.Colors(Color.White, Color.LightGray, Color.DarkGray), "Connect", basicFont, new GUI.Colors(Color.Black, Color.Black, Color.White), GUI.Label.textAlign.centerCenter, ConnectClick));
|
||||
elements.Add(new MyMonoGame.GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4), "Galactic Colors Control", titleFont, new MyMonoGame.Colors(Color.DarkRed, Color.Green), MyMonoGame.GUI.Label.textAlign.centerCenter));
|
||||
elements.Add(new MyMonoGame.GUI.TextField(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 2), null, basicFont, new MyMonoGame.Colors(Color.White, Color.WhiteSmoke, Color.LightGray), MyMonoGame.GUI.Label.textAlign.centerCenter, "Server address", ConnectClick));
|
||||
//elements.Add(new MyMonoGame.GUI.BoxButton(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight * 3 / 4, 200, 40), buttonsSprites[0], new MyMonoGame.GUI.Colors(Color.White, Color.LightGray, Color.DarkGray), ConnectClick));
|
||||
elements.Add(new MyMonoGame.GUI.BoxLabelButton(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight * 3 / 4,200,40),buttonsSprites[0], new MyMonoGame.Colors(Color.White, Color.LightGray, Color.DarkGray), "Connect", basicFont, new MyMonoGame.Colors(Color.Black, Color.Black, Color.White), MyMonoGame.GUI.Label.textAlign.centerCenter, ConnectClick));
|
||||
break;
|
||||
|
||||
case GameStatus.Options:
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Galactic_Colors_Control_GUI
|
|||
{
|
||||
static class Utilities
|
||||
{
|
||||
static public void SpriteFromPng(string path, ref Texture2D sprite, GraphicsDevice graphics )
|
||||
static public void SpriteFromPng(string path, ref Texture2D sprite, GraphicsDevice graphics)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
|
@ -21,7 +21,8 @@ namespace Galactic_Colors_Control_GUI
|
|||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) {
|
||||
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
sound = SoundEffect.FromStream(fileStream);
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue