22 std::function<
void(
GameState)> changeState)
23 : _uiRegistry(UiRegistry),
25 _translationManager(translationManager),
27 _uiFactory(uiFactory),
28 _changeState(changeState)
40 "assets/fonts/main.ttf",
47 const float buttonSpacing = 60.0f;
49 struct KeyBindingButton {
54 std::vector<KeyBindingButton> bindings = {
63 for (
const auto& binding : bindings) {
66 {200.0f, yPos + 10.0f},
68 "assets/fonts/main.ttf",
79 [
this, actionToBind = binding.action]() {
86 yPos += buttonSpacing;
110 if (
const auto* kp = event.getIf<sf::Event::KeyPressed>()) {
111 if (kp->code == sf::Keyboard::Key::Escape) {
143 log::warning(
"No button found for action {}",
static_cast<int>(action));
154 log::error(
"Failed to get Button components");
158 auto& buttons = buttonsRes.value().get();
160 if (!buttons.has(e)) {
161 log::warning(
"Button component not found for entity {}",
static_cast<std::uint64_t
>(e));
165 buttons[e].text = keyName;
System to handle network-related operations on the client side.
Manages game settings and preferences.
std::string getKeyName(sf::Keyboard::Key key) const
void setKey(KeyAction action, sf::Keyboard::Key key)
sf::Keyboard::Key getKey(KeyAction action) const
bool save(const std::string &filename="config/settings.cfg")
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.
void refreshButtonLabel(KeyAction action)
Refresh the label of a button corresponding to a key action.
std::unordered_map< KeyAction, ecs::Entity > _actionToButton
Map of actions to their corresponding button entities.
Settings & _settings
Reference to the application settings.
TranslationManager & _translationManager
Reference to the translation manager.
graphics::UiFactory & _uiFactory
UI Factory for creating UI components.
KeyAction _actionToRebind
Action currently being rebound.
bool _isWaitingForKey
Flag indicating if waiting for key input.
void handleEvent(const sf::Event &event) override
Handle an incoming event.
ecs::Registry & _uiRegistry
Reference to the ECS registry.
ChangeStateFn _changeState
Function to change the game state.
void onExit(void) override
Called when the scene is exited.
KeyBindingScene(ecs::Registry ®istry, Settings &settings, TranslationManager &translationManager, NetworkSyncSystem &network, graphics::UiFactory &uiFactory, std::function< void(GameState)> changeState)
void onEnter(void) override
Called when the scene is entered.
void update(float dt) override
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 >
KeyAction
Actions that can be bound to keys.
@ Reload
Action for reloading.
@ MoveRight
Action for moving right.
@ MoveDown
Action for moving down.
@ MoveUp
Action for moving up.
@ Shoot
Action for shooting.
@ MoveLeft
Action for moving left.
@ 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.