Switch between controller glyphs and keyboard keys automatically

If a controller button is pressed, a controller is connected (even at
startup!) or an axis is moved, the game will switch to displaying
controller glyphs. If a keyboard key is pressed or the last controller
is removed, the game will switch to displaying keyboard keys.
This commit is contained in:
Dav999-v
2023-03-20 02:12:49 +01:00
committed by Misa Elizabeth Kai
parent e55e9efd9b
commit 01200b5e64
3 changed files with 22 additions and 2 deletions

View File

@@ -4,6 +4,7 @@
#include <string.h>
#include "Alloc.h"
#include "ButtonGlyphs.h"
#include "Exit.h"
#include "Game.h"
#include "GlitchrunnerMode.h"
@@ -174,6 +175,8 @@ void KeyPoll::Poll(void)
music.playef(4);
}
BUTTONGLYPHS_keyboard_set_active(true);
if (textentry())
{
if (evt.key.keysym.sym == SDLK_BACKSPACE && !keybuffer.empty())
@@ -268,6 +271,7 @@ void KeyPoll::Poll(void)
/* Controller Input */
case SDL_CONTROLLERBUTTONDOWN:
buttonmap[(SDL_GameControllerButton) evt.cbutton.button] = true;
BUTTONGLYPHS_keyboard_set_active(false);
break;
case SDL_CONTROLLERBUTTONUP:
buttonmap[(SDL_GameControllerButton) evt.cbutton.button] = false;
@@ -300,6 +304,7 @@ void KeyPoll::Poll(void)
}
break;
}
BUTTONGLYPHS_keyboard_set_active(false);
break;
}
case SDL_CONTROLLERDEVICEADDED:
@@ -311,6 +316,7 @@ void KeyPoll::Poll(void)
SDL_GameControllerName(toOpen)
);
controllers[SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(toOpen))] = toOpen;
BUTTONGLYPHS_keyboard_set_active(false);
break;
}
case SDL_CONTROLLERDEVICEREMOVED:
@@ -319,6 +325,10 @@ void KeyPoll::Poll(void)
controllers.erase(evt.cdevice.which);
vlog_info("Closing %s", SDL_GameControllerName(toClose));
SDL_GameControllerClose(toClose);
if (controllers.empty())
{
BUTTONGLYPHS_keyboard_set_active(true);
}
break;
}