R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ConfirmQuitMenu.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** r-type
4** File description:
5** ConfirmQuitMenu - Quit confirmation dialog (business logic)
6*/
7
9#include "../common/Logger/Logger.hpp"
10
11namespace Game {
13
15 if (!_menu) {
16 return;
17 }
18
19 _menu->Clear();
20
21 const float buttonWidth = 280.0f;
22 const float buttonHeight = 50.0f;
23 const float spacing = 18.0f;
24
25 // 2 buttons stack, centered
26 const float totalHeight = (buttonHeight * 2.0f) + spacing;
27 const float offsets[2] = {-(totalHeight / 2.0f) + (buttonHeight / 2.0f),
28 (totalHeight / 2.0f) - (buttonHeight / 2.0f)};
29
30 _menu->AddButton(CreateCenteredButton("YES, QUIT", offsets[0], buttonWidth, buttonHeight, 0xFFF44336,
31 0xFFE57373, [this]() { OnConfirmClicked(); }));
32 _menu->AddButton(CreateCenteredButton("NO", offsets[1], buttonWidth, buttonHeight, 0xFF424242,
33 0xFF616161, [this]() { OnCancelClicked(); }));
34 }
35
36 void ConfirmQuitMenu::SetOnConfirm(std::function<void()> callback) {
37 _onConfirm = std::move(callback);
38 }
39
40 void ConfirmQuitMenu::SetOnCancel(std::function<void()> callback) {
41 _onCancel = std::move(callback);
42 }
43
45 LOG_INFO("[ConfirmQuitMenu] Quit confirmed");
46 if (_onConfirm) {
47 _onConfirm();
48 }
49 }
50
52 LOG_INFO("[ConfirmQuitMenu] Quit canceled");
53 if (_onCancel) {
54 _onCancel();
55 } else {
56 Hide();
57 }
58 }
59} // namespace Game
#define LOG_INFO(...)
Definition Logger.hpp:181
Base class for all menu implementations.
Definition BaseMenu.hpp:26
std::shared_ptr< UI::IMenu > _menu
Definition BaseMenu.hpp:101
std::shared_ptr< UI::IButton > CreateCenteredButton(const char *label, float offsetY, float width, float height, unsigned int backgroundColor, unsigned int hoverColor, std::function< void()> callback)
Create a button with standard styling and positioning.
Definition BaseMenu.cpp:60
virtual void Hide()
Hide the menu.
Definition BaseMenu.cpp:34
void SetOnCancel(std::function< void()> callback)
Set callback invoked when user cancels.
ConfirmQuitMenu(UI::IUIFactory &uiFactory)
Construct a new ConfirmQuitMenu.
std::function< void()> _onConfirm
void SetOnConfirm(std::function< void()> callback)
Set callback invoked when user confirms quit.
std::function< void()> _onCancel
void Initialize() override
Initialize UI elements (creates buttons).
Abstract factory interface for creating UI elements.