From f42823435792670b4b28412847543dc81448db37 Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Sat, 1 Feb 2025 13:18:15 -0600 Subject: [PATCH 1/5] DRY-ed the cursor drawing to use a common function --- GUI.cpp | 53 ++++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/GUI.cpp b/GUI.cpp index bfde84ec..694a4c35 100644 --- a/GUI.cpp +++ b/GUI.cpp @@ -484,25 +484,20 @@ void DrawCurrentLevelOutline(bool backPart) namespace { - void drawSelectionCursor(WorldSegment* segment) + void drawCursorAt(WorldSegment* segment, Crd3D cursor, ALLEGRO_COLOR color, bool needsCorrection) { auto& ssConfig = stonesenseState.ssConfig; - - Crd3D selection = segment->segState.dfSelection; - if ((selection.x != -30000 && ssConfig.config.follow_DFcursor) - || (ssConfig.config.track_mode == Config::TRACKING_FOCUS)) { - segment->CorrectTileForSegmentOffset(selection.x, selection.y, selection.z); - segment->CorrectTileForSegmentRotation(selection.x, selection.y, selection.z); + if (needsCorrection) { + segment->CorrectTileForSegmentOffset(cursor.x, cursor.y, cursor.z); + segment->CorrectTileForSegmentRotation(cursor.x, cursor.y, cursor.z); } - else { - return; - } - Crd2D point = LocalTileToScreen(selection.x, selection.y, selection.z); + + Crd2D point = LocalTileToScreen(cursor.x, cursor.y, cursor.z); int sheetx = SPRITEOBJECT_CURSOR % SHEET_OBJECTSWIDE; int sheety = SPRITEOBJECT_CURSOR / SHEET_OBJECTSWIDE; al_draw_tinted_scaled_bitmap( stonesenseState.IMGObjectSheet, - uiColor(3), + color, sheetx * SPRITEWIDTH, sheety * SPRITEHEIGHT, SPRITEWIDTH, @@ -514,29 +509,25 @@ namespace 0); } - void drawDebugCursor(WorldSegment* segment) + void drawSelectionCursor(WorldSegment* segment) { auto& ssConfig = stonesenseState.ssConfig; + Crd3D selection = segment->segState.dfSelection; + if ((selection.x != -30000 && ssConfig.config.follow_DFcursor) + || (ssConfig.config.track_mode == Config::TRACKING_FOCUS)) { + segment->CorrectTileForSegmentOffset(selection.x, selection.y, selection.z); + segment->CorrectTileForSegmentRotation(selection.x, selection.y, selection.z); + } + else { + return; + } + drawCursorAt(segment, selection, uiColor(3), false); + } + void drawDebugCursor(WorldSegment* segment) + { Crd3D cursor = segment->segState.dfCursor; - segment->CorrectTileForSegmentOffset(cursor.x, cursor.y, cursor.z); - segment->CorrectTileForSegmentRotation(cursor.x, cursor.y, cursor.z); - - Crd2D point = LocalTileToScreen(cursor.x, cursor.y, cursor.z); - int sheetx = SPRITEOBJECT_CURSOR % SHEET_OBJECTSWIDE; - int sheety = SPRITEOBJECT_CURSOR / SHEET_OBJECTSWIDE; - al_draw_tinted_scaled_bitmap( - stonesenseState.IMGObjectSheet, - uiColor(2), - sheetx * SPRITEWIDTH, - sheety * SPRITEHEIGHT, - SPRITEWIDTH, - SPRITEHEIGHT, - point.x - ((SPRITEWIDTH / 2) * ssConfig.scale), - point.y - (WALLHEIGHT)*ssConfig.scale, - SPRITEWIDTH * ssConfig.scale, - SPRITEHEIGHT * ssConfig.scale, - 0); + drawCursorAt(segment, cursor, uiColor(2), true); } void drawAdvmodeMenuTalk(const ALLEGRO_FONT* font, int x, int y) From 75f7e97ed222ea2a165d8b6611b4af47f7d4a09a Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Sun, 2 Feb 2025 11:40:16 -0600 Subject: [PATCH 2/5] Removed needsCorrection and cleaned things up --- GUI.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/GUI.cpp b/GUI.cpp index 694a4c35..4013b3b8 100644 --- a/GUI.cpp +++ b/GUI.cpp @@ -484,13 +484,11 @@ void DrawCurrentLevelOutline(bool backPart) namespace { - void drawCursorAt(WorldSegment* segment, Crd3D cursor, ALLEGRO_COLOR color, bool needsCorrection) + void drawCursorAt(WorldSegment* segment, Crd3D cursor, ALLEGRO_COLOR color) { auto& ssConfig = stonesenseState.ssConfig; - if (needsCorrection) { - segment->CorrectTileForSegmentOffset(cursor.x, cursor.y, cursor.z); - segment->CorrectTileForSegmentRotation(cursor.x, cursor.y, cursor.z); - } + segment->CorrectTileForSegmentOffset(cursor.x, cursor.y, cursor.z); + segment->CorrectTileForSegmentRotation(cursor.x, cursor.y, cursor.z); Crd2D point = LocalTileToScreen(cursor.x, cursor.y, cursor.z); int sheetx = SPRITEOBJECT_CURSOR % SHEET_OBJECTSWIDE; @@ -515,19 +513,17 @@ namespace Crd3D selection = segment->segState.dfSelection; if ((selection.x != -30000 && ssConfig.config.follow_DFcursor) || (ssConfig.config.track_mode == Config::TRACKING_FOCUS)) { - segment->CorrectTileForSegmentOffset(selection.x, selection.y, selection.z); - segment->CorrectTileForSegmentRotation(selection.x, selection.y, selection.z); + drawCursorAt(segment, selection, uiColor(3)); } else { return; } - drawCursorAt(segment, selection, uiColor(3), false); } void drawDebugCursor(WorldSegment* segment) { Crd3D cursor = segment->segState.dfCursor; - drawCursorAt(segment, cursor, uiColor(2), true); + drawCursorAt(segment, cursor, uiColor(2)); } void drawAdvmodeMenuTalk(const ALLEGRO_FONT* font, int x, int y) From 5c5b2b08904341d3549dbce8028c380132be5443 Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Mon, 3 Feb 2025 14:14:41 -0600 Subject: [PATCH 3/5] Pass a reference, not a copy (hopefully) --- GUI.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GUI.cpp b/GUI.cpp index 4013b3b8..41548d8e 100644 --- a/GUI.cpp +++ b/GUI.cpp @@ -484,7 +484,7 @@ void DrawCurrentLevelOutline(bool backPart) namespace { - void drawCursorAt(WorldSegment* segment, Crd3D cursor, ALLEGRO_COLOR color) + void drawCursorAt(WorldSegment* segment, Crd3D& cursor, const ALLEGRO_COLOR& color) { auto& ssConfig = stonesenseState.ssConfig; segment->CorrectTileForSegmentOffset(cursor.x, cursor.y, cursor.z); @@ -510,7 +510,7 @@ namespace void drawSelectionCursor(WorldSegment* segment) { auto& ssConfig = stonesenseState.ssConfig; - Crd3D selection = segment->segState.dfSelection; + Crd3D& selection = segment->segState.dfSelection; if ((selection.x != -30000 && ssConfig.config.follow_DFcursor) || (ssConfig.config.track_mode == Config::TRACKING_FOCUS)) { drawCursorAt(segment, selection, uiColor(3)); @@ -522,7 +522,7 @@ namespace void drawDebugCursor(WorldSegment* segment) { - Crd3D cursor = segment->segState.dfCursor; + Crd3D& cursor = segment->segState.dfCursor; drawCursorAt(segment, cursor, uiColor(2)); } From c6ca1eafda040d1386b94457cee600c22129daa4 Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Thu, 6 Feb 2025 12:05:53 -0600 Subject: [PATCH 4/5] Add cursor occlusion when blocked by tiles --- GUI.cpp | 35 +++++++++++++++++++++++++++++++++-- SpriteMaps.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/GUI.cpp b/GUI.cpp index 41548d8e..ea087f9d 100644 --- a/GUI.cpp +++ b/GUI.cpp @@ -486,13 +486,44 @@ namespace { void drawCursorAt(WorldSegment* segment, Crd3D& cursor, const ALLEGRO_COLOR& color) { + std::array directions = { eUpLeft, eUp, eUpRight, eRight, eDownRight, eDown, eDownLeft, eLeft }; + std::array dirs = {}; + + for (unsigned int i = 0; i < directions.size(); i++) { + dirs[i] = segment->getTileRelativeTo(cursor.x, cursor.y, cursor.z, directions[i]); + } + + auto isObscuring = [&](Tile* tile) { + auto& buildType = tile->building.type; + return tile && + buildType != BUILDINGTYPE_NA && + buildType != df::enums::building_type::Civzone && + buildType != df::enums::building_type::Stockpile; + }; + + // Check the tiles in front of the cursor + bool occludeCursor = false; + for (int i : {3, 4, 5}) { + if (occludeCursor) break; + if (!dirs[i]) { + continue; + } + int shape = dirs[i]->tileShapeBasic(); + if (isObscuring(dirs[i]) || + shape == df::tiletype_shape_basic::Ramp || + shape == df::tiletype_shape_basic::Wall) { + occludeCursor = true; + } + } + auto& ssConfig = stonesenseState.ssConfig; segment->CorrectTileForSegmentOffset(cursor.x, cursor.y, cursor.z); segment->CorrectTileForSegmentRotation(cursor.x, cursor.y, cursor.z); Crd2D point = LocalTileToScreen(cursor.x, cursor.y, cursor.z); - int sheetx = SPRITEOBJECT_CURSOR % SHEET_OBJECTSWIDE; - int sheety = SPRITEOBJECT_CURSOR / SHEET_OBJECTSWIDE; + int spriteIDX = (occludeCursor ? SPRITEOBJECT_CURSOROCCLUDE : SPRITEOBJECT_CURSOR); + int sheetx = spriteIDX % SHEET_OBJECTSWIDE; + int sheety = spriteIDX / SHEET_OBJECTSWIDE; al_draw_tinted_scaled_bitmap( stonesenseState.IMGObjectSheet, color, diff --git a/SpriteMaps.h b/SpriteMaps.h index 5c960c0e..c813f6c9 100644 --- a/SpriteMaps.h +++ b/SpriteMaps.h @@ -45,6 +45,7 @@ enum enumObjectSprites { SPRITEOBJECT_BLUEPRINT = 321, SPRITEOBJECT_STOCKPILE = 322, SPRITEOBJECT_CURSOR = 323, + SPRITEOBJECT_CURSOROCCLUDE = 304, }; From 17141277ee73bdecdb38fe2d08ab7ba5196b5a56 Mon Sep 17 00:00:00 2001 From: Squid Coder Date: Thu, 6 Feb 2025 12:19:10 -0600 Subject: [PATCH 5/5] Update changelog.txt --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index bdc9e52b..b2ded775 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -67,6 +67,7 @@ Template for new versions: - `stonesense`: improved the way altars look - `stonesense`: fog no longer unnecessarily renders to a separate bitmap - `stonesense`: added new connective tiles for pools of blood and vomit +- `stonesense`: made the cursor change sprites when it is partially covered by tiles relative to the camera view # 51.02-r1