Skip to content

Commit

Permalink
Menu|Definitions: Use Values to replace menu text labels
Browse files Browse the repository at this point in the history
Improved implementation that works with titles as well.
  • Loading branch information
skyjake committed Mar 10, 2019
1 parent 573c6a9 commit 3e7406f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
2 changes: 2 additions & 0 deletions doomsday/apps/plugins/common/include/menu/widgets/widget.h
Expand Up @@ -237,6 +237,8 @@ class Widget

virtual void pageActivated();

static de::String labelText(const de::String &text);

private:
DENG2_PRIVATE(d)
};
Expand Down
10 changes: 6 additions & 4 deletions doomsday/apps/plugins/common/src/hu_menu.cpp
Expand Up @@ -2471,14 +2471,16 @@ void Hu_MenuDrawFocusCursor(Vector2i const &origin, float scale, float alpha)

void Hu_MenuDrawPageTitle(String title, Vector2i const &origin)
{
if(title.isEmpty()) return;
title = Widget::labelText(title);

if(title.isEmpty()) return;

DGL_Enable(DGL_TEXTURE_2D);
FR_SetFont(FID(GF_FONTB));
FR_SetColorv(cfg.common.menuTextColors[0]);
FR_SetAlpha(mnRendState->pageAlpha);

FR_DrawTextXY3(title.toUtf8().constData(), origin.x, origin.y, ALIGN_TOP, Hu_MenuMergeEffectWithDrawTextFlags(0));
FR_DrawTextXY3(title.toLatin1(), origin.x, origin.y, ALIGN_TOP, Hu_MenuMergeEffectWithDrawTextFlags(0));

DGL_Disable(DGL_TEXTURE_2D);
}
Expand All @@ -2499,7 +2501,7 @@ void Hu_MenuDrawPageHelp(String helpText, Vector2i const &origin)
FR_SetColorv(cfg.common.menuTextColors[1]);
FR_SetAlpha(mnRendState->pageAlpha);

FR_DrawTextXY3(helpText.toUtf8().constData(), origin.x, origin.y, ALIGN_BOTTOM, Hu_MenuMergeEffectWithDrawTextFlags(0));
FR_DrawTextXY3(helpText.toLatin1(), origin.x, origin.y, ALIGN_BOTTOM, Hu_MenuMergeEffectWithDrawTextFlags(0));

DGL_Disable(DGL_TEXTURE_2D);

Expand Down Expand Up @@ -3145,7 +3147,7 @@ void Hu_MenuDrawLoadGamePage(Page const & /*page*/, Vector2i const &origin)
FR_SetColorAndAlpha(cfg.common.menuTextColors[0][CR], cfg.common.menuTextColors[0][CG], cfg.common.menuTextColors[0][CB], mnRendState->pageAlpha);

#if __JHERETIC__ || __JHEXEN__
FR_DrawTextXY3("Load Game", SCREENWIDTH / 2, origin.y - 20, ALIGN_TOP, Hu_MenuMergeEffectWithDrawTextFlags(0));
FR_DrawTextXY3(Widget::labelText("Load Game").toLatin1(), SCREENWIDTH / 2, origin.y - 20, ALIGN_TOP, Hu_MenuMergeEffectWithDrawTextFlags(0));
#else
WI_DrawPatch(pLoadGame, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.common.menuPatchReplaceMode), pLoadGame),
Vector2i(origin.x - 8, origin.y - 26), ALIGN_TOPLEFT, 0, Hu_MenuMergeEffectWithDrawTextFlags(0));
Expand Down
10 changes: 1 addition & 9 deletions doomsday/apps/plugins/common/src/menu/widgets/buttonwidget.cpp
Expand Up @@ -166,15 +166,7 @@ String ButtonWidget::text() const

ButtonWidget &ButtonWidget::setText(String const &newText)
{
// Widget text may be replaced with Values.
if (const auto *repl = Defs().getValueById("Menu Label|" + newText))
{
d->text = repl->text;
}
else
{
d->text = newText;
}
d->text = labelText(newText);
return *this;
}

Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/plugins/common/src/menu/widgets/labelwidget.cpp
Expand Up @@ -120,9 +120,9 @@ LabelWidget &LabelWidget::setPatch(patchid_t *newPatch)
return *this;
}

LabelWidget &LabelWidget::setText(String const &newText)
LabelWidget &LabelWidget::setText(const String &text)
{
d->text = newText;
d->text = labelText(text);
return *this;
}

Expand Down
11 changes: 11 additions & 0 deletions doomsday/apps/plugins/common/src/menu/widgets/widget.cpp
Expand Up @@ -23,6 +23,7 @@
#include "menu/widgets/widget.h"
#include "menu/page.h"

#include "g_defs.h"
#include "hu_menu.h" // menu sounds

using namespace de;
Expand Down Expand Up @@ -343,5 +344,15 @@ Vector4f Widget::selectionFlashColor(const Vector4f &noFlashColor) const
void Widget::pageActivated()
{}

String Widget::labelText(const String &text) // static
{
// Widget text may be replaced with Values.
if (const auto *repl = Defs().getValueById("Menu Label|" + text))
{
return repl->text;
}
return text;
}

} // namespace menu
} // namespace common

0 comments on commit 3e7406f

Please sign in to comment.