Browse Source

Make effect manager generic

habeebweeb 4 years ago
parent
commit
159556fe99

+ 1 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindowPanes/EffectsPanes/BloomPane.cs

@@ -12,7 +12,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Slider blueSlider;
         private Toggle hdrToggle;
 
-        public BloomPane(EffectManager effectManager) : base(effectManager.BloomEffectManager)
+        public BloomPane(EffectManager effectManager) : base(effectManager.Get<BloomEffectManager>())
         {
             Bloom bloom = GameMain.Instance.MainCamera.GetComponent<Bloom>();
 

+ 1 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindowPanes/EffectsPanes/DepthOfFieldPane.cs

@@ -11,7 +11,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Slider blurSlider;
         private Toggle thicknessToggle;
 
-        public DepthOfFieldPane(EffectManager effectManager) : base(effectManager.DepthOfFieldEffectManager)
+        public DepthOfFieldPane(EffectManager effectManager) : base(effectManager.Get<DepthOfFieldEffectManager>())
         {
             this.focalLengthSlider = new Slider(Translation.Get("effectDof", "focalLength"), 0f, 10f);
             this.focalSizeSlider = new Slider(Translation.Get("effectDof", "focalArea"), 0f, 2f);

+ 2 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindowPanes/EffectsPanes/EffectPane.cs

@@ -40,9 +40,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public override void UpdatePane()
         {
-            if (!EffectManager.IsReady) return;
+            if (!EffectManager.Ready) return;
             this.updating = true;
-            this.effectToggle.Value = this.EffectManager.IsActive;
+            this.effectToggle.Value = this.EffectManager.Active;
             this.UpdateControls();
             this.updating = false;
         }

+ 1 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindowPanes/EffectsPanes/FogPane.cs

@@ -13,7 +13,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Slider greenSlider;
         private Slider blueSlider;
 
-        public FogPane(EffectManager effectManager) : base(effectManager.FogEffectManager)
+        public FogPane(EffectManager effectManager) : base(effectManager.Get<FogEffectManager>())
         {
             this.distanceSlider = new Slider(
                 Translation.Get("effectFog", "distance"), 0f, 30f, FogEffectManager.InitialDistance

+ 1 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindowPanes/EffectsPanes/VignettePane.cs

@@ -10,7 +10,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Slider blurSpreadSlider;
         private Slider aberrationSlider;
 
-        public VignettePane(EffectManager effectManager) : base(effectManager.VignetteEffectManager)
+        public VignettePane(EffectManager effectManager) : base(effectManager.Get<VignetteEffectManager>())
         {
             this.intensitySlider = new Slider(Translation.Get("effectVignette", "intensity"), -40f, 70f);
             this.intensitySlider.ControlEvent += (s, a) =>

+ 33 - 17
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EffectManager.cs

@@ -1,39 +1,55 @@
+using System;
+using System.Collections.Generic;
+
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     internal class EffectManager
     {
-        public BloomEffectManager BloomEffectManager { get; }
-        public DepthOfFieldEffectManager DepthOfFieldEffectManager { get; }
-        public VignetteEffectManager VignetteEffectManager { get; }
-        public FogEffectManager FogEffectManager { get; }
+        private Dictionary<Type, IEffectManager> EffectManagers = new Dictionary<Type, IEffectManager>();
+        private BloomEffectManager bloomEffectManager;
 
         public EffectManager()
         {
-            BloomEffectManager = new BloomEffectManager();
-            DepthOfFieldEffectManager = new DepthOfFieldEffectManager();
-            VignetteEffectManager = new VignetteEffectManager();
-            FogEffectManager = new FogEffectManager();
+            // Not going to add more effects because SceneCapture does it better anyway
+            bloomEffectManager = AddManager<BloomEffectManager>();
+            AddManager<DepthOfFieldEffectManager>();
+            AddManager<VignetteEffectManager>();
+            AddManager<FogEffectManager>();
+        }
+
+        public T Get<T>() where T : IEffectManager
+        {
+            if (EffectManagers.ContainsKey(typeof(T))) return (T)EffectManagers[typeof(T)];
+            else return default(T);
+        }
+
+        private T AddManager<T>() where T : IEffectManager, new()
+        {
+            T manager = new T();
+            EffectManagers[typeof(T)] = manager;
+            return manager;
         }
 
         public void Activate()
         {
-            BloomEffectManager.Activate();
-            DepthOfFieldEffectManager.Activate();
-            VignetteEffectManager.Activate();
-            FogEffectManager.Activate();
+            foreach (IEffectManager effectManager in EffectManagers.Values)
+            {
+                effectManager.Activate();
+            }
         }
 
         public void Deactivate()
         {
-            BloomEffectManager.Deactivate();
-            DepthOfFieldEffectManager.Deactivate();
-            VignetteEffectManager.Deactivate();
-            FogEffectManager.Deactivate();
+            foreach (IEffectManager effectManager in EffectManagers.Values)
+            {
+                effectManager.Deactivate();
+            }
         }
 
         public void Update()
         {
-            BloomEffectManager.Update();
+            // Bloom is the only effect that needs to update because I'm dumb/lazy
+            bloomEffectManager.Update();
         }
     }
 }

+ 9 - 7
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EffectManagers/BloomEffectManager.cs

@@ -9,8 +9,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private int initialBlurIterations;
         private Color initialThresholdColour;
         private Bloom.HDRBloomMode initialHDRBloomMode;
-        public bool IsReady { get; private set; }
-        public bool IsActive { get; private set; }
+        public bool Ready { get; private set; }
+        public bool Active { get; private set; }
         private float intensity;
         public float Intensity
         {
@@ -71,7 +71,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             if (Bloom == null)
             {
-                IsReady = true;
+                Ready = true;
                 Bloom = GameMain.Instance.MainCamera.GetOrAddComponent<Bloom>();
                 initialIntensity = Intensity = Bloom.bloomIntensity;
                 initialBlurIterations = BlurIterations = Bloom.bloomBlurIterations;
@@ -89,7 +89,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             BloomHDR = initialHDRBloomMode == Bloom.HDRBloomMode.On;
             BloomHDR = false;
             Bloom.enabled = true;
-            IsActive = false;
+            Active = false;
         }
 
         public void Reset()
@@ -103,8 +103,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public void SetEffectActive(bool active)
         {
             Bloom.enabled = active;
-            IsActive = active;
-            if (this.IsActive)
+            Active = active;
+            if (this.Active)
             {
                 Bloom.bloomIntensity = Intensity;
                 Bloom.bloomBlurIterations = BlurIterations;
@@ -116,9 +116,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         public void Update()
         {
-            if (IsActive)
+            if (Active)
             {
                 // Fuck this stupid shit
+                // 2020/08/15 this stupid shit doesn't even work anymore
+                // TODO: Fix this stupid shit
                 Bloom.enabled = true;
                 Bloom.bloomIntensity = intensity;
             }

+ 6 - 6
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EffectManagers/DepthOfFieldManager.cs

@@ -5,8 +5,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     internal class DepthOfFieldEffectManager : IEffectManager
     {
         private DepthOfFieldScatter DepthOfField { get; set; }
-        public bool IsReady { get; private set; }
-        public bool IsActive { get; private set; }
+        public bool Ready { get; private set; }
+        public bool Active { get; private set; }
         private readonly float initialValue = 0f;
         private float focalLength;
         public float FocalLength
@@ -44,7 +44,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             if (DepthOfField == null)
             {
-                IsReady = true;
+                Ready = true;
                 DepthOfField = GameMain.Instance.MainCamera.GetOrAddComponent<DepthOfFieldScatter>();
                 if (DepthOfField.dofHdrShader == null)
                 {
@@ -69,7 +69,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             MaxBlurSize = initialValue;
             VisualizeFocus = false;
             DepthOfField.enabled = false;
-            IsActive = false;
+            Active = false;
         }
 
         public void Reset()
@@ -83,8 +83,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public void SetEffectActive(bool active)
         {
             DepthOfField.enabled = active;
-            this.IsActive = active;
-            if (this.IsActive)
+            this.Active = active;
+            if (this.Active)
             {
                 DepthOfField.focalLength = FocalLength;
                 DepthOfField.focalSize = FocalSize;

+ 5 - 5
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EffectManagers/FogEffectManager.cs

@@ -5,8 +5,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     internal class FogEffectManager : IEffectManager
     {
         private GlobalFog Fog { get; set; }
-        public bool IsReady { get; private set; }
-        public bool IsActive { get; private set; }
+        public bool Ready { get; private set; }
+        public bool Active { get; private set; }
         public static float InitialDistance { get; private set; } = 4f;
         public static float InitialDensity { get; private set; } = 1f;
         public static float InitialHeightScale { get; private set; } = 1f;
@@ -92,7 +92,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             Height = InitialHeight;
             FogColour = InitialColour;
             Fog.enabled = false;
-            IsActive = false;
+            Active = false;
         }
 
         public void Reset()
@@ -107,8 +107,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public void SetEffectActive(bool active)
         {
             Fog.enabled = active;
-            this.IsActive = active;
-            if (this.IsActive)
+            this.Active = active;
+            if (this.Active)
             {
                 Fog.startDistance = Distance;
                 Fog.globalDensity = Density;

+ 2 - 2
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EffectManagers/IEffectManager.cs

@@ -2,8 +2,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     internal interface IEffectManager
     {
-        bool IsReady { get; }
-        bool IsActive { get; }
+        bool Ready { get; }
+        bool Active { get; }
         void Activate();
         void Deactivate();
         void SetEffectActive(bool active);

+ 6 - 6
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EffectManagers/VignetteEffectManager.cs

@@ -7,8 +7,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private float initialBlur;
         private float initialBlurSpread;
         private float initialChromaticAberration;
-        public bool IsReady { get; private set; }
-        public bool IsActive { get; private set; }
+        public bool Ready { get; private set; }
+        public bool Active { get; private set; }
         private float intensity;
         public float Intensity
         {
@@ -38,7 +38,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             if (Vignette == null)
             {
-                IsReady = true;
+                Ready = true;
                 Vignette = GameMain.Instance.MainCamera.GetOrAddComponent<Vignetting>();
                 Vignette.mode = Vignetting.AberrationMode.Simple;
 
@@ -56,7 +56,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             BlurSpread = initialBlurSpread;
             ChromaticAberration = initialChromaticAberration;
             Vignette.enabled = false;
-            IsActive = false;
+            Active = false;
         }
 
         public void Reset()
@@ -70,8 +70,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public void SetEffectActive(bool active)
         {
             Vignette.enabled = active;
-            IsActive = active;
-            if (this.IsActive)
+            Active = active;
+            if (this.Active)
             {
                 Vignette.intensity = Intensity;
                 Vignette.blur = Blur;