123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- namespace COM3D2.MeidoPhotoStudio.Plugin
- {
- internal class MaidPoseSelectorPane : BasePane
- {
- private MeidoManager meidoManager;
- private Button poseLeftButton;
- private Button poseRightButton;
- private Button poseGroupLeftButton;
- private Button poseGroupRightButton;
- private Dropdown poseGroupDropdown;
- private Dropdown poseDropdown;
- private SelectionGrid poseModeGrid;
- private bool customPoseMode;
- private bool poseListEnabled;
- private Dictionary<string, List<string>> CurrentPoseDict
- {
- get => customPoseMode ? Constants.CustomPoseDict : Constants.PoseDict;
- }
- private List<string> CurrentPoseGroupList
- {
- get => customPoseMode ? Constants.CustomPoseGroupList : Constants.PoseGroupList;
- }
- private string SelectedPoseGroup => CurrentPoseGroupList[poseGroupDropdown.SelectedItemIndex];
- private List<string> CurrentPoseList => CurrentPoseDict[SelectedPoseGroup];
- private int SelectedPoseIndex => poseDropdown.SelectedItemIndex;
- private string SelectedPose => CurrentPoseList[SelectedPoseIndex];
- private PoseInfo CurrentPoseInfo => new PoseInfo(SelectedPoseGroup, SelectedPose, customPoseMode);
- private string previousPoseGroup;
- private static readonly string[] tabTranslations = new[] { "baseTab", "customTab" };
- public MaidPoseSelectorPane(MeidoManager meidoManager)
- {
- Constants.customPoseChange += SavePoseEnd;
- this.meidoManager = meidoManager;
- this.poseModeGrid = new SelectionGrid(Translation.GetArray("posePane", tabTranslations));
- this.poseModeGrid.ControlEvent += (s, a) => SetPoseMode();
- this.poseGroupDropdown = new Dropdown(Translation.GetArray("poseGroupDropdown", Constants.PoseGroupList));
- this.poseGroupDropdown.SelectionChange += (s, a) => ChangePoseGroup();
- this.poseDropdown = new Dropdown(UIPoseList());
- this.poseDropdown.SelectionChange += (s, a) => ChangePose();
- this.poseGroupLeftButton = new Button("<");
- this.poseGroupLeftButton.ControlEvent += (s, a) => poseGroupDropdown.Step(-1);
- this.poseGroupRightButton = new Button(">");
- this.poseGroupRightButton.ControlEvent += (s, a) => poseGroupDropdown.Step(1);
- this.poseLeftButton = new Button("<");
- this.poseLeftButton.ControlEvent += (s, a) => poseDropdown.Step(-1);
- this.poseRightButton = new Button(">");
- this.poseRightButton.ControlEvent += (s, a) => poseDropdown.Step(1);
- this.customPoseMode = poseModeGrid.SelectedItemIndex == 1;
- this.previousPoseGroup = SelectedPoseGroup;
- this.poseListEnabled = CurrentPoseList.Count > 0;
- }
- protected override void ReloadTranslation()
- {
- this.updating = true;
- this.poseModeGrid.SetItems(Translation.GetArray("posePane", tabTranslations));
- if (!customPoseMode)
- {
- this.poseGroupDropdown.SetDropdownItems(
- Translation.GetArray("poseGroupDropdown", Constants.PoseGroupList)
- );
- }
- this.updating = false;
- }
- public override void Draw()
- {
- float arrowButtonSize = 30f;
- GUILayoutOption[] arrowLayoutOptions = {
- GUILayout.Width(arrowButtonSize),
- GUILayout.Height(arrowButtonSize)
- };
- float dropdownButtonHeight = arrowButtonSize;
- float dropdownButtonWidth = 153f;
- GUILayoutOption[] dropdownLayoutOptions = new GUILayoutOption[] {
- GUILayout.Height(dropdownButtonHeight),
- GUILayout.Width(dropdownButtonWidth)
- };
- GUI.enabled = meidoManager.HasActiveMeido && !meidoManager.ActiveMeido.Stop;
- this.poseModeGrid.Draw();
- MiscGUI.WhiteLine();
- GUILayout.BeginHorizontal();
- this.poseGroupLeftButton.Draw(arrowLayoutOptions);
- this.poseGroupDropdown.Draw(dropdownLayoutOptions);
- this.poseGroupRightButton.Draw(arrowLayoutOptions);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUI.enabled = GUI.enabled && poseListEnabled;
- this.poseLeftButton.Draw(arrowLayoutOptions);
- this.poseDropdown.Draw(dropdownLayoutOptions);
- this.poseRightButton.Draw(arrowLayoutOptions);
- GUILayout.EndHorizontal();
- GUI.enabled = true;
- }
- public override void UpdatePane()
- {
- this.updating = true;
- PoseInfo poseInfo = this.meidoManager.ActiveMeido.CachedPose;
- bool oldPoseMode = customPoseMode;
- poseModeGrid.SelectedItemIndex = poseInfo.CustomPose ? 1 : 0;
- int poseGroupIndex = CurrentPoseGroupList.IndexOf(poseInfo.PoseGroup);
- if (poseGroupIndex < 0) poseGroupIndex = 0;
- int poseIndex = CurrentPoseDict[poseInfo.PoseGroup].IndexOf(poseInfo.Pose);
- if (poseIndex < 0) poseIndex = 0;
- if (oldPoseMode != customPoseMode)
- {
- string[] list = customPoseMode
- ? CurrentPoseGroupList.ToArray()
- : Translation.GetArray("poseGroupDropdown", CurrentPoseGroupList);
- this.poseGroupDropdown.SetDropdownItems(list);
- }
- this.poseGroupDropdown.SelectedItemIndex = poseGroupIndex;
- this.poseDropdown.SelectedItemIndex = poseIndex;
- this.updating = false;
- }
- private void SavePoseEnd(object sender, CustomPoseEventArgs args)
- {
- this.updating = true;
- this.poseModeGrid.SelectedItemIndex = 1;
- this.poseGroupDropdown.SetDropdownItems(
- CurrentPoseGroupList.ToArray(), CurrentPoseGroupList.IndexOf(args.Category)
- );
- this.updating = false;
- this.poseDropdown.SetDropdownItems(UIPoseList(), CurrentPoseDict[args.Category].IndexOf(args.Path));
- poseListEnabled = true;
- }
- private void SetPoseMode()
- {
- customPoseMode = poseModeGrid.SelectedItemIndex == 1;
- if (this.updating) return;
- string[] list = customPoseMode
- ? CurrentPoseGroupList.ToArray()
- : Translation.GetArray("poseGroupDropdown", CurrentPoseGroupList);
- this.poseGroupDropdown.SetDropdownItems(list, 0);
- }
- private void ChangePoseGroup()
- {
- if (previousPoseGroup == SelectedPoseGroup)
- {
- this.poseDropdown.SelectedItemIndex = 0;
- }
- else
- {
- previousPoseGroup = SelectedPoseGroup;
- this.poseDropdown.SetDropdownItems(UIPoseList(), 0);
- }
- }
- private void ChangePose()
- {
- if (!poseListEnabled || updating) return;
- meidoManager.ActiveMeido.SetPose(CurrentPoseInfo);
- }
- private string[] UIPoseList()
- {
- if (CurrentPoseList.Count == 0) return new[] { "No Poses" };
- else
- {
- return CurrentPoseList.Select((pose, i) =>
- {
- return $"{i + 1}:{(customPoseMode ? Path.GetFileNameWithoutExtension(pose) : pose)}";
- }).ToArray();
- }
- }
- }
- }
|