mirror of
https://github.com/libretro/devilutionX.git
synced 2026-11-12 13:05:17 -10:00
Initial game controller support. Actions are based on the Switch branch but the controller code itself is implemented differently, allowing for easy remapping and minimizing changes to the Source/ directory. Many subtle and not so subtle controller bugs have been fixed in this implementation, including: 1. Smoother & more responsive movement with the joysticks. 2. Consistent controls for all the menus in the game (stores, quest log, etc). 3. Cursor appearance / disappearance at appropriate times. Low-level controls are abstracted and 3 SDL interfaces are supported: game controller, joystick, and keyboard. See SourceX/controls/ for more details on this. Wishlist for the future: 1. Primary button and use button should attack continously. This is hard as it requires checking the cooldowns / attack speed. 2. Quick spell menu navigation is very buggy. It is also buggy in the switch branch. I haven't had a change to investigate.
66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
#include "controls/controller.h"
|
|
|
|
#include "controls/devices/kbcontroller.h"
|
|
#include "controls/devices/joystick.h"
|
|
#include "controls/devices/game_controller.h"
|
|
|
|
namespace dvl {
|
|
|
|
ControllerButtonEvent ToControllerButtonEvent(const SDL_Event &event)
|
|
{
|
|
ControllerButtonEvent result{ ControllerButton::NONE, false };
|
|
switch (event.type) {
|
|
#ifndef USE_SDL1
|
|
case SDL_CONTROLLERAXISMOTION:
|
|
result.up = event.caxis.value == 0;
|
|
break;
|
|
case SDL_CONTROLLERBUTTONUP:
|
|
#endif
|
|
case SDL_JOYBUTTONUP:
|
|
case SDL_KEYUP:
|
|
result.up = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
#if HAS_KBCTRL == 1
|
|
result.button = KbCtrlToControllerButton(event);
|
|
if (result.button != ControllerButton::NONE)
|
|
return result;
|
|
#endif
|
|
|
|
#ifndef USE_SDL1
|
|
result.button = GameControllerToControllerButton(event);
|
|
if (result.button != ControllerButton::NONE)
|
|
return result;
|
|
#endif
|
|
|
|
result.button = JoyButtonToControllerButton(event);
|
|
|
|
return result;
|
|
}
|
|
|
|
bool IsControllerButtonPressed(ControllerButton button)
|
|
{
|
|
bool result = false;
|
|
#ifndef USE_SDL1
|
|
result = result || IsGameControllerButtonPressed(button);
|
|
#endif
|
|
#if HAS_KBCTRL == 1
|
|
result = result || IsKbCtrlButtonPressed(button);
|
|
#endif
|
|
result = result || IsJoystickButtonPressed(button);
|
|
return result;
|
|
}
|
|
|
|
void InitController()
|
|
{
|
|
InitJoystick();
|
|
#ifndef USE_SDL1
|
|
InitGameController();
|
|
#endif
|
|
}
|
|
|
|
} // namespace dvl
|