soport per a gamepad

This commit is contained in:
2026-04-05 00:22:21 +02:00
parent 6d42f848a5
commit a328681365
6 changed files with 209 additions and 1 deletions

View File

@@ -20,6 +20,14 @@ void JI_SetInputBlocked(bool blocked) {
input_blocked = blocked;
}
static Uint8 virtual_keystates[SDL_SCANCODE_COUNT] = {0};
void JI_SetVirtualKey(int scancode, bool pressed) {
if (scancode >= 0 && scancode < SDL_SCANCODE_COUNT) {
virtual_keystates[scancode] = pressed ? 1 : 0;
}
}
void JI_moveCheats(Uint8 new_key) {
cheat[0] = cheat[1];
cheat[1] = cheat[2];
@@ -47,7 +55,8 @@ bool JI_KeyPressed(int key) {
if (input_blocked) return false;
// ESC bloquejada pel Director (primera pulsació mostra notificació)
if (key == SDL_SCANCODE_ESCAPE && Director::get()->isEscBlocked()) return false;
return keystates[key] != 0;
if (key < 0 || key >= SDL_SCANCODE_COUNT) return false;
return keystates[key] != 0 || virtual_keystates[key] != 0;
}
bool JI_CheatActivated(const char* cheat_code) {

View File

@@ -6,6 +6,10 @@ void JI_DisableKeyboard(Uint32 time);
// Bloqueja tot l'input cap al joc (JI_KeyPressed retorna false per a tot)
void JI_SetInputBlocked(bool blocked);
// Estableix l'estat d'una tecla virtual (p.ex. des del gamepad).
// JI_KeyPressed retorna true si el teclat real O la virtual estan premudes.
void JI_SetVirtualKey(int scancode, bool pressed);
void JI_Update();
bool JI_KeyPressed(int key);