mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge pull request #1545 from def-/pr-load-font
Move out common font loading into method
This commit is contained in:
commit
138a9c6ff7
|
@ -112,6 +112,7 @@ public:
|
|||
virtual void ToggleFullscreen() = 0;
|
||||
virtual void ToggleWindowBordered() = 0;
|
||||
virtual void ToggleWindowVSync() = 0;
|
||||
virtual void LoadFont() = 0;
|
||||
|
||||
// networking
|
||||
virtual void EnterGame() = 0;
|
||||
|
|
|
@ -3508,6 +3508,28 @@ void CClient::ToggleWindowVSync()
|
|||
g_Config.m_GfxVsync ^= 1;
|
||||
}
|
||||
|
||||
void CClient::LoadFont()
|
||||
{
|
||||
static CFont *pDefaultFont = 0;
|
||||
char aFilename[512];
|
||||
const char *pFontFile = "fonts/DejaVuSansCJKName.ttf";
|
||||
if(str_find(g_Config.m_ClLanguagefile, "chinese") != NULL || str_find(g_Config.m_ClLanguagefile, "japanese") != NULL ||
|
||||
str_find(g_Config.m_ClLanguagefile, "korean") != NULL)
|
||||
pFontFile = "fonts/DejavuWenQuanYiMicroHei.ttf";
|
||||
IOHANDLE File = Storage()->OpenFile(pFontFile, IOFLAG_READ, IStorage::TYPE_ALL, aFilename, sizeof(aFilename));
|
||||
if(File)
|
||||
{
|
||||
io_close(File);
|
||||
IEngineTextRender *pTextRender = Kernel()->RequestInterface<IEngineTextRender>();
|
||||
pDefaultFont = pTextRender->GetFont(aFilename);
|
||||
if(pDefaultFont == NULL)
|
||||
pDefaultFont = pTextRender->LoadFont(aFilename);
|
||||
Kernel()->RequestInterface<IEngineTextRender>()->SetDefaultFont(pDefaultFont);
|
||||
}
|
||||
if(!pDefaultFont)
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load font. filename='%s'", pFontFile);
|
||||
}
|
||||
|
||||
void CClient::ConchainWindowVSync(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
|
||||
{
|
||||
CClient *pSelf = (CClient *)pUserData;
|
||||
|
|
|
@ -391,6 +391,7 @@ public:
|
|||
void ToggleFullscreen();
|
||||
void ToggleWindowBordered();
|
||||
void ToggleWindowVSync();
|
||||
void LoadFont();
|
||||
|
||||
// DDRace
|
||||
|
||||
|
|
|
@ -1346,24 +1346,7 @@ void CMenus::RenderLanguageSelection(CUIRect MainView)
|
|||
{
|
||||
str_copy(g_Config.m_ClLanguagefile, s_Languages[s_SelectedLanguage].m_FileName, sizeof(g_Config.m_ClLanguagefile));
|
||||
g_Localization.Load(s_Languages[s_SelectedLanguage].m_FileName, Storage(), Console());
|
||||
|
||||
// Load Font
|
||||
static CFont *pDefaultFont = 0;
|
||||
char aFilename[512];
|
||||
const char *pFontFile = "fonts/DejaVuSansCJKName.ttf";
|
||||
if(str_find(g_Config.m_ClLanguagefile, "chinese") != NULL || str_find(g_Config.m_ClLanguagefile, "japanese") != NULL ||
|
||||
str_find(g_Config.m_ClLanguagefile, "korean") != NULL)
|
||||
pFontFile = "fonts/DejavuWenQuanYiMicroHei.ttf";
|
||||
IOHANDLE File = Storage()->OpenFile(pFontFile, IOFLAG_READ, IStorage::TYPE_ALL, aFilename, sizeof(aFilename));
|
||||
if(File)
|
||||
{
|
||||
io_close(File);
|
||||
if((pDefaultFont = TextRender()->GetFont(aFilename)) == NULL)
|
||||
pDefaultFont = TextRender()->LoadFont(aFilename);
|
||||
TextRender()->SetDefaultFont(pDefaultFont);
|
||||
}
|
||||
if(!pDefaultFont)
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load font. filename='%s'", pFontFile);
|
||||
Client()->LoadFont();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -290,22 +290,7 @@ void CGameClient::OnInit()
|
|||
for(int i = 0; i < NUM_NETOBJTYPES; i++)
|
||||
Client()->SnapSetStaticsize(i, m_NetObjHandler.GetObjSize(i));
|
||||
|
||||
// load default font
|
||||
static CFont *pDefaultFont = 0;
|
||||
char aFilename[512];
|
||||
const char *pFontFile = "fonts/DejaVuSansCJKName.ttf";
|
||||
if(str_find(g_Config.m_ClLanguagefile, "chinese") != NULL || str_find(g_Config.m_ClLanguagefile, "japanese") != NULL ||
|
||||
str_find(g_Config.m_ClLanguagefile, "korean") != NULL)
|
||||
pFontFile = "fonts/DejavuWenQuanYiMicroHei.ttf";
|
||||
IOHANDLE File = Storage()->OpenFile(pFontFile, IOFLAG_READ, IStorage::TYPE_ALL, aFilename, sizeof(aFilename));
|
||||
if(File)
|
||||
{
|
||||
io_close(File);
|
||||
pDefaultFont = TextRender()->LoadFont(aFilename);
|
||||
TextRender()->SetDefaultFont(pDefaultFont);
|
||||
}
|
||||
if(!pDefaultFont)
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load font. filename='%s'", pFontFile);
|
||||
Client()->LoadFont();
|
||||
|
||||
// init all components
|
||||
for(int i = m_All.m_Num-1; i >= 0; --i)
|
||||
|
|
Loading…
Reference in a new issue