From 026b428c7dc079b241b321e8443fb95c7ea844ed Mon Sep 17 00:00:00 2001 From: ephphatha Date: Sun, 17 Apr 2022 21:47:23 +1000 Subject: [PATCH] Add NewCursor(Item&) for setting the cursor based on a held item The case for empty items should never be hit in the current code, but I've got a related PR that'll make use of that so adding it now. --- Source/control.cpp | 2 +- Source/cursor.cpp | 9 +++++++++ Source/cursor.h | 8 ++++++++ Source/inv.cpp | 8 ++------ Source/qol/stash.cpp | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 26270d4de..1901d088a 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -372,7 +372,7 @@ void RemoveGold(Player &player, int goldIndex) player.RemoveInvItem(gi); MakeGoldStack(player.HoldItem, dropGoldValue); - NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); + NewCursor(player.HoldItem); player._pGold = CalculateGold(player); dropGoldValue = 0; diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 6853c58c5..4caa8b13c 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -165,6 +165,15 @@ void ResetCursor() NewCursor(pcurs); } +void NewCursor(const Item &item) +{ + if (item.isEmpty()) { + NewCursor(CURSOR_HAND); + } else { + NewCursor(item._iCurs + CURSOR_FIRSTITEM); + } +} + void NewCursor(int cursId) { if (cursId < CURSOR_HOURGLASS && MyPlayer != nullptr) { diff --git a/Source/cursor.h b/Source/cursor.h index 4520b45ea..6b810d8a6 100644 --- a/Source/cursor.h +++ b/Source/cursor.h @@ -44,7 +44,15 @@ extern DVL_API_FOR_TEST int pcurs; void InitCursor(); void FreeCursor(); void ResetCursor(); + +struct Item; +/** + * @brief Use the item sprite as the cursor (or show the default hand cursor if the item isEmpty) + */ +void NewCursor(const Item &item); + void NewCursor(int cursId); + void InitLevelCursor(); void CheckRportal(); void CheckTown(); diff --git a/Source/inv.cpp b/Source/inv.cpp index ad6d99b72..53fc8d515 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -475,12 +475,8 @@ void CheckInvPaste(int pnum, Point cursorPosition) player.HoldItem = player.InvBody[INVLOC_HAND_RIGHT]; else player.HoldItem = player.InvBody[INVLOC_HAND_LEFT]; - if (pnum == MyPlayerId) - NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); bool done2h = AutoPlaceItemInInventory(player, player.HoldItem, true); player.HoldItem = tempitem; - if (pnum == MyPlayerId) - NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); if (!done2h) return; @@ -853,7 +849,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove, bool dropIt holdItem._itype = ItemType::None; } else { - NewCursor(holdItem._iCurs + CURSOR_FIRSTITEM); + NewCursor(holdItem); if (!IsHardwareCursor() && !dropItem) { // For a hardware cursor, we set the "hot point" to the center of the item instead. Size cursSize = GetInvItemSize(holdItem._iCurs + CURSOR_FIRSTITEM); @@ -1641,7 +1637,7 @@ void InvGetItem(int pnum, int ii) CleanupItems(ii); pcursitem = -1; if (!player.HoldItem.isEmpty()) - NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); + NewCursor(player.HoldItem); } void AutoGetItem(int pnum, Item *itemPointer, int ii) diff --git a/Source/qol/stash.cpp b/Source/qol/stash.cpp index 734a3f781..915033f71 100644 --- a/Source/qol/stash.cpp +++ b/Source/qol/stash.cpp @@ -222,7 +222,7 @@ void CheckStashCut(Point cursorPosition, bool automaticMove) holdItem._itype = ItemType::None; } else { - NewCursor(holdItem._iCurs + CURSOR_FIRSTITEM); + NewCursor(holdItem); if (!IsHardwareCursor()) { // For a hardware cursor, we set the "hot point" to the center of the item instead. Size cursSize = GetInvItemSize(holdItem._iCurs + CURSOR_FIRSTITEM);