WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
ConfigTester.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using DirectOutput;
10 using DirectOutput.Table;
11 using System.Threading;
12 
14 {
15  public partial class ConfigTester : Form
16  {
17  private Pinball Pinball;
18  private Settings Settings = new Settings();
19  private bool OutputActive = false;
20  public ConfigTester()
21  {
22  InitializeComponent();
23 
24  Settings = Settings.LoadSettings();
25 
26  PulseDurationInput.Value = Settings.PulseDurationMs;
27 
28  }
29 
30  public bool LoadConfig()
31  {
32  OpenConfigDialog OCD = new OpenConfigDialog(Settings);
33  if (OCD.ShowDialog() == DialogResult.OK)
34  {
35  if (Pinball != null)
36  {
37  Pinball.Finish();
38  }
39 
40 
41  Pinball = new Pinball();
42  Pinball.Setup(OCD.GlobalConfigFilename, OCD.TableFilename, OCD.RomName);
43  Pinball.Init();
45 
46 
47  return true;
48  }
49  else
50  {
51 
52  return false;
53  }
54  }
55 
56  public void DisplayTableElements()
57  {
58  OutputActive = false;
59  Pinball.Table.TableElements.Sort((TE1, TE2) => (TE1.TableElementType == TE2.TableElementType ? TE1.Number.CompareTo(TE2.Number) : TE1.TableElementType.CompareTo(TE2.TableElementType)));
60 
61  TableElements.Rows.Clear();
62 
63  foreach (TableElement TE in Pinball.Table.TableElements)
64  {
65  int RowIndex = TableElements.Rows.Add();
66  TableElements.Rows[RowIndex].Tag = TE;
67  TableElements[TEType.Name, RowIndex].Value = TE.TableElementType.ToString();
68  TableElements[TEName.Name, RowIndex].Value = (TE.Name.IsNullOrWhiteSpace() ? "" : TE.Name);
69  TableElements[TENumber.Name, RowIndex].Value = TE.Number;
70  TableElements[TEValue.Name, RowIndex].Value = TE.Value;
71  TableElements[TEActivate.Name, RowIndex].Value = (TE.Value > 0 ? "Deactivate" : "Activate");
72  TableElements[TEPulse.Name, RowIndex].Value = (TE.Value > 0 ? @"Pulse ¯\_/¯" : @"Pulse _/¯\_");
73 
74  }
75 
76  OutputActive = true;
77 
78 
79  }
80 
81  private void ConfigTester_FormClosed(object sender, FormClosedEventArgs e)
82  {
83 
84  }
85 
86  private void ConfigTester_FormClosing(object sender, FormClosingEventArgs e)
87  {
88  if (Pinball != null)
89  {
90 
91  Pinball.Finish();
92  }
93  Settings.SaveSettings();
94  }
95 
96  private void ConfigTester_Load(object sender, EventArgs e)
97  {
98  if (!LoadConfig())
99  {
100  this.Close();
101  }
102  }
103 
104  private void TableElements_CellClick(object sender, DataGridViewCellEventArgs e)
105  {
106  int OrgValue;
107  if (e.ColumnIndex >= 0 && e.ColumnIndex < TableElements.ColumnCount)
108  {
109  if (e.RowIndex >= 0 && e.RowIndex < TableElements.RowCount)
110  {
111  if (TableElements.Columns[e.ColumnIndex].Name == TEActivate.Name)
112  {
113  OrgValue = 0;
114  int.TryParse(TableElements[TEValue.Name, e.RowIndex].Value.ToString(), out OrgValue);
115  int NewValue = (OrgValue > 0 ? 0 : 1);
116  TableElements[TEValue.Name, e.RowIndex].Value = NewValue;
117  }
118  else if (TableElements.Columns[e.ColumnIndex].Name == TEPulse.Name)
119  {
120  OrgValue = 0;
121  int.TryParse(TableElements[TEValue.Name, e.RowIndex].Value.ToString(),out OrgValue);
122  int PulseValue = (OrgValue > 0 ? 0 : 1);
123 
124  TableElements[TEValue.Name, e.RowIndex].Value = PulseValue;
125  Thread.Sleep(Settings.PulseDurationMs);
126  TableElements[TEValue.Name, e.RowIndex].Value = OrgValue;
127  }
128  }
129  }
130  }
131 
132  private void TableElements_CellValueChanged(object sender, DataGridViewCellEventArgs e)
133  {
134  if (e.ColumnIndex >= 0 && e.ColumnIndex < TableElements.ColumnCount)
135  {
136  if (e.RowIndex >= 0 && e.RowIndex < TableElements.RowCount)
137  {
138  if (TableElements.Columns[e.ColumnIndex].Name == TEValue.Name)
139  {
140  object Value = TableElements[TEValue.Name, e.RowIndex].Value;
141  int NumericValue = 0;
142  if (!int.TryParse(Value.ToString(), out NumericValue))
143  {
144  MessageBox.Show("The value entered is not a valid number.\nWill set the value to 0.", "Invalid value entered", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
145  TableElements[TEValue.Name, e.RowIndex].Value = 0;
146  NumericValue = 0;
147  }
148  if (OutputActive)
149  {
150  TableElement TE = (TableElement)TableElements.Rows[e.RowIndex].Tag;
151 
153  D.Value = NumericValue;
154  Pinball.ReceiveData(D);
155  }
156 
157  TableElements[TEActivate.Name, e.RowIndex].Value = (NumericValue > 0 ? "Deactivate" : "Activate");
158  TableElements[TEPulse.Name, e.RowIndex].Value = (NumericValue > 0 ? @"Pulse ¯\_/¯" : @"Pulse _/¯\_");
159 
160  }
161  }
162  }
163  }
164 
165  private void PulseDurationInput_ValueChanged(object sender, EventArgs e)
166  {
167  Settings.PulseDurationMs = (int)PulseDurationInput.Value;
168  }
169 
170  private void ActivateAllButton_Click(object sender, EventArgs e)
171  {
172  for (int RowIndex = 0; RowIndex < TableElements.Rows.Count; RowIndex++)
173  {
174  TableElements[TEValue.Name, RowIndex].Value = 1;
175  }
176  }
177 
178  private void DeactivateAllButton_Click(object sender, EventArgs e)
179  {
180  for (int RowIndex = 0; RowIndex < TableElements.Rows.Count; RowIndex++)
181  {
182  TableElements[TEValue.Name, RowIndex].Value = 0;
183  }
184  }
185 
186  private void LoadConfigButton_Click(object sender, EventArgs e)
187  {
188  LoadConfig();
189  }
190 
191  private void ShowFrontEndButton_Click(object sender, EventArgs e)
192  {
194  }
195 
196 
197 
198 
199 
200 
201 
202  }
203 }
void Setup(string GlobalConfigFilename="", string TableFilename="", string RomName="")
Configures the Pinball object. Loads the global config, table config and cabinet config ...
Definition: Pinball.cs:104
int Number
Number of the TableElement.
Definition: TableElement.cs:43
void Sort()
Sorts the ExtList.
Definition: ExtList.cs:256
Pinball is the main object of the DirectOutput framework. It holds all objects required to process P...
Definition: Pinball.cs:23
Table.Table Table
Gets or sets the table object for the Pinball object.
Definition: Pinball.cs:42
int Value
The value of the table element.
void Finish()
Finishes the Pinball object.
Definition: Pinball.cs:446
static Settings LoadSettings()
Definition: Settings.cs:97
string Name
Name of the TableElement. Triggers NameChanged if value is changed.
Definition: TableElement.cs:65
TableElementList TableElements
Lists the TableElement objects for the Table. This list is automaticaly extend with new TableElement...
Definition: Table.cs:27
Data representing the state of a table emlement
void Init()
Initializes/starts the Pinball object
Definition: Pinball.cs:402
void ReceiveData(char TableElementTypeChar, int Number, int Value)
Receives the table element data from the calling app (e.g. B2S.Server providing data through the plug...
Definition: Pinball.cs:688
TableElementData GetTableElementData()
Gets a TableElementData object containing the current data for the TableElement.
static void Open(Pinball Pinball, Form Owner=null)
Definition: MainMenu.cs:58
The Table namespace contains all table specific classes like the Table class itself, TableElement and effect assigment classes.
Definition: Table.cs:14
TableElementTypeEnum TableElementType
Type of the TableElement.
Definition: TableElement.cs:24
Represents a element (e.g. Switch, Solenoid) of a pinball table
Definition: TableElement.cs:12
int Value
Value of the TableElement. Triggers ValueChanged if the value is changed.
Definition: TableElement.cs:94