comparison FrmChangeGameSystem.cs @ 0:1bb28f84d567

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 65279b85446f
comparison
equal deleted inserted replaced
-1:000000000000 0:1bb28f84d567
1 // FrmChangeGameSystem.cs
2 //
3 // Copyright (C) 2007 IBBoard
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License version 2.1 of the License as published by the Free
8 // Software Foundation.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 //
19 //
20
21 using System;
22 using IBBoard.WarFoundry.API;
23 using IBBoard.WarFoundry.API.Objects;
24 using Gtk;
25 using log4net;
26
27 namespace IBBoard.WarFoundry
28 {
29 public partial class FrmChangeGameSystem : Dialog
30 {
31 private ILog logger = LogManager.GetLogger(typeof(FrmChangeGameSystem));
32 //private AbstractNativeWarFoundryFactory factory;
33 private GameSystem selectedSystem;
34
35 public FrmChangeGameSystem(Window parent) : base("Change Game System", parent, DialogFlags.Modal)
36 {
37 this.Build();
38 lstGameSystems.Selection.Changed+= new EventHandler(OnSelectionChanged);
39 TreeViewColumn gameSystemColumn = new TreeViewColumn ();
40 gameSystemColumn.Title = "Game System";
41 CellRendererText gameSystemCell = new CellRendererText ();
42 gameSystemColumn.PackStart (gameSystemCell, true);
43 lstGameSystems.AppendColumn(gameSystemColumn);
44 gameSystemColumn.SetCellDataFunc (gameSystemCell, new TreeCellDataFunc (RenderSystemName));
45 ListStore store = new ListStore(typeof(GameSystem));
46
47 foreach (GameSystem system in WarFoundryLoader.GetDefault().GetGameSystems())
48 {
49 store.AppendValues(system);
50 }
51
52 lstGameSystems.Model = store;
53 }
54
55 private void RenderSystemName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
56 {
57 GameSystem system = (GameSystem) model.GetValue(iter, 0);
58 (cell as CellRendererText).Text = system.Name;
59 }
60
61 protected virtual void OnGameSystemOkayClicked(object sender, EventArgs e)
62 {
63 logger.Debug("Okay clicked");
64 SetReturnValue();
65 Respond(ResponseType.Ok);
66 }
67
68 private void SetReturnValue()
69 {
70 TreeModel model;
71 TreeIter iter;
72 lstGameSystems.Selection.GetSelected (out model, out iter);
73 selectedSystem = (GameSystem) model.GetValue(iter, 0);
74 }
75
76 protected virtual void OnSelectionChanged(object o, EventArgs e)
77 {
78 logger.Debug("Selection changed");
79 buttonOk.Sensitive = (lstGameSystems.Selection.CountSelectedRows() > 0);
80 }
81
82 protected virtual void OnCancel (object sender, System.EventArgs e)
83 {
84 logger.Debug("Cancel clicked");
85 Respond(ResponseType.Cancel);
86 }
87
88 protected virtual void lstGameSystemsRowActivated (object o, Gtk.RowActivatedArgs args)
89 {
90 logger.Debug("List row double-clicked");
91 SetReturnValue();
92 Respond(ResponseType.Ok);
93 }
94
95 public GameSystem SelectedSystem
96 {
97 get { return selectedSystem; }
98 }
99 }
100 }