Changed the helpsystem properties entrySpacing and iconTextSpacing to relative values.

Also reverted the helpsystem horizontal alignment functionality as it's not needed.
This commit is contained in:
Leon Styhre 2022-03-20 19:07:52 +01:00
parent 07f151d906
commit 3eacb27c3b
5 changed files with 15 additions and 51 deletions

View file

@ -15,13 +15,12 @@
HelpStyle::HelpStyle()
: position {Renderer::getScreenWidth() * 0.012f, Renderer::getScreenHeight() * 0.9515f}
, origin {glm::vec2 {}}
, horizontalAlignment {"left"}
, textColor {0x777777FF}
, textColorDimmed {0x777777FF}
, iconColor {0x777777FF}
, iconColorDimmed {0x777777FF}
, entrySpacing {16.0f}
, iconTextSpacing {8.0f}
, entrySpacing {0.00833f}
, iconTextSpacing {0.00416f}
, opacity {1.0f}
, letterCase {"uppercase"}
{
@ -38,33 +37,12 @@ void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::s
if (!elem)
return;
if (elem->has("horizontalAlignment")) {
horizontalAlignment = elem->get<std::string>("horizontalAlignment");
if (horizontalAlignment != "left" && horizontalAlignment != "center" &&
horizontalAlignment != "right") {
LOG(LogWarning) << "HelpSystem: Invalid theme configuration, property "
"<horizontalAlignment> defined as \""
<< horizontalAlignment << "\"";
horizontalAlignment = "left";
}
}
if (horizontalAlignment == "center")
position.x = 0.0f;
if (elem->has("pos"))
position = elem->get<glm::vec2>("pos") *
glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()};
if (elem->has("origin")) {
if (theme->isLegacyTheme()) {
origin = elem->get<glm::vec2>("origin");
}
else {
LOG(LogWarning) << "HelpSystem: Invalid theme configuration, property "
"<origin> not allowed for the helpsystem component";
}
}
if (elem->has("origin"))
origin = elem->get<glm::vec2>("origin");
if (elem->has("textColor"))
textColor = elem->get<unsigned int>("textColor");
@ -86,10 +64,10 @@ void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::s
font = Font::getFromTheme(elem, ThemeFlags::ALL, font);
if (elem->has("entrySpacing"))
entrySpacing = elem->get<float>("entrySpacing");
entrySpacing = glm::clamp(elem->get<float>("entrySpacing"), 0.0f, 0.04f);
if (elem->has("iconTextSpacing"))
iconTextSpacing = elem->get<float>("iconTextSpacing");
iconTextSpacing = glm::clamp(elem->get<float>("iconTextSpacing"), 0.0f, 0.04f);
if (elem->has("letterCase"))
letterCase = elem->get<std::string>("letterCase");

View file

@ -20,7 +20,6 @@ class ThemeData;
struct HelpStyle {
glm::vec2 position;
glm::vec2 origin;
std::string horizontalAlignment;
unsigned int textColor;
unsigned int textColorDimmed;
unsigned int iconColor;

View file

@ -292,8 +292,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"gameCount", UNSIGNED_INTEGER}}},
{"helpsystem",
{{"pos", NORMALIZED_PAIR},
{"origin", NORMALIZED_PAIR}, // For backward compatibility with legacy themes.
{"horizontalAlignment", STRING},
{"origin", NORMALIZED_PAIR},
{"textColor", COLOR},
{"textColorDimmed", COLOR},
{"iconColor", COLOR},

View file

@ -237,9 +237,9 @@ void HelpComponent::updateGrid()
lbl->setOpacity(mStyle.opacity);
labels.push_back(lbl);
width +=
icon->getSize().x + lbl->getSize().x +
((mStyle.iconTextSpacing + mStyle.entrySpacing) * mRenderer->getScreenWidthModifier());
width += icon->getSize().x + lbl->getSize().x +
((mStyle.iconTextSpacing * mRenderer->getScreenWidth() +
mStyle.entrySpacing * mRenderer->getScreenWidth()));
}
mGrid->setSize(width, height);
@ -247,27 +247,15 @@ void HelpComponent::updateGrid()
for (unsigned int i = 0; i < icons.size(); ++i) {
const int col = i * 4;
mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width);
mGrid->setColWidthPerc(
col + 1, (mStyle.iconTextSpacing * mRenderer->getScreenWidthModifier()) / width);
mGrid->setColWidthPerc(col + 1,
(mStyle.iconTextSpacing * mRenderer->getScreenWidth()) / width);
mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x / width);
mGrid->setEntry(icons.at(i), glm::ivec2 {col, 0}, false, false);
mGrid->setEntry(labels.at(i), glm::ivec2 {col + 2, 0}, false, false);
}
if (mStyle.horizontalAlignment == "right") {
mGrid->setPosition({mRenderer->getScreenWidth() - mGrid->getSize().x - mStyle.position.x +
mStyle.iconTextSpacing + mStyle.entrySpacing,
mStyle.position.y, 0.0f});
}
else if (mStyle.horizontalAlignment == "center") {
mGrid->setPosition({(mRenderer->getScreenWidth() / 2.0f) - (mGrid->getSize().x / 2.0f) -
mStyle.position.x + mStyle.iconTextSpacing,
mStyle.position.y, 0.0f});
}
else {
mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f});
}
mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f});
mGrid->setOrigin(mStyle.origin);
}

View file

@ -227,8 +227,8 @@
</video>
<helpsystem name="help">
<pos>0.020 0.954</pos>
<horizontalAlignment>right</horizontalAlignment>
<pos>0.9885 0.954</pos>
<origin>1 0 </origin>
</helpsystem>
<image name="consolegame">