From 050b6716bfd7c44c4e2c91e5dff058544b3654b9 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 4 Aug 2025 11:37:46 +0200 Subject: [PATCH] =?UTF-8?q?migrant=20input:=20commit=20abans=20que=20gemin?= =?UTF-8?q?i=20destro=C3=A7e=20algo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/define_buttons.cpp | 21 +++--- source/define_buttons.h | 15 ++-- source/director.cpp | 14 ++-- source/input.cpp | 25 +++++++ source/input.h | 5 +- source/options.cpp | 84 ++++++++++++--------- source/options.h | 150 +++++++++++++++++++++++++++++++++----- source/sections/game.cpp | 14 ++-- source/sections/title.cpp | 12 +-- source/sections/title.h | 4 +- 10 files changed, 245 insertions(+), 99 deletions(-) diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 1100663..bd1c732 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -12,11 +12,12 @@ // Constructor DefineButtons::DefineButtons() - : input_(Input::get()) { - // Inicializa variables - x_ = param.game.width / 2; - y_ = param.title.press_start_position; - + : input_(Input::get()), + enabled_(false), + finished_(false), + x_(param.game.width / 2), + y_(param.title.press_start_position), + index_button_(0) { clearButtons(); auto gamepads = input_->getGamepads(); @@ -29,8 +30,8 @@ DefineButtons::DefineButtons() void DefineButtons::render() { static auto text = Resource::get()->getText("8bithud"); if (enabled_) { - text->writeCentered(x_, y_ - 10, Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(static_cast(gamepad_options_->player_id))); - text->writeCentered(x_, y_, gamepad_options_->instance->name); + text->writeCentered(x_, y_ - 10, Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(static_cast(gamepad_->player_id))); + text->writeCentered(x_, y_, gamepad_->name); text->writeCentered(x_, y_ + 10, buttons_.at(index_button_).label); } } @@ -77,9 +78,9 @@ void DefineButtons::checkEvents(const SDL_Event &event) { } // Habilita el objeto -auto DefineButtons::enable(std::shared_ptr gamepad_options) -> bool { - if (gamepad_options != nullptr) { - gamepad_options_ = gamepad_options; +auto DefineButtons::enable(Options::Gamepad *gamepad) -> bool { + if (gamepad != nullptr) { + gamepad_ = gamepad; enabled_ = true; finished_ = false; index_button_ = 0; diff --git a/source/define_buttons.h b/source/define_buttons.h index dc46a16..fd4fc77 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -27,10 +27,10 @@ class DefineButtons { DefineButtons(); ~DefineButtons() = default; - void render(); // Dibuja el objeto en pantalla - void checkEvents(const SDL_Event &event); // Procesa los eventos - auto enable(std::shared_ptr gamepad_options) -> bool; // Habilita la redefinición de botones - [[nodiscard]] auto isEnabled() const -> bool { return enabled_; }; // Comprueba si está habilitado + void render(); // Dibuja el objeto en pantalla + void checkEvents(const SDL_Event &event); // Procesa los eventos + auto enable(Options::Gamepad *gamepad) -> bool; // Habilita la redefinición de botones + [[nodiscard]] auto isEnabled() const -> bool { return enabled_; }; // Comprueba si está habilitado private: // Objetos @@ -38,12 +38,13 @@ class DefineButtons { // Variables bool enabled_ = false; // Indica si está activo - int x_ = 0, y_ = 0; // Coordenadas de texto + bool finished_ = false; // Indica si ha terminado + int x_ = 0; // Coordenadas de texto + int y_ = 0; // Coordenadas de texto std::vector