Merge lp:~nordfriese/widelands/workareas into lp:widelands
- workareas
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 9077 | ||||
Proposed branch: | lp:~nordfriese/widelands/workareas | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
741 lines (+371/-46) 19 files modified
data/shaders/workarea.fp (+7/-0) data/shaders/workarea.vp (+15/-0) src/editor/editorinteractive.cc (+1/-1) src/graphic/CMakeLists.txt (+2/-0) src/graphic/game_renderer.cc (+8/-0) src/graphic/game_renderer.h (+1/-0) src/graphic/gl/workarea_program.cc (+134/-0) src/graphic/gl/workarea_program.h (+78/-0) src/graphic/render_queue.cc (+10/-0) src/graphic/render_queue.h (+4/-0) src/logic/widelands_geometry.h (+4/-0) src/wui/buildingwindow.cc (+1/-1) src/wui/interactive_base.cc (+87/-18) src/wui/interactive_base.h (+5/-4) src/wui/interactive_player.cc (+8/-10) src/wui/interactive_player.h (+2/-0) src/wui/interactive_spectator.cc (+1/-9) src/wui/mapview.cc (+2/-2) src/wui/mapview.h (+1/-1) |
||||
To merge this branch: | bzr merge lp:~nordfriese/widelands/workareas | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
GunChleoc | Approve | ||
Review via email: mp+364266@code.launchpad.net |
Commit message
Show the work areas of buildings as overlays on triangles
Description of the change
GunChleoc (gunchleoc) wrote : | # |
Toni Förster (stonerl) wrote : | # |
I like it so far, the node markers are a little too thin, IMHO. Why not use the old workarea12.png or workarea1.png? They are small enough.
Benedikt Straub (nordfriese) wrote : | # |
Implemented your comment and updated the documentation.
I think the old markers are much too big and bright, I never really liked them. The purpose of these markers now is only to hint at the locations of nodes; IMHO a small, light cross is enough for that. If you want something bigger, you can always enable the buildhelp…
GunChleoc (gunchleoc) wrote : | # |
constexpr kWorkareaTransp
Toni Förster (stonerl) wrote : | # |
Fair enough. But are they supposed to be a to look like a ++
Just a question; this is in no way related to your changes. I noticed that some military buildings, like the Fortress, have a different colour on the outer layer, what is this supposed to indicate?
Toni Förster (stonerl) wrote : | # |
Can't build r9014.
src/graphic/
constexpr kWorkareaTransp
Benedikt Straub (nordfriese) wrote : | # |
Fixed the typo, should compile now.
The marker is a small star (*) with six beams that point in the six cardinal directions.
The outer circle(s) is/are the enhancement area(s). They indicate the additional area that will be part of the workarea after an upgrade. We already have different overlay images for those in trunk, it´s just more noticeable with the colours now.
Toni Förster (stonerl) wrote : | # |
I made two different versions of the marker. You can find them here:
https:/
https:/
Would you give them a try?
Benedikt Straub (nordfriese) wrote : | # |
I think version 2 looks like a square with a circle in it, that looks strange. Version 1 is good, a bit too large though IMHO. I uploaded a new image similar to it now, how about this?
Toni Förster (stonerl) wrote : | # |
Looks good.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4585. State: errored. Details: https:/
Appveyor build 4372. State: failed. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
I have done some testing as well and have selected multiple buildings on a slow machine - no problem :)
For the grid, how about having another shader that draws lines on the edges? That would also take care of most of the work for adding a grid to the editor:
kaputtnik (franku) wrote : | # |
Looks very good :)
I wonder why the little stars are missing on the border? For an enhanceable building the stars are at the edge of the bluish area. E.g. compare the workarea when trying to build an empire Outpost the stars are at the edge of the bluish and red area, then try to build an empire Barrier (the one which the Outpost can be enhanced to) on the same spot the stars are one node inside the bluish area.
For farms the stars are also one node inside the bluish area, so not showing all the nodes where fields can be planted.
Benedikt Straub (nordfriese) wrote : | # |
Well spotted, pushed a fix for it…
> For the grid, how about having another shader that draws lines on the edges? That would also take care of most of the work for adding a grid to the editor
I´m going to try to take care of that feature soon :)
But I´m against showing a real grid in-game. It´s fine to hint at it by using on-node markers like the buildhelp and these star markers, but IMHO an actual grid is only a tool to make it easier to design the map, and not desirable for the gameplay.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4599. State: passed. Details: https:/
Appveyor build 4387. State: failed. Details: https:/
Klaus Halfmann (klaus-halfmann) wrote : | # |
Is this for R20?
Benedikt Straub (nordfriese) wrote : | # |
Would be nice, but I thought we were in feature freeze ;)
GunChleoc (gunchleoc) wrote : | # |
Yes, feature freeze. We're mopping up the remaining bugs right now, so we can't risk merging anything else.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4645. State: errored. Details: https:/
Appveyor build 4432. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4672. State: passed. Details: https:/
Appveyor build 4458. State: success. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
@Nordfriese: You forgot to set the branch owner to widelands-dev, so I can't merge trunk to it. Can you take care of getting this branch in?
Benedikt Straub (nordfriese) wrote : | # |
Merged trunk
@bunnybot merge
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4784. State: errored. Details: https:/
Appveyor build 4565. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.
Travis build 4784. State: errored. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
Transient failure on Travis
@bunnybot merge force
Preview Diff
1 | === renamed file 'data/images/wui/overlays/workarea123.png' => 'data/images/wui/buildings/toggle_workarea.png' | |||
2 | === added file 'data/images/wui/overlays/grid_marker.png' | |||
3 | 0 | Binary files data/images/wui/overlays/grid_marker.png 1970-01-01 00:00:00 +0000 and data/images/wui/overlays/grid_marker.png 2019-04-24 15:57:58 +0000 differ | 0 | Binary files data/images/wui/overlays/grid_marker.png 1970-01-01 00:00:00 +0000 and data/images/wui/overlays/grid_marker.png 2019-04-24 15:57:58 +0000 differ |
4 | === removed file 'data/images/wui/overlays/workarea1.png' | |||
5 | 1 | Binary files data/images/wui/overlays/workarea1.png 2019-03-30 06:46:25 +0000 and data/images/wui/overlays/workarea1.png 1970-01-01 00:00:00 +0000 differ | 1 | Binary files data/images/wui/overlays/workarea1.png 2019-03-30 06:46:25 +0000 and data/images/wui/overlays/workarea1.png 1970-01-01 00:00:00 +0000 differ |
6 | === removed file 'data/images/wui/overlays/workarea12.png' | |||
7 | 2 | Binary files data/images/wui/overlays/workarea12.png 2019-03-30 06:46:25 +0000 and data/images/wui/overlays/workarea12.png 1970-01-01 00:00:00 +0000 differ | 2 | Binary files data/images/wui/overlays/workarea12.png 2019-03-30 06:46:25 +0000 and data/images/wui/overlays/workarea12.png 1970-01-01 00:00:00 +0000 differ |
8 | === removed file 'data/images/wui/overlays/workarea2.png' | |||
9 | 3 | Binary files data/images/wui/overlays/workarea2.png 2019-03-30 06:46:25 +0000 and data/images/wui/overlays/workarea2.png 1970-01-01 00:00:00 +0000 differ | 3 | Binary files data/images/wui/overlays/workarea2.png 2019-03-30 06:46:25 +0000 and data/images/wui/overlays/workarea2.png 1970-01-01 00:00:00 +0000 differ |
10 | === removed file 'data/images/wui/overlays/workarea23.png' | |||
11 | 4 | Binary files data/images/wui/overlays/workarea23.png 2019-03-30 06:46:25 +0000 and data/images/wui/overlays/workarea23.png 1970-01-01 00:00:00 +0000 differ | 4 | Binary files data/images/wui/overlays/workarea23.png 2019-03-30 06:46:25 +0000 and data/images/wui/overlays/workarea23.png 1970-01-01 00:00:00 +0000 differ |
12 | === removed file 'data/images/wui/overlays/workarea3.png' | |||
13 | 5 | Binary files data/images/wui/overlays/workarea3.png 2014-12-03 20:13:06 +0000 and data/images/wui/overlays/workarea3.png 1970-01-01 00:00:00 +0000 differ | 5 | Binary files data/images/wui/overlays/workarea3.png 2014-12-03 20:13:06 +0000 and data/images/wui/overlays/workarea3.png 1970-01-01 00:00:00 +0000 differ |
14 | === added file 'data/shaders/workarea.fp' | |||
15 | --- data/shaders/workarea.fp 1970-01-01 00:00:00 +0000 | |||
16 | +++ data/shaders/workarea.fp 2019-04-24 15:57:58 +0000 | |||
17 | @@ -0,0 +1,7 @@ | |||
18 | 1 | #version 120 | ||
19 | 2 | |||
20 | 3 | varying vec4 var_overlay; | ||
21 | 4 | |||
22 | 5 | void main() { | ||
23 | 6 | gl_FragColor = var_overlay; | ||
24 | 7 | } | ||
25 | 0 | 8 | ||
26 | === added file 'data/shaders/workarea.vp' | |||
27 | --- data/shaders/workarea.vp 1970-01-01 00:00:00 +0000 | |||
28 | +++ data/shaders/workarea.vp 2019-04-24 15:57:58 +0000 | |||
29 | @@ -0,0 +1,15 @@ | |||
30 | 1 | #version 120 | ||
31 | 2 | |||
32 | 3 | // Attributes. | ||
33 | 4 | attribute vec2 attr_position; | ||
34 | 5 | attribute vec4 attr_overlay; | ||
35 | 6 | |||
36 | 7 | uniform float u_z_value; | ||
37 | 8 | |||
38 | 9 | // Output of vertex shader. | ||
39 | 10 | varying vec4 var_overlay; | ||
40 | 11 | |||
41 | 12 | void main() { | ||
42 | 13 | var_overlay = attr_overlay; | ||
43 | 14 | gl_Position = vec4(attr_position, u_z_value, 1.); | ||
44 | 15 | } | ||
45 | 0 | 16 | ||
46 | === modified file 'src/editor/editorinteractive.cc' | |||
47 | --- src/editor/editorinteractive.cc 2019-04-24 07:09:29 +0000 | |||
48 | +++ src/editor/editorinteractive.cc 2019-04-24 15:57:58 +0000 | |||
49 | @@ -262,7 +262,7 @@ | |||
50 | 262 | 262 | ||
51 | 263 | void EditorInteractive::draw(RenderTarget& dst) { | 263 | void EditorInteractive::draw(RenderTarget& dst) { |
52 | 264 | const auto& ebase = egbase(); | 264 | const auto& ebase = egbase(); |
54 | 265 | auto* fields_to_draw = map_view()->draw_terrain(ebase, &dst); | 265 | auto* fields_to_draw = map_view()->draw_terrain(ebase, Workareas(), &dst); |
55 | 266 | 266 | ||
56 | 267 | const float scale = 1.f / map_view()->view().zoom; | 267 | const float scale = 1.f / map_view()->view().zoom; |
57 | 268 | const uint32_t gametime = ebase.get_gametime(); | 268 | const uint32_t gametime = ebase.get_gametime(); |
58 | 269 | 269 | ||
59 | === modified file 'src/graphic/CMakeLists.txt' | |||
60 | --- src/graphic/CMakeLists.txt 2019-04-08 13:32:28 +0000 | |||
61 | +++ src/graphic/CMakeLists.txt 2019-04-24 15:57:58 +0000 | |||
62 | @@ -231,6 +231,8 @@ | |||
63 | 231 | gl/terrain_program.h | 231 | gl/terrain_program.h |
64 | 232 | gl/dither_program.cc | 232 | gl/dither_program.cc |
65 | 233 | gl/dither_program.h | 233 | gl/dither_program.h |
66 | 234 | gl/workarea_program.cc | ||
67 | 235 | gl/workarea_program.h | ||
68 | 234 | DEPENDS | 236 | DEPENDS |
69 | 235 | base_exceptions | 237 | base_exceptions |
70 | 236 | base_geometry | 238 | base_geometry |
71 | 237 | 239 | ||
72 | === modified file 'src/graphic/game_renderer.cc' | |||
73 | --- src/graphic/game_renderer.cc 2019-04-24 06:01:37 +0000 | |||
74 | +++ src/graphic/game_renderer.cc 2019-04-24 15:57:58 +0000 | |||
75 | @@ -60,6 +60,7 @@ | |||
76 | 60 | void draw_terrain(const Widelands::EditorGameBase& egbase, | 60 | void draw_terrain(const Widelands::EditorGameBase& egbase, |
77 | 61 | const FieldsToDraw& fields_to_draw, | 61 | const FieldsToDraw& fields_to_draw, |
78 | 62 | const float scale, | 62 | const float scale, |
79 | 63 | Workareas workarea, | ||
80 | 63 | RenderTarget* dst) { | 64 | RenderTarget* dst) { |
81 | 64 | const Recti& bounding_rect = dst->get_rect(); | 65 | const Recti& bounding_rect = dst->get_rect(); |
82 | 65 | const Surface& surface = dst->get_surface(); | 66 | const Surface& surface = dst->get_surface(); |
83 | @@ -86,6 +87,13 @@ | |||
84 | 86 | i.blend_mode = BlendMode::UseAlpha; | 87 | i.blend_mode = BlendMode::UseAlpha; |
85 | 87 | RenderQueue::instance().enqueue(i); | 88 | RenderQueue::instance().enqueue(i); |
86 | 88 | 89 | ||
87 | 90 | if (!workarea.empty()) { | ||
88 | 91 | // Enqueue the drawing of the workarea overlay layer. | ||
89 | 92 | i.program_id = RenderQueue::Program::kTerrainWorkarea; | ||
90 | 93 | i.terrain_arguments.workareas = workarea; | ||
91 | 94 | RenderQueue::instance().enqueue(i); | ||
92 | 95 | } | ||
93 | 96 | |||
94 | 89 | // Enqueue the drawing of the road layer. | 97 | // Enqueue the drawing of the road layer. |
95 | 90 | i.program_id = RenderQueue::Program::kTerrainRoad; | 98 | i.program_id = RenderQueue::Program::kTerrainRoad; |
96 | 91 | RenderQueue::instance().enqueue(i); | 99 | RenderQueue::instance().enqueue(i); |
97 | 92 | 100 | ||
98 | === modified file 'src/graphic/game_renderer.h' | |||
99 | --- src/graphic/game_renderer.h 2019-02-23 11:00:49 +0000 | |||
100 | +++ src/graphic/game_renderer.h 2019-04-24 15:57:58 +0000 | |||
101 | @@ -33,6 +33,7 @@ | |||
102 | 33 | void draw_terrain(const Widelands::EditorGameBase& egbase, | 33 | void draw_terrain(const Widelands::EditorGameBase& egbase, |
103 | 34 | const FieldsToDraw& fields_to_draw, | 34 | const FieldsToDraw& fields_to_draw, |
104 | 35 | const float scale, | 35 | const float scale, |
105 | 36 | Workareas workarea, | ||
106 | 36 | RenderTarget* dst); | 37 | RenderTarget* dst); |
107 | 37 | 38 | ||
108 | 38 | // Draw the border stones for 'field' if it is a border and 'visibility' is | 39 | // Draw the border stones for 'field' if it is a border and 'visibility' is |
109 | 39 | 40 | ||
110 | === added file 'src/graphic/gl/workarea_program.cc' | |||
111 | --- src/graphic/gl/workarea_program.cc 1970-01-01 00:00:00 +0000 | |||
112 | +++ src/graphic/gl/workarea_program.cc 2019-04-24 15:57:58 +0000 | |||
113 | @@ -0,0 +1,134 @@ | |||
114 | 1 | /* | ||
115 | 2 | * Copyright (C) 2006-2019 by the Widelands Development Team | ||
116 | 3 | * | ||
117 | 4 | * This program is free software; you can redistribute it and/or | ||
118 | 5 | * modify it under the terms of the GNU General Public License | ||
119 | 6 | * as published by the Free Software Foundation; either version 2 | ||
120 | 7 | * of the License, or (at your option) any later version. | ||
121 | 8 | * | ||
122 | 9 | * This program is distributed in the hope that it will be useful, | ||
123 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
124 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
125 | 12 | * GNU General Public License for more details. | ||
126 | 13 | * | ||
127 | 14 | * You should have received a copy of the GNU General Public License | ||
128 | 15 | * along with this program; if not, write to the Free Software | ||
129 | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
130 | 17 | * | ||
131 | 18 | */ | ||
132 | 19 | |||
133 | 20 | #include "graphic/gl/workarea_program.h" | ||
134 | 21 | |||
135 | 22 | #include "graphic/gl/coordinate_conversion.h" | ||
136 | 23 | #include "graphic/gl/fields_to_draw.h" | ||
137 | 24 | #include "graphic/gl/utils.h" | ||
138 | 25 | #include "graphic/texture.h" | ||
139 | 26 | |||
140 | 27 | WorkareaProgram::WorkareaProgram() { | ||
141 | 28 | gl_program_.build("workarea"); | ||
142 | 29 | |||
143 | 30 | attr_position_ = glGetAttribLocation(gl_program_.object(), "attr_position"); | ||
144 | 31 | attr_overlay_ = glGetAttribLocation(gl_program_.object(), "attr_overlay"); | ||
145 | 32 | |||
146 | 33 | u_z_value_ = glGetUniformLocation(gl_program_.object(), "u_z_value"); | ||
147 | 34 | } | ||
148 | 35 | |||
149 | 36 | void WorkareaProgram::gl_draw(int gl_texture, float z_value) { | ||
150 | 37 | glUseProgram(gl_program_.object()); | ||
151 | 38 | |||
152 | 39 | auto& gl_state = Gl::State::instance(); | ||
153 | 40 | gl_state.enable_vertex_attrib_array( | ||
154 | 41 | {attr_position_, attr_overlay_}); | ||
155 | 42 | |||
156 | 43 | gl_array_buffer_.bind(); | ||
157 | 44 | gl_array_buffer_.update(vertices_); | ||
158 | 45 | |||
159 | 46 | Gl::vertex_attrib_pointer( | ||
160 | 47 | attr_position_, 2, sizeof(PerVertexData), offsetof(PerVertexData, gl_x)); | ||
161 | 48 | Gl::vertex_attrib_pointer( | ||
162 | 49 | attr_overlay_, 4, sizeof(PerVertexData), offsetof(PerVertexData, overlay_r)); | ||
163 | 50 | |||
164 | 51 | gl_state.bind(GL_TEXTURE0, gl_texture); | ||
165 | 52 | |||
166 | 53 | glUniform1f(u_z_value_, z_value); | ||
167 | 54 | |||
168 | 55 | glDrawArrays(GL_TRIANGLES, 0, vertices_.size()); | ||
169 | 56 | } | ||
170 | 57 | |||
171 | 58 | constexpr uint8_t kWorkareaTransparency = 127; | ||
172 | 59 | static RGBAColor workarea_colors[] { | ||
173 | 60 | RGBAColor(63, 31, 127, kWorkareaTransparency), // All three circles | ||
174 | 61 | RGBAColor(127, 63, 0, kWorkareaTransparency), // Medium and outer circle | ||
175 | 62 | RGBAColor(0, 127, 0, kWorkareaTransparency), // Outer circle | ||
176 | 63 | RGBAColor(63, 0, 127, kWorkareaTransparency), // Inner and medium circle | ||
177 | 64 | RGBAColor(127, 0, 0, kWorkareaTransparency), // Medium circle | ||
178 | 65 | RGBAColor(0, 0, 127, kWorkareaTransparency), // Inner circle | ||
179 | 66 | }; | ||
180 | 67 | static inline RGBAColor apply_color(RGBAColor c1, RGBAColor c2) { | ||
181 | 68 | uint8_t r = (c1.r * c1.a + c2.r * c2.a) / (c1.a + c2.a); | ||
182 | 69 | uint8_t g = (c1.g * c1.a + c2.g * c2.a) / (c1.a + c2.a); | ||
183 | 70 | uint8_t b = (c1.b * c1.a + c2.b * c2.a) / (c1.a + c2.a); | ||
184 | 71 | uint8_t a = (c1.a + c2.a) / 2; | ||
185 | 72 | return RGBAColor(r, g, b, a); | ||
186 | 73 | } | ||
187 | 74 | |||
188 | 75 | void WorkareaProgram::add_vertex(const FieldsToDraw::Field& field, RGBAColor overlay) { | ||
189 | 76 | vertices_.emplace_back(); | ||
190 | 77 | PerVertexData& back = vertices_.back(); | ||
191 | 78 | |||
192 | 79 | back.gl_x = field.gl_position.x; | ||
193 | 80 | back.gl_y = field.gl_position.y; | ||
194 | 81 | back.overlay_r = overlay.r / 255.f; | ||
195 | 82 | back.overlay_g = overlay.g / 255.f; | ||
196 | 83 | back.overlay_b = overlay.b / 255.f; | ||
197 | 84 | back.overlay_a = overlay.a / 255.f; | ||
198 | 85 | } | ||
199 | 86 | |||
200 | 87 | void WorkareaProgram::draw(uint32_t texture_id, | ||
201 | 88 | Workareas workarea, | ||
202 | 89 | const FieldsToDraw& fields_to_draw, | ||
203 | 90 | float z_value) { | ||
204 | 91 | vertices_.clear(); | ||
205 | 92 | vertices_.reserve(fields_to_draw.size() * 3); | ||
206 | 93 | |||
207 | 94 | for (size_t current_index = 0; current_index < fields_to_draw.size(); ++current_index) { | ||
208 | 95 | const FieldsToDraw::Field& field = fields_to_draw.at(current_index); | ||
209 | 96 | |||
210 | 97 | // The bottom right neighbor fields_to_draw is needed for both triangles | ||
211 | 98 | // associated with this field. If it is not in fields_to_draw, there is no need to | ||
212 | 99 | // draw any triangles. | ||
213 | 100 | if (field.brn_index == FieldsToDraw::kInvalidIndex) { | ||
214 | 101 | continue; | ||
215 | 102 | } | ||
216 | 103 | |||
217 | 104 | // Down triangle. | ||
218 | 105 | if (field.bln_index != FieldsToDraw::kInvalidIndex) { | ||
219 | 106 | RGBAColor color(0, 0, 0, 0); | ||
220 | 107 | for (const std::map<Widelands::TCoords<>, uint8_t>& wa_map : workarea) { | ||
221 | 108 | const auto it = wa_map.find(Widelands::TCoords<>(field.fcoords, Widelands::TriangleIndex::D)); | ||
222 | 109 | if (it != wa_map.end()) { | ||
223 | 110 | color = apply_color(color, workarea_colors[it->second]); | ||
224 | 111 | } | ||
225 | 112 | } | ||
226 | 113 | add_vertex(fields_to_draw.at(current_index), color); | ||
227 | 114 | add_vertex(fields_to_draw.at(field.bln_index), color); | ||
228 | 115 | add_vertex(fields_to_draw.at(field.brn_index), color); | ||
229 | 116 | } | ||
230 | 117 | |||
231 | 118 | // Right triangle. | ||
232 | 119 | if (field.rn_index != FieldsToDraw::kInvalidIndex) { | ||
233 | 120 | RGBAColor color(0, 0, 0, 0); | ||
234 | 121 | for (const std::map<Widelands::TCoords<>, uint8_t>& wa_map : workarea) { | ||
235 | 122 | const auto it = wa_map.find(Widelands::TCoords<>(field.fcoords, Widelands::TriangleIndex::R)); | ||
236 | 123 | if (it != wa_map.end()) { | ||
237 | 124 | color = apply_color(color, workarea_colors[it->second]); | ||
238 | 125 | } | ||
239 | 126 | } | ||
240 | 127 | add_vertex(fields_to_draw.at(current_index), color); | ||
241 | 128 | add_vertex(fields_to_draw.at(field.brn_index), color); | ||
242 | 129 | add_vertex(fields_to_draw.at(field.rn_index), color); | ||
243 | 130 | } | ||
244 | 131 | } | ||
245 | 132 | |||
246 | 133 | gl_draw(texture_id, z_value); | ||
247 | 134 | } | ||
248 | 0 | 135 | ||
249 | === added file 'src/graphic/gl/workarea_program.h' | |||
250 | --- src/graphic/gl/workarea_program.h 1970-01-01 00:00:00 +0000 | |||
251 | +++ src/graphic/gl/workarea_program.h 2019-04-24 15:57:58 +0000 | |||
252 | @@ -0,0 +1,78 @@ | |||
253 | 1 | /* | ||
254 | 2 | * Copyright (C) 2006-2019 by the Widelands Development Team | ||
255 | 3 | * | ||
256 | 4 | * This program is free software; you can redistribute it and/or | ||
257 | 5 | * modify it under the terms of the GNU General Public License | ||
258 | 6 | * as published by the Free Software Foundation; either version 2 | ||
259 | 7 | * of the License, or (at your option) any later version. | ||
260 | 8 | * | ||
261 | 9 | * This program is distributed in the hope that it will be useful, | ||
262 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
263 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
264 | 12 | * GNU General Public License for more details. | ||
265 | 13 | * | ||
266 | 14 | * You should have received a copy of the GNU General Public License | ||
267 | 15 | * along with this program; if not, write to the Free Software | ||
268 | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
269 | 17 | * | ||
270 | 18 | */ | ||
271 | 19 | |||
272 | 20 | #ifndef WL_GRAPHIC_GL_WORKAREA_PROGRAM_H | ||
273 | 21 | #define WL_GRAPHIC_GL_WORKAREA_PROGRAM_H | ||
274 | 22 | |||
275 | 23 | #include <vector> | ||
276 | 24 | |||
277 | 25 | #include "base/vector.h" | ||
278 | 26 | #include "graphic/gl/fields_to_draw.h" | ||
279 | 27 | #include "graphic/gl/utils.h" | ||
280 | 28 | #include "logic/description_maintainer.h" | ||
281 | 29 | #include "logic/map_objects/world/terrain_description.h" | ||
282 | 30 | |||
283 | 31 | class WorkareaProgram { | ||
284 | 32 | public: | ||
285 | 33 | // Compiles the program. Throws on errors. | ||
286 | 34 | WorkareaProgram(); | ||
287 | 35 | |||
288 | 36 | // Draws the workarea overlay. | ||
289 | 37 | void draw(uint32_t texture_id, | ||
290 | 38 | Workareas workarea, | ||
291 | 39 | const FieldsToDraw& fields_to_draw, | ||
292 | 40 | float z_value); | ||
293 | 41 | |||
294 | 42 | private: | ||
295 | 43 | struct PerVertexData { | ||
296 | 44 | float gl_x; | ||
297 | 45 | float gl_y; | ||
298 | 46 | float overlay_r; | ||
299 | 47 | float overlay_g; | ||
300 | 48 | float overlay_b; | ||
301 | 49 | float overlay_a; | ||
302 | 50 | }; | ||
303 | 51 | static_assert(sizeof(PerVertexData) == 24, "Wrong padding."); | ||
304 | 52 | |||
305 | 53 | void gl_draw(int gl_texture, float z_value); | ||
306 | 54 | |||
307 | 55 | // Adds a vertex to the end of vertices with data from 'field' in order to apply the specified 'overlay'. | ||
308 | 56 | void add_vertex(const FieldsToDraw::Field& field, RGBAColor overlay); | ||
309 | 57 | |||
310 | 58 | // The program used for drawing the workarea overlay. | ||
311 | 59 | Gl::Program gl_program_; | ||
312 | 60 | |||
313 | 61 | // The buffer that will contain 'vertices_' for rendering. | ||
314 | 62 | Gl::Buffer<PerVertexData> gl_array_buffer_; | ||
315 | 63 | |||
316 | 64 | // Attributes. | ||
317 | 65 | GLint attr_position_; | ||
318 | 66 | GLint attr_overlay_; | ||
319 | 67 | |||
320 | 68 | // Uniforms. | ||
321 | 69 | GLint u_z_value_; | ||
322 | 70 | |||
323 | 71 | // Objects below are kept around to avoid memory allocations on each frame. | ||
324 | 72 | // They could theoretically also be recreated. | ||
325 | 73 | std::vector<PerVertexData> vertices_; | ||
326 | 74 | |||
327 | 75 | DISALLOW_COPY_AND_ASSIGN(WorkareaProgram); | ||
328 | 76 | }; | ||
329 | 77 | |||
330 | 78 | #endif // end of include guard: WL_GRAPHIC_GL_WORKAREA_PROGRAM_H | ||
331 | 0 | 79 | ||
332 | === modified file 'src/graphic/render_queue.cc' | |||
333 | --- src/graphic/render_queue.cc 2019-02-23 11:00:49 +0000 | |||
334 | +++ src/graphic/render_queue.cc 2019-04-24 15:57:58 +0000 | |||
335 | @@ -30,6 +30,7 @@ | |||
336 | 30 | #include "graphic/gl/fill_rect_program.h" | 30 | #include "graphic/gl/fill_rect_program.h" |
337 | 31 | #include "graphic/gl/road_program.h" | 31 | #include "graphic/gl/road_program.h" |
338 | 32 | #include "graphic/gl/terrain_program.h" | 32 | #include "graphic/gl/terrain_program.h" |
339 | 33 | #include "graphic/gl/workarea_program.h" | ||
340 | 33 | 34 | ||
341 | 34 | namespace { | 35 | namespace { |
342 | 35 | 36 | ||
343 | @@ -142,6 +143,7 @@ | |||
344 | 142 | : next_z_(1), | 143 | : next_z_(1), |
345 | 143 | terrain_program_(new TerrainProgram()), | 144 | terrain_program_(new TerrainProgram()), |
346 | 144 | dither_program_(new DitherProgram()), | 145 | dither_program_(new DitherProgram()), |
347 | 146 | workarea_program_(new WorkareaProgram()), | ||
348 | 145 | road_program_(new RoadProgram()) { | 147 | road_program_(new RoadProgram()) { |
349 | 146 | } | 148 | } |
350 | 147 | 149 | ||
351 | @@ -164,6 +166,7 @@ | |||
352 | 164 | case Program::kRect: | 166 | case Program::kRect: |
353 | 165 | case Program::kTerrainBase: | 167 | case Program::kTerrainBase: |
354 | 166 | case Program::kTerrainDither: | 168 | case Program::kTerrainDither: |
355 | 169 | case Program::kTerrainWorkarea: | ||
356 | 167 | case Program::kTerrainRoad: | 170 | case Program::kTerrainRoad: |
357 | 168 | /* all fallthroughs intended */ | 171 | /* all fallthroughs intended */ |
358 | 169 | break; | 172 | break; |
359 | @@ -251,6 +254,13 @@ | |||
360 | 251 | ++i; | 254 | ++i; |
361 | 252 | } break; | 255 | } break; |
362 | 253 | 256 | ||
363 | 257 | case Program::kTerrainWorkarea: { | ||
364 | 258 | ScopedScissor scoped_scissor(item.terrain_arguments.destination_rect); | ||
365 | 259 | workarea_program_->draw(item.terrain_arguments.terrains->get(0).get_texture(0).blit_data().texture_id, | ||
366 | 260 | item.terrain_arguments.workareas, *item.terrain_arguments.fields_to_draw, item.z_value); | ||
367 | 261 | ++i; | ||
368 | 262 | } break; | ||
369 | 263 | |||
370 | 254 | case Program::kTerrainRoad: { | 264 | case Program::kTerrainRoad: { |
371 | 255 | ScopedScissor scoped_scissor(item.terrain_arguments.destination_rect); | 265 | ScopedScissor scoped_scissor(item.terrain_arguments.destination_rect); |
372 | 256 | road_program_->draw(item.terrain_arguments.renderbuffer_width, | 266 | road_program_->draw(item.terrain_arguments.renderbuffer_width, |
373 | 257 | 267 | ||
374 | === modified file 'src/graphic/render_queue.h' | |||
375 | --- src/graphic/render_queue.h 2019-02-23 11:00:49 +0000 | |||
376 | +++ src/graphic/render_queue.h 2019-04-24 15:57:58 +0000 | |||
377 | @@ -38,6 +38,7 @@ | |||
378 | 38 | class DitherProgram; | 38 | class DitherProgram; |
379 | 39 | class RoadProgram; | 39 | class RoadProgram; |
380 | 40 | class TerrainProgram; | 40 | class TerrainProgram; |
381 | 41 | class WorkareaProgram; | ||
382 | 41 | 42 | ||
383 | 42 | // The RenderQueue is a singleton implementing the concept of deferred | 43 | // The RenderQueue is a singleton implementing the concept of deferred |
384 | 43 | // rendering: Every rendering call that pretends to draw onto the screen will | 44 | // rendering: Every rendering call that pretends to draw onto the screen will |
385 | @@ -82,6 +83,7 @@ | |||
386 | 82 | enum Program { | 83 | enum Program { |
387 | 83 | kTerrainBase, | 84 | kTerrainBase, |
388 | 84 | kTerrainDither, | 85 | kTerrainDither, |
389 | 86 | kTerrainWorkarea, | ||
390 | 85 | kTerrainRoad, | 87 | kTerrainRoad, |
391 | 86 | kBlit, | 88 | kBlit, |
392 | 87 | kRect, | 89 | kRect, |
393 | @@ -119,6 +121,7 @@ | |||
394 | 119 | int renderbuffer_height = 0; | 121 | int renderbuffer_height = 0; |
395 | 120 | const DescriptionMaintainer<Widelands::TerrainDescription>* terrains = nullptr; | 122 | const DescriptionMaintainer<Widelands::TerrainDescription>* terrains = nullptr; |
396 | 121 | const FieldsToDraw* fields_to_draw = nullptr; | 123 | const FieldsToDraw* fields_to_draw = nullptr; |
397 | 124 | Workareas workareas; | ||
398 | 122 | float scale = 1.f; | 125 | float scale = 1.f; |
399 | 123 | Rectf destination_rect = Rectf(0.f, 0.f, 0.f, 0.f); | 126 | Rectf destination_rect = Rectf(0.f, 0.f, 0.f, 0.f); |
400 | 124 | }; | 127 | }; |
401 | @@ -178,6 +181,7 @@ | |||
402 | 178 | 181 | ||
403 | 179 | std::unique_ptr<TerrainProgram> terrain_program_; | 182 | std::unique_ptr<TerrainProgram> terrain_program_; |
404 | 180 | std::unique_ptr<DitherProgram> dither_program_; | 183 | std::unique_ptr<DitherProgram> dither_program_; |
405 | 184 | std::unique_ptr<WorkareaProgram> workarea_program_; | ||
406 | 181 | std::unique_ptr<RoadProgram> road_program_; | 185 | std::unique_ptr<RoadProgram> road_program_; |
407 | 182 | 186 | ||
408 | 183 | std::vector<Item> blended_items_; | 187 | std::vector<Item> blended_items_; |
409 | 184 | 188 | ||
410 | === modified file 'src/logic/widelands_geometry.h' | |||
411 | --- src/logic/widelands_geometry.h 2019-02-23 11:00:49 +0000 | |||
412 | +++ src/logic/widelands_geometry.h 2019-04-24 15:57:58 +0000 | |||
413 | @@ -21,6 +21,8 @@ | |||
414 | 21 | #define WL_LOGIC_WIDELANDS_GEOMETRY_H | 21 | #define WL_LOGIC_WIDELANDS_GEOMETRY_H |
415 | 22 | 22 | ||
416 | 23 | #include <cmath> | 23 | #include <cmath> |
417 | 24 | #include <map> | ||
418 | 25 | #include <set> | ||
419 | 24 | #include <tuple> | 26 | #include <tuple> |
420 | 25 | 27 | ||
421 | 26 | #include <stdint.h> | 28 | #include <stdint.h> |
422 | @@ -155,4 +157,6 @@ | |||
423 | 155 | }; | 157 | }; |
424 | 156 | } // namespace Widelands | 158 | } // namespace Widelands |
425 | 157 | 159 | ||
426 | 160 | using Workareas = std::set<std::map<Widelands::TCoords<>, uint8_t>>; | ||
427 | 161 | |||
428 | 158 | #endif // end of include guard: WL_LOGIC_WIDELANDS_GEOMETRY_H | 162 | #endif // end of include guard: WL_LOGIC_WIDELANDS_GEOMETRY_H |
429 | 159 | 163 | ||
430 | === modified file 'src/wui/buildingwindow.cc' | |||
431 | --- src/wui/buildingwindow.cc 2019-03-22 18:52:17 +0000 | |||
432 | +++ src/wui/buildingwindow.cc 2019-04-24 15:57:58 +0000 | |||
433 | @@ -320,7 +320,7 @@ | |||
434 | 320 | if (!wa_info->empty()) { | 320 | if (!wa_info->empty()) { |
435 | 321 | toggle_workarea_ = | 321 | toggle_workarea_ = |
436 | 322 | new UI::Button(capsbuttons, "workarea", 0, 0, 34, 34, UI::ButtonStyle::kWuiMenu, | 322 | new UI::Button(capsbuttons, "workarea", 0, 0, 34, 34, UI::ButtonStyle::kWuiMenu, |
438 | 323 | g_gr->images().get("images/wui/overlays/workarea123.png")); | 323 | g_gr->images().get("images/wui/buildings/toggle_workarea.png")); |
439 | 324 | toggle_workarea_->sigclicked.connect( | 324 | toggle_workarea_->sigclicked.connect( |
440 | 325 | boost::bind(&BuildingWindow::toggle_workarea, boost::ref(*this))); | 325 | boost::bind(&BuildingWindow::toggle_workarea, boost::ref(*this))); |
441 | 326 | 326 | ||
442 | 327 | 327 | ||
443 | === modified file 'src/wui/interactive_base.cc' | |||
444 | --- src/wui/interactive_base.cc 2019-04-24 06:01:37 +0000 | |||
445 | +++ src/wui/interactive_base.cc 2019-04-24 15:57:58 +0000 | |||
446 | @@ -112,14 +112,7 @@ | |||
447 | 112 | avg_usframetime_(0), | 112 | avg_usframetime_(0), |
448 | 113 | buildroad_(nullptr), | 113 | buildroad_(nullptr), |
449 | 114 | road_build_player_(0), | 114 | road_build_player_(0), |
458 | 115 | unique_window_handler_(new UniqueWindowHandler()), | 115 | unique_window_handler_(new UniqueWindowHandler()) { |
451 | 116 | // Start at idx 0 for 2 enhancements, idx 3 for 1, idx 5 if none | ||
452 | 117 | workarea_pics_{g_gr->images().get("images/wui/overlays/workarea123.png"), | ||
453 | 118 | g_gr->images().get("images/wui/overlays/workarea23.png"), | ||
454 | 119 | g_gr->images().get("images/wui/overlays/workarea3.png"), | ||
455 | 120 | g_gr->images().get("images/wui/overlays/workarea12.png"), | ||
456 | 121 | g_gr->images().get("images/wui/overlays/workarea2.png"), | ||
457 | 122 | g_gr->images().get("images/wui/overlays/workarea1.png")} { | ||
459 | 123 | 116 | ||
460 | 124 | // Load the buildhelp icons. | 117 | // Load the buildhelp icons. |
461 | 125 | { | 118 | { |
462 | @@ -200,8 +193,20 @@ | |||
463 | 200 | return nullptr; | 193 | return nullptr; |
464 | 201 | } | 194 | } |
465 | 202 | 195 | ||
468 | 203 | bool InteractiveBase::has_workarea_preview(const Widelands::Coords& coords) const { | 196 | bool InteractiveBase::has_workarea_preview(const Widelands::Coords& coords, const Widelands::Map* map) const { |
469 | 204 | return workarea_previews_.count(coords) == 1; | 197 | if (!map) { |
470 | 198 | return workarea_previews_.count(coords) == 1; | ||
471 | 199 | } | ||
472 | 200 | for (const auto& pair : workarea_previews_) { | ||
473 | 201 | uint32_t radius = 0; | ||
474 | 202 | for (const auto& p : *pair.second) { | ||
475 | 203 | radius = std::max(radius, p.first); | ||
476 | 204 | } | ||
477 | 205 | if (map->calc_distance(coords, pair.first) <= radius) { | ||
478 | 206 | return true; | ||
479 | 207 | } | ||
480 | 208 | } | ||
481 | 209 | return false; | ||
482 | 205 | } | 210 | } |
483 | 206 | 211 | ||
484 | 207 | UniqueWindowHandler& InteractiveBase::unique_windows() { | 212 | UniqueWindowHandler& InteractiveBase::unique_windows() { |
485 | @@ -303,12 +308,53 @@ | |||
486 | 303 | workarea_previews_[coords] = &workarea_info; | 308 | workarea_previews_[coords] = &workarea_info; |
487 | 304 | } | 309 | } |
488 | 305 | 310 | ||
495 | 306 | std::map<Coords, const Image*> | 311 | /* Helper function to get the correct index for graphic/gl/workarea_program.cc::workarea_colors . |
496 | 307 | InteractiveBase::get_workarea_overlays(const Widelands::Map& map) const { | 312 | * a, b, c are the indices for the three nodes bordering this triangle. |
497 | 308 | std::map<Coords, const Image*> result; | 313 | * This function returns the biggest workarea type that matches all three corners. |
498 | 309 | for (const auto& pair : workarea_previews_) { | 314 | * The indices stand for: |
499 | 310 | const Coords& coords = pair.first; | 315 | * 0 – all three circles |
500 | 311 | const WorkareaInfo* workarea_info = pair.second; | 316 | * 1 – medium and outer circle |
501 | 317 | * 2 – outer circle | ||
502 | 318 | * 3 – inner and medium circle | ||
503 | 319 | * 4 – medium circle | ||
504 | 320 | * 5 – inner circle | ||
505 | 321 | * We currently assume that no building will have more than three workarea circles. | ||
506 | 322 | */ | ||
507 | 323 | static uint8_t workarea_max(uint8_t a, uint8_t b, uint8_t c) { | ||
508 | 324 | // Whether all nodes are part of the inner circle | ||
509 | 325 | bool inner = (a == 0 || a == 3 || a == 5) && (b == 0 || b == 3 || b == 5) && (c == 0 || c == 3 || c == 5); | ||
510 | 326 | // Whether all nodes are part of the medium circle | ||
511 | 327 | bool medium = (a == 0 || a == 1 || a == 3 || a == 4) && (b == 0 || b == 1 || b == 3 || b == 4) && | ||
512 | 328 | (c == 0 || c == 1 || c == 3 || c == 4); | ||
513 | 329 | // Whether all nodes are part of the outer circle | ||
514 | 330 | bool outer = a <= 2 && b <= 2 && c <= 2; | ||
515 | 331 | |||
516 | 332 | if (medium) { | ||
517 | 333 | if (outer && inner) { | ||
518 | 334 | return 0; | ||
519 | 335 | } else if (inner) { | ||
520 | 336 | return 3; | ||
521 | 337 | } else if (outer) { | ||
522 | 338 | return 1; | ||
523 | 339 | } else { | ||
524 | 340 | return 4; | ||
525 | 341 | } | ||
526 | 342 | } else if (outer) { | ||
527 | 343 | assert(!inner); | ||
528 | 344 | return 2; | ||
529 | 345 | } else { | ||
530 | 346 | assert(inner); | ||
531 | 347 | return 5; | ||
532 | 348 | } | ||
533 | 349 | } | ||
534 | 350 | |||
535 | 351 | Workareas InteractiveBase::get_workarea_overlays(const Widelands::Map& map) const { | ||
536 | 352 | Workareas result_set; | ||
537 | 353 | for (const auto& wa_pair : workarea_previews_) { | ||
538 | 354 | std::map<Coords, uint8_t> intermediate_result; | ||
539 | 355 | const Coords& coords = wa_pair.first; | ||
540 | 356 | const WorkareaInfo* workarea_info = wa_pair.second; | ||
541 | 357 | intermediate_result[coords] = 0; | ||
542 | 312 | WorkareaInfo::size_type wa_index; | 358 | WorkareaInfo::size_type wa_index; |
543 | 313 | switch (workarea_info->size()) { | 359 | switch (workarea_info->size()) { |
544 | 314 | case 0: | 360 | case 0: |
545 | @@ -335,13 +381,36 @@ | |||
546 | 335 | hollow_area.radius = it->first; | 381 | hollow_area.radius = it->first; |
547 | 336 | Widelands::MapHollowRegion<> mr(map, hollow_area); | 382 | Widelands::MapHollowRegion<> mr(map, hollow_area); |
548 | 337 | do { | 383 | do { |
550 | 338 | result[mr.location()] = workarea_pics_[wa_index]; | 384 | intermediate_result[mr.location()] = wa_index; |
551 | 339 | } while (mr.advance(map)); | 385 | } while (mr.advance(map)); |
552 | 340 | wa_index++; | 386 | wa_index++; |
553 | 341 | hollow_area.hole_radius = hollow_area.radius; | 387 | hollow_area.hole_radius = hollow_area.radius; |
554 | 342 | } | 388 | } |
555 | 389 | |||
556 | 390 | std::map<TCoords<>, uint8_t> result; | ||
557 | 391 | for (const auto& pair : intermediate_result) { | ||
558 | 392 | Coords c; | ||
559 | 393 | map.get_brn(pair.first, &c); | ||
560 | 394 | const auto brn = intermediate_result.find(c); | ||
561 | 395 | if (brn == intermediate_result.end()) { | ||
562 | 396 | continue; | ||
563 | 397 | } | ||
564 | 398 | map.get_bln(pair.first, &c); | ||
565 | 399 | const auto bln = intermediate_result.find(c); | ||
566 | 400 | map.get_rn(pair.first, &c); | ||
567 | 401 | const auto rn = intermediate_result.find(c); | ||
568 | 402 | if (bln != intermediate_result.end()) { | ||
569 | 403 | result[TCoords<>(pair.first, Widelands::TriangleIndex::D)] = workarea_max( | ||
570 | 404 | pair.second, brn->second, bln->second); | ||
571 | 405 | } | ||
572 | 406 | if (rn != intermediate_result.end()) { | ||
573 | 407 | result[TCoords<>(pair.first, Widelands::TriangleIndex::R)] = workarea_max( | ||
574 | 408 | pair.second, brn->second, rn->second); | ||
575 | 409 | } | ||
576 | 410 | } | ||
577 | 411 | result_set.emplace(result); | ||
578 | 343 | } | 412 | } |
580 | 344 | return result; | 413 | return result_set; |
581 | 345 | } | 414 | } |
582 | 346 | 415 | ||
583 | 347 | void InteractiveBase::hide_workarea(const Widelands::Coords& coords) { | 416 | void InteractiveBase::hide_workarea(const Widelands::Coords& coords) { |
584 | 348 | 417 | ||
585 | === modified file 'src/wui/interactive_base.h' | |||
586 | --- src/wui/interactive_base.h 2019-04-19 07:27:15 +0000 | |||
587 | +++ src/wui/interactive_base.h 2019-04-24 15:57:58 +0000 | |||
588 | @@ -231,7 +231,7 @@ | |||
589 | 231 | TextToDraw get_text_to_draw() const; | 231 | TextToDraw get_text_to_draw() const; |
590 | 232 | 232 | ||
591 | 233 | // Returns the current overlays for the work area previews. | 233 | // Returns the current overlays for the work area previews. |
593 | 234 | std::map<Widelands::Coords, const Image*> get_workarea_overlays(const Widelands::Map& map) const; | 234 | Workareas get_workarea_overlays(const Widelands::Map& map) const; |
594 | 235 | 235 | ||
595 | 236 | // Returns the 'BuildhelpOverlay' for 'caps' or nullptr if there is no help | 236 | // Returns the 'BuildhelpOverlay' for 'caps' or nullptr if there is no help |
596 | 237 | // to be displayed on this field. | 237 | // to be displayed on this field. |
597 | @@ -241,8 +241,10 @@ | |||
598 | 241 | return road_building_overlays_; | 241 | return road_building_overlays_; |
599 | 242 | } | 242 | } |
600 | 243 | 243 | ||
603 | 244 | /// Returns true if there is a workarea preview being shown at the given coordinates | 244 | /// Returns true if there is a workarea preview being shown at the given coordinates. |
604 | 245 | bool has_workarea_preview(const Widelands::Coords& coords) const; | 245 | /// If 'map' is 0, checks only if the given coords are the center of a workarea; |
605 | 246 | /// otherwise checks if the coords are within any workarea. | ||
606 | 247 | bool has_workarea_preview(const Widelands::Coords& coords, const Widelands::Map* map = nullptr) const; | ||
607 | 246 | 248 | ||
608 | 247 | /// Returns true if the current player is allowed to hear sounds from map objects on this field | 249 | /// Returns true if the current player is allowed to hear sounds from map objects on this field |
609 | 248 | virtual bool player_hears_field(const Widelands::Coords& coords) const = 0; | 250 | virtual bool player_hears_field(const Widelands::Coords& coords) const = 0; |
610 | @@ -304,7 +306,6 @@ | |||
611 | 304 | 306 | ||
612 | 305 | UI::UniqueWindow::Registry debugconsole_; | 307 | UI::UniqueWindow::Registry debugconsole_; |
613 | 306 | std::unique_ptr<UniqueWindowHandler> unique_window_handler_; | 308 | std::unique_ptr<UniqueWindowHandler> unique_window_handler_; |
614 | 307 | std::vector<const Image*> workarea_pics_; | ||
615 | 308 | BuildhelpOverlay buildhelp_overlays_[Widelands::Field::Buildhelp_None]; | 309 | BuildhelpOverlay buildhelp_overlays_[Widelands::Field::Buildhelp_None]; |
616 | 309 | }; | 310 | }; |
617 | 310 | 311 | ||
618 | 311 | 312 | ||
619 | === modified file 'src/wui/interactive_player.cc' | |||
620 | --- src/wui/interactive_player.cc 2019-04-24 06:01:37 +0000 | |||
621 | +++ src/wui/interactive_player.cc 2019-04-24 15:57:58 +0000 | |||
622 | @@ -160,7 +160,8 @@ | |||
623 | 160 | bool const multiplayer) | 160 | bool const multiplayer) |
624 | 161 | : InteractiveGameBase(g, global_s, NONE, multiplayer), | 161 | : InteractiveGameBase(g, global_s, NONE, multiplayer), |
625 | 162 | auto_roadbuild_mode_(global_s.get_bool("auto_roadbuild_mode", true)), | 162 | auto_roadbuild_mode_(global_s.get_bool("auto_roadbuild_mode", true)), |
627 | 163 | flag_to_connect_(Widelands::Coords::null()) { | 163 | flag_to_connect_(Widelands::Coords::null()), |
628 | 164 | grid_marker_pic_(g_gr->images().get("images/wui/overlays/grid_marker.png")) { | ||
629 | 164 | add_toolbar_button( | 165 | add_toolbar_button( |
630 | 165 | "wui/menus/menu_options_menu", "options_menu", _("Main menu"), &options_, true); | 166 | "wui/menus/menu_options_menu", "options_menu", _("Main menu"), &options_, true); |
631 | 166 | options_.open_window = [this] { new GameOptionsMenu(*this, options_, main_windows_); }; | 167 | options_.open_window = [this] { new GameOptionsMenu(*this, options_, main_windows_); }; |
632 | @@ -286,9 +287,9 @@ | |||
633 | 286 | const Widelands::Map& map = gbase.map(); | 287 | const Widelands::Map& map = gbase.map(); |
634 | 287 | const uint32_t gametime = gbase.get_gametime(); | 288 | const uint32_t gametime = gbase.get_gametime(); |
635 | 288 | 289 | ||
637 | 289 | auto* fields_to_draw = given_map_view->draw_terrain(gbase, dst); | 290 | Workareas workareas = get_workarea_overlays(map); |
638 | 291 | auto* fields_to_draw = given_map_view->draw_terrain(gbase, workareas, dst); | ||
639 | 290 | const auto& road_building = road_building_overlays(); | 292 | const auto& road_building = road_building_overlays(); |
640 | 291 | const std::map<Widelands::Coords, const Image*> workarea_overlays = get_workarea_overlays(map); | ||
641 | 292 | 293 | ||
642 | 293 | const float scale = 1.f / given_map_view->view().zoom; | 294 | const float scale = 1.f / given_map_view->view().zoom; |
643 | 294 | 295 | ||
644 | @@ -329,13 +330,10 @@ | |||
645 | 329 | } | 330 | } |
646 | 330 | } | 331 | } |
647 | 331 | 332 | ||
655 | 332 | // Draw work area previews. | 333 | // Draw work area markers. |
656 | 333 | { | 334 | if (has_workarea_preview(f->fcoords, &map)) { |
657 | 334 | const auto it = workarea_overlays.find(f->fcoords); | 335 | blit_field_overlay(dst, *f, grid_marker_pic_, |
658 | 335 | if (it != workarea_overlays.end()) { | 336 | Vector2i(grid_marker_pic_->width() / 2, grid_marker_pic_->height() / 2), scale); |
652 | 336 | blit_field_overlay(dst, *f, it->second, | ||
653 | 337 | Vector2i(it->second->width() / 2, it->second->height() / 2), scale); | ||
654 | 338 | } | ||
659 | 339 | } | 337 | } |
660 | 340 | 338 | ||
661 | 341 | if (f->vision > 0) { | 339 | if (f->vision > 0) { |
662 | 342 | 340 | ||
663 | === modified file 'src/wui/interactive_player.h' | |||
664 | --- src/wui/interactive_player.h 2019-03-14 23:06:02 +0000 | |||
665 | +++ src/wui/interactive_player.h 2019-04-24 15:57:58 +0000 | |||
666 | @@ -91,6 +91,8 @@ | |||
667 | 91 | UI::UniqueWindow::Registry objectives_; | 91 | UI::UniqueWindow::Registry objectives_; |
668 | 92 | UI::UniqueWindow::Registry encyclopedia_; | 92 | UI::UniqueWindow::Registry encyclopedia_; |
669 | 93 | UI::UniqueWindow::Registry message_menu_; | 93 | UI::UniqueWindow::Registry message_menu_; |
670 | 94 | |||
671 | 95 | const Image* grid_marker_pic_; | ||
672 | 94 | }; | 96 | }; |
673 | 95 | 97 | ||
674 | 96 | #endif // end of include guard: WL_WUI_INTERACTIVE_PLAYER_H | 98 | #endif // end of include guard: WL_WUI_INTERACTIVE_PLAYER_H |
675 | 97 | 99 | ||
676 | === modified file 'src/wui/interactive_spectator.cc' | |||
677 | --- src/wui/interactive_spectator.cc 2019-04-24 06:01:37 +0000 | |||
678 | +++ src/wui/interactive_spectator.cc 2019-04-24 15:57:58 +0000 | |||
679 | @@ -116,12 +116,11 @@ | |||
680 | 116 | 116 | ||
681 | 117 | const Widelands::Game& the_game = game(); | 117 | const Widelands::Game& the_game = game(); |
682 | 118 | const Widelands::Map& map = the_game.map(); | 118 | const Widelands::Map& map = the_game.map(); |
684 | 119 | auto* fields_to_draw = given_map_view->draw_terrain(the_game, dst); | 119 | auto* fields_to_draw = given_map_view->draw_terrain(the_game, get_workarea_overlays(map), dst); |
685 | 120 | const float scale = 1.f / given_map_view->view().zoom; | 120 | const float scale = 1.f / given_map_view->view().zoom; |
686 | 121 | const uint32_t gametime = the_game.get_gametime(); | 121 | const uint32_t gametime = the_game.get_gametime(); |
687 | 122 | 122 | ||
688 | 123 | const auto text_to_draw = get_text_to_draw(); | 123 | const auto text_to_draw = get_text_to_draw(); |
689 | 124 | const std::map<Widelands::Coords, const Image*> workarea_overlays = get_workarea_overlays(map); | ||
690 | 125 | for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) { | 124 | for (size_t idx = 0; idx < fields_to_draw->size(); ++idx) { |
691 | 126 | const FieldsToDraw::Field& field = fields_to_draw->at(idx); | 125 | const FieldsToDraw::Field& field = fields_to_draw->at(idx); |
692 | 127 | 126 | ||
693 | @@ -137,13 +136,6 @@ | |||
694 | 137 | bob->draw(the_game, text_to_draw, field.rendertarget_pixel, field.fcoords, scale, dst); | 136 | bob->draw(the_game, text_to_draw, field.rendertarget_pixel, field.fcoords, scale, dst); |
695 | 138 | } | 137 | } |
696 | 139 | 138 | ||
697 | 140 | // Draw work area previews. | ||
698 | 141 | const auto it = workarea_overlays.find(field.fcoords); | ||
699 | 142 | if (it != workarea_overlays.end()) { | ||
700 | 143 | const Image* pic = it->second; | ||
701 | 144 | blit_field_overlay(dst, field, pic, Vector2i(pic->width() / 2, pic->height() / 2), scale); | ||
702 | 145 | } | ||
703 | 146 | |||
704 | 147 | // Draw build help. | 139 | // Draw build help. |
705 | 148 | if (buildhelp()) { | 140 | if (buildhelp()) { |
706 | 149 | auto caps = Widelands::NodeCaps::CAPS_NONE; | 141 | auto caps = Widelands::NodeCaps::CAPS_NONE; |
707 | 150 | 142 | ||
708 | === modified file 'src/wui/mapview.cc' | |||
709 | --- src/wui/mapview.cc 2019-04-23 16:24:40 +0000 | |||
710 | +++ src/wui/mapview.cc 2019-04-24 15:57:58 +0000 | |||
711 | @@ -339,7 +339,7 @@ | |||
712 | 339 | NEVER_HERE(); | 339 | NEVER_HERE(); |
713 | 340 | } | 340 | } |
714 | 341 | 341 | ||
716 | 342 | FieldsToDraw* MapView::draw_terrain(const Widelands::EditorGameBase& egbase, RenderTarget* dst) { | 342 | FieldsToDraw* MapView::draw_terrain(const Widelands::EditorGameBase& egbase, Workareas workarea, RenderTarget* dst) { |
717 | 343 | uint32_t now = SDL_GetTicks(); | 343 | uint32_t now = SDL_GetTicks(); |
718 | 344 | while (!view_plans_.empty()) { | 344 | while (!view_plans_.empty()) { |
719 | 345 | auto& plan = view_plans_.front(); | 345 | auto& plan = view_plans_.front(); |
720 | @@ -383,7 +383,7 @@ | |||
721 | 383 | 383 | ||
722 | 384 | fields_to_draw_.reset(egbase, view_.viewpoint, view_.zoom, dst); | 384 | fields_to_draw_.reset(egbase, view_.viewpoint, view_.zoom, dst); |
723 | 385 | const float scale = 1.f / view_.zoom; | 385 | const float scale = 1.f / view_.zoom; |
725 | 386 | ::draw_terrain(egbase, fields_to_draw_, scale, dst); | 386 | ::draw_terrain(egbase, fields_to_draw_, scale, workarea, dst); |
726 | 387 | return &fields_to_draw_; | 387 | return &fields_to_draw_; |
727 | 388 | } | 388 | } |
728 | 389 | 389 | ||
729 | 390 | 390 | ||
730 | === modified file 'src/wui/mapview.h' | |||
731 | --- src/wui/mapview.h 2019-03-26 02:56:03 +0000 | |||
732 | +++ src/wui/mapview.h 2019-04-24 15:57:58 +0000 | |||
733 | @@ -172,7 +172,7 @@ | |||
734 | 172 | // Schedules drawing of the terrain of this MapView. The returned value can | 172 | // Schedules drawing of the terrain of this MapView. The returned value can |
735 | 173 | // be used to override contents of 'fields_to_draw' for player knowledge and | 173 | // be used to override contents of 'fields_to_draw' for player knowledge and |
736 | 174 | // visibility, and to correctly draw map objects, overlays and text. | 174 | // visibility, and to correctly draw map objects, overlays and text. |
738 | 175 | FieldsToDraw* draw_terrain(const Widelands::EditorGameBase& egbase, RenderTarget* dst); | 175 | FieldsToDraw* draw_terrain(const Widelands::EditorGameBase& egbase, Workareas workarea, RenderTarget* dst); |
739 | 176 | 176 | ||
740 | 177 | // Not overriden from UI::Panel, instead we expect to be passed the data through. | 177 | // Not overriden from UI::Panel, instead we expect to be passed the data through. |
741 | 178 | bool handle_mousepress(uint8_t btn, int32_t x, int32_t y); | 178 | bool handle_mousepress(uint8_t btn, int32_t x, int32_t y); |
A few nits in the comments