|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using Explorer.Tests; |
| 6 | +using UnityEngine; |
| 7 | + |
| 8 | +namespace Explorer |
| 9 | +{ |
| 10 | + public class OptionsPage : WindowPage |
| 11 | + { |
| 12 | + public override string Name => "Options"; |
| 13 | + |
| 14 | + public string toggleKeyInputString = ""; |
| 15 | + public Vector2 defaultSizeInputVector; |
| 16 | + public int defaultPageLimit; |
| 17 | + |
| 18 | + private CacheObjectBase toggleKeyInput; |
| 19 | + private CacheObjectBase defaultSizeInput; |
| 20 | + private CacheObjectBase defaultPageLimitInput; |
| 21 | + |
| 22 | + public override void Init() |
| 23 | + { |
| 24 | + toggleKeyInputString = ModConfig.Instance.Main_Menu_Toggle.ToString(); |
| 25 | + toggleKeyInput = CacheFactory.GetTypeAndCacheObject(typeof(OptionsPage).GetField("toggleKeyInputString"), this); |
| 26 | + |
| 27 | + defaultSizeInputVector = ModConfig.Instance.Default_Window_Size; |
| 28 | + defaultSizeInput = CacheFactory.GetTypeAndCacheObject(typeof(OptionsPage).GetField("defaultSizeInputVector"), this); |
| 29 | + |
| 30 | + defaultPageLimit = ModConfig.Instance.Default_Page_Limit; |
| 31 | + defaultPageLimitInput = CacheFactory.GetTypeAndCacheObject(typeof(OptionsPage).GetField("defaultPageLimit"), this); |
| 32 | + } |
| 33 | + |
| 34 | + public override void Update() { } |
| 35 | + |
| 36 | + public override void DrawWindow() |
| 37 | + { |
| 38 | + GUI.skin.label.alignment = TextAnchor.MiddleCenter; |
| 39 | + GUILayout.Label("<color=orange><size=16><b>Settings</b></size></color>", new GUILayoutOption[0]); |
| 40 | + GUI.skin.label.alignment = TextAnchor.MiddleLeft; |
| 41 | + |
| 42 | + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[0]); |
| 43 | + |
| 44 | + GUILayout.BeginHorizontal(new GUILayoutOption[0]); |
| 45 | + GUILayout.Label($"Menu Toggle Key:", new GUILayoutOption[] { GUILayout.Width(215f) }); |
| 46 | + toggleKeyInput.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f); |
| 47 | + GUILayout.EndHorizontal(); |
| 48 | + |
| 49 | + GUILayout.BeginHorizontal(new GUILayoutOption[0]); |
| 50 | + GUILayout.Label($"Default Window Size:", new GUILayoutOption[] { GUILayout.Width(215f) }); |
| 51 | + defaultSizeInput.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f); |
| 52 | + GUILayout.EndHorizontal(); |
| 53 | + |
| 54 | + GUILayout.BeginHorizontal(new GUILayoutOption[0]); |
| 55 | + GUILayout.Label($"Default Items per Page:", new GUILayoutOption[] { GUILayout.Width(215f) }); |
| 56 | + defaultPageLimitInput.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f); |
| 57 | + GUILayout.EndHorizontal(); |
| 58 | + |
| 59 | + if (GUILayout.Button("<color=lime><b>Apply and Save</b></color>", new GUILayoutOption[0])) |
| 60 | + { |
| 61 | + ApplyAndSave(); |
| 62 | + } |
| 63 | + |
| 64 | + GUILayout.EndVertical(); |
| 65 | + |
| 66 | + //GUIUnstrip.Space(10f); |
| 67 | + |
| 68 | + //GUI.skin.label.alignment = TextAnchor.MiddleCenter; |
| 69 | + //GUILayout.Label("<color=orange><size=16><b>Other</b></size></color>", new GUILayoutOption[0]); |
| 70 | + //GUI.skin.label.alignment = TextAnchor.MiddleLeft; |
| 71 | + |
| 72 | + //GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[0]); |
| 73 | + |
| 74 | + //if (GUILayout.Button("Inspect Test Class", new GUILayoutOption[0])) |
| 75 | + //{ |
| 76 | + // WindowManager.InspectObject(TestClass.Instance, out bool _); |
| 77 | + //} |
| 78 | + |
| 79 | + //GUILayout.EndVertical(); |
| 80 | + } |
| 81 | + |
| 82 | + private void ApplyAndSave() |
| 83 | + { |
| 84 | + if (Enum.Parse(typeof(KeyCode), toggleKeyInputString) is KeyCode key) |
| 85 | + { |
| 86 | + ModConfig.Instance.Main_Menu_Toggle = key; |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + ExplorerCore.LogWarning($"Could not parse '{toggleKeyInputString}' to KeyCode!"); |
| 91 | + } |
| 92 | + |
| 93 | + ModConfig.Instance.Default_Window_Size = defaultSizeInputVector; |
| 94 | + ModConfig.Instance.Default_Page_Limit = defaultPageLimit; |
| 95 | + |
| 96 | + ModConfig.SaveSettings(); |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments