1
0
Fork 0

Ajout des elements graphiques basiques

Nettoyage du ignore
This commit is contained in:
sheychen 2016-10-11 20:57:59 +02:00
parent 9108f24cf9
commit ba9d086ea8
28 changed files with 820 additions and 26 deletions

2
.gitignore vendored
View File

@ -209,4 +209,4 @@ FakesAssemblies/
# LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
ModelManifest.xml

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">
<!--
Modify this string to change the font that will be imported.
-->
<FontName>editundo</FontName>
<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
-->
<Size>16</Size>
<!--
Spacing is a float value, measured in pixels. Modify this value to change
the amount of spacing in between characters.
-->
<Spacing>0</Spacing>
<!--
UseKerning controls the layout of the font. If this value is true, kerning information
will be used when placing characters.
-->
<UseKerning>true</UseKerning>
<!--
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
and "Bold, Italic", and are case sensitive.
-->
<Style>Regular</Style>
<!--
If you uncomment this line, the default character will be substituted if you draw
or measure text that contains characters which were not included in the font.
-->
<!-- <DefaultCharacter>*</DefaultCharacter> -->
<!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
<CharacterRegion>
<Start>&#32;</Start>
<End>&#126;</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">
<!--
Modify this string to change the font that will be imported.
-->
<FontName>Tahoma</FontName>
<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
-->
<Size>8</Size>
<!--
Spacing is a float value, measured in pixels. Modify this value to change
the amount of spacing in between characters.
-->
<Spacing>0</Spacing>
<!--
UseKerning controls the layout of the font. If this value is true, kerning information
will be used when placing characters.
-->
<UseKerning>true</UseKerning>
<!--
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
and "Bold, Italic", and are case sensitive.
-->
<Style>Regular</Style>
<!--
If you uncomment this line, the default character will be substituted if you draw
or measure text that contains characters which were not included in the font.
-->
<!-- <DefaultCharacter>*</DefaultCharacter> -->
<!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
<CharacterRegion>
<Start>&#32;</Start>
<End>&#126;</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">
<!--
Modify this string to change the font that will be imported.
-->
<FontName>MV Boli</FontName>
<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
-->
<Size>50</Size>
<!--
Spacing is a float value, measured in pixels. Modify this value to change
the amount of spacing in between characters.
-->
<Spacing>0</Spacing>
<!--
UseKerning controls the layout of the font. If this value is true, kerning information
will be used when placing characters.
-->
<UseKerning>true</UseKerning>
<!--
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
and "Bold, Italic", and are case sensitive.
-->
<Style>Regular</Style>
<!--
If you uncomment this line, the default character will be substituted if you draw
or measure text that contains characters which were not included in the font.
-->
<!-- <DefaultCharacter>*</DefaultCharacter> -->
<!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
<CharacterRegion>
<Start>&#32;</Start>
<End>&#126;</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

View File

