1
0
Fork 0

Gui Client Start Update

master
sheychen 2016-11-14 15:09:44 +01:00
parent 4476963f4a
commit 507f9c625f
16 changed files with 891 additions and 624 deletions

View File

@ -3,7 +3,6 @@ using Galactic_Colors_Control_Common;
using Galactic_Colors_Control_Common.Protocol;
using System;
using System.Reflection;
using System.Threading;
namespace Galactic_Colors_Control_Console
{
@ -23,7 +22,7 @@ namespace Galactic_Colors_Control_Console
Console.Title = "Galactic Colors Control Client"; //Start display
Console.Write(">");
Common.ConsoleWrite("Galactic Colors Control Client", ConsoleColor.Red);
Common.ConsoleWrite("Console " + Assembly.GetEntryAssembly().GetName().Version.ToString(), ConsoleColor.DarkYellow);
Common.ConsoleWrite("Console " + Assembly.GetEntryAssembly().GetName().Version.ToString(), ConsoleColor.Yellow);
bool hostSet = false;
while (!hostSet) //Request hostname
{
@ -79,7 +78,7 @@ namespace Galactic_Colors_Control_Console
return;
string[] req;
if(input[0] == commandChar)
if (input[0] == commandChar)
{
input = input.Substring(1);
req = Common.SplitArgs(input);

View File

@ -0,0 +1,74 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Galactic_Colors_Control_GUI
{
/// <summary>
/// Multilayer Background
/// </summary>
public class Background
{
private double[] backgroundX;
private double[] backgroundY;
private Texture2D[] backSprites;
private double[] ratio;
public double speedX = 0;
public double speedY = 0;
internal void Draw(object spriteBatch)
{
throw new NotImplementedException();
}
/// <summary>
/// Background.lenght == Ratio.Lenght
/// </summary>
public Background(Texture2D[] BackSprites, double[] Ratio)
{
backSprites = BackSprites;
ratio = Ratio;
backgroundX = new double[backSprites.Length];
backgroundY = new double[backSprites.Length];
}
/// <summary>
/// Manual Move
/// </summary>
public void Move(double x, double y)
{
for (int index = 0; index < backSprites.Length; index++)
{
backgroundX[index] += (x * ratio[index]);
backgroundY[index] += (y * ratio[index]);
if (backgroundX[index] > backSprites[index].Width) { backgroundX[index] = 0; }
if (backgroundY[index] > backSprites[index].Height) { backgroundY[index] = 0; }
if (backgroundX[index] < 0) { backgroundX[index] = backSprites[index].Width; }
if (backgroundY[index] < 0) { backgroundY[index] = backSprites[index].Height; }
}
}
/// <summary>
/// AutoMove for speedX and speedY
/// </summary>
public void Update()
{
Move(speedX, speedY);
}
public void Draw(SpriteBatch spriteBatch)
{
for (int index = 0; index < backSprites.Length; index++)
{
for (int X = -1; X < Game.singleton.ScreenWidth / backSprites[index].Width + 1; X++)
{
for (int Y = -1; Y < Game.singleton.ScreenHeight / backSprites[index].Height + 1; Y++)
{
spriteBatch.Draw(backSprites[index], new Rectangle(X * backSprites[index].Width + (int)backgroundX[index], Y * backSprites[index].Height + (int)backgroundY[index], backSprites[index].Width, backSprites[index].Height), Color.White);
}
}
}
}
}
}

View File

@ -44,9 +44,17 @@
<Compile Include="..\AssemblyInfoCommon.cs">
<Link>Properties\AssemblyInfoCommon.cs</Link>
</Compile>
<Compile Include="Game1.cs" />
<Compile Include="Background.cs" />
<Compile Include="Game.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="States\ConnectState.cs" />
<Compile Include="States\GameState.cs" />
<Compile Include="States\IndentificationState.cs" />
<Compile Include="States\MainMenuState.cs" />
<Compile Include="States\OptionsState.cs" />
<Compile Include="States\State.cs" />
<Compile Include="States\TitleState.cs" />
<Compile Include="Utilities.cs" />
</ItemGroup>
<ItemGroup>
@ -114,6 +122,10 @@
<MonoGameContentReference Include="Content\Content.mgcb" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Galactic Colors Control Common\Galactic Colors Control Common.csproj">
<Project>{022a69ce-22b5-4934-be9f-a9c6df9557ed}</Project>
<Name>Galactic Colors Control Common</Name>
</ProjectReference>
<ProjectReference Include="..\Galactic Colors Control\Galactic Colors Control.csproj">
<Project>{93582ce8-c8c8-4e19-908b-d671ecbade25}</Project>
<Name>Galactic Colors Control</Name>

View File

@ -0,0 +1,214 @@
using Galactic_Colors_Control;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MyMonoGame.GUI;
using System;
using System.IO;
using System.Reflection;
using System.Threading;
namespace Galactic_Colors_Control_GUI
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game : Microsoft.Xna.Framework.Game
{
public static Game singleton;
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private ContentManager content;
private SoundEffect[] effects = new SoundEffect[4]; //click, hover, explosion,...
public Fonts fonts;
internal static Texture2D nullSprite;
private Texture2D[] pointerSprites = new Texture2D[1];
public boxSprites[] buttonsSprites = new boxSprites[1];
public Background background;
public Client client; //Client Core
public Manager GUI = new Manager(); //MyMonogameGUI
private string skinName;
private bool isFullScreen = false;
public States.State gameState = new States.TitleState(new States.MainMenuState(), new TimeSpan(0,0,5));
private int _ScreenWidth = 1280;
private int _ScreenHeight = 720;
public int ScreenWidth { get { return _ScreenWidth; } private set { _ScreenWidth = value; } }
public int ScreenHeight { get { return _ScreenHeight; } private set { _ScreenHeight = value; } }
public Game()
{
singleton = this;
if (isFullScreen) //Fullscreen resolution
{
ScreenWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
ScreenHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
}
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = ScreenWidth;
graphics.PreferredBackBufferHeight = ScreenHeight;
graphics.IsFullScreen = isFullScreen;
graphics.ApplyChanges();
Content.RootDirectory = "Content";
content = Content;
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
nullSprite = new Texture2D(GraphicsDevice, 1, 1);
nullSprite.SetData(new Color[1 * 1] { Color.White });
GUI.Initialise();
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
//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");
fonts.small = content.Load<SpriteFont>("Fonts/small");
fonts.basic = content.Load<SpriteFont>("Fonts/basic");
fonts.title = content.Load<SpriteFont>("Fonts/title");
for (int i = 0; i < pointerSprites.Length; i++)
{
pointerSprites[i] = content.Load<Texture2D>("Textures/Hub/pointer" + i);
}
Texture2D[] backSprites = new Texture2D[2];
backSprites[0] = content.Load<Texture2D>("Textures/background0");
backSprites[1] = content.Load<Texture2D>("Textures/background1");
States.MainMenuState.logoSprite = content.Load<Texture2D>("Textures/LogoSmall");
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");
}
//Load from files
if (Directory.Exists("Skin/" + skinName))
{
if (Directory.Exists("Skin/" + skinName + "/Sounds"))
{
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"))
{
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/background0.png", ref backSprites[0], GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/background1.png", ref backSprites[1], GraphicsDevice);
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);
}
}
}
}
background = new Background(backSprites, new double[2] { 1, 2 }); //Background initialisation
background.speedX = 1;
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
// Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
gameState.Update();
GUI.Update();
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.DarkGray);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
GUI.Draw(spriteBatch);
gameState.Draw(spriteBatch);
Color ActiveColor = IsActive ? Color.Green : Color.Red;
GUI.Label(new MyMonoGame.Vector(10, ScreenHeight - 20), (1 / (float)gameTime.ElapsedGameTime.TotalSeconds).ToString(), fonts.small, new MyMonoGame.Colors(ActiveColor));
spriteBatch.Draw(pointerSprites[0], new Rectangle(Mouse.GetState().X - 10, Mouse.GetState().Y - 10, 20, 20), Color.Red);
spriteBatch.End();
base.Draw(gameTime);
}
}
}

View File

@ -1,614 +0,0 @@
//TODO comment and update for new clientcore
using Galactic_Colors_Control;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MyMonoGame.GUI;
using System;
using System.IO;
using System.Reflection;
using System.Threading;
namespace Galactic_Colors_Control_GUI
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private ContentManager content;
private SoundEffect[] effects = new SoundEffect[4];
private SpriteFont smallFont;
private SpriteFont basicFont;
private SpriteFont titleFont;
internal static Texture2D nullSprite;
private Texture2D logoSprite;
private Texture2D[] backSprites = new Texture2D[2];
private double[] backgroundX = new double[2];
private double[] backgroundY = new double[2];
private double acceleratorX = 1;
private Texture2D[] pointerSprites = new Texture2D[1];
private boxSprites[] buttonsSprites = new boxSprites[1];
private Client client;
private Manager GUI = new Manager();
private string skinName;
private bool isFullScren = false;
private enum GameStatus
{
Home, Connect, Options, Game, Pause, End, Thanks,
Title,
Indentification,
Kick
}
private GameStatus gameStatus = GameStatus.Home;
private int ScreenWidth = 1280;
private int ScreenHeight = 720;
private string username = null;
private bool showOKMessage = false;
private string messageTitle;
private string messageText = string.Empty;
private bool showYNMessage = false;
private bool showLoading = false;
private bool showChat = false;
private string chatText = string.Empty;
private string chatInput = string.Empty;
private bool showParty = false;
private bool showOutput = true;
public Game1()
{
if (isFullScren)
{
ScreenWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
ScreenHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
}
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = ScreenWidth;
graphics.PreferredBackBufferHeight = ScreenHeight;
graphics.IsFullScreen = isFullScren;
graphics.ApplyChanges();
Content.RootDirectory = "Content";
content = Content;
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
nullSprite = new Texture2D(GraphicsDevice, 1, 1);
nullSprite.SetData(new Color[1 * 1] { Color.White });
GUI.Initialise();
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
//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++)
{
pointerSprites[i] = content.Load<Texture2D>("Textures/Hub/pointer" + i);
}
backSprites[0] = content.Load<Texture2D>("Textures/background0");
backSprites[1] = content.Load<Texture2D>("Textures/background1");
logoSprite = content.Load<Texture2D>("Textures/LogoSmall");
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 (Directory.Exists("Skin/" + skinName + "/Sounds"))
{
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"))
{
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/background0.png", ref backSprites[0], GraphicsDevice);
Utilities.SpriteFromPng("Skin/" + skinName + "Textures/background1.png", ref backSprites[1], GraphicsDevice);
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);
}
}
}
}
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
// Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
switch (gameStatus)
{
case GameStatus.Home:
case GameStatus.Title:
case GameStatus.Connect:
case GameStatus.Indentification:
backgroundX[0] -= 1 * acceleratorX;
backgroundX[1] -= 2 * acceleratorX;
break;
case GameStatus.Game:
if (showOutput)
//TODO
/*if (client.Output.Count > 0)
{
string text = client.Output[0];
switch (text)
{
case "/clear":
chatText = string.Empty;
break;
default:
ChatAdd(text);
break;
}
client.Output.Remove(text);
}*/
if (!client.isRunning) { gameStatus = GameStatus.Kick; }
break;
}
GUI.Update();
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.DarkGray);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
GUI.Draw(spriteBatch);
switch (gameStatus)
{
case GameStatus.Title:
DrawBackground(0);
DrawBackground(1);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 2), "Galactic Colors Control", titleFont, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
break;
case GameStatus.Home:
DrawBackground(0);
DrawBackground(1);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4), "Galactic Colors Control", titleFont, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4 + 40), "GUI " + Assembly.GetEntryAssembly().GetName().Version.ToString(), basicFont, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
if (GUI.Button(new Rectangle(ScreenWidth - 64, ScreenHeight - 74, 64, 64), logoSprite)) { System.Diagnostics.Process.Start("https://sheychen.shost.ca/"); }
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 75, ScreenHeight / 2 - 30, 150, 40), buttonsSprites[0], "Play", basicFont, new MyMonoGame.Colors(Color.White, Color.Green)))
{
GUI.ResetFocus();
client = new Client();
new Thread(() =>
{
while (acceleratorX < 5)
{
Thread.Sleep(20);
acceleratorX += 0.1d;
}
gameStatus = GameStatus.Connect;
}).Start();
}
//if (GUI.Button(new Rectangle(ScreenWidth / 2 - 75, ScreenHeight / 2 + 20, 150, 40), buttonsSprites[0], "Options", basicFont, new MyMonoGame.Colors(Color.White, Color.Blue))) {
// GUI.ResetFocus();
// gameStatus = GameStatus.Options;
//}
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 75, ScreenHeight / 2 + 70, 150, 40), buttonsSprites[0], "Exit", basicFont, new MyMonoGame.Colors(Color.White, Color.Red)))
{
GUI.ResetFocus();
gameStatus = GameStatus.Title;
new Thread(() =>
{
while (acceleratorX > 0)
{
Thread.Sleep(10);
acceleratorX -= 0.01d;
}
Exit();
}).Start();
}
break;
case GameStatus.Connect:
DrawBackground(0);
DrawBackground(1);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4), "Galactic Colors Control", titleFont, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
if (showLoading)
{
GUI.Box(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 50), buttonsSprites[0]);
GUI.Label(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 50), "Loading", basicFont);
}
else
{
if (showOKMessage)
{
GUI.Box(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 150), buttonsSprites[0]);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4 + 60), messageTitle, basicFont, null, Manager.textAlign.bottomCenter);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4 + 100), messageText, smallFont, null, Manager.textAlign.bottomCenter);
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 140, ScreenHeight / 4 + 150, 280, 40), buttonsSprites[0], "Ok", basicFont)) { GUI.ResetFocus(); showOKMessage = false; }
}
else
{
if (showYNMessage)
{
GUI.Box(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 100), buttonsSprites[0]);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4 + 60), messageTitle, basicFont, null, Manager.textAlign.bottomCenter);
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 140, ScreenHeight / 4 + 100, 135, 40), buttonsSprites[0], "Yes", basicFont))
{
GUI.ResetFocus();
new Thread(ConnectHost).Start();
showYNMessage = false;
}
if (GUI.Button(new Rectangle(ScreenWidth / 2 + 5, ScreenHeight / 4 + 100, 135, 40), buttonsSprites[0], "No", basicFont))
{
//TODO client.Output.Clear();
client.ResetHost();
GUI.ResetFocus();
showYNMessage = false;
}
}
else
{
if (GUI.TextField(new Rectangle(ScreenWidth / 2 - 75, ScreenHeight / 2 - 30, 150, 40), ref username, basicFont, new MyMonoGame.Colors(Color.LightGray, Color.White), Manager.textAlign.centerCenter, "Server address")) { new Thread(ValidateHost).Start(); }
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 75, ScreenHeight / 2 + 20, 150, 40), buttonsSprites[0], "Connect", basicFont, new MyMonoGame.Colors(Color.LightGray, Color.White))) { new Thread(ValidateHost).Start(); }
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 75, ScreenHeight / 2 + 70, 150, 40), buttonsSprites[0], "Back", basicFont, new MyMonoGame.Colors(Color.LightGray, Color.White)))
{
GUI.ResetFocus();
new Thread(() =>
{
while (acceleratorX > 1)
{
Thread.Sleep(20);
acceleratorX -= 0.1d;
}
gameStatus = GameStatus.Home;
username = null;
}).Start();
}
}
}
}
break;
case GameStatus.Indentification:
DrawBackground(0);
DrawBackground(1);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4), "Galactic Colors Control", titleFont, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
if (showLoading)
{
GUI.Box(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 50), buttonsSprites[0]);
GUI.Label(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 50), "Loading", basicFont);
}
else
{
if (showOKMessage)
{
GUI.Box(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 150), buttonsSprites[0]);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4 + 60), messageTitle, basicFont, null, Manager.textAlign.bottomCenter);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4 + 100), messageText, smallFont, null, Manager.textAlign.bottomCenter);
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 140, ScreenHeight / 4 + 150, 280, 40), buttonsSprites[0], "Ok", basicFont)) { GUI.ResetFocus(); showOKMessage = false; }
}
else
{
if (GUI.TextField(new Rectangle(ScreenWidth / 2 - 75, ScreenHeight / 2 - 30, 150, 40), ref username, basicFont, new MyMonoGame.Colors(Color.LightGray, Color.White), Manager.textAlign.centerCenter, "Username")) { new Thread(IdentifiacateHost).Start(); }
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 75, ScreenHeight / 2 + 20, 150, 40), buttonsSprites[0], "Validate", basicFont, new MyMonoGame.Colors(Color.LightGray, Color.White))) { new Thread(IdentifiacateHost).Start(); }
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 75, ScreenHeight / 2 + 70, 150, 40), buttonsSprites[0], "Back", basicFont, new MyMonoGame.Colors(Color.LightGray, Color.White)))
{
GUI.ResetFocus();
new Thread(() =>
{
while (acceleratorX > 1)
{
Thread.Sleep(20);
acceleratorX -= 0.1d;
}
gameStatus = GameStatus.Home;
username = null;
}).Start();
}
}
}
break;
case GameStatus.Game:
DrawBackground(0);
DrawBackground(1);
GUI.Texture(new Rectangle(0, 0, ScreenWidth, 30), nullSprite, new MyMonoGame.Colors(new Color(0.1f, 0.1f, 0.1f)));
if (GUI.Button(new Rectangle(5, 5, 50, 20), (showChat ? "Hide" : "Show") + " chat", smallFont, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.Gray))) { GUI.ResetFocus(); showChat = !showChat; }
if (GUI.Button(new Rectangle(65, 5, 50, 20), (showParty ? "Leave" : "Join") + " party", smallFont, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.Gray))) { new Thread(PartyClick).Start(); }
if (showChat)
{
GUI.Box(new Rectangle(0, 30, 310, 310), buttonsSprites[0]);
//TODO if (GUI.TextField(new Rectangle(5, 35, 305, 20), ref chatInput, basicFont, null, Manager.textAlign.centerLeft, "Enter message")) { if (chatInput != null) { ChatAdd(chatInput); client.SendRequest(chatInput); chatInput = null; } }
GUI.Label(new Rectangle(5, 60, 305, 245), chatText, smallFont, null, Manager.textAlign.topLeft, true);
}
if (showLoading)
{
GUI.Box(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 50), buttonsSprites[0]);
GUI.Label(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 50), "Loading", basicFont);
}
else
{
if (showOKMessage)
{
GUI.Box(new Rectangle(ScreenWidth / 2 - 150, ScreenHeight / 4 + 50, 300, 150), buttonsSprites[0]);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4 + 60), messageTitle, basicFont, null, Manager.textAlign.bottomCenter);
GUI.Label(new MyMonoGame.Vector(ScreenWidth / 2, ScreenHeight / 4 + 100), messageText, smallFont, null, Manager.textAlign.bottomCenter);
if (GUI.Button(new Rectangle(ScreenWidth / 2 - 140, ScreenHeight / 4 + 150, 280, 40), buttonsSprites[0], "Ok", basicFont)) { GUI.ResetFocus(); showOKMessage = false; }
}
}
break;
}
Color ActiveColor = IsActive ? Color.Green : Color.Red;
GUI.Label(new MyMonoGame.Vector(10, ScreenHeight - 20), (1 / (float)gameTime.ElapsedGameTime.TotalSeconds).ToString(), smallFont, new MyMonoGame.Colors(ActiveColor));
spriteBatch.Draw(pointerSprites[0], new Rectangle(Mouse.GetState().X - 10, Mouse.GetState().Y - 10, 20, 20), Color.Red);
spriteBatch.End();
base.Draw(gameTime);
}
private void ValidateHost()
{
showLoading = true;
if (username == null) { username = ""; }
string Host = client.ValidateHost(username);
if (Host == null)
{
messageTitle = "Error";
messageText = string.Empty;
//TODO foreach (string line in client.Output.ToArray()) { messageText += (line + Environment.NewLine); }
showOKMessage = true;
//TODO client.Output.Clear();
client.ResetHost(); ;
}
else
{
messageTitle = "Use " + Host + "?";
showYNMessage = true;
}
showLoading = false;
}
private void ConnectHost()
{
showLoading = true;
if (client.ConnectHost())
{
gameStatus = GameStatus.Indentification;
}
else
{
messageTitle = "Error";
messageText = string.Empty;
//TODO foreach (string line in client.Output.ToArray()) { messageText += (line + Environment.NewLine); }
showOKMessage = true;
//TODO client.Output.Clear();
client.ResetHost();
}
showLoading = false;
}
private void IdentifiacateHost()
{
showLoading = true;
if (username != null)
{
if (username.Length > 3)
{
//TODO client.Output.Clear();
//TODO client.SendRequest("/connect " + username);
/*int wait = 0;
while (wait < 20)
{
if (client.Output.Count > 0)
{
wait = 20;
}
else
{
wait++;
Thread.Sleep(200);
}
}
if (client.Output.Count > 0)
{
if (client.Output.Contains("Identifiaction succes"))
{
gameStatus = GameStatus.Game;
}
else
{
messageTitle = "Error";
messageText = string.Empty;
foreach (string line in client.Output.ToArray()) { messageText += (line + Environment.NewLine); }
showOKMessage = true;
showLoading = false;
client.Output.Clear();
}
}
else
{
messageTitle = "Timeout";
messageText = "";
showOKMessage = true;
showLoading = false;
client.Output.Clear();
}*/
}
}
showLoading = false;
}
private void PartyClick()
{
showLoading = true;
GUI.ResetFocus();
//TODO
/*
if (showParty)
{
client.SendRequest("/party leave");
showParty = false;
showLoading = false;
}
else
{
client.Output.Clear();
client.SendRequest("/party list");
int wait = 0;
while (wait < 20)
{
if (client.Output.Count > 0)
{
wait = 20;
}
else
{
wait++;
Thread.Sleep(200);
}
}
if (client.Output.Count > 0)
{
Thread.Sleep(500);
if (client.Output.Count > 1)
{
messageTitle = "Party";
messageText = string.Empty;
foreach (string line in client.Output.ToArray()) { messageText += (line + Environment.NewLine); }
showOKMessage = true;
client.Output.Clear();
}
else
{
messageTitle = "Any party";
messageText = string.Empty;
foreach (string line in client.Output.ToArray()) { messageText += (line + Environment.NewLine); }
showOKMessage = true;
client.Output.Clear();
}
}
else
{
messageTitle = "Timeout";
messageText = "";
showOKMessage = true;
showLoading = false;
client.Output.Clear();
}
}*/
}
private void ChatAdd(string text)
{
chatText += ((chatText != string.Empty ? Environment.NewLine : "") + text);
}
private void DrawBackground(int index)
{
if (backgroundX[index] > backSprites[index].Width) { backgroundX[index] = 0; }
if (backgroundY[index] > backSprites[index].Height) { backgroundY[index] = 0; }
if (backgroundX[index] < 0) { backgroundX[index] = backSprites[index].Width; }
if (backgroundY[index] < 0) { backgroundY[index] = backSprites[index].Height; }
for (int X = -1; X < ScreenWidth / backSprites[index].Width + 1; X++)
{
for (int Y = -1; Y < ScreenHeight / backSprites[index].Height + 1; Y++)
{
GUI.Texture(new Rectangle(X * backSprites[index].Width + (int)backgroundX[index], Y * backSprites[index].Height + (int)backgroundY[index], backSprites[index].Width, backSprites[index].Height), backSprites[index], new MyMonoGame.Colors(Color.White));
}
}
}
}
}

View File

@ -13,7 +13,8 @@ namespace Galactic_Colors_Control_GUI
[STAThread]
private static void Main()
{
using (var game = new Game1())
//TODO add debug and more
using (var game = new Game())
game.Run();
}
}

View File

@ -0,0 +1,150 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MyMonoGame.GUI;
using System.Threading;
using System;
namespace Galactic_Colors_Control_GUI.States
{
public struct Message
{
public string title;
public string text;
public Message(string Title, string Text = "")
{
title = Title;
text = Text;
}
}
public class ConnectState : State
{
private bool locked = false;
private bool showLoading = false;
private bool showOKMessage = false;
private bool showYNMessage = false;
private Message message;
private string adress;
public override void Draw(SpriteBatch spritebatch)
{
Game.singleton.background.Draw(spritebatch);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4), "Galactic Colors Control", Game.singleton.fonts.title, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
if (showLoading)
{
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 50), Game.singleton.buttonsSprites[0]);
Game.singleton.GUI.Label(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 50), "Loading", Game.singleton.fonts.basic);
}
else
{
if (showOKMessage)
{
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 150), Game.singleton.buttonsSprites[0]);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 60), message.title, Game.singleton.fonts.basic , null, Manager.textAlign.bottomCenter);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 100), message.text, Game.singleton.fonts.small, null, Manager.textAlign.bottomCenter);
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 140, Game.singleton.ScreenHeight / 4 + 150, 280, 40), Game.singleton.buttonsSprites[0], "Ok", Game.singleton.fonts.basic)) { locked = false; Game.singleton.GUI.ResetFocus(); showOKMessage = false; }
}
else
{
if (showYNMessage)
{
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 100), Game.singleton.buttonsSprites[0]);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 60), message.title, Game.singleton.fonts.basic, null, Manager.textAlign.bottomCenter);
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 140, Game.singleton.ScreenHeight / 4 + 100, 135, 40), Game.singleton.buttonsSprites[0], "Yes", Game.singleton.fonts.basic))
{
if (!locked)
{
locked = true;
showYNMessage = false;
Game.singleton.GUI.ResetFocus();
new Thread(ConnectHost).Start();
}
}
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 + 5, Game.singleton.ScreenHeight / 4 + 100, 135, 40), Game.singleton.buttonsSprites[0], "No", Game.singleton.fonts.basic))
{
showYNMessage = false;
Game.singleton.client.ResetHost();
Game.singleton.GUI.ResetFocus();
}
}
else
{
if (Game.singleton.GUI.TextField(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 - 30, 150, 40), ref adress, Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White), Manager.textAlign.centerCenter, "Server address")) {
if (!locked)
{
locked = true;
new Thread(ValidateHost).Start();
}
}
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 + 20, 150, 40), Game.singleton.buttonsSprites[0], "Connect", Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White)))
{
if (!locked)
{
locked = true;
new Thread(ValidateHost).Start();
}
}
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 + 70, 150, 40), Game.singleton.buttonsSprites[0], "Back", Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White)))
{
if (!locked)
{
locked = true;
Game.singleton.GUI.ResetFocus();
new Thread(() =>
{
while (!Utilities.DoubleTo(ref Game.singleton.background.speedX, 1, 0.1)) { Thread.Sleep(20); }
Game.singleton.gameState = new MainMenuState();
}).Start();
}
}
}
}
}
}
public override void Update()
{
Game.singleton.background.Update();
}
private void ValidateHost()
{
showLoading = true;
if (adress == null) { adress = ""; }
string Host = Game.singleton.client.ValidateHost(adress);
if (Host[0] == '*')
{
Host = Host.Substring(1);
message.title = "Error";
message.text = Host;
showOKMessage = true;
Game.singleton.client.ResetHost(); ;
}
else
{
message.title = "Use " + Host + "?";
showYNMessage = true;
}
showLoading = false;
locked = false;
}
private void ConnectHost()
{
showLoading = true;
if (Game.singleton.client.ConnectHost())
{
Game.singleton.gameState = new IndentificationState();
}
else
{
message.title = "Error";
message.text = string.Empty;
showOKMessage = true;
Game.singleton.client.ResetHost();
}
showLoading = false;
}
}
}

