← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~nomeata/widelands/plot-improvements into lp:widelands

 

Joachim Breitner has proposed merging lp:~nomeata/widelands/plot-improvements into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #536543 in widelands: "Add "whole game" to the time axis in statistics"
  https://bugs.launchpad.net/widelands/+bug/536543
  Bug #672085 in widelands: "New stock menu layout too high for small resolutions"
  https://bugs.launchpad.net/widelands/+bug/672085
  Bug #886709 in widelands: "new slider statistics menu opens in wrong position or so"
  https://bugs.launchpad.net/widelands/+bug/886709
  Bug #887728 in widelands: "The new statistics slider does not update if the window is left open"
  https://bugs.launchpad.net/widelands/+bug/887728

For more details, see:
https://code.launchpad.net/~nomeata/widelands/plot-improvements/+merge/81649

This ought to fix 887728.
-- 
https://code.launchpad.net/~nomeata/widelands/plot-improvements/+merge/81649
Your team Widelands Developers is requested to review the proposed merge of lp:~nomeata/widelands/plot-improvements into lp:widelands.
=== modified file 'src/ui_basic/slider.cc'
--- src/ui_basic/slider.cc	2011-11-06 18:26:10 +0000
+++ src/ui_basic/slider.cc	2011-11-08 22:48:39 +0000
@@ -572,6 +572,12 @@
 
 }
 
+void DiscreteSlider::set_labels(const std::vector<std::string> labels_in) {
+	labels = labels_in;
+	slider.set_max_value(labels_in.size()-1);
+	layout();
+}
+
 void DiscreteSlider::layout() {
 	uint32_t w = get_w();
 	uint32_t h = get_h();

=== modified file 'src/ui_basic/slider.h'
--- src/ui_basic/slider.h	2011-11-06 18:26:10 +0000
+++ src/ui_basic/slider.h	2011-11-08 22:48:39 +0000
@@ -211,13 +211,18 @@
 protected:
 	HorizontalSlider slider;
 public:
+	void set_labels(std::vector<std::string>);
+
 	Signal *       changed;
 	Signal1<int32_t> *  changedto;
+
+private:
+	std::vector<std::string> labels;
+
 protected:
-	const std::vector<std::string> labels;
 
-	void draw(RenderTarget & dst);
-	void layout();
+	virtual void draw(RenderTarget & dst);
+	virtual void layout();
 };
 
 

=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc	2011-11-06 16:18:15 +0000
+++ src/wui/buildingwindow.cc	2011-11-08 22:48:39 +0000
@@ -290,9 +290,10 @@
 	if (m_helpwindow_registry.window)
 		delete m_helpwindow_registry.window;
 	else
-		new UI::LuaTextHelpWindow(&igbase(), m_helpwindow_registry,
-				m_building.descname(),
-				m_building.descr().helptext_script());
+		new UI::LuaTextHelpWindow
+			(&igbase(), m_helpwindow_registry,
+			 m_building.descname(),
+			 m_building.descr().helptext_script());
 }
 
 /*

=== modified file 'src/wui/plot_area.cc'
--- src/wui/plot_area.cc	2011-11-06 10:23:32 +0000
+++ src/wui/plot_area.cc	2011-11-08 22:48:39 +0000
@@ -140,14 +140,18 @@
 }
 
 /**
- * Find the last predefined time span that is less than the game time
+ * Find the last predefined time span that is less than the game time. If this
+ * is called from the outside, e.g. from a slider, then from that moment on
+ * this class assumes that values passed to set_time_id adhere to the new
+ * choice of time spans.
  */
-void WUIPlot_Area::calc_game_time_id() {
+int32_t WUIPlot_Area::get_game_time_id() {
 	uint32_t game_time = get_game_time();
 	uint32_t i = 0;
 	for (i = 0; i < 7 && time_in_ms[i] <= game_time; i++) {
 	}
 	m_game_time_id = i;
+	return m_game_time_id;
 }
 
 /*
@@ -387,7 +391,7 @@
 	m_plotdata[id].showplot  = false;
 	m_plotdata[id].plotcolor = color;
 
-	calc_game_time_id();
+	get_game_time_id();
 }
 
 /*
@@ -405,3 +409,13 @@
 	m_sample_rate = id;
 }
 
+
+void WUIPlot_Area_Slider::draw(RenderTarget & dst) {
+	int32_t new_game_time_id = m_plot_area.get_game_time_id();
+	if (new_game_time_id != m_last_game_time_id) {
+		m_last_game_time_id = new_game_time_id;
+		set_labels(m_plot_area.get_labels());
+		slider.set_value(m_plot_area.get_time_id());
+	}
+	UI::DiscreteSlider::draw(dst);
+}

=== modified file 'src/wui/plot_area.h'
--- src/wui/plot_area.h	2011-11-06 21:26:10 +0000
+++ src/wui/plot_area.h	2011-11-08 22:48:39 +0000
@@ -79,6 +79,8 @@
 			return m_time;
 	};
 	void set_sample_rate(uint32_t id); // in milliseconds
+	
+	int32_t get_game_time_id();
 
 	void register_plot_data
 		(uint32_t id, const std::vector<uint32_t> * data, RGBColor);
@@ -91,7 +93,6 @@
 private:
 	uint32_t get_game_time();
 	uint32_t get_plot_time();
-	void calc_game_time_id();
 	UNIT get_suggested_unit(uint32_t game_time);
 	std::string get_unit_name(UNIT unit);
 	uint32_t ms_to_unit(UNIT unit, uint32_t ms);
@@ -129,10 +130,19 @@
 		 background_picture_id,
 		 tooltip_text,
 		 cursor_size,
-		 enabled)
+		 enabled),
+	  m_plot_area(plot_area),
+	  m_last_game_time_id(plot_area.get_game_time_id())
 	{
 		changedto->set(&plot_area, &WUIPlot_Area::set_time_id);
 	}
+
+protected:
+	void draw(RenderTarget & dst);
+
+private:
+	WUIPlot_Area & m_plot_area;
+	int32_t m_last_game_time_id;
 };
 
 #endif

=== modified file 'src/wui/waresdisplay.cc'
--- src/wui/waresdisplay.cc	2011-11-05 18:47:36 +0000
+++ src/wui/waresdisplay.cc	2011-11-08 22:48:39 +0000
@@ -29,6 +29,8 @@
 #include "logic/tribe.h"
 #include "logic/worker.h"
 
+#include "wexception.h"
+
 #include <cstdio>
 #include <boost/lexical_cast.hpp>
 
@@ -186,6 +188,7 @@
 			return m_tribe.workers_order();
 			break;
 	}
+	throw wexception("Invalid m_type %d", m_type);
 }
 
 Widelands::Tribe_Descr::WaresOrderCoords const & AbstractWaresDisplay::icons_order_coords() const
@@ -198,6 +201,7 @@
 			return m_tribe.workers_order_coords();
 			break;
 	}
+	throw wexception("Invalid m_type %d", m_type);
 }
 
 


Follow ups