Skip to content

Commit

Permalink
Implemented subtiles highlighters.
Browse files Browse the repository at this point in the history
  • Loading branch information
ipochto committed Dec 5, 2023
1 parent 8024b66 commit 8376505
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/include/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ class CViewport
void Set(const PixelPos &mapPixelPos);
/// Draw the map grid for dubug purposes
void DrawMapGridInViewport() const;
/// Highlight overlays when size of logical and graphical tiles are identical
void HighlightGraphicalTileInViewport(int dx, int dy, uint32_t color = ColorRed, uint8_t transparency = 64) const;
/// Highlight overlays when size of logical and graphical tiles are differ
void HighlightGraphicalTileInViewport(int dx, int dy, int graphicTileOffset, int sx,
const fieldHighlightChecker highlightChecker,
uint32_t color = ColorRed, uint8_t transparency = 64) const;

/** Draw the map background.
* The template parameter graphicalTileIsLogicalTile selects the specialization.
* Drawing maps where graphical and logical tile sizes differ implies some extra
Expand Down
54 changes: 38 additions & 16 deletions src/map/map_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,25 @@ void CViewport::DrawMapGridInViewport() const
Video.DrawLineClip(ColorDarkGray, {this->TopLeftPos.x - this->Offset.x, y}, {this->BottomRightPos.x, y});
}
}
/// Highlight overlays when size of logical and graphical tiles are identical
void CViewport::HighlightGraphicalTileInViewport(int dx, int dy, uint32_t color /* = ColorRed */, uint8_t transparency /* = 64*/) const
{
Video.FillTransRectangleClip(color, dx, dy, PixelTileSize.x, PixelTileSize.y, transparency);
}

/// Highlight overlays when size of logical and graphical tiles are differ
void CViewport::HighlightGraphicalTileInViewport(int dx, int dy, int graphicTileOffset, int sx,
const fieldHighlightChecker highlightChecker,
uint32_t color /* = ColorRed */, uint8_t transparency /* = 64*/) const
{
for (int i = 0; i < graphicTileOffset; i++) {
for (int j = 0; j < graphicTileOffset; j++) {
if (highlightChecker(Map.Fields[sx + j + (Map.Info.MapWidth * i)])) {
Video.FillTransRectangleClip(color, dx + j * PixelTileSize.x, dy + i * PixelTileSize.y, PixelTileSize.x, PixelTileSize.y, transparency);
}
}
}
}

template<bool graphicalTileIsLogicalTile>
void CViewport::DrawMapBackgroundInViewport(const fieldHighlightChecker highlightChecker /* = nullptr */) const
Expand Down Expand Up @@ -331,24 +350,27 @@ void CViewport::DrawMapBackgroundInViewport(const fieldHighlightChecker highligh
#ifdef DEBUG
// AStar passability overlay
if (CViewport::isPassabilityHighlighted()) {
for (int i = 0; i < graphicTileOffset; i++) {
for (int j = 0; j < graphicTileOffset; j++) {
if (Map.Fields[sx + j + (mapW * i)].getFlag() & MapFieldUnpassable) {
Video.FillTransRectangleClip(ColorRed, dx + j * PixelTileSize.x, dy + i * PixelTileSize.y, PixelTileSize.x, PixelTileSize.y, 32);
} else {
Video.FillTransRectangleClip(ColorGreen, dx + j * PixelTileSize.x, dy + i * PixelTileSize.y, PixelTileSize.x, PixelTileSize.y, 32);
}

if (Map.Fields[sx + j + (mapW * i)].getFlag() & (MapFieldLandUnit | MapFieldBuilding | MapFieldSeaUnit)) {
Video.FillTransRectangleClip(ColorOrange, dx + j * PixelTileSize.x, dy + i * PixelTileSize.y, PixelTileSize.x, PixelTileSize.y, 32);
}
}
}

HighlightGraphicalTileInViewport(dx, dy, graphicTileOffset, sx,
[](const CMapField &mf) -> bool { return mf.getFlag() & MapFieldUnpassable; },
ColorRed, 32);
HighlightGraphicalTileInViewport(dx, dy, graphicTileOffset, sx,
[](const CMapField &mf) -> bool { return !(mf.getFlag() & MapFieldUnpassable); },
ColorGreen, 32);
HighlightGraphicalTileInViewport(dx, dy, graphicTileOffset, sx,
[](const CMapField &mf) -> bool { return mf.getFlag() & (MapFieldLandUnit | MapFieldBuilding | MapFieldSeaUnit); },
ColorOrange, 32);
}
#endif
/// Highlight layer if needed (editor stuff)
if (highlightChecker && highlightChecker(mf)) {
Video.FillTransRectangleClip(ColorRed, dx, dy, PixelTileSize.x, PixelTileSize.y, 64);
/// Highlight overlay if needed (editor stuff)
if (highlightChecker) {
if constexpr(graphicalTileIsLogicalTile) {
if(highlightChecker(mf)) {
HighlightGraphicalTileInViewport(dx, dy);
}
} else {
HighlightGraphicalTileInViewport(dx, dy, graphicTileOffset, sx, highlightChecker);
}
}
if constexpr(graphicalTileIsLogicalTile) {
++sx;
Expand Down

0 comments on commit 8376505

Please sign in to comment.