Merge lp:~widelands-dev/widelands/stock-amounts into lp:widelands

Proposed by Benedikt Straub on 2018-09-10
Status: Merged
Merged at revision: 8824
Proposed branch: lp:~widelands-dev/widelands/stock-amounts
Merge into: lp:widelands
Diff against target: 56 lines (+24/-3)
1 file modified
src/wui/waresdisplay.cc (+24/-3)
To merge this branch: bzr merge lp:~widelands-dev/widelands/stock-amounts
Reviewer Review Type Date Requested Status
GunChleoc 2018-09-10 Approve on 2018-09-11
Review via email: mp+354558@code.launchpad.net

Commit message

Very large amounts in WaresDisplays are shortened as "10k", "10M", "10G" to prevent text from flowing over on the left.

Description of the change

Numbers from 0 to 9999 are displayed normally, then abbreviated 10k up to 999k, then 1M to 999M, then 1G.
A whitespace between number and suffix ("10 k") would look nicer but sadly isn´t possible; testing, I found that "972 M" overflows again, while "972M" just fits. The current font and layout don´t permit more than 4 chars total here.

To post a comment you must log in.
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3928. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/426624392.
Appveyor build 3726. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_stock_amounts-3726.

GunChleoc (gunchleoc) wrote :

Just 1 nit for the i18n

8821. By Benedikt Straub on 2018-09-11

Merged trunk

8822. By Benedikt Straub on 2018-09-11

Need one translation less

Benedikt Straub (nordfriese) wrote :

OK, implemented your comment

hessenfarmer (stephan-lutz) wrote :

this will still fail on CI environments.
please merge newest trunk with the CI fixes in

8823. By Benedikt Straub on 2018-09-11

Merged trunk

bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3935. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/427098399.
Appveyor build 3733. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_stock_amounts-3733.

GunChleoc (gunchleoc) wrote :

Code LGTM now, thanks!

Not tested yet.

review: Approve
GunChleoc (gunchleoc) wrote :

Now tested. I noticed that the economy options doesn't have it, but the change that somebody sets the target to 10k is kinda low :P

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/wui/waresdisplay.cc'
2--- src/wui/waresdisplay.cc 2018-07-08 13:53:45 +0000
3+++ src/wui/waresdisplay.cc 2018-09-11 07:44:57 +0000
4@@ -22,7 +22,7 @@
5 #include <cstdio>
6 #include <utility>
7
8-#include <boost/lexical_cast.hpp>
9+#include <boost/format.hpp>
10
11 #include "base/i18n.h"
12 #include "base/wexception.h"
13@@ -385,12 +385,33 @@
14 remove_all_warelists();
15 }
16
17+const char* unit_suffixes[] = {
18+ "%1%",
19+ /** TRANSLATORS: This is a large number with a suffix (e.g. 50k = 50,000). */
20+ /** TRANSLATORS: Space is limited, use only 1 letter for the suffix and no whitespace. */
21+ _("%1%k"),
22+ /** TRANSLATORS: This is a large number with a suffix (e.g. 5M = 5,000,000). */
23+ /** TRANSLATORS: Space is limited, use only 1 letter for the suffix and no whitespace. */
24+ _("%1%M"),
25+ /** TRANSLATORS: This is a large number with a suffix (e.g. 5G = 5,000,000,000). */
26+ /** TRANSLATORS: Space is limited, use only 1 letter for the suffix and no whitespace. */
27+ _("%1%G")
28+};
29+static std::string get_amount_string(uint32_t amount) {
30+ uint8_t size = 0;
31+ while (amount >= (size ? 1000 : 10000)) {
32+ amount /= 1000;
33+ size++;
34+ }
35+ return (boost::format(unit_suffixes[size]) % amount).str();
36+}
37+
38 std::string WaresDisplay::info_for_ware(Widelands::DescriptionIndex ware) {
39 int totalstock = 0;
40 for (const Widelands::WareList* warelist : warelists_) {
41 totalstock += warelist->stock(ware);
42 }
43- return boost::lexical_cast<std::string>(totalstock);
44+ return get_amount_string(totalstock);
45 }
46
47 /*
48@@ -420,7 +441,7 @@
49 "<div width=26 background=454545><p align=center><img src=\"" +
50 tribe.get_ware_descr(c->first)->icon_filename() +
51 "\"></p></div><div width=26 background=000000><p><font size=9>" +
52- boost::lexical_cast<std::string>(static_cast<int32_t>(c->second)) +
53+ get_amount_string(c->second) +
54 "</font></p></div></p></div>";
55 }
56 return ret;