claude: acabat de posar tot lo que deia i reventa. Debuggar
This commit is contained in:
@@ -33,10 +33,12 @@ set(APP_SOURCES
|
||||
source/writer.cpp
|
||||
|
||||
# --- UI (User Interface) ---
|
||||
source/ui/menu_option.cpp
|
||||
source/ui/menu_renderer.cpp
|
||||
source/ui/notifier.cpp
|
||||
source/ui/service_menu.cpp
|
||||
source/ui/ui_message.cpp
|
||||
source/ui/window_message.cpp
|
||||
|
||||
# --- Lógica del Juego ---
|
||||
source/balloon_formations.cpp
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "input.h"
|
||||
|
||||
class WindowMessage;
|
||||
#include "ui/window_message.h"
|
||||
|
||||
namespace Options {
|
||||
struct Gamepad;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "mouse.h" // Para handleEvent
|
||||
#include "screen.h"
|
||||
#include "section.hpp" // Para Name, Options, name, options
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
|
||||
namespace GlobalEvents {
|
||||
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
||||
@@ -29,6 +30,16 @@ void check(const SDL_Event &event) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ServiceMenu::get()->isEnabled()) {
|
||||
ServiceMenu::get()->handleEvent(event); // Método que vamos a crear
|
||||
|
||||
// Si DefineButtons está activo, no procesar más eventos
|
||||
if (ServiceMenu::get()->isDefiningButtons()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Mouse::handleEvent(event);
|
||||
|
||||
static auto *input_ = Input::get();
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "menu_option.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class ActionListOption : public MenuOption {
|
||||
public:
|
||||
using ValueGetter = std::function<std::string()>;
|
||||
using ValueSetter = std::function<void(const std::string&)>;
|
||||
using ActionExecutor = std::function<void()>;
|
||||
|
||||
ActionListOption(
|
||||
const std::string& caption,
|
||||
ServiceMenu::SettingsGroup group,
|
||||
std::vector<std::string> options,
|
||||
ValueGetter getter,
|
||||
ValueSetter setter,
|
||||
ActionExecutor action_executor,
|
||||
bool hidden = false
|
||||
);
|
||||
|
||||
// Implementaciones de MenuOption
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override;
|
||||
[[nodiscard]] auto getValueAsString() const -> std::string override;
|
||||
[[nodiscard]] auto getMaxValueWidth(Text* text) const -> int override;
|
||||
void adjustValue(bool up) override;
|
||||
void executeAction() override;
|
||||
void sync(); //override;
|
||||
|
||||
private:
|
||||
std::vector<std::string> options_;
|
||||
ValueGetter value_getter_;
|
||||
ValueSetter value_setter_;
|
||||
ActionExecutor action_executor_;
|
||||
size_t current_index_;
|
||||
|
||||
void updateCurrentIndex();
|
||||
[[nodiscard]] auto findCurrentIndex() const -> size_t;
|
||||
};
|
||||
@@ -1,30 +1,9 @@
|
||||
#include "action_list_option.h"
|
||||
#include "menu_option.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "text.h"
|
||||
|
||||
ActionListOption::ActionListOption(
|
||||
const std::string& caption,
|
||||
ServiceMenu::SettingsGroup group,
|
||||
std::vector<std::string> options,
|
||||
ValueGetter getter,
|
||||
ValueSetter setter,
|
||||
ActionExecutor action_executor,
|
||||
bool hidden) : MenuOption(caption, group, hidden),
|
||||
options_(std::move(options)),
|
||||
value_getter_(std::move(getter)),
|
||||
value_setter_(std::move(setter)),
|
||||
action_executor_(std::move(action_executor)),
|
||||
current_index_(0) {
|
||||
updateCurrentIndex();
|
||||
}
|
||||
|
||||
auto ActionListOption::getBehavior() const -> Behavior {
|
||||
// Puede tanto ajustar valor (lista) como ejecutar acción (botón)
|
||||
return Behavior::BOTH;
|
||||
}
|
||||
|
||||
auto ActionListOption::getValueAsString() const -> std::string {
|
||||
if (value_getter_) {
|
||||
return value_getter_();
|
||||
@@ -174,3 +174,37 @@ class ActionOption : public MenuOption {
|
||||
private:
|
||||
std::function<void()> action_;
|
||||
};
|
||||
|
||||
// Opción de lista con acción
|
||||
class ActionListOption : public MenuOption {
|
||||
public:
|
||||
using ValueGetter = std::function<std::string()>;
|
||||
using ValueSetter = std::function<void(const std::string&)>;
|
||||
using ActionExecutor = std::function<void()>;
|
||||
|
||||
ActionListOption(const std::string& caption, ServiceMenu::SettingsGroup group,
|
||||
std::vector<std::string> options, ValueGetter getter, ValueSetter setter,
|
||||
ActionExecutor action_executor, bool hidden = false)
|
||||
: MenuOption(caption, group, hidden), options_(std::move(options)),
|
||||
value_getter_(std::move(getter)), value_setter_(std::move(setter)),
|
||||
action_executor_(std::move(action_executor)), current_index_(0) {
|
||||
updateCurrentIndex();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::BOTH; }
|
||||
[[nodiscard]] auto getValueAsString() const -> std::string override;
|
||||
[[nodiscard]] auto getMaxValueWidth(Text* text) const -> int override;
|
||||
void adjustValue(bool up) override;
|
||||
void executeAction() override;
|
||||
void sync(); // Sincroniza con el valor actual
|
||||
|
||||
private:
|
||||
std::vector<std::string> options_;
|
||||
ValueGetter value_getter_;
|
||||
ValueSetter value_setter_;
|
||||
ActionExecutor action_executor_;
|
||||
size_t current_index_;
|
||||
|
||||
void updateCurrentIndex();
|
||||
[[nodiscard]] auto findCurrentIndex() const -> size_t;
|
||||
};
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "section.hpp" // Para Name, name, Options, options
|
||||
#include "ui/ui_message.h" // Para UIMessage
|
||||
#include "utils.h" // Para Zone
|
||||
#include "action_list_option.h" // Para ActionListOption
|
||||
#include "define_buttons.h" // Para DefineButtons
|
||||
|
||||
// Singleton
|
||||
@@ -541,4 +540,76 @@ void ServiceMenu::setHiddenOptions() {
|
||||
}
|
||||
|
||||
updateMenu(); // El menú debe refrescarse si algo se oculta
|
||||
}
|
||||
|
||||
void ServiceMenu::handleEvent(const SDL_Event &event) {
|
||||
if (!enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Si DefineButtons está activo, que maneje todos los eventos
|
||||
if (define_buttons_ && define_buttons_->isEnabled()) {
|
||||
define_buttons_->checkEvents(event);
|
||||
return; // No procesar otros eventos mientras DefineButtons está activo
|
||||
}
|
||||
|
||||
// Procesar eventos normales del ServiceMenu
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
switch (event.key.key) {
|
||||
case SDLK_ESCAPE:
|
||||
case SDLK_BACKSPACE:
|
||||
moveBack();
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case SDLK_KP_ENTER:
|
||||
selectOption();
|
||||
break;
|
||||
case SDLK_UP:
|
||||
setSelectorUp();
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
setSelectorDown();
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
adjustOption(false);
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
adjustOption(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||
switch (event.gbutton.button) {
|
||||
case SDL_GAMEPAD_BUTTON_SOUTH:
|
||||
case SDL_GAMEPAD_BUTTON_BACK:
|
||||
moveBack();
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_EAST:
|
||||
case SDL_GAMEPAD_BUTTON_START:
|
||||
selectOption();
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_DPAD_UP:
|
||||
setSelectorUp();
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_DPAD_DOWN:
|
||||
setSelectorDown();
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_DPAD_LEFT:
|
||||
adjustOption(false);
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_DPAD_RIGHT:
|
||||
adjustOption(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,11 @@
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "ui_message.h" // Para UIMessage
|
||||
#include "define_buttons.h"
|
||||
|
||||
class MenuOption;
|
||||
class MenuRenderer;
|
||||
class DefineButtons; // Forward declaration
|
||||
//class DefineButtons; // Forward declaration
|
||||
|
||||
class ServiceMenu {
|
||||
public:
|
||||
@@ -55,6 +56,14 @@ class ServiceMenu {
|
||||
void moveBack();
|
||||
void checkEvents(const SDL_Event &event); // Nuevo método para eventos
|
||||
|
||||
// NUEVO: Método para manejar eventos (llamado desde GlobalEvents)
|
||||
void handleEvent(const SDL_Event &event);
|
||||
|
||||
// NUEVO: Getter para saber si DefineButtons está activo
|
||||
[[nodiscard]] auto isDefiningButtons() const -> bool {
|
||||
return define_buttons_ && define_buttons_->isEnabled();
|
||||
}
|
||||
|
||||
// --- Getters para que el Renderer pueda leer el estado ---
|
||||
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
|
||||
[[nodiscard]] auto getTitle() const -> const std::string & { return title_; }
|
||||
|
||||
Reference in New Issue
Block a user