Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2736,7 +2736,7 @@ void CL_SetSteamCrashComment()
//
static ConCommand startupmenu( "startupmenu", &CL_CheckToDisplayStartupMenus, "Opens initial menu screen and loads the background bsp, but only if no other level is being loaded, and we're not in developer mode." );

ConVar cl_language( "cl_language", "english", FCVAR_USERINFO, "Language (from HKCU\\Software\\Valve\\Steam\\Language)" );
ConVar cl_language( "cl_language", "english", FCVAR_USERINFO | FCVAR_ARCHIVE, "Language (from HKCU\\Software\\Valve\\Steam\\Language)" );
void CL_InitLanguageCvar()
{
Msg("CL_InitLanguageCvar\n");
Expand Down
4 changes: 4 additions & 0 deletions gameui/OptionsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "OptionsSubMultiplayer.h"
#include "OptionsSubDifficulty.h"
#include "OptionsSubPortal.h"
#include "OptionsSubLanguage.h"
#ifdef WIN32
// NVNT haptic configuration dialog
#include "OptionsSubHaptics.h"
Expand Down Expand Up @@ -96,6 +97,9 @@ COptionsDialog::COptionsDialog(vgui::Panel *parent) : PropertyDialog(parent, "Op
m_pOptionsSubVideo = new COptionsSubVideo(this);
AddPage(m_pOptionsSubVideo, "#GameUI_Video");

// Language selection page
AddPage(new COptionsSubLanguage(this), "#GameUI_Language");

if ( !ModInfo().IsSinglePlayerOnly() )
{
AddPage(new COptionsSubVoice(this), "#GameUI_Voice");
Expand Down
133 changes: 133 additions & 0 deletions gameui/OptionsSubLanguage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Language selection options page
//
//=============================================================================//
#include "OptionsSubLanguage.h"

#include "EngineInterface.h"
#include "vgui_controls/ComboBox.h"
#include "vgui_controls/Label.h"

#include <KeyValues.h>
#include <vgui/IScheme.h>
#include <vgui/ILocalize.h>
#include "tier1/convar.h"
#include "common/language.h"

// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>

using namespace vgui;

// Languages offered in the UI selection
struct LanguageOption_t
{
ELanguage eLang;
const char *pchName; // Display name (localization token)
};

static const LanguageOption_t s_LanguageOptions[] =
{
{ k_Lang_English, "#GameUI_Language_English" },
{ k_Lang_Simplified_Chinese, "#GameUI_Language_Simplified_Chinese" },
{ k_Lang_Traditional_Chinese, "#GameUI_Language_Traditional_Chinese" },
{ k_Lang_Japanese, "#GameUI_Language_Japanese" },
{ k_Lang_Korean, "#GameUI_Language_Korean" },
{ k_Lang_German, "#GameUI_Language_German" },
{ k_Lang_French, "#GameUI_Language_French" },
{ k_Lang_Spanish, "#GameUI_Language_Spanish" },
{ k_Lang_Russian, "#GameUI_Language_Russian" },
};

COptionsSubLanguage::COptionsSubLanguage(vgui::Panel *parent) : PropertyPage(parent, NULL)
{
m_pLanguageLabel = new Label(this, "LanguageLabel", "#GameUI_Language");

m_pLanguageCombo = new ComboBox(this, "LanguageCombo", 10, false);
m_pLanguageCombo->AddActionSignalTarget(this);

for ( int i = 0; i < Q_ARRAYSIZE(s_LanguageOptions); ++i )
{
KeyValues *pData = new KeyValues("Language", "lang", (int)s_LanguageOptions[i].eLang);
m_pLanguageCombo->AddItem(s_LanguageOptions[i].pchName, pData);
}

LoadControlSettings("Resource\\OptionsSubLanguage.res");
}

COptionsSubLanguage::~COptionsSubLanguage()
{
}

void COptionsSubLanguage::ApplySchemeSettings(vgui::IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
}

void COptionsSubLanguage::OnResetData()
{
// Read the current language from cl_language
ConVarRef cl_language("cl_language");
const char *pchLang = cl_language.IsValid() ? cl_language.GetString() : "english";

ELanguage eLang = PchLanguageToELanguage(pchLang, k_Lang_English);
m_nCurrentLanguage = (int)eLang;

// Select the matching item
for ( int i = 0; i < m_pLanguageCombo->GetItemCount(); ++i )
{
KeyValues *pData = m_pLanguageCombo->GetItemUserData(i);
if ( pData && pData->GetInt("lang") == m_nCurrentLanguage )
{
m_pLanguageCombo->ActivateItem(i);
break;
}
}
}

void COptionsSubLanguage::OnApplyChanges()
{
KeyValues *pData = m_pLanguageCombo->GetActiveItemUserData();
if ( !pData )
return;

int nLang = pData->GetInt("lang", k_Lang_English);
if ( nLang == m_nCurrentLanguage )
return;

ELanguage eLang = (ELanguage)nLang;
const char *pchShortName = GetLanguageShortName(eLang);

// Update cl_language
ConVarRef cl_language("cl_language");
if ( cl_language.IsValid() )
{
cl_language.SetValue(pchShortName);
}

// Reload all localization files so the new language takes effect
if ( g_pVGuiLocalize )
{
g_pVGuiLocalize->RemoveAll();
g_pVGuiLocalize->AddFile("Resource/gameui_%language%.txt", "GAME", true);
g_pVGuiLocalize->AddFile("Resource/valve_%language%.txt", "GAME", true);
g_pVGuiLocalize->AddFile("Resource/platform_%language%.txt");
g_pVGuiLocalize->AddFile("Resource/vgui_%language%.txt");
}

m_nCurrentLanguage = nLang;
}

void COptionsSubLanguage::OnControlModified(Panel *panel)
{
if ( panel == m_pLanguageCombo )
{
SetModified(true);
}
}

void COptionsSubLanguage::OnTextChanged(Panel *panel)
{
OnControlModified(panel);
}
48 changes: 48 additions & 0 deletions gameui/OptionsSubLanguage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Language selection options page
//
//=============================================================================//

#ifndef OPTIONS_SUB_LANGUAGE_H
#define OPTIONS_SUB_LANGUAGE_H
#ifdef _WIN32
#pragma once
#endif

#include <vgui_controls/PropertyPage.h>

namespace vgui
{
class Label;
class ComboBox;
class Panel;
}

//-----------------------------------------------------------------------------
// Purpose: Language selection, Part of OptionsDialog
//-----------------------------------------------------------------------------
class COptionsSubLanguage : public vgui::PropertyPage
{
DECLARE_CLASS_SIMPLE( COptionsSubLanguage, vgui::PropertyPage );

public:
COptionsSubLanguage(vgui::Panel *parent);
~COptionsSubLanguage();

virtual void OnResetData();
virtual void OnApplyChanges();

protected:
virtual void ApplySchemeSettings(vgui::IScheme *pScheme);

MESSAGE_FUNC_PTR( OnControlModified, "ControlModified", panel );
MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel );

private:
vgui::ComboBox *m_pLanguageCombo;
vgui::Label *m_pLanguageLabel;
int m_nCurrentLanguage;
};

#endif // OPTIONS_SUB_LANGUAGE_H
Loading