From db425a12289f94cb8ee8cf9b20d61e400f024517 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 5 Dec 2019 21:39:02 +0100 Subject: [PATCH] - fixed keybinding and mouse cursor display. - fixed some merge issues in Shadow Warrior. --- source/build/include/baselayer.h | 2 +- source/build/src/sdlayer.cpp | 23 +++++++++-------------- source/common/console/c_console.cpp | 6 ++++-- source/common/menu/menu.cpp | 6 ++++-- source/common/menu/optionmenuitems.h | 5 ++++- source/sw/src/draw.cpp | 2 +- source/sw/src/menus.h | 1 - source/sw/src/panel.cpp | 3 +-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index af8c402ce..c3a878b33 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -145,7 +145,7 @@ void joyScanDevices(void); void mouseInit(void); void mouseUninit(void); void mouseGrabInput(bool grab); -void mouseLockToWindow(char a); +void mouseLockToWindow(bool a); void mouseMoveToCenter(void); void joyReadButtons(int32_t *pResult); diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 84d0badb0..89cef255a 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -33,10 +33,14 @@ #include "i_time.h" #include "c_dispatch.h" #include "d_gui.h" +#include "menu.h" #include "utf8.h" #include "imgui.h" #include "imgui_impl_sdl.h" #include "imgui_impl_opengl3.h" + + + #ifndef NETCODE_DISABLE #include "enet.h" #endif @@ -960,18 +964,9 @@ void mouseGrabInput(bool grab) g_mouseGrabbed = grab; inputState.MouseSetPos(0, 0); -} - -void mouseLockToWindow(char a) -{ - if (!(a & 2)) - { - mouseGrabInput(a); - g_mouseLockedToWindow = g_mouseGrabbed; - } - - // Fixme - SDL_ShowCursor(GUICapture ? SDL_ENABLE : SDL_DISABLE); + SDL_ShowCursor(!grab ? SDL_ENABLE : SDL_DISABLE); + if (grab) GUICapture &= ~1; + else GUICapture |= 1; } // @@ -1891,7 +1886,7 @@ int32_t handleevents_pollsdl(void) { code = ev.text.text[j]; // Fixme: Send an EV_GUI_Event instead and properly deal with Unicode. - if (GUICapture & 1) + if ((GUICapture & 1) && menuactive != MENU_WaitKey) { event_t ev = { EV_GUI_Event, EV_GUI_Char, int16_t(j), !!(SDL_GetModState() & KMOD_ALT) }; D_PostEvent(&ev); @@ -1903,7 +1898,7 @@ int32_t handleevents_pollsdl(void) case SDL_KEYDOWN: case SDL_KEYUP: { - if (GUICapture & 1) + if ((GUICapture & 1) && menuactive != MENU_WaitKey) { event_t event = {}; event.type = EV_GUI_Event; diff --git a/source/common/console/c_console.cpp b/source/common/console/c_console.cpp index b9fba6b15..aaeff2b06 100644 --- a/source/common/console/c_console.cpp +++ b/source/common/console/c_console.cpp @@ -55,6 +55,7 @@ #include "inputstate.h" #include "i_time.h" #include "gamecvars.h" +#include "baselayer.h" #define LEFTMARGIN 8 @@ -1317,13 +1318,14 @@ void C_ToggleConsole () HistPos = NULL; TabbedLast = false; TabbedList = false; - GUICapture |= 1; + mouseGrabInput(false); + } else //if (gamestate != GS_FULLCONSOLE && gamestate != GS_STARTUP) { ConsoleState = c_rising; C_FlushDisplay (); - GUICapture &= ~1; + mouseGrabInput(true); } } diff --git a/source/common/menu/menu.cpp b/source/common/menu/menu.cpp index e2b6994cc..a001ea575 100644 --- a/source/common/menu/menu.cpp +++ b/source/common/menu/menu.cpp @@ -51,6 +51,7 @@ #include "fx_man.h" #include "pragmas.h" #include "build.h" +#include "baselayer.h" void RegisterDukeMenus(); void RegisterRedneckMenus(); @@ -372,7 +373,7 @@ void M_StartControlPanel (bool makeSound) } C_HideConsole (); // [RH] Make sure console goes bye bye. - GUICapture |= 1; + mouseGrabInput(false); menuactive = MENU_On; // Pause sound effects before we play the menu switch sound. // That way, it won't be paused. @@ -814,6 +815,7 @@ void M_Ticker (void) if (DMenu::MenuTime & 3) return; if (DMenu::CurrentMenu != NULL && menuactive != MENU_Off) { + D_ProcessEvents(); // The main loop is blocked when the menu is open and cannot dispatch the events. if (transition.previous) transition.previous->Ticker(); DMenu::CurrentMenu->Ticker(); @@ -898,7 +900,7 @@ void M_ClearMenus () } DMenu::CurrentMenu = nullptr; menuactive = MENU_Off; - GUICapture &= ~1; + mouseGrabInput(true); gi->MenuClosed(); } diff --git a/source/common/menu/optionmenuitems.h b/source/common/menu/optionmenuitems.h index 9de745e97..8df332b8f 100644 --- a/source/common/menu/optionmenuitems.h +++ b/source/common/menu/optionmenuitems.h @@ -370,6 +370,7 @@ public: pKey = keyptr; SetMenuMessage(1); menuactive = MENU_WaitKey; // There should be a better way to disable GUI capture... + mouseGrabInput(true); } bool TranslateKeyboardEvents() override @@ -396,9 +397,11 @@ public: { *pKey = ev->data1; menuactive = MENU_On; + mouseGrabInput(false); SetMenuMessage(0); + auto p = mParentMenu; Close(); - mParentMenu->MenuEvent((ev->data1 == KEY_ESCAPE)? MKEY_Abort : MKEY_Input, 0); + p->MenuEvent((ev->data1 == KEY_ESCAPE)? MKEY_Abort : MKEY_Input, 0); return true; } return false; diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 4d0384195..b1d6a8c4e 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -2591,7 +2591,7 @@ DrawCompass(PLAYERp pp) start_ang = NORM_CANG(start_ang - 4); flags = ROTATE_SPRITE_SCREEN_CLIP | ROTATE_SPRITE_CORNER; - if (RedrawCompass && !UsingMenus) + if (RedrawCompass && !M_Active()) { RedrawCompass = FALSE; SET(flags, ROTATE_SPRITE_ALL_PAGES); diff --git a/source/sw/src/menus.h b/source/sw/src/menus.h index d28c0c952..6a1289569 100644 --- a/source/sw/src/menus.h +++ b/source/sw/src/menus.h @@ -104,7 +104,6 @@ typedef enum ct_quitmenu, ct_ordermenu, ct_episodemenu, ct_max } CTLType; -extern SWBOOL UsingMenus; extern int SENSITIVITY; extern CTLType ControlPanelType; extern int16_t MenuTextShade; diff --git a/source/sw/src/panel.cpp b/source/sw/src/panel.cpp index a66b35f2c..16e75b1e3 100644 --- a/source/sw/src/panel.cpp +++ b/source/sw/src/panel.cpp @@ -7597,8 +7597,7 @@ pDisplaySprites(PLAYERp pp) } #if 1 - extern SWBOOL UsingMenus; - if (TEST(psp->flags, PANF_KILL_AFTER_SHOW) && !TEST(psp->flags, PANF_NOT_ALL_PAGES) && !UsingMenus) + if (TEST(psp->flags, PANF_KILL_AFTER_SHOW) && !TEST(psp->flags, PANF_NOT_ALL_PAGES) && !M_Active()) { psp->numpages = 0; SET(flags, ROTATE_SPRITE_ALL_PAGES);