Merge lp:~widelands-dev/widelands/soldierselect_radiobutton into lp:widelands

Proposed by SirVer
Status: Merged
Merged at revision: 6671
Proposed branch: lp:~widelands-dev/widelands/soldierselect_radiobutton
Merge into: lp:widelands
Diff against target: 197 lines (+48/-48) (has conflicts)
3 files modified
src/wui/buildingwindow.cc (+1/-29)
src/wui/soldiercapacitycontrol.cc (+8/-7)
src/wui/soldierlist.cc (+39/-12)
Text conflict in src/wui/soldiercapacitycontrol.cc
To merge this branch: bzr merge lp:~widelands-dev/widelands/soldierselect_radiobutton
Reviewer Review Type Date Requested Status
cghislai (community) Approve
Review via email: mp+176784@code.launchpad.net

Description of the change

Add a radiobutton to select strength of soldiers.

To post a comment you must log in.
Revision history for this message
cghislai (charlyghislain) wrote :

Looks good and works great. I also like those new icons.
Should there be such option for training sites as well, so we can choose to train rookies or heroes ? I have no idea if the underlying logic could allow this

review: Approve
Revision history for this message
Teppo Mäenpää (kxq) wrote :

About trainingsites: How should these options differ?

Currently, there is an option regarding whether the trainingsite attempts to train least-trained guy or most-trained guy, if there are more than one tha could be trained in a step. There is no UI for that.

Also, it would be relatively easy to switch on/off the whole premature soldier-layoff feature.

Revision history for this message
SirVer (sirver) wrote :

> Should there be such option for training sites as well, so we can choose to train rookies or heroes?
With teppos recent changes I think we have these bases covered - at least we should gather some experience before we go ahead and tweak there again. So I think for now we should not further touch trainingsites at all.

> Also, it would be relatively easy to switch on/off the whole premature soldier-layoff feature.
No way - we have barely any experience with it and I think it is a good idea.

Thanks for the review. I'll merge this soonish then. Or are there more comments?

Revision history for this message
Teppo Mäenpää (kxq) wrote :

I agree that the new buttons look really good, and that their placement is good as well.

However, start and stop buttons have now appeared to the lower left corner. Those should not be present in militarysites. Without this check, "Stop" and "Continue" buttons are not presented. The patch should not remove that check as it does now.

Revision history for this message
Teppo Mäenpää (kxq) wrote :

typo: "Without this check" -> "Without this patch"

Revision history for this message
Teppo Mäenpää (kxq) wrote :

Clarifying myself further: I would change soldierselect_radiobutton/6667 like below. This is a bit ugly, but I somehow just lost the attach-file button..:

=== modified file 'src/wui/buildingwindow.cc'
--- old/src/wui/buildingwindow.cc 2013-07-24 20:52:13 +0000
+++ new/src/wui/buildingwindow.cc 2013-07-27 08:48:17 +0000
@@ -196,7 +196,8 @@
                        }
                }
                else
- if (upcast(const Widelands::ProductionSite, productionsite, &m_building)) {
+ if (upcast(const Widelands::ProductionSite, productionsite, &m_building))
+ if (not dynamic_cast<const Widelands::MilitarySite *>(productionsite)) {
                        const bool is_stopped = productionsite->is_stopped();
                        UI::Button * stopbtn =
                                new UI::Button

Revision history for this message
SirVer (sirver) wrote :

> I agree that the new buttons look really good, and that their placement is good as well.
Thanks! Glad that you like it that way too.

> However, start and stop buttons have now appeared to the lower left corner.
Good catch - I messed that up. I added something along the lines of your patch and merged the branch.

> not dynamic_cast<const Widelands::MilitarySite *>(productionsite)
btw, we have a convenience macro for this is_a(Widelands::Militarysite, productionsite)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'pics/msite_prefer_heroes.png'
2Binary files pics/msite_prefer_heroes.png 2013-06-25 13:35:10 +0000 and pics/msite_prefer_heroes.png 1970-01-01 00:00:00 +0000 differ
3=== removed file 'pics/msite_prefer_rookies.png'
4Binary files pics/msite_prefer_rookies.png 2013-06-25 13:35:10 +0000 and pics/msite_prefer_rookies.png 1970-01-01 00:00:00 +0000 differ
5=== added file 'pics/prefer_heroes.png'
6Binary files pics/prefer_heroes.png 1970-01-01 00:00:00 +0000 and pics/prefer_heroes.png 2013-07-27 10:08:29 +0000 differ
7=== added file 'pics/prefer_rookies.png'
8Binary files pics/prefer_rookies.png 1970-01-01 00:00:00 +0000 and pics/prefer_rookies.png 2013-07-27 10:08:29 +0000 differ
9=== modified file 'src/wui/buildingwindow.cc'
10--- src/wui/buildingwindow.cc 2013-07-26 20:19:36 +0000
11+++ src/wui/buildingwindow.cc 2013-07-27 10:08:29 +0000
12@@ -197,35 +197,7 @@
13 }
14 else
15 if (upcast(const Widelands::ProductionSite, productionsite, &m_building)) {
16- if (upcast(const Widelands::MilitarySite, ms, productionsite))
17- {
18- if (Widelands::MilitarySite::kPrefersHeroes == ms->get_soldier_preference())
19- {
20- UI::Button * cs_btn =
21- new UI::Button
22- (capsbuttons, "rookies", 0, 0, 34, 34,
23- g_gr->images().get("pics/but4.png"),
24- g_gr->images().get("pics/msite_prefer_rookies.png"),
25- _("Prefer rookies"));
26- cs_btn->sigclicked.connect
27- (boost::bind(&Building_Window::act_prefer_rookies, boost::ref(*this)));
28- capsbuttons->add (cs_btn, UI::Box::AlignCenter);
29- }
30- else
31- {
32- UI::Button * cs_btn =
33- new UI::Button
34- (capsbuttons, "heroes", 0, 0, 34, 34,
35- g_gr->images().get("pics/but4.png"),
36- g_gr->images().get("pics/msite_prefer_heroes.png"),
37- _("Prefer heroes"));
38- cs_btn->sigclicked.connect
39- (boost::bind(&Building_Window::act_prefer_heroes, boost::ref(*this)));
40- capsbuttons->add (cs_btn, UI::Box::AlignCenter);
41- }
42- }
43- else // is not a MilitarySite (but is still a productionsite)
44- {
45+ if (!is_a(Widelands::MilitarySite, productionsite)) {
46 const bool is_stopped = productionsite->is_stopped();
47 UI::Button * stopbtn =
48 new UI::Button
49
50=== modified file 'src/wui/soldiercapacitycontrol.cc'
51--- src/wui/soldiercapacitycontrol.cc 2013-07-26 20:19:36 +0000
52+++ src/wui/soldiercapacitycontrol.cc 2013-07-27 10:08:29 +0000
53@@ -23,13 +23,14 @@
54 #include "logic/player.h"
55 #include "logic/soldiercontrol.h"
56 #include "ui_basic/button.h"
57+<<<<<<< TREE
58 #include "wui/interactive_gamebase.h"
59+=======
60+#include "ui_basic/radiobutton.h"
61+>>>>>>> MERGE-SOURCE
62
63 using Widelands::SoldierControl;
64
65-static char const * pic_up_train = "pics/menu_up_train.png";
66-static char const * pic_down_train = "pics/menu_down_train.png";
67-
68 /**
69 * Widget to control the capacity of \ref MilitaryBuilding and \ref TrainingSite
70 * via \ref SoldierControl
71@@ -63,13 +64,13 @@
72 m_igb(igb),
73 m_building(building),
74 m_decrease
75- (this, "decrease", 0, 0, 24, 24,
76+ (this, "decrease", 0, 0, 32, 32,
77 g_gr->images().get("pics/but4.png"),
78- g_gr->images().get(pic_down_train), _("Decrease capacity")),
79+ g_gr->images().get("pics/menu_down_train.png"), _("Decrease capacity")),
80 m_increase
81- (this, "increase", 0, 0, 24, 24,
82+ (this, "increase", 0, 0, 32, 32,
83 g_gr->images().get("pics/but4.png"),
84- g_gr->images().get(pic_up_train), _("Increase capacity")),
85+ g_gr->images().get("pics/menu_up_train.png"), _("Increase capacity")),
86 m_value(this, "199", UI::Align_Center)
87 {
88 m_decrease.sigclicked.connect(boost::bind(&SoldierCapacityControl::click_decrease, boost::ref(*this)));
89
90=== modified file 'src/wui/soldierlist.cc'
91--- src/wui/soldierlist.cc 2013-07-26 20:19:36 +0000
92+++ src/wui/soldierlist.cc 2013-07-27 10:08:29 +0000
93@@ -23,14 +23,17 @@
94
95 #include "container_iterate.h"
96 #include "graphic/font.h"
97+#include "graphic/graphic.h"
98 #include "graphic/rendertarget.h"
99 #include "logic/building.h"
100+#include "logic/militarysite.h"
101 #include "logic/player.h"
102 #include "logic/soldier.h"
103 #include "logic/soldiercontrol.h"
104 #include "ui_basic/box.h"
105 #include "ui_basic/button.h"
106 #include "ui_basic/table.h"
107+#include "upcast.h"
108 #include "wlapplication.h"
109 #include "wui/interactive_gamebase.h"
110 #include "wui/soldiercapacitycontrol.h"
111@@ -38,8 +41,6 @@
112 using Widelands::Soldier;
113 using Widelands::SoldierControl;
114
115-//static char const * pic_drop_soldier = "pics/menu_drop_soldier.png";
116-
117 /**
118 * Iconic representation of soldiers, including their levels and current HP.
119 */
120@@ -353,8 +354,7 @@
121 }
122
123 /**
124- * List of soldiers and a "drop soldiers" button suitable for
125- * \ref MilitarySiteWindow and \ref TrainingSiteWindow
126+ * List of soldiers \ref MilitarySiteWindow and \ref TrainingSiteWindow
127 */
128 struct SoldierList : UI::Box {
129 SoldierList
130@@ -367,10 +367,12 @@
131 private:
132 void mouseover(const Soldier * soldier);
133 void eject(const Soldier * soldier);
134+ void set_soldier_preference(int32_t changed_to);
135
136 Interactive_GameBase & m_igb;
137 Widelands::Building & m_building;
138 SoldierPanel m_soldierpanel;
139+ UI::Radiogroup m_soldier_preference;
140 UI::Textarea m_infotext;
141 };
142
143@@ -402,14 +404,32 @@
144 style.calc_bare_width("HP: 8/8 AT: 8/8 DE: 8/8 EV: 8/8_"));
145 set_min_desired_breadth(maxtextwidth + 4);
146
147- UI::Box * capacity_buttons = new UI::Box(this, 0, 0, UI::Box::Horizontal);
148- capacity_buttons->add
149- (create_soldier_capacity_control(*capacity_buttons, igb, building),
150- UI::Box::AlignCenter);
151-
152- add(capacity_buttons, UI::Box::AlignRight);
153-
154-
155+ UI::Box * buttons = new UI::Box(this, 0, 0, UI::Box::Horizontal);
156+
157+ if (upcast(Widelands::MilitarySite, ms, &building)) {
158+ m_soldier_preference.add_button
159+ (buttons, Point(0, 0), g_gr->images().get("pics/prefer_rookies.png"), _("Prefer Rookies"));
160+ m_soldier_preference.add_button
161+ (buttons, Point(32, 0), g_gr->images().get("pics/prefer_heroes.png"), _("Prefer Heroes"));
162+ UI::Radiobutton* button = m_soldier_preference.get_first_button();
163+ while (button) {
164+ buttons->add(button, AlignLeft);
165+ button = button->next_button();
166+ }
167+
168+ m_soldier_preference.set_state(0);
169+ if (ms->get_soldier_preference() == Widelands::MilitarySite::kPrefersHeroes) {
170+ m_soldier_preference.set_state(1);
171+ }
172+ m_soldier_preference.changedto.connect
173+ (boost::bind(&SoldierList::set_soldier_preference, this, _1));
174+ }
175+ buttons->add_inf_space();
176+ buttons->add
177+ (create_soldier_capacity_control(*buttons, igb, building),
178+ UI::Box::AlignRight);
179+
180+ add(buttons, UI::Box::AlignCenter, true);
181 }
182
183 SoldierControl & SoldierList::soldiers() const
184@@ -451,6 +471,13 @@
185 m_igb.game().send_player_drop_soldier(m_building, soldier->serial());
186 }
187
188+void SoldierList::set_soldier_preference(int32_t changed_to) {
189+ upcast(Widelands::MilitarySite, ms, &m_building);
190+ assert(ms);
191+ ms->set_soldier_preference
192+ (changed_to == 0 ? Widelands::MilitarySite::kPrefersRookies : Widelands::MilitarySite::kPrefersHeroes);
193+}
194+
195 UI::Panel * create_soldier_list
196 (UI::Panel & parent,
197 Interactive_GameBase & igb,

Subscribers

People subscribed via source and target branches

to status/vote changes: