← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~gamag/widelands/buildcostTooltip into lp:widelands

 

Gabriel Margiani has proposed merging lp:~gamag/widelands/buildcostTooltip into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1019585 in widelands: "Building window background "jumping" when previewing upgrade build cost"
  https://bugs.launchpad.net/widelands/+bug/1019585
  Bug #1090887 in widelands: "buildcosts and "wares that get recycled" preview moves the window"
  https://bugs.launchpad.net/widelands/+bug/1090887

For more details, see:
https://code.launchpad.net/~gamag/widelands/buildcostTooltip/+merge/144383

Moved the build/return costs preview into a tooltip using the nice new rt engine.
(by the way, why can't I use 000000 as black background in richtext [will be fully transparent]?)
-- 
https://code.launchpad.net/~gamag/widelands/buildcostTooltip/+merge/144383
Your team Widelands Developers is requested to review the proposed merge of lp:~gamag/widelands/buildcostTooltip into lp:widelands.
=== modified file 'src/logic/item_ware_descr.h'
--- src/logic/item_ware_descr.h	2012-11-24 16:22:10 +0000
+++ src/logic/item_ware_descr.h	2013-01-22 20:15:33 +0000
@@ -69,6 +69,7 @@
 
 	/// \return index to ware's icon inside picture stack
 	const IPicture* icon() const throw () {return m_icon;}
+	std::string icon_name() const throw () {return m_icon_fname;}
 
 	/// \return ware's localized descriptive text
 	std::string const & helptext() const throw () {return m_helptext;}

=== modified file 'src/ui_basic/icongrid.cc'
--- src/ui_basic/icongrid.cc	2012-12-14 20:09:35 +0000
+++ src/ui_basic/icongrid.cc	2013-01-22 20:15:33 +0000
@@ -38,29 +38,25 @@
 		 const IPicture* background_pictute_id,
 		 const IPicture* foreground_picture_id,
 		 const uint32_t callback_argument_id,
-		 Textarea          & ta, std::string const & descr)
+		 std::string const & tooltip_text)
 		:
 		Button
 			(&parent, name, x, y, w, h, background_pictute_id,
 			 foreground_picture_id,
-			 "", true, true),
-			 m_icongrid(parent), m_ta(ta), m_descr(descr),
+			 tooltip_text, true, true),
+			 m_icongrid(parent),
 			 _callback_argument_id(callback_argument_id)
 		{}
 
 private:
 	Icon_Grid & m_icongrid;
-	Textarea  & m_ta;
-	std::string m_descr;
 	const uint32_t _callback_argument_id;
 
 	void handle_mousein(bool const inside) {
 		if (inside) {
 			m_icongrid.mousein(_callback_argument_id);
-			m_ta.set_text(m_descr);
 		} else {
 			m_icongrid.mouseout(_callback_argument_id);
-			m_ta.set_text("");
 		}
 		Button::handle_mousein(inside);
 	}
@@ -77,8 +73,7 @@
 	Panel            (parent, x, y, 0, 0),
 	m_columns        (cols),
 	m_cell_width     (cellw),
-	m_cell_height    (cellh),
-	m_ta         (this, 0, 0, 0, g_fh->get_fontheight(UI_FONT_SMALL) + 2)
+	m_cell_height    (cellh)
 {}
 
 
@@ -88,7 +83,7 @@
 */
 int32_t Icon_Grid::add
 	(std::string const & name, const IPicture* pic,
-	 void * const data, std::string const & descr)
+	 void * const data, std::string const & tooltip_text)
 {
 	Item it;
 
@@ -100,14 +95,10 @@
 	int32_t const rows = (m_items.size() + m_columns - 1) / m_columns;
 
 	if (rows <= 1) {
-		set_desired_size(m_cell_width * m_columns, m_cell_height + m_ta.get_h());
-		m_ta.set_size(get_inner_w(), m_ta.get_h());
-		m_ta.set_pos(Point(0, m_cell_height));
+		set_desired_size(m_cell_width * m_columns, m_cell_height);
 	} else {
 		set_desired_size
-			(m_cell_width * m_columns, m_cell_height * rows + m_ta.get_h());
-		m_ta.set_size(get_inner_w(), m_ta.get_h());
-		m_ta.set_pos(Point(0, m_cell_height * rows));
+			(m_cell_width * m_columns, m_cell_height * rows);
 	}
 
 	uint32_t idx = m_items.size() - 1;
@@ -118,7 +109,7 @@
 		(*this, name,
 		 x, y, m_cell_width, m_cell_height,
 		 NULL, pic,
-		 idx, m_ta, descr);
+		 idx, tooltip_text);
 	btn->sigclicked.connect(boost::bind(&Icon_Grid::clicked_button, this, idx));
 
 	return idx;

