272 lines
11 KiB
Lua
272 lines
11 KiB
Lua
require("Base/BasePanel")
|
||
XiaoYaoYouPanel = Inherit(BasePanel)
|
||
local this = XiaoYaoYouPanel
|
||
local cursortingOrder
|
||
local freeTravel = ConfigManager.GetConfig(ConfigName.FreeTravel)
|
||
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
local _MaxNum = 10
|
||
local firstMapId = 6001
|
||
--初始化组件(用于子类重写)
|
||
function this:InitComponent()
|
||
this.spLoader = SpriteLoader.New()
|
||
this.btnBack = Util.GetGameObject(self.gameObject, "btnBack")
|
||
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
|
||
this.scroll = Util.GetGameObject(self.gameObject, "scroll")
|
||
this.content = Util.GetGameObject(self.gameObject, "scroll/Content")
|
||
this.btnList = {}
|
||
this.infoList = {}
|
||
for i = 1, _MaxNum do
|
||
this.btnList[i] = Util.GetGameObject(this.scroll, "Content/map/btn_"..i)
|
||
this.infoList[i] = Util.GetGameObject(this.scroll, "Content/Infos/info_"..i)
|
||
end
|
||
-- 逍遥点刷新倒计时显示
|
||
this.bgTime = Util.GetGameObject(self.gameObject, "costProp/Bgtime")
|
||
this.costIcon=Util.GetGameObject(self.gameObject, "costProp/icon"):GetComponent("Image")
|
||
this.costInfo=Util.GetGameObject(self.gameObject, "costProp/energyInfo"):GetComponent("Text")
|
||
this.addItmBtn = Util.GetGameObject(self.gameObject, "costProp/add")
|
||
this.actCountTime = Util.GetGameObject(this.bgTime, "time"):GetComponent("Text")
|
||
|
||
-- this.scrollItem = Util.GetGameObject(self.gameObject, "scrollItem")
|
||
-- this.itemPre = Util.GetGameObject(self.gameObject, "prefab/ItemPre")
|
||
-- local rootHight = this.scrollItem.transform.rect.height
|
||
-- local width = this.scrollItem.transform.rect.width
|
||
-- this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scrollItem.transform,
|
||
-- this.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, -3))
|
||
-- this.ScrollView.moveTween.MomentumAmount = 1
|
||
-- this.ScrollView.moveTween.Strength = 2
|
||
end
|
||
|
||
--绑定事件(用于子类重写)
|
||
function this:BindEvent()
|
||
Util.AddClick(this.btnBack, function ()
|
||
self:ClosePanel()
|
||
end)
|
||
Util.AddClick(this.addItmBtn, function ()
|
||
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.XiaoYaoYouItemExchange,98)
|
||
end)
|
||
end
|
||
|
||
--添加事件监听(用于子类重写)
|
||
function this:AddListener()
|
||
Game.GlobalEvent:AddEvent(GameEvent.XiaoYao.RefreshEventShow, this.UpdateYunYouVleShow)
|
||
end
|
||
|
||
--移除事件监听(用于子类重写)
|
||
function this:RemoveListener()
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.XiaoYao.RefreshEventShow, this.UpdateYunYouVleShow)
|
||
end
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function this:OnOpen(data)
|
||
--显示资源条
|
||
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.MonsterCamp })
|
||
-- 界面显示
|
||
this.RefreshShow(data)
|
||
this.needShowRefresh = false -- show方法中不再需要刷新
|
||
-- 滚动到底部
|
||
this.ScrollToBottom()
|
||
end
|
||
|
||
|
||
function this:OnShow()
|
||
-- 判断是否需要自己刷新
|
||
if not this.needShowRefresh then
|
||
this.needShowRefresh = true
|
||
return
|
||
end
|
||
-- 刷新
|
||
XiaoYaoManager.GetOpenMapData(function(data)
|
||
this.RefreshShow(data)
|
||
end)
|
||
end
|
||
|
||
-- 刷新界面显示
|
||
function this.RefreshShow(data)
|
||
local _allData={}
|
||
local _cruLevel = PlayerManager.level
|
||
Log("当前玩家等级:".._cruLevel)
|
||
for index, config in ConfigPairs(freeTravel) do
|
||
local _isUnLock = config.UnlockLevel >= 0
|
||
and _cruLevel >= config.UnlockLevel--判断章节是否开启
|
||
and (config.MapID == firstMapId or XiaoYaoManager.IsFirstPass(config.MapID - 1))
|
||
local showReward = ConfigManager.GetConfigData(ConfigName.RewardGroup,config.FirstReward).ShowItem
|
||
local _progress=0
|
||
local isShowRed=false
|
||
Log("当前mapid:"..config.MapID)
|
||
Log("index"..index)
|
||
if data[config.MapID]~=nil then
|
||
_progress=data[config.MapID].process
|
||
if data[config.MapID].first==1 then
|
||
showReward = ConfigManager.GetConfigData(ConfigName.RewardGroup,config.FinalReward[1]).ShowItem
|
||
end
|
||
end
|
||
|
||
local _singleData={
|
||
mapId=config.MapID,
|
||
mapName=config.FreeTravelName,
|
||
mapImage=config.MapIcon,
|
||
ziImage=config.NameIcon,
|
||
isUnLock=_isUnLock,
|
||
progress=_progress,
|
||
passReward=showReward[1],
|
||
unlockLevel = config.UnlockLevel,
|
||
}
|
||
_allData[index]=_singleData
|
||
end
|
||
Log("所有地图数量:"..#_allData)
|
||
|
||
for i = 1, _MaxNum do
|
||
this.SingleDataShow(this.btnList[i], this.infoList[i], _allData[i], i)
|
||
end
|
||
this.ShowCountTime()
|
||
-- this.ScrollView:SetData(_allData, function (index, go)
|
||
-- this.SingleDataShow(go, _allData[index])
|
||
-- end)
|
||
end
|
||
|
||
--- 滑动到底部
|
||
function this.ScrollToBottom()
|
||
local cheight = this.content.transform.rect.height
|
||
local vheight = this.scroll.transform.rect.height
|
||
local dheight = cheight - vheight
|
||
-- 判断滚动到最下面的条件
|
||
local pos = this.content.transform.anchoredPosition3D
|
||
--LogGreen("#data:"..LengthOfTable(XiaoYaoManager.allMapData))
|
||
if LengthOfTable(XiaoYaoManager.allMapData) >= 7 then
|
||
this.content.transform.anchoredPosition3D = Vector3(pos.x, 0, 0)
|
||
else
|
||
this.content.transform.anchoredPosition3D = Vector3(pos.x, dheight, 0)
|
||
end
|
||
|
||
end
|
||
|
||
--刷新每一条的显示数据
|
||
function this.SingleDataShow(btn, go, data, index)
|
||
local fightIcon = Util.GetGameObject(go, "fightIcon"):GetComponent("Image")
|
||
local reward = Util.GetGameObject(go, "fightIcon/reward")
|
||
local name = Util.GetGameObject(fightIcon.gameObject, "name"):GetComponent("Text")
|
||
local redPoint = Util.GetGameObject(go, "fightIcon/redPoint")
|
||
local rewardTip = Util.GetGameObject(go, "fightIcon/rewardTip"):GetComponent("Image")
|
||
|
||
local _rewardObj= SubUIManager.Open(SubUIConfig.ItemView, reward.transform)
|
||
-- local progressObj=Util.GetGameObject(go,"fightIcon/progress")
|
||
-- local progress=Util.GetGameObject(go,"fightIcon/progress/Image"):GetComponent("Image")
|
||
-- local progressVle=Util.GetGameObject(go,"fightIcon/progress/Text"):GetComponent("Text")
|
||
local tip = Util.GetGameObject(go,"fightIcon/tip")
|
||
local num = Util.GetGameObject(tip.gameObject,"num"):GetComponent("Text")
|
||
local tip2 = Util.GetGameObject(go,"fightIcon/tip/tip"):GetComponent("Text")
|
||
local zi = Util.GetGameObject(go,"fightIcon/zi"):GetComponent("Image")
|
||
-- local lock=Util.GetGameObject(go,"fightIcon/lock")
|
||
-- local btn=Util.GetGameObject(go,"btn")
|
||
Util.AddOnceClick(btn,function()
|
||
Log(string.format("点击了%s地图",data.mapName))
|
||
if not data.isUnLock then
|
||
PopupTipPanel.ShowTip(Language[12012])
|
||
else
|
||
XiaoYaoManager.OpenXiaoYaoMap(data.mapId)
|
||
end
|
||
end)
|
||
|
||
-- lock:SetActive(not data.isUnLock)
|
||
name.text= GetLanguageStrById(data.mapName)
|
||
SetTextVerTial(name.gameObject,Vector3.New(99,22,0),"MiddleLeft")
|
||
if data.isUnLock then
|
||
redPoint:SetActive(XiaoYaoManager.CheckRedPoint(data.mapId))
|
||
Util.SetGray(go,false)
|
||
tip2.text = ""
|
||
local prog=data.progress < 100 and data.progress or 0
|
||
-- 在起点时进度为1%,但前端显示为0%
|
||
if prog == 1 then
|
||
prog = 0
|
||
end
|
||
if GetCurLanguage() == 0 then
|
||
num.text =Language[12013].. string.format("\n<color=#E8C101>%u\n%%</color>",prog)
|
||
else
|
||
num.text =Language[12013].. string.format("<color=#E8C101>%u%%</color>",prog)
|
||
end
|
||
else
|
||
Util.SetGray(go,true)
|
||
if data.unlockLevel < 0 then
|
||
num.text = Language[12014]
|
||
tip2.text = ""
|
||
elseif PlayerManager.level < data.unlockLevel then
|
||
tip2.text = ""
|
||
if GetCurLanguage() == 0 then
|
||
num.text = Language[12015].."\n"..data.unlockLevel.."\n"..Language[12016]
|
||
else
|
||
num.text = Language[12015]..data.unlockLevel..Language[12016]
|
||
end
|
||
elseif data.mapId ~= firstMapId and not XiaoYaoManager.IsFirstPass(data.mapId - 1) then
|
||
tip2.text = ""
|
||
num.text = Language[12017]
|
||
else
|
||
tip2.text = ""
|
||
num.text = Language[12014]
|
||
end
|
||
end
|
||
SetTextVerTial(num.gameObject,Vector3.New(17.5,6.5,0),"MiddleLeft")
|
||
-- fightIcon.sprite=this.spLoader:LoadSprite(data.mapImage)
|
||
zi.sprite = this.spLoader:LoadSprite(data.ziImage)
|
||
-- local prog=data.progress < 100 and data.progress or 0
|
||
-- progressObj:SetActive(data.isUnLock)
|
||
-- progress.fillAmount=prog/100
|
||
-- progressVle.text=string.format("%u/100",prog)
|
||
if XiaoYaoManager.IsFirstPass(data.mapId) then
|
||
-- 不再显示数量
|
||
data.passReward[2] = 0
|
||
_rewardObj:OnOpen(false, data.passReward, 1)
|
||
rewardTip.sprite = this.spLoader:LoadSprite("x_xianyuan_gailvjiaobiao_zh")
|
||
else
|
||
_rewardObj:OnOpen(false, data.passReward, 1)
|
||
rewardTip.sprite = this.spLoader:LoadSprite("x_xianyuan_shoucijiaobiao_zh")
|
||
end
|
||
end
|
||
function this:OnSortingOrderChange(_cursortingOrder)
|
||
cursortingOrder = _cursortingOrder
|
||
end
|
||
-- 逍遥点是否显示倒计时
|
||
function this.ShowCountTime()
|
||
this.costIcon.sprite=this.spLoader:LoadSprite(GetResourcePath(itemConfig[UpViewRechargeType.YunYouVle].ResourceID))
|
||
local curValue=BagManager.GetItemCountById(UpViewRechargeType.YunYouVle)
|
||
local maxValue=PrivilegeManager.GetPrivilegeNumber(39)
|
||
--LogGreen("curValue:"..curValue.." maxValue:"..maxValue)
|
||
this.costInfo.text=string.format("%d/%d",curValue,maxValue)
|
||
-- this.bgTime:SetActive(curValue<maxValue)
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
end
|
||
this.timer = nil
|
||
this.actCountTime.text = ""
|
||
|
||
-- 启动倒计时
|
||
this.timer = Timer.New(function ()
|
||
local leftTime = AutoRecoverManager.GetRecoverTime(UpViewRechargeType.YunYouVle)
|
||
local curValue=BagManager.GetItemCountById(UpViewRechargeType.YunYouVle)
|
||
this.UpdateYunYouVleShow()
|
||
if curValue>=maxValue then
|
||
-- 回复满了,在地图外面可以停止计时器
|
||
this.actCountTime.text = ""
|
||
else
|
||
this.actCountTime.text = GetTimeMaoHaoStrBySeconds(math.floor(leftTime))
|
||
end
|
||
end, 1, -1, true)
|
||
this.timer:Start()
|
||
end
|
||
--刷新云游值显示栏信息
|
||
function this.UpdateYunYouVleShow()
|
||
this.costInfo.text=string.format("%d/%d",BagManager.GetItemCountById(UpViewRechargeType.YunYouVle),PrivilegeManager.GetPrivilegeNumber(39))
|
||
end
|
||
--界面关闭时调用(用于子类重写)
|
||
function this:OnClose()
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
end
|
||
this.timer = nil
|
||
end
|
||
|
||
--界面销毁时调用(用于子类重写)
|
||
function this:OnDestroy()
|
||
this.spLoader:Destroy()
|
||
|
||
end
|
||
return XiaoYaoYouPanel |