Esempio n. 1
0
        private static void     OnSettingsGenerated(ScriptableObject asset)
        {
            RemoteModuleSettings remoteSettings = asset as RemoteModuleSettings;

            if (remoteSettings != null)
            {
                Action OverrideSettings = () =>
                {
                    remoteSettings.HighlightedMatchStyle = new GUIStyle(GUI.skin.label);
                    remoteSettings.HighlightedMatchStyle.normal.textColor = new Color(219F / 255F, 219F / 255F, 219F / 255F, 1F);
                    remoteSettings.HighlightedMatchStyle.richText         = true;
                    remoteSettings.CommandInputStyle = new GUIStyle(GUI.skin.textField);
                    //remoteSettings.commandInputStyle.normal.background = AssetDatabase.LoadAssetAtPath<Texture2D>(Path.Combine(HQ.RootPath, "NGGameConsole/Textures/commandInputBg.png"));
                    remoteSettings.ExecButtonStyle           = new GUIStyle("ToolbarButton");
                    remoteSettings.ExecButtonStyle.fontStyle = FontStyle.Bold;
                };

                if (Utility.CheckOnGUI() == false)
                {
                    GUICallbackWindow.Open(OverrideSettings);
                }
                else
                {
                    OverrideSettings();
                }
            }
        }
Esempio n. 2
0
        public RemoteModule()
        {
            this.name    = "Remote";
            this.streams = new List <StreamLog>();
            this.streams.Add(new StreamLog());
            this.rows          = new List <Row>();
            this.perWindowVars = new PerWindowVars <Vars>();

            RemoteModuleSettings remoteSettings = HQ.Settings.Get <RemoteModuleSettings>();

            foreach (ILogFilter filter in remoteSettings.GenerateFilters())
            {
                this.streams[0].groupFilters.filters.Add(filter);
            }
        }
Esempio n. 3
0
        public override Rect    PostGUI(Rect r, ref string command)
        {
            if (this.matchingCommands != null)
            {
                RemoteModuleSettings settings = HQ.Settings.Get <RemoteModuleSettings>();

                string[] commands;
                string[] arguments;
                this.ParseInput(command, out commands, out arguments);

                r.height = 16F;
                r.x      = settings.HighlightedMatchStyle.CalcSize(new GUIContent(this.precachedParentCommand)).x;
                r.width  = 200F;

                if (Event.current.type == EventType.ScrollWheel)
                {
                    if (Event.current.delta.y < 0F)
                    {
                        if (this.selectedMatchingCommand < this.matchingCommands.Length - 1)
                        {
                            ++this.selectedMatchingCommand;
                        }
                    }
                    else
                    {
                        if (this.selectedMatchingCommand >= 0)
                        {
                            --this.selectedMatchingCommand;
                        }
                    }

                    Event.current.Use();
                }

                if (this.selectedMatchingCommand + 1 >= this.scrollOffset + this.maxCommandsOnScreen)
                {
                    this.scrollOffset = this.selectedMatchingCommand + 1 - this.maxCommandsOnScreen;
                }
                else if (this.selectedMatchingCommand < this.scrollOffset)
                {
                    if (this.selectedMatchingCommand == -1)
                    {
                        this.scrollOffset = 0;
                    }
                    else
                    {
                        this.scrollOffset = this.selectedMatchingCommand;
                    }
                }

                for (int i = this.scrollOffset, j = 0; i < this.matchingCommands.Length && j < this.maxCommandsOnScreen; ++i, ++j)
                {
                    r.y -= r.height;

                    if (Event.current.type == EventType.Repaint)
                    {
                        if (r.Contains(Event.current.mousePosition) == false)
                        {
                            EditorGUI.DrawRect(r, settings.completionBackgroundColor);
                        }
                        else
                        {
                            EditorGUI.DrawRect(r, settings.hoverCompletionBackgroundColor);
                        }
                    }

                    string highlighted = ((i == this.selectedMatchingCommand) ? "<b>" : "") +
                                         "<color=#" +
                                         ((int)(settings.partialCompletionColor.r * 255)).ToString("X2") +
                                         ((int)(settings.partialCompletionColor.g * 255)).ToString("X2") +
                                         ((int)(settings.partialCompletionColor.b * 255)).ToString("X2") +
                                         ((int)(settings.partialCompletionColor.a * 255)).ToString("X2") + ">" +
                                         this.matchingCommands[i].Substring(0, commands[commands.Length - 1].Length) +
                                         "</color>" +
                                         this.matchingCommands[i].Substring(commands[commands.Length - 1].Length) +
                                         ((i == this.selectedMatchingCommand) ? "</b>" : "");

                    if (GUI.Button(r, highlighted, settings.HighlightedMatchStyle) == true)
                    {
                        int    argumentsPosition = command.IndexOf(NGCLI.CommandsArgumentsSeparator);
                        string rawArguments      = string.Empty;

                        if (argumentsPosition != -1)
                        {
                            rawArguments = command.Substring(argumentsPosition + 1);
                        }

                        commands[commands.Length - 1] = this.matchingCommands[i];

                        textEditor.instance = EditorGUIProxy.s_RecycledEditor;

                        if (rawArguments != string.Empty)
                        {
                            command = string.Join(NGCLI.CommandsSeparator.ToString(), commands) +
                                      NGCLI.CommandsArgumentsSeparator +
                                      rawArguments;
                            this.SetCursor(command, command.Length - rawArguments.Length - 1);
                        }
                        else
                        {
                            command = string.Join(NGCLI.CommandsSeparator.ToString(), commands);
                            this.SetCursor(command, command.Length);
                        }

                        if (textEditor.text != command)
                        {
                            textEditor.text = command;
                            textEditor.MoveTextEnd();
                        }

                        this.matchingCommands = null;
                        break;
                    }
                }

                if (Event.current.type == EventType.Repaint &&
                    this.scrollOffset + this.maxCommandsOnScreen < this.matchingCommands.Length)
                {
                    r.height = 10F;
                    r.y     -= r.height;

                    EditorGUI.DrawRect(r, settings.completionBackgroundColor);
                    GUI.Label(r, "... (" + (this.matchingCommands.Length - this.scrollOffset - this.maxCommandsOnScreen) + ")", GeneralStyles.SmallLabel);
                }

                r.x = 0F;
            }
            else
            {
                this.scrollOffset = 0;
            }

            return(r);
        }