=== modified file 'src/ui_basic/icongrid.h'
--- src/ui_basic/icongrid.h	2012-12-14 20:09:35 +0000
+++ src/ui_basic/icongrid.h	2013-01-22 20:15:33 +0000
@@ -49,7 +49,7 @@
 		(std::string const & name,
 		 const IPicture* pic,
 		 void              * data,
-		 std::string const & descr = std::string());
+		 std::string const & tooltip_text = std::string());
 	void * get_data(int32_t idx);
 
 private:
@@ -64,7 +64,6 @@
 	int32_t m_cell_width; ///< size of one cell
 	int32_t m_cell_height;
 
-	Textarea          m_ta;
 	std::vector<Item> m_items;
 };
 

=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc	2012-12-30 03:24:39 +0000
+++ src/wui/buildingwindow.cc	2013-01-22 20:15:33 +0000
@@ -72,17 +72,6 @@
 	// actually create buttons on the first call to think(),
 	// so that overriding create_capsbuttons() works
 
-	UI::Box * prevbox = new UI::Box(vbox, 0, 0, UI::Box::Vertical);
-
-	m_prevtext = new UI::Textarea(prevbox);
-	m_prevtext->set_desired_size(0, 0);
-	prevbox->add(m_prevtext, UI::Box::AlignLeft);
-
-	m_enhancecostPrev = new WaresMapDisplay(prevbox, 0, 0, 10, m_building.tribe(), NULL);
-	prevbox->add(m_enhancecostPrev, UI::Box::AlignLeft);
-
-	vbox->add(prevbox, UI::Box::AlignLeft);
-
 	set_center_panel(vbox);
 	set_think(true);
 
@@ -214,22 +203,14 @@
 						new UI::Button
 							(capsbuttons, "enhance", 0, 0, 34, 34,
 							 g_gr->imgcache().load(PicMod_UI, "pics/but4.png"),
-							 building_descr.get_buildicon()); //  button id = building id)
+							 building_descr.get_buildicon(),
+							 std::string(buffer) + "<br>" + _("Buildcosts:") + "<br>" +
+								 waremap_to_string(tribe, building_descr.buildcost())); //  button id = building id
 					enhancebtn->sigclicked.connect
 						(boost::bind
 							(&Building_Window::act_enhance,
 							 boost::ref(*this),
 							 boost::ref(*i.current)));
-					enhancebtn->sigmousein.connect
-						(boost::bind
-							(&Building_Window::show_costPrev,
-							 boost::ref(*this),
-							 boost::ref
-								(*reinterpret_cast<WaresMapDisplay::maptype const *>
-									(&building_descr.buildcost())),
-							 std::string(buffer)));
-					enhancebtn->sigmouseout.connect
-						(boost::bind(&Building_Window::hide_costPrev, boost::ref(*this)));
 					capsbuttons->add
 						(enhancebtn,
 						 UI::Box::AlignCenter);
@@ -254,22 +235,16 @@
 		}
 
 		if (m_capscache & Widelands::Building::PCap_Dismantle) {
-			WaresMapDisplay::maptype wares;
+			std::map<Widelands::Ware_Index, uint8_t> wares;
 			Widelands::DismantleSite::count_returned_wares(m_building.descr(), wares);
 			UI::Button * dismantlebtn =
 				new UI::Button
 					(capsbuttons, "dismantle", 0, 0, 34, 34,
 					 g_gr->imgcache().load(PicMod_UI, "pics/but4.png"),
-					 g_gr->imgcache().load(PicMod_Game, pic_dismantle));
+					 g_gr->imgcache().load(PicMod_Game, pic_dismantle),
+					 std::string(_("Dismantle")) + "<br>" + _("Returns:") + "<br>" +
+						 waremap_to_string(owner.tribe(), wares));
 			dismantlebtn->sigclicked.connect(boost::bind(&Building_Window::act_dismantle, boost::ref(*this)));
