From 0f2c5cecb1b3ca221129a882b363a1d453c7273d Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Tue, 24 Nov 2020 17:50:31 +0100 Subject: [PATCH 01/15] fixed lints --- d2common/d2util/stringutils.go | 2 +- d2game/d2gamescreen/character_select.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/d2common/d2util/stringutils.go b/d2common/d2util/stringutils.go index c9d9aa65..24f268bd 100644 --- a/d2common/d2util/stringutils.go +++ b/d2common/d2util/stringutils.go @@ -135,7 +135,7 @@ func SplitIntoLinesWithMaxWidth(fullSentence string, maxChars int) []string { return lines } -// SplitIntoLineWithMaxWidthOneLine do the same as SplitIntoLinesWithMaxWidth but return string with newline char +// SplitIntoLinesWithMaxWidthOneLine does the same as SplitIntoLinesWithMaxWidth but return string with newline char func SplitIntoLinesWithMaxWidthOneLine(s string, l int) string { return strings.Join(SplitIntoLinesWithMaxWidth(s, l), "\n") } diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index c0c622a1..6bd355f8 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -296,11 +296,13 @@ func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) { v.newCharButton.SetPosition(newCharBtnX, newCharBtnY) v.newCharButton.OnActivated(func() { v.onNewCharButtonClicked() }) - v.convertCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#825"), 13)) + v.convertCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, + d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#825"), 13)) v.convertCharButton.SetPosition(convertCharBtnX, convertCharBtnY) v.convertCharButton.SetEnabled(false) - v.deleteCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#832"), 13)) + v.deleteCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, + d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#832"), 13)) v.deleteCharButton.OnActivated(func() { v.onDeleteCharButtonClicked() }) v.deleteCharButton.SetPosition(deleteCharBtnX, deleteCharBtnY) From d87e4a846a07acb2be4812639efdfc49a1aad05c Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 25 Nov 2020 10:03:50 +0100 Subject: [PATCH 02/15] 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() }) From 03a266467535b37e2bea3a465331a5dba3fc89cd Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 25 Nov 2020 11:06:05 +0100 Subject: [PATCH 03/15] function translateLabel is now global function of d2gamescreen --- d2game/d2gamescreen/main_menu.go | 45 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index 356fe060..95239f15 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -93,6 +93,13 @@ const ( viewAllCinematicsLabel // (View All Earned Cinematics) epilogueLabel selectCinematics + openBattleNetLaBEL + tcpIpGameLabel + tcpIpOptionsLabel + tcpIpHostGameLabel + tcpIpJoinGameLabel + tcpIpEnterHostIpLabel + tcpIpYourIpLabel ) func baseLabelNumbers(idx int) int { @@ -106,6 +113,15 @@ func baseLabelNumbers(idx int) int { 1640, // View All Earned Cinematics 1659, // Epilogue 1660, // SELECT CINEMATICS + 1663, // OPEN BATTLE.NET + 1666, // TCP/IP GAME + 1667, // TCP/IP Options + 1675, // HOST GAME + 1676, // JOIN GAME + 1678, // Enter Host IP Address to Join Game + 1680, // Your IP Address is: + 1689, // Tip: host game + 1690, // Tip: join game } return baseLabelNumbers[idx] } @@ -265,6 +281,10 @@ func (v *MainMenu) loadBackgroundSprites() { v.serverIPBackground.SetPosition(serverIPbackgroundX, serverIPbackgroundY) } +func translateLabel(label int, lng string, asset *d2asset.AssetManager) string { + return asset.TranslateString(fmt.Sprintf("#%d", baseLabelNumbers(label+d2resource.GetLabelModificator(lng)))) +} + func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.versionLabel = v.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteStatic) v.versionLabel.Alignment = d2ui.HorizontalAlignRight @@ -301,11 +321,12 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.tcpIPOptionsLabel = v.uiManager.NewLabel(d2resource.Font42, d2resource.PaletteUnits) v.tcpIPOptionsLabel.SetPosition(tcpOptionsX, tcpOptionsY) v.tcpIPOptionsLabel.Alignment = d2ui.HorizontalAlignCenter - v.tcpIPOptionsLabel.SetText("TCP/IP Options") + v.tcpIPOptionsLabel.SetText(translateLabel(tcpIpOptionsLabel, v.language, v.asset)) v.tcpJoinGameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.tcpJoinGameLabel.Alignment = d2ui.HorizontalAlignCenter - v.tcpJoinGameLabel.SetText("Enter Host IP Address\nto Join Game") + //v.tcpJoinGameLabel.SetText("Enter Host IP Address\nto Join Game") + v.tcpJoinGameLabel.SetText(translateLabel(tcpIpEnterHostIpLabel, v.language, v.asset)) v.tcpJoinGameLabel.Color[0] = rgbaColor(gold) v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY) @@ -359,25 +380,21 @@ 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, v.translateLabel(exitLabel, v.language)) + v.exitDiabloButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(exitLabel, v.language, v.asset)) v.exitDiabloButton.SetPosition(exitDiabloBtnX, exitDiabloBtnY) v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() }) - v.creditsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, v.translateLabel(creditsLabel, v.language)) + v.creditsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, translateLabel(creditsLabel, v.language, v.asset)) v.creditsButton.SetPosition(creditBtnX, creditBtnY) v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() }) - v.cinematicsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, v.translateLabel(cinematicsLabel, v.language)) + v.cinematicsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, translateLabel(cinematicsLabel, v.language, v.asset)) v.cinematicsButton.SetPosition(cineBtnX, cineBtnY) v.cinematicsButton.OnActivated(func() { v.onCinematicsButtonClicked() }) loading.Progress(seventyPercent) - v.singlePlayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.translateLabel(singlePlayerLabel, v.language)) + v.singlePlayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(singlePlayerLabel, v.language, v.asset)) v.singlePlayerButton.SetPosition(singlePlayerBtnX, singlePlayerBtnY) v.singlePlayerButton.OnActivated(func() { v.onSinglePlayerClicked() }) @@ -408,11 +425,11 @@ func (v *MainMenu) createButtons(loading d2screen.LoadingState) { func (v *MainMenu) createMultiplayerMenuButtons() { v.multiplayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, - v.translateLabel(otherMultiplayerLabel, v.language)) + translateLabel(otherMultiplayerLabel, v.language, v.asset)) v.multiplayerButton.SetPosition(multiplayerBtnX, multiplayerBtnY) v.multiplayerButton.OnActivated(func() { v.onMultiplayerClicked() }) - v.networkTCPIPButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, "TCP/IP GAME") + v.networkTCPIPButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIpGameLabel, v.language, v.asset)) v.networkTCPIPButton.SetPosition(tcpNetBtnX, tcpNetBtnY) v.networkTCPIPButton.OnActivated(func() { v.onNetworkTCPIPClicked() }) @@ -421,11 +438,11 @@ func (v *MainMenu) createMultiplayerMenuButtons() { v.networkCancelButton.SetPosition(networkCancelBtnX, networkCancelBtnY) v.networkCancelButton.OnActivated(func() { v.onNetworkCancelClicked() }) - v.btnTCPIPHostGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, "HOST GAME") + v.btnTCPIPHostGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIpHostGameLabel, v.language, v.asset)) v.btnTCPIPHostGame.SetPosition(tcpHostBtnX, tcpHostBtnY) v.btnTCPIPHostGame.OnActivated(func() { v.onTCPIPHostGameClicked() }) - v.btnTCPIPJoinGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, "JOIN GAME") + v.btnTCPIPJoinGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIpJoinGameLabel, v.language, v.asset)) v.btnTCPIPJoinGame.SetPosition(tcpJoinBtnX, tcpJoinBtnY) v.btnTCPIPJoinGame.OnActivated(func() { v.onTCPIPJoinGameClicked() }) } From 56787b13b8e3e7cf35f3fe49a6496226da5cff4d Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 25 Nov 2020 12:37:16 +0100 Subject: [PATCH 04/15] Opimalisation --- d2common/d2resource/languages_map.go | 6 ++-- d2core/d2asset/asset_manager.go | 39 +++++++------------------ d2game/d2gamescreen/character_select.go | 2 +- d2game/d2gamescreen/main_menu.go | 2 +- d2game/d2player/hero_stats_panel.go | 2 +- 5 files changed, 17 insertions(+), 34 deletions(-) diff --git a/d2common/d2resource/languages_map.go b/d2common/d2resource/languages_map.go index 1c4529e2..b1c13e6a 100644 --- a/d2common/d2resource/languages_map.go +++ b/d2common/d2resource/languages_map.go @@ -51,7 +51,7 @@ func GetFontCharset(language string) string { } // modificators for labels (used in string tables -func getModificators() map[string]int { +func getModifiers() map[string]int { return map[string]int{ "ENG": 0, // (English) // checked "ESP": 0, // (Spanish) @@ -69,8 +69,8 @@ func getModificators() map[string]int { } // GetFontCharset returns modificator for language -func GetLabelModificator(language string) int { - mod := getModificators() +func GetLabelModifier(language string) int { + mod := getModifiers() return mod[language] } diff --git a/d2core/d2asset/asset_manager.go b/d2core/d2asset/asset_manager.go index 5a5acdec..b048f20c 100644 --- a/d2core/d2asset/asset_manager.go +++ b/d2core/d2asset/asset_manager.go @@ -278,44 +278,27 @@ func (am *AssetManager) LoadStringTable(tablePath string) (d2tbl.TextDictionary, return table, err } -// TranslateString returns the translation of the given string. The string is retrieved from -// the loaded string tables. -func (am *AssetManager) TranslateString(key string) string { +func (am *AssetManager) TranslateString(input interface{}) string { + var key string + + switch s := input.(type) { + case string: + key = s + case fmt.Stringer: + key = s.String() + } + for idx := range am.tables { if value, found := am.tables[idx][key]; found { return value } } + // Fix to allow v.setDescLabels("#123") to be bypassed for a patch in issue #360. Reenable later. // log.Panicf("Could not find a string for the key '%s'", key) return key } -// TranslateHeroClass translates her class given to game locale -func (am *AssetManager) TranslateHeroClass(h d2enum.Hero) string { - switch h { - case d2enum.HeroBarbarian: - return am.TranslateString("Barbarian") - case d2enum.HeroNecromancer: - return am.TranslateString("Necromancer") - case d2enum.HeroPaladin: - return am.TranslateString("Paladin") - case d2enum.HeroAssassin: - return am.TranslateString("Assassin") - case d2enum.HeroSorceress: - return am.TranslateString("Sorceress") - case d2enum.HeroAmazon: - return am.TranslateString("Amazon") - case d2enum.HeroDruid: - return am.TranslateString("Druid") - default: - am.Error("Unknown Hero Class") - } - - // should not be reached - return "---" -} - // LoadPaletteTransform loads a palette transform file func (am *AssetManager) LoadPaletteTransform(path string) (*d2pl2.PL2, error) { if pl2, found := am.transforms.Retrieve(path); found { diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index 6bd355f8..b432adc6 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -349,7 +349,7 @@ func (v *CharacterSelect) updateCharacterBoxes() { heroName := v.gameStates[idx].HeroName heroInfo := v.asset.TranslateString("level") + " " + strconv.FormatInt(int64(v.gameStates[idx].Stats.Level), 10) + - " " + v.asset.TranslateHeroClass(v.gameStates[idx].HeroType) + " " + v.asset.TranslateString(v.gameStates[idx].HeroType.String()) v.characterNameLabel[i].SetText(d2ui.ColorTokenize(heroName, d2ui.ColorTokenGold)) v.characterStatsLabel[i].SetText(d2ui.ColorTokenize(heroInfo, d2ui.ColorTokenWhite)) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index 95239f15..e655b5fc 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -282,7 +282,7 @@ func (v *MainMenu) loadBackgroundSprites() { } func translateLabel(label int, lng string, asset *d2asset.AssetManager) string { - return asset.TranslateString(fmt.Sprintf("#%d", baseLabelNumbers(label+d2resource.GetLabelModificator(lng)))) + return asset.TranslateString(fmt.Sprintf("#%d", baseLabelNumbers(label+d2resource.GetLabelModifier(lng)))) } func (v *MainMenu) createLabels(loading d2screen.LoadingState) { diff --git a/d2game/d2player/hero_stats_panel.go b/d2game/d2player/hero_stats_panel.go index d1814a65..89658943 100644 --- a/d2game/d2player/hero_stats_panel.go +++ b/d2game/d2player/hero_stats_panel.go @@ -254,7 +254,7 @@ func (s *HeroStatsPanel) renderStaticLabels(target d2interface.Surface) { centerAlign bool }{ {labelHeroNameX, labelHeroNameY, s.heroName, d2resource.Font16, true}, - {labelHeroClassX, labelHeroClassY, s.asset.TranslateHeroClass(s.heroClass), d2resource.Font16, true}, + {labelHeroClassX, labelHeroClassY, s.asset.TranslateString(s.heroClass.String()), d2resource.Font16, true}, {labelLevelX, labelLevelY, s.asset.TranslateString("strchrlvl"), d2resource.Font6, true}, {labelExperienceX, labelExperienceY, s.asset.TranslateString("strchrexp"), d2resource.Font6, true}, From 122b49b1cf6b3eaa92c8e2001682a9375383b438 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 25 Nov 2020 18:40:56 +0100 Subject: [PATCH 05/15] Adds translatable labels in most part of main menu --- d2app/app.go | 6 +- d2game/d2gamescreen/character_select.go | 9 +- d2game/d2gamescreen/cinematics.go | 7 +- d2game/d2gamescreen/main_menu.go | 100 ++++++++++++++++++++--- d2game/d2gamescreen/select_hero_class.go | 36 +++++--- 5 files changed, 125 insertions(+), 33 deletions(-) diff --git a/d2app/app.go b/d2app/app.go index bdb96e82..186e17ec 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -922,7 +922,7 @@ func (a *App) ToMainMenu(errorMessageOptional ...string) { // ToSelectHero forces the game to transition to the Select Hero (create character) screen func (a *App) ToSelectHero(connType d2clientconnectiontype.ClientConnectionType, host string) { - selectHero, err := d2gamescreen.CreateSelectHeroClass(a, a.asset, a.renderer, a.audio, a.ui, connType, a.config.LogLevel, host) + selectHero, err := d2gamescreen.CreateSelectHeroClass(a, a.asset, a.renderer, a.audio, a.ui, connType, a.config.LogLevel, a.language, host) if err != nil { a.Error(err.Error()) return @@ -952,7 +952,7 @@ func (a *App) ToCreateGame(filePath string, connType d2clientconnectiontype.Clie // ToCharacterSelect forces the game to transition to the Character Select (load character) screen func (a *App) ToCharacterSelect(connType d2clientconnectiontype.ClientConnectionType, connHost string) { characterSelect, err := d2gamescreen.CreateCharacterSelect(a, a.asset, a.renderer, a.inputManager, - a.audio, a.ui, connType, a.config.LogLevel, connHost) + a.audio, a.ui, connType, a.config.LogLevel, a.language, connHost) if err != nil { fmt.Printf("unable to create character select screen: %s", err) } @@ -979,5 +979,5 @@ func (a *App) ToCredits() { // ToCinematics forces the game to transition to the cinematics menu func (a *App) ToCinematics() { - a.screen.SetNextScreen(d2gamescreen.CreateCinematics(a, a.asset, a.renderer, a.audio, a.config.LogLevel, a.ui)) + a.screen.SetNextScreen(d2gamescreen.CreateCinematics(a, a.asset, a.renderer, a.audio, a.config.LogLevel, a.language, a.ui)) } diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index b432adc6..0f049db2 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -29,6 +29,7 @@ func CreateCharacterSelect( ui *d2ui.UIManager, connectionType d2clientconnectiontype.ClientConnectionType, l d2util.LogLevel, + lang string, connectionHost string, ) (*CharacterSelect, error) { playerStateFactory, err := d2hero.NewHeroStateFactory(asset) @@ -53,6 +54,7 @@ func CreateCharacterSelect( navigator: navigator, uiManager: ui, HeroStateFactory: playerStateFactory, + language: lang, } characterSelect.Logger = d2util.NewLogger() @@ -100,6 +102,7 @@ type CharacterSelect struct { navigator d2interface.Navigator *d2util.Logger + language string } const ( @@ -229,7 +232,7 @@ func (v *CharacterSelect) loadHeroTitle() { func (v *CharacterSelect) loadDeleteCharConfirm() { v.deleteCharConfirmLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) - lines := "Are you sure that you want\nto delete this character?\nTake note: this will delete all\nversions of this Character." + lines := d2util.SplitIntoLinesWithMaxWidthOneLine(translateLabel(delCharConfLabel, v.language, v.asset), 30) v.deleteCharConfirmLabel.SetText(lines) v.deleteCharConfirmLabel.Alignment = d2ui.HorizontalAlignCenter deleteConfirmX, deleteConfirmY := 400, 185 @@ -312,12 +315,12 @@ func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) { loading.Progress(twentyPercent) - v.deleteCharCancelButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, "NO") + v.deleteCharCancelButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, translateLabel(noLabel, v.language, v.asset)) v.deleteCharCancelButton.SetPosition(deleteCancelX, deleteCancelY) v.deleteCharCancelButton.SetVisible(false) v.deleteCharCancelButton.OnActivated(func() { v.onDeleteCharacterCancelClicked() }) - v.deleteCharOkButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, "YES") + v.deleteCharOkButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, translateLabel(yesLabel, v.language, v.asset)) v.deleteCharOkButton.SetPosition(deleteOkX, deleteOkY) v.deleteCharOkButton.SetVisible(false) v.deleteCharOkButton.OnActivated(func() { v.onDeleteCharacterConfirmClicked() }) diff --git a/d2game/d2gamescreen/cinematics.go b/d2game/d2gamescreen/cinematics.go index 718c0efb..d5f59389 100644 --- a/d2game/d2gamescreen/cinematics.go +++ b/d2game/d2gamescreen/cinematics.go @@ -30,6 +30,7 @@ func CreateCinematics( renderer d2interface.Renderer, aup d2interface.AudioProvider, l d2util.LogLevel, + lang string, ui *d2ui.UIManager) *Cinematics { cinematics := &Cinematics{ asset: asset, @@ -37,6 +38,7 @@ func CreateCinematics( navigator: navigator, uiManager: ui, audioProvider: aup, + language: lang, } cinematics.Logger = d2util.NewLogger() @@ -68,6 +70,7 @@ type Cinematics struct { audioProvider d2interface.AudioProvider *d2util.Logger + language string } // OnLoad is called to load the resources for the credits screen @@ -96,13 +99,13 @@ func (v *Cinematics) OnLoad(_ d2screen.LoadingState) { v.cinematicsLabel = v.uiManager.NewLabel(d2resource.Font30, d2resource.PaletteStatic) v.cinematicsLabel.Alignment = d2ui.HorizontalAlignCenter - v.cinematicsLabel.SetText("SELECT CINEMATIC") + v.cinematicsLabel.SetText(translateLabel(selectCinematicLabel, v.language, v.asset)) v.cinematicsLabel.Color[0] = rgbaColor(lightBrown) v.cinematicsLabel.SetPosition(cinematicsLabelX, cinematicsLabelY) } func (v *Cinematics) createButtons() { - v.cinematicsExitBtn = v.uiManager.NewButton(d2ui.ButtonTypeMedium, v.asset.TranslateString("cancel")) + v.cinematicsExitBtn = v.uiManager.NewButton(d2ui.ButtonTypeMedium, v.asset.TranslateString(translateLabel(cancelLabel, v.language, v.asset))) v.cinematicsExitBtn.SetPosition(cinematicsExitBtnX, cinematicsExitBtnY) v.cinematicsExitBtn.OnActivated(func() { v.onCinematicsExitBtnClicked() }) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index e655b5fc..34235ac3 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -84,15 +84,23 @@ type BuildInfo struct { } const ( - singlePlayerLabel = iota + // main menu labels + cancelLabel = iota + copyrightLabel + allRightsReservedLabel + singlePlayerLabel battleNetLabel otherMultiplayerLabel exitLabel creditsLabel cinematicsLabel - viewAllCinematicsLabel // (View All Earned Cinematics) + + // cinematics menu labels + viewAllCinematicsLabel epilogueLabel - selectCinematics + selectCinematicLabel + + // multiplayer menu labels openBattleNetLaBEL tcpIpGameLabel tcpIpOptionsLabel @@ -100,19 +108,55 @@ const ( tcpIpJoinGameLabel tcpIpEnterHostIpLabel tcpIpYourIpLabel + tipHostLabel + tipJoinLabel + ipNotFoundLabel + + // select hero class menu labels + charNameLabel + hardCoreLabel + selectHeroClassLabel + amazonDescr + necromancerDescr + barbarianDescr + sorceressDescr + paladinDescr + + notUsed1 // this position isn't used here. + + hellLabel + nightmareLabel + normalLabel + selectDifficultyLabel + + notUsed2 + + delCharConfLabel + openLabel + notUsed3 + yesLabel + noLabel ) func baseLabelNumbers(idx int) int { baseLabelNumbers := []int{ + // main menu labels + 1612, // CANCEL + 1613, // (c) 2000 Blizzard Entertainment + 1614, // All Rights Reserved. 1620, // SINGLE PLAYER 1621, // BATTLE.NET 1623, // OTHER MULTIPLAYER 1625, // EXIT DIABLO II 1627, // CREDITS 1639, // CINEMATICS + + // cinematics menu labels 1640, // View All Earned Cinematics 1659, // Epilogue 1660, // SELECT CINEMATICS + + // multiplayer labels 1663, // OPEN BATTLE.NET 1666, // TCP/IP GAME 1667, // TCP/IP Options @@ -122,6 +166,39 @@ func baseLabelNumbers(idx int) int { 1680, // Your IP Address is: 1689, // Tip: host game 1690, // Tip: join game + 1691, // Cannot detect a valid TCP/IP address. + 1694, // Character Name + 1696, // Hardcore + 1697, // Select Hero Class + + 1698, // amazon description + 1704, // nec description + 1709, // barb description + 1710, // sorc description + 1711, // pal description + + /* these items are for battle.net multiplayer + labels and are not used yet + in addition, as many elements as the value + of the highest modifier must be replaced*/ + 1712, // not used here + + // difficulty levels: + 1800, // Hell + 1864, // Nightmare + 1865, // Normal + 1867, // Select Difficulty + + 1869, // not used, for locales with +1 mod + + 1878, // delete char confirm + 1881, // Open + 1889, // char name is currently taken (not used) + 1896, // YES + 1925, // NO + + 1926, // not used, for locales with +1 mod + } return baseLabelNumbers[idx] } @@ -300,14 +377,14 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.copyrightLabel = v.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteStatic) v.copyrightLabel.Alignment = d2ui.HorizontalAlignCenter - v.copyrightLabel.SetText("Diablo 2 is © Copyright 2000-2016 Blizzard Entertainment") + v.copyrightLabel.SetText(translateLabel(copyrightLabel, v.language, v.asset)) v.copyrightLabel.Color[0] = rgbaColor(lightBrown) v.copyrightLabel.SetPosition(copyrightX, copyrightY) loading.Progress(thirtyPercent) v.copyrightLabel2 = v.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteStatic) v.copyrightLabel2.Alignment = d2ui.HorizontalAlignCenter - v.copyrightLabel2.SetText("All Rights Reserved.") + v.copyrightLabel2.SetText(translateLabel(allRightsReservedLabel, v.language, v.asset)) v.copyrightLabel2.Color[0] = rgbaColor(lightBrown) v.copyrightLabel2.SetPosition(copyright2X, copyright2Y) @@ -325,14 +402,13 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.tcpJoinGameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.tcpJoinGameLabel.Alignment = d2ui.HorizontalAlignCenter - //v.tcpJoinGameLabel.SetText("Enter Host IP Address\nto Join Game") - v.tcpJoinGameLabel.SetText(translateLabel(tcpIpEnterHostIpLabel, v.language, v.asset)) + v.tcpJoinGameLabel.SetText(d2util.SplitIntoLinesWithMaxWidthOneLine(translateLabel(tcpIpEnterHostIpLabel, v.language, v.asset), 27)) v.tcpJoinGameLabel.Color[0] = rgbaColor(gold) v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY) v.machineIP = v.uiManager.NewLabel(d2resource.Font24, d2resource.PaletteUnits) v.machineIP.Alignment = d2ui.HorizontalAlignCenter - v.machineIP.SetText("Your IP address is:\n" + v.getLocalIP()) + v.machineIP.SetText(translateLabel(tcpIpYourIpLabel, v.language, v.asset) + "\n" + v.getLocalIP()) v.machineIP.Color[0] = rgbaColor(lightYellow) v.machineIP.SetPosition(machineIPX, machineIPY) @@ -407,11 +483,11 @@ func (v *MainMenu) createButtons(loading d2screen.LoadingState) { v.mapTestButton.OnActivated(func() { v.onMapTestClicked() }) v.btnTCPIPCancel = v.uiManager.NewButton(d2ui.ButtonTypeMedium, - v.asset.TranslateString("cancel")) + translateLabel(cancelLabel, v.language, v.asset)) v.btnTCPIPCancel.SetPosition(tcpBtnX, tcpBtnY) v.btnTCPIPCancel.OnActivated(func() { v.onTCPIPCancelClicked() }) - v.btnServerIPCancel = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, "CANCEL") + v.btnServerIPCancel = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, translateLabel(cancelLabel, v.language, v.asset)) v.btnServerIPCancel.SetPosition(srvCancelBtnX, srvCancelBtnY) v.btnServerIPCancel.OnActivated(func() { v.onBtnTCPIPCancelClicked() }) @@ -434,7 +510,7 @@ func (v *MainMenu) createMultiplayerMenuButtons() { v.networkTCPIPButton.OnActivated(func() { v.onNetworkTCPIPClicked() }) v.networkCancelButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, - v.asset.TranslateString("cancel")) + translateLabel(cancelLabel, v.language, v.asset)) v.networkCancelButton.SetPosition(networkCancelBtnX, networkCancelBtnY) v.networkCancelButton.OnActivated(func() { v.onNetworkCancelClicked() }) @@ -698,5 +774,5 @@ func (v *MainMenu) getLocalIP() string { v.Warning("no IPv4 Address could be found") - return "no IPv4 Address could be found" + return translateLabel(ipNotFoundLabel, v.language, v.asset) } diff --git a/d2game/d2gamescreen/select_hero_class.go b/d2game/d2gamescreen/select_hero_class.go index 733ccb4e..370ee5f3 100644 --- a/d2game/d2gamescreen/select_hero_class.go +++ b/d2game/d2gamescreen/select_hero_class.go @@ -279,6 +279,7 @@ func CreateSelectHeroClass( ui *d2ui.UIManager, connectionType d2clientconnectiontype.ClientConnectionType, l d2util.LogLevel, + lang string, connectionHost string, ) (*SelectHeroClass, error) { playerStateFactory, err := d2hero.NewHeroStateFactory(asset) @@ -303,6 +304,7 @@ func CreateSelectHeroClass( uiManager: ui, HeroStateFactory: playerStateFactory, InventoryItemFactory: inventoryItemFactory, + language: lang, } selectHeroClass.Logger = d2util.NewLogger() @@ -343,6 +345,7 @@ type SelectHeroClass struct { navigator d2interface.Navigator *d2util.Logger + language string } // OnLoad loads the resources for the Select Hero Class screen @@ -416,7 +419,7 @@ func (v *SelectHeroClass) createLabels() { halfFontWidth := fontWidth / half v.headingLabel.SetPosition(headingX-halfFontWidth, headingY) - v.headingLabel.SetText("Select Hero Class") + v.headingLabel.SetText(translateLabel(selectHeroClassLabel, v.language, v.asset)) v.headingLabel.Alignment = d2ui.HorizontalAlignCenter v.heroClassLabel = v.uiManager.NewLabel(d2resource.Font30, d2resource.PaletteUnits) @@ -437,17 +440,18 @@ func (v *SelectHeroClass) createLabels() { v.heroNameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.heroNameLabel.Alignment = d2ui.HorizontalAlignLeft - v.heroNameLabel.SetText(d2ui.ColorTokenize("Character Name", d2ui.ColorTokenGold)) + v.heroNameLabel.SetText(d2ui.ColorTokenize(translateLabel(charNameLabel, v.language, v.asset), d2ui.ColorTokenGold)) v.heroNameLabel.SetPosition(heroNameLabelX, heroNameLabelY) v.expansionCharLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.expansionCharLabel.Alignment = d2ui.HorizontalAlignLeft - v.expansionCharLabel.SetText(d2ui.ColorTokenize("EXPANSION CHARACTER", d2ui.ColorTokenGold)) + // to be honest, it should be TranslateString("#803"), but I suppose that's the same + v.expansionCharLabel.SetText(d2ui.ColorTokenize(v.asset.TranslateString("expansionchar2x"), d2ui.ColorTokenGold)) v.expansionCharLabel.SetPosition(expansionLabelX, expansionLabelY) v.hardcoreCharLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.hardcoreCharLabel.Alignment = d2ui.HorizontalAlignLeft - v.hardcoreCharLabel.SetText(d2ui.ColorTokenize("Hardcore", d2ui.ColorTokenGold)) + v.hardcoreCharLabel.SetText(d2ui.ColorTokenize(translateLabel(hardCoreLabel, v.language, v.asset), d2ui.ColorTokenGold)) v.hardcoreCharLabel.SetPosition(hardcoreLabelX, hardcoreLabelY) } @@ -685,25 +689,26 @@ func (v *SelectHeroClass) updateHeroText() { return case d2enum.HeroBarbarian: v.heroClassLabel.SetText(v.asset.TranslateString("partycharbar")) - v.setDescLabels("He is unequaled in close-quarters combat and mastery of weapons.") + v.setDescLabels(barbarianDescr, "") case d2enum.HeroNecromancer: v.heroClassLabel.SetText(v.asset.TranslateString("partycharnec")) - v.setDescLabels("Summoning undead minions and cursing his enemies are his specialties.") + v.setDescLabels(necromancerDescr, "") case d2enum.HeroPaladin: v.heroClassLabel.SetText(v.asset.TranslateString("partycharpal")) - v.setDescLabels("He is a natural party leader, holy man, and blessed warrior.") + v.setDescLabels(paladinDescr, "") case d2enum.HeroAssassin: v.heroClassLabel.SetText(v.asset.TranslateString("partycharass")) - v.setDescLabels("Schooled in the Martial Arts, her mind and body are deadly weapons.") + v.setDescLabels(0, "#305") case d2enum.HeroSorceress: v.heroClassLabel.SetText(v.asset.TranslateString("partycharsor")) - v.setDescLabels("She has mastered the elemental magicks -- fire, lightning, and ice.") + v.setDescLabels(sorceressDescr, "") case d2enum.HeroAmazon: v.heroClassLabel.SetText(v.asset.TranslateString("partycharama")) - v.setDescLabels("Skilled with the spear and the bow, she is a very versatile fighter.") + v.setDescLabels(amazonDescr, "") case d2enum.HeroDruid: v.heroClassLabel.SetText(v.asset.TranslateString("partychardru")) - v.setDescLabels("Commanding the forces of nature, he summons wild beasts and raging storms to his side.") + // here is a problem with polish language: in polish string table, there are two items with key "#304" + v.setDescLabels(0, "#304") } } @@ -712,8 +717,13 @@ const ( twoLine = 2 ) -func (v *SelectHeroClass) setDescLabels(descKey string) { - heroDesc := v.asset.TranslateString(descKey) +func (v *SelectHeroClass) setDescLabels(descKey int, key string) { + var heroDesc string + if key != "" { + heroDesc = v.asset.TranslateString(key) + } else { + heroDesc = translateLabel(descKey, v.language, v.asset) + } parts := d2util.SplitIntoLinesWithMaxWidth(heroDesc, heroDescCharWidth) numLines := len(parts) From 91f28516ffb4511eea334c47899e0585773de2b5 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 25 Nov 2020 19:25:19 +0100 Subject: [PATCH 06/15] fixed lints --- d2common/d2resource/languages_map.go | 2 +- d2core/d2asset/asset_manager.go | 2 ++ d2game/d2gamescreen/cinematics.go | 3 +- d2game/d2gamescreen/main_menu.go | 42 ++++++++++++++++-------- d2game/d2gamescreen/select_hero_class.go | 2 ++ 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/d2common/d2resource/languages_map.go b/d2common/d2resource/languages_map.go index b1c13e6a..0670982a 100644 --- a/d2common/d2resource/languages_map.go +++ b/d2common/d2resource/languages_map.go @@ -68,7 +68,7 @@ func getModifiers() map[string]int { } } -// GetFontCharset returns modificator for language +// GetLabelModifier returns modificator for language func GetLabelModifier(language string) int { mod := getModifiers() diff --git a/d2core/d2asset/asset_manager.go b/d2core/d2asset/asset_manager.go index b048f20c..9606b868 100644 --- a/d2core/d2asset/asset_manager.go +++ b/d2core/d2asset/asset_manager.go @@ -278,6 +278,8 @@ func (am *AssetManager) LoadStringTable(tablePath string) (d2tbl.TextDictionary, return table, err } +// TranslateString returns the translation of the given string. The string is retrieved from +// the loaded string tables. func (am *AssetManager) TranslateString(input interface{}) string { var key string diff --git a/d2game/d2gamescreen/cinematics.go b/d2game/d2gamescreen/cinematics.go index d5f59389..f00ea385 100644 --- a/d2game/d2gamescreen/cinematics.go +++ b/d2game/d2gamescreen/cinematics.go @@ -105,7 +105,8 @@ func (v *Cinematics) OnLoad(_ d2screen.LoadingState) { } func (v *Cinematics) createButtons() { - v.cinematicsExitBtn = v.uiManager.NewButton(d2ui.ButtonTypeMedium, v.asset.TranslateString(translateLabel(cancelLabel, v.language, v.asset))) + v.cinematicsExitBtn = v.uiManager.NewButton(d2ui.ButtonTypeMedium, + v.asset.TranslateString(translateLabel(cancelLabel, v.language, v.asset))) v.cinematicsExitBtn.SetPosition(cinematicsExitBtnX, cinematicsExitBtnY) v.cinematicsExitBtn.OnActivated(func() { v.onCinematicsExitBtnClicked() }) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index 34235ac3..c4079e9b 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -89,6 +89,7 @@ const ( copyrightLabel allRightsReservedLabel singlePlayerLabel + //nolint:deadcode,varcheck,unused // will be used, or is need battleNetLabel otherMultiplayerLabel exitLabel @@ -96,24 +97,30 @@ const ( cinematicsLabel // cinematics menu labels + //nolint:deadcode,varcheck,unused // will be used, or is need viewAllCinematicsLabel + //nolint:deadcode,varcheck,unused // will be used, or is need epilogueLabel selectCinematicLabel // multiplayer menu labels - openBattleNetLaBEL - tcpIpGameLabel - tcpIpOptionsLabel - tcpIpHostGameLabel - tcpIpJoinGameLabel - tcpIpEnterHostIpLabel - tcpIpYourIpLabel + //nolint:deadcode,varcheck,unused // will be used, or is need + openBattleNetLabeL + tcpIPGameLabel + tcpIPOptionsLabel + tcpIPHostGameLabel + tcpIPJoinGameLabel + tcpIPEnterHostIPLabel + tcpIPYourIPLabel + //nolint:deadcode,varcheck,unused // will be used, or is need tipHostLabel + //nolint:deadcode,varcheck,unused // will be used, or is need tipJoinLabel ipNotFoundLabel // select hero class menu labels charNameLabel + //nolint:deadcode,varcheck,unused // will be used, or is need hardCoreLabel selectHeroClassLabel amazonDescr @@ -122,17 +129,25 @@ const ( sorceressDescr paladinDescr + //nolint:deadcode,varcheck,unused // will be used, or is need notUsed1 // this position isn't used here. + //nolint:deadcode,varcheck,unused // will be used, or is need hellLabel + //nolint:deadcode,varcheck,unused // will be used, or is need nightmareLabel + //nolint:deadcode,varcheck,unused // will be used, or is need normalLabel + //nolint:deadcode,varcheck,unused // will be used, or is need selectDifficultyLabel + //nolint:deadcode,varcheck,unused // will be used, or is need notUsed2 delCharConfLabel + //nolint:deadcode,varcheck,unused // will be used, or is need openLabel + //nolint:deadcode,varcheck,unused // will be used, or is need notUsed3 yesLabel noLabel @@ -200,6 +215,7 @@ func baseLabelNumbers(idx int) int { 1926, // not used, for locales with +1 mod } + return baseLabelNumbers[idx] } @@ -398,17 +414,17 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.tcpIPOptionsLabel = v.uiManager.NewLabel(d2resource.Font42, d2resource.PaletteUnits) v.tcpIPOptionsLabel.SetPosition(tcpOptionsX, tcpOptionsY) v.tcpIPOptionsLabel.Alignment = d2ui.HorizontalAlignCenter - v.tcpIPOptionsLabel.SetText(translateLabel(tcpIpOptionsLabel, v.language, v.asset)) + v.tcpIPOptionsLabel.SetText(translateLabel(tcpIPOptionsLabel, v.language, v.asset)) v.tcpJoinGameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.tcpJoinGameLabel.Alignment = d2ui.HorizontalAlignCenter - v.tcpJoinGameLabel.SetText(d2util.SplitIntoLinesWithMaxWidthOneLine(translateLabel(tcpIpEnterHostIpLabel, v.language, v.asset), 27)) + v.tcpJoinGameLabel.SetText(d2util.SplitIntoLinesWithMaxWidthOneLine(translateLabel(tcpIPEnterHostIPLabel, v.language, v.asset), 27)) v.tcpJoinGameLabel.Color[0] = rgbaColor(gold) v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY) v.machineIP = v.uiManager.NewLabel(d2resource.Font24, d2resource.PaletteUnits) v.machineIP.Alignment = d2ui.HorizontalAlignCenter - v.machineIP.SetText(translateLabel(tcpIpYourIpLabel, v.language, v.asset) + "\n" + v.getLocalIP()) + v.machineIP.SetText(translateLabel(tcpIPYourIPLabel, v.language, v.asset) + "\n" + v.getLocalIP()) v.machineIP.Color[0] = rgbaColor(lightYellow) v.machineIP.SetPosition(machineIPX, machineIPY) @@ -505,7 +521,7 @@ func (v *MainMenu) createMultiplayerMenuButtons() { v.multiplayerButton.SetPosition(multiplayerBtnX, multiplayerBtnY) v.multiplayerButton.OnActivated(func() { v.onMultiplayerClicked() }) - v.networkTCPIPButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIpGameLabel, v.language, v.asset)) + v.networkTCPIPButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIPGameLabel, v.language, v.asset)) v.networkTCPIPButton.SetPosition(tcpNetBtnX, tcpNetBtnY) v.networkTCPIPButton.OnActivated(func() { v.onNetworkTCPIPClicked() }) @@ -514,11 +530,11 @@ func (v *MainMenu) createMultiplayerMenuButtons() { v.networkCancelButton.SetPosition(networkCancelBtnX, networkCancelBtnY) v.networkCancelButton.OnActivated(func() { v.onNetworkCancelClicked() }) - v.btnTCPIPHostGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIpHostGameLabel, v.language, v.asset)) + v.btnTCPIPHostGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIPHostGameLabel, v.language, v.asset)) v.btnTCPIPHostGame.SetPosition(tcpHostBtnX, tcpHostBtnY) v.btnTCPIPHostGame.OnActivated(func() { v.onTCPIPHostGameClicked() }) - v.btnTCPIPJoinGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIpJoinGameLabel, v.language, v.asset)) + v.btnTCPIPJoinGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIPJoinGameLabel, v.language, v.asset)) v.btnTCPIPJoinGame.SetPosition(tcpJoinBtnX, tcpJoinBtnY) v.btnTCPIPJoinGame.OnActivated(func() { v.onTCPIPJoinGameClicked() }) } diff --git a/d2game/d2gamescreen/select_hero_class.go b/d2game/d2gamescreen/select_hero_class.go index 370ee5f3..1c1f93cb 100644 --- a/d2game/d2gamescreen/select_hero_class.go +++ b/d2game/d2gamescreen/select_hero_class.go @@ -719,11 +719,13 @@ const ( func (v *SelectHeroClass) setDescLabels(descKey int, key string) { var heroDesc string + if key != "" { heroDesc = v.asset.TranslateString(key) } else { heroDesc = translateLabel(descKey, v.language, v.asset) } + parts := d2util.SplitIntoLinesWithMaxWidth(heroDesc, heroDescCharWidth) numLines := len(parts) From 6f6516ae33c62ab4bdd08223d7764ad8d9b05252 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Wed, 25 Nov 2020 20:57:52 +0100 Subject: [PATCH 07/15] a bit updated comments --- d2common/d2resource/languages_map.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/d2common/d2resource/languages_map.go b/d2common/d2resource/languages_map.go index 0670982a..7d620a0c 100644 --- a/d2common/d2resource/languages_map.go +++ b/d2common/d2resource/languages_map.go @@ -50,7 +50,9 @@ func GetFontCharset(language string) string { return charset[language] } -// modificators for labels (used in string tables +// modificators for labels (used in string tables) +// some of values need to be set up. For now values with "checked" comment +// was tested and works fine in main menu. func getModifiers() map[string]int { return map[string]int{ "ENG": 0, // (English) // checked From e5bab6660b8713536f87bd2ece781e1e2980c278 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Thu, 26 Nov 2020 10:17:56 +0100 Subject: [PATCH 08/15] modification of comments --- d2game/d2gamescreen/main_menu.go | 10 +++++----- d2game/d2player/hero_stats_panel.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index c4079e9b..e1d9cbe3 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -191,12 +191,12 @@ func baseLabelNumbers(idx int) int { 1709, // barb description 1710, // sorc description 1711, // pal description + /*in addition, as many elements as the value + of the highest modifier must be listed*/ + 1712, - /* these items are for battle.net multiplayer - labels and are not used yet - in addition, as many elements as the value - of the highest modifier must be replaced*/ - 1712, // not used here + /* here, should be labels used to battle.net multiplayer, but they are not used yet, + therefore I don't list them here.*/ // difficulty levels: 1800, // Hell diff --git a/d2game/d2player/hero_stats_panel.go b/d2game/d2player/hero_stats_panel.go index 89658943..41cd0b59 100644 --- a/d2game/d2player/hero_stats_panel.go +++ b/d2game/d2player/hero_stats_panel.go @@ -254,7 +254,7 @@ func (s *HeroStatsPanel) renderStaticLabels(target d2interface.Surface) { centerAlign bool }{ {labelHeroNameX, labelHeroNameY, s.heroName, d2resource.Font16, true}, - {labelHeroClassX, labelHeroClassY, s.asset.TranslateString(s.heroClass.String()), d2resource.Font16, true}, + {labelHeroClassX, labelHeroClassY, s.asset.TranslateString(s.heroClass), d2resource.Font16, true}, {labelLevelX, labelLevelY, s.asset.TranslateString("strchrlvl"), d2resource.Font6, true}, {labelExperienceX, labelExperienceY, s.asset.TranslateString("strchrexp"), d2resource.Font6, true}, From 76257ca351c53f0714091b2f29d5160d04a3af3a Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Thu, 26 Nov 2020 11:13:35 +0100 Subject: [PATCH 09/15] moved some stuff --- d2app/app.go | 6 +- d2common/d2resource/languages_map.go | 25 +++--- d2core/d2asset/asset_manager.go | 72 +++++++++++++++ d2game/d2gamescreen/character_select.go | 9 +- d2game/d2gamescreen/cinematics.go | 7 +- d2game/d2gamescreen/main_menu.go | 107 ++++------------------- d2game/d2gamescreen/select_hero_class.go | 11 +-- 7 files changed, 116 insertions(+), 121 deletions(-) diff --git a/d2app/app.go b/d2app/app.go index 186e17ec..bdb96e82 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -922,7 +922,7 @@ func (a *App) ToMainMenu(errorMessageOptional ...string) { // ToSelectHero forces the game to transition to the Select Hero (create character) screen func (a *App) ToSelectHero(connType d2clientconnectiontype.ClientConnectionType, host string) { - selectHero, err := d2gamescreen.CreateSelectHeroClass(a, a.asset, a.renderer, a.audio, a.ui, connType, a.config.LogLevel, a.language, host) + selectHero, err := d2gamescreen.CreateSelectHeroClass(a, a.asset, a.renderer, a.audio, a.ui, connType, a.config.LogLevel, host) if err != nil { a.Error(err.Error()) return @@ -952,7 +952,7 @@ func (a *App) ToCreateGame(filePath string, connType d2clientconnectiontype.Clie // ToCharacterSelect forces the game to transition to the Character Select (load character) screen func (a *App) ToCharacterSelect(connType d2clientconnectiontype.ClientConnectionType, connHost string) { characterSelect, err := d2gamescreen.CreateCharacterSelect(a, a.asset, a.renderer, a.inputManager, - a.audio, a.ui, connType, a.config.LogLevel, a.language, connHost) + a.audio, a.ui, connType, a.config.LogLevel, connHost) if err != nil { fmt.Printf("unable to create character select screen: %s", err) } @@ -979,5 +979,5 @@ func (a *App) ToCredits() { // ToCinematics forces the game to transition to the cinematics menu func (a *App) ToCinematics() { - a.screen.SetNextScreen(d2gamescreen.CreateCinematics(a, a.asset, a.renderer, a.audio, a.config.LogLevel, a.language, a.ui)) + a.screen.SetNextScreen(d2gamescreen.CreateCinematics(a, a.asset, a.renderer, a.audio, a.config.LogLevel, a.ui)) } diff --git a/d2common/d2resource/languages_map.go b/d2common/d2resource/languages_map.go index 7d620a0c..617b21f3 100644 --- a/d2common/d2resource/languages_map.go +++ b/d2common/d2resource/languages_map.go @@ -50,11 +50,21 @@ func GetFontCharset(language string) string { return charset[language] } -// modificators for labels (used in string tables) +/* modifiers for labels (used in string tables) +modifier is something like that: +english table: polish table: +key | value key | value +#1 | v1 | +#4 | v2 #4 | v1 +#5 | v3 #5 | v2 +#8 | v4 #8 | v3 +So, GetLabelModifier returns value of offset in locale languages table +*/ // some of values need to be set up. For now values with "checked" comment // was tested and works fine in main menu. -func getModifiers() map[string]int { - return map[string]int{ +// GetLabelModifier returns modifier for language +func GetLabelModifier(language string) int { + modifiers := map[string]int{ "ENG": 0, // (English) // checked "ESP": 0, // (Spanish) "DEU": 0, // (German) // checked @@ -66,13 +76,8 @@ func getModifiers() map[string]int { "SIN": 0, // "CHI": 0, // (Chinese) "POL": 1, // (Polish) // checked - "RUS": 0, // (Russian) // checked + "RUS": 0, // (Russian) } -} -// GetLabelModifier returns modificator for language -func GetLabelModifier(language string) int { - mod := getModifiers() - - return mod[language] + return modifiers[language] } diff --git a/d2core/d2asset/asset_manager.go b/d2core/d2asset/asset_manager.go index 9606b868..079bee07 100644 --- a/d2core/d2asset/asset_manager.go +++ b/d2core/d2asset/asset_manager.go @@ -57,6 +57,7 @@ type AssetManager struct { palettes d2interface.Cache transforms d2interface.Cache Records *d2records.RecordManager + language string } // SetLogLevel sets the log level for the asset manager, record manager, and file loader @@ -124,6 +125,7 @@ func (am *AssetManager) LoadLanguage(languagePath string) string { language := d2resource.GetLanguageLiteral(languageCode) am.Infof("Language: %s", language) + am.language = language return language } @@ -301,6 +303,76 @@ func (am *AssetManager) TranslateString(input interface{}) string { return key } +func (a *AssetManager) baseLabelNumbers(idx int) int { + baseLabelNumbers := []int{ + // main menu labels + 1612, // CANCEL + 1613, // (c) 2000 Blizzard Entertainment + 1614, // All Rights Reserved. + 1620, // SINGLE PLAYER + 1621, // BATTLE.NET + 1623, // OTHER MULTIPLAYER + 1625, // EXIT DIABLO II + 1627, // CREDITS + 1639, // CINEMATICS + + // cinematics menu labels + 1640, // View All Earned Cinematics + 1659, // Epilogue + 1660, // SELECT CINEMATICS + + // multiplayer labels + 1663, // OPEN BATTLE.NET + 1666, // TCP/IP GAME + 1667, // TCP/IP Options + 1675, // HOST GAME + 1676, // JOIN GAME + 1678, // Enter Host IP Address to Join Game + 1680, // Your IP Address is: + 1689, // Tip: host game + 1690, // Tip: join game + 1691, // Cannot detect a valid TCP/IP address. + 1694, // Character Name + 1696, // Hardcore + 1697, // Select Hero Class + + 1698, // amazon description + 1704, // nec description + 1709, // barb description + 1710, // sorc description + 1711, // pal description + /*in addition, as many elements as the value + of the highest modifier must be listed*/ + 1712, + + /* here, should be labels used to battle.net multiplayer, but they are not used yet, + therefore I don't list them here.*/ + + // difficulty levels: + 1800, // Hell + 1864, // Nightmare + 1865, // Normal + 1867, // Select Difficulty + + 1869, // not used, for locales with +1 mod + 1878, // delete char confirm + 1881, // Open + 1889, // char name is currently taken (not used) + 1896, // YES + 1925, // NO + + 1926, // not used, for locales with +1 mod + + } + + return baseLabelNumbers[idx] +} + +// TranslateLabel translates the label taking into account its shift in the table +func (a *AssetManager) TranslateLabel(label int) string { + return a.TranslateString(fmt.Sprintf("#%d", a.baseLabelNumbers(label+d2resource.GetLabelModifier(a.language)))) +} + // LoadPaletteTransform loads a palette transform file func (am *AssetManager) LoadPaletteTransform(path string) (*d2pl2.PL2, error) { if pl2, found := am.transforms.Retrieve(path); found { diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index 0f049db2..e7e321e7 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -29,7 +29,6 @@ func CreateCharacterSelect( ui *d2ui.UIManager, connectionType d2clientconnectiontype.ClientConnectionType, l d2util.LogLevel, - lang string, connectionHost string, ) (*CharacterSelect, error) { playerStateFactory, err := d2hero.NewHeroStateFactory(asset) @@ -54,7 +53,6 @@ func CreateCharacterSelect( navigator: navigator, uiManager: ui, HeroStateFactory: playerStateFactory, - language: lang, } characterSelect.Logger = d2util.NewLogger() @@ -102,7 +100,6 @@ type CharacterSelect struct { navigator d2interface.Navigator *d2util.Logger - language string } const ( @@ -232,7 +229,7 @@ func (v *CharacterSelect) loadHeroTitle() { func (v *CharacterSelect) loadDeleteCharConfirm() { v.deleteCharConfirmLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) - lines := d2util.SplitIntoLinesWithMaxWidthOneLine(translateLabel(delCharConfLabel, v.language, v.asset), 30) + lines := d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateLabel(delCharConfLabel), 30) v.deleteCharConfirmLabel.SetText(lines) v.deleteCharConfirmLabel.Alignment = d2ui.HorizontalAlignCenter deleteConfirmX, deleteConfirmY := 400, 185 @@ -315,12 +312,12 @@ func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) { loading.Progress(twentyPercent) - v.deleteCharCancelButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, translateLabel(noLabel, v.language, v.asset)) + v.deleteCharCancelButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, v.asset.TranslateLabel(noLabel)) v.deleteCharCancelButton.SetPosition(deleteCancelX, deleteCancelY) v.deleteCharCancelButton.SetVisible(false) v.deleteCharCancelButton.OnActivated(func() { v.onDeleteCharacterCancelClicked() }) - v.deleteCharOkButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, translateLabel(yesLabel, v.language, v.asset)) + v.deleteCharOkButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, v.asset.TranslateLabel(yesLabel)) v.deleteCharOkButton.SetPosition(deleteOkX, deleteOkY) v.deleteCharOkButton.SetVisible(false) v.deleteCharOkButton.OnActivated(func() { v.onDeleteCharacterConfirmClicked() }) diff --git a/d2game/d2gamescreen/cinematics.go b/d2game/d2gamescreen/cinematics.go index f00ea385..76b51a83 100644 --- a/d2game/d2gamescreen/cinematics.go +++ b/d2game/d2gamescreen/cinematics.go @@ -30,7 +30,6 @@ func CreateCinematics( renderer d2interface.Renderer, aup d2interface.AudioProvider, l d2util.LogLevel, - lang string, ui *d2ui.UIManager) *Cinematics { cinematics := &Cinematics{ asset: asset, @@ -38,7 +37,6 @@ func CreateCinematics( navigator: navigator, uiManager: ui, audioProvider: aup, - language: lang, } cinematics.Logger = d2util.NewLogger() @@ -70,7 +68,6 @@ type Cinematics struct { audioProvider d2interface.AudioProvider *d2util.Logger - language string } // OnLoad is called to load the resources for the credits screen @@ -99,14 +96,14 @@ func (v *Cinematics) OnLoad(_ d2screen.LoadingState) { v.cinematicsLabel = v.uiManager.NewLabel(d2resource.Font30, d2resource.PaletteStatic) v.cinematicsLabel.Alignment = d2ui.HorizontalAlignCenter - v.cinematicsLabel.SetText(translateLabel(selectCinematicLabel, v.language, v.asset)) + v.cinematicsLabel.SetText(v.asset.TranslateLabel(selectCinematicLabel)) v.cinematicsLabel.Color[0] = rgbaColor(lightBrown) v.cinematicsLabel.SetPosition(cinematicsLabelX, cinematicsLabelY) } func (v *Cinematics) createButtons() { v.cinematicsExitBtn = v.uiManager.NewButton(d2ui.ButtonTypeMedium, - v.asset.TranslateString(translateLabel(cancelLabel, v.language, v.asset))) + v.asset.TranslateString(v.asset.TranslateLabel(cancelLabel))) v.cinematicsExitBtn.SetPosition(cinematicsExitBtnX, cinematicsExitBtnY) v.cinematicsExitBtn.OnActivated(func() { v.onCinematicsExitBtnClicked() }) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index e1d9cbe3..8c4cc009 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -153,72 +153,6 @@ const ( noLabel ) -func baseLabelNumbers(idx int) int { - baseLabelNumbers := []int{ - // main menu labels - 1612, // CANCEL - 1613, // (c) 2000 Blizzard Entertainment - 1614, // All Rights Reserved. - 1620, // SINGLE PLAYER - 1621, // BATTLE.NET - 1623, // OTHER MULTIPLAYER - 1625, // EXIT DIABLO II - 1627, // CREDITS - 1639, // CINEMATICS - - // cinematics menu labels - 1640, // View All Earned Cinematics - 1659, // Epilogue - 1660, // SELECT CINEMATICS - - // multiplayer labels - 1663, // OPEN BATTLE.NET - 1666, // TCP/IP GAME - 1667, // TCP/IP Options - 1675, // HOST GAME - 1676, // JOIN GAME - 1678, // Enter Host IP Address to Join Game - 1680, // Your IP Address is: - 1689, // Tip: host game - 1690, // Tip: join game - 1691, // Cannot detect a valid TCP/IP address. - 1694, // Character Name - 1696, // Hardcore - 1697, // Select Hero Class - - 1698, // amazon description - 1704, // nec description - 1709, // barb description - 1710, // sorc description - 1711, // pal description - /*in addition, as many elements as the value - of the highest modifier must be listed*/ - 1712, - - /* here, should be labels used to battle.net multiplayer, but they are not used yet, - therefore I don't list them here.*/ - - // difficulty levels: - 1800, // Hell - 1864, // Nightmare - 1865, // Normal - 1867, // Select Difficulty - - 1869, // not used, for locales with +1 mod - - 1878, // delete char confirm - 1881, // Open - 1889, // char name is currently taken (not used) - 1896, // YES - 1925, // NO - - 1926, // not used, for locales with +1 mod - - } - - return baseLabelNumbers[idx] -} - // CreateMainMenu creates an instance of MainMenu func CreateMainMenu( navigator d2interface.Navigator, @@ -248,7 +182,6 @@ func CreateMainMenu( buildInfo: buildInfo, uiManager: ui, heroState: heroStateFactory, - language: lng, } mainMenu.Logger = d2util.NewLogger() @@ -312,8 +245,6 @@ type MainMenu struct { buildInfo BuildInfo *d2util.Logger - - language string } // OnLoad is called to load the resources for the main menu @@ -374,10 +305,6 @@ func (v *MainMenu) loadBackgroundSprites() { v.serverIPBackground.SetPosition(serverIPbackgroundX, serverIPbackgroundY) } -func translateLabel(label int, lng string, asset *d2asset.AssetManager) string { - return asset.TranslateString(fmt.Sprintf("#%d", baseLabelNumbers(label+d2resource.GetLabelModifier(lng)))) -} - func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.versionLabel = v.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteStatic) v.versionLabel.Alignment = d2ui.HorizontalAlignRight @@ -393,14 +320,14 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.copyrightLabel = v.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteStatic) v.copyrightLabel.Alignment = d2ui.HorizontalAlignCenter - v.copyrightLabel.SetText(translateLabel(copyrightLabel, v.language, v.asset)) + v.copyrightLabel.SetText(v.asset.TranslateLabel(copyrightLabel)) v.copyrightLabel.Color[0] = rgbaColor(lightBrown) v.copyrightLabel.SetPosition(copyrightX, copyrightY) loading.Progress(thirtyPercent) v.copyrightLabel2 = v.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteStatic) v.copyrightLabel2.Alignment = d2ui.HorizontalAlignCenter - v.copyrightLabel2.SetText(translateLabel(allRightsReservedLabel, v.language, v.asset)) + v.copyrightLabel2.SetText(v.asset.TranslateLabel(allRightsReservedLabel)) v.copyrightLabel2.Color[0] = rgbaColor(lightBrown) v.copyrightLabel2.SetPosition(copyright2X, copyright2Y) @@ -414,17 +341,17 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.tcpIPOptionsLabel = v.uiManager.NewLabel(d2resource.Font42, d2resource.PaletteUnits) v.tcpIPOptionsLabel.SetPosition(tcpOptionsX, tcpOptionsY) v.tcpIPOptionsLabel.Alignment = d2ui.HorizontalAlignCenter - v.tcpIPOptionsLabel.SetText(translateLabel(tcpIPOptionsLabel, v.language, v.asset)) + v.tcpIPOptionsLabel.SetText(v.asset.TranslateLabel(tcpIPOptionsLabel)) v.tcpJoinGameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.tcpJoinGameLabel.Alignment = d2ui.HorizontalAlignCenter - v.tcpJoinGameLabel.SetText(d2util.SplitIntoLinesWithMaxWidthOneLine(translateLabel(tcpIPEnterHostIPLabel, v.language, v.asset), 27)) + v.tcpJoinGameLabel.SetText(d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateLabel(tcpIPEnterHostIPLabel), 27)) v.tcpJoinGameLabel.Color[0] = rgbaColor(gold) v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY) v.machineIP = v.uiManager.NewLabel(d2resource.Font24, d2resource.PaletteUnits) v.machineIP.Alignment = d2ui.HorizontalAlignCenter - v.machineIP.SetText(translateLabel(tcpIPYourIPLabel, v.language, v.asset) + "\n" + v.getLocalIP()) + v.machineIP.SetText(v.asset.TranslateLabel(tcpIPYourIPLabel) + "\n" + v.getLocalIP()) v.machineIP.Color[0] = rgbaColor(lightYellow) v.machineIP.SetPosition(machineIPX, machineIPY) @@ -473,20 +400,20 @@ func (v *MainMenu) createLogos(loading d2screen.LoadingState) { } func (v *MainMenu) createButtons(loading d2screen.LoadingState) { - v.exitDiabloButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(exitLabel, v.language, v.asset)) + v.exitDiabloButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateLabel(exitLabel)) v.exitDiabloButton.SetPosition(exitDiabloBtnX, exitDiabloBtnY) v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() }) - v.creditsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, translateLabel(creditsLabel, v.language, v.asset)) + v.creditsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, v.asset.TranslateLabel(creditsLabel)) v.creditsButton.SetPosition(creditBtnX, creditBtnY) v.creditsButton.OnActivated(func() { v.onCreditsButtonClicked() }) - v.cinematicsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, translateLabel(cinematicsLabel, v.language, v.asset)) + v.cinematicsButton = v.uiManager.NewButton(d2ui.ButtonTypeShort, v.asset.TranslateLabel(cinematicsLabel)) v.cinematicsButton.SetPosition(cineBtnX, cineBtnY) v.cinematicsButton.OnActivated(func() { v.onCinematicsButtonClicked() }) loading.Progress(seventyPercent) - v.singlePlayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(singlePlayerLabel, v.language, v.asset)) + v.singlePlayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateLabel(singlePlayerLabel)) v.singlePlayerButton.SetPosition(singlePlayerBtnX, singlePlayerBtnY) v.singlePlayerButton.OnActivated(func() { v.onSinglePlayerClicked() }) @@ -499,11 +426,11 @@ func (v *MainMenu) createButtons(loading d2screen.LoadingState) { v.mapTestButton.OnActivated(func() { v.onMapTestClicked() }) v.btnTCPIPCancel = v.uiManager.NewButton(d2ui.ButtonTypeMedium, - translateLabel(cancelLabel, v.language, v.asset)) + v.asset.TranslateLabel(cancelLabel)) v.btnTCPIPCancel.SetPosition(tcpBtnX, tcpBtnY) v.btnTCPIPCancel.OnActivated(func() { v.onTCPIPCancelClicked() }) - v.btnServerIPCancel = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, translateLabel(cancelLabel, v.language, v.asset)) + v.btnServerIPCancel = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, v.asset.TranslateLabel(cancelLabel)) v.btnServerIPCancel.SetPosition(srvCancelBtnX, srvCancelBtnY) v.btnServerIPCancel.OnActivated(func() { v.onBtnTCPIPCancelClicked() }) @@ -517,24 +444,24 @@ func (v *MainMenu) createButtons(loading d2screen.LoadingState) { func (v *MainMenu) createMultiplayerMenuButtons() { v.multiplayerButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, - translateLabel(otherMultiplayerLabel, v.language, v.asset)) + v.asset.TranslateLabel(otherMultiplayerLabel)) v.multiplayerButton.SetPosition(multiplayerBtnX, multiplayerBtnY) v.multiplayerButton.OnActivated(func() { v.onMultiplayerClicked() }) - v.networkTCPIPButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIPGameLabel, v.language, v.asset)) + v.networkTCPIPButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateLabel(tcpIPGameLabel)) v.networkTCPIPButton.SetPosition(tcpNetBtnX, tcpNetBtnY) v.networkTCPIPButton.OnActivated(func() { v.onNetworkTCPIPClicked() }) v.networkCancelButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, - translateLabel(cancelLabel, v.language, v.asset)) + v.asset.TranslateLabel(cancelLabel)) v.networkCancelButton.SetPosition(networkCancelBtnX, networkCancelBtnY) v.networkCancelButton.OnActivated(func() { v.onNetworkCancelClicked() }) - v.btnTCPIPHostGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIPHostGameLabel, v.language, v.asset)) + v.btnTCPIPHostGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateLabel(tcpIPHostGameLabel)) v.btnTCPIPHostGame.SetPosition(tcpHostBtnX, tcpHostBtnY) v.btnTCPIPHostGame.OnActivated(func() { v.onTCPIPHostGameClicked() }) - v.btnTCPIPJoinGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, translateLabel(tcpIPJoinGameLabel, v.language, v.asset)) + v.btnTCPIPJoinGame = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateLabel(tcpIPJoinGameLabel)) v.btnTCPIPJoinGame.SetPosition(tcpJoinBtnX, tcpJoinBtnY) v.btnTCPIPJoinGame.OnActivated(func() { v.onTCPIPJoinGameClicked() }) } @@ -790,5 +717,5 @@ func (v *MainMenu) getLocalIP() string { v.Warning("no IPv4 Address could be found") - return translateLabel(ipNotFoundLabel, v.language, v.asset) + return v.asset.TranslateLabel(ipNotFoundLabel) } diff --git a/d2game/d2gamescreen/select_hero_class.go b/d2game/d2gamescreen/select_hero_class.go index 1c1f93cb..a022494a 100644 --- a/d2game/d2gamescreen/select_hero_class.go +++ b/d2game/d2gamescreen/select_hero_class.go @@ -279,7 +279,6 @@ func CreateSelectHeroClass( ui *d2ui.UIManager, connectionType d2clientconnectiontype.ClientConnectionType, l d2util.LogLevel, - lang string, connectionHost string, ) (*SelectHeroClass, error) { playerStateFactory, err := d2hero.NewHeroStateFactory(asset) @@ -304,7 +303,6 @@ func CreateSelectHeroClass( uiManager: ui, HeroStateFactory: playerStateFactory, InventoryItemFactory: inventoryItemFactory, - language: lang, } selectHeroClass.Logger = d2util.NewLogger() @@ -345,7 +343,6 @@ type SelectHeroClass struct { navigator d2interface.Navigator *d2util.Logger - language string } // OnLoad loads the resources for the Select Hero Class screen @@ -419,7 +416,7 @@ func (v *SelectHeroClass) createLabels() { halfFontWidth := fontWidth / half v.headingLabel.SetPosition(headingX-halfFontWidth, headingY) - v.headingLabel.SetText(translateLabel(selectHeroClassLabel, v.language, v.asset)) + v.headingLabel.SetText(v.asset.TranslateLabel(selectHeroClassLabel)) v.headingLabel.Alignment = d2ui.HorizontalAlignCenter v.heroClassLabel = v.uiManager.NewLabel(d2resource.Font30, d2resource.PaletteUnits) @@ -440,7 +437,7 @@ func (v *SelectHeroClass) createLabels() { v.heroNameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.heroNameLabel.Alignment = d2ui.HorizontalAlignLeft - v.heroNameLabel.SetText(d2ui.ColorTokenize(translateLabel(charNameLabel, v.language, v.asset), d2ui.ColorTokenGold)) + v.heroNameLabel.SetText(d2ui.ColorTokenize(v.asset.TranslateLabel(charNameLabel), d2ui.ColorTokenGold)) v.heroNameLabel.SetPosition(heroNameLabelX, heroNameLabelY) v.expansionCharLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) @@ -451,7 +448,7 @@ func (v *SelectHeroClass) createLabels() { v.hardcoreCharLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.hardcoreCharLabel.Alignment = d2ui.HorizontalAlignLeft - v.hardcoreCharLabel.SetText(d2ui.ColorTokenize(translateLabel(hardCoreLabel, v.language, v.asset), d2ui.ColorTokenGold)) + v.hardcoreCharLabel.SetText(d2ui.ColorTokenize(v.asset.TranslateLabel(hardCoreLabel), d2ui.ColorTokenGold)) v.hardcoreCharLabel.SetPosition(hardcoreLabelX, hardcoreLabelY) } @@ -723,7 +720,7 @@ func (v *SelectHeroClass) setDescLabels(descKey int, key string) { if key != "" { heroDesc = v.asset.TranslateString(key) } else { - heroDesc = translateLabel(descKey, v.language, v.asset) + heroDesc = v.asset.TranslateLabel(descKey) } parts := d2util.SplitIntoLinesWithMaxWidth(heroDesc, heroDescCharWidth) From 1dcd63a238a7e1926ac447222f017afd37eb7a09 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Thu, 26 Nov 2020 11:30:11 +0100 Subject: [PATCH 10/15] fixed lint errors --- d2common/d2resource/languages_map.go | 2 +- d2core/d2asset/asset_manager.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/d2common/d2resource/languages_map.go b/d2common/d2resource/languages_map.go index 617b21f3..44045a17 100644 --- a/d2common/d2resource/languages_map.go +++ b/d2common/d2resource/languages_map.go @@ -50,6 +50,7 @@ func GetFontCharset(language string) string { return charset[language] } +// GetLabelModifier returns modifier for language /* modifiers for labels (used in string tables) modifier is something like that: english table: polish table: @@ -62,7 +63,6 @@ So, GetLabelModifier returns value of offset in locale languages table */ // some of values need to be set up. For now values with "checked" comment // was tested and works fine in main menu. -// GetLabelModifier returns modifier for language func GetLabelModifier(language string) int { modifiers := map[string]int{ "ENG": 0, // (English) // checked diff --git a/d2core/d2asset/asset_manager.go b/d2core/d2asset/asset_manager.go index 079bee07..2ab2ab27 100644 --- a/d2core/d2asset/asset_manager.go +++ b/d2core/d2asset/asset_manager.go @@ -126,6 +126,7 @@ func (am *AssetManager) LoadLanguage(languagePath string) string { am.Infof("Language: %s", language) am.language = language + return language } @@ -303,7 +304,7 @@ func (am *AssetManager) TranslateString(input interface{}) string { return key } -func (a *AssetManager) baseLabelNumbers(idx int) int { +func (am *AssetManager) baseLabelNumbers(idx int) int { baseLabelNumbers := []int{ // main menu labels 1612, // CANCEL @@ -369,8 +370,8 @@ func (a *AssetManager) baseLabelNumbers(idx int) int { } // TranslateLabel translates the label taking into account its shift in the table -func (a *AssetManager) TranslateLabel(label int) string { - return a.TranslateString(fmt.Sprintf("#%d", a.baseLabelNumbers(label+d2resource.GetLabelModifier(a.language)))) +func (am *AssetManager) TranslateLabel(label int) string { + return am.TranslateString(fmt.Sprintf("#%d", am.baseLabelNumbers(label+d2resource.GetLabelModifier(am.language)))) } // LoadPaletteTransform loads a palette transform file From 862951e440c54ac83030b61aa34eee94a4ec34dd Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Thu, 26 Nov 2020 11:48:49 +0100 Subject: [PATCH 11/15] code cleanup --- d2game/d2gamescreen/main_menu.go | 1 - 1 file changed, 1 deletion(-) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index 8c4cc009..a3f8d645 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -162,7 +162,6 @@ func CreateMainMenu( audioProvider d2interface.AudioProvider, ui *d2ui.UIManager, buildInfo BuildInfo, - lng string, l d2util.LogLevel, errorMessageOptional ...string, ) (*MainMenu, error) { From 570d71845e8188a5274b6ba463600ebd9f298e84 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Thu, 26 Nov 2020 11:50:00 +0100 Subject: [PATCH 12/15] fixed build error --- d2app/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d2app/app.go b/d2app/app.go index bdb96e82..8b13c0d1 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.language, a.config.LogLevel, errorMessageOptional...) + a.config.LogLevel, errorMessageOptional...) if err != nil { a.Error(err.Error()) return From 640a9e043d850426cbf50c8d530d06cf1952ff72 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Thu, 26 Nov 2020 12:25:47 +0100 Subject: [PATCH 13/15] code cleanup --- d2common/d2util/stringutils.go | 5 ----- d2game/d2gamescreen/character_select.go | 10 ++++++---- d2game/d2gamescreen/main_menu.go | 3 ++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/d2common/d2util/stringutils.go b/d2common/d2util/stringutils.go index 24f268bd..c9c859cb 100644 --- a/d2common/d2util/stringutils.go +++ b/d2common/d2util/stringutils.go @@ -135,11 +135,6 @@ func SplitIntoLinesWithMaxWidth(fullSentence string, maxChars int) []string { return lines } -// SplitIntoLinesWithMaxWidthOneLine does the same as SplitIntoLinesWithMaxWidth but return string with newline char -func SplitIntoLinesWithMaxWidthOneLine(s string, l int) string { - return strings.Join(SplitIntoLinesWithMaxWidth(s, l), "\n") -} - func splitCjkIntoChunks(str string, chars int) []string { chunks := make([]string, chars/len(str)) i, count := 0, 0 diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index e7e321e7..10e5339d 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -5,6 +5,7 @@ import ( "math" "os" "strconv" + "strings" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero" @@ -229,7 +230,7 @@ func (v *CharacterSelect) loadHeroTitle() { func (v *CharacterSelect) loadDeleteCharConfirm() { v.deleteCharConfirmLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) - lines := d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateLabel(delCharConfLabel), 30) + lines := strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateLabel(delCharConfLabel), 30), "\n") v.deleteCharConfirmLabel.SetText(lines) v.deleteCharConfirmLabel.Alignment = d2ui.HorizontalAlignCenter deleteConfirmX, deleteConfirmY := 400, 185 @@ -292,17 +293,18 @@ func rgbaColor(rgba uint32) color.RGBA { } func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) { - v.newCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#831"), 13)) + v.newCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, strings.Join( + d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#831"), 13), "\n")) v.newCharButton.SetPosition(newCharBtnX, newCharBtnY) v.newCharButton.OnActivated(func() { v.onNewCharButtonClicked() }) v.convertCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, - d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#825"), 13)) + strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#825"), 13), "\n")) v.convertCharButton.SetPosition(convertCharBtnX, convertCharBtnY) v.convertCharButton.SetEnabled(false) v.deleteCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, - d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#832"), 13)) + strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#832"), 13), "\n")) v.deleteCharButton.OnActivated(func() { v.onDeleteCharButtonClicked() }) v.deleteCharButton.SetPosition(deleteCharBtnX, deleteCharBtnY) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index a3f8d645..2fce8dc0 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "runtime" + "strings" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero" @@ -344,7 +345,7 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) { v.tcpJoinGameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.tcpJoinGameLabel.Alignment = d2ui.HorizontalAlignCenter - v.tcpJoinGameLabel.SetText(d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateLabel(tcpIPEnterHostIPLabel), 27)) + v.tcpJoinGameLabel.SetText(strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateLabel(tcpIPEnterHostIPLabel), 27), "\n")) v.tcpJoinGameLabel.Color[0] = rgbaColor(gold) v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY) From 2dab48a2ee3fdaa122149523fe25d398be13985b Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Thu, 26 Nov 2020 13:51:39 +0100 Subject: [PATCH 14/15] Updated some labels --- d2core/d2asset/asset_manager.go | 2 ++ d2game/d2gamescreen/character_select.go | 2 +- d2game/d2gamescreen/main_menu.go | 44 ++++++++++++------------ d2game/d2gamescreen/select_hero_class.go | 5 ++- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/d2core/d2asset/asset_manager.go b/d2core/d2asset/asset_manager.go index 2ab2ab27..7cee1fd4 100644 --- a/d2core/d2asset/asset_manager.go +++ b/d2core/d2asset/asset_manager.go @@ -364,6 +364,8 @@ func (am *AssetManager) baseLabelNumbers(idx int) int { 1926, // not used, for locales with +1 mod + 970, // EXIT + 971, } return baseLabelNumbers[idx] diff --git a/d2game/d2gamescreen/character_select.go b/d2game/d2gamescreen/character_select.go index 10e5339d..8cfefed1 100644 --- a/d2game/d2gamescreen/character_select.go +++ b/d2game/d2gamescreen/character_select.go @@ -308,7 +308,7 @@ func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) { v.deleteCharButton.OnActivated(func() { v.onDeleteCharButtonClicked() }) v.deleteCharButton.SetPosition(deleteCharBtnX, deleteCharBtnY) - v.exitButton = v.uiManager.NewButton(d2ui.ButtonTypeMedium, "EXIT") + v.exitButton = v.uiManager.NewButton(d2ui.ButtonTypeMedium, v.asset.TranslateLabel(exitLabel)) v.exitButton.SetPosition(exitBtnX, exitBtnY) v.exitButton.OnActivated(func() { v.onExitButtonClicked() }) diff --git a/d2game/d2gamescreen/main_menu.go b/d2game/d2gamescreen/main_menu.go index 2fce8dc0..5d5bc4af 100644 --- a/d2game/d2gamescreen/main_menu.go +++ b/d2game/d2gamescreen/main_menu.go @@ -90,38 +90,35 @@ const ( copyrightLabel allRightsReservedLabel singlePlayerLabel - //nolint:deadcode,varcheck,unused // will be used, or is need - battleNetLabel + _ otherMultiplayerLabel - exitLabel + exitGameLabel creditsLabel cinematicsLabel // cinematics menu labels - //nolint:deadcode,varcheck,unused // will be used, or is need + //nolint:deadcode,varcheck,unused // will be used viewAllCinematicsLabel - //nolint:deadcode,varcheck,unused // will be used, or is need + //nolint:deadcode,varcheck,unused // will be used epilogueLabel selectCinematicLabel // multiplayer menu labels - //nolint:deadcode,varcheck,unused // will be used, or is need - openBattleNetLabeL + _ tcpIPGameLabel tcpIPOptionsLabel tcpIPHostGameLabel tcpIPJoinGameLabel tcpIPEnterHostIPLabel tcpIPYourIPLabel - //nolint:deadcode,varcheck,unused // will be used, or is need + //nolint:deadcode,varcheck,unused // will be used tipHostLabel - //nolint:deadcode,varcheck,unused // will be used, or is need + //nolint:deadcode,varcheck,unused // will be used tipJoinLabel ipNotFoundLabel // select hero class menu labels charNameLabel - //nolint:deadcode,varcheck,unused // will be used, or is need hardCoreLabel selectHeroClassLabel amazonDescr @@ -130,28 +127,31 @@ const ( sorceressDescr paladinDescr - //nolint:deadcode,varcheck,unused // will be used, or is need - notUsed1 // this position isn't used here. + _ - //nolint:deadcode,varcheck,unused // will be used, or is need + //nolint:deadcode,varcheck,unused // will be used hellLabel - //nolint:deadcode,varcheck,unused // will be used, or is need + //nolint:deadcode,varcheck,unused // will be used nightmareLabel - //nolint:deadcode,varcheck,unused // will be used, or is need + //nolint:deadcode,varcheck,unused // will be used normalLabel - //nolint:deadcode,varcheck,unused // will be used, or is need + //nolint:deadcode,varcheck,unused // will be used selectDifficultyLabel - //nolint:deadcode,varcheck,unused // will be used, or is need - notUsed2 + _ delCharConfLabel - //nolint:deadcode,varcheck,unused // will be used, or is need + //nolint:deadcode,varcheck,unused // will be used openLabel - //nolint:deadcode,varcheck,unused // will be used, or is need - notUsed3 + + _ + yesLabel noLabel + + _ + + exitLabel ) // CreateMainMenu creates an instance of MainMenu @@ -400,7 +400,7 @@ func (v *MainMenu) createLogos(loading d2screen.LoadingState) { } func (v *MainMenu) createButtons(loading d2screen.LoadingState) { - v.exitDiabloButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateLabel(exitLabel)) + v.exitDiabloButton = v.uiManager.NewButton(d2ui.ButtonTypeWide, v.asset.TranslateLabel(exitGameLabel)) v.exitDiabloButton.SetPosition(exitDiabloBtnX, exitDiabloBtnY) v.exitDiabloButton.OnActivated(func() { v.onExitButtonClicked() }) diff --git a/d2game/d2gamescreen/select_hero_class.go b/d2game/d2gamescreen/select_hero_class.go index a022494a..dcdb773c 100644 --- a/d2game/d2gamescreen/select_hero_class.go +++ b/d2game/d2gamescreen/select_hero_class.go @@ -442,8 +442,7 @@ func (v *SelectHeroClass) createLabels() { v.expansionCharLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) v.expansionCharLabel.Alignment = d2ui.HorizontalAlignLeft - // to be honest, it should be TranslateString("#803"), but I suppose that's the same - v.expansionCharLabel.SetText(d2ui.ColorTokenize(v.asset.TranslateString("expansionchar2x"), d2ui.ColorTokenGold)) + v.expansionCharLabel.SetText(d2ui.ColorTokenize(v.asset.TranslateString("#803"), d2ui.ColorTokenGold)) v.expansionCharLabel.SetPosition(expansionLabelX, expansionLabelY) v.hardcoreCharLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits) @@ -453,7 +452,7 @@ func (v *SelectHeroClass) createLabels() { } func (v *SelectHeroClass) createButtons() { - v.exitButton = v.uiManager.NewButton(d2ui.ButtonTypeMedium, "EXIT") + v.exitButton = v.uiManager.NewButton(d2ui.ButtonTypeMedium, v.asset.TranslateLabel(exitLabel)) v.exitButton.SetPosition(selHeroExitBtnX, selHeroExitBtnY) v.exitButton.OnActivated(func() { v.onExitButtonClicked() }) From 3964d4f6f2f0e3180febba4e4efd667d1d3ac239 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Thu, 26 Nov 2020 15:28:06 +0100 Subject: [PATCH 15/15] exit button in credits --- d2game/d2gamescreen/credits.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d2game/d2gamescreen/credits.go b/d2game/d2gamescreen/credits.go index d144e728..8b9ac802 100644 --- a/d2game/d2gamescreen/credits.go +++ b/d2game/d2gamescreen/credits.go @@ -105,7 +105,7 @@ func (v *Credits) OnLoad(loading d2screen.LoadingState) { v.creditsBackground.SetPosition(creditsX, creditsY) loading.Progress(twentyPercent) - v.exitButton = v.uiManager.NewButton(d2ui.ButtonTypeMedium, "EXIT") + v.exitButton = v.uiManager.NewButton(d2ui.ButtonTypeMedium, v.asset.TranslateLabel(exitLabel)) v.exitButton.SetPosition(charSelExitBtnX, charSelExitBtnY) v.exitButton.OnActivated(func() { v.onExitButtonClicked() }) loading.Progress(fourtyPercent)