]> Dogcows Code - chaz/carfire/blob - Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs
516a85a1302e44abb64c5212d35d0d4bb692383b
[chaz/carfire] / Project06 / CS 3505 Project 06 / CS 3505 Project 06 / LobbyGUI.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
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;
12
13 namespace CS_3505_Project_06
14 {
15 public class lobbyGUI : ILobby
16 {
17 float scale;
18
19 Texture2D background;
20 Texture2D spotLight;
21 Texture2D cs;
22 Texture2D selectGameScreen;
23
24 Vector2 backgroundPos;
25 Vector2 spotLightPos;
26 Vector2 spotLightCenter;
27 Vector2 csPos;
28
29 Vector2 zero;
30 Vector2 spotLightVelocity;
31
32 int MaxX;
33 int MinX;
34 int MaxY;
35 int MinY;
36
37 Texture2D checkedBox;
38 Texture2D deselectBox;
39 Texture2D emptySelectBox;
40 Texture2D menuItem;
41
42 Boolean ready;
43
44 SpriteFont menuFont;
45 string selected;
46 Vector2 createGamePos;
47 string createGameText;
48 Vector2 findGamePos;
49 string findGameText;
50
51 Vector2 returnToMainPos;
52 string returnToMainText;
53
54 KeyboardState previousKeyboardState;
55 KeyboardState currentKeyboardState;
56
57 GamerCollection<LocalNetworkGamer> players;
58 AvailableNetworkSessionCollection availableSessions;
59
60 int selectedSessionIndex;
61
62 private enum lobbyState
63 {
64 Welcome,
65 CreateGame,
66 FindGame,
67 Connected
68 }
69
70 lobbyState currentState;
71
72 public lobbyGUI()
73 {
74 currentState = lobbyState.Welcome;
75 selectedSessionIndex = 0;
76 ready = false;
77 }
78
79 public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)
80 {
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);
90
91 zero = new Vector2(0, 0);
92
93 MaxX = graphics.GraphicsDevice.Viewport.Width;
94 MinX = 0;
95 MaxY = graphics.GraphicsDevice.Viewport.Height;
96 MinY = 100;
97
98 scale = MaxX / 1600f;
99
100 //playerlist stuff
101 checkedBox = contentManager.Load<Texture2D>("checkedBox");
102 deselectBox = contentManager.Load<Texture2D>("deselectBox");
103 emptySelectBox = contentManager.Load<Texture2D>("emptySelectBox");
104 menuItem = contentManager.Load<Texture2D>("menuItem");
105
106
107
108 //menu fonts
109 menuFont = contentManager.Load<SpriteFont>("menuFont");
110 createGamePos = new Vector2(100f, MaxY / 3);
111 createGameText = "Create Game";
112 selected = createGameText;
113
114 findGamePos = new Vector2(100f, (MaxY / 3) + 60);
115 findGameText = "Find Game";
116
117 returnToMainPos = new Vector2(MaxX / 2, MaxY - 120);
118 returnToMainText = "press [ X ] to return to main menu";
119
120
121 }
122
123 public void UnloadContent()
124 {
125
126 }
127
128 public long Update(GameTime gameTime, NetworkGame networkGame)
129 {
130
131 UpdateSpotLight(gameTime);
132 currentKeyboardState = Keyboard.GetState();
133
134 if (networkGame.sessionExists())
135 {
136 players = networkGame.LocalGamers;
137 }
138
139 //check inputs
140 switch (currentState)
141 {
142 case lobbyState.Welcome:
143 if (selected == createGameText)
144 {
145 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
146 currentState = lobbyState.CreateGame;
147 if (currentKeyboardState.IsKeyDown(Keys.Down))
148 selected = findGameText;
149 }
150 else
151 {
152 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
153 currentState = lobbyState.FindGame;
154 if (currentKeyboardState.IsKeyDown(Keys.Up))
155 selected = createGameText;
156 }
157 break;
158
159 case lobbyState.CreateGame:
160 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
161 {
162 currentState = lobbyState.Welcome;
163 ready = false;
164 if (networkGame.sessionExists())
165 {
166 players = null;
167 networkGame.LeaveSession();
168 }
169 }
170 if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y))
171 {
172 currentState = lobbyState.Connected;
173 networkGame.CreateSession(4);
174 players = networkGame.LocalGamers;
175 }
176 break;
177
178 case lobbyState.FindGame:
179 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
180 {
181 currentState = lobbyState.Welcome;
182 ready = false;
183 }
184 availableSessions = networkGame.FindSessions();
185
186 break;
187
188 case lobbyState.Connected:
189 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
190 {
191 ready = false;
192 if (networkGame.sessionExists())
193 {
194 players = null;
195 networkGame.LeaveSession();
196 }
197 currentState = lobbyState.Welcome;
198 }
199 if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R))
200 ready = true;
201 break;
202
203 }
204 previousKeyboardState = Keyboard.GetState();
205
206 return 1;
207 }
208
209 /// <summary>
210 /// Draws the lobby GUI. Has different states for difference menu configurations
211 /// </summary>
212 public long Draw(SpriteBatch spriteBatch)
213 {
214 spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);
215 spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
216 spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);
217
218 switch (currentState)
219 {
220 case lobbyState.Welcome:
221 spriteBatch.DrawString(menuFont, "press [ Home ] to login", new Vector2(350, 20), Color.LightGray, 0f, zero, .6f, SpriteEffects.None, 0.5f);
222 if (selected == createGameText)
223 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
224 else
225 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f);
226 if (selected == findGameText)
227 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
228 else
229 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
230 break;
231
232 case lobbyState.CreateGame:
233 DrawPlayerList(spriteBatch);
234 spriteBatch.DrawString(menuFont, "You are now the Host!", new Vector2(MaxX / 2, MaxY / 3), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f);
235 spriteBatch.DrawString(menuFont, "press: Y to continue", new Vector2(MaxX /2, (MaxY / 3) + menuFont.LineSpacing), Color.White, 0f, zero, .6f, SpriteEffects.None, 0.5f);
236 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);
237
238 break;
239
240 case lobbyState.FindGame:
241 spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);
242 if(availableSessions == null)
243 spriteBatch.DrawString(menuFont, "searching for available games ....", new Vector2(150, 100), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f);
244 else if (availableSessions.Count == 0)
245 spriteBatch.DrawString(menuFont, "no games currently available, searching ....", new Vector2(150, 100), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f);
246 else
247 {
248 for (int sessionIndex = 0; sessionIndex < availableSessions.Count; sessionIndex++)
249 {
250 Color color = Color.Gray;
251
252 if (sessionIndex == selectedSessionIndex)
253 color = Color.Red;
254
255 spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].HostGamertag, new Vector2(150, 100 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f);
256 spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].CurrentGamerCount + " / " + availableSessions[sessionIndex].OpenPublicGamerSlots, new Vector2(400, 300 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f);
257 spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].QualityOfService + "", new Vector2(350, 100 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f);
258 }
259 }
260 break;
261
262 case lobbyState.Connected:
263 DrawPlayerList(spriteBatch);
264 spriteBatch.DrawString(menuFont, "Waiting for ready players...", new Vector2(MaxX / 2, MaxY / 2), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f);
265 break;
266 }
267
268 return 1;
269 }
270
271 private void UpdateSpotLight(GameTime gameTime)
272 {
273 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
274 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
275
276 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
277 {
278 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
279 }
280 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
281 {
282 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);
283 }
284 }
285
286
287 private void DrawPlayerList(SpriteBatch spriteBatch)
288 {
289
290 //reference point
291 Vector2 topOfList = new Vector2(MaxX / 8, MaxY / 4);
292
293 //command info
294 spriteBatch.DrawString(menuFont, "Current Players", new Vector2(topOfList.X + 15, topOfList.Y - 25), Color.White);
295 spriteBatch.DrawString(menuFont, "Command Options: to mark your self as ready", new Vector2(20, 20), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
296 spriteBatch.DrawString(menuFont, "type players # to toggle chat", new Vector2(175, 40), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
297 spriteBatch.DrawString(menuFont, "return to main menu", new Vector2(175, 60), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
298 spriteBatch.DrawString(menuFont, "R", new Vector2(145, 20), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
299 spriteBatch.DrawString(menuFont, "#", new Vector2(145, 40), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
300 spriteBatch.DrawString(menuFont, "X", new Vector2(145, 60), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
301
302
303 spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
304
305 //player 1
306 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
307 if(!ready)
308 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
309 else
310 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
311
312 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
313 Boolean chatwith = false; // change to reflect info from network, move to update and create one for each player
314 if (!chatwith)
315 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X +218, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
316 else
317 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
318
319 //player 2
320 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 65), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
321 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
322 if (!ready)
323 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
324 else
325 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
326
327 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
328 // change to reflect info from network
329 if (!chatwith)
330 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
331 else
332 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
333
334 //player 3
335 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 130), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
336 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
337 if (!ready)
338 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
339 else
340 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
341
342 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
343
344 if (!chatwith)
345 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
346 else
347 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
348
349 //player 4
350 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 195), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
351 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
352 if (!ready)
353 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
354 else
355 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
356
357 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
358 if (!chatwith)
359 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
360 else
361 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
362
363
364 //draw player names
365 if (players != null)
366 {
367 for (int g = 0; g < players.Count; g++)
368 {
369 spriteBatch.DrawString(menuFont, players[g].Gamertag, new Vector2(topOfList.X + 10, topOfList.Y + 10 + 65*g), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);
370 }
371 }
372 }
373 }
374 }
This page took 0.04585 seconds and 3 git commands to generate.