1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 06:24:32 +00:00

improvements to key config menu

- hide actionset selection if only 1 set is present
- show keys pressed
- highlight "tabs" a bit more visually
- rumble selected controller on device select change
This commit is contained in:
fgenesis 2020-07-07 16:24:03 +02:00
parent 04bf58ab91
commit 53b027067a
4 changed files with 76 additions and 23 deletions

View file

@ -45,6 +45,8 @@ Joystick::Joystick()
clearRumbleTime= 0;
numJoyAxes = 0;
numHats = 0;
numButtons = 0;
clearAxes();
s1ax = 0;
@ -136,7 +138,8 @@ bool Joystick::init(int stick)
if(numJoyAxes > MAX_JOYSTICK_AXIS)
numJoyAxes = MAX_JOYSTICK_AXIS;
numHats = SDL_JoystickNumHats(sdl_joy);
numButtons = SDL_JoystickNumButtons(sdl_joy);
return true;
@ -243,7 +246,7 @@ void Joystick::update(float dt)
}
if (sdl_controller)
{
for(int i = 0; i < numJoyAxes; ++i)
for(unsigned i = 0; i < numJoyAxes; ++i)
{
Sint16 ax = SDL_GameControllerGetAxis(sdl_controller, (SDL_GameControllerAxis)i);
axisRaw[i] = float(ax)/32768.0f;
@ -265,7 +268,7 @@ void Joystick::update(float dt)
#endif
// Note: this connects with the else above when the SDL2 path is compiled!
{
for(int i = 0; i < numJoyAxes; ++i)
for(unsigned i = 0; i < numJoyAxes; ++i)
{
Sint16 ax = SDL_JoystickGetAxis(sdl_joy, i);
axisRaw[i] = float(ax)/32768.0f;
@ -290,8 +293,10 @@ void Joystick::update(float dt)
else
#endif
{
for (unsigned i = 0; i < MAX_JOYSTICK_BTN; i++)
for (unsigned i = 0; i < numButtons; i++)
buttonBitmask |= !!SDL_JoystickGetButton(sdl_joy, i) << i;
//for (unsigned i = 0; i < numHats; i++)
}
}
@ -310,7 +315,7 @@ bool Joystick::anyButton() const
return !!buttonBitmask;;
}
int Joystick::getNumAxes() const
unsigned Joystick::getNumAxes() const
{
#ifdef BBGE_BUILD_SDL2
return sdl_controller ? SDL_CONTROLLER_AXIS_MAX : numJoyAxes;
@ -319,12 +324,22 @@ int Joystick::getNumAxes() const
#endif
}
unsigned Joystick::getNumButtons() const
{
return numButtons;
}
unsigned Joystick::getNumHats() const
{
return numHats;
}
float Joystick::getAxisUncalibrated(int id) const
{
return id < MAX_JOYSTICK_AXIS ? axisRaw[id] : 0.0f;
}
const char *Joystick::getAxisName(int axis) const
const char *Joystick::getAxisName(unsigned axis) const
{
if(axis >= numJoyAxes)
return NULL;
@ -335,7 +350,7 @@ const char *Joystick::getAxisName(int axis) const
return NULL;
}
const char *Joystick::getButtonName(int btn) const
const char *Joystick::getButtonName(unsigned btn) const
{
#ifdef BBGE_BUILD_SDL2
if(sdl_controller)

View file

@ -13,6 +13,7 @@
#define MAX_JOYSTICK_BTN 32
#define MAX_JOYSTICK_AXIS 32
#define MAX_JOYSTICK_HATS 8
const static float JOY_AXIS_THRESHOLD = 0.6f;
@ -38,14 +39,16 @@ public:
bool anyButton() const;
bool getButton(size_t id) const { return !!(buttonBitmask & (1u << id)); }
float getAxisUncalibrated(int id) const;
int getNumAxes() const;
unsigned getNumAxes() const;
unsigned getNumButtons() const;
unsigned getNumHats() const;
int getIndex() const { return stickIndex; }
int getInstanceID() const { return instanceID; }
inline bool isEnabled() const { return enabled; }
inline void setEnabled(bool on) { enabled = on; }
const char *getAxisName(int axis) const;
const char *getButtonName(int btn) const;
const char *getAxisName(unsigned axis) const;
const char *getButtonName(unsigned btn) const;
const char *getName() const;
const char *getGUID() const;
@ -59,7 +62,7 @@ private:
int stickIndex;
int instanceID;
unsigned buttonBitmask;
int numJoyAxes;
unsigned numJoyAxes, numHats, numButtons;
SDL_Joystick *sdl_joy;
float axisRaw[MAX_JOYSTICK_AXIS];
std::string name;