EffectPane.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal abstract class EffectPane<T> : BasePane where T : IEffectManager
  6. {
  7. protected abstract T EffectManager { get; set; }
  8. protected Toggle effectToggle;
  9. protected Button resetEffectButton;
  10. private bool enabled;
  11. public override bool Enabled
  12. {
  13. get => enabled;
  14. set
  15. {
  16. this.enabled = value;
  17. this.EffectManager.SetEffectActive(this.enabled);
  18. }
  19. }
  20. public EffectPane(T effectManager) : base()
  21. {
  22. this.EffectManager = effectManager;
  23. this.resetEffectButton = new Button(Translation.Get("effectsPane", "reset"));
  24. this.resetEffectButton.ControlEvent += (s, a) => this.ResetEffect();
  25. this.effectToggle = new Toggle(Translation.Get("effectsPane", "onToggle"));
  26. this.effectToggle.ControlEvent += (s, a) => this.Enabled = this.effectToggle.Value;
  27. }
  28. protected override void ReloadTranslation()
  29. {
  30. this.updating = true;
  31. this.effectToggle.Label = Translation.Get("effectsPane", "onToggle");
  32. this.resetEffectButton.Label = Translation.Get("effectsPane", "reset");
  33. TranslatePane();
  34. this.updating = false;
  35. }
  36. protected abstract void TranslatePane();
  37. public override void UpdatePane()
  38. {
  39. if (!EffectManager.IsReady) return;
  40. this.updating = true;
  41. this.effectToggle.Value = this.EffectManager.IsActive;
  42. this.UpdateControls();
  43. this.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 = this.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. this.EffectManager.Deactivate();
  61. this.EffectManager.SetEffectActive(true);
  62. this.UpdatePane();
  63. }
  64. }
  65. }