using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace lobbyTest { public class lobbyGUI { Texture2D background; Texture2D spotLight; Texture2D cs; Texture2D selectGameScreen; Vector2 backgroundPos; Vector2 spotLightPos; Vector2 spotLightCenter; Vector2 csPos; Vector2 zero; Vector2 spotLightVelocity; int MaxX; int MinX; int MaxY; int MinY; SpriteFont menuFont; string selected; Vector2 createGamePos; string createGameText; Vector2 findGamePos; string findGameText; Vector2 returnToMainPos; string returnToMainText; KeyboardState previousKeyboardState; KeyboardState currentKeyboardState; private enum lobbyState { Welcome, CreateGame, FindGame, Connected } lobbyState currentState; public lobbyGUI() { currentState = lobbyState.Welcome; } public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics) { background = contentManager.Load("background"); spotLight = contentManager.Load("spotlight"); cs = contentManager.Load("cs"); selectGameScreen = contentManager.Load("selectGameScreen"); backgroundPos = new Vector2(0f, 0f); spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98); spotLightCenter = new Vector2(800f, 800f); spotLightVelocity = new Vector2(-100, 33); csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98); zero = new Vector2(0, 0); MaxX = graphics.GraphicsDevice.Viewport.Width; MinX = 0; MaxY = graphics.GraphicsDevice.Viewport.Height; MinY = 100; //menu fonts menuFont = contentManager.Load("menuFont"); createGamePos = new Vector2(100f, MaxY / 3); createGameText = "Create Game"; selected = createGameText; findGamePos = new Vector2(100f, (MaxY / 3) + 60); findGameText = "Find Game"; returnToMainPos = new Vector2(MaxX / 2, MaxY - 120); returnToMainText = "press [ X ] to return to main menu"; } public void UnloadContent() { } public long Update(GameTime gameTime) { UpdateSpotLight(gameTime); currentKeyboardState = Keyboard.GetState(); //check inputs switch (currentState) { case lobbyState.Welcome: if (selected == createGameText) { if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter)) currentState = lobbyState.CreateGame; if (currentKeyboardState.IsKeyDown(Keys.Down)) selected = findGameText; } else { if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter)) currentState = lobbyState.FindGame; if (currentKeyboardState.IsKeyDown(Keys.Up)) selected = createGameText; } break; case lobbyState.CreateGame: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) currentState = lobbyState.Welcome; break; case lobbyState.FindGame: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) currentState = lobbyState.Welcome; break; case lobbyState.Connected: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) currentState = lobbyState.Welcome; break; } previousKeyboardState = Keyboard.GetState(); return 1; } /// /// Draws the lobby GUI. Has different states for difference menu configurations /// public long Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0); spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0); spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0); switch (currentState) { case lobbyState.Welcome: if (selected == createGameText) spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f); else spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f); if (selected == findGameText) spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f); else spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f); break; case lobbyState.CreateGame: break; case lobbyState.FindGame: spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0); //spriteBatch.DrawString(menuFont, "Select Game", new Vector2(100, 100), Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f); //spriteBatch.DrawString(menuFont, returnToMainText, returnToMainPos, Color.Gray, 0, new Vector2(180 , 0), .6f, SpriteEffects.None, 0.5f); break; case lobbyState.Connected: break; } return 1; } private void UpdateSpotLight(GameTime gameTime) { spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds, spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds); if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall { spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y); } else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall { spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1); } } } }