Selaa lähdekoodia

Fix pose selector breaking when loading scene

Scenes that refer to a custom pose file that doesn't exist on the file
system broke the pose selector when it updates its content.
habeebweeb 2 vuotta sitten
vanhempi
commit
5a235040f8

+ 42 - 20
src/MeidoPhotoStudio.Plugin/GUI/Panes/PoseWindowPanes/MaidPoseSelectorPane.cs

@@ -112,33 +112,51 @@ namespace MeidoPhotoStudio.Plugin
         {
             updating = true;
 
-            PoseInfo poseInfo = meidoManager.ActiveMeido.CachedPose;
+            try
+            {
+                var cachedPose = meidoManager.ActiveMeido.CachedPose;
 
-            bool oldPoseMode = customPoseMode;
+                poseModeGrid.SelectedItemIndex = cachedPose.CustomPose ? 1 : 0;
 
-            poseModeGrid.SelectedItemIndex = poseInfo.CustomPose ? 1 : 0;
+                var oldCustomPoseMode = customPoseMode;
+                customPoseMode = cachedPose.CustomPose;
 
-            int poseGroupIndex = CurrentPoseGroupList.IndexOf(poseInfo.PoseGroup);
+                if (oldCustomPoseMode != customPoseMode)
+                    poseGroupDropdown.SetDropdownItems(
+                        customPoseMode ? CurrentPoseGroupList.ToArray() : Translation.GetArray(
+                            "poseGroupDropdown", CurrentPoseGroupList
+                        )
+                    );
 
-            if (poseGroupIndex < 0) poseGroupIndex = 0;
+                var newPoseGroupIndex = CurrentPoseGroupList.IndexOf(cachedPose.PoseGroup);
 
-            int poseIndex = CurrentPoseDict[poseInfo.PoseGroup].IndexOf(poseInfo.Pose);
+                if (newPoseGroupIndex < 0)
+                    poseGroupDropdown.SelectedItemIndex = 0;
+                else if (oldCustomPoseMode != customPoseMode
+                    || poseGroupDropdown.SelectedItemIndex != newPoseGroupIndex)
+                {
+                    poseGroupDropdown.SelectedItemIndex = newPoseGroupIndex;
+                    poseDropdown.SetDropdownItems(UIPoseList());
+                }
 
-            if (poseIndex < 0) poseIndex = 0;
+                var newPoseIndex = CurrentPoseDict.TryGetValue(cachedPose.PoseGroup, out var poseList)
+                    ? poseList.IndexOf(cachedPose.Pose)
+                    : 0;
 
-            if (oldPoseMode != customPoseMode)
-            {
-                string[] list = customPoseMode
-                    ? CurrentPoseGroupList.ToArray()
-                    : Translation.GetArray("poseGroupDropdown", CurrentPoseGroupList);
+                if (newPoseIndex < 0)
+                    newPoseIndex = 0;
 
-                poseGroupDropdown.SetDropdownItems(list);
+                poseDropdown.SelectedItemIndex = newPoseIndex;
+                poseListEnabled = CurrentPoseList.Count > 0;
+            }
+            catch
+            {
+                // Do nothing
+            }
+            finally
+            {
+                updating = false;
             }
-
-            poseGroupDropdown.SelectedItemIndex = poseGroupIndex;
-            poseDropdown.SelectedItemIndex = poseIndex;
-
-            updating = false;
         }
 
         private void OnPresetChange(object sender, PresetChangeEventArgs args)
@@ -169,9 +187,10 @@ namespace MeidoPhotoStudio.Plugin
 
         private void SetPoseMode()
         {
-            customPoseMode = poseModeGrid.SelectedItemIndex == 1;
+            if (updating)
+                return;
 
-            if (updating) return;
+            customPoseMode = poseModeGrid.SelectedItemIndex == 1;
 
             string[] list = customPoseMode
                 ? CurrentPoseGroupList.ToArray()
@@ -182,6 +201,9 @@ namespace MeidoPhotoStudio.Plugin
 
         private void ChangePoseGroup()
         {
+            if (updating)
+                return;
+
             poseListEnabled = CurrentPoseList.Count > 0;
             if (previousPoseGroup == SelectedPoseGroup)
             {