9#include <SFML/Window/Joystick.hpp>
23 std::function<
void(
GameState)> changeState)
24 : _uiRegistry(UiRegistry),
26 _translationManager(translationManager),
28 _uiFactory(uiFactory),
29 _changeState(changeState)
35 log::info(
"Entering GamepadSettingsScene");
43 "assets/fonts/main.ttf",
54 "assets/fonts/main.ttf",
67 log::info(
"Gamepad {}", index == 1 ?
"enabled" :
"disabled");
78 "assets/fonts/main.ttf",
84 {540.0f, yPos + 3.0f},
99 {240.0f, yPos + 5.0f},
101 "assets/fonts/main.ttf",
124 {240.0f, yPos + 5.0f},
126 "assets/fonts/main.ttf",
149 {240.0f, yPos + 5.0f},
151 "assets/fonts/main.ttf",
175 "Movement: Left Stick or D-pad",
176 "assets/fonts/main.ttf",
209 for (
unsigned int i = 0; i < sf::Joystick::getButtonCount(0); ++i) {
210 if (sf::Joystick::isButtonPressed(0, i)) {
227 log::info(
"Gamepad button {} bound to action",
233 sf::sleep(sf::milliseconds(200));
240 if (
const auto* kp = event.getIf<sf::Event::KeyPressed>()) {
241 if (kp->code == sf::Keyboard::Key::Escape) {
269 unsigned int button = 0;
286 log::error(
"Failed to get Button components");
290 auto& buttons = buttonsRes.value().get();
292 if (!buttons.has(e)) {
297 buttons[e].text = buttonName;
302 static const std::vector<std::string> buttonNames = {
303 "A (0)",
"B (1)",
"X (2)",
"Y (3)",
304 "LB (4)",
"RB (5)",
"Back (6)",
"Start (7)",
305 "LS (8)",
"RS (9)",
"LT (10)",
"RT (11)"
308 if (button < buttonNames.size()) {
309 return buttonNames[button];
311 return "Button " + std::to_string(button);
System to handle network-related operations on the client side.
Manages game settings and preferences.
void setGamepadPauseButton(unsigned int button)
void setGamepadReloadButton(unsigned int button)
unsigned int getGamepadReloadButton() const
void setGamepadEnabled(bool enabled)
bool getGamepadEnabled() const
unsigned int getGamepadPauseButton() const
bool save(const std::string &filename="config/settings.cfg")
void setGamepadDeadzone(float deadzone)
unsigned int getGamepadShootButton() const
void setGamepadShootButton(unsigned int button)
float getGamepadDeadzone() const
Manages game translations for all UI elements.
std::string get(const std::string &key) const
Get translated string for a key.
Factory class for creating UI components in the ECS registry.
static ecs::Entity createText(ecs::Registry ®istry, const position &position, const std::string &content, const std::string &fontPath, unsigned int fontSize, const std::uint8_t zIndex=0, const color &textColor={255, 255, 255})
static ecs::Entity createButton(ecs::Registry ®istry, const position &position, const size &size, const std::string &label, std::function< void()> onClick=nullptr)
Create a button UI component.
static ecs::Entity createDropdown(ecs::Registry ®istry, const position &position, const size &size, const std::vector< std::string > &options, const int selectedIndex, std::function< void(int index)> onSelect=nullptr)
static ecs::Entity createSlider(ecs::Registry ®istry, const position &position, const size &size, float minValue, float maxValue, float initialValue, std::function< void(float)> onChange=nullptr)
ChangeStateFn _changeState
GamepadAction _actionToRebind
std::unordered_map< GamepadAction, ecs::Entity > _actionToButton
TranslationManager & _translationManager
void handleEvent(const sf::Event &event) override
Handle an incoming event.
GamepadSettingsScene(ecs::Registry &UiRegistry, Settings &settings, TranslationManager &translationManager, NetworkSyncSystem &network, graphics::UiFactory &uiFactory, std::function< void(GameState)> changeState)
void onEnter() override
Called when the scene is entered.
ecs::Registry & _uiRegistry
void refreshButtonLabel(GamepadAction action)
graphics::UiFactory & _uiFactory
void update(float dt) override
Update the scene state.
std::string getButtonName(unsigned int button) const
void onExit() override
Called when the scene is exited.
Represents an entity in the ECS (Entity-Component-System) architecture.
auto get(this const Self &self) -> std::expected< std::reference_wrapper< ConstLike< Self, SparseArray< T > > >, rtp::Error >
@ Settings
Settings menu state.
void error(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an error message.
void warning(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log a warning message.
void info(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an informational message.