[controller] Only close inventory if cursor is clean

This commit is contained in:
Anders Jenbo committed 2019-12-18 23:07:42 +01:00
1 parent f313b66a34
commit 9d4bb70913
3 files changed
+49 -22

No files matched your search

+15 -7
View File
@@ -930,18 +930,26 @@ void UpdateSpellTarget()
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()
{
if (invflag) {
int spl = plr[myplr]._pRSpell;
if (pcurs >= CURSOR_FIRSTITEM) {
cursmx = plr[myplr].WorldX;
cursmy = plr[myplr].WorldY;
if (!DropItemBeforeTrig()) {
cursmx--; // Try to drop on the other side
cursmy++;
DropItemBeforeTrig();
}
TryDropItem();
return;
}
if (spl != SPL_IDENTIFY && spl != SPL_REPAIR && spl != SPL_RECHARGE)
+1
View File
@@ -31,6 +31,7 @@ void PerformPrimaryAction();
// Open chests, doors, pickup items.
void PerformSecondaryAction();
void TryDropItem();
void PerformSpellAction();
typedef struct coords {
+33 -15
View File
@@ -319,16 +319,33 @@ void StoreSpellCoords()
} // 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
DropItemBeforeTrig();
if (pcurs >= CURSOR_FIRSTITEM) {
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)
SetCursor_(CURSOR_HAND);
if (chrflag)
FocusOnCharInfo();
return true;
}
WINBOOL PeekMessageA(LPMSG lpMsg)
@@ -411,14 +428,15 @@ WINBOOL PeekMessageA(LPMSG lpMsg)
PerformSpellAction();
break;
case GameActionType::TOGGLE_QUICK_SPELL_MENU:
lpMsg->message = DVL_WM_KEYDOWN;
lpMsg->wParam = 'S';
chrflag = false;
questlog = false;
invflag = false;
BlurInventory();
sbookflag = false;
StoreSpellCoords();
if (BlurInventory()) {
lpMsg->message = DVL_WM_KEYDOWN;
lpMsg->wParam = 'S';
chrflag = false;
questlog = false;
invflag = false;
sbookflag = false;
StoreSpellCoords();
}
break;
case GameActionType::TOGGLE_CHARACTER_INFO:
chrflag = !chrflag;
@@ -429,13 +447,13 @@ WINBOOL PeekMessageA(LPMSG lpMsg)
}
break;
case GameActionType::TOGGLE_INVENTORY:
invflag = !invflag;
if (invflag) {
invflag = !BlurInventory();
} else {
sbookflag = false;
spselflag = false;
invflag = true;
FocusOnInventory();
} else {
BlurInventory();
}
break;
case GameActionType::SEND_KEY: