Skip to content

Commit 9e31b01

Browse files
committed
refactor: simplify ghost preview logic for festival square
1 parent f24175c commit 9e31b01

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

src/building/building_farm.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ void building_farm::static_params_t<T>::planer_ghost_preview(build_planner &plan
136136
blocked_tile_vec blocked_tiles_farm;
137137

138138
const bool blocked = is_blocked(end, this->building_size, blocked_tiles_farm);
139-
140139
if (blocked) {
141140
planer.draw_partially_blocked(ctx, false, blocked_tiles_farm);
142-
} else {
143-
int image_id = get_farm_image(TYPE, end);
144-
planer.draw_building_ghost(ctx, image_id, pixel + vec2i{ -60, 30 });
145-
draw_crops(ctx, TYPE, 0, end, pixel + vec2i{ -60, 30 }, COLOR_MASK_GREEN);
141+
return;
146142
}
143+
144+
int image_id = get_farm_image(TYPE, end);
145+
planer.draw_building_ghost(ctx, image_id, pixel + vec2i{ -60, 30 });
146+
draw_crops(ctx, TYPE, 0, end, pixel + vec2i{ -60, 30 }, COLOR_MASK_GREEN);
147147
}
148148

149149
int building_farm::get_crops_image(e_building_type type, int growth) {

src/building/building_festival_square.cpp

+8-16
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,23 @@ void building_festival_square::static_params::planer_setup_preview_graphics(buil
2525
}
2626

2727
void building_festival_square::static_params::planer_ghost_preview(build_planner &planer, painter &ctx, tile2i start, tile2i end, vec2i pixel) const {
28-
int can_build = 0;
29-
30-
int size = building_impl::params(type).building_size;
3128
int orientation = 0;
3229

33-
can_build = map_orientation_for_venue_with_map_orientation(end, e_venue_mode_festival_square, &orientation);
30+
bool can_build = map_orientation_for_venue_with_map_orientation(end, e_venue_mode_festival_square, &orientation);
3431
// TODO: proper correct for map orientation (for now, just use a different orientation)
3532
orientation = abs(orientation + (8 - city_view_orientation())) % 8;
3633

3734
if (can_build != 1) { // no can place
38-
for (int i = 0; i < size * size; i++) {
35+
for (int i = 0; i < building_size * building_size; i++) {
3936
planer.draw_flat_tile(ctx, pixel + VIEW_OFFSETS[i], COLOR_MASK_RED);
4037
}
4138
} else { // can place (theoretically)
42-
building_festival_square::ghost_preview(ctx, end, pixel, orientation);
39+
int square_id = current_params().anim[animkeys().square].first_img();
40+
bool is_exist = building_count_total(BUILDING_FESTIVAL_SQUARE);
41+
int color_mask = is_exist ? COLOR_MASK_RED : COLOR_MASK_GREEN;
42+
for (int i = 0; i < building_size * building_size; i++) {
43+
ImageDraw::isometric(ctx, square_id + i, pixel + vec2i{ ((i % building_size) - (i / building_size)) * 30, ((i % building_size) + (i / building_size)) * 15 }, color_mask);
44+
}
4345
}
4446
}
4547

@@ -90,13 +92,3 @@ void building_festival_square::on_undo() {
9092
void building_festival_square::on_post_load() {
9193
g_city.buildings.festival_square = this->tile();
9294
}
93-
94-
void building_festival_square::ghost_preview(painter &ctx, tile2i tile, vec2i pixel, int orientation) {
95-
int square_id = current_params().anim[animkeys().square].first_img();
96-
int size = festival_square_m.building_size;
97-
bool is_exist = building_count_total(BUILDING_FESTIVAL_SQUARE);
98-
int color_mask = is_exist ? COLOR_MASK_RED : COLOR_MASK_GREEN;
99-
for (int i = 0; i < size * size; i++) {
100-
ImageDraw::isometric(ctx, square_id + i, pixel + vec2i{((i % size) - (i / size)) * 30, ((i % size) + (i / size)) * 15}, color_mask);
101-
}
102-
}

src/building/building_festival_square.h

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,5 @@ class building_festival_square : public building_impl {
2323
virtual void on_undo() override;
2424
virtual void on_post_load() override;
2525

26-
static void ghost_preview(painter &ctx, tile2i tile, vec2i pixel, int orientation);
27-
2826
static const static_params &current_params() { return (const static_params &)params(TYPE); }
2927
};

0 commit comments

Comments
 (0)