miduo_client/Assets/ManagedResources/~Lua/Modules/XunBaoMiZong/XunBaoMiZongMapPanel.lua

309 lines
12 KiB
Lua

require("Base/BasePanel")
require("Base/Stack")
require("Modules/Map/Logic/TileMapController")
require("Modules/Map/Logic/TileMapView")
local XunBaoMiZongMap = Inherit(BasePanel)
local this = XunBaoMiZongMap
local mainLevelSettingConfig = ConfigManager.GetConfig(ConfigName.MainLevelSettingConfig)
local func = nil
local mapCtrl = "MapCtrl"
local cantWalk = false
local inside = false
-- 缩放值
local offsetScale = math.min(Screen.width/3241, Screen.height/1920)
--初始化组件(用于子类重写)
function XunBaoMiZongMap:InitComponent()
self.spLoader = SpriteLoader.New()
self.btnBack = Util.GetGameObject(self.gameObject, "mapParent/btnBack")
self.dragCtrl = Util.GetGameObject(self.gameObject, "mapParent/Ctrl")
self.roleRoot = Util.GetGameObject(self.gameObject, "mapParent/selectMap/Image (1)/roleRoot")
self.btnGet = Util.GetGameObject(self.gameObject, "mapParent/btnGet"):GetComponent("Image")
self.effect = Util.GetGameObject(self.gameObject, "mapParent/UI_Effect_YJBK_Zao")
self.effect:SetActive(false)
self.effectLuoDi = Util.GetGameObject(self.gameObject, "mapParent/fx_xunbaomizong_renwuluodi")
self.effectLuoDi:SetActive(false)
self.effectDaoda = Util.GetGameObject(self.gameObject, "mapParent/fx_xunbaomizong_daoda")
self.effectDaoda:SetActive(false)
self.effectBtnGet = Util.GetGameObject(self.btnGet.gameObject, "fx_xunbaomizong_xunbaochangzhu")
self.effectBtnGet:SetActive(false)
end
--绑定事件(用于子类重写)
function XunBaoMiZongMap:BindEvent()
Util.AddClick(self.btnBack, function()
SwitchPanel.OpenPanel(nil,function ()
self:ClosePanel()
end)
end)
Util.AddClick(self.btnGet.gameObject, function()
local distance = math.distanceXY(self.rewardPos,self.oldPos)
local banjing = ConfigManager.GetConfigData(ConfigName.SpecialConfig,125).Value
if distance <= tonumber(banjing) then
local Id = ConfigManager.GetConfigDataByKey(ConfigName.LotterySetting,"ActivityId",self.actData.activityId).Id
NetManager.RecruitRequest(Id,function (msg)
--镐子特效放置到最终位置
self.effect.transform:SetParent(Util.GetTransform(self.mapRoot, "uiObj#"))
self.effect:GetComponent("RectTransform").localScale = Vector2.one * 1.5
self.effect:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(self.rewardPos.x, self.rewardPos.y, 10)
self.effect:SetActive(true)
self.btnGet.gameObject:GetComponent("Button").interactable = false
self.btnBack.gameObject:GetComponent("Button").interactable = false
cantWalk = true
SoundManager.PlaySound("UI_021")
Timer.New(function ()
self.effect:SetActive(false)
self.effectBtnGet:SetActive(false)
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function()
SwitchPanel.OpenPanel(nil,function ()
self:ClosePanel()
end)
end)
end,1.5):Start()
Timer.New(function ()
SoundManager.PlaySound("Audio_linglongbaojing_neiquanlunge_007")
end,0.4,2):Start()
end)
else
PopupTipPanel.ShowTip("请根据箭头找到宝藏!")
end
end)
end
function XunBaoMiZongMap:OnSortingOrderChange()
end
--界面打开时调用(用于子类重写)
function XunBaoMiZongMap:OnOpen(_data,_func)
self.actData = _data
func = _func
-- SoundManager.PlaySound(SoundConfig.Sound_WorldMap)
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function XunBaoMiZongMap:OnShow()
SoundManager.PlayMusic("BGM_026")
if self.liveNode then
self.liveNode:OnClose()
end
cantWalk = true
self.btnGet.gameObject:GetComponent("Button").interactable = true
self.btnBack.gameObject:GetComponent("Button").interactable = true
self.btnGet.sprite = self.spLoader:LoadSprite("x_xbmz_xunbaoanniu01")
self.effectBtnGet:SetActive(false)
self.liveNode = PlayerLiveView:New(self.roleRoot,1,nil,nil,nil,true)
self.liveNode:OnOpen(300,Vector3.zero,WALK_DIR.IDLE_FRONT)
self.liveNode:SetTitleHide()
self:LoadMapData()
Timer.New(function ()
cantWalk = false
end,2):Start()
end
function XunBaoMiZongMap:LoadMapData()
UIManager.camera.clearFlags = CameraClearFlags.Depth
-- 所有物体的根节点
self.mapRoot = poolManager:LoadAsset(mapCtrl, PoolManager.AssetType.GameObject)
self.mapRoot.name = mapCtrl
self.mapRoot.transform:SetParent(UIManager.uiRoot.transform.parent)
self.mapRoot.transform.position = Vector3.New(0, 0, -100)
TileMapView.fogSize = 2
TileMapView.AwakeInit(self.mapRoot, 5001)
TileMapView.isShowFog = false
TileMapController.IsShieldDrag = function()
--当栈中有逻辑,则拖动可以打断镜头跟随
return false
end
TileMapController.OnClickTile = this.OnClickTile
TileMapController.Init(self.mapRoot, self.dragCtrl)
TileMapView.Init()
-- 设置相机初始化位置
TileMapView.SetCameraPos(Vector3.New(25, -26, 0))-- -20.77
-- 设置镜头的尺寸
TileMapController.SetScale(TileMapView.GetMapScale() * offsetScale)
self._BuildFlag = {}
self._BuildFlagClick = {}
for buildType, config in ConfigPairs(ConfigManager.GetConfig(ConfigName.MainLevelSettingConfig)) do
if mainLevelSettingConfig[buildType] == nil then return end
local go = poolManager:LoadAsset("FightMiddleFlag", PoolManager.AssetType.GameObject)
go.transform:SetParent(Util.GetTransform(self.mapRoot, "uiObj#"))
go.name = "FightMiddleFlag"..buildType
go:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(config.ChapterTitlePosition[1], config.ChapterTitlePosition[2]-254, 1)
Util.GetTransform(go, "click"):GetComponent("RectTransform").anchoredPosition3D = Vector3.New(config.ChapterClickPosition[1], config.ChapterClickPosition[2], 0)
go.transform.localScale = Vector3.one
self._BuildFlag[buildType] = go
self._BuildFlagClick[buildType] = Util.GetTransform(go, "click").gameObject
Util.GetGameObject(go, "name"):GetComponent("Text").text = GetLanguageStrById(mainLevelSettingConfig[buildType].Name)
SetTextVerTial(Util.GetGameObject(go, "name"):GetComponent("Text"),Vector3.New(40.02,9.55,0))
local passImage = Util.GetGameObject(go, "passImage"):SetActive(false)--关闭”通“字
end
--设置初始位置
self.oldPos = Vector3.New(2501,-2607,10)--设置初始位置
--最终奖励点信息
self.curRewardPointData = ConfigManager.GetConfigData(ConfigName.MainLevelSettingConfig,math.random(1,15))
self.rewardPos = Vector2.New(self.curRewardPointData.ChapterCenterPosition[1],self.curRewardPointData.ChapterCenterPosition[2])
Log("当前奖励点名字:"..tostring(self.curRewardPointData.Name))
local thread = coroutine.start(function()
coroutine.wait(1)
SoundManager.PlaySound("UI_Battle_04")
self.effectLuoDi.transform:SetParent(Util.GetTransform(self.mapRoot, "uiObj#"))
self.effectLuoDi:SetActive(true)
coroutine.wait(0.5)
----设置人物初始位置
self:SelectRenPos(Util.GetTransform(self.mapRoot, "uiObj#"),self.oldPos)
end)
self.liveNode:SetSelfDirectingTag(true,self.oldPos,self.rewardPos)
end
function XunBaoMiZongMap:SelectRenPos(_parent,ChapterRolePosition)
if this.liveNode and this.liveNode.leader then
this.liveNode.leader:SetActive(true)
this.liveNode.leader.transform:SetParent(_parent.transform)
this.liveNode.leader:GetComponent("RectTransform").anchoredPosition3D = ChapterRolePosition
end
end
-- 单击
function this.OnClickTile(u, v,fuv)
if cantWalk then return end
local data = ConfigManager.GetConfigData(ConfigName.SpecialConfig,124).Value
local listss = string.split(data,"|")
local pointList = {}
for i = 1, #listss do
pointList[i] = {}
local vector = string.split(listss[i],"#")
pointList[i].x = tonumber(vector[1])
pointList[i].y = tonumber(vector[2])
end
local targetPos = TileMapView.GetLiveTilePos(fuv.x, -fuv.y) * 100
-- Log(string.format("点击位置坐标(%s, %s)", u, v))
-- Log(tostring(targetPos))
if this.CheckArena(pointList,targetPos) then
this:SetRoleWalk(targetPos,fuv)
end
end
function this.CheckArena(list,point)
local bool = false
for i = 1, #list do
local point1 = list[i]
local point2 = list[i + 1] or list[1]
if (point1.y > point.y and point2.y < point.y) or (point1.y < point.y and point2.y > point.y) then
if point.x < (point2.x - point1.x)*(point.y - point1.y)/(point2.y - point1.y) + point1.x then
bool = not bool
end
end
end
return bool
end
--角色行走
function XunBaoMiZongMap:SetRoleWalk(_targetPos,_fuv)
local targetPos = Vector3.New(_targetPos.x,_targetPos.y,10)
local pos = Vector3.New(self.oldPos.x,self.oldPos.y,10)
if not self.liveNode then
return
end
local duration = math.distanceXY(targetPos,pos)/500
TileMapView.CameraTween(_fuv.x,26,duration)
self.liveNode.leader.transform:DOLocalMove(targetPos, duration, false):OnStart(function ()
self:SetRoleDirAction(targetPos.x, targetPos.y, pos.x, pos.y)
self.timeCount = 0
end):OnUpdate(function() --TODO:测试速度
cantWalk = true
self:DoCheckDistance()
self.timeCount = self.timeCount + 1
if self.timeCount%20 == 0 then
SoundManager.PlaySound("Footsteps_Run_07",false)
end
end):OnComplete(function ()
cantWalk = false
self.oldPos = self.liveNode.leader.transform.localPosition
self:DoCheckDistance()
self.liveNode:SetWalkDir(WALK_DIR.IDLE_FRONT)
end):SetEase(Ease.Linear)
end
function XunBaoMiZongMap:DoCheckDistance()
local distance = math.distanceXY(self.rewardPos,self.liveNode.leader.transform.localPosition)
local banjing = ConfigManager.GetConfigData(ConfigName.SpecialConfig,125).Value
if distance <= tonumber(banjing) then
if not inside then
SoundManager.PlaySound("Audio_linglongbaojing_kaiqi_002",false)
inside = true
end
self.btnGet.sprite = self.spLoader:LoadSprite("x_xbmz_xunbaoanniu")
self.liveNode:SetSelfDirectingTag(false)
self.effectBtnGet:SetActive(true)
else
inside = false
self.btnGet.sprite = self.spLoader:LoadSprite("x_xbmz_xunbaoanniu01")
self.liveNode:SetSelfDirectingTag(true,self.liveNode.leader.transform.localPosition,self.rewardPos)
self.effectBtnGet:SetActive(false)
end
end
function XunBaoMiZongMap:SetRoleDirAction(targetU, targetV, u0, v0)
local dU = targetU - u0
local dV = targetV - v0
if dU > 0 then
self:SetWalkDir(WALK_DIR.RUN_RIGHT)
elseif dU < 0 then
self:SetWalkDir(WALK_DIR.RUN_LEFT)
elseif dV < 0 then
self:SetWalkDir(WALK_DIR.RUN_UP)
elseif dV > 0 then
self:SetWalkDir(WALK_DIR.RUN_DOWN)
end
end
function XunBaoMiZongMap:SetWalkDir(dir)
self.liveNode:SetWalkDir(dir)
end
--卸载
function XunBaoMiZongMap:Dispose()
if self.liveNode then
self.liveNode:OnClose()
self.liveNode = nil
end
UIManager.camera.clearFlags = CameraClearFlags.Skybox
TileMapView.Exit()
TileMapController.Exit()
poolManager:UnLoadAsset(mapCtrl, self.mapRoot, PoolManager.AssetType.GameObject)
self.mapRoot = nil
for _, flag in pairs(self._BuildFlag) do
Util.AddOnceClick(flag, function()end)
poolManager:UnLoadAsset("FightMiddleFlag", flag, PoolManager.AssetType.GameObject)
end
self._BuildFlag = {}
self._BuildFlagClick = {}
end
--界面关闭时调用(用于子类重写)
function XunBaoMiZongMap:OnClose()
self.effect.transform:SetParent(Util.GetTransform(self.gameObject, "mapParent"))
self.effect:SetActive(false)
self.effectLuoDi.transform:SetParent(Util.GetTransform(self.gameObject, "mapParent"))
self.effectLuoDi:SetActive(false)
self:Dispose()
SoundManager.StopMusic("BGM_010")
if func then
func()
func = nil
end
end
--界面销毁时调用(用于子类重写)
function XunBaoMiZongMap:OnDestroy()
self.spLoader:Destroy()
end
return XunBaoMiZongMap