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

Commit fc8991c

Browse files
author
expert975
committed
Implement language selection GUI
1 parent 04e9b9b commit fc8991c

7 files changed

Lines changed: 153 additions & 3 deletions

File tree

battlegrounds/accounting/cLoginPanel.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ local function closeLoginPanel()
7878
loadingBar.hide()
7979
guiSetVisible(homeScreen.staticimage[1],true)
8080
fadeCamera(true)
81+
LanguageSelection.setShowing(true)
8182
end
8283

8384
local function showLoadingBar()

battlegrounds/gui/homescreen_c.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ end)
338338
function sendPlayerToLobbyOnPlayPress(button)
339339
if button == "left" then
340340
triggerServerEvent("mtabg_sendPlayerToLobby",localPlayer)
341+
LanguageSelection.setShowing(false)
341342
guiSetVisible(homeScreen.staticimage[1],false)
342343
guiSetVisible(homeScreen.staticimage[5],false)
343344
for i=6,21 do

battlegrounds/hud/hud_c.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ addEventHandler("onClientMouseLeave",endScreen.label[7],onMouseOverBackToHomeScr
368368

369369
function sendPlayerBackToHomeScreenOnDeath()
370370
guiSetVisible(homeScreen.staticimage[1],true)
371+
LanguageSelection.setShowing(true)
371372
guiSetVisible(endScreen.image[1],false)
372373
guiSetVisible(endScreen.image[2],false)
373374
sendToHomeScreen(homeScreenDimension)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
local sx, sy = guiGetScreenSize()
2+
local globeTexture = DxTexture("lang/globe2.png")
3+
local color = 0
4+
local lastTick = 0
5+
local rootx = sx*0.013020833 --25
6+
local rooty = sy*0.148148148 --160
7+
local sizex = sx*0.039062500 --75
8+
local sizey = sy*0.069444444 --75
9+
local radius = sizex*.5
10+
local centerx = sizex*.5 + rootx
11+
local centery = sizey*.5 + rooty
12+
local isRendering = false
13+
local functionToCallOnClick
14+
local Globe = {}
15+
16+
local function render()
17+
dxDrawImage(rootx, rooty, sizex, sizey, globeTexture, 0, 0, 0, tocolor(color,color,color,255), false)
18+
end
19+
20+
local function isClickInsideGlobe(button, state, cursorx, cursory)
21+
if button == "left" and state == "up" then
22+
local distance = math.sqrt(
23+
math.pow(centerx - cursorx, 2)
24+
+ math.pow(centery - cursory, 2)
25+
)
26+
local isInside = distance <= radius
27+
if isInside and functionToCallOnClick then
28+
functionToCallOnClick()
29+
end
30+
end
31+
end
32+
33+
local function fadeIn()
34+
if color < 255 then
35+
local dTime = getTickCount() - lastTick
36+
local controlVar = (256*dTime)/1000
37+
color = color + controlVar
38+
if color > 255 then
39+
color = 255
40+
end
41+
lastTick = getTickCount()
42+
else
43+
removeEventHandler("onClientRender", root, fadeIn)
44+
end
45+
end
46+
47+
function Globe.setFadingIn()
48+
lastTick = getTickCount()
49+
addEventHandler("onClientRender", root, fadeIn)
50+
end
51+
52+
function Globe.setRendering(shouldRender)
53+
if shouldRender then
54+
addEventHandler("onClientRender", root, render)
55+
addEventHandler("onClientClick", root, isClickInsideGlobe)
56+
Globe.setFadingIn()
57+
else
58+
removeEventHandler("onClientRender", root, render)
59+
removeEventHandler("onClientClick", root, isClickInsideGlobe)
60+
removeEventHandler("onClientRender", root, fadeIn)
61+
end
62+
isRendering = shouldRender
63+
end
64+
65+
function Globe.getRendering()
66+
return isRendering
67+
end
68+
69+
function Globe.toggleRendering()
70+
Globe.setRendering(not isRendering)
71+
end
72+
73+
function Globe.setCallOnClick(functionToCall)
74+
functionToCallOnClick = functionToCall
75+
end
76+
77+
LanguageGlobeButton = Globe
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
local sx, sy = guiGetScreenSize()
2+
local rootx = sx*0.008854167 --17
3+
local rooty = sy*0.225925926 --244
4+
local languageComboBox
5+
local languageCodes = {}
6+
7+
local function setNewLanguage()
8+
local selectedItem = languageComboBox:getSelected()
9+
local languageName = languageComboBox:getItemText(selectedItem)
10+
Language.set(languageCodes[languageName])
11+
end
12+
13+
local function createComboBox()
14+
languageComboBox = guiCreateComboBox(rootx, rooty, 100, 20, Language.getCurrentName(), false)
15+
guiComboBoxAdjustHeight(languageComboBox, Language.getCount())
16+
end
17+
18+
local function getAvailableLanguages()
19+
for languageIndex, languageCode in ipairs(Language.getAvailable()) do
20+
local languageName = Language.getLanguageNameFromCode(languageCode)
21+
languageCodes[languageName] = languageCode
22+
end
23+
end
24+
25+
local function populateCombobox()
26+
getAvailableLanguages()
27+
for languageName, languageCode in pairs(languageCodes) do
28+
guiComboBoxAddItem(languageComboBox, languageName)
29+
end
30+
end
31+
32+
local function showComboBox()
33+
languageComboBox:setVisible(true)
34+
end
35+
36+
local function hideComboBox()
37+
languageComboBox:setVisible(false)
38+
end
39+
40+
local function toggleDialog()
41+
if languageComboBox:getVisible() then
42+
hideComboBox()
43+
setNewLanguage()
44+
else
45+
showComboBox()
46+
end
47+
end
48+
49+
local function attachToButton()
50+
LanguageGlobeButton.setCallOnClick(toggleDialog)
51+
end
52+
53+
local function createDialog()
54+
createComboBox()
55+
populateCombobox()
56+
hideComboBox()
57+
attachToButton()
58+
end
59+
addEventHandler("onClientResourceStart", resourceRoot, createDialog)
60+
61+
LanguageSelection = {}
62+
function LanguageSelection.setShowing(shouldShow)
63+
LanguageGlobeButton.setRendering(shouldShow)
64+
if not shouldShow then
65+
languageComboBox:setVisible(false)
66+
end
67+
end

battlegrounds/lang/globeIcon.png

11.8 KB
Loading

battlegrounds/meta.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ Version: 0.0.1 Pre-Alpha
4545
<script src="lang/cLanguageStrings.lua" type="client" cache="false" />
4646
<script src="lang/cLanguage.lua" type="client" cache="false" />
4747
<script src="lang/cDebug.lua" type="client" cache="false" />
48+
<script src="lang/cLanguageGlobeButton.lua" type="client" cache="false" />
49+
<script src="lang/cLanguageSelection.lua" type="client" cache="false" />
50+
51+
<config src="lang/language.fods" type="server" />
52+
53+
<file src="lang/globeIcon.png"/>
4854

49-
<config src="lang/language.fods" type="server" />
50-
51-
5255
<!-- lootPointEditor -->
5356
<script src="lootPointEditor/lootPoints.lua" type="server" /> <!-- Must be the first -->
5457
<script src="lootPointEditor/sWriteTableToDisk.lua" type="server" /> <!-- Must be the second -->

0 commit comments

Comments
 (0)