Merge lp:~widelands-dev/widelands/bug-1463829 into lp:widelands

Proposed by GunChleoc on 2015-08-12
Status: Merged
Merged at revision: 7519
Proposed branch: lp:~widelands-dev/widelands/bug-1463829
Merge into: lp:widelands
Diff against target: 143 lines (+30/-24)
2 files modified
src/wui/building_statistics_menu.cc (+27/-18)
src/wui/building_statistics_menu.h (+3/-6)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1463829
Reviewer Review Type Date Requested Status
SirVer 2015-08-12 Approve on 2015-08-31
Review via email: mp+267779@code.launchpad.net

Description of the change

Improved labels for Building Statistics window.

Fixes also an issue raised in the forum: https://wl.widelands.org/forum/topic/1768/

To post a comment you must log in.
SirVer (sirver) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/wui/building_statistics_menu.cc'
2--- src/wui/building_statistics_menu.cc 2015-08-04 07:49:23 +0000
3+++ src/wui/building_statistics_menu.cc 2015-08-12 09:26:56 +0000
4@@ -31,15 +31,16 @@
5 #include "logic/productionsite.h"
6 #include "logic/tribe.h"
7
8-constexpr int kBuildGridCellSize = 50;
9+constexpr int kBuildGridCellHeight = 50;
10+constexpr int kBuildGridCellWidth = 55;
11 constexpr int kMargin = 5;
12 constexpr int kColumns = 5;
13 constexpr int kButtonHeight = 20;
14 constexpr int kButtonRowHeight = kButtonHeight + kMargin;
15 constexpr int kLabelHeight = 18;
16 constexpr int kLabelFontSize = 12;
17-constexpr int kTabHeight = 35 + 5 * (kBuildGridCellSize + kLabelHeight + kLabelHeight);
18-constexpr int32_t kWindowWidth = kColumns * kBuildGridCellSize;
19+constexpr int kTabHeight = 35 + 5 * (kBuildGridCellHeight + kLabelHeight + kLabelHeight);
20+constexpr int32_t kWindowWidth = kColumns * kBuildGridCellWidth;
21 constexpr int32_t kWindowHeight = kTabHeight + kMargin + 4 * kButtonRowHeight;
22
23 constexpr int32_t kUpdateTimeInGametimeMs = 1000; // 1 second, gametime
24@@ -159,8 +160,8 @@
25
26 const BuildingIndex nr_buildings = tribe.get_nrbuildings();
27 building_buttons_ = std::vector<UI::Button*>(nr_buildings);
28- owned_labels_ = std::vector<UI::MultilineTextarea*>(nr_buildings);
29- productivity_labels_ = std::vector<UI::MultilineTextarea*>(nr_buildings);
30+ owned_labels_ = std::vector<UI::Textarea*>(nr_buildings);
31+ productivity_labels_ = std::vector<UI::Textarea*>(nr_buildings);
32
33 // Column counters
34 int columns[kNoOfBuildingTabs] = {0, 0, 0, 0, 0};
35@@ -376,8 +377,8 @@
36 (boost::format("building_button%s") % id).str(),
37 0,
38 0,
39- kBuildGridCellSize,
40- kBuildGridCellSize,
41+ kBuildGridCellWidth,
42+ kBuildGridCellHeight,
43 g_gr->images().get("pics/but1.png"),
44 &g_gr->animations()
45 .get_animation(descr.get_animation("idle"))
46@@ -388,11 +389,11 @@
47 button_box->add(building_buttons_[id], UI::Align_Left);
48
49 owned_labels_[id] =
50- new UI::MultilineTextarea(button_box, 0, 0, kBuildGridCellSize, kLabelHeight);
51+ new UI::Textarea(button_box, 0, 0, kBuildGridCellWidth, kLabelHeight, UI::Align_Center);
52 button_box->add(owned_labels_[id], UI::Align_Left);
53
54 productivity_labels_[id] =
55- new UI::MultilineTextarea(button_box, 0, 0, kBuildGridCellSize, kLabelHeight);
56+ new UI::Textarea(button_box, 0, 0, kBuildGridCellWidth, kLabelHeight, UI::Align_Center);
57 button_box->add(productivity_labels_[id], UI::Align_Left);
58
59 row.add(button_box, UI::Align_Left);
60@@ -546,7 +547,7 @@
61 void BuildingStatisticsMenu::think() {
62 // Adjust height to current tab
63 int tab_height =
64- 35 + row_counters_[tab_panel_.active()] * (kBuildGridCellSize + kLabelHeight + kLabelHeight);
65+ 35 + row_counters_[tab_panel_.active()] * (kBuildGridCellHeight + kLabelHeight + kLabelHeight);
66 tab_panel_.set_size(kWindowWidth, tab_height);
67 set_size(get_w(), tab_height + kMargin + 4 * kButtonRowHeight + get_tborder() + get_bborder());
68 navigation_panel_.set_pos(Point(0, tab_height + kMargin));
69@@ -662,7 +663,8 @@
70 } else {
71 color = UI_FONT_CLR_GOOD;
72 }
73- const std::string perc_str = (boost::format("%i%%") % percent).str();
74+ /** TRANSLATORS: Percent in building statistics window, e.g. 85% */
75+ const std::string perc_str = (boost::format(_("%i%%")) % percent).str();
76 set_labeltext_autosize(productivity_labels_[id], perc_str, color);
77 }
78 if (has_selection_ && id == current_building_type_) {
79@@ -745,15 +747,22 @@
80 }
81 }
82
83-void BuildingStatisticsMenu::set_labeltext_autosize(UI::MultilineTextarea* textarea,
84+void BuildingStatisticsMenu::set_labeltext_autosize(UI::Textarea* textarea,
85 const std::string& text,
86 const RGBColor& color) {
87- const std::string formatted_str =
88- (boost::format("<rt><p font-face=condensed font-weight=bold "
89- "font-size=%i font-color=%s>%s</p></rt>") %
90- (text.length() > 5 ? kLabelFontSize - floor(text.length() / 2) : kLabelFontSize) %
91- color.hex_value() % text).str();
92- textarea->set_text(formatted_str);
93+ int fontsize = text.length() > 7 ? kLabelFontSize - floor(text.length() / 3) : kLabelFontSize;
94+
95+ UI::TextStyle style;
96+ if (text.length() > 5) {
97+ style.font = UI::Font::get(UI::g_fh1->fontset().condensed(), fontsize);
98+ } else {
99+ style.font = UI::Font::get(UI::g_fh1->fontset().serif(), fontsize);
100+ }
101+ style.fg = color;
102+ style.bold = true;
103+
104+ textarea->set_textstyle(style);
105+ textarea->set_text(text);
106 textarea->set_visible(true);
107 }
108
109
110=== modified file 'src/wui/building_statistics_menu.h'
111--- src/wui/building_statistics_menu.h 2015-07-31 14:57:43 +0000
112+++ src/wui/building_statistics_menu.h 2015-08-12 09:26:56 +0000
113@@ -29,7 +29,6 @@
114 #include "ui_basic/button.h"
115 #include "ui_basic/editbox.h"
116 #include "ui_basic/tabpanel.h"
117-#include "ui_basic/multilinetextarea.h"
118 #include "ui_basic/textarea.h"
119 #include "ui_basic/unique_window.h"
120 #include "wui/interactive_player.h"
121@@ -76,7 +75,7 @@
122 void jump_building(JumpTarget target, bool reverse);
123
124 /// Sets the label for id type to text in the chosen color with dynamic font size
125- void set_labeltext_autosize(UI::MultilineTextarea* textarea,
126+ void set_labeltext_autosize(UI::Textarea* textarea,
127 const std::string& text,
128 const RGBColor& color);
129
130@@ -101,11 +100,9 @@
131 /// Button with building icon
132 std::vector<UI::Button*> building_buttons_;
133 /// Labels with owned / under construction buildings
134- std::vector<UI::MultilineTextarea*> owned_labels_;
135+ std::vector<UI::Textarea*> owned_labels_;
136 /// Labels with buildings' productivity
137- // TODO(GunChleoc): These need to be multiline, so we can give them a color.
138- // Turn into normal textareas in fh1 branch.
139- std::vector<UI::MultilineTextarea*> productivity_labels_;
140+ std::vector<UI::Textarea*> productivity_labels_;
141
142 /// The buttons for stepping through buildings
143 UI::Panel navigation_panel_;