Ejemplo n.º 1
0
        private void drawTextArea(IRCChatWindow parent)
        {
            GUILayout.BeginVertical();
            GUILayout.TextField(topic ?? "",
                                (bufferWidth > 0) ?
                                new GUILayoutOption[] {
                GUILayout.ExpandWidth(false),
                GUILayout.Width(bufferWidth),
                GUILayout.MaxWidth(bufferWidth)
            } :
                                new GUILayoutOption[] {
                GUILayout.ExpandWidth(false),
                GUILayout.Width(10),
                GUILayout.MaxWidth(10)
            });

            drawBuffer();

            GUILayout.BeginHorizontal();
            GUILayout.Label(config.nick, GUILayout.ExpandWidth(false));
            if (Event.current.type == EventType.Repaint)
            {
                nicknameWidth = GUILayoutUtility.GetLastRect().width;
            }

            GUI.SetNextControlName(INPUT_CONTROL_NAME);
            inputText = GUILayout.TextField(inputText,
                                            ((bufferWidth > 0) && (nicknameWidth > 0)) ?
                                            new GUILayoutOption[] {
                GUILayout.ExpandWidth(false),
                GUILayout.Width(bufferWidth - nicknameWidth - GUI.skin.label.margin.right),
                GUILayout.MaxWidth(bufferWidth - nicknameWidth - GUI.skin.label.margin.right)
            } :
                                            new GUILayoutOption[] {
                GUILayout.ExpandWidth(false),
                GUILayout.Width(10),
                GUILayout.MaxWidth(10)
            });
            if (Event.current.type == EventType.Repaint)
            {
                inputTextRect      = GUILayoutUtility.GetLastRect();
                inputTextRectValid = true;
            }
            if (inputTextRectValid && inputTextRect.Contains(Event.current.mousePosition))
            {
                // mouse is within the input text box
                if (inputLocks != ControlTypes.All)
                {
                    inputLocks = InputLockManager.SetControlLock("kspirc");
                }

                if (textInputNeedsSelectionClearing == true)
                {
                    TextEditor te = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                    if (te != null)
                    {
                        string selection = te.SelectedText;
                        te.MoveTextEnd();
                        te.SelectNone();
                        textInputNeedsSelectionClearing = false;
                    }
                }

                if (GUI.GetNameOfFocusedControl() != ChannelGUI.INPUT_CONTROL_NAME)
                {
                    GUI.FocusControl(INPUT_CONTROL_NAME);
                    textInputNeedsSelectionClearing = true;
                }
            }
            else if (inputLocks == ControlTypes.All)
            {
                InputLockManager.RemoveControlLock("kspirc");
                inputLocks = ControlTypes.None;
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
Ejemplo n.º 2
0
        KSPIRC()
        {
            instance = this;

            GameObject.DontDestroyOnLoad(this);

            version = this.GetType().Assembly.GetName().Version.ToString();

            config = new IRCConfig();

            configWindow = new IRCConfigWindow(version, config);
            configWindow.configChangedEvent += configChanged;

            linkWindow        = new IRCLinkWindow(config);
            linkWindow.hidden = true;

            chatWindow = new IRCChatWindow(linkWindow, version, config);
            chatWindow.channelClosedEvent   += channelClosed;
            chatWindow.onUserCommandEntered += (e) => handleUserCommand(e.command);
            chatWindow.onShowConfigHandler  += showConfig;
            chatWindow.hidden = IRC_WINDOW_HIDDEN;

            initCommandHandlers();
            initUserCommandHandlers();

            client = new IRCClient();
            client.onCommandReceived            += (e) => handleServerCommand(e.command);
            client.onCommandSent                += (e) => logSendCommand(e.command);
            client.onConnect                    += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Connecting to server " + config.host + ":" + config.port + "...");
            client.onConnected                  += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Server connection established.");
            client.onSSLConnected               += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "SSL Server connection established.");
            client.onDisconnected               += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Disconnected from server.");
            client.onConnectionFailed           += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Connection failed to server.");
            client.onConnectionAttemptsExceeded += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "Connection attempts exceeded. Change config before retrying.");
            client.onSSLCertificateError        += () => chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, "*", "SSL Certificate error - use this server at your own risk.");

            if ((config.host != null) && (config.port > 0) && (config.nick != ""))
            {
                Debug.Log("Connecting to: " + config.host + ":" + config.port);
                configWindow.hidden = true;
                client.connect(config);
            }
            else
            {
                configWindow.hidden = false;
                chatWindow.addToChannel("IRC Plugin", "*", "IRC plugin not configured, not connecting to IRC server.");
                chatWindow.addToChannel("IRC Plugin", "*", "Edit config and confirm updates to connect.");
            }

            if (ToolbarManager.ToolbarAvailable)
            {
                windowButton             = ToolbarManager.Instance.add("irc", "irc");
                windowButton.TexturePath = "KSPIRC/button-regular";
                windowButton.ToolTip     = "IRC";
                windowButton.Visibility  = new GameScenesVisibility(GameScenes.CREDITS,
                                                                    GameScenes.EDITOR,
                                                                    GameScenes.FLIGHT,
                                                                    GameScenes.LOADING,
                                                                    GameScenes.LOADINGBUFFER,
                                                                    GameScenes.MAINMENU,
                                                                    GameScenes.PSYSTEM,
                                                                    GameScenes.SPACECENTER,
                                                                    GameScenes.TRACKSTATION);
                windowButton.OnClick += (e) => toggleChatWindow();
            }
            else
            {
                ApplicationLauncher.AppScenes scenes = ApplicationLauncher.AppScenes.ALWAYS;

                Texture toolbarButtonTexture = (Texture)GameDatabase.Instance.GetTexture("KSPIRC/button-regular", false);
                appLauncherButton = ApplicationLauncher.Instance.AddModApplication(onAppLaunchToggleOn,
                                                                                   onAppLaunchToggleOff,
                                                                                   null,
                                                                                   null,
                                                                                   null,
                                                                                   null,
                                                                                   scenes,
                                                                                   toolbarButtonTexture);
            }
        }
