miduo_client/Assets/ManagedResources/~Lua/Modules/Setting/SettingInfo.lua

275 lines
11 KiB
Lua

local SettingInfo = quick_class("SettingInfo")
local this = SettingInfo
local languageGroup = {Language[11854],Language[11855]}
function SettingInfo:ctor( gameObject,rootPanel)
self.gameObject = gameObject
self:InitComponent(gameObject, rootPanel)
end
--初始化组件(用于子类重写)
function SettingInfo:InitComponent(gameObject, rootPanel)
this.spLoader = SpriteLoader.New()
this.rootPanel = rootPanel
this.head = Util.GetGameObject(gameObject, "playerInfo/head")
this.headpos = Util.GetGameObject(gameObject, "playerInfo/head/pos")
this.headRedpot = Util.GetGameObject(gameObject, "playerInfo/head/redpot")
this.name = Util.GetGameObject(gameObject, "playerInfo/name/Text")
this.btnChangeName = Util.GetGameObject(gameObject, "playerInfo/name/Image/btn")
this.exp = Util.GetGameObject(gameObject, "playerInfo/exp"):GetComponent("Slider")
this.expText = Util.GetGameObject(gameObject, "playerInfo/exp/ExpText"):GetComponent("Text")
this.uidText = Util.GetGameObject(gameObject, "playerInfo/uid/Text"):GetComponent("Text")
this.idText = Util.GetGameObject(gameObject, "playerInfo/id/Text"):GetComponent("Text")
this.guildText = Util.GetGameObject(gameObject, "playerInfo/guild/Text"):GetComponent("Text")
this.serverText = Util.GetGameObject(gameObject, "playerInfo/server/Text"):GetComponent("Text")
this.BGMSlider = Util.GetGameObject(gameObject, "setting/BGMSlider"):GetComponent("Slider")
this.BGMSliderValue = Util.GetGameObject(gameObject, "setting/BGMSlider/count"):GetComponent("Text")
this.SoundSlider = Util.GetGameObject(gameObject, "setting/SoundSlider"):GetComponent("Slider")
this.SoundSliderValue = Util.GetGameObject(gameObject, "setting/SoundSlider/count"):GetComponent("Text")
this.btnChangeLogin = Util.GetGameObject(gameObject, "setting/changelogin")
this.btnOneKeyCopy = Util.GetGameObject(gameObject, "setting/oneKeyCopy")
this.btnBind = Util.GetGameObject(gameObject, "other/box/BindAccount")
this.btnCancel = Util.GetGameObject(gameObject, "other/box/CancelAccount")
--兑换码
this.cdKey = Util.GetGameObject(gameObject, "other/box/cdkey")
this.submit = Util.GetGameObject(gameObject, "other/box/submit")
-- --游戏语言切换按钮
-- this.languageBtn = Util.GetGameObject(gameObject, "other/box/languageBtn")
-- this.languageText= Util.GetGameObject(this.languageBtn,"Text"):GetComponent("Text")
-- this.languageText.text=GetCurLanguage()==0 and "中文" or "英文"
if IsLanguagePack then
this.dropDown = Util.GetGameObject(gameObject,"other/box/Dropdown"):GetComponent("Dropdown")
this.dropDownText = Util.GetGameObject(gameObject,"other/box/Dropdown/Label"):GetComponent("Text")
this.dropDownTip = Util.GetGameObject(gameObject,"other/box/Dropdown/tip")
else
this.dropDown = Util.GetGameObject(gameObject,"other/box/Dropdown")
this.dropDown:SetActive(false)
end
if ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.IS_SELECT_RESLUTION) then
this.selectResolution = Util.GetGameObject(gameObject,"other/box/selectResolution"):GetComponent("Dropdown")
this.selectResolutionText = Util.GetGameObject(gameObject,"other/box/selectResolution/Label"):GetComponent("Text")
this.selectResolutionTip = Util.GetGameObject(gameObject,"other/box/selectResolution/tip")
else
this.selectResolution = Util.GetGameObject(gameObject,"other/box/selectResolution")
this.selectResolution:SetActive(false)
end
if AppConst.isSDKLogin and SDKMgr:GetSubChannel() and SDKMgr:GetSubChannel()=="Yes" then
this.btnBind:SetActive(true)
else
this.btnBind:SetActive(false)
end
end
function SettingInfo:SetTipShow()
if IsLanguagePack then
local flag = PlayerPrefs.GetInt("language_flag")
--LogGreen("PlayerPrefs:"..flag)
if flag == 0 then
this.dropDownText.text = Language[11854]
elseif flag == 2 then
this.dropDownText.text = "Tiếng Việt"
elseif flag == 1 then
this.dropDownText.text = "English"
end
this.dropDown.value = flag
if GetCurLanguage() ~= flag then
this.dropDownTip.gameObject:SetActive(true)
else
this.dropDownTip.gameObject:SetActive(false)
end
end
end
function SettingInfo:SetReslutionTipShow()
if ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.IS_SELECT_RESLUTION) then
local value = PlayerPrefs.GetInt("ResLution")
this.selectResolution.value = value
if value == 0 then
UnityEngine.Application.targetFrameRate = 30;
this.selectResolutionText.text = "普通帧率"
this.selectResolutionTip.gameObject:SetActive(false)
else
UnityEngine.Application.targetFrameRate = 60;
this.selectResolutionText.text = "高帧率"
this.selectResolutionTip.gameObject:SetActive(true)
end
end
end
--绑定事件(用于子类重写)
function SettingInfo:BindEvent()
if IsLanguagePack then
this.dropDown.onValueChanged:AddListener(
function(value)
PlayerPrefs.SetInt("language_flag",value)
this:SetTipShow()
if value == GetCurLanguage() then
return
end
MsgPanel.ShowTwo(Language[11856],function() end,function()
Game.Logout()
end,Language[10731],Language[10732],"",false,"")
end
)
end
if ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.IS_SELECT_RESLUTION) then
this.selectResolution.onValueChanged:AddListener(
function(value)
PlayerPrefs.SetInt("ResLution",value)
this:SetReslutionTipShow()
end
)
end
--cdKey兑换
Util.AddClick(this.cdKey, function()
UIManager.OpenPanel(UIName.CDKeyExchangePanel)
end)
--游客绑定
Util.AddClick(this.btnBind, function()
if AppConst.isSDKLogin and SDKMgr:GetSubChannel() and SDKMgr:GetSubChannel()=="Yes" then
SubmitExtraData({type=SDKSubMitType.TYPE_FENGTI_BIND_ACCOUNT})
end
end)
--账号注销
Util.AddClick(this.btnCancel, function()
end)
-- --语言切换
-- Util.AddClick(this.languageBtn, function()
-- local setId=GetCurLanguage()==0 and 1 or 0
-- Log("中英切换"..setId)
-- PlayerPrefs.SetInt("language",setId)
-- this.languageText.text=GetCurLanguage()==0 and "中文" or "英文"
-- end)
--上报战斗日志
Util.AddOnceClick(this.submit, function()
BattleRecordManager.SubmitBattleRecord()
end)
Util.AddClick(this.head, function()
UIManager.OpenPanel(UIName.HeadChangePopup)
end)
Util.AddClick(this.btnChangeName, function()
--PopupTipPanel.ShowTip("功能尚未开放,敬请期待")
UIManager.OpenPanel(UIName.CreateNamePopup)
end)
Util.AddSlider(this.BGMSlider.gameObject, function(go, value)
SettingManager.SetSettingData(SETTING_TYPE.BGM_RATIO, value)
this.BGMSliderValue.text = math.floor(value * 100)
end)
Util.AddSlider(this.SoundSlider.gameObject, function(go, value)
SettingManager.SetSettingData(SETTING_TYPE.SOUND_RATIO, value)
this.SoundSliderValue.text = math.floor(value * 100)
end)
Util.AddClick(this.btnChangeLogin, function()
MsgPanel.ShowTwo(Language[11857], nil, function()
Game.Logout()
end)
end)
Util.AddClick(this.btnOneKeyCopy, function()
if not UnityEngine.Application.isMobilePlatform then
PopupTipPanel.ShowTip(Language[11858])
return
end
local str = Language[11859] .. PlayerManager.serverInfo.name .. "\n" .. Language[11860] .. PlayerManager.nickName ..
"\n" .. Language[11861] .. AppConst.OpenId .. "\n" .. Language[11862] .. PlayerManager.uid
AndroidDeviceInfo.Instance:SetCopyValue(str)
PopupTipPanel.ShowTip(Language[11863])
end)
BindRedPointObject(RedPointType.Setting_Head, this.headRedpot)
end
--添加事件监听(用于子类重写)
function SettingInfo:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Player.OnHeadFrameChange, this.RefreshPlayerInfoShow)
Game.GlobalEvent:AddEvent(GameEvent.Player.OnHeadChange, this.RefreshPlayerInfoShow)
Game.GlobalEvent:AddEvent(GameEvent.Player.OnChangeName, this.RefreshPlayerInfoShow)
end
--移除事件监听(用于子类重写)
function SettingInfo:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Player.OnHeadFrameChange, this.RefreshPlayerInfoShow)
Game.GlobalEvent:RemoveEvent(GameEvent.Player.OnHeadChange, this.RefreshPlayerInfoShow)
Game.GlobalEvent:RemoveEvent(GameEvent.Player.OnChangeName, this.RefreshPlayerInfoShow)
end
--界面打开时调用(用于子类重写)
function SettingInfo:OnOpen()
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function SettingInfo:OnShow()
this:SetTipShow()
this:SetReslutionTipShow()
this.cdKey:SetActive(SERVER_VERSION == 0)
this.RefreshPlayerInfoShow()
this.BGMSlider.value = SettingManager.GetSettingData(SETTING_TYPE.BGM_RATIO)
this.SoundSlider.value = SettingManager.GetSettingData(SETTING_TYPE.SOUND_RATIO)
this:OnShowData()
end
function this.RefreshPlayerInfoShow()
if not this.playerHead then
--this.playerHead = CommonPool.CreateNode(POOL_ITEM_TYPE.PLAYER_HEAD, this.headpos)
this.playerHead = SubUIManager.Open(SubUIConfig.PlayerHeadView, this.headpos.transform)
end
this.playerHead:Reset()
this.playerHead:SetHead(PlayerManager.head)
this.playerHead:SetFrame(HeadManager.GetCurFrameId())
this.playerHead:SetLevel(PlayerManager.level)
this.playerHead:SetLayer(this.rootPanel.sortingOrder)
this.playerHead:SetEffectScale(1.1)
this.name:GetComponent("Text").text = PracticeManager.SetNameColor(PlayerManager.nickName,PracticeManager.PracticeLevel)
this.exp.value = PlayerManager.exp / PlayerManager.userLevelData[PlayerManager.level].Exp
this.expText.text = PlayerManager.exp .. "/" .. PlayerManager.userLevelData[PlayerManager.level].Exp
this.uidText.text = PlayerManager.uid
this.idText.text = AppConst.OpenId or LoginManager.openId
local guildData = MyGuildManager.GetMyGuildInfo()
this.guildText.text = guildData == nil and Language[10086] or guildData.name
this.serverText.text = PlayerManager.serverInfo.name
end
function SettingInfo:OnSortingOrderChange()
-- 头像层级
if this.playerHead then
this.playerHead:SetLayer(this.rootPanel.sortingOrder)
end
end
function SettingInfo:OnShowData()
end
--界面关闭时调用(用于子类重写)
function SettingInfo:OnClose()
end
--界面销毁时调用(用于子类重写)
function SettingInfo:OnDestroy()
this.spLoader:Destroy()
--SubUIManager.Close(this.UpView)
if this.playerHead then
this.playerHead:Recycle()
this.playerHead = nil
end
ClearRedPointObject(RedPointType.Setting_Head)
end
return SettingInfo