From c86cec3c5ff2972f07edf7e3dfe0dbe1d3747524 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Wed, 6 Nov 2019 00:06:30 +0100 Subject: [PATCH] Prioritize controller navigation Only do one type of navigation at any one time. Priority: Inventry, Stats, Spells, Walk. --- Source/player.cpp | 3 ++ SourceS/miniwin/misc.h | 1 + SourceX/miniwin/misc_msg.cpp | 101 ++++++++++++++++++----------------- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/Source/player.cpp b/Source/player.cpp index 8bda76c58..8e84cd233 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -748,6 +748,9 @@ void NextPlrLevel(int pnum) if (pnum == myplr) { drawmanaflag = TRUE; } + + if (sgbControllerActive) + FocusOnCharInfo(); } void AddPlrExperience(int pnum, int lvl, int exp) diff --git a/SourceS/miniwin/misc.h b/SourceS/miniwin/misc.h index e75d45344..7a1c8c7ef 100644 --- a/SourceS/miniwin/misc.h +++ b/SourceS/miniwin/misc.h @@ -191,6 +191,7 @@ void ResetEvent(HANDLE hEvent); int WINAPI WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds); void SetCursorPos(int X, int Y); +void FocusOnCharInfo(); SHORT WINAPI GetAsyncKeyState(int vKey); diff --git a/SourceX/miniwin/misc_msg.cpp b/SourceX/miniwin/misc_msg.cpp index 109e834e4..30dc53ce0 100644 --- a/SourceX/miniwin/misc_msg.cpp +++ b/SourceX/miniwin/misc_msg.cpp @@ -40,6 +40,44 @@ void SetCursorPos(int X, int Y) SDL_WarpMouseInWindow(nullptr, X, Y); } +// Moves the mouse to the first attribute "+" button. +void FocusOnCharInfo() +{ + if (!chrflag || plr[myplr]._pStatPts <= 0) + return; + + // Find the first incrementable stat. + int pc = plr[myplr]._pClass; + int stat = -1; + for (int i = 4; i >= 0; --i) { + switch (i) { + case ATTRIB_STR: + if (plr[myplr]._pBaseStr >= MaxStats[pc][ATTRIB_STR]) + continue; + break; + case ATTRIB_MAG: + if (plr[myplr]._pBaseMag >= MaxStats[pc][ATTRIB_MAG]) + continue; + break; + case ATTRIB_DEX: + if (plr[myplr]._pBaseDex >= MaxStats[pc][ATTRIB_DEX]) + continue; + break; + case ATTRIB_VIT: + if (plr[myplr]._pBaseVit >= MaxStats[pc][ATTRIB_VIT]) + continue; + break; + default: + continue; + } + stat = i; + } + if (stat == -1) + return; + const auto &rect = ChrBtnsRect[stat]; + SetCursorPos(rect.x + (rect.w / 2), rect.y + (rect.h / 2)); +} + static int translate_sdl_key(SDL_Keysym key) { // ref: https://wiki.libsdl.org/SDL_Keycode @@ -260,44 +298,6 @@ void FocusOnInventory() SetCursorPos(InvRect[25].X + (INV_SLOT_SIZE_PX / 2), InvRect[25].Y - (INV_SLOT_SIZE_PX / 2)); } -// Moves the mouse to the first attribute "+" button. -void FocusOnCharInfo() -{ - if (!chrflag || plr[myplr]._pStatPts == 0) - return; - - // Find the first incrementable stat. - int pc = plr[myplr]._pClass; - int stat = -1; - for (int i = 4; i >= 0; --i) { - switch (i) { - case ATTRIB_STR: - if (plr[myplr]._pBaseStr >= MaxStats[pc][ATTRIB_STR]) - continue; - break; - case ATTRIB_MAG: - if (plr[myplr]._pBaseMag >= MaxStats[pc][ATTRIB_MAG]) - continue; - break; - case ATTRIB_DEX: - if (plr[myplr]._pBaseDex >= MaxStats[pc][ATTRIB_DEX]) - continue; - break; - case ATTRIB_VIT: - if (plr[myplr]._pBaseVit >= MaxStats[pc][ATTRIB_VIT]) - continue; - break; - default: - continue; - } - stat = i; - } - if (stat == -1) - return; - const auto &rect = ChrBtnsRect[stat]; - SetCursorPos(rect.x + (rect.w / 2), rect.y + (rect.h / 2)); -} - void StoreSpellCoords() { constexpr int START_X = 20; @@ -443,26 +443,29 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter case GameActionType::TOGGLE_QUICK_SPELL_MENU: lpMsg->message = DVL_WM_KEYDOWN; lpMsg->wParam = 'S'; + chrflag = false; + questlog = false; + invflag = false; + sbookflag = false; StoreSpellCoords(); break; case GameActionType::TOGGLE_CHARACTER_INFO: - questlog = false; chrflag = !chrflag; - if (chrflag) + if (chrflag) { + questlog = false; + spselflag = false; FocusOnCharInfo(); - else - FocusOnInventory(); + } break; case GameActionType::TOGGLE_INVENTORY: - if (pcurs >= CURSOR_FIRSTITEM && invflag) - // Drop item so that it does not get destroyed. - DropItemBeforeTrig(); - sbookflag = false; invflag = !invflag; - if (invflag) + if (invflag) { + sbookflag = false; + spselflag = false; FocusOnInventory(); - else - FocusOnCharInfo(); + } else { + BlurInventory(); + } break; case GameActionType::SEND_KEY: lpMsg->message = action.send_key.up ? DVL_WM_KEYUP : DVL_WM_KEYDOWN;