miduo_client/Assets/ManagedResources/~Lua/Modules/Explore/ExploreMainPanel.lua

224 lines
9.5 KiB
Lua
Raw Normal View History

2021-12-22 12:07:00 +08:00
require("Base/BasePanel")
ExploreMainPanel = Inherit(BasePanel)
--初始化组件(用于子类重写)
function ExploreMainPanel:InitComponent()
self.spLoader = SpriteLoader.New()
self.upView = SubUIManager.Open(SubUIConfig.UpView,self.gameObject.transform)
2021-12-27 14:53:55 +08:00
self.Bg = Util.GetGameObject(self.gameObject,"Map/Bg")
2021-12-22 12:07:00 +08:00
self.mapList = {}
self.mapPre = Util.GetGameObject(self.gameObject,"Map/mapPre")
self.mapParent = Util.GetGameObject(self.gameObject, "Map")
2021-12-23 17:23:02 +08:00
self.backBtn = Util.GetGameObject(self.gameObject, "btns/backBtn")
self.oneKeyExploreBtn = Util.GetGameObject(self.gameObject, "btns/oneKeyExploreBtn")
self.formationBtn = Util.GetGameObject(self.gameObject, "btns/formationBtn")
self.tip = Util.GetGameObject(self.gameObject, "btns/tip")
2021-12-24 00:14:32 +08:00
self.tipPos = self.tip.transform.localPosition
self.tipRoot = Util.GetGameObject(self.gameObject, "btns")
2021-12-22 12:07:00 +08:00
self.xiangqingBtn = Util.GetGameObject(self.tip, "xiangqingBtn")
self.jinruBtn = Util.GetGameObject(self.tip, "jinruBtn")
self.tansuoBtn = Util.GetGameObject(self.tip, "tansuoBtn")
self.mapId = 0
2021-12-27 15:42:52 +08:00
self.ctrl = Util.GetGameObject(self.gameObject, "ctr")
2021-12-27 14:53:55 +08:00
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, -637, 637))
if (v2.x + av2.x < 210 and v2.x + av2.x > -210) or (v2.y + av2.y < 637 and v2.y + av2.y > -637) 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, -637, 637))
if v2.y + av2.y < 637 and v2.y + av2.y > -637 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
2021-12-22 12:07:00 +08:00
end
--绑定事件(用于子类重写)
function ExploreMainPanel:BindEvent()
Util.AddClick(self.backBtn,function()
self:ClosePanel()
end)
Util.AddClick(self.oneKeyExploreBtn,function()
--一键探索弹窗
2021-12-23 13:09:34 +08:00
UIManager.OpenPanel(UIName.GeneralSizeFitterPopup,GENERALSIZEFITTER_TYPE.OneKeyExplore,ExploreManager.GetFormationData(0),ExploreManager.GetMapsData())
2021-12-22 12:07:00 +08:00
end)
Util.AddClick(self.formationBtn,function()
--探索队伍弹窗
2021-12-23 13:09:34 +08:00
--0 调整 1探索
UIManager.OpenPanel(UIName.GeneralSizeFitterPopup,GENERALSIZEFITTER_TYPE.ExploreSelectFormation,ExploreManager.GetFormationData(1),0,ExploreManager.ExploreMapData[self.mapId])
2021-12-22 12:07:00 +08:00
end)
Util.AddClick(self.xiangqingBtn,function()
--地图详情tips
UIManager.OpenPanel(UIName.GeneralInfoPopup,GENERALINFO_TYPE.ExploreMapTip,ExploreManager.GetExploreMapTipData(self.mapId))
end)
Util.AddClick(self.jinruBtn,function()
2021-12-24 17:49:54 +08:00
if LengthOfTable(self.data[self.mapId].formations) > 0 then
UIManager.OpenPanel(UIName.ExplorePanel,ExploreManager.ExploreMapData[self.mapId])
else
PopupTipPanel.ShowTip("目标区域无探索队伍,无法进入!")
end
2021-12-22 12:07:00 +08:00
end)
Util.AddClick(self.tansuoBtn,function()
--选择队伍弹窗
2021-12-23 13:09:34 +08:00
UIManager.OpenPanel(UIName.GeneralSizeFitterPopup,GENERALSIZEFITTER_TYPE.ExploreSelectFormation,ExploreManager.GetFormationData(0),1,ExploreManager.ExploreMapData[self.mapId])
2021-12-22 12:07:00 +08:00
end)
end
--添加事件监听(用于子类重写)
function ExploreMainPanel:AddListener()
2021-12-24 17:49:54 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Explore.UpdateFormation,self.OnShow,self)
2021-12-22 12:07:00 +08:00
end
--移除事件监听(用于子类重写)
function ExploreMainPanel:RemoveListener()
2021-12-24 17:49:54 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.Explore.UpdateFormation,self.OnShow,self)
2021-12-22 12:07:00 +08:00
end
--界面打开时调用(用于子类重写)
function ExploreMainPanel:OnOpen()
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function ExploreMainPanel:OnShow()
2021-12-24 00:14:32 +08:00
self.mapId = 0
2021-12-23 17:23:02 +08:00
ForceRebuildLayout(self.Bg.transform)
2021-12-22 12:07:00 +08:00
self.data = ExploreManager.ExploreMapData
self.tip.gameObject:SetActive(false)
2021-12-23 17:23:02 +08:00
self.upView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main })
2021-12-22 12:07:00 +08:00
self:SetMapData()
self:SetMapState()
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].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")
2021-12-24 00:14:32 +08:00
self.mapList[k].minForce = Util.GetGameObject(self.mapList[k].mapInfo,"minForce")
self.mapList[k].force = Util.GetGameObject(self.mapList[k].mapInfo,"minForce/Text")
2021-12-23 17:23:02 +08:00
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/exploreIma")
2021-12-22 12:07:00 +08:00
self.mapList[k].condition = Util.GetGameObject(self.mapList[k].mapInfo,"condition")
self.mapList[k].conditionTip = Util.GetGameObject(self.mapList[k].condition,"Text"):GetComponent("Text")
2021-12-24 00:14:32 +08:00
self.mapList[k].tipPos = Util.GetGameObject(self.mapList[k].go,"tipPos")
2021-12-22 12:07:00 +08:00
end
2021-12-23 17:23:02 +08:00
self.mapList[k].data = v
self.mapList[k].go.gameObject:SetActive(true)
self.mapList[k].go.transform.localPosition = v.pos
2021-12-24 17:49:54 +08:00
self.mapList[k].mapBg.gameObject:SetActive(false)
2021-12-22 12:07:00 +08:00
self.mapList[k].mapBgIma.sprite = self.spLoader:LoadSprite(v.iconName)
2021-12-23 17:23:02 +08:00
self.mapList[k].mapBgIma:SetNativeSize()
2021-12-24 00:14:32 +08:00
SetNumShow(self.mapList[k].minForce,self.mapList[k].force.gameObject,v.force)
2021-12-22 12:07:00 +08:00
if PlayerManager.level < v.openLevel then
2021-12-23 17:23:02 +08:00
self.mapList[k].condition.gameObject:SetActive(true)
self.mapList[k].conditionTip.text = v.openLevel.."级解锁"
Util.SetGray(self.mapList[k].bgName,true)
2021-12-22 12:07:00 +08:00
else
2021-12-23 17:23:02 +08:00
self.mapList[k].condition.gameObject:SetActive(false)
Util.SetGray(self.mapList[k].bgName,false)
2021-12-22 12:07:00 +08:00
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
2021-12-24 00:14:32 +08:00
self:SetTip(self.mapList[k].tipPos,k)
2021-12-22 12:07:00 +08:00
end
end)
end
end
function ExploreMainPanel:SetMapState()
2021-12-23 17:23:02 +08:00
for k,v in pairs(self.mapList) do
v.exploreIma.gameObject:SetActive(LengthOfTable(v.data.formations) > 0)
end
2021-12-22 12:07:00 +08:00
end
2021-12-24 00:14:32 +08:00
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
2021-12-22 12:07:00 +08:00
end
--界面关闭时调用(用于子类重写)
function ExploreMainPanel:OnClose()
2021-12-24 00:14:32 +08:00
self:SetTip(self.tipRoot,self.mapId)
2021-12-22 12:07:00 +08:00
end
--界面销毁时调用(用于子类重写)
function ExploreMainPanel:OnDestroy()
self.mapList = {}
2021-12-23 13:09:34 +08:00
SubUIManager.Close(self.upView)
self.upView = nil
self.spLoader:Destroy()
2021-12-22 12:07:00 +08:00
end
return ExploreMainPanel