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
11
namespace
Game
{
12
DefeatMenu::DefeatMenu
(
UI::IUIFactory
&uiFactory) :
BaseMenu
(uiFactory) {}
13
14
void
DefeatMenu::Initialize
() {
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,
27
WrapWithClickSound
([
this
]() {
OnReturnToMenuClicked
(); })));
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
38
void
DefeatMenu::Render
() {
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
46
BaseMenu::Render
();
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
52
void
DefeatMenu::OnReturnToMenuClicked
() {
53
LOG_INFO
(
"[DefeatMenu] Return to menu clicked"
);
54
if
(
_onReturnToMenu
) {
55
_onReturnToMenu
();
56
}
57
}
58
}
// namespace Game
DefeatMenu.hpp
LOG_INFO
#define LOG_INFO(...)
Definition
Logger.hpp:181
Game::BaseMenu
Base class for all menu implementations.
Definition
BaseMenu.hpp:26
Game::BaseMenu::_menu
std::shared_ptr< UI::IMenu > _menu
Definition
BaseMenu.hpp:101
Game::BaseMenu::CreateCenteredButton
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
Game::BaseMenu::Render
virtual void Render()
Render menu (should be called every frame).
Definition
BaseMenu.cpp:22
Game::BaseMenu::WrapWithClickSound
std::function< void()> WrapWithClickSound(std::function< void()> callback)
Wrap a callback to play click sound before executing.
Definition
BaseMenu.cpp:48
Game::BaseMenu::IsVisible
virtual bool IsVisible() const
Check if menu is currently visible.
Definition
BaseMenu.cpp:40
Game::DefeatMenu::Render
void Render() override
Custom render to display defeat message.
Definition
DefeatMenu.cpp:38
Game::DefeatMenu::_defeatReason
std::string _defeatReason
Definition
DefeatMenu.hpp:57
Game::DefeatMenu::_onReturnToMenu
std::function< void()> _onReturnToMenu
Definition
DefeatMenu.hpp:56
Game::DefeatMenu::OnReturnToMenuClicked
void OnReturnToMenuClicked()
Definition
DefeatMenu.cpp:52
Game::DefeatMenu::SetDefeatReason
void SetDefeatReason(const std::string &reason)
Set the defeat reason/message to display.
Definition
DefeatMenu.cpp:34
Game::DefeatMenu::DefeatMenu
DefeatMenu(UI::IUIFactory &uiFactory)
Construct a new DefeatMenu.
Definition
DefeatMenu.cpp:12
Game::DefeatMenu::Initialize
void Initialize() override
Initialize UI elements (creates buttons and text).
Definition
DefeatMenu.cpp:14
Game::DefeatMenu::SetOnReturnToMenu
void SetOnReturnToMenu(std::function< void()> callback)
Set callback invoked when user clicks return to menu button.
Definition
DefeatMenu.cpp:30
UI::IUIFactory
Abstract factory interface for creating UI elements.
Definition
IUIFactory.hpp:28
Game
Definition
AccessibilityMenu.cpp:13
client
Menu
DefeatMenu.cpp
Generated by
1.9.8