2021-04-30 21:34:50 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityExplorer.Core.Config;
|
2021-05-12 20:48:56 +10:00
|
|
|
|
using UnityExplorer.UI.CSConsole;
|
2021-05-26 17:40:09 +10:00
|
|
|
|
using UnityExplorer.UI.Widgets;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Panels
|
|
|
|
|
{
|
|
|
|
|
public class CSConsolePanel : UIPanel
|
|
|
|
|
{
|
|
|
|
|
public override string Name => "C# Console";
|
|
|
|
|
public override UIManager.Panels PanelType => UIManager.Panels.CSConsole;
|
2021-05-16 21:46:38 +10:00
|
|
|
|
public override int MinWidth => 750;
|
2021-05-05 21:27:09 +10:00
|
|
|
|
public override int MinHeight => 300;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-10 21:07:27 +10:00
|
|
|
|
public InputFieldScroller InputScroll { get; private set; }
|
|
|
|
|
public InputFieldRef Input => InputScroll.InputField;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
public Text InputText { get; private set; }
|
|
|
|
|
public Text HighlightText { get; private set; }
|
|
|
|
|
|
2021-05-15 01:21:07 +10:00
|
|
|
|
public Dropdown HelpDropdown { get; private set; }
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-15 01:21:07 +10:00
|
|
|
|
// events
|
|
|
|
|
public Action<string> OnInputChanged;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
public Action OnResetClicked;
|
|
|
|
|
public Action OnCompileClicked;
|
2021-05-15 01:21:07 +10:00
|
|
|
|
public Action<int> OnHelpDropdownChanged;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
public Action<bool> OnCtrlRToggled;
|
|
|
|
|
public Action<bool> OnSuggestionsToggled;
|
|
|
|
|
public Action<bool> OnAutoIndentToggled;
|
|
|
|
|
|
|
|
|
|
private void InvokeOnValueChanged(string value)
|
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
if (value.Length == UIManager.MAX_INPUTFIELD_CHARS)
|
|
|
|
|
ExplorerCore.LogWarning($"Reached maximum InputField character length! ({UIManager.MAX_INPUTFIELD_CHARS})");
|
|
|
|
|
|
2021-04-30 21:34:50 +10:00
|
|
|
|
OnInputChanged?.Invoke(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2021-05-12 20:48:56 +10:00
|
|
|
|
ConsoleController.Update();
|
2021-04-30 21:34:50 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Saving
|
|
|
|
|
|
|
|
|
|
public override void DoSaveToConfigElement()
|
|
|
|
|
{
|
|
|
|
|
ConfigManager.CSConsoleData.Value = this.ToSaveData();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 23:03:30 +10:00
|
|
|
|
public override string GetSaveDataFromConfigManager() => ConfigManager.CSConsoleData.Value;
|
2021-05-05 21:27:09 +10:00
|
|
|
|
|
|
|
|
|
// UI Construction
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-05 21:27:09 +10:00
|
|
|
|
protected internal override void DoSetDefaultPosAndAnchors()
|
2021-04-30 21:34:50 +10:00
|
|
|
|
{
|
2021-05-18 19:55:27 +10:00
|
|
|
|
Rect.localPosition = Vector2.zero;
|
|
|
|
|
Rect.pivot = new Vector2(0f, 1f);
|
|
|
|
|
Rect.anchorMin = new Vector2(0.4f, 0.175f);
|
|
|
|
|
Rect.anchorMax = new Vector2(0.85f, 0.925f);
|
2021-04-30 21:34:50 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ConstructPanelContent()
|
|
|
|
|
{
|
2021-05-14 06:14:25 +10:00
|
|
|
|
// Tools Row
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-14 06:14:25 +10:00
|
|
|
|
var toolsRow = UIFactory.CreateHorizontalGroup(this.content, "ToggleRow", false, false, true, true, 5, new Vector4(8, 8, 10, 5),
|
|
|
|
|
default, TextAnchor.MiddleLeft);
|
|
|
|
|
UIFactory.SetLayoutElement(toolsRow, minHeight: 25, flexibleHeight: 0, flexibleWidth: 9999);
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-15 01:21:07 +10:00
|
|
|
|
// Buttons
|
|
|
|
|
|
|
|
|
|
var compileButton = UIFactory.CreateButton(toolsRow, "CompileButton", "Compile", new Color(0.33f, 0.5f, 0.33f));
|
|
|
|
|
UIFactory.SetLayoutElement(compileButton.Component.gameObject, minHeight: 28, minWidth: 130, flexibleHeight: 0);
|
|
|
|
|
compileButton.ButtonText.fontSize = 15;
|
|
|
|
|
compileButton.OnClick += () => { OnCompileClicked?.Invoke(); };
|
|
|
|
|
|
|
|
|
|
var resetButton = UIFactory.CreateButton(toolsRow, "ResetButton", "Reset", new Color(0.33f, 0.33f, 0.33f));
|
|
|
|
|
UIFactory.SetLayoutElement(resetButton.Component.gameObject, minHeight: 28, minWidth: 80, flexibleHeight: 0);
|
|
|
|
|
resetButton.ButtonText.fontSize = 15;
|
|
|
|
|
resetButton.OnClick += () => { OnResetClicked?.Invoke(); };
|
|
|
|
|
|
|
|
|
|
// Help dropdown
|
|
|
|
|
|
|
|
|
|
var helpDrop = UIFactory.CreateDropdown(toolsRow, out var dropdown, "Help", 14, null);
|
|
|
|
|
UIFactory.SetLayoutElement(helpDrop, minHeight: 25, minWidth: 100);
|
|
|
|
|
HelpDropdown = dropdown;
|
|
|
|
|
HelpDropdown.onValueChanged.AddListener((int val) => { this.OnHelpDropdownChanged?.Invoke(val); });
|
|
|
|
|
|
2021-04-30 21:34:50 +10:00
|
|
|
|
// Enable Ctrl+R toggle
|
|
|
|
|
|
2021-05-14 06:14:25 +10:00
|
|
|
|
var ctrlRToggleObj = UIFactory.CreateToggle(toolsRow, "CtrlRToggle", out var CtrlRToggle, out Text ctrlRToggleText);
|
|
|
|
|
UIFactory.SetLayoutElement(ctrlRToggleObj, minWidth: 150, flexibleWidth: 0, minHeight: 25);
|
2021-04-30 21:34:50 +10:00
|
|
|
|
ctrlRToggleText.alignment = TextAnchor.UpperLeft;
|
2021-05-14 06:14:25 +10:00
|
|
|
|
ctrlRToggleText.text = "Compile on Ctrl+R";
|
2021-04-30 21:34:50 +10:00
|
|
|
|
CtrlRToggle.onValueChanged.AddListener((bool val) => { OnCtrlRToggled?.Invoke(val); });
|
|
|
|
|
|
|
|
|
|
// Enable Suggestions toggle
|
|
|
|
|
|
2021-05-14 06:14:25 +10:00
|
|
|
|
var suggestToggleObj = UIFactory.CreateToggle(toolsRow, "SuggestionToggle", out var SuggestionsToggle, out Text suggestToggleText);
|
2021-04-30 21:34:50 +10:00
|
|
|
|
UIFactory.SetLayoutElement(suggestToggleObj, minWidth: 120, flexibleWidth: 0, minHeight: 25);
|
|
|
|
|
suggestToggleText.alignment = TextAnchor.UpperLeft;
|
|
|
|
|
suggestToggleText.text = "Suggestions";
|
|
|
|
|
SuggestionsToggle.onValueChanged.AddListener((bool val) => { OnSuggestionsToggled?.Invoke(val); });
|
|
|
|
|
|
|
|
|
|
// Enable Auto-indent toggle
|
|
|
|
|
|
2021-05-14 06:14:25 +10:00
|
|
|
|
var autoIndentToggleObj = UIFactory.CreateToggle(toolsRow, "IndentToggle", out var AutoIndentToggle, out Text autoIndentToggleText);
|
2021-05-15 01:21:07 +10:00
|
|
|
|
UIFactory.SetLayoutElement(autoIndentToggleObj, minWidth: 120, flexibleWidth: 0, minHeight: 25);
|
2021-04-30 21:34:50 +10:00
|
|
|
|
autoIndentToggleText.alignment = TextAnchor.UpperLeft;
|
2021-05-14 02:45:59 +10:00
|
|
|
|
autoIndentToggleText.text = "Auto-indent";
|
2021-04-30 21:34:50 +10:00
|
|
|
|
AutoIndentToggle.onValueChanged.AddListener((bool val) => { OnAutoIndentToggled?.Invoke(val); });
|
|
|
|
|
|
2021-05-14 06:14:25 +10:00
|
|
|
|
// Console Input
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
|
|
|
|
int fontSize = 16;
|
|
|
|
|
|
2021-05-17 18:47:37 +10:00
|
|
|
|
var inputObj = UIFactory.CreateScrollInputField(this.content, "ConsoleInput", ConsoleController.STARTUP_TEXT, out var inputScroller, fontSize);
|
2021-05-10 21:07:27 +10:00
|
|
|
|
InputScroll = inputScroller;
|
2021-05-12 20:48:56 +10:00
|
|
|
|
ConsoleController.defaultInputFieldAlpha = Input.Component.selectionColor.a;
|
2021-05-10 21:07:27 +10:00
|
|
|
|
Input.OnValueChanged += InvokeOnValueChanged;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-11 19:15:46 +10:00
|
|
|
|
InputText = Input.Component.textComponent;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
InputText.supportRichText = false;
|
2021-05-10 23:00:02 +10:00
|
|
|
|
Input.PlaceholderText.fontSize = fontSize;
|
2021-05-15 01:21:07 +10:00
|
|
|
|
InputText.color = Color.clear;
|
|
|
|
|
Input.Component.customCaretColor = true;
|
|
|
|
|
Input.Component.caretColor = Color.white;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
2021-05-10 23:00:02 +10:00
|
|
|
|
// Lexer highlight text overlay
|
|
|
|
|
var highlightTextObj = UIFactory.CreateUIObject("HighlightText", InputText.gameObject);
|
2021-04-30 21:34:50 +10:00
|
|
|
|
var highlightTextRect = highlightTextObj.GetComponent<RectTransform>();
|
|
|
|
|
highlightTextRect.pivot = new Vector2(0, 1);
|
|
|
|
|
highlightTextRect.anchorMin = Vector2.zero;
|
|
|
|
|
highlightTextRect.anchorMax = Vector2.one;
|
2021-05-10 23:00:02 +10:00
|
|
|
|
highlightTextRect.offsetMin = Vector2.zero;
|
|
|
|
|
highlightTextRect.offsetMax = Vector2.zero;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
|
|
|
|
HighlightText = highlightTextObj.AddComponent<Text>();
|
2021-05-15 01:21:07 +10:00
|
|
|
|
HighlightText.color = Color.white;
|
2021-04-30 21:34:50 +10:00
|
|
|
|
HighlightText.supportRichText = true;
|
|
|
|
|
HighlightText.fontSize = fontSize;
|
|
|
|
|
|
2021-05-10 23:00:02 +10:00
|
|
|
|
// Set fonts
|
|
|
|
|
InputText.font = UIManager.ConsoleFont;
|
|
|
|
|
Input.PlaceholderText.font = UIManager.ConsoleFont;
|
|
|
|
|
HighlightText.font = UIManager.ConsoleFont;
|
|
|
|
|
|
2021-04-30 21:34:50 +10:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|