15#include <SFML/Window/Joystick.hpp>
33 std::function<
void(
GameState)> changeState)
34 : _uiRegistry(uiRegistry),
36 _translationManager(translationManager),
38 _uiFactory(uiFactory),
39 _changeState(changeState),
40 _worldRegistry(worldRegistry),
41 _worldBuilder(worldBuilder)
57 levelMusic.
audioPath =
"assets/musics/lvl1.mp3";
59 levelMusic.
loop =
true;
61 levelMusic.
dirty =
true;
65 log::warning(
"Failed to spawn entity for Level 1 music");
77 auto &buttons = buttonsOpt.value().get();
80 panel.idleColor[0] = 20; panel.idleColor[1] = 20; panel.idleColor[2] = 20;
81 panel.hoverColor[0] = 20; panel.hoverColor[1] = 20; panel.hoverColor[2] = 20;
82 panel.pressedColor[0] = 20; panel.pressedColor[1] = 20; panel.pressedColor[2] = 20;
90 "assets/fonts/main.ttf",
100 auto e = eRes.value();
104 t.
fontPath =
"assets/fonts/main.ttf";
113 _hudHealth = makeHudText({980.0f, 18.0f}, 18, {110, 220, 170});
114 _hudScore = makeHudText({980.0f, 42.0f}, 18, {120, 190, 230});
115 _hudAmmo = makeHudText({980.0f, 66.0f}, 16, {230, 190, 120});
116 _hudFps = makeHudText({980.0f, 90.0f}, 14, {180, 180, 190});
118 _hudPing = makeHudText({1020.0f, 660.0f}, 12, {140, 140, 150});
119 _hudEntities = makeHudText({1020.0f, 678.0f}, 12, {140, 140, 150});
131 auto &sliders = slidersOpt.value().get();
134 slider.trackColor[0] = 25; slider.trackColor[1] = 25; slider.trackColor[2] = 25;
135 slider.fillColor[0] = 180; slider.fillColor[1] = 120; slider.fillColor[2] = 60;
136 slider.handleColor[0] = 25; slider.handleColor[1] = 25; slider.handleColor[2] = 25;
157 static bool wasPausePressed =
false;
160 if (isPausePressed && !wasPausePressed) {
163 wasPausePressed =
true;
167 wasPausePressed =
true;
170 wasPausePressed = isPausePressed;
173 if (
const auto* kp = e.getIf<sf::Event::KeyPressed>()) {
174 if (kp->code == sf::Keyboard::Key::Enter) {
179 bool focused =
false;
181 auto &inputs = inputsOpt.
value().get();
190 }
else if (kp->code == sf::Keyboard::Key::Escape) {
223 if (!textsOpt)
return;
224 auto& texts = textsOpt.value().get();
233 texts[
_hudHealth].content =
"HP " + std::to_string(current) +
" / " + std::to_string(max);
241 const std::size_t count = spritesOpt.value().get().size();
242 texts[
_hudEntities].content =
"Entities " + std::to_string(count + 2);
248 std::string ammoText =
"AMMO " + std::to_string(current) +
" / " + std::to_string(max);
251 ammoText +=
" (Reloading " + std::to_string(remaining).substr(0, 4) +
"s)";
266 constexpr float kChargeMax = 2.0f;
272 auto &inputs = inputsOpt.
value().get();
273 for (
const auto &e : inputs.entities()) {
274 if (inputs[e].isFocused) {
299 constexpr float baseTextureWidth = 1280.0f;
302 const float scaledW = baseTextureWidth * t.scale.x;
311 t.position.x = scaledW;
361 auto &inputs = inputsOpt.
value().get();
366 const std::string message = input.value;
390 auto &buttons = buttonsOpt.value().get();
393 panel.idleColor[0] = 20; panel.idleColor[1] = 20; panel.idleColor[2] = 20;
394 panel.hoverColor[0] = 20; panel.hoverColor[1] = 20; panel.hoverColor[2] = 20;
395 panel.pressedColor[0] = 20; panel.pressedColor[1] = 20; panel.pressedColor[2] = 20;
403 "assets/fonts/main.ttf",
413 "assets/fonts/main.ttf",
421 auto &inputs = inputsOpt.value().get();
423 inputs[
_chatInput].onSubmit = [
this](
const std::string&) {
453 auto &texts = textsOpt.value().get();
458 std::string combined;
459 for (
const auto &line : history) {
460 if (!combined.empty())
auto spawn(const EntityTemplate &t) -> std::expected< ecs::Entity, Error >
System to handle network-related operations on the client side.
uint16_t getAmmoCurrent(void) const
bool isReloading(void) const
uint32_t getPingMs(void) const
int getHealthCurrent(void) const
bool consumeGameOver(void)
uint16_t getAmmoMax(void) const
float getReloadCooldownRemaining(void) const
uint32_t getCurrentLevelId(void) const
Get the current level ID for client-side visuals (parallax)
int getHealthMax(void) const
void trySendMessage(const std::string &message) const
Send a chat message to the server.
std::string getLastChatMessage(void) const
Get the last received room chat message.
const std::deque< std::string > & getChatHistory(void) const
Get chat history buffer (most recent last)
Manages game settings and preferences.
sf::Keyboard::Key getKey(KeyAction action) const
bool getGamepadEnabled() const
unsigned int getGamepadPauseButton() const
Manages game translations for all UI elements.
Factory class for creating UI components in the ECS registry.
static ecs::Entity createTextInput(ecs::Registry ®istry, const position &position, const size &size, const std::string &fontPath, unsigned int fontSize, const int maxLength=64, const std::string &placeholder="", std::function< void(const std::string &)> onSubmit=nullptr, std::function< void(const std::string &)> onChange=nullptr)
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 createSlider(ecs::Registry ®istry, const position &position, const size &size, float minValue, float maxValue, float initialValue, std::function< void(float)> onChange=nullptr)
uint32_t _uiPing
Current ping in the UI.
EntityBuilder & _worldBuilder
Reference to the world entity builder.
void handleEvent(const sf::Event &event) override
Handle an incoming event.
graphics::UiFactory & _uiFactory
UI Factory for creating UI components.
ecs::Entity _hudFps
Entity for displaying FPS in the HUD.
bool _chatOpen
Whether expanded chat is open.
PlayingScene(ecs::Registry &worldRegistry, ecs::Registry &uiRegistry, Settings &settings, TranslationManager &translationManager, NetworkSyncSystem &network, graphics::UiFactory &uiFactory, EntityBuilder &worldBuilder, std::function< void(GameState)> changeState)
Constructor for PlayingScene.
uint32_t _uiFps
Current FPS in the UI.
void onExit(void) override
Called when the scene is exited.
ChangeStateFn _changeState
Function to change the game state.
ecs::Entity _chatCompactPanel
Compact chat background panel.
void onEnter(void) override
Called when the scene is entered.
void spawnParallax(void)
Spawn parallax background entities.
ecs::Entity _hudHealth
Entity for displaying health.
bool _hudInit
Flag indicating if HUD is initialized.
float _fpsTimer
FPS timer accumulator.
ecs::Entity _hudEntities
Parent entity for HUD elements.
float _chargeTime
Local charge timer for HUD.
ecs::Entity _chatHistoryText
Text entity for chat history.
ecs::Entity _hudAmmo
Entity for displaying ammo.
Settings & _settings
Reference to the application settings.
ecs::Entity _chatPanel
Expanded chat panel.
void update(float dt) override
Update the scene state.
ecs::Entity _chatCompactText
Text entity for last chat message.
NetworkSyncSystem & _network
Reference to the client network.
ecs::Registry & _uiRegistry
Reference to the ECS registry.
ecs::Entity _hudScore
Entity for displaying score in the HUD.
ecs::Entity _hudPing
Entity for displaying ping in the HUD.
ecs::Registry & _worldRegistry
Reference to the world ECS registry.
uint32_t _fpsFrames
FPS frame count.
ecs::Entity _hudChargeBar
Entity for charged shot HUD bar.
uint32_t _uiScore
Player score in the UI.
void sendChatMessage(void)
void updateChatHistoryText(void)
ecs::Entity _chatInput
Text input entity for chat.
Represents an entity in the ECS (Entity-Component-System) architecture.
constexpr bool isNull(void) const noexcept
auto spawn(void) -> std::expected< Entity, rtp::Error >
auto add(Entity entity, Args &&...args) -> std::expected< std::reference_wrapper< T >, rtp::Error >
auto get(this const Self &self) -> std::expected< std::reference_wrapper< ConstLike< Self, SparseArray< T > > >, rtp::Error >
@ Shoot
Action for shooting.
@ GameOver
Game over state.
@ Paused
Game paused 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.
static EntityTemplate createParallaxLvl3_1()
static EntityTemplate createParallaxLvl3_9()
static EntityTemplate createParallaxLvl4_3()
static EntityTemplate createParallaxLvl3_8()
static EntityTemplate createParallaxLvl3_4()
static EntityTemplate createParallaxLvl3_3()
static EntityTemplate createParallaxLvl4_4()
static EntityTemplate createParallaxLvl3_2()
static EntityTemplate createParallaxLvl3_5()
static EntityTemplate createParallaxLvl2_1()
static EntityTemplate createParrallaxLvl1_2()
static EntityTemplate createParallaxLvl4_5()
static EntityTemplate createParrallaxLvl1_1()
static EntityTemplate createParallaxLvl3_7()
static EntityTemplate createParallaxLvl4_1()
static EntityTemplate createParallaxLvl4_2()
static EntityTemplate createParallaxLvl4_6()
static EntityTemplate createParallaxLvl3_6()
Component representing a sprite.
Component for entities that emit continuous sound (music, loops, ambient)
std::string audioPath
Path to the audio file.
bool isPlaying
Current playback state.
bool dirty
Flag to indicate changes need to be applied.
float volume
Volume level (0.0 - 1.0)
bool loop
Whether the audio should loop.
Component for a draggable slider control.
Component representing text to render.
uint8_t green
Green component.
int zIndex
Rendering order.
uint8_t blue
Blue component.
Vec2f position
Position of the text.
uint8_t red
Red component.
uint8_t alpha
Alpha (opacity)
unsigned int fontSize
Font size.
std::string fontPath
Path to the font file.
std::string content
Text content.