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

Commit

Permalink
Implement language selection GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
expert975 committed Oct 15, 2017
1 parent 04e9b9b commit fc8991c
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 3 deletions.
1 change: 1 addition & 0 deletions battlegrounds/accounting/cLoginPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ local function closeLoginPanel()
loadingBar.hide()
guiSetVisible(homeScreen.staticimage[1],true)
fadeCamera(true)
LanguageSelection.setShowing(true)
end

local function showLoadingBar()
Expand Down
1 change: 1 addition & 0 deletions battlegrounds/gui/homescreen_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ end)
function sendPlayerToLobbyOnPlayPress(button)
if button == "left" then
triggerServerEvent("mtabg_sendPlayerToLobby",localPlayer)
LanguageSelection.setShowing(false)
guiSetVisible(homeScreen.staticimage[1],false)
guiSetVisible(homeScreen.staticimage[5],false)
for i=6,21 do
Expand Down
1 change: 1 addition & 0 deletions battlegrounds/hud/hud_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ addEventHandler("onClientMouseLeave",endScreen.label[7],onMouseOverBackToHomeScr

function sendPlayerBackToHomeScreenOnDeath()
guiSetVisible(homeScreen.staticimage[1],true)
LanguageSelection.setShowing(true)
guiSetVisible(endScreen.image[1],false)
guiSetVisible(endScreen.image[2],false)
sendToHomeScreen(homeScreenDimension)
Expand Down
77 changes: 77 additions & 0 deletions battlegrounds/lang/cLanguageGlobeButton.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
local sx, sy = guiGetScreenSize()
local globeTexture = DxTexture("lang/globe2.png")
local color = 0
local lastTick = 0
local rootx = sx*0.013020833 --25
local rooty = sy*0.148148148 --160
local sizex = sx*0.039062500 --75
local sizey = sy*0.069444444 --75
local radius = sizex*.5
local centerx = sizex*.5 + rootx
local centery = sizey*.5 + rooty
local isRendering = false
local functionToCallOnClick
local Globe = {}

local function render()
dxDrawImage(rootx, rooty, sizex, sizey, globeTexture, 0, 0, 0, tocolor(color,color,color,255), false)
end

local function isClickInsideGlobe(button, state, cursorx, cursory)
if button == "left" and state == "up" then
local distance = math.sqrt(
math.pow(centerx - cursorx, 2)
+ math.pow(centery - cursory, 2)
)
local isInside = distance <= radius
if isInside and functionToCallOnClick then
functionToCallOnClick()
end
end
end

local function fadeIn()
if color < 255 then
local dTime = getTickCount() - lastTick
local controlVar = (256*dTime)/1000
color = color + controlVar
if color > 255 then
color = 255
end
lastTick = getTickCount()
else
removeEventHandler("onClientRender", root, fadeIn)
end
end

function Globe.setFadingIn()
lastTick = getTickCount()
addEventHandler("onClientRender", root, fadeIn)
end

function Globe.setRendering(shouldRender)
if shouldRender then
addEventHandler("onClientRender", root, render)
addEventHandler("onClientClick", root, isClickInsideGlobe)
Globe.setFadingIn()
else
removeEventHandler("onClientRender", root, render)
removeEventHandler("onClientClick", root, isClickInsideGlobe)
removeEventHandler("onClientRender", root, fadeIn)
end
isRendering = shouldRender
end

function Globe.getRendering()
return isRendering
end

function Globe.toggleRendering()
Globe.setRendering(not isRendering)
end

function Globe.setCallOnClick(functionToCall)
functionToCallOnClick = functionToCall
end

LanguageGlobeButton = Globe
67 changes: 67 additions & 0 deletions battlegrounds/lang/cLanguageSelection.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
local sx, sy = guiGetScreenSize()
local rootx = sx*0.008854167 --17
local rooty = sy*0.225925926 --244
local languageComboBox
local languageCodes = {}

local function setNewLanguage()
local selectedItem = languageComboBox:getSelected()
local languageName = languageComboBox:getItemText(selectedItem)
Language.set(languageCodes[languageName])
end

local function createComboBox()
languageComboBox = guiCreateComboBox(rootx, rooty, 100, 20, Language.getCurrentName(), false)
guiComboBoxAdjustHeight(languageComboBox, Language.getCount())
end

local function getAvailableLanguages()
for languageIndex, languageCode in ipairs(Language.getAvailable()) do
local languageName = Language.getLanguageNameFromCode(languageCode)
languageCodes[languageName] = languageCode
end
end

local function populateCombobox()
getAvailableLanguages()
for languageName, languageCode in pairs(languageCodes) do
guiComboBoxAddItem(languageComboBox, languageName)
end
end

local function showComboBox()
languageComboBox:setVisible(true)
end

local function hideComboBox()
languageComboBox:setVisible(false)
end

local function toggleDialog()
if languageComboBox:getVisible() then
hideComboBox()
setNewLanguage()
else
showComboBox()
end
end

local function attachToButton()
LanguageGlobeButton.setCallOnClick(toggleDialog)
end

local function createDialog()
createComboBox()
populateCombobox()
hideComboBox()
attachToButton()
end
addEventHandler("onClientResourceStart", resourceRoot, createDialog)

LanguageSelection = {}
function LanguageSelection.setShowing(shouldShow)
LanguageGlobeButton.setRendering(shouldShow)
if not shouldShow then
languageComboBox:setVisible(false)
end
end
Binary file added battlegrounds/lang/globeIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions battlegrounds/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ Version: 0.0.1 Pre-Alpha
<script src="lang/cLanguageStrings.lua" type="client" cache="false" />
<script src="lang/cLanguage.lua" type="client" cache="false" />
<script src="lang/cDebug.lua" type="client" cache="false" />
<script src="lang/cLanguageGlobeButton.lua" type="client" cache="false" />
<script src="lang/cLanguageSelection.lua" type="client" cache="false" />

<config src="lang/language.fods" type="server" />

<file src="lang/globeIcon.png"/>

<config src="lang/language.fods" type="server" />


<!-- lootPointEditor -->
<script src="lootPointEditor/lootPoints.lua" type="server" /> <!-- Must be the first -->
<script src="lootPointEditor/sWriteTableToDisk.lua" type="server" /> <!-- Must be the second -->
Expand Down

0 comments on commit fc8991c

Please sign in to comment.