key_config.cpp i keys.yaml per a centralitzar i no hardcodejar tecles
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <set> // Para set
|
||||
#include <system_error> // Para std::error_code
|
||||
|
||||
#include "core/input/key_config.hpp" // Para KeyConfig
|
||||
#include "core/input/mouse.hpp" // Para Mouse
|
||||
#include "core/rendering/render_info.hpp" // Para RenderInfo
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
@@ -434,8 +435,10 @@ void MapEditor::render() {
|
||||
void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-function-cognitive-complexity)
|
||||
// Si el tile picker está abierto, los eventos van a él.
|
||||
// Excepción: la T lo cierra como toggle (sin tocar el brush).
|
||||
const auto* kc = KeyConfig::get();
|
||||
|
||||
if (tile_picker_.isOpen()) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_T && static_cast<int>(event.key.repeat) == 0) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "tile_picker") && static_cast<int>(event.key.repeat) == 0) {
|
||||
tile_picker_.close();
|
||||
return;
|
||||
}
|
||||
@@ -446,7 +449,7 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
|
||||
// Si el mini mapa está visible, delegar eventos (ESC o M para cerrar)
|
||||
if (mini_map_visible_ && mini_map_) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN &&
|
||||
(event.key.key == SDLK_ESCAPE || event.key.key == SDLK_M) &&
|
||||
(event.key.key == kc->key("EDITOR", "cancel") || event.key.key == kc->key("EDITOR", "minimap")) &&
|
||||
static_cast<int>(event.key.repeat) == 0) {
|
||||
mini_map_visible_ = false;
|
||||
return;
|
||||
@@ -456,19 +459,19 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
|
||||
}
|
||||
|
||||
// ESC: cancelar eyedropper en progreso (sin tocar el brush previo)
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_ESCAPE && eyedropper_.active) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "cancel") && eyedropper_.active) {
|
||||
eyedropper_.active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// ESC: desactivar brush
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_ESCAPE && !brush_.isEmpty()) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "cancel") && !brush_.isEmpty()) {
|
||||
brush_.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// E: toggle borrador (alterna entre brush vacío y brush 1x1 ERASE)
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_E && static_cast<int>(event.key.repeat) == 0) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "eraser") && static_cast<int>(event.key.repeat) == 0) {
|
||||
if (brush_.width == 1 && brush_.height == 1 && !brush_.tiles.empty() && brush_.tiles[0] == BrushPattern::ERASE) {
|
||||
brush_.clear();
|
||||
} else {
|
||||
@@ -478,13 +481,13 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
|
||||
}
|
||||
|
||||
// M: toggle mini mapa
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_M && static_cast<int>(event.key.repeat) == 0) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "minimap") && static_cast<int>(event.key.repeat) == 0) {
|
||||
toggleMiniMap();
|
||||
return;
|
||||
}
|
||||
|
||||
// 8: alternar entre draw y collision
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_8 && static_cast<int>(event.key.repeat) == 0) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "collision") && static_cast<int>(event.key.repeat) == 0) {
|
||||
setEditingCollision(!editing_collision_);
|
||||
return;
|
||||
}
|
||||
@@ -492,21 +495,15 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
|
||||
// Cursores: navegar a habitación adyacente
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
|
||||
std::string direction;
|
||||
switch (event.key.key) {
|
||||
case SDLK_UP:
|
||||
direction = "UP";
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
direction = "DOWN";
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
direction = "LEFT";
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
direction = "RIGHT";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
const auto NAV_KEY = event.key.key;
|
||||
if (NAV_KEY == kc->key("EDITOR", "nav_up")) {
|
||||
direction = "UP";
|
||||
} else if (NAV_KEY == kc->key("EDITOR", "nav_down")) {
|
||||
direction = "DOWN";
|
||||
} else if (NAV_KEY == kc->key("EDITOR", "nav_left")) {
|
||||
direction = "LEFT";
|
||||
} else if (NAV_KEY == kc->key("EDITOR", "nav_right")) {
|
||||
direction = "RIGHT";
|
||||
}
|
||||
if (!direction.empty() && GameControl::get_adjacent_room) {
|
||||
std::string adjacent = GameControl::get_adjacent_room(direction);
|
||||
@@ -523,7 +520,7 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
|
||||
}
|
||||
|
||||
// T: abrir TilePicker (el cierre con T también se gestiona arriba, antes de delegar al picker)
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_T && static_cast<int>(event.key.repeat) == 0) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "tile_picker") && static_cast<int>(event.key.repeat) == 0) {
|
||||
// Deseleccionar entidades
|
||||
selection_.clear();
|
||||
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
#include <queue> // Para queue (BFS)
|
||||
#include <set> // Para set
|
||||
|
||||
#include "core/input/key_config.hpp" // Para KeyConfig
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/screenshot.hpp" // Para Screenshot::save
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/text.hpp" // Para Text (números de room)
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource::Cache
|
||||
#include "game/gameplay/room.hpp" // Para Room::Data
|
||||
@@ -365,13 +366,15 @@ void MiniMap::render(const std::string& current_room) {
|
||||
// Maneja eventos del minimapa (drag para explorar, click para navegar)
|
||||
void MiniMap::handleEvent(const SDL_Event& event, const std::string& current_room) {
|
||||
// Toggle de números de room
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_N && static_cast<int>(event.key.repeat) == 0) {
|
||||
const auto* kc = KeyConfig::get();
|
||||
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("MINIMAP", "numbers") && static_cast<int>(event.key.repeat) == 0) {
|
||||
show_numbers_ = !show_numbers_;
|
||||
return;
|
||||
}
|
||||
|
||||
// Captura del minimapa
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_S && static_cast<int>(event.key.repeat) == 0) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("MINIMAP", "capture") && static_cast<int>(event.key.repeat) == 0) {
|
||||
if (map_surface_) {
|
||||
// Renderizar números sobre map_surface_ si están activos
|
||||
if (show_numbers_) {
|
||||
|
||||
@@ -103,10 +103,10 @@ class MiniMap {
|
||||
static constexpr int PADDING = 4; // Padding alrededor del minimapa
|
||||
|
||||
// Colores del minimapa (índices de paleta)
|
||||
Uint8 bg_color_{2}; // Fondo general (configurable)
|
||||
Uint8 conn_color_{14}; // Líneas de conexión (configurable)
|
||||
static constexpr Uint8 COLOR_ROOM_BORDER = 0; // Borde de cada miniroom
|
||||
static constexpr Uint8 COLOR_SHADOW = 1; // Sombra de cada miniroom
|
||||
Uint8 bg_color_{2}; // Fondo general (configurable)
|
||||
Uint8 conn_color_{14}; // Líneas de conexión (configurable)
|
||||
static constexpr Uint8 COLOR_ROOM_BORDER = 0; // Borde de cada miniroom
|
||||
static constexpr Uint8 COLOR_SHADOW = 1; // Sombra de cada miniroom
|
||||
static constexpr Uint8 COLOR_NUMBER_TEXT = 15; // Texto de números (blanco)
|
||||
static constexpr Uint8 COLOR_NUMBER_SHADOW = 1; // Sombra de números (oscuro)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user