Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 94 additions & 83 deletions Source/controls/plrctrls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,80 @@ Point FindClosestStashSlot(Point mousePos)
return bestSlot;
}

void LiftInventoryItem()
{
int inventorySlot = (Slot >= 0) ? Slot : FindClosestInventorySlot(MousePosition, MyPlayer->HoldItem);

int jumpSlot = inventorySlot; // If the cursor is over an inventory slot we may need to adjust it due to pasting items of different sizes over each other
if (inventorySlot >= SLOTXY_INV_FIRST && inventorySlot <= SLOTXY_INV_LAST) {
const Size cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? Size { 1, 1 } : GetInventorySize(MyPlayer->HoldItem);

// Find any item occupying a slot that is currently under the cursor
int8_t itemUnderCursor = [](int inventorySlot, Size cursorSizeInCells) {
if (inventorySlot < SLOTXY_INV_FIRST || inventorySlot > SLOTXY_INV_LAST)
return 0;
for (int x = 0; x < cursorSizeInCells.width; x++) {
for (int y = 0; y < cursorSizeInCells.height; y++) {
int slotUnderCursor = inventorySlot + x + y * INV_ROW_SLOT_SIZE;
if (slotUnderCursor > SLOTXY_INV_LAST)
continue;
int itemId = GetItemIdOnSlot(slotUnderCursor);
if (itemId != 0)
return itemId;
}
}
return 0;
}(inventorySlot, cursorSizeInCells);

// Capture the first slot of the first item (if any) under the cursor
if (itemUnderCursor > 0)
jumpSlot = FindFirstSlotOnItem(itemUnderCursor);
}
CheckInvItem();

if (inventorySlot >= SLOTXY_INV_FIRST && inventorySlot <= SLOTXY_INV_LAST) {
Point mousePos = GetSlotCoord(jumpSlot);
Slot = jumpSlot;
const Size newCursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? GetItemSizeOnSlot(jumpSlot) : GetInventorySize(MyPlayer->HoldItem);
mousePos.x += ((newCursorSizeInCells.width - 1) * InventorySlotSizeInPixels.width) / 2;
mousePos.y += ((newCursorSizeInCells.height - 1) * InventorySlotSizeInPixels.height) / 2;
SetCursorPos(mousePos);
}
}

void LiftStashItem()
{
Point stashSlot = (ActiveStashSlot != InvalidStashPoint) ? ActiveStashSlot : FindClosestStashSlot(MousePosition);

Size cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? Size { 1, 1 } : GetInventorySize(MyPlayer->HoldItem);

// Find any item occupying a slot that is currently under the cursor
StashStruct::StashCell itemUnderCursor = [](Point stashSlot, Size cursorSizeInCells) -> StashStruct::StashCell {
if (stashSlot == InvalidStashPoint)
return StashStruct::EmptyCell;
for (Point slotUnderCursor : PointsInRectangle(Rectangle { stashSlot, cursorSizeInCells })) {
if (slotUnderCursor.x >= 10 || slotUnderCursor.y >= 10)
continue;
StashStruct::StashCell itemId = Stash.GetItemIdAtPosition(slotUnderCursor);
if (itemId != StashStruct::EmptyCell)
return itemId;
}
return StashStruct::EmptyCell;
}(stashSlot, cursorSizeInCells);

Point jumpSlot = itemUnderCursor == StashStruct::EmptyCell ? stashSlot : FindFirstStashSlotOnItem(itemUnderCursor);
CheckStashItem(MousePosition);

Point mousePos = GetStashSlotCoord(jumpSlot);
ActiveStashSlot = jumpSlot;
// Center the Cursor based on the item we just put down or we're holding.
cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? GetItemSizeOnSlot(jumpSlot) : GetInventorySize(MyPlayer->HoldItem);
mousePos.x += ((cursorSizeInCells.width) * InventorySlotSizeInPixels.width) / 2;
mousePos.y += ((cursorSizeInCells.height) * InventorySlotSizeInPixels.height) / 2;

SetCursorPos(mousePos);
}

/**
* @brief Figures out where on the body to move when on the first row
*/
Expand Down Expand Up @@ -1415,6 +1489,9 @@ using HandleLeftStickOrDPadFn = void (*)(devilution::AxisDirection);

HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler()
{
if (SpellSelectFlag) {
return &HotSpellMove;
}
if (IsStashOpen) {
return &StashMove;
}
Expand All @@ -1424,15 +1501,12 @@ HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler()
if (CharFlag && MyPlayer->_pStatPts > 0) {
return &AttrIncBtnSnap;
}
if (SpellSelectFlag) {
return &HotSpellMove;
if (QuestLogIsOpen) {
return &QuestLogMove;
}
if (SpellbookFlag) {
return &SpellBookMove;
}
if (QuestLogIsOpen) {
return &QuestLogMove;
}
if (IsPlayerInStore()) {
return &StoreMove;
}
Expand Down Expand Up @@ -1685,7 +1759,8 @@ void ProcessGameAction(const GameAction &action)
PerformSecondaryAction();
break;
case GameActionType_CAST_SPELL:
PerformSpellAction();
if (!InGameMenu())
PerformSpellAction();
break;
case GameActionType_TOGGLE_QUICK_SPELL_MENU:
if (!invflag || BlurInventory()) {
Expand Down Expand Up @@ -1889,89 +1964,25 @@ void UseBeltItem(BeltItemType type)

void PerformPrimaryAction()
{
if (SpellSelectFlag) {
SetSpell();
return;
}

if (invflag) { // inventory is open
if (pcurs > CURSOR_HAND && pcurs < CURSOR_FIRSTITEM) {
if (pcurs == CURSOR_HOURGLASS)
return;
TryIconCurs();
NewCursor(CURSOR_HAND);
} else if (GetRightPanel().contains(MousePosition) || GetMainPanel().contains(MousePosition)) {
int inventorySlot = (Slot >= 0) ? Slot : FindClosestInventorySlot(MousePosition, MyPlayer->HoldItem);

int jumpSlot = inventorySlot; // If the cursor is over an inventory slot we may need to adjust it due to pasting items of different sizes over each other
if (inventorySlot >= SLOTXY_INV_FIRST && inventorySlot <= SLOTXY_INV_LAST) {
const Size cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? Size { 1, 1 } : GetInventorySize(MyPlayer->HoldItem);

// Find any item occupying a slot that is currently under the cursor
int8_t itemUnderCursor = [](int inventorySlot, Size cursorSizeInCells) {
if (inventorySlot < SLOTXY_INV_FIRST || inventorySlot > SLOTXY_INV_LAST)
return 0;
for (int x = 0; x < cursorSizeInCells.width; x++) {
for (int y = 0; y < cursorSizeInCells.height; y++) {
int slotUnderCursor = inventorySlot + x + y * INV_ROW_SLOT_SIZE;
if (slotUnderCursor > SLOTXY_INV_LAST)
continue;
int itemId = GetItemIdOnSlot(slotUnderCursor);
if (itemId != 0)
return itemId;
}
}
return 0;
}(inventorySlot, cursorSizeInCells);

// Capture the first slot of the first item (if any) under the cursor
if (itemUnderCursor > 0)
jumpSlot = FindFirstSlotOnItem(itemUnderCursor);
}
CheckInvItem();

if (inventorySlot >= SLOTXY_INV_FIRST && inventorySlot <= SLOTXY_INV_LAST) {
Point mousePos = GetSlotCoord(jumpSlot);
Slot = jumpSlot;
const Size newCursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? GetItemSizeOnSlot(jumpSlot) : GetInventorySize(MyPlayer->HoldItem);
mousePos.x += ((newCursorSizeInCells.width - 1) * InventorySlotSizeInPixels.width) / 2;
mousePos.y += ((newCursorSizeInCells.height - 1) * InventorySlotSizeInPixels.height) / 2;
SetCursorPos(mousePos);
}
LiftInventoryItem();
} else if (IsStashOpen && GetLeftPanel().contains(MousePosition)) {
Point stashSlot = (ActiveStashSlot != InvalidStashPoint) ? ActiveStashSlot : FindClosestStashSlot(MousePosition);

Size cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? Size { 1, 1 } : GetInventorySize(MyPlayer->HoldItem);

// Find any item occupying a slot that is currently under the cursor
StashStruct::StashCell itemUnderCursor = [](Point stashSlot, Size cursorSizeInCells) -> StashStruct::StashCell {
if (stashSlot == InvalidStashPoint)
return StashStruct::EmptyCell;
for (Point slotUnderCursor : PointsInRectangle(Rectangle { stashSlot, cursorSizeInCells })) {
if (slotUnderCursor.x >= 10 || slotUnderCursor.y >= 10)
continue;
StashStruct::StashCell itemId = Stash.GetItemIdAtPosition(slotUnderCursor);
if (itemId != StashStruct::EmptyCell)
return itemId;
}
return StashStruct::EmptyCell;
}(stashSlot, cursorSizeInCells);

Point jumpSlot = itemUnderCursor == StashStruct::EmptyCell ? stashSlot : FindFirstStashSlotOnItem(itemUnderCursor);
CheckStashItem(MousePosition);

Point mousePos = GetStashSlotCoord(jumpSlot);
ActiveStashSlot = jumpSlot;
// Center the Cursor based on the item we just put down or we're holding.
cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? GetItemSizeOnSlot(jumpSlot) : GetInventorySize(MyPlayer->HoldItem);
mousePos.x += ((cursorSizeInCells.width) * InventorySlotSizeInPixels.width) / 2;
mousePos.y += ((cursorSizeInCells.height) * InventorySlotSizeInPixels.height) / 2;

SetCursorPos(mousePos);
LiftStashItem();
}
return;
}

if (SpellSelectFlag) {
SetSpell();
return;
}

if (CharFlag && !CharPanelButtonActive && MyPlayer->_pStatPts > 0) {
CheckChrBtns();
if (CharPanelButtonActive)
Expand Down Expand Up @@ -2048,7 +2059,12 @@ bool TryDropItem()

void PerformSpellAction()
{
if (InGameMenu() || QuestLogIsOpen || SpellbookFlag)
if (SpellSelectFlag) {
SetSpell();
return;
}

if (QuestLogIsOpen)
return;

if (invflag) {
Expand All @@ -2073,11 +2089,6 @@ void PerformSpellAction()
if (pcurs > CURSOR_HAND)
NewCursor(CURSOR_HAND);

if (SpellSelectFlag) {
SetSpell();
return;
}

const Player &myPlayer = *MyPlayer;
SpellID spl = myPlayer._pRSpell;
if ((PlayerUnderCursor == nullptr && (spl == SpellID::Resurrect || spl == SpellID::HealOther))
Expand Down
16 changes: 9 additions & 7 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,7 @@ void InitPadmapActions()
QuickCast(i);
},
nullptr,
CanPlayerTakeAction,
[]() { return CanPlayerTakeAction() && !InGameMenu(); },
i + 1);
}
options.Padmapper.AddAction(
Expand Down Expand Up @@ -2091,7 +2091,7 @@ void InitPadmapActions()
ControllerActionHeld = GameActionType_NONE;
LastMouseButtonAction = MouseActionType::None;
},
CanPlayerTakeAction);
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"CancelAction",
N_("Cancel action"),
Expand Down Expand Up @@ -2179,7 +2179,9 @@ void InitPadmapActions()
ControllerButton_AXIS_TRIGGERLEFT,
[] {
ProcessGameAction(GameAction { GameActionType_TOGGLE_CHARACTER_INFO });
});
},
nullptr,
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"Inventory",
N_("Inventory"),
Expand All @@ -2189,7 +2191,7 @@ void InitPadmapActions()
ProcessGameAction(GameAction { GameActionType_TOGGLE_INVENTORY });
},
nullptr,
CanPlayerTakeAction);
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"QuestLog",
N_("Quest log"),
Expand All @@ -2199,7 +2201,7 @@ void InitPadmapActions()
ProcessGameAction(GameAction { GameActionType_TOGGLE_QUEST_LOG });
},
nullptr,
CanPlayerTakeAction);
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"SpellBook",
N_("Spellbook"),
Expand All @@ -2209,7 +2211,7 @@ void InitPadmapActions()
ProcessGameAction(GameAction { GameActionType_TOGGLE_SPELL_BOOK });
},
nullptr,
CanPlayerTakeAction);
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"DisplaySpells",
N_("Speedbook"),
Expand All @@ -2219,7 +2221,7 @@ void InitPadmapActions()
ProcessGameAction(GameAction { GameActionType_TOGGLE_QUICK_SPELL_MENU });
},
nullptr,
CanPlayerTakeAction);
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"Toggle Automap",
N_("Toggle automap"),
Expand Down