X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FLobbyGUI.cs;h=31ce27bfd6274646daa1a54fa547907b31b34ed5;hp=b902822106940bb69c21a4afef6b9b5b19027245;hb=4e7638512503342a26e131896103c1f28d726dab;hpb=bc3db44f8f717780cce18d5384272f501984e446 diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs b/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs index b902822..31ce27b 100644 --- a/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs +++ b/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs @@ -2,10 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Input; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Net; +using System.Diagnostics; +using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Content; namespace CS_3505_Project_06 { @@ -51,6 +54,11 @@ namespace CS_3505_Project_06 KeyboardState previousKeyboardState; KeyboardState currentKeyboardState; + GamerCollection players; + AvailableNetworkSessionCollection availableSessions; + + int selectedSessionIndex; + private enum lobbyState { Welcome, @@ -64,6 +72,8 @@ namespace CS_3505_Project_06 public lobbyGUI() { currentState = lobbyState.Welcome; + selectedSessionIndex = 0; + ready = false; } public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics) @@ -86,13 +96,14 @@ namespace CS_3505_Project_06 MinY = 100; scale = MaxX / 1600f; + //playerlist stuff checkedBox = contentManager.Load("checkedBox"); deselectBox = contentManager.Load("deselectBox"); emptySelectBox = contentManager.Load("emptySelectBox"); menuItem = contentManager.Load("menuItem"); - ready = false; + //menu fonts menuFont = contentManager.Load("menuFont"); @@ -106,7 +117,7 @@ namespace CS_3505_Project_06 returnToMainPos = new Vector2(MaxX / 2, MaxY - 120); returnToMainText = "press [ X ] to return to main menu"; - + } public void UnloadContent() @@ -116,8 +127,15 @@ namespace CS_3505_Project_06 public long Update(GameTime gameTime, NetworkGame networkGame) { + UpdateSpotLight(gameTime); currentKeyboardState = Keyboard.GetState(); + + if (networkGame.sessionExists()) + { + players = networkGame.LocalGamers; + } + //check inputs switch (currentState) { @@ -137,28 +155,64 @@ namespace CS_3505_Project_06 selected = createGameText; } break; + case lobbyState.CreateGame: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) { currentState = lobbyState.Welcome; ready = false; + if (networkGame.sessionExists()) + { + players = null; + networkGame.LeaveSession(); + } } - if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) - ready = true; + if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y)) + { + currentState = lobbyState.Connected; + networkGame.CreateSession(4); + } break; + case lobbyState.FindGame: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) { currentState = lobbyState.Welcome; ready = false; } + availableSessions = networkGame.FindSessions(); + if (availableSessions != null) + { + networkGame.JoinSession(availableSessions[0]); + currentState = lobbyState.Connected; + availableSessions.Dispose(); + availableSessions = null; + } break; + case lobbyState.Connected: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) + { + ready = false; + if (networkGame.sessionExists()) + { + players = null; + networkGame.LeaveSession(); + } currentState = lobbyState.Welcome; + } if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) ready = true; + + if (networkGame.sessionExists()) + { + players = networkGame.LocalGamers; + } + else + currentState = lobbyState.Welcome; + + break; } @@ -175,6 +229,7 @@ namespace CS_3505_Project_06 spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0); spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0); spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0); + switch (currentState) { case lobbyState.Welcome: @@ -191,16 +246,37 @@ namespace CS_3505_Project_06 case lobbyState.CreateGame: DrawPlayerList(spriteBatch); + spriteBatch.DrawString(menuFont, "You are now the Host!", new Vector2(MaxX / 2, MaxY / 3), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f); + spriteBatch.DrawString(menuFont, "press: Y to continue", new Vector2(MaxX /2, (MaxY / 3) + menuFont.LineSpacing), Color.White, 0f, zero, .6f, SpriteEffects.None, 0.5f); + 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); break; + case lobbyState.FindGame: spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0); - //spriteBatch.DrawString(menuFont, "Select Game", new Vector2(100, 100), Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f); + if(availableSessions == null) + spriteBatch.DrawString(menuFont, "searching for available games ....", new Vector2(150, 100), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f); + else if (availableSessions.Count == 0) + spriteBatch.DrawString(menuFont, "no games currently available, searching ....", new Vector2(150, 100), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f); + else + { + for (int sessionIndex = 0; sessionIndex < availableSessions.Count; sessionIndex++) + { + Color color = Color.Gray; - //spriteBatch.DrawString(menuFont, returnToMainText, returnToMainPos, Color.Gray, 0, new Vector2(180 , 0), .6f, SpriteEffects.None, 0.5f); + if (sessionIndex == selectedSessionIndex) + color = Color.Red; + + spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].HostGamertag, new Vector2(150, 100 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f); + spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].CurrentGamerCount + " / " + availableSessions[sessionIndex].OpenPublicGamerSlots + availableSessions[sessionIndex].OpenPrivateGamerSlots, + new Vector2(400, 100 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f); + } + } break; + case lobbyState.Connected: DrawPlayerList(spriteBatch); + spriteBatch.DrawString(menuFont, "Waiting for ready players...", new Vector2(MaxX / 2, MaxY / 2), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f); break; } @@ -226,12 +302,22 @@ namespace CS_3505_Project_06 private void DrawPlayerList(SpriteBatch spriteBatch) { + //reference point Vector2 topOfList = new Vector2(MaxX / 8, MaxY / 4); + + //command info spriteBatch.DrawString(menuFont, "Current Players", new Vector2(topOfList.X + 15, topOfList.Y - 25), Color.White); + spriteBatch.DrawString(menuFont, "Command Options: to mark your self as ready", new Vector2(20, 20), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "type players # to toggle chat", new Vector2(175, 40), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "return to main menu", new Vector2(175, 60), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "R", new Vector2(145, 20), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "#", new Vector2(145, 40), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "X", new Vector2(145, 60), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f); + - //top player spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); - spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 10), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); + + //player 1 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f); if(!ready) spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); @@ -247,7 +333,6 @@ namespace CS_3505_Project_06 //player 2 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 65), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); - spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 75), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f); if (!ready) spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); @@ -263,7 +348,6 @@ namespace CS_3505_Project_06 //player 3 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 130), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); - spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 140), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f); if (!ready) spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); @@ -279,7 +363,6 @@ namespace CS_3505_Project_06 //player 4 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 195), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); - spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 205), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f); if (!ready) spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); @@ -292,6 +375,15 @@ namespace CS_3505_Project_06 else spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); + + //draw player names + if (players != null) + { + for (int g = 0; g < players.Count; g++) + { + spriteBatch.DrawString(menuFont, players[g].Gamertag, new Vector2(topOfList.X + 10, topOfList.Y + 10 + 65*g), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); + } + } } } }