R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ConnectionMenu.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** r-type
4** File description:
5** ConnectionMenu - Menu for entering connection details (nickname, IP, port)
6*/
7
8#pragma once
9
10#include <functional>
11#include <memory>
12
14#include "Menu/BaseMenu.hpp"
15#include "UI/ITextInput.hpp"
16#include "UI/IUIFactory.hpp"
17
18namespace Game {
29 class ConnectionMenu : public BaseMenu {
30 public:
31 explicit ConnectionMenu(UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics);
32 ~ConnectionMenu() override = default;
33
38 void SetOnJoin(
39 std::function<void(const std::string &, const std::string &, const std::string &)> onJoin);
40
44 void SetOnBack(std::function<void()> onBack);
45
46 void Initialize() override;
47 void Update() override;
48 void Render() override;
49
50 private:
51 void OnJoinClicked();
52 void OnBackClicked();
53
54 // Validation helpers
55 bool ValidateNickname(const std::string &nickname, std::string &errorMsg);
56 bool ValidateIP(const std::string &ip, std::string &errorMsg);
57 bool ValidatePort(const std::string &port, std::string &errorMsg);
58 void ClearError();
59
60 std::function<void(const std::string &, const std::string &, const std::string &)> _onJoin{};
61 std::function<void()> _onBack{};
62
64
65 // Text inputs
66 std::unique_ptr<UI::ITextInput> _nicknameInput;
67 std::unique_ptr<UI::ITextInput> _ipInput;
68 std::unique_ptr<UI::ITextInput> _portInput;
69
70 // Error display
71 std::string _errorMessage;
72 bool _hasError{false};
73 enum class ErrorField { NONE, NICKNAME, IP, PORT };
75
76 // Button positioning for error message
77 float _buttonsY{0.0f};
78 float _buttonHeight{0.0f};
79 };
80} // namespace Game
Base class for all menu implementations.
Definition BaseMenu.hpp:26
Connection menu for entering player nickname, server IP, and port.
void Render() override
Render menu (should be called every frame).
std::unique_ptr< UI::ITextInput > _ipInput
~ConnectionMenu() override=default
std::function< void(const std::string &, const std::string &, const std::string &)> _onJoin
void Update() override
Update menu state (should be called every frame).
void SetOnBack(std::function< void()> onBack)
Set callback triggered when the Back button is clicked.
std::function< void()> _onBack
bool ValidateIP(const std::string &ip, std::string &errorMsg)
bool ValidateNickname(const std::string &nickname, std::string &errorMsg)
void Initialize() override
Initialize menu (must be implemented by derived classes).
std::unique_ptr< UI::ITextInput > _portInput
Graphics::IGraphics & _graphics
std::unique_ptr< UI::ITextInput > _nicknameInput
bool ValidatePort(const std::string &port, std::string &errorMsg)
void SetOnJoin(std::function< void(const std::string &, const std::string &, const std::string &)> onJoin)
Set callback triggered when the Join button is clicked.
Abstract interface for graphics rendering operations.
Definition IGraphics.hpp:32
Abstract factory interface for creating UI elements.