EffectPane.cs 2.3 KB

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