Merge lp:~gamag/widelands/buildcostTooltip into lp:widelands
- buildcostTooltip
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 6494 |
Proposed branch: | lp:~gamag/widelands/buildcostTooltip |
Merge into: | lp:widelands |
Diff against target: |
1046 lines (+155/-309) 8 files modified
src/logic/item_ware_descr.h (+1/-0) src/ui_basic/icongrid.cc (+17/-26) src/ui_basic/icongrid.h (+1/-2) src/wui/buildingwindow.cc (+25/-73) src/wui/buildingwindow.h (+0/-5) src/wui/fieldaction.cc (+63/-75) src/wui/waresdisplay.cc (+27/-85) src/wui/waresdisplay.h (+21/-43) |
To merge this branch: | bzr merge lp:~gamag/widelands/buildcostTooltip |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
SirVer | Needs Information | ||
Gabriel Margiani | Needs Resubmitting | ||
Review via email: mp+144383@code.launchpad.net |
Commit message
Description of the change
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]?)
Gabriel Margiani (gamag) wrote : | # |
Moved some const's around and fixed other things.
>I feel the text can be a few pts smaller in the preview.
I'm not sure if I did wath you mean... I like it as it is now.
>The think you mention with the black sounds like a bug. Can you provide a minimal example for >reproduction?
It's not really minimal, but a changed the background of the numbers in preview form 010101to 000000.
Hope I didn't forget something..
SirVer (sirver) wrote : | # |
Great! I am completely fine to merge it as is now. There's only one minor point I missed the last time:
- passing const bool (int, int32_t...) into a function makes no sense - in fact, it makes little sense to pass anything by value as const. It is not your code, but could you fix this whenever you see it?
Please let me know if you want to fix this or not. If not, I will merge the change as is. If yes - Year!
Gabriel Margiani (gamag) wrote : | # |
I think it's fixed now.
Gabriel Margiani (gamag) wrote : | # |
Only the numbers in preview have no black background....
SirVer (sirver) wrote : | # |
Cool. I merged this now. Thanks for working on this :).
I found the bug why black was considered transparent and fixed it after I merged your changes - so if you feel like full black is better, just go ahead and change it to black now.
Gabriel Margiani (gamag) wrote : | # |
I changed it already after your first review. Thanks.
Preview Diff
1 | === modified file 'src/logic/item_ware_descr.h' |
2 | --- src/logic/item_ware_descr.h 2012-11-24 16:22:10 +0000 |
3 | +++ src/logic/item_ware_descr.h 2013-01-23 21:09:25 +0000 |
4 | @@ -69,6 +69,7 @@ |
5 | |
6 | /// \return index to ware's icon inside picture stack |
7 | const IPicture* icon() const throw () {return m_icon;} |
8 | + std::string icon_name() const throw () {return m_icon_fname;} |
9 | |
10 | /// \return ware's localized descriptive text |
11 | std::string const & helptext() const throw () {return m_helptext;} |
12 | |
13 | === modified file 'src/ui_basic/icongrid.cc' |
14 | --- src/ui_basic/icongrid.cc 2012-12-14 20:09:35 +0000 |
15 | +++ src/ui_basic/icongrid.cc 2013-01-23 21:09:25 +0000 |
16 | @@ -33,34 +33,30 @@ |
17 | struct IconGridButton : public Button { |
18 | IconGridButton |
19 | (Icon_Grid & parent, |
20 | - std::string const & name, |
21 | - const int32_t x, const int32_t y, const uint32_t w, const uint32_t h, |
22 | + const std::string & name, |
23 | + int32_t x, int32_t y, uint32_t w, uint32_t h, |
24 | const IPicture* background_pictute_id, |
25 | const IPicture* foreground_picture_id, |
26 | - const uint32_t callback_argument_id, |
27 | - Textarea & ta, std::string const & descr) |
28 | + uint32_t callback_argument_id, |
29 | + const std::string & tooltip_text) |
30 | : |
31 | Button |
32 | (&parent, name, x, y, w, h, background_pictute_id, |
33 | foreground_picture_id, |
34 | - "", true, true), |
35 | - m_icongrid(parent), m_ta(ta), m_descr(descr), |
36 | + tooltip_text, true, true), |
37 | + m_icongrid(parent), |
38 | _callback_argument_id(callback_argument_id) |
39 | {} |
40 | |
41 | private: |
42 | Icon_Grid & m_icongrid; |
43 | - Textarea & m_ta; |
44 | - std::string m_descr; |
45 | const uint32_t _callback_argument_id; |
46 | |
47 | - void handle_mousein(bool const inside) { |
48 | + void handle_mousein(bool inside) { |
49 | if (inside) { |
50 | m_icongrid.mousein(_callback_argument_id); |
51 | - m_ta.set_text(m_descr); |
52 | } else { |
53 | m_icongrid.mouseout(_callback_argument_id); |
54 | - m_ta.set_text(""); |
55 | } |
56 | Button::handle_mousein(inside); |
57 | } |
58 | @@ -71,14 +67,13 @@ |
59 | */ |
60 | Icon_Grid::Icon_Grid |
61 | (Panel * const parent, |
62 | - int32_t const x, int32_t const y, int32_t const cellw, int32_t const cellh, |
63 | - int32_t const cols) |
64 | + int32_t x, int32_t y, int32_t cellw, int32_t cellh, |
65 | + int32_t cols) |
66 | : |
67 | Panel (parent, x, y, 0, 0), |
68 | m_columns (cols), |
69 | m_cell_width (cellw), |
70 | - m_cell_height (cellh), |
71 | - m_ta (this, 0, 0, 0, g_fh->get_fontheight(UI_FONT_SMALL) + 2) |
72 | + m_cell_height (cellh) |
73 | {} |
74 | |
75 | |
76 | @@ -87,8 +82,8 @@ |
77 | * Returns the index of the newly added icon. |
78 | */ |
79 | int32_t Icon_Grid::add |
80 | - (std::string const & name, const IPicture* pic, |
81 | - void * const data, std::string const & descr) |
82 | + (const std::string & name, const IPicture* pic, |
83 | + void * data, const std::string & tooltip_text) |
84 | { |
85 | Item it; |
86 | |
87 | @@ -97,17 +92,13 @@ |
88 | m_items.push_back(it); |
89 | |
90 | // resize |
91 | - int32_t const rows = (m_items.size() + m_columns - 1) / m_columns; |
92 | + const int32_t rows = (m_items.size() + m_columns - 1) / m_columns; |
93 | |
94 | if (rows <= 1) { |
95 | - set_desired_size(m_cell_width * m_columns, m_cell_height + m_ta.get_h()); |
96 | - m_ta.set_size(get_inner_w(), m_ta.get_h()); |
97 | - m_ta.set_pos(Point(0, m_cell_height)); |
98 | + set_desired_size(m_cell_width * m_columns, m_cell_height); |
99 | } else { |
100 | set_desired_size |
101 | - (m_cell_width * m_columns, m_cell_height * rows + m_ta.get_h()); |
102 | - m_ta.set_size(get_inner_w(), m_ta.get_h()); |
103 | - m_ta.set_pos(Point(0, m_cell_height * rows)); |
104 | + (m_cell_width * m_columns, m_cell_height * rows); |
105 | } |
106 | |
107 | uint32_t idx = m_items.size() - 1; |
108 | @@ -118,7 +109,7 @@ |
109 | (*this, name, |
110 | x, y, m_cell_width, m_cell_height, |
111 | NULL, pic, |
112 | - idx, m_ta, descr); |
113 | + idx, tooltip_text); |
114 | btn->sigclicked.connect(boost::bind(&Icon_Grid::clicked_button, this, idx)); |
115 | |
116 | return idx; |
117 | @@ -132,7 +123,7 @@ |
118 | /** |
119 | * Returns the user-defined data of the icon with the given index. |
120 | */ |
121 | -void * Icon_Grid::get_data(int32_t const idx) |
122 | +void * Icon_Grid::get_data(int32_t idx) |
123 | { |
124 | assert(static_cast<uint32_t>(idx) < m_items.size()); |
125 | |
126 | |
127 | === modified file 'src/ui_basic/icongrid.h' |
128 | --- src/ui_basic/icongrid.h 2012-12-14 20:09:35 +0000 |
129 | +++ src/ui_basic/icongrid.h 2013-01-23 21:09:25 +0000 |
130 | @@ -49,7 +49,7 @@ |
131 | (std::string const & name, |
132 | const IPicture* pic, |
133 | void * data, |
134 | - std::string const & descr = std::string()); |
135 | + const std::string & tooltip_text = ""); |
136 | void * get_data(int32_t idx); |
137 | |
138 | private: |
139 | @@ -64,7 +64,6 @@ |
140 | int32_t m_cell_width; ///< size of one cell |
141 | int32_t m_cell_height; |
142 | |
143 | - Textarea m_ta; |
144 | std::vector<Item> m_items; |
145 | }; |
146 | |
147 | |
148 | === modified file 'src/wui/buildingwindow.cc' |
149 | --- src/wui/buildingwindow.cc 2012-12-30 03:24:39 +0000 |
150 | +++ src/wui/buildingwindow.cc 2013-01-23 21:09:25 +0000 |
151 | @@ -35,9 +35,9 @@ |
152 | |
153 | #include "buildingwindow.h" |
154 | |
155 | -static char const * pic_bulldoze = "pics/menu_bld_bulldoze.png"; |
156 | -static char const * pic_dismantle = "pics/menu_bld_dismantle.png"; |
157 | -static char const * pic_debug = "pics/menu_debug.png"; |
158 | +static const char * pic_bulldoze = "pics/menu_bld_bulldoze.png"; |
159 | +static const char * pic_dismantle = "pics/menu_bld_dismantle.png"; |
160 | +static const char * pic_debug = "pics/menu_debug.png"; |
161 | |
162 | |
163 | Building_Window::Building_Window |
164 | @@ -72,17 +72,6 @@ |
165 | // actually create buttons on the first call to think(), |
166 | // so that overriding create_capsbuttons() works |
167 | |
168 | - UI::Box * prevbox = new UI::Box(vbox, 0, 0, UI::Box::Vertical); |
169 | - |
170 | - m_prevtext = new UI::Textarea(prevbox); |
171 | - m_prevtext->set_desired_size(0, 0); |
172 | - prevbox->add(m_prevtext, UI::Box::AlignLeft); |
173 | - |
174 | - m_enhancecostPrev = new WaresMapDisplay(prevbox, 0, 0, 10, m_building.tribe(), NULL); |
175 | - prevbox->add(m_enhancecostPrev, UI::Box::AlignLeft); |
176 | - |
177 | - vbox->add(prevbox, UI::Box::AlignLeft); |
178 | - |
179 | set_center_panel(vbox); |
180 | set_think(true); |
181 | |
182 | @@ -167,16 +156,16 @@ |
183 | m_capscache = building().get_playercaps(); |
184 | m_capscache_player_number = igbase().player_number(); |
185 | |
186 | - Widelands::Player const & owner = building().owner(); |
187 | - Widelands::Player_Number const owner_number = owner.player_number(); |
188 | - bool const can_see = igbase().can_see(owner_number); |
189 | - bool const can_act = igbase().can_act(owner_number); |
190 | + const Widelands::Player & owner = building().owner(); |
191 | + const Widelands::Player_Number owner_number = owner.player_number(); |
192 | + const bool can_see = igbase().can_see(owner_number); |
193 | + const bool can_act = igbase().can_act(owner_number); |
194 | |
195 | bool requires_destruction_separator = false; |
196 | if (can_act) { |
197 | - if (upcast(Widelands::ProductionSite const, productionsite, &m_building)) |
198 | - if (not dynamic_cast<Widelands::MilitarySite const *>(productionsite)) { |
199 | - bool const is_stopped = productionsite->is_stopped(); |
200 | + if (upcast(const Widelands::ProductionSite, productionsite, &m_building)) |
201 | + if (not dynamic_cast<const Widelands::MilitarySite *>(productionsite)) { |
202 | + const bool is_stopped = productionsite->is_stopped(); |
203 | UI::Button * stopbtn = |
204 | new UI::Button |
205 | (capsbuttons, is_stopped ? "continue" : "stop", 0, 0, 34, 34, |
206 | @@ -199,12 +188,12 @@ |
207 | } |
208 | |
209 | if (m_capscache & Widelands::Building::PCap_Enhancable) { |
210 | - std::set<Widelands::Building_Index> const & enhancements = |
211 | + const std::set<Widelands::Building_Index> & enhancements = |
212 | m_building.enhancements(); |
213 | - Widelands::Tribe_Descr const & tribe = owner.tribe(); |
214 | + const Widelands::Tribe_Descr & tribe = owner.tribe(); |
215 | container_iterate_const(std::set<Widelands::Building_Index>, enhancements, i) |
216 | if (owner.is_building_type_allowed(*i.current)) { |
217 | - Widelands::Building_Descr const & building_descr = |
218 | + const Widelands::Building_Descr & building_descr = |
219 | *tribe.get_building_descr(*i.current); |
220 | char buffer[128]; |
221 | snprintf |
222 | @@ -214,22 +203,14 @@ |
223 | new UI::Button |
224 | (capsbuttons, "enhance", 0, 0, 34, 34, |
225 | g_gr->imgcache().load(PicMod_UI, "pics/but4.png"), |
226 | - building_descr.get_buildicon()); // button id = building id) |
227 | + building_descr.get_buildicon(), |
228 | + std::string(buffer) + "<br><font size=11>" + _("Construction costs:") + "</font><br>" + |
229 | + waremap_to_richtext(tribe, building_descr.buildcost())); // button id = building id |
230 | enhancebtn->sigclicked.connect |
231 | (boost::bind |
232 | (&Building_Window::act_enhance, |
233 | boost::ref(*this), |
234 | boost::ref(*i.current))); |
235 | - enhancebtn->sigmousein.connect |
236 | - (boost::bind |
237 | - (&Building_Window::show_costPrev, |
238 | - boost::ref(*this), |
239 | - boost::ref |
240 | - (*reinterpret_cast<WaresMapDisplay::maptype const *> |
241 | - (&building_descr.buildcost())), |
242 | - std::string(buffer))); |
243 | - enhancebtn->sigmouseout.connect |
244 | - (boost::bind(&Building_Window::hide_costPrev, boost::ref(*this))); |
245 | capsbuttons->add |
246 | (enhancebtn, |
247 | UI::Box::AlignCenter); |
248 | @@ -254,22 +235,16 @@ |
249 | } |
250 | |
251 | if (m_capscache & Widelands::Building::PCap_Dismantle) { |
252 | - WaresMapDisplay::maptype wares; |
253 | + std::map<Widelands::Ware_Index, uint8_t> wares; |
254 | Widelands::DismantleSite::count_returned_wares(m_building.descr(), wares); |
255 | UI::Button * dismantlebtn = |
256 | new UI::Button |
257 | (capsbuttons, "dismantle", 0, 0, 34, 34, |
258 | g_gr->imgcache().load(PicMod_UI, "pics/but4.png"), |
259 | - g_gr->imgcache().load(PicMod_Game, pic_dismantle)); |
260 | + g_gr->imgcache().load(PicMod_Game, pic_dismantle), |
261 | + std::string(_("Dismantle")) + "<br><font size=11>" + _("Returns:") + "</font><br>" + |
262 | + waremap_to_richtext(owner.tribe(), wares)); |
263 | dismantlebtn->sigclicked.connect(boost::bind(&Building_Window::act_dismantle, boost::ref(*this))); |
264 | - dismantlebtn->sigmousein.connect |
265 | - (boost::bind |
266 | - (&Building_Window::show_costPrev, |
267 | - boost::ref(*this), |
268 | - wares, |
269 | - _("Dismantle"))); |
270 | - dismantlebtn->sigmouseout.connect |
271 | - (boost::bind(&Building_Window::hide_costPrev, boost::ref(*this))); |
272 | capsbuttons->add |
273 | (dismantlebtn, |
274 | UI::Box::AlignCenter); |
275 | @@ -397,7 +372,7 @@ |
276 | } |
277 | |
278 | void Building_Window::act_start_stop() { |
279 | - if (dynamic_cast<Widelands::ProductionSite const *>(&m_building)) |
280 | + if (dynamic_cast<const Widelands::ProductionSite *>(&m_building)) |
281 | igbase().game().send_player_start_stop_building (m_building); |
282 | |
283 | die(); |
284 | @@ -408,7 +383,7 @@ |
285 | Callback for enhancement request |
286 | =============== |
287 | */ |
288 | -void Building_Window::act_enhance(Widelands::Building_Index const id) |
289 | +void Building_Window::act_enhance(Widelands::Building_Index id) |
290 | { |
291 | if (get_key_state(SDLK_LCTRL) or get_key_state(SDLK_RCTRL)) { |
292 | if (m_building.get_playercaps() & Widelands::Building::PCap_Enhancable) |
293 | @@ -434,29 +409,6 @@ |
294 | igbase().game().map().get_fcoords(m_building.get_position())); |
295 | } |
296 | |
297 | -/* |
298 | -=============== |
299 | -Show the enhancecosts / dismanteleresults preview |
300 | -=============== |
301 | -*/ |
302 | -void Building_Window::show_costPrev(WaresMapDisplay::maptype const & cost, std::string text) |
303 | -{ |
304 | - m_enhancecostPrev->set_map(&cost); |
305 | - m_prevtext->set_text(text); |
306 | -} |
307 | - |
308 | -/* |
309 | -=============== |
310 | -Hide the Preview |
311 | -=============== |
312 | -*/ |
313 | -void Building_Window::hide_costPrev() |
314 | -{ |
315 | - m_enhancecostPrev->set_map(NULL); |
316 | - m_prevtext->set_text(""); |
317 | - m_prevtext->set_desired_size(0, 0); |
318 | -} |
319 | - |
320 | /** |
321 | * Show the building's workarea (if it has one). |
322 | */ |
323 | @@ -465,12 +417,12 @@ |
324 | if (m_workarea_job_id) |
325 | return; // already shown, nothing to be done |
326 | |
327 | - Workarea_Info const & workarea_info = m_building.descr().m_workarea_info; |
328 | + const Workarea_Info & workarea_info = m_building.descr().m_workarea_info; |
329 | if (workarea_info.size() == 0) |
330 | return; // building has no workarea |
331 | |
332 | Widelands::Map & map = |
333 | - ref_cast<Interactive_GameBase const, UI::Panel>(*get_parent()).egbase() |
334 | + ref_cast<const Interactive_GameBase, UI::Panel>(*get_parent()).egbase() |
335 | .map(); |
336 | Overlay_Manager & overlay_manager = map.overlay_manager(); |
337 | m_workarea_job_id = overlay_manager.get_a_job_id(); |
338 | @@ -508,7 +460,7 @@ |
339 | { |
340 | if (m_workarea_job_id) { |
341 | Widelands::Map & map = |
342 | - ref_cast<Interactive_GameBase const, UI::Panel>(*get_parent()).egbase() |
343 | + ref_cast<const Interactive_GameBase, UI::Panel>(*get_parent()).egbase() |
344 | .map(); |
345 | Overlay_Manager & overlay_manager = map.overlay_manager(); |
346 | overlay_manager.remove_overlay(m_workarea_job_id); |
347 | |
348 | === modified file 'src/wui/buildingwindow.h' |
349 | --- src/wui/buildingwindow.h 2012-12-14 20:09:35 +0000 |
350 | +++ src/wui/buildingwindow.h 2013-01-23 21:09:25 +0000 |
351 | @@ -67,8 +67,6 @@ |
352 | void act_start_stop(); |
353 | void act_enhance(Widelands::Building_Index); |
354 | void clicked_goto(); |
355 | - void show_costPrev(WaresMapDisplay::maptype const & cost, std::string text); |
356 | - void hide_costPrev(); |
357 | |
358 | void create_ware_queue_panel |
359 | (UI::Box *, Widelands::Building &, Widelands::WaresQueue *, bool = false); |
360 | @@ -83,9 +81,6 @@ |
361 | |
362 | UI::Tab_Panel * m_tabs; |
363 | |
364 | - UI::Textarea * m_prevtext; |
365 | - WaresMapDisplay * m_enhancecostPrev; |
366 | - |
367 | UI::Box * m_capsbuttons; ///< \ref UI::Box that contains capabilities buttons |
368 | UI::Button * m_toggle_workarea; |
369 | |
370 | |
371 | === modified file 'src/wui/fieldaction.cc' |
372 | --- src/wui/fieldaction.cc 2013-01-16 21:53:42 +0000 |
373 | +++ src/wui/fieldaction.cc 2013-01-23 21:09:25 +0000 |
374 | @@ -63,8 +63,8 @@ |
375 | struct BuildGrid : public UI::Icon_Grid { |
376 | BuildGrid |
377 | (UI::Panel * parent, |
378 | - Widelands::Tribe_Descr const & tribe, |
379 | - const int32_t x, const int32_t y, |
380 | + const Widelands::Tribe_Descr & tribe, |
381 | + int32_t x, int32_t y, |
382 | int32_t cols); |
383 | |
384 | boost::signal<void (Widelands::Building_Index::value_t)> buildclicked; |
385 | @@ -79,14 +79,14 @@ |
386 | void mouseinslot(int32_t idx); |
387 | |
388 | private: |
389 | - Widelands::Tribe_Descr const & m_tribe; |
390 | + const Widelands::Tribe_Descr & m_tribe; |
391 | }; |
392 | |
393 | |
394 | BuildGrid::BuildGrid |
395 | (UI::Panel * parent, |
396 | - Widelands::Tribe_Descr const & tribe, |
397 | - int32_t const x, int32_t const y, |
398 | + const Widelands::Tribe_Descr & tribe, |
399 | + int32_t x, int32_t y, |
400 | int32_t cols) |
401 | : |
402 | UI::Icon_Grid |
403 | @@ -104,13 +104,16 @@ |
404 | Add a new building to the list of buildable buildings |
405 | =============== |
406 | */ |
407 | -void BuildGrid::add(Widelands::Building_Index::value_t const id) |
408 | +void BuildGrid::add(Widelands::Building_Index::value_t id) |
409 | { |
410 | - Widelands::Building_Descr const & descr = |
411 | + const Widelands::Building_Descr & descr = |
412 | *m_tribe.get_building_descr(Widelands::Building_Index(id)); |
413 | UI::Icon_Grid::add |
414 | (descr.name(), descr.get_buildicon(), |
415 | - reinterpret_cast<void *>(id), descr.descname()); |
416 | + reinterpret_cast<void *>(id), |
417 | + descr.descname() + "<br><font size=11>" + _("Construction costs:") + "</font><br>" + |
418 | + waremap_to_richtext(m_tribe, descr.buildcost())); |
419 | +; |
420 | } |
421 | |
422 | |
423 | @@ -122,7 +125,7 @@ |
424 | belongs to and trigger signal buildclicked. |
425 | =============== |
426 | */ |
427 | -void BuildGrid::clickslot(int32_t const idx) |
428 | +void BuildGrid::clickslot(int32_t idx) |
429 | { |
430 | buildclicked(static_cast<int32_t>(reinterpret_cast<intptr_t>(get_data(idx)))); |
431 | } |
432 | @@ -208,13 +211,13 @@ |
433 | (const std::string & name, |
434 | const char * picname, |
435 | UI::Panel * panel, |
436 | - const std::string & tooltip_text = std::string()); |
437 | + const std::string & tooltip_text = ""); |
438 | UI::Button & add_button |
439 | (UI::Box *, |
440 | - char const * name, |
441 | - char const * picname, |
442 | + const char * name, |
443 | + const char * picname, |
444 | void (FieldActionWindow::*fn)(), |
445 | - std::string const & tooltip_text, |
446 | + const std::string & tooltip_text, |
447 | bool repeating = false); |
448 | void okdialog(); |
449 | |
450 | @@ -224,8 +227,6 @@ |
451 | |
452 | Widelands::FCoords m_node; |
453 | |
454 | - UI::Box m_box; |
455 | - WaresMapDisplay * m_buildcostPrev; |
456 | UI::Tab_Panel m_tabpanel; |
457 | bool m_fastclick; // if true, put the mouse over first button in first tab |
458 | uint32_t m_best_tab; |
459 | @@ -236,10 +237,10 @@ |
460 | AttackBox * m_attack_box; |
461 | }; |
462 | |
463 | -static char const * const pic_tab_buildroad = "pics/menu_tab_buildroad.png"; |
464 | -static char const * const pic_tab_watch = "pics/menu_tab_watch.png"; |
465 | -static char const * const pic_tab_military = "pics/menu_tab_military.png"; |
466 | -static char const * const pic_tab_buildhouse[] = { |
467 | +static const char * const pic_tab_buildroad = "pics/menu_tab_buildroad.png"; |
468 | +static const char * const pic_tab_watch = "pics/menu_tab_watch.png"; |
469 | +static const char * const pic_tab_military = "pics/menu_tab_military.png"; |
470 | +static const char * const pic_tab_buildhouse[] = { |
471 | "pics/menu_tab_buildsmall.png", |
472 | "pics/menu_tab_buildmedium.png", |
473 | "pics/menu_tab_buildbig.png", |
474 | @@ -254,21 +255,21 @@ |
475 | static const std::string name_tab_build[] = {"small", "medium", "big", "port"}; |
476 | |
477 | |
478 | -static char const * const pic_tab_buildmine = "pics/menu_tab_buildmine.png"; |
479 | - |
480 | -static char const * const pic_buildroad = "pics/menu_build_way.png"; |
481 | -static char const * const pic_remroad = "pics/menu_rem_way.png"; |
482 | -static char const * const pic_buildflag = "pics/menu_build_flag.png"; |
483 | -static char const * const pic_ripflag = "pics/menu_rip_flag.png"; |
484 | -static char const * const pic_watchfield = "pics/menu_watch_field.png"; |
485 | -static char const * const pic_showcensus = "pics/menu_show_census.png"; |
486 | -static char const * const pic_showstatistics = "pics/menu_show_statistics.png"; |
487 | -static char const * const pic_debug = "pics/menu_debug.png"; |
488 | -static char const * const pic_abort = "pics/menu_abort.png"; |
489 | -static char const * const pic_geologist = "pics/menu_geologist.png"; |
490 | - |
491 | -static char const * const pic_tab_attack = "pics/menu_tab_attack.png"; |
492 | -static char const * const pic_attack = "pics/menu_attack.png"; |
493 | +static const char * const pic_tab_buildmine = "pics/menu_tab_buildmine.png"; |
494 | + |
495 | +static const char * const pic_buildroad = "pics/menu_build_way.png"; |
496 | +static const char * const pic_remroad = "pics/menu_rem_way.png"; |
497 | +static const char * const pic_buildflag = "pics/menu_build_flag.png"; |
498 | +static const char * const pic_ripflag = "pics/menu_rip_flag.png"; |
499 | +static const char * const pic_watchfield = "pics/menu_watch_field.png"; |
500 | +static const char * const pic_showcensus = "pics/menu_show_census.png"; |
501 | +static const char * const pic_showstatistics = "pics/menu_show_statistics.png"; |
502 | +static const char * const pic_debug = "pics/menu_debug.png"; |
503 | +static const char * const pic_abort = "pics/menu_abort.png"; |
504 | +static const char * const pic_geologist = "pics/menu_geologist.png"; |
505 | + |
506 | +static const char * const pic_tab_attack = "pics/menu_tab_attack.png"; |
507 | +static const char * const pic_attack = "pics/menu_attack.png"; |
508 | |
509 | |
510 | /* |
511 | @@ -286,9 +287,7 @@ |
512 | m_map(&ib->egbase().map()), |
513 | m_overlay_manager(*m_map->get_overlay_manager()), |
514 | m_node(ib->get_sel_pos().node, &(*m_map)[ib->get_sel_pos().node]), |
515 | - m_box(this, 0, 0, UI::Box::Vertical), |
516 | - m_buildcostPrev(0), |
517 | - m_tabpanel(&m_box, 0, 0, g_gr->imgcache().load(PicMod_UI, "pics/but1.png")), |
518 | + m_tabpanel(this, 0, 0, g_gr->imgcache().load(PicMod_UI, "pics/but1.png")), |
519 | m_fastclick(true), |
520 | m_best_tab(0), |
521 | m_workarea_preview_job_id(Overlay_Manager::Job_Id::Null()), |
522 | @@ -297,13 +296,7 @@ |
523 | ib->set_sel_freeze(true); |
524 | |
525 | |
526 | - m_box.add(&m_tabpanel, UI::Box::AlignCenter); |
527 | - if (m_plr) { |
528 | - m_buildcostPrev = new WaresMapDisplay(&m_box, 0, 0, 6, m_plr->tribe(), NULL); |
529 | - m_box.add(m_buildcostPrev, UI::Box::AlignLeft); |
530 | - } |
531 | - |
532 | - set_center_panel(&m_box); |
533 | + set_center_panel(&m_tabpanel); |
534 | |
535 | char filename[] = "pics/workarea0cumulative.png"; |
536 | compile_assert(NUMBER_OF_WORKAREA_PICS <= 9); |
537 | @@ -320,7 +313,6 @@ |
538 | m_overlay_manager.remove_overlay(m_workarea_preview_job_id); |
539 | ibase().set_sel_freeze(false); |
540 | delete m_attack_box; |
541 | - delete m_buildcostPrev; |
542 | } |
543 | |
544 | |
545 | @@ -366,11 +358,11 @@ |
546 | // Add road-building actions |
547 | upcast(Interactive_GameBase, igbase, &ibase()); |
548 | |
549 | - Widelands::Player_Number const owner = m_node.field->get_owned_by(); |
550 | + const Widelands::Player_Number owner = m_node.field->get_owned_by(); |
551 | |
552 | if (not igbase or igbase->can_see(owner)) { |
553 | Widelands::BaseImmovable * const imm = m_map->get_immovable(m_node); |
554 | - bool const can_act = igbase ? igbase->can_act(owner) : true; |
555 | + const bool can_act = igbase ? igbase->can_act(owner) : true; |
556 | |
557 | // The box with road-building buttons |
558 | buildbox = new UI::Box(&m_tabpanel, 0, 0, UI::Box::Horizontal); |
559 | @@ -411,7 +403,7 @@ |
560 | _("Send geologist to explore site")); |
561 | } |
562 | } else { |
563 | - int32_t const buildcaps = m_plr ? m_plr->get_buildcaps(m_node) : 0; |
564 | + const int32_t buildcaps = m_plr ? m_plr->get_buildcaps(m_node) : 0; |
565 | |
566 | // Add house building |
567 | if |
568 | @@ -428,7 +420,7 @@ |
569 | &FieldActionWindow::act_buildflag, |
570 | _("Put a flag")); |
571 | |
572 | - if (can_act && dynamic_cast<Widelands::Road const *>(imm)) |
573 | + if (can_act && dynamic_cast<const Widelands::Road *>(imm)) |
574 | add_button |
575 | (buildbox, "destroy_road", |
576 | pic_remroad, |
577 | @@ -446,7 +438,7 @@ |
578 | |
579 | // Watch actions, only when game (no use in editor) same for statistics. |
580 | // census is ok |
581 | - if (dynamic_cast<Game const *>(&ibase().egbase())) { |
582 | + if (dynamic_cast<const Game *>(&ibase().egbase())) { |
583 | add_button |
584 | (&watchbox, "watch", |
585 | pic_watchfield, |
586 | @@ -526,29 +518,29 @@ |
587 | Add buttons for house building. |
588 | =============== |
589 | */ |
590 | -void FieldActionWindow::add_buttons_build(int32_t const buildcaps) |
591 | +void FieldActionWindow::add_buttons_build(int32_t buildcaps) |
592 | { |
593 | if (not m_plr) |
594 | return; |
595 | BuildGrid * bbg_house[4] = {0, 0, 0, 0}; |
596 | BuildGrid * bbg_mine = 0; |
597 | |
598 | - Widelands::Tribe_Descr const & tribe = m_plr->tribe(); |
599 | + const Widelands::Tribe_Descr & tribe = m_plr->tribe(); |
600 | |
601 | m_fastclick = false; |
602 | |
603 | - Widelands::Building_Index const nr_buildings = tribe.get_nrbuildings(); |
604 | + const Widelands::Building_Index nr_buildings = tribe.get_nrbuildings(); |
605 | for |
606 | (Widelands::Building_Index id = Widelands::Building_Index::First(); |
607 | id < nr_buildings; |
608 | ++id) |
609 | { |
610 | - Widelands::Building_Descr const & descr = *tribe.get_building_descr(id); |
611 | + const Widelands::Building_Descr & descr = *tribe.get_building_descr(id); |
612 | BuildGrid * * ppgrid; |
613 | |
614 | // Some building types cannot be built (i.e. construction site) and not |
615 | // allowed buildings. |
616 | - if (dynamic_cast<Game const *>(&ibase().egbase())) { |
617 | + if (dynamic_cast<const Game *>(&ibase().egbase())) { |
618 | if (!descr.is_buildable() || !m_plr->is_building_type_allowed(id)) |
619 | continue; |
620 | } else if (!descr.is_buildable() && !descr.is_enhanced()) |
621 | @@ -610,7 +602,7 @@ |
622 | Buttons used during road building: Set flag here and Abort |
623 | =============== |
624 | */ |
625 | -void FieldActionWindow::add_buttons_road(bool const flag) |
626 | +void FieldActionWindow::add_buttons_road(bool flag) |
627 | { |
628 | UI::Box & buildbox = *new UI::Box(&m_tabpanel, 0, 0, UI::Box::Horizontal); |
629 | |
630 | @@ -634,8 +626,8 @@ |
631 | =============== |
632 | */ |
633 | uint32_t FieldActionWindow::add_tab |
634 | - (std::string const & name, char const * picname, |
635 | - UI::Panel * panel, std::string const & tooltip_text) |
636 | + (const std::string & name, const char * picname, |
637 | + UI::Panel * panel, const std::string & tooltip_text) |
638 | { |
639 | return |
640 | m_tabpanel.add |
641 | @@ -645,11 +637,11 @@ |
642 | |
643 | UI::Button & FieldActionWindow::add_button |
644 | (UI::Box * const box, |
645 | - char const * const name, |
646 | - char const * const picname, |
647 | + const char * const name, |
648 | + const char * const picname, |
649 | void (FieldActionWindow::*fn)(), |
650 | - std::string const & tooltip_text, |
651 | - bool const repeating) |
652 | + const std::string & tooltip_text, |
653 | + bool repeating) |
654 | { |
655 | UI::Button & button = |
656 | *new UI::Button |
657 | @@ -749,7 +741,7 @@ |
658 | |
659 | void FieldActionWindow::act_configure_economy() |
660 | { |
661 | - if (upcast(Widelands::Flag const, flag, m_node.field->get_immovable())) |
662 | + if (upcast(const Widelands::Flag, flag, m_node.field->get_immovable())) |
663 | flag->get_economy()->show_options_window(); |
664 | } |
665 | |
666 | @@ -835,7 +827,7 @@ |
667 | Start construction of the building with the give description index |
668 | =============== |
669 | */ |
670 | -void FieldActionWindow::act_build(Widelands::Building_Index::value_t const idx) |
671 | +void FieldActionWindow::act_build(Widelands::Building_Index::value_t idx) |
672 | { |
673 | Widelands::Game & game = ref_cast<Game, Editor_Game_Base>(ibase().egbase()); |
674 | game.send_player_build |
675 | @@ -853,7 +845,6 @@ |
676 | void FieldActionWindow::building_icon_mouse_out |
677 | (Widelands::Building_Index::value_t) |
678 | { |
679 | - m_buildcostPrev->set_map(NULL); |
680 | if (m_workarea_preview_job_id) { |
681 | m_overlay_manager.remove_overlay(m_workarea_preview_job_id); |
682 | m_workarea_preview_job_id = Overlay_Manager::Job_Id::Null(); |
683 | @@ -862,11 +853,8 @@ |
684 | |
685 | |
686 | void FieldActionWindow::building_icon_mouse_in |
687 | - (Widelands::Building_Index::value_t const idx) |
688 | + (const Widelands::Building_Index::value_t idx) |
689 | { |
690 | - m_buildcostPrev->set_map |
691 | - (&m_plr->tribe().get_building_descr(Widelands::Building_Index(idx))->buildcost()); |
692 | - |
693 | if (ibase().m_show_workarea_preview and not m_workarea_preview_job_id) { |
694 | m_workarea_preview_job_id = m_overlay_manager.get_a_job_id(); |
695 | Widelands::HollowArea<> hollow_area(Widelands::Area<>(m_node, 0), 0); |
696 | @@ -939,7 +927,7 @@ |
697 | if (m_attack_box->soldiers() > 0) |
698 | game.send_player_enemyflagaction |
699 | (building->base_flag(), |
700 | - ref_cast<Interactive_Player const, Interactive_Base const> |
701 | + ref_cast<const Interactive_Player, const Interactive_Base> |
702 | (ibase()) |
703 | .player_number(), |
704 | m_attack_box->soldiers(), // number of soldiers |
705 | @@ -972,10 +960,10 @@ |
706 | return w.init(); |
707 | } |
708 | |
709 | - Widelands::Map const & map = player->egbase().map(); |
710 | + const Widelands::Map & map = player->egbase().map(); |
711 | |
712 | // we're building a road right now |
713 | - Widelands::FCoords const target = |
714 | + const Widelands::FCoords target = |
715 | map.get_fcoords(ibase->get_sel_pos().node); |
716 | |
717 | // if user clicked on the same field again, build a flag |
718 | @@ -998,12 +986,12 @@ |
719 | |
720 | // did he click on a flag or a road where a flag can be built? |
721 | |
722 | - if (upcast(Widelands::PlayerImmovable const, i, map.get_immovable(target))) |
723 | + if (upcast(const Widelands::PlayerImmovable, i, map.get_immovable(target))) |
724 | { |
725 | bool finish = false; |
726 | - if (dynamic_cast<Widelands::Flag const *>(i)) |
727 | + if (dynamic_cast<const Widelands::Flag *>(i)) |
728 | finish = true; |
729 | - else if (dynamic_cast<Widelands::Road const *>(i)) |
730 | + else if (dynamic_cast<const Widelands::Road *>(i)) |
731 | if (player->get_buildcaps(target) & Widelands::BUILDCAPS_FLAG) { |
732 | ref_cast<Game, Editor_Game_Base>(player->egbase()) |
733 | .send_player_build_flag(player->player_number(), target); |
734 | |
735 | === modified file 'src/wui/waresdisplay.cc' |
736 | --- src/wui/waresdisplay.cc 2013-01-05 18:52:13 +0000 |
737 | +++ src/wui/waresdisplay.cc 2013-01-23 21:09:25 +0000 |
738 | @@ -40,8 +40,8 @@ |
739 | |
740 | AbstractWaresDisplay::AbstractWaresDisplay |
741 | (UI::Panel * const parent, |
742 | - int32_t const x, int32_t const y, |
743 | - Widelands::Tribe_Descr const & tribe, |
744 | + int32_t x, int32_t y, |
745 | + const Widelands::Tribe_Descr & tribe, |
746 | Widelands::WareWorker type, |
747 | bool selectable, |
748 | boost::function<void(Widelands::Ware_Index, bool)> callback_function, |
749 | @@ -91,9 +91,9 @@ |
750 | |
751 | |
752 | bool AbstractWaresDisplay::handle_mousemove |
753 | - (Uint8, int32_t const x, int32_t const y, int32_t, int32_t) |
754 | + (uint8_t, int32_t x, int32_t y, int32_t, int32_t) |
755 | { |
756 | - Widelands::Ware_Index const index = ware_at_point(x, y); |
757 | + const Widelands::Ware_Index index = ware_at_point(x, y); |
758 | |
759 | m_curware.set_text |
760 | (index ? |
761 | @@ -108,7 +108,7 @@ |
762 | } |
763 | |
764 | bool AbstractWaresDisplay::handle_mousepress |
765 | - (Uint8 btn, int32_t const x, int32_t const y) |
766 | + (uint8_t btn, int32_t x, int32_t y) |
767 | { |
768 | if (btn == SDL_BUTTON_LEFT) { |
769 | Widelands::Ware_Index ware = ware_at_point(x, y); |
770 | @@ -186,7 +186,7 @@ |
771 | } |
772 | } |
773 | |
774 | -Widelands::Tribe_Descr::WaresOrder const & AbstractWaresDisplay::icons_order() const |
775 | +const Widelands::Tribe_Descr::WaresOrder & AbstractWaresDisplay::icons_order() const |
776 | { |
777 | switch (m_type) { |
778 | case Widelands::wwWARE: |
779 | @@ -199,7 +199,7 @@ |
780 | throw wexception("Invalid m_type %d", m_type); |
781 | } |
782 | |
783 | -Widelands::Tribe_Descr::WaresOrderCoords const & AbstractWaresDisplay::icons_order_coords() const |
784 | +const Widelands::Tribe_Descr::WaresOrderCoords & AbstractWaresDisplay::icons_order_coords() const |
785 | { |
786 | switch (m_type) { |
787 | case Widelands::wwWARE: |
788 | @@ -313,14 +313,14 @@ |
789 | |
790 | WaresDisplay::WaresDisplay |
791 | (UI::Panel * const parent, |
792 | - int32_t const x, int32_t const y, |
793 | - Widelands::Tribe_Descr const & tribe, |
794 | + int32_t x, int32_t y, |
795 | + const Widelands::Tribe_Descr & tribe, |
796 | Widelands::WareWorker type, |
797 | bool selectable) |
798 | : AbstractWaresDisplay(parent, x, y, tribe, type, selectable) |
799 | {} |
800 | |
801 | -RGBColor AbstractWaresDisplay::info_color_for_ware(Widelands::Ware_Index const /* ware */) { |
802 | +RGBColor AbstractWaresDisplay::info_color_for_ware(Widelands::Ware_Index /* ware */) { |
803 | return RGBColor(0, 0, 0); |
804 | } |
805 | |
806 | @@ -345,7 +345,7 @@ |
807 | =============== |
808 | */ |
809 | void WaresDisplay::add_warelist |
810 | - (Widelands::WareList const & wares) |
811 | + (const Widelands::WareList & wares) |
812 | { |
813 | // If you register something twice, it is counted twice. Not my problem. |
814 | m_warelists.push_back(&wares); |
815 | @@ -355,85 +355,27 @@ |
816 | } |
817 | |
818 | |
819 | -/* |
820 | -==================================================== |
821 | -struct BuildcostDisplay |
822 | -==================================================== |
823 | -*/ |
824 | - |
825 | -WaresMapDisplay::WaresMapDisplay |
826 | - (UI::Panel * const parent, |
827 | - const int32_t x, const int32_t y, |
828 | - int32_t columns, |
829 | - Widelands::Tribe_Descr const & tribe, |
830 | - maptype const * map) |
831 | - : |
832 | - UI::Panel (parent, x, y, 0, 0), m_tribe(tribe), m_columns(columns) |
833 | -{ |
834 | - set_map(map); |
835 | -} |
836 | - |
837 | -WaresMapDisplay::~WaresMapDisplay() |
838 | -{} |
839 | - |
840 | -void WaresMapDisplay::set_map(maptype const * map) { |
841 | - m_map = map; |
842 | - if (m_map) { |
843 | - int32_t c = m_map->size(); |
844 | - set_desired_size |
845 | - ((c < m_columns ? c : m_columns) * (WARE_MENU_PIC_WIDTH + 4) + 1, |
846 | - ((c / m_columns) + (c % m_columns != 0)) * (WARE_MENU_PIC_HEIGHT + 3 + WARE_MENU_INFO_SIZE) + 1); |
847 | - set_visible(true); |
848 | - } else { |
849 | - set_desired_size(0, 0); |
850 | - set_visible(false); |
851 | - } |
852 | -} |
853 | - |
854 | -void WaresMapDisplay::draw(RenderTarget & dst) |
855 | -{ |
856 | - if (not m_map) |
857 | - return; |
858 | - |
859 | - Point p = Point(2, 2); |
860 | - |
861 | - maptype::const_iterator c; |
862 | +std::string waremap_to_richtext |
863 | + (const Widelands::Tribe_Descr & tribe, |
864 | + const std::map<Widelands::Ware_Index, uint8_t> & map) |
865 | +{ |
866 | + std::string ret; |
867 | + |
868 | + std::map<Widelands::Ware_Index, uint8_t>::const_iterator c; |
869 | |
870 | Widelands::Tribe_Descr::WaresOrder::iterator i; |
871 | std::vector<Widelands::Ware_Index>::iterator j; |
872 | - Widelands::Tribe_Descr::WaresOrder order = m_tribe.wares_order(); |
873 | + Widelands::Tribe_Descr::WaresOrder order = tribe.wares_order(); |
874 | |
875 | for (i = order.begin(); i != order.end(); i++) |
876 | for (j = i->begin(); j != i->end(); ++j) |
877 | - if ((c = m_map->find(*j)) != m_map->end()) { |
878 | - // draw a background |
879 | - const IPicture* pic = g_gr->imgcache().load (PicMod_Game, "pics/ware_list_bg.png"); |
880 | - uint32_t w = pic->get_w(); |
881 | - |
882 | - dst.blit(p, pic); |
883 | - |
884 | - const Point pos = p + Point((w - WARE_MENU_PIC_WIDTH) / 2, 1); |
885 | - // Draw it |
886 | - dst.blit |
887 | - (pos, |
888 | - m_tribe.get_ware_descr(c->first)->icon()); |
889 | - dst.fill_rect |
890 | - (Rect(pos + Point(0, WARE_MENU_PIC_HEIGHT), WARE_MENU_PIC_WIDTH, WARE_MENU_INFO_SIZE), |
891 | - RGBColor(0, 0, 0)); |
892 | - |
893 | - UI::g_fh->draw_text |
894 | - (dst, UI::TextStyle::ui_ultrasmall(), |
895 | - p + Point(WARE_MENU_PIC_WIDTH, WARE_MENU_PIC_HEIGHT - 4), |
896 | - boost::lexical_cast<std::string, uint32_t>(c->second), |
897 | - UI::Align_Right); |
898 | - |
899 | - p.x += (WARE_MENU_PIC_WIDTH + 4); |
900 | - if (p.x >= (m_columns * (WARE_MENU_PIC_WIDTH + 4))) { |
901 | - p.x = 2; |
902 | - p.y += (WARE_MENU_PIC_HEIGHT + 3 + WARE_MENU_INFO_SIZE); |
903 | - } |
904 | + if ((c = map.find(*j)) != map.end()) { |
905 | + ret += "<sub width=30 padding=2><p align=center>" |
906 | + "<sub width=26 background=454545><p align=center><img src=\"" |
907 | + + tribe.get_ware_descr(c->first)->icon_name() |
908 | + + "\"></p></sub><sub width=26 background=000000><p><font size=9>" |
909 | + + boost::lexical_cast<std::string>(static_cast<int32_t>(c->second)) |
910 | + + "</font></p></sub></p></sub>"; |
911 | } |
912 | + return ret; |
913 | } |
914 | - |
915 | - |
916 | - |
917 | |
918 | === modified file 'src/wui/waresdisplay.h' |
919 | --- src/wui/waresdisplay.h 2012-12-16 21:02:00 +0000 |
920 | +++ src/wui/waresdisplay.h 2013-01-23 21:09:25 +0000 |
921 | @@ -45,20 +45,21 @@ |
922 | * |
923 | * For practical purposes, use one of the derived classes, e.g. @ref WaresDisplay. |
924 | */ |
925 | -struct AbstractWaresDisplay : public UI::Panel { |
926 | +class AbstractWaresDisplay : public UI::Panel { |
927 | +public: |
928 | AbstractWaresDisplay |
929 | (UI::Panel * const parent, |
930 | - int32_t const x, int32_t const y, |
931 | - Widelands::Tribe_Descr const &, |
932 | + int32_t x, int32_t y, |
933 | + const Widelands::Tribe_Descr &, |
934 | Widelands::WareWorker type, |
935 | bool selectable, |
936 | boost::function<void(Widelands::Ware_Index, bool)> callback_function = NULL, |
937 | bool horizontal = true); |
938 | |
939 | bool handle_mousemove |
940 | - (Uint8 state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff); |
941 | + (uint8_t state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff); |
942 | |
943 | - bool handle_mousepress(Uint8 btn, int32_t x, int32_t y); |
944 | + bool handle_mousepress(uint8_t btn, int32_t x, int32_t y); |
945 | |
946 | |
947 | // Wares may be selected (highlighted) |
948 | @@ -85,12 +86,12 @@ |
949 | protected: |
950 | virtual void layout(); |
951 | |
952 | - virtual std::string info_for_ware(Widelands::Ware_Index const) = 0; |
953 | + virtual std::string info_for_ware(Widelands::Ware_Index) = 0; |
954 | |
955 | virtual RGBColor info_color_for_ware(Widelands::Ware_Index); |
956 | |
957 | - Widelands::Tribe_Descr::WaresOrder const & icons_order() const; |
958 | - Widelands::Tribe_Descr::WaresOrderCoords const & icons_order_coords() const; |
959 | + const Widelands::Tribe_Descr::WaresOrder & icons_order() const; |
960 | + const Widelands::Tribe_Descr::WaresOrderCoords & icons_order_coords() const; |
961 | virtual Point ware_position(Widelands::Ware_Index) const; |
962 | virtual void draw(RenderTarget &); |
963 | virtual void draw_ware |
964 | @@ -98,10 +99,10 @@ |
965 | Widelands::Ware_Index); |
966 | |
967 | private: |
968 | - typedef std::vector<Widelands::WareList const *> vector_type; |
969 | + typedef std::vector<const Widelands::WareList *> vector_type; |
970 | typedef std::vector<bool> selection_type; |
971 | |
972 | - Widelands::Tribe_Descr const & m_tribe; |
973 | + const Widelands::Tribe_Descr & m_tribe; |
974 | Widelands::WareWorker m_type; |
975 | UI::Textarea m_curware; |
976 | selection_type m_selected; |
977 | @@ -112,59 +113,36 @@ |
978 | }; |
979 | |
980 | /* |
981 | -struct WaresDisplay |
982 | +class WaresDisplay |
983 | ------------------ |
984 | Panel that displays the contents of many WareLists. The ware_lists |
985 | must be valid while they are registered with this class. |
986 | */ |
987 | -struct WaresDisplay : public AbstractWaresDisplay { |
988 | +class WaresDisplay : public AbstractWaresDisplay { |
989 | +public: |
990 | WaresDisplay |
991 | (UI::Panel * const parent, |
992 | - int32_t const x, int32_t const y, |
993 | - Widelands::Tribe_Descr const &, |
994 | + int32_t x, int32_t y, |
995 | + const Widelands::Tribe_Descr &, |
996 | Widelands::WareWorker type, |
997 | bool selectable); |
998 | |
999 | virtual ~WaresDisplay(); |
1000 | |
1001 | - void add_warelist(Widelands::WareList const &); |
1002 | + void add_warelist(const Widelands::WareList &); |
1003 | void remove_all_warelists(); |
1004 | |
1005 | protected: |
1006 | virtual std::string info_for_ware(Widelands::Ware_Index); |
1007 | |
1008 | private: |
1009 | - typedef std::vector<Widelands::WareList const *> vector_type; |
1010 | + typedef std::vector<const Widelands::WareList *> vector_type; |
1011 | vector_type m_warelists; |
1012 | std::vector<boost::signals::connection> connections_; |
1013 | }; |
1014 | |
1015 | - |
1016 | -/** |
1017 | - * Displays the build costs of a given building |
1018 | - */ |
1019 | - |
1020 | -struct WaresMapDisplay : public UI::Panel { |
1021 | - typedef std::map<Widelands::Ware_Index, uint8_t> maptype; |
1022 | - |
1023 | - WaresMapDisplay |
1024 | - (UI::Panel * const parent, |
1025 | - int32_t const x, int32_t const y, |
1026 | - int32_t columns, |
1027 | - Widelands::Tribe_Descr const & tribe, |
1028 | - maptype const * map = NULL); |
1029 | - |
1030 | - virtual ~WaresMapDisplay(); |
1031 | - |
1032 | - void set_map(maptype const * map); |
1033 | - |
1034 | -private: |
1035 | - virtual void draw(RenderTarget &); |
1036 | - |
1037 | -private: |
1038 | - Widelands::Tribe_Descr const & m_tribe; |
1039 | - maptype const * m_map; |
1040 | - int32_t m_columns; |
1041 | -}; |
1042 | +std::string waremap_to_richtext |
1043 | + (const Widelands::Tribe_Descr & tribe, |
1044 | + const std::map<Widelands::Ware_Index, uint8_t> & map); |
1045 | |
1046 | #endif |
Cool contribution! Thanks a lot. It looks really nice in the game as well and feels very natural. I am also glad that somebody did something new and cool with the rich text system :). I feel the text can be a few pts smaller in the preview.
The think you mention with the black sounds like a bug. Can you provide a minimal example for reproduction?
On to the code review: to_richtext. The string is already implicit in the return type.
- please move the const in front where applicable: string const & -> const string&. same void * const -> const void * or in this case likely rather void *.
- std::string const & descr = std::string()); use "" instead of string().
- _("Buildcosts:") sounds strange for a user facing string. How about "Construction cost"? This appears twice in the code.
- std::string ret(""); - Initialization is not needed.
- nice touch renaming the structs to classes :)
- rt string -> richtext. similar i'd rename the function to waremap_
Very, very nice work! Thanks.