Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
comparison Widgets/UnitDisplayWidget.cs @ 53:28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
* Use proper method for making dialog appear
Re #306: Combine equipment lists in GTK#
* Populate unit equipment lists on unit display widget
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 25 Aug 2010 15:21:56 +0000 |
parents | 4bad8cb3f889 |
children | 7bba99c368c8 |
comparison
equal
deleted
inserted
replaced
52:4bad8cb3f889 | 53:28b242612ad7 |
---|---|
5 using System; | 5 using System; |
6 using Gtk; | 6 using Gtk; |
7 using IBBoard.Commands; | 7 using IBBoard.Commands; |
8 using IBBoard.Lang; | 8 using IBBoard.Lang; |
9 using IBBoard.WarFoundry.API; | 9 using IBBoard.WarFoundry.API; |
10 using IBBoard.WarFoundry.API.Objects; | 10 using WFObjects = IBBoard.WarFoundry.API.Objects; |
11 using IBBoard.WarFoundry.API.Commands; | 11 using IBBoard.WarFoundry.API.Commands; |
12 using IBBoard.WarFoundry.GUI.GTK.UIControl; | 12 using IBBoard.WarFoundry.GUI.GTK.UIControl; |
13 using IBBoard.WarFoundry.API.Objects; | |
14 using IBBoard.WarFoundry.API.Util; | |
13 | 15 |
14 namespace IBBoard.WarFoundry.GTK.Widgets | 16 namespace IBBoard.WarFoundry.GTK.Widgets |
15 { | 17 { |
16 [System.ComponentModel.Category("WarFoundry GTK# GUI")] | 18 [System.ComponentModel.Category("WarFoundry GTK# GUI")] |
17 [System.ComponentModel.ToolboxItem(true)] | 19 [System.ComponentModel.ToolboxItem(true)] |
18 public partial class UnitDisplayWidget : Gtk.Bin | 20 public partial class UnitDisplayWidget : Gtk.Bin |
19 { | 21 { |
20 private IBBoard.WarFoundry.API.Objects.Unit unit; | 22 private WFObjects.Unit unit; |
21 private CommandStack stack; | 23 private CommandStack stack; |
22 | 24 |
23 public UnitDisplayWidget(IBBoard.WarFoundry.API.Objects.Unit sourceUnit, CommandStack commandStack) | 25 public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack) |
24 { | 26 { |
25 this.Build(); | 27 this.Build(); |
26 stack = commandStack; | 28 stack = commandStack; |
27 unit = sourceUnit; | 29 unit = sourceUnit; |
28 unitName.Text = unit.Name; | 30 unitName.Text = unit.Name; |
37 | 39 |
38 unitSize.SetRange(unit.UnitType.MinSize, max); | 40 unitSize.SetRange(unit.UnitType.MinSize, max); |
39 unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged); | 41 unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged); |
40 unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged); | 42 unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged); |
41 SetStats(); | 43 SetStats(); |
44 SetWeapons(); | |
42 } | 45 } |
43 | 46 |
44 private void SetStats() | 47 private void SetStats() |
45 { | 48 { |
46 //GameSystem system = unit.Army.GameSystem; | |
47 //SystemStats stats = system.StandardSystemStats; | |
48 CellRendererText renderer = new CellRendererText(); | 49 CellRendererText renderer = new CellRendererText(); |
49 unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName)); | 50 unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName)); |
50 | 51 |
51 TreeCellDataFunc statFunc = new TreeCellDataFunc(RenderUnitStat); | 52 TreeCellDataFunc statFunc = new TreeCellDataFunc(RenderUnitStat); |
52 Stat[] stats = unit.UnitStatsArray; | 53 Stat[] stats = unit.UnitStatsArray; |
56 for (int i = 0; i < length; i++) | 57 for (int i = 0; i < length; i++) |
57 { | 58 { |
58 unitStats.AppendColumn(stats[i].ParentSlotName, renderer, statFunc); | 59 unitStats.AppendColumn(stats[i].ParentSlotName, renderer, statFunc); |
59 } | 60 } |
60 | 61 |
61 TreeStore model = new TreeStore(typeof(IBBoard.WarFoundry.API.Objects.Unit)); | 62 TreeStore model = new TreeStore(typeof(WFObjects.Unit)); |
62 model.AppendValues(unit); | 63 model.AppendValues(unit); |
63 unitStats.Model = model; | 64 unitStats.Model = model; |
64 } | 65 } |
65 | 66 |
66 private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | 67 private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
67 { | 68 { |
68 object o = model.GetValue(iter, 0); | 69 object o = model.GetValue(iter, 0); |
69 | 70 |
70 if (o is IBBoard.WarFoundry.API.Objects.Unit) | 71 if (o is WFObjects.Unit) |
71 { | 72 { |
72 IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o; | 73 WFObjects.Unit u = (WFObjects.Unit)o; |
73 (cell as CellRendererText).Text = u.UnitType.Name; | 74 (cell as CellRendererText).Text = u.UnitType.Name; |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
77 private void RenderUnitStat(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | 78 private void RenderUnitStat(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
78 { | 79 { |
79 object o = model.GetValue(iter, 0); | 80 object o = model.GetValue(iter, 0); |
80 | 81 |
81 if (o is IBBoard.WarFoundry.API.Objects.Unit) | 82 if (o is WFObjects.Unit) |
82 { | 83 { |
83 IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o; | 84 WFObjects.Unit u = (WFObjects.Unit)o; |
84 (cell as CellRendererText).Text = u.GetStatValue(column.Title); | 85 (cell as CellRendererText).Text = u.GetStatValue(column.Title); |
85 } | 86 } |
86 } | 87 } |
87 | 88 |
88 public IBBoard.WarFoundry.API.Objects.Unit Unit | 89 private void SetWeapons() |
90 { | |
91 CellRendererText renderer = new CellRendererText(); | |
92 equipmentList.AppendColumn("", renderer, new TreeCellDataFunc(RenderEquipmentLine)); | |
93 | |
94 | |
95 TreeStore model = new TreeStore(typeof(UnitEquipmentItem)); | |
96 model.AppendValues(unit.GetEquipment()); | |
97 equipmentList.Model = model; | |
98 } | |
99 | |
100 public void RenderEquipmentLine(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
101 { | |
102 object o = model.GetValue(iter, 0); | |
103 | |
104 if (o is UnitEquipmentItem) | |
105 { | |
106 UnitEquipmentItem item = (UnitEquipmentItem)o; | |
107 (cell as CellRendererText).Text = GetUnitEquipmentText(item); | |
108 } | |
109 | |
110 } | |
111 | |
112 private string GetUnitEquipmentText(UnitEquipmentItem item) | |
113 { | |
114 string translation = ""; | |
115 | |
116 if (item.Cost == 0) | |
117 { | |
118 translation = Translation.GetTranslation("equipmentAmountWithZeroCost", "{0} ({1} - free)", item.Name, GetAmountString(item)); | |
119 } | |
120 else | |
121 { | |
122 translation = Translation.GetTranslation("equipmentAmountWithCost", "{0} ({1} at {2}pts each)", item.Name, GetAmountString(item), item.Cost); | |
123 } | |
124 | |
125 return translation; | |
126 } | |
127 | |
128 private string GetAmountString(UnitEquipmentItem item) | |
129 { | |
130 double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, item); | |
131 string amountString = ""; | |
132 | |
133 if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, item)) | |
134 { | |
135 int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, item); | |
136 | |
137 if (amount == 100) | |
138 { | |
139 amountString = Translation.GetTranslation("equipmentChoiceAmountAll", "all ({1})", amount, number); | |
140 } | |
141 | |
142 else | |
143 { | |
144 amountString = Translation.GetTranslation("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number); | |
145 } | |
146 } | |
147 | |
148 else | |
149 { | |
150 amountString = Translation.GetTranslation("equipmentChoiceAmountNumber", "{0}", amount); | |
151 } | |
152 | |
153 return amountString; | |
154 } | |
155 | |
156 public WFObjects.Unit Unit | |
89 { | 157 { |
90 get { return unit; } | 158 get { return unit; } |
91 } | 159 } |
92 | 160 |
93 private void UnitNameChanged(WarFoundryObject obj, string oldValue, string newValue) | 161 private void UnitNameChanged(WarFoundryObject obj, string oldValue, string newValue) |