Browse Source

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.
pull/4484/head
ephphatha 4 years ago committed by Anders Jenbo
parent
commit
026b428c7d
  1. 2
      Source/control.cpp
  2. 9
      Source/cursor.cpp
  3. 8
      Source/cursor.h
  4. 8
      Source/inv.cpp
  5. 2
      Source/qol/stash.cpp

2
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;

9
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) {

8
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();

8
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)

2
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);

Loading…
Cancel
Save