]> Dogcows Code - chaz/carfire/blob - Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs
Added to functionality of gui. Also added 2 methods I needed in NetworkGame, comments...
[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
59
60 private enum lobbyState
61 {
62 Welcome,
63 CreateGame,
64 FindGame,
65 Connected
66 }
67
68 lobbyState currentState;
69
70 public lobbyGUI()
71 {
72 currentState = lobbyState.Welcome;
73 }
74
75 public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)
76 {
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);
86
87 zero = new Vector2(0, 0);
88
89 MaxX = graphics.GraphicsDevice.Viewport.Width;
90 MinX = 0;
91 MaxY = graphics.GraphicsDevice.Viewport.Height;
92 MinY = 100;
93
94 scale = MaxX / 1600f;
95 //playerlist stuff
96 checkedBox = contentManager.Load<Texture2D>("checkedBox");
97 deselectBox = contentManager.Load<Texture2D>("deselectBox");
98 emptySelectBox = contentManager.Load<Texture2D>("emptySelectBox");
99 menuItem = contentManager.Load<Texture2D>("menuItem");
100
101 ready = false;
102
103 //menu fonts
104 menuFont = contentManager.Load<SpriteFont>("menuFont");
105 createGamePos = new Vector2(100f, MaxY / 3);
106 createGameText = "Create Game";
107 selected = createGameText;
108
109 findGamePos = new Vector2(100f, (MaxY / 3) + 60);
110 findGameText = "Find Game";
111
112 returnToMainPos = new Vector2(MaxX / 2, MaxY - 120);
113 returnToMainText = "press [ X ] to return to main menu";
114
115
116 }
117
118 public void UnloadContent()
119 {
120
121 }
122
123 public long Update(GameTime gameTime, NetworkGame networkGame)
124 {
125
126 UpdateSpotLight(gameTime);
127 currentKeyboardState = Keyboard.GetState();
128
129 //check inputs
130 switch (currentState)
131 {
132 case lobbyState.Welcome:
133 if (selected == createGameText)
134 {
135 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
136 currentState = lobbyState.CreateGame;
137 if (currentKeyboardState.IsKeyDown(Keys.Down))
138 selected = findGameText;
139 }
140 else
141 {
142 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
143 currentState = lobbyState.FindGame;
144 if (currentKeyboardState.IsKeyDown(Keys.Up))
145 selected = createGameText;
146 }
147 break;
148 case lobbyState.CreateGame:
149 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
150 {
151 currentState = lobbyState.Welcome;
152 ready = false;
153 networkGame.LeaveSession();
154 }
155 if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y))
156 {
157 currentState = lobbyState.Connected;
158 networkGame.CreateSession(4);
159 players = networkGame.LocalGamers;
160 }
161 break;
162 case lobbyState.FindGame:
163 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
164 {
165 currentState = lobbyState.Welcome;
166 ready = false;
167 }
168
169 break;
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))
174 ready = true;
175 break;
176
177 }
178 previousKeyboardState = Keyboard.GetState();
179
180 return 1;
181 }
182
183 /// <summary>
184 /// Draws the lobby GUI. Has different states for difference menu configurations
185 /// </summary>
186 public long Draw(SpriteBatch spriteBatch)
187 {
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);
191
192 switch (currentState)
193 {
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);
198 else
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);
202 else
203 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
204 break;
205
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);
211
212 break;
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);
216
217 //spriteBatch.DrawString(menuFont, returnToMainText, returnToMainPos, Color.Gray, 0, new Vector2(180 , 0), .6f, SpriteEffects.None, 0.5f);
218 break;
219 case lobbyState.Connected:
220 DrawPlayerList(spriteBatch);
221 break;
222 }
223
224 return 1;
225 }
226
227 private void UpdateSpotLight(GameTime gameTime)
228 {
229 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
230 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
231
232 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
233 {
234 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
235 }
236 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
237 {
238 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);
239 }
240 }
241
242
243 private void DrawPlayerList(SpriteBatch spriteBatch)
244 {
245
246 //reference point
247 Vector2 topOfList = new Vector2(MaxX / 8, MaxY / 4);
248
249 //command info
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);
257
258
259 spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
260
261 //player 1
262 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
263 if(!ready)
264 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
265 else
266 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
267
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
270 if (!chatwith)
271 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X +218, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
272 else
273 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
274
275 //player 2
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);
278 if (!ready)
279 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
280 else
281 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
282
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
285 if (!chatwith)
286 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
287 else
288 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
289
290 //player 3
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);
293 if (!ready)
294 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
295 else
296 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
297
298 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
299
300 if (!chatwith)
301 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
302 else
303 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
304
305 //player 4
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);
308 if (!ready)
309 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
310 else
311 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
312
313 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
314 if (!chatwith)
315 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
316 else
317 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
318
319
320 //draw player names
321 if (players != null)
322 {
323 for (int g = 0; g < players.Count; g++)
324 {
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);
326 }
327 }
328
329 //top player
330 }
331 }
332 }
This page took 0.04624 seconds and 4 git commands to generate.