123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using UnityEngine;
- namespace COM3D2.MeidoPhotoStudio.Plugin
- {
- public class MaidSwitcherPane : BasePane
- {
- private readonly MeidoManager meidoManager;
- private readonly Button previousButton;
- private readonly Button nextButton;
- private readonly Toggle editToggle;
- public MaidSwitcherPane(MeidoManager meidoManager)
- {
- this.meidoManager = meidoManager;
- this.meidoManager.UpdateMeido += (s, a) => UpdatePane();
- previousButton = new Button("<");
- previousButton.ControlEvent += (s, a) => ChangeMaid(-1);
- nextButton = new Button(">");
- nextButton.ControlEvent += (s, a) => ChangeMaid(1);
- editToggle = new Toggle("Edit", true);
- editToggle.ControlEvent += (s, a) => SetEditMaid();
- }
- public override void Draw()
- {
- const float boxSize = 70;
- const int margin = (int)(boxSize / 2.8f);
- GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
- buttonStyle.margin.top = margin;
- GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
- labelStyle.margin.top = margin;
- GUIStyle boxStyle = new GUIStyle(GUI.skin.box) { margin = new RectOffset(0, 0, 0, 0) };
- GUIStyle horizontalStyle = new GUIStyle { padding = new RectOffset(4, 4, 0, 0) };
- GUILayoutOption[] buttonOptions = new[] { GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(false) };
- GUILayoutOption[] boxLayoutOptions = new[] { GUILayout.Height(boxSize), GUILayout.Width(boxSize) };
- GUI.enabled = meidoManager.HasActiveMeido;
- Meido meido = meidoManager.ActiveMeido;
- GUILayout.BeginHorizontal(horizontalStyle, GUILayout.Height(boxSize));
- previousButton.Draw(buttonStyle, buttonOptions);
- GUILayout.Space(20);
- if (meidoManager.HasActiveMeido && meido.Portrait) MpsGui.DrawTexture(meido.Portrait, boxLayoutOptions);
- else GUILayout.Box(GUIContent.none, boxStyle, boxLayoutOptions);
- string label = meidoManager.HasActiveMeido ? $"{meido.LastName}\n{meido.FirstName}" : string.Empty;
- GUILayout.Label(label, labelStyle, GUILayout.ExpandWidth(false));
- GUILayout.FlexibleSpace();
- nextButton.Draw(buttonStyle, buttonOptions);
- GUILayout.EndHorizontal();
- Rect previousRect = GUILayoutUtility.GetLastRect();
- if (MeidoPhotoStudio.EditMode) editToggle.Draw(new Rect(previousRect.x + 4f, previousRect.y, 40f, 20f));
- Rect labelRect = new Rect(previousRect.width - 45f, previousRect.y, 40f, 20f);
- GUIStyle slotStyle = new GUIStyle()
- {
- alignment = TextAnchor.UpperRight,
- fontSize = 13
- };
- slotStyle.padding.right = 5;
- slotStyle.normal.textColor = Color.white;
- if (meidoManager.HasActiveMeido) GUI.Label(labelRect, $"{meidoManager.ActiveMeido.Slot + 1}", slotStyle);
- }
- public override void UpdatePane()
- {
- if (meidoManager.HasActiveMeido)
- {
- this.updating = true;
- editToggle.Value = meidoManager.ActiveMeido.IsEditMaid;
- this.updating = false;
- }
- }
- private void ChangeMaid(int dir)
- {
- int selected = Utility.Wrap(
- meidoManager.SelectedMeido + (int)Mathf.Sign(dir), 0, meidoManager.ActiveMeidoList.Count
- );
- meidoManager.ChangeMaid(selected);
- }
- private void SetEditMaid()
- {
- if (updating) return;
- if (!editToggle.Value)
- {
- updating = true;
- editToggle.Value = true;
- updating = false;
- return;
- }
- if (meidoManager.HasActiveMeido)
- {
- meidoManager.SetEditMaid(meidoManager.ActiveMeido);
- }
- }
- }
- }
|