315 lines
12 KiB
Lua
315 lines
12 KiB
Lua
require("Base/BasePanel")
|
||
XiaoYaoMapPanel = Inherit(BasePanel)
|
||
local this = XiaoYaoMapPanel
|
||
local cursortingOrder
|
||
local mapData={}
|
||
local curGridIndex=1
|
||
local allGridData={}
|
||
local isAuto=false
|
||
local priThread = nil
|
||
|
||
--初始化组件(用于子类重写)
|
||
function this:InitComponent()
|
||
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
|
||
this.mapName=Util.GetGameObject(self.gameObject,"mapTitle/mapName"):GetComponent("Text")
|
||
this.mapProcess=Util.GetGameObject(self.gameObject,"mapTitle/mapProcess"):GetComponent("Text")
|
||
this.btnBack = Util.GetGameObject(self.gameObject, "btnBack")
|
||
this.shopBtn = Util.GetGameObject(self.gameObject, "btnGrid/shopBtn")
|
||
this.rouleBtn = Util.GetGameObject(self.gameObject, "btnGrid/rouleBtn")
|
||
this.bossBtn = Util.GetGameObject(self.gameObject, "btnGrid/bossBtn")
|
||
this.previewBtn=Util.GetGameObject(self.gameObject, "previewBtn")
|
||
this.autoBtn=Util.GetGameObject(self.gameObject, "auto")--自动游历按钮
|
||
this.toggle=Util.GetGameObject(self.gameObject, "auto/toggle")--自动游历开关显示
|
||
this.mapParent=Util.GetGameObject(self.gameObject,"mapParent")
|
||
this.gridParent=Util.GetGameObject(self.gameObject,"mapParent/gridParent")
|
||
this.grid=Util.GetGameObject(self.gameObject,"prefab/grid")
|
||
this.startBtn=Util.GetGameObject(self.gameObject,"startBtn")
|
||
this.TT=Util.GetGameObject(self.gameObject,"mapParent/TT")
|
||
this.mapY=this.mapParent.transform.localPosition.y
|
||
|
||
-- 逍遥点刷新倒计时显示
|
||
this.bgTime = Util.GetGameObject(self.gameObject, "costProp/Bgtime")
|
||
this.actCountTime = Util.GetGameObject(this.bgTime, "time"):GetComponent("Text")
|
||
|
||
this.youliTag = Util.GetGameObject(self.gameObject, "mapParent/TT/youli")
|
||
|
||
end
|
||
|
||
--绑定事件(用于子类重写)
|
||
function this:BindEvent()
|
||
Util.AddClick(this.btnBack, function ()
|
||
XiaoYaoManager.OpenMapList()
|
||
self:ClosePanel()
|
||
end)
|
||
--商店点击
|
||
Util.AddClick(this.shopBtn, function ()
|
||
|
||
end)
|
||
--转盘点击
|
||
Util.AddClick(this.rouleBtn, function ()
|
||
local grids={{index=3,gName="ccc"},{index=5,gName="eee"},{index=2,gName="bbb"},{index=4,gName="ddd"}}
|
||
table.sort(grids,function(a,b)
|
||
return a.index < b.index
|
||
end)
|
||
for i = 1, #grids do
|
||
Log(grids[i].gName)
|
||
end
|
||
end)
|
||
--boss点击事件
|
||
Util.AddClick(this.bossBtn, function ()
|
||
|
||
end)
|
||
--奖励预览
|
||
Util.AddClick(this.previewBtn, function ()
|
||
UIManager.OpenPanel(UIName.XiaoYaoRewardPreviewPanel)
|
||
end)
|
||
|
||
--自动游历点击
|
||
Util.AddClick(this.autoBtn, function ()
|
||
if isAuto then
|
||
this.StopAuto()
|
||
else
|
||
isAuto=true
|
||
this.toggle.gameObject:SetActive(true)
|
||
end
|
||
|
||
end)
|
||
--开始游历
|
||
Util.AddClick(this.startBtn,function()
|
||
if curGridIndex>=#allGridData then
|
||
MsgPanel.ShowTwo("已到达终点,是否重新云游!", nil, function()
|
||
XiaoYaoManager.OpenMapList()
|
||
end)
|
||
return
|
||
end
|
||
this.youliTag:SetActive(isAuto)
|
||
XiaoYaoManager.StartXiaoYao()
|
||
end)
|
||
|
||
--开始游历
|
||
Util.AddClick(this.succeedObj,function()
|
||
XiaoYaoManager.OpenMapList()
|
||
end)
|
||
end
|
||
|
||
--添加事件监听(用于子类重写)
|
||
function this:AddListener()
|
||
Game.GlobalEvent:AddEvent(GameEvent.XiaoYao.StartXiaoYao, this.RunMap)
|
||
end
|
||
|
||
--移除事件监听(用于子类重写)
|
||
function this:RemoveListener()
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.XiaoYao.StartXiaoYao, this.RunMap)
|
||
end
|
||
|
||
function this.RunMap(_data)
|
||
Log("开始跑图")
|
||
local targetIndex=0
|
||
for i = 1, #_data.pointes do
|
||
targetIndex=targetIndex+_data.pointes[i]
|
||
end
|
||
targetIndex=targetIndex+curGridIndex
|
||
Log("目标格子索引:"..targetIndex)
|
||
if targetIndex>#allGridData then
|
||
targetIndex=#allGridData
|
||
end
|
||
this.turnEffect:Reset(function()
|
||
curGridIndex=curGridIndex+1
|
||
this.TT.transform:DOAnchorPos(Vector3(allGridData[curGridIndex].x,allGridData[curGridIndex].y,0),0.3)
|
||
this.MapMove(allGridData[curGridIndex].x,0.3)
|
||
if curGridIndex==targetIndex then--如果停到对应位置
|
||
this.turnEffect:Stop()--暂停
|
||
this.mapProcess.text=string.format("%d%%",(curGridIndex/#allGridData*100))
|
||
if allGridData[curGridIndex].event~=nil then
|
||
this.EventTrigger(_data)
|
||
end
|
||
if curGridIndex>=#allGridData then
|
||
this.StopAuto()
|
||
UIManager.OpenPanel(UIName.XiaoYaoEventPanel,0)
|
||
end
|
||
if isAuto then
|
||
XiaoYaoManager.StartXiaoYao()
|
||
end
|
||
end
|
||
end,0.3,-1,true)
|
||
this.turnEffect:Start()
|
||
end
|
||
--取消自动游历
|
||
function this.StopAuto()
|
||
isAuto=false
|
||
this.youliTag:SetActive(false)
|
||
this.toggle.gameObject:SetActive(false)
|
||
end
|
||
--事件触发处理
|
||
function this.EventTrigger(_data)
|
||
if priThread then
|
||
coroutine.stop(priThread)
|
||
priThread = nil
|
||
end
|
||
Log("触发事件类型为:".._data.pathType)
|
||
if _data.pathType==0 then --普通节点
|
||
|
||
elseif _data.pathType==1 then --宝箱
|
||
PopupTipPanel.ShowTip("获得一个宝箱!")
|
||
elseif _data.pathType==2 then --双倍节点
|
||
PopupTipPanel.ShowTip("奖励翻倍!")
|
||
elseif _data.pathType==3 then --额外骰子节点
|
||
PopupTipPanel.ShowTip("骰子x2")
|
||
elseif _data.pathType==4 then --招募英雄节点
|
||
UIManager.OpenPanel(UIName.XiaoYaoEventPanel,_data.pathType)
|
||
priThread = coroutine.start(function()
|
||
coroutine.wait(1)
|
||
PopupTipPanel.ShowTip("触发了东海寻仙")
|
||
end)
|
||
this.shopBtn:SetActive(true)
|
||
elseif _data.pathType==5 then --怪物节点
|
||
UIManager.OpenPanel(UIName.XiaoYaoEventPanel,_data.pathType)
|
||
this.bossBtn:SetActive(true)
|
||
elseif _data.pathType==6 then --转盘
|
||
UIManager.OpenPanel(UIName.XiaoYaoEventPanel,_data.pathType)
|
||
this.rouleBtn:SetActive(true)
|
||
end
|
||
if _data.drop.itemlist ~= nil and #_data.drop.itemlist > 0 then
|
||
local content = {}
|
||
for i = 1, #_data.drop.itemlist do
|
||
local itemdata = {}
|
||
itemdata.configData = itemConfig[_data.drop.itemlist[i].itemId]
|
||
itemdata.name = itemdata.configData.Name
|
||
itemdata.icon = Util.LoadSprite(GetResourcePath(itemdata.configData.ResourceID))
|
||
itemdata.num = _data.drop.itemlist[i].itemNum
|
||
table.insert(content, itemdata)
|
||
end
|
||
PopupText(content, 0.5, 2)
|
||
end
|
||
end
|
||
--界面打开时调用(用于子类重写)
|
||
function this:OnOpen(_mapData)
|
||
mapData=_mapData
|
||
this.InitShowEvent()
|
||
--初始化地图
|
||
for i = 1, #mapData.cell do
|
||
local x, y=Map_Pos2UV(mapData.cell[i].cellId)
|
||
allGridData[i]={}
|
||
allGridData[i].x=x*128-64
|
||
allGridData[i].y=-y*128+64
|
||
if mapData.cell[i].pointId>0 then
|
||
allGridData[i].event = ConfigManager.GetConfigData(ConfigName.MapPointConfig,mapData.cell[i].pointId).Icon
|
||
end
|
||
end
|
||
Log("当前地图格子数量"..this.gridParent.transform.childCount)
|
||
if this.gridParent.transform.childCount<=0 then
|
||
for i = 1, #allGridData do
|
||
local obj= newObjToParent(this.grid, this.gridParent.transform)
|
||
if allGridData[i].event~=nil then
|
||
if not isEffect[allGridData[i].event] then
|
||
poolManager:LoadLive(MapFloatingConfig[allGridData[i].event].name, obj.transform,
|
||
MapFloatingConfig[allGridData[i].event].scale, MapFloatingConfig[allGridData[i].event].position)
|
||
else
|
||
self.effectLive=poolManager:LoadAsset(MapFloatingConfig[allGridData[i].event].name, PoolManager.AssetType.GameObject)
|
||
self.effectLive.transform:SetParent(obj.transform)
|
||
self.effectLive.transform.localScale = MapFloatingConfig[allGridData[i].event].scale
|
||
self.effectLive.transform.localPosition = MapFloatingConfig[allGridData[i].event].position
|
||
end
|
||
end
|
||
obj.transform:DOAnchorPos(Vector3(allGridData[i].x,allGridData[i].y,0),0)
|
||
end
|
||
end
|
||
curGridIndex=mapData.location
|
||
Log("当前位置索引:"..curGridIndex)
|
||
this.TT.transform:DOAnchorPos(Vector3(allGridData[curGridIndex].x,allGridData[curGridIndex].y,0),0)
|
||
this.TT.transform:SetAsLastSibling()
|
||
this.MapMove(allGridData[curGridIndex].x,0)
|
||
local mapConfig=ConfigManager.GetConfigDataByKey(ConfigName.FreeTravel,"MapID",XiaoYaoManager.curMapId)
|
||
this.mapName.text=mapConfig.FreeTravelName
|
||
this.mapProcess.text=string.format("%d%%",(curGridIndex/#allGridData*100))
|
||
local mapBg = mapConfig.MapImage
|
||
Log("当前地图id:"..XiaoYaoManager.curMapId)
|
||
--实例化地图背景
|
||
for i = 1, #mapBg do
|
||
Log(mapBg[i])
|
||
this.mapParent.transform:GetChild(i-1):GetComponent("Image").sprite=Util.LoadSprite(mapBg[i])
|
||
end
|
||
end
|
||
--初始化地图事件显示
|
||
function this.InitShowEvent()
|
||
if mapData.diceNum>1 then --骰子x2
|
||
-- body
|
||
end
|
||
if mapData.randomTime>0 and mapData.randomNum>0 then
|
||
this.rouleBtn:SetActive(true)
|
||
end
|
||
if mapData.monsterInfo then
|
||
this.bossBtn:SetActive(true)
|
||
end
|
||
if mapData.goodsInfo then
|
||
this.shopBtn:SetActive(true)
|
||
end
|
||
end
|
||
|
||
function this.MapMove(curX,moveTime)
|
||
if curX>2700 and this.mapParent:GetComponent("RectTransform").localPosition.x<=-2200 then
|
||
return
|
||
end
|
||
if curX>540 then
|
||
this.mapParent.transform:DOAnchorPos(Vector3(540-curX,this.mapY,0),moveTime)
|
||
else
|
||
this.mapParent.transform:DOAnchorPos(Vector3(0,this.mapY,0),moveTime)
|
||
end
|
||
end
|
||
|
||
-- 逍遥点是否显示倒计时
|
||
function this.ShowCountTime()
|
||
this.bgTime:SetActive(not EndLessMapManager.EnergyEnough())
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
end
|
||
this.timer = nil
|
||
this.actCountTime.text = ""
|
||
|
||
-- 初始化是判断一次
|
||
if not EndLessMapManager.EnergyEnough() then
|
||
-- 启动倒计时
|
||
this.timer = Timer.New(function ()
|
||
local leftTime = AutoRecoverManager.GetRecoverTime(1)
|
||
if EndLessMapManager.EnergyEnough()then
|
||
-- 回复满了,在地图外面可以停止计时器
|
||
this.timer:Stop()
|
||
this.bgTime:SetActive(false)
|
||
else
|
||
this.actCountTime.text = GetTimeMaoHaoStrBySeconds(math.floor(leftTime))
|
||
end
|
||
end, 1, -1, true)
|
||
this.timer:Start()
|
||
end
|
||
end
|
||
|
||
function this:OnShow()
|
||
--显示资源条
|
||
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.MonsterCamp })
|
||
this.ShowCountTime()
|
||
if not this.turnEffect then
|
||
this.turnEffect=Timer.New(nil,1,-1,true)
|
||
end
|
||
end
|
||
|
||
function this:OnSortingOrderChange(_cursortingOrder)
|
||
cursortingOrder = _cursortingOrder
|
||
end
|
||
|
||
--界面关闭时调用(用于子类重写)
|
||
function this:OnClose()
|
||
if this.turnEffect then
|
||
this.turnEffect:Stop()
|
||
this.turnEffect=nil
|
||
end
|
||
this.rouleBtn:SetActive(false)
|
||
this.bossBtn:SetActive(false)
|
||
this.shopBtn:SetActive(false)
|
||
this.StopAuto()
|
||
end
|
||
|
||
--界面销毁时调用(用于子类重写)
|
||
function this:OnDestroy()
|
||
|
||
end
|
||
return XiaoYaoMapPanel |