Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
WinScreen.cpp
Go to the documentation of this file.
1
2
3#include "WinScreen.hpp"
4
5#include <cstdint>
6#include <string>
7
8#include "I18n.hpp"
9
10static constexpr float PANEL_MIN_W = 480.0f;
11static constexpr float BTN_W = 140.0f;
12static constexpr float BTN_H = 40.0f;
13static constexpr float BTN_MARGIN = 20.0f; // gap between last line and button
14static constexpr Color OVERLAY_COLOR = {0, 0, 0, 178};
15static constexpr Color PANEL_BORDER = {60, 70, 90, 200};
16static constexpr Color ACCENT = {210, 220, 240, 255};
17static constexpr Color TITLE_COLOR = {255, 220, 80, 255};
18
37
38void WinScreen::setWinner(const std::string& team, Color color)
39{
40 _winnerTeam = team;
41 _winnerColor = color;
42}
43
44void WinScreen::setDuration(int seconds, int64_t ticks)
45{
46 _durationSeconds = seconds;
47 _durationTicks = ticks;
48}
49
50std::string WinScreen::_formatDuration(unsigned int seconds)
51{
52 unsigned int h = seconds / 3600;
53 unsigned int m = (seconds % 3600) / 60;
54 unsigned int s = seconds % 60;
55 std::string out;
56 if (h > 0) out += std::to_string(h) + "h ";
57 if (m > 0 || h > 0) out += std::to_string(m) + "m ";
58 out += std::to_string(s) + "s";
59 return out;
60}
61
62void WinScreen::_rebuildPanel(int scaledFontSize) const
63{
64 (void)scaledFontSize;
66
67 // Title line
69
70 // "Team X won!"
73
74 // Duration line
75 if (_durationSeconds < 0) {
77 } else {
78 std::string durLine = std::string(I18n::get(I18n::Key::WIN_DURATION)) +
79 _formatDuration(static_cast<unsigned int>(_durationSeconds)) + " (" +
81 ")";
82 _panel.addLine(durLine, ACCENT);
83 }
84}
85
87{
90 return true; // overlay always consumes all input
91}
92
93void WinScreen::draw(int scaledFontSize) const
94{
95 int sw = GetScreenWidth();
96 int sh = GetScreenHeight();
97
98 // Full-screen dim
99 DrawRectangle(0, 0, sw, sh, OVERLAY_COLOR);
100
101 _rebuildPanel(scaledFontSize);
102 _panel.draw(scaledFontSize);
103
104 // Position Quit button in the reserved space at the bottom of the panel
106 Rectangle panelBounds = _panel.getLastBounds();
107 float btnX = panelBounds.x + (panelBounds.width - BTN_W) / 2.0f;
108 float btnY = panelBounds.y + panelBounds.height - BTN_H - BTN_MARGIN;
109 _quitBtn.setPosition(btnX, btnY).setSize(BTN_W, BTN_H);
110 _quitBtn.draw(scaledFontSize);
111}
static constexpr float PANEL_MIN_W
Definition WinScreen.cpp:10
static constexpr Color ACCENT
Definition WinScreen.cpp:16
static constexpr float BTN_W
Definition WinScreen.cpp:11
static constexpr Color OVERLAY_COLOR
Definition WinScreen.cpp:14
static constexpr Color PANEL_BORDER
Definition WinScreen.cpp:15
static constexpr float BTN_MARGIN
Definition WinScreen.cpp:13
static constexpr float BTN_H
Definition WinScreen.cpp:12
static constexpr Color TITLE_COLOR
Definition WinScreen.cpp:17
End-game overlay widget.
bool handleInput() override
void draw(int scaledFontSize) const override
Draws the widget.
bool wasClicked()
Returns true once per click, then resets.
ButtonWidget & setAnchor(Anchor anchor, float margin=10.0f)
Sets anchor: button is auto-positioned relative to screen edges.
ButtonWidget & setRoundness(float roundness)
ButtonWidget & setSize(float width, float height)
ButtonWidget & setBorderColor(Color color)
ButtonWidget & setPosition(float x, float y)
Sets the button position directly (requires Anchor::None).
@ None
No anchor: position set directly via setPosition().
ButtonWidget & setBorderThickness(float thickness)
ButtonWidget & setLabel(const std::string &label)
static const char * get(Key key)
Definition I18n.hpp:86
@ WIN_DURATION_UNKNOWN
TooltipWidget & addLine(const std::string &text, Color color=WHITE)
Adds a single-color text line.
TooltipWidget & setExtraBottomPadding(float px)
Adds extra blank space at the bottom of the box (e.g. to reserve room for a button).
TooltipWidget & clearLines()
Removes all lines.
TooltipWidget & setBorderColor(Color color)
TooltipWidget & setTextAlign(TextAlign align)
TooltipWidget & setAnchor(Anchor anchor, float margin=10.0f)
Auto-positioning relative to screen edges.
TooltipWidget & setMinWidth(float minWidth)
Override minimum panel width (0 = fit to content).
TooltipWidget & setBackgroundColor(Color color)
TooltipWidget & setPadding(int padding)
void draw(int scaledFontSize) const override
Draws the widget.
TooltipWidget & addColoredLine(const std::vector< std::string > &segments, const std::vector< Color > &colors)
Adds a line with multiple colored segments (inline spans).
TooltipWidget & setBorderThickness(int thickness)
Rectangle getLastBounds() const
Returns the bounding rectangle for the last drawn frame. Useful for positioning sibling widgets (e....
TooltipWidget _panel
Definition WinScreen.hpp:62
int _durationSeconds
Definition WinScreen.hpp:57
ButtonWidget _quitBtn
Definition WinScreen.hpp:63
void setDuration(int seconds, int64_t ticks)
Sets the win duration (server-authoritative, from gwt).
Definition WinScreen.cpp:44
Color _winnerColor
Definition WinScreen.hpp:56
int64_t _durationTicks
Definition WinScreen.hpp:58
void _rebuildPanel(int scaledFontSize) const
Definition WinScreen.cpp:62
std::string _winnerTeam
Definition WinScreen.hpp:55
void draw(int scaledFontSize) const override
Draws the widget.
Definition WinScreen.cpp:93
bool _quitRequested
Definition WinScreen.hpp:60
void setWinner(const std::string &team, Color color)
Sets the winning team name and highlight color.
Definition WinScreen.cpp:38
static std::string _formatDuration(unsigned int seconds)
Definition WinScreen.cpp:50
bool handleInput() override
Handles button input. Always returns true (overlay blocks all input).
Definition WinScreen.cpp:86