]> Dogcows Code - chaz/carfire/blob - Project06/lobbyTest/lobbyTest/LobbyGUI.cs
Some basic text added to create game screen
[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 spriteBatch.DrawString(menuFont, "Command Options: to mark your self as ready", new Vector2(20, 20), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
232 spriteBatch.DrawString(menuFont, "type players # to toggle chat", new Vector2(175, 40), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
233 spriteBatch.DrawString(menuFont, "return to main menu", new Vector2(175, 60), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);
234 spriteBatch.DrawString(menuFont, "R", new Vector2(145, 20), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
235 spriteBatch.DrawString(menuFont, "#", new Vector2(145, 40), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
236 spriteBatch.DrawString(menuFont, "X", new Vector2(145, 60), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);
237
238 //top player
239 spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
240 spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 10), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);
241 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
242 if(!ready)
243 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
244 else
245 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
246
247 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
248 Boolean chatwith = false; // change to reflect info from network, move to update and create one for each player
249 if (!chatwith)
250 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X +218, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
251 else
252 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
253
254 //player 2
255 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 65), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
256 spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 75), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);
257 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
258 if (!ready)
259 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
260 else
261 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
262
263 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
264 // change to reflect info from network
265 if (!chatwith)
266 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
267 else
268 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
269
270 //player 3
271 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 130), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
272 spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 140), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);
273 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
274 if (!ready)
275 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
276 else
277 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
278
279 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
280
281 if (!chatwith)
282 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
283 else
284 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
285
286 //player 4
287 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 195), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
288 spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 205), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);
289 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
290 if (!ready)
291 spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
292 else
293 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
294
295 spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);
296 if (!chatwith)
297 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
298 else
299 spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);
300
301 }
302 }
303 }
This page took 0.04339 seconds and 4 git commands to generate.