Example #1
0
    // Update general keys
    void UpdateGeneralKeys()
    {
        if (Event.current.type != EventType.KeyUp)
        {
            return;
        }

        switch (Event.current.keyCode)
        {
        case KeyCode.Escape:
            //popupMenu = null;
            if (popupWindow != null)
            {
                popupWindow.Close();
            }

            if (!introEnabled && (accountNameFocused || accountPasswordFocused))
            {
                GUIHelper.ClearAllFocus();
            }
            break;

        // TODO: This doesn't work with KeyDown...but why?
        case KeyCode.A:
            if (Event.current.modifiers == EventModifiers.Control && GUIUtility.keyboardControl != 0)
            {
                TextEditor t = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                t.SelectAll();
            }
            break;
        }
    }
Example #2
0
    // Clear focus
    void ClearFocus()
    {
        if (!clearFlag)
        {
            return;
        }

        GUIHelper.ClearAllFocus();

        // Clear pressed keys
        if (Event.current != null && Event.current.isKey)
        {
            Event.current.keyCode = KeyCode.None;
            Event.current.Use();
            Event.current = null;
        }

        // Show mouse cursor
        Screen.lockCursor = false;
        Screen.showCursor = true;

        clearFlag = false;
    }
Example #3
0
    // Draws the chat
    public void DrawChat()
    {
        using (new GUIVertical()) {
            // Chat messages
            using (new GUIScrollView(ref chatScrollPosition)) {
                using (new GUIVertical()) {
                    for (int i = 0; i < entries.Count; i++)
                    {
                        var entry   = entries[i];
                        var msgRect = GUILayoutUtility.GetRect(entry.guiContent, textStyle);

                        GUIHelper.Shadowed(
                            msgRect.x, msgRect.y,
                            (x, y) => {
                            GUI.contentColor = entry.color;
                            msgRect.x        = x;
                            msgRect.y        = y;
                            GUI.Label(msgRect, entry.guiContent, textStyle);
                        }
                            );
                    }

                    GUI.contentColor = Color.white;
                }
            }

            // Set chat input color
            if (inGameLobby.currentState == GameLobbyState.Game)
            {
                if (chatInputFocused)
                {
                    chatInputColor = Color.white;
                }
                else
                {
                    chatInputColor = new Color(1f, 1f, 1f, 0f);
                }
            }
            else
            {
                chatInputColor = Color.white;
            }

            GUI.color = chatInputColor;

            // Channel + input field
            using (new GUIHorizontal()) {
                // Channel switch
                if (inGameLobby.currentState != GameLobbyState.Game || chatInputFocused)
                {
                    GUI.contentColor = GUIColor.GetChannelColor(currentChannel);
                    GUILayout.Box(currentChannel, GUILayout.ExpandWidth(false));
                    GUI.contentColor = Color.white;
                }
                else
                {
                    GUILayout.Box("_", GUILayout.ExpandWidth(false));
                }

                // Save settings before changing them
                //var wordWrap = GUI.skin.textField.wordWrap;
                var richText = GUI.skin.textField.richText;
                //var fixedWidth = GUI.skin.textField.fixedWidth;

                //GUI.skin.textField.wordWrap = true;
                GUI.skin.textField.richText = true;
                //GUI.skin.textField.fixedWidth = GUIArea.width * 0.1f;

                // Chat input field
                GUI.enabled = chatInputEnabled && chatInputFocused;
                GUI.SetNextControlName("LobbyChatInput");
                GUILayout.Box("");

                chatText = GUI.TextField(GUILayoutUtility.GetLastRect(), chatText, 300);

                // Reset old settings
                //GUI.skin.textField.wordWrap = wordWrap;
                GUI.skin.textField.richText = richText;
                //GUI.skin.textField.fixedWidth = fixedWidth;
            }

            GUILayout.Space(4);

            GUI.enabled = true;
            GUI.color   = Color.white;

            // Debug

            /*GUI.Label(new Rect(300, 0, 500, 25), GUI.GetNameOfFocusedControl());
             * GUI.Label(new Rect(300, 25, 500, 25), Event.current.type.ToString());
             * GUI.Label(new Rect(300, 50, 500, 25), inGameLobby.currentState.ToString());
             * GUI.Label(new Rect(300, 75, 500, 25), chatInputEnabled.ToString());*/

            // Only on editing the current message we save it in array
            if (myMessagesIndex == myMessages.Count - 1)
            {
                myMessages[myMessages.Count - 1] = chatText;
            }

            if (chatInputFocused)
            {
                // This is for Asian IME input, we only send
                // if Return hasn't been used to change the text.
                if (Event.current.type == EventType.KeyDown)
                {
                    chatTextBeforeReturn = chatText;
                }

                // The KeyUp event follows afterwards
                if (Event.current.type == EventType.KeyUp)
                {
                    switch (Event.current.keyCode)
                    {
                    // Return
                    case KeyCode.Return:
                        if (chatText == chatTextBeforeReturn)
                        {
                            SendChat();

                            if (inGameLobby.currentState == GameLobbyState.Game)
                            {
                                GUIHelper.ClearAllFocus();
                            }
                        }
                        break;

                    // Up
                    case KeyCode.UpArrow:
                        if (myMessages.Count == 0)
                        {
                            break;
                        }

                        myMessagesIndex -= 1;
                        if (myMessagesIndex < 0)
                        {
                            myMessagesIndex = 0;
                        }
                        chatText = myMessages[myMessagesIndex];
                        break;

                    // Down
                    case KeyCode.DownArrow:
                        if (myMessages.Count == 0)
                        {
                            break;
                        }

                        myMessagesIndex += 1;
                        if (myMessagesIndex >= myMessages.Count)
                        {
                            myMessagesIndex = myMessages.Count - 1;
                            chatText        = myMessages[myMessagesIndex];
                        }
                        else
                        {
                            chatText = myMessages[myMessagesIndex];
                        }
                        break;

                    // Space
                    case KeyCode.Space:
                        ChannelChange();
                        break;

                        /*case KeyCode.A:
                         *      if(Event.current.modifiers == EventModifiers.Control) {
                         *              //GUIHelper.ClearAllFocus();
                         *              //GUIHelper.Focus("LobbyChatInput");
                         *              TextEditor t = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                         *              t.SelectAll();
                         *              //LogManager.General.Log("Select all!");
                         *      }
                         *      break;*/
                    }
                }
            }
            else
            {
                if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Return && Login.instance.popupWindow == null)
                {
                    GUIHelper.Focus("LobbyChatInput");
                    Event.current.Use();
                }
            }
        }

        // Update focus info
        chatInputFocused = GUI.GetNameOfFocusedControl() == "LobbyChatInput";
    }