@ -0,0 +1,112 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace Galactic_Colors_Control_GUI.GUI
{
class Button : Element
{
protected string _text;
protected SpriteFont _font;
protected Color _backColor, _backColorHover, _backColorFocus, _textColor, _textColorHover, _textColorFocus;
protected event EventHandler _click;
Texture2D _backSprite;
public Button() { }
public Button(Rectangle pos, Color backColor, EventHandler click = null)
{
_pos = pos;
_backColor = backColor;
_backColorHover = backColor;
_backColorFocus = backColor;
_backSprite = Game1.nullSprite;
_click = click;
}
public Button(Rectangle pos, Color backColor, Color backColorHover, EventHandler click = null)
{
_pos = pos;
_backColor = backColor;
_backColorHover = backColorHover;
_backColorFocus = backColorHover;
_backSprite = Game1.nullSprite;
_click = click;
}
public Button(Rectangle pos, Color backColor, Color backColorHover, Color backColorFocus, EventHandler click = null)
{
_pos = pos;
_backColor = backColor;
_backColorHover = backColorHover;
_backColorFocus = backColorFocus;
_backSprite = Game1.nullSprite;
_click = click;
}
public Button(Rectangle pos, Color backColor, string text, SpriteFont font, Color textColor, EventHandler click = null)
{
_pos = pos;
_font = font;
_backColor = backColor;
_backColorHover = backColor;
_backColorFocus = backColor;
_textColor = textColor;
_textColorHover = textColor;
_textColorFocus = textColor;
_text = text;
_backSprite = Game1.nullSprite;
_click = click;
}
public Button(Rectangle pos, Color backColor, Color backColorHover, string text, SpriteFont font, Color textColor, Color textColorHover, EventHandler click = null)
{
_pos = pos;
_font = font;
_backColor = backColor;
_backColorHover = backColorHover;
_backColorFocus = backColorHover;
_textColor = textColor;
_textColorHover = textColorHover;
_textColorFocus = textColorHover;
_text = text;
_backSprite = Game1.nullSprite;
_click = click;
}
public Button(Rectangle pos, Color backColor, Color backColorHover, Color backColorFocus, string text, SpriteFont font, Color textColor, Color textColorHover, Color textColorFocus, EventHandler click = null)
{
_pos = pos;
_backColor = backColor;
_backColorHover = backColorHover;
_backColorFocus = backColorFocus;
_text = text;
_font = font;
_textColor = textColor;
_textColorHover = textColorHover;
_textColorFocus = textColorFocus;
_backSprite = Game1.nullSprite;
_click = click;
}
public override void Click(object sender, EventArgs e)
{
if (_click != null)
{
_click.Invoke(sender, e);
}
}
public override void Draw(SpriteBatch spriteBatch)
{
Color backColor = _isFocus ? _backColorFocus : (_isHover ? _backColorHover : _backColor);
spriteBatch.Draw(_backSprite, _pos, backColor);
if (_text != null)
{
Color textColor = _isFocus ? _textColorFocus : (_isHover ? _textColorHover : _textColor);
spriteBatch.DrawString(_font, _text, new Vector2(_pos.X + (_pos.Width - _font.MeasureString(_text).X) / 2, _pos.Y + (_pos.Height - _font.MeasureString(_text).Y) / 2), textColor);
}
if (_isFocus) { _isFocus = false; }
}
}
}

View File

@ -0,0 +1,44 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
namespace Galactic_Colors_Control_GUI.GUI
{
class Element
{
protected Rectangle _pos;
protected bool _isHover;
protected bool _isFocus;
public bool Contain(int x, int y)
{
return _pos.Contains(x, y);
}
public virtual void Draw(SpriteBatch spriteBatch)
{
}
public void Update(int x, int y, Mouse mouse, 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)
{
}
}
}

View File

@ -0,0 +1,75 @@
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
{
protected string _text;
protected SpriteFont _font;
protected Color _color, _colorHover, _colorFocus;
protected Vector _vector;
protected bool _center;
public Label() { }
public Label(Vector vector, string text, SpriteFont font, Color color, bool center = false)
{
_vector = vector;
_text = text;
_font = font;
_color = color;
_colorHover = color;
_colorFocus = color;
_center = center;
OnTextChange(text);
}
public Label(Vector vector, string text, SpriteFont font, Color color, Color colorHover, bool center = false)
{
_vector = vector;
_text = text;
_font = font;
_color = color;
_colorHover = colorHover;
_colorFocus = colorHover;
_center = center;
OnTextChange(text);
}
public Label(Vector vector, string text, SpriteFont font, Color color, Color colorHover, Color colorFocus, bool center = false)
{
_vector = vector;
_text = text;
_font = font;
_color = color;
_colorHover = colorHover;
_colorFocus = colorFocus;
_center = center;
OnTextChange(text);
}
protected void OnTextChange(string text)
{
if (_center)
{
_pos = new Rectangle(_vector.X - (int)_font.MeasureString(text).X / 2, _vector.Y - (int)_font.MeasureString(text).Y / 2, (int)_font.MeasureString(text).X, (int)_font.MeasureString(text).Y);
}
else
{
_pos = new Rectangle(_vector.X, _vector.Y, (int)_font.MeasureString(text).X, (int)_font.MeasureString(text).Y);
}
}
public override void Draw(SpriteBatch spriteBatch)
{
Color color = _isFocus ? _colorFocus : (_isHover ? _colorHover : _color);
spriteBatch.DrawString(_font, _text, new Vector2(_pos.X, _pos.Y), color);
}
}
}

View File

@ -0,0 +1,16 @@
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;
}
}

View File

@ -0,0 +1,113 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace Galactic_Colors_Control_GUI.GUI
{
class TexturedButton : Button
{
buttonSprites _backSprites;
public TexturedButton(Rectangle pos, buttonSprites backSprites, Color backColor, EventHandler click = null)
{
_pos = pos;
_backSprites = backSprites;
_backColor = backColor;
_backColorHover = backColor;
_backColorFocus = backColor;
_click += click;
}
public TexturedButton(Rectangle pos, buttonSprites backSprites, Color backColor, Color backColorHover, EventHandler click = null)
{
_pos = pos;
_backSprites = backSprites;
_backColor = backColor;
_backColorHover = backColorHover;
_backColorFocus = backColorHover;
_click += click;
}
public TexturedButton(Rectangle pos, buttonSprites backSprites, Color backColor, Color backColorHover, Color backColorFocus, EventHandler click = null)
{
_pos = pos;
_backSprites = backSprites;
_backColor = backColor;
_backColorHover = backColorHover;
_backColorFocus = backColorFocus;
_click += click;
}
public TexturedButton(Rectangle pos, buttonSprites backSprites, Color backColor, string text, SpriteFont font, Color textColor, EventHandler click = null)
{
_pos = pos;
_font = font;
_backSprites = backSprites;
_backColor = backColor;
_textColor = textColor;
_textColorHover = textColor;
_textColorFocus = textColor;
_text = text;
_click += click;
}
public TexturedButton(Rectangle pos, buttonSprites backSprites, Color backColor, Color backColorHover, string text, SpriteFont font, Color textColor, Color textColorHover, EventHandler click = null)
{
_pos = pos;
_font = font;
_backSprites = backSprites;
_backColor = backColor;
_backColorHover = backColorHover;
_backColorFocus = backColorHover;
_textColor = textColor;
_textColorHover = textColorHover;
_textColorFocus = textColorHover;
_text = text;
_click += click;
}
public TexturedButton(Rectangle pos, buttonSprites backSprites, Color backColor, Color backColorHover, Color backColorFocus, string text, SpriteFont font, Color textColor, Color textColorHover, Color textColorFocus, EventHandler click = null)
{
_pos = pos;
_backSprites = backSprites;
_backColor = backColor;
_backColorHover = backColorHover;
_backColorFocus = backColorFocus;
_text = text;
_font = font;
_textColor = textColor;
_textColorHover = textColorHover;
_textColorFocus = textColorFocus;
_click += click;
}
public override void Draw(SpriteBatch spriteBatch)
{
Color backColor = _isFocus ? _backColorFocus : (_isHover ? _backColorHover : _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);
if (_text != null)
{
Color textColor = _isFocus ? _textColorFocus : (_isHover ? _textColorHover : _textColor);
spriteBatch.DrawString(_font, _text, new Vector2(_pos.X + (_pos.Width - _font.MeasureString(_text).X) / 2, _pos.Y + (_pos.Height - _font.MeasureString(_text).Y) / 2), textColor);
}
if (_isFocus) { _isFocus = false; }
}
}
}

View File

@ -0,0 +1,20 @@
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;
}
}
}

View File

@ -0,0 +1,17 @@
using Microsoft.Xna.Framework.Graphics;
namespace Galactic_Colors_Control_GUI.GUI
{
public struct buttonSprites
{
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;
}
}

View File

@ -39,8 +39,16 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Game1.cs" />
<Compile Include="GUI\Button.cs" />
<Compile Include="GUI\buttonSprites.cs" />
<Compile Include="GUI\Label.cs" />
<Compile Include="GUI\Mouse.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="OpenTK">
@ -57,6 +65,33 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Icon.ico" />
<Content Include="Content\Textures\Hub\Buttons\0\topLeft.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Hub\Buttons\0\topCenter.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Hub\Buttons\0\topRight.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Hub\Buttons\0\centerLeft.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Hub\Buttons\0\centerCenter.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Hub\Buttons\0\centerRight.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Hub\Buttons\0\bottomLeft.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Hub\Buttons\0\bottomCenter.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Hub\Buttons\0\bottomRight.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\Hub\pointer0.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -67,6 +102,7 @@
<ItemGroup>
<MonoGameContentReference Include="Content\Content.mgcb" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -4,7 +4,9 @@ using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace Galactic_Colors_Control_GUI
@ -24,8 +26,11 @@ namespace Galactic_Colors_Control_GUI
private SpriteFont basicFont;
private SpriteFont titleFont;
private Texture2D nullSprite;
internal static Texture2D nullSprite;
private Texture2D[] pointerSprites = new Texture2D[1];
private GUI.buttonSprites[] buttonsSprites = new GUI.buttonSprites[1];
private List<GUI.Element> elements = new List<GUI.Element>();
Version version;
@ -33,18 +38,22 @@ namespace Galactic_Colors_Control_GUI
private MouseState newState;
private int mouseX;
private int mouseY;
private bool haveOverButton = false;
private Keys[] oldKeys;
private Keys[] newKeys;
private string skinName;
private enum GameStatus { Home, Options, Game, Pause, End, Thanks }
private GameStatus gameStatus;
private int ScreenWidth = 1080;
private int ScreenHeight = 720;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
graphics.PreferredBackBufferWidth = ScreenWidth;
graphics.PreferredBackBufferHeight = ScreenHeight;
graphics.IsFullScreen = false;
graphics.ApplyChanges();
Content.RootDirectory = "Content";
@ -62,10 +71,22 @@ namespace Galactic_Colors_Control_GUI
version = Assembly.GetEntryAssembly().GetName().Version;
nullSprite = new Texture2D(GraphicsDevice, 1, 1);
nullSprite.SetData(new Color[1 * 1] { Color.White });
base.Initialize();
}
// TODO : remove this
private void AddRandom(object sender, EventArgs e)
{
Random rand = new Random();
elements.Add(new GUI.Button(new Rectangle(rand.Next(0, ScreenHeight - 20), rand.Next(0, ScreenWidth - 20), 20, 20), Color.Black, Color.DarkSlateGray, Color.SlateGray, RemoveThis));
}
// TODO : remove this
private void RemoveThis(object sender, EventArgs e)
{
elements.Remove(sender as GUI.Element);
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
@ -75,34 +96,73 @@ namespace Galactic_Colors_Control_GUI
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
//effects[0] = content.Load<SoundEffect>("Sounds/alert");
//effects[1] = content.Load<SoundEffect>("Sounds/bip");
//effects[2] = content.Load<SoundEffect>("Sounds/change");
//effects[3] = content.Load<SoundEffect>("Sounds/valid");
//Need OpenAL Update for Windows 10 at least
effects[0] = content.Load<SoundEffect>("Sounds/alert");
effects[1] = content.Load<SoundEffect>("Sounds/bip");
effects[2] = content.Load<SoundEffect>("Sounds/change");
effects[3] = content.Load<SoundEffect>("Sounds/valid");
smallFont = content.Load<SpriteFont>("Fonts/small");
basicFont = content.Load<SpriteFont>("Fonts/basic");
titleFont = content.Load<SpriteFont>("Fonts/title");
for (int i = 0; i < pointerSprites.Length; i++) {
Console.WriteLine("Load pointer" + i);
pointerSprites[i] = content.Load<Texture2D>("Textures/Hub/pointer" + i);
}
for (int i = 0; i < buttonsSprites.Length; i++)
{
buttonsSprites[i].topLeft = content.Load<Texture2D>("Textures/Hub/Buttons/" + i + "/topLeft");
buttonsSprites[i].topCenter = content.Load<Texture2D>("Textures/Hub/Buttons/" + i + "/topCenter");
buttonsSprites[i].topRight = content.Load<Texture2D>("Textures/Hub/Buttons/" + i + "/topRight");
buttonsSprites[i].centerLeft = content.Load<Texture2D>("Textures/Hub/Buttons/" + i + "/centerLeft");
buttonsSprites[i].centerCenter = content.Load<Texture2D>("Textures/Hub/Buttons/" + i + "/centerCenter");
buttonsSprites[i].centerRight = content.Load<Texture2D>("Textures/Hub/Buttons/" + i + "/centerRight");
buttonsSprites[i].bottomLeft = content.Load<Texture2D>("Textures/Hub/Buttons/" + i + "/bottomLeft");
buttonsSprites[i].bottomCenter = content.Load<Texture2D>("Textures/Hub/Buttons/" + i + "/bottomCenter");
buttonsSprites[i].bottomRight = content.Load<Texture2D>("Textures/Hub/Buttons/" + i + "/bottomRight");
}
if (Directory.Exists("Skin/" + skinName))
{
if (File.Exists("Skin/" + skinName + "/Sounds/alert.mp3")) using (FileStream fileStream = new FileStream("Skin/" + skinName + "/Sounds/alert.mp3", FileMode.Open)) { effects[0] = SoundEffect.FromStream(fileStream); }
if (File.Exists("Skin/" + skinName + "/Sounds/bip.mp3")) using (FileStream fileStream = new FileStream("Skin/" + skinName + "/Sounds/bip.mp3", FileMode.Open)) { effects[1] = SoundEffect.FromStream(fileStream); }
if (File.Exists("Skin/" + skinName + "/Sounds/change.mp3")) using (FileStream fileStream = new FileStream("Skin/" + skinName + "/Sounds/change.mp3", FileMode.Open)) { effects[2] = SoundEffect.FromStream(fileStream); }
if (File.Exists("Skin/" + skinName + "/Sounds/valid.mp3")) using (FileStream fileStream = new FileStream("Skin/" + skinName + "/Sounds/valid.mp3", FileMode.Open)) { effects[3] = SoundEffect.FromStream(fileStream); }
for (int i = 0; i < pointerSprites.Length; i++)
if (Directory.Exists("Skin/" + skinName + "/Sounds"))
{
if (File.Exists("Skin/" + skinName + "/Textures/Hub/pointer" + i + ".png")) using (FileStream fileStream = new FileStream("Skin/" + skinName + "/Textures/Hub/pointer" + i + ".png", FileMode.Open)) { pointerSprites[i] = Texture2D.FromStream(GraphicsDevice, fileStream); }
Utilities.SoundFromMp3("Skin/" + skinName + "/Sounds/alert.mp3", ref effects[0]);
Utilities.SoundFromMp3("Skin/" + skinName + "/Sounds/bip.mp3", ref effects[1]);
Utilities.SoundFromMp3("Skin/" + skinName + "/Sounds/change.mp3", ref effects[2]);
Utilities.SoundFromMp3("Skin/" + skinName + "/Sounds/valid.mp3", ref effects[3]);
}
if (Directory.Exists("Skin/" + skinName + "/Textures"))
{
if (Directory.Exists("Skin/" + skinName + "/Textures/Hub/"))
{
if(Directory.Exists("Skin/" + skinName + "/Textures/Hub/Buttons"))
{
for (int i = 0; i < buttonsSprites.Length; i++)
{
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/Hub/Buttons/" + i + "/topLeft.png", ref buttonsSprites[i].topLeft, GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/Hub/Buttons/" + i + "/topCenter.png", ref buttonsSprites[i].topCenter, GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/Hub/Buttons/" + i + "/topRight.png", ref buttonsSprites[i].topRight, GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/Hub/Buttons/" + i + "/centerLeft.png", ref buttonsSprites[i].centerLeft, GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/Hub/Buttons/" + i + "/centerCenter.png", ref buttonsSprites[i].centerCenter, GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/Hub/Buttons/" + i + "/centerRight.png", ref buttonsSprites[i].centerRight, GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/Hub/Buttons/" + i + "/bottomLeft.png", ref buttonsSprites[i].bottomLeft, GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/Hub/Buttons/" + i + "/bottomCenter.png", ref buttonsSprites[i].bottomCenter, GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/Hub/Buttons/" + i + "/bottomRight.png", ref buttonsSprites[i].bottomRight, GraphicsDevice);
}
}
for (int i = 0; i < pointerSprites.Length; i++)
{
Utilities.SpriteFromPng("Skin/" + skinName + "/Textures/Hub/pointer" + i + ".png", ref pointerSprites[i], GraphicsDevice);
}
}
}
}
// TODO: use this.Content to load your game content here
ChangeTo(GameStatus.Home);
}
/// <summary>
@ -124,11 +184,26 @@ namespace Galactic_Colors_Control_GUI
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
mouseX = Mouse.GetState().X;
mouseY = Mouse.GetState().Y;
oldState = newState;
newState = Mouse.GetState();
mouseX = newState.X;
mouseY = newState.Y;
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);
nowState.rightRelease = (oldState.LeftButton == ButtonState.Pressed && newState.LeftButton == ButtonState.Released);
oldKeys = newKeys;
newKeys = Keyboard.GetState().GetPressedKeys();
if (IsActive)
{
EventArgs e = new EventArgs();
foreach(GUI.Element element in elements.ToArray())
{
element.Update(mouseX, mouseY, nowState, e);
}
}
switch (gameStatus)
@ -171,6 +246,50 @@ namespace Galactic_Colors_Control_GUI
spriteBatch.Begin();
/*
switch (gameStatus)
{
case GameStatus.Home:
drawElements = true;
break;
case GameStatus.Options:
break;
case GameStatus.Game:
break;
case GameStatus.Pause:
break;
case GameStatus.End:
break;
case GameStatus.Thanks:
break;
}
*/
foreach (GUI.Element element in elements)
{
element.Draw(spriteBatch);
}
spriteBatch.Draw(pointerSprites[0], new Rectangle(mouseX - 10, mouseY - 10, 20, 20), Color.Red);
spriteBatch.End();
base.Draw(gameTime);
}
private void ChangeTo(GameStatus newGameStatus)
{
//Things to do when leave status
switch (gameStatus)
{
case GameStatus.Home:
@ -198,11 +317,43 @@ namespace Galactic_Colors_Control_GUI
break;
}
spriteBatch.Draw(pointerSprites[0], new Rectangle(mouseX - 10, mouseY - 10, 20, 20), Color.Red);
elements.Clear();
spriteBatch.End();
//Initialise new status
switch (newGameStatus)
{
case GameStatus.Home:
elements.Add(new GUI.Label(new GUI.Vector(ScreenWidth / 2, ScreenHeight / 4), "Galactic Colors Control", titleFont, Color.DarkRed, true));
//elements.Add(new GUI.TextField(new GUI.Vector(ScreenWidth / 2, ScreenHeight / 2), null, basicFont, Color.Black, Color.Black, Color.DarkSlateGray, true, "Server address"));
elements.Add(new GUI.TexturedButton(new Rectangle(ScreenWidth / 2 - 100, ScreenHeight * 3 / 4,200,40),buttonsSprites[0], Color.White, Color.LightGray, Color.DarkGray, "Connect", basicFont, Color.Black, Color.Black, Color.White, ConnectClick));
break;
case GameStatus.Options:
break;
case GameStatus.Game:
break;
case GameStatus.Pause:
break;
case GameStatus.End:
break;
case GameStatus.Thanks:
break;
}
gameStatus = newGameStatus;
}
private void ConnectClick(object sender, EventArgs e)
{
base.Draw(gameTime);
}
}
}

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: AssemblyVersion("1.0.1.1")]
[assembly: AssemblyFileVersion("1.0.1.1")]

View File

@ -0,0 +1,30 @@
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
namespace Galactic_Colors_Control_GUI
{
static class Utilities
{
static public void SpriteFromPng(string path, ref Texture2D sprite, GraphicsDevice graphics )
{
if (File.Exists(path))
{
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
sprite = Texture2D.FromStream(graphics, fileStream);
}
}
}
static public void SoundFromMp3(string path, ref SoundEffect sound)
{
if (File.Exists(path))
{
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) {
sound = SoundEffect.FromStream(fileStream);
}
}
}
}
}