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

220 lines
8.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

local SettingInfo = quick_class("SettingInfo")
local this = SettingInfo
local languageGroup = {"中文","英文"}
function SettingInfo:ctor( gameObject,rootPanel)
self.gameObject = gameObject
self:InitComponent(gameObject, rootPanel)
end
--初始化组件(用于子类重写)
function SettingInfo:InitComponent(gameObject, rootPanel)
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.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
end
function SettingInfo:SetTipShow()
if IsLanguagePack then
local flag = PlayerPrefs.GetInt("language_flag")
LogGreen("PlayerPrefs:"..flag)
if flag == 0 then
this.dropDownText.text = "中文"
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: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("所选语言需要在重新登录之后才能生效,是否重新登录?",function() end,function()
Game.Logout()
end,"取消","确定","",false,"")
end
)
end
--cdKey兑换
Util.AddClick(this.cdKey, function()
UIManager.OpenPanel(UIName.CDKeyExchangePanel)
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("您确定要重新登录?", nil, function()
Game.Logout()
end)
end)
Util.AddClick(this.btnOneKeyCopy, function()
if not UnityEngine.Application.isMobilePlatform then
PopupTipPanel.ShowTip("不支持当前平台")
return
end
local str = "服务器名:" .. PlayerManager.serverInfo.name .. "\n" .. "角色名:" .. PlayerManager.nickName ..
"\n" .. "账号ID" .. AppConst.OpenId .. "\n" .. "角色ID" .. PlayerManager.uid
AndroidDeviceInfo.Instance:SetCopyValue(str)
PopupTipPanel.ShowTip("复制成功")
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.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 = PlayerManager.nickName
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 "" or guildData.name
this.serverText.text = PlayerManager.serverInfo.name
end
function SettingInfo:OnSortingOrderChange()
-- 头像层级
if this.playerHead then
this.playerHead:SetLayer(self.sortingOrder)
end
end
function SettingInfo:OnShowData()
end
--界面关闭时调用(用于子类重写)
function SettingInfo:OnClose()
end
--界面销毁时调用(用于子类重写)
function SettingInfo:OnDestroy()
--SubUIManager.Close(this.UpView)
if this.playerHead then
this.playerHead:Recycle()
this.playerHead = nil
end
ClearRedPointObject(RedPointType.Setting_Head)
end
return SettingInfo