miduo_client/Assets/ManagedResources/~Lua/Modules/XiaoYao/XiaoYaoYouPanel.lua

195 lines
6.5 KiB
Lua
Raw Normal View History

require("Base/BasePanel")
XiaoYaoYouPanel = Inherit(BasePanel)
local this = XiaoYaoYouPanel
local cursortingOrder
2020-10-14 16:57:35 +08:00
local freeTravel = ConfigManager.GetConfig(ConfigName.FreeTravel)
2020-10-19 10:36:40 +08:00
local _MaxNum = 10
--初始化组件(用于子类重写)
function this:InitComponent()
this.btnBack = Util.GetGameObject(self.gameObject, "btnBack")
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
2020-10-19 10:36:40 +08:00
this.scroll = Util.GetGameObject(self.gameObject, "scroll")
2020-10-19 11:15:32 +08:00
this.content = Util.GetGameObject(self.gameObject, "scroll/Content")
2020-10-19 10:36:40 +08:00
this.btnList = {}
this.infoList = {}
for i = 1, _MaxNum do
this.btnList[i] = Util.GetGameObject(this.scroll, "Content/map/btn_"..i)
2020-10-19 11:15:32 +08:00
this.infoList[i] = Util.GetGameObject(this.scroll, "Content/Infos/info_"..i)
2020-10-19 10:36:40 +08:00
end
-- 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)
end
--添加事件监听(用于子类重写)
function this:AddListener()
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
end
--界面打开时调用(用于子类重写)
2020-10-14 16:57:35 +08:00
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={}
2020-10-14 16:57:35 +08:00
local _cruLevel = PlayerManager.level
Log("当前玩家等级:".._cruLevel)
for index, config in ConfigPairs(freeTravel) do
local _isUnLock = config.UnlockLevel >= 0 and _cruLevel >= config.UnlockLevel--判断章节是否开启
2020-10-14 16:57:35 +08:00
local showReward = ConfigManager.GetConfigData(ConfigName.RewardGroup,config.FinalReward).ShowItem
local _progress=0
2020-10-15 10:53:00 +08:00
Log("当前mapid"..config.MapID)
2020-10-14 16:57:35 +08:00
if data[config.MapID]~=nil then
_progress=data[config.MapID]
end
2020-10-19 11:15:32 +08:00
local _singleData={
mapId=config.MapID,
mapName=config.FreeTravelName,
mapImage=config.MapIcon,
ziImage=config.NameIcon,
2020-10-19 11:15:32 +08:00
isUnLock=_isUnLock,
progress=_progress,
passReward=showReward[1],
unlockLevel = config.UnlockLevel
}
2020-10-14 16:57:35 +08:00
_allData[index]=_singleData
end
2020-10-14 16:57:35 +08:00
Log("所有地图数量:"..#_allData)
2020-10-19 10:36:40 +08:00
for i = 1, _MaxNum do
this.SingleDataShow(this.btnList[i], this.infoList[i], _allData[i], i)
end
-- this.ScrollView:SetData(_allData, function (index, go)
-- this.SingleDataShow(go, _allData[index])
-- end)
2020-10-19 11:15:32 +08:00
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
this.content.transform.anchoredPosition3D = Vector3(pos.x, dheight, 0)
end
--刷新每一条的显示数据
2020-10-19 10:36:40 +08:00
function this.SingleDataShow(btn, go, data, index)
local fightIcon = Util.GetGameObject(go, "fightIcon"):GetComponent("Image")
local reward = Util.GetGameObject(go, "fightIcon/reward")
2020-10-19 10:36:40 +08:00
local name = Util.GetGameObject(go, "fightIcon/name"):GetComponent("Text")
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")
2020-10-19 11:15:32 +08:00
local tip = Util.GetGameObject(go,"fightIcon/tip"):GetComponent("Text")
local num = Util.GetGameObject(go,"fightIcon/tip/num"):GetComponent("Text")
local tip2 = Util.GetGameObject(go,"fightIcon/tip/tip"):GetComponent("Text")
2020-10-19 10:36:40 +08:00
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("地图尚未开启!")
else
2020-10-14 16:57:35 +08:00
XiaoYaoManager.OpenXiaoYaoMap(data.mapId)
end
end)
Log("isUnLock值"..tostring(data.isUnLock))
2020-10-19 10:36:40 +08:00
-- lock:SetActive(not data.isUnLock)
name.text=data.mapName
2020-10-19 11:15:32 +08:00
if data.isUnLock then
tip.text = "\n\n\n"
2020-10-19 11:15:32 +08:00
tip2.text = ""
local prog=data.progress < 100 and data.progress or 0
-- 在起点时进度为1%但前端显示为0%
if prog == 1 then
prog = 0
end
num.text = string.format("%u\n%%",prog)
2020-10-19 11:15:32 +08:00
else
if data.unlockLevel >= 0 then
tip.text = "\n\n\n"
tip2.text = "\n"
num.text = data.unlockLevel
else
tip.text = "\n\n\n"
tip2.text = ""
num.text = ""
end
2020-10-19 11:15:32 +08:00
end
2020-10-19 10:36:40 +08:00
-- fightIcon.sprite=Util.LoadSprite(data.mapImage)
zi.sprite = Util.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)
2020-10-15 16:30:51 +08:00
_rewardObj:OnOpen(false, data.passReward, 1)
end
function this:OnSortingOrderChange(_cursortingOrder)
cursortingOrder = _cursortingOrder
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
end
return XiaoYaoYouPanel