Esempio n. 4
0
        private Rect    DrawCLI(Rect r)
        {
            RemoteModuleSettings settings = HQ.Settings.Get <RemoteModuleSettings>();

            r.height = Constants.SingleLineHeight;
            r.width -= settings.execButtonWidth;

            if (this.parser.Root.children.Count == 0)
            {
                EditorGUI.LabelField(r, LC.G("RemoteModule_CLIUnavailable"), settings.CommandInputStyle);
            }
            else
            {
                if (Event.current.type == EventType.MouseMove && this.parser.matchingCommands != null)
                {
                    this.console.Repaint();
                }

                this.textEditor.instance = EditorGUIProxy.s_RecycledEditor;

                // Hack Tricky way to keep the focus on the text field and the cursor at the end.
                bool postTextField = false;
                if (this.next != 0 && Event.current.type == EventType.Repaint)
                {
                    this.next = 0;
                    GUI.FocusControl(CommandParser.CommandTextFieldName);
                    EditorGUIUtility.editingTextField = true;
                    postTextField = true;
                }

                EditorGUI.BeginChangeCheck();
                this.parser.HandleKeyboard(ref this.command);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    if (this.textEditor.text != this.command)
                    {
                        this.textEditor.text = this.command;
                        this.textEditor.MoveTextEnd();
                    }

                    this.next = EditorGUIUtility.keyboardControl;
                    GUI.FocusControl(CommandParser.CommandTextFieldName);
                }

                EditorGUI.BeginChangeCheck();
                GUI.SetNextControlName(CommandParser.CommandTextFieldName);
                this.command = EditorGUI.TextField(r, this.command, settings.CommandInputStyle);

                if (postTextField == true)
                {
                    this.textEditor.MoveTextEnd();
                    this.console.Repaint();
                }

                if (EditorGUI.EndChangeCheck() == true)
                {
                    this.parser.UpdateMatchesAvailable(this.command);
                }

                if (this.parser.matchingCommands != null &&
                    Event.current.type == EventType.Repaint &&
                    EditorGUIUtility.editingTextField == false)
                {
                    this.parser.matchingCommands = null;
                }
            }

            EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(command) == true || this.parser.Root.children.Count == 0);
            {
                r.x    += r.width;
                r.width = settings.execButtonWidth;
                if (GUI.Button(r, "Exec", settings.ExecButtonStyle) == true)
                {
                    this.Exec();
                }
                r.y += r.height;
            }
            EditorGUI.EndDisabledGroup();

            return(r);
        }
Esempio n. 5
0
        private Rect    DrawStreamTabs(Rect r)
        {
            ConsoleSettings settings = HQ.Settings.Get <ConsoleSettings>();
            float           maxWidth = r.width;

            r.height = Constants.SingleLineHeight;

            // Switch stream
            if (settings.inputsManager.Check("Navigation", ConsoleConstants.SwitchNextStreamCommand) == true)
            {
                this.currentVars.workingStream += 1;
                if (this.currentVars.workingStream >= this.streams.Count)
                {
                    this.currentVars.workingStream = 0;
                }

                Event.current.Use();
            }
            if (settings.inputsManager.Check("Navigation", ConsoleConstants.SwitchPreviousStreamCommand) == true)
            {
                this.currentVars.workingStream -= 1;
                if (this.currentVars.workingStream < 0)
                {
                    this.currentVars.workingStream = this.streams.Count - 1;
                }

                Event.current.Use();
            }

            for (int i = 0; i < this.streams.Count; i++)
            {
                r = this.streams[i].OnTabGUI(r, i);
            }

            r.width = 16F;

            if (GUI.Button(r, "+", HQ.Settings.Get <GeneralSettings>().MenuButtonStyle) == true)
            {
                RemoteModuleSettings remoteSettings = HQ.Settings.Get <RemoteModuleSettings>();
                StreamLog            stream         = new StreamLog();
                stream.Init(this.console, this);
                stream.rowsDrawer.SetRowGetter(this);
                stream.FilterAltered += this.console.SaveModules;
                stream.OptionAltered += this.console.SaveModules;

                foreach (ILogFilter filter in remoteSettings.GenerateFilters())
                {
                    stream.groupFilters.filters.Add(filter);
                }

                this.streams.Add(stream);

                if (this.StreamAdded != null)
                {
                    this.StreamAdded(stream);
                }

                this.console.CheckNewLogConsume -= stream.ConsumeLog;
                this.console.PropagateNewLog    -= stream.AddLog;
                this.console.SaveModules();

                if (this.streams.Count == 1)
                {
                    this.currentVars.workingStream = 0;
                }
            }
            r.x += r.width;

            if (this.streams.Count > 2)
            {
                r.y    += r.height + 2F;
                r.x     = 0F;
                r.width = maxWidth;
            }
            else
            {
                r.width = maxWidth - r.x;
            }

            return(r);
        }