diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 0a69fba1f..fd7eef060 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -98,6 +98,7 @@ set(libdevilutionx_SRCS engine/backbuffer_state.cpp engine/direction.cpp engine/dx.cpp + engine/events.cpp engine/load_cel.cpp engine/load_cl2.cpp engine/load_clx.cpp @@ -126,8 +127,6 @@ set(libdevilutionx_SRCS levels/town.cpp levels/trigs.cpp - miniwin/misc_msg.cpp - panels/charpanel.cpp panels/info_box.cpp panels/mainpanel.cpp diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index c9998a2e6..1acf395ec 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -10,7 +10,6 @@ #include "controls/remap_keyboard.h" #include "engine/render/text_render.hpp" #include "hwcursor.hpp" -#include "miniwin/misc_msg.h" #include "options.h" #include "utils/language.h" #include "utils/stdcompat/optional.hpp" diff --git a/Source/control.cpp b/Source/control.cpp index 48a22159a..267ae3422 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -31,7 +31,6 @@ #include "levels/trigs.h" #include "lighting.h" #include "minitext.h" -#include "miniwin/misc_msg.h" #include "missiles.h" #include "options.h" #include "panels/charpanel.hpp" @@ -553,6 +552,26 @@ bool IsChatAvailable() #endif } +void FocusOnCharInfo() +{ + Player &myPlayer = *MyPlayer; + + if (invflag || myPlayer._pStatPts <= 0) + return; + + // Find the first incrementable stat. + int stat = -1; + for (auto attribute : enum_values()) { + if (myPlayer.GetBaseAttributeValue(attribute) >= myPlayer.GetMaximumAttributeValue(attribute)) + continue; + stat = static_cast(attribute); + } + if (stat == -1) + return; + + SetCursorPos(ChrBtnsRect[stat].Center()); +} + void AddPanelString(string_view str) { if (InfoString.empty()) diff --git a/Source/control.h b/Source/control.h index d54973988..a45f682b5 100644 --- a/Source/control.h +++ b/Source/control.h @@ -59,6 +59,12 @@ extern SDL_Rect PanBtnPos[8]; void CalculatePanelAreas(); bool IsChatAvailable(); + +/** + * @brief Moves the mouse to the first attribute "+" button. + */ +void FocusOnCharInfo(); + /** * @brief Check if the UI can cover the game area entierly */ diff --git a/Source/controls/game_controls.cpp b/Source/controls/game_controls.cpp index da607252e..9c619bd92 100644 --- a/Source/controls/game_controls.cpp +++ b/Source/controls/game_controls.cpp @@ -3,7 +3,6 @@ #include #include "controls/controller_motion.h" -#include "miniwin/misc_msg.h" #ifndef USE_SDL1 #include "controls/devices/game_controller.h" #endif diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 945323326..9e38272ee 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -11,7 +11,6 @@ #include "automap.h" #include "control.h" #include "controls/controller_motion.h" -#include "miniwin/misc_msg.h" #ifndef USE_SDL1 #include "controls/devices/game_controller.h" #endif diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 9842ee8e9..5692b86d0 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -5,6 +5,7 @@ #include "diablo.h" #include "doom.h" #include "engine.h" +#include "engine/events.hpp" #include "engine/render/clx_render.hpp" #include "init.h" #include "inv.h" diff --git a/Source/debug.cpp b/Source/debug.cpp index a6e65e4ee..03f814dbb 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -15,13 +15,13 @@ #include "control.h" #include "cursor.h" #include "engine/backbuffer_state.hpp" +#include "engine/events.hpp" #include "engine/load_cel.hpp" #include "engine/point.hpp" #include "error.h" #include "inv.h" #include "levels/setmaps.h" #include "lighting.h" -#include "miniwin/misc_msg.h" #include "monstdat.h" #include "monster.h" #include "plrmsg.h" diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 312f3f7e0..dfe884909 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -16,7 +16,6 @@ #include "dead.h" #ifdef _DEBUG #include "debug.h" -#include "miniwin/misc_msg.h" #endif #include "DiabloUI/diabloui.h" #include "controls/plrctrls.h" @@ -29,6 +28,7 @@ #include "engine/clx_sprite.hpp" #include "engine/demomode.h" #include "engine/dx.h" +#include "engine/events.hpp" #include "engine/load_cel.hpp" #include "engine/load_file.hpp" #include "engine/random.hpp" @@ -738,6 +738,8 @@ void GameEventHandler(const SDL_Event &event, uint16_t modState) return; #endif case SDL_MOUSEMOTION: + if (ControlMode == ControlTypes::KeyboardAndMouse && invflag) + InvalidateInventorySlot(); MousePosition = { event.motion.x, event.motion.y }; gmenu_on_mouse_move(); return; @@ -2300,6 +2302,18 @@ void InitPadmapActions() sgOptions.Padmapper.CommitActions(); } +void SetCursorPos(Point position) +{ + if (ControlDevice != ControlTypes::KeyboardAndMouse) { + MousePosition = position; + return; + } + + LogicalToOutput(&position.x, &position.y); + if (!demo::IsRunning()) + SDL_WarpMouseInWindow(ghMainWnd, position.x, position.y); +} + void FreeGameMem() { pDungeonCels = nullptr; diff --git a/Source/diablo.h b/Source/diablo.h index f5b617602..24a0c58a0 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -82,6 +82,7 @@ extern char gszProductName[64]; extern MouseActionType LastMouseButtonAction; void InitKeymapActions(); +void SetCursorPos(Point position); void FreeGameMem(); bool StartGame(bool bNewGame, bool bSinglePlayer); [[noreturn]] void diablo_quit(int exitStatus); diff --git a/Source/engine/demomode.cpp b/Source/engine/demomode.cpp index 4841c2710..82117b09c 100644 --- a/Source/engine/demomode.cpp +++ b/Source/engine/demomode.cpp @@ -10,6 +10,7 @@ #endif #include "controls/plrctrls.h" +#include "engine/events.hpp" #include "gmenu.h" #include "menu.h" #include "nthread.h" diff --git a/Source/engine/demomode.h b/Source/engine/demomode.h index 02e635e0f..9ad61ff49 100644 --- a/Source/engine/demomode.h +++ b/Source/engine/demomode.h @@ -7,8 +7,6 @@ #include -#include "miniwin/misc_msg.h" - namespace devilution { namespace demo { diff --git a/Source/miniwin/misc_msg.cpp b/Source/engine/events.cpp similarity index 66% rename from Source/miniwin/misc_msg.cpp rename to Source/engine/events.cpp index 4a10a3e5c..3dd537ef8 100644 --- a/Source/miniwin/misc_msg.cpp +++ b/Source/engine/events.cpp @@ -1,30 +1,20 @@ -#include "miniwin/misc_msg.h" +#include "engine/events.hpp" -#include -#include -#include - -#include - -#include "control.h" -#include "controls/controller.h" #include "controls/input.h" -#include "controls/plrctrls.h" -#ifndef USE_SDL1 -#include "controls/touch/event_handlers.h" -#endif -#include "cursor.h" +#include "engine.h" #include "engine/demomode.h" -#include "engine/rectangle.hpp" -#include "hwcursor.hpp" +#include "interfac.h" #include "movie.h" -#include "panels/spell_list.hpp" -#include "qol/stash.h" -#include "utils/display.h" #include "utils/log.hpp" -#include "utils/utf8.hpp" + +#ifdef USE_SDL1 +#include "utils/display.h" +#else +#include "controls/touch/event_handlers.h" +#endif #ifdef __vita__ +#include "diablo.h" #include "platform/vita/touch.h" #endif @@ -33,59 +23,8 @@ #include #endif -/** @file - * * - * Windows message handling and keyboard event conversion for SDL. - */ - namespace devilution { -void SetMouseButtonEvent(SDL_Event &event, uint32_t type, uint8_t button, Point position) -{ - event.type = type; - event.button.button = button; - if (type == SDL_MOUSEBUTTONDOWN) { - event.button.state = SDL_PRESSED; - } else { - event.button.state = SDL_RELEASED; - } - event.button.x = position.x; - event.button.y = position.y; -} - -void SetCursorPos(Point position) -{ - if (ControlDevice != ControlTypes::KeyboardAndMouse) { - MousePosition = position; - return; - } - - LogicalToOutput(&position.x, &position.y); - if (!demo::IsRunning()) - SDL_WarpMouseInWindow(ghMainWnd, position.x, position.y); -} - -// Moves the mouse to the first attribute "+" button. -void FocusOnCharInfo() -{ - Player &myPlayer = *MyPlayer; - - if (invflag || myPlayer._pStatPts <= 0) - return; - - // Find the first incrementable stat. - int stat = -1; - for (auto attribute : enum_values()) { - if (myPlayer.GetBaseAttributeValue(attribute) >= myPlayer.GetMaximumAttributeValue(attribute)) - continue; - stat = static_cast(attribute); - } - if (stat == -1) - return; - - SetCursorPos(ChrBtnsRect[stat].Center()); -} - namespace { bool FalseAvail(const char *name, int value) @@ -94,8 +33,6 @@ bool FalseAvail(const char *name, int value) return true; } -} // namespace - bool FetchMessage_Real(SDL_Event *event, uint16_t *modState) { #ifdef __SWITCH__ @@ -167,6 +104,9 @@ bool FetchMessage_Real(SDL_Event *event, uint16_t *modState) case SDL_JOYHATMOTION: case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: + case SDL_MOUSEMOTION: + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: *event = e; break; case SDL_KEYDOWN: @@ -175,15 +115,6 @@ bool FetchMessage_Real(SDL_Event *event, uint16_t *modState) return FalseAvail(e.type == SDL_KEYDOWN ? "SDL_KEYDOWN" : "SDL_KEYUP", e.key.keysym.sym); *event = e; break; - case SDL_MOUSEMOTION: - *event = e; - if (ControlMode == ControlTypes::KeyboardAndMouse && invflag) - InvalidateInventorySlot(); - break; - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - *event = e; - break; #ifndef USE_SDL1 case SDL_MOUSEWHEEL: event->type = SDL_KEYDOWN; @@ -212,6 +143,17 @@ bool FetchMessage_Real(SDL_Event *event, uint16_t *modState) return true; } +} // namespace + +EventHandler CurrentEventHandler; + +EventHandler SetEventHandler(EventHandler eventHandler) +{ + EventHandler previousHandler = CurrentEventHandler; + CurrentEventHandler = eventHandler; + return previousHandler; +} + bool FetchMessage(SDL_Event *event, uint16_t *modState) { const bool available = demo::IsRunning() ? demo::FetchMessage(event, modState) : FetchMessage_Real(event, modState); diff --git a/Source/miniwin/misc_msg.h b/Source/engine/events.hpp similarity index 59% rename from Source/miniwin/misc_msg.h rename to Source/engine/events.hpp index e3095adaa..e7d65ab5f 100644 --- a/Source/miniwin/misc_msg.h +++ b/Source/engine/events.hpp @@ -1,27 +1,24 @@ -/** - * @file miniwin/misc_msg.h - * - * Contains most of the the demomode specific logic - */ #pragma once -#include #include +#include + +#include "engine/point.hpp" + #ifdef USE_SDL1 #include "utils/sdl2_to_1_2_backports.h" #endif -#include "engine/point.hpp" - namespace devilution { using EventHandler = void (*)(const SDL_Event &event, uint16_t modState); -void SetCursorPos(Point position); -void FocusOnCharInfo(); +/** @brief The current input handler function */ +extern EventHandler CurrentEventHandler; + +EventHandler SetEventHandler(EventHandler NewProc); -void SetMouseButtonEvent(SDL_Event &event, uint32_t type, uint8_t button, Point position); bool FetchMessage(SDL_Event *event, uint16_t *modState); void HandleMessage(const SDL_Event &event, uint16_t modState); diff --git a/Source/engine/render/dun_render.cpp b/Source/engine/render/dun_render.cpp index 11ef500a9..22ea46a7b 100644 --- a/Source/engine/render/dun_render.cpp +++ b/Source/engine/render/dun_render.cpp @@ -19,12 +19,9 @@ #include #include "lighting.h" -#include "utils/stdcompat/algorithm.hpp" -#ifdef _DEBUG -#include "miniwin/misc_msg.h" -#endif #include "options.h" #include "utils/attributes.h" +#include "utils/stdcompat/algorithm.hpp" #ifdef DEBUG_STR #include "engine/render/text_render.hpp" #endif diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 604b576a8..10337b177 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -25,9 +25,6 @@ #include "inv.h" #include "lighting.h" #include "minitext.h" -#ifdef _DEBUG -#include "miniwin/misc_msg.h" -#endif #include "missiles.h" #include "nthread.h" #include "options.h" diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index b528d258c..89fe16bb2 100644 --- a/Source/gamemenu.cpp +++ b/Source/gamemenu.cpp @@ -7,6 +7,7 @@ #include "cursor.h" #include "engine/backbuffer_state.hpp" +#include "engine/events.hpp" #include "engine/sound.h" #include "engine/sound_defs.hpp" #include "error.h" diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index e856e174f..c005b441d 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -14,7 +14,6 @@ #include "engine/load_cel.hpp" #include "engine/render/clx_render.hpp" #include "engine/render/text_render.hpp" -#include "miniwin/misc_msg.h" #include "options.h" #include "stores.h" #include "utils/language.h" diff --git a/Source/init.cpp b/Source/init.cpp index e33817035..0416f24c2 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -16,8 +16,8 @@ #include "engine/assets.hpp" #include "engine/backbuffer_state.hpp" #include "engine/dx.h" +#include "engine/events.hpp" #include "hwcursor.hpp" -#include "miniwin/misc_msg.h" #include "options.h" #include "pfile.h" #include "utils/file_util.h" @@ -41,8 +41,6 @@ namespace devilution { /** True if the game is the current active window */ bool gbActive; -/** The current input handler function */ -EventHandler CurrentEventHandler; /** Indicate if we only have access to demo data */ bool gbIsSpawn; /** Indicate if we have loaded the Hellfire expansion data */ @@ -375,11 +373,4 @@ void MainWndProc(const SDL_Event &event) #endif } -EventHandler SetEventHandler(EventHandler eventHandler) -{ - EventHandler previousHandler = CurrentEventHandler; - CurrentEventHandler = eventHandler; - return previousHandler; -} - } // namespace devilution diff --git a/Source/init.h b/Source/init.h index 10f9cfa02..b8305c0e8 100644 --- a/Source/init.h +++ b/Source/init.h @@ -5,18 +5,20 @@ */ #pragma once -#include "miniwin/misc_msg.h" #include "utils/attributes.h" #include "utils/stdcompat/optional.hpp" -#ifndef UNPACKED_MPQS +#ifdef UNPACKED_MPQS +#include +#else #include "mpq/mpq_reader.hpp" #endif +#include + namespace devilution { extern bool gbActive; -extern EventHandler CurrentEventHandler; extern DVL_API_FOR_TEST bool gbIsSpawn; extern DVL_API_FOR_TEST bool gbIsHellfire; extern DVL_API_FOR_TEST bool gbVanilla; @@ -87,6 +89,5 @@ void LoadLanguageArchive(); void LoadGameArchives(); void init_create_window(); void MainWndProc(const SDL_Event &event); -EventHandler SetEventHandler(EventHandler NewProc); } // namespace devilution diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 0c51e5f25..43c33d62a 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -13,6 +13,7 @@ #include "engine/clx_sprite.hpp" #include "engine/demomode.h" #include "engine/dx.h" +#include "engine/events.hpp" #include "engine/load_cel.hpp" #include "engine/load_clx.hpp" #include "engine/load_pcx.hpp" @@ -21,7 +22,6 @@ #include "hwcursor.hpp" #include "init.h" #include "loadsave.h" -#include "miniwin/misc_msg.h" #include "pfile.h" #include "plrmsg.h" #include "utils/sdl_geometry.h" diff --git a/Source/inv.cpp b/Source/inv.cpp index ade22e604..caa72ae93 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -21,7 +21,6 @@ #include "inv_iterators.hpp" #include "levels/town.h" #include "minitext.h" -#include "miniwin/misc_msg.h" #include "options.h" #include "panels/ui_panels.hpp" #include "plrmsg.h" diff --git a/Source/movie.cpp b/Source/movie.cpp index 9cbf937a6..b3bebd59f 100644 --- a/Source/movie.cpp +++ b/Source/movie.cpp @@ -9,9 +9,9 @@ #include "effects.h" #include "engine/backbuffer_state.hpp" #include "engine/demomode.h" +#include "engine/events.hpp" #include "engine/sound.h" #include "hwcursor.hpp" -#include "miniwin/misc_msg.h" #include "storm/storm_svid.h" #include "utils/display.h" diff --git a/Source/options.h b/Source/options.h index 9617ec851..abbd9fca1 100644 --- a/Source/options.h +++ b/Source/options.h @@ -12,7 +12,6 @@ #include "controls/controller_buttons.h" #include "controls/game_controls.h" #include "engine/sound_defs.hpp" -#include "miniwin/misc_msg.h" #include "pack.h" #include "utils/enum_traits.h" #include "utils/stdcompat/optional.hpp" diff --git a/Source/panels/spell_list.cpp b/Source/panels/spell_list.cpp index ec81d4603..45f13d78c 100644 --- a/Source/panels/spell_list.cpp +++ b/Source/panels/spell_list.cpp @@ -8,7 +8,6 @@ #include "engine/palette.h" #include "engine/render/text_render.hpp" #include "inv_iterators.hpp" -#include "miniwin/misc_msg.h" #include "options.h" #include "panels/spell_icons.hpp" #include "player.h" diff --git a/Source/platform/vita/touch.cpp b/Source/platform/vita/touch.cpp index b53c6b9b2..c382d94f2 100644 --- a/Source/platform/vita/touch.cpp +++ b/Source/platform/vita/touch.cpp @@ -95,6 +95,19 @@ void InitTouch() y_borderwidth = (current.h - visible_height) / 2; } +void SetMouseButtonEvent(SDL_Event &event, uint32_t type, uint8_t button, Point position) +{ + event.type = type; + event.button.button = button; + if (type == SDL_MOUSEBUTTONDOWN) { + event.button.state = SDL_PRESSED; + } else { + event.button.state = SDL_RELEASED; + } + event.button.x = position.x; + event.button.y = position.y; +} + void PreprocessFingerDown(SDL_Event *event) { // front (0) or back (1) panel diff --git a/Source/player.cpp b/Source/player.cpp index a1d071101..ce3b5e2f3 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -12,7 +12,6 @@ #include "controls/plrctrls.h" #include "cursor.h" #include "dead.h" -#include "miniwin/misc_msg.h" #ifdef _DEBUG #include "debug.h" #endif diff --git a/Source/qol/stash.cpp b/Source/qol/stash.cpp index c46b2efb9..bb8766cb8 100644 --- a/Source/qol/stash.cpp +++ b/Source/qol/stash.cpp @@ -16,7 +16,6 @@ #include "engine/size.hpp" #include "hwcursor.hpp" #include "minitext.h" -#include "miniwin/misc_msg.h" #include "stores.h" #include "utils/format_int.hpp" #include "utils/language.h"