using Gungeon; using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; using SGUI; namespace UpForLastCommand { public class Module : ETGModule { public static readonly string MOD_NAME = "up for last command"; public static readonly string VERSION = "1.2.2.3,4,1.0"; public static readonly string TEXT_COLOR = "#00FFFF"; public override void Start() { SGroup console = ETGModConsole.Instance.GUI; STextField textField = null; foreach (SElement item in console.Children) { if (item is STextField field) { textField = field; break; } } if (textField != null) { textField.OnKey += OnKey; textField.OnSubmit += OnSubmit; } Log($"{MOD_NAME} v{VERSION} started successfully. press the up and down arrow keys to scroll through your last commands", TEXT_COLOR); } private List lastCommands = new List(); private string lastVal = string.Empty; private int currentCommandIndex = -1; private void OnKey(STextField textField, bool keyDown, KeyCode keyCode) { if (textField != null && keyDown) { if (keyCode == KeyCode.UpArrow || keyCode == KeyCode.DownArrow) { if (lastCommands.Count <= 0) { textField.Text = string.Empty; return; } if (keyCode == KeyCode.UpArrow) { currentCommandIndex--; if (currentCommandIndex <= 0) { currentCommandIndex = 0; } } else if(keyCode == KeyCode.DownArrow) { currentCommandIndex++; if (currentCommandIndex >= lastCommands.Count) { currentCommandIndex = lastCommands.Count - 1; } } textField.Text = lastCommands[currentCommandIndex]; } } } void OnSubmit(STextField elem, string text) { int lastIdx = lastCommands.Count - 1; if (text != string.Empty && (lastCommands.Count <= 0 || text != lastCommands[lastIdx])) { lastCommands.Add(text); } currentCommandIndex = lastCommands.Count; } public static void Log(string text, string color="#FFFFFF") { ETGModConsole.Log($"{text}"); } public override void Exit() { } public override void Init() { } } }