Jelajahi Sumber

Clean up GUI controls

habeebweeb 4 tahun lalu
induk
melakukan
a95f06cfae

+ 1 - 10
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/BaseControl.cs

@@ -1,21 +1,12 @@
 using System;
 using UnityEngine;
-using UnityEngine.SceneManagement;
 
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     internal abstract class BaseControl
     {
         public event EventHandler ControlEvent;
-        public bool Enabled { get; set; } = true;
-        public bool Visible { get; set; } = true;
         public virtual void Draw(params GUILayoutOption[] layoutOptions) { }
-        public virtual void Update() { }
-        public virtual void Awake() { }
-        public virtual void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) { }
-        public virtual void OnControlEvent(EventArgs args)
-        {
-            ControlEvent?.Invoke(this, args);
-        }
+        public virtual void OnControlEvent(EventArgs args) => ControlEvent?.Invoke(this, args);
     }
 }

+ 1 - 5
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/Button.cs

@@ -6,13 +6,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     internal class Button : BaseControl
     {
         public string Label { get; set; }
-        public Button(string label)
-        {
-            Label = label;
-        }
+        public Button(string label) => Label = label;
         public void Draw(GUIStyle buttonStyle, params GUILayoutOption[] layoutOptions)
         {
-            if (!Visible) return;
             if (GUILayout.Button(Label, buttonStyle, layoutOptions)) OnControlEvent(EventArgs.Empty);
         }
 

+ 4 - 13
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/ComboBox.cs

@@ -30,26 +30,17 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public void SetDropdownItem(string newItem) => BaseDropDown.SetDropdownItem(newItem);
 
-        public void Draw(float buttonSize, GUIStyle textFieldStyle, params GUILayoutOption[] layoutOptions)
+        public override void Draw(params GUILayoutOption[] layoutOptions)
         {
-            GUILayout.BeginHorizontal();
-            textField.Draw(textFieldStyle, layoutOptions);
             GUIStyle buttonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleCenter };
-            BaseDropDown.Draw(buttonStyle, GUILayout.Width(buttonSize), GUILayout.Height(buttonSize));
-            GUILayout.EndHorizontal();
-        }
-
-        public void Draw(float buttonSize, params GUILayoutOption[] layoutOptions)
-        {
-            Draw(buttonSize, new GUIStyle(GUI.skin.textField), layoutOptions);
+            Draw(buttonStyle, layoutOptions);
         }
 
-        public override void Draw(params GUILayoutOption[] layoutOptions)
+        public void Draw(GUIStyle style, params GUILayoutOption[] layoutOptions)
         {
             GUILayout.BeginHorizontal();
             textField.Draw(new GUIStyle(GUI.skin.textField), layoutOptions);
-            GUIStyle buttonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleCenter };
-            BaseDropDown.Draw(buttonStyle, GUILayout.ExpandWidth(false));
+            BaseDropDown.Draw(style, GUILayout.ExpandWidth(false));
             GUILayout.EndHorizontal();
         }
     }

+ 0 - 3
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/Slider.cs

@@ -55,8 +55,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             this.value = Utility.Bound(value, left, right);
         }
 
-        public Slider(float min, float max, float value = 0f) : this(string.Empty, min, max, value) { }
-
         public Slider(string label, SliderProp prop) : this(label, prop.Left, prop.Right, prop.Initial) { }
 
         public Slider(SliderProp prop) : this(string.Empty, prop.Left, prop.Right, prop.Initial) { }
@@ -70,7 +68,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public override void Draw(params GUILayoutOption[] layoutOptions)
         {
-            if (!Visible) return;
             GUIStyle sliderStyle = new GUIStyle(GUI.skin.horizontalSlider);
             sliderStyle.margin.bottom = 0;
             if (hasLabel)

+ 0 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/TextArea.cs

@@ -7,7 +7,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public string Value { get; set; } = string.Empty;
         public void Draw(GUIStyle textAreaStyle, params GUILayoutOption[] layoutOptions)
         {
-            if (!Visible) return;
             Value = GUILayout.TextArea(Value, textAreaStyle, layoutOptions);
         }
         public override void Draw(params GUILayoutOption[] layoutOptions)

+ 0 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/TextField.cs

@@ -11,7 +11,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public string Value { get; set; } = string.Empty;
         public void Draw(GUIStyle textFieldStyle, params GUILayoutOption[] layoutOptions)
         {
-            if (!Visible) return;
             GUI.SetNextControlName(controlName);
             Value = GUILayout.TextField(Value, textFieldStyle, layoutOptions);
             if (Event.current.isKey && Event.current.keyCode == KeyCode.Return) OnControlEvent(EventArgs.Empty);

+ 0 - 3
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/Toggle.cs

@@ -18,8 +18,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public string Label { get; set; }
 
-        public Toggle(bool state = false) : this("", state) { }
-
         public Toggle(string label, bool state = false)
         {
             Label = label;
@@ -33,7 +31,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public void Draw(GUIStyle toggleStyle, params GUILayoutOption[] layoutOptions)
         {
-            if (!Visible) return;
             bool value = GUILayout.Toggle(Value, Label, toggleStyle, layoutOptions);
             if (value != Value) Value = value;
         }