2 using System.Collections.Generic;
6 namespace DirectOutput.FX.TimmedFX
14 private const int FadingRefreshIntervalMs = 30;
17 private int _FadeUpDuration = 300;
25 public int FadeUpDuration
27 get {
return _FadeUpDuration; }
28 set { _FadeUpDuration = value; }
31 private int _FadeDownDuration = 300;
39 public int FadeDownDuration
41 get {
return _FadeDownDuration; }
42 set { _FadeDownDuration = value; }
56 get {
return _FadeDurationMode; }
57 set { _FadeDurationMode = value; }
62 float TargetValue = -1;
63 float CurrentValue = 0;
65 int LastTargetTriggerValue = -1;
66 Table.TableElementData TableElementData;
72 public override void Trigger(Table.TableElementData TableElementData)
74 if (TargetEffect!=null && TableElementData.Value != TargetValue)
76 TargetValue = TableElementData.Value.Limit(0,255);
78 this.TableElementData = TableElementData;
80 double Duration = (CurrentValue < TargetValue ? FadeUpDuration : FadeDownDuration);
83 Duration = Duration / 255 * (TargetValue - CurrentValue).Abs();
85 int Steps = (int)(Duration>0?(Duration / FadingRefreshIntervalMs):0);
89 StepValue = (float)(TargetValue - CurrentValue) / Steps;
90 LastTargetTriggerValue = -1;
96 Table.Pinball.Alarms.UnregisterAlarm( FadingStep);
98 CurrentValue=TargetValue;
99 LastTargetTriggerValue = -1;
100 TriggerTargetEffect(TableElementData);
106 private void FadingStep()
108 CurrentValue += StepValue;
110 if ((CurrentValue < TargetValue && StepValue > 0) || (CurrentValue > TargetValue && StepValue < 0))
113 Table.Pinball.Alarms.RegisterIntervalAlarm(FadingRefreshIntervalMs, FadingStep);
117 CurrentValue = TargetValue;
120 if (LastTargetTriggerValue != (
int)CurrentValue)
122 LastTargetTriggerValue = (int)CurrentValue;
123 TableElementData.Value = LastTargetTriggerValue;
124 TriggerTargetEffect(TableElementData);