123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- ---@class KLMiniMapPanel:UIKmlLuaPanelBase
- ---@field view KLMiniMapPanelView
- local KLMiniMapPanel = class(UIKmlLuaPanelBase)
- local this =KLMiniMapPanel
- ---创建时调用一次
- function this:Init()
- --self.sceneImgWidth = self.view.img_scene:GetWidth()
- --self.sceneImgHeight = self.view.img_scene:GetHeight()
- self.sceneImgWidth,self.sceneImgHeight = GUI:getSizeDelta(self.view.img_scene)
- ---@type table<string,UIKmlLuaPanelBase>
- self.iconMap = {}
- self.TransPoint = {}
- self.IsTrans=false
- self.MonsterPointMinPool = TablePool() ---小地图
- self.monsterPointMinTempList = {}---小地图temp列表保存
- self.mapIconVisibleInfo = {}
- local s = SL:GetConfig("cfg_global",280).value
- local strs = string.split(s,'#')
- self.monsterCheckN =tonumber(strs[1])
- self.monsterLimitCount =tonumber(strs[2])
- end
- function this:Show()
- if SL:GetIsWebGL() then
- GUI:Text_setTextAlignment(self.view.txt_title,"21")
- else
- GUI:Text_setTextAlignment(self.view.txt_title,"01")
- end
- end
- ---创建或者刷新界面数据时调用
- function this:Refresh()
-
- self:OnPlayerMapPosChange()
- self:OnPlayerTurnDir(_,SL:GetMetaValue(EMetaVarGetKey.DIR))
- self:SetTransferIcon()
- self:SetNpcIcon()
- local mapName = SL:GetMetaValue(EMetaVarGetKey.MAP_NAME)
- local mapLine = SL:GetMetaValue(EMetaVarGetKey.MAP_LINE)
- ---@type cfg_map_info_column
- local mapInfo = SL:GetConfig("cfg_map_info", SL:GetMetaValue(EMetaVarGetKey.MAP_ID))
- if mapInfo and mapInfo.nopositionmove == 0 then
- GUI:Text_setString(self.view.txt_title,string.format("%s<color=#fbd994>[%s线]</color>",mapName,mapLine))
- else
- GUI:Text_setString(self.view.txt_title,string.format("%s",mapName))
- end
- self.TransPoint = SL:GetAllTransferPointById()
- self:ShowMonsterPointMin()
- if mapInfo and mapInfo.nopositionmove == 0 then
- GUI:setVisible(self.view.btn_switch_line, true)
- else
- GUI:setVisible(self.view.btn_switch_line, false)
- end
-
- self.timeId = SL:Schedule(self.timeId,0,1,-1,function()
- self:ShowMonsterPointMinUpdate()
- end)
- end
- ---注册UI事件和服务器消息
- function this:RegistEvents()
- SL:RegisterLUAEvent(LUA_EVENT_FIGHTEND,self.LUA_EVENT_FIGHTEND,self)
- SL:RegisterLUAEvent(LUA_EVENT_MAPINFOCHANGE,self.LUA_EVENT_NPC_LEAVE_NEAR,self) --切换不同地图
- SL:RegisterLUAEvent(LUA_EVENT_PLAYER_TURN_DIR,self.OnPlayerTurnDir,self)
- SL:RegisterLUAEvent(LUA_EVENT_MAPINFOCHANGE,self.MapEventChange,self)
- SL:RegisterLUAEvent(LUA_EVENT_PLAYER_MAPPOS_CHANGE,self.OnPlayerMapPosChange,self)
- GUI:AddOnClickEvent(self.view.btn_switch_line,self,self.BtnSwitchLineOnClick)
- GUI:AddOnClickEvent(self.view.btn_bg,self,self.BtnBgOnClick)
- SL:RegisterLuaNetMsg(MessageDef.ResUpdateViewMessage, self.ShowMonsterPointMin, self)
- SL:RegisterLuaNetMsg(MessageDef.ResMonsterEnterViewMessage, self.ShowMonsterPointMin, self)
- SL:RegisterLuaNetMsg(MessageDef.ResWalkMessage, self.ResWalkMessage, self)
- SL:RegisterLuaNetMsg(MessageDef.ResFightResultMessage, self.ResFightResultMessage, self)
-
- end
- function this:LUA_EVENT_FIGHTEND(id,data)
- self.IsTrans = false
- end
- function this:LUA_EVENT_NPC_LEAVE_NEAR(_,dir)
- self.IsTrans = false
- self.TransPoint = SL:GetAllTransferPointById()
- end
- function this:OnPlayerTurnDir(_,dir)
- GUI:setRotation(self.view.img_player_icon,(dir+1)*-45)
- end
- function this:MapEventChange()
- for k, _ in pairs(self.iconMap) do
- self:RemoveIcon(k)
- end
- self:Refresh()
- end
- function this:OnPlayerMapPosChange()
- local mapFile = SL:GetMetaValue(EMetaVarGetKey.MINIMAP_FILE)
- GUI:Image_loadTexture(self.view.img_scene,string.format("Texture/%s.png",mapFile))
- ---@type Dot2
- local pos = SL:GetMetaValue(EMetaVarGetKey.MAP_PLAYER_POS)
- local x = pos.x/256*self.sceneImgWidth - self.sceneImgWidth/2
- local z = pos.z/256*self.sceneImgHeight - self.sceneImgHeight/2
- GUI:setPosition(self.view.img_scene,-x,-z)
- GUI:Text_setString(self.view.txt_coord,pos.x..","..pos.z)
- self:JudgeMapTransfer()
- end
- function this:JudgeMapTransfer()
- if #self.TransPoint == 0 then
- self.TransPoint = SL:GetAllTransferPointById()
- if #self.TransPoint == 0 then
- return
- end
- end
- if self.IsTrans == false then
- for i, v in pairs(self.TransPoint) do
- for j, k in pairs(EDirectionToDot2) do
- local disx = math.abs(v.point.position[1] - SL:MeData_GetCoord().x)
- local disz = math.abs(v.point.position[2] - SL:MeData_GetCoord().z)
- if math.sqrt(disx * disx + disz * disz) <= v.dis then
- if v.point.condition then
- local canTransfer = SL:CheckCalculateConditionGroup(v.point.condition)
- if not canTransfer then
- local condition = SL:Split(v.point.condition, "=")
- local str = "等级不满足,"..condition[2].."等级后开启"
- SL:TipMessage( str, 1, NoticeType.NoticeMid )
- return
- end
- end
-
- local cfgTable = SL:GetConfigTable('cfg_mapMove')
- ---@param e cfg_mapMove_column
- for q, e in pairs(cfgTable) do
- if tonumber(e.mapID) == v.point.targetId then
- self.TransMapId = v.point.id
- self.IsTrans = true
- self:SetTrans()
- return
- end
- end
- end
- end
- end
- end
- end
- function this:SetTrans()
- Coroutine.Start(self.ShowTransAni,self)
- end
- function this:ShowTransAni()
- if not SL:Me_GetSellerIsCanMove() then
- return
- end
- self.timeCount=0
- --self:PlayTransAni()
- SL:SendTransferPointMessage(self.TransMapId)
- self.IsTrans=false
- end
- function this:SetMapIconVisible(id,visible)
- self.mapIconVisibleInfo[id] = visible and "1" or "0"
- if self.iconMap[id] then
- GUI:setVisible(self.iconMap[id].view.root, visible)
- end
- end
- ---@param id string
- ---@param item UIKmlLuaPanelBase
- function this:SetMapIcon(id, item, x, y)
- if self.iconMap[id] then
- GUI:UIPanel_Close(_,self.iconMap[id])
- self.iconMap[id] = nil
- end
- --GUI:SetParent(icon,self.view.scene_group)
- --item.kmlControl:SetParent(self.view.img_scene.kmlControl)
- local miniMapX=x/256*self.sceneImgWidth-self.sceneImgWidth/2
- local miniMapY=y/256*self.sceneImgHeight-self.sceneImgHeight/2
- GUI:setPosition(item.view.root,miniMapX,miniMapY)
- self.iconMap[id] = item
- if self.mapIconVisibleInfo[id] then
- GUI:setVisible(item.view.root,self.mapIconVisibleInfo[id] == "1")
- end
- end
- ---@param id string
- function this:RemoveIcon(id)
- if self.iconMap[id] then
- GUI:UIPanel_Close(_,self.iconMap[id])
- self.iconMap[id] = nil
- end
- end
- ---@设置传送点图标
- function this:SetTransferIcon()
- local mapId = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
- ---@type cfg_transfer_point_column[]
- local transferPoint = SL:FindConfigs('cfg_transfer_point', 'mapId', mapId)
- if transferPoint then
- for _,v in pairs(transferPoint) do
- local transferIcon = GUI:UIPanel_Open("dev/ui/Map/Item/KLMapTransferIcon/KLMapTransferIconItem",self.view.img_scene,self,v,true)
- self:SetMapIcon("MapTransferIcon" .. v.id,transferIcon,v.position[1],v.position[2])
- end
- end
- end
- function this:SetNpcIcon()
- local mapId = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
- ---@type cfg_npclist_column[]
- local npcList = SL:FindConfigs('cfg_npclist', 'mapId', mapId)
- if npcList then
- for _,npcTbl in pairs(npcList) do
- local npcIcon = GUI:UIPanel_Open("dev/ui/Map/Item/KLMapNpcIcon/KLMapNpcIconItem",self.view.img_scene,self,{npcTbl,false},true)
- self:SetMapIcon("MapNpcIcon" .. npcTbl.id,npcIcon,npcTbl.x,npcTbl.y)
- end
- end
- end
- function this:BtnSwitchLineOnClick()
- SL.HideMainPanel()
- GUI:UIPanel_Open("dev/ui/Map/Panel/KLUIMapBranch/KLUIMapBranchPanel")
- end
- function this:BtnBgOnClick()
- SL:ShowBigMap()
- end
- ---设置怪物点---------------------------------------------------------------
- function this:ShowMonsterPointMinUpdate()
- if not self.showMonsterPointMinUpdateTime or Time.time-self.showMonsterPointMinUpdateTime<1 then
- return
- end
- self.showMonsterPointMinUpdateTime = Time.time
- if not self.needRemove then
- self.needRemove = {}
- end
- table.clear(self.needRemove)
- if not self.needAdd then
- self.needAdd = {}
- end
- table.clear(self.needAdd)
- if not self.tempShowMonster then
- self.tempShowMonster = {}
- end
- table.clear(self.tempShowMonster)
-
-
- local showMonster = SL:GetMetaValue("GET_MONSTER_DATA_LIST")
- local maxDist = 0
- local curShowCount = 0
- local meX,meZ = SL:MeData_Pos()
- for k, v in pairs(showMonster) do
- local ax = Mathf.Abs(v.pos.x-meX)
- local az = Mathf.Abs(v.pos.z-meZ)
- if (ax>0 or az>0) and ax<=self.monsterCheckN and az<=self.monsterCheckN then
- if curShowCount<self.monsterLimitCount then
- self.tempShowMonster[v.data.id] = v
- curShowCount=curShowCount+1
- end
- end
- end
- for k, v in pairs(self.tempShowMonster) do
- local id = v.data.id
- if not self.monsterPointMinTempList[id] then
- self.needAdd[id] = v
- end
- end
- for k, v in pairs(self.monsterPointMinTempList) do
- local id = k
- if not self.tempShowMonster[id] then
- self.needRemove[id] = v
- end
- end
- for k, v in pairs(self.needRemove) do
- local id = k
- self.monsterPointMinTempList[id] = nil
- v:SetPanelXY(-3000,-3000)
- self.MonsterPointMinPool:Push(v)
- end
- for k, v in pairs(self.monsterPointMinTempList) do
- ---@type KLMapMonsterPointItem
- local monsterPointTemp = v
- local monster = SL:GetMetaValue("GET_MONSTER_DATA_BY_ID",k)
- if monster then
- local x = monster.pos.x / 256 * self.sceneImgWidth - self.sceneImgWidth / 2
- local y = monster.pos.z / 256 * self.sceneImgHeight - self.sceneImgHeight / 2
- if monsterPointTemp.x~=x or monsterPointTemp.y~=y then
- monsterPointTemp:SetPanelXY(x, y)
- end
- end
- end
-
- --local limitCount = 10
- --local index = 1
- for i, monster in pairs(self.needAdd) do
- --if index>limitCount then
- -- break
- --end
- --index =index+1
- ---@type KLMapMonsterPointItem
- local monsterPointTemp = self.MonsterPointMinPool:Pop()
- if not next(monsterPointTemp) then
- monsterPointTemp = GUI:UIPanel_Open("dev/ui/Map/Item/KLMapMonsterPoint/KLMapMonsterPointItem", self.view.img_scene, self, nil, true)
- end
- --if not string.contains(monsterPointTemp.view.root.kmlControl.rectTransform.name,monsterPointTemp.panelName) then
- -- SL:LogError("dddddddddddddddddddddddd")
- --end
- self.monsterPointMinTempList[monster.data.id] = monsterPointTemp
- -- monsterPointTemp:SetActiveUI(true)
- local x = monster.pos.x / 256 * self.sceneImgWidth - self.sceneImgWidth / 2
- local y = monster.pos.z / 256 * self.sceneImgHeight - self.sceneImgHeight / 2
- monsterPointTemp:SetMonsterData(monster.data.id,x,y)
- monsterPointTemp:SetPanelXY(x, y)
- monsterPointTemp:SetPanelRotation(0)
- monsterPointTemp:setScale(1)
- monsterPointTemp:ShowNormalMonsterIcon(monster)
- end
- end
- function this:ShowMonsterPointMin()
- if not self.showMonsterPointMinUpdateTime then
- self.showMonsterPointMinUpdateTime = Time.time
- end
- end
- ---@param message FightProtos.FightResultRes
- function this:ResFightResultMessage(_, message)
- if message then
- for _,v in pairs(message.target) do
- if v.hp <=0 and self.monsterPointMinTempList[v.targetId] then
- self.monsterPointMinTempList[v.targetId]:SetNormalDead()
- end
- end
- end
- end
- ---@param message MapProtos.WalkRes
- function this:ResWalkMessage(_, message)
- if message then
- if self.monsterPointMinTempList[message.id] then
- local pos = {}
- pos.x = message.x / 256 * self.sceneImgWidth - self.sceneImgWidth / 2
- pos.y = message.y / 256 * self.sceneImgHeight - self.sceneImgHeight / 2
- self.monsterPointMinTempList[message.id]:SetPanelXY(pos.x, pos.y)
- end
- end
- end
- function this:Close()
- self.showMonsterPointMinUpdateTime = nil
- if self.timeId then
- SL:UnSchedule(self.timeId)
- self.timeId= nil
- end
- self.monsterPointMinTempList = {}---temp列表保存
- self.MonsterPointMinPool:Clear()
- if self.iconMap then
- for k, v in pairs(self.iconMap) do
- GUI:UIPanel_Close(_,v)
- end
- table.clear(self.iconMap)
- end
- end
- ------------------怪点end---------------------------------------------------------------------------
- return this
|