Пример #1
0
        /// <summary>
        /// Call this function on OnGUI calls
        /// </summary>
        internal static void Draw()
        {
            if (!Shown && Time.time - ShownAtTime > ShowAnimationTime)
            {
                return;
            }

            Color background = Color.black;

            background.a = 0.75f;

            int height    = Screen.height / 2;
            int width     = Screen.width;
            int linecount = height / LineHeight;

            float yOffset = 0;

            if (Time.time - ShownAtTime < ShowAnimationTime)
            {
                int   a   = Shown ? height : 0;
                int   b   = Shown ? 0 : height;
                float val = (Time.time - ShownAtTime) / ShowAnimationTime;

                yOffset = -EaseOutQuad(a, b, val);

                if (!Shown)
                {
                    val = 1 - val;
                }

                background.a *= val;
            }

            // Background rectangle
            ModUtilities.Graphics.DrawRect(new Rect(0, yOffset, width, height + 5), background);

            for (int line = 0; line < Math.Min(linecount - 1, CmdLog.Count); line++)
            {
                LogEntry entry = CmdLog.Get(line);
                int      y     = (linecount - 2 - line) * LineHeight;
                DrawText(entry.Message, new Vector2(5, y + yOffset), entry.GetColor());
            }

            float consoleY = (linecount - 1) * LineHeight + yOffset;

            try
            {
                DrawText(Prompt + CurrentCmd, new Vector2(5, consoleY), Color.green);
                float x = Width(Prompt) + Width(CurrentCmd.Substring(0, EditLocation));
                DrawText(Cursor, new Vector2(5 + x, consoleY), Color.green);
            }
            catch (Exception e)
            {
                Error($"currentCmd: \"{CurrentCmd}\"\neditLocation: {EditLocation}");
                Error(e.ToString());
                CurrentCmd   = "";
                EditLocation = 0;
            }

            float Width(string text) => Style.CalcSize(new GUIContent(text)).x;
        }
Пример #2
0
        /// <summary>
        /// Call this function on Update calls
        /// </summary>
        internal static void Update()
        {
            // Toggle console with TAB
            if (ModInput.GetKeyDown("ToggleConsole"))
            {
                Shown = !Shown;

                float off = 0;

                //The user is toggling the console but the animation hasn't yet ended, resume it later
                if (Time.time - ShownAtTime < ShowAnimationTime)
                {
                    off -= ShowAnimationTime - (Time.time - ShownAtTime);
                }

                ShownAtTime = Time.time + off;

                if (SceneManager.GetActiveScene().name == "gameplay")
                {
                    if (Shown)
                    {
                        PreviousUIState           = GameplayUIManager.UIState;
                        GameplayUIManager.UIState = UIState.PauseMenuOrSubMenu;
                    }
                    else
                    {
                        GameplayUIManager.UIState = PreviousUIState;
                        PreviousUIState           = UIState.None;
                    }
                }
            }

            if (Shown)
            {
                if (ModInput.GetKeyDown("ConsoleAutocompletion"))
                {
                    TriggerAutocompletion();
                }

                // Handling history
                if (Input.GetKeyDown(KeyCode.UpArrow) && HistorySelector < History.Count - 1)
                {
                    HistorySelector += 1;
                    CurrentCmd       = History.Get(HistorySelector);
                    EditLocation     = CurrentCmd.Length;
                }
                if (Input.GetKeyDown(KeyCode.DownArrow) && HistorySelector > -1)
                {
                    HistorySelector -= 1;
                    if (HistorySelector == -1)
                    {
                        CurrentCmd = "";
                    }
                    else
                    {
                        CurrentCmd = History.Get(HistorySelector);
                    }
                    EditLocation = CurrentCmd.Length;
                }
                // Handle editing
                if (Input.GetKeyDown(KeyCode.LeftArrow) && EditLocation > 0)
                {
                    EditLocation--;
                }
                if (Input.GetKeyDown(KeyCode.RightArrow) && EditLocation < CurrentCmd.Length)
                {
                    EditLocation++;
                }

                ReadInput(); // Read text input
            }
        }