Files
coffee_crisis_arcade_edition/source/define_buttons.h

72 lines
2.4 KiB
C++

#pragma once
#include <SDL3/SDL.h>
#include <cstddef>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "input.h"
#include "ui/window_message.h"
namespace Options {
struct Gamepad;
}
class DefineButtons {
public:
struct Button {
std::string label;
Input::Action action;
SDL_GamepadButton button;
Button(std::string label, Input::Action action, SDL_GamepadButton button)
: label(std::move(label)), action(action), button(button) {}
};
DefineButtons();
~DefineButtons() = default;
void render();
void update();
void checkEvents(const SDL_Event &event);
auto enable(Options::Gamepad *options_gamepad) -> bool;
void disable();
bool isReadyToClose() const;
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
[[nodiscard]] auto isFinished() const -> bool { return finished_; }
private:
// Constante para cuánto tiempo mostrar el mensaje (en frames)
static constexpr size_t MESSAGE_DISPLAY_FRAMES = 180; // ~3 segundos a 60fps
// Punteros
Input *input_ = nullptr; // Entrada del usuario
Options::Gamepad *options_gamepad_ = nullptr; // Opciones del gamepad
std::unique_ptr<WindowMessage> window_message_; // Mensaje de ventana
// Vectores y strings
std::vector<Button> buttons_; // Lista de botones
std::vector<std::string> controller_names_; // Nombres de los controladores
// size_t
size_t index_button_ = 0; // Índice del botón seleccionado
size_t message_timer_ = 0; // Contador de frames para el mensaje
// bools
bool enabled_ = false; // Flag para indicar si está activo
bool finished_ = false; // Flag para indicar si ha terminado
bool closing_ = false; // Flag para indicar que está cerrando
bool message_shown_ = false; // Flag para indicar que ya mostró el mensaje
// Métodos
void incIndexButton();
void doControllerButtonDown(const SDL_GamepadButtonEvent &event);
void bindButtons(Options::Gamepad *options_gamepad);
auto checkButtonNotInUse(SDL_GamepadButton button) -> bool;
void clearButtons();
void checkEnd();
void updateWindowMessage();
};