using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; using UnityExplorer.Config; using UnityExplorer.Helpers; using UnityExplorer.UI.Shared; using UnityExplorer.Unstrip; namespace UnityExplorer.UI.Modules { public class OptionsPage : MainMenu.Page { public override string Name => "Options"; private InputField m_keycodeInput; private Toggle m_unlockMouseToggle; private InputField m_pageLimitInput; private InputField m_defaultOutputInput; private Toggle m_hideOnStartupToggle; public override void Init() { ConstructUI(); } public override void Update() { } internal void OnApply() { if (!string.IsNullOrEmpty(m_keycodeInput.text) && Enum.Parse(typeof(KeyCode), m_keycodeInput.text) is KeyCode keyCode) ExplorerConfig.Instance.Main_Menu_Toggle = keyCode; ExplorerConfig.Instance.Force_Unlock_Mouse = m_unlockMouseToggle.isOn; if (!string.IsNullOrEmpty(m_pageLimitInput.text) && int.TryParse(m_pageLimitInput.text, out int lim)) ExplorerConfig.Instance.Default_Page_Limit = lim; ExplorerConfig.Instance.Default_Output_Path = m_defaultOutputInput.text; ExplorerConfig.Instance.Hide_On_Startup = m_hideOnStartupToggle.isOn; ExplorerConfig.SaveSettings(); ExplorerConfig.InvokeConfigChanged(); } #region UI CONSTRUCTION internal void ConstructUI() { GameObject parent = MainMenu.Instance.PageViewport; Content = UIFactory.CreateVerticalGroup(parent, new Color(0.15f, 0.15f, 0.15f)); var mainGroup = Content.GetComponent(); mainGroup.padding.left = 4; mainGroup.padding.right = 4; mainGroup.padding.top = 4; mainGroup.padding.bottom = 4; mainGroup.spacing = 5; mainGroup.childForceExpandHeight = false; mainGroup.childForceExpandWidth = true; mainGroup.childControlHeight = true; mainGroup.childControlWidth = true; // ~~~~~ Title ~~~~~ GameObject titleObj = UIFactory.CreateLabel(Content, TextAnchor.UpperLeft); Text titleLabel = titleObj.GetComponent(); titleLabel.text = "Options"; titleLabel.fontSize = 20; LayoutElement titleLayout = titleObj.AddComponent(); titleLayout.minHeight = 30; titleLayout.flexibleHeight = 0; // ~~~~~ Actual options ~~~~~ var optionsGroupObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f)); var optionsGroup = optionsGroupObj.GetComponent(); optionsGroup.childForceExpandHeight = false; optionsGroup.childForceExpandWidth = true; optionsGroup.childControlWidth = true; optionsGroup.childControlHeight = true; optionsGroup.spacing = 5; optionsGroup.padding.top = 5; optionsGroup.padding.left = 5; optionsGroup.padding.right = 5; optionsGroup.padding.bottom = 5; ConstructKeycodeOpt(optionsGroupObj); ConstructMouseUnlockOpt(optionsGroupObj); ConstructPageLimitOpt(optionsGroupObj); ConstructOutputPathOpt(optionsGroupObj); ConstructHideOnStartupOpt(optionsGroupObj); var applyBtnObj = UIFactory.CreateButton(Content, new Color(0.2f, 0.2f, 0.2f)); var applyText = applyBtnObj.GetComponentInChildren(); applyText.text = "Apply and Save"; var applyLayout = applyBtnObj.AddComponent(); applyLayout.minHeight = 30; applyLayout.flexibleWidth = 1000; var applyBtn = applyBtnObj.GetComponent