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

Proposed by SirVer
Status: Merged
Merged at revision: 7694
Proposed branch: lp:~widelands-dev/widelands/fix_overlays
Merge into: lp:widelands
Diff against target: 194 lines (+33/-31)
8 files modified
src/editor/tools/editor_decrease_resources_tool.cc (+2/-2)
src/editor/tools/editor_increase_resources_tool.cc (+2/-3)
src/editor/tools/editor_set_resources_tool.cc (+12/-19)
src/editor/tools/editor_set_resources_tool.h (+5/-3)
src/editor/tools/editor_set_starting_pos_tool.cc (+1/-1)
src/editor/ui_menus/editor_tool_change_resources_options_menu.cc (+6/-2)
src/wui/overlay_manager.cc (+1/-0)
src/wui/overlay_manager.h (+4/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fix_overlays
Reviewer Review Type Date Requested Status
xxx-deleted (community) Approve
kaputtnik (community) Approve
SirVer Needs Resubmitting
GunChleoc Approve
Review via email: mp+281641@code.launchpad.net

Commit message

Fixes the display of the buildhelp.

This got broken in r7688 by changing the callback function of the OverlayManager to return a bool instead of a NodeCap.

Description of the change

Fixes the buildhelp.

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

Still needs testing, but code LGTM.

review: Approve
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_overlays mirrored to https://github.com/widelands/widelands/tree/_widelands_dev_widelands_fix_overlays

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
kaputtnik (franku) wrote :

Solved buildhelp during game play, but in editor there is something wrong:

1. When trying to place resources on mountains, the red small house is displayed on the mountains
2. When trying to place fish resource in editor the small red house is displayed on water

review: Needs Fixing
Revision history for this message
bunnybot (widelandsofficial) wrote :

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

Revision history for this message
SirVer (sirver) wrote :

Should be all good now. I did some mild refactorings during bug tracking too. PTAL.

review: Needs Resubmitting
Revision history for this message
GunChleoc (gunchleoc) wrote :

Code still LGTM.

Revision history for this message
kaputtnik (franku) wrote :

Works now as expected :-)

The only thing is what Tino already mentioned: A resource could not removed if one choose another resource and hold down Shift while clicking. See https://code.launchpad.net/~janosch-peters/widelands/editor-remove-invalid-resources/+merge/281462/comments/713355

I don't know how it was before, but this is a inconsistent behavior to immovables. Immovables could ever be removed from the map regardless of the kind of actual immovable. F.e. trees could be removed if a ruin is selected by holding down Shift. So we might want to make a new bug about this?

Another side note: For resource water there is only one image in the repo (precisely there are two images: water.png and water4.png which are exactly the same). For other resources there are 4 images used, representing the amount of resource placed on the map. Is this intended or are the small images for water just missing?

Approve functionality for the build help.

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

Dammn... two times reread but still ambiguous...please replace:

" F.e. trees could be removed if a ruin is selected by holding down Shift."
with
" F.e. trees could be removed if a ruin is selected and hold down Shift."

Revision history for this message
GunChleoc (gunchleoc) wrote :

I think water is just there or not, and it doesn't deplete - we only have 1 resource indicator for it too.

Please open a new bug for the resource removing thing.

Revision history for this message
TiborB (tiborb95) wrote :

> A resource could not removed if one choose another resource and hold down Shift while clicking.

This is old behavior, and yes it is inconsistency (between underground resources and removables)...

Revision history for this message
TiborB (tiborb95) wrote :

correction: ...immovables - of course

Revision history for this message
xxx-deleted (janosch-peters-deactivatedaccount) wrote :

Tho code look good, sorry for introducing this bug.

About the resource-editing thing: Strictly speaking I think the behaviour is consistent.

The analogous feature of "remove immovable" in terms of resources is "set resource to 0". This works even if you have a different resource selected. The decrease/increase resource has no equivalent.

After a little bit of testing I also think the current increase/decrease behaviour makes sense. Imaging you have several resource sitting next to another. If you have a bigger tool size and start to reduce resources, it should only affect the resource you have selected. If we change the behaviour to allow decreasing any resource, at least in my scenario this will lead to unexpected results.

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

> Tho code look good, sorry for introducing this bug.

no worries, changing code introduces bugs, that is the way of life.

> I think water is just there or not, and it doesn't deplete - we only have 1 resource indicator for it too.

that is not correct. Water is not handled special in any way in the code, it is just another resource. The 'percentage found when depleted' is just set higher for wells.
I think I was just too lazy to make more than one water resource indicator back in the day, there is really no reason why there is only one that I can think of.

thanks for reviewing/testing. It seems like everybody is happy with this branch now, the open discussion items have nothing to do with the changes in this particular branch. So gonna merge now.

@bunnybot merge

Revision history for this message
kaputtnik (franku) wrote :

Yes, you are right :-)

I didn't understand the post from GunChleoc. My question was just if there are images for water resource missing which indicates less amount of water on the map.

Revision history for this message
GunChleoc (gunchleoc) wrote :

