307 lines
13 KiB
Lua
307 lines
13 KiB
Lua
require("Base/BasePanel")
|
|
ExploreMainPanel = Inherit(BasePanel)
|
|
local pointnum = 2
|
|
--初始化组件(用于子类重写)
|
|
function ExploreMainPanel:InitComponent()
|
|
self.spLoader = SpriteLoader.New()
|
|
self.upView = SubUIManager.Open(SubUIConfig.UpView,self.gameObject.transform)
|
|
self.Bg = Util.GetGameObject(self.gameObject,"Map/Bg")
|
|
self.mapList = {}
|
|
self.mapPre = Util.GetGameObject(self.gameObject,"Map/mapPre")
|
|
self.mapParent = Util.GetGameObject(self.gameObject, "Map")
|
|
self.backBtn = Util.GetGameObject(self.gameObject, "btns/backBtn")
|
|
self.oneKeyExploreBtn = Util.GetGameObject(self.gameObject, "btns/oneKeyExploreBtn")
|
|
self.oneKeyExploreBtnRed = Util.GetGameObject(self.oneKeyExploreBtn, "red")
|
|
self.formationBtn = Util.GetGameObject(self.gameObject, "btns/formationBtn")
|
|
self.tip = Util.GetGameObject(self.gameObject, "btns/tip")
|
|
self.tipPos = self.tip.transform.localPosition
|
|
self.tipRoot = Util.GetGameObject(self.gameObject, "btns")
|
|
self.xiangqingBtn = Util.GetGameObject(self.tip, "xiangqingBtn")
|
|
self.jinruBtn = Util.GetGameObject(self.tip, "jinruBtn")
|
|
self.tansuoBtn = Util.GetGameObject(self.tip, "tansuoBtn")
|
|
self.mapId = 0
|
|
self.ctrl = Util.GetGameObject(self.gameObject, "ctr")
|
|
self.bg = Util.GetGameObject(self.gameObject, "Map")
|
|
self.trigger = Util.GetEventTriggerListener(self.ctrl)
|
|
self.bgTran = self.bg:GetComponent("RectTransform")
|
|
self.moveTween = self.bg:GetComponent(typeof(UITweenSpring))
|
|
if not self.moveTween then
|
|
self.moveTween = self.bg:AddComponent(typeof(UITweenSpring))
|
|
end
|
|
self.moveTween.enabled = false
|
|
local lastx = 0
|
|
local lasty = 0
|
|
|
|
local setPosFunc = function(v2)
|
|
local av2 = self.bgTran.anchoredPosition
|
|
local dv2
|
|
if v2.x ~= lastx and v2.y ~= lasty then
|
|
lastx = v2.x
|
|
dv2 = Vector2.New(math.clamp(v2.x + av2.x, -210, 210), math.clamp(v2.y + av2.y, -468, 468))
|
|
if (v2.x + av2.x < 210 and v2.x + av2.x > -210) or (v2.y + av2.y < 468 and v2.y + av2.y > -468) then
|
|
self.moveTween:Rebound(3, 0.1)
|
|
end
|
|
elseif v2.y ~= lasty then
|
|
lasty = v2.y
|
|
dv2 = Vector2.New(av2.x,math.clamp(v2.y + av2.y, -468, 468))
|
|
if v2.y + av2.y < 468 and v2.y + av2.y > -468 then
|
|
self.moveTween:Rebound(2, 0.1)
|
|
end
|
|
elseif v2.y ~= lasty then
|
|
lastx = v2.x
|
|
dv2 = Vector2.New(math.clamp(v2.x + av2.x, -210, 210), av2.y)
|
|
if v2.x + av2.x < 210 and v2.x + av2.x > -210 then
|
|
self.moveTween:Rebound(1, 0.1)
|
|
end
|
|
end
|
|
if dv2 then
|
|
self.bgTran.anchoredPosition = dv2
|
|
end
|
|
end
|
|
|
|
self.moveTween.OnUpdate = setPosFunc
|
|
self.moveTween.MomentumAmount = 1
|
|
self.moveTween.Strength = 1
|
|
|
|
self.trigger.onBeginDrag = self.trigger.onBeginDrag + function(p, d)
|
|
self.moveTween.enabled = true
|
|
lastx = 0
|
|
lasty = 0
|
|
self.moveTween.Momentum = Vector3.zero
|
|
self.moveTween.IsUseCallBack = false
|
|
end
|
|
self.trigger.onDrag = self.trigger.onDrag + function(p, d)
|
|
self.moveTween:LerpMomentum(d.delta)
|
|
setPosFunc(d.delta)
|
|
end
|
|
self.trigger.onEndDrag = self.trigger.onEndDrag + function(p, d)
|
|
self.moveTween.IsUseCallBack = true
|
|
lastx = 0
|
|
lasty = 0
|
|
setPosFunc(d.delta)
|
|
end
|
|
self.trigger.onPointerUp = self.trigger.onPointerUp + function()
|
|
self:SetTip(self.tipRoot,self.mapId)
|
|
end
|
|
|
|
self.helpBtn = Util.GetGameObject(self.gameObject, "btns/helpBtn")
|
|
self.helpPosition=self.helpBtn:GetComponent("RectTransform").localPosition
|
|
self.rankBtn = Util.GetGameObject(self.gameObject, "btns/rankBtn")
|
|
self.rankBtn:SetActive(false)
|
|
self.taskBtn = Util.GetGameObject(self.gameObject, "btns/taskBtn")
|
|
self.taskBtn:SetActive(false)
|
|
self.shopBtn = Util.GetGameObject(self.gameObject, "btns/shopBtn")
|
|
self.shopBtn:SetActive(false)
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function ExploreMainPanel:BindEvent()
|
|
Util.AddClick(self.helpBtn,function()
|
|
UIManager.OpenPanel(UIName.HelpPopup,125,self.helpPosition.x,self.helpPosition.y)
|
|
end)
|
|
Util.AddClick(self.backBtn,function()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(self.oneKeyExploreBtn,function()
|
|
--一键探索弹窗
|
|
UIManager.OpenPanel(UIName.GeneralSizeFitterPopup,GENERALSIZEFITTER_TYPE.OneKeyExplore,ExploreManager.GetFormationData(0),ExploreManager.GetMapsData())
|
|
end)
|
|
Util.AddClick(self.formationBtn,function()
|
|
--探索队伍弹窗
|
|
--0 调整 1探索
|
|
UIManager.OpenPanel(UIName.GeneralSizeFitterPopup,GENERALSIZEFITTER_TYPE.ExploreSelectFormation,ExploreManager.GetFormationData(1),0,ExploreManager.ExploreMapData[self.mapId])
|
|
end)
|
|
Util.AddClick(self.xiangqingBtn,function()
|
|
--地图详情tips
|
|
UIManager.OpenPanel(UIName.GeneralInfoPopup,GENERALINFO_TYPE.ExploreMapTip,ExploreManager.GetExploreMapTipData(self.mapId))
|
|
end)
|
|
Util.AddClick(self.jinruBtn,function()
|
|
if LengthOfTable(self.data[self.mapId].formations) > 0 then
|
|
SwitchPanel.OpenPanel(UIName.ExplorePanel,function() end,ExploreManager.ExploreMapData[self.mapId])
|
|
else
|
|
PopupTipPanel.ShowTip("目标区域无探索队伍,无法进入!")
|
|
end
|
|
end)
|
|
Util.AddClick(self.tansuoBtn,function()
|
|
--选择队伍弹窗
|
|
UIManager.OpenPanel(UIName.GeneralSizeFitterPopup,GENERALSIZEFITTER_TYPE.ExploreSelectFormation,ExploreManager.GetFormationData(0),1,ExploreManager.ExploreMapData[self.mapId])
|
|
end)
|
|
Util.AddClick(self.rankBtn,function()
|
|
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[37])
|
|
end)
|
|
Util.AddClick(self.taskBtn,function()
|
|
MonsterCampManager.preType = 2
|
|
UIManager.OpenPanel(UIName.TrialRewardPopup,ExploreManager.SetRewardData(),function(id,rewardFunc)
|
|
NetManager.TakeMissionRewardRequest(TaskTypeDef.ExploreTask,id,function (msg)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function()
|
|
if rewardFunc then
|
|
rewardFunc()
|
|
end
|
|
end)
|
|
end)
|
|
end,1)
|
|
end)
|
|
Util.AddClick(self.shopBtn,function()
|
|
JumpManager.GoJump(40065)
|
|
end)
|
|
BindRedPointObject(RedPointType.ExploreFunc,self.oneKeyExploreBtnRed)
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function ExploreMainPanel:AddListener()
|
|
Game.GlobalEvent:AddEvent(GameEvent.Explore.UpdateFormation,self.OnShow,self)
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function ExploreMainPanel:RemoveListener()
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Explore.UpdateFormation,self.OnShow,self)
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function ExploreMainPanel:OnOpen()
|
|
|
|
end
|
|
|
|
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
|
function ExploreMainPanel:OnShow()
|
|
self.mapId = 0
|
|
ForceRebuildLayout(self.Bg.transform)
|
|
self.data = ExploreManager.ExploreMapData
|
|
self.tip.gameObject:SetActive(false)
|
|
self.upView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.ExploreFun })
|
|
self:SetMapData()
|
|
self:SetMapState()
|
|
self.mapParent.transform:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(168,468,0)
|
|
end
|
|
|
|
function ExploreMainPanel:SetMapData()
|
|
for k,v in pairs(self.mapList) do
|
|
v.go.gameObject:SetActive(false)
|
|
end
|
|
for k,v in pairs(self.data) do
|
|
if not self.mapList[k] then
|
|
self.mapList[k] = {}
|
|
self.mapList[k].go = newObjToParent(self.mapPre,self.mapParent)
|
|
self.mapList[k].go.name = "mapPre"..k
|
|
self.mapList[k].mapBg = Util.GetGameObject(self.mapList[k].go,"mapBg")
|
|
self.mapList[k].mapBgIma = Util.GetGameObject(self.mapList[k].mapBg,"ImgBg"):GetComponent("Image")
|
|
self.mapList[k].mapInfo = Util.GetGameObject(self.mapList[k].go,"mapInfo")
|
|
self.mapList[k].minForce = Util.GetGameObject(self.mapList[k].mapInfo,"minForce")
|
|
self.mapList[k].force = Util.GetGameObject(self.mapList[k].mapInfo,"minForce/Text")
|
|
self.mapList[k].bgName = Util.GetGameObject(self.mapList[k].mapInfo,"info/bgName")
|
|
self.mapList[k].lock = Util.GetGameObject(self.mapList[k].mapInfo,"info/bgName/Lock")
|
|
self.mapList[k].lock.gameObject:SetActive(false)
|
|
self.mapList[k].canGetImg = Util.GetGameObject(self.mapList[k].mapInfo,"info/bgName/canGetImg"):GetComponent("Image")
|
|
self.mapList[k].canGetImg.gameObject:SetActive(true)
|
|
self.mapList[k].nameMask = Util.GetGameObject(self.mapList[k].mapInfo,"info/nameMask"):GetComponent("Text")
|
|
self.mapList[k].name = Util.GetGameObject(self.mapList[k].mapInfo,"info/nameMask/name"):GetComponent("Text")
|
|
self.mapList[k].exploreIma = Util.GetGameObject(self.mapList[k].mapInfo,"info/explore")
|
|
self.mapList[k].exploreList = {}
|
|
for i = 1,pointnum do
|
|
self.mapList[k].exploreList[i] = Util.GetGameObject(self.mapList[k].exploreIma,"ima"..i)
|
|
end
|
|
|
|
self.mapList[k].condition = Util.GetGameObject(self.mapList[k].mapInfo,"info/bgName/condition")
|
|
self.mapList[k].conditionTip = Util.GetGameObject(self.mapList[k].condition,"Text"):GetComponent("Text")
|
|
self.mapList[k].tipPos = Util.GetGameObject(self.mapList[k].go,"tipPos")
|
|
end
|
|
self.mapList[k].data = v
|
|
self.mapList[k].go.gameObject:SetActive(true)
|
|
self.mapList[k].go.transform.localPosition = v.pos
|
|
self.mapList[k].mapBg.gameObject:SetActive(false)
|
|
self.mapList[k].mapBgIma.sprite = self.spLoader:LoadSprite(v.iconName)
|
|
self.mapList[k].mapBgIma:SetNativeSize()
|
|
local numStr = ""
|
|
if v.force >= 1000000 then
|
|
numStr = tostring(math.floor(v.force / 10000))
|
|
else
|
|
numStr = tostring(v.force)
|
|
end
|
|
SetNumShow(self.mapList[k].minForce,self.mapList[k].force.gameObject,numStr,v.force >= 1000000)
|
|
if PlayerManager.level < v.openLevel then
|
|
self.mapList[k].condition.gameObject:SetActive(true)
|
|
if v.openLevel ~= 999 then
|
|
self.mapList[k].conditionTip.text = v.openLevel.."级解锁"
|
|
else
|
|
self.mapList[k].conditionTip.text = "地图暂未开放"
|
|
end
|
|
self.mapList[k].minForce.gameObject:SetActive(false)
|
|
Util.SetGray(self.mapList[k].bgName,true)
|
|
else
|
|
self.mapList[k].minForce.gameObject:SetActive(true)
|
|
self.mapList[k].condition.gameObject:SetActive(false)
|
|
Util.SetGray(self.mapList[k].bgName,false)
|
|
end
|
|
self.mapList[k].canGetImg.sprite = self.spLoader:LoadSprite(GetSpriteNameByItemId(v.mainRewardId))
|
|
self.mapList[k].nameMask.text = v.name
|
|
self.mapList[k].name.text = v.name
|
|
Util.AddOnceClick(self.mapList[k].go,function()
|
|
if PlayerManager.level >= v.openLevel then
|
|
self:SetTip(self.mapList[k].tipPos,k)
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
function ExploreMainPanel:SetMapState()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
local s = function()
|
|
for k,v in pairs(self.mapList) do
|
|
if LengthOfTable(v.data.formations) > 0 then
|
|
v.exploreIma.gameObject:SetActive(true)
|
|
local index = 0
|
|
for i = 1,#self.mapList[k].exploreList do
|
|
self.mapList[k].exploreList[i].gameObject:SetActive(false)
|
|
end
|
|
Timer.New(function()
|
|
if self.mapList[k].exploreList[index] then
|
|
self.mapList[k].exploreList[index].gameObject:SetActive(false)
|
|
end
|
|
index = (index + 1)%pointnum == 0 and pointnum or (index + 1)%pointnum
|
|
self.mapList[k].exploreList[index].gameObject:SetActive(true)
|
|
end,0.25,2):Start()
|
|
else
|
|
v.exploreIma.gameObject:SetActive(false)
|
|
end
|
|
end
|
|
end
|
|
s()
|
|
self.timer = Timer.New(s,1,-1,false)
|
|
self.timer:Start()
|
|
end
|
|
|
|
function ExploreMainPanel:SetTip(root,k)
|
|
if self.mapId == k then
|
|
self.tip.gameObject:SetActive(false)
|
|
self.mapId = 0
|
|
else
|
|
self.mapId = k
|
|
self.tip.transform:SetParent(root.transform)
|
|
self.tip.gameObject:SetActive(true)
|
|
self.tip.transform.localPosition = Vector3.New(0,0,0)
|
|
self.tip.transform.localScale = Vector3.one
|
|
end
|
|
end
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function ExploreMainPanel:OnClose()
|
|
self:SetTip(self.tipRoot,self.mapId)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function ExploreMainPanel:OnDestroy()
|
|
self.mapList = {}
|
|
SubUIManager.Close(self.upView)
|
|
self.upView = nil
|
|
self.spLoader:Destroy()
|
|
ClearRedPointObject(RedPointType.ExploreFunc,self.oneKeyExploreBtnRed)
|
|
end
|
|
|
|
return ExploreMainPanel |