les tecles de funcio ja no arriben a jinput

This commit is contained in:
2026-04-04 18:39:53 +02:00
parent b707bdd63b
commit 699989efb0
4 changed files with 41 additions and 16 deletions

View File

@@ -14,7 +14,9 @@ namespace GlobalInputs {
static bool inc_zoom_was_pressed = false; static bool inc_zoom_was_pressed = false;
static bool fullscreen_was_pressed = false; static bool fullscreen_was_pressed = false;
void handle() { auto handle() -> bool {
bool consumed = false;
// Decrement zoom // Decrement zoom
bool dec_zoom = JI_KeyPressed(Options::keys_gui.dec_zoom); bool dec_zoom = JI_KeyPressed(Options::keys_gui.dec_zoom);
if (dec_zoom && !dec_zoom_was_pressed) { if (dec_zoom && !dec_zoom_was_pressed) {
@@ -22,7 +24,9 @@ namespace GlobalInputs {
char msg[32]; char msg[32];
snprintf(msg, sizeof(msg), "ZOOM %dx", Screen::get()->getZoom()); snprintf(msg, sizeof(msg), "ZOOM %dx", Screen::get()->getZoom());
Overlay::showNotification(msg); Overlay::showNotification(msg);
consumed = true;
} }
if (dec_zoom) consumed = true; // Mentres estiga polsada, consumir-la
dec_zoom_was_pressed = dec_zoom; dec_zoom_was_pressed = dec_zoom;
// Increment zoom // Increment zoom
@@ -32,7 +36,9 @@ namespace GlobalInputs {
char msg[32]; char msg[32];
snprintf(msg, sizeof(msg), "ZOOM %dx", Screen::get()->getZoom()); snprintf(msg, sizeof(msg), "ZOOM %dx", Screen::get()->getZoom());
Overlay::showNotification(msg); Overlay::showNotification(msg);
consumed = true;
} }
if (inc_zoom) consumed = true;
inc_zoom_was_pressed = inc_zoom; inc_zoom_was_pressed = inc_zoom;
// Toggle fullscreen // Toggle fullscreen
@@ -40,8 +46,12 @@ namespace GlobalInputs {
if (fullscreen && !fullscreen_was_pressed) { if (fullscreen && !fullscreen_was_pressed) {
Screen::get()->toggleFullscreen(); Screen::get()->toggleFullscreen();
Overlay::showNotification(Screen::get()->isFullscreen() ? "FULLSCREEN" : "WINDOWED"); Overlay::showNotification(Screen::get()->isFullscreen() ? "FULLSCREEN" : "WINDOWED");
consumed = true;
} }
if (fullscreen) consumed = true;
fullscreen_was_pressed = fullscreen; fullscreen_was_pressed = fullscreen;
return consumed;
} }
} // namespace GlobalInputs } // namespace GlobalInputs

View File

@@ -2,5 +2,6 @@
namespace GlobalInputs { namespace GlobalInputs {
// Comprovar una vegada per frame, després de JI_Update() // Comprovar una vegada per frame, després de JI_Update()
void handle(); // Retorna true si ha consumit alguna tecla (per suprimir-la de la capa de joc)
auto handle() -> bool;
} // namespace GlobalInputs } // namespace GlobalInputs

View File

@@ -4,6 +4,7 @@
#include "core/input/global_inputs.hpp" #include "core/input/global_inputs.hpp"
#include "core/jail/jgame.hpp" #include "core/jail/jgame.hpp"
#include "game/options.hpp"
const bool* keystates; // = SDL_GetKeyboardState( NULL ); const bool* keystates; // = SDL_GetKeyboardState( NULL );
SDL_Event event; SDL_Event event;
@@ -11,6 +12,13 @@ Uint8 cheat[5];
bool key_pressed = false; bool key_pressed = false;
int waitTime = 0; int waitTime = 0;
// Comprova si un scancode pertany a les tecles reservades per a la GUI
static bool isGuiKey(SDL_Scancode sc) {
return sc == Options::keys_gui.dec_zoom ||
sc == Options::keys_gui.inc_zoom ||
sc == Options::keys_gui.fullscreen;
}
void JI_DisableKeyboard(Uint32 time) { void JI_DisableKeyboard(Uint32 time) {
waitTime = time; waitTime = time;
} }
@@ -32,11 +40,15 @@ void JI_Update() {
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_QUIT) JG_QuitSignal(); if (event.type == SDL_EVENT_QUIT) JG_QuitSignal();
if (event.type == SDL_EVENT_KEY_UP) { if (event.type == SDL_EVENT_KEY_UP) {
key_pressed = true; // Si és una tecla GUI, no la passem al joc legacy
JI_moveCheats(event.key.scancode); if (!isGuiKey(event.key.scancode)) {
key_pressed = true;
JI_moveCheats(event.key.scancode);
}
} }
} }
// GlobalInputs processa les tecles GUI per polling
GlobalInputs::handle(); GlobalInputs::handle();
} }

View File

@@ -13,14 +13,14 @@ namespace Overlay {
// --- Aspecte de la notificació --- // --- Aspecte de la notificació ---
static constexpr Uint32 NOTIF_BG_COLOR = 0xFF2E1A1A; // Fons blau fosc (ABGR) static constexpr Uint32 NOTIF_BG_COLOR = 0xFF2E1A1A; // Fons blau fosc (ABGR)
static constexpr Uint32 NOTIF_TEXT_COLOR = 0xFFFFFF00; // Text cyan (ABGR) static constexpr Uint32 NOTIF_TEXT_COLOR = 0xFFFFFF00; // Text cyan (ABGR)
static constexpr int NOTIF_PADDING_H = 8; // Padding horitzontal (esquerra/dreta dins la caixa) static constexpr int NOTIF_PADDING_H = 8; // Padding horitzontal (esquerra/dreta dins la caixa)
static constexpr int NOTIF_PADDING_V = 4; // Padding vertical (dalt/baix dins la caixa) static constexpr int NOTIF_PADDING_V = 4; // Padding vertical (dalt/baix dins la caixa)
static constexpr int NOTIF_MARGIN_X = 4; // Offset des de la vora esquerra de la pantalla static constexpr int NOTIF_MARGIN_X = 4; // Offset des de la vora esquerra de la pantalla
static constexpr int NOTIF_MARGIN_Y = 4; // Offset des de la vora superior de la pantalla static constexpr int NOTIF_MARGIN_Y = 4; // Offset des de la vora superior de la pantalla
// --- Animació --- // --- Animació ---
static constexpr float SLIDE_SPEED = 4.0F; // Velocitat de l'animació (unitats/segon) static constexpr float SLIDE_SPEED = 4.0F; // Velocitat de l'animació (unitats/segon)
// --- Pantalla --- // --- Pantalla ---
static constexpr int SCREEN_W = 320; static constexpr int SCREEN_W = 320;
@@ -28,16 +28,19 @@ namespace Overlay {
// --- Estat de les notificacions --- // --- Estat de les notificacions ---
enum class Status { RISING, STAY, VANISHING, FINISHED }; enum class Status { RISING,
STAY,
VANISHING,
FINISHED };
struct Notification { struct Notification {
std::string message; std::string message;
Status status{Status::RISING}; Status status{Status::RISING};
float anim{0.0F}; // 0 = fora de pantalla, 1 = posició final float anim{0.0F}; // 0 = fora de pantalla, 1 = posició final
float timer{0.0F}; float timer{0.0F};
float duration{2.0F}; float duration{2.0F};
int box_w{0}; // Ample de la caixa (calculat al crear) int box_w{0}; // Ample de la caixa (calculat al crear)
int box_h{0}; // Alçada de la caixa (calculat al crear) int box_h{0}; // Alçada de la caixa (calculat al crear)
}; };
static std::vector<Notification> notifications_; static std::vector<Notification> notifications_;
@@ -119,8 +122,7 @@ namespace Overlay {
// Elimina les acabades // Elimina les acabades
notifications_.erase( notifications_.erase(
std::remove_if(notifications_.begin(), notifications_.end(), std::remove_if(notifications_.begin(), notifications_.end(), [](const Notification& n) { return n.status == Status::FINISHED; }),
[](const Notification& n) { return n.status == Status::FINISHED; }),
notifications_.end()); notifications_.end());
} }