Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
ConnectScene.h
Go to the documentation of this file.
1
6#ifndef _BOMBERMAN_SCENES_CONNECT_SCENE_H_
7#define _BOMBERMAN_SCENES_CONNECT_SCENE_H_
8
9#include <SDL.h>
10#include <cstdint>
11#include <memory>
12#include <string>
13#include <string_view>
14
15#include "Entities/Text.h"
17#include "Scenes/Scene.h"
18
19namespace bomberman
20{
28 class ConnectScene : public Scene
29 {
30 public:
37 ConnectScene(Game* game, uint16_t port);
38
40 void onEnter() override;
42 void onExit() override;
44 void onEvent(const SDL_Event& event) override;
46 void update(unsigned int delta) override;
47
48 private:
49 // Placeholder text also reused as fallback connect values when a field is left empty.
50 static constexpr std::string_view kDefaultPlayerName = "Player";
51 static constexpr std::string_view kDefaultHost = "127.0.0.1";
52
54 enum class FocusField : uint8_t
55 {
56 PlayerName = 0,
57 Host = 1,
58 ConnectButton = 2
59 };
60
61 // ----- Scene Flow and Status -----
62
67 void tryStartConnect();
68
75 void setConnectStatus(std::string_view message, SDL_Color color);
76
78 [[nodiscard]]
79 std::string_view effectivePlayerName() const;
81 [[nodiscard]]
82 std::string_view effectiveHost() const;
84 void restoreIdleStatusAfterHostEdit();
85
86 // ----- Form Helpers -----
87
89 void refreshFieldPresentation();
91 void cycleFocus(int direction);
93 void appendSanitizedFieldText(std::string& target, std::string_view chunk, bool isHostField);
94
96 [[nodiscard]]
97 int measureTextWidth(std::string_view text) const;
98 [[nodiscard]]
99 bool fitsFieldWidth(std::string_view text, bool isHostField) const;
100
102 [[nodiscard]]
103 static bool isValidHost(std::string_view host);
104
106 void recenterFieldValues();
107
108 // ----- UI Objects -----
109
110 std::shared_ptr<Text> titleText_ = nullptr;
111 std::shared_ptr<Text> playerNameLabelText_ = nullptr;
112 std::shared_ptr<Text> playerNameValueText_ = nullptr;
113 std::shared_ptr<Text> hostLabelText_ = nullptr;
114 std::shared_ptr<Text> hostValueText_ = nullptr;
115 std::shared_ptr<Text> portValueText_ = nullptr;
116 std::shared_ptr<Text> connectButtonText_ = nullptr;
117 std::shared_ptr<Text> statusText_ = nullptr;
118
119 // ----- Scene and Form State -----
120
121 FocusField focusedField_ = FocusField::PlayerName;
122 std::string playerName_;
123 std::string host_;
124 bool playerNameTouched_ = false;
125 bool hostTouched_ = false;
126 uint16_t port_ = 0;
127 bool transitionedToLobby_ = false;
129
130 // ----- Cached Layout -----
131
132 int playerNameFieldX_ = 0;
133 int playerNameFieldY_ = 0;
134 int playerNameFieldW_ = 0;
135 int hostFieldX_ = 0;
136 int hostFieldY_ = 0;
137 int hostFieldW_ = 0;
138 };
139} // namespace bomberman
140
141#endif // _BOMBERMAN_SCENES_CONNECT_SCENE_H_
Client-side multiplayer connection lifecycle and packet endpoint.
Pre-game multiplayer connect scene.
Definition ConnectScene.h:29
void update(unsigned int delta) override
Polls NetClient connection state and updates status/scene flow.
Definition ConnectScene.cpp:235
void onEvent(const SDL_Event &event) override
Handles field editing, connect submission, and local leave/cancel input.
Definition ConnectScene.cpp:137
void onExit() override
Disables SDL text input when leaving the connect form.
Definition ConnectScene.cpp:132
void onEnter() override
Enables SDL text input while the connect form is active.
Definition ConnectScene.cpp:127
Definition Game.h:23
Scene base class.
Definition Scene.h:17
EConnectState
Client connection lifecycle state.
Definition NetClient.h:25
@ Disconnected
Not connected and holding no transport resources.