miduo_client/Assets/ManagedResources/~Lua/Modules/Map/View/PointHandleView.lua

561 lines
18 KiB
Lua

--- 事件点的上层处理方法
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by aaa.
--- DateTime: 2019/8/27 10:14
require("Modules/Map/View/MapPointView")
require("Modules/Map/Config/MapConfig")
PointHandleView = {}
local this = PointHandleView
local carBonMissionData = ConfigManager.GetConfig(ConfigName.ChallengeMissionConfig)
local MapPointConfig = ConfigManager.GetConfig(ConfigName.MapPointConfig)
function this.GeneratePoint()
this.EventPoint = {}
this.TipPoint = {}
this.NotePoint = {}
-- 记录已经在地图显示的地图点
this.SawPoint = {}
-- 阻挡点图标
this.BlockPoint = {}
-- 显示战力的点
this.PowerPoint = {}
-- 如果是无尽副本。生成丑的要死的阻挡点
if CarbonManager.difficulty == CARBON_TYPE.ENDLESS then
-- 无尽副本阻挡点设置图标 cell.Style == 8
--for i, v in pairs(MapManager.mapPointList) do
-- local pointData = MapPointConfig[v]
-- if pointData then
-- if pointData.Style == 8 then
-- this.SetBlockIcon(i)
-- end
-- end
--end
end
for k, v in pairs(MapManager.mapPointList) do
local x, y = Map_Pos2UV(k)
-- LogYellow("X:"..x.." Y"..y)
this.GenEventPoint(x, y, v)
end
this.InitShow()
-- 开启定时器
this.StartCountTime()
-- 刷新被主角狗眼糟蹋过的点
this.ShowSawPoints()
-- -- 初始化标记点
-- if CarbonManager.difficulty == CARBON_TYPE.ENDLESS then
-- for pos, data in pairs(EndLessMapManager.PointNoteDataList[4401]) do--MapManager.curMapId]) do
-- this.OnAddNotePoint(pos, data.noteInfo)
-- end
-- end
if MapManager.curCarbonType == CarBonTypeId.ENDLESS then
-- 设置一下战力的显示
this.RefreshAtkShow()
end
end
function this.OnShow()
if EndLessMapManager.isAddPoint then
-- 开启定时器
this.StartCountTime()
end
end
function this.AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Map.PointAdd, this.OnAddPoint)
Game.GlobalEvent:AddEvent(GameEvent.Map.PointRemove, this.OnRemovePoint)
Game.GlobalEvent:AddEvent(GameEvent.Map.OnAddNotePoint, this.OnAddNotePoint)
Game.GlobalEvent:AddEvent(GameEvent.Map.OnRemoveNotePoint, this.RemoveNotePoint)
Game.GlobalEvent:AddEvent(GameEvent.Map.DisperseFog, this.OnDisperseFog)
Game.GlobalEvent:AddEvent(GameEvent.Map.OnAddCountTimePoint, this.OnAddFreshPoint)
end
function this.RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Map.PointAdd, this.OnAddPoint)
Game.GlobalEvent:RemoveEvent(GameEvent.Map.PointRemove, this.OnRemovePoint)
Game.GlobalEvent:RemoveEvent(GameEvent.Map.DisperseFog, this.OnDisperseFog)
Game.GlobalEvent:RemoveEvent(GameEvent.Map.OnAddNotePoint, this.OnAddNotePoint)
Game.GlobalEvent:RemoveEvent(GameEvent.Map.OnRemoveNotePoint, this.RemoveNotePoint)
Game.GlobalEvent:RemoveEvent(GameEvent.Map.OnAddCountTimePoint, this.OnAddFreshPoint)
end
--生成事件点
function this.GenEventPoint(u, v, pointId)
local pointView = MapPointView.New(u, v, pointId)
if pointView then
-- --LogGreen("生成了事件点")
pointView.go.transform:SetParent(Util.GetTransform(this.Ctrl, "uiObj#"))
pointView.go:GetComponent("RectTransform").anchoredPosition3D = TileMapView.GetLiveTilePos(u, v) * 100
pointView.go.transform.localScale = Vector3.one
this.EventPoint[Map_UV2Pos(u, v)] = pointView
this.SawPoint[Map_UV2Pos(u, v)] = 0
local isNear = false
local u0, v0 = Map_Pos2UV(MapManager.curPos)
isNear = math.abs(u - u0) + math.abs(v - v0) <= MapManager.fogSize
local isHidePoint = pointView:InitEventPointShow()
if not isHidePoint and isNear then
pointView.go:SetActive(isNear)
end
-- 是否需要显示战力
if MapManager.pointAtkPower[Map_UV2Pos(u, v)] then
local data = MapManager.pointAtkPower[Map_UV2Pos(u, v)]
pointView:ShowAtkNum(tonumber(data), true)
Util.GetGameObject(pointView.go, "atk"):GetComponent("RectTransform").anchoredPosition = ShowTimePos[pointView.iconId].pos
if data > 0 then
local t = {}
t.point = pointView
t.power = data
this.PowerPoint[Map_UV2Pos(u, v)] = t
end
else
pointView:ShowAtkNum(0, false)
end
-- 初始化隐藏组件
pointView:ShowFreshTime(false)
pointView:ShowDialogue(false)
pointView:ShowDialogue(false)
end
end
-- 刷新事件点的战力显示
function this.RefreshAtkShow()
-- 获取当前战队的战力
local teamPower = MapManager.GetMapTeamPower()
for i, v in pairs(this.PowerPoint) do
v.point:ShowAtkNum(v.power, true, teamPower)
end
end
-- 设置显示雷达,通过当前主线任务状态
function this.SetDirShinning(mainMission)
if CarbonManager.difficulty ~= 2 or CarbonManager.difficulty ~= CARBON_TYPE.ENDLESS then
if mainMission then
local mapPointIds = carBonMissionData[mainMission.id].NextMissionPos
if mapPointIds and #mapPointIds > 0 then
for i = 1, #mapPointIds do
local pointIds = mapPointIds[mainMission.step + 1]
if pointIds and #pointIds > 0 then
for j = 1, #pointIds do
local mapPointId = pointIds[j]
-- 设置当前电圈
if mapPointId and mapPointId ~= 0 then
--初始校验值
local pos = MapManager.GetPosByMapPointId(mapPointId)
local pointData = this.EventPoint[pos]
if pointData then
if pointData.cell.isHidden ~= 2 and pointData.cell.isHidden ~= 3 then
if pos then
local u, v = Map_Pos2UV(pos)
this.AddTipPoint(u, v)
end
end
end
end
end
end
end
end
end
end
end
-- 判断地图点是否是当前的高亮点
function this.IsAShinningPoint(curMapoint)
-- 无尽副本或者是试炼副本没有
if CarbonManager.difficulty == CARBON_TYPE.TRIAL or CarbonManager.difficulty == CARBON_TYPE.ENDLESS then
--Log("此副本没有任务!")
return
end
local Yep = false
if CarbonManager.difficulty ~= 2 then
local mainMission = MissionManager.carBonMission
if mainMission then
local mapPointIds = carBonMissionData[mainMission.id].NextMissionPos
if mapPointIds and # mapPointIds > 0 then
for i = 1, #mapPointIds do
local pointIds = mapPointIds[i]
if pointIds and #pointIds > 0 then
for j = 1, #pointIds do
local mapPointId = pointIds[j]
if mapPointId and mapPointId ~= 0 then
if mapPointId == curMapoint then
Yep = true
-- 高亮的地图点一次只有一个
break
end
end
end
end
end
end
end
end
return Yep
end
-- 消除地图迷雾
function this.OnDisperseFog(pos, radius)
local u1, v1 = Map_Pos2UV(pos)
if OptionBehaviourManager.CurTriggerPanel then
OptionBehaviourManager.CurTriggerPanel.gameObject:SetActive(false)
end
TileMapView.CameraTween(u1, v1, 1, function ()
TileMapView.UpdateWarFog(u1, v1, radius)
Timer.New(function ()
local u, v = Map_Pos2UV(MapManager.curPos)
-- 显示迷雾中心的事件点
for k, p in pairs(this.EventPoint) do
local u0, v0 = Map_Pos2UV(k)
local isNear = math.abs(u0 - u1) + math.abs(v0 - v1) <= radius
if isNear then
p:CanSeePoint()
this.SawPoint[k] = 1
if CarbonManager.difficulty == CARBON_TYPE.ENDLESS then
this.SetNotePointShow(false, k)
end
end
end
TileMapView.CameraTween(u, v, 1, function ()
-- 重新触发事件,打开事件界面
if OptionBehaviourManager.CurTriggerPanel then
OptionBehaviourManager.CurTriggerPanel.gameObject:SetActive(true)
end
end)
end, 1, 1, true):Start()
end)
end
--- ========== 增加销毁 =====================================
function this.AddTipPoint(u, v)
local pos = Map_UV2Pos(u, v)
if not this.TipPoint[pos] then
local go = poolManager:LoadAsset("UI_effect_TanSuo_TiShi", PoolManager.AssetType.GameObject)
go.name = "TipPoint"
go:SetActive(true)
go.transform:SetParent(this.Ctrl.transform)
go.transform.localPosition = TileMapView.GetLiveTilePos(u, v)
local v3 = go.transform.position
go.transform.position = Vector3.New(v3.x, v3.y, v3.z - 15)
this.TipPoint[pos] = go
end
end
-- 增加一个标记点
function this.OnAddNotePoint(pos, noteText)
local u,v = Map_Pos2UV(pos)
if not this.NotePoint[pos] then
local go = poolManager:LoadAsset("mapNoteTip", PoolManager.AssetType.GameObject)
go.transform:SetParent(Util.GetTransform(this.Ctrl, "uiObj#"))
Util.GetGameObject(go, "textImg/context"):GetComponent("Text").text = noteText
go.name = "mapNoteTip"
go:SetActive(true)
local goPos = TileMapView.GetLiveTilePos(u, v) * 100
go:GetComponent("RectTransform").anchoredPosition3D = goPos + Vector3.New(0, 60, 0)
go.transform.localScale = Vector3.one
this.NotePoint[pos] = go
if this.SawPoint[pos] == 1 then
this.SetNotePointShow(false, pos)
end
-- 同时存进列表
local data = {}
data.notePos = pos
data.noteInfo = noteText
EndLessMapManager.PointNoteDataList[MapManager.curMapId][data.notePos] = data
end
end
-- 设置阻挡点图标
function this.SetBlockIcon(pos)
local u, v = Map_Pos2UV(pos)
if not this.BlockPoint [pos] then
local go = poolManager:LoadAsset("mapButtonPoint", PoolManager.AssetType.GameObject)
go.transform:SetParent(Util.GetTransform(this.Ctrl, "uiObj#"))
go:GetComponent("Image").sprite = self.spLoader:LoadSprite("r_map_xiangzi") -- 无用的
go:GetComponent("Image"):SetNativeSize()
go.name = "blockPoint"
go:SetActive(true)
local goPos = TileMapView.GetLiveTilePos(u, v) * 100
go:GetComponent("RectTransform").anchoredPosition3D = goPos + Vector3.New(0, 0, -10)
go.transform.localScale = Vector3.one
this.BlockPoint[pos] = go
end
end
-- 设置标记点的下半身
function this.SetNotePointShow(state, pos)
if this.NotePoint[pos] then
Util.GetGameObject(this.NotePoint[pos], "sign"):SetActive(state)
end
end
function this.RemoveNotePoint(pos)
local go = this.NotePoint[pos]
if go then
poolManager:UnLoadAsset("mapNoteTip", go, PoolManager.AssetType.GameObject)
this.NotePoint[pos] = nil
end
if EndLessMapManager.PointNoteDataList[MapManager.curMapId][pos] then
EndLessMapManager.PointNoteDataList[MapManager.curMapId][pos] = nil
end
end
function this.RemoveTipPoint(u, v)
local pos = Map_UV2Pos(u, v)
local go = this.TipPoint[pos]
if go then
poolManager:UnLoadAsset("UI_effect_TanSuo_TiShi", go, PoolManager.AssetType.GameObject)
this.TipPoint[pos] = nil
end
end
--移除事件点
function this.RemoveEventPoint(u, v)
local pointView = this.EventPoint[Map_UV2Pos(u, v)]
if pointView then
pointView:OnRemovePoint()
this.EventPoint[Map_UV2Pos(u, v)] = nil
if this.SawPoint[Map_UV2Pos(u, v)] then
this.SawPoint[Map_UV2Pos(u, v)] = 0
this.SetNotePointShow(true, Map_UV2Pos(u, v))
end
-- 删除的是一个有战力的点
if this.PowerPoint[Map_UV2Pos(u, v)] then
this.PowerPoint[Map_UV2Pos(u, v)] = nil
end
end
end
function this.InitShow()
for k, p in pairs(this.EventPoint) do
p.go:SetActive(false)
end
end
--刷新动态点的显示
function this.RefreshShow()
local u, v
for k, p in pairs(this.EventPoint) do
u, v = Map_Pos2UV(k)
if this.CheckFieldOfView(u, v) then
p:CanSeePoint()
this.SawPoint[k] = 1
if CarbonManager.difficulty == CARBON_TYPE.ENDLESS then
this.SetNotePointShow(false, k)
end
end
end
end
-- 刷新走过的路径中出现的点
function this.ShowSawPoints()
if CarbonManager.difficulty ~= CARBON_TYPE.ENDLESS then return end
-- LogYellow("#MapManager.wakeCells:"..#MapManager.wakeCells)
if #MapManager.wakeCells == 0 then Log(Language[11300]) return end
for pos, point in pairs(this.EventPoint) do
local u0, v0 = Map_Pos2UV(pos)
for i = 1, #MapManager.wakeCells do
local u, v = Map_Pos2UV(MapManager.wakeCells[i])
if math.abs(u0 - u) + math.abs(v0 - v) <= MapManager.fogSize then
point:CanSeePoint()
this.SawPoint[pos] = 1
end
end
end
end
function this.CheckFieldOfView(u, v)
return math.abs(u - this.leaderMapData.u) + math.abs(v - this.leaderMapData.v) <= MapManager.fogSize
end
function this.OnAddPoint(pos, pointId)
-- LogPink("pointId "..pointId)
if pos and not this.EventPoint[pos] then
local u, v = Map_Pos2UV(pos)
this.GenEventPoint(u, v, pointId)
-- 在MapManager中添加新增的地图点
-- 如果增加的点是一个需要亮的点
if this.IsAShinningPoint(pointId) then
LogPink("1111111111111111111111111111")
--this.SetDirShinning(MissionManager.carBonMission)
local pos = MapManager.GetPosByMapPointId(pointId)
local pointData = this.EventPoint[pos]
if pointData then
LogPink("12222222222")
if pointData.cell.isHidden ~= 2 and pointData.cell.isHidden ~= 3 then
if pos then
LogPink("33333333333333333333333")
local u, v = Map_Pos2UV(pos)
this.AddTipPoint(u, v)
end
end
end
end
this.RefreshAtkShow()
end
end
function this.OnRemovePoint(mapPointPos)
local u, v = Map_Pos2UV(mapPointPos) -- 当前位置坐标
local mapPointId = MapManager.mapPointList[mapPointPos]
if MapPointConfig[mapPointId].Style == 8 then
TileMapView.GetTileData(u, v).val = 0
else
this.RemoveEventPoint(u, v)
end
-- 删除一个位置
MapManager.mapPointList[Map_UV2Pos(u, v)] = nil
-- 如果删除的点是亮的
if this.IsAShinningPoint(mapPointId) then
Log("删除一个高两点")
this.RemoveTipPoint(u, v)
end
end
-- 增加一个需要显示刷线时间的点
function this.OnAddFreshPoint()
Log("this.OnAddFreshPoint()")
this.StartCountTime()
end
-- 刷新的点开始倒计时
function this.StartCountTime()
Log("this.StartCountTime()")
this.timeComp = {}
local countData = EndLessMapManager.freshPointData
local haveData = false
for i, v in pairs(countData) do
haveData = true
if this.EventPoint[i] then
this.timeComp[i] = Util.GetGameObject(this.EventPoint[i].go, "freshTime/Text"):GetComponent("Text")
this.timeComp[i].text = ""
this.EventPoint[i]:ShowFreshTime(true)
end
end
-- 没有数据,直接返回
if not haveData then return Log(Language[11301]) end
this.timer = nil
local startCount = function ()
this.timer = Timer.New(function ()
local isNil = true
for p, d in pairs(EndLessMapManager.freshPointData) do
isNil = false
local nextRefreshTime = d
if nextRefreshTime then
if nextRefreshTime <= math.ceil(PlayerManager.serverTime) then
if this.EventPoint[p] then
this.EventPoint[p]:ShowFreshTime(false)
EndLessMapManager.freshPointData[p] = nil
this.timeComp[p] = nil
end
else
if this.timeComp[p] then
this.timeComp[p].text = TimeStampToDateStr3(nextRefreshTime - math.ceil(PlayerManager.serverTime))
end
end
end
end
--if isNil then
-- this.timer:Stop()
--end
end, 1, -1, true)
this.timer:Start()
end
startCount()
EndLessMapManager.isAddPoint = false
end
---===========================================================
function this.Dispose()
-- 事件点
for k, v in pairs(this.EventPoint) do
-- 刚删完预设还没删除表数据就出图,会报空
if v.go then
v:Dispose()
this.EventPoint[k] = nil
end
end
-- 高亮点
for k, v in pairs(this.TipPoint) do
if v then
poolManager:UnLoadAsset("UI_effect_TanSuo_TiShi", v, PoolManager.AssetType.GameObject)
end
this.TipPoint[k] = nil
end
-- 标记点
for k, v in pairs(this.NotePoint) do
if v then
poolManager:UnLoadAsset("mapNoteTip", v, PoolManager.AssetType.GameObject)
end
this.NotePoint[k] = nil
end
-- 阻挡点
for b, p in pairs(this.BlockPoint) do
if p then
poolManager:UnLoadAsset("mapButtonPoint", p, PoolManager.AssetType.GameObject)
end
this.NotePoint[b] = nil
end
if this.timer then
this.timer:Stop()
this.timer = nil
end
this.timeComp = {}
this.PowerPoint = {}
this.SawPoint = {}
-- 清空数据
EndLessMapManager.freshPointData = {}
end
return PointHandleView