R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
AddServerMenu.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** r-type
4** File description:
5** AddServerMenu - Dialog for adding a new server to the list
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 {
28 class AddServerMenu : public BaseMenu {
29 public:
30 explicit AddServerMenu(UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics);
31 ~AddServerMenu() override = default;
32
37 void SetOnAdd(
38 std::function<void(const std::string &, const std::string &, const std::string &)> onAdd);
39
43 void SetOnCancel(std::function<void()> onCancel);
44
45 void Initialize() override;
46 void Update() override;
47 void Render() override;
48
49 private:
50 void OnAddClicked();
51 void OnCancelClicked();
52
53 // Helper methods to reduce duplication
54 std::unique_ptr<UI::ITextInput> CreateInput(float width, float height, float yPos,
55 const std::string &placeholder, int maxLength,
56 const std::string &regex, const std::string &logName);
57 void ClearInputs();
58
59 // Validation helpers
60 bool ValidateName(const std::string &name, std::string &errorMsg);
61 bool ValidateIP(const std::string &ip, std::string &errorMsg);
62 bool ValidatePort(const std::string &port, std::string &errorMsg);
63 void ClearError();
64
65 std::function<void(const std::string &, const std::string &, const std::string &)> _onAdd{};
66 std::function<void()> _onCancel{};
67
69
70 // Text inputs
71 std::unique_ptr<UI::ITextInput> _nameInput;
72 std::unique_ptr<UI::ITextInput> _ipInput;
73 std::unique_ptr<UI::ITextInput> _portInput;
74
75 // Error display
76 std::string _errorMessage;
77 bool _hasError{false};
78 enum class ErrorField { NONE, NAME, IP, PORT };
80
81 // Button positioning for error message
82 float _buttonsY{0.0f};
83 float _buttonHeight{0.0f};
84 };
85} // namespace Game
Dialog menu for adding a new server.
std::string _errorMessage
void Update() override
Update menu state (should be called every frame).
std::unique_ptr< UI::ITextInput > CreateInput(float width, float height, float yPos, const std::string &placeholder, int maxLength, const std::string &regex, const std::string &logName)
Graphics::IGraphics & _graphics
void Render() override
Render menu (should be called every frame).
std::function< void(const std::string &, const std::string &, const std::string &)> _onAdd
~AddServerMenu() override=default
bool ValidateName(const std::string &name, std::string &errorMsg)
bool ValidatePort(const std::string &port, std::string &errorMsg)
std::unique_ptr< UI::ITextInput > _nameInput
bool ValidateIP(const std::string &ip, std::string &errorMsg)
void SetOnCancel(std::function< void()> onCancel)
Set callback triggered when the Cancel button is clicked.
std::function< void()> _onCancel
void Initialize() override
Initialize menu (must be implemented by derived classes).
std::unique_ptr< UI::ITextInput > _portInput
std::unique_ptr< UI::ITextInput > _ipInput
void SetOnAdd(std::function< void(const std::string &, const std::string &, const std::string &)> onAdd)
Set callback triggered when the Add button is clicked.
Base class for all menu implementations.
Definition BaseMenu.hpp:26
Abstract interface for graphics rendering operations.
Definition IGraphics.hpp:32
Abstract factory interface for creating UI elements.