Skip to content

Commit 73bbb34

Browse files
committed
Minor refactoring of fullscreen popup rendering
- Avoid reusing `SLabelProperties Props` variable by using designated initializers. - Avoid rendering empty extra text label in some popups. - Pass `nullptr` to UI split functions for unused/overridden values. - Remove unnecessary default parameters of `TextWidth` calls. - Normalize `float` constant notation.
1 parent 5bda840 commit 73bbb34

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

src/game/client/components/menus.cpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,35 +1315,45 @@ void CMenus::RenderPopupFullscreen(CUIRect Screen)
13151315
CUIRect Box, Part;
13161316
Box = Screen;
13171317
if(m_Popup != POPUP_FIRST_LAUNCH)
1318+
{
13181319
Box.Margin(150.0f, &Box);
1320+
}
13191321

1320-
// render the box
1322+
// Background
13211323
Box.Draw(BgColor, IGraphics::CORNER_ALL, 15.0f);
13221324

1323-
Box.HSplitTop(20.f, &Part, &Box);
1324-
Box.HSplitTop(24.f, &Part, &Box);
1325-
Part.VMargin(20.f, &Part);
1326-
SLabelProperties Props;
1327-
Props.m_MaxWidth = (int)Part.w;
1328-
1329-
if(TextRender()->TextWidth(24.f, pTitle, -1, -1.0f) > Part.w)
1330-
Ui()->DoLabel(&Part, pTitle, 24.f, TEXTALIGN_ML, Props);
1331-
else
1332-
Ui()->DoLabel(&Part, pTitle, 24.f, TEXTALIGN_MC);
1325+
// Title
1326+
{
1327+
CUIRect Title;
1328+
Box.HSplitTop(20.0f, nullptr, &Box);
1329+
Box.HSplitTop(24.0f, &Title, &Box);
1330+
Box.HSplitTop(20.0f, nullptr, &Box);
1331+
Title.VMargin(20.0f, &Title);
13331332

1334-
Box.HSplitTop(20.f, &Part, &Box);
1335-
Box.HSplitTop(24.f, &Part, &Box);
1336-
Part.VMargin(20.f, &Part);
1333+
const float TitleFontSize = 24.0f;
1334+
if(TextRender()->TextWidth(TitleFontSize, pTitle) > Title.w)
1335+
Ui()->DoLabel(&Title, pTitle, TitleFontSize, TEXTALIGN_ML, {.m_MaxWidth = Title.w});
1336+
else
1337+
Ui()->DoLabel(&Title, pTitle, TitleFontSize, TEXTALIGN_MC);
1338+
}
13371339

1338-
float FontSize = m_Popup == POPUP_FIRST_LAUNCH ? 16.0f : 20.f;
1340+
// Extra text (optional)
1341+
{
1342+
CUIRect ExtraText;
1343+
Box.HSplitTop(24.0f, &ExtraText, &Box);
1344+
ExtraText.VMargin(20.0f, &ExtraText);
1345+
if(pExtraText[0] != '\0')
1346+
{
1347+
const float ExtraTextFontSize = m_Popup == POPUP_FIRST_LAUNCH ? 16.0f : 20.0f;
13391348

1340-
Props.m_MaxWidth = (int)Part.w;
1341-
if(TopAlign)
1342-
Ui()->DoLabel(&Part, pExtraText, FontSize, TEXTALIGN_TL, Props);
1343-
else if(TextRender()->TextWidth(FontSize, pExtraText, -1, -1.0f) > Part.w)
1344-
Ui()->DoLabel(&Part, pExtraText, FontSize, TEXTALIGN_ML, Props);
1345-
else
1346-
Ui()->DoLabel(&Part, pExtraText, FontSize, TEXTALIGN_MC);
1349+
if(TopAlign)
1350+
Ui()->DoLabel(&ExtraText, pExtraText, ExtraTextFontSize, TEXTALIGN_TL, {.m_MaxWidth = ExtraText.w});
1351+
else if(TextRender()->TextWidth(ExtraTextFontSize, pExtraText) > ExtraText.w)
1352+
Ui()->DoLabel(&ExtraText, pExtraText, ExtraTextFontSize, TEXTALIGN_ML, {.m_MaxWidth = ExtraText.w});
1353+
else
1354+
Ui()->DoLabel(&ExtraText, pExtraText, ExtraTextFontSize, TEXTALIGN_MC);
1355+
}
1356+
}
13471357

13481358
if(m_Popup == POPUP_MESSAGE || m_Popup == POPUP_CONFIRM)
13491359
{
@@ -1392,14 +1402,12 @@ void CMenus::RenderPopupFullscreen(CUIRect Screen)
13921402
if(GameClient()->Editor()->HasUnsavedData())
13931403
{
13941404
str_format(aBuf, sizeof(aBuf), "%s\n\n%s", Localize("There's an unsaved map in the editor, you might want to save it."), Localize("Continue anyway?"));
1395-
Props.m_MaxWidth = Part.w - 20.0f;
1396-
Ui()->DoLabel(&Box, aBuf, 20.f, TEXTALIGN_ML, Props);
1405+
Ui()->DoLabel(&Box, aBuf, 20.0f, TEXTALIGN_ML, {.m_MaxWidth = Part.w - 20.0f});
13971406
}
13981407
else if(GameClient()->m_TouchControls.HasEditingChanges() || m_MenusIngameTouchControls.UnsavedChanges())
13991408
{
14001409
str_format(aBuf, sizeof(aBuf), "%s\n\n%s", Localize("There's an unsaved change in the touch controls editor, you might want to save it."), Localize("Continue anyway?"));
1401-
Props.m_MaxWidth = Part.w - 20.0f;
1402-
Ui()->DoLabel(&Box, aBuf, 20.f, TEXTALIGN_ML, Props);
1410+
Ui()->DoLabel(&Box, aBuf, 20.0f, TEXTALIGN_ML, {.m_MaxWidth = Part.w - 20.0f});
14031411
}
14041412

14051413
// buttons

0 commit comments

Comments
 (0)