From 397f139151f2f46d3ed76e7f083b40a72b970038 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sat, 24 Jul 2021 07:27:55 +0200 Subject: [PATCH] add option to change the language of the config program --- config/ConfigFormUnit.cpp | 68 ++++++- config/ConfigFormUnit.dfm | 383 ++++++++++++++++++++------------------ config/ConfigFormUnit.h | 3 + src/config.c | 3 + 4 files changed, 271 insertions(+), 186 deletions(-) diff --git a/config/ConfigFormUnit.cpp b/config/ConfigFormUnit.cpp index 7575a08..6b92cf7 100644 --- a/config/ConfigFormUnit.cpp +++ b/config/ConfigFormUnit.cpp @@ -13,6 +13,7 @@ #pragma resource "*.dfm" TConfigForm *ConfigForm; bool Initialized; +bool IsEnglish; /* Save previous settings so we don't override custom settings */ int Maxfps; @@ -24,7 +25,40 @@ int Minfps; __fastcall TConfigForm::TConfigForm(TComponent* Owner) : TForm(Owner) { - if (SysLocale.PriLangID == LANG_CHINESE) { +} + +void __fastcall TConfigForm::LanguageLblClick(TObject *Sender) +{ + auto *ini = new TIniFile(".\\ddraw.ini"); + + if (IsEnglish) { + ini->WriteString("ddraw", "configlang", "auto"); + } + else { + ini->WriteString("ddraw", "configlang", "english"); + } + + delete ini; + + ShellExecute( + NULL, + L"open", + Application->ExeName.w_str(), + NULL, + NULL, + SW_SHOWNORMAL); + + Application->Terminate(); +} + +void TConfigForm::ApplyTranslation(TIniFile *ini) +{ + auto lang = LowerCase(ini->ReadString("ddraw", "configlang", "auto")); + int priID = SysLocale.PriLangID; + + if (lang == "chinese" || (lang == "auto" && priID == LANG_CHINESE)) { + LanguageLbl->Visible = true; + /* -Chinese Simplified- made by universal963 @ github */ ConfigForm->Caption = L"cnc-ddraw 配置"; @@ -72,7 +106,9 @@ __fastcall TConfigForm::TConfigForm(TComponent* Owner) MaxgameticksCbx->AddItem(L"25tick每秒", NULL); MaxgameticksCbx->AddItem(L"15tick每秒", NULL); } - else if (SysLocale.PriLangID == LANG_SPANISH) { + else if (lang == "spanish" || (lang == "auto" && priID == LANG_SPANISH)) { + LanguageLbl->Visible = true; + /* -Spanish- made by c-sanchez @ github */ ConfigForm->Caption = L"Ajustes de cnc-ddraw"; @@ -120,7 +156,9 @@ __fastcall TConfigForm::TConfigForm(TComponent* Owner) MaxgameticksCbx->AddItem(L"25 tics por segundo", NULL); MaxgameticksCbx->AddItem(L"15 tics por segundo", NULL); } - else if (SysLocale.PriLangID == LANG_GERMAN) { + else if (lang == "german" || (lang == "auto" && priID == LANG_GERMAN)) { + LanguageLbl->Visible = true; + /* -German- made by helgo1506 @ github */ ConfigForm->Caption = L"cnc-ddraw Konfiguration"; @@ -169,6 +207,28 @@ __fastcall TConfigForm::TConfigForm(TComponent* Owner) MaxgameticksCbx->AddItem(L"15 Ticks pro Sekunde", NULL); } else { + IsEnglish = true; + UnicodeString name = ""; + + try { + int lcid = Languages()->IndexOf(SysLocale.DefaultLCID); + name = SplitString(Languages()->Name[lcid].w_str(), L" (")[0]; + } catch (...) { + } + + if (priID == LANG_CHINESE) { + LanguageLbl->Visible = true; + LanguageLbl->Caption = name == "" ? "Chinese" : name; + } + else if (priID == LANG_SPANISH) { + LanguageLbl->Visible = true; + LanguageLbl->Caption = name == "" ? "Spanish" : name; + } + else if (priID == LANG_GERMAN) { + LanguageLbl->Visible = true; + LanguageLbl->Caption = name == "" ? "German" : name; + } + /* ConfigForm->Caption = L"cnc-ddraw config"; DisplayBtn->Caption = L"Display Settings"; @@ -243,6 +303,8 @@ void __fastcall TConfigForm::FormCreate(TObject *Sender) { auto *ini = new TIniFile(".\\ddraw.ini"); + ApplyTranslation(ini); + /* Display Settings */ bool windowed = GetBool(ini, "windowed", false); diff --git a/config/ConfigFormUnit.dfm b/config/ConfigFormUnit.dfm index 0ce5f57..ba802eb 100644 --- a/config/ConfigFormUnit.dfm +++ b/config/ConfigFormUnit.dfm @@ -2682,6 +2682,189 @@ object ConfigForm: TConfigForm OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 + object CompatibilityPnl: TPanel + Left = 201 + Top = 8 + Width = 499 + Height = 465 + BevelOuter = bvNone + Color = clWhite + ParentBackground = False + ShowCaption = False + TabOrder = 3 + Visible = False + StyleElements = [seFont, seBorder] + object MaxgameticksLbl: TLabel + Left = 40 + Top = 28 + Width = 123 + Height = 21 + Caption = 'Limit game speed' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -16 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + StyleElements = [seClient, seBorder] + end + object NoactivateappLbl: TLabel + Left = 40 + Top = 105 + Width = 129 + Height = 21 + Margins.Top = 18 + Caption = 'Fix broken Alt+Tab' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -16 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + StyleElements = [seClient, seBorder] + end + object HookLbl: TLabel + Left = 40 + Top = 173 + Width = 281 + Height = 21 + Margins.Top = 18 + Caption = 'Fix broken windowed mode or upscaling' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -16 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + StyleElements = [seClient, seBorder] + end + object MinfpsLbl: TLabel + Left = 40 + Top = 241 + Width = 350 + Height = 21 + Margins.Top = 18 + Caption = 'Force high FPS / Fix stuttering on Freesync/G-Sync' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -16 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + StyleElements = [seClient, seBorder] + end + object FixpitchLbl: TLabel + Left = 40 + Top = 309 + Width = 272 + Height = 21 + Margins.Top = 18 + Caption = 'Fix diagonally displayed drawing issues' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -16 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + StyleElements = [seClient, seBorder] + end + object NonexclusiveLbl: TLabel + Left = 40 + Top = 377 + Width = 225 + Height = 21 + Margins.Top = 18 + Caption = 'Fix invisible videos / UI elements' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -16 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + StyleElements = [seClient, seBorder] + end + object MaxgameticksPbox: TPaintBox + Left = 40 + Top = 54 + Width = 342 + Height = 31 + OnPaint = PboxPaint + end + object MaxgameticksCbx: TComboBox + Left = 41 + Top = 55 + Width = 340 + Height = 29 + BevelEdges = [] + BevelInner = bvNone + BevelOuter = bvSpace + Style = csDropDownList + DropDownCount = 10 + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -16 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + TabOrder = 0 + OnChange = MaxgameticksCbxChange + Items.Strings = ( + 'No limit' + 'Sync with monitor refresh rate' + 'Emulate 60hz refresh rate monitor' + '1000 ticks per second' + '500 ticks per second' + '60 ticks per second' + '30 ticks per second' + '25 ticks per second' + '15 ticks per second') + end + object NoactivateappChk: TToggleSwitch + Left = 40 + Top = 132 + Width = 50 + Height = 20 + ShowStateCaption = False + TabOrder = 1 + OnClick = NoactivateappChkClick + end + object HookChk: TToggleSwitch + Left = 40 + Top = 200 + Width = 50 + Height = 20 + ShowStateCaption = False + TabOrder = 2 + OnClick = HookChkClick + end + object MinfpsChk: TToggleSwitch + Left = 40 + Top = 268 + Width = 50 + Height = 20 + ShowStateCaption = False + TabOrder = 3 + OnClick = MinfpsChkClick + end + object FixpitchChk: TToggleSwitch + Left = 40 + Top = 336 + Width = 50 + Height = 20 + ShowStateCaption = False + TabOrder = 4 + OnClick = FixpitchChkClick + end + object NonexclusiveChk: TToggleSwitch + Left = 40 + Top = 404 + Width = 50 + Height = 20 + ShowStateCaption = False + TabOrder = 5 + OnClick = NonexclusiveChkClick + end + end object AdvancedPnl: TPanel Left = 201 Top = 8 @@ -2968,6 +3151,23 @@ object ConfigForm: TConfigForm Height = 31 OnPaint = PboxPaint end + object LanguageLbl: TLabel + Left = 453 + Top = 8 + Width = 38 + Height = 13 + Alignment = taRightJustify + Caption = 'English' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + Visible = False + StyleElements = [seClient, seBorder] + OnClick = LanguageLblClick + end object PresentationCbx: TComboBox Left = 41 Top = 55 @@ -3028,189 +3228,6 @@ object ConfigForm: TConfigForm OnClick = DevmodeChkClick end end - object CompatibilityPnl: TPanel - Left = 201 - Top = 8 - Width = 499 - Height = 465 - BevelOuter = bvNone - Color = clWhite - ParentBackground = False - ShowCaption = False - TabOrder = 3 - Visible = False - StyleElements = [seFont, seBorder] - object MaxgameticksLbl: TLabel - Left = 40 - Top = 28 - Width = 123 - Height = 21 - Caption = 'Limit game speed' - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -16 - Font.Name = 'Segoe UI' - Font.Style = [] - ParentFont = False - StyleElements = [seClient, seBorder] - end - object NoactivateappLbl: TLabel - Left = 40 - Top = 105 - Width = 129 - Height = 21 - Margins.Top = 18 - Caption = 'Fix broken Alt+Tab' - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -16 - Font.Name = 'Segoe UI' - Font.Style = [] - ParentFont = False - StyleElements = [seClient, seBorder] - end - object HookLbl: TLabel - Left = 40 - Top = 173 - Width = 281 - Height = 21 - Margins.Top = 18 - Caption = 'Fix broken windowed mode or upscaling' - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -16 - Font.Name = 'Segoe UI' - Font.Style = [] - ParentFont = False - StyleElements = [seClient, seBorder] - end - object MinfpsLbl: TLabel - Left = 40 - Top = 241 - Width = 350 - Height = 21 - Margins.Top = 18 - Caption = 'Force high FPS / Fix stuttering on Freesync/G-Sync' - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -16 - Font.Name = 'Segoe UI' - Font.Style = [] - ParentFont = False - StyleElements = [seClient, seBorder] - end - object FixpitchLbl: TLabel - Left = 40 - Top = 309 - Width = 272 - Height = 21 - Margins.Top = 18 - Caption = 'Fix diagonally displayed drawing issues' - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -16 - Font.Name = 'Segoe UI' - Font.Style = [] - ParentFont = False - StyleElements = [seClient, seBorder] - end - object NonexclusiveLbl: TLabel - Left = 40 - Top = 377 - Width = 225 - Height = 21 - Margins.Top = 18 - Caption = 'Fix invisible videos / UI elements' - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -16 - Font.Name = 'Segoe UI' - Font.Style = [] - ParentFont = False - StyleElements = [seClient, seBorder] - end - object MaxgameticksPbox: TPaintBox - Left = 40 - Top = 54 - Width = 342 - Height = 31 - OnPaint = PboxPaint - end - object MaxgameticksCbx: TComboBox - Left = 41 - Top = 55 - Width = 340 - Height = 29 - BevelEdges = [] - BevelInner = bvNone - BevelOuter = bvSpace - Style = csDropDownList - DropDownCount = 10 - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -16 - Font.Name = 'Segoe UI' - Font.Style = [] - ParentFont = False - TabOrder = 0 - OnChange = MaxgameticksCbxChange - Items.Strings = ( - 'No limit' - 'Sync with monitor refresh rate' - 'Emulate 60hz refresh rate monitor' - '1000 ticks per second' - '500 ticks per second' - '60 ticks per second' - '30 ticks per second' - '25 ticks per second' - '15 ticks per second') - end - object NoactivateappChk: TToggleSwitch - Left = 40 - Top = 132 - Width = 50 - Height = 20 - ShowStateCaption = False - TabOrder = 1 - OnClick = NoactivateappChkClick - end - object HookChk: TToggleSwitch - Left = 40 - Top = 200 - Width = 50 - Height = 20 - ShowStateCaption = False - TabOrder = 2 - OnClick = HookChkClick - end - object MinfpsChk: TToggleSwitch - Left = 40 - Top = 268 - Width = 50 - Height = 20 - ShowStateCaption = False - TabOrder = 3 - OnClick = MinfpsChkClick - end - object FixpitchChk: TToggleSwitch - Left = 40 - Top = 336 - Width = 50 - Height = 20 - ShowStateCaption = False - TabOrder = 4 - OnClick = FixpitchChkClick - end - object NonexclusiveChk: TToggleSwitch - Left = 40 - Top = 404 - Width = 50 - Height = 20 - ShowStateCaption = False - TabOrder = 5 - OnClick = NonexclusiveChkClick - end - end object MenuPnl: TPanel Left = 0 Top = 8 diff --git a/config/ConfigFormUnit.h b/config/ConfigFormUnit.h index c49a754..45e9c39 100644 --- a/config/ConfigFormUnit.h +++ b/config/ConfigFormUnit.h @@ -60,6 +60,7 @@ __published: // Von der IDE verwaltete Komponenten TPaintBox *RendererPbox; TPaintBox *ShaderPbox; TPaintBox *MaxgameticksPbox; + TLabel *LanguageLbl; void __fastcall DisplayBtnClick(TObject *Sender); void __fastcall AdvancedBtnClick(TObject *Sender); void __fastcall CompatibilityBtnClick(TObject *Sender); @@ -82,9 +83,11 @@ __published: // Von der IDE verwaltete Komponenten void __fastcall FixpitchChkClick(TObject *Sender); void __fastcall NonexclusiveChkClick(TObject *Sender); void __fastcall PboxPaint(TObject *Sender); + void __fastcall LanguageLblClick(TObject *Sender); private: // Benutzer-Deklarationen void SaveSettings(); bool GetBool(TIniFile *ini, System::UnicodeString key, bool defValue); + void ApplyTranslation(TIniFile *ini); public: // Benutzer-Deklarationen __fastcall TConfigForm(TComponent* Owner); }; diff --git a/src/config.c b/src/config.c index e7b3d6f..7126f46 100644 --- a/src/config.c +++ b/src/config.c @@ -323,6 +323,9 @@ static void cfg_create_ini() "; Force CPU0 affinity, avoids crashes/freezing, *might* have a performance impact\n" "singlecpu=true\n" "\n" + "; cnc-ddraw config program language, possible values: auto, english, chinese, german, spanish\n" + "configlang=auto\n" + "\n" "\n" "\n" "; ### Game specific settings ###\n"