Ejemplo n.º 1
0
        private static void DrawMenuDisplay()
        {
            //& Draws the menu display
            // Draws the buttons from the system
            GUILayout.BeginVertical(GUI.skin.textArea, GUILayout.ExpandHeight(true));
            GUILayout.Label(SYSTEM_CMD_MENU, GUI.skin.GetStyle("centerLabel"), GUILayout.ExpandWidth(true), GUILayout.Height(20));
            systemCmdScroll = GUILayout.BeginScrollView(systemCmdScroll, GUILayout.Height(DebugHandler.devWindow.Rect.height * 0.3f));

            foreach (ConsoleButton button in GuuConsole.buttons.Values)
            {
                if (GUILayout.Button(button.Text))
                {
                    GuuConsole.ExecuteCommand(button.Command, true);
                }
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            // Draws the buttons from the users
            GUILayout.BeginVertical(GUI.skin.textArea, GUILayout.ExpandHeight(true));
            GUILayout.Label(USER_CMD_MENU, GUI.skin.GetStyle("centerLabel"), GUILayout.ExpandWidth(true), GUILayout.Height(20));
            usedCmdScroll = GUILayout.BeginScrollView(usedCmdScroll, GUILayout.ExpandHeight(true));

            foreach (ConsoleButton button in GuuConsole.customButtons.Values)
            {
                if (GUILayout.Button(button.Text))
                {
                    GuuConsole.ExecuteCommand(button.Command, true);
                }
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();
        }
Ejemplo n.º 2
0
        //+ INTERACTIONS
        public override bool Execute(string[] args)
        {
            if (args == null || args.Length != 3)
            {
                GuuCore.LOGGER?.LogError($"The '<color=white>{Command}</color>' command takes 3 arguments");
                return(false);
            }

            string id   = args[0].Replace(" ", "_").ToLowerInvariant();
            string text = args[1];
            string cmd  = args[2];

            if (args[0].Contains(" "))
            {
                GuuCore.LOGGER?.LogWarning($"The '<color=white><id></color>' argument cannot contain any spaces. Using '<color=white>_</color>' instead! (New ID: {id})");
            }

            bool result = GuuConsole.RegisterButton(new ConsoleButton(id, text, cmd, true));

            if (result)
            {
                GuuCore.LOGGER?.Log($"Added new user defined button '<color=white>{id}</color>' with command '<color=white>{cmd}</color>'", GuuConsole.SUCCESS_COLOR);
            }

            return(result);
        }
Ejemplo n.º 3
0
        //+ INTERACTIONS
        public override bool Execute(string[] args)
        {
            if (args == null || args.Length != 3)
            {
                GuuCore.LOGGER?.LogError($"The '{Command}' command takes 3 arguments");
                return(false);
            }

            string id   = args[0].Replace(" ", "_").ToLowerInvariant();
            string text = args[1].Equals("*") ? GuuConsole.customButtons[id].Text : args[1];
            string cmd  = args[2].Equals("*") ? GuuConsole.customButtons[id].Command : args[2];

            if (args[0].Contains(" "))
            {
                GuuCore.LOGGER?.LogWarning($"The '<id>' argument cannot contain any spaces. Using '_' instead! (New ID: {id})");
            }

            bool result = GuuConsole.customButtons.ContainsKey(id) && GuuConsole.RegisterButton(new ConsoleButton(id, text, cmd, true), true);

            if (result)
            {
                GuuCore.LOGGER?.Log($"Edited user defined button '{id}'", GuuConsole.SUCCESS_COLOR);
            }

            return(result);
        }
        //+ INTERACTIONS
        public override bool Execute(string[] args)
        {
            if (args == null || args.Length != 1)
            {
                GuuCore.LOGGER?.LogError($"The '<color=white>{Command}</color>' command takes 1 arguments");
                return(false);
            }

            string id = args[0].Replace(" ", "_").ToLowerInvariant();

            if (args[0].Equals("all"))
            {
                foreach (string key in GuuConsole.customButtons.Keys)
                {
                    GuuConsole.RemoveButton(key);
                }

                GuuCore.LOGGER?.Log("Removed all user defined buttons", GuuConsole.SUCCESS_COLOR);
                return(true);
            }

            if (args[0].Contains(" "))
            {
                GuuCore.LOGGER?.LogWarning($"The '<color=white><id></color>' argument cannot contain any spaces. Using '<color=white>_</color>' instead! (New ID: {id})");
            }

            bool result = GuuConsole.RemoveButton(id, true);

            if (result)
            {
                GuuCore.LOGGER?.Log($"Removed the user defined button '<color=white>{id}</color>'", GuuConsole.SUCCESS_COLOR);
            }

            return(result);
        }
Ejemplo n.º 5
0
        //+ INITIALIZATION
        internal static void Init()
        {
            Application.logMessageReceived             += UnityLog;
            AppDomain.CurrentDomain.UnhandledException += HandleUncaughtException;

            GuuConsole.Init();
        }
Ejemplo n.º 6
0
        //+ HELPERS
        private static void CheckChanges()
        {
            if (lastInput?.Equals(input) ?? false)
            {
                return;
            }
            lastInput = input;

            bool   spaces = input.Contains(" ");
            string cmd    = spaces ? input.Substring(0, input.IndexOf(' ')) : input;

            if (TxtEditor.hasSelection)
            {
                cmd = string.Empty;
            }

            if (!spaces || TxtEditor.hasSelection)
            {
                acCache.Clear();
                acSelection = cmd;

                foreach (string id in GuuConsole.commands.Keys)
                {
                    if (id.ToLowerInvariant().StartsWith(cmd.ToLowerInvariant()))
                    {
                        acCache.Add(id);
                    }
                }
            }
            else
            {
                if (!GuuConsole.commands.ContainsKey(cmd))
                {
                    return;
                }

                string[] args  = GuuConsole.StripArgs(input, true);
                int      count = args.Length;
                string   last  = args[count - 1];

                acSelection = last;
                acCache.Clear();
                acCache = GuuConsole.commands[cmd].GetAutoComplete(count - 1, last)?.ToList() ?? new List <string>();
            }

            if (acCache.Count == 0)
            {
                autoComplete = false;
                return;
            }

            if (completeIndex >= acCache.Count)
            {
                completeIndex = acCache.Count - 1;
            }
        }
Ejemplo n.º 7
0
        //+ BRIDGE
        internal static void RegisterCommand(string cmdID, ConsoleCommand cmd)
        {
            if (IGNORE_LIST.Contains(cmdID))
            {
                return;
            }
            if (GuuConsole.commands.ContainsKey(cmdID))
            {
                SRML_LOGGER?.Log($"Found command with conflicting id '{cmdID}', adding prefix, new id is 'srml.{cmdID}'");
                GuuConsole.RegisterCommand(new SRMLCommand(cmd, $"srml.{cmdID}"));
                return;
            }

            GuuConsole.RegisterCommand(new SRMLCommand(cmd));
        }
Ejemplo n.º 8
0
        //+ LOGGING
        internal static void Log(string message)
        {
            if (message.MatchesAny(TO_IGNORE))
            {
                return;
            }

            string trace = string.Empty;

            if (GuuCore.FULL_TRACE && !message.Contains("-- FULL TRACE --"))
            {
                trace = $"\n-- FULL TRACE --\n{new StackTrace()}";
            }

            GuuConsole.Log(message + trace);
            GUU_LOG?.Log(message + trace);
        }
Ejemplo n.º 9
0
        //+ INPUT CONTROL
        internal override bool OnProcessInput(EventModifiers mods)
        {
            if (Event.current == null)
            {
                return(false);
            }

            switch (Event.current.keyCode)
            {
            // Closes auto complete if open and ESC is pressed
            case KeyCode.Escape when autoComplete:
                autoComplete = false;

                return(true);

            // Submits the input of the console if ENTER/RETURN is pressed
            case KeyCode.Return:
            case KeyCode.KeypadEnter:
                GuuConsole.ExecuteCommand(input.TrimEnd(' '));
                input = string.Empty;

                currHistory   = -1;
                completeIndex = 0;
                autoComplete  = false;

                return(true);

            // Toggles the auto complete if CTRL+Space is pressed (CMD for mac)
            case KeyCode.Space when mods == EventModifiers.Control || mods == EventModifiers.Command:
                CheckChanges();

                removeLastSpace = true;
                if (acCache.Count == 0)
                {
                    return(true);
                }

                autoComplete = true;
                return(true);

            // Executes auto complete when TAB is pressed without modifiers
            case KeyCode.Tab when mods == EventModifiers.None && autoComplete:
                input      = input.Substring(0, input.Length - acSelection.Length) + acCache[completeIndex];
                moveCursor = true;
                return(true);

            // Changes the history if the UP ARROW was pressed
            case KeyCode.UpArrow when !autoComplete && GuuConsole.history.Count > 0:
                currHistory = currHistory == -1 ? GuuConsole.history.Count - 1 : currHistory > 0 ? currHistory - 1 : currHistory;
                input       = GuuConsole.history[currHistory];

                moveCursor = true;
                return(true);

            // Changes the history if the DOWN ARROW was pressed
            case KeyCode.DownArrow when !autoComplete && GuuConsole.history.Count > 0:
                if (currHistory == -1)
                {
                    return(true);
                }

                currHistory = currHistory < GuuConsole.history.Count - 1 ? currHistory + 1 : -1;
                input       = currHistory == -1 ? string.Empty : GuuConsole.history[currHistory];

                moveCursor = true;
                return(true);

            // Changes the auto complete selection if UP ARROW was pressed
            case KeyCode.UpArrow when autoComplete:
                completeIndex = completeIndex == 0 ? acCache.Count - 1 : completeIndex - 1;
                acScroll.y    = 25 * completeIndex;

                return(true);

            // Changes the auto complete selection if DOWN ARROW was pressed
            case KeyCode.DownArrow when autoComplete:
                completeIndex = completeIndex == acCache.Count - 1 ? 0 : completeIndex + 1;
                acScroll.y    = 25 * completeIndex;

                return(true);

            // Anything else
            default:
                return(false);
            }
        }
Ejemplo n.º 10
0
 //+ INTERACTIONS
 internal void Execute()
 {
     GuuConsole.ExecuteCommand(Command, true);
 }