-
Notifications
You must be signed in to change notification settings - Fork 56
Occlude the cursor when covered by tiles #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
realSquidCoder
wants to merge
6
commits into
DFHack:master
Choose a base branch
from
SquidCoderIndustries:squid-cursor-occlusion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f428234
DRY-ed the cursor drawing to use a common function
realSquidCoder 75f7e97
Removed needsCorrection and cleaned things up
realSquidCoder 5c5b2b0
Pass a reference, not a copy (hopefully)
realSquidCoder 44c5bf6
Merge branch 'master' into squid-DRY-cursor
realSquidCoder c6ca1ea
Add cursor occlusion when blocked by tiles
realSquidCoder 1714127
Update changelog.txt
realSquidCoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,50 +484,49 @@ void DrawCurrentLevelOutline(bool backPart) | |
|
||
namespace | ||
{ | ||
void drawSelectionCursor(WorldSegment* segment) | ||
void drawCursorAt(WorldSegment* segment, Crd3D& cursor, const ALLEGRO_COLOR& color) | ||
{ | ||
auto& ssConfig = stonesenseState.ssConfig; | ||
std::array<dirRelative, 8> directions = { eUpLeft, eUp, eUpRight, eRight, eDownRight, eDown, eDownLeft, eLeft }; | ||
std::array<Tile*, 8> dirs = {}; | ||
|
||
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); | ||
for (unsigned int i = 0; i < directions.size(); i++) { | ||
dirs[i] = segment->getTileRelativeTo(cursor.x, cursor.y, cursor.z, directions[i]); | ||
} | ||
else { | ||
return; | ||
|
||
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]) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The checks on |
||
shape == df::tiletype_shape_basic::Ramp || | ||
shape == df::tiletype_shape_basic::Wall) { | ||
occludeCursor = true; | ||
} | ||
} | ||
Crd2D point = LocalTileToScreen(selection.x, selection.y, selection.z); | ||
int sheetx = SPRITEOBJECT_CURSOR % SHEET_OBJECTSWIDE; | ||
int sheety = SPRITEOBJECT_CURSOR / SHEET_OBJECTSWIDE; | ||
al_draw_tinted_scaled_bitmap( | ||
stonesenseState.IMGObjectSheet, | ||
uiColor(3), | ||
sheetx * SPRITEWIDTH, | ||
sheety * SPRITEHEIGHT, | ||
SPRITEWIDTH, | ||
SPRITEHEIGHT, | ||
point.x - ((SPRITEWIDTH / 2) * ssConfig.scale), | ||
point.y - (WALLHEIGHT)*ssConfig.scale, | ||
SPRITEWIDTH * ssConfig.scale, | ||
SPRITEHEIGHT * ssConfig.scale, | ||
0); | ||
} | ||
|
||
void drawDebugCursor(WorldSegment* segment) | ||
{ | ||
auto& ssConfig = stonesenseState.ssConfig; | ||
|
||
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; | ||
int spriteIDX = (occludeCursor ? SPRITEOBJECT_CURSOROCCLUDE : SPRITEOBJECT_CURSOR); | ||
int sheetx = spriteIDX % SHEET_OBJECTSWIDE; | ||
int sheety = spriteIDX / SHEET_OBJECTSWIDE; | ||
al_draw_tinted_scaled_bitmap( | ||
stonesenseState.IMGObjectSheet, | ||
uiColor(2), | ||
color, | ||
sheetx * SPRITEWIDTH, | ||
sheety * SPRITEHEIGHT, | ||
SPRITEWIDTH, | ||
|
@@ -539,6 +538,25 @@ namespace | |
0); | ||
} | ||
|
||
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)) { | ||
drawCursorAt(segment, selection, uiColor(3)); | ||
} | ||
else { | ||
return; | ||
} | ||
} | ||
|
||
void drawDebugCursor(WorldSegment* segment) | ||
{ | ||
Crd3D& cursor = segment->segState.dfCursor; | ||
drawCursorAt(segment, cursor, uiColor(2)); | ||
} | ||
|
||
void drawAdvmodeMenuTalk(const ALLEGRO_FONT* font, int x, int y) | ||
{ | ||
//df::adventure * menu = df::global::adventure; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend against using a copy of the
dirs
array used in SegmentProcessing, as it stores more directions than needed as well as being specialized for border calculations. Instead I would recommend an implementation similar to the following: