diff --git a/src/viewport.cpp b/src/viewport.cpp index 6df6440b99..5d3fcab24a 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -149,14 +149,6 @@ struct ChildScreenSpriteToDraw { int next; ///< next child to draw (-1 at the end) }; -/** Enumeration of multi-part foundations */ -enum FoundationPart { - FOUNDATION_PART_NONE = 0xFF, ///< Neither foundation nor groundsprite drawn yet. - FOUNDATION_PART_NORMAL = 0, ///< First part (normal foundation or no foundation) - FOUNDATION_PART_HALFTILE = 1, ///< Second part (halftile foundation) - FOUNDATION_PART_END -}; - /** * Mode of "sprite combining" * @see StartSpriteCombine @@ -1015,16 +1007,17 @@ static void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint * @param ti TileInfo Tile that is being drawn * @param z_offset Z offset relative to the groundsprite. Only used for the sprite position, not for sprite sorting. * @param foundation_part Foundation part the sprite belongs to. + * @param sub Sub-section of sprite to draw. */ -static void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part) +void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part, const SubSprite *sub) { /* FIXME: This is not totally valid for some autorail highlights that extend over the edges of the tile. */ if (_vd.foundation[foundation_part] == -1) { /* draw on real ground */ - AddTileSpriteToDraw(image, pal, ti->x, ti->y, ti->z + z_offset); + AddTileSpriteToDraw(image, pal, ti->x, ti->y, ti->z + z_offset, sub); } else { /* draw on top of foundation */ - AddChildSpriteToFoundation(image, pal, NULL, foundation_part, 0, -z_offset * ZOOM_LVL_BASE); + AddChildSpriteToFoundation(image, pal, sub, foundation_part, 0, -z_offset * ZOOM_LVL_BASE); } } @@ -1034,7 +1027,7 @@ static void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *t * @param ti TileInfo Tile that is being drawn * @param pal Palette to apply. */ -static void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal) +void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal) { if (!IsValidTile(ti->tile)) return; diff --git a/src/viewport_func.h b/src/viewport_func.h index 8a303e85a0..5aa40daa7d 100644 --- a/src/viewport_func.h +++ b/src/viewport_func.h @@ -19,6 +19,8 @@ #include "station_type.h" #include "vehicle_base.h" +struct TileInfo; + static const int TILE_HEIGHT_STEP = 50; ///< One Z unit tile height difference is displayed as 50m. void SetSelectionRed(bool); @@ -98,4 +100,7 @@ void ShowTooltipForTile(Window *w, const TileIndex tile); void ViewportMapClearTunnelCache(); void ViewportMapInvalidateTunnelCacheByTile(const TileIndex tile); +void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal); +void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part, const SubSprite *sub = NULL); + #endif /* VIEWPORT_FUNC_H */ diff --git a/src/viewport_type.h b/src/viewport_type.h index 9011070e34..7b9ce33c80 100644 --- a/src/viewport_type.h +++ b/src/viewport_type.h @@ -149,4 +149,12 @@ enum ViewportScrollTarget { VST_CLIENT, ///< Single player }; +/** Enumeration of multi-part foundations */ +enum FoundationPart { + FOUNDATION_PART_NONE = 0xFF, ///< Neither foundation nor groundsprite drawn yet. + FOUNDATION_PART_NORMAL = 0, ///< First part (normal foundation or no foundation) + FOUNDATION_PART_HALFTILE = 1, ///< Second part (halftile foundation) + FOUNDATION_PART_END +}; + #endif /* VIEWPORT_TYPE_H */ diff --git a/src/zoning_cmd.cpp b/src/zoning_cmd.cpp index 8423408367..342e68f791 100644 --- a/src/zoning_cmd.cpp +++ b/src/zoning_cmd.cpp @@ -26,6 +26,7 @@ #include "tracerestrict.h" #include "window_func.h" #include "zoning.h" +#include "viewport_func.h" #include "3rdparty/cpp-btree/btree_set.h" Zoning _zoning; @@ -391,11 +392,34 @@ void DrawTileZoning(const TileInfo *ti) } if (_zoning.outer != ZEM_NOTHING) { - DrawZoningSprites(SPR_SELECT_TILE, TileZoningSpriteEvaluationCached(ti->tile, _local_company, _zoning.outer, false), ti); + const SpriteID colour = TileZoningSpriteEvaluationCached(ti->tile, _local_company, _zoning.outer, false); + + if (colour != ZONING_INVALID_SPRITE_ID) { + DrawTileSelectionRect(ti, colour); + } } if (_zoning.inner != ZEM_NOTHING) { - DrawZoningSprites(SPR_ZONING_INNER_HIGHLIGHT_BASE, TileZoningSpriteEvaluationCached(ti->tile, _local_company, _zoning.inner, true), ti); + const SpriteID colour = TileZoningSpriteEvaluationCached(ti->tile, _local_company, _zoning.inner, true); + + if (colour != ZONING_INVALID_SPRITE_ID) { + SpriteID sprite = SPR_ZONING_INNER_HIGHLIGHT_BASE; + + if (IsHalftileSlope(ti->tileh)) { + const int INF = 1000; + static const SubSprite sub_sprites[4] = { + { -INF , -INF , 32 - 33, INF }, // CORNER_W, clip 33 pixels from right + { -INF , 0 + 22, INF , INF }, // CORNER_S, clip 22 pixels from top + { -31 + 34, -INF , INF , INF }, // CORNER_E, clip 34 pixels from left + { -INF , -INF , INF , 30 - 8 } // CORNER_N, clip 8 pixels from bottom + }; + + DrawSelectionSprite(sprite, colour, ti, 7 + TILE_HEIGHT, FOUNDATION_PART_HALFTILE, &(sub_sprites[GetHalftileSlopeCorner(ti->tileh)])); + } else { + sprite += SlopeToSpriteOffset(ti->tileh); + } + DrawSelectionSprite(sprite, colour, ti, 7, FOUNDATION_PART_NORMAL); + } } }