GravityControlPane.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal class GravityControlPane : BasePane
  6. {
  7. private MeidoManager meidoManager;
  8. private Toggle hairToggle;
  9. private Toggle skirtToggle;
  10. private Toggle globalToggle;
  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. }
  21. public override void Draw()
  22. {
  23. bool enabled = this.meidoManager.HasActiveMeido;
  24. GUI.enabled = enabled;
  25. Meido meido = this.meidoManager.ActiveMeido;
  26. GUILayout.BeginHorizontal();
  27. GUI.enabled = enabled && meido.HairGravityValid;
  28. hairToggle.Draw();
  29. GUI.enabled = enabled && meido.SkirtGravityValid;
  30. skirtToggle.Draw();
  31. GUI.enabled = true;
  32. GUILayout.EndHorizontal();
  33. globalToggle.Draw();
  34. GUI.enabled = true;
  35. }
  36. public override void UpdatePane()
  37. {
  38. if (!this.meidoManager.HasActiveMeido) return;
  39. Meido meido = meidoManager.ActiveMeido;
  40. this.updating = true;
  41. hairToggle.Value = meido.HairGravityActive;
  42. skirtToggle.Value = meido.SkirtGravityActive;
  43. this.updating = false;
  44. }
  45. private void ToggleGravity(bool value, bool skirt = false)
  46. {
  47. if (updating) return;
  48. if (this.meidoManager.GlobalGravity)
  49. {
  50. foreach (Meido meido in this.meidoManager.ActiveMeidoList)
  51. {
  52. if (skirt) meido.SkirtGravityActive = value;
  53. else meido.HairGravityActive = value;
  54. }
  55. }
  56. else
  57. {
  58. if (skirt) this.meidoManager.ActiveMeido.SkirtGravityActive = value;
  59. else this.meidoManager.ActiveMeido.HairGravityActive = value;
  60. }
  61. }
  62. private void SetGlobalGravity(bool value) => this.meidoManager.GlobalGravity = value;
  63. }
  64. }