From 06cb911ea34722d5539482e712a538912f9626b8 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 31 May 2021 17:59:25 -0400 Subject: [PATCH] Update IMGUI to something roughly TB-like --- .../Interface/IMGUI/Constants.cs | 66 +++++++++---------- .../Tests/TechbloxModdingAPIPluginTest.cs | 2 +- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/TechbloxModdingAPI/Interface/IMGUI/Constants.cs b/TechbloxModdingAPI/Interface/IMGUI/Constants.cs index a966a5f..02564a6 100644 --- a/TechbloxModdingAPI/Interface/IMGUI/Constants.cs +++ b/TechbloxModdingAPI/Interface/IMGUI/Constants.cs @@ -33,7 +33,7 @@ namespace TechbloxModdingAPI.Interface.IMGUI } } - private static Font _riffic = null; + private static Font _font = null; private static Texture2D _blueBackground = null; private static Texture2D _grayBackground = null; @@ -49,12 +49,13 @@ namespace TechbloxModdingAPI.Interface.IMGUI private static GUISkin BuildDefaultGUISkin() { _defaultCompletion = 0; - if (_riffic == null) return GUI.skin; + //if (_font == null) return GUI.skin; // build GUISkin GUISkin gui = ScriptableObject.CreateInstance(); - gui.font = _riffic; + gui.font = _font; gui.settings.selectionColor = Color.white; gui.settings.tripleClickSelectsLine = true; + Color textColour = new Color(0.706f, 0.706f, 0.706f); // set properties off all UI elements foreach (PropertyInfo p in typeof(GUISkin).GetProperties()) { @@ -63,29 +64,30 @@ namespace TechbloxModdingAPI.Interface.IMGUI { style.richText = true; style.alignment = TextAnchor.MiddleCenter; - style.fontSize = 30; + style.fontSize = 16; style.wordWrap = true; style.border = new RectOffset(4, 4, 4, 4); style.margin = new RectOffset(4, 4, 4, 4); style.padding = new RectOffset(4, 4, 4, 4); // normal state - style.normal.background = _blueBackground; - style.normal.textColor = Color.white; + style.normal.background = _grayBackground; + style.normal.textColor = textColour; // hover state style.hover.background = _grayBackground; - style.hover.textColor = Color.white; + style.hover.textColor = textColour; // focused style.focused.background = _grayBackground; - style.focused.textColor = Color.white; + style.focused.textColor = textColour; // clicking state style.active.background = _whiteBackground; - style.active.textColor = Color.white; + style.active.textColor = textColour; p.SetValue(gui, style); // probably unnecessary } } // set element-specific styles // label + gui.label.fontSize = 20; gui.label.normal.background = null; gui.label.hover.background = null; gui.label.focused.background = null; @@ -115,35 +117,29 @@ namespace TechbloxModdingAPI.Interface.IMGUI private static void LoadGUIAssets() { - AsyncOperationHandle rifficHandle = Addressables.LoadAssetAsync("Assets/Art/Fonts/riffic-bold.ttf"); - rifficHandle.Completed += handle => + /*AsyncOperationHandle fontHandle = Addressables.LoadAssetAsync("Assets/Plugins/TextMesh Pro/Fonts/LiberationSans.ttf"); + fontHandle.Completed += handle => { - _riffic = handle.Result; - _defaultCompletion++; - }; - _blueBackground = new Texture2D(1, 1); - _blueBackground.SetPixel(0, 0, new Color(0.004f, 0.522f, 0.847f) /* Techblox Blue */); - _blueBackground.Apply(); - _grayBackground = new Texture2D(1, 1); - _grayBackground.SetPixel(0, 0, new Color(0.745f, 0.745f, 0.745f) /* Gray */); - _grayBackground.Apply(); - _whiteBackground = new Texture2D(1, 1); - _whiteBackground.SetPixel(0, 0, new Color(0.898f, 0.898f, 0.898f) /* Very light gray */); - _whiteBackground.Apply(); - _textInputBackground = new Texture2D(1, 1); - _textInputBackground.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.25f) /* Translucent gray */); - _textInputBackground.Apply(); - _areaBackground = new Texture2D(1, 1); - _areaBackground.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.25f) /* Translucent gray */); - _areaBackground.Apply(); - /* // this is actually gray (used for the loading screen) - AsyncOperationHandle backgroundHandle = - Addressables.LoadAssetAsync("Assets/Art/Textures/UI/FrontEndMap/RCX_Blue_Background_5k.jpg"); - backgroundHandle.Completed += handle => - { - _blueBackground = handle.Result; + _font = handle.Result; _defaultCompletion++; };*/ + _font = Resources.Load("Assets/Plugins/TextMesh Pro/Fonts/LiberationSans.ttf"); + // TODO generate larger textures with borders on them so it actually looks more like Techblox + _blueBackground = new Texture2D(1, 1); + _blueBackground.SetPixel(0, 0, new Color(0.004f, 0.522f, 0.847f) /* Gamecraft Blue, unused */); + _blueBackground.Apply(); + _grayBackground = new Texture2D(1, 1); + _grayBackground.SetPixel(0, 0, new Color(0.11f, 0.11f, 0.11f, 1f) /* Very dark gray */); + _grayBackground.Apply(); + _whiteBackground = new Texture2D(1, 1); + _whiteBackground.SetPixel(0, 0, new Color(0.961f, 0.961f, 0.961f) /* Very light gray */); + _whiteBackground.Apply(); + _textInputBackground = new Texture2D(1, 1); + _textInputBackground.SetPixel(0, 0, new Color(0.961f, 0.961f, 0.961f) /* Very light gray */); + _textInputBackground.Apply(); + _areaBackground = new Texture2D(1, 1); + _areaBackground.SetPixel(0, 0, new Color(0.051f, 0.051f, 0.051f, 1f) /* Very very dark gray */); + _areaBackground.Apply(); _defaultCompletion++; } } diff --git a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs index f618211..d938482 100644 --- a/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs +++ b/TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs @@ -216,7 +216,7 @@ namespace TechbloxModdingAPI.Tests button.OnClick += (b, __) => { Logging.MetaDebugLog($"Click on {((Interface.IMGUI.Button)b).Name}");}; var button2 = new Button("TEST2"); button2.OnClick += (b, __) => { Logging.MetaDebugLog($"Click on {((Interface.IMGUI.Button)b).Name}");}; - Text uiText = new Text("This is text!", multiline: true); + Text uiText = new Text("", multiline: true); uiText.OnEdit += (t, txt) => { Logging.MetaDebugLog($"Text in {((Text)t).Name} is now '{txt}'"); }; Label uiLabel = new Label("Label!"); Image uiImg = new Image(name:"Behold this texture!");