mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
added a config to display the code string of a country flag instead of the image. Closes #897
This commit is contained in:
parent
3811476c6e
commit
e960cbdff3
|
@ -17,6 +17,7 @@ MACRO_CONFIG_INT(ConsoleOutputLevel, console_output_level, 0, 0, 2, CFGFLAG_CLIE
|
|||
|
||||
MACRO_CONFIG_INT(ClCpuThrottle, cl_cpu_throttle, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
|
||||
MACRO_CONFIG_INT(ClEditor, cl_editor, 0, 0, 1, CFGFLAG_CLIENT, "")
|
||||
MACRO_CONFIG_INT(ClLoadCountryFlags, cl_load_country_flags, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Load and show country flags")
|
||||
|
||||
MACRO_CONFIG_INT(ClAutoDemoRecord, cl_auto_demo_record, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Automatically record demos")
|
||||
MACRO_CONFIG_INT(ClAutoDemoMax, cl_auto_demo_max, 10, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Maximum number of automatically recorded demos (0 = no limit)")
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <engine/console.h>
|
||||
#include <engine/graphics.h>
|
||||
#include <engine/storage.h>
|
||||
#include <engine/textrender.h>
|
||||
#include <engine/shared/config.h>
|
||||
#include <engine/shared/linereader.h>
|
||||
|
||||
|
@ -57,22 +58,30 @@ void CCountryFlags::LoadCountryflagsIndexfile()
|
|||
|
||||
// load the graphic file
|
||||
char aBuf[128];
|
||||
str_format(aBuf, sizeof(aBuf), "countryflags/%s.png", aOrigin);
|
||||
CImageInfo Info;
|
||||
if(!Graphics()->LoadPNG(&Info, aBuf, IStorage::TYPE_ALL))
|
||||
if(g_Config.m_ClLoadCountryFlags)
|
||||
{
|
||||
char aMsg[128];
|
||||
str_format(aMsg, sizeof(aMsg), "failed to load '%s'", aBuf);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aMsg);
|
||||
continue;
|
||||
str_format(aBuf, sizeof(aBuf), "countryflags/%s.png", aOrigin);
|
||||
if(!Graphics()->LoadPNG(&Info, aBuf, IStorage::TYPE_ALL))
|
||||
{
|
||||
char aMsg[128];
|
||||
str_format(aMsg, sizeof(aMsg), "failed to load '%s'", aBuf);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aMsg);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// add entry
|
||||
CCountryFlag CountryFlag;
|
||||
CountryFlag.m_CountryCode = CountryCode;
|
||||
str_copy(CountryFlag.m_aCountryCodeString, aOrigin, sizeof(CountryFlag.m_aCountryCodeString));
|
||||
CountryFlag.m_Texture = Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0);
|
||||
mem_free(Info.m_pData);
|
||||
if(g_Config.m_ClLoadCountryFlags)
|
||||
{
|
||||
CountryFlag.m_Texture = Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0);
|
||||
mem_free(Info.m_pData);
|
||||
}
|
||||
else
|
||||
CountryFlag.m_Texture = -1;
|
||||
if(g_Config.m_Debug)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "loaded country flag '%s'", aOrigin);
|
||||
|
@ -117,3 +126,24 @@ const CCountryFlags::CCountryFlag *CCountryFlags::GetByIndex(int Index) const
|
|||
{
|
||||
return &m_aCountryFlags[max(0, Index%m_aCountryFlags.size())];
|
||||
}
|
||||
|
||||
void CCountryFlags::Render(int CountryCode, const vec4 *pColor, float x, float y, float w, float h)
|
||||
{
|
||||
const CCountryFlag *pFlag = GetByCountryCode(CountryCode);
|
||||
if(pFlag->m_Texture != -1)
|
||||
{
|
||||
Graphics()->TextureSet(pFlag->m_Texture);
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(pColor->r, pColor->g, pColor->b, pColor->a);
|
||||
IGraphics::CQuadItem QuadItem(x, y, w, h);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
CTextCursor Cursor;
|
||||
TextRender()->SetCursor(&Cursor, x, y, 10.0f, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END);
|
||||
Cursor.m_LineWidth = w;
|
||||
TextRender()->TextEx(&Cursor, pFlag->m_aCountryCodeString, -1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
int Num() const;
|
||||
const CCountryFlag *GetByCountryCode(int CountryCode) const;
|
||||
const CCountryFlag *GetByIndex(int Index) const;
|
||||
//int Find(int CountryCode) const;
|
||||
void Render(int CountryCode, const vec4 *pColor, float x, float y, float w, float h);
|
||||
|
||||
private:
|
||||
enum
|
||||
|
|
|
@ -1132,12 +1132,8 @@ int CMenus::Render()
|
|||
float OldWidth = Item.m_Rect.w;
|
||||
Item.m_Rect.w = Item.m_Rect.h*2;
|
||||
Item.m_Rect.x += (OldWidth-Item.m_Rect.w)/ 2.0f;
|
||||
Graphics()->TextureSet(pEntry->m_Texture);
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
IGraphics::CQuadItem QuadItem(Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
m_pClient->m_pCountryFlags->Render(pEntry->m_CountryCode, &Color, Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h);
|
||||
UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -567,12 +567,8 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
|
|||
float OldWidth = Rect.w;
|
||||
Rect.w = Rect.h*2;
|
||||
Rect.x += (OldWidth-Rect.w)/2.0f;
|
||||
Graphics()->TextureSet(m_pClient->m_pCountryFlags->GetByCountryCode(g_Config.m_BrFilterCountryIndex)->m_Texture);
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(1.0f, 1.0f, 1.0f, g_Config.m_BrFilterCountry?1.0f: 0.5f);
|
||||
IGraphics::CQuadItem QuadItem(Rect.x, Rect.y, Rect.w, Rect.h);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
vec4 Color(1.0f, 1.0f, 1.0f, g_Config.m_BrFilterCountry?1.0f: 0.5f);
|
||||
m_pClient->m_pCountryFlags->Render(g_Config.m_BrFilterCountryIndex, &Color, Rect.x, Rect.y, Rect.w, Rect.h);
|
||||
|
||||
if(g_Config.m_BrFilterCountry && UI()->DoButtonLogic(&g_Config.m_BrFilterCountryIndex, "", 0, &Rect))
|
||||
m_Popup = POPUP_COUNTRY;
|
||||
|
@ -766,12 +762,8 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
|
|||
TextRender()->TextEx(&Cursor, pClan, -1);
|
||||
|
||||
// flag
|
||||
Graphics()->TextureSet(m_pClient->m_pCountryFlags->GetByCountryCode(pSelectedServer->m_aClients[i].m_Country)->m_Texture);
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.5f);
|
||||
IGraphics::CQuadItem QuadItem(Flag.x, Flag.y, Flag.w, Flag.h);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
vec4 Color(1.0f, 1.0f, 1.0f, 0.5f);
|
||||
m_pClient->m_pCountryFlags->Render(pSelectedServer->m_aClients[i].m_Country, &Color, Flag.x, Flag.y, Flag.w, Flag.h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,13 +221,10 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView)
|
|||
float OldWidth = Item.m_Rect.w;
|
||||
Item.m_Rect.w = Item.m_Rect.h*2;
|
||||
Item.m_Rect.x += (OldWidth-Item.m_Rect.w)/ 2.0f;
|
||||
Graphics()->TextureSet(pEntry->m_Texture);
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
IGraphics::CQuadItem QuadItem(Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, 0);
|
||||
vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
m_pClient->m_pCountryFlags->Render(pEntry->m_CountryCode, &Color, Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h);
|
||||
if(pEntry->m_Texture != -1)
|
||||
UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -920,11 +917,8 @@ void CMenus::RenderLanguageSelection(CUIRect MainView)
|
|||
Item.m_Rect.VSplitLeft(Item.m_Rect.h*2.0f, &Rect, &Item.m_Rect);
|
||||
Rect.VMargin(6.0f, &Rect);
|
||||
Rect.HMargin(3.0f, &Rect);
|
||||
Graphics()->TextureSet(m_pClient->m_pCountryFlags->GetByCountryCode(r.front().m_CountryCode)->m_Texture);
|
||||
Graphics()->QuadsBegin();
|
||||
IGraphics::CQuadItem QuadItem(Rect.x, Rect.y, Rect.w, Rect.h);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
m_pClient->m_pCountryFlags->Render(r.front().m_CountryCode, &Color, Rect.x, Rect.y, Rect.w, Rect.h);
|
||||
Item.m_Rect.HSplitTop(2.0f, 0, &Item.m_Rect);
|
||||
UI()->DoLabelScaled(&Item.m_Rect, r.front().m_Name, 16.0f, -1);
|
||||
}
|
||||
|
|
|
@ -273,12 +273,9 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
|
|||
TextRender()->TextEx(&Cursor, m_pClient->m_aClients[pInfo->m_ClientID].m_aClan, -1);
|
||||
|
||||
// country flag
|
||||
Graphics()->TextureSet(m_pClient->m_pCountryFlags->GetByCountryCode(m_pClient->m_aClients[pInfo->m_ClientID].m_Country)->m_Texture);
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.5f);
|
||||
IGraphics::CQuadItem QuadItem(CountryOffset, y+(Spacing+TeeSizeMod*5.0f)/2.0f, CountryLength, LineHeight-Spacing-TeeSizeMod*5.0f);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
vec4 Color(1.0f, 1.0f, 1.0f, 0.5f);
|
||||
m_pClient->m_pCountryFlags->Render(m_pClient->m_aClients[pInfo->m_ClientID].m_Country, &Color,
|
||||
CountryOffset, y+(Spacing+TeeSizeMod*5.0f)/2.0f, CountryLength, LineHeight-Spacing-TeeSizeMod*5.0f);
|
||||
|
||||
// ping
|
||||
str_format(aBuf, sizeof(aBuf), "%d", clamp(pInfo->m_Latency, 0, 1000));
|
||||
|
|
Loading…
Reference in a new issue