EffectPane.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public abstract class EffectPane<T> : BasePane where T : IEffectManager
  5. {
  6. protected abstract T EffectManager { get; set; }
  7. protected readonly Toggle effectToggle;
  8. protected readonly Button resetEffectButton;
  9. private bool enabled;
  10. public override bool Enabled
  11. {
  12. get => enabled;
  13. set
  14. {
  15. enabled = value;
  16. if (updating) return;
  17. EffectManager.SetEffectActive(enabled);
  18. }
  19. }
  20. protected EffectPane(EffectManager effectManager)
  21. {
  22. EffectManager = effectManager.Get<T>();
  23. resetEffectButton = new Button(Translation.Get("effectsPane", "reset"));
  24. resetEffectButton.ControlEvent += (s, a) => ResetEffect();
  25. effectToggle = new Toggle(Translation.Get("effectsPane", "onToggle"));
  26. effectToggle.ControlEvent += (s, a) => Enabled = effectToggle.Value;
  27. }
  28. protected override void ReloadTranslation()
  29. {
  30. updating = true;
  31. effectToggle.Label = Translation.Get("effectsPane", "onToggle");
  32. resetEffectButton.Label = Translation.Get("effectsPane", "reset");
  33. TranslatePane();
  34. updating = false;
  35. }
  36. protected abstract void TranslatePane();
  37. public override void UpdatePane()
  38. {
  39. if (!EffectManager.Ready) return;
  40. updating = true;
  41. effectToggle.Value = EffectManager.Active;
  42. UpdateControls();
  43. updating = false;
  44. }
  45. protected abstract void UpdateControls();
  46. public override void Draw()
  47. {
  48. GUILayout.BeginHorizontal();
  49. effectToggle.Draw();
  50. GUILayout.FlexibleSpace();
  51. GUI.enabled = Enabled;
  52. resetEffectButton.Draw();
  53. GUILayout.EndHorizontal();
  54. DrawPane();
  55. GUI.enabled = true;
  56. }
  57. protected abstract void DrawPane();
  58. private void ResetEffect()
  59. {
  60. EffectManager.Deactivate();
  61. EffectManager.SetEffectActive(true);
  62. UpdatePane();
  63. }
  64. }
  65. }