les tecles de control estan definides al fitxer de configuracio
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include <unordered_map> // Para unordered_map, _Node_iterator, operator==, _Node_iterator_base, _Node_const_iterator
|
||||
#include <utility> // Para pair, move
|
||||
|
||||
#include "game/options.hpp" // Para Options::controls
|
||||
|
||||
// Singleton
|
||||
Input* Input::instance = nullptr;
|
||||
|
||||
@@ -26,8 +28,7 @@ auto Input::get() -> Input* { return Input::instance; }
|
||||
Input::Input(std::string game_controller_db_path, std::string gamepad_configs_file)
|
||||
: gamepad_mappings_file_(std::move(game_controller_db_path)),
|
||||
gamepad_configs_file_(std::move(gamepad_configs_file)) {
|
||||
// Inicializa el subsistema SDL_INIT_GAMEPAD
|
||||
initSDLGamePad();
|
||||
initSDLGamePad(); // Inicializa el subsistema SDL_INIT_GAMEPAD
|
||||
}
|
||||
|
||||
// Asigna inputs a teclas
|
||||
@@ -35,6 +36,13 @@ void Input::bindKey(Action action, SDL_Scancode code) {
|
||||
keyboard_.bindings[action].scancode = code;
|
||||
}
|
||||
|
||||
// Aplica las teclas configuradas desde Options
|
||||
void Input::applyKeyboardBindingsFromOptions() {
|
||||
bindKey(Action::LEFT, Options::controls.key_left);
|
||||
bindKey(Action::RIGHT, Options::controls.key_right);
|
||||
bindKey(Action::JUMP, Options::controls.key_jump);
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(const std::shared_ptr<Gamepad>& gamepad, Action action, SDL_GamepadButton button) {
|
||||
if (gamepad != nullptr) {
|
||||
|
||||
@@ -121,6 +121,7 @@ class Input {
|
||||
|
||||
// --- Métodos de configuración de controles ---
|
||||
void bindKey(Action action, SDL_Scancode code);
|
||||
void applyKeyboardBindingsFromOptions(); // Aplica las teclas configuradas desde Options
|
||||
static void bindGameControllerButton(const std::shared_ptr<Gamepad>& gamepad, Action action, SDL_GamepadButton button);
|
||||
static void bindGameControllerButton(const std::shared_ptr<Gamepad>& gamepad, Action action_target, Action action_source);
|
||||
|
||||
|
||||
@@ -140,6 +140,9 @@ Director::Director(std::vector<std::string> const& args) {
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"), Asset::get()->get("controllers.json")); // Carga configuración de controles
|
||||
#endif
|
||||
|
||||
// Aplica las teclas configuradas desde Options
|
||||
Input::get()->applyKeyboardBindingsFromOptions();
|
||||
|
||||
Debug::init();
|
||||
|
||||
// Special handling for cheevos.bin - also needs filesystem path
|
||||
|
||||
@@ -7,26 +7,20 @@
|
||||
|
||||
// Forward declarations from Options namespace
|
||||
namespace Options {
|
||||
enum class ControlScheme;
|
||||
//enum class ControlScheme;
|
||||
enum class NotificationPosition;
|
||||
} // namespace Options
|
||||
|
||||
namespace GameDefaults {
|
||||
|
||||
// =============================================================================
|
||||
// GAME
|
||||
// =============================================================================
|
||||
constexpr int GAME_WIDTH = 256; // Ancho de la ventana por defecto
|
||||
constexpr int GAME_HEIGHT = 192; // Alto de la ventana por defecto
|
||||
|
||||
// =============================================================================
|
||||
// WINDOW
|
||||
// =============================================================================
|
||||
constexpr int WINDOW_ZOOM = 2; // Zoom de la ventana por defecto
|
||||
|
||||
// =============================================================================
|
||||
// VIDEO
|
||||
// =============================================================================
|
||||
constexpr bool VIDEO_MODE = false; // Modo de pantalla completa por defecto (false = ventana)
|
||||
constexpr ScreenFilter VIDEO_FILTER = ScreenFilter::NEAREST; // Filtro por defecto
|
||||
constexpr bool VIDEO_VERTICAL_SYNC = true; // Vsync activado por defecto
|
||||
@@ -35,16 +29,12 @@ constexpr bool VIDEO_INTEGER_SCALE = true; // Escalado entero
|
||||
constexpr bool VIDEO_KEEP_ASPECT = true; // Mantener aspecto activado por defecto
|
||||
constexpr const char* PALETTE_NAME = "zx-spectrum"; // Paleta por defecto
|
||||
|
||||
// =============================================================================
|
||||
// BORDER
|
||||
// =============================================================================
|
||||
constexpr bool BORDER_ENABLED = true; // Borde activado por defecto
|
||||
constexpr int BORDER_WIDTH = 32; // Ancho del borde por defecto
|
||||
constexpr int BORDER_HEIGHT = 24; // Alto del borde por defecto
|
||||
|
||||
// =============================================================================
|
||||
// AUDIO
|
||||
// =============================================================================
|
||||
constexpr float AUDIO_VOLUME = 1.0F; // Volumen por defecto
|
||||
constexpr bool AUDIO_ENABLED = true; // Audio por defecto
|
||||
|
||||
@@ -56,15 +46,11 @@ constexpr bool MUSIC_ENABLED = true; // Musica habilitada por defecto
|
||||
constexpr float SOUND_VOLUME = 1.0F; // Volumen por defecto de los efectos de sonido
|
||||
constexpr bool SOUND_ENABLED = true; // Sonido habilitado por defecto
|
||||
|
||||
// =============================================================================
|
||||
// NOTIFICATIONS
|
||||
// =============================================================================
|
||||
constexpr bool NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto
|
||||
const Uint8 NOTIFICATION_COLOR = static_cast<Uint8>(PaletteColor::BLUE); // Color de las notificaciones por defecto
|
||||
|
||||
// =============================================================================
|
||||
// OTHER
|
||||
// =============================================================================
|
||||
constexpr bool CONSOLE = false; // Consola desactivada por defecto
|
||||
constexpr const char* VERSION = "1.10"; // Versión por defecto
|
||||
|
||||
|
||||
@@ -171,6 +171,14 @@ auto saveToFile(const std::string& file_path) -> bool {
|
||||
file << "# Paleta\n";
|
||||
file << "video.palette " << video.palette << "\n";
|
||||
|
||||
file << "\n## CONTROLS\n";
|
||||
file << "# Tecla para mover a la izquierda (SDL_Scancode)\n";
|
||||
file << "controls.left " << static_cast<int>(controls.key_left) << "\n\n";
|
||||
file << "# Tecla para mover a la derecha (SDL_Scancode)\n";
|
||||
file << "controls.right " << static_cast<int>(controls.key_right) << "\n\n";
|
||||
file << "# Tecla para saltar (SDL_Scancode)\n";
|
||||
file << "controls.jump " << static_cast<int>(controls.key_jump) << "\n";
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
|
||||
@@ -224,6 +232,18 @@ auto setOptions(const std::string& var, const std::string& value) -> bool {
|
||||
}},
|
||||
{"video.palette", [](const std::string& v) {
|
||||
video.palette = v;
|
||||
}},
|
||||
{"controls.left", [](const std::string& v) {
|
||||
int val = safeStoi(v, SDL_SCANCODE_LEFT);
|
||||
controls.key_left = static_cast<SDL_Scancode>(val);
|
||||
}},
|
||||
{"controls.right", [](const std::string& v) {
|
||||
int val = safeStoi(v, SDL_SCANCODE_RIGHT);
|
||||
controls.key_right = static_cast<SDL_Scancode>(val);
|
||||
}},
|
||||
{"controls.jump", [](const std::string& v) {
|
||||
int val = safeStoi(v, SDL_SCANCODE_UP);
|
||||
controls.key_jump = static_cast<SDL_Scancode>(val);
|
||||
}}};
|
||||
|
||||
auto it = OPTION_HANDLERS.find(var);
|
||||
|
||||
@@ -13,11 +13,13 @@
|
||||
// --- Namespace Options: gestión de configuración y opciones del juego ---
|
||||
namespace Options {
|
||||
// Tipos de control de teclado
|
||||
/*
|
||||
enum class ControlScheme {
|
||||
CURSOR,
|
||||
OPQA,
|
||||
WASD
|
||||
};
|
||||
*/
|
||||
|
||||
} // namespace Options
|
||||
|
||||
@@ -40,6 +42,22 @@ struct Notification {
|
||||
color(c) {}
|
||||
};
|
||||
|
||||
// Estructura para las opciones de control de teclado
|
||||
struct ControlScheme {
|
||||
SDL_Scancode key_left{SDL_SCANCODE_LEFT}; // Tecla para mover a la izquierda
|
||||
SDL_Scancode key_right{SDL_SCANCODE_RIGHT}; // Tecla para mover a la derecha
|
||||
SDL_Scancode key_jump{SDL_SCANCODE_UP}; // Tecla para saltar
|
||||
|
||||
// Constructor por defecto
|
||||
ControlScheme() = default;
|
||||
|
||||
// Constructor
|
||||
ControlScheme(SDL_Scancode left, SDL_Scancode right, SDL_Scancode jump)
|
||||
: key_left(left),
|
||||
key_right(right),
|
||||
key_jump(jump) {}
|
||||
};
|
||||
|
||||
// Estructura para albergar trucos
|
||||
struct Cheat {
|
||||
enum class State : bool {
|
||||
@@ -215,7 +233,7 @@ inline Stats stats{}; // Datos con las estadisticas
|
||||
inline Notification notifications{}; // Opciones relativas a las notificaciones;
|
||||
inline Window window{}; // Opciones relativas a la ventana
|
||||
inline Audio audio{}; // Opciones relativas al audio
|
||||
inline ControlScheme keys{ControlScheme::CURSOR}; // Teclas usadas para jugar
|
||||
inline ControlScheme controls{}; // Teclas usadas para jugar
|
||||
|
||||
// --- Funciones ---
|
||||
void init(); // Crea e inicializa las opciones del programa
|
||||
|
||||
@@ -57,8 +57,9 @@ void Credits::handleInput() {
|
||||
|
||||
// Inicializa los textos
|
||||
void Credits::iniTexts() {
|
||||
std::string keys;
|
||||
std::string keys = "CURSORS";
|
||||
|
||||
/*
|
||||
switch (Options::keys) {
|
||||
case Options::ControlScheme::CURSOR:
|
||||
keys = "CURSORS";
|
||||
@@ -72,6 +73,7 @@ void Credits::iniTexts() {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
texts_.clear();
|
||||
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
|
||||
|
||||
Reference in New Issue
Block a user