Make terminal great again
This commit is contained in:
parent
2fb6d279da
commit
fd407dab78
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
@ -19,10 +20,16 @@ namespace NeonTea.Quakeball.Interface {
|
|||||||
private float DesiredTerminalPos;
|
private float DesiredTerminalPos;
|
||||||
private bool IsOpen = false;
|
private bool IsOpen = false;
|
||||||
|
|
||||||
|
private Dictionary<string, Func<string[], bool>> Commands = new Dictionary<string, Func<string[], bool>>();
|
||||||
|
|
||||||
private List<string> Messages = new List<string>();
|
private List<string> Messages = new List<string>();
|
||||||
private string Text = "";
|
private string Text = "";
|
||||||
|
private List<string> PreviousRuns = new List<string>();
|
||||||
|
private int CurrentScroll = -1;
|
||||||
|
private bool JustScrolled = false;
|
||||||
|
|
||||||
public static string INFO_COLOR = "#FE8";
|
public static string INFO_COLOR = "#FE8";
|
||||||
|
public static string ERROR_COLOR = "#F33";
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
ToggleTerminalAction = new InputAction("Toggle Terminal", binding: "<Keyboard>/backquote");
|
ToggleTerminalAction = new InputAction("Toggle Terminal", binding: "<Keyboard>/backquote");
|
||||||
@ -31,10 +38,23 @@ namespace NeonTea.Quakeball.Interface {
|
|||||||
SubmitTerminal = new InputAction("Terminal Submit", binding: "<Keyboard>/enter");
|
SubmitTerminal = new InputAction("Terminal Submit", binding: "<Keyboard>/enter");
|
||||||
SubmitTerminal.Enable();
|
SubmitTerminal.Enable();
|
||||||
SubmitTerminal.performed += Submit;
|
SubmitTerminal.performed += Submit;
|
||||||
|
SubmitTerminal = new InputAction("Terminal ScrollUp", binding: "<Keyboard>/uparrow");
|
||||||
|
SubmitTerminal.Enable();
|
||||||
|
SubmitTerminal.performed += _ => { Scroll(1); };
|
||||||
|
SubmitTerminal = new InputAction("Terminal ScrollDown", binding: "<Keyboard>/downarrow");
|
||||||
|
SubmitTerminal.Enable();
|
||||||
|
SubmitTerminal.performed += _ => { Scroll(-1); };
|
||||||
|
|
||||||
DesiredTerminalPos = (TerminalPanel.rect.height / 2) * (IsOpen ? -1 : 1);
|
DesiredTerminalPos = (TerminalPanel.rect.height / 2) * (IsOpen ? -1 : 1);
|
||||||
|
|
||||||
InputField.restoreOriginalTextOnEscape = false;
|
InputField.restoreOriginalTextOnEscape = false;
|
||||||
|
InputField.onValueChanged.AddListener(_ => {
|
||||||
|
if (JustScrolled) {
|
||||||
|
JustScrolled = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CurrentScroll = -1;
|
||||||
|
});
|
||||||
|
|
||||||
AddMessage($"<color={INFO_COLOR}>Welcome to Quakeball!</color>");
|
AddMessage($"<color={INFO_COLOR}>Welcome to Quakeball!</color>");
|
||||||
}
|
}
|
||||||
@ -62,15 +82,50 @@ namespace NeonTea.Quakeball.Interface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool RegisterCommand(string name, Func<string[], bool> command) {
|
||||||
|
if (Commands.ContainsKey(name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Commands.Add(name, command);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Run(string command) {
|
||||||
|
string[] parts = command.Split(new char[] { ' ' });
|
||||||
|
string name = parts[0];
|
||||||
|
if (Commands.ContainsKey(name)) {
|
||||||
|
Func<string[], bool> func = Commands[name];
|
||||||
|
string[] args = new string[parts.Length - 1];
|
||||||
|
Array.Copy(parts, 1, args, 0, parts.Length - 1);
|
||||||
|
if (func(args)) {
|
||||||
|
AddMessage(command);
|
||||||
|
} else {
|
||||||
|
AddMessage($"<color={ERROR_COLOR}>{command}</color>");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
AddMessage($"<color={ERROR_COLOR}>{command}</color>");
|
||||||
|
AddMessage("No such command exists!");
|
||||||
|
}
|
||||||
|
PreviousRuns.Insert(0, command);
|
||||||
|
}
|
||||||
|
|
||||||
public void AddMessage(string message) {
|
public void AddMessage(string message) {
|
||||||
Messages.Add(message);
|
Messages.Add(message);
|
||||||
Text = String.Join("\n", Messages.ToArray());
|
Text = String.Join("\n", Messages.ToArray());
|
||||||
TextField.text = Text;
|
TextField.text = Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Scroll(int amount) {
|
||||||
|
if (IsOpened() && PreviousRuns.Count > 0) {
|
||||||
|
JustScrolled = true;
|
||||||
|
CurrentScroll = Math.Min(Math.Max(0, CurrentScroll + amount), PreviousRuns.Count - 1);
|
||||||
|
InputField.text = PreviousRuns[CurrentScroll];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Submit(InputAction.CallbackContext context) {
|
private void Submit(InputAction.CallbackContext context) {
|
||||||
if (IsOpened()) {
|
if (IsOpened()) {
|
||||||
AddMessage(InputField.text);
|
Run(InputField.text);
|
||||||
InputField.text = "";
|
InputField.text = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,11 @@
|
|||||||
"key": "mesh.meshColliderIsConvex",
|
"key": "mesh.meshColliderIsConvex",
|
||||||
"value": "{\"m_Value\":false}"
|
"value": "{\"m_Value\":false}"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
|
||||||
|
"key": "editor.stripProBuilderScriptsOnBuild",
|
||||||
|
"value": "{\"m_Value\":true}"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "UnityEngine.ProBuilder.SelectionModifierBehavior, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
"type": "UnityEngine.ProBuilder.SelectionModifierBehavior, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
|
||||||
"key": "editor.rectSelectModifier",
|
"key": "editor.rectSelectModifier",
|
||||||
|
Loading…
Reference in New Issue
Block a user