233 lines
9.3 KiB
Lua
233 lines
9.3 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:addEventListener(EventManager.CUSTOM_EVENT.BIND_ACCOUNT_SUCCESS, function()
|
|
self:refreshAccountInfo()
|
|
end)
|
|
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()
|
|
-- 超框选择小字体特殊处理
|
|
if language == "id" or language == "pt" then
|
|
language = language .."_1"
|
|
end
|
|
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:initCDKeyBtn()
|
|
self:initSupportBtn()
|
|
self:refreshMusic()
|
|
self:refreshVoice()
|
|
end
|
|
|
|
function GameSettingUI:initLoginBtn()
|
|
self:initGoogleLoginBtn()
|
|
self:initAppleLoginBtn()
|
|
local deleteBtn = self.uiMap["game_setting_ui.bg.delete_btn"]
|
|
deleteBtn:addClickListener(function()
|
|
ModuleManager.AccountManager:showDeleteUI()
|
|
end)
|
|
self:refreshAccountInfo()
|
|
end
|
|
|
|
function GameSettingUI:initGoogleLoginBtn()
|
|
if Platform:isIosPlatform() then
|
|
self.uiMap["game_setting_ui.bg.google_sign_btn"]:setVisible(false)
|
|
self.uiMap["game_setting_ui.bg.google_switch_btn"]:setVisible(false)
|
|
else
|
|
self.uiMap["game_setting_ui.bg.google_sign_btn"]:setVisible(true)
|
|
self.uiMap["game_setting_ui.bg.google_sign_btn"]:addClickListener(function()
|
|
if ModuleManager.AccountManager:getIsBinded() then
|
|
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC))
|
|
return
|
|
end
|
|
ModuleManager.AccountManager:bindAccount()
|
|
end)
|
|
|
|
self.uiMap["game_setting_ui.bg.google_switch_btn"]:setVisible(true)
|
|
self.uiMap["game_setting_ui.bg.google_switch_btn"]:addClickListener(function()
|
|
if ModuleManager.AccountManager:getIsBinded() then
|
|
ModuleManager.AccountManager:changeAccount()
|
|
else
|
|
local params = {
|
|
content = I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_TIPS_DESC),
|
|
boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL,
|
|
okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK),
|
|
okFunc = function()
|
|
ModuleManager.AccountManager:changeAccount()
|
|
end
|
|
}
|
|
GFunc.showMessageBox(params)
|
|
end
|
|
end)
|
|
self.uiMap["game_setting_ui.bg.google_switch_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_DESC))
|
|
end
|
|
end
|
|
|
|
function GameSettingUI:initAppleLoginBtn()
|
|
if Platform:isIosPlatform() then
|
|
self.uiMap["game_setting_ui.bg.apple_sign_btn"]:setVisible(true)
|
|
self.uiMap["game_setting_ui.bg.apple_sign_btn"]:addClickListener(function()
|
|
if ModuleManager.AccountManager:getIsBinded() then
|
|
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC))
|
|
return
|
|
end
|
|
ModuleManager.AccountManager:bindAccount()
|
|
end)
|
|
self.uiMap["game_setting_ui.bg.apple_switch_btn"]:setVisible(true)
|
|
self.uiMap["game_setting_ui.bg.apple_switch_btn"]:addClickListener(function()
|
|
if ModuleManager.AccountManager:getIsBinded() then
|
|
ModuleManager.AccountManager:changeAccount()
|
|
else
|
|
local params = {
|
|
content = I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_TIPS_DESC),
|
|
boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL,
|
|
okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK),
|
|
okFunc = function()
|
|
ModuleManager.AccountManager:changeAccount()
|
|
end
|
|
}
|
|
GFunc.showMessageBox(params)
|
|
end
|
|
end)
|
|
self.uiMap["game_setting_ui.bg.apple_switch_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_DESC))
|
|
else
|
|
self.uiMap["game_setting_ui.bg.apple_sign_btn"]:setVisible(false)
|
|
self.uiMap["game_setting_ui.bg.apple_switch_btn"]:setVisible(false)
|
|
end
|
|
end
|
|
|
|
function GameSettingUI:initCDKeyBtn()
|
|
self.uiMap["game_setting_ui.bg.cdkey_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.CDKEY_NAME))
|
|
self.uiMap["game_setting_ui.bg.cdkey_btn.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.CDKEY_EXCHANGE))
|
|
self.uiMap["game_setting_ui.bg.cdkey_btn"]:addClickListener(function()
|
|
ModuleManager.GameSettingManager:showCDKeyUI()
|
|
end)
|
|
end
|
|
|
|
function GameSettingUI:initSupportBtn()
|
|
self.uiMap["game_setting_ui.bg.support_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.SUPPORT_DESC_1))
|
|
self.uiMap["game_setting_ui.bg.support_btn.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.SUPPORT_DESC_2))
|
|
self.uiMap["game_setting_ui.bg.support_btn"]:addClickListener(function()
|
|
ModuleManager.GameSettingManager:showSupport()
|
|
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://perfeggsgame.com/tos.html")
|
|
end)
|
|
|
|
self.uiMap["game_setting_ui.bg.tx_2"]:addClickListener(function()
|
|
GFunc.openUrl("https://perfeggsgame.com/pp.html")
|
|
end)
|
|
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
|
|
|
|
function GameSettingUI:refreshAccountInfo()
|
|
if Platform:isIosPlatform() then
|
|
if ModuleManager.AccountManager:getIsBinded() then
|
|
self.uiMap["game_setting_ui.bg.apple_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC))
|
|
else
|
|
self.uiMap["game_setting_ui.bg.apple_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BIND_ACCOUNT_DESC))
|
|
end
|
|
else
|
|
if ModuleManager.AccountManager: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
|
|
end
|
|
end
|
|
|
|
return GameSettingUI |