DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
ConfigTester.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
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 
13 namespace DirectOutputConfigTester
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 
25 
26  PulseDurationInput.Value = Settings.PulseDurationMs;
27 
28  }
29 
30  public bool LoadConfig()
31  {
33  if (OCD.ShowDialog() == DialogResult.OK)
34  {
35  if (Pinball != null)
36  {
37  Pinball.Finish();
38  }
39 
40 
41  Pinball = new Pinball();
43 
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  {
193  DirectOutput.Frontend.MainMenu.Open(Pinball);
194  }
195 
196 
197 
198 
199 
200 
201 
202  }
203 }