59 lines
1.6 KiB
C++
59 lines
1.6 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();
|
|
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
|
|
[[nodiscard]] auto isFinished() const -> bool { return finished_; }
|
|
|
|
private:
|
|
Input *input_ = nullptr;
|
|
std::unique_ptr<WindowMessage> window_message_;
|
|
|
|
bool enabled_ = false;
|
|
bool finished_ = false;
|
|
std::vector<Button> buttons_;
|
|
size_t index_button_ = 0;
|
|
std::vector<std::string> controller_names_;
|
|
Options::Gamepad *options_gamepad_ = nullptr;
|
|
|
|
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();
|
|
}; |