]> Dogcows Code - chaz/carfire/blob - Project06/lobbyTest/lobbyTest/LobbyGUI.cs
player list graphics and stuff added
[chaz/carfire] / Project06 / lobbyTest / lobbyTest / LobbyGUI.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework.Content;
6 using Microsoft.Xna.Framework.Input;
7 using Microsoft.Xna.Framework;
8 using Microsoft.Xna.Framework.Graphics;
9
10 namespace lobbyTest
11 {
12 public class lobbyGUI
13 {
14 float scale;
15
16 Texture2D background;
17 Texture2D spotLight;
18 Texture2D cs;
19 Texture2D selectGameScreen;
20
21 Vector2 backgroundPos;
22 Vector2 spotLightPos;
23 Vector2 spotLightCenter;
24 Vector2 csPos;
25
26 Vector2 zero;
27 Vector2 spotLightVelocity;
28
29 int MaxX;
30 int MinX;
31 int MaxY;
32 int MinY;
33
34 Texture2D checkedBox;
35 Texture2D deselectBox;
36 Texture2D emptySelectBox;
37 Texture2D menuItem;
38
39 Boolean ready;
40
41 SpriteFont menuFont;
42 string selected;
43 Vector2 createGamePos;
44 string createGameText;
45 Vector2 findGamePos;
46 string findGameText;
47
48 Vector2 returnToMainPos;
49 string returnToMainText;
50
51 KeyboardState previousKeyboardState;
52 KeyboardState currentKeyboardState;
53
54 private enum lobbyState
55 {
56 Welcome,
57 CreateGame,
58 FindGame,
59 Connected
60 }
61
62 lobbyState currentState;
63
64 public lobbyGUI()
65 {
66 currentState = lobbyState.Welcome;
67 }
68
69 public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)
70 {
71 background = contentManager.Load<Texture2D>("background");
72 spotLight = contentManager.Load<Texture2D>("spotlight");
73 cs = contentManager.Load<Texture2D>("cs");
74 selectGameScreen = contentManager.Load<Texture2D>("selectGameScreen");
75 backgroundPos = new Vector2(0f, 0f);
76 spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98);
77 spotLightCenter = new Vector2(800f, 800f);
78 spotLightVelocity = new Vector2(-100, 33);
79 csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98);
80
81 zero = new Vector2(0, 0);
82
83 MaxX = graphics.GraphicsDevice.Viewport.Width;
84 MinX = 0;
85 MaxY = graphics.GraphicsDevice.Viewport.Height;
86 MinY = 100;
87
88 scale = MaxX / 1600f;
89 //playerlist stuff
90 checkedBox = contentManager.Load<Texture2D>("checkedBox");
91 deselectBox = contentManager.Load<Texture2D>("deselectBox");
92 emptySelectBox = contentManager.Load<Texture2D>("emptySelectBox");
93 menuItem = contentManager.Load<Texture2D>("menuItem");
94
95 ready = false;
96
97 //menu fonts
98 menuFont = contentManager.Load<SpriteFont>("menuFont");
99 createGamePos = new Vector2(100f, MaxY / 3);
100 createGameText = "Create Game";
101 selected = createGameText;
102
103 findGamePos = new Vector2(100f, (MaxY / 3) + 60);
104 findGameText = "Find Game";
105
106 returnToMainPos = new Vector2(MaxX / 2, MaxY - 120);
107 returnToMainText = "press [ X ] to return to main menu";
108
109
110 }
111
112 public void UnloadContent()
113 {
114
115 }
116
117 public long Update(GameTime gameTime)
118 {
119 UpdateSpotLight(gameTime);
120 currentKeyboardState = Keyboard.GetState();
121 //check inputs
122 switch (currentState)
123 {
124 case lobbyState.Welcome:
125 if (selected == createGameText)
126 {
127 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
128 currentState = lobbyState.CreateGame;
129 if (currentKeyboardState.IsKeyDown(Keys.Down))
130 selected = findGameText;
131 }
132 else
133 {
134 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
135 currentState = lobbyState.FindGame;
136 if (currentKeyboardState.IsKeyDown(Keys.Up))
137 selected = createGameText;
138 }
139 break;
140 case lobbyState.CreateGame:
141 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
142 {
143 currentState = lobbyState.Welcome;
144 ready = false;
145 }
146 if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R))
147 ready = true;
148 break;
149 case lobbyState.FindGame:
150 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
151 {
152 currentState = lobbyState.Welcome;
153 ready = false;
154 }
155
156 break;
157 case lobbyState.Connected:
158 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
159 currentState = lobbyState.Welcome;
160 if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R))
161 ready = true;
162 break;
163
164 }
165 previousKeyboardState = Keyboard.GetState();
166
167 return 1;
168 }
169
170 /// <summary>
171 /// Draws the lobby GUI. Has different states for difference menu configurations
172 /// </summary>
173 public long Draw(SpriteBatch spriteBatch)
174 {
175 spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);
176 spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
177 spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);
178 switch (currentState)
179 {
180 case lobbyState.Welcome:
181 spriteBatch.DrawString(menuFont, "press [ Home ] to login", new Vector2(350, 20), Color.LightGray, 0f, zero, .6f, SpriteEffects.None, 0.5f);
182 if (selected == createGameText)
183 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
184 else
185 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f);
186 if (selected == findGameText)
187 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
188 else
189 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
190 break;
191
192 case lobbyState.CreateGame:
193 DrawPlayerList(spriteBatch);
194
195 break;
196 case lobbyState.FindGame:
197 spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);
198 //spriteBatch.DrawString(menuFont, "Select Game", new Vector2(100, 100), Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
199
200 //spriteBatch.DrawString(menuFont, returnToMainText, returnToMainPos, Color.Gray, 0, new Vector2(180 , 0), .6f, SpriteEffects.None, 0.5f);
201 break;
202 case lobbyState.Connected:
203 DrawPlayerList(spriteBatch);
204 break;
205 }
206
207 return 1;
208 }
209
210 private void UpdateSpotLight(GameTime gameTime)
211 {
212 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
213 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
214
215 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
216 {
217 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
218 }
219 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
220 {
221 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);
222 }
223 }
224
225
226 private void DrawPlayerList(SpriteBatch spriteBatch)
227 {
228
229 Vector2 topOfList = new Vector2(MaxX / 8, MaxY / 4);
230 spriteBatch.DrawString(menuFont, "Current Players", new Vector2(topOfList.X + 15, topOfList.Y - 25), Color.White);
231
232 //top player
233 spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
234 spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 10), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);
235 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
236 if(!ready)
237 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
238 else
239 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
240
241 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
242 Boolean chatwith = false; // change to reflect info from network, move to update and create one for each player
243 if (!chatwith)
244 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X +218, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
245 else
246 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
247
248 //player 2
249 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 65), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
250 spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 75), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);
251 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
252 if (!ready)
253 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
254 else
255 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
256
257 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
258 // change to reflect info from network
259 if (!chatwith)
260 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
261 else
262 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
263
264 //player 3
265 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 130), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
266 spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 140), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);
267 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
268 if (!ready)
269 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
270 else
271 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
272
273 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
274
275 if (!chatwith)
276 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
277 else
278 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
279
280 //player 4
281 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 195), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
282 spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 205), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);
283 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
284 if (!ready)
285 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
286 else
287 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
288
289 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
290 if (!chatwith)
291 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
292 else
293 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
294
295 }
296 }
297 }
This page took 0.043782 seconds and 4 git commands to generate.