1
0
Fork 0

Unity like

This commit is contained in:
sheychen 2016-10-16 18:04:06 +02:00
parent 4fbd3871c6
commit e532dc13fa
3 changed files with 127 additions and 96 deletions

View File

@ -122,21 +122,21 @@ namespace Exemple
System.Diagnostics.Process.Start("https://github.com/search?q=" + Github);
Github = null;
}
showAbout = GUI.ButtonBoxLabel(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight * 3 / 4 + 50, 200, 40), boxSprite, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.DarkGray), "About", basicFont, new MyMonoGame.Colors(Color.Black, Color.Green));
showAbout = GUI.Button(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight * 3 / 4 + 50, 200, 40), boxSprite, "About", basicFont, null ,new MyMonoGame.Colors(Color.Black, Color.Green));
}
else
{
GUI.Box(new Rectangle(200, 100, ScreenWidth - 400, ScreenHeight - 200), boxSprite, new MyMonoGame.Colors(Color.LightGray, Color.White));
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4), "By Sheychen", basicFont, new MyMonoGame.Colors(Color.Red, Color.OrangeRed),Manager.textAlign.centerCenter);
if(GUI.ButtonBoxLabel(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight / 2 - 100, 200, 40), boxSprite, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.DarkGray), "My website", basicFont, new MyMonoGame.Colors(Color.Black, Color.Black, Color.White)))
if(GUI.Button(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight / 2 - 100, 200, 40), boxSprite, "My website", basicFont))
{
System.Diagnostics.Process.Start("https://sheychen.shost.ca");
}
if(GUI.ButtonBoxLabel(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight / 2 - 50, 200, 40), boxSprite, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.DarkGray), "Show on GitHub", basicFont, new MyMonoGame.Colors(Color.Black, Color.Black, Color.White)))
if(GUI.Button(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight / 2 - 50, 200, 40), boxSprite, "Show on GitHub", basicFont))
{
System.Diagnostics.Process.Start("https://github.com/sheychen290/MyMonoGame");
}
showAbout = !GUI.ButtonBoxLabel(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight / 2, 200, 40), boxSprite, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.DarkGray), "Back", basicFont, new MyMonoGame.Colors(Color.Black, Color.Black, Color.White));
showAbout = !GUI.Button(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight / 2, 200, 40), boxSprite, "Back", basicFont);
}
spriteBatch.DrawString(basicFont, "\\", new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Color.Black);

View File

