Quellcode durchsuchen

Use null conditional for event handlers

Also modify gizmos
habeebweeb vor 4 Jahren
Ursprung
Commit
cb4d13d301

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

@@ -15,11 +15,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public virtual void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) { }
         public virtual void OnControlEvent(EventArgs args)
         {
-            EventHandler handler = ControlEvent;
-            if (handler != null)
-            {
-                handler(this, args);
-            }
+            ControlEvent?.Invoke(this, args);
         }
     }
 }

+ 3 - 10
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/DropDown.cs

@@ -132,7 +132,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         private void OnDropdownEvent(EventHandler handler)
         {
-            if (handler != null) handler(this, EventArgs.Empty);
+            handler?.Invoke(this, EventArgs.Empty);
         }
     }
 
@@ -233,18 +233,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             if (selection != selectedItemIndex || (clicked && !onScrollBar))
             {
-                EventHandler<DropdownSelectArgs> handler = SelectionChange;
-                if (handler != null)
-                    handler(null, new DropdownSelectArgs(currentDropdownID, selection));
+                SelectionChange?.Invoke(null, new DropdownSelectArgs(currentDropdownID, selection));
                 Visible = false;
             }
 
-            if (!Visible)
-            {
-                EventHandler<DropdownCloseArgs> handler = DropdownClose;
-                if (handler != null)
-                    handler(null, new DropdownCloseArgs(currentDropdownID, scrollPos, clickedYou));
-            }
+            if (!Visible) DropdownClose?.Invoke(null, new DropdownCloseArgs(currentDropdownID, scrollPos, clickedYou));
         }
 
         private static void InitializeStyle()

+ 1 - 5
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MaidSelectorPane.cs

@@ -21,11 +21,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             Controls.Add(clearMaidsButton);
 
             callMaidsButton = new Button("Call");
-            callMaidsButton.ControlEvent += (s, a) =>
-            {
-                EventHandler handler = MaidCall;
-                if (handler != null) handler(this, EventArgs.Empty);
-            };
+            callMaidsButton.ControlEvent += (s, a) => MaidCall?.Invoke(this, EventArgs.Empty);
             Controls.Add(callMaidsButton);
         }
 

+ 1 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MaidSwitcherPane.cs

@@ -62,8 +62,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         private static void OnMaidChange(MeidoChangeEventArgs args)
         {
-            EventHandler<MeidoChangeEventArgs> handler = MaidChange;
-            if (handler != null) handler(null, args);
+            MaidChange?.Invoke(null, args);
         }
     }
 }

+ 1 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/TabsPane.cs

@@ -24,8 +24,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private static void OnChangeTab()
         {
             selectedTab = (Constants.Window)Tabs.SelectedItem;
-            EventHandler handler = TabChange;
-            if (handler != null) handler(null, EventArgs.Empty);
+            TabChange?.Invoke(null, EventArgs.Empty);
         }
 
         public static void Draw()

+ 1 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/DragPointManager.cs

@@ -566,8 +566,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         private void OnMeidoSelect(MeidoChangeEventArgs args)
         {
-            EventHandler<MeidoChangeEventArgs> handler = SelectMaid;
-            if (handler != null) handler(this, args);
+            SelectMaid?.Invoke(this, args);
         }
     }
 }

+ 2 - 8
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/MeidoManager.cs

@@ -149,11 +149,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private void ChangeMeido(object sender, MeidoChangeEventArgs args)
         {
             SelectedMeido = args.selected;
-            // if (args.fromMeido)
-            // {
-            EventHandler<MeidoChangeEventArgs> handler = SelectMeido;
-            if (handler != null) handler(this, args);
-            // }
+            SelectMeido?.Invoke(this, args);
         }
 
         private void EndCallMeidos(object sender, EventArgs args)
@@ -162,9 +158,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             {
                 IsFade = false;
                 GameMain.Instance.MainCamera.FadeIn(1f);
-                EventHandler handler = CalledMeidos;
-                if (handler != null)
-                    handler(this, EventArgs.Empty);
+                CalledMeidos?.Invoke(this, EventArgs.Empty);
             }
         }
     }

+ 10 - 10
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/BaseDrag.cs

@@ -24,7 +24,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         protected bool reInitDrag = false;
         protected bool isPlaying;
         protected GizmoRender gizmo;
-        public bool gizmoVisible;
         public bool Visible
         {
             get => dragPointRenderer.enabled;
@@ -32,22 +31,25 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         }
         public float DragPointScale
         {
+            get => transform.localScale.x;
             set => transform.localScale = new Vector3(value, value, value);
         }
         public float GizmoScale
         {
             set
             {
-                if (gizmo != null)
-                {
-                    gizmo.offsetScale = value;
-                }
+                if (gizmo != null) gizmo.offsetScale = value;
             }
         }
-        private static bool IsGizmoDrag
+        public bool GizmoVisible
         {
-            get => Utility.GetFieldValue<GizmoRender, bool>(null, "is_drag_");
+            get => gizmo?.Visible ?? false;
+            set
+            {
+                if (gizmo != null) gizmo.Visible = value;
+            }
         }
+        private static bool IsGizmoDrag => Utility.GetFieldValue<GizmoRender, bool>(null, "is_drag_");
 
         protected enum DragType
         {
@@ -119,9 +121,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             if (gizmo != null)
             {
-                gizmo.Visible = gizmoVisible;
-
-                if (gizmoVisible)
+                if (GizmoVisible)
                 {
                     if (isPlaying && IsGizmoDrag)
                     {

+ 1 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/DragBody.cs

@@ -42,8 +42,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             if (dragType == DragType.Select)
             {
-                EventHandler handler = Select;
-                if (handler != null) handler(this, EventArgs.Empty);
+                Select?.Invoke(this, EventArgs.Empty);
                 return;
             }
 

+ 1 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/DragHead.cs

@@ -75,8 +75,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             if (dragType == DragType.Select)
             {
-                EventHandler handler = Select;
-                if (handler != null) handler(this, EventArgs.Empty);
+                Select?.Invoke(this, EventArgs.Empty);
                 return;
             }
 

+ 5 - 10
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/Meido.cs

@@ -101,20 +101,17 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             Maid.Visible = false;
 
-            if (dragPointManager != null) dragPointManager.Deactivate();
+            dragPointManager?.Deactivate();
         }
 
         public void Deactivate()
         {
             Unload();
-            if (dragPointManager != null) dragPointManager.Destroy();
+            dragPointManager?.Destroy();
             Maid.SetPos(Vector3.zero);
             Maid.SetRot(Vector3.zero);
             Maid.SetPosOffset(Vector3.zero);
-            if (Maid.body0 != null)
-            {
-                Maid.body0.SetBoneHitHeightY(0f);
-            }
+            Maid.body0?.SetBoneHitHeightY(0f);
 
             Maid.Visible = false;
             Maid.ActiveSlotNo = -1;
@@ -198,14 +195,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         private void OnBodyLoad()
         {
-            EventHandler handler = BodyLoad;
-            if (handler != null) handler(this, EventArgs.Empty);
+            BodyLoad?.Invoke(this, EventArgs.Empty);
         }
 
         private void OnMeidoSelect(MeidoChangeEventArgs args)
         {
-            EventHandler<MeidoChangeEventArgs> handler = SelectMeido;
-            if (handler != null) handler(this, args);
+            SelectMeido?.Invoke(this, args);
         }
     }
 }