Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Commit

Permalink
Add language change event
Browse files Browse the repository at this point in the history
Add clientside "onUserLanguageChange" event.
This event is triggered when the user language changes.
See CONTRIBUTING.md section "Writing translatable code".
  • Loading branch information
expert975 committed Oct 15, 2017
1 parent bd17fff commit 04e9b9b
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 24 deletions.
12 changes: 12 additions & 0 deletions battlegrounds/accounting/cLoginPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
32 changes: 32 additions & 0 deletions battlegrounds/gui/homescreen_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ homeScreen = {
font = {}
}



homeScreen.font[1] = guiCreateFont("/fonts/etelka.ttf",13)
homeScreen.font[2] = guiCreateFont("/fonts/etelka.ttf",25)

Expand Down Expand Up @@ -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)
18 changes: 18 additions & 0 deletions battlegrounds/gui/inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
30 changes: 20 additions & 10 deletions battlegrounds/gui/sidemenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -186,3 +191,8 @@ function getMenuMarkedItem()
end
end
end

local function changeLanguage(newLang)
showClientMenuItem()
end
addEventHandler("onUserLanguageChange", resourceRoot, changeLanguage)
55 changes: 44 additions & 11 deletions battlegrounds/hud/hud_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -272,7 +282,6 @@ endScreen = {
font = {}
}

local text = ""
local rank = ""

endScreen.font[1] = guiCreateFont("/fonts/etelka.ttf",11)
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)
4 changes: 1 addition & 3 deletions battlegrounds/hud/matchud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)


0 comments on commit 04e9b9b

Please sign in to comment.