WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
TableInfo.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.FX;
10 using DirectOutput.Table;
11 using System.Reflection;
12 using System.IO;
13 
14 namespace DirectOutput.Frontend
15 {
16  public partial class TableInfo : Form
17  {
18  private Pinball _Pinball;
19 
20  public Pinball Pinball
21  {
22  get { return _Pinball; }
23  set
24  {
25  _Pinball = value;
26  UpdateAll();
27  }
28  }
29 
30  private void UpdateAll()
31  {
32  UpdateWindowTitle();
33  UpdateTableGeneral();
34  UpdateTableEffects();
35  UpdateTableElements();
36  UpdateTableAssignedStaticEffects();
37  }
38 
39  private void UpdateTableGeneral()
40  {
41  DataTable DT = new DataTable();
42  DT.Columns.Add("Property", typeof(string));
43  DT.Columns.Add("Value", typeof(string));
44 
45  DT.Rows.Add("Table name", Pinball.Table.TableName);
46  DT.Rows.Add("Rom name", Pinball.Table.RomName);
47  DT.Rows.Add("Table filename", Pinball.Table.TableFilename);
48  DT.Rows.Add("Table configuration source", ((TableConfigSourceEnum)Pinball.Table.ConfigurationSource).ToString());
49  if (Pinball.Table.ConfigurationSource == TableConfigSourceEnum.TableConfigurationFile)
50  {
51  DT.Rows.Add("Table configuration filename", Pinball.Table.TableConfigurationFilename);
52  }
53  foreach (TableElementTypeEnum TET in Enum.GetValues(typeof(TableElementTypeEnum)))
54  {
55  DT.Rows.Add("{0} count".Build(((TableElementTypeEnum)TET).ToString()), Pinball.Table.TableElements.GetTableElementListForType(TET).Count);
56  }
57 
58  DT.Rows.Add("Configured effects", Pinball.Table.Effects.Count);
59  DT.Rows.Add("Assigned startup effects", Pinball.Table.AssignedStaticEffects.Count);
60 
61  TableGeneral.ClearSelection();
62  TableGeneral.Columns.Clear();
63  TableGeneral.AutoGenerateColumns = true;
64  TableGeneral.DataSource = DT;
65  TableGeneral.Refresh();
66  TableGeneral.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
67  }
68 
69 
70  private void UpdateTableAssignedStaticEffects()
71  {
72  DataTable DT = new DataTable();
73  DT.Columns.Add("Name", typeof(string));
74  DT.Columns.Add("Type", typeof(string));
75  DT.Columns.Add("Configured in", typeof(string));
76 
77  if (Pinball != null)
78  {
79  foreach (AssignedEffect AE in Pinball.Table.AssignedStaticEffects)
80  {
81  Type T = null;
82  string Configured = "<not configured>";
83  if (Pinball.Table.Effects.Contains(AE.EffectName))
84  {
85  T = Pinball.Table.Effects[AE.EffectName].GetType();
86  Configured = "Table";
87  }
88 
89  DT.Rows.Add(AE.EffectName, T.Name, Configured);
90  }
91  }
92  TableAssignedStaticEffects.ClearSelection();
93  TableAssignedStaticEffects.Columns.Clear();
94  TableAssignedStaticEffects.AutoGenerateColumns = true;
95  TableAssignedStaticEffects.DataSource = DT;
96  TableAssignedStaticEffects.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
97  TableAssignedStaticEffects.Refresh();
98  }
99 
100 
101  private void UpdateTableEffects()
102  {
103  DataTable DT = new DataTable();
104  DT.Columns.Add("Name", typeof(string));
105  DT.Columns.Add("Type", typeof(string));
106 
107  if (Pinball != null)
108  {
109  foreach (IEffect E in Pinball.Table.Effects)
110  {
111  DT.Rows.Add(E.Name, E.GetType().Name);
112  }
113  }
114  TableEffects.ClearSelection();
115  TableEffects.Columns.Clear();
116  TableEffects.AutoGenerateColumns = true;
117  TableEffects.DataSource = DT;
118  TableEffects.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
119 
120  TableEffects.Refresh();
121 
122  UpdateEffect();
123  }
124 
125  private void UpdateTableElements()
126  {
127  DataTable DT = new DataTable();
128  DT.Columns.Add("Type", typeof(string));
129  DT.Columns.Add("Number", typeof(int));
130  DT.Columns.Add("Name", typeof(string));
131  DT.Columns.Add("Value", typeof(int));
132  DT.Columns.Add("Assigned FX", typeof(int));
133 
134  if (Pinball != null)
135  {
136  foreach (TableElement E in Pinball.Table.TableElements)
137  {
138  DT.Rows.Add(((TableElementTypeEnum)E.TableElementType).ToString(), E.Number, E.Name, E.Value, E.AssignedEffects.Count);
139  }
140  };
141 
142  DT.DefaultView.Sort = "Type ASC, Number ASC";
143  TableElements.ClearSelection();
144  TableElements.Columns.Clear();
145  TableElements.AutoGenerateColumns = true;
146  TableElements.DataSource = DT;
147  TableElements.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
148 
149  //TableElements.Refresh();
150  }
151 
152  private void UpdateTableElement()
153  {
154  if (TableElements.SelectedRows.Count > 0)
155  {
156  DataRow DR = ((DataRowView)TableElements.SelectedRows[0].DataBoundItem).Row;
157 
158  if(Pinball.Table.TableElements.Contains((TableElementTypeEnum)Enum.Parse(typeof(TableElementTypeEnum), (string)DR.ItemArray[0]), (int)DR.ItemArray[1])) {
159  UpdateTableElementAssignedEffects(Pinball.Table.TableElements[(TableElementTypeEnum)Enum.Parse(typeof(TableElementTypeEnum), (string)DR.ItemArray[0]), (int)DR.ItemArray[1]]);
160  return;
161  }
162  }
163  UpdateTableElementAssignedEffects(null);
164  }
165 
166  private void UpdateTableElementAssignedEffects(TableElement TableElement)
167  {
168  DataTable DT = new DataTable();
169  DT.Columns.Add("Name", typeof(string));
170  DT.Columns.Add("Type", typeof(string));
171  DT.Columns.Add("Configured in", typeof(string));
172 
173  if (TableElement != null)
174  {
175  foreach (AssignedEffect AE in TableElement.AssignedEffects)
176  {
177  Type T = null;
178  string Configured="<not configured>";
179  if(Pinball.Table.Effects.Contains(AE.EffectName)) {
180  T= Pinball.Table.Effects[AE.EffectName].GetType();
181  Configured = "Table";
182  }
183  DT.Rows.Add(AE.EffectName,T.Name,Configured);
184  }
185  }
186  TableElementAssignedEffects.ClearSelection();
187  TableElementAssignedEffects.Columns.Clear();
188  TableElementAssignedEffects.AutoGenerateColumns = true;
189  TableElementAssignedEffects.DataSource = DT;
190  TableElementAssignedEffects.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
191  TableElementAssignedEffects.Refresh();
192  }
193 
194 
195  private void UpdateEffect()
196  {
197  if (TableEffects.SelectedRows.Count > 0)
198  {
199  string N = (string)TableEffects.SelectedRows[0].Cells[0].Value;
200  if (Pinball.Table.Effects.Contains(N))
201  {
202  UpdateEffectProperties(Pinball.Table.Effects[N]);
203  return;
204  }
205  }
206  UpdateEffectProperties(null);
207  }
208 
209  private void UpdateEffectProperties(IEffect Effect)
210  {
211 
212 
213  DataTable DT = new DataTable();
214  DT.Columns.Add("Property", typeof(string));
215  DT.Columns.Add("Value", typeof(string));
216  if (Effect != null)
217  {
218  DT.Rows.Add("Name", Effect.Name);
219 
220  Type T = Effect.GetType();
221  DT.Rows.Add("Type", T.Name);
222 
223  foreach (PropertyInfo PI in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
224  {
225  if (PI.Name != "Name" )
226  {
227  DT.Rows.Add(PI.Name, PI.GetValue(Effect, new object[] { }).ToString());
228  }
229  }
230  }
231  TableEffectProperties.ClearSelection();
232  TableEffectProperties.Columns.Clear();
233  TableEffectProperties.AutoGenerateColumns = true;
234 
235  TableEffectProperties.DataSource = DT;
236  TableEffectProperties.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
237  TableEffectProperties.Refresh();
238 
239 
240 
241  }
242 
243 
244  private void UpdateWindowTitle()
245  {
246  string S = "Table Configuration";
247  if (!Pinball.Table.TableName.IsNullOrWhiteSpace())
248  {
249  S += " - {0}".Build(Pinball.Table.TableName);
250  }
251 
252  if (!Pinball.Table.RomName.IsNullOrWhiteSpace())
253  {
254  S += " - {0}".Build(Pinball.Table.RomName);
255  }
256  this.Text = S;
257  }
258 
259 
260 
262  {
263  InitializeComponent();
264  this.Pinball = Pinball;
265  }
266 
267  private void TableEffects_SelectionChanged(object sender, EventArgs e)
268  {
269  UpdateEffect();
270  }
271 
272  private void TableElements_SelectionChanged(object sender, EventArgs e)
273  {
274  UpdateTableElement();
275  }
276 
277  private void RefreshWindow_Click(object sender, EventArgs e)
278  {
279  UpdateAll();
280  }
281 
282  private void ExportTableConfiguration_Click(object sender, EventArgs e)
283  {
284  if (!Pinball.Table.TableConfigurationFilename.IsNullOrWhiteSpace())
285  {
286  FileInfo FI = new FileInfo(Pinball.Table.TableConfigurationFilename);
287  SaveTableConfigDialog.InitialDirectory = FI.Directory.FullName;
288  SaveTableConfigDialog.FileName = FI.FullName;
289  }
290  else if (!Pinball.Table.TableFilename.IsNullOrWhiteSpace())
291  {
292  FileInfo FI = new FileInfo(Pinball.Table.TableFilename);
293  SaveTableConfigDialog.InitialDirectory = FI.Directory.FullName;
294  SaveTableConfigDialog.FileName = Path.Combine(FI.Directory.FullName,"{0}.xml".Build(FI.GetNameWithoutExtension()));
295  }
296  else
297  {
298  SaveTableConfigDialog.InitialDirectory = Pinball.GlobalConfig.GetGlobalConfigDirectory().FullName;
299  }
300  if (SaveTableConfigDialog.ShowDialog() == DialogResult.OK)
301  {
302  Pinball.Table.TableConfigurationFilename = SaveTableConfigDialog.FileName;
303  try
304  {
305  Pinball.Table.SaveConfigXmlFile(SaveTableConfigDialog.FileName);
306  UpdateWindowTitle();
307  MessageBox.Show("Table configuration saved to\n{0}".Build(SaveTableConfigDialog.FileName), "Table configuration saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
308  }
309  catch (Exception E)
310  {
311  MessageBox.Show("Could not save table config to\n{0}\n\nThe following error occured:\n{1}".Build(SaveTableConfigDialog.FileName, E.Message), "File save error", MessageBoxButtons.OK, MessageBoxIcon.Error);
312  }
313  }
314  }
315 
316 
317 
318 
319 
320 
321 
322 
323  }
324 }
AssignedEffectList AssignedEffects
List of effects which are assigned to the table element.
int Number
Number of the TableElement.
Definition: TableElement.cs:43
string RomName
Name of the table rom. Triggers RomNameChanged if value is changed.
Definition: Table.cs:110
string TableName
Name of the Table. Triggers TableNameChanged if value is changed.
Definition: Table.cs:82
TableElementTypeEnum
Enum for the different TableElement types.
Pinball is the main object of the DirectOutput framework. It holds all objects required to process P...
Definition: Pinball.cs:23
TableConfigSourceEnum ConfigurationSource
Gets or sets the configuration source.
Definition: Table.cs:174
new string Name
Name of the effect.
Definition: IEffect.cs:53
Table.Table Table
Gets or sets the table object for the Pinball object.
Definition: Pinball.cs:42
TableConfigSourceEnum
Enum used to specify the source of a table configuration
Common interface for all effects. If a new effect is implemented it is best to inherit from the abst...
Definition: IEffect.cs:13
string Name
Name of the TableElement. Triggers NameChanged if value is changed.
Definition: TableElement.cs:65
string TableFilename
Gets or sets the filename of the table.
Definition: Table.cs:137
string TableConfigurationFilename
Gets or sets the table configuration filename.
Definition: Table.cs:146
string EffectName
Name of the AssignedEffect. Triggers EffectNameChanged if value is changed.
TableInfo(Pinball Pinball)
Definition: TableInfo.cs:261
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
The namespace FX contains effect related classes. Effects can be assigned directly to a Table and wi...
Represents a element (e.g. Switch, Solenoid) of a pinball table
Definition: TableElement.cs:12
int Count
Number of items in the ExtList.
Definition: ExtList.cs:159
Handles the assignemt of a effect to a AssignedEffectList.
int Value
Value of the TableElement. Triggers ValueChanged if the value is changed.
Definition: TableElement.cs:94