Browse Source

Correct mouse interactions for game controller

pull/420/head
Anders Jenbo 6 years ago
parent
commit
dbc91ae036
  1. 4
      Source/control.cpp
  2. 1
      SourceS/miniwin/misc.h
  3. 20
      SourceX/controls/plrctrls.cpp
  4. 19
      SourceX/miniwin/misc_msg.cpp

4
Source/control.cpp

@ -1158,7 +1158,7 @@ void DrawInfoBox()
} else {
if (pcursitem != -1)
GetItemStr(pcursitem);
if (pcursobj != -1)
else if (pcursobj != -1)
GetObjectStr(pcursobj);
if (pcursmonst != -1) {
if (leveltype != DTYPE_TOWN) {
@ -1171,7 +1171,7 @@ void DrawInfoBox()
} else {
PrintMonstHistory(monster[pcursmonst].MType->mtype);
}
} else {
} else if (pcursitem == -1) {
strcpy(infostr, towner[pcursmonst]._tName);
}
}

1
SourceS/miniwin/misc.h

@ -513,6 +513,7 @@ constexpr auto DVL_WM_PAINT = 0x000F;
constexpr auto DVL_WM_CLOSE = 0x0010;
constexpr auto DVL_WM_QUERYENDSESSION = 0x0011;
constexpr auto DVL_WM_ERASEBKGND = 0x0014;
constexpr auto DVL_WM_MOUSEHOVER = 0x02A1;
constexpr auto DVL_WM_QUERYNEWPALETTE = 0x030F;
constexpr auto DVL_WM_PALETTECHANGED = 0x0311;

20
SourceX/controls/plrctrls.cpp

@ -503,21 +503,21 @@ void plrctrls_after_check_curs_move()
// check for monsters first, then items, then towners.
if (sgbControllerActive) {
// Clear focuse set by cursor
if (!invflag) {
*infostr = '\0';
ClearPanel();
}
pcursplr = -1;
pcursmonst = -1;
pcursitem = -1;
pcursobj = -1;
if (!invflag) {
*infostr = '\0';
ClearPanel();
// TODO target players if !FriendlyMode
if (leveltype != DTYPE_TOWN)
CheckMonstersNearby();
else
CheckTownersNearby();
CheckItemsNearby();
// TODO target players if !FriendlyMode
if (leveltype != DTYPE_TOWN)
CheckMonstersNearby();
else
CheckTownersNearby();
CheckItemsNearby();
}
}
}

19
SourceX/miniwin/misc_msg.cpp

@ -19,9 +19,14 @@ namespace dvl {
static std::deque<MSG> message_queue;
bool mouseWarping = false;
int mouseWarpingX;
int mouseWarpingY;
void SetCursorPos(int X, int Y)
{
mouseWarpingX = X;
mouseWarpingY = Y;
#ifndef USE_SDL1
if (renderer) {
SDL_Rect view;
@ -37,7 +42,7 @@ void SetCursorPos(int X, int Y)
#endif
mouseWarping = true;
SDL_WarpMouseInWindow(nullptr, X, Y);
SDL_WarpMouseInWindow(window, X, Y);
}
// Moves the mouse to the first attribute "+" button.
@ -293,8 +298,6 @@ void SetMouseLMBMessage(const SDL_Event &event, LPMSG lpMsg)
// Moves the mouse to the first inventory slot.
void FocusOnInventory()
{
if (!invflag)
return;
SetCursorPos(InvRect[25].X + (INV_SLOT_SIZE_PX / 2), InvRect[25].Y - (INV_SLOT_SIZE_PX / 2));
}
@ -551,6 +554,16 @@ WINBOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilter
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_CLOSE) {
lpMsg->message = DVL_WM_QUERYENDSESSION;
} else if (e.window.event == SDL_WINDOWEVENT_ENTER) {
lpMsg->message = DVL_WM_MOUSEHOVER;
// Bug in SDL, SDL_WarpMouseInWindow doesn't emit SDL_MOUSEMOTION
// and SDL_GetMouseState gives previous location if mouse was
// outside window (observed on Ubuntu 19.04)
if (mouseWarping) {
MouseX = mouseWarpingX;
MouseY = mouseWarpingY;
mouseWarping = false;
}
} else {
return false_avail();
}

Loading…
Cancel
Save