Ejemplo n.º 3
0
        public void draw(IRCChatWindow parent)
        {
            initStyles();

            // reset highlights as soon as we draw anything
            channelHighlightedPrivateMessage = false;
            channelHighlightedMessage        = false;
            channelHighlightedJoin           = false;

            GUILayout.BeginHorizontal();
            // TODO: get rid of weird margin/padding around drawTextArea() when drawNames() is called
            //       (the margin/padding is not there if it isn't called)
            drawTextArea(parent);

            if (!namesHidden && handle.StartsWith("#"))
            {
                drawNames();
            }
            GUILayout.EndHorizontal();

            // user has typed, reset tab completion
            if ((inputTextAfterTabCompletion != null) && (inputText != inputTextAfterTabCompletion))
            {
                inputTextBeforeTabCompletion = null;
                inputTextAfterTabCompletion  = null;
                lastTabCompletionUser        = null;
            }

            if (!keyDown && (Event.current.type == EventType.KeyDown))
            {
                if (parent.GetInputState().focused)
                {
                    string input = inputText.Trim();
                    if ((Event.current.keyCode == KeyCode.Return) || (Event.current.keyCode == KeyCode.KeypadEnter) ||
                        (Event.current.character == '\r') || (Event.current.character == '\n'))
                    {
                        if (input.Length > 0)
                        {
                            handleInput(input);
                        }
                        inputText = "";
                        inputTextBeforeTabCompletion = null;
                        inputTextAfterTabCompletion  = null;
                        lastTabCompletionUser        = null;
                        GUI.FocusControl(INPUT_CONTROL_NAME);
                    }
                    else if ((Event.current.keyCode == KeyCode.Tab) || (Event.current.character == '\t'))
                    {
                        if (input.Length > 0)
                        {
                            handleTabCompletion();
                        }
                    }
                }

                keyDown = true;
            }
            else if (keyDown && (Event.current.type == EventType.KeyUp))
            {
                keyDown = false;
            }

            if (Event.current.isKey &&
                ((Event.current.keyCode == KeyCode.Tab) || (Event.current.character == '\t')) &&
                (parent.GetInputState().focused))
            {
                TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                editor.MoveTextEnd();

                // prevent tab cycling
                Event.current.Use();
            }
        }