From what Sirver said, it sounds like I am wrong and they are missing. So is a resource indicator for little water as opposed to a lot of water. Would you like fixing that for us?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/tools/editor_decrease_resources_tool.cc'
2--- src/editor/tools/editor_decrease_resources_tool.cc 2016-01-04 20:50:19 +0000
3+++ src/editor/tools/editor_decrease_resources_tool.cc 2016-01-07 09:30:32 +0000
4@@ -56,10 +56,10 @@
5 map->is_resource_valid(world, mr.location(), args->cur_res)) {
6 args->orgResT.push_back(mr.location().field->get_resources());
7 args->orgRes.push_back(mr.location().field->get_resources_amount());
8- EditorSetResourcesTool::set_res_and_overlay(world, amount, args->cur_res, &mr, args, map);
9+ EditorSetResourcesTool::set_res_and_overlay(
10+ world, amount, args->cur_res, mr.location(), map);
11 }
12
13-
14 } while (mr.advance(*map));
15 return mr.radius();
16 }
17
18=== modified file 'src/editor/tools/editor_increase_resources_tool.cc'
19--- src/editor/tools/editor_increase_resources_tool.cc 2016-01-04 20:50:19 +0000
20+++ src/editor/tools/editor_increase_resources_tool.cc 2016-01-07 09:30:32 +0000
21@@ -54,10 +54,9 @@
22 map->is_resource_valid(world, mr.location(), args->cur_res)) {
23 args->orgResT.push_back(mr.location().field->get_resources());
24 args->orgRes.push_back(mr.location().field->get_resources_amount());
25- EditorSetResourcesTool::set_res_and_overlay(world, amount, args->cur_res, &mr, args, map);
26+ EditorSetResourcesTool::set_res_and_overlay(
27+ world, amount, args->cur_res, mr.location(), map);
28 }
29-
30-
31 } while (mr.advance(*map));
32 return mr.radius();
33 }
34
35=== modified file 'src/editor/tools/editor_set_resources_tool.cc'
36--- src/editor/tools/editor_set_resources_tool.cc 2016-01-04 20:50:19 +0000
37+++ src/editor/tools/editor_set_resources_tool.cc 2016-01-07 09:30:32 +0000
38@@ -52,10 +52,8 @@
39 if (map->is_resource_valid(world, mr.location(), args->cur_res)) {
40 args->orgResT.push_back(mr.location().field->get_resources());
41 args->orgRes.push_back(mr.location().field->get_resources_amount());
42- set_res_and_overlay(world, amount, args->cur_res, &mr, args, map);
43+ set_res_and_overlay(world, amount, args->cur_res, mr.location(), map);
44 }
45-
46-
47 } while (mr.advance(*map));
48 return mr.radius();
49 }
50@@ -66,14 +64,12 @@
51 EditorInteractive& /* parent */,
52 EditorActionArgs* args,
53 Widelands::Map* map) {
54- OverlayManager & overlay_manager = map->overlay_manager();
55 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
56 (*map,
57 Widelands::Area<Widelands::FCoords>
58 (map->get_fcoords(center.node), args->sel_radius));
59 std::list<uint8_t>::iterator ir = args->orgRes.begin(), it = args->orgResT.begin();
60 do {
61- int32_t res = mr.location().field->get_resources();
62 int32_t amount = *ir;
63 int32_t max_amount = world.get_resource(args->cur_res)->max_amount();
64
65@@ -82,7 +78,7 @@
66 if (amount > max_amount)
67 amount = max_amount;
68
69- set_res_and_overlay(world, amount, *ir, &mr, args, map);
70+ set_res_and_overlay(world, amount, *ir, mr.location(), map);
71
72 ++ir;
73 ++it;
74@@ -102,31 +98,28 @@
75
76 void EditorSetResourcesTool::set_res_and_overlay(const Widelands::World& world,
77 int32_t amount, uint8_t new_res,
78- Widelands::MapRegion<Widelands::Area<Widelands::FCoords> >* mr,
79- EditorActionArgs* args,
80+ const Widelands::FCoords& fcoords,
81 Widelands::Map* map) {
82- int32_t old_res = mr->location().field->get_resources();
83+ int32_t old_res = fcoords.field->get_resources();
84
85 // Ok, we're doing something. First remove the current overlays.
86 if (old_res != Widelands::kNoResource) {
87 std::string str = world.get_resource(old_res)->get_editor_pic(
88- mr->location().field->get_resources_amount());
89+ fcoords.field->get_resources_amount());
90 const Image* pic = g_gr->images().get(str);
91- map->overlay_manager().remove_overlay(mr->location(), pic);
92+ map->overlay_manager().remove_overlay(fcoords, pic);
93 }
94
95 if (!amount) {
96- mr->location().field->set_resources(Widelands::kNoResource, 0);
97- mr->location().field->set_initial_res_amount(0);
98+ fcoords.field->set_resources(Widelands::kNoResource, 0);
99+ fcoords.field->set_initial_res_amount(0);
100 } else {
101- mr->location().field->set_resources(new_res, amount);
102- mr->location().field->set_initial_res_amount(amount);
103+ fcoords.field->set_resources(new_res, amount);
104+ fcoords.field->set_initial_res_amount(amount);
105 // set new overlay
106 std::string str = world.get_resource(new_res)->get_editor_pic(amount);
107 const Image* pic = g_gr->images().get(str);
108- map->overlay_manager().register_overlay(mr->location(), pic, 4);
109- map->recalc_for_field_area(
110- world, Widelands::Area<Widelands::FCoords>(mr->location(), 0));
111+ map->overlay_manager().register_overlay(fcoords, pic, 0);
112+ map->recalc_for_field_area(world, Widelands::Area<Widelands::FCoords>(fcoords, 0));
113 }
114 }
115-
116
117=== modified file 'src/editor/tools/editor_set_resources_tool.h'
118--- src/editor/tools/editor_set_resources_tool.h 2016-01-04 20:50:19 +0000
119+++ src/editor/tools/editor_set_resources_tool.h 2016-01-07 09:30:32 +0000
120@@ -50,9 +50,11 @@
121 /**
122 * Sets the resource amount and updates the overlay.
123 */
124- static void set_res_and_overlay(const Widelands::World& world, int32_t amount, uint8_t resIx,
125- Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > *mr,
126- EditorActionArgs* args, Widelands::Map* map);
127+ static void set_res_and_overlay(const Widelands::World& world,
128+ int32_t amount,
129+ uint8_t resIx,
130+ const Widelands::FCoords& fcoords,
131+ Widelands::Map* map);
132
133 char const * get_sel_impl() const override {
134 return "pics/fsel_editor_set_resources.png";
135
136=== modified file 'src/editor/tools/editor_set_starting_pos_tool.cc'
137--- src/editor/tools/editor_set_starting_pos_tool.cc 2016-01-04 20:50:19 +0000
138+++ src/editor/tools/editor_set_starting_pos_tool.cc 2016-01-07 09:30:32 +0000
139@@ -95,7 +95,7 @@
140
141 // add new overlay
142 overlay_manager.register_overlay
143- (center.node, pic, 8, Point(pic->width() / 2, STARTING_POS_HOTSPOT_Y));
144+ (center.node, pic, 4, Point(pic->width() / 2, STARTING_POS_HOTSPOT_Y));
145
146 // set new player pos
147 map->set_starting_pos(m_current_player, center.node);
148
149=== modified file 'src/editor/ui_menus/editor_tool_change_resources_options_menu.cc'
150--- src/editor/ui_menus/editor_tool_change_resources_options_menu.cc 2016-01-05 10:07:13 +0000
151+++ src/editor/ui_menus/editor_tool_change_resources_options_menu.cc 2016-01-07 09:30:32 +0000
152@@ -222,8 +222,12 @@
153 Widelands::EditorGameBase& egbase = eia().egbase();
154 Widelands::Map & map = egbase.map();
155 map.overlay_manager().register_overlay_callback_function(
156- [&] (const Widelands::TCoords<Widelands::FCoords>& coords)
157- {return map.is_resource_valid(egbase.world(), coords, resIx);});
158+ [resIx, &map, &egbase](const Widelands::TCoords<Widelands::FCoords>& coords) -> uint32_t {
159+ if (map.is_resource_valid(egbase.world(), coords, resIx)) {
160+ return coords.field->nodecaps();
161+ }
162+ return 0;
163+ });
164
165 map.recalc_whole_map(egbase.world());
166 select_correct_tool();
167
168=== modified file 'src/wui/overlay_manager.cc'
169--- src/wui/overlay_manager.cc 2015-12-30 21:47:08 +0000
170+++ src/wui/overlay_manager.cc 2016-01-07 09:30:32 +0000
171@@ -44,6 +44,7 @@
172 RegisteredOverlaysMap::const_iterator it = overlay_map.lower_bound(c);
173 while (it != overlay_map.end() && it->first == c && it->second.level <= MAX_OVERLAYS_PER_NODE)
174 {
175+ assert(it->second.pic);
176 overlays[num_ret].pic = it->second.pic;
177 overlays[num_ret].hotspot = it->second.hotspot;
178 if (++num_ret == MAX_OVERLAYS_PER_NODE)
179
180=== modified file 'src/wui/overlay_manager.h'
181--- src/wui/overlay_manager.h 2016-01-03 21:51:01 +0000
182+++ src/wui/overlay_manager.h 2016-01-07 09:30:32 +0000
183@@ -65,8 +65,11 @@
184 Point hotspot;
185 };
186
187+ // The function used to calculate overlays for the build help. The function
188+ // needs to return the nodecaps of the field that correspond to the image
189+ // that should be used.
190 using CallbackFn =
191- boost::function<bool(const Widelands::TCoords<Widelands::FCoords>& coordinates)>;
192+ boost::function<int32_t(const Widelands::TCoords<Widelands::FCoords>& coordinates)>;
193
194 OverlayManager();
195

Subscribers

People subscribed via source and target branches

to status/vote changes: