From 3e443178618b43ce9bf50160f5dbab081ed96f3d Mon Sep 17 00:00:00 2001 From: Sinai Date: Thu, 13 May 2021 03:55:08 +1000 Subject: [PATCH] Cleanup CSConsole, add start of Options and Log panels --- src/UI/CSConsole/ConsoleController.cs | 59 ++++++++++++--------------- src/UI/Panels/ConsoleLogPanel.cs | 36 ++++++++++++++++ src/UI/Panels/OptionsPanel.cs | 36 ++++++++++++++++ src/UI/UIManager.cs | 10 ++++- src/UnityExplorer.csproj | 2 + 5 files changed, 108 insertions(+), 35 deletions(-) create mode 100644 src/UI/Panels/ConsoleLogPanel.cs create mode 100644 src/UI/Panels/OptionsPanel.cs diff --git a/src/UI/CSConsole/ConsoleController.cs b/src/UI/CSConsole/ConsoleController.cs index 394d030..2bfb9a0 100644 --- a/src/UI/CSConsole/ConsoleController.cs +++ b/src/UI/CSConsole/ConsoleController.cs @@ -276,45 +276,36 @@ The following helper methods are available: int endIdx = Input.Text.Length - 1; int topLine = 0; - try + // Calculate visible text if necessary + if (Input.Rect.rect.height > Panel.InputScroll.ViewportRect.rect.height) { - // Calculate visible text if necessary - if (Input.Rect.rect.height > Panel.InputScroll.ViewportRect.rect.height) + topLine = -1; + int bottomLine = -1; + + // the top and bottom position of the viewport in relation to the text height + // they need the half-height adjustment to normalize against the 'line.topY' value. + var viewportMin = Input.Rect.rect.height - Input.Rect.anchoredPosition.y - (Input.Rect.rect.height * 0.5f); + var viewportMax = viewportMin - Panel.InputScroll.ViewportRect.rect.height; + + for (int i = 0; i < Input.TextGenerator.lineCount; i++) { - topLine = -1; - int bottomLine = -1; - - // the top and bottom position of the viewport in relation to the text height - // they need the half-height adjustment to normalize against the 'line.topY' value. - var viewportMin = Input.Rect.rect.height - Input.Rect.anchoredPosition.y - (Input.Rect.rect.height * 0.5f); - var viewportMax = viewportMin - Panel.InputScroll.ViewportRect.rect.height; - - for (int i = 0; i < Input.TextGenerator.lineCount; i++) - { - var line = Input.TextGenerator.lines[i]; - // if not set the top line yet, and top of line is below the viewport top - if (topLine == -1 && line.topY <= viewportMin) - topLine = i; - // if bottom of line is below the viewport bottom - if ((line.topY - line.height) >= viewportMax) - bottomLine = i; - } - - topLine = Math.Max(0, topLine - 1); - bottomLine = Math.Min(Input.TextGenerator.lineCount - 1, bottomLine + 1); - - startIdx = Input.TextGenerator.lines[topLine].startCharIdx; - endIdx = (bottomLine >= Input.TextGenerator.lineCount - 1) - ? Input.Text.Length - 1 - : (Input.TextGenerator.lines[bottomLine + 1].startCharIdx - 1); + var line = Input.TextGenerator.lines[i]; + // if not set the top line yet, and top of line is below the viewport top + if (topLine == -1 && line.topY <= viewportMin) + topLine = i; + // if bottom of line is below the viewport bottom + if ((line.topY - line.height) >= viewportMax) + bottomLine = i; } - } - catch (Exception ex) - { - ExplorerCore.Log("Exception on HighlightVisibleText: " + ex.GetType().Name + ", " + ex.Message); - } + topLine = Math.Max(0, topLine - 1); + bottomLine = Math.Min(Input.TextGenerator.lineCount - 1, bottomLine + 1); + startIdx = Input.TextGenerator.lines[topLine].startCharIdx; + endIdx = (bottomLine >= Input.TextGenerator.lineCount - 1) + ? Input.Text.Length - 1 + : (Input.TextGenerator.lines[bottomLine + 1].startCharIdx - 1); + } // Highlight the visible text with the LexerBuilder Panel.HighlightText.text = Lexer.BuildHighlightedString(Input.Text, startIdx, endIdx, topLine); diff --git a/src/UI/Panels/ConsoleLogPanel.cs b/src/UI/Panels/ConsoleLogPanel.cs new file mode 100644 index 0000000..dc9e167 --- /dev/null +++ b/src/UI/Panels/ConsoleLogPanel.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UnityExplorer.UI.Panels +{ + public class ConsoleLogPanel : UIPanel + { + public override string Name => "Console Log"; + public override UIManager.Panels PanelType => UIManager.Panels.ConsoleLog; + + public override int MinWidth => 300; + public override int MinHeight => 75; + + public override void ConstructPanelContent() + { + throw new NotImplementedException(); + } + + public override void DoSaveToConfigElement() + { + throw new NotImplementedException(); + } + + public override string GetSaveData() + { + throw new NotImplementedException(); + } + + protected internal override void DoSetDefaultPosAndAnchors() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/UI/Panels/OptionsPanel.cs b/src/UI/Panels/OptionsPanel.cs new file mode 100644 index 0000000..aff3f95 --- /dev/null +++ b/src/UI/Panels/OptionsPanel.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UnityExplorer.UI.Panels +{ + public class OptionsPanel : UIPanel + { + public override string Name => "Options"; + public override UIManager.Panels PanelType => UIManager.Panels.Options; + + public override int MinWidth => 400; + public override int MinHeight => 200; + + public override void ConstructPanelContent() + { + throw new NotImplementedException(); + } + + public override void DoSaveToConfigElement() + { + throw new NotImplementedException(); + } + + public override string GetSaveData() + { + throw new NotImplementedException(); + } + + protected internal override void DoSetDefaultPosAndAnchors() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index a27695b..cc4186b 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -39,10 +39,12 @@ namespace UnityExplorer.UI // panels internal static GameObject PanelHolder { get; private set; } - + public static ObjectExplorerPanel Explorer { get; private set; } public static InspectorPanel Inspector { get; private set; } public static CSConsolePanel CSharpConsole { get; private set; } + public static OptionsPanel Options { get; private set; } + public static ConsoleLogPanel ConsoleLog { get; private set; } public static AutoCompleteModal AutoCompleter { get; private set; } @@ -180,6 +182,12 @@ namespace UnityExplorer.UI CSharpConsole.ConstructUI(); ConsoleController.Init(); + Options = new OptionsPanel(); + Options.ConstructUI(); + + ConsoleLog = new ConsoleLogPanel(); + ConsoleLog.ConstructUI(); + ShowMenu = !ConfigManager.Hide_On_Startup.Value; ExplorerCore.Log("UI initialized."); diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index b1fc840..8b6123c 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -262,8 +262,10 @@ + +