View File

@ -0,0 +1,169 @@
//TODO add party support
using Galactic_Colors_Control_Common;
using Galactic_Colors_Control_Common.Protocol;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MyMonoGame.GUI;
using System.Threading;
using System;
using Microsoft.Xna.Framework.Input;
namespace Galactic_Colors_Control_GUI.States
{
public class GameState : State
{
private string username;
private bool showChat = false;
private string chatText;
private string chatInput;
private bool showLoading = false;
private bool showOKMessage = false;
private Message message;
public GameState(string Username)
{
Game.singleton.client.OnEvent += new EventHandler(OnEvent); //Set OnEvent function
username = Username;
}
public override void Draw(SpriteBatch spritebatch)
{
Game.singleton.background.Draw(spritebatch);
Game.singleton.GUI.Texture(new Rectangle(0, 0, Game.singleton.ScreenWidth, 30), Game.nullSprite, new MyMonoGame.Colors(new Color(0.1f, 0.1f, 0.1f)));
if (Game.singleton.GUI.Button(new Rectangle(5, 5, 50, 20), (showChat ? "Hide" : "Show") + " chat", Game.singleton.fonts.small, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.Gray))) { Game.singleton.GUI.ResetFocus(); showChat = !showChat; }
//if (Game.singleton.GUI.Button(new Rectangle(65, 5, 50, 20), (showParty ? "Leave" : "Join") + " party", smallFont, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.Gray))) { new Thread(PartyClick).Start(); }
if (showChat)
{
Game.singleton.GUI.Box(new Rectangle(0, 30, 310, 310), Game.singleton.buttonsSprites[0]);
if (Game.singleton.GUI.TextField(new Rectangle(5, 35, 305, 20), ref chatInput, Game.singleton.fonts.basic, null, Manager.textAlign.centerLeft, "Enter message")) { if (chatInput != null) { new Thread(ChatEnter).Start(); } }
Game.singleton.GUI.Label(new Rectangle(5, 60, 305, 245), chatText, Game.singleton.fonts.small, null, Manager.textAlign.topLeft, true);
}
if (showLoading)
{
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 50), Game.singleton.buttonsSprites[0]);
Game.singleton.GUI.Label(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 50), "Loading", Game.singleton.fonts.basic);
}
else
{
if (showOKMessage)
{
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 150), Game.singleton.buttonsSprites[0]);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 60), message.title, Game.singleton.fonts.basic, null, Manager.textAlign.bottomCenter);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 100), message.text, Game.singleton.fonts.small, null, Manager.textAlign.bottomCenter);
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 140, Game.singleton.ScreenHeight / 4 + 150, 280, 40), Game.singleton.buttonsSprites[0], "Ok", Game.singleton.fonts.basic)) { Game.singleton.GUI.ResetFocus(); showOKMessage = false; Game.singleton.client.ExitHost(); Game.singleton.gameState = new MainMenuState(); }
}
}
}
public override void Update()
{
if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Game.singleton.GUI.ResetFocus(); Game.singleton.client.ExitHost(); Game.singleton.gameState = new MainMenuState(); }
}
private void ChatEnter()
{
string request = chatInput;
chatInput = null;
ResultData res = Game.singleton.client.Request(new string[2] { "say", request });
if(res.type != ResultTypes.OK)
{
//TODO Mutlilang
ChatText("Error :" + Common.ArrayToString(res.result));
}
}
private void OnEvent(object sender, EventArgs e)
{
EventData eve = ((EventDataArgs)e).Data;
switch (eve.type)
{
case EventTypes.ChatMessage:
ChatText(Common.ArrayToString(eve.data));
break;
case EventTypes.ServerJoin:
ChatText(Common.ArrayToString(eve.data) + "join the server");
break;
case EventTypes.ServerLeave:
ChatText(Common.ArrayToString(eve.data) + "leave the server");
break;
case EventTypes.ServerKick:
message.title = "Kick from server";
message.text = Common.ArrayToString(eve.data);
showOKMessage = true;
break;
}
}
public void ChatText(string text)
{
chatText += (text + Environment.NewLine);
}
/*
private void PartyClick()
{
showLoading = true;
GUI.ResetFocus();
//TODO
/*
if (showParty)
{
client.SendRequest("/party leave");
showParty = false;
showLoading = false;
}
else
{
client.Output.Clear();
client.SendRequest("/party list");
int wait = 0;
while (wait < 20)
{
if (client.Output.Count > 0)
{
wait = 20;
}
else
{
wait++;
Thread.Sleep(200);
}
}
if (client.Output.Count > 0)
{
Thread.Sleep(500);
if (client.Output.Count > 1)
{
messageTitle = "Party";
messageText = string.Empty;
foreach (string line in client.Output.ToArray()) { messageText += (line + Environment.NewLine); }
showOKMessage = true;
client.Output.Clear();
}
else
{
messageTitle = "Any party";
messageText = string.Empty;
foreach (string line in client.Output.ToArray()) { messageText += (line + Environment.NewLine); }
showOKMessage = true;
client.Output.Clear();
}
}
else
{
messageTitle = "Timeout";
messageText = "";
showOKMessage = true;
showLoading = false;
client.Output.Clear();
}
}
}*/
}
}

