2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework.Net;
6 using System.Diagnostics;
7 using Microsoft.Xna.Framework.GamerServices;
8 using Microsoft.Xna.Framework.Graphics;
9 using Microsoft.Xna.Framework;
10 using Microsoft.Xna.Framework.Input;
11 using Microsoft.Xna.Framework.Content;
13 namespace CS_3505_Project_06
15 public class lobbyGUI : ILobby
22 Texture2D selectGameScreen;
24 Vector2 backgroundPos;
26 Vector2 spotLightCenter;
30 Vector2 spotLightVelocity;
38 Texture2D deselectBox;
39 Texture2D emptySelectBox;
46 Vector2 createGamePos;
47 string createGameText;
51 Vector2 returnToMainPos;
52 string returnToMainText;
54 KeyboardState previousKeyboardState;
55 KeyboardState currentKeyboardState;
57 GamerCollection<LocalNetworkGamer> players;
60 private enum lobbyState
68 lobbyState currentState;
72 currentState = lobbyState.Welcome;
75 public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)
77 background = contentManager.Load<Texture2D>("background");
78 spotLight = contentManager.Load<Texture2D>("spotlight");
79 cs = contentManager.Load<Texture2D>("cs");
80 selectGameScreen = contentManager.Load<Texture2D>("selectGameScreen");
81 backgroundPos = new Vector2(0f, 0f);
82 spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98);
83 spotLightCenter = new Vector2(800f, 800f);
84 spotLightVelocity = new Vector2(-100, 33);
85 csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98);
87 zero = new Vector2(0, 0);
89 MaxX = graphics.GraphicsDevice.Viewport.Width;
91 MaxY = graphics.GraphicsDevice.Viewport.Height;
96 checkedBox = contentManager.Load<Texture2D>("checkedBox");
97 deselectBox = contentManager.Load<Texture2D>("deselectBox");
98 emptySelectBox = contentManager.Load<Texture2D>("emptySelectBox");
99 menuItem = contentManager.Load<Texture2D>("menuItem");
104 menuFont = contentManager.Load<SpriteFont>("menuFont");
105 createGamePos = new Vector2(100f, MaxY / 3);
106 createGameText = "Create Game";
107 selected = createGameText;
109 findGamePos = new Vector2(100f, (MaxY / 3) + 60);
110 findGameText = "Find Game";
112 returnToMainPos = new Vector2(MaxX / 2, MaxY - 120);
113 returnToMainText = "press [ X ] to return to main menu";
118 public void UnloadContent()
123 public long Update(GameTime gameTime, NetworkGame networkGame)
126 UpdateSpotLight(gameTime);
127 currentKeyboardState = Keyboard.GetState();
130 switch (currentState)
132 case lobbyState.Welcome:
133 if (selected == createGameText)
135 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
136 currentState = lobbyState.CreateGame;
137 if (currentKeyboardState.IsKeyDown(Keys.Down))
138 selected = findGameText;
142 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
143 currentState = lobbyState.FindGame;
144 if (currentKeyboardState.IsKeyDown(Keys.Up))
145 selected = createGameText;
148 case lobbyState.CreateGame:
149 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
151 currentState = lobbyState.Welcome;
153 networkGame.LeaveSession();
155 if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y))
157 currentState = lobbyState.Connected;
158 networkGame.CreateSession(4);
159 players = networkGame.LocalGamers;
162 case lobbyState.FindGame:
163 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
165 currentState = lobbyState.Welcome;
170 case lobbyState.Connected:
171 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
172 currentState = lobbyState.Welcome;
173 if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R))
178 previousKeyboardState = Keyboard.GetState();
184 /// Draws the lobby GUI. Has different states for difference menu configurations
186 public long Draw(SpriteBatch spriteBatch)
188 spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);
189 spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
190 spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);
192 switch (currentState)
194 case lobbyState.Welcome:
195 spriteBatch.DrawString(menuFont, "press [ Home ] to login", new Vector2(350, 20), Color.LightGray, 0f, zero, .6f, SpriteEffects.None, 0.5f);
196 if (selected == createGameText)
197 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
199 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f);
200 if (selected == findGameText)
201 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
203 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
206 case lobbyState.CreateGame:
207 DrawPlayerList(spriteBatch);
208 spriteBatch.DrawString(menuFont, "You are now the Host!", new Vector2(MaxX / 2, MaxY / 3), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f);
209 spriteBatch.DrawString(menuFont, "press: Y to continue", new Vector2(MaxX /2, (MaxY / 3) + menuFont.LineSpacing), Color.White, 0f, zero, .6f, SpriteEffects.None, 0.5f);
210 spriteBatch.DrawString(menuFont, "X to return to main menu", new Vector2(MaxX /2 + 40, (MaxY / 3) + 2 * menuFont.LineSpacing), Color.White, 0f, zero, .6f, SpriteEffects.None, 0.5f);
213 case lobbyState.FindGame:
214 spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);
215 //spriteBatch.DrawString(menuFont, "Select Game", new Vector2(100, 100), Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
217 //spriteBatch.DrawString(menuFont, returnToMainText, returnToMainPos, Color.Gray, 0, new Vector2(180 , 0), .6f, SpriteEffects.None, 0.5f);
219 case lobbyState.Connected:
220 DrawPlayerList(spriteBatch);
227 private void UpdateSpotLight(GameTime gameTime)
229 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
230 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
232 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
234 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
236 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
238 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);
243 private void DrawPlayerList(SpriteBatch spriteBatch)
247 Vector2 topOfList = new Vector2(MaxX / 8, MaxY / 4);
250 spriteBatch.DrawString(menuFont, "Current Players", new Vector2(topOfList.X + 15, topOfList.Y - 25), Color.White);
251 spriteBatch.DrawString(menuFont, "Command Options: to mark your self as ready", new Vector2(20, 20), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
252 spriteBatch.DrawString(menuFont, "type players # to toggle chat", new Vector2(175, 40), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
253 spriteBatch.DrawString(menuFont, "return to main menu", new Vector2(175, 60), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
254 spriteBatch.DrawString(menuFont, "R", new Vector2(145, 20), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
255 spriteBatch.DrawString(menuFont, "#", new Vector2(145, 40), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
256 spriteBatch.DrawString(menuFont, "X", new Vector2(145, 60), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
259 spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
262 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
264 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
266 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
268 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
269 Boolean chatwith = false; // change to reflect info from network, move to update and create one for each player
271 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X +218, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
273 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
276 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 65), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
277 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
279 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
281 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
283 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
284 // change to reflect info from network
286 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
288 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
291 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 130), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
292 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
294 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
296 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
298 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
301 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
303 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
306 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 195), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
307 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
309 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
311 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
313 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
315 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
317 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
323 for (int g = 0; g < players.Count; g++)
325 spriteBatch.DrawString(menuFont, players[g].Gamertag, new Vector2(topOfList.X + 10, topOfList.Y + 10 + 65*g), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);