Merge lp:~widelands-dev/widelands/fix_resource_overlay into lp:widelands

Proposed by SirVer
Status: Merged
Merged at revision: 7707
Proposed branch: lp:~widelands-dev/widelands/fix_resource_overlay
Merge into: lp:widelands
Diff against target: 2964 lines (+639/-590)
60 files modified
src/editor/CMakeLists.txt (+2/-1)
src/editor/editorinteractive.cc (+150/-101)
src/editor/editorinteractive.h (+82/-60)
src/editor/map_generator.cc (+1/-2)
src/editor/tools/editor_action_args.h (+1/-1)
src/editor/tools/editor_decrease_resources_tool.cc (+3/-4)
src/editor/tools/editor_delete_bob_tool.cc (+1/-1)
src/editor/tools/editor_delete_immovable_tool.cc (+1/-1)
src/editor/tools/editor_history.cc (+0/-9)
src/editor/tools/editor_history.h (+1/-8)
src/editor/tools/editor_increase_resources_tool.cc (+2/-3)
src/editor/tools/editor_set_origin_tool.cc (+6/-6)
src/editor/tools/editor_set_port_space_tool.cc (+2/-2)
src/editor/tools/editor_set_resources_tool.cc (+4/-38)
src/editor/tools/editor_set_resources_tool.h (+0/-11)
src/editor/tools/editor_tool.h (+1/-1)
src/editor/tools/editor_tool_action.h (+1/-1)
src/editor/ui_menus/editor_main_menu.h (+1/-1)
src/editor/ui_menus/editor_main_menu_load_map.cc (+1/-3)
src/editor/ui_menus/editor_main_menu_map_options.h (+1/-1)
src/editor/ui_menus/editor_main_menu_new_map.cc (+1/-5)
src/editor/ui_menus/editor_main_menu_new_map.h (+1/-1)
src/editor/ui_menus/editor_main_menu_random_map.cc (+1/-6)
src/editor/ui_menus/editor_main_menu_random_map.h (+1/-1)
src/editor/ui_menus/editor_player_menu.cc (+6/-6)
src/editor/ui_menus/editor_player_menu.h (+1/-1)
src/editor/ui_menus/editor_tool_change_height_options_menu.h (+1/-1)
src/editor/ui_menus/editor_tool_change_resources_options_menu.cc (+2/-2)
src/editor/ui_menus/editor_tool_change_resources_options_menu.h (+1/-1)
src/editor/ui_menus/editor_tool_menu.cc (+34/-34)
src/editor/ui_menus/editor_tool_menu.h (+1/-1)
src/editor/ui_menus/editor_tool_noise_height_options_menu.h (+1/-1)
src/editor/ui_menus/editor_tool_options_menu.cc (+1/-1)
src/editor/ui_menus/editor_tool_place_immovable_options_menu.h (+1/-1)
src/editor/ui_menus/editor_tool_set_terrain_options_menu.h (+1/-1)
src/editor/ui_menus/editor_toolsize_menu.cc (+1/-1)
src/editor/ui_menus/editor_toolsize_menu.h (+1/-1)
src/logic/field.h (+1/-9)
src/logic/map.cc (+55/-19)
src/logic/map.h (+24/-6)
src/logic/map_objects/tribes/production_program.cc (+1/-2)
src/logic/map_objects/tribes/worker.cc (+2/-4)
src/logic/player.cc (+3/-3)
src/logic/player.h (+2/-1)
src/map_io/map_resources_packet.cc (+3/-2)
src/map_io/s2map.cc (+11/-11)
src/notifications/note_ids.h (+2/-1)
src/scripting/lua_map.cc (+14/-11)
src/ui_basic/panel.h (+2/-1)
src/wui/field_overlay_manager.cc (+6/-0)
src/wui/field_overlay_manager.h (+4/-0)
src/wui/fieldaction.cc (+3/-4)
src/wui/interactive_base.cc (+116/-124)
src/wui/interactive_base.h (+35/-35)
src/wui/interactive_gamebase.cc (+4/-4)
src/wui/interactive_gamebase.h (+1/-1)
src/wui/interactive_player.cc (+13/-13)
src/wui/interactive_spectator.cc (+12/-12)
test/maps/lua_testsuite.wmf/scripting/efield.lua (+1/-1)
test/maps/lua_testsuite.wmf/scripting/gfield.lua (+7/-6)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fix_resource_overlay
Reviewer Review Type Date Requested Status
GunChleoc Approve
kaputtnik (community) correct functionality Approve
Review via email: mp+282680@code.launchpad.net

Commit message

- Make mutating of field resources only possible through the map, no longer through the field interface. This allows the Map to decide if and which notifications it needs to send.
- Editor's resource overlays are completely handled in the EditorInteractive class which listens for change notifications from the map.

Description of the change

Fixes bug 977980 - display of overlays.

I decided on a slightly more involve fix that added some symmetry between resources and terrains to the code and decoupled UI from logic through the use of notifications.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Hi, I am bunnybot (https://github.com/widelands/bunnybot).

I am keeping the source branch lp:~widelands-dev/widelands/fix_resource_overlay mirrored to https://github.com/widelands/widelands/tree/_widelands_dev_widelands_fix_resource_overlay

You can give me commands by starting a line with @bunnybot <command>. I understand:
 merge: Merges the source branch into the target branch, closing the merge proposal. I will use the proposed commit message if it is set.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 267 has changed state to: passed. Details: https://travis-ci.org/widelands/widelands/builds/102491117.

Revision history for this message
kaputtnik (franku) wrote :

Works again :-)

Approve for functionality. One has to look at the code though.

The other linked Bug "Set Origin" isn't solved with this branch, so i remove the link.

review: Approve
Revision history for this message
kaputtnik (franku) wrote :

Found one thing: The layer isn't destroyed when loading a map or creating a new map. The previous placed resources are still shown. This is very confusing if one creates a random maps, which may not look good and create another random map. So the second map shows also the resources from previous random map.

See also: bug 1521736 (editor does not clean up memory (?) when loading another map)

review: Needs Fixing
Revision history for this message
SirVer (sirver) wrote :

Thanks for testing!

I changed the code to close all child windows in the editor and close all windows when the map changes. that also means when the map origin changes (because that changes the whole map).

Revision history for this message
kaputtnik (franku) wrote :

Sorry, one crash after another...

Start editor, create a new map -> crash.

Start editor, create a random map, -> crash. On time got a hint in console:

WARNING: Could not find a suitable place for player 1
Speicherzugriffsfehler (Speicherabzug geschrieben)

review: Needs Fixing
Revision history for this message
SirVer (sirver) wrote :

> Sorry, one crash after another...

no need to apologize. I apologize for amateur-programming night tonight :/

next try. Could you take it for a spin?

Revision history for this message
kaputtnik (franku) wrote :

Works now... until one thing related to bug 1521736 :

Loading another map or create a new map does not reset tool size and former chosen resources or terrain are still used. If you have enabled the info tool and load/create another map the pointer is still the info tool.

I would expect that loading another map would reset all input, just like it is when starting the editor.

Seems to be a never ending story :-D

Revision history for this message
SirVer (sirver) wrote :

Next try. Tools were very differently coupled than uI, so that was a little more work. But I agree that it makes sense. Could you have another look?

Revision history for this message
kaputtnik (franku) wrote :

Looks very good now :-)

There are some compiler statements/warnings. Because i am not sure to which code they belong, or if they are importand, i write them down here:

1. /src/editor/editorinteractive.cc:134: No space after opening brace allowed!
2. /src/editor/editorinteractive.cc:135: No space after opening brace allowed!
3. /src/editor/editorinteractive.cc:635:9: Warnung: Die Standardfallbehandlung in switch fehlt [-Wswitch-default]
  switch (action) {
4. /src/scripting/lua_map.cc:4483: A space is mandatory after catch/for/if/switch/throw/while.
5. /src/editor/ui_menus/editor_tool_change_resources_options_menu.cc:226: Bad indentation.

Thanks for your work so far :-)

Approving functionality.

review: Approve (correct functionality)
Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM, just 1 code style nit.

I noticed that you use variable type "auto" a lot - please double-check if you can be more specific. Strong typing is good ;)

review: Approve
Revision history for this message
SirVer (sirver) wrote :

I fixed everything but

3. /src/editor/editorinteractive.cc:635:9: Warnung: Die Standardfallbehandlung in switch fehlt [-Wswitch-default]

that is a stupid warning. I handled all possible cases in this switch() statement for the enum class it handles. The default: should never be taken, so it should actually not be there. I prepare a branch to remove this warning.

> I noticed that you use variable type "auto" a lot - please double-check if you can be more specific. Strong typing is good ;)

auto is not any less strong typing, since the compiler knows the exact type. In fact auto can be stronger typing than explicit types because it never does implicit conversion.

int32_t a = 1;
uint8_t b = 9;
uint8_t c = a - b; // is a bug, underflow.
auto c = a - b; // works, means type of c == int32_t, so all is good.

If you feel it impedes readability in a specific place, I will add types of course.

@bunnybot merge

Revision history for this message
GunChleoc (gunchleoc) wrote :

Fine by me, thanks for explaining.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/CMakeLists.txt'
2--- src/editor/CMakeLists.txt 2016-01-10 11:36:05 +0000
3+++ src/editor/CMakeLists.txt 2016-01-16 15:57:59 +0000
4@@ -96,6 +96,7 @@
5 logic_widelands_geometry
6 map_io
7 map_io_map_loader
8+ notifications
9 random
10 scripting_lua_interface
11 scripting_lua_table
12@@ -104,6 +105,6 @@
13 widelands_ball_of_mud
14 wui
15 wui_common
16+ wui_field_overlay_manager
17 wui_mapview_pixelfunctions
18- wui_field_overlay_manager
19 )
20
21=== modified file 'src/editor/editorinteractive.cc'
22--- src/editor/editorinteractive.cc 2016-01-10 11:36:05 +0000
23+++ src/editor/editorinteractive.cc 2016-01-16 15:57:59 +0000
24@@ -62,71 +62,89 @@
25 egbase->tribes();
26 }
27
28+// Updates the resources overlays after a field has changed.
29+void update_resource_overlay(const Widelands::NoteFieldResourceChanged& note,
30+ const Widelands::World& world,
31+ FieldOverlayManager* field_overlay_manager) {
32+ // Ok, we're doing something. First remove the current overlays.
33+ if (note.old_resource != Widelands::kNoResource) {
34+ const std::string str =
35+ world.get_resource(note.old_resource)->get_editor_pic(note.old_amount);
36+ const Image* pic = g_gr->images().get(str);
37+ field_overlay_manager->remove_overlay(note.fc, pic);
38+ }
39+
40+ const auto amount = note.fc.field->get_resources_amount();
41+ const auto resource_type = note.fc.field->get_resources();
42+ if (amount > 0 && resource_type != Widelands::kNoResource) {
43+ const std::string str =
44+ world.get_resource(note.fc.field->get_resources())->get_editor_pic(amount);
45+ const Image* pic = g_gr->images().get(str);
46+ field_overlay_manager->register_overlay(note.fc, pic, 0);
47+ }
48+}
49+
50 } // namespace
51
52 EditorInteractive::EditorInteractive(Widelands::EditorGameBase & e) :
53 InteractiveBase(e, g_options.pull_section("global")),
54- m_need_save(false),
55- m_realtime(SDL_GetTicks()),
56- m_left_mouse_button_is_down(false),
57- m_history(m_undo, m_redo),
58+ need_save_(false),
59+ realtime_(SDL_GetTicks()),
60+ left_mouse_button_is_down_(false),
61+ tools_(new Tools()),
62+ history_(new EditorHistory(undo_, redo_)),
63
64 #define INIT_BUTTON(picture, name, tooltip) \
65 TOOLBAR_BUTTON_COMMON_PARAMETERS(name), \
66 g_gr->images().get("pics/" picture ".png"), \
67 tooltip \
68
69- m_toggle_main_menu
70+ toggle_main_menu_
71 (INIT_BUTTON
72 ("menu_toggle_menu", "menu", _("Menu"))),
73- m_toggle_tool_menu
74+ toggle_tool_menu_
75 (INIT_BUTTON
76 ("editor_menu_toggle_tool_menu", "tools", _("Tools"))),
77- m_toggle_toolsize_menu
78+ toggle_toolsize_menu_
79 (INIT_BUTTON
80 ("editor_menu_set_toolsize_menu", "toolsize",
81 _("Tool Size"))),
82- m_toggle_minimap
83+ toggle_minimap_
84 (INIT_BUTTON
85 ("menu_toggle_minimap", "minimap", _("Minimap"))),
86- m_toggle_buildhelp
87+ toggle_buildhelp_
88 (INIT_BUTTON
89 ("menu_toggle_buildhelp", "buildhelp", _("Show Building Spaces (on/off)"))),
90- m_toggle_player_menu
91+ toggle_player_menu_
92 (INIT_BUTTON
93 ("editor_menu_player_menu", "players", _("Players"))),
94- m_undo
95+ undo_
96 (INIT_BUTTON
97 ("editor_undo", "undo", _("Undo"))),
98- m_redo
99+ redo_
100 (INIT_BUTTON
101 ("editor_redo", "redo", _("Redo")))
102 {
103- m_toggle_main_menu.sigclicked.connect(boost::bind(&EditorInteractive::toggle_mainmenu, this));
104- m_toggle_tool_menu.sigclicked.connect(boost::bind(&EditorInteractive::tool_menu_btn, this));
105- m_toggle_toolsize_menu.sigclicked.connect(boost::bind(&EditorInteractive::toolsize_menu_btn, this));
106- m_toggle_minimap.sigclicked.connect(boost::bind(&EditorInteractive::toggle_minimap, this));
107- m_toggle_buildhelp.sigclicked.connect(boost::bind(&EditorInteractive::toggle_buildhelp, this));
108- m_toggle_player_menu.sigclicked.connect(boost::bind(&EditorInteractive::toggle_playermenu, this));
109- m_undo.sigclicked.connect(
110- boost::bind(&EditorHistory::undo_action, &m_history, boost::cref(egbase().world())));
111- m_redo.sigclicked.connect(
112- boost::bind(&EditorHistory::redo_action, &m_history, boost::cref(egbase().world())));
113+ toggle_main_menu_.sigclicked.connect(boost::bind(&EditorInteractive::toggle_mainmenu, this));
114+ toggle_tool_menu_.sigclicked.connect(boost::bind(&EditorInteractive::tool_menu_btn, this));
115+ toggle_toolsize_menu_.sigclicked.connect(boost::bind(&EditorInteractive::toolsize_menu_btn, this));
116+ toggle_minimap_.sigclicked.connect(boost::bind(&EditorInteractive::toggle_minimap, this));
117+ toggle_buildhelp_.sigclicked.connect(boost::bind(&EditorInteractive::toggle_buildhelp, this));
118+ toggle_player_menu_.sigclicked.connect(boost::bind(&EditorInteractive::toggle_playermenu, this));
119+ undo_.sigclicked.connect([this] {history_->undo_action(egbase().world());});
120+ redo_.sigclicked.connect([this] {history_->redo_action(egbase().world());});
121
122- m_toolbar.set_layout_toplevel(true);
123- m_toolbar.add(&m_toggle_main_menu, UI::Box::AlignLeft);
124- m_toolbar.add(&m_toggle_tool_menu, UI::Box::AlignLeft);
125- m_toolbar.add(&m_toggle_toolsize_menu, UI::Box::AlignLeft);
126- m_toolbar.add(&m_toggle_minimap, UI::Box::AlignLeft);
127- m_toolbar.add(&m_toggle_buildhelp, UI::Box::AlignLeft);
128- m_toolbar.add(&m_toggle_player_menu, UI::Box::AlignLeft);
129- m_toolbar.add(&m_undo, UI::Box::AlignLeft);
130- m_toolbar.add(&m_redo, UI::Box::AlignLeft);
131+ toolbar_.set_layout_toplevel(true);
132+ toolbar_.add(&toggle_main_menu_, UI::Box::AlignLeft);
133+ toolbar_.add(&toggle_tool_menu_, UI::Box::AlignLeft);
134+ toolbar_.add(&toggle_toolsize_menu_, UI::Box::AlignLeft);
135+ toolbar_.add(&toggle_minimap_, UI::Box::AlignLeft);
136+ toolbar_.add(&toggle_buildhelp_, UI::Box::AlignLeft);
137+ toolbar_.add(&toggle_player_menu_, UI::Box::AlignLeft);
138+ toolbar_.add(&undo_, UI::Box::AlignLeft);
139+ toolbar_.add(&redo_, UI::Box::AlignLeft);
140 adjust_toolbar_position();
141
142- m_undo.set_enabled(false);
143- m_redo.set_enabled(false);
144-
145 #ifndef NDEBUG
146 set_display_flag(InteractiveBase::dfDebug, true);
147 #else
148@@ -134,6 +152,13 @@
149 #endif
150
151 fieldclicked.connect(boost::bind(&EditorInteractive::map_clicked, this, false));
152+
153+ // Subscribe to changes of the resource type on a field..
154+ field_resource_changed_subscriber_ =
155+ Notifications::subscribe<Widelands::NoteFieldResourceChanged>(
156+ [this](const Widelands::NoteFieldResourceChanged& note) {
157+ update_resource_overlay(note, egbase().world(), mutable_field_overlay_manager());
158+ });
159 }
160
161 void EditorInteractive::register_overlays() {
162@@ -175,7 +200,6 @@
163 // TODO(unknown): get rid of cleanup_for_load, it tends to be very messy
164 // Instead, delete and re-create the egbase.
165 egbase().cleanup_for_load();
166- m_history.reset();
167
168 std::unique_ptr<Widelands::MapLoader> ml(map.get_correct_loader(filename));
169 if (!ml.get())
170@@ -189,8 +213,6 @@
171 std::vector<std::string> tipstext;
172 tipstext.push_back("editor");
173
174- m_history.reset();
175-
176 GameTips editortips(loader_ui, tipstext);
177
178 load_all_tribes(&egbase(), &loader_ui);
179@@ -202,12 +224,8 @@
180 }
181
182 ml->load_map_complete(egbase(), true);
183-
184 egbase().load_graphics(loader_ui);
185-
186- register_overlays();
187-
188- set_need_save(false);
189+ map_changed(MapWas::kReplaced);
190 }
191
192
193@@ -219,7 +237,7 @@
194 } catch (LuaScriptNotExistingError &) {
195 // do nothing.
196 }
197- show_buildhelp(true);
198+ map_changed(MapWas::kReplaced);
199 }
200
201
202@@ -231,17 +249,17 @@
203 void EditorInteractive::think() {
204 InteractiveBase::think();
205
206- uint32_t lasttime = m_realtime;
207-
208- m_realtime = SDL_GetTicks();
209-
210- egbase().get_gametime_pointer() += m_realtime - lasttime;
211+ uint32_t lasttime = realtime_;
212+
213+ realtime_ = SDL_GetTicks();
214+
215+ egbase().get_gametime_pointer() += realtime_ - lasttime;
216 }
217
218
219
220 void EditorInteractive::exit() {
221- if (m_need_save) {
222+ if (need_save_) {
223 if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL)) {
224 end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
225 } else {
226@@ -258,30 +276,28 @@
227 }
228
229 void EditorInteractive::toggle_mainmenu() {
230- if (m_mainmenu.window)
231- delete m_mainmenu.window;
232+ if (mainmenu_.window)
233+ delete mainmenu_.window;
234 else
235- new EditorMainMenu(*this, m_mainmenu);
236+ new EditorMainMenu(*this, mainmenu_);
237 }
238
239 void EditorInteractive::map_clicked(bool should_draw) {
240- m_history.do_action
241- (tools.current(),
242- tools.use_tool, egbase().map(), egbase().world(),
243- get_sel_pos(), *this, should_draw);
244+ history_->do_action(tools_->current(), tools_->use_tool, egbase().map(), egbase().world(),
245+ get_sel_pos(), *this, should_draw);
246 set_need_save(true);
247 }
248
249 bool EditorInteractive::handle_mouserelease(uint8_t btn, int32_t x, int32_t y) {
250 if (btn == SDL_BUTTON_LEFT) {
251- m_left_mouse_button_is_down = false;
252+ left_mouse_button_is_down_ = false;
253 }
254 return InteractiveBase::handle_mouserelease(btn, x, y);
255 }
256
257 bool EditorInteractive::handle_mousepress(uint8_t btn, int32_t x, int32_t y) {
258 if (btn == SDL_BUTTON_LEFT) {
259- m_left_mouse_button_is_down = true;
260+ left_mouse_button_is_down_ = true;
261 }
262 return InteractiveBase::handle_mousepress(btn, x, y);
263 }
264@@ -289,44 +305,44 @@
265 /// Needed to get freehand painting tools (hold down mouse and move to edit).
266 void EditorInteractive::set_sel_pos(Widelands::NodeAndTriangle<> const sel) {
267 bool const target_changed =
268- tools.current().operates_on_triangles() ?
269+ tools_->current().operates_on_triangles() ?
270 sel.triangle != get_sel_pos().triangle : sel.node != get_sel_pos().node;
271 InteractiveBase::set_sel_pos(sel);
272- if (target_changed && m_left_mouse_button_is_down)
273+ if (target_changed && left_mouse_button_is_down_)
274 map_clicked(true);
275 }
276
277 void EditorInteractive::tool_menu_btn() {
278- if (m_toolmenu.window)
279- delete m_toolmenu.window;
280+ if (toolmenu_.window)
281+ delete toolmenu_.window;
282 else
283- new EditorToolMenu(*this, m_toolmenu);
284+ new EditorToolMenu(*this, toolmenu_);
285 }
286
287
288 void EditorInteractive::toggle_playermenu() {
289- if (m_playermenu.window)
290- delete m_playermenu.window;
291+ if (playermenu_.window)
292+ delete playermenu_.window;
293 else {
294- select_tool(tools.set_starting_pos, EditorTool::First);
295- new EditorPlayerMenu(*this, m_playermenu);
296+ select_tool(tools_->set_starting_pos, EditorTool::First);
297+ new EditorPlayerMenu(*this, playermenu_);
298 }
299
300 }
301
302 void EditorInteractive::toolsize_menu_btn() {
303- if (m_toolsizemenu.window)
304- delete m_toolsizemenu.window;
305+ if (toolsizemenu_.window)
306+ delete toolsizemenu_.window;
307 else
308- new EditorToolsizeMenu(*this, m_toolsizemenu);
309+ new EditorToolsizeMenu(*this, toolsizemenu_);
310 }
311
312 void EditorInteractive::set_sel_radius_and_update_menu(uint32_t const val) {
313- if (tools.current().has_size_one()) {
314+ if (tools_->current().has_size_one()) {
315 set_sel_radius(0);
316 return;
317 }
318- if (UI::UniqueWindow * const w = m_toolsizemenu.window) {
319+ if (UI::UniqueWindow * const w = toolsizemenu_.window) {
320 dynamic_cast<EditorToolsizeMenu&>(*w).update(val);
321 } else {
322 set_sel_radius(val);
323@@ -385,16 +401,16 @@
324
325 case SDLK_LSHIFT:
326 case SDLK_RSHIFT:
327- if (tools.use_tool == EditorTool::First)
328- select_tool(tools.current(), EditorTool::Second);
329+ if (tools_->use_tool == EditorTool::First)
330+ select_tool(tools_->current(), EditorTool::Second);
331 handled = true;
332 break;
333
334 case SDLK_LALT:
335 case SDLK_RALT:
336 case SDLK_MODE:
337- if (tools.use_tool == EditorTool::First)
338- select_tool(tools.current(), EditorTool::Third);
339+ if (tools_->use_tool == EditorTool::First)
340+ select_tool(tools_->current(), EditorTool::Third);
341 handled = true;
342 break;
343
344@@ -416,7 +432,7 @@
345 break;
346
347 case SDLK_i:
348- select_tool(tools.info, EditorTool::First);
349+ select_tool(tools_->info, EditorTool::First);
350 handled = true;
351 break;
352
353@@ -449,15 +465,15 @@
354
355 case SDLK_z:
356 if ((code.mod & (KMOD_LCTRL | KMOD_RCTRL)) && (code.mod & (KMOD_LSHIFT | KMOD_RSHIFT)))
357- m_history.redo_action(egbase().world());
358+ history_->redo_action(egbase().world());
359 else if (code.mod & (KMOD_LCTRL | KMOD_RCTRL))
360- m_history.undo_action(egbase().world());
361+ history_->undo_action(egbase().world());
362 handled = true;
363 break;
364
365 case SDLK_y:
366 if (code.mod & (KMOD_LCTRL | KMOD_RCTRL))
367- m_history.redo_action(egbase().world());
368+ history_->redo_action(egbase().world());
369 handled = true;
370 break;
371 default:
372@@ -471,8 +487,8 @@
373 case SDLK_LALT:
374 case SDLK_RALT:
375 case SDLK_MODE:
376- if (tools.use_tool != EditorTool::First)
377- select_tool(tools.current(), EditorTool::First);
378+ if (tools_->use_tool != EditorTool::First)
379+ select_tool(tools_->current(), EditorTool::First);
380 handled = true;
381 break;
382 default:
383@@ -485,15 +501,15 @@
384
385 void EditorInteractive::select_tool
386 (EditorTool & primary, EditorTool::ToolIndex const which) {
387- if (which == EditorTool::First && & primary != tools.current_pointer) {
388+ if (which == EditorTool::First && & primary != tools_->current_pointer) {
389 if (primary.has_size_one()) {
390 set_sel_radius(0);
391- if (UI::UniqueWindow * const w = m_toolsizemenu.window) {
392+ if (UI::UniqueWindow * const w = toolsizemenu_.window) {
393 EditorToolsizeMenu& toolsize_menu = dynamic_cast<EditorToolsizeMenu&>(*w);
394 toolsize_menu.set_buttons_enabled(false);
395 }
396 } else {
397- if (UI::UniqueWindow * const w = m_toolsizemenu.window) {
398+ if (UI::UniqueWindow * const w = toolsizemenu_.window) {
399 EditorToolsizeMenu& toolsize_menu = dynamic_cast<EditorToolsizeMenu&>(*w);
400 toolsize_menu.update(toolsize_menu.value());
401 }
402@@ -504,8 +520,8 @@
403 mutable_field_overlay_manager()->register_overlay_callback_function(nullptr);
404 map.recalc_whole_map(egbase().world());
405 }
406- tools.current_pointer = &primary;
407- tools.use_tool = which;
408+ tools_->current_pointer = &primary;
409+ tools_->use_tool = which;
410
411 if (char const * const sel_pic = primary.get_sel(which))
412 set_sel_picture(sel_pic);
413@@ -528,7 +544,7 @@
414 r.player = player;
415 r.object = data;
416
417- m_player_tribe_references.push_back(r);
418+ player_tribe_references_.push_back(r);
419 }
420
421 /// Unreference !once!, if referenced many times, this will leak a reference.
422@@ -537,7 +553,7 @@
423 assert(player <= egbase().map().get_nrplayers());
424 assert(data);
425
426- std::vector<PlayerReferences> & references = m_player_tribe_references;
427+ std::vector<PlayerReferences> & references = player_tribe_references_;
428 std::vector<PlayerReferences>::iterator it = references.begin();
429 std::vector<PlayerReferences>::const_iterator references_end =
430 references.end();
431@@ -561,17 +577,17 @@
432 assert(0 < player);
433 assert(player <= egbase().map().get_nrplayers());
434
435- for (uint32_t i = 0; i < m_player_tribe_references.size(); ++i)
436- if (m_player_tribe_references[i].player == player)
437+ for (uint32_t i = 0; i < player_tribe_references_.size(); ++i)
438+ if (player_tribe_references_[i].player == player)
439 return true;
440
441 return false;
442 }
443
444 void EditorInteractive::run_editor(const std::string& filename, const std::string& script_to_run) {
445- Widelands::EditorGameBase editor(nullptr);
446- EditorInteractive eia(editor);
447- editor.set_ibase(&eia); // TODO(unknown): get rid of this
448+ Widelands::EditorGameBase egbase(nullptr);
449+ EditorInteractive eia(egbase);
450+ egbase.set_ibase(&eia); // TODO(unknown): get rid of this
451 {
452 UI::ProgressWindow loader_ui("pics/editor.jpg");
453 std::vector<std::string> tipstext;
454@@ -580,11 +596,11 @@
455
456 {
457 Widelands::Map & map = *new Widelands::Map;
458- editor.set_map(&map);
459+ egbase.set_map(&map);
460 if (filename.empty()) {
461 loader_ui.step("Creating empty map...");
462 map.create_empty_map(
463- editor.world(),
464+ egbase.world(),
465 64,
466 64,
467 0,
468@@ -592,9 +608,9 @@
469 _("No Name"),
470 g_options.pull_section("global").get_string("realname", pgettext("map_name", "Unknown")));
471
472- load_all_tribes(&editor, &loader_ui);
473+ load_all_tribes(&egbase, &loader_ui);
474
475- editor.load_graphics(loader_ui);
476+ egbase.load_graphics(loader_ui);
477 loader_ui.step(std::string());
478 } else {
479 loader_ui.stepf("Loading map \"%s\"...", filename.c_str());
480@@ -602,8 +618,7 @@
481 }
482 }
483
484- eia.select_tool(eia.tools.increase_height, EditorTool::First);
485- editor.postload();
486+ egbase.postload();
487
488 eia.start();
489
490@@ -613,5 +628,39 @@
491 }
492 eia.run<UI::Panel::Returncodes>();
493
494- editor.cleanup_objects();
495+ egbase.cleanup_objects();
496+}
497+
498+void EditorInteractive::map_changed(const MapWas& action) {
499+ switch (action) {
500+ case MapWas::kReplaced:
501+ history_.reset(new EditorHistory(undo_, redo_));
502+ undo_.set_enabled(false);
503+ redo_.set_enabled(false);
504+
505+ tools_.reset(new Tools());
506+ select_tool(tools_->increase_height, EditorTool::First);
507+ set_sel_radius(0);
508+
509+ set_need_save(false);
510+ show_buildhelp(true);
511+
512+ // Close all windows.
513+ for (Panel* child = get_first_child(); child; child = child->get_next_sibling()) {
514+ if (is_a(UI::Window, child)) {
515+ child->die();
516+ }
517+ }
518+ break;
519+
520+ case MapWas::kGloballyMutated:
521+ break;
522+ }
523+
524+ mutable_field_overlay_manager()->remove_all_overlays();
525+ register_overlays();
526+}
527+
528+EditorInteractive::Tools* EditorInteractive::tools() {
529+ return tools_.get();
530 }
531
532=== modified file 'src/editor/editorinteractive.h'
533--- src/editor/editorinteractive.h 2016-01-07 12:47:17 +0000
534+++ src/editor/editorinteractive.h 2016-01-16 15:57:59 +0000
535@@ -20,6 +20,8 @@
536 #ifndef WL_EDITOR_EDITORINTERACTIVE_H
537 #define WL_EDITOR_EDITORINTERACTIVE_H
538
539+#include <memory>
540+
541 #include "editor/tools/editor_history.h"
542 #include "editor/tools/editor_increase_height_tool.h"
543 #include "editor/tools/editor_increase_resources_tool.h"
544@@ -32,6 +34,8 @@
545 #include "editor/tools/editor_set_port_space_tool.h"
546 #include "editor/tools/editor_set_starting_pos_tool.h"
547 #include "editor/tools/editor_set_terrain_tool.h"
548+#include "logic/map.h"
549+#include "notifications/notifications.h"
550 #include "ui_basic/button.h"
551 #include "ui_basic/unique_window.h"
552 #include "wui/interactive_base.h"
553@@ -43,33 +47,8 @@
554 * This is the EditorInteractive. It is like the InteractivePlayer class,
555 * but for the Editor instead of the game
556 */
557-struct EditorInteractive : public InteractiveBase {
558- friend struct EditorToolMenu;
559-
560- // Runs the Editor via the commandline --editor flag. Will load 'filename' as a
561- // map and run 'script_to_run' directly after all initialization is done.
562- static void run_editor(const std::string & filename, const std::string& script_to_run);
563-
564-private:
565- EditorInteractive(Widelands::EditorGameBase &);
566-
567+class EditorInteractive : public InteractiveBase {
568 public:
569- void register_overlays();
570- void load(const std::string & filename);
571-
572- // leaf functions from base class
573- void start() override;
574- void think() override;
575-
576- void map_clicked(bool draw = false);
577- void set_sel_pos(Widelands::NodeAndTriangle<>) override;
578- void set_sel_radius_and_update_menu(uint32_t);
579-
580- // Handle UI elements.
581- bool handle_key(bool down, SDL_Keysym) override;
582- bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;
583- bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y) override;
584-
585 struct Tools {
586 Tools()
587 :
588@@ -106,7 +85,28 @@
589 EditorUnsetPortSpaceTool unset_port_space;
590 EditorSetOriginTool set_origin;
591 EditorMakeInfrastructureTool make_infrastructure;
592- } tools;
593+ };
594+ EditorInteractive(Widelands::EditorGameBase &);
595+
596+ // Runs the Editor via the commandline --editor flag. Will load 'filename' as a
597+ // map and run 'script_to_run' directly after all initialization is done.
598+ static void run_editor(const std::string & filename, const std::string& script_to_run);
599+
600+ void load(const std::string & filename);
601+
602+ // leaf functions from base class
603+ void start() override;
604+ void think() override;
605+
606+ void map_clicked(bool draw = false);
607+ void set_sel_pos(Widelands::NodeAndTriangle<>) override;
608+ void set_sel_radius_and_update_menu(uint32_t);
609+
610+ // Handle UI elements.
611+ bool handle_key(bool down, SDL_Keysym) override;
612+ bool handle_mousepress(uint8_t btn, int32_t x, int32_t y) override;
613+ bool handle_mouserelease(uint8_t btn, int32_t x, int32_t y) override;
614+
615
616 void select_tool(EditorTool &, EditorTool::ToolIndex);
617
618@@ -119,47 +119,69 @@
619 void reference_player_tribe(Widelands::PlayerNumber, void const * const) override;
620 void unreference_player_tribe(Widelands::PlayerNumber, void const * const);
621 bool is_player_tribe_referenced(Widelands::PlayerNumber);
622- void set_need_save(bool const t) {m_need_save = t;}
623+ void set_need_save(bool const t) {need_save_ = t;}
624+
625+ // Signalizes that the egbase().map has changed. This can happen when a new
626+ // map is created or loaded, in which case all windows should be closed and
627+ // all tools should be reset. Otherwise, something else happened that
628+ // requires the UI to be completely recalculated, for example the origin of
629+ // the map has changed.
630+ enum class MapWas {
631+ kGloballyMutated,
632+ kReplaced,
633+ };
634+ void map_changed(const MapWas& action);
635+
636+ // Access to the tools.
637+ Tools* tools();
638
639 private:
640+ friend struct EditorToolMenu;
641+
642+ struct PlayerReferences {
643+ int32_t player;
644+ void const * object;
645+ };
646+
647+ // Registers the overlays for player starting positions.
648+ void register_overlays();
649+
650 void tool_menu_btn();
651 void toolsize_menu_btn();
652 void toggle_mainmenu();
653 void toggle_playermenu();
654
655 // state variables
656- bool m_need_save;
657- struct PlayerReferences {
658- int32_t player;
659- void const * object;
660- };
661- std::vector<PlayerReferences> m_player_tribe_references;
662-
663- uint32_t m_realtime;
664- bool m_left_mouse_button_is_down;
665-
666- EditorHistory m_history;
667-
668- UI::UniqueWindow::Registry m_toolmenu;
669-
670- UI::UniqueWindow::Registry m_toolsizemenu;
671- UI::UniqueWindow::Registry m_playermenu;
672- UI::UniqueWindow::Registry m_mainmenu;
673- UI::UniqueWindow::Registry m_heightmenu;
674- UI::UniqueWindow::Registry m_noise_heightmenu;
675- UI::UniqueWindow::Registry m_terrainmenu;
676- UI::UniqueWindow::Registry m_immovablemenu;
677- UI::UniqueWindow::Registry m_bobmenu;
678- UI::UniqueWindow::Registry m_resourcesmenu;
679-
680- UI::Button m_toggle_main_menu;
681- UI::Button m_toggle_tool_menu;
682- UI::Button m_toggle_toolsize_menu;
683- UI::Button m_toggle_minimap;
684- UI::Button m_toggle_buildhelp;
685- UI::Button m_toggle_player_menu;
686- UI::Button m_undo;
687- UI::Button m_redo;
688+ bool need_save_;
689+ std::vector<PlayerReferences> player_tribe_references_;
690+ uint32_t realtime_;
691+ bool left_mouse_button_is_down_;
692+
693+ std::unique_ptr<Tools> tools_;
694+ std::unique_ptr<EditorHistory> history_;
695+
696+ std::unique_ptr<Notifications::Subscriber<Widelands::NoteFieldResourceChanged>>
697+ field_resource_changed_subscriber_;
698+ UI::UniqueWindow::Registry toolmenu_;
699+
700+ UI::UniqueWindow::Registry toolsizemenu_;
701+ UI::UniqueWindow::Registry playermenu_;
702+ UI::UniqueWindow::Registry mainmenu_;
703+ UI::UniqueWindow::Registry heightmenu_;
704+ UI::UniqueWindow::Registry noise_heightmenu_;
705+ UI::UniqueWindow::Registry terrainmenu_;
706+ UI::UniqueWindow::Registry immovablemenu_;
707+ UI::UniqueWindow::Registry bobmenu_;
708+ UI::UniqueWindow::Registry resourcesmenu_;
709+
710+ UI::Button toggle_main_menu_;
711+ UI::Button toggle_tool_menu_;
712+ UI::Button toggle_toolsize_menu_;
713+ UI::Button toggle_minimap_;
714+ UI::Button toggle_buildhelp_;
715+ UI::Button toggle_player_menu_;
716+ UI::Button undo_;
717+ UI::Button redo_;
718 };
719
720 #endif // end of include guard: WL_EDITOR_EDITORINTERACTIVE_H
721
722=== modified file 'src/editor/map_generator.cc'
723--- src/editor/map_generator.cc 2016-01-06 19:11:20 +0000
724+++ src/editor/map_generator.cc 2016-01-16 15:57:59 +0000
725@@ -134,8 +134,7 @@
726 res_val *= static_cast<uint8_t>(map_info_.resource_amount) + 1;
727 res_val /= 3;
728 if (map_.is_resource_valid(world, fc, res_idx)) {
729- fc.field->set_resources(res_idx, res_val);
730- fc.field->set_initial_res_amount(res_val);
731+ map_.initialize_resources(fc, res_idx, res_val);
732 }
733 };
734
735
736=== modified file 'src/editor/tools/editor_action_args.h'
737--- src/editor/tools/editor_action_args.h 2015-11-11 09:54:53 +0000
738+++ src/editor/tools/editor_action_args.h 2016-01-16 15:57:59 +0000
739@@ -30,7 +30,7 @@
740 class BobDescr;
741 } // namespace Widelands
742
743-struct EditorInteractive;
744+class EditorInteractive;
745 struct EditorToolAction;
746
747 /// Class to save important and changeable properties of classes needed for actions
748
749=== modified file 'src/editor/tools/editor_decrease_resources_tool.cc'
750--- src/editor/tools/editor_decrease_resources_tool.cc 2016-01-10 11:36:05 +0000
751+++ src/editor/tools/editor_decrease_resources_tool.cc 2016-01-16 15:57:59 +0000
752@@ -36,7 +36,7 @@
753 */
754 int32_t EditorDecreaseResourcesTool::handle_click_impl(const Widelands::World& world,
755 Widelands::NodeAndTriangle<> const center,
756- EditorInteractive& parent,
757+ EditorInteractive& /* parent */,
758 EditorActionArgs* args,
759 Widelands::Map* map) {
760 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
761@@ -54,8 +54,7 @@
762 map->is_resource_valid(world, mr.location(), args->cur_res)) {
763 args->orgResT.push_back(mr.location().field->get_resources());
764 args->orgRes.push_back(mr.location().field->get_resources_amount());
765- EditorSetResourcesTool::set_res_and_overlay(world, amount, args->cur_res, mr.location(),
766- parent.mutable_field_overlay_manager(), map);
767+ map->initialize_resources(mr.location(), args->cur_res, amount);
768 }
769
770 } while (mr.advance(*map));
771@@ -67,7 +66,7 @@
772 EditorInteractive& parent,
773 EditorActionArgs* args,
774 Widelands::Map* map) {
775- return parent.tools.set_resources.handle_undo_impl(world, center, parent, args, map);
776+ return parent.tools()->set_resources.handle_undo_impl(world, center, parent, args, map);
777 }
778
779 EditorActionArgs EditorDecreaseResourcesTool::format_args_impl(EditorInteractive & parent)
780
781=== modified file 'src/editor/tools/editor_delete_bob_tool.cc'
782--- src/editor/tools/editor_delete_bob_tool.cc 2016-01-06 19:11:20 +0000
783+++ src/editor/tools/editor_delete_bob_tool.cc 2016-01-16 15:57:59 +0000
784@@ -57,7 +57,7 @@
785 EditorActionArgs* args,
786 Widelands::Map* map) {
787
788- uint32_t ret = parent.tools.place_bob.handle_undo_impl(world, center, parent, args, map);
789+ uint32_t ret = parent.tools()->place_bob.handle_undo_impl(world, center, parent, args, map);
790 args->obob_type.clear();
791 return ret;
792 }
793
794=== modified file 'src/editor/tools/editor_delete_immovable_tool.cc'
795--- src/editor/tools/editor_delete_immovable_tool.cc 2016-01-06 19:11:20 +0000
796+++ src/editor/tools/editor_delete_immovable_tool.cc 2016-01-16 15:57:59 +0000
797@@ -58,7 +58,7 @@
798 EditorInteractive& parent,
799 EditorActionArgs* args,
800 Widelands::Map* map) {
801- return parent.tools.place_immovable.handle_undo_impl(world, center, parent, args, map);
802+ return parent.tools()->place_immovable.handle_undo_impl(world, center, parent, args, map);
803 }
804
805 EditorActionArgs EditorDeleteImmovableTool::format_args_impl(EditorInteractive & parent)
806
807=== modified file 'src/editor/tools/editor_history.cc'
808--- src/editor/tools/editor_history.cc 2016-01-04 20:50:19 +0000
809+++ src/editor/tools/editor_history.cc 2016-01-16 15:57:59 +0000
810@@ -133,12 +133,3 @@
811 }
812 return tool.handle_click(ind, world, center, parent, ac.args, &map);
813 }
814-
815-
816-void EditorHistory::reset()
817-{
818- undo_stack.clear();
819- redo_stack.clear();
820- m_undo_button.set_enabled(false);
821- m_redo_button.set_enabled(false);
822-}
823
824=== modified file 'src/editor/tools/editor_history.h'
825--- src/editor/tools/editor_history.h 2014-09-10 14:08:25 +0000
826+++ src/editor/tools/editor_history.h 2016-01-16 15:57:59 +0000
827@@ -25,8 +25,7 @@
828 #include "editor/tools/editor_draw_tool.h"
829 #include "editor/tools/editor_tool.h"
830
831-//struct EditorActionArgs;
832-struct EditorInteractive;
833+class EditorInteractive;
834 namespace UI {struct Button;}
835
836 /**
837@@ -35,7 +34,6 @@
838 * Do all tool action you want to make "undoable" using this class.
839 */
840 struct EditorHistory {
841-
842 EditorHistory(UI::Button & undo, UI::Button & redo):
843 m_undo_button(undo), m_redo_button(redo) {}
844
845@@ -49,11 +47,7 @@
846 uint32_t undo_action(const Widelands::World& world);
847 uint32_t redo_action(const Widelands::World& world);
848
849- /// Must be called after every change of map, world, or ... to avoid undo errors
850- void reset();
851-
852 private:
853-
854 UI::Button & m_undo_button;
855 UI::Button & m_redo_button;
856
857@@ -61,7 +55,6 @@
858
859 std::deque<EditorToolAction> undo_stack;
860 std::deque<EditorToolAction> redo_stack;
861-
862 };
863
864
865
866=== modified file 'src/editor/tools/editor_increase_resources_tool.cc'
867--- src/editor/tools/editor_increase_resources_tool.cc 2016-01-10 11:36:05 +0000
868+++ src/editor/tools/editor_increase_resources_tool.cc 2016-01-16 15:57:59 +0000
869@@ -31,7 +31,7 @@
870
871 int32_t EditorIncreaseResourcesTool::handle_click_impl(const Widelands::World& world,
872 Widelands::NodeAndTriangle<> const center,
873- EditorInteractive& parent,
874+ EditorInteractive& /* parent */,
875 EditorActionArgs* args,
876 Widelands::Map* map) {
877 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
878@@ -52,8 +52,7 @@
879 map->is_resource_valid(world, mr.location(), args->cur_res)) {
880 args->orgResT.push_back(mr.location().field->get_resources());
881 args->orgRes.push_back(mr.location().field->get_resources_amount());
882- EditorSetResourcesTool::set_res_and_overlay(world, amount, args->cur_res, mr.location(),
883- parent.mutable_field_overlay_manager(), map);
884+ map->initialize_resources(mr.location(), args->cur_res, amount);
885 }
886 } while (mr.advance(*map));
887 return mr.radius();
888
889=== modified file 'src/editor/tools/editor_set_origin_tool.cc'
890--- src/editor/tools/editor_set_origin_tool.cc 2016-01-07 12:47:17 +0000
891+++ src/editor/tools/editor_set_origin_tool.cc 2016-01-16 15:57:59 +0000
892@@ -29,7 +29,7 @@
893 EditorActionArgs* /* args */,
894 Widelands::Map* map) {
895 map->set_origin(center.node);
896- eia.register_overlays();
897+ eia.map_changed(EditorInteractive::MapWas::kGloballyMutated);
898 eia.set_rel_viewpoint
899 (Point
900 (-(center.node.x * 2 + (center.node.y & 1)) * (TRIANGLE_WIDTH / 2),
901@@ -41,15 +41,15 @@
902 int32_t
903 EditorSetOriginTool::handle_undo_impl(const Widelands::World&,
904 Widelands::NodeAndTriangle<Widelands::Coords> center,
905- EditorInteractive& parent,
906+ EditorInteractive& eia,
907 EditorActionArgs* /* args */,
908 Widelands::Map* map) {
909 Widelands::Coords nc
910 (map->get_width() - center.node.x,
911 map->get_height() - center.node.y);
912 map->set_origin(nc);
913- parent.register_overlays();
914- parent.set_rel_viewpoint
915+ eia.map_changed(EditorInteractive::MapWas::kGloballyMutated);
916+ eia.set_rel_viewpoint
917 (Point
918 (- (nc.x * 2 + (nc.y & 1)) *(TRIANGLE_WIDTH / 2),
919 - nc.y * TRIANGLE_HEIGHT),
920@@ -57,7 +57,7 @@
921 return 0;
922 }
923
924-EditorActionArgs EditorSetOriginTool::format_args_impl(EditorInteractive & parent)
925+EditorActionArgs EditorSetOriginTool::format_args_impl(EditorInteractive & eia)
926 {
927- return EditorTool::format_args_impl(parent);
928+ return EditorTool::format_args_impl(eia);
929 }
930
931=== modified file 'src/editor/tools/editor_set_port_space_tool.cc'
932--- src/editor/tools/editor_set_port_space_tool.cc 2016-01-10 11:36:05 +0000
933+++ src/editor/tools/editor_set_port_space_tool.cc 2016-01-16 15:57:59 +0000
934@@ -86,7 +86,7 @@
935 EditorInteractive& parent,
936 EditorActionArgs* args,
937 Map* map) {
938- return parent.tools.unset_port_space.handle_click_impl(world, center, parent, args, map);
939+ return parent.tools()->unset_port_space.handle_click_impl(world, center, parent, args, map);
940 }
941
942 int32_t EditorUnsetPortSpaceTool::handle_click_impl(const Widelands::World& world,
943@@ -121,5 +121,5 @@
944 EditorInteractive& parent,
945 EditorActionArgs* args,
946 Map* map) {
947- return parent.tools.set_port_space.handle_click_impl(world, center, parent, args, map);
948+ return parent.tools()->set_port_space.handle_click_impl(world, center, parent, args, map);
949 }
950
951=== modified file 'src/editor/tools/editor_set_resources_tool.cc'
952--- src/editor/tools/editor_set_resources_tool.cc 2016-01-10 11:36:05 +0000
953+++ src/editor/tools/editor_set_resources_tool.cc 2016-01-16 15:57:59 +0000
954@@ -27,11 +27,10 @@
955 #include "logic/map_objects/world/resource_description.h"
956 #include "logic/map_objects/world/world.h"
957 #include "logic/mapregion.h"
958-#include "wui/field_overlay_manager.h"
959
960 int32_t EditorSetResourcesTool::handle_click_impl(const Widelands::World& world,
961 Widelands::NodeAndTriangle<> const center,
962- EditorInteractive& parent,
963+ EditorInteractive& /* parent */,
964 EditorActionArgs* args,
965 Widelands::Map* map) {
966 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
967@@ -50,8 +49,7 @@
968 if (map->is_resource_valid(world, mr.location(), args->cur_res)) {
969 args->orgResT.push_back(mr.location().field->get_resources());
970 args->orgRes.push_back(mr.location().field->get_resources_amount());
971- set_res_and_overlay(world, amount, args->cur_res, mr.location(),
972- parent.mutable_field_overlay_manager(), map);
973+ map->initialize_resources(mr.location(), args->cur_res, amount);
974 }
975 } while (mr.advance(*map));
976 return mr.radius();
977@@ -60,7 +58,7 @@
978 int32_t
979 EditorSetResourcesTool::handle_undo_impl(const Widelands::World& world,
980 Widelands::NodeAndTriangle<Widelands::Coords> center,
981- EditorInteractive& parent,
982+ EditorInteractive& /* parent */,
983 EditorActionArgs* args,
984 Widelands::Map* map) {
985 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
986@@ -77,9 +75,7 @@
987 if (amount > max_amount)
988 amount = max_amount;
989
990- set_res_and_overlay(
991- world, amount, *ir, mr.location(), parent.mutable_field_overlay_manager(), map);
992-
993+ map->initialize_resources(mr.location(), *it, amount);
994 ++ir;
995 ++it;
996 } while (mr.advance(*map));
997@@ -95,33 +91,3 @@
998 a.set_to = m_set_to;
999 return a;
1000 }
1001-
1002-void EditorSetResourcesTool::set_res_and_overlay(const Widelands::World& world,
1003- int32_t amount, uint8_t new_res,
1004- const Widelands::FCoords& fcoords,
1005- FieldOverlayManager* field_overlay_manager,
1006- Widelands::Map* map) {
1007- int32_t old_res = fcoords.field->get_resources();
1008-
1009-
1010- // Ok, we're doing something. First remove the current overlays.
1011- if (old_res != Widelands::kNoResource) {
1012- std::string str = world.get_resource(old_res)->get_editor_pic(
1013- fcoords.field->get_resources_amount());
1014- const Image* pic = g_gr->images().get(str);
1015- field_overlay_manager->remove_overlay(fcoords, pic);
1016- }
1017-
1018- if (!amount) {
1019- fcoords.field->set_resources(Widelands::kNoResource, 0);
1020- fcoords.field->set_initial_res_amount(0);
1021- } else {
1022- fcoords.field->set_resources(new_res, amount);
1023- fcoords.field->set_initial_res_amount(amount);
1024- // set new overlay
1025- std::string str = world.get_resource(new_res)->get_editor_pic(amount);
1026- const Image* pic = g_gr->images().get(str);
1027- field_overlay_manager->register_overlay(fcoords, pic, 0);
1028- map->recalc_for_field_area(world, Widelands::Area<Widelands::FCoords>(fcoords, 0));
1029- }
1030-}
1031
1032=== modified file 'src/editor/tools/editor_set_resources_tool.h'
1033--- src/editor/tools/editor_set_resources_tool.h 2016-01-10 11:36:05 +0000
1034+++ src/editor/tools/editor_set_resources_tool.h 2016-01-16 15:57:59 +0000
1035@@ -23,7 +23,6 @@
1036 #include "editor/tools/editor_tool.h"
1037 #include "logic/mapregion.h"
1038 #include "logic/widelands.h"
1039-#include "wui/field_overlay_manager.h"
1040
1041 /// Decreases the resources of a node by a value.
1042 struct EditorSetResourcesTool : public EditorTool {
1043@@ -48,16 +47,6 @@
1044
1045 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
1046
1047- /**
1048- * Sets the resource amount and updates the overlay.
1049- */
1050- static void set_res_and_overlay(const Widelands::World& world,
1051- int32_t amount,
1052- uint8_t resIx,
1053- const Widelands::FCoords& fcoords,
1054- FieldOverlayManager* field_overlay_manager,
1055- Widelands::Map* map);
1056-
1057 char const * get_sel_impl() const override {
1058 return "pics/fsel_editor_set_resources.png";
1059 }
1060
1061=== modified file 'src/editor/tools/editor_tool.h'
1062--- src/editor/tools/editor_tool.h 2016-01-04 20:50:19 +0000
1063+++ src/editor/tools/editor_tool.h 2016-01-16 15:57:59 +0000
1064@@ -26,7 +26,7 @@
1065 #include "editor/tools/editor_action_args.h"
1066 #include "logic/widelands_geometry.h"
1067
1068-struct EditorInteractive;
1069+class EditorInteractive;
1070 namespace Widelands {
1071 class Map;
1072 class World;
1073
1074=== modified file 'src/editor/tools/editor_tool_action.h'
1075--- src/editor/tools/editor_tool_action.h 2014-09-10 14:08:25 +0000
1076+++ src/editor/tools/editor_tool_action.h 2016-01-16 15:57:59 +0000
1077@@ -25,7 +25,7 @@
1078
1079 class EditorTool;
1080 namespace Widelands {class map;}
1081-struct EditorInteractive;
1082+class EditorInteractive;
1083
1084
1085 /// Class to save an action done by an editor tool
1086
1087=== modified file 'src/editor/ui_menus/editor_main_menu.h'
1088--- src/editor/ui_menus/editor_main_menu.h 2015-09-25 13:08:22 +0000
1089+++ src/editor/ui_menus/editor_main_menu.h 2016-01-16 15:57:59 +0000
1090@@ -24,7 +24,7 @@
1091 #include "ui_basic/button.h"
1092 #include "ui_basic/unique_window.h"
1093
1094-struct EditorInteractive;
1095+class EditorInteractive;
1096
1097 /**
1098 * This represents the main menu
1099
1100=== modified file 'src/editor/ui_menus/editor_main_menu_load_map.cc'
1101--- src/editor/ui_menus/editor_main_menu_load_map.cc 2016-01-07 12:47:17 +0000
1102+++ src/editor/ui_menus/editor_main_menu_load_map.cc 2016-01-16 15:57:59 +0000
1103@@ -50,9 +50,7 @@
1104 } else {
1105 EditorInteractive& eia = dynamic_cast<EditorInteractive&>(*get_parent());
1106 eia.load(mapdata.filename);
1107- eia.toggle_minimap();
1108- eia.toggle_minimap();
1109- die();
1110+ // load() will delete us.
1111 }
1112 }
1113
1114
1115=== modified file 'src/editor/ui_menus/editor_main_menu_map_options.h'
1116--- src/editor/ui_menus/editor_main_menu_map_options.h 2015-03-30 10:17:48 +0000
1117+++ src/editor/ui_menus/editor_main_menu_map_options.h 2016-01-16 15:57:59 +0000
1118@@ -30,7 +30,7 @@
1119 #include "ui_basic/textarea.h"
1120 #include "ui_basic/window.h"
1121
1122-struct EditorInteractive;
1123+class EditorInteractive;
1124
1125 /**
1126 * This is the Main Options Menu. Here, information
1127
1128=== modified file 'src/editor/ui_menus/editor_main_menu_new_map.cc'
1129--- src/editor/ui_menus/editor_main_menu_new_map.cc 2016-01-06 19:11:20 +0000
1130+++ src/editor/ui_menus/editor_main_menu_new_map.cc 2016-01-16 15:57:59 +0000
1131@@ -125,11 +125,7 @@
1132 egbase.load_graphics(loader);
1133
1134 map.recalc_whole_map(egbase.world());
1135-
1136- parent.set_need_save(true);
1137- parent.toggle_minimap();
1138- parent.toggle_minimap();
1139-
1140+ parent.map_changed(EditorInteractive::MapWas::kReplaced);
1141 die();
1142 }
1143
1144
1145=== modified file 'src/editor/ui_menus/editor_main_menu_new_map.h'
1146--- src/editor/ui_menus/editor_main_menu_new_map.h 2015-12-04 17:58:39 +0000
1147+++ src/editor/ui_menus/editor_main_menu_new_map.h 2016-01-16 15:57:59 +0000
1148@@ -27,7 +27,7 @@
1149 #include "ui_basic/spinbox.h"
1150 #include "ui_basic/window.h"
1151
1152-struct EditorInteractive;
1153+class EditorInteractive;
1154
1155 /**
1156 * This is the new map selection menu. It offers
1157
1158=== modified file 'src/editor/ui_menus/editor_main_menu_random_map.cc'
1159--- src/editor/ui_menus/editor_main_menu_random_map.cc 2016-01-06 19:11:20 +0000
1160+++ src/editor/ui_menus/editor_main_menu_random_map.cc 2016-01-16 15:57:59 +0000
1161@@ -449,12 +449,7 @@
1162 egbase.load_graphics(loader);
1163
1164 map.recalc_whole_map(egbase.world());
1165-
1166- eia.set_need_save(true);
1167- eia.register_overlays();
1168- eia.toggle_minimap();
1169- eia.toggle_minimap();
1170-
1171+ eia.map_changed(EditorInteractive::MapWas::kReplaced);
1172 die();
1173 }
1174
1175
1176=== modified file 'src/editor/ui_menus/editor_main_menu_random_map.h'
1177--- src/editor/ui_menus/editor_main_menu_random_map.h 2015-12-03 18:55:59 +0000
1178+++ src/editor/ui_menus/editor_main_menu_random_map.h 2016-01-16 15:57:59 +0000
1179@@ -34,7 +34,7 @@
1180 struct UniqueRandomMapInfo;
1181 }
1182
1183-struct EditorInteractive;
1184+class EditorInteractive;
1185 namespace UI {
1186 template <typename T, typename ID> struct IDButton;
1187 }
1188
1189=== modified file 'src/editor/ui_menus/editor_player_menu.cc'
1190--- src/editor/ui_menus/editor_player_menu.cc 2016-01-10 11:36:05 +0000
1191+++ src/editor/ui_menus/editor_player_menu.cc 2016-01-16 15:57:59 +0000
1192@@ -233,7 +233,7 @@
1193 menu.mutable_field_overlay_manager()->remove_overlay(sp, g_gr->images().get(picsname));
1194 }
1195 // if removed player was selected switch to the next highest player
1196- if (old_nr_players == menu.tools.set_starting_pos.get_current_player())
1197+ if (old_nr_players == menu.tools()->set_starting_pos.get_current_player())
1198 set_starting_pos_clicked(nr_players);
1199 }
1200 map.set_nrplayers(nr_players);
1201@@ -290,11 +290,11 @@
1202 menu.move_view_to(sp);
1203
1204 // select tool set mplayer
1205- menu.select_tool(menu.tools.set_starting_pos, EditorTool::First);
1206- menu.tools.set_starting_pos.set_current_player(n);
1207+ menu.select_tool(menu.tools()->set_starting_pos, EditorTool::First);
1208+ menu.tools()->set_starting_pos.set_current_player(n);
1209
1210 // reselect tool, so everything is in a defined state
1211- menu.select_tool(menu.tools.current(), EditorTool::First);
1212+ menu.select_tool(menu.tools()->current(), EditorTool::First);
1213
1214 // Register callback function to make sure that only valid locations are
1215 // selected.
1216@@ -379,8 +379,8 @@
1217 (start_pos, g_gr->images().get(picsname));
1218 }
1219
1220- parent.select_tool(parent.tools.make_infrastructure, EditorTool::First);
1221- parent.tools.make_infrastructure.set_player(n);
1222+ parent.select_tool(parent.tools()->make_infrastructure, EditorTool::First);
1223+ parent.tools()->make_infrastructure.set_player(n);
1224 overlay_manager->register_overlay_callback_function(
1225 boost::bind(&editor_make_infrastructure_tool_callback, _1, boost::ref(egbase), n));
1226 map.recalc_whole_map(egbase.world());
1227
1228=== modified file 'src/editor/ui_menus/editor_player_menu.h'
1229--- src/editor/ui_menus/editor_player_menu.h 2015-09-12 07:53:38 +0000
1230+++ src/editor/ui_menus/editor_player_menu.h 2016-01-16 15:57:59 +0000
1231@@ -31,7 +31,7 @@
1232 #include "ui_basic/unique_window.h"
1233
1234
1235-struct EditorInteractive;
1236+class EditorInteractive;
1237 namespace UI {
1238 struct Textarea;
1239 struct EditBox;
1240
1241=== modified file 'src/editor/ui_menus/editor_tool_change_height_options_menu.h'
1242--- src/editor/ui_menus/editor_tool_change_height_options_menu.h 2014-09-10 14:08:25 +0000
1243+++ src/editor/ui_menus/editor_tool_change_height_options_menu.h 2016-01-16 15:57:59 +0000
1244@@ -24,7 +24,7 @@
1245 #include "ui_basic/button.h"
1246 #include "ui_basic/textarea.h"
1247
1248-struct EditorInteractive;
1249+class EditorInteractive;
1250 struct EditorIncreaseHeightTool;
1251
1252 struct EditorToolChangeHeightOptionsMenu :
1253
1254=== modified file 'src/editor/ui_menus/editor_tool_change_resources_options_menu.cc'
1255--- src/editor/ui_menus/editor_tool_change_resources_options_menu.cc 2016-01-10 11:36:05 +0000
1256+++ src/editor/ui_menus/editor_tool_change_resources_options_menu.cc 2016-01-16 15:57:59 +0000
1257@@ -222,8 +222,8 @@
1258 Widelands::EditorGameBase& egbase = eia().egbase();
1259 Widelands::Map & map = egbase.map();
1260 eia().mutable_field_overlay_manager()->register_overlay_callback_function(
1261- [resIx, &map, &egbase](const Widelands::TCoords<Widelands::FCoords>& coords) -> uint32_t {
1262- if (map.is_resource_valid(egbase.world(), coords, resIx)) {
1263+ [resIx, &map, &egbase](const Widelands::TCoords<Widelands::FCoords>& coords) -> uint32_t {
1264+ if (map.is_resource_valid(egbase.world(), coords, resIx)) {
1265 return coords.field->nodecaps();
1266 }
1267 return 0;
1268
1269=== modified file 'src/editor/ui_menus/editor_tool_change_resources_options_menu.h'
1270--- src/editor/ui_menus/editor_tool_change_resources_options_menu.h 2014-11-28 12:53:24 +0000
1271+++ src/editor/ui_menus/editor_tool_change_resources_options_menu.h 2016-01-16 15:57:59 +0000
1272@@ -25,7 +25,7 @@
1273 #include "ui_basic/radiobutton.h"
1274 #include "ui_basic/textarea.h"
1275
1276-struct EditorInteractive;
1277+class EditorInteractive;
1278 struct EditorIncreaseResourcesTool;
1279
1280 struct EditorToolChangeResourcesOptionsMenu :
1281
1282=== modified file 'src/editor/ui_menus/editor_tool_menu.cc'
1283--- src/editor/ui_menus/editor_tool_menu.cc 2016-01-07 12:47:17 +0000
1284+++ src/editor/ui_menus/editor_tool_menu.cc 2016-01-16 15:57:59 +0000
1285@@ -55,7 +55,7 @@
1286
1287 int32_t const num_tools = 8;
1288 #define ADD_BUTTON(pic, tooltip) \
1289- m_radioselect.add_button \
1290+ radioselect_.add_button \
1291 (this, \
1292 pos, \
1293 g_gr->images().get("pics/editor_menu_tool_" pic ".png"), \
1294@@ -76,20 +76,20 @@
1295 (offs.x + (width + spacing) * num_tools, offs.y + (height + spacing));
1296
1297 {
1298- const EditorTool & current = parent.tools.current();
1299- m_radioselect.set_state
1300- (&current == &parent.tools.noise_height ? 1 :
1301- &current == &parent.tools.set_terrain ? 2 :
1302- &current == &parent.tools.place_immovable ? 3 :
1303- &current == &parent.tools.place_bob ? 4 :
1304- &current == &parent.tools.increase_resources ? 5 :
1305- &current == &parent.tools.set_port_space ? 6 :
1306- &current == &parent.tools.set_origin ? 7 :
1307+ const EditorTool & current = parent.tools()->current();
1308+ radioselect_.set_state
1309+ (&current == &parent.tools()->noise_height ? 1 :
1310+ &current == &parent.tools()->set_terrain ? 2 :
1311+ &current == &parent.tools()->place_immovable ? 3 :
1312+ &current == &parent.tools()->place_bob ? 4 :
1313+ &current == &parent.tools()->increase_resources ? 5 :
1314+ &current == &parent.tools()->set_port_space ? 6 :
1315+ &current == &parent.tools()->set_origin ? 7 :
1316 0);
1317 }
1318
1319- m_radioselect.changed.connect(boost::bind(&EditorToolMenu::changed_to, this));
1320- m_radioselect.clicked.connect(boost::bind(&EditorToolMenu::changed_to, this));
1321+ radioselect_.changed.connect(boost::bind(&EditorToolMenu::changed_to, this));
1322+ radioselect_.clicked.connect(boost::bind(&EditorToolMenu::changed_to, this));
1323
1324 if (get_usedefaultpos())
1325 center_to_parent();
1326@@ -99,7 +99,7 @@
1327 * Called when the radiogroup changes or is reclicked
1328 */
1329 void EditorToolMenu::changed_to() {
1330- const int32_t n = m_radioselect.get_state();
1331+ const int32_t n = radioselect_.get_state();
1332
1333 EditorInteractive & parent =
1334 dynamic_cast<EditorInteractive&>(*get_parent());
1335@@ -108,35 +108,35 @@
1336 UI::UniqueWindow::Registry * current_registry_pointer = nullptr;
1337 switch (n) {
1338 case 0:
1339- current_tool_pointer = &parent.tools.increase_height;
1340- current_registry_pointer = &parent.m_heightmenu;
1341+ current_tool_pointer = &parent.tools()->increase_height;
1342+ current_registry_pointer = &parent.heightmenu_;
1343 break;
1344 case 1:
1345- current_tool_pointer = &parent.tools.noise_height;
1346- current_registry_pointer = &parent.m_noise_heightmenu;
1347+ current_tool_pointer = &parent.tools()->noise_height;
1348+ current_registry_pointer = &parent.noise_heightmenu_;
1349 break;
1350 case 2:
1351- current_tool_pointer = &parent.tools.set_terrain;
1352- current_registry_pointer = &parent.m_terrainmenu;
1353+ current_tool_pointer = &parent.tools()->set_terrain;
1354+ current_registry_pointer = &parent.terrainmenu_;
1355 break;
1356 case 3:
1357- current_tool_pointer = &parent.tools.place_immovable;
1358- current_registry_pointer = &parent.m_immovablemenu;
1359+ current_tool_pointer = &parent.tools()->place_immovable;
1360+ current_registry_pointer = &parent.immovablemenu_;
1361 break;
1362 case 4:
1363- current_tool_pointer = &parent.tools.place_bob;
1364- current_registry_pointer = &parent.m_bobmenu;
1365+ current_tool_pointer = &parent.tools()->place_bob;
1366+ current_registry_pointer = &parent.bobmenu_;
1367 break;
1368 case 5:
1369- current_tool_pointer = &parent.tools.increase_resources;
1370- current_registry_pointer = &parent.m_resourcesmenu;
1371+ current_tool_pointer = &parent.tools()->increase_resources;
1372+ current_registry_pointer = &parent.resourcesmenu_;
1373 break;
1374 case 6:
1375- current_tool_pointer = &parent.tools.set_port_space;
1376+ current_tool_pointer = &parent.tools()->set_port_space;
1377 current_registry_pointer = nullptr; // no need for a window
1378 break;
1379 case 7:
1380- current_tool_pointer = &parent.tools.set_origin;
1381+ current_tool_pointer = &parent.tools()->set_origin;
1382 current_registry_pointer = nullptr; // no need for a window
1383 break;
1384 default:
1385@@ -145,7 +145,7 @@
1386 }
1387
1388 parent.select_tool(*current_tool_pointer, EditorTool::First);
1389- if (current_tool_pointer == &parent.tools.set_port_space) {
1390+ if (current_tool_pointer == &parent.tools()->set_port_space) {
1391 // Set correct overlay
1392 Widelands::Map & map = parent.egbase().map();
1393 parent.mutable_field_overlay_manager()->register_overlay_callback_function(
1394@@ -166,37 +166,37 @@
1395 case 0:
1396 new EditorToolChangeHeightOptionsMenu
1397 (parent,
1398- parent.tools.increase_height,
1399+ parent.tools()->increase_height,
1400 *current_registry_pointer);
1401 break;
1402 case 1:
1403 new EditorToolNoiseHeightOptionsMenu
1404 (parent,
1405- parent.tools.noise_height,
1406+ parent.tools()->noise_height,
1407 *current_registry_pointer);
1408 break;
1409 case 2:
1410 new EditorToolSetTerrainOptionsMenu
1411 (parent,
1412- parent.tools.set_terrain,
1413+ parent.tools()->set_terrain,
1414 *current_registry_pointer);
1415 break;
1416 case 3:
1417 new EditorToolPlaceImmovableOptionsMenu
1418 (parent,
1419- parent.tools.place_immovable,
1420+ parent.tools()->place_immovable,
1421 *current_registry_pointer);
1422 break;
1423 case 4:
1424 new EditorToolPlaceBobOptionsMenu
1425 (parent,
1426- parent.tools.place_bob,
1427+ parent.tools()->place_bob,
1428 *current_registry_pointer);
1429 break;
1430 case 5:
1431 new EditorToolChangeResourcesOptionsMenu
1432 (parent,
1433- parent.tools.increase_resources,
1434+ parent.tools()->increase_resources,
1435 *current_registry_pointer);
1436 break;
1437 default:
1438
1439=== modified file 'src/editor/ui_menus/editor_tool_menu.h'
1440--- src/editor/ui_menus/editor_tool_menu.h 2014-09-10 14:08:25 +0000
1441+++ src/editor/ui_menus/editor_tool_menu.h 2016-01-16 15:57:59 +0000
1442@@ -29,7 +29,7 @@
1443 EditorToolMenu(EditorInteractive &, UI::UniqueWindow::Registry &);
1444
1445 private:
1446- UI::Radiogroup m_radioselect;
1447+ UI::Radiogroup radioselect_;
1448
1449 void changed_to();
1450 };
1451
1452=== modified file 'src/editor/ui_menus/editor_tool_noise_height_options_menu.h'
1453--- src/editor/ui_menus/editor_tool_noise_height_options_menu.h 2014-09-10 14:08:25 +0000
1454+++ src/editor/ui_menus/editor_tool_noise_height_options_menu.h 2016-01-16 15:57:59 +0000
1455@@ -24,7 +24,7 @@
1456 #include "ui_basic/button.h"
1457 #include "ui_basic/textarea.h"
1458
1459-struct EditorInteractive;
1460+class EditorInteractive;
1461 struct EditorNoiseHeightTool;
1462
1463 struct EditorToolNoiseHeightOptionsMenu : public EditorToolOptionsMenu {
1464
1465=== modified file 'src/editor/ui_menus/editor_tool_options_menu.cc'
1466--- src/editor/ui_menus/editor_tool_options_menu.cc 2014-11-30 18:49:38 +0000
1467+++ src/editor/ui_menus/editor_tool_options_menu.cc 2016-01-16 15:57:59 +0000
1468@@ -27,7 +27,7 @@
1469 :
1470 UI::UniqueWindow
1471 (&parent, "tool_options_menu", &registry, width, height, title),
1472- m_current_pointer(parent.tools.current_pointer)
1473+ m_current_pointer(parent.tools()->current_pointer)
1474 {
1475 if (get_usedefaultpos())
1476 center_to_parent();
1477
1478=== modified file 'src/editor/ui_menus/editor_tool_place_immovable_options_menu.h'
1479--- src/editor/ui_menus/editor_tool_place_immovable_options_menu.h 2014-09-10 14:08:25 +0000
1480+++ src/editor/ui_menus/editor_tool_place_immovable_options_menu.h 2016-01-16 15:57:59 +0000
1481@@ -27,7 +27,7 @@
1482 #include "editor/ui_menus/editor_tool_options_menu.h"
1483 #include "editor/tools/editor_place_immovable_tool.h"
1484
1485-struct EditorInteractive;
1486+class EditorInteractive;
1487
1488 struct EditorToolPlaceImmovableOptionsMenu : public EditorToolOptionsMenu {
1489 EditorToolPlaceImmovableOptionsMenu(EditorInteractive&,
1490
1491=== modified file 'src/editor/ui_menus/editor_tool_set_terrain_options_menu.h'
1492--- src/editor/ui_menus/editor_tool_set_terrain_options_menu.h 2015-11-28 22:29:26 +0000
1493+++ src/editor/ui_menus/editor_tool_set_terrain_options_menu.h 2016-01-16 15:57:59 +0000
1494@@ -29,7 +29,7 @@
1495 #include "logic/map_objects/world/terrain_description.h"
1496 #include "ui_basic/textarea.h"
1497
1498-struct EditorInteractive;
1499+class EditorInteractive;
1500 struct EditorSetTerrainTool;
1501
1502 struct EditorToolSetTerrainOptionsMenu : public EditorToolOptionsMenu {
1503
1504=== modified file 'src/editor/ui_menus/editor_toolsize_menu.cc'
1505--- src/editor/ui_menus/editor_toolsize_menu.cc 2015-07-26 10:20:28 +0000
1506+++ src/editor/ui_menus/editor_toolsize_menu.cc 2016-01-16 15:57:59 +0000
1507@@ -65,7 +65,7 @@
1508 m_decrease.set_repeating(true);
1509 update(parent.get_sel_radius());
1510
1511- if (eia().tools.current().has_size_one()) {
1512+ if (eia().tools()->current().has_size_one()) {
1513 set_buttons_enabled(false);
1514 }
1515
1516
1517=== modified file 'src/editor/ui_menus/editor_toolsize_menu.h'
1518--- src/editor/ui_menus/editor_toolsize_menu.h 2015-07-26 09:25:51 +0000
1519+++ src/editor/ui_menus/editor_toolsize_menu.h 2016-01-16 15:57:59 +0000
1520@@ -25,7 +25,7 @@
1521 #include "ui_basic/unique_window.h"
1522
1523
1524-struct EditorInteractive;
1525+class EditorInteractive;
1526
1527
1528 /// The tool size window/menu.
1529
1530=== modified file 'src/logic/field.h'
1531--- src/logic/field.h 2016-01-07 12:47:17 +0000
1532+++ src/logic/field.h 2016-01-16 15:57:59 +0000
1533@@ -199,18 +199,10 @@
1534 roads |= type << dir;
1535 }
1536
1537+ // Resources can be set through Map::set_resources()
1538 // TODO(unknown): This should return DescriptionIndex
1539 uint8_t get_resources() const {return m_resources;}
1540 uint8_t get_resources_amount() const {return m_res_amount;}
1541- void set_resources(uint8_t const res, uint8_t const amount) {
1542- m_resources = res;
1543- m_res_amount = amount;
1544- }
1545-
1546- // TODO(unknown): This should take uint8_t
1547- void set_initial_res_amount(int32_t const amount) {
1548- m_initial_res_amount = amount;
1549- }
1550 // TODO(unknown): This should return uint8_t
1551 int32_t get_initial_res_amount() const {return m_initial_res_amount;}
1552
1553
1554=== modified file 'src/logic/map.cc'
1555--- src/logic/map.cc 2016-01-10 11:36:05 +0000
1556+++ src/logic/map.cc 2016-01-16 15:57:59 +0000
1557@@ -250,11 +250,9 @@
1558 amount /= 6;
1559
1560 if (res == -1 || !amount) {
1561- f.field->set_resources(Widelands::kNoResource, 0);
1562- f.field->set_initial_res_amount(0);
1563+ clear_resources(f);
1564 } else {
1565- f.field->set_resources(res, amount);
1566- f.field->set_initial_res_amount(amount);
1567+ initialize_resources(f, res, amount);
1568 }
1569
1570 }
1571@@ -322,12 +320,13 @@
1572 Field::Terrains default_terrains;
1573 default_terrains.d = default_terrain;
1574 default_terrains.r = default_terrain;
1575- Field * field = m_fields.get();
1576- const Field * const fields_end = field + max_index();
1577- for (; field < fields_end; ++field) {
1578- field->set_height(10);
1579- field->set_terrains(default_terrains);
1580- field->set_resources(Widelands::kNoResource, 0);
1581+ for (int16_t y = 0; y < m_height; ++y) {
1582+ for (int16_t x = 0; x < m_width; ++x) {
1583+ auto f = get_fcoords(Coords(x, y));
1584+ f.field->set_height(10);
1585+ f.field->set_terrains(default_terrains);
1586+ clear_resources(f);
1587+ }
1588 }
1589 }
1590 recalc_whole_map(world);
1591@@ -1837,24 +1836,25 @@
1592 // remove invalid resources if necessary
1593 // check vertex to which the triangle belongs
1594 if (!is_resource_valid(world, c, c.field->get_resources())){
1595- c.field->set_resources(Widelands::kNoResource, 0);
1596+ clear_resources(c);
1597 }
1598
1599 // always check south-east vertex
1600 Widelands::FCoords f_se(c, c.field);
1601 get_neighbour(f_se, Widelands::WALK_SE, &f_se);
1602 if (!is_resource_valid(world, f_se, f_se.field->get_resources())){
1603- f_se.field->set_resources(Widelands::kNoResource, 0);
1604+ clear_resources(f_se);
1605 }
1606
1607 // check south-west vertex if d-Triangle is changed, check east vertex if r-Triangle is changed
1608 Widelands::FCoords f_sw_e(c, c.field);
1609 get_neighbour(f_sw_e, c.t == TCoords<FCoords>::D ? Widelands::WALK_SW : Widelands::WALK_E, &f_sw_e);
1610 if (!is_resource_valid(world, f_sw_e, f_sw_e.field->get_resources())){
1611- f_sw_e.field->set_resources(Widelands::kNoResource, 0);
1612+ clear_resources(f_sw_e);
1613 }
1614
1615- Notifications::publish(NoteFieldTransformed(c, c.field - &m_fields[0]));
1616+ Notifications::publish(
1617+ NoteFieldTerrainChanged{c, static_cast<MapIndex>(c.field - &m_fields[0])});
1618
1619 recalc_for_field_area(world, Area<FCoords>(c, 2));
1620
1621@@ -1895,11 +1895,47 @@
1622
1623 void Map::ensure_resource_consistency(const World& world)
1624 {
1625- for (MapIndex i = 0; i < max_index(); ++i)
1626- if (!is_resource_valid(world, get_fcoords(m_fields[i]), m_fields[i].get_resources()))
1627- m_fields[i].set_resources(Widelands::kNoResource, 0);
1628-}
1629-
1630+ for (MapIndex i = 0; i < max_index(); ++i) {
1631+ auto fcords = get_fcoords(m_fields[i]);
1632+ if (!is_resource_valid(world, fcords, fcords.field->get_resources())) {
1633+ clear_resources(fcords);
1634+ }
1635+ }
1636+}
1637+
1638+void Map::initialize_resources(const FCoords& c,
1639+ const DescriptionIndex resource_type,
1640+ uint8_t amount) {
1641+ // You cannot have an amount of nothing.
1642+ if (resource_type == Widelands::kNoResource) {
1643+ amount = 0;
1644+ }
1645+ const auto note = NoteFieldResourceChanged{
1646+ c, c.field->m_resources, c.field->m_initial_res_amount, c.field->m_res_amount,
1647+ };
1648+
1649+ c.field->m_resources = resource_type;
1650+ c.field->m_initial_res_amount = amount;
1651+ c.field->m_res_amount = amount;
1652+ Notifications::publish(note);
1653+}
1654+
1655+void Map::set_resources(const FCoords& c, uint8_t amount) {
1656+ // You cannot change the amount of resources on a field without resources.
1657+ if (c.field->m_resources == Widelands::kNoResource) {
1658+ return;
1659+ }
1660+ assert(amount <= c.field->m_initial_res_amount);
1661+ const auto note = NoteFieldResourceChanged{
1662+ c, c.field->m_resources, c.field->m_initial_res_amount, c.field->m_res_amount,
1663+ };
1664+ c.field->m_res_amount = amount;
1665+ Notifications::publish(note);
1666+}
1667+
1668+void Map::clear_resources(const FCoords& c) {
1669+ initialize_resources(c, Widelands::kNoResource, 0);
1670+}
1671
1672 uint32_t Map::set_height(const World& world, const FCoords fc, uint8_t const new_value) {
1673 assert(new_value <= MAX_FIELD_HEIGHT);
1674
1675=== modified file 'src/logic/map.h'
1676--- src/logic/map.h 2016-01-10 11:36:05 +0000
1677+++ src/logic/map.h 2016-01-16 15:57:59 +0000
1678@@ -68,15 +68,21 @@
1679 struct Path;
1680 class Immovable;
1681
1682-struct NoteFieldTransformed {
1683- CAN_BE_SENT_AS_NOTE(NoteId::FieldTransformed)
1684+struct NoteFieldTerrainChanged {
1685+ CAN_BE_SENT_AS_NOTE(NoteId::FieldTerrainChanged)
1686
1687 FCoords fc;
1688 MapIndex map_index;
1689-
1690- NoteFieldTransformed(const FCoords& init_fc, const MapIndex init_map_index)
1691- : fc(init_fc), map_index(init_map_index) {
1692- }
1693+};
1694+
1695+/// Send when the resource of a field is changed.
1696+struct NoteFieldResourceChanged {
1697+ CAN_BE_SENT_AS_NOTE(NoteId::FieldResourceTypeChanged)
1698+
1699+ FCoords fc;
1700+ DescriptionIndex old_resource;
1701+ uint8_t old_initial_amount;
1702+ uint8_t old_amount;
1703 };
1704
1705 struct ImmovableFound {
1706@@ -362,6 +368,18 @@
1707 /// Changes the height of the nodes in an Area by a difference.
1708 uint32_t change_height(const World& world, Area<FCoords>, int16_t difference);
1709
1710+ /// Initializes the 'initial_resources' on 'coords' to the 'resource_type'
1711+ /// with the given 'amount'.
1712+ void initialize_resources(const FCoords& coords, DescriptionIndex resource_type, uint8_t amount);
1713+
1714+ /// Sets the number of resources of the field to 'amount'. The type of the
1715+ /// resource on this field is not changed.
1716+ void set_resources(const FCoords& coords, uint8_t amount);
1717+
1718+ /// Clears the resources, i.e. the amount will be set to 0 and the type of
1719+ /// resources will be kNoResource.
1720+ void clear_resources(const FCoords& coords);
1721+
1722 /**
1723 * Ensures that the height of each node within radius from fc is in
1724 * height_interval. If the height is < height_interval.min, it is changed to
1725
1726=== modified file 'src/logic/map_objects/tribes/production_program.cc'
1727--- src/logic/map_objects/tribes/production_program.cc 2016-01-12 21:25:20 +0000
1728+++ src/logic/map_objects/tribes/production_program.cc 2016-01-16 15:57:59 +0000
1729@@ -1309,8 +1309,7 @@
1730 assert(amount > 0);
1731
1732 --amount;
1733-
1734- mr.location().field->set_resources(m_resource, amount);
1735+ map.set_resources(mr.location(), amount);
1736 break;
1737 }
1738 } while (mr.advance(map));
1739
1740=== modified file 'src/logic/map_objects/tribes/worker.cc'
1741--- src/logic/map_objects/tribes/worker.cc 2016-01-06 19:11:20 +0000
1742+++ src/logic/map_objects/tribes/worker.cc 2016-01-16 15:57:59 +0000
1743@@ -176,7 +176,7 @@
1744 assert(amount > 0);
1745
1746 --amount;
1747- mr.location().field->set_resources(res, amount);
1748+ map.set_resources(mr.location(), amount);
1749 break;
1750 }
1751 } while (mr.advance(map));
1752@@ -286,9 +286,7 @@
1753 assert(amount > 0);
1754
1755 --amount;
1756-
1757- mr.location().field->set_resources
1758- (res, mr.location().field->get_initial_res_amount() - amount);
1759+ map.set_resources(mr.location(), mr.location().field->get_initial_res_amount() - amount);
1760 break;
1761 }
1762 } while (mr.advance(map));
1763
1764=== modified file 'src/logic/player.cc'
1765--- src/logic/player.cc 2016-01-06 19:11:20 +0000
1766+++ src/logic/player.cc 2016-01-16 15:57:59 +0000
1767@@ -194,9 +194,9 @@
1768 }
1769 });
1770
1771- // Subscribe to NoteFieldTransformed.
1772- field_transformed_subscriber_ =
1773- Notifications::subscribe<NoteFieldTransformed>([this](const NoteFieldTransformed& note) {
1774+ // Subscribe to NoteFieldTerrainChanged.
1775+ field_terrain_changed_subscriber_ =
1776+ Notifications::subscribe<NoteFieldTerrainChanged>([this](const NoteFieldTerrainChanged& note) {
1777 if (vision(note.map_index) > 1) {
1778 rediscover_node(egbase().map(), egbase().map()[0], note.fc);
1779 }
1780
1781=== modified file 'src/logic/player.h'
1782--- src/logic/player.h 2016-01-06 19:11:20 +0000
1783+++ src/logic/player.h 2016-01-16 15:57:59 +0000
1784@@ -538,7 +538,8 @@
1785 void rediscover_node(const Map&, const Widelands::Field&, FCoords);
1786
1787 std::unique_ptr<Notifications::Subscriber<NoteImmovable>> immovable_subscriber_;
1788- std::unique_ptr<Notifications::Subscriber<NoteFieldTransformed>> field_transformed_subscriber_;
1789+ std::unique_ptr<Notifications::Subscriber<NoteFieldTerrainChanged>>
1790+ field_terrain_changed_subscriber_;
1791
1792 MessageQueue m_messages;
1793
1794
1795=== modified file 'src/map_io/map_resources_packet.cc'
1796--- src/map_io/map_resources_packet.cc 2015-11-28 22:29:26 +0000
1797+++ src/map_io/map_resources_packet.cc 2016-01-16 15:57:59 +0000
1798@@ -85,8 +85,9 @@
1799
1800 if (0xa < set_id)
1801 throw "Unknown resource in map file. It is not in world!\n";
1802- map[Coords(x, y)].set_resources(set_id, set_amount);
1803- map[Coords(x, y)].set_initial_res_amount(set_start_amount);
1804+ const auto fcoords = map.get_fcoords(Coords(x, y));
1805+ map.initialize_resources(fcoords, set_id, set_start_amount);
1806+ map.set_resources(fcoords, set_amount);
1807 }
1808 }
1809 } else {
1810
1811=== modified file 'src/map_io/s2map.cc'
1812--- src/map_io/s2map.cc 2015-11-29 09:43:15 +0000
1813+++ src/map_io/s2map.cc 2016-01-16 15:57:59 +0000
1814@@ -617,19 +617,19 @@
1815 if (!section)
1816 throw wexception("Section 12 (Resources) not found");
1817
1818- f = m_map.m_fields.get();
1819 pc = section.get();
1820 char const * res;
1821 int32_t amount = 0;
1822- for (uint16_t y = 0; y < mapheight; ++y)
1823- for (uint16_t x = 0; x < mapwidth; ++x, ++f, ++pc) {
1824- uint8_t c = *pc;
1825+ for (uint16_t y = 0; y < mapheight; ++y) {
1826+ for (uint16_t x = 0; x < mapwidth; ++x, ++pc) {
1827+ auto c = m_map.get_fcoords(Widelands::Coords(x, y));
1828+ uint8_t value = *pc;
1829
1830- switch (c & 0xF8) {
1831- case 0x40: res = "coal"; amount = c & 7; break;
1832- case 0x48: res = "iron"; amount = c & 7; break;
1833- case 0x50: res = "gold"; amount = c & 7; break;
1834- case 0x59: res = "granite"; amount = c & 7; break;
1835+ switch (value & 0xF8) {
1836+ case 0x40: res = "coal"; amount = value & 7; break;
1837+ case 0x48: res = "iron"; amount = value & 7; break;
1838+ case 0x50: res = "gold"; amount = value & 7; break;
1839+ case 0x59: res = "granite"; amount = value & 7; break;
1840 default: res = ""; amount = 0; break;
1841 };
1842
1843@@ -644,9 +644,9 @@
1844 }
1845 const int32_t real_amount = static_cast<int32_t>
1846 (2.86 * static_cast<float>(amount));
1847- f->set_resources(nres, real_amount);
1848- f->set_initial_res_amount(real_amount);
1849+ m_map.initialize_resources(c, nres, real_amount);
1850 }
1851+ }
1852
1853
1854
1855
1856=== modified file 'src/notifications/note_ids.h'
1857--- src/notifications/note_ids.h 2015-05-20 19:17:56 +0000
1858+++ src/notifications/note_ids.h 2016-01-16 15:57:59 +0000
1859@@ -30,7 +30,8 @@
1860 LogMessage,
1861 Immovable,
1862 FieldPossession,
1863- FieldTransformed,
1864+ FieldTerrainChanged,
1865+ FieldResourceTypeChanged,
1866 ProductionSiteOutOfResources,
1867 TrainingSiteSoldierTrained,
1868 ShipMessage,
1869
1870=== modified file 'src/scripting/lua_map.cc'
1871--- src/scripting/lua_map.cc 2016-01-06 19:11:20 +0000
1872+++ src/scripting/lua_map.cc 2016-01-16 15:57:59 +0000
1873@@ -4442,15 +4442,18 @@
1874 return 1;
1875 }
1876 int LuaField::set_resource(lua_State * L) {
1877- Field * field = fcoords(L).field;
1878+ auto& egbase = get_egbase(L);
1879 int32_t res = get_egbase(L).world().get_resource
1880 (luaL_checkstring(L, -1));
1881
1882 if (res == Widelands::INVALID_INDEX)
1883 report_error(L, "Illegal resource: '%s'", luaL_checkstring(L, -1));
1884
1885- field->set_resources(res, field->get_resources_amount());
1886-
1887+ auto c = fcoords(L);
1888+ const auto current_amount = c.field->get_resources_amount();
1889+ auto& map = egbase.map();
1890+ map.initialize_resources(c, res, c.field->get_initial_res_amount());
1891+ map.set_resources(c, current_amount);
1892 return 0;
1893 }
1894
1895@@ -4466,8 +4469,8 @@
1896 return 1;
1897 }
1898 int LuaField::set_resource_amount(lua_State * L) {
1899- Field * field = fcoords(L).field;
1900- int32_t res = field->get_resources();
1901+ auto c = fcoords(L);
1902+ int32_t res = c.field->get_resources();
1903 int32_t amount = luaL_checkint32(L, -1);
1904 const ResourceDescription * resDesc = get_egbase(L).world().get_resource(res);
1905 int32_t max_amount = resDesc ? resDesc->max_amount() : 0;
1906@@ -4475,14 +4478,14 @@
1907 if (amount < 0 || amount > max_amount)
1908 report_error(L, "Illegal amount: %i, must be >= 0 and <= %i", amount, max_amount);
1909
1910- field->set_resources(res, amount);
1911- //in editor, reset also initial amount
1912 EditorGameBase & egbase = get_egbase(L);
1913- upcast(Game, game, &egbase);
1914- if (!game) {
1915- field->set_initial_res_amount(amount);
1916+ auto& map = egbase.map();
1917+ if (is_a(Game, &egbase)) {
1918+ map.set_resources(c, amount);
1919+ } else {
1920+ // in editor, reset also initial amount
1921+ map.initialize_resources(c, res, amount);
1922 }
1923-
1924 return 0;
1925 }
1926 /* RST
1927
1928=== modified file 'src/ui_basic/panel.h'
1929--- src/ui_basic/panel.h 2015-08-06 17:14:34 +0000
1930+++ src/ui_basic/panel.h 2016-01-16 15:57:59 +0000
1931@@ -247,6 +247,8 @@
1932 ///\return the current set UI font
1933 std::string ui_fn();
1934
1935+ virtual void die();
1936+
1937 protected:
1938 // This panel will never receive keypresses (do_key), instead
1939 // textinput will be passed on (do_textinput).
1940@@ -258,7 +260,6 @@
1941 void set_thinks(bool yes);
1942
1943
1944- virtual void die();
1945 bool keyboard_free() {return !(_focus);}
1946
1947 virtual void update_desired_size();
1948
1949=== modified file 'src/wui/field_overlay_manager.cc'
1950--- src/wui/field_overlay_manager.cc 2016-01-10 11:36:05 +0000
1951+++ src/wui/field_overlay_manager.cc 2016-01-16 15:57:59 +0000
1952@@ -207,6 +207,12 @@
1953 }
1954 }
1955
1956+void FieldOverlayManager::remove_all_overlays() {
1957+ m_overlays[0].clear();
1958+ m_overlays[1].clear();
1959+ m_overlays[2].clear();
1960+}
1961+
1962 void FieldOverlayManager::register_overlay_callback_function(CallbackFn function) {
1963 m_callback = function;
1964 }
1965
1966=== modified file 'src/wui/field_overlay_manager.h'
1967--- src/wui/field_overlay_manager.h 2016-01-10 11:56:27 +0000
1968+++ src/wui/field_overlay_manager.h 2016-01-16 15:57:59 +0000
1969@@ -97,6 +97,10 @@
1970 /// remove all overlays with this overlay_id
1971 void remove_overlay(OverlayId overlay_id);
1972
1973+ /// Removes all overlays.
1974+ // TODO(sirver): It would be preferable to just delete and recreate the object.
1975+ void remove_all_overlays();
1976+
1977 /// Returns the currently registered overlays and the buildhelp for a node.
1978 void get_overlays(Widelands::FCoords c, std::vector<OverlayInfo>* result) const;
1979
1980
1981=== modified file 'src/wui/fieldaction.cc'
1982--- src/wui/fieldaction.cc 2016-01-10 11:36:05 +0000
1983+++ src/wui/fieldaction.cc 2016-01-16 15:57:59 +0000
1984@@ -819,10 +819,9 @@
1985 void FieldActionWindow::building_icon_mouse_in
1986 (const Widelands::DescriptionIndex idx)
1987 {
1988- if (ibase().m_show_workarea_preview && !m_workarea_preview_overlay_id) {
1989- const WorkareaInfo & workarea_info =
1990- m_plr->tribe().get_building_descr(Widelands::DescriptionIndex(idx))
1991- ->m_workarea_info;
1992+ if (ibase().show_workarea_preview_ && !m_workarea_preview_overlay_id) {
1993+ const WorkareaInfo& workarea_info =
1994+ m_plr->tribe().get_building_descr(Widelands::DescriptionIndex(idx))->m_workarea_info;
1995 m_workarea_preview_overlay_id = ibase().show_work_area(workarea_info, m_node);
1996 }
1997 }
1998
1999=== modified file 'src/wui/interactive_base.cc'
2000--- src/wui/interactive_base.cc 2016-01-10 11:36:05 +0000
2001+++ src/wui/interactive_base.cc 2016-01-16 15:57:59 +0000
2002@@ -82,28 +82,28 @@
2003 InteractiveBase::InteractiveBase(EditorGameBase& the_egbase, Section& global_s)
2004 : MapView(nullptr, 0, 0, g_gr->get_xres(), g_gr->get_yres(), *this),
2005 // Initialize chatoveraly before the toolbar so it is below
2006- m_show_workarea_preview(global_s.get_bool("workareapreview", true)),
2007- m_chatOverlay(new ChatOverlay(this, 10, 25, get_w() / 2, get_h() - 25)),
2008- m_toolbar(this, 0, 0, UI::Box::Horizontal),
2009+ show_workarea_preview_(global_s.get_bool("workareapreview", true)),
2010+ chat_overlay_(new ChatOverlay(this, 10, 25, get_w() / 2, get_h() - 25)),
2011+ toolbar_(this, 0, 0, UI::Box::Horizontal),
2012 m(new InteractiveBaseInternals(new QuickNavigation(the_egbase, get_w(), get_h()))),
2013- m_field_overlay_manager(new FieldOverlayManager()),
2014- m_edge_overlay_manager(new EdgeOverlayManager()),
2015- m_egbase(the_egbase),
2016+ field_overlay_manager_(new FieldOverlayManager()),
2017+ edge_overlay_manager_(new EdgeOverlayManager()),
2018+ egbase_(the_egbase),
2019 #ifndef NDEBUG // not in releases
2020- m_display_flags(dfDebug),
2021+ display_flags_(dfDebug),
2022 #else
2023- m_display_flags(0),
2024+ display_flags_(0),
2025 #endif
2026- m_lastframe(SDL_GetTicks()),
2027- m_frametime(0),
2028- m_avg_usframetime(0),
2029- m_jobid(0),
2030- m_road_buildhelp_overlay_jobid(0),
2031- m_buildroad(nullptr),
2032- m_road_build_player(0),
2033+ lastframe_(SDL_GetTicks()),
2034+ frametime_(0),
2035+ avg_usframetime_(0),
2036+ jobid_(0),
2037+ road_buildhelp_overlay_jobid_(0),
2038+ buildroad_(nullptr),
2039+ road_build_player_(0),
2040 unique_window_handler_(new UniqueWindowHandler()),
2041 // Start at idx 0 for 2 enhancements, idx 3 for 1, idx 5 if none
2042- m_workarea_pics{g_gr->images().get("pics/workarea123.png"),
2043+ workarea_pics_{g_gr->images().get("pics/workarea123.png"),
2044 g_gr->images().get("pics/workarea23.png"),
2045 g_gr->images().get("pics/workarea3.png"),
2046 g_gr->images().get("pics/workarea12.png"),
2047@@ -114,12 +114,12 @@
2048 [this](const GraphicResolutionChanged& message) {
2049 set_size(message.width, message.height);
2050
2051- m_chatOverlay->set_size(get_w() / 2, get_h() - 25);
2052- m_chatOverlay->recompute();
2053+ chat_overlay_->set_size(get_w() / 2, get_h() - 25);
2054+ chat_overlay_->recompute();
2055 adjust_toolbar_position();
2056 });
2057
2058- m_toolbar.set_layout_toplevel(true);
2059+ toolbar_.set_layout_toplevel(true);
2060 m->quicknavigation->set_setview
2061 (boost::bind(&MapView::set_viewpoint, this, _1, true));
2062 set_changeview
2063@@ -137,7 +137,7 @@
2064
2065 // Having this in the initializer list (before Sys_InitGraphics) will give
2066 // funny results.
2067- m_sel.pic = g_gr->images().get("pics/fsel.png");
2068+ sel_.pic = g_gr->images().get("pics/fsel.png");
2069
2070 setDefaultCommand (boost::bind(&InteractiveBase::cmd_lua, this, _1));
2071 addCommand
2072@@ -147,7 +147,7 @@
2073
2074 InteractiveBase::~InteractiveBase()
2075 {
2076- if (m_buildroad)
2077+ if (buildroad_)
2078 abort_build_road();
2079 }
2080
2081@@ -161,29 +161,29 @@
2082 Map & map = egbase().map();
2083
2084 // Remove old sel pointer
2085- if (m_sel.jobid)
2086- m_field_overlay_manager->remove_overlay(m_sel.jobid);
2087+ if (sel_.jobid)
2088+ field_overlay_manager_->remove_overlay(sel_.jobid);
2089 const FieldOverlayManager::OverlayId jobid =
2090- m_sel.jobid = m_field_overlay_manager->next_overlay_id();
2091+ sel_.jobid = field_overlay_manager_->next_overlay_id();
2092
2093- m_sel.pos = center;
2094+ sel_.pos = center;
2095
2096 // register sel overlay position
2097- if (m_sel.triangles) {
2098+ if (sel_.triangles) {
2099 assert
2100 (center.triangle.t == TCoords<>::D ||
2101 center.triangle.t == TCoords<>::R);
2102 Widelands::MapTriangleRegion<> mr
2103- (map, Area<TCoords<> >(center.triangle, m_sel.radius));
2104+ (map, Area<TCoords<> >(center.triangle, sel_.radius));
2105 do
2106- m_field_overlay_manager->register_overlay
2107- (mr.location(), m_sel.pic, 7, Point::invalid(), jobid);
2108+ field_overlay_manager_->register_overlay
2109+ (mr.location(), sel_.pic, 7, Point::invalid(), jobid);
2110 while (mr.advance(map));
2111 } else {
2112- Widelands::MapRegion<> mr(map, Area<>(center.node, m_sel.radius));
2113+ Widelands::MapRegion<> mr(map, Area<>(center.node, sel_.radius));
2114 do
2115- m_field_overlay_manager->register_overlay
2116- (mr.location(), m_sel.pic, 7, Point::invalid(), jobid);
2117+ field_overlay_manager_->register_overlay
2118+ (mr.location(), sel_.pic, 7, Point::invalid(), jobid);
2119 while (mr.advance(map));
2120 if (upcast(InteractiveGameBase const, igbase, this))
2121 if
2122@@ -217,8 +217,8 @@
2123 * Set the current sel selection radius.
2124 */
2125 void InteractiveBase::set_sel_radius(const uint32_t n) {
2126- if (n != m_sel.radius) {
2127- m_sel.radius = n;
2128+ if (n != sel_.radius) {
2129+ sel_.radius = n;
2130 set_sel_pos(get_sel_pos()); // redraw
2131 }
2132 }
2133@@ -227,7 +227,7 @@
2134 * Set/Unset sel picture
2135 */
2136 void InteractiveBase::set_sel_picture(const char * const file) {
2137- m_sel.pic = g_gr->images().get(file);
2138+ sel_.pic = g_gr->images().get(file);
2139 set_sel_pos(get_sel_pos()); // redraw
2140 }
2141 void InteractiveBase::unset_sel_picture() {
2142@@ -235,16 +235,16 @@
2143 }
2144
2145 bool InteractiveBase::buildhelp() const {
2146- return m_field_overlay_manager->buildhelp();
2147+ return field_overlay_manager_->buildhelp();
2148 }
2149
2150 void InteractiveBase::show_buildhelp(bool t) {
2151- m_field_overlay_manager->show_buildhelp(t);
2152+ field_overlay_manager_->show_buildhelp(t);
2153 on_buildhelp_changed(t);
2154 }
2155
2156 void InteractiveBase::toggle_buildhelp() {
2157- m_field_overlay_manager->show_buildhelp(!m_field_overlay_manager->buildhelp());
2158+ field_overlay_manager_->show_buildhelp(!field_overlay_manager_->buildhelp());
2159 }
2160
2161 void InteractiveBase::on_buildhelp_changed(bool /* value */) {
2162@@ -263,8 +263,8 @@
2163 default:
2164 throw wexception("Encountered unexpected WorkareaInfo size %i", workareas_nrs);
2165 }
2166- Widelands::Map & map = m_egbase.map();
2167- FieldOverlayManager::OverlayId overlay_id = m_field_overlay_manager->next_overlay_id();
2168+ Widelands::Map & map = egbase_.map();
2169+ FieldOverlayManager::OverlayId overlay_id = field_overlay_manager_->next_overlay_id();
2170
2171 Widelands::HollowArea<> hollow_area(Widelands::Area<>(coords, 0), 0);
2172
2173@@ -274,9 +274,9 @@
2174 hollow_area.radius = it->first;
2175 Widelands::MapHollowRegion<> mr(map, hollow_area);
2176 do
2177- m_field_overlay_manager->register_overlay
2178+ field_overlay_manager_->register_overlay
2179 (mr.location(),
2180- m_workarea_pics[wa_index],
2181+ workarea_pics_[wa_index],
2182 0,
2183 Point::invalid(),
2184 overlay_id);
2185@@ -288,7 +288,7 @@
2186 }
2187
2188 void InteractiveBase::hide_work_area(FieldOverlayManager::OverlayId overlay_id) {
2189- m_field_overlay_manager->remove_overlay(overlay_id);
2190+ field_overlay_manager_->remove_overlay(overlay_id);
2191 }
2192
2193
2194@@ -310,9 +310,9 @@
2195 // Timing
2196 uint32_t curframe = SDL_GetTicks();
2197
2198- m_frametime = curframe - m_lastframe;
2199- m_avg_usframetime = ((m_avg_usframetime * 15) + (m_frametime * 1000)) / 16;
2200- m_lastframe = curframe;
2201+ frametime_ = curframe - lastframe_;
2202+ avg_usframetime_ = ((avg_usframetime_ * 15) + (frametime_ * 1000)) / 16;
2203+ lastframe_ = curframe;
2204
2205 // If one of the arrow keys is pressed, scroll here
2206 const uint32_t scrollval = 10;
2207@@ -366,12 +366,12 @@
2208
2209 static boost::format node_format("(%i, %i)");
2210 node_text = as_uifont
2211- ((node_format % m_sel.pos.node.x % m_sel.pos.node.y).str(), UI_FONT_SIZE_SMALL);
2212+ ((node_format % sel_.pos.node.x % sel_.pos.node.y).str(), UI_FONT_SIZE_SMALL);
2213 } else { //this is an editor
2214 static boost::format node_format("(%i, %i, %i)");
2215- const int32_t height = map[m_sel.pos.node].get_height();
2216+ const int32_t height = map[sel_.pos.node].get_height();
2217 node_text = as_uifont
2218- ((node_format % m_sel.pos.node.x % m_sel.pos.node.y % height).str(), UI_FONT_SIZE_SMALL);
2219+ ((node_format % sel_.pos.node.x % sel_.pos.node.y % height).str(), UI_FONT_SIZE_SMALL);
2220 }
2221
2222 dst.blit(
2223@@ -384,10 +384,9 @@
2224 // Blit FPS when in debug mode.
2225 if (get_display_flag(dfDebug)) {
2226 static boost::format fps_format("%5.1f fps (avg: %5.1f fps)");
2227- const std::string fps_text = as_uifont
2228- ((fps_format %
2229- (1000.0 / m_frametime) % (1000.0 / (m_avg_usframetime / 1000)))
2230- .str(), UI_FONT_SIZE_SMALL);
2231+ const std::string fps_text = as_uifont(
2232+ (fps_format % (1000.0 / frametime_) % (1000.0 / (avg_usframetime_ / 1000))).str(),
2233+ UI_FONT_SIZE_SMALL);
2234 dst.blit(Point(5, (is_game) ? 25 : 5),
2235 UI::g_fh1->render(fps_text),
2236 BlendMode::UseAlpha,
2237@@ -474,13 +473,7 @@
2238 }
2239
2240
2241-/*
2242-===========
2243-InteractiveBase::toggle_minimap()
2244-
2245-Open the minimap or close it if it's open
2246-===========
2247-*/
2248+// Open the minimap or close it if it's open
2249 void InteractiveBase::toggle_minimap() {
2250 if (m->minimap.window) {
2251 delete m->minimap.window;
2252@@ -522,7 +515,7 @@
2253 */
2254 uint32_t InteractiveBase::get_display_flags() const
2255 {
2256- return m_display_flags;
2257+ return display_flags_;
2258 }
2259
2260
2261@@ -533,10 +526,9 @@
2262 */
2263 void InteractiveBase::set_display_flags(uint32_t flags)
2264 {
2265- m_display_flags = flags;
2266+ display_flags_ = flags;
2267 }
2268
2269-
2270 /*
2271 ===============
2272 Get and set one individual flag of the display flags.
2273@@ -544,15 +536,15 @@
2274 */
2275 bool InteractiveBase::get_display_flag(uint32_t const flag)
2276 {
2277- return m_display_flags & flag;
2278+ return display_flags_& flag;
2279 }
2280
2281 void InteractiveBase::set_display_flag(uint32_t const flag, bool const on)
2282 {
2283- m_display_flags &= ~flag;
2284+ display_flags_ &= ~flag;
2285
2286 if (on)
2287- m_display_flags |= flag;
2288+ display_flags_ |= flag;
2289 }
2290
2291 /*
2292@@ -561,13 +553,13 @@
2293 ===============
2294 */
2295 void InteractiveBase::start_build_road
2296- (Coords _start, Widelands::PlayerNumber const player)
2297+ (Coords start, Widelands::PlayerNumber const player)
2298 {
2299 // create an empty path
2300- assert(!m_buildroad);
2301- m_buildroad = new CoordPath(_start);
2302+ assert(!buildroad_);
2303+ buildroad_ = new CoordPath(start);
2304
2305- m_road_build_player = player;
2306+ road_build_player_ = player;
2307
2308 roadb_add_overlay();
2309 }
2310@@ -580,14 +572,14 @@
2311 */
2312 void InteractiveBase::abort_build_road()
2313 {
2314- assert(m_buildroad);
2315+ assert(buildroad_);
2316
2317 roadb_remove_overlay();
2318
2319- m_road_build_player = 0;
2320+ road_build_player_ = 0;
2321
2322- delete m_buildroad;
2323- m_buildroad = nullptr;
2324+ delete buildroad_;
2325+ buildroad_ = nullptr;
2326 }
2327
2328
2329@@ -598,20 +590,20 @@
2330 */
2331 void InteractiveBase::finish_build_road()
2332 {
2333- assert(m_buildroad);
2334+ assert(buildroad_);
2335
2336 roadb_remove_overlay();
2337
2338- if (m_buildroad->get_nsteps()) {
2339+ if (buildroad_->get_nsteps()) {
2340 upcast(Game, game, &egbase());
2341
2342 // Build the path as requested
2343 if (game)
2344 game->send_player_build_road
2345- (m_road_build_player, *new Widelands::Path(*m_buildroad));
2346+ (road_build_player_, *new Widelands::Path(*buildroad_));
2347 else
2348- egbase().get_player(m_road_build_player)->build_road
2349- (*new Widelands::Path(*m_buildroad));
2350+ egbase().get_player(road_build_player_)->build_road
2351+ (*new Widelands::Path(*buildroad_));
2352
2353 if
2354 (allow_user_input() &&
2355@@ -620,7 +612,7 @@
2356 // place flags
2357 const Map & map = egbase().map();
2358 const std::vector<Coords> & c_vector =
2359- m_buildroad->get_coords();
2360+ buildroad_->get_coords();
2361 std::vector<Coords>::const_iterator const first =
2362 c_vector.begin() + 2;
2363 std::vector<Coords>::const_iterator const last =
2364@@ -633,9 +625,9 @@
2365 ++it)
2366 if (game)
2367 game->send_player_build_flag
2368- (m_road_build_player, map.get_fcoords(*it));
2369+ (road_build_player_, map.get_fcoords(*it));
2370 else
2371- egbase().get_player(m_road_build_player)->build_flag
2372+ egbase().get_player(road_build_player_)->build_flag
2373 (map.get_fcoords(*it));
2374
2375 } else {
2376@@ -645,16 +637,16 @@
2377 --it)
2378 if (game)
2379 game->send_player_build_flag
2380- (m_road_build_player, map.get_fcoords(*it));
2381+ (road_build_player_, map.get_fcoords(*it));
2382 else
2383- egbase().get_player(m_road_build_player)->build_flag
2384+ egbase().get_player(road_build_player_)->build_flag
2385 (map.get_fcoords(*it));
2386 }
2387 }
2388 }
2389
2390- delete m_buildroad;
2391- m_buildroad = nullptr;
2392+ delete buildroad_;
2393+ buildroad_ = nullptr;
2394 }
2395
2396
2397@@ -665,21 +657,21 @@
2398 ===============
2399 */
2400 bool InteractiveBase::append_build_road(Coords const field) {
2401- assert(m_buildroad);
2402+ assert(buildroad_);
2403
2404 Map & map = egbase().map();
2405- const Widelands::Player & player = egbase().player(m_road_build_player);
2406+ const Widelands::Player & player = egbase().player(road_build_player_);
2407
2408 { // find a path to the clicked-on node
2409 Widelands::Path path;
2410 Widelands::CheckStepRoad cstep(player, Widelands::MOVECAPS_WALK);
2411 if
2412 (map.findpath
2413- (m_buildroad->get_end(), field, 0, path, cstep, Map::fpBidiCost)
2414+ (buildroad_->get_end(), field, 0, path, cstep, Map::fpBidiCost)
2415 <
2416 0)
2417 return false; // could not find a path
2418- m_buildroad->append(map, path);
2419+ buildroad_->append(map, path);
2420 }
2421
2422 {
2423@@ -690,15 +682,15 @@
2424 {
2425 Widelands::CheckStepLimited cstep;
2426 {
2427- for (const Coords& coord : m_buildroad->get_coords()) {
2428+ for (const Coords& coord : buildroad_->get_coords()) {
2429 cstep.add_allowed_location(coord);
2430 }
2431 }
2432 map.findpath
2433- (m_buildroad->get_start(), field, 0, path, cstep, Map::fpBidiCost);
2434+ (buildroad_->get_start(), field, 0, path, cstep, Map::fpBidiCost);
2435 }
2436- m_buildroad->truncate(0);
2437- m_buildroad->append(map, path);
2438+ buildroad_->truncate(0);
2439+ buildroad_->append(map, path);
2440 }
2441
2442 roadb_remove_overlay();
2443@@ -713,9 +705,9 @@
2444 ===============
2445 */
2446 Coords InteractiveBase::get_build_road_start() const {
2447- assert(m_buildroad);
2448+ assert(buildroad_);
2449
2450- return m_buildroad->get_start();
2451+ return buildroad_->get_start();
2452 }
2453
2454 /*
2455@@ -724,9 +716,9 @@
2456 ===============
2457 */
2458 Coords InteractiveBase::get_build_road_end() const {
2459- assert(m_buildroad);
2460+ assert(buildroad_);
2461
2462- return m_buildroad->get_end();
2463+ return buildroad_->get_end();
2464 }
2465
2466 void InteractiveBase::log_message(const std::string& message) const
2467@@ -747,19 +739,19 @@
2468 */
2469 void InteractiveBase::roadb_add_overlay()
2470 {
2471- assert(m_buildroad);
2472+ assert(buildroad_);
2473
2474 //log("Add overlay\n");
2475
2476 Map & map = egbase().map();
2477
2478 // preview of the road
2479- assert(!m_jobid);
2480- m_jobid = m_field_overlay_manager->next_overlay_id();
2481- const CoordPath::StepVector::size_type nr_steps = m_buildroad->get_nsteps();
2482+ assert(!jobid_);
2483+ jobid_ = field_overlay_manager_->next_overlay_id();
2484+ const CoordPath::StepVector::size_type nr_steps = buildroad_->get_nsteps();
2485 for (CoordPath::StepVector::size_type idx = 0; idx < nr_steps; ++idx) {
2486- Widelands::Direction dir = (*m_buildroad)[idx];
2487- Coords c = m_buildroad->get_coords()[idx];
2488+ Widelands::Direction dir = (*buildroad_)[idx];
2489+ Coords c = buildroad_->get_coords()[idx];
2490
2491 if (dir < Widelands::WALK_E || dir > Widelands::WALK_SW) {
2492 map.get_neighbour(c, dir, &c);
2493@@ -768,22 +760,22 @@
2494
2495 int32_t const shift = 2 * (dir - Widelands::WALK_E);
2496
2497- uint8_t set_to = m_edge_overlay_manager->get_overlay(c);
2498+ uint8_t set_to = edge_overlay_manager_->get_overlay(c);
2499 set_to |= Widelands::RoadType::kNormal << shift;
2500- m_edge_overlay_manager->register_overlay(c, set_to, m_jobid);
2501+ edge_overlay_manager_->register_overlay(c, set_to, jobid_);
2502 }
2503
2504 // build hints
2505- Widelands::FCoords endpos = map.get_fcoords(m_buildroad->get_end());
2506+ Widelands::FCoords endpos = map.get_fcoords(buildroad_->get_end());
2507
2508- assert(!m_road_buildhelp_overlay_jobid);
2509- m_road_buildhelp_overlay_jobid = m_field_overlay_manager->next_overlay_id();
2510+ assert(!road_buildhelp_overlay_jobid_);
2511+ road_buildhelp_overlay_jobid_ = field_overlay_manager_->next_overlay_id();
2512 for (int32_t dir = 1; dir <= 6; ++dir) {
2513 Widelands::FCoords neighb;
2514 int32_t caps;
2515
2516 map.get_neighbour(endpos, dir, &neighb);
2517- caps = egbase().player(m_road_build_player).get_buildcaps(neighb);
2518+ caps = egbase().player(road_build_player_).get_buildcaps(neighb);
2519
2520 if (!(caps & Widelands::MOVECAPS_WALK))
2521 continue; // need to be able to walk there
2522@@ -804,7 +796,7 @@
2523 continue;
2524 }
2525
2526- if (m_buildroad->get_index(neighb) >= 0)
2527+ if (buildroad_->get_index(neighb) >= 0)
2528 continue; // the road can't cross itself
2529
2530 int32_t slope;
2531@@ -830,12 +822,12 @@
2532 else
2533 name = "pics/roadb_red.png";
2534
2535- m_field_overlay_manager->register_overlay
2536+ field_overlay_manager_->register_overlay
2537 (neighb,
2538 g_gr->images().get(name),
2539 7,
2540 Point::invalid(),
2541- m_road_buildhelp_overlay_jobid);
2542+ road_buildhelp_overlay_jobid_);
2543 }
2544 }
2545
2546@@ -846,21 +838,21 @@
2547 */
2548 void InteractiveBase::roadb_remove_overlay()
2549 {
2550- assert(m_buildroad);
2551+ assert(buildroad_);
2552
2553 //log("Remove overlay\n");
2554
2555 // preview of the road
2556- if (m_jobid) {
2557- m_edge_overlay_manager->remove_overlay(m_jobid);
2558+ if (jobid_) {
2559+ edge_overlay_manager_->remove_overlay(jobid_);
2560 }
2561- m_jobid = 0;
2562+ jobid_ = 0;
2563
2564 // build hints
2565- if (m_road_buildhelp_overlay_jobid) {
2566- m_field_overlay_manager->remove_overlay(m_road_buildhelp_overlay_jobid);
2567+ if (road_buildhelp_overlay_jobid_) {
2568+ field_overlay_manager_->remove_overlay(road_buildhelp_overlay_jobid_);
2569 }
2570- m_road_buildhelp_overlay_jobid = 0;
2571+ road_buildhelp_overlay_jobid_ = 0;
2572 }
2573
2574
2575@@ -876,7 +868,7 @@
2576 break;
2577 /* no break */
2578 case SDLK_PAGEUP:
2579- if (upcast(Game, game, &m_egbase)) {
2580+ if (upcast(Game, game, &egbase_)) {
2581 if (GameController* const ctrl = game->game_controller()) {
2582 ctrl->set_desired_speed(ctrl->desired_speed() + 1000);
2583 }
2584@@ -884,7 +876,7 @@
2585 return true;
2586
2587 case SDLK_PAUSE:
2588- if (upcast(Game, game, &m_egbase)) {
2589+ if (upcast(Game, game, &egbase_)) {
2590 if (GameController* const ctrl = game->game_controller()) {
2591 ctrl->toggle_paused();
2592 }
2593@@ -896,7 +888,7 @@
2594 break;
2595 /* no break */
2596 case SDLK_PAGEDOWN:
2597- if (upcast(Widelands::Game, game, &m_egbase)) {
2598+ if (upcast(Widelands::Game, game, &egbase_)) {
2599 if (GameController* const ctrl = game->game_controller()) {
2600 uint32_t const speed = ctrl->desired_speed();
2601 ctrl->set_desired_speed(1000 < speed ? speed - 1000 : 0);
2602@@ -906,7 +898,7 @@
2603 #ifndef NDEBUG // only in debug builds
2604 case SDLK_F6:
2605 GameChatMenu::create_script_console(
2606- this, m_debugconsole, *DebugConsole::get_chat_provider());
2607+ this, debugconsole_, *DebugConsole::get_chat_provider());
2608 return true;
2609 #endif
2610 default:
2611
2612=== modified file 'src/wui/interactive_base.h'
2613--- src/wui/interactive_base.h 2016-01-10 11:36:05 +0000
2614+++ src/wui/interactive_base.h 2016-01-16 15:57:59 +0000
2615@@ -64,10 +64,10 @@
2616 InteractiveBase(Widelands::EditorGameBase &, Section & global_s);
2617 virtual ~InteractiveBase();
2618
2619- Widelands::EditorGameBase & egbase() const {return m_egbase;}
2620+ Widelands::EditorGameBase & egbase() const {return egbase_;}
2621 virtual void reference_player_tribe(Widelands::PlayerNumber, const void * const) {}
2622
2623- bool m_show_workarea_preview;
2624+ bool show_workarea_preview_;
2625 FieldOverlayManager::OverlayId show_work_area(const WorkareaInfo& workarea_info,
2626 Widelands::Coords coords);
2627 void hide_work_area(FieldOverlayManager::OverlayId overlay_id);
2628@@ -79,9 +79,9 @@
2629 virtual void postload();
2630
2631 const Widelands::NodeAndTriangle<> & get_sel_pos() const {
2632- return m_sel.pos;
2633+ return sel_.pos;
2634 }
2635- bool get_sel_freeze() const {return m_sel.freeze;}
2636+ bool get_sel_freeze() const {return sel_.freeze;}
2637
2638 // Returns true if the buildhelp is currently displayed.
2639 bool buildhelp() const;
2640@@ -93,12 +93,12 @@
2641 * sel_triangles determines whether the mouse pointer selects triangles.
2642 * (False meas that it selects nodes.)
2643 */
2644- bool get_sel_triangles() const {return m_sel.triangles;}
2645- void set_sel_triangles(const bool yes) {m_sel.triangles = yes;}
2646+ bool get_sel_triangles() const {return sel_.triangles;}
2647+ void set_sel_triangles(const bool yes) {sel_.triangles = yes;}
2648
2649- uint32_t get_sel_radius() const {return m_sel.radius;}
2650+ uint32_t get_sel_radius() const {return sel_.radius;}
2651 virtual void set_sel_pos(Widelands::NodeAndTriangle<>);
2652- void set_sel_freeze(const bool yes) {m_sel.freeze = yes;}
2653+ void set_sel_freeze(const bool yes) {sel_.freeze = yes;}
2654 void set_sel_radius(uint32_t);
2655
2656 void move_view_to(Widelands::Coords);
2657@@ -111,8 +111,8 @@
2658 void set_display_flag(uint32_t flag, bool on);
2659
2660 // road building
2661- bool is_building_road() const {return m_buildroad;}
2662- Widelands::CoordPath * get_build_road() {return m_buildroad;}
2663+ bool is_building_road() const {return buildroad_;}
2664+ Widelands::CoordPath * get_build_road() {return buildroad_;}
2665 void start_build_road
2666 (Widelands::Coords start, Widelands::PlayerNumber player);
2667 void abort_build_road();
2668@@ -132,14 +132,14 @@
2669 }
2670
2671 const FieldOverlayManager& field_overlay_manager() const {
2672- return *m_field_overlay_manager;
2673+ return *field_overlay_manager_;
2674 }
2675 FieldOverlayManager* mutable_field_overlay_manager() {
2676- return m_field_overlay_manager.get();
2677+ return field_overlay_manager_.get();
2678 }
2679
2680 const EdgeOverlayManager& edge_overlay_manager() const {
2681- return *m_edge_overlay_manager;
2682+ return *edge_overlay_manager_;
2683 }
2684
2685 void toggle_minimap();
2686@@ -162,13 +162,13 @@
2687 void unset_sel_picture();
2688 void set_sel_picture(const char * const);
2689 void adjust_toolbar_position() {
2690- m_toolbar.set_pos
2691- (Point((get_inner_w() - m_toolbar.get_w()) >> 1, get_inner_h() - 34));
2692+ toolbar_.set_pos
2693+ (Point((get_inner_w() - toolbar_.get_w()) >> 1, get_inner_h() - 34));
2694 }
2695
2696 // TODO(sirver): why are these protected?
2697- ChatOverlay * m_chatOverlay;
2698- UI::Box m_toolbar;
2699+ ChatOverlay * chat_overlay_;
2700+ UI::Box toolbar_;
2701
2702 private:
2703 void roadb_add_overlay ();
2704@@ -191,39 +191,39 @@
2705 freeze(Freeze), triangles(Triangles), pos(Pos), radius(Radius),
2706 pic(Pic), jobid(Jobid)
2707 {}
2708- bool freeze; // don't change m_sel even if mouse moves
2709+ bool freeze; // don't change sel _even if mouse moves
2710 bool triangles; // otherwise nodes
2711 Widelands::NodeAndTriangle<> pos;
2712 uint32_t radius;
2713 const Image* pic;
2714 FieldOverlayManager::OverlayId jobid;
2715- } m_sel;
2716+ } sel_;
2717
2718 std::unique_ptr<InteractiveBaseInternals> m;
2719
2720- std::unique_ptr<FieldOverlayManager> m_field_overlay_manager;
2721- std::unique_ptr<EdgeOverlayManager> m_edge_overlay_manager;
2722+ std::unique_ptr<FieldOverlayManager> field_overlay_manager_;
2723+ std::unique_ptr<EdgeOverlayManager> edge_overlay_manager_;
2724
2725 std::unique_ptr<Notifications::Subscriber<GraphicResolutionChanged>>
2726 graphic_resolution_changed_subscriber_;
2727- Widelands::EditorGameBase & m_egbase;
2728- uint32_t m_display_flags;
2729- uint32_t m_lastframe; // system time (milliseconds)
2730- uint32_t m_frametime; // in millseconds
2731- uint32_t m_avg_usframetime; // in microseconds!
2732-
2733- EdgeOverlayManager::OverlayId m_jobid;
2734- FieldOverlayManager::OverlayId m_road_buildhelp_overlay_jobid;
2735- Widelands::CoordPath * m_buildroad; // path for the new road
2736- Widelands::PlayerNumber m_road_build_player;
2737-
2738- UI::UniqueWindow::Registry m_debugconsole;
2739+ Widelands::EditorGameBase & egbase_;
2740+ uint32_t display_flags_;
2741+ uint32_t lastframe_; // system time (milliseconds)
2742+ uint32_t frametime_; // in millseconds
2743+ uint32_t avg_usframetime_; // in microseconds!
2744+
2745+ EdgeOverlayManager::OverlayId jobid_;
2746+ FieldOverlayManager::OverlayId road_buildhelp_overlay_jobid_;
2747+ Widelands::CoordPath * buildroad_; // path for the new road
2748+ Widelands::PlayerNumber road_build_player_;
2749+
2750+ UI::UniqueWindow::Registry debugconsole_;
2751 std::unique_ptr<UniqueWindowHandler> unique_window_handler_;
2752- std::vector<const Image*> m_workarea_pics;
2753+ std::vector<const Image*> workarea_pics_;
2754 };
2755
2756 #define PIC2 g_gr->images().get("pics/but2.png")
2757 #define TOOLBAR_BUTTON_COMMON_PARAMETERS(name) \
2758- &m_toolbar, name, 0, 0, 34U, 34U, PIC2
2759+ &toolbar_, name, 0, 0, 34U, 34U, PIC2
2760
2761 #endif // end of include guard: WL_WUI_INTERACTIVE_BASE_H
2762
2763=== modified file 'src/wui/interactive_gamebase.cc'
2764--- src/wui/interactive_gamebase.cc 2016-01-10 11:36:05 +0000
2765+++ src/wui/interactive_gamebase.cc 2016-01-16 15:57:59 +0000
2766@@ -51,7 +51,7 @@
2767 PlayerType pt, bool const chatenabled, bool const multiplayer)
2768 :
2769 InteractiveBase(_game, global_s),
2770- m_chatProvider(nullptr),
2771+ chat_provider_(nullptr),
2772 m_building_census_format
2773 (global_s.get_string("building_census_format", "%N")),
2774 m_building_statistics_format
2775@@ -87,15 +87,15 @@
2776
2777 void InteractiveGameBase::set_chat_provider(ChatProvider & chat)
2778 {
2779- m_chatProvider = &chat;
2780- m_chatOverlay->set_chat_provider(chat);
2781+ chat_provider_ = &chat;
2782+ chat_overlay_->set_chat_provider(chat);
2783
2784 m_chatenabled = true;
2785 }
2786
2787 ChatProvider * InteractiveGameBase::get_chat_provider()
2788 {
2789- return m_chatProvider;
2790+ return chat_provider_;
2791 }
2792
2793 void InteractiveGameBase::draw_overlay(RenderTarget& dst) {
2794
2795=== modified file 'src/wui/interactive_gamebase.h'
2796--- src/wui/interactive_gamebase.h 2016-01-07 12:47:17 +0000
2797+++ src/wui/interactive_gamebase.h 2016-01-16 15:57:59 +0000
2798@@ -91,7 +91,7 @@
2799 virtual int32_t calculate_buildcaps(const Widelands::TCoords<Widelands::FCoords> c) = 0;
2800
2801 GameMainMenuWindows m_mainm_windows;
2802- ChatProvider * m_chatProvider;
2803+ ChatProvider * chat_provider_;
2804 std::string m_building_census_format;
2805 std::string m_building_statistics_format;
2806 std::string m_building_tooltip_format;
2807
2808=== modified file 'src/wui/interactive_player.cc'
2809--- src/wui/interactive_player.cc 2016-01-10 11:36:05 +0000
2810+++ src/wui/interactive_player.cc 2016-01-16 15:57:59 +0000
2811@@ -69,7 +69,7 @@
2812 m_auto_roadbuild_mode(global_s.get_bool("auto_roadbuild_mode", true)),
2813 m_flag_to_connect(Widelands::Coords::null()),
2814
2815-// Chat is different, as m_chatProvider needs to be checked when toggling
2816+// Chat is different, as chat_provider_ needs to be checked when toggling
2817 // Minimap is different as it warps and stuff
2818
2819 #define INIT_BTN_this(picture, name, tooltip) \
2820@@ -124,19 +124,19 @@
2821
2822 // TODO(unknown): instead of making unneeded buttons invisible after generation,
2823 // they should not at all be generated. -> implement more dynamic toolbar UI
2824- m_toolbar.add(&m_toggle_options_menu, UI::Box::AlignLeft);
2825- m_toolbar.add(&m_toggle_statistics_menu, UI::Box::AlignLeft);
2826- m_toolbar.add(&m_toggle_minimap, UI::Box::AlignLeft);
2827- m_toolbar.add(&m_toggle_buildhelp, UI::Box::AlignLeft);
2828+ toolbar_.add(&m_toggle_options_menu, UI::Box::AlignLeft);
2829+ toolbar_.add(&m_toggle_statistics_menu, UI::Box::AlignLeft);
2830+ toolbar_.add(&m_toggle_minimap, UI::Box::AlignLeft);
2831+ toolbar_.add(&m_toggle_buildhelp, UI::Box::AlignLeft);
2832 if (multiplayer) {
2833- m_toolbar.add(&m_toggle_chat, UI::Box::AlignLeft);
2834+ toolbar_.add(&m_toggle_chat, UI::Box::AlignLeft);
2835 m_toggle_chat.set_visible(false);
2836 m_toggle_chat.set_enabled(false);
2837 }
2838
2839- m_toolbar.add(&m_toggle_help, UI::Box::AlignLeft);
2840- m_toolbar.add(&m_toggle_objectives, UI::Box::AlignLeft);
2841- m_toolbar.add(&m_toggle_message_menu, UI::Box::AlignLeft);
2842+ toolbar_.add(&m_toggle_help, UI::Box::AlignLeft);
2843+ toolbar_.add(&m_toggle_objectives, UI::Box::AlignLeft);
2844+ toolbar_.add(&m_toggle_message_menu, UI::Box::AlignLeft);
2845
2846 set_player_number(plyn);
2847 fieldclicked.connect(boost::bind(&InteractivePlayer::node_action, this));
2848@@ -249,8 +249,8 @@
2849 void InteractivePlayer::toggle_chat() {
2850 if (m_chat.window)
2851 delete m_chat.window;
2852- else if (m_chatProvider)
2853- GameChatMenu::create_chat_console(this, m_chat, *m_chatProvider);
2854+ else if (chat_provider_)
2855+ GameChatMenu::create_chat_console(this, m_chat, *chat_provider_);
2856 }
2857
2858 bool InteractivePlayer::can_see(Widelands::PlayerNumber const p) const
2859@@ -360,11 +360,11 @@
2860
2861 case SDLK_KP_ENTER:
2862 case SDLK_RETURN:
2863- if (!m_chatProvider | !m_chatenabled || !is_multiplayer())
2864+ if (!chat_provider_ | !m_chatenabled || !is_multiplayer())
2865 break;
2866
2867 if (!m_chat.window)
2868- GameChatMenu::create_chat_console(this, m_chat, *m_chatProvider);
2869+ GameChatMenu::create_chat_console(this, m_chat, *chat_provider_);
2870
2871 return true;
2872 default:
2873
2874=== modified file 'src/wui/interactive_spectator.cc'
2875--- src/wui/interactive_spectator.cc 2015-11-01 10:11:56 +0000
2876+++ src/wui/interactive_spectator.cc 2016-01-16 15:57:59 +0000
2877@@ -69,16 +69,16 @@
2878 m_toggle_statistics.sigclicked.connect(boost::bind(&InteractiveSpectator::toggle_statistics, this));
2879 m_toggle_minimap.sigclicked.connect(boost::bind(&InteractiveSpectator::toggle_minimap, this));
2880
2881- m_toolbar.set_layout_toplevel(true);
2882+ toolbar_.set_layout_toplevel(true);
2883 if (!is_multiplayer()) {
2884- m_toolbar.add(&m_exit, UI::Box::AlignLeft);
2885- m_toolbar.add(&m_save, UI::Box::AlignLeft);
2886+ toolbar_.add(&m_exit, UI::Box::AlignLeft);
2887+ toolbar_.add(&m_save, UI::Box::AlignLeft);
2888 } else
2889- m_toolbar.add(&m_toggle_options_menu, UI::Box::AlignLeft);
2890- m_toolbar.add(&m_toggle_statistics, UI::Box::AlignLeft);
2891- m_toolbar.add(&m_toggle_minimap, UI::Box::AlignLeft);
2892- m_toolbar.add(&m_toggle_buildhelp, UI::Box::AlignLeft);
2893- m_toolbar.add(&m_toggle_chat, UI::Box::AlignLeft);
2894+ toolbar_.add(&m_toggle_options_menu, UI::Box::AlignLeft);
2895+ toolbar_.add(&m_toggle_statistics, UI::Box::AlignLeft);
2896+ toolbar_.add(&m_toggle_minimap, UI::Box::AlignLeft);
2897+ toolbar_.add(&m_toggle_buildhelp, UI::Box::AlignLeft);
2898+ toolbar_.add(&m_toggle_chat, UI::Box::AlignLeft);
2899
2900 // TODO(unknown): instead of making unneeded buttons invisible after generation,
2901 // they should not at all be generated. -> implement more dynamic toolbar UI
2902@@ -162,8 +162,8 @@
2903 {
2904 if (m_chat.window)
2905 delete m_chat.window;
2906- else if (m_chatProvider)
2907- GameChatMenu::create_chat_console(this, m_chat, *m_chatProvider);
2908+ else if (chat_provider_)
2909+ GameChatMenu::create_chat_console(this, m_chat, *chat_provider_);
2910 }
2911
2912
2913@@ -270,11 +270,11 @@
2914
2915 case SDLK_RETURN:
2916 case SDLK_KP_ENTER:
2917- if (!m_chatProvider | !m_chatenabled)
2918+ if (!chat_provider_ | !m_chatenabled)
2919 break;
2920
2921 if (!m_chat.window)
2922- GameChatMenu::create_chat_console(this, m_chat, *m_chatProvider);
2923+ GameChatMenu::create_chat_console(this, m_chat, *chat_provider_);
2924
2925 dynamic_cast<GameChatMenu*>(m_chat.window)->enter_chat_message();
2926 return true;
2927
2928=== modified file 'test/maps/lua_testsuite.wmf/scripting/efield.lua'
2929--- test/maps/lua_testsuite.wmf/scripting/efield.lua 2016-01-01 17:35:01 +0000
2930+++ test/maps/lua_testsuite.wmf/scripting/efield.lua 2016-01-16 15:57:59 +0000
2931@@ -13,7 +13,7 @@
2932 function field_resources_tests:test_initial_resource_in_editor()
2933 -- making sure that (set_) resource_amount sets also initial resource in the editor
2934 -- the resource has to be set to something different than 'none', as none has no amount
2935- self.f.resource = "coal"
2936+ self.f.resource = "water"
2937 self.f.resource_amount=10
2938 assert_equal(self.f.initial_resource_amount, self.f.resource_amount)
2939 assert_equal(10, self.f.initial_resource_amount)
2940
2941=== modified file 'test/maps/lua_testsuite.wmf/scripting/gfield.lua'
2942--- test/maps/lua_testsuite.wmf/scripting/gfield.lua 2015-10-31 12:11:44 +0000
2943+++ test/maps/lua_testsuite.wmf/scripting/gfield.lua 2016-01-16 15:57:59 +0000
2944@@ -9,13 +9,14 @@
2945 assert_equal(5, self.f.resource_amount)
2946 end
2947
2948-
2949-
2950 function field_resources_tests:test_initial_resources_in_game()
2951 -- Changing a resource in game should not change the
2952 -- initial_resources.
2953- assert_equal("water", self.f.resource)
2954- assert_equal(5, self.f.initial_resource_amount)
2955- self.f.resource_amount = 1
2956- assert_equal(5, self.f.initial_resource_amount)
2957+ local f = map:get_field(61,40)
2958+ assert_equal("water", f.resource)
2959+ assert_equal(5, f.initial_resource_amount)
2960+ assert_equal(5, f.resource_amount)
2961+ f.resource_amount = 1
2962+ assert_equal(5, f.initial_resource_amount)
2963+ assert_equal(1, f.resource_amount)
2964 end

Subscribers

People subscribed via source and target branches

to status/vote changes: