Merge lp:~widelands-dev/widelands/bug-1395322-tool3 into lp:widelands

Proposed by GunChleoc on 2016-04-03
Status: Merged
Merged at revision: 7946
Proposed branch: lp:~widelands-dev/widelands/bug-1395322-tool3
Merge into: lp:widelands
Diff against target: 1161 lines (+301/-605)
11 files modified
data/scripting/editor/editor_controls.lua (+16/-9)
src/editor/editorinteractive.cc (+6/-0)
src/editor/tools/set_port_space_tool.cc (+1/-1)
src/editor/ui_menus/tool_change_height_options_menu.cc (+56/-159)
src/editor/ui_menus/tool_change_height_options_menu.h (+7/-13)
src/editor/ui_menus/tool_change_resources_options_menu.cc (+89/-173)
src/editor/ui_menus/tool_change_resources_options_menu.h (+12/-15)
src/editor/ui_menus/tool_noise_height_options_menu.cc (+99/-221)
src/editor/ui_menus/tool_noise_height_options_menu.h (+10/-14)
src/ui_basic/spinbox.cc (+1/-0)
src/ui_basic/spinbox.h (+4/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1395322-tool3
Reviewer Review Type Date Requested Status
kaputtnik testing 2016-04-03 Approve on 2016-04-07
GunChleoc Resubmit on 2016-04-06
Review via email: mp+290829@code.launchpad.net

Commit message

Added CTRL as selection key for the 2nd alternative tool and updated help text. Redesigned the Height, Noise and Resources tools to use proper SpinBoxes and Boxes.

Description of the change

Left ALT is causing problems in some OS, so I added the CTRL keys for the 2nd alternative tool. I left the ALT keys in though in order not to frustrate map designers who are used to the Alt key.

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

Continuous integration builds have changed state:

Travis build 951. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/120451312.
Appveyor build 784. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1395322_tool3-784.

7938. By kaputtnik on 2016-04-05

adjusted help texts

7939. By GunChleoc on 2016-04-05

Proofreading.

7940. By GunChleoc on 2016-04-05

Merged trunk.

bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 968. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/120930924.
Appveyor build 801. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1395322_tool3-801.

kaputtnik (franku) wrote :

Great :-)

review: Approve (testing)
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 969. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/120978837.
Appveyor build 802. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1395322_tool3-802.

Miroslav Remák (miroslavr256) wrote :

If we're going to be so specific, we should also mention that Shift or Ctrl + Click removes map elements for Immovables, Animals and Port Space tools. Except Ctrl + Click with the Port Space tool does placement instead of removal for some reason. Perhaps we could fix this inconsistency? That would be an easy one-line change in EditorSetPortSpaceTool's constructor.

Also, see diff comments.

GunChleoc (gunchleoc) wrote :

Yes, I think we should fix the inconsistency. Thanks for flagging it up!

I think the help is getting a bit crowded, too much for the user to remember. So, I'd suggest explaining the general trends in the help function and adding specific help to each tool as a tooltip.

kaputtnik (franku) wrote :

I don't know the reason why Ctrl is used to remove objects at all. In my opinion there should be only one key for removing objects and use this key for all objects. So for all objects:

Click: Place Objects or Increase (meaning 'add something')
Shift + Click: Remove Objects or Decrease (meaning 'remove something')

This should be consistent for all objects, imho. And the Ctrl key should only work for special things (like "Set Value").

Miroslav Remák (miroslavr256) wrote :

It's used as a fallback to the first alternative version of the tool if the second one is not available. It makes sense to me, but I'm not against changing this behavior.

GunChleoc (gunchleoc) wrote :

I don't think that we should go to the trouble to remove the fallbacks - it would only add code. We document the intended keys, and if additional keys work too, I don't see a problem. Basically, if there is no third option, the behavour of the Ctrl key is undefined, so it doesn't matter if it switches to the 1st or 2nd tool.

kaputtnik (franku) wrote :

Ok, then it would be fine if the CTRL + Click for Portdocks get changed in this branch :-)

And removing the shift key from:

"Shift or Ctrl + Click : Set height to the value selected by ‘Set Value’"

Miroslav Remák (miroslavr256) wrote :

Sounds good.

7941. By GunChleoc on 2016-04-06

Fixed inconsistent behaviour of port space tool.

7942. By GunChleoc on 2016-04-06

Merged trunk.

7943. By GunChleoc on 2016-04-06

The menu for Editor Height Tool now used spinboxes and box layout. Added tooltips.

7944. By GunChleoc on 2016-04-06

Redesigned the resources tool menu.

7945. By GunChleoc on 2016-04-06

Merged trunk.

7946. By GunChleoc on 2016-04-06

Refactored menu for noise height tool and fixed some labels.

7947. By GunChleoc on 2016-04-06

Updated editor help texts.

7948. By GunChleoc on 2016-04-06

Initialize with actual values + cleanup.

GunChleoc (gunchleoc) wrote :

And another scope creep... since the tooltips wouldn't take, I redesigned the Heigh, Noise and Resources tools to use proper SpinBoxes and Boxes.

review: Resubmit
kaputtnik (franku) wrote :

Removing the additional headers for "Height and Resources tool" and "Noise height tool" in the help doesn't fit my taste. A general help should be driven by "Information as clear as it could be", not "Information as short it could be". But if you think it's good, lets leave it. The Tooltips make such help nearly superfluous :-)

The only thing i am wondering is the tooltip for "Noise height -> Set Value" which says "Use Shift + Click or Ctrl + Click ...". I think only "Ctrl + Click" should be shown here?

bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 975. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/121219958.
Appveyor build 808. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1395322_tool3-808.

GunChleoc (gunchleoc) wrote :

> The Tooltips make such help nearly superfluous :-)

Exactly my point - it's there with the tooltips, and the less the user has to read and memorize, the better IMO.

> The only thing i am wondering is the tooltip for "Noise height -> Set Value"
> which says "Use Shift + Click or Ctrl + Click ...". I think only "Ctrl +
> Click" should be shown here?

+1 - will do :)

7949. By GunChleoc on 2016-04-07

Improved tooltip for noise height tool.

kaputtnik (franku) wrote :

I think it's good to go now :-)

review: Approve (testing)
Miroslav Remák (miroslavr256) wrote :

See diff comments, otherwise LGTM.

7950. By GunChleoc on 2016-04-07

Cleaned up includes.

GunChleoc (gunchleoc) wrote :

Thanks for testing & review :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/scripting/editor/editor_controls.lua'
2--- data/scripting/editor/editor_controls.lua 2016-04-02 08:09:19 +0000
3+++ data/scripting/editor/editor_controls.lua 2016-04-07 14:03:59 +0000
4@@ -4,16 +4,17 @@
5 include "txts/help/common_helptexts.lua"
6
7 return {
8- title = _"Keyboard Shortcuts",
9+ title = _"Controls",
10 text =
11 rt(
12+ h2(_"Keyboard Shortcuts") ..
13 p(
14+ -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
15+ dl(help_format_hotkey("F1"), _"Help") ..
16 -- TRANSLATORS: This is an access key combination.
17 dl(help_format_hotkey("H"), _"Toggle main menu") ..
18 -- TRANSLATORS: This is an access key combination. The hotkey is 't'
19 dl(help_format_hotkey("T"), _"Toggle tools menu") ..
20- -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
21- dl(help_format_hotkey(pgettext("hotkey", "1-0")), _"Change tool size") ..
22 help_toggle_minimap_hotkey() ..
23 help_toggle_building_spaces_hotkey() ..
24 -- TRANSLATORS: This is an access key combination. The hotkey is 'p'
25@@ -22,12 +23,6 @@
26 dl(help_format_hotkey("Ctrl + Z"), _"Undo") ..
27 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
28 dl(help_format_hotkey("Ctrl + Y"), _"Redo") ..
29- -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
30- dl(help_format_hotkey("F1"), _"Help") ..
31- -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
32- dl(help_format_hotkey(pgettext("hotkey", "Shift (Hold)")), _"First alternative tool while pressed") ..
33- -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
34- dl(help_format_hotkey(pgettext("hotkey", "Alt (Hold)")), _"Second alternative tool while pressed") ..
35 -- TRANSLATORS: This is an access key combination. The hotkey is 'i'
36 dl(help_format_hotkey("I"), _"Activate information tool") ..
37 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
38@@ -35,6 +30,18 @@
39 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
40 dl(help_format_hotkey(pgettext("hotkey", "Ctrl + S")), _"Save map") ..
41 help_toggle_fullscreen_hotkey()
42+ ) ..
43+
44+ h2(_"Tools") ..
45+ p(
46+ -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
47+ dl(help_format_hotkey(pgettext("hotkey", "1-0")), _"Change tool size") ..
48+ -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
49+ dl(help_format_hotkey(pgettext("hotkey", "Click")), _"Place new elements on the map, or increase map elements by the value selected by ‘Increase/Decrease value’") ..
50+ -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
51+ dl(help_format_hotkey(pgettext("hotkey", "Shift + Click")), _"Remove elements from the map, or decrease map elements by the value selected by ‘Increase/Decrease value’") ..
52+ -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
53+ dl(help_format_hotkey(pgettext("hotkey", "Ctrl + Click")), _"Set map elements to the value selected by ‘Set Value’")
54 )
55 )
56 }
57
58=== modified file 'src/editor/editorinteractive.cc'
59--- src/editor/editorinteractive.cc 2016-04-06 09:23:04 +0000
60+++ src/editor/editorinteractive.cc 2016-04-07 14:03:59 +0000
61@@ -441,6 +441,9 @@
62 handled = true;
63 break;
64
65+ case SDLK_LCTRL:
66+ case SDLK_RCTRL:
67+ // TODO(GunChleoc): Keeping ALT and MODE to make the transition easier. Remove for Build 20.
68 case SDLK_LALT:
69 case SDLK_RALT:
70 case SDLK_MODE:
71@@ -525,6 +528,9 @@
72 switch (code.sym) {
73 case SDLK_LSHIFT:
74 case SDLK_RSHIFT:
75+ case SDLK_LCTRL:
76+ case SDLK_RCTRL:
77+ // TODO(GunChleoc): Keeping ALT and MODE to make the transition easier. Remove for Build 20.
78 case SDLK_LALT:
79 case SDLK_RALT:
80 case SDLK_MODE:
81
82=== modified file 'src/editor/tools/set_port_space_tool.cc'
83--- src/editor/tools/set_port_space_tool.cc 2016-04-06 09:23:04 +0000
84+++ src/editor/tools/set_port_space_tool.cc 2016-04-07 14:03:59 +0000
85@@ -45,7 +45,7 @@
86 EditorSetPortSpaceTool::EditorSetPortSpaceTool
87 (EditorUnsetPortSpaceTool & the_unset_tool)
88 :
89- EditorTool(the_unset_tool, *this)
90+ EditorTool(the_unset_tool, the_unset_tool)
91 {}
92
93
94
95=== modified file 'src/editor/ui_menus/tool_change_height_options_menu.cc'
96--- src/editor/ui_menus/tool_change_height_options_menu.cc 2016-04-06 09:23:04 +0000
97+++ src/editor/ui_menus/tool_change_height_options_menu.cc 2016-04-07 14:03:59 +0000
98@@ -22,177 +22,74 @@
99 #include <cstdio>
100 #include <string>
101
102+#include <boost/format.hpp>
103+
104 #include "base/i18n.h"
105 #include "editor/editorinteractive.h"
106 #include "editor/tools/increase_height_tool.h"
107 #include "editor/tools/set_height_tool.h"
108 #include "graphic/graphic.h"
109 #include "logic/widelands_geometry.h"
110-#include "ui_basic/button.h"
111
112-#define width 20
113-#define height 20
114 EditorToolChangeHeightOptionsMenu::EditorToolChangeHeightOptionsMenu
115 (EditorInteractive & parent,
116 EditorIncreaseHeightTool & increase_tool,
117 UI::UniqueWindow::Registry & registry)
118 :
119- EditorToolOptionsMenu
120- (parent, registry, 250, 135, _("Height Tools Options")),
121+ EditorToolOptionsMenu(parent, registry, 350, 100, _("Height Tools Options")),
122 increase_tool_(increase_tool),
123- change_by_label_
124- (this,
125- hmargin(), vmargin(), get_inner_w() - 2 * hmargin(), height,
126- _("Increase/Decrease Value"), UI::Align::kBottomCenter),
127- change_by_increase_
128- (this, "incr_change_by",
129- get_inner_w() - hmargin() - width,
130- change_by_label_.get_y() + change_by_label_.get_h() + spacing(),
131- width, height,
132- g_gr->images().get("images/ui_basic/but1.png"),
133- g_gr->images().get("images/ui_basic/scrollbar_up.png"),
134- std::string(),
135- increase_tool.get_change_by() < MAX_FIELD_HEIGHT_DIFF),
136- change_by_decrease_
137- (this, "decr_change_by",
138- hmargin(),
139- change_by_increase_.get_y(),
140- width, height,
141- g_gr->images().get("images/ui_basic/but1.png"),
142- g_gr->images().get("images/ui_basic/scrollbar_down.png"),
143- std::string(),
144- 1 < increase_tool.get_change_by()),
145- change_by_value_
146- (this,
147- change_by_increase_.get_x() + change_by_increase_.get_w() +
148- hspacing(),
149- change_by_increase_.get_y(),
150- change_by_decrease_.get_x() - hspacing()
151- -
152- (change_by_increase_.get_x() + change_by_increase_.get_w() +
153- hspacing()),
154- height,
155- UI::Align::kBottomCenter),
156- set_to_label_
157- (this,
158- vmargin(),
159- change_by_increase_.get_y() + change_by_increase_.get_h() +
160- vspacing(),
161- get_inner_w() - 2 * hmargin(), height,
162- _("Set Value"), UI::Align::kBottomCenter),
163- set_to_increase_
164- (this, "incr_set_to",
165- change_by_increase_.get_x(),
166- set_to_label_.get_y() + set_to_label_.get_h() + vspacing(),
167- width, height,
168- g_gr->images().get("images/ui_basic/but1.png"),
169- g_gr->images().get("images/ui_basic/scrollbar_up.png"),
170- std::string(),
171- increase_tool.set_tool().get_interval().min < MAX_FIELD_HEIGHT),
172- set_to_decrease_
173- (this, "decr_set_to",
174- hmargin(),
175- set_to_increase_.get_y(),
176- width, height,
177- g_gr->images().get("images/ui_basic/but1.png"),
178- g_gr->images().get("images/ui_basic/scrollbar_down.png"),
179- std::string(),
180- 0 < increase_tool.set_tool().get_interval().min),
181- set_to_value_
182- (this,
183- change_by_value_.get_x(), set_to_increase_.get_y(),
184- change_by_value_.get_w(), height,
185- UI::Align::kBottomCenter)
186+ box_(this, hmargin(), vmargin(), UI::Box::Vertical, 0, 0, vspacing()),
187+ change_by_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
188+ increase_tool_.get_change_by(), 1, MAX_FIELD_HEIGHT_DIFF,
189+ _("Increase/Decrease Value:"), UI::SpinBox::Units::kNone,
190+ g_gr->images().get("images/ui_basic/but1.png"),
191+ UI::SpinBox::Type::kSmall),
192+ set_to_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
193+ increase_tool_.set_tool().get_interval().min, 0, MAX_FIELD_HEIGHT,
194+ _("Set Value:"), UI::SpinBox::Units::kNone,
195+ g_gr->images().get("images/ui_basic/but1.png"),
196+ UI::SpinBox::Type::kSmall)
197 {
198- change_by_increase_.sigclicked.connect
199- (boost::bind
200- (&EditorToolChangeHeightOptionsMenu::clicked_change_by_increment, boost::ref(*this)));
201- change_by_decrease_.sigclicked.connect
202- (boost::bind
203- (&EditorToolChangeHeightOptionsMenu::clicked_change_by_decrement, boost::ref(*this)));
204- set_to_increase_.sigclicked.connect
205- (boost::bind(&EditorToolChangeHeightOptionsMenu::clicked_setto_increment, boost::ref(*this)));
206- set_to_decrease_.sigclicked.connect
207- (boost::bind(&EditorToolChangeHeightOptionsMenu::clicked_setto_decrement, boost::ref(*this)));
208-
209- change_by_increase_.set_repeating(true);
210- change_by_decrease_.set_repeating(true);
211- set_to_increase_ .set_repeating(true);
212- set_to_decrease_ .set_repeating(true);
213- update();
214-}
215-
216-
217-void EditorToolChangeHeightOptionsMenu::clicked_change_by_decrement() {
218- int32_t change_by = increase_tool_.get_change_by();
219- assert(change_by == increase_tool_.decrease_tool().get_change_by());
220- assert(1 < change_by);
221-
222- --change_by;
223-
224- increase_tool_ .set_change_by(change_by);
225- increase_tool_.decrease_tool().set_change_by(change_by);
226- change_by_decrease_.set_enabled(1 < change_by);
227- change_by_increase_.set_enabled(true);
228- select_correct_tool();
229- update();
230-}
231-
232-
233-void EditorToolChangeHeightOptionsMenu::clicked_change_by_increment() {
234- int32_t change_by = increase_tool_.get_change_by();
235- assert(change_by == increase_tool_.decrease_tool().get_change_by());
236- assert(change_by < MAX_FIELD_HEIGHT_DIFF);
237-
238- ++change_by;
239-
240- increase_tool_ .set_change_by(change_by);
241- increase_tool_.decrease_tool().set_change_by(change_by);
242- change_by_decrease_.set_enabled(true);
243- change_by_increase_.set_enabled(change_by < MAX_FIELD_HEIGHT_DIFF);
244- select_correct_tool();
245- update();
246-}
247-
248-
249-void EditorToolChangeHeightOptionsMenu::clicked_setto_decrement() {
250- Widelands::Field::Height setto =
251- increase_tool_.set_tool().get_interval().min;
252- assert(setto == increase_tool_.set_tool().get_interval().max);
253- assert(0 < setto);
254-
255- --setto;
256-
257- increase_tool_.set_tool().set_interval
258- (Widelands::HeightInterval(setto, setto));
259- set_to_decrease_.set_enabled(0 < setto);
260- set_to_increase_.set_enabled(true);
261- select_correct_tool();
262- update();
263-}
264-
265-
266-void EditorToolChangeHeightOptionsMenu::clicked_setto_increment() {
267- Widelands::Field::Height setto =
268- increase_tool_.set_tool().get_interval().min;
269- assert(setto == increase_tool_.set_tool().get_interval().max);
270- assert(setto < MAX_FIELD_HEIGHT);
271-
272- ++setto;
273-
274- increase_tool_.set_tool().set_interval
275- (Widelands::HeightInterval(setto, setto));
276- set_to_decrease_.set_enabled(true);
277- set_to_increase_.set_enabled(setto < MAX_FIELD_HEIGHT);
278- select_correct_tool();
279- update();
280-}
281-
282-
283-/// Update all the textareas, so that they represent the correct values.
284-void EditorToolChangeHeightOptionsMenu::update() {
285- change_by_value_.set_text(std::to_string(increase_tool_.get_change_by()));
286-
287- set_to_value_.set_text(std::to_string(
288- static_cast<unsigned int>(increase_tool_.set_tool().get_interval().min)));
289+ change_by_.set_tooltip(
290+ /** TRANSLATORS: Editor change height access keys. **/
291+ (boost::format(_("Use %s to increase, %s to decrease"))
292+ /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
293+ % _("Click")
294+ /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
295+ % _("Shift + Click")).str());
296+ set_to_.set_tooltip(
297+ /** TRANSLATORS: Editor set height access key. **/
298+ (boost::format(_("Use %s to set to this value"))
299+ /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
300+ % _("Ctrl + Click")).str());
301+
302+ change_by_.changed.connect
303+ (boost::bind
304+ (&EditorToolChangeHeightOptionsMenu::update_change_by, boost::ref(*this)));
305+ set_to_.changed.connect
306+ (boost::bind
307+ (&EditorToolChangeHeightOptionsMenu::update_set_to, boost::ref(*this)));
308+
309+ box_.add(&change_by_, UI::Align::kLeft);
310+ box_.add(&set_to_, UI::Align::kLeft);
311+ box_.set_size(get_inner_w() - 2 * hmargin(), change_by_.get_h() + set_to_.get_h() + vspacing());
312+ set_inner_size(box_.get_w() + 2 * hmargin(), box_.get_h() + 2 * vspacing());
313+}
314+
315+void EditorToolChangeHeightOptionsMenu::update_change_by() {
316+ int32_t change_by = change_by_.get_value();
317+ assert(change_by > 0);
318+ assert(change_by <= MAX_FIELD_HEIGHT_DIFF);
319+
320+ increase_tool_ .set_change_by(change_by);
321+ increase_tool_.decrease_tool().set_change_by(change_by);
322+ select_correct_tool();
323+}
324+
325+void EditorToolChangeHeightOptionsMenu::update_set_to() {
326+ int32_t set_to = set_to_.get_value();
327+ assert(set_to >= 0);
328+ assert(set_to <= MAX_FIELD_HEIGHT);
329+ increase_tool_.set_tool().set_interval(Widelands::HeightInterval(set_to, set_to));
330+ select_correct_tool();
331 }
332
333=== modified file 'src/editor/ui_menus/tool_change_height_options_menu.h'
334--- src/editor/ui_menus/tool_change_height_options_menu.h 2016-04-06 09:23:04 +0000
335+++ src/editor/ui_menus/tool_change_height_options_menu.h 2016-04-07 14:03:59 +0000
336@@ -21,8 +21,8 @@
337 #define WL_EDITOR_UI_MENUS_TOOL_CHANGE_HEIGHT_OPTIONS_MENU_H
338
339 #include "editor/ui_menus/tool_options_menu.h"
340-#include "ui_basic/button.h"
341-#include "ui_basic/textarea.h"
342+#include "ui_basic/box.h"
343+#include "ui_basic/spinbox.h"
344
345 class EditorInteractive;
346 struct EditorIncreaseHeightTool;
347@@ -37,18 +37,12 @@
348
349 private:
350 EditorIncreaseHeightTool& increase_tool_;
351- UI::Textarea change_by_label_;
352- UI::Button change_by_increase_, change_by_decrease_;
353- UI::Textarea change_by_value_;
354- UI::Textarea set_to_label_;
355- UI::Button set_to_increase_, set_to_decrease_;
356- UI::Textarea set_to_value_;
357+ UI::Box box_;
358+ UI::SpinBox change_by_;
359+ UI::SpinBox set_to_;
360
361- void clicked_change_by_decrement();
362- void clicked_change_by_increment();
363- void clicked_setto_decrement ();
364- void clicked_setto_increment ();
365- void update();
366+ void update_change_by();
367+ void update_set_to();
368 };
369
370 #endif // end of include guard: WL_EDITOR_UI_MENUS_TOOL_CHANGE_HEIGHT_OPTIONS_MENU_H
371
372=== modified file 'src/editor/ui_menus/tool_change_resources_options_menu.cc'
373--- src/editor/ui_menus/tool_change_resources_options_menu.cc 2016-04-06 09:23:04 +0000
374+++ src/editor/ui_menus/tool_change_resources_options_menu.cc 2016-04-07 14:03:59 +0000
375@@ -22,6 +22,8 @@
376 #include <cstdio>
377 #include <string>
378
379+#include <boost/format.hpp>
380+
381 #include "base/i18n.h"
382 #include "base/wexception.h"
383 #include "editor/editorinteractive.h"
384@@ -33,11 +35,9 @@
385 #include "logic/map_objects/world/world.h"
386 #include "logic/widelands.h"
387 #include "logic/widelands_geometry.h"
388-#include "ui_basic/button.h"
389 #include "wui/field_overlay_manager.h"
390
391-const static int BUTTON_WIDTH = 20;
392-const static int BUTTON_HEIGHT = 20;
393+constexpr int kMaxValue = 63;
394
395 inline EditorInteractive & EditorToolChangeResourcesOptionsMenu::eia() {
396 return dynamic_cast<EditorInteractive&>(*get_parent());
397@@ -50,178 +50,114 @@
398 EditorIncreaseResourcesTool & increase_tool,
399 UI::UniqueWindow::Registry & registry)
400 :
401- EditorToolOptionsMenu
402- (parent, registry, 250, 120, _("Resources")),
403- change_by_label_
404- (this,
405- hmargin(), vmargin(), get_inner_w() - 2 * hmargin(), BUTTON_HEIGHT,
406- _("Increase/Decrease Value"), UI::Align::kBottomCenter),
407- change_by_increase_
408- (this, "incr_change_by",
409- get_inner_w() - hmargin() - BUTTON_WIDTH,
410- change_by_label_.get_y() + change_by_label_.get_h() + spacing(),
411- BUTTON_WIDTH, BUTTON_HEIGHT,
412- g_gr->images().get("images/ui_basic/but1.png"),
413- g_gr->images().get("images/ui_basic/scrollbar_up.png")),
414- change_by_decrease_
415- (this, "decr_change_by",
416- hmargin(),
417- change_by_increase_.get_y(),
418- BUTTON_WIDTH, BUTTON_HEIGHT,
419- g_gr->images().get("images/ui_basic/but1.png"),
420- g_gr->images().get("images/ui_basic/scrollbar_down.png")),
421- change_by_value_
422- (this,
423- change_by_increase_.get_x() + change_by_increase_.get_w() +
424- hspacing(),
425- change_by_increase_.get_y(),
426- change_by_decrease_.get_x() - hspacing()
427- -
428- (change_by_increase_.get_x() + change_by_increase_.get_w() +
429- hspacing()),
430- BUTTON_HEIGHT,
431- UI::Align::kBottomCenter),
432- set_to_label_
433- (this,
434- vmargin(),
435- change_by_increase_.get_y() + change_by_increase_.get_h() + vspacing(),
436- get_inner_w() - 2 * hmargin(), BUTTON_HEIGHT,
437- _("Set Value"), UI::Align::kBottomCenter),
438- set_to_increase_
439- (this, "incr_set_to",
440- change_by_increase_.get_x(),
441- set_to_label_.get_y() + set_to_label_.get_h() + vspacing(),
442- BUTTON_WIDTH, BUTTON_HEIGHT,
443- g_gr->images().get("images/ui_basic/but1.png"),
444- g_gr->images().get("images/ui_basic/scrollbar_up.png")),
445- set_to_decrease_
446- (this, "decr_set_to",
447- hmargin(),
448- set_to_increase_.get_y(), BUTTON_WIDTH, BUTTON_HEIGHT,
449- g_gr->images().get("images/ui_basic/but1.png"),
450- g_gr->images().get("images/ui_basic/scrollbar_down.png")),
451- set_to_value_
452- (this,
453- change_by_value_.get_x(), set_to_increase_.get_y(),
454- change_by_value_.get_w(), BUTTON_HEIGHT,
455- UI::Align::kBottomCenter),
456- cur_selection_(this, 0, 0, _("Current Selection"), UI::Align::kBottomCenter),
457- increase_tool_(increase_tool)
458+ EditorToolOptionsMenu(parent, registry, 350, 120, _("Resources")),
459+ increase_tool_(increase_tool),
460+ box_(this, hmargin(), vmargin(), UI::Box::Vertical, 0, 0, vspacing()),
461+ change_by_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
462+ increase_tool_.get_change_by(), 1, kMaxValue,
463+ _("Increase/Decrease Value:"), UI::SpinBox::Units::kNone,
464+ g_gr->images().get("images/ui_basic/but1.png"),
465+ UI::SpinBox::Type::kSmall),
466+ set_to_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
467+ increase_tool_.set_tool().get_set_to(), 0, kMaxValue,
468+ _("Set Value:"), UI::SpinBox::Units::kNone,
469+ g_gr->images().get("images/ui_basic/but1.png"),
470+ UI::SpinBox::Type::kSmall),
471+ resources_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, 1),
472+ cur_selection_(&box_, 0, 0, "", UI::Align::kCenter)
473 {
474- change_by_increase_.sigclicked.connect
475- (boost::bind
476- (&EditorToolChangeResourcesOptionsMenu::clicked_button,
477- boost::ref(*this),
478- Change_By_Increase));
479- change_by_decrease_.sigclicked.connect
480- (boost::bind
481- (&EditorToolChangeResourcesOptionsMenu::clicked_button,
482- boost::ref(*this),
483- Change_By_Decrease));
484- set_to_increase_.sigclicked.connect
485- (boost::bind
486- (&EditorToolChangeResourcesOptionsMenu::clicked_button,
487- boost::ref(*this),
488- Set_To_Increase));
489- set_to_decrease_.sigclicked.connect
490- (boost::bind
491- (&EditorToolChangeResourcesOptionsMenu::clicked_button,
492- boost::ref(*this),
493- Set_To_Decrease));
494-
495- change_by_increase_.set_repeating(true);
496- change_by_decrease_.set_repeating(true);
497- set_to_increase_ .set_repeating(true);
498- set_to_decrease_ .set_repeating(true);
499- const Widelands::World & world = parent.egbase().world();
500- Widelands::DescriptionIndex const nr_resources = world.get_nr_resources();
501-
502- // Find the maximal width and height for the resource pictures.
503- int resource_pic_max_width = 0, resource_pic_max_height = 0;
504+ // Configure spin boxes
505+ change_by_.set_tooltip(
506+ /** TRANSLATORS: Editor change resources access keys. **/
507+ (boost::format(_("Use %s to increase, %s to decrease"))
508+ /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
509+ % _("Click")
510+ /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
511+ % _("Shift + Click")).str());
512+ set_to_.set_tooltip(
513+ /** TRANSLATORS: Editor set resources access key. **/
514+ (boost::format(_("Use %s to set to this value"))
515+ /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
516+ % _("Ctrl + Click")).str());
517+
518+ change_by_.changed.connect
519+ (boost::bind
520+ (&EditorToolChangeResourcesOptionsMenu::update_change_by, boost::ref(*this)));
521+ set_to_.changed.connect
522+ (boost::bind
523+ (&EditorToolChangeResourcesOptionsMenu::update_set_to, boost::ref(*this)));
524+
525+ box_.add(&change_by_, UI::Align::kLeft);
526+ box_.add(&set_to_, UI::Align::kLeft);
527+ box_.set_size(get_inner_w() - 2 * hmargin(), change_by_.get_h() + set_to_.get_h() + vspacing());
528+
529+ // Add resource buttons
530+ const Widelands::World& world = parent.egbase().world();
531+ const Widelands::DescriptionIndex nr_resources = world.get_nr_resources();
532+
533 for (Widelands::DescriptionIndex i = 0; i < nr_resources; ++i) {
534- const Image* pic = g_gr->images().get(world.get_resource(i)->representative_image());
535- resource_pic_max_width = std::max(resource_pic_max_width, pic->width());
536- resource_pic_max_height = std::max(resource_pic_max_height, pic->height());
537+ const Widelands::ResourceDescription& resource = *world.get_resource(i);
538+ radiogroup_.add_button
539+ (&resources_box_,
540+ Point(0, 0),
541+ g_gr->images().get(resource.representative_image()),
542+ resource.descname());
543+ resources_box_.add(radiogroup_.get_first_button(), UI::Align::kLeft, false, true);
544 }
545
546- const uint16_t resources_in_row =
547- (get_inner_w() - 2 * hmargin() + spacing())
548- /
549- (resource_pic_max_width + spacing());
550+ box_.add_space(vspacing());
551+ box_.add(&resources_box_, UI::Align::kLeft, true);
552+ box_.set_size(box_.get_w(), box_.get_h() + 4 * vspacing() + resources_box_.get_h());
553+
554+ radiogroup_.set_state(increase_tool_.get_cur_res());
555
556 radiogroup_.changed.connect
557- (boost::bind(&EditorToolChangeResourcesOptionsMenu::selected, this));
558+ (boost::bind(&EditorToolChangeResourcesOptionsMenu::change_resource, this));
559 radiogroup_.clicked.connect
560- (boost::bind(&EditorToolChangeResourcesOptionsMenu::selected, this));
561-
562- uint16_t cur_x = 0;
563- Point pos
564- (hmargin(), set_to_value_.get_y() + set_to_value_.get_h() + vspacing());
565- for
566- (Widelands::DescriptionIndex i = 0;
567- i < nr_resources;
568- pos.x += resource_pic_max_width + hspacing(), ++cur_x, ++i)
569- {
570- if (cur_x == resources_in_row) {
571- cur_x = 0;
572- pos.x = hmargin();
573- pos.y += resource_pic_max_height + vspacing();
574- }
575- radiogroup_.add_button
576- (this,
577- pos,
578- g_gr->images().get(world.get_resource(i)->representative_image()));
579- }
580- pos.y += resource_pic_max_height + vspacing();
581-
582- set_inner_size(get_inner_w(), pos.y + cur_selection_.get_h() + vmargin());
583- cur_selection_.set_pos(Point(get_inner_w() / 2, pos.y + hspacing()));
584-
585- radiogroup_.set_state(increase_tool_.get_cur_res());
586-
587+ (boost::bind(&EditorToolChangeResourcesOptionsMenu::change_resource, this));
588+
589+ // Add label
590+ cur_selection_.set_fixed_width(box_.get_inner_w());
591+ box_.add(&cur_selection_, UI::Align::kLeft);
592+
593+ box_.set_size(box_.get_w(), box_.get_h() + vspacing() + cur_selection_.get_h());
594+ set_inner_size(get_inner_w(), box_.get_h() + 1 * vmargin());
595 update();
596 }
597
598-
599-void EditorToolChangeResourcesOptionsMenu::clicked_button(Button const n)
600-{
601- assert
602- (increase_tool_.get_change_by()
603- ==
604- increase_tool_.decrease_tool().get_change_by());
605-
606- int32_t change_by = increase_tool_.get_change_by();
607- int32_t set_to = increase_tool_.set_tool().get_set_to();
608-
609- switch (n) {
610- case Change_By_Increase: change_by += change_by < 63; break;
611- case Change_By_Decrease: change_by -= 1 < change_by; break;
612- case Set_To_Increase: set_to += set_to < 63; break;
613- case Set_To_Decrease: set_to -= 0 < set_to;
614- }
615+void EditorToolChangeResourcesOptionsMenu::update_change_by() {
616+ int32_t change_by = change_by_.get_value();
617+ assert(change_by > 0);
618+ assert(change_by <= kMaxValue);
619 increase_tool_.set_change_by(change_by);
620 increase_tool_.decrease_tool().set_change_by(change_by);
621+ select_correct_tool();
622+}
623+
624+void EditorToolChangeResourcesOptionsMenu::update_set_to() {
625+ int32_t set_to = set_to_.get_value();
626+ assert(set_to >= 0);
627+ assert(set_to <= kMaxValue);
628 increase_tool_.set_tool().set_set_to(set_to);
629-
630 select_correct_tool();
631- update();
632 }
633
634+
635 /**
636 * called when a resource has been selected
637 */
638-void EditorToolChangeResourcesOptionsMenu::selected() {
639- const int32_t resIx = radiogroup_.get_state();
640+void EditorToolChangeResourcesOptionsMenu::change_resource() {
641+ const int32_t resource_index = radiogroup_.get_state();
642
643- increase_tool_.set_tool().set_cur_res(resIx);
644- increase_tool_.set_cur_res(resIx);
645- increase_tool_.decrease_tool().set_cur_res(resIx);
646+ increase_tool_.set_tool().set_cur_res(resource_index);
647+ increase_tool_.set_cur_res(resource_index);
648+ increase_tool_.decrease_tool().set_cur_res(resource_index);
649
650 Widelands::EditorGameBase& egbase = eia().egbase();
651 Widelands::Map & map = egbase.map();
652 eia().mutable_field_overlay_manager()->register_overlay_callback_function(
653- [resIx, &map, &egbase](const Widelands::TCoords<Widelands::FCoords>& coords) -> uint32_t {
654- if (map.is_resource_valid(egbase.world(), coords, resIx)) {
655+ [resource_index, &map, &egbase](const Widelands::TCoords<Widelands::FCoords>& coords) -> uint32_t {
656+ if (map.is_resource_valid(egbase.world(), coords, resource_index)) {
657 return coords.field->nodecaps();
658 }
659 return 0;
660@@ -229,7 +165,6 @@
661
662 map.recalc_whole_map(egbase.world());
663 select_correct_tool();
664-
665 update();
666 }
667
668@@ -237,26 +172,7 @@
669 * Update all the textareas, so that they represent the correct values
670 */
671 void EditorToolChangeResourcesOptionsMenu::update() {
672-
673- change_by_value_.set_text(std::to_string(increase_tool_.get_change_by()));
674-
675- set_to_value_.set_text(std::to_string(
676- static_cast<unsigned int>(increase_tool_.set_tool().get_set_to())));
677-
678 cur_selection_.set_text
679- (eia().egbase().world().get_resource(increase_tool_.set_tool().get_cur_res())->descname());
680- cur_selection_.set_pos
681- (Point
682- ((get_inner_w() - cur_selection_.get_w()) / 2, get_inner_h() - 20));
683-
684- {
685- int32_t const change_by = increase_tool_.get_change_by();
686- change_by_decrease_.set_enabled(1 < change_by);
687- change_by_increase_.set_enabled (change_by < 63);
688- }
689- {
690- int32_t const set_to = increase_tool_.set_tool().get_set_to();
691- set_to_decrease_ .set_enabled(0 < set_to);
692- set_to_increase_ .set_enabled (set_to < 63);
693- }
694+ ((boost::format(_("Current: %s"))
695+ % eia().egbase().world().get_resource(increase_tool_.set_tool().get_cur_res())->descname()).str());
696 }
697
698=== modified file 'src/editor/ui_menus/tool_change_resources_options_menu.h'
699--- src/editor/ui_menus/tool_change_resources_options_menu.h 2016-04-06 09:23:04 +0000
700+++ src/editor/ui_menus/tool_change_resources_options_menu.h 2016-04-07 14:03:59 +0000
701@@ -21,8 +21,9 @@
702 #define WL_EDITOR_UI_MENUS_TOOL_CHANGE_RESOURCES_OPTIONS_MENU_H
703
704 #include "editor/ui_menus/tool_options_menu.h"
705-#include "ui_basic/button.h"
706+#include "ui_basic/box.h"
707 #include "ui_basic/radiobutton.h"
708+#include "ui_basic/spinbox.h"
709 #include "ui_basic/textarea.h"
710
711 class EditorInteractive;
712@@ -38,22 +39,18 @@
713
714 private:
715 EditorInteractive & eia();
716- void selected();
717- enum Button {
718- Change_By_Increase, Change_By_Decrease,
719- Set_To_Increase, Set_To_Decrease
720- };
721- void clicked_button(Button);
722+ void change_resource();
723+ void update_change_by();
724+ void update_set_to();
725 void update();
726- UI::Textarea change_by_label_;
727- UI::Button change_by_increase_, change_by_decrease_;
728- UI::Textarea change_by_value_;
729- UI::Textarea set_to_label_;
730- UI::Button set_to_increase_, set_to_decrease_;
731- UI::Textarea set_to_value_;
732+
733+ EditorIncreaseResourcesTool& increase_tool_;
734+ UI::Box box_;
735+ UI::SpinBox change_by_;
736+ UI::SpinBox set_to_;
737+ UI::Box resources_box_;
738+ UI::Radiogroup radiogroup_;
739 UI::Textarea cur_selection_;
740- UI::Radiogroup radiogroup_;
741- EditorIncreaseResourcesTool& increase_tool_;
742 };
743
744 #endif // end of include guard: WL_EDITOR_UI_MENUS_TOOL_CHANGE_RESOURCES_OPTIONS_MENU_H
745
746=== modified file 'src/editor/ui_menus/tool_noise_height_options_menu.cc'
747--- src/editor/ui_menus/tool_noise_height_options_menu.cc 2016-04-06 09:23:04 +0000
748+++ src/editor/ui_menus/tool_noise_height_options_menu.cc 2016-04-07 14:03:59 +0000
749@@ -30,236 +30,114 @@
750 #include "editor/tools/noise_height_tool.h"
751 #include "graphic/graphic.h"
752 #include "logic/widelands_geometry.h"
753+#include "ui_basic/textarea.h"
754
755
756 using Widelands::Field;
757
758-#define width 20
759-#define height 20
760 EditorToolNoiseHeightOptionsMenu::EditorToolNoiseHeightOptionsMenu
761 (EditorInteractive & parent,
762 EditorNoiseHeightTool & noise_tool,
763 UI::UniqueWindow::Registry & registry)
764 :
765- EditorToolOptionsMenu
766- (parent, registry, 250, 3 * height + 4 * vspacing() + 2 * vmargin(), _("Noise Height Options")),
767+ EditorToolOptionsMenu(parent, registry, 300, 120, _("Noise Height Options")),
768 noise_tool_(noise_tool),
769- lower_label_
770- (this,
771- hmargin(),
772- vmargin(),
773- width, height,
774- UI::Align::kLeft),
775- upper_label_
776- (this,
777- hmargin(),
778- lower_label_.get_y() + lower_label_.get_h() + 2 * vspacing(),
779- width, height,
780- UI::Align::kLeft),
781- lower_decrease_
782- (this, "decr_lower",
783- get_inner_w() - 2 * width - hspacing(),
784- lower_label_.get_y(),
785- width, height,
786- g_gr->images().get("images/ui_basic/but0.png"),
787- g_gr->images().get("images/ui_basic/scrollbar_down.png"),
788- std::string(),
789- 0 < noise_tool.get_interval().min),
790- lower_increase_
791- (this, "incr_lower",
792- get_inner_w() - width - hspacing(),
793- lower_label_.get_y(),
794- width, height,
795- g_gr->images().get("images/ui_basic/but0.png"),
796- g_gr->images().get("images/ui_basic/scrollbar_up.png"),
797- std::string(),
798- noise_tool.get_interval().min < MAX_FIELD_HEIGHT),
799- upper_decrease_
800- (this, "decr_upper",
801- get_inner_w() - 2 * width - hspacing(),
802- upper_label_.get_y(),
803- width, height,
804- g_gr->images().get("images/ui_basic/but0.png"),
805- g_gr->images().get("images/ui_basic/scrollbar_down.png"),
806- std::string(),
807- 0 < noise_tool.get_interval().max),
808- upper_increase_
809- (this, "incr_upper",
810- get_inner_w() - width - hspacing(),
811- upper_label_.get_y(),
812- width, height,
813- g_gr->images().get("images/ui_basic/but0.png"),
814- g_gr->images().get("images/ui_basic/scrollbar_up.png"),
815- std::string(),
816- noise_tool.get_interval().max < MAX_FIELD_HEIGHT),
817- set_label_
818- (this,
819- hmargin(),
820- upper_label_.get_y() + upper_label_.get_h() + 2 * vspacing(),
821- width, height,
822- UI::Align::kLeft),
823- setto_decrease_
824- (this, "decr_set_to",
825- get_inner_w() - 2 * width - hspacing(),
826- set_label_.get_y(),
827- width, height,
828- g_gr->images().get("images/ui_basic/but1.png"),
829- g_gr->images().get("images/ui_basic/scrollbar_down.png"),
830- std::string(),
831- 0 < noise_tool.set_tool().get_interval().min),
832- setto_increase_
833- (this, "incr_set_to",
834- get_inner_w() - width - hspacing(),
835- set_label_.get_y(),
836- width, height,
837- g_gr->images().get("images/ui_basic/but1.png"),
838- g_gr->images().get("images/ui_basic/scrollbar_up.png"),
839- std::string(),
840- noise_tool.set_tool().get_interval().max < MAX_FIELD_HEIGHT)
841+ box_(this, hmargin(), vmargin(), UI::Box::Vertical, 0, 0, vspacing()),
842+ lower_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
843+ noise_tool_.get_interval().min, 1, MAX_FIELD_HEIGHT,
844+ _("Minimum Height:"), UI::SpinBox::Units::kNone,
845+ g_gr->images().get("images/ui_basic/but1.png"),
846+ UI::SpinBox::Type::kSmall),
847+ upper_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
848+ noise_tool_.get_interval().max, 0, MAX_FIELD_HEIGHT,
849+ _("Maximum Height:"), UI::SpinBox::Units::kNone,
850+ g_gr->images().get("images/ui_basic/but1.png"),
851+ UI::SpinBox::Type::kSmall),
852+ set_to_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
853+ noise_tool_.set_tool().get_interval().min, 0, MAX_FIELD_HEIGHT,
854+ _("Set Value:"), UI::SpinBox::Units::kNone,
855+ g_gr->images().get("images/ui_basic/but1.png"),
856+ UI::SpinBox::Type::kSmall)
857 {
858- lower_increase_.sigclicked.connect
859- (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_lower_increase, boost::ref(*this)));
860- lower_decrease_.sigclicked.connect
861- (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_lower_decrease, boost::ref(*this)));
862- upper_increase_.sigclicked.connect
863- (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_upper_increase, boost::ref(*this)));
864- upper_decrease_.sigclicked.connect
865- (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_upper_decrease, boost::ref(*this)));
866- setto_increase_.sigclicked.connect
867- (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_setto_increase, boost::ref(*this)));
868- setto_decrease_.sigclicked.connect
869- (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_setto_decrease, boost::ref(*this)));
870-
871- lower_increase_.set_repeating(true);
872- lower_decrease_.set_repeating(true);
873- upper_increase_.set_repeating(true);
874- upper_decrease_.set_repeating(true);
875- setto_increase_.set_repeating(true);
876- setto_decrease_.set_repeating(true);
877- update();
878-}
879-
880-/**
881- * Update all textareas
882-*/
883-void EditorToolNoiseHeightOptionsMenu::update() {
884- const Widelands::HeightInterval height_interval = noise_tool_.get_interval();
885-
886- lower_label_.set_text((boost::format(_("Minimum: %u"))
887- % static_cast<unsigned int>(height_interval.min)).str());
888-
889- upper_label_.set_text((boost::format(_("Maximum: %u"))
890- % static_cast<unsigned int>(height_interval.max)).str());
891-
892- set_label_.set_text((boost::format(_("Set value: %u"))
893- % static_cast<unsigned int>(noise_tool_.set_tool().get_interval().min)).str());
894-
895- select_correct_tool();
896-}
897-
898-
899-void EditorToolNoiseHeightOptionsMenu::clicked_lower_decrease() {
900- Widelands::HeightInterval height_interval = noise_tool_.get_interval();
901-
902- assert(height_interval.valid());
903- assert(0 < height_interval.min);
904-
905- --height_interval.min;
906-
907- assert(height_interval.valid());
908-
909- noise_tool_.set_interval(height_interval);
910- lower_decrease_.set_enabled(0 < height_interval.min);
911- lower_increase_.set_enabled(true);
912- update();
913-}
914-
915-
916-void EditorToolNoiseHeightOptionsMenu::clicked_lower_increase() {
917- Widelands::HeightInterval height_interval = noise_tool_.get_interval();
918-
919- assert(height_interval.valid());
920- assert(height_interval.min < MAX_FIELD_HEIGHT);
921-
922- ++height_interval.min;
923- height_interval.max = std::max(height_interval.min, height_interval.max);
924-
925- assert(height_interval.valid());
926-
927- noise_tool_.set_interval(height_interval);
928- lower_decrease_.set_enabled(true);
929- lower_increase_.set_enabled(height_interval.min < MAX_FIELD_HEIGHT);
930- upper_decrease_.set_enabled(true);
931- upper_increase_.set_enabled(height_interval.max < MAX_FIELD_HEIGHT);
932-
933- update();
934-}
935-
936-
937-void EditorToolNoiseHeightOptionsMenu::clicked_upper_decrease() {
938- Widelands::HeightInterval height_interval = noise_tool_.get_interval();
939-
940- assert(height_interval.valid());
941- assert(0 < noise_tool_.get_interval().max);
942-
943- --height_interval.max;
944- height_interval.min = std::min(height_interval.min, height_interval.max);
945-
946- assert(height_interval.valid());
947-
948- noise_tool_.set_interval(height_interval);
949- lower_decrease_.set_enabled(0 < height_interval.min);
950- lower_increase_.set_enabled(true);
951- upper_decrease_.set_enabled(0 < height_interval.max);
952- upper_increase_.set_enabled(true);
953- update();
954-}
955-
956-
957-void EditorToolNoiseHeightOptionsMenu::clicked_upper_increase() {
958- Widelands::HeightInterval height_interval = noise_tool_.get_interval();
959-
960- assert(noise_tool_.get_interval().valid());
961- assert(noise_tool_.get_interval().max < MAX_FIELD_HEIGHT);
962-
963- ++height_interval.max;
964-
965- assert(noise_tool_.get_interval().valid());
966-
967- noise_tool_.set_interval(height_interval);
968- upper_decrease_.set_enabled(true);
969- upper_increase_.set_enabled(height_interval.max < MAX_FIELD_HEIGHT);
970- update();
971-}
972-
973-
974-void EditorToolNoiseHeightOptionsMenu::clicked_setto_decrease() {
975- EditorSetHeightTool & set_tool = noise_tool_.set_tool();
976- Field::Height h = set_tool.get_interval().min;
977-
978- assert(h == set_tool.get_interval().max);
979- assert(0 < h);
980-
981- --h;
982-
983- set_tool.set_interval(Widelands::HeightInterval(h, h));
984- setto_decrease_.set_enabled(0 < h);
985- setto_increase_.set_enabled(true);
986- update();
987-}
988-
989-
990-void EditorToolNoiseHeightOptionsMenu::clicked_setto_increase() {
991- EditorSetHeightTool & set_tool = noise_tool_.set_tool();
992- Field::Height h = set_tool.get_interval().min;
993-
994- assert(h == set_tool.get_interval().max);
995- assert(h < MAX_FIELD_HEIGHT);
996-
997- ++h;
998-
999- set_tool.set_interval(Widelands::HeightInterval(h, h));
1000- setto_decrease_.set_enabled(true);
1001- setto_increase_.set_enabled(h < MAX_FIELD_HEIGHT);
1002- update();
1003+ lower_.set_tooltip(
1004+ /** TRANSLATORS: Editor noise height access keys. **/
1005+ _("Click to set the height to a random value within the specified range"));
1006+ upper_.set_tooltip(
1007+ /** TRANSLATORS: Editor noise height access keys. **/
1008+ _("Click to set the height to a random value within the specified range"));
1009+ set_to_.set_tooltip(
1010+ /** TRANSLATORS: Editor set hoise height access keys. **/
1011+ (boost::format(_("Use %s to set to this value"))
1012+ /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
1013+ % _("Ctrl + Click")).str());
1014+
1015+ lower_.changed.connect
1016+ (boost::bind
1017+ (&EditorToolNoiseHeightOptionsMenu::update_lower, boost::ref(*this)));
1018+ upper_.changed.connect
1019+ (boost::bind
1020+ (&EditorToolNoiseHeightOptionsMenu::update_upper, boost::ref(*this)));
1021+ set_to_.changed.connect
1022+ (boost::bind
1023+ (&EditorToolNoiseHeightOptionsMenu::update_set_to, boost::ref(*this)));
1024+
1025+ UI::Textarea* label = new UI::Textarea(&box_, 0, 0, 0, 0, _("Random Height"), UI::Align::kCenter);
1026+ label->set_fixed_width(get_inner_w() - 2 * hmargin());
1027+ box_.add(label, UI::Align::kLeft);
1028+ box_.add(&upper_, UI::Align::kLeft);
1029+ box_.add(&lower_, UI::Align::kLeft);
1030+
1031+ box_.add_space(2 * vspacing());
1032+ label = new UI::Textarea(&box_, 0, 0, 0, 0, _("Fixed Height"), UI::Align::kCenter);
1033+ label->set_fixed_width(get_inner_w() - 2 * hmargin());
1034+ box_.add(label, UI::Align::kLeft);
1035+ box_.add(&set_to_, UI::Align::kLeft);
1036+
1037+ box_.set_size(get_inner_w() - 2 * hmargin(),
1038+ upper_.get_h() + lower_.get_h() + set_to_.get_h() + 2 * label->get_h() + 7 * vspacing());
1039+
1040+ set_inner_size(box_.get_w() + 2 * hmargin(), box_.get_h() + 2 * vspacing());
1041+}
1042+
1043+
1044+void EditorToolNoiseHeightOptionsMenu::update_lower() {
1045+ int32_t upper = upper_.get_value();
1046+ int32_t lower = lower_.get_value();
1047+ // Make sure that upper increases if necessary
1048+ upper = std::max(lower, upper);
1049+ lower = std::min(lower, upper);
1050+ update_interval(lower, upper);
1051+}
1052+
1053+
1054+void EditorToolNoiseHeightOptionsMenu::update_upper() {
1055+ int32_t upper = upper_.get_value();
1056+ int32_t lower = lower_.get_value();
1057+ // Make sure that lower decreases if necessary
1058+ lower = std::min(lower, upper);
1059+ upper = std::max(lower, upper);
1060+ update_interval(lower, upper);
1061+}
1062+
1063+void EditorToolNoiseHeightOptionsMenu::update_interval(int32_t lower, int32_t upper) {
1064+ assert(lower >= 0);
1065+ assert(lower <= MAX_FIELD_HEIGHT);
1066+ assert(upper >= 0);
1067+ assert(upper <= MAX_FIELD_HEIGHT);
1068+
1069+ Widelands::HeightInterval height_interval(lower, upper);
1070+ assert(height_interval.valid());
1071+
1072+ lower_.set_value(height_interval.min);
1073+ upper_.set_value(height_interval.max);
1074+ noise_tool_.set_interval(height_interval);
1075+ select_correct_tool();
1076+}
1077+
1078+void EditorToolNoiseHeightOptionsMenu::update_set_to() {
1079+ int32_t set_to = set_to_.get_value();
1080+ assert(set_to >= 0);
1081+ assert(set_to <= MAX_FIELD_HEIGHT);
1082+ noise_tool_.set_tool().set_interval(Widelands::HeightInterval(set_to, set_to));
1083+ select_correct_tool();
1084 }
1085
1086=== modified file 'src/editor/ui_menus/tool_noise_height_options_menu.h'
1087--- src/editor/ui_menus/tool_noise_height_options_menu.h 2016-04-06 09:23:04 +0000
1088+++ src/editor/ui_menus/tool_noise_height_options_menu.h 2016-04-07 14:03:59 +0000
1089@@ -21,8 +21,8 @@
1090 #define WL_EDITOR_UI_MENUS_TOOL_NOISE_HEIGHT_OPTIONS_MENU_H
1091
1092 #include "editor/ui_menus/tool_options_menu.h"
1093-#include "ui_basic/button.h"
1094-#include "ui_basic/textarea.h"
1095+#include "ui_basic/box.h"
1096+#include "ui_basic/spinbox.h"
1097
1098 class EditorInteractive;
1099 struct EditorNoiseHeightTool;
1100@@ -34,19 +34,15 @@
1101 UI::UniqueWindow::Registry &);
1102
1103 private:
1104+ void update_interval(int32_t lower, int32_t upper);
1105+ void update_upper();
1106+ void update_lower();
1107+ void update_set_to();
1108+
1109 EditorNoiseHeightTool& noise_tool_;
1110- UI::Textarea lower_label_, upper_label_;
1111- UI::Button lower_decrease_, lower_increase_, upper_decrease_, upper_increase_;
1112- UI::Textarea set_label_;
1113- UI::Button setto_decrease_, setto_increase_;
1114-
1115- void clicked_lower_decrease();
1116- void clicked_lower_increase();
1117- void clicked_upper_decrease();
1118- void clicked_upper_increase();
1119- void clicked_setto_decrease();
1120- void clicked_setto_increase();
1121- void update();
1122+ UI::Box box_;
1123+ UI::SpinBox lower_, upper_;
1124+ UI::SpinBox set_to_;
1125 };
1126
1127 #endif // end of include guard: WL_EDITOR_UI_MENUS_TOOL_NOISE_HEIGHT_OPTIONS_MENU_H
1128
1129=== modified file 'src/ui_basic/spinbox.cc'
1130--- src/ui_basic/spinbox.cc 2016-04-01 12:22:09 +0000
1131+++ src/ui_basic/spinbox.cc 2016-04-07 14:03:59 +0000
1132@@ -254,6 +254,7 @@
1133 void SpinBox::change_value(int32_t const value)
1134 {
1135 set_value(value + sbi_->value);
1136+ changed();
1137 }
1138
1139
1140
1141=== modified file 'src/ui_basic/spinbox.h'
1142--- src/ui_basic/spinbox.h 2016-03-26 18:57:47 +0000
1143+++ src/ui_basic/spinbox.h 2016-04-07 14:03:59 +0000
1144@@ -23,6 +23,8 @@
1145 #include <cstring>
1146 #include <list>
1147
1148+#include <boost/signals2.hpp>
1149+
1150 #include "graphic/align.h"
1151 #include "ui_basic/box.h"
1152 #include "ui_basic/button.h"
1153@@ -63,6 +65,8 @@
1154 int32_t step_size = 1, int32_t big_step_size = 10);
1155 ~SpinBox();
1156
1157+ boost::signals2::signal<void ()> changed;
1158+
1159 void set_value(int32_t);
1160 // For spinboxes of type kValueList. The vector needs to be sorted in ascending order,
1161 // otherwise you will confuse the user.