Beispiel #1
0
 public bool HandleChatInput(InputManager inputManager)
 {
     if (IsChatting) {
         if (inputManager.KeyState(Keys.Tab) == ButtonState.Pressed) {
             string[] split = ChatBuffer.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
             if (split.Length > 0) {
                 List<Player> found = new List<Player>();
                 foreach (KeyValuePair<int, Player> kvp in Players) {
                     if (kvp.Value.Name.Length >= split[split.Length - 1].Length && kvp.Value.Name.Substring(0, split[split.Length - 1].Length).ToLower() == split[split.Length - 1].ToLower()) {
                         found.Add(kvp.Value);
                     }
                 }
                 if (found.Count == 1) {
                     ChatBuffer = ChatBuffer.Substring(0, ChatBuffer.Length - split[split.Length - 1].Length);
                     string toAdd = found[0].Name;
                     if (ChatBuffer.Length == 0 && (IsAllChatting || found[0].Team == LocalPlayer.Team))
                         toAdd += ": ";
                     else
                         toAdd += " ";
                     ChatBuffer += toAdd;
                 }
             }
         }
         if (inputManager.KeyState(Keys.Backspace) == ButtonState.Pressed && ChatBuffer.Length > 0)
             ChatBuffer = ChatBuffer.Substring(0, ChatBuffer.Length - 1);
         foreach (char c in inputManager.GetTextInput()) {
             ChatBuffer = ChatBuffer + c;
         }
         if (inputManager.KeyState(Keys.Escape) == ButtonState.Pressed) {
             ChatBuffer = "";
             IsChatting = false;
         }
         if (inputManager.KeyState(Keys.Enter) == ButtonState.Pressed) {
             if (IsAllChatting)
                 SendAllChat(ChatBuffer);
             else
                 SendTeamChat(ChatBuffer);
             ChatBuffer = "";
             IsChatting = false;
         }
         return true;
     }
     else {
         if (inputManager.KeyState(Keys.Enter) == ButtonState.Pressed) {
             if (inputManager.IsShiftKeyDown) {
                 // All chat
                 IsAllChatting = true;
             }
             else {
                 // Team chat
                 IsAllChatting = false;
             }
             IsChatting = true;
         }
     }
     return false;
 }