WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
BlinkEffect.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Xml.Serialization;
6 
7 namespace DirectOutput.FX.TimmedFX
8 {
14  {
15  private int _ActiveValue = -1;
16 
23  public int HighValue
24  {
25  get { return _ActiveValue; }
26  set { _ActiveValue = value.Limit(-1, 255); }
27  }
28 
29  private int _LowValue = 0;
30 
37  public int LowValue
38  {
39  get { return _LowValue; }
40  set { _LowValue = value.Limit(0, 255); }
41  }
42 
43 
44 
45 
46 
47 
48  private int _DurationActiveMs = 500;
49 
56  public int DurationActiveMs
57  {
58  get { return _DurationActiveMs; }
59  set { _DurationActiveMs = value.Limit(1, int.MaxValue); }
60  }
61 
62 
63  private int _DurationInactiveMs = 500;
64 
71  public int DurationInactiveMs
72  {
73  get { return _DurationInactiveMs; }
74  set { _DurationInactiveMs = value.Limit(1, int.MaxValue); }
75  }
76 
77 
78  private BlinkEffectUntriggerBehaviourEnum _UntriggerBehaviour = BlinkEffectUntriggerBehaviourEnum.Immediate;
79 
86  public BlinkEffectUntriggerBehaviourEnum UntriggerBehaviour
87  {
88  get { return _UntriggerBehaviour; }
89  set { _UntriggerBehaviour = value; }
90  }
91 
92 
93 
100  [XmlIgnoreAttribute]
101  public bool Active { get; private set; }
102 
103 
104  private bool BlinkEnabled = false;
105  private bool BlinkState = false;
106  private int BlinkOrgTableElementDataValue = 1;
107  private Table.TableElementData BlinkTableElementData;
108 
109  private void StartBlinking(Table.TableElementData TableElementData)
110  {
111  BlinkTableElementData = TableElementData;
112  BlinkOrgTableElementDataValue = BlinkTableElementData.Value;
113 
114  if (!BlinkEnabled)
115  {
116  BlinkEnabled = true;
117  BlinkState = false;
118  DoBlink();
119  }
120  else
121  {
122  if (BlinkState)
123  {
124  BlinkTableElementData.Value = (HighValue >= 0 ? HighValue : BlinkOrgTableElementDataValue);
125  TriggerTargetEffect(BlinkTableElementData);
126  }
127  }
128  }
129 
130  private void StopBlinking()
131  {
132  BlinkEnabled = false;
133  if (UntriggerBehaviour == BlinkEffectUntriggerBehaviourEnum.Immediate)
134  {
135  Table.Pinball.Alarms.UnregisterAlarm(DoBlink);
136  BlinkTableElementData.Value = 0;
137  TriggerTargetEffect(BlinkTableElementData);
138  };
139  }
140 
141  private void DoBlink()
142  {
143  BlinkState = !BlinkState;
144  if (BlinkState)
145  {
146  BlinkTableElementData.Value = (HighValue >= 0 ? HighValue : BlinkOrgTableElementDataValue);
147  Table.Pinball.Alarms.RegisterAlarm(DurationActiveMs, DoBlink);
148  }
149  else
150  {
151  if (BlinkEnabled)
152  {
153  BlinkTableElementData.Value = LowValue;
154  Table.Pinball.Alarms.RegisterAlarm(DurationInactiveMs, DoBlink);
155  }
156  else
157  {
158  BlinkTableElementData.Value = 0;
159  }
160  }
161  TriggerTargetEffect(BlinkTableElementData);
162 
163  }
164 
165 
166 
172  public override void Trigger(Table.TableElementData TableElementData)
173  {
174  if (TargetEffect != null)
175  {
176  if (TableElementData.Value != 0)
177  {
178  StartBlinking(TableElementData);
179  }
180  else
181  {
182  StopBlinking();
183 
184  }
185  }
186  }
187 
188 
189 
193  public override void Finish()
194  {
195  try
196  {
197  Table.Pinball.Alarms.UnregisterAlarm(DoBlink);
198  }
199  catch { }
200  base.Finish();
201  }
202 
203  }
204 }
BlinkEffectUntriggerBehaviourEnum
Defines the untrigger behaviours for the blink effect.
Base class for effects targeting another effect.