-			dismantlebtn->sigmousein.connect
-				(boost::bind
-					(&Building_Window::show_costPrev,
-					 boost::ref(*this),
-					 wares,
-					 _("Dismantle")));
-			dismantlebtn->sigmouseout.connect
-				(boost::bind(&Building_Window::hide_costPrev, boost::ref(*this)));
 			capsbuttons->add
 				(dismantlebtn,
 				 UI::Box::AlignCenter);
@@ -434,29 +409,6 @@
 		 igbase().game().map().get_fcoords(m_building.get_position()));
 }
 
-/*
-===============
-Show the enhancecosts / dismanteleresults preview
-===============
-*/
-void Building_Window::show_costPrev(WaresMapDisplay::maptype const & cost, std::string text)
-{
-	m_enhancecostPrev->set_map(&cost);
-	m_prevtext->set_text(text);
-}
-
-/*
-===============
-Hide the Preview
-===============
-*/
-void Building_Window::hide_costPrev()
-{
-	m_enhancecostPrev->set_map(NULL);
-	m_prevtext->set_text("");
-	m_prevtext->set_desired_size(0, 0);
-}
-
 /**
  * Show the building's workarea (if it has one).
  */

=== modified file 'src/wui/buildingwindow.h'
--- src/wui/buildingwindow.h	2012-12-14 20:09:35 +0000
+++ src/wui/buildingwindow.h	2013-01-22 20:15:33 +0000
@@ -67,8 +67,6 @@
 	void act_start_stop();
 	void act_enhance(Widelands::Building_Index);
 	void clicked_goto();
-	void show_costPrev(WaresMapDisplay::maptype const & cost, std::string text);
-	void hide_costPrev();
 
 	void create_ware_queue_panel
 		(UI::Box *, Widelands::Building &, Widelands::WaresQueue *, bool = false);
@@ -83,9 +81,6 @@
 
 	UI::Tab_Panel * m_tabs;
 
-	UI::Textarea * m_prevtext;
-	WaresMapDisplay * m_enhancecostPrev;
-
 	UI::Box * m_capsbuttons; ///< \ref UI::Box that contains capabilities buttons
 	UI::Button * m_toggle_workarea;
 

=== modified file 'src/wui/fieldaction.cc'
--- src/wui/fieldaction.cc	2013-01-16 21:53:42 +0000
+++ src/wui/fieldaction.cc	2013-01-22 20:15:33 +0000
@@ -110,7 +110,10 @@
 		*m_tribe.get_building_descr(Widelands::Building_Index(id));
 	UI::Icon_Grid::add
 		(descr.name(), descr.get_buildicon(),
-		 reinterpret_cast<void *>(id), descr.descname());
+		 reinterpret_cast<void *>(id),
+		 descr.descname() + "<br>" + _("Buildcosts:") + "<br>" +
+			waremap_to_string(m_tribe, descr.buildcost()));
+;
 }
 
 
@@ -224,8 +227,6 @@
 
 	Widelands::FCoords  m_node;
 
-	UI::Box m_box;
-	WaresMapDisplay * m_buildcostPrev;
 	UI::Tab_Panel      m_tabpanel;
 	bool m_fastclick; // if true, put the mouse over first button in first tab
 	uint32_t m_best_tab;
@@ -286,9 +287,7 @@
 	m_map(&ib->egbase().map()),
 	m_overlay_manager(*m_map->get_overlay_manager()),
 	m_node(ib->get_sel_pos().node, &(*m_map)[ib->get_sel_pos().node]),
-	m_box(this, 0, 0, UI::Box::Vertical),
-	m_buildcostPrev(0),
-	m_tabpanel(&m_box, 0, 0, g_gr->imgcache().load(PicMod_UI, "pics/but1.png")),
+	m_tabpanel(this, 0, 0, g_gr->imgcache().load(PicMod_UI, "pics/but1.png")),
 	m_fastclick(true),
 	m_best_tab(0),
 	m_workarea_preview_job_id(Overlay_Manager::Job_Id::Null()),
@@ -297,13 +296,7 @@
 	ib->set_sel_freeze(true);
 
 
-	m_box.add(&m_tabpanel, UI::Box::AlignCenter);
-	if (m_plr) {
-		m_buildcostPrev = new WaresMapDisplay(&m_box, 0, 0, 6, m_plr->tribe(), NULL);
-		m_box.add(m_buildcostPrev, UI::Box::AlignLeft);
-	}
-
-	set_center_panel(&m_box);
+	set_center_panel(&m_tabpanel);
 
 	char filename[] = "pics/workarea0cumulative.png";
 	compile_assert(NUMBER_OF_WORKAREA_PICS <= 9);
@@ -320,7 +313,6 @@
 		m_overlay_manager.remove_overlay(m_workarea_preview_job_id);
 	ibase().set_sel_freeze(false);
 	delete m_attack_box;
-	delete m_buildcostPrev;
 }
 
 
@@ -853,7 +845,6 @@
 void FieldActionWindow::building_icon_mouse_out
 	(Widelands::Building_Index::value_t)
 {
-	m_buildcostPrev->set_map(NULL);
 	if (m_workarea_preview_job_id) {
 		m_overlay_manager.remove_overlay(m_workarea_preview_job_id);
 		m_workarea_preview_job_id = Overlay_Manager::Job_Id::Null();
@@ -864,9 +855,6 @@
 void FieldActionWindow::building_icon_mouse_in
 	(Widelands::Building_Index::value_t const idx)
 {
-	m_buildcostPrev->set_map
-		(&m_plr->tribe().get_building_descr(Widelands::Building_Index(idx))->buildcost());
-
 	if (ibase().m_show_workarea_preview and not m_workarea_preview_job_id) {
 		m_workarea_preview_job_id = m_overlay_manager.get_a_job_id();
 		Widelands::HollowArea<> hollow_area(Widelands::Area<>(m_node, 0), 0);

=== modified file 'src/wui/waresdisplay.cc'
--- src/wui/waresdisplay.cc	2013-01-05 18:52:13 +0000
+++ src/wui/waresdisplay.cc	2013-01-22 20:15:33 +0000
@@ -355,85 +355,27 @@
 }
 
 
-/*
-====================================================
-struct BuildcostDisplay
-====================================================
-*/
-
-WaresMapDisplay::WaresMapDisplay
-	(UI::Panel * const parent,
-	 const int32_t x, const int32_t y,
-	 int32_t columns,
-	 Widelands::Tribe_Descr const & tribe,
-	 maptype const * map)
-	:
-	UI::Panel (parent, x, y, 0, 0), m_tribe(tribe), m_columns(columns)
-{
-	set_map(map);
-}
-
-WaresMapDisplay::~WaresMapDisplay()
-{}
-
-void WaresMapDisplay::set_map(maptype const * map) {
-	m_map = map;
-	if (m_map) {
-		int32_t c = m_map->size();
-		set_desired_size
-			((c < m_columns ? c : m_columns) * (WARE_MENU_PIC_WIDTH + 4) + 1,
-			 ((c / m_columns) + (c % m_columns != 0)) * (WARE_MENU_PIC_HEIGHT + 3 + WARE_MENU_INFO_SIZE) + 1);
-		set_visible(true);
-	} else {
-		set_desired_size(0, 0);
-		set_visible(false);
-	}
-}
-
-void WaresMapDisplay::draw(RenderTarget & dst)
-{
-	if (not m_map)
-		return;
-
-	Point p = Point(2, 2);
-
-	maptype::const_iterator c;
+std::string waremap_to_string
+		(Widelands::Tribe_Descr const & tribe,
+		 std::map<Widelands::Ware_Index, uint8_t> const & map)
+{
+	std::string ret("");
+
+	std::map<Widelands::Ware_Index, uint8_t>::const_iterator c;
 
 	Widelands::Tribe_Descr::WaresOrder::iterator i;
 	std::vector<Widelands::Ware_Index>::iterator j;
-	Widelands::Tribe_Descr::WaresOrder order = m_tribe.wares_order();
+	Widelands::Tribe_Descr::WaresOrder order = tribe.wares_order();
 
 	for (i = order.begin(); i != order.end(); i++)
 		for (j = i->begin(); j != i->end(); ++j)
-			if ((c = m_map->find(*j)) != m_map->end()) {
-				//  draw a background
-				const IPicture* pic = g_gr->imgcache().load (PicMod_Game, "pics/ware_list_bg.png");
-				uint32_t w = pic->get_w();
-
-				dst.blit(p, pic);
-
-				const Point pos = p + Point((w - WARE_MENU_PIC_WIDTH) / 2, 1);
-				// Draw it
-				dst.blit
-				(pos,
-				 m_tribe.get_ware_descr(c->first)->icon());
-				dst.fill_rect
-				(Rect(pos + Point(0, WARE_MENU_PIC_HEIGHT), WARE_MENU_PIC_WIDTH, WARE_MENU_INFO_SIZE),
-				 RGBColor(0, 0, 0));
-
-				UI::g_fh->draw_text
-				(dst, UI::TextStyle::ui_ultrasmall(),
-				 p + Point(WARE_MENU_PIC_WIDTH, WARE_MENU_PIC_HEIGHT - 4),
-				 boost::lexical_cast<std::string, uint32_t>(c->second),
-				 UI::Align_Right);
-
-				p.x += (WARE_MENU_PIC_WIDTH + 4);
-				if (p.x >= (m_columns * (WARE_MENU_PIC_WIDTH + 4))) {
-					p.x = 2;
-					p.y += (WARE_MENU_PIC_HEIGHT + 3 + WARE_MENU_INFO_SIZE);
-				}
+			if ((c = map.find(*j)) != map.end()) {
+				ret += "<sub width=30 padding=2><p align=center>"
+						 "<sub width=26 background=454545><p align=center><img src=\""
+						+ tribe.get_ware_descr(c->first)->icon_name()
+						+ "\"></p></sub><sub width=26 background=010101><p><font size=9>"
+						+ boost::lexical_cast<std::string>(static_cast<int32_t>(c->second))
+						+ "</font></p></sub></p></sub>";
 			}
+	return ret;
 }
-
-
-

=== modified file 'src/wui/waresdisplay.h'
--- src/wui/waresdisplay.h	2012-12-16 21:02:00 +0000
+++ src/wui/waresdisplay.h	2013-01-22 20:15:33 +0000
@@ -45,7 +45,8 @@
  *
  * For practical purposes, use one of the derived classes, e.g. @ref WaresDisplay.
  */
-struct AbstractWaresDisplay : public UI::Panel {
+class AbstractWaresDisplay : public UI::Panel {
+public:
 	AbstractWaresDisplay
 		(UI::Panel * const parent,
 		 int32_t const x, int32_t const y,
@@ -112,12 +113,13 @@
 };
 
 /*
-struct WaresDisplay
+class WaresDisplay
 ------------------
 Panel that displays the contents of many WareLists. The ware_lists
 must be valid while they are registered with this class.
 */
-struct WaresDisplay : public AbstractWaresDisplay {
+class WaresDisplay : public AbstractWaresDisplay {
+public:
 	WaresDisplay
 		(UI::Panel * const parent,
 		 int32_t const x, int32_t const y,
@@ -139,32 +141,9 @@
 	std::vector<boost::signals::connection> connections_;
 };
 
-
-/**
- * Displays the build costs of a given building
- */
-
-struct WaresMapDisplay : public UI::Panel {
-	typedef std::map<Widelands::Ware_Index, uint8_t> maptype;
-
-	WaresMapDisplay
-		(UI::Panel * const parent,
-		 int32_t const x, int32_t const y,
-		 int32_t columns,
-		 Widelands::Tribe_Descr const & tribe,
-		 maptype const * map = NULL);
-
-	virtual ~WaresMapDisplay();
-
-	void set_map(maptype const * map);
-
-private:
-	virtual void draw(RenderTarget &);
-
-private:
-	Widelands::Tribe_Descr const & m_tribe;
-	maptype const * m_map;
-	int32_t m_columns;
-};
+// Convert a ware:number map to an rt string.
+std::string waremap_to_string
+		(Widelands::Tribe_Descr const & tribe,
+		 std::map<Widelands::Ware_Index, uint8_t> const & map);
 
 #endif