]> Dogcows Code - chaz/carfire/blobdiff - Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs
Added more comments to gui code, lots of refactoring still needed. Probably will...
[chaz/carfire] / Project06 / CS 3505 Project 06 / CS 3505 Project 06 / LobbyGUI.cs
index 17275a945adf4a946504354d09cd9f056ab52b05..08efb7c34df81445e0ac23e47d91f28ada4fdbc9 100644 (file)
@@ -14,6 +14,7 @@ namespace CS_3505_Project_06
 {\r
     public class lobbyGUI : ILobby\r
     {\r
+        #region local variables\r
         float scale;\r
 \r
         Texture2D background;\r
@@ -65,6 +66,8 @@ namespace CS_3505_Project_06
         String chatMessage;\r
         Queue<ChatInfo> currentChat;\r
 \r
+        \r
+\r
         private enum lobbyState\r
         {\r
             Welcome,\r
@@ -76,6 +79,7 @@ namespace CS_3505_Project_06
         }\r
 \r
         lobbyState currentState;\r
+        #endregion\r
 \r
         public lobbyGUI()\r
         {\r
@@ -136,7 +140,9 @@ namespace CS_3505_Project_06
             \r
         }\r
 \r
-        // TODO: New method.\r
+        /// <summary>\r
+        /// Transition into connected state\r
+        /// </summary>\r
         void JoinedSession(NetworkSession session, NetworkGame networkGame)\r
         {\r
             if (session != null)\r
@@ -151,25 +157,46 @@ namespace CS_3505_Project_06
             }\r
         }\r
 \r
-        // TODO: New method.\r
+        /// <summary>\r
+        /// Called when Async FindSession returns. Available sessions is then updated\r
+        /// </summary>\r
         void FoundSessions(AvailableNetworkSessionCollection sessions, NetworkGame networkGame)\r
         {\r
             availableSessions = sessions;\r
         }\r
 \r
-        // TODO: New method.\r
+        /// <summary>\r
+        /// Catches exceptions for and Async calls\r
+        /// </summary>\r
         void AsyncCallbackFailed(Exception exception, NetworkGame networkGame)\r
         {\r
             currentState = lobbyState.Welcome;\r
             Console.WriteLine("Exception as thrown during async call: " + exception.Message);\r
         }\r
 \r
+        /// <summary>\r
+        /// Adds and new chats to the chat list. If chat list is full, older messages are removed.\r
+        /// </summary>\r
         private void UpdateChat(GameTime gameTime, NetworkGame networkGame)\r
         {\r
-            currentChat.Concat(networkGame.ReceiveChats());\r
+            List<ChatInfo> chts = networkGame.ReceiveChats();\r
+            for (int x = 0; x < chts.Count(); x++)\r
+                currentChat.Enqueue(chts[x]);\r
+\r
+            //if number of chat messages has reached max remove older messages as new ones are added\r
+            if (currentChat.Count() > 8)\r
+            {\r
+                for (int x = 0; x < chts.Count(); x++)\r
+                {\r
+                    currentChat.Dequeue();\r
+                }\r
+            }\r
 \r
         }\r
 \r
+        /// <summary>\r
+        /// Main update call for Lobby, what is actually updated is determined by what the current state is.\r
+        /// </summary>\r
         public long Update(GameTime gameTime, NetworkGame networkGame)\r
         {\r
             \r
@@ -260,12 +287,16 @@ namespace CS_3505_Project_06
                         }\r
                     }\r
 \r
-\r
-                    Console.WriteLine("Finding");\r
                     break;\r
+\r
                 case lobbyState.Connected:\r
-                    if (chatActive)\r
+                    if (chatActive)   //If chat is activated by pressing T all inputs go to chat. Enter finishes chat esc returns\r
                     {\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Escape) && previousKeyboardState.IsKeyUp(Keys.Escape))\r
+                        {\r
+                            chatActive = false;\r
+                            break;\r
+                        }\r
                         if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))\r
                         {\r
                             networkGame.SendChat(chatMessage);\r
@@ -286,14 +317,16 @@ namespace CS_3505_Project_06
 \r
                         foreach(Keys ky in newKeys)\r
                         {\r
-                            if(ky.Equals(Keys.Space))\r
+                            if (ky.Equals(Keys.Back))\r
+                                chatMessage = chatMessage.Substring(0, chatMessage.Length-1);\r
+                            else if(ky.Equals(Keys.Space))\r
                                 chatMessage = chatMessage + " ";\r
                             else\r
                                 chatMessage = chatMessage + ky.ToString();\r
                         }\r
                         \r
                     }\r
