2 using System.Collections.Generic;
5 using DirectOutput.Cab.Toys.Layer;
7 namespace DirectOutput.FX.AnalogToyFX
15 private const int FadingRefreshIntervalMs = 30;
29 get {
return _RetriggerBehaviour; }
30 set { _RetriggerBehaviour = value; }
44 get {
return _FadeMode; }
45 set { _FadeMode = value; }
50 private int _FadeInactiveDurationMs = 500;
58 public int FadeInactiveDurationMs
60 get {
return _FadeInactiveDurationMs; }
61 set { _FadeInactiveDurationMs = value; }
65 private int _FadeActiveDurationMs = 500;
73 public int FadeActiveDurationMs
75 get {
return _FadeActiveDurationMs; }
76 set { _FadeActiveDurationMs = value; }
92 get {
return _ActiveValue; }
93 set { _ActiveValue = value; }
106 get {
return _InactiveValue; }
107 set { _InactiveValue = value; }
113 float[] Current =
new float[2];
114 float[] Step =
new float[2];
115 float[] Target =
new float[2];
116 bool IsFading =
false;
118 private void StartFading(
bool Active)
120 Table.Pinball.Alarms.UnregisterAlarm(FadingStep);
124 int Duration = (Active ? FadeActiveDurationMs : FadeInactiveDurationMs);
125 int Steps = Duration / FadingRefreshIntervalMs;
136 CurrentAnalogAlphaValue = Toy.Layers[Layer].GetAnalogAlphaValue();
140 CurrentAnalogAlphaValue = (!Active ? ActiveValue : InactiveValue);
144 Current[0] = CurrentAnalogAlphaValue.
Value;
145 Current[1] = CurrentAnalogAlphaValue.
Alpha;
147 Target[0] = TargetValue.
Value;
148 Target[1] = TargetValue.
Alpha;
151 for (
int i = 0; i < 2; i++)
153 Step[i] = (Target[i] - Current[i]) / Steps;
159 Toy.Layers[Layer].Set(TargetValue);
164 private void FadingStep()
166 bool ContinueFading =
false;
167 for (
int i = 0; i < 2; i++)
171 Current[i] += Step[i];
172 if (Current[i] < Target[i] && Current[i] < 255)
174 ContinueFading =
true;
178 Current[i] = Target[i];
182 else if (Step[i] < 0)
184 Current[i] += Step[i];
185 if (Current[i] > Target[i] && Current[i] > 0)
187 ContinueFading =
true;
191 Current[i] = Target[i];
197 Toy.Layers[Layer].Set((
int)Current[0], (
int)Current[1]);
201 Table.Pinball.Alarms.RegisterAlarm(FadingRefreshIntervalMs, FadingStep);
210 bool LastTriggerState =
false;
217 public override void Trigger(Table.TableElementData TableElementData)
222 bool TriggerState = TableElementData.Value != 0;
224 if (TriggerState != LastTriggerState || IsFading ==
false || RetriggerBehaviour ==
RetriggerBehaviourEnum.RestartEffect)
226 StartFading(TriggerState);
229 LastTriggerState = TriggerState;
238 public override void Init(Table.Table Table)
246 public override void Finish()
250 Table.Pinball.Alarms.UnregisterAlarm(FadingStep);
255 Toy.Layers.Remove(Layer);