Skip to content

Commit f12ba0b

Browse files
committed
Add label placeholder looknfeel system
Instead of hardcoding color values in the implementation code
1 parent c24ccf4 commit f12ba0b

File tree

7 files changed

+37
-6
lines changed

7 files changed

+37
-6
lines changed

Client/core/CGUI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void CLocalGUI::CreateWindows(bool bGameIsAlreadyLoaded)
162162
m_pLabelVersionTag->SetSize(CVector2D(m_pLabelVersionTag->GetTextExtent() + 5, 18));
163163
m_pLabelVersionTag->SetPosition(CVector2D(ScreenSize.fX - m_pLabelVersionTag->GetTextExtent() - 5, ScreenSize.fY - 15));
164164
m_pLabelVersionTag->SetAlpha(0.5f);
165-
m_pLabelVersionTag->SetTextColor(255, 255, 255);
165+
m_pLabelVersionTag->SetPlaceholderColors();
166166
m_pLabelVersionTag->SetZOrderingEnabled(false);
167167
m_pLabelVersionTag->MoveToBack();
168168
m_pLabelVersionTag->SetVisible(false);

Client/core/CSettings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ void CSettings::CreateGUI()
947947

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

983983
m_pLabelBrowserWhitelistAdd = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pEditBrowserWhitelistAdd, _("Enter a domain e.g. google.com")));
984984
m_pLabelBrowserWhitelistAdd->SetPosition(CVector2D(10.0f, 3.0f), false);
985-
m_pLabelBrowserWhitelistAdd->SetTextColor(0, 0, 0);
985+
m_pLabelBrowserWhitelistAdd->SetPlaceholderColors();
986986
m_pLabelBrowserWhitelistAdd->SetSize(CVector2D(1, 1), true);
987987
m_pLabelBrowserWhitelistAdd->SetAlpha(0.7f);
988988
m_pLabelBrowserWhitelistAdd->SetProperty("MousePassThroughEnabled", "True");

Client/core/ServerBrowser/CServerBrowser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void CServerBrowser::CreateTab(ServerBrowserType type, const char* szName)
333333

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

422422
m_pLabelSearchDescription[type] = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pEditSearch[type], _("Search servers...")));
423423
m_pLabelSearchDescription[type]->SetPosition(CVector2D(10, 3), false);
424-
m_pLabelSearchDescription[type]->SetTextColor(0, 0, 0);
424+
m_pLabelSearchDescription[type]->SetPlaceholderColors();
425425
m_pLabelSearchDescription[type]->SetSize(CVector2D(1, 1), true);
426426
m_pLabelSearchDescription[type]->SetAlpha(0.6f);
427427
m_pLabelSearchDescription[type]->SetProperty("MousePassThroughEnabled", "True");

Client/gui/CGUILabel_Impl.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,27 @@ float CGUILabel_Impl::GetTextExtent()
164164

165165
return 0.0f;
166166
}
167+
168+
void CGUILabel_Impl::InvertTextColor()
169+
{
170+
auto& color = GetTextColor();
171+
SetTextColor(255 - color.R, 255 - color.G, 255 - color.B);
172+
}
173+
174+
void CGUILabel_Impl::SetPlaceholderColors()
175+
{
176+
auto* text = reinterpret_cast<CEGUI::StaticText*>(m_pWindow);
177+
178+
if (!text->isPropertyPresent("PlaceholderTextColours"))
179+
{
180+
InvertTextColor();
181+
return;
182+
}
183+
184+
auto& prop = text->getProperty("PlaceholderTextColours");
185+
186+
unsigned int color = 0;
187+
const char* buffer = prop.c_str();
188+
sscanf(buffer, "tl:%x tr:%x bl:%x br:%x", &color, &color, &color, &color);
189+
SetTextColor(color >> 16, (color >> 8) & 0xFF, color & 0xFF);
190+
}

Client/gui/CGUILabel_Impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ class CGUILabel_Impl : public CGUILabel, public CGUIElement_Impl
4343

4444
eCGUIType GetType() { return CGUI_LABEL; };
4545

46+
void InvertTextColor();
47+
void SetPlaceholderColors();
48+
4649
#define EXCLUDE_SET_TEXT
4750
#include "CGUIElement_Inc.h"
4851
#undef EXCLUDE_SET_TEXT
52+
4953
};

Client/mods/deathmatch/logic/CTransferBox.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void CTransferBox::CreateTransferWindow()
6666
float fTempX = (m_progressBar->GetSize().fX - m_GUI->GetTextExtent(m_infoLabel->GetText().c_str()) - TRANSFERBOX_ICONSIZE - 4) * 0.5f;
6767
m_infoLabel->SetPosition(CVector2D(fTempX + TRANSFERBOX_ICONSIZE + 4, 0));
6868
m_infoLabel->SetSize(CVector2D(fTransferBoxWidth, TRANSFERBOX_PROGRESSHEIGHT));
69-
m_infoLabel->SetTextColor(0, 0, 0);
69+
m_infoLabel->SetPlaceholderColors();
7070
m_infoLabel->SetVerticalAlign(CGUI_ALIGN_VERTICALCENTER);
7171

7272
for (size_t i = 0; i < m_iconImages.size(); ++i)

Client/sdk/gui/CGUILabel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ class CGUILabel : public CGUIElement
3636
virtual float GetCharacterWidth(int iCharIndex) = 0;
3737
virtual float GetFontHeight() = 0;
3838
virtual float GetTextExtent() = 0;
39+
40+
virtual void InvertTextColor() = 0;
41+
virtual void SetPlaceholderColors() = 0;
3942
};

0 commit comments

Comments
 (0)