Browse Source

Remove miniwin

Event handling code moved to `engine/events.{hpp,cpp}`.
pull/5744/head
Gleb Mazovetskiy 3 years ago
parent
commit
1788d2f8ec
  1. 3
      Source/CMakeLists.txt
  2. 1
      Source/DiabloUI/settingsmenu.cpp
  3. 21
      Source/control.cpp
  4. 6
      Source/control.h
  5. 1
      Source/controls/game_controls.cpp
  6. 1
      Source/controls/plrctrls.cpp
  7. 1
      Source/controls/touch/renderers.cpp
  8. 2
      Source/debug.cpp
  9. 16
      Source/diablo.cpp
  10. 1
      Source/diablo.h
  11. 1
      Source/engine/demomode.cpp
  12. 2
      Source/engine/demomode.h
  13. 106
      Source/engine/events.cpp
  14. 19
      Source/engine/events.hpp
  15. 5
      Source/engine/render/dun_render.cpp
  16. 3
      Source/engine/render/scrollrt.cpp
  17. 1
      Source/gamemenu.cpp
  18. 1
      Source/gmenu.cpp
  19. 11
      Source/init.cpp
  20. 9
      Source/init.h
  21. 2
      Source/interfac.cpp
  22. 1
      Source/inv.cpp
  23. 2
      Source/movie.cpp
  24. 1
      Source/options.h
  25. 1
      Source/panels/spell_list.cpp
  26. 13
      Source/platform/vita/touch.cpp
  27. 1
      Source/player.cpp
  28. 1
      Source/qol/stash.cpp

3
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

1
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"

21
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<CharacterAttribute>()) {
if (myPlayer.GetBaseAttributeValue(attribute) >= myPlayer.GetMaximumAttributeValue(attribute))
continue;
stat = static_cast<int>(attribute);
}
if (stat == -1)
return;
SetCursorPos(ChrBtnsRect[stat].Center());
}
void AddPanelString(string_view str)
{
if (InfoString.empty())

6
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
*/

1
Source/controls/game_controls.cpp

@ -3,7 +3,6 @@
#include <cstdint>
#include "controls/controller_motion.h"
#include "miniwin/misc_msg.h"
#ifndef USE_SDL1
#include "controls/devices/game_controller.h"
#endif

1
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

1
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"

2
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"

16
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;

1
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);

1
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"

2
Source/engine/demomode.h

@ -7,8 +7,6 @@
#include <SDL.h>
#include "miniwin/misc_msg.h"
namespace devilution {
namespace demo {

106
Source/miniwin/misc_msg.cpp → Source/engine/events.cpp

@ -1,30 +1,20 @@
#include "miniwin/misc_msg.h"
#include "engine/events.hpp"
#include <cstdint>
#include <deque>
#include <string>
#include <SDL.h>
#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 <switch.h>
#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<CharacterAttribute>()) {
if (myPlayer.GetBaseAttributeValue(attribute) >= myPlayer.GetMaximumAttributeValue(attribute))
continue;
stat = static_cast<int>(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);

19
Source/miniwin/misc_msg.h → Source/engine/events.hpp

@ -1,27 +1,24 @@
/**
* @file miniwin/misc_msg.h
*
* Contains most of the the demomode specific logic
*/
#pragma once
#include <SDL.h>
#include <cstdint>
#include <SDL.h>
#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);

5
Source/engine/render/dun_render.cpp

@ -19,12 +19,9 @@
#include <cstdint>
#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

3
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"

1
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"

1
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"

11
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

9
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 <string>
#else
#include "mpq/mpq_reader.hpp"
#endif
#include <SDL.h>
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

2
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"

1
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"

2
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"

1
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"

1
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"

13
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

1
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

1
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"

Loading…
Cancel
Save