c1_lua/lua/app/ui/game_setting/game_setting_ui.lua
2023-05-08 21:10:41 +08:00

140 lines
4.9 KiB
Lua

local GameSettingUI = class("GameSettingUI", BaseUI)
local CHECK_WHITE_LIST_COUNT = 5
function GameSettingUI:ctor()
self.clickMusicCount = 0
end
function GameSettingUI:isFullScreen()
return false
end
function GameSettingUI:getPrefabPath()
return "assets/prefabs/ui/setting/game_setting_ui.prefab"
end
function GameSettingUI:onLoadRootComplete()
self.uiMap = self.root:genAllChildren()
self:_display()
self:_addListeners()
self:_bind()
end
function GameSettingUI:onPressBackspace()
self:closeUI()
end
function GameSettingUI:_display()
self.uiMap["game_setting_ui.bg.title"]:setText(I18N:getGlobalText(I18N.GlobalConst.SETTING_DESC))
self.uiMap["game_setting_ui.bg.music_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.SETTING_DESC_MUSIC))
self.uiMap["game_setting_ui.bg.voice_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.SETTING_DESC_VOICE))
self.uiMap["game_setting_ui.bg.language_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.SETTING_DESC_LANGUAGE))
self.uiMap["game_setting_ui.bg.tx_1"]:setText(I18N:getGlobalText(I18N.GlobalConst.SERVICE_DESC))
self.uiMap["game_setting_ui.bg.tx_2"]:setText(I18N:getGlobalText(I18N.GlobalConst.PRIVACY_DESC))
local version = CS.BF.BFMain.Instance.GameLaunchMgr:GetCurrentVersion()
self.uiMap["game_setting_ui.bg.version_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.CLIENT_VERSION, version))
local language = I18N:getCurLanguage()
self.uiMap["game_setting_ui.bg.language_btn.status"]:setSprite(GConst.ATLAS_PATH.UI_SETTING, "language_" .. language)
local acountId = DataManager.PlayerData:getAcountId() or GConst.EMPTY_STRING
self.uiMap["game_setting_ui.bg.player_bg.player_id"]:setText(I18N:getGlobalText(I18N.GlobalConst.SETTING_DESC_1, acountId))
self:initLoginBtn()
self:refreshMusic()
self:refreshVoice()
end
function GameSettingUI:initLoginBtn()
self.uiMap["game_setting_ui.bg.google_sign_btn"]:addClickListener(function()
end)
if DataManager.PlayerData:getIsBinded() then
self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC))
else
self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BIND_ACCOUNT_DESC))
end
self.uiMap["game_setting_ui.bg.google_switch_btn"]:addClickListener(function()
end)
self.uiMap["game_setting_ui.bg.google_switch_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_DESC))
local deleteTx = self.uiMap["game_setting_ui.bg.delete_tx"]
deleteTx:setText(I18N:getGlobalText(I18N.GlobalConst.DELETE_ACCOUNT_DESC))
deleteTx:addClickListener(function()
end)
end
function GameSettingUI:_addListeners()
self.uiMap["game_setting_ui.bg.close_btn"]:addClickListener(function()
self:closeUI()
end)
self.uiMap["game_setting_ui.bg.music_bg"]:addClickListener(function()
local status = AudioManager:isMusicEnabled()
if not status then
AudioManager:setMusicVolume(1)
else
AudioManager:setMusicVolume(0)
end
if CS.BF.BFMain.IsWhite then
self.clickMusicCount = self.clickMusicCount + 1
if self.clickMusicCount > CHECK_WHITE_LIST_COUNT then
GFunc.showToast("Please don't frequently operate")
end
end
self:refreshMusic()
end)
self.uiMap["game_setting_ui.bg.voice_bg"]:addClickListener(function()
local status = AudioManager:isEffectEnabled()
if not status then
AudioManager:setEffectVolume(1)
else
AudioManager:setEffectVolume(0)
end
self:refreshVoice()
end)
self.uiMap["game_setting_ui.bg.language_btn"]:addClickListener(function()
ModuleManager.GameSettingManager:showLanguageUI()
end)
self.uiMap["game_setting_ui.bg.player_bg.player_id_btn"]:addClickListener(function()
local acountId = DataManager.PlayerData:getAcountId() or GConst.EMPTY_STRING
GFunc.copyStr(acountId)
end)
self.uiMap["game_setting_ui.bg.tx_1"]:addClickListener(function()
GFunc.openUrl("https://cobbygame.com/tos.html")
end)
self.uiMap["game_setting_ui.bg.tx_2"]:addClickListener(function()
GFunc.openUrl("https://www.cobbygame.com/pp.html")
end)
end
function GameSettingUI:_bind()
end
function GameSettingUI:refreshMusic()
local offIcon = self.uiMap["game_setting_ui.bg.music_bg.off"]
local onIcon = self.uiMap["game_setting_ui.bg.music_bg.on"]
local status = AudioManager:isMusicEnabled()
offIcon:setVisible(status ~= true)
onIcon:setVisible(status == true)
end
function GameSettingUI:refreshVoice()
local offIcon = self.uiMap["game_setting_ui.bg.voice_bg.off"]
local onIcon = self.uiMap["game_setting_ui.bg.voice_bg.on"]
local status = AudioManager:isEffectEnabled()
offIcon:setVisible(status ~= true)
onIcon:setVisible(status == true)
end
return GameSettingUI