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;
58 AvailableNetworkSessionCollection availableSessions;
60 int selectedSessionIndex;
62 private enum lobbyState
70 lobbyState currentState;
74 currentState = lobbyState.Welcome;
75 selectedSessionIndex = 0;
79 public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)
81 background = contentManager.Load<Texture2D>("background");
82 spotLight = contentManager.Load<Texture2D>("spotlight");
83 cs = contentManager.Load<Texture2D>("cs");
84 selectGameScreen = contentManager.Load<Texture2D>("selectGameScreen");
85 backgroundPos = new Vector2(0f, 0f);
86 spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98);
87 spotLightCenter = new Vector2(800f, 800f);
88 spotLightVelocity = new Vector2(-100, 33);
89 csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98);
91 zero = new Vector2(0, 0);
93 MaxX = graphics.GraphicsDevice.Viewport.Width;
95 MaxY = graphics.GraphicsDevice.Viewport.Height;
101 checkedBox = contentManager.Load<Texture2D>("checkedBox");
102 deselectBox = contentManager.Load<Texture2D>("deselectBox");
103 emptySelectBox = contentManager.Load<Texture2D>("emptySelectBox");
104 menuItem = contentManager.Load<Texture2D>("menuItem");
109 menuFont = contentManager.Load<SpriteFont>("menuFont");
110 createGamePos = new Vector2(100f, MaxY / 3);
111 createGameText = "Create Game";
112 selected = createGameText;
114 findGamePos = new Vector2(100f, (MaxY / 3) + 60);
115 findGameText = "Find Game";
117 returnToMainPos = new Vector2(MaxX / 2, MaxY - 120);
118 returnToMainText = "press [ X ] to return to main menu";
123 public void UnloadContent()
128 public long Update(GameTime gameTime, NetworkGame networkGame)
131 UpdateSpotLight(gameTime);
132 currentKeyboardState = Keyboard.GetState();
134 if (networkGame.sessionExists())
136 players = networkGame.LocalGamers;
140 switch (currentState)
142 case lobbyState.Welcome:
143 if (selected == createGameText)
145 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
146 currentState = lobbyState.CreateGame;
147 if (currentKeyboardState.IsKeyDown(Keys.Down))
148 selected = findGameText;
152 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
153 currentState = lobbyState.FindGame;
154 if (currentKeyboardState.IsKeyDown(Keys.Up))
155 selected = createGameText;
159 case lobbyState.CreateGame:
160 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
162 currentState = lobbyState.Welcome;
164 if (networkGame.sessionExists())
167 networkGame.LeaveSession();
170 if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y))
172 currentState = lobbyState.Connected;
173 networkGame.CreateSession(4);
177 case lobbyState.FindGame:
178 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
180 currentState = lobbyState.Welcome;
183 availableSessions = networkGame.FindSessions();
184 if (availableSessions != null)
186 networkGame.JoinSession(availableSessions[0]);
187 currentState = lobbyState.Connected;
191 case lobbyState.Connected:
192 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
195 if (networkGame.sessionExists())
198 networkGame.LeaveSession();
200 currentState = lobbyState.Welcome;
202 if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R))
205 if (networkGame.sessionExists())
207 players = networkGame.LocalGamers;
210 currentState = lobbyState.Welcome;
216 previousKeyboardState = Keyboard.GetState();
222 /// Draws the lobby GUI. Has different states for difference menu configurations
224 public long Draw(SpriteBatch spriteBatch)
226 spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);
227 spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
228 spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);
230 switch (currentState)
232 case lobbyState.Welcome:
233 spriteBatch.DrawString(menuFont, "press [ Home ] to login", new Vector2(350, 20), Color.LightGray, 0f, zero, .6f, SpriteEffects.None, 0.5f);
234 if (selected == createGameText)
235 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
237 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f);
238 if (selected == findGameText)
239 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
241 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
244 case lobbyState.CreateGame:
245 DrawPlayerList(spriteBatch);
246 spriteBatch.DrawString(menuFont, "You are now the Host!", new Vector2(MaxX / 2, MaxY / 3), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f);
247 spriteBatch.DrawString(menuFont, "press: Y to continue", new Vector2(MaxX /2, (MaxY / 3) + menuFont.LineSpacing), Color.White, 0f, zero, .6f, SpriteEffects.None, 0.5f);
248 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);
252 case lobbyState.FindGame:
253 spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);
254 if(availableSessions == null)
255 spriteBatch.DrawString(menuFont, "searching for available games ....", new Vector2(150, 100), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f);
256 else if (availableSessions.Count == 0)
257 spriteBatch.DrawString(menuFont, "no games currently available, searching ....", new Vector2(150, 100), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f);
260 for (int sessionIndex = 0; sessionIndex < availableSessions.Count; sessionIndex++)
262 Color color = Color.Gray;
264 if (sessionIndex == selectedSessionIndex)
267 spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].HostGamertag, new Vector2(150, 100 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f);
268 spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].CurrentGamerCount + " / " + availableSessions[sessionIndex].OpenPublicGamerSlots + availableSessions[sessionIndex].OpenPrivateGamerSlots,
269 new Vector2(400, 100 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f);
274 case lobbyState.Connected:
275 DrawPlayerList(spriteBatch);
276 spriteBatch.DrawString(menuFont, "Waiting for ready players...", new Vector2(MaxX / 2, MaxY / 2), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f);
283 private void UpdateSpotLight(GameTime gameTime)
285 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
286 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
288 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
290 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
292 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
294 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);
299 private void DrawPlayerList(SpriteBatch spriteBatch)
303 Vector2 topOfList = new Vector2(MaxX / 8, MaxY / 4);
306 spriteBatch.DrawString(menuFont, "Current Players", new Vector2(topOfList.X + 15, topOfList.Y - 25), Color.White);
307 spriteBatch.DrawString(menuFont, "Command Options: to mark your self as ready", new Vector2(20, 20), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
308 spriteBatch.DrawString(menuFont, "type players # to toggle chat", new Vector2(175, 40), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
309 spriteBatch.DrawString(menuFont, "return to main menu", new Vector2(175, 60), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
310 spriteBatch.DrawString(menuFont, "R", new Vector2(145, 20), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
311 spriteBatch.DrawString(menuFont, "#", new Vector2(145, 40), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
312 spriteBatch.DrawString(menuFont, "X", new Vector2(145, 60), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
315 spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
318 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
320 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
322 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
324 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
325 Boolean chatwith = false; // change to reflect info from network, move to update and create one for each player
327 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X +218, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
329 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
332 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 65), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
333 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
335 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
337 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
339 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
340 // change to reflect info from network
342 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
344 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
347 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 130), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
348 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
350 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
352 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
354 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
357 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
359 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
362 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 195), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
363 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
365 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
367 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
369 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
371 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
373 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
379 for (int g = 0; g < players.Count; g++)
381 spriteBatch.DrawString(menuFont, players[g].Gamertag, new Vector2(topOfList.X + 10, topOfList.Y + 10 + 65*g), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);