Skip to content

Commit 7d317b8

Browse files
committed
refactor: simplified ghost preview logic fr bandstand
1 parent 9e31b01 commit 7d317b8

File tree

2 files changed

+29
-38
lines changed

2 files changed

+29
-38
lines changed

src/building/building_bandstand.cpp

+29-37
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,44 @@ void building_bandstand::static_params::planer_setup_preview_graphics(build_plan
4141
}
4242

4343
void building_bandstand::static_params::planer_ghost_preview(build_planner &planer, painter &ctx, tile2i start, tile2i end, vec2i pixel) const {
44-
int can_build = 0;
45-
46-
int size = building_impl::params(type).building_size;
4744
int orientation = 0;
4845

49-
can_build = map_orientation_for_venue_with_map_orientation(end, e_venue_mode_bandstand, &orientation);
46+
int can_build = map_orientation_for_venue_with_map_orientation(end, e_venue_mode_bandstand, &orientation);
5047
// TODO: proper correct for map orientation (for now, just use a different orientation)
5148
orientation = abs(orientation + (8 - city_view_orientation())) % 8;
5249

5350
if (can_build != 1) { // no can place
54-
for (int i = 0; i < size * size; i++) {
51+
for (int i = 0; i < building_size * building_size; i++) {
5552
planer.draw_flat_tile(ctx, pixel + VIEW_OFFSETS[i], COLOR_MASK_RED);
5653
}
5754
} else { // can place (theoretically)
58-
building_bandstand::ghost_preview(ctx, end, pixel, orientation);
55+
int square_id = bandstand_m.anim[animkeys().square].first_img();
56+
for (int i = 0; i < building_size * building_size; i++) {
57+
ImageDraw::isometric(ctx, square_id + i, pixel + vec2i{ ((i % building_size) - (i / building_size)) * 30, ((i % building_size) + (i / building_size)) * 15 }, COLOR_MASK_GREEN);
58+
}
59+
60+
switch (orientation / 2) {
61+
case 0:
62+
planer.draw_building_ghost(ctx, bandstand_m.stand_sn_n, pixel, COLOR_MASK_GREEN);
63+
planer.draw_building_ghost(ctx, bandstand_m.stand_sn_s, pixel + vec2i{ -30, 15 }, COLOR_MASK_GREEN);
64+
planer.draw_building_ghost(ctx, bandstand_m.booth, pixel + vec2i{ 60, 30 }, COLOR_MASK_GREEN);
65+
break;
66+
case 1:
67+
planer.draw_building_ghost(ctx, bandstand_m.stand_we_w, pixel + vec2i{ 30, 15 }, COLOR_MASK_GREEN);
68+
planer.draw_building_ghost(ctx, bandstand_m.stand_we_e, pixel + vec2i{ 60, 30 }, COLOR_MASK_GREEN);
69+
planer.draw_building_ghost(ctx, bandstand_m.booth, pixel + vec2i{ 0, 60 }, COLOR_MASK_GREEN);
70+
break;
71+
case 2:
72+
planer.draw_building_ghost(ctx, bandstand_m.stand_sn_n, pixel + vec2i{ -30, 15 }, COLOR_MASK_GREEN);
73+
planer.draw_building_ghost(ctx, bandstand_m.stand_sn_s, pixel + vec2i{ -60, 30 }, COLOR_MASK_GREEN);
74+
planer.draw_building_ghost(ctx, bandstand_m.booth, pixel + vec2i{ 0, 60 }, COLOR_MASK_GREEN);
75+
break;
76+
case 3:
77+
planer.draw_building_ghost(ctx, bandstand_m.stand_we_w, pixel, COLOR_MASK_GREEN);
78+
planer.draw_building_ghost(ctx, bandstand_m.stand_we_e, pixel + vec2i{ 30, 15 }, COLOR_MASK_GREEN);
79+
planer.draw_building_ghost(ctx, bandstand_m.booth, pixel + vec2i{ -60, 30 }, COLOR_MASK_GREEN);
80+
break;
81+
}
5982
}
6083
}
6184

@@ -234,34 +257,3 @@ bool building_bandstand::draw_ornaments_and_animations_height(painter &ctx, vec2
234257

235258
return false;
236259
}
237-
238-
void building_bandstand::ghost_preview(painter &ctx, tile2i tile, vec2i pixel, int orientation) {
239-
int size = bandstand_m.building_size;
240-
int square_id = bandstand_m.anim[animkeys().square].first_img();
241-
for (int i = 0; i < size * size; i++) {
242-
ImageDraw::isometric(ctx, square_id + i, pixel + vec2i{((i % size) - (i / size)) * 30, ((i % size) + (i / size)) * 15}, COLOR_MASK_GREEN);
243-
}
244-
245-
switch (orientation / 2) {
246-
case 0:
247-
build_planner::draw_building_ghost(ctx, bandstand_m.stand_sn_n, pixel, COLOR_MASK_GREEN);
248-
build_planner::draw_building_ghost(ctx, bandstand_m.stand_sn_s, pixel + vec2i{-30, 15}, COLOR_MASK_GREEN);
249-
build_planner::draw_building_ghost(ctx, bandstand_m.booth, pixel + vec2i{60, 30}, COLOR_MASK_GREEN);
250-
break;
251-
case 1:
252-
build_planner::draw_building_ghost(ctx, bandstand_m.stand_we_w, pixel + vec2i{30, 15}, COLOR_MASK_GREEN);
253-
build_planner::draw_building_ghost(ctx, bandstand_m.stand_we_e, pixel + vec2i{60, 30}, COLOR_MASK_GREEN);
254-
build_planner::draw_building_ghost(ctx, bandstand_m.booth, pixel + vec2i{0, 60}, COLOR_MASK_GREEN);
255-
break;
256-
case 2:
257-
build_planner::draw_building_ghost(ctx, bandstand_m.stand_sn_n, pixel + vec2i{-30, 15}, COLOR_MASK_GREEN);
258-
build_planner::draw_building_ghost(ctx, bandstand_m.stand_sn_s, pixel + vec2i{-60, 30}, COLOR_MASK_GREEN);
259-
build_planner::draw_building_ghost(ctx, bandstand_m.booth, pixel + vec2i{0, 60}, COLOR_MASK_GREEN);
260-
break;
261-
case 3:
262-
build_planner::draw_building_ghost(ctx, bandstand_m.stand_we_w, pixel, COLOR_MASK_GREEN);
263-
build_planner::draw_building_ghost(ctx, bandstand_m.stand_we_e, pixel + vec2i{30, 15}, COLOR_MASK_GREEN);
264-
build_planner::draw_building_ghost(ctx, bandstand_m.booth, pixel + vec2i{-60, 30}, COLOR_MASK_GREEN);
265-
break;
266-
}
267-
}

src/building/building_bandstand.h

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class building_bandstand : public building_entertainment {
3939

4040
virtual bool draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color mask) override;
4141
void draw_shows_musicians(painter &ctx, vec2i pixel, int direction, color color_mask);
42-
static void ghost_preview(painter &ctx, tile2i tile, vec2i pixel, int orientation);
4342

4443
static const static_params &current_params() { return (const static_params &)params(TYPE); }
4544
};

0 commit comments

Comments
 (0)