R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
DefeatMenu.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** r-type
4** File description:
5** DefeatMenu - Game over defeat screen
6*/
7
8#include "Menu/DefeatMenu.hpp"
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 = 300.0f;
22 const float buttonHeight = 60.0f;
23
24 // Single "Return to Menu" button, centered below the defeat message
25 _menu->AddButton(CreateCenteredButton("RETURN TO MENU", 100.0f, buttonWidth, buttonHeight, 0xFF1976D2,
26 0xFF42A5F5,
28 }
29
30 void DefeatMenu::SetOnReturnToMenu(std::function<void()> callback) {
31 _onReturnToMenu = std::move(callback);
32 }
33
34 void DefeatMenu::SetDefeatReason(const std::string &reason) {
35 _defeatReason = reason;
36 }
37
39 if (!IsVisible()) {
40 return;
41 }
42
43 // Draw dark overlay background
44 // This will be rendered by the graphics system
45 // For now, just call the base menu render which will draw buttons
47
48 // Note: The defeat text will need to be drawn by the graphics system
49 // in the GameLoop's render method when this menu is active
50 }
51
53 LOG_INFO("[DefeatMenu] Return to menu clicked");
54 if (_onReturnToMenu) {
56 }
57 }
58} // 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 Render()
Render menu (should be called every frame).
Definition BaseMenu.cpp:22
std::function< void()> WrapWithClickSound(std::function< void()> callback)
Wrap a callback to play click sound before executing.
Definition BaseMenu.cpp:48
virtual bool IsVisible() const
Check if menu is currently visible.
Definition BaseMenu.cpp:40
void Render() override
Custom render to display defeat message.
std::string _defeatReason
std::function< void()> _onReturnToMenu
void OnReturnToMenuClicked()
void SetDefeatReason(const std::string &reason)
Set the defeat reason/message to display.
DefeatMenu(UI::IUIFactory &uiFactory)
Construct a new DefeatMenu.
void Initialize() override
Initialize UI elements (creates buttons and text).
void SetOnReturnToMenu(std::function< void()> callback)
Set callback invoked when user clicks return to menu button.
Abstract factory interface for creating UI elements.