GravityControlPane.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class GravityControlPane : BasePane
  5. {
  6. private readonly MeidoManager meidoManager;
  7. private readonly Toggle hairToggle;
  8. private readonly Toggle skirtToggle;
  9. private readonly Toggle globalToggle;
  10. private string header;
  11. public GravityControlPane(MeidoManager meidoManager)
  12. {
  13. this.meidoManager = meidoManager;
  14. hairToggle = new Toggle(Translation.Get("gravityControlPane", "hairToggle"));
  15. hairToggle.ControlEvent += (s, a) => ToggleGravity(hairToggle.Value, skirt: false);
  16. skirtToggle = new Toggle(Translation.Get("gravityControlPane", "skirtToggle"));
  17. skirtToggle.ControlEvent += (s, a) => ToggleGravity(skirtToggle.Value, skirt: true);
  18. globalToggle = new Toggle(Translation.Get("gravityControlPane", "globalToggle"));
  19. globalToggle.ControlEvent += (s, a) => SetGlobalGravity(globalToggle.Value);
  20. header = Translation.Get("gravityControlPane", "gravityHeader");
  21. }
  22. protected override void ReloadTranslation()
  23. {
  24. hairToggle.Label = Translation.Get("gravityControlPane", "hairToggle");
  25. skirtToggle.Label = Translation.Get("gravityControlPane", "skirtToggle");
  26. globalToggle.Label = Translation.Get("gravityControlPane", "globalToggle");
  27. header = Translation.Get("gravityControlPane", "gravityHeader");
  28. }
  29. public override void Draw()
  30. {
  31. bool enabled = meidoManager.HasActiveMeido;
  32. GUI.enabled = enabled;
  33. MpsGui.Header(header);
  34. MpsGui.WhiteLine();
  35. Meido meido = meidoManager.ActiveMeido;
  36. GUILayout.BeginHorizontal();
  37. GUI.enabled = enabled && meido.HairGravityControl.Valid;
  38. hairToggle.Draw();
  39. GUI.enabled = enabled && meido.SkirtGravityControl.Valid;
  40. skirtToggle.Draw();
  41. GUILayout.EndHorizontal();
  42. GUI.enabled = enabled;
  43. globalToggle.Draw();
  44. GUI.enabled = true;
  45. }
  46. public override void UpdatePane()
  47. {
  48. if (!meidoManager.HasActiveMeido) return;
  49. Meido meido = meidoManager.ActiveMeido;
  50. updating = true;
  51. hairToggle.Value = meido.HairGravityActive;
  52. skirtToggle.Value = meido.SkirtGravityActive;
  53. updating = false;
  54. }
  55. private void ToggleGravity(bool value, bool skirt = false)
  56. {
  57. if (updating) return;
  58. if (meidoManager.GlobalGravity)
  59. {
  60. foreach (Meido meido in meidoManager.ActiveMeidoList)
  61. {
  62. if (skirt) meido.SkirtGravityActive = value;
  63. else meido.HairGravityActive = value;
  64. }
  65. }
  66. else
  67. {
  68. if (skirt) meidoManager.ActiveMeido.SkirtGravityActive = value;
  69. else meidoManager.ActiveMeido.HairGravityActive = value;
  70. }
  71. }
  72. private void SetGlobalGravity(bool value) => meidoManager.GlobalGravity = value;
  73. }
  74. }