5
|
1 // This file (FrmChangeGameSystem.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2009 IBBoard.
|
0
|
2 //
|
5
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
|
0
|
4
|
|
5 using System;
|
|
6 using IBBoard.WarFoundry.API;
|
|
7 using IBBoard.WarFoundry.API.Objects;
|
|
8 using Gtk;
|
|
9 using log4net;
|
|
10
|
5
|
11 namespace IBBoard.WarFoundry.GTK
|
0
|
12 {
|
|
13 public partial class FrmChangeGameSystem : Dialog
|
|
14 {
|
|
15 private ILog logger = LogManager.GetLogger(typeof(FrmChangeGameSystem));
|
|
16 //private AbstractNativeWarFoundryFactory factory;
|
|
17 private GameSystem selectedSystem;
|
|
18
|
|
19 public FrmChangeGameSystem(Window parent) : base("Change Game System", parent, DialogFlags.Modal)
|
|
20 {
|
|
21 this.Build();
|
|
22 lstGameSystems.Selection.Changed+= new EventHandler(OnSelectionChanged);
|
|
23 TreeViewColumn gameSystemColumn = new TreeViewColumn ();
|
|
24 gameSystemColumn.Title = "Game System";
|
|
25 CellRendererText gameSystemCell = new CellRendererText ();
|
|
26 gameSystemColumn.PackStart (gameSystemCell, true);
|
|
27 lstGameSystems.AppendColumn(gameSystemColumn);
|
|
28 gameSystemColumn.SetCellDataFunc (gameSystemCell, new TreeCellDataFunc (RenderSystemName));
|
|
29 ListStore store = new ListStore(typeof(GameSystem));
|
|
30
|
|
31 foreach (GameSystem system in WarFoundryLoader.GetDefault().GetGameSystems())
|
|
32 {
|
|
33 store.AppendValues(system);
|
|
34 }
|
|
35
|
|
36 lstGameSystems.Model = store;
|
|
37 }
|
|
38
|
|
39 private void RenderSystemName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
|
|
40 {
|
|
41 GameSystem system = (GameSystem) model.GetValue(iter, 0);
|
|
42 (cell as CellRendererText).Text = system.Name;
|
|
43 }
|
|
44
|
|
45 protected virtual void OnGameSystemOkayClicked(object sender, EventArgs e)
|
|
46 {
|
|
47 logger.Debug("Okay clicked");
|
|
48 SetReturnValue();
|
|
49 Respond(ResponseType.Ok);
|
|
50 }
|
|
51
|
|
52 private void SetReturnValue()
|
|
53 {
|
|
54 TreeModel model;
|
|
55 TreeIter iter;
|
|
56 lstGameSystems.Selection.GetSelected (out model, out iter);
|
|
57 selectedSystem = (GameSystem) model.GetValue(iter, 0);
|
|
58 }
|
|
59
|
|
60 protected virtual void OnSelectionChanged(object o, EventArgs e)
|
|
61 {
|
|
62 logger.Debug("Selection changed");
|
|
63 buttonOk.Sensitive = (lstGameSystems.Selection.CountSelectedRows() > 0);
|
|
64 }
|
|
65
|
|
66 protected virtual void OnCancel (object sender, System.EventArgs e)
|
|
67 {
|
|
68 logger.Debug("Cancel clicked");
|
|
69 Respond(ResponseType.Cancel);
|
|
70 }
|
|
71
|
|
72 protected virtual void lstGameSystemsRowActivated (object o, Gtk.RowActivatedArgs args)
|
|
73 {
|
|
74 logger.Debug("List row double-clicked");
|
|
75 SetReturnValue();
|
|
76 Respond(ResponseType.Ok);
|
|
77 }
|
|
78
|
|
79 public GameSystem SelectedSystem
|
|
80 {
|
|
81 get { return selectedSystem; }
|
|
82 }
|
|
83 }
|
|
84 }
|