View File

@ -0,0 +1,101 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MyMonoGame.GUI;
using System.Threading;
using System;
using Galactic_Colors_Control_Common.Protocol;
using Galactic_Colors_Control_Common;
namespace Galactic_Colors_Control_GUI.States
{
public class IndentificationState : State
{
private string username;
private Message message;
private bool locked = false;
private bool showLoading = false;
private bool showOKMessage = false;
public override void Draw(SpriteBatch spritebatch)
{
Game.singleton.background.Draw(spritebatch);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4), "Galactic Colors Control", Game.singleton.fonts.title , new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
if (showLoading)
{
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 50), Game.singleton.buttonsSprites[0]);
Game.singleton.GUI.Label(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 50), "Loading", Game.singleton.fonts.basic);
}
else
{
if (showOKMessage)
{
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 150), Game.singleton.buttonsSprites[0]);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 60), message.title, Game.singleton.fonts.basic, null, Manager.textAlign.bottomCenter);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 100), message.text, Game.singleton.fonts.small, null, Manager.textAlign.bottomCenter);
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 140, Game.singleton.ScreenHeight / 4 + 150, 280, 40), Game.singleton.buttonsSprites[0], "Ok", Game.singleton.fonts.basic)){ Game.singleton.GUI.ResetFocus(); showOKMessage = false; }
}
else
{
if (Game.singleton.GUI.TextField(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 - 30, 150, 40), ref username, Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White), Manager.textAlign.centerCenter, "Username")) {
if (!locked)
{
locked = true;
new Thread(IdentifiacateHost).Start();
}
}
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 + 20, 150, 40), Game.singleton.buttonsSprites[0], "Validate", Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White))) {
if (!locked)
{
locked = true;
new Thread(IdentifiacateHost).Start();
}
}
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 + 70, 150, 40), Game.singleton.buttonsSprites[0], "Back", Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White)))
{
if (!locked)
{
locked = true;
Game.singleton.GUI.ResetFocus();
new Thread(() =>
{
while (!Utilities.DoubleTo(ref Game.singleton.background.speedX, 1, 0.1)) { Thread.Sleep(20); }
Game.singleton.gameState = new MainMenuState();
}).Start();
}
}
}
}
}
private void IdentifiacateHost()
{
showLoading = true;
if (username != null)
{
if (username.Length > 3)
{
ResultData res = Game.singleton.client.Request(new string[2] { "connect", username });
if (res.type == ResultTypes.OK)
{
Game.singleton.gameState = new GameState(username);
}
else
{
message.title = "Error";
message.text = Common.ArrayToString(res.result);
showOKMessage = true;
}
}
}
showLoading = false;
locked = false;
}
public override void Update()
{
Game.singleton.background.Update();
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using MyMonoGame.GUI;
using System.Reflection;
using Galactic_Colors_Control;
using System.Threading;
namespace Galactic_Colors_Control_GUI.States
{
public class MainMenuState : State
{
public static Texture2D logoSprite;
private bool locked = false;
public override void Draw(SpriteBatch spritebatch)
{
Game.singleton.background.Draw(spritebatch);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4), "Galactic Colors Control", Game.singleton.fonts.title, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 40), "GUI " + Assembly.GetEntryAssembly().GetName().Version.ToString(), Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth - 64, Game.singleton.ScreenHeight - 74, 64, 64), logoSprite)) { System.Diagnostics.Process.Start("https://sheychen.shost.ca/"); }
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 - 30, 150, 40), Game.singleton.buttonsSprites[0], "Play", Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.White, Color.Green)))
{
if (!locked)
{
locked = true;
Game.singleton.GUI.ResetFocus();
Game.singleton.client = new Client();
new Thread(() =>
{
while (!Utilities.DoubleTo(ref Game.singleton.background.speedX, 5, 0.1)) { Thread.Sleep(20); }
Game.singleton.gameState = new ConnectState();
}).Start();
}
}
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 + 20, 150, 40), Game.singleton.buttonsSprites[0], "Options", Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.White, Color.Blue))) {
Game.singleton.GUI.ResetFocus();
Game.singleton.gameState = new OptionsState();
}
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 + 70, 150, 40), Game.singleton.buttonsSprites[0], "Exit", Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.White, Color.Red)))
{
if (!locked)
{
locked = true;
Game.singleton.GUI.ResetFocus();
Game.singleton.gameState = new TitleState();
new Thread(() =>
{
while (!Utilities.DoubleTo(ref Game.singleton.background.speedX, 0, 0.1)) { Thread.Sleep(50); }
Game.singleton.Exit();
}).Start();
}
}
}
public override void Update()
{
Game.singleton.background.Update();
}
}
}

