Browse Source

More consistent gamepad context sensitivity

pull/7852/head
staphen 1 year ago committed by Anders Jenbo
parent
commit
5855b3149e
  1. 177
      Source/controls/plrctrls.cpp
  2. 16
      Source/diablo.cpp

177
Source/controls/plrctrls.cpp

@ -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
*/
@ -1415,6 +1489,9 @@ using HandleLeftStickOrDPadFn = void (*)(devilution::AxisDirection);
HandleLeftStickOrDPadFn GetLeftStickOrDPadGameUIHandler()
{
if (SpellSelectFlag) {
return &HotSpellMove;
}
if (IsStashOpen) {
return &StashMove;
}
@ -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;
}
@ -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()) {
@ -1889,6 +1964,11 @@ 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)
@ -1896,82 +1976,13 @@ void PerformPrimaryAction()
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)
@ -2048,7 +2059,12 @@ bool TryDropItem()
void PerformSpellAction()
{
if (InGameMenu() || QuestLogIsOpen || SpellbookFlag)
if (SpellSelectFlag) {
SetSpell();
return;
}
if (QuestLogIsOpen)
return;
if (invflag) {
@ -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))

16
Source/diablo.cpp

@ -2044,7 +2044,7 @@ void InitPadmapActions()
QuickCast(i);
},
nullptr,
CanPlayerTakeAction,
[]() { return CanPlayerTakeAction() && !InGameMenu(); },
i + 1);
}
options.Padmapper.AddAction(
@ -2091,7 +2091,7 @@ void InitPadmapActions()
ControllerActionHeld = GameActionType_NONE;
LastMouseButtonAction = MouseActionType::None;
},
CanPlayerTakeAction);
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"CancelAction",
N_("Cancel action"),
@ -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"),
@ -2189,7 +2191,7 @@ void InitPadmapActions()
ProcessGameAction(GameAction { GameActionType_TOGGLE_INVENTORY });
},
nullptr,
CanPlayerTakeAction);
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"QuestLog",
N_("Quest log"),
@ -2199,7 +2201,7 @@ void InitPadmapActions()
ProcessGameAction(GameAction { GameActionType_TOGGLE_QUEST_LOG });
},
nullptr,
CanPlayerTakeAction);
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"SpellBook",
N_("Spellbook"),
@ -2209,7 +2211,7 @@ void InitPadmapActions()
ProcessGameAction(GameAction { GameActionType_TOGGLE_SPELL_BOOK });
},
nullptr,
CanPlayerTakeAction);
[]() { return CanPlayerTakeAction() && !InGameMenu(); });
options.Padmapper.AddAction(
"DisplaySpells",
N_("Speedbook"),
@ -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"),

Loading…
Cancel
Save