-                    else\r
+                    else  //normal op mode\r
                     {\r
                         UpdateChat(gameTime, networkGame);\r
                         chatMessage = "";\r
@@ -304,6 +337,7 @@ namespace CS_3505_Project_06
                         if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))\r
                         {\r
                             ready = false;\r
+                            currentChat.Clear();\r
                             if (networkGame.HasActiveSession)\r
                             {\r
                                 players = null;\r
@@ -383,6 +417,7 @@ namespace CS_3505_Project_06
 \r
                 case lobbyState.FindingGames:\r
                     spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);\r
+                    spriteBatch.DrawString(menuFont, "select game by pressing listed games index", new Vector2(250, 400), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f);\r
                     if(availableSessions == null)\r
                         spriteBatch.DrawString(menuFont, "searching for available games ....", new Vector2(150, 100), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f);\r
                     else if (availableSessions.Count == 0)\r
@@ -396,9 +431,9 @@ namespace CS_3505_Project_06
                             if (sessionIndex == selectedSessionIndex)\r
                                 color = Color.Red;\r
 \r
-                            spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].HostGamertag, new Vector2(150, 100 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f);\r
-                            spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].CurrentGamerCount + " / " + availableSessions[sessionIndex].OpenPublicGamerSlots + availableSessions[sessionIndex].OpenPrivateGamerSlots,\r
-                                                   new Vector2(400, 100 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f);\r
+                            spriteBatch.DrawString(menuFont, sessionIndex+1 + "          " + availableSessions[sessionIndex].HostGamertag, new Vector2(150, 125 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f);\r
+                            spriteBatch.DrawString(menuFont, availableSessions[sessionIndex].CurrentGamerCount + " / 4",\r
+                                                   new Vector2(450, 125 + sessionIndex * menuFont.LineSpacing), color, 0f, zero, .7f, SpriteEffects.None, 0.5f);\r
                         }\r
                     }\r
                     break;\r
@@ -418,6 +453,9 @@ namespace CS_3505_Project_06
             return 1;\r
         }\r
 \r
+        /// <summary>\r
+        /// Updates backgound animation with moving spotlight. Spotlight bounces off walls \r
+        /// </summary>\r
         private void UpdateSpotLight(GameTime gameTime)\r
         {\r
             spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,\r
@@ -433,6 +471,9 @@ namespace CS_3505_Project_06
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Draws the list of current chat messages received by the local client.\r
+        /// </summary>\r
         private void DrawChatInfo(SpriteBatch spriteBatch)\r
         {\r
             if (currentChat.Count > 0)\r
@@ -440,14 +481,17 @@ namespace CS_3505_Project_06
                 for (int y = 0; y < currentChat.Count; y++)\r
                 {\r
                     spriteBatch.DrawString(menuFont, currentChat.ElementAt(y).Sender + ": " + currentChat.ElementAt(y).Message\r
-                                            , new Vector2(400, 100 - y*10), Color.Blue, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+                                            , new Vector2(400, 10 + y*15), Color.Blue, 0f, zero, .6f, SpriteEffects.None, 1f);\r
                 }\r
 \r
             }\r
             if(chatActive)\r
-                spriteBatch.DrawString(menuFont, chatMessage, new Vector2(400, 100), Color.Green, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+                spriteBatch.DrawString(menuFont, chatMessage, new Vector2(400, 10 + 15*(currentChat.Count + 1)), Color.Green, 0f, zero, .6f, SpriteEffects.None, 1f);\r
         }\r
 \r
+        /// <summary>\r
+        /// Draws player list objects for the connected state.\r
+        /// </summary>\r
         private void DrawPlayerList(SpriteBatch spriteBatch)\r
         {\r
             \r
@@ -458,11 +502,13 @@ namespace CS_3505_Project_06
             spriteBatch.DrawString(menuFont, "Current Players", new Vector2(topOfList.X + 15, topOfList.Y - 25), Color.White);\r
             spriteBatch.DrawString(menuFont, "Command Options:          to mark your self as ready", new Vector2(20, 20), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
             spriteBatch.DrawString(menuFont, "type players # to toggle chat", new Vector2(175, 40), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
-            spriteBatch.DrawString(menuFont, "return to main menu", new Vector2(175, 60), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "return to main menu", new Vector2(175, 80), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "enter chat mode", new Vector2(175, 60), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
             spriteBatch.DrawString(menuFont, "R", new Vector2(145, 20), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);\r
             spriteBatch.DrawString(menuFont, "#", new Vector2(145, 40), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);\r
-            spriteBatch.DrawString(menuFont, "X", new Vector2(145, 60), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);\r
-            \r
+            spriteBatch.DrawString(menuFont, "X", new Vector2(145, 80), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "T", new Vector2(145, 60), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+\r
             //Background squares\r
             spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
             spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 65), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
@@ -510,7 +556,7 @@ namespace CS_3505_Project_06
             spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
             \r
             //Chat CheckBoxs\r
-            Boolean chatwith = false;  // change to reflect info from network, move to update and create one for each player\r
+            Boolean chatwith = true;  // change to reflect info from network, move to update and create one for each player\r
             if (!chatwith)\r
                 spriteBatch.Draw(deselectBox, new Vector2(topOfList.X +218, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
             else\r
This page took 0.032629 seconds and 4 git commands to generate.