@ -23,6 +23,9 @@ namespace MyMonoGame.GUI
public enum textAlign { topLeft, topCenter, topRight, centerLeft, centerCenter, centerRight, bottomLeft, bottomCenter, bottomRight };
private SpriteBatch spriteBatch;
public Colors backgroundColors = new Colors(Color.White, Color.LightGray, Color.Gray);
public Colors textColors = new Colors(Color.Black, Color.Black, Color.White);
public void Initialise()
{
Utilities.KeyString.InitializeKeyString();
@ -190,8 +193,123 @@ namespace MyMonoGame.GUI
return (placeHolder != null && (value == null || value == "")) ? placeHolder : value;
}
public bool TextField(Rectangle pos, ref string value, SpriteFont font, Colors colors, textAlign align = textAlign.centerCenter, string placeHolder = null)
public void RenderBox(Rectangle pos, boxSprites backSprites, Color backColor)
{
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);
}
public void ResetFocus()
{
lastFocusX = short.MinValue;
lastFocusY = short.MinValue;
}
/*================================================================================================================================================*/
public void Box(Rectangle pos, boxSprites backSprites, Colors colors = null)
{
if(colors == null) { colors = backgroundColors; }
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
RenderBox(pos, backSprites, backColor);
}
public bool Button(Rectangle pos)
{
Status status = GetStatus(pos);
return status == Status.Active;
}
public bool Button(Rectangle pos, Texture2D texture, Colors colors = null)
{
if (colors == null) { colors = backgroundColors; }
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
spriteBatch.Draw(texture, pos, backColor);
return status == Status.Active;
}
public bool Button(Rectangle pos, boxSprites backSprites, Colors colors = null)
{
if (colors == null) { colors = backgroundColors; }
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
RenderBox(pos, backSprites, backColor);
return status == Status.Active;
}
public bool Button(Rectangle pos, string text, SpriteFont font, Colors colors = null, textAlign align = textAlign.centerCenter)
{
Status status = GetStatus(pos);
Label(pos, text, font, colors, align);
return status == Status.Active;
}
public bool Button(Vector vector, string text, SpriteFont font, Colors colors = null, textAlign align = textAlign.bottomRight)
{
Vector v = GetLabelPos(new Rectangle(vector.X, vector.Y, 0, 0), align, font, text);
Status status = GetStatus(new Rectangle(v.X, v.Y, (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y));
Label(vector, text, font, colors, align);
return status == Status.Active;
}
public bool Button(Rectangle pos, boxSprites backSprites, string text, SpriteFont font, Colors colors = null, Colors textcolors = null, textAlign align = textAlign.centerCenter)
{
if (colors == null) { colors = backgroundColors; }
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
RenderBox(pos, backSprites, backColor);
Label(pos, text, font, textcolors, align);
return status == Status.Active;
}
public void Texture(Rectangle pos, Texture2D texture, Colors colors = null)
{
if (colors == null) { colors = backgroundColors; }
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
spriteBatch.Draw(texture, pos, backColor);
}
public void Label(Rectangle pos, string text, SpriteFont font, Colors colors = null, textAlign align = textAlign.centerCenter)
{
if (colors == null) { colors = textColors; }
Vector v = GetLabelPos(pos, align, font, text);
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), backColor);
}
public void Label(Vector vector, string text, SpriteFont font, Colors colors = null, textAlign align = textAlign.bottomRight)
{
if (colors == null) { colors = textColors; }
Vector v = GetLabelPos(new Rectangle(vector.X, vector.Y, 0, 0), align, font, text);
Status status = GetStatus(new Rectangle(v.X, v.Y, (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y));
Color backColor = colors.Get(status);
spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), backColor);
}
public bool TextField(Rectangle pos, ref string value, SpriteFont font, Colors colors = null, textAlign align = textAlign.centerCenter, string placeHolder = null)
{
if (colors == null) { colors = textColors; }
string _text = fieldText(value, placeHolder);
Vector v = GetLabelPos(pos, align, font, _text);
Status status = GetStatus(pos);
@ -226,8 +344,9 @@ namespace MyMonoGame.GUI
return nowKey == Keys.Enter;
}
public bool TextField(Vector vector, ref string value, SpriteFont font, Colors colors, textAlign align = textAlign.bottomRight, string placeHolder = null)
public bool TextField(Vector vector, ref string value, SpriteFont font, Colors colors = null, textAlign align = textAlign.bottomRight, string placeHolder = null)
{
if (colors == null) { colors = textColors; }
string _text = fieldText(value, placeHolder);
Vector v = GetLabelPos(new Rectangle(vector.X, vector.Y, 0, 0), align, font, _text);
Status status = GetStatus(new Rectangle(v.X, v.Y, (int)font.MeasureString(_text).X, (int)font.MeasureString(_text).Y));
@ -261,93 +380,5 @@ namespace MyMonoGame.GUI
spriteBatch.DrawString(font, _text, new Vector2(v.X, v.Y), backColor);
return nowKey == Keys.Enter;
}
public void Label(Rectangle pos, string text, SpriteFont font, Colors colors, textAlign align = textAlign.centerCenter)
{
Vector v = GetLabelPos(pos, align, font, text);
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), backColor);
}
public void ResetFocus()
{
lastFocusX = short.MinValue;
lastFocusY = short.MinValue;
}
public void Label(Vector vector, string text, SpriteFont font, Colors colors, textAlign align = textAlign.bottomRight)
{
Vector v = GetLabelPos(new Rectangle(vector.X, vector.Y, 0,0), align, font, text);
Status status = GetStatus(new Rectangle(v.X, v.Y, (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y));
Color backColor = colors.Get(status);
spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), backColor);
}
public void Texture(Rectangle pos, Texture2D texture, Colors colors)
{
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
spriteBatch.Draw(texture, pos, backColor);
}
public bool ButtonTexture(Rectangle pos, Texture2D texture, Colors colors)
{
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
spriteBatch.Draw(texture, pos, backColor);
return status == Status.Active;
}
public bool Button(Rectangle pos)
{
Status status = GetStatus(pos);
return status == Status.Active;
}
public bool ButtonBoxLabel(Rectangle pos, boxSprites backSprites, Colors colors, string text, SpriteFont font, Colors textColors, textAlign align = textAlign.centerCenter)
{
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
RenderBox(pos, backSprites, backColor);
Label(pos, text, font, textColors, align);
return status == Status.Active;
}
public bool ButtonBox(Rectangle pos, boxSprites backSprites, Colors colors)
{
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
RenderBox(pos, backSprites, backColor);
return status == Status.Active;
}
public void Box(Rectangle pos, boxSprites backSprites, Colors colors)
{
Status status = GetStatus(pos);
Color backColor = colors.Get(status);
RenderBox(pos, backSprites, backColor);
}
public void RenderBox(Rectangle pos, boxSprites backSprites, Color backColor)
{
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);
}
}
}

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 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")]
[assembly: AssemblyVersion("1.0.2.1")]
[assembly: AssemblyFileVersion("1.0.2.1")]