private void TableElements_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex >= 0 && e.ColumnIndex < TableElements.ColumnCount) { if (e.RowIndex >= 0 && e.RowIndex < TableElements.RowCount) { if (TableElements.Columns[e.ColumnIndex].Name == TEValue.Name) { object Value = TableElements[TEValue.Name, e.RowIndex].Value; int NumericValue = 0; if (!int.TryParse(Value.ToString(), out NumericValue)) { MessageBox.Show("The value entered is not a valid number.\nWill set the value to 0.", "Invalid value entered", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); TableElements[TEValue.Name, e.RowIndex].Value = 0; NumericValue = 0; } if (OutputActive) { TableElement TE = (TableElement)TableElements.Rows[e.RowIndex].Tag; TableElementData D = TE.GetTableElementData(); D.Value = NumericValue; Pinball.ReceiveData(D); } TableElements[TEActivate.Name, e.RowIndex].Value = (NumericValue > 0 ? "Deactivate" : "Activate"); TableElements[TEPulse.Name, e.RowIndex].Value = (NumericValue > 0 ? @"Pulse ¯\_/¯" : @"Pulse _/¯\_"); } } } }
/// <summary> /// Triggers the effect.<br/> /// If the TargetEffect throws a exception, it will be deactivated. /// </summary> /// <param name="TableElementData">The TableElementData object for the TableElement which has triggered the effect.</param> public override void Trigger(TableElementData TableElementData) { if (TargetEffect != null) { Table.Pinball.Alarms.RegisterAlarm(DelayMs, TriggerTargetEffect, TableElementData, true); } }
/// <summary> /// Triggers the MinDurationEffect with the given TableElementData.<br/> /// The minimal duration is started, if the value portion of the TableElementData parameter is !=0. /// </summary> /// <param name="TableElementData">TableElementData for the TableElement which has triggered the effect.</param> public override void Trigger(TableElementData TableElementData) { if (TargetEffect != null) { if (TableElementData.Value != 0) { if (!Active || RetriggerBehaviour == RetriggerBehaviourEnum.Restart) { DurationStart = DateTime.Now; UntriggerData = TableElementData; TriggerTargetEffect(TableElementData); Active = true; } } else { if (Active && UntriggerData.TableElementType == TableElementData.TableElementType && UntriggerData.Number == TableElementData.Number) { if ((DateTime.Now - DurationStart).TotalMilliseconds >= MinDurationMs) { MinDurationEnd(); } else { Table.Pinball.Alarms.RegisterAlarm(MinDurationMs - (int)(DateTime.Now - DurationStart).TotalMilliseconds, MinDurationEnd); } } } } }
/// <summary> /// Triggers all AssignedEffect objects in the list. /// </summary> /// <param name="TableElementData">The table element data.</param> public void Trigger(TableElementData TableElementData) { foreach (AssignedEffect TEE in this) { TEE.Trigger(TableElementData); } }
private void MinDurationEnd() { if (Active) { TableElementData D = UntriggerData; D.Value = 0; TriggerTargetEffect(D); } Active = false; }
/// <summary> /// Updates the table element statistics. /// </summary> /// <param name="TableElementData">The table element data.</param> /// <param name="Duration">The duration.</param> public void UpdateTableElementStatistics(TableElementData TableElementData, TimeSpan Duration) { try { TableElementCallStatistics[TableElementData.TableElementType].AddDuration(Duration); } catch (Exception E) { Log.Exception("Could not update TimeSpanStatistics for Pinball table element type {0} ({1})".Build(TableElementData.ToString(), TableElementData), E); } }
/// <summary> /// Triggers the assigned Effect. /// <remarks> If the assigned effect throws a exception the effect will be deactivated.</remarks> /// </summary> /// <param name="TableElementData">The table element data.</param> public void Trigger(TableElementData TableElementData) { if (Effect != null) { try { Effect.Trigger(TableElementData); } catch (Exception E) { Log.Exception("A exception occured when triggering effect {0} for table element {1} {2} with value {3}. Effect assignement will be deactivated.".Build(new object[] { Effect.Name, TableElementData.TableElementType, TableElementData.Number, TableElementData.Value }), E); Effect = null; } } }
/// <summary> /// Triggers the target effect.<br/> /// The method will deactivate the target effect if it throws a exception. /// </summary> /// <param name="TriggerData">The trigger data for the target effect.</param> protected void TriggerTargetEffect(TableElementData TriggerData) { if (TargetEffect != null) { try { TargetEffect.Trigger(TriggerData); } catch (Exception E) { Log.Exception("The target effect {0} of the {1} {2} has thrown a exception. Disabling further calls of the target effect.".Build(TargetEffectName, GetType().Name, Name), E); TargetEffect = null; } } }
/// <summary> /// Triggers the effect with the given TableElementData. /// </summary> /// <param name="TableElementData">TableElementData for the TableElement which has triggered the effect.</param> public override void Trigger(TableElementData TableElementData) { if (ConditionExpression != null) { try { if (ConditionExpression.Evaluate()) { TableElementData.Value = 255; } else { TableElementData.Value = 0; } TriggerTargetEffect(TableElementData); } catch (Exception E) { Log.Exception("A exception occured when evaluating the expression {0} of effect {1}. Effect will be deactivated.".Build(ConditionExpression.Text, Name), E); ConditionExpression = null; } } }
/// <summary> /// Triggers the effect with the given TableElementData. /// </summary> /// <param name="TableElementData">TableElementData for the TableElement which has triggered the effect.</param> public override void Trigger(Table.TableElementData TableElementData) { if (TableElementData.Value != 0) { if (!Active || RetriggerBehaviour == RetriggerBehaviourEnum.Restart) { TriggerTargetEffect(TableElementData); UntriggerData = TableElementData; UntriggerData.Value = 0; Table.Pinball.Alarms.RegisterAlarm(MaxDurationMs, DurationEnd); Active = true; } } else { if (Active && UntriggerData.TableElementType == TableElementData.TableElementType && UntriggerData.Number == TableElementData.Number) { TriggerTargetEffect(TableElementData); Table.Pinball.Alarms.UnregisterAlarm(DurationEnd); Active = false; } } }
/// <summary> /// Receives the table element data from the calling app.<br /> /// The received data is put in a queue and the internal thread of the framework is notified about the availability of new data. /// </summary> /// <param name="TableElementData">The table element data to be received.</param> public void ReceiveData(TableElementData TableElementData) { InputQueue.Enqueue(TableElementData); MainThreadSignal(); //ThreadInfoList.HeartBeat("Data delivery"); }
/// <summary> /// Triggers the effect with the given TableElementData.<br></br> /// \warning Remember that the TableElementData parameter will contain null if a effect is called as a static effect. Make sure your implementation of this method does not fail resp. throw exceptions when called with null. /// </summary> /// <param name="TableElementData">TableElementData for the TableElement which has triggered the effect.</param> public abstract void Trigger(TableElementData TableElementData);