View File

@ -0,0 +1,17 @@
using Microsoft.Xna.Framework.Graphics;
namespace Galactic_Colors_Control_GUI.States
{
public class OptionsState : State
{
public override void Draw(SpriteBatch spritebatch)
{
Game.singleton.background.Draw(spritebatch);
}
public override void Update()
{
Game.singleton.background.Update();
}
}
}

View File

@ -0,0 +1,20 @@
using Microsoft.Xna.Framework.Graphics;
namespace Galactic_Colors_Control_GUI.States
{
/// <summary>
/// Game Menu Main Class
/// </summary>
public class State
{
public virtual void Draw(SpriteBatch spritebatch)
{
}
public virtual void Update()
{
}
}
}

View File

@ -0,0 +1,41 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MyMonoGame.GUI;
using System;
namespace Galactic_Colors_Control_GUI.States
{
/// <summary>
/// Only title in screen (and state change)
/// </summary>
public class TitleState : State
{
private DateTime _changeDate;
private State _target;
public TitleState()
{
_target = null;
}
public TitleState(State target, TimeSpan time)
{
_target = target;
_changeDate = DateTime.Now.Add(time);
}
public override void Draw(SpriteBatch spritebatch)
{
Game.singleton.background.Draw(spritebatch);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 2), "Galactic Colors Control", Game.singleton.fonts.title, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
}
public override void Update()
{
if (_target != null)
{
if (DateTime.Now > _changeDate) { Game.singleton.gameState = _target; }
}
}
}
}

View File

@ -1,9 +1,17 @@
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
namespace Galactic_Colors_Control_GUI
{
public struct Fonts
{
public SpriteFont small; //Text fonts
public SpriteFont basic;
public SpriteFont title;
}
internal static class Utilities
{
/// <summary>
@ -37,5 +45,18 @@ namespace Galactic_Colors_Control_GUI
}
}
}
public static bool DoubleTo(ref double value, double target, double speed)
{
speed = Math.Abs(speed);
bool up = value < target;
value += (up ? 1 : -1) * speed;
if ((up && value >= target) || (!up && value <= target))
{
value = target;
return true;
}
return false;
}
}
}

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Galactic Colors Control Server", "Galactic Colors Control Server\Galactic Colors Control Server.csproj", "{9E3AF4E1-88C6-4139-A15C-B4F633E80612}"
ProjectSection(ProjectDependencies) = postProject
@ -15,6 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Galactic Colors Control", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Galactic Colors Control GUI", "Galactic Colors Control GUI\Galactic Colors Control GUI.csproj", "{F6CDDF1B-5A57-4A84-B57C-749FFF9AE031}"
ProjectSection(ProjectDependencies) = postProject
{022A69CE-22B5-4934-BE9F-A9C6DF9557ED} = {022A69CE-22B5-4934-BE9F-A9C6DF9557ED}
{93582CE8-C8C8-4E19-908B-D671ECBADE25} = {93582CE8-C8C8-4E19-908B-D671ECBADE25}
EndProjectSection
EndProject

View File

@ -208,16 +208,16 @@ namespace Galactic_Colors_Control
/// <returns>Send success</returns>
private bool Send(Data packet)
{
try
{
//try
//{
ClientSocket.Send(packet.ToBytes());
return true;
}
/*}
catch //Can't contact server
{
_errorCount++;
}
return false;
return false;*/
}
/// <summary>