From 04e9b9bbb7d995c52110fa1f03ad22b4c4f37aaf Mon Sep 17 00:00:00 2001 From: expert975 Date: Thu, 12 Oct 2017 21:59:52 -0300 Subject: [PATCH] Add language change event Add clientside "onUserLanguageChange" event. This event is triggered when the user language changes. See CONTRIBUTING.md section "Writing translatable code". --- battlegrounds/accounting/cLoginPanel.lua | 12 ++++++ battlegrounds/gui/homescreen_c.lua | 32 ++++++++++++++ battlegrounds/gui/inventory.lua | 18 ++++++++ battlegrounds/gui/sidemenu.lua | 30 ++++++++----- battlegrounds/hud/hud_c.lua | 55 +++++++++++++++++++----- battlegrounds/hud/matchud.lua | 4 +- 6 files changed, 127 insertions(+), 24 deletions(-) diff --git a/battlegrounds/accounting/cLoginPanel.lua b/battlegrounds/accounting/cLoginPanel.lua index 6a198cf..e0f1f6f 100644 --- a/battlegrounds/accounting/cLoginPanel.lua +++ b/battlegrounds/accounting/cLoginPanel.lua @@ -18,6 +18,7 @@ LoginScreen = { edit = {} } + LoginScreen.staticimage[1] = guiCreateStaticImage(0.00, 0.00, 1.00, 1.00, "accounting/img/background.png", true) LoginScreen.staticimage[2] = guiCreateStaticImage(0.11, 0.06, 0.77, 0.28, "accounting/img/battlegrounds_logo.png", true, LoginScreen.staticimage[1]) LoginScreen.edit[1] = guiCreateEdit(0.35, 0.41, 0.29, 0.05, "", true, LoginScreen.staticimage[1]) -- ID @@ -422,3 +423,14 @@ addEventHandler("onClientResourceStart", getResourceRootElement(), function() Camera.fade(false, .1) --fade camera on resource restart triggerServerEvent("mtabg_onJoin", localPlayer) end) + + +local function changeLanguage(newLang) + LoginScreen.label[1]:setText(str("loginPanelID")) + LoginScreen.label[7]:setText(str("loginPanelKey")) + LoginScreen.label[2]:setText(str("loginPanelPassword")) + LoginScreen.checkbox[1]:setText(str("loginPanelRememberPassword")) + LoginScreen.label[4]:setText(str("loginPanelLoginButton")) + LoginScreen.label[5]:setText(str("loginPanelRegisterButton")) +end +addEventHandler("onUserLanguageChange", resourceRoot, changeLanguage) diff --git a/battlegrounds/gui/homescreen_c.lua b/battlegrounds/gui/homescreen_c.lua index bfd74fb..902556d 100644 --- a/battlegrounds/gui/homescreen_c.lua +++ b/battlegrounds/gui/homescreen_c.lua @@ -13,6 +13,8 @@ homeScreen = { font = {} } + + homeScreen.font[1] = guiCreateFont("/fonts/etelka.ttf",13) homeScreen.font[2] = guiCreateFont("/fonts/etelka.ttf",25) @@ -650,3 +652,33 @@ function getMatrixAgain() outputChatBox(tostring(g)..", "..tostring(h)) end addCommandHandler("getit",getMatrixAgain) + +local function changeLanguage(newLang) + homeScreen.label[1]:setText(str("mainMenuHomeButton")) + homeScreen.label[2]:setText(str("mainMenuCharacterButton")) + homeScreen.label[3]:setText(str("mainMenuSoonButton")) + homeScreen.label[4]:setText(str("mainMenuStatisticsButton")) + homeScreen.label[5]:setText(str("mainMenuPlayerName", localPlayer.name):gsub("#%x%x%x%x%x%x", "")) + homeScreen.label[7]:setText(str("mainMenuPlayButtonShadow")) + homeScreen.label[8]:setText(str("mainMenuPlayButton")) + homeScreen.label["gamesplayed"]:setText(str("statisticsMenuGamesPlayed")) + homeScreen.label["wins"]:setText(str("statisticsMenuWins")) + homeScreen.label["losses"]:setText(str("statisticsMenuLosses")) + homeScreen.label["winlossratio"]:setText(str("statisticsMenuWinLossRatio")) + homeScreen.label["kills"]:setText(str("statisticsMenuKills")) + homeScreen.label["deaths"]:setText(str("statisticsMenuDeaths")) + homeScreen.label["killdeathratio"]:setText(str("statisticsMenuKillDeathRatio")) + homeScreen.label["headshots"]:setText(str("statisticsMenuHeadshots")) + homeScreen.label["battlepoints"]:setText(str("statisticsMenuBattlePointsEarned")) + homeScreen.label["battlepointsspent"]:setText(str("statisticsMenuBattlePointsSpent")) + homeScreen.label[19]:setText(str("statisticsMenuPlayerName", localPlayer.name):gsub("#%x%x%x%x%x%x", "")) + homeScreen.label[30]:setText(str("statisticsMenuID")) + homeScreen.label[31]:setText(str("statisticsMenuNA")) + homeScreen.label["legendary"]:setText(str("rewardsMenuLegendaryCrates")) + homeScreen.label["epic"]:setText(str("rewardsMenuEpicCrates")) + homeScreen.label["uncommon"]:setText(str("rewardsMenuUncommonCrates")) + homeScreen.label["common"]:setText(str("rewardsMenuCommonCrates")) + homeScreen.label[36]:setText(str("skinsMenuNotAvailableYet")) + homeScreen.label[37]:setText(str("skinsMenuPresetSkins")) +end +addEventHandler("onUserLanguageChange", resourceRoot, changeLanguage) diff --git a/battlegrounds/gui/inventory.lua b/battlegrounds/gui/inventory.lua index 8a329ce..ce0d17a 100644 --- a/battlegrounds/gui/inventory.lua +++ b/battlegrounds/gui/inventory.lua @@ -397,3 +397,21 @@ function onPlayerRightClickMenu(button, state) end end addEventHandler("onClientGUIClick", rightClick["label"], onPlayerRightClickMenu, false) + + +local function changeLanguage(newLang) + inventoryGUI.gridlist[1]:setColumnTitle(inventoryGUI.gridlist["inventory"], str("inventoryYourLoot")) + inventoryGUI.gridlist[1]:setColumnTitle(inventoryGUI.gridlist["inventoryamount"], str("inventoryItemAmount")) + inventoryGUI.gridlist[2]:setColumnTitle(inventoryGUI.gridlist["loot"], str("inventoryVicinityLoot")) + inventoryGUI.gridlist[2]:setColumnTitle(inventoryGUI.gridlist["lootamount"], str("inventoryItemAmount")) + inventoryGUI.label[7]:setText(str("inventoryVicinityLoot")) + inventoryGUI.label[8]:setText(str("inventoryYourLoot")) + inventoryGUI.label[11]:setText(str("inventoryStatus")) + inventoryGUI.label[4]:setText(str("inventoryPlayerName", localPlayer.name)) + inventoryGUI.label[10]:setText(str("inventoryCapacity", + tostring(playerCapacity.used), + tostring(playerCapacity.maxCapacity))) + updateInventoryMessage() + updateRightClickMenuText() +end +addEventHandler("onUserLanguageChange", resourceRoot, changeLanguage) diff --git a/battlegrounds/gui/sidemenu.lua b/battlegrounds/gui/sidemenu.lua index e7a1e50..f9ffab9 100644 --- a/battlegrounds/gui/sidemenu.lua +++ b/battlegrounds/gui/sidemenu.lua @@ -25,9 +25,14 @@ function initSideMenu() end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),initSideMenu) - -function showClientMenuItem(arg1,arg2,arg3,arg4) -local number = 0 +local sideMenuArg1 +local sideMenuArg2 +function showClientMenuItem(arg1,arg2) + arg1 = arg1 or sideMenuArg1 + arg2 = arg2 or sideMenuArg2 + sideMenuArg1 = arg1 + sideMenuArg2 = arg2 + local number = 0 if arg1 == "Take" then number = number+1 guiSetVisible(rowImage[number],true) @@ -51,14 +56,14 @@ local number = 0 setElementData(rowText[number],"markedMenuItem",true) end setElementData(rowText[number],"usedItem","dead") - number = number+1 - setElementData(rowText[number],"usedItem","deadreason") - guiSetVisible(rowImage[number],true) - guiSetText(rowText[number], str("sideMenuCheckBody")) + -- number = number+1 + -- setElementData(rowText[number],"usedItem","deadreason") + -- guiSetVisible(rowImage[number],true) + -- guiSetText(rowText[number], str("sideMenuCheckBody")) - setElementData(rowText[3],"usedItem","hidebody") - guiSetVisible(rowImage[3],true) - guiSetText(rowText[3], str("sideMenuHideBody")) + -- setElementData(rowText[3],"usedItem","hidebody") + -- guiSetVisible(rowImage[3],true) + -- guiSetText(rowText[3], str("sideMenuHideBody")) end if arg1 == "Gear" then number = number+1 @@ -186,3 +191,8 @@ function getMenuMarkedItem() end end end + +local function changeLanguage(newLang) + showClientMenuItem() +end +addEventHandler("onUserLanguageChange", resourceRoot, changeLanguage) diff --git a/battlegrounds/hud/hud_c.lua b/battlegrounds/hud/hud_c.lua index 199ed1a..ceea08f 100644 --- a/battlegrounds/hud/hud_c.lua +++ b/battlegrounds/hud/hud_c.lua @@ -106,7 +106,6 @@ local helpText = { str("lobbyHelpText6") } -local text = "" local countdown = "" lobbyLabel[1] = guiCreateLabel(0.02, 0.31, 0.32, 0.05, "", true) lobbyLabel[2] = guiCreateLabel(0.02, 0.36, 0.32, 0.05, "", true) @@ -194,9 +193,17 @@ function displayHealthGUI() end addEventHandler("onClientRender",root,displayHealthGUI) +local currentHelpTextIndex +local function updateHelpText() + if currentHelpTextIndex then + guiSetText(lobbyLabel[4],helpText[currentHelpTextIndex]) + end +end + function setRandomHelpText() if getElementData(localPlayer,"inLobby") then - guiSetText(lobbyLabel[4],helpText[math.random(1,#helpText)]) + currentHelpTextIndex = math.random(1, #helpText) + updateHelpText() end end setTimer(setRandomHelpText,10000,0) @@ -246,7 +253,10 @@ end addEvent("mtabg_onClientBattleGroundsSetCountdown",true) addEventHandler("mtabg_onClientBattleGroundsSetCountdown",root,onClientBattleGroundsSetCountdown) +local lobbyLabelNumber function onClientBattleGroundsAnnounceMatchStart(number) + number = number or lobbyLabelNumber + lobbyLabelNumber = number if number == "More players needed" then guiSetText(lobbyLabel[3], str("lobbyInsuficientPlayersError")) elseif number == "Match running" then @@ -272,7 +282,6 @@ endScreen = { font = {} } -local text = "" local rank = "" endScreen.font[1] = guiCreateFont("/fonts/etelka.ttf",11) @@ -305,16 +314,20 @@ end guiSetVisible(endScreen.image[1],false) guiSetVisible(endScreen.image[2],false) -local homeScreenDimension = 500 -function showEndScreen(rank,dimension) - if rank ~= 1 then - text = str("endScreenYouLost") - guiSetText(endScreen.label[2],text) +local endScreenRank +local function updateEndScreenText() + if endScreenRank ~= 1 then + guiSetText(endScreen.label[2], str("endScreenYouLost")) else - text = str("endScreenYouWon") - guiSetText(endScreen.label[2],text) + guiSetText(endScreen.label[2], str("endScreenYouWon")) end - guiSetText(endScreen.label[5],"#"..tostring(rank)) + guiSetText(endScreen.label[5],"#"..tostring(endScreenRank)) +end + +local homeScreenDimension = 500 +function showEndScreen(rank,dimension) + endScreenRank = rank + updateEndScreenText() guiSetVisible(endScreen.image[1],true) guiSetVisible(endScreen.image[2],true) guiBringToFront(endScreen.label[7]) @@ -420,3 +433,23 @@ local function moveLittleDude() --moves littleDude end end addEventHandler("onClientRender", root, moveLittleDude) + +local function changeLanguage(newLang) + helpText = { + str("lobbyHelpText1"), + str("lobbyHelpText2"), + str("lobbyHelpText3"), + str("lobbyHelpText4"), + str("lobbyHelpText5"), + str("lobbyHelpText6") + } + updateHelpText() + fuelLabel:setText(str("vehicleFuel")) + fuelLabel:setText(str("vehicleFuel", tostring(fuelAmount))) + endScreen.label[3]:setText(str("endScreenRank")) + endScreen.label[4]:setText(str("endScreenKills")) + endScreen.label[7]:setText(str("endScreenBackToHomeButton")) + onClientBattleGroundsAnnounceMatchStart() + updateEndScreenText() +end +addEventHandler("onUserLanguageChange", resourceRoot, changeLanguage) diff --git a/battlegrounds/hud/matchud.lua b/battlegrounds/hud/matchud.lua index 0146c3e..fcf84a4 100644 --- a/battlegrounds/hud/matchud.lua +++ b/battlegrounds/hud/matchud.lua @@ -24,7 +24,5 @@ guiGridListAddColumn(LobbyScreen.gridlist[1], "Players", 0.2) guiGridListAddColumn(LobbyScreen.gridlist[1], "Mode", 0.2) guiGridListAddColumn(LobbyScreen.gridlist[1], "Current Status", 0.2) LobbyScreen.label[1] = guiCreateLabel(0.01, 0.92, 0.37, 0.03, "MTA:Battlegrounds Version: 0.0.1a", true, LobbyScreen.window[1]) -LobbyScreen.button[1] = guiCreateButton(0.02, 0.57, 0.11, 0.07, "Enter Game", true, LobbyScreen.window[1]) +LobbyScreen.button[1] = guiCreateButton(0.02, 0.57, 0.11, 0.07, "Enter Game", true, LobbyScreen.window[1]) guiSetVisible(LobbyScreen.window[1],false) - -