Browse Source

[controller] Only close inventory if cursor is clean

pull/513/head
Anders Jenbo 6 years ago
parent
commit
9d4bb70913
  1. 22
      SourceX/controls/plrctrls.cpp
  2. 1
      SourceX/controls/plrctrls.h
  3. 48
      SourceX/miniwin/misc_msg.cpp

22
SourceX/controls/plrctrls.cpp

@ -930,18 +930,26 @@ void UpdateSpellTarget()
cursmy = player._py + kOffsets[player._pdir][1]; cursmy = player._py + kOffsets[player._pdir][1];
} }
/**
* @brief Try dropping item in all 9 possible places
*/
void TryDropItem()
{
cursmx = plr[myplr].WorldX;
cursmy = plr[myplr].WorldY;
if (!DropItemBeforeTrig()) {
cursmx--; // Try to drop on the other side
cursmy++;
DropItemBeforeTrig();
}
}
void PerformSpellAction() void PerformSpellAction()
{ {
if (invflag) { if (invflag) {
int spl = plr[myplr]._pRSpell; int spl = plr[myplr]._pRSpell;
if (pcurs >= CURSOR_FIRSTITEM) { if (pcurs >= CURSOR_FIRSTITEM) {
cursmx = plr[myplr].WorldX; TryDropItem();
cursmy = plr[myplr].WorldY;
if (!DropItemBeforeTrig()) {
cursmx--; // Try to drop on the other side
cursmy++;
DropItemBeforeTrig();
}
return; return;
} }
if (spl != SPL_IDENTIFY && spl != SPL_REPAIR && spl != SPL_RECHARGE) if (spl != SPL_IDENTIFY && spl != SPL_REPAIR && spl != SPL_RECHARGE)

1
SourceX/controls/plrctrls.h

@ -31,6 +31,7 @@ void PerformPrimaryAction();
// Open chests, doors, pickup items. // Open chests, doors, pickup items.
void PerformSecondaryAction(); void PerformSecondaryAction();
void TryDropItem();
void PerformSpellAction(); void PerformSpellAction();
typedef struct coords { typedef struct coords {

48
SourceX/miniwin/misc_msg.cpp

@ -319,16 +319,33 @@ void StoreSpellCoords()
} // namespace } // namespace
/** /**
* @brief Clean the inventory related cursor states. * @brief Try to clean the inventory related cursor states.
* @return True if it is safe to close the inventory
*/ */
void BlurInventory() bool BlurInventory()
{ {
if (pcurs >= CURSOR_FIRSTITEM) // drop item to allow us to pick up other items if (pcurs >= CURSOR_FIRSTITEM) {
DropItemBeforeTrig(); TryDropItem();
if (pcurs >= CURSOR_FIRSTITEM) {
if (plr[myplr]._pClass == PC_WARRIOR) {
PlaySFX(PS_WARR16); // "Where would I put this?"
#ifndef SPAWN
} else if (plr[myplr]._pClass == PC_ROGUE) {
PlaySFX(PS_ROGUE16);
} else if (plr[myplr]._pClass == PC_SORCERER) {
PlaySFX(PS_MAGE16);
#endif
}
return false;
}
}
if (pcurs == CURSOR_REPAIR || pcurs == CURSOR_RECHARGE) if (pcurs == CURSOR_REPAIR || pcurs == CURSOR_RECHARGE)
SetCursor_(CURSOR_HAND); SetCursor_(CURSOR_HAND);
if (chrflag) if (chrflag)
FocusOnCharInfo(); FocusOnCharInfo();
return true;
} }
WINBOOL PeekMessageA(LPMSG lpMsg) WINBOOL PeekMessageA(LPMSG lpMsg)
@ -411,14 +428,15 @@ WINBOOL PeekMessageA(LPMSG lpMsg)
PerformSpellAction(); PerformSpellAction();
break; break;
case GameActionType::TOGGLE_QUICK_SPELL_MENU: case GameActionType::TOGGLE_QUICK_SPELL_MENU:
lpMsg->message = DVL_WM_KEYDOWN; if (BlurInventory()) {
lpMsg->wParam = 'S'; lpMsg->message = DVL_WM_KEYDOWN;
chrflag = false; lpMsg->wParam = 'S';
questlog = false; chrflag = false;
invflag = false; questlog = false;
BlurInventory(); invflag = false;
sbookflag = false; sbookflag = false;
StoreSpellCoords(); StoreSpellCoords();
}
break; break;
case GameActionType::TOGGLE_CHARACTER_INFO: case GameActionType::TOGGLE_CHARACTER_INFO:
chrflag = !chrflag; chrflag = !chrflag;
@ -429,13 +447,13 @@ WINBOOL PeekMessageA(LPMSG lpMsg)
} }
break; break;
case GameActionType::TOGGLE_INVENTORY: case GameActionType::TOGGLE_INVENTORY:
invflag = !invflag;
if (invflag) { if (invflag) {
invflag = !BlurInventory();
} else {
sbookflag = false; sbookflag = false;
spselflag = false; spselflag = false;
invflag = true;
FocusOnInventory(); FocusOnInventory();
} else {
BlurInventory();
} }
break; break;
case GameActionType::SEND_KEY: case GameActionType::SEND_KEY:

Loading…
Cancel
Save