← Back to team overview

widelands-dev team mailing list archive

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

 

SirVer has proposed merging lp:~widelands-dev/widelands/soldierselect_radiobutton into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1202228 in widelands: "Better controls for specifying preference of strong and weak soldiers"
  https://bugs.launchpad.net/widelands/+bug/1202228

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/soldierselect_radiobutton/+merge/176784

Add a radiobutton to select strength of soldiers.
-- 
https://code.launchpad.net/~widelands-dev/widelands/soldierselect_radiobutton/+merge/176784
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/soldierselect_radiobutton into lp:widelands.
=== removed file 'pics/msite_prefer_heroes.png'
Binary 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
=== removed file 'pics/msite_prefer_rookies.png'
Binary 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
=== added file 'pics/prefer_heroes.png'
Binary files pics/prefer_heroes.png	1970-01-01 00:00:00 +0000 and pics/prefer_heroes.png	2013-07-24 20:54:27 +0000 differ
=== added file 'pics/prefer_rookies.png'
Binary files pics/prefer_rookies.png	1970-01-01 00:00:00 +0000 and pics/prefer_rookies.png	2013-07-24 20:54:27 +0000 differ
=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc	2013-07-23 14:49:48 +0000
+++ src/wui/buildingwindow.cc	2013-07-24 20:54:27 +0000
@@ -197,55 +197,25 @@
 		}
 		else
 		if (upcast(const Widelands::ProductionSite, productionsite, &m_building)) {
-			if (upcast(const Widelands::MilitarySite, ms, productionsite))
-			{
-				if (Widelands::MilitarySite::kPrefersHeroes == ms->get_soldier_preference())
-				{
-					UI::Button * cs_btn =
-					new UI::Button
-					(capsbuttons, "rookies", 0, 0, 34, 34,
-						g_gr->images().get("pics/but4.png"),
-						g_gr->images().get("pics/msite_prefer_rookies.png"),
-						_("Prefer rookies"));
-					cs_btn->sigclicked.connect
-					(boost::bind(&Building_Window::act_prefer_rookies, boost::ref(*this)));
-					capsbuttons->add (cs_btn, UI::Box::AlignCenter);
-				}
-				else
-				{
-					UI::Button * cs_btn =
-					new UI::Button
-					(capsbuttons, "heroes", 0, 0, 34, 34,
-						g_gr->images().get("pics/but4.png"),
-						g_gr->images().get("pics/msite_prefer_heroes.png"),
-						_("Prefer heroes"));
-					cs_btn->sigclicked.connect
-					(boost::bind(&Building_Window::act_prefer_heroes, boost::ref(*this)));
-					capsbuttons->add (cs_btn, UI::Box::AlignCenter);
-				}
-			}
-			else // is not a MilitarySite (but is still a productionsite)
-			{
-				const bool is_stopped = productionsite->is_stopped();
-				UI::Button * stopbtn =
-					new UI::Button
-						(capsbuttons, is_stopped ? "continue" : "stop", 0, 0, 34, 34,
-						 g_gr->images().get("pics/but4.png"),
-						 g_gr->images().get((is_stopped ? "pics/continue.png" : "pics/stop.png")),
-						 is_stopped ? _("Continue") : _("Stop"));
-				stopbtn->sigclicked.connect(boost::bind(&Building_Window::act_start_stop, boost::ref(*this)));
-				capsbuttons->add
-					(stopbtn,
-					 UI::Box::AlignCenter);
-
-
-				// Add a fixed width separator rather than infinite space so the
-				// enhance/destroy/dismantle buttons are fixed in their position
-				// and not subject to the number of buttons on the right of the
-				// panel.
-				UI::Panel * spacer = new UI::Panel(capsbuttons, 0, 0, 17, 34);
-				capsbuttons->add(spacer, UI::Box::AlignCenter);
-			}
+			const bool is_stopped = productionsite->is_stopped();
+			UI::Button * stopbtn =
+				new UI::Button
+					(capsbuttons, is_stopped ? "continue" : "stop", 0, 0, 34, 34,
+					 g_gr->images().get("pics/but4.png"),
+					 g_gr->images().get((is_stopped ? "pics/continue.png" : "pics/stop.png")),
+					 is_stopped ? _("Continue") : _("Stop"));
+			stopbtn->sigclicked.connect(boost::bind(&Building_Window::act_start_stop, boost::ref(*this)));
+			capsbuttons->add
+				(stopbtn,
+				 UI::Box::AlignCenter);
+
+
+			// Add a fixed width separator rather than infinite space so the
+			// enhance/destroy/dismantle buttons are fixed in their position
+			// and not subject to the number of buttons on the right of the
+			// panel.
+			UI::Panel * spacer = new UI::Panel(capsbuttons, 0, 0, 17, 34);
+			capsbuttons->add(spacer, UI::Box::AlignCenter);
 		} // upcast to productionsite
 
 		if (m_capscache & Widelands::Building::PCap_Enhancable) {

=== modified file 'src/wui/soldiercapacitycontrol.cc'
--- src/wui/soldiercapacitycontrol.cc	2013-07-21 07:53:21 +0000
+++ src/wui/soldiercapacitycontrol.cc	2013-07-24 20:54:27 +0000
@@ -24,12 +24,10 @@
 #include "logic/player.h"
 #include "logic/soldiercontrol.h"
 #include "ui_basic/button.h"
+#include "ui_basic/radiobutton.h"
 
 using Widelands::SoldierControl;
 
-static char const * pic_up_train   = "pics/menu_up_train.png";
-static char const * pic_down_train = "pics/menu_down_train.png";
-
 /**
  * Widget to control the capacity of \ref MilitaryBuilding and \ref TrainingSite
  * via \ref SoldierControl
@@ -63,13 +61,13 @@
 m_igb(igb),
 m_building(building),
 m_decrease
-	(this, "decrease", 0, 0, 24, 24,
+	(this, "decrease", 0, 0, 32, 32,
 	 g_gr->images().get("pics/but4.png"),
-	 g_gr->images().get(pic_down_train), _("Decrease capacity")),
+	 g_gr->images().get("pics/menu_down_train.png"), _("Decrease capacity")),
 m_increase
-	(this, "increase", 0, 0, 24, 24,
+	(this, "increase", 0, 0, 32, 32,
 	 g_gr->images().get("pics/but4.png"),
-	 g_gr->images().get(pic_up_train), _("Increase capacity")),
+	 g_gr->images().get("pics/menu_up_train.png"), _("Increase capacity")),
 m_value(this, "199", UI::Align_Center)
 {
 	m_decrease.sigclicked.connect(boost::bind(&SoldierCapacityControl::click_decrease, boost::ref(*this)));

=== modified file 'src/wui/soldierlist.cc'
--- src/wui/soldierlist.cc	2013-02-10 18:47:18 +0000
+++ src/wui/soldierlist.cc	2013-07-24 20:54:27 +0000
@@ -23,9 +23,11 @@
 
 #include "container_iterate.h"
 #include "graphic/font.h"
+#include "graphic/graphic.h"
 #include "graphic/rendertarget.h"
 #include "interactive_gamebase.h"
 #include "logic/building.h"
+#include "logic/militarysite.h"
 #include "logic/player.h"
 #include "logic/soldier.h"
 #include "logic/soldiercontrol.h"
@@ -33,13 +35,12 @@
 #include "ui_basic/box.h"
 #include "ui_basic/button.h"
 #include "ui_basic/table.h"
+#include "upcast.h"
 #include "wlapplication.h"
 
 using Widelands::Soldier;
 using Widelands::SoldierControl;
 
-//static char const * pic_drop_soldier = "pics/menu_drop_soldier.png";
-
 /**
  * Iconic representation of soldiers, including their levels and current HP.
  */
@@ -353,8 +354,7 @@
 }
 
 /**
- * List of soldiers and a "drop soldiers" button suitable for
- * \ref MilitarySiteWindow and \ref TrainingSiteWindow
+ * List of soldiers \ref MilitarySiteWindow and \ref TrainingSiteWindow
  */
 struct SoldierList : UI::Box {
 	SoldierList
@@ -367,10 +367,12 @@
 private:
 	void mouseover(const Soldier * soldier);
 	void eject(const Soldier * soldier);
+	void set_soldier_preference(int32_t changed_to);
 
 	Interactive_GameBase & m_igb;
 	Widelands::Building & m_building;
 	SoldierPanel m_soldierpanel;
+	UI::Radiogroup m_soldier_preference;
 	UI::Textarea m_infotext;
 };
 
@@ -402,14 +404,32 @@
 		 style.calc_bare_width("HP: 8/8  AT: 8/8  DE: 8/8  EV: 8/8_"));
 	set_min_desired_breadth(maxtextwidth + 4);
 
-	UI::Box * capacity_buttons = new UI::Box(this, 0, 0, UI::Box::Horizontal);
-	capacity_buttons->add
-		(create_soldier_capacity_control(*capacity_buttons, igb, building),
-		 UI::Box::AlignCenter);
-
-	add(capacity_buttons, UI::Box::AlignRight);
-
-
+	UI::Box * buttons = new UI::Box(this, 0, 0, UI::Box::Horizontal);
+
+	if (upcast(Widelands::MilitarySite, ms, &building)) {
+		m_soldier_preference.add_button
+			(buttons, Point(0, 0), g_gr->images().get("pics/prefer_rookies.png"), _("Prefer Rookies"));
+		m_soldier_preference.add_button
+			(buttons, Point(32, 0), g_gr->images().get("pics/prefer_heroes.png"), _("Prefer Heroes"));
+		UI::Radiobutton* button = m_soldier_preference.get_first_button();
+		while (button) {
+			buttons->add(button, AlignLeft);
+			button = button->next_button();
+		}
+
+		m_soldier_preference.set_state(0);
+		if (ms->get_soldier_preference() == Widelands::MilitarySite::kPrefersHeroes) {
+			m_soldier_preference.set_state(1);
+		}
+		m_soldier_preference.changedto.connect
+			(boost::bind(&SoldierList::set_soldier_preference, this, _1));
+	}
+	buttons->add_inf_space();
+	buttons->add
+		(create_soldier_capacity_control(*buttons, igb, building),
+		 UI::Box::AlignRight);
+
+	add(buttons, UI::Box::AlignCenter, true);
 }
 
 SoldierControl & SoldierList::soldiers() const
@@ -451,6 +471,13 @@
 		m_igb.game().send_player_drop_soldier(m_building, soldier->serial());
 }
 
+void SoldierList::set_soldier_preference(int32_t changed_to) {
+	upcast(Widelands::MilitarySite, ms, &m_building);
+	assert(ms);
+	ms->set_soldier_preference
+		(changed_to == 0 ? Widelands::MilitarySite::kPrefersRookies : Widelands::MilitarySite::kPrefersHeroes);
+}
+
 UI::Panel * create_soldier_list
 	(UI::Panel & parent,
 	 Interactive_GameBase & igb,


Follow ups