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

Proposed by GunChleoc
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 (community) testing Approve
GunChleoc Needs Resubmitting
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.
Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
kaputtnik (franku) wrote :

Great :-)

review: Approve (testing)
Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
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").

Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
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’"

Revision history for this message
Miroslav Remák (miroslavr256) wrote :

Sounds good.

Revision history for this message
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: Needs Resubmitting
Revision history for this message
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?

Revision history for this message
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.

Revision history for this message
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 :)

Revision history for this message
kaputtnik (franku) wrote :

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

review: Approve (testing)
Revision history for this message
Miroslav Remák (miroslavr256) wrote :

See diff comments, otherwise LGTM.

Revision history for this message
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
=== modified file 'data/scripting/editor/editor_controls.lua'
--- data/scripting/editor/editor_controls.lua 2016-04-02 08:09:19 +0000
+++ data/scripting/editor/editor_controls.lua 2016-04-07 14:03:59 +0000
@@ -4,16 +4,17 @@
4include "txts/help/common_helptexts.lua"4include "txts/help/common_helptexts.lua"
55
6return {6return {
7 title = _"Keyboard Shortcuts",7 title = _"Controls",
8 text =8 text =
9 rt(9 rt(
10 h2(_"Keyboard Shortcuts") ..
10 p(11 p(
12 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
13 dl(help_format_hotkey("F1"), _"Help") ..
11 -- TRANSLATORS: This is an access key combination.14 -- TRANSLATORS: This is an access key combination.
12 dl(help_format_hotkey("H"), _"Toggle main menu") ..15 dl(help_format_hotkey("H"), _"Toggle main menu") ..
13 -- TRANSLATORS: This is an access key combination. The hotkey is 't'16 -- TRANSLATORS: This is an access key combination. The hotkey is 't'
14 dl(help_format_hotkey("T"), _"Toggle tools menu") ..17 dl(help_format_hotkey("T"), _"Toggle tools menu") ..
15 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
16 dl(help_format_hotkey(pgettext("hotkey", "1-0")), _"Change tool size") ..
17 help_toggle_minimap_hotkey() ..18 help_toggle_minimap_hotkey() ..
18 help_toggle_building_spaces_hotkey() ..19 help_toggle_building_spaces_hotkey() ..
19 -- TRANSLATORS: This is an access key combination. The hotkey is 'p'20 -- TRANSLATORS: This is an access key combination. The hotkey is 'p'
@@ -22,12 +23,6 @@
22 dl(help_format_hotkey("Ctrl + Z"), _"Undo") ..23 dl(help_format_hotkey("Ctrl + Z"), _"Undo") ..
23 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.24 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
24 dl(help_format_hotkey("Ctrl + Y"), _"Redo") ..25 dl(help_format_hotkey("Ctrl + Y"), _"Redo") ..
25 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
26 dl(help_format_hotkey("F1"), _"Help") ..
27 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
28 dl(help_format_hotkey(pgettext("hotkey", "Shift (Hold)")), _"First alternative tool while pressed") ..
29 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
30 dl(help_format_hotkey(pgettext("hotkey", "Alt (Hold)")), _"Second alternative tool while pressed") ..
31 -- TRANSLATORS: This is an access key combination. The hotkey is 'i'26 -- TRANSLATORS: This is an access key combination. The hotkey is 'i'
32 dl(help_format_hotkey("I"), _"Activate information tool") ..27 dl(help_format_hotkey("I"), _"Activate information tool") ..
33 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.28 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
@@ -35,6 +30,18 @@
35 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.30 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
36 dl(help_format_hotkey(pgettext("hotkey", "Ctrl + S")), _"Save map") ..31 dl(help_format_hotkey(pgettext("hotkey", "Ctrl + S")), _"Save map") ..
37 help_toggle_fullscreen_hotkey()32 help_toggle_fullscreen_hotkey()
33 ) ..
34
35 h2(_"Tools") ..
36 p(
37 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
38 dl(help_format_hotkey(pgettext("hotkey", "1-0")), _"Change tool size") ..
39 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
40 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’") ..
41 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
42 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’") ..
43 -- TRANSLATORS: This is an access key combination. Localize, but do not change the key.
44 dl(help_format_hotkey(pgettext("hotkey", "Ctrl + Click")), _"Set map elements to the value selected by ‘Set Value’")
38 )45 )
39 )46 )
40}47}
4148
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc 2016-04-06 09:23:04 +0000
+++ src/editor/editorinteractive.cc 2016-04-07 14:03:59 +0000
@@ -441,6 +441,9 @@
441 handled = true;441 handled = true;
442 break;442 break;
443443
444 case SDLK_LCTRL:
445 case SDLK_RCTRL:
446 // TODO(GunChleoc): Keeping ALT and MODE to make the transition easier. Remove for Build 20.
444 case SDLK_LALT:447 case SDLK_LALT:
445 case SDLK_RALT:448 case SDLK_RALT:
446 case SDLK_MODE:449 case SDLK_MODE:
@@ -525,6 +528,9 @@
525 switch (code.sym) {528 switch (code.sym) {
526 case SDLK_LSHIFT:529 case SDLK_LSHIFT:
527 case SDLK_RSHIFT:530 case SDLK_RSHIFT:
531 case SDLK_LCTRL:
532 case SDLK_RCTRL:
533 // TODO(GunChleoc): Keeping ALT and MODE to make the transition easier. Remove for Build 20.
528 case SDLK_LALT:534 case SDLK_LALT:
529 case SDLK_RALT:535 case SDLK_RALT:
530 case SDLK_MODE:536 case SDLK_MODE:
531537
=== modified file 'src/editor/tools/set_port_space_tool.cc'
--- src/editor/tools/set_port_space_tool.cc 2016-04-06 09:23:04 +0000
+++ src/editor/tools/set_port_space_tool.cc 2016-04-07 14:03:59 +0000
@@ -45,7 +45,7 @@
45EditorSetPortSpaceTool::EditorSetPortSpaceTool45EditorSetPortSpaceTool::EditorSetPortSpaceTool
46(EditorUnsetPortSpaceTool & the_unset_tool)46(EditorUnsetPortSpaceTool & the_unset_tool)
47 :47 :
48 EditorTool(the_unset_tool, *this)48 EditorTool(the_unset_tool, the_unset_tool)
49{}49{}
5050
5151
5252
=== modified file 'src/editor/ui_menus/tool_change_height_options_menu.cc'
--- src/editor/ui_menus/tool_change_height_options_menu.cc 2016-04-06 09:23:04 +0000
+++ src/editor/ui_menus/tool_change_height_options_menu.cc 2016-04-07 14:03:59 +0000
@@ -22,177 +22,74 @@
22#include <cstdio>22#include <cstdio>
23#include <string>23#include <string>
2424
25#include <boost/format.hpp>
26
25#include "base/i18n.h"27#include "base/i18n.h"
26#include "editor/editorinteractive.h"28#include "editor/editorinteractive.h"
27#include "editor/tools/increase_height_tool.h"29#include "editor/tools/increase_height_tool.h"
28#include "editor/tools/set_height_tool.h"30#include "editor/tools/set_height_tool.h"
29#include "graphic/graphic.h"31#include "graphic/graphic.h"
30#include "logic/widelands_geometry.h"32#include "logic/widelands_geometry.h"
31#include "ui_basic/button.h"
3233
33#define width 20
34#define height 20
35EditorToolChangeHeightOptionsMenu::EditorToolChangeHeightOptionsMenu34EditorToolChangeHeightOptionsMenu::EditorToolChangeHeightOptionsMenu
36 (EditorInteractive & parent,35 (EditorInteractive & parent,
37 EditorIncreaseHeightTool & increase_tool,36 EditorIncreaseHeightTool & increase_tool,
38 UI::UniqueWindow::Registry & registry)37 UI::UniqueWindow::Registry & registry)
39 :38 :
40 EditorToolOptionsMenu39 EditorToolOptionsMenu(parent, registry, 350, 100, _("Height Tools Options")),
41 (parent, registry, 250, 135, _("Height Tools Options")),
42 increase_tool_(increase_tool),40 increase_tool_(increase_tool),
43 change_by_label_41 box_(this, hmargin(), vmargin(), UI::Box::Vertical, 0, 0, vspacing()),
44 (this,42 change_by_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
45 hmargin(), vmargin(), get_inner_w() - 2 * hmargin(), height,43 increase_tool_.get_change_by(), 1, MAX_FIELD_HEIGHT_DIFF,
46 _("Increase/Decrease Value"), UI::Align::kBottomCenter),44 _("Increase/Decrease Value:"), UI::SpinBox::Units::kNone,
47 change_by_increase_45 g_gr->images().get("images/ui_basic/but1.png"),
48 (this, "incr_change_by",46 UI::SpinBox::Type::kSmall),
49 get_inner_w() - hmargin() - width,47 set_to_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
50 change_by_label_.get_y() + change_by_label_.get_h() + spacing(),48 increase_tool_.set_tool().get_interval().min, 0, MAX_FIELD_HEIGHT,
51 width, height,49 _("Set Value:"), UI::SpinBox::Units::kNone,
52 g_gr->images().get("images/ui_basic/but1.png"),50 g_gr->images().get("images/ui_basic/but1.png"),
53 g_gr->images().get("images/ui_basic/scrollbar_up.png"),51 UI::SpinBox::Type::kSmall)
54 std::string(),
55 increase_tool.get_change_by() < MAX_FIELD_HEIGHT_DIFF),
56 change_by_decrease_
57 (this, "decr_change_by",
58 hmargin(),
59 change_by_increase_.get_y(),
60 width, height,
61 g_gr->images().get("images/ui_basic/but1.png"),
62 g_gr->images().get("images/ui_basic/scrollbar_down.png"),
63 std::string(),
64 1 < increase_tool.get_change_by()),
65 change_by_value_
66 (this,
67 change_by_increase_.get_x() + change_by_increase_.get_w() +
68 hspacing(),
69 change_by_increase_.get_y(),
70 change_by_decrease_.get_x() - hspacing()
71 -
72 (change_by_increase_.get_x() + change_by_increase_.get_w() +
73 hspacing()),
74 height,
75 UI::Align::kBottomCenter),
76 set_to_label_
77 (this,
78 vmargin(),
79 change_by_increase_.get_y() + change_by_increase_.get_h() +
80 vspacing(),
81 get_inner_w() - 2 * hmargin(), height,
82 _("Set Value"), UI::Align::kBottomCenter),
83 set_to_increase_
84 (this, "incr_set_to",
85 change_by_increase_.get_x(),
86 set_to_label_.get_y() + set_to_label_.get_h() + vspacing(),
87 width, height,
88 g_gr->images().get("images/ui_basic/but1.png"),
89 g_gr->images().get("images/ui_basic/scrollbar_up.png"),
90 std::string(),
91 increase_tool.set_tool().get_interval().min < MAX_FIELD_HEIGHT),
92 set_to_decrease_
93 (this, "decr_set_to",
94 hmargin(),
95 set_to_increase_.get_y(),
96 width, height,
97 g_gr->images().get("images/ui_basic/but1.png"),
98 g_gr->images().get("images/ui_basic/scrollbar_down.png"),
99 std::string(),
100 0 < increase_tool.set_tool().get_interval().min),
101 set_to_value_
102 (this,
103 change_by_value_.get_x(), set_to_increase_.get_y(),
104 change_by_value_.get_w(), height,
105 UI::Align::kBottomCenter)
106{52{
107 change_by_increase_.sigclicked.connect53 change_by_.set_tooltip(
108 (boost::bind54 /** TRANSLATORS: Editor change height access keys. **/
109 (&EditorToolChangeHeightOptionsMenu::clicked_change_by_increment, boost::ref(*this)));55 (boost::format(_("Use %s to increase, %s to decrease"))
110 change_by_decrease_.sigclicked.connect56 /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
111 (boost::bind57 % _("Click")
112 (&EditorToolChangeHeightOptionsMenu::clicked_change_by_decrement, boost::ref(*this)));58 /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
113 set_to_increase_.sigclicked.connect59 % _("Shift + Click")).str());
114 (boost::bind(&EditorToolChangeHeightOptionsMenu::clicked_setto_increment, boost::ref(*this)));60 set_to_.set_tooltip(
115 set_to_decrease_.sigclicked.connect61 /** TRANSLATORS: Editor set height access key. **/
116 (boost::bind(&EditorToolChangeHeightOptionsMenu::clicked_setto_decrement, boost::ref(*this)));62 (boost::format(_("Use %s to set to this value"))
11763 /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
118 change_by_increase_.set_repeating(true);64 % _("Ctrl + Click")).str());
119 change_by_decrease_.set_repeating(true);65
120 set_to_increase_ .set_repeating(true);66 change_by_.changed.connect
121 set_to_decrease_ .set_repeating(true);67 (boost::bind
122 update();68 (&EditorToolChangeHeightOptionsMenu::update_change_by, boost::ref(*this)));
123}69 set_to_.changed.connect
12470 (boost::bind
12571 (&EditorToolChangeHeightOptionsMenu::update_set_to, boost::ref(*this)));
126void EditorToolChangeHeightOptionsMenu::clicked_change_by_decrement() {72
127 int32_t change_by = increase_tool_.get_change_by();73 box_.add(&change_by_, UI::Align::kLeft);
128 assert(change_by == increase_tool_.decrease_tool().get_change_by());74 box_.add(&set_to_, UI::Align::kLeft);
129 assert(1 < change_by);75 box_.set_size(get_inner_w() - 2 * hmargin(), change_by_.get_h() + set_to_.get_h() + vspacing());
13076 set_inner_size(box_.get_w() + 2 * hmargin(), box_.get_h() + 2 * vspacing());
131 --change_by;77}
13278
133 increase_tool_ .set_change_by(change_by);79void EditorToolChangeHeightOptionsMenu::update_change_by() {
134 increase_tool_.decrease_tool().set_change_by(change_by);80 int32_t change_by = change_by_.get_value();
135 change_by_decrease_.set_enabled(1 < change_by);81 assert(change_by > 0);
136 change_by_increase_.set_enabled(true);82 assert(change_by <= MAX_FIELD_HEIGHT_DIFF);
137 select_correct_tool();83
138 update();84 increase_tool_ .set_change_by(change_by);
139}85 increase_tool_.decrease_tool().set_change_by(change_by);
14086 select_correct_tool();
14187}
142void EditorToolChangeHeightOptionsMenu::clicked_change_by_increment() {88
143 int32_t change_by = increase_tool_.get_change_by();89void EditorToolChangeHeightOptionsMenu::update_set_to() {
144 assert(change_by == increase_tool_.decrease_tool().get_change_by());90 int32_t set_to = set_to_.get_value();
145 assert(change_by < MAX_FIELD_HEIGHT_DIFF);91 assert(set_to >= 0);
14692 assert(set_to <= MAX_FIELD_HEIGHT);
147 ++change_by;93 increase_tool_.set_tool().set_interval(Widelands::HeightInterval(set_to, set_to));
14894 select_correct_tool();
149 increase_tool_ .set_change_by(change_by);
150 increase_tool_.decrease_tool().set_change_by(change_by);
151 change_by_decrease_.set_enabled(true);
152 change_by_increase_.set_enabled(change_by < MAX_FIELD_HEIGHT_DIFF);
153 select_correct_tool();
154 update();
155}
156
157
158void EditorToolChangeHeightOptionsMenu::clicked_setto_decrement() {
159 Widelands::Field::Height setto =
160 increase_tool_.set_tool().get_interval().min;
161 assert(setto == increase_tool_.set_tool().get_interval().max);
162 assert(0 < setto);
163
164 --setto;
165
166 increase_tool_.set_tool().set_interval
167 (Widelands::HeightInterval(setto, setto));
168 set_to_decrease_.set_enabled(0 < setto);
169 set_to_increase_.set_enabled(true);
170 select_correct_tool();
171 update();
172}
173
174
175void EditorToolChangeHeightOptionsMenu::clicked_setto_increment() {
176 Widelands::Field::Height setto =
177 increase_tool_.set_tool().get_interval().min;
178 assert(setto == increase_tool_.set_tool().get_interval().max);
179 assert(setto < MAX_FIELD_HEIGHT);
180
181 ++setto;
182
183 increase_tool_.set_tool().set_interval
184 (Widelands::HeightInterval(setto, setto));
185 set_to_decrease_.set_enabled(true);
186 set_to_increase_.set_enabled(setto < MAX_FIELD_HEIGHT);
187 select_correct_tool();
188 update();
189}
190
191
192/// Update all the textareas, so that they represent the correct values.
193void EditorToolChangeHeightOptionsMenu::update() {
194 change_by_value_.set_text(std::to_string(increase_tool_.get_change_by()));
195
196 set_to_value_.set_text(std::to_string(
197 static_cast<unsigned int>(increase_tool_.set_tool().get_interval().min)));
198}95}
19996
=== modified file 'src/editor/ui_menus/tool_change_height_options_menu.h'
--- src/editor/ui_menus/tool_change_height_options_menu.h 2016-04-06 09:23:04 +0000
+++ src/editor/ui_menus/tool_change_height_options_menu.h 2016-04-07 14:03:59 +0000
@@ -21,8 +21,8 @@
21#define WL_EDITOR_UI_MENUS_TOOL_CHANGE_HEIGHT_OPTIONS_MENU_H21#define WL_EDITOR_UI_MENUS_TOOL_CHANGE_HEIGHT_OPTIONS_MENU_H
2222
23#include "editor/ui_menus/tool_options_menu.h"23#include "editor/ui_menus/tool_options_menu.h"
24#include "ui_basic/button.h"24#include "ui_basic/box.h"
25#include "ui_basic/textarea.h"25#include "ui_basic/spinbox.h"
2626
27class EditorInteractive;27class EditorInteractive;
28struct EditorIncreaseHeightTool;28struct EditorIncreaseHeightTool;
@@ -37,18 +37,12 @@
3737
38private:38private:
39 EditorIncreaseHeightTool& increase_tool_;39 EditorIncreaseHeightTool& increase_tool_;
40 UI::Textarea change_by_label_;40 UI::Box box_;
41 UI::Button change_by_increase_, change_by_decrease_;41 UI::SpinBox change_by_;
42 UI::Textarea change_by_value_;42 UI::SpinBox set_to_;
43 UI::Textarea set_to_label_;
44 UI::Button set_to_increase_, set_to_decrease_;
45 UI::Textarea set_to_value_;
4643
47 void clicked_change_by_decrement();44 void update_change_by();
48 void clicked_change_by_increment();45 void update_set_to();
49 void clicked_setto_decrement ();
50 void clicked_setto_increment ();
51 void update();
52};46};
5347
54#endif // end of include guard: WL_EDITOR_UI_MENUS_TOOL_CHANGE_HEIGHT_OPTIONS_MENU_H48#endif // end of include guard: WL_EDITOR_UI_MENUS_TOOL_CHANGE_HEIGHT_OPTIONS_MENU_H
5549
=== modified file 'src/editor/ui_menus/tool_change_resources_options_menu.cc'
--- src/editor/ui_menus/tool_change_resources_options_menu.cc 2016-04-06 09:23:04 +0000
+++ src/editor/ui_menus/tool_change_resources_options_menu.cc 2016-04-07 14:03:59 +0000
@@ -22,6 +22,8 @@
22#include <cstdio>22#include <cstdio>
23#include <string>23#include <string>
2424
25#include <boost/format.hpp>
26
25#include "base/i18n.h"27#include "base/i18n.h"
26#include "base/wexception.h"28#include "base/wexception.h"
27#include "editor/editorinteractive.h"29#include "editor/editorinteractive.h"
@@ -33,11 +35,9 @@
33#include "logic/map_objects/world/world.h"35#include "logic/map_objects/world/world.h"
34#include "logic/widelands.h"36#include "logic/widelands.h"
35#include "logic/widelands_geometry.h"37#include "logic/widelands_geometry.h"
36#include "ui_basic/button.h"
37#include "wui/field_overlay_manager.h"38#include "wui/field_overlay_manager.h"
3839
39const static int BUTTON_WIDTH = 20;40constexpr int kMaxValue = 63;
40const static int BUTTON_HEIGHT = 20;
4141
42inline EditorInteractive & EditorToolChangeResourcesOptionsMenu::eia() {42inline EditorInteractive & EditorToolChangeResourcesOptionsMenu::eia() {
43 return dynamic_cast<EditorInteractive&>(*get_parent());43 return dynamic_cast<EditorInteractive&>(*get_parent());
@@ -50,178 +50,114 @@
50 EditorIncreaseResourcesTool & increase_tool,50 EditorIncreaseResourcesTool & increase_tool,
51 UI::UniqueWindow::Registry & registry)51 UI::UniqueWindow::Registry & registry)
52 :52 :
53 EditorToolOptionsMenu53 EditorToolOptionsMenu(parent, registry, 350, 120, _("Resources")),
54 (parent, registry, 250, 120, _("Resources")),54 increase_tool_(increase_tool),
55 change_by_label_55 box_(this, hmargin(), vmargin(), UI::Box::Vertical, 0, 0, vspacing()),
56 (this,56 change_by_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
57 hmargin(), vmargin(), get_inner_w() - 2 * hmargin(), BUTTON_HEIGHT,57 increase_tool_.get_change_by(), 1, kMaxValue,
58 _("Increase/Decrease Value"), UI::Align::kBottomCenter),58 _("Increase/Decrease Value:"), UI::SpinBox::Units::kNone,
59 change_by_increase_59 g_gr->images().get("images/ui_basic/but1.png"),
60 (this, "incr_change_by",60 UI::SpinBox::Type::kSmall),
61 get_inner_w() - hmargin() - BUTTON_WIDTH,61 set_to_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
62 change_by_label_.get_y() + change_by_label_.get_h() + spacing(),62 increase_tool_.set_tool().get_set_to(), 0, kMaxValue,
63 BUTTON_WIDTH, BUTTON_HEIGHT,63 _("Set Value:"), UI::SpinBox::Units::kNone,
64 g_gr->images().get("images/ui_basic/but1.png"),64 g_gr->images().get("images/ui_basic/but1.png"),
65 g_gr->images().get("images/ui_basic/scrollbar_up.png")),65 UI::SpinBox::Type::kSmall),
66 change_by_decrease_66 resources_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, 1),
67 (this, "decr_change_by",67 cur_selection_(&box_, 0, 0, "", UI::Align::kCenter)
68 hmargin(),
69 change_by_increase_.get_y(),
70 BUTTON_WIDTH, BUTTON_HEIGHT,
71 g_gr->images().get("images/ui_basic/but1.png"),
72 g_gr->images().get("images/ui_basic/scrollbar_down.png")),
73 change_by_value_
74 (this,
75 change_by_increase_.get_x() + change_by_increase_.get_w() +
76 hspacing(),
77 change_by_increase_.get_y(),
78 change_by_decrease_.get_x() - hspacing()
79 -
80 (change_by_increase_.get_x() + change_by_increase_.get_w() +
81 hspacing()),
82 BUTTON_HEIGHT,
83 UI::Align::kBottomCenter),
84 set_to_label_
85 (this,
86 vmargin(),
87 change_by_increase_.get_y() + change_by_increase_.get_h() + vspacing(),
88 get_inner_w() - 2 * hmargin(), BUTTON_HEIGHT,
89 _("Set Value"), UI::Align::kBottomCenter),
90 set_to_increase_
91 (this, "incr_set_to",
92 change_by_increase_.get_x(),
93 set_to_label_.get_y() + set_to_label_.get_h() + vspacing(),
94 BUTTON_WIDTH, BUTTON_HEIGHT,
95 g_gr->images().get("images/ui_basic/but1.png"),
96 g_gr->images().get("images/ui_basic/scrollbar_up.png")),
97 set_to_decrease_
98 (this, "decr_set_to",
99 hmargin(),
100 set_to_increase_.get_y(), BUTTON_WIDTH, BUTTON_HEIGHT,
101 g_gr->images().get("images/ui_basic/but1.png"),
102 g_gr->images().get("images/ui_basic/scrollbar_down.png")),
103 set_to_value_
104 (this,
105 change_by_value_.get_x(), set_to_increase_.get_y(),
106 change_by_value_.get_w(), BUTTON_HEIGHT,
107 UI::Align::kBottomCenter),
108 cur_selection_(this, 0, 0, _("Current Selection"), UI::Align::kBottomCenter),
109 increase_tool_(increase_tool)
110{68{
111 change_by_increase_.sigclicked.connect69 // Configure spin boxes
112 (boost::bind70 change_by_.set_tooltip(
113 (&EditorToolChangeResourcesOptionsMenu::clicked_button,71 /** TRANSLATORS: Editor change resources access keys. **/
114 boost::ref(*this),72 (boost::format(_("Use %s to increase, %s to decrease"))
115 Change_By_Increase));73 /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
116 change_by_decrease_.sigclicked.connect74 % _("Click")
117 (boost::bind75 /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
118 (&EditorToolChangeResourcesOptionsMenu::clicked_button,76 % _("Shift + Click")).str());
119 boost::ref(*this),77 set_to_.set_tooltip(
120 Change_By_Decrease));78 /** TRANSLATORS: Editor set resources access key. **/
121 set_to_increase_.sigclicked.connect79 (boost::format(_("Use %s to set to this value"))
122 (boost::bind80 /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
123 (&EditorToolChangeResourcesOptionsMenu::clicked_button,81 % _("Ctrl + Click")).str());
124 boost::ref(*this),82
125 Set_To_Increase));83 change_by_.changed.connect
126 set_to_decrease_.sigclicked.connect84 (boost::bind
127 (boost::bind85 (&EditorToolChangeResourcesOptionsMenu::update_change_by, boost::ref(*this)));
128 (&EditorToolChangeResourcesOptionsMenu::clicked_button,86 set_to_.changed.connect
129 boost::ref(*this),87 (boost::bind
130 Set_To_Decrease));88 (&EditorToolChangeResourcesOptionsMenu::update_set_to, boost::ref(*this)));
13189
132 change_by_increase_.set_repeating(true);90 box_.add(&change_by_, UI::Align::kLeft);
133 change_by_decrease_.set_repeating(true);91 box_.add(&set_to_, UI::Align::kLeft);
134 set_to_increase_ .set_repeating(true);92 box_.set_size(get_inner_w() - 2 * hmargin(), change_by_.get_h() + set_to_.get_h() + vspacing());
135 set_to_decrease_ .set_repeating(true);93
136 const Widelands::World & world = parent.egbase().world();94 // Add resource buttons
137 Widelands::DescriptionIndex const nr_resources = world.get_nr_resources();95 const Widelands::World& world = parent.egbase().world();
13896 const Widelands::DescriptionIndex nr_resources = world.get_nr_resources();
139 // Find the maximal width and height for the resource pictures.97
140 int resource_pic_max_width = 0, resource_pic_max_height = 0;
141 for (Widelands::DescriptionIndex i = 0; i < nr_resources; ++i) {98 for (Widelands::DescriptionIndex i = 0; i < nr_resources; ++i) {
142 const Image* pic = g_gr->images().get(world.get_resource(i)->representative_image());99 const Widelands::ResourceDescription& resource = *world.get_resource(i);
143 resource_pic_max_width = std::max(resource_pic_max_width, pic->width());100 radiogroup_.add_button
144 resource_pic_max_height = std::max(resource_pic_max_height, pic->height());101 (&resources_box_,
102 Point(0, 0),
103 g_gr->images().get(resource.representative_image()),
104 resource.descname());
105 resources_box_.add(radiogroup_.get_first_button(), UI::Align::kLeft, false, true);
145 }106 }
146107
147 const uint16_t resources_in_row =108 box_.add_space(vspacing());
148 (get_inner_w() - 2 * hmargin() + spacing())109 box_.add(&resources_box_, UI::Align::kLeft, true);
149 /110 box_.set_size(box_.get_w(), box_.get_h() + 4 * vspacing() + resources_box_.get_h());
150 (resource_pic_max_width + spacing());111
112 radiogroup_.set_state(increase_tool_.get_cur_res());
151113
152 radiogroup_.changed.connect114 radiogroup_.changed.connect
153 (boost::bind(&EditorToolChangeResourcesOptionsMenu::selected, this));115 (boost::bind(&EditorToolChangeResourcesOptionsMenu::change_resource, this));
154 radiogroup_.clicked.connect116 radiogroup_.clicked.connect
155 (boost::bind(&EditorToolChangeResourcesOptionsMenu::selected, this));117 (boost::bind(&EditorToolChangeResourcesOptionsMenu::change_resource, this));
156118
157 uint16_t cur_x = 0;119 // Add label
158 Point pos120 cur_selection_.set_fixed_width(box_.get_inner_w());
159 (hmargin(), set_to_value_.get_y() + set_to_value_.get_h() + vspacing());121 box_.add(&cur_selection_, UI::Align::kLeft);
160 for122
161 (Widelands::DescriptionIndex i = 0;123 box_.set_size(box_.get_w(), box_.get_h() + vspacing() + cur_selection_.get_h());
162 i < nr_resources;124 set_inner_size(get_inner_w(), box_.get_h() + 1 * vmargin());
163 pos.x += resource_pic_max_width + hspacing(), ++cur_x, ++i)
164 {
165 if (cur_x == resources_in_row) {
166 cur_x = 0;
167 pos.x = hmargin();
168 pos.y += resource_pic_max_height + vspacing();
169 }
170 radiogroup_.add_button
171 (this,
172 pos,
173 g_gr->images().get(world.get_resource(i)->representative_image()));
174 }
175 pos.y += resource_pic_max_height + vspacing();
176
177 set_inner_size(get_inner_w(), pos.y + cur_selection_.get_h() + vmargin());
178 cur_selection_.set_pos(Point(get_inner_w() / 2, pos.y + hspacing()));
179
180 radiogroup_.set_state(increase_tool_.get_cur_res());
181
182 update();125 update();
183}126}
184127
185128void EditorToolChangeResourcesOptionsMenu::update_change_by() {
186void EditorToolChangeResourcesOptionsMenu::clicked_button(Button const n)129 int32_t change_by = change_by_.get_value();
187{130 assert(change_by > 0);
188 assert131 assert(change_by <= kMaxValue);
189 (increase_tool_.get_change_by()
190 ==
191 increase_tool_.decrease_tool().get_change_by());
192
193 int32_t change_by = increase_tool_.get_change_by();
194 int32_t set_to = increase_tool_.set_tool().get_set_to();
195
196 switch (n) {
197 case Change_By_Increase: change_by += change_by < 63; break;
198 case Change_By_Decrease: change_by -= 1 < change_by; break;
199 case Set_To_Increase: set_to += set_to < 63; break;
200 case Set_To_Decrease: set_to -= 0 < set_to;
201 }
202 increase_tool_.set_change_by(change_by);132 increase_tool_.set_change_by(change_by);
203 increase_tool_.decrease_tool().set_change_by(change_by);133 increase_tool_.decrease_tool().set_change_by(change_by);
134 select_correct_tool();
135}
136
137void EditorToolChangeResourcesOptionsMenu::update_set_to() {
138 int32_t set_to = set_to_.get_value();
139 assert(set_to >= 0);
140 assert(set_to <= kMaxValue);
204 increase_tool_.set_tool().set_set_to(set_to);141 increase_tool_.set_tool().set_set_to(set_to);
205
206 select_correct_tool();142 select_correct_tool();
207 update();
208}143}
209144
145
210/**146/**
211 * called when a resource has been selected147 * called when a resource has been selected
212 */148 */
213void EditorToolChangeResourcesOptionsMenu::selected() {149void EditorToolChangeResourcesOptionsMenu::change_resource() {
214 const int32_t resIx = radiogroup_.get_state();150 const int32_t resource_index = radiogroup_.get_state();
215151
216 increase_tool_.set_tool().set_cur_res(resIx);152 increase_tool_.set_tool().set_cur_res(resource_index);
217 increase_tool_.set_cur_res(resIx);153 increase_tool_.set_cur_res(resource_index);
218 increase_tool_.decrease_tool().set_cur_res(resIx);154 increase_tool_.decrease_tool().set_cur_res(resource_index);
219155
220 Widelands::EditorGameBase& egbase = eia().egbase();156 Widelands::EditorGameBase& egbase = eia().egbase();
221 Widelands::Map & map = egbase.map();157 Widelands::Map & map = egbase.map();
222 eia().mutable_field_overlay_manager()->register_overlay_callback_function(158 eia().mutable_field_overlay_manager()->register_overlay_callback_function(
223 [resIx, &map, &egbase](const Widelands::TCoords<Widelands::FCoords>& coords) -> uint32_t {159 [resource_index, &map, &egbase](const Widelands::TCoords<Widelands::FCoords>& coords) -> uint32_t {
224 if (map.is_resource_valid(egbase.world(), coords, resIx)) {160 if (map.is_resource_valid(egbase.world(), coords, resource_index)) {
225 return coords.field->nodecaps();161 return coords.field->nodecaps();
226 }162 }
227 return 0;163 return 0;
@@ -229,7 +165,6 @@
229165
230 map.recalc_whole_map(egbase.world());166 map.recalc_whole_map(egbase.world());
231 select_correct_tool();167 select_correct_tool();
232
233 update();168 update();
234}169}
235170
@@ -237,26 +172,7 @@
237 * Update all the textareas, so that they represent the correct values172 * Update all the textareas, so that they represent the correct values
238*/173*/
239void EditorToolChangeResourcesOptionsMenu::update() {174void EditorToolChangeResourcesOptionsMenu::update() {
240
241 change_by_value_.set_text(std::to_string(increase_tool_.get_change_by()));
242
243 set_to_value_.set_text(std::to_string(
244 static_cast<unsigned int>(increase_tool_.set_tool().get_set_to())));
245
246 cur_selection_.set_text175 cur_selection_.set_text
247 (eia().egbase().world().get_resource(increase_tool_.set_tool().get_cur_res())->descname());176 ((boost::format(_("Current: %s"))
248 cur_selection_.set_pos177 % eia().egbase().world().get_resource(increase_tool_.set_tool().get_cur_res())->descname()).str());
249 (Point
250 ((get_inner_w() - cur_selection_.get_w()) / 2, get_inner_h() - 20));
251
252 {
253 int32_t const change_by = increase_tool_.get_change_by();
254 change_by_decrease_.set_enabled(1 < change_by);
255 change_by_increase_.set_enabled (change_by < 63);
256 }
257 {
258 int32_t const set_to = increase_tool_.set_tool().get_set_to();
259 set_to_decrease_ .set_enabled(0 < set_to);
260 set_to_increase_ .set_enabled (set_to < 63);
261 }
262}178}
263179
=== modified file 'src/editor/ui_menus/tool_change_resources_options_menu.h'
--- src/editor/ui_menus/tool_change_resources_options_menu.h 2016-04-06 09:23:04 +0000
+++ src/editor/ui_menus/tool_change_resources_options_menu.h 2016-04-07 14:03:59 +0000
@@ -21,8 +21,9 @@
21#define WL_EDITOR_UI_MENUS_TOOL_CHANGE_RESOURCES_OPTIONS_MENU_H21#define WL_EDITOR_UI_MENUS_TOOL_CHANGE_RESOURCES_OPTIONS_MENU_H
2222
23#include "editor/ui_menus/tool_options_menu.h"23#include "editor/ui_menus/tool_options_menu.h"
24#include "ui_basic/button.h"24#include "ui_basic/box.h"
25#include "ui_basic/radiobutton.h"25#include "ui_basic/radiobutton.h"
26#include "ui_basic/spinbox.h"
26#include "ui_basic/textarea.h"27#include "ui_basic/textarea.h"
2728
28class EditorInteractive;29class EditorInteractive;
@@ -38,22 +39,18 @@
3839
39private:40private:
40 EditorInteractive & eia();41 EditorInteractive & eia();
41 void selected();42 void change_resource();
42 enum Button {43 void update_change_by();
43 Change_By_Increase, Change_By_Decrease,44 void update_set_to();
44 Set_To_Increase, Set_To_Decrease
45 };
46 void clicked_button(Button);
47 void update();45 void update();
48 UI::Textarea change_by_label_;46
49 UI::Button change_by_increase_, change_by_decrease_;47 EditorIncreaseResourcesTool& increase_tool_;
50 UI::Textarea change_by_value_;48 UI::Box box_;
51 UI::Textarea set_to_label_;49 UI::SpinBox change_by_;
52 UI::Button set_to_increase_, set_to_decrease_;50 UI::SpinBox set_to_;
53 UI::Textarea set_to_value_;51 UI::Box resources_box_;
52 UI::Radiogroup radiogroup_;
54 UI::Textarea cur_selection_;53 UI::Textarea cur_selection_;
55 UI::Radiogroup radiogroup_;
56 EditorIncreaseResourcesTool& increase_tool_;
57};54};
5855
59#endif // end of include guard: WL_EDITOR_UI_MENUS_TOOL_CHANGE_RESOURCES_OPTIONS_MENU_H56#endif // end of include guard: WL_EDITOR_UI_MENUS_TOOL_CHANGE_RESOURCES_OPTIONS_MENU_H
6057
=== modified file 'src/editor/ui_menus/tool_noise_height_options_menu.cc'
--- src/editor/ui_menus/tool_noise_height_options_menu.cc 2016-04-06 09:23:04 +0000
+++ src/editor/ui_menus/tool_noise_height_options_menu.cc 2016-04-07 14:03:59 +0000
@@ -30,236 +30,114 @@
30#include "editor/tools/noise_height_tool.h"30#include "editor/tools/noise_height_tool.h"
31#include "graphic/graphic.h"31#include "graphic/graphic.h"
32#include "logic/widelands_geometry.h"32#include "logic/widelands_geometry.h"
33#include "ui_basic/textarea.h"
3334
3435
35using Widelands::Field;36using Widelands::Field;
3637
37#define width 20
38#define height 20
39EditorToolNoiseHeightOptionsMenu::EditorToolNoiseHeightOptionsMenu38EditorToolNoiseHeightOptionsMenu::EditorToolNoiseHeightOptionsMenu
40 (EditorInteractive & parent,39 (EditorInteractive & parent,
41 EditorNoiseHeightTool & noise_tool,40 EditorNoiseHeightTool & noise_tool,
42 UI::UniqueWindow::Registry & registry)41 UI::UniqueWindow::Registry & registry)
43 :42 :
44 EditorToolOptionsMenu43 EditorToolOptionsMenu(parent, registry, 300, 120, _("Noise Height Options")),
45 (parent, registry, 250, 3 * height + 4 * vspacing() + 2 * vmargin(), _("Noise Height Options")),
46 noise_tool_(noise_tool),44 noise_tool_(noise_tool),
47 lower_label_45 box_(this, hmargin(), vmargin(), UI::Box::Vertical, 0, 0, vspacing()),
48 (this,46 lower_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
49 hmargin(),47 noise_tool_.get_interval().min, 1, MAX_FIELD_HEIGHT,
50 vmargin(),48 _("Minimum Height:"), UI::SpinBox::Units::kNone,
51 width, height,49 g_gr->images().get("images/ui_basic/but1.png"),
52 UI::Align::kLeft),50 UI::SpinBox::Type::kSmall),
53 upper_label_51 upper_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
54 (this,52 noise_tool_.get_interval().max, 0, MAX_FIELD_HEIGHT,
55 hmargin(),53 _("Maximum Height:"), UI::SpinBox::Units::kNone,
56 lower_label_.get_y() + lower_label_.get_h() + 2 * vspacing(),54 g_gr->images().get("images/ui_basic/but1.png"),
57 width, height,55 UI::SpinBox::Type::kSmall),
58 UI::Align::kLeft),56 set_to_(&box_, 0, 0, get_inner_w() - 2 * hmargin(), 80,
59 lower_decrease_57 noise_tool_.set_tool().get_interval().min, 0, MAX_FIELD_HEIGHT,
60 (this, "decr_lower",58 _("Set Value:"), UI::SpinBox::Units::kNone,
61 get_inner_w() - 2 * width - hspacing(),59 g_gr->images().get("images/ui_basic/but1.png"),
62 lower_label_.get_y(),60 UI::SpinBox::Type::kSmall)
63 width, height,
64 g_gr->images().get("images/ui_basic/but0.png"),
65 g_gr->images().get("images/ui_basic/scrollbar_down.png"),
66 std::string(),
67 0 < noise_tool.get_interval().min),
68 lower_increase_
69 (this, "incr_lower",
70 get_inner_w() - width - hspacing(),
71 lower_label_.get_y(),
72 width, height,
73 g_gr->images().get("images/ui_basic/but0.png"),
74 g_gr->images().get("images/ui_basic/scrollbar_up.png"),
75 std::string(),
76 noise_tool.get_interval().min < MAX_FIELD_HEIGHT),
77 upper_decrease_
78 (this, "decr_upper",
79 get_inner_w() - 2 * width - hspacing(),
80 upper_label_.get_y(),
81 width, height,
82 g_gr->images().get("images/ui_basic/but0.png"),
83 g_gr->images().get("images/ui_basic/scrollbar_down.png"),
84 std::string(),
85 0 < noise_tool.get_interval().max),
86 upper_increase_
87 (this, "incr_upper",
88 get_inner_w() - width - hspacing(),
89 upper_label_.get_y(),
90 width, height,
91 g_gr->images().get("images/ui_basic/but0.png"),
92 g_gr->images().get("images/ui_basic/scrollbar_up.png"),
93 std::string(),
94 noise_tool.get_interval().max < MAX_FIELD_HEIGHT),
95 set_label_
96 (this,
97 hmargin(),
98 upper_label_.get_y() + upper_label_.get_h() + 2 * vspacing(),
99 width, height,
100 UI::Align::kLeft),
101 setto_decrease_
102 (this, "decr_set_to",
103 get_inner_w() - 2 * width - hspacing(),
104 set_label_.get_y(),
105 width, height,
106 g_gr->images().get("images/ui_basic/but1.png"),
107 g_gr->images().get("images/ui_basic/scrollbar_down.png"),
108 std::string(),
109 0 < noise_tool.set_tool().get_interval().min),
110 setto_increase_
111 (this, "incr_set_to",
112 get_inner_w() - width - hspacing(),
113 set_label_.get_y(),
114 width, height,
115 g_gr->images().get("images/ui_basic/but1.png"),
116 g_gr->images().get("images/ui_basic/scrollbar_up.png"),
117 std::string(),
118 noise_tool.set_tool().get_interval().max < MAX_FIELD_HEIGHT)
119{61{
120 lower_increase_.sigclicked.connect62 lower_.set_tooltip(
121 (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_lower_increase, boost::ref(*this)));63 /** TRANSLATORS: Editor noise height access keys. **/
122 lower_decrease_.sigclicked.connect64 _("Click to set the height to a random value within the specified range"));
123 (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_lower_decrease, boost::ref(*this)));65 upper_.set_tooltip(
124 upper_increase_.sigclicked.connect66 /** TRANSLATORS: Editor noise height access keys. **/
125 (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_upper_increase, boost::ref(*this)));67 _("Click to set the height to a random value within the specified range"));
126 upper_decrease_.sigclicked.connect68 set_to_.set_tooltip(
127 (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_upper_decrease, boost::ref(*this)));69 /** TRANSLATORS: Editor set hoise height access keys. **/
128 setto_increase_.sigclicked.connect70 (boost::format(_("Use %s to set to this value"))
129 (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_setto_increase, boost::ref(*this)));71 /** TRANSLATORS: This is an access key combination. Localize, but do not change the key. **/
130 setto_decrease_.sigclicked.connect72 % _("Ctrl + Click")).str());
131 (boost::bind(&EditorToolNoiseHeightOptionsMenu::clicked_setto_decrease, boost::ref(*this)));73
13274 lower_.changed.connect
133 lower_increase_.set_repeating(true);75 (boost::bind
134 lower_decrease_.set_repeating(true);76 (&EditorToolNoiseHeightOptionsMenu::update_lower, boost::ref(*this)));
135 upper_increase_.set_repeating(true);77 upper_.changed.connect
136 upper_decrease_.set_repeating(true);78 (boost::bind
137 setto_increase_.set_repeating(true);79 (&EditorToolNoiseHeightOptionsMenu::update_upper, boost::ref(*this)));
138 setto_decrease_.set_repeating(true);80 set_to_.changed.connect
139 update();81 (boost::bind
140}82 (&EditorToolNoiseHeightOptionsMenu::update_set_to, boost::ref(*this)));
14183
142/**84 UI::Textarea* label = new UI::Textarea(&box_, 0, 0, 0, 0, _("Random Height"), UI::Align::kCenter);
143 * Update all textareas85 label->set_fixed_width(get_inner_w() - 2 * hmargin());
144*/86 box_.add(label, UI::Align::kLeft);
145void EditorToolNoiseHeightOptionsMenu::update() {87 box_.add(&upper_, UI::Align::kLeft);
146 const Widelands::HeightInterval height_interval = noise_tool_.get_interval();88 box_.add(&lower_, UI::Align::kLeft);
14789
148 lower_label_.set_text((boost::format(_("Minimum: %u"))90 box_.add_space(2 * vspacing());
149 % static_cast<unsigned int>(height_interval.min)).str());91 label = new UI::Textarea(&box_, 0, 0, 0, 0, _("Fixed Height"), UI::Align::kCenter);
15092 label->set_fixed_width(get_inner_w() - 2 * hmargin());
151 upper_label_.set_text((boost::format(_("Maximum: %u"))93 box_.add(label, UI::Align::kLeft);
152 % static_cast<unsigned int>(height_interval.max)).str());94 box_.add(&set_to_, UI::Align::kLeft);
15395
154 set_label_.set_text((boost::format(_("Set value: %u"))96 box_.set_size(get_inner_w() - 2 * hmargin(),
155 % static_cast<unsigned int>(noise_tool_.set_tool().get_interval().min)).str());97 upper_.get_h() + lower_.get_h() + set_to_.get_h() + 2 * label->get_h() + 7 * vspacing());
15698
157 select_correct_tool();99 set_inner_size(box_.get_w() + 2 * hmargin(), box_.get_h() + 2 * vspacing());
158}100}
159101
160102
161void EditorToolNoiseHeightOptionsMenu::clicked_lower_decrease() {103void EditorToolNoiseHeightOptionsMenu::update_lower() {
162 Widelands::HeightInterval height_interval = noise_tool_.get_interval();104 int32_t upper = upper_.get_value();
163105 int32_t lower = lower_.get_value();
164 assert(height_interval.valid());106 // Make sure that upper increases if necessary
165 assert(0 < height_interval.min);107 upper = std::max(lower, upper);
166108 lower = std::min(lower, upper);
167 --height_interval.min;109 update_interval(lower, upper);
168110}
169 assert(height_interval.valid());111
170112
171 noise_tool_.set_interval(height_interval);113void EditorToolNoiseHeightOptionsMenu::update_upper() {
172 lower_decrease_.set_enabled(0 < height_interval.min);114 int32_t upper = upper_.get_value();
173 lower_increase_.set_enabled(true);115 int32_t lower = lower_.get_value();
174 update();116 // Make sure that lower decreases if necessary
175}117 lower = std::min(lower, upper);
176118 upper = std::max(lower, upper);
177119 update_interval(lower, upper);
178void EditorToolNoiseHeightOptionsMenu::clicked_lower_increase() {120}
179 Widelands::HeightInterval height_interval = noise_tool_.get_interval();121
180122void EditorToolNoiseHeightOptionsMenu::update_interval(int32_t lower, int32_t upper) {
181 assert(height_interval.valid());123 assert(lower >= 0);
182 assert(height_interval.min < MAX_FIELD_HEIGHT);124 assert(lower <= MAX_FIELD_HEIGHT);
183125 assert(upper >= 0);
184 ++height_interval.min;126 assert(upper <= MAX_FIELD_HEIGHT);
185 height_interval.max = std::max(height_interval.min, height_interval.max);127
186128 Widelands::HeightInterval height_interval(lower, upper);
187 assert(height_interval.valid());129 assert(height_interval.valid());
188130
189 noise_tool_.set_interval(height_interval);131 lower_.set_value(height_interval.min);
190 lower_decrease_.set_enabled(true);132 upper_.set_value(height_interval.max);
191 lower_increase_.set_enabled(height_interval.min < MAX_FIELD_HEIGHT);133 noise_tool_.set_interval(height_interval);
192 upper_decrease_.set_enabled(true);134 select_correct_tool();
193 upper_increase_.set_enabled(height_interval.max < MAX_FIELD_HEIGHT);135}
194136
195 update();137void EditorToolNoiseHeightOptionsMenu::update_set_to() {
196}138 int32_t set_to = set_to_.get_value();
197139 assert(set_to >= 0);
198140 assert(set_to <= MAX_FIELD_HEIGHT);
199void EditorToolNoiseHeightOptionsMenu::clicked_upper_decrease() {141 noise_tool_.set_tool().set_interval(Widelands::HeightInterval(set_to, set_to));
200 Widelands::HeightInterval height_interval = noise_tool_.get_interval();142 select_correct_tool();
201
202 assert(height_interval.valid());
203 assert(0 < noise_tool_.get_interval().max);
204
205 --height_interval.max;
206 height_interval.min = std::min(height_interval.min, height_interval.max);
207
208 assert(height_interval.valid());
209
210 noise_tool_.set_interval(height_interval);
211 lower_decrease_.set_enabled(0 < height_interval.min);
212 lower_increase_.set_enabled(true);
213 upper_decrease_.set_enabled(0 < height_interval.max);
214 upper_increase_.set_enabled(true);
215 update();
216}
217
218
219void EditorToolNoiseHeightOptionsMenu::clicked_upper_increase() {
220 Widelands::HeightInterval height_interval = noise_tool_.get_interval();
221
222 assert(noise_tool_.get_interval().valid());
223 assert(noise_tool_.get_interval().max < MAX_FIELD_HEIGHT);
224
225 ++height_interval.max;
226
227 assert(noise_tool_.get_interval().valid());
228
229 noise_tool_.set_interval(height_interval);
230 upper_decrease_.set_enabled(true);
231 upper_increase_.set_enabled(height_interval.max < MAX_FIELD_HEIGHT);
232 update();
233}
234
235
236void EditorToolNoiseHeightOptionsMenu::clicked_setto_decrease() {
237 EditorSetHeightTool & set_tool = noise_tool_.set_tool();
238 Field::Height h = set_tool.get_interval().min;
239
240 assert(h == set_tool.get_interval().max);
241 assert(0 < h);
242
243 --h;
244
245 set_tool.set_interval(Widelands::HeightInterval(h, h));
246 setto_decrease_.set_enabled(0 < h);
247 setto_increase_.set_enabled(true);
248 update();
249}
250
251
252void EditorToolNoiseHeightOptionsMenu::clicked_setto_increase() {
253 EditorSetHeightTool & set_tool = noise_tool_.set_tool();
254 Field::Height h = set_tool.get_interval().min;
255
256 assert(h == set_tool.get_interval().max);
257 assert(h < MAX_FIELD_HEIGHT);
258
259 ++h;
260
261 set_tool.set_interval(Widelands::HeightInterval(h, h));
262 setto_decrease_.set_enabled(true);
263 setto_increase_.set_enabled(h < MAX_FIELD_HEIGHT);
264 update();
265}143}
266144
=== modified file 'src/editor/ui_menus/tool_noise_height_options_menu.h'
--- src/editor/ui_menus/tool_noise_height_options_menu.h 2016-04-06 09:23:04 +0000
+++ src/editor/ui_menus/tool_noise_height_options_menu.h 2016-04-07 14:03:59 +0000
@@ -21,8 +21,8 @@
21#define WL_EDITOR_UI_MENUS_TOOL_NOISE_HEIGHT_OPTIONS_MENU_H21#define WL_EDITOR_UI_MENUS_TOOL_NOISE_HEIGHT_OPTIONS_MENU_H
2222
23#include "editor/ui_menus/tool_options_menu.h"23#include "editor/ui_menus/tool_options_menu.h"
24#include "ui_basic/button.h"24#include "ui_basic/box.h"
25#include "ui_basic/textarea.h"25#include "ui_basic/spinbox.h"
2626
27class EditorInteractive;27class EditorInteractive;
28struct EditorNoiseHeightTool;28struct EditorNoiseHeightTool;
@@ -34,19 +34,15 @@
34 UI::UniqueWindow::Registry &);34 UI::UniqueWindow::Registry &);
3535
36private:36private:
37 void update_interval(int32_t lower, int32_t upper);
38 void update_upper();
39 void update_lower();
40 void update_set_to();
41
37 EditorNoiseHeightTool& noise_tool_;42 EditorNoiseHeightTool& noise_tool_;
38 UI::Textarea lower_label_, upper_label_;43 UI::Box box_;
39 UI::Button lower_decrease_, lower_increase_, upper_decrease_, upper_increase_;44 UI::SpinBox lower_, upper_;
40 UI::Textarea set_label_;45 UI::SpinBox set_to_;
41 UI::Button setto_decrease_, setto_increase_;
42
43 void clicked_lower_decrease();
44 void clicked_lower_increase();
45 void clicked_upper_decrease();
46 void clicked_upper_increase();
47 void clicked_setto_decrease();
48 void clicked_setto_increase();
49 void update();
50};46};
5147
52#endif // end of include guard: WL_EDITOR_UI_MENUS_TOOL_NOISE_HEIGHT_OPTIONS_MENU_H48#endif // end of include guard: WL_EDITOR_UI_MENUS_TOOL_NOISE_HEIGHT_OPTIONS_MENU_H
5349
=== modified file 'src/ui_basic/spinbox.cc'
--- src/ui_basic/spinbox.cc 2016-04-01 12:22:09 +0000
+++ src/ui_basic/spinbox.cc 2016-04-07 14:03:59 +0000
@@ -254,6 +254,7 @@
254void SpinBox::change_value(int32_t const value)254void SpinBox::change_value(int32_t const value)
255{255{
256 set_value(value + sbi_->value);256 set_value(value + sbi_->value);
257 changed();
257}258}
258259
259260
260261
=== modified file 'src/ui_basic/spinbox.h'
--- src/ui_basic/spinbox.h 2016-03-26 18:57:47 +0000
+++ src/ui_basic/spinbox.h 2016-04-07 14:03:59 +0000
@@ -23,6 +23,8 @@
23#include <cstring>23#include <cstring>
24#include <list>24#include <list>
2525
26#include <boost/signals2.hpp>
27
26#include "graphic/align.h"28#include "graphic/align.h"
27#include "ui_basic/box.h"29#include "ui_basic/box.h"
28#include "ui_basic/button.h"30#include "ui_basic/button.h"
@@ -63,6 +65,8 @@
63 int32_t step_size = 1, int32_t big_step_size = 10);65 int32_t step_size = 1, int32_t big_step_size = 10);
64 ~SpinBox();66 ~SpinBox();
6567
68 boost::signals2::signal<void ()> changed;
69
66 void set_value(int32_t);70 void set_value(int32_t);
67 // For spinboxes of type kValueList. The vector needs to be sorted in ascending order,71 // For spinboxes of type kValueList. The vector needs to be sorted in ascending order,
68 // otherwise you will confuse the user.72 // otherwise you will confuse the user.

Subscribers

People subscribed via source and target branches

to status/vote changes: