From d87e4a846a07acb2be4812639efdfc49a1aad05c Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 25 Nov 2020 10:03:50 +0100 Subject: [PATCH] init of multi-language main menu --- d2app/app.go | 2 +- d2common/d2resource/languages_map.go | 25 +++++++++++++++ d2game/d2gamescreen/main_menu.go | 46 +++++++++++++++++++++++++--- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/d2app/app.go b/d2app/app.go index 8b13c0d1..bdb96e82 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -911,7 +911,7 @@ func (a *App) ToMainMenu(errorMessageOptional ...string) { buildInfo := d2gamescreen.BuildInfo{Branch: a.gitBranch, Commit: a.gitCommit} mainMenu, err := d2gamescreen.CreateMainMenu(a, a.asset, a.renderer, a.inputManager, a.audio, a.ui, buildInfo, - a.config.LogLevel, errorMessageOptional...) + a.language, a.config.LogLevel, errorMessageOptional...) if err != nil { a.Error(err.Error()) return diff --git a/d2common/d2resource/languages_map.go b/d2common/d2resource/languages_map.go index 2a549692..1c4529e2 100644 --- a/d2common/d2resource/languages_map.go +++ b/d2common/d2resource/languages_map.go @@ -49,3 +49,28 @@ func GetFontCharset(language string) string { return charset[language] } + +// modificators for labels (used in string tables +func getModificators() map[string]int { + return map[string]int{ + "ENG": 0, // (English) // checked + "ESP": 0, // (Spanish) + "DEU": 0, // (German) // checked + "FRA": 0, // (French) + "POR": 0, // (Portuguese) + "ITA": 0, // (Italian) + "JPN": 0, // (Japanese) + "KOR": 0, // (Korean) + "SIN": 0, // + "CHI": 0, // (Chinese) + "POL": 1, // (Polish) // checked + "RUS": 0, // (Russian) // checked + } +} + +// GetFontCharset returns modificator for language +func GetLabelModificator(language string) int { + mod := getModificators() + + return mod[language] +} diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index f17377e8..356fe060 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -83,6 +83,33 @@ type BuildInfo struct { Branch, Commit string } +const ( + singlePlayerLabel = iota + battleNetLabel + otherMultiplayerLabel + exitLabel + creditsLabel + cinematicsLabel + viewAllCinematicsLabel // (View All Earned Cinematics) + epilogueLabel + selectCinematics +) + +func baseLabelNumbers(idx int) int { + baseLabelNumbers := []int{ + 1620, // SINGLE PLAYER + 1621, // BATTLE.NET + 1623, // OTHER MULTIPLAYER + 1625, // EXIT DIABLO II + 1627, // CREDITS + 1639, // CINEMATICS + 1640, // View All Earned Cinematics + 1659, // Epilogue + 1660, // SELECT CINEMATICS + } + return baseLabelNumbers[idx] +} + // CreateMainMenu creates an instance of MainMenu func CreateMainMenu( navigator d2interface.Navigator, @@ -92,6 +119,7 @@ func CreateMainMenu( audioProvider d2interface.AudioProvider, ui *d2ui.UIManager, buildInfo BuildInfo, + lng string, l d2util.LogLevel, errorMessageOptional ...string, ) (*MainMenu, error) { @@ -111,6 +139,7 @@ func CreateMainMenu( buildInfo: buildInfo, uiManager: ui, heroState: heroStateFactory, + language: lng, } mainMenu.Logger = d2util.NewLogger() @@ -174,6 +203,8 @@ type MainMenu struct { buildInfo BuildInfo *d2util.Logger + + language string } // OnLoad is called to load the resources for the main menu @@ -328,21 +359,25 @@ func (v *MainMenu) createLogos(loading d2screen.LoadingState) { v.diabloLogoRightBack.SetPosition(diabloLogoX, diabloLogoY) } +func (v *MainMenu) translateLabel(label int, lng string) string { + return v.asset.TranslateString(fmt.Sprintf("#%d", baseLabelNumbers(label+d2resource.GetLabelModificator(lng)))) +} + func (v *MainMenu) createButtons(loading d2screen.LoadingState) { - v.exitDiabloButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, "EXIT DIABLO II") + v.exitDiabloButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.translateLabel(exitLabel, v.language)) v.exitDiabloButton.SetPosition(exitDiabloBtnX, exitDiabloBtnY) v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() }) - v.creditsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, "CREDITS") + v.creditsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, v.translateLabel(creditsLabel, v.language)) v.creditsButton.SetPosition(creditBtnX, creditBtnY) v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() }) - v.cinematicsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, "CINEMATICS") + v.cinematicsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, v.translateLabel(cinematicsLabel, v.language)) v.cinematicsButton.SetPosition(cineBtnX, cineBtnY) v.cinematicsButton.OnActivated(func() { v.onCinematicsButtonClicked() }) loading.Progress(seventyPercent) - v.singlePlayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, "SINGLE PLAYER") + v.singlePlayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.translateLabel(singlePlayerLabel, v.language)) v.singlePlayerButton.SetPosition(singlePlayerBtnX, singlePlayerBtnY) v.singlePlayerButton.OnActivated(func() { v.onSinglePlayerClicked() }) @@ -372,7 +407,8 @@ func (v *MainMenu) createButtons(loading d2screen.LoadingState) { } func (v *MainMenu) createMultiplayerMenuButtons() { - v.multiplayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, "MULTIPLAYER") + v.multiplayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, + v.translateLabel(otherMultiplayerLabel, v.language)) v.multiplayerButton.SetPosition(multiplayerBtnX, multiplayerBtnY) v.multiplayerButton.OnActivated(func() { v.onMultiplayerClicked() })