Skip to content

Commit

Permalink
Add label placeholder looknfeel system
Browse files Browse the repository at this point in the history
Instead of hardcoding color values in the implementation code
  • Loading branch information
Lpsd committed Jan 24, 2025
1 parent c24ccf4 commit f12ba0b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Client/core/CGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void CLocalGUI::CreateWindows(bool bGameIsAlreadyLoaded)
m_pLabelVersionTag->SetSize(CVector2D(m_pLabelVersionTag->GetTextExtent() + 5, 18));
m_pLabelVersionTag->SetPosition(CVector2D(ScreenSize.fX - m_pLabelVersionTag->GetTextExtent() - 5, ScreenSize.fY - 15));
m_pLabelVersionTag->SetAlpha(0.5f);
m_pLabelVersionTag->SetTextColor(255, 255, 255);
m_pLabelVersionTag->SetPlaceholderColors();
m_pLabelVersionTag->SetZOrderingEnabled(false);
m_pLabelVersionTag->MoveToBack();
m_pLabelVersionTag->SetVisible(false);
Expand Down
4 changes: 2 additions & 2 deletions Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ void CSettings::CreateGUI()

m_pLabelBrowserBlacklistAdd = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pEditBrowserBlacklistAdd, _("Enter a domain e.g. google.com")));
m_pLabelBrowserBlacklistAdd->SetPosition(CVector2D(10.0f, 3.0f), false);
m_pLabelBrowserBlacklistAdd->SetTextColor(0, 0, 0);
m_pLabelBrowserBlacklistAdd->SetPlaceholderColors();
m_pLabelBrowserBlacklistAdd->SetSize(CVector2D(1, 1), true);
m_pLabelBrowserBlacklistAdd->SetAlpha(0.7f);
m_pLabelBrowserBlacklistAdd->SetProperty("MousePassThroughEnabled", "True");
Expand Down Expand Up @@ -982,7 +982,7 @@ void CSettings::CreateGUI()

m_pLabelBrowserWhitelistAdd = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pEditBrowserWhitelistAdd, _("Enter a domain e.g. google.com")));
m_pLabelBrowserWhitelistAdd->SetPosition(CVector2D(10.0f, 3.0f), false);
m_pLabelBrowserWhitelistAdd->SetTextColor(0, 0, 0);
m_pLabelBrowserWhitelistAdd->SetPlaceholderColors();
m_pLabelBrowserWhitelistAdd->SetSize(CVector2D(1, 1), true);
m_pLabelBrowserWhitelistAdd->SetAlpha(0.7f);
m_pLabelBrowserWhitelistAdd->SetProperty("MousePassThroughEnabled", "True");
Expand Down
4 changes: 2 additions & 2 deletions Client/core/ServerBrowser/CServerBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void CServerBrowser::CreateTab(ServerBrowserType type, const char* szName)

m_pLabelAddressDescription[type] = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pEditAddress[type], "Enter an address [IP:Port]"));
m_pLabelAddressDescription[type]->SetPosition(CVector2D(10, 5), false);
m_pLabelAddressDescription[type]->SetTextColor(0, 0, 0);
m_pLabelAddressDescription[type]->SetPlaceholderColors();
m_pLabelAddressDescription[type]->AutoSize(m_pLabelAddressDescription[type]->GetText().c_str());
m_pLabelAddressDescription[type]->SetAlpha(0.6f);
m_pLabelAddressDescription[type]->SetProperty("MousePassThroughEnabled", "True");
Expand Down Expand Up @@ -421,7 +421,7 @@ void CServerBrowser::CreateTab(ServerBrowserType type, const char* szName)

m_pLabelSearchDescription[type] = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pEditSearch[type], _("Search servers...")));
m_pLabelSearchDescription[type]->SetPosition(CVector2D(10, 3), false);
m_pLabelSearchDescription[type]->SetTextColor(0, 0, 0);
m_pLabelSearchDescription[type]->SetPlaceholderColors();
m_pLabelSearchDescription[type]->SetSize(CVector2D(1, 1), true);
m_pLabelSearchDescription[type]->SetAlpha(0.6f);
m_pLabelSearchDescription[type]->SetProperty("MousePassThroughEnabled", "True");
Expand Down
24 changes: 24 additions & 0 deletions Client/gui/CGUILabel_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,27 @@ float CGUILabel_Impl::GetTextExtent()

return 0.0f;
}

void CGUILabel_Impl::InvertTextColor()
{
auto& color = GetTextColor();
SetTextColor(255 - color.R, 255 - color.G, 255 - color.B);
}

void CGUILabel_Impl::SetPlaceholderColors()
{
auto* text = reinterpret_cast<CEGUI::StaticText*>(m_pWindow);

if (!text->isPropertyPresent("PlaceholderTextColours"))
{
InvertTextColor();
return;
}

auto& prop = text->getProperty("PlaceholderTextColours");

unsigned int color = 0;
const char* buffer = prop.c_str();
sscanf(buffer, "tl:%x tr:%x bl:%x br:%x", &color, &color, &color, &color);
SetTextColor(color >> 16, (color >> 8) & 0xFF, color & 0xFF);
}
4 changes: 4 additions & 0 deletions Client/gui/CGUILabel_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class CGUILabel_Impl : public CGUILabel, public CGUIElement_Impl

eCGUIType GetType() { return CGUI_LABEL; };

void InvertTextColor();
void SetPlaceholderColors();

#define EXCLUDE_SET_TEXT
#include "CGUIElement_Inc.h"
#undef EXCLUDE_SET_TEXT

};
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CTransferBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void CTransferBox::CreateTransferWindow()
float fTempX = (m_progressBar->GetSize().fX - m_GUI->GetTextExtent(m_infoLabel->GetText().c_str()) - TRANSFERBOX_ICONSIZE - 4) * 0.5f;
m_infoLabel->SetPosition(CVector2D(fTempX + TRANSFERBOX_ICONSIZE + 4, 0));
m_infoLabel->SetSize(CVector2D(fTransferBoxWidth, TRANSFERBOX_PROGRESSHEIGHT));
m_infoLabel->SetTextColor(0, 0, 0);
m_infoLabel->SetPlaceholderColors();
m_infoLabel->SetVerticalAlign(CGUI_ALIGN_VERTICALCENTER);

for (size_t i = 0; i < m_iconImages.size(); ++i)
Expand Down
3 changes: 3 additions & 0 deletions Client/sdk/gui/CGUILabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ class CGUILabel : public CGUIElement
virtual float GetCharacterWidth(int iCharIndex) = 0;
virtual float GetFontHeight() = 0;
virtual float GetTextExtent() = 0;

virtual void InvertTextColor() = 0;
virtual void SetPlaceholderColors() = 0;
};

0 comments on commit f12ba0b

Please sign in to comment.