local UIMiniMap = UIViewClass() local MAP_PATH = ConstAssetPathConfig.MAP_PATH local UIMiniMapPointItem = require("View/MiniMap/UIMiniMapPointItem") local ScrollType_Line = 1 local ScrollType_Find = 2 local HeadPosY = 50 local UpdateInterval = 0.2 local tonumberV2=FP.tonumberV2 local ITEM_PATH = ConstAssetPathConfig.ITEM_PATH local POINT_PATH = ConstAssetPathConfig.MapPointPath function UIMiniMap:OnCreated() self.img_HeadBack = self.img_HeadBack.gameObject.transform self.rebelStrikePointList = {} self.countryNightBossPointList = {} end function UIMiniMap:OnOpened() self:RegistSystemEvent(EventID.UI_UpdateLineInfo, self.UpdateLineInfo) self:RegistSystemEvent(EventID.UI_UpdateRebelStrike_MapInfo, self.UpdateRebelStrikeInfo) self:RegistSystemEvent(EventID.Update_CountryNightBoss_SceneInfo, self.UpdateCountryNightBossInfo) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.CheckTownActive) self:RegistTriggerEvent(self.group_MapWorld, UIEventTriggerType.PointerDown) self:StartRepeatFunc(self.OnUpdateFun, UpdateInterval) self.Index = 0 --0当前地图 1世界地图 self.isShowScrollLine = false self.isDuringScrollAnimation = false self:SwitchContiner() -- 换线 self:InitLineInfo() --叛军突袭 self:UpdateRebelStrikeInfo() -- 国战晚间boss self:UpdateCountryNightBossInfo() --根据功能检测是否显示小地图的城镇按钮 self:CheckTownActive() UTL.UIRender.AdaptiveImageSizeFit(self.img_Bg, true) UTL.UIRender.AdaptiveImageSizeFit(self.img_Bg1, true) end local CrossServerIndex = 13 function UIMiniMap:CheckTownActive() local isCrossServerUnlock = MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.ZoneCity) UIUtils.SetActive(self.group_Map[CrossServerIndex], isCrossServerUnlock) UIUtils.SetActive(self.img_kuafu, isCrossServerUnlock) end function UIMiniMap:InitLineInfo() local isShowChangeline = CTL.MiniMap.IsShowChangeLine() UIUtils.SetActive(self.btn_ChangeLine, isShowChangeline); UIUtils.SetActive(self.group_content, isShowChangeline) if isShowChangeline then self:OnClickChangeLine() end end --加载传送门 function UIMiniMap:LoadLevelConveyItem() if self.ConveyItemList then return end self.ConveyItemList = {} local conveyItemList = LevelItemManager.GetItemListByType(LuaConst.LevelItemType.Convey) for _,v in ipairs(conveyItemList) do local item = TK2API.GetInstance(ITEM_PATH,self.img_MapArea.transform) local label = UIUtils.GetLocalizationTextFromChild(item,0) local itemData = v.ItemData UIUtils.SetLabelText(label,Const_IDS[itemData.Name]) local posX, posY = tonumberV2(itemData.ItemPos) local fixPosX = (posX - self.OffsetX) * self.OffsetSize local fixPosY = (posY - self.OffsetY) * self.OffsetSize item.transform:SetLocalPosition(fixPosX, fixPosY, 0) table.insert(self.ConveyItemList,item) end end -- 国战晚间boss显示 function UIMiniMap:UpdateCountryNightBossInfo() if CTL.CountryNightBoss.IsChangAnLevel() then for i, v in ipairs(self.countryNightBossPointList) do v:Clear() self.countryNightBossPointList[i] = nil end local bossInfoDic = MDL.CountryNightBoss.GetBossInfoDic() for bossId, bossInfo in pairs(bossInfoDic) do if not MDL.CountryNightBoss.IsBossOver(bossId) then local levelItem = BattleDataGetter.GetLevelItemByID(bossInfo.levelItemID) local pointType = CTL.MiniMap.MiniMapPointType.CountryNightBoss local mapPointItem = UIMiniMapPointItem:new(pointType, POINT_PATH, self.img_MapArea.transform) local posX, posY = tonumberV2(levelItem.ItemData.ItemPos) local fixPosX = (posX - self.OffsetX) * self.OffsetSize local fixPosY = (posY - self.OffsetY) * self.OffsetSize mapPointItem:SetPointPos(fixPosX, fixPosY, nil) table.insert(self.countryNightBossPointList, mapPointItem) end end self.img_SelfPoint:SetAsLastSibling() end end --叛军突袭显示 function UIMiniMap:UpdateRebelStrikeInfo() for i, v in ipairs(self.rebelStrikePointList) do v:Clear() self.rebelStrikePointList[i] = nil end for _, v in LevelItemManager.GetItemIterByType(LuaConst.LevelItemType.SpawnNpcPoint) do local entity, type = v:GetMapPointInfo() if entity then local pointType = CTL.MiniMap.GetRebelStrikeType(type) local mapPointItem = UIMiniMapPointItem:new(pointType, POINT_PATH, self.img_MapArea.transform) local posX, posY = tonumberV2(entity:GetLogicPos()) local fixPosX = (posX - self.OffsetX) * self.OffsetSize local fixPosY = (posY - self.OffsetY) * self.OffsetSize mapPointItem:SetPointPos(fixPosX, fixPosY, nil) table.insert(self.rebelStrikePointList,mapPointItem) end end --确保自己的层级在最上边 self.img_SelfPoint:SetAsLastSibling() end function UIMiniMap:OnPointerDown(comp, eventData) --to do --if comp == self.img_MapArea then -- print(eventData) --end end function UIMiniMap:OnUpdateFun(deltaTime, timeSinceUpdate) if self.StartUpdatePos then self:UpdatePlayerPos() end end function UIMiniMap:OnClosed() TK2API.ReturnAsset(self.path, self.tex); TK2API.ReturnAsset(self.OutResPath, self.OutResTex); if self.ConveyItemList then for _,v in ipairs(self.ConveyItemList) do TK2API.ReturnInstance(ITEM_PATH, v.gameObject) end end for i, v in ipairs(self.rebelStrikePointList) do v:Clear() self.rebelStrikePointList[i] = nil end for i, v in ipairs(self.countryNightBossPointList) do v:Clear() self.countryNightBossPointList[i] = nil end self.BgEffect:StopUIEffect() end function UIMiniMap:SwitchContiner() self.StartUpdatePos = false if self.Index == 0 then self.BgEffect:PlayUIEffect() UIUtils.SetActive(self.group_MapArea, true) UIUtils.SetActive(self.group_MapWorld, false) self.btn_Change:SetText(Const_IDS.IDS_WorldMap) --地图信息 local levelInfoData = BattleDataGetter.GetLevelInfoData() if levelInfoData then self.miniMapData = DataSheetManager.MiniMapData:GetDataByID(levelInfoData.SceneMapID) --小地图资源 self.path = string.format(MAP_PATH, self.miniMapData.SceneMap) self.tex = TK2API.GetTextureAsset(self.path) self.img_MapArea.texture = self.tex self.img_MapArea:SetNativeSize() self.BGSize = self.img_MapArea.rectTransform:GetSizeDelta() self.OffsetSize, self.OffsetX, self.OffsetY = self:GetMapOffsetPos(self.tex.width) --诗句资源 if string.isNilOrEmpty(self.miniMapData.MiniMapPoetry) or GameAppInfo.IsVietnamPackage() then UIUtils.SetActive(self.texture_Desc.gameObject, false) else UIUtils.SetActive(self.texture_Desc.gameObject, true) UIUtils.SetLocalizationImage(self.texture_Desc, self.miniMapData.MiniMapPoetry) self.texture_Desc:SetNativeSize() end self.StartUpdatePos = true self:LoadLevelConveyItem() self:UpdatePlayerPos() end else self.BgEffect:StopUIEffect() UIUtils.SetActive(self.group_MapArea, false) UIUtils.SetActive(self.group_MapWorld, true) self.btn_Change:SetText(Const_IDS.IDS_AreaMap) --设置头像位置 local roleId = MDL.Player.GetCurShowId() UTL.Item.SetHeroIconByHeroId(self.texture_HeadImg, roleId, MDL.HeroAwaken.GetIsHeroAwaken(roleId)) local localIndex = MDL.MiniMap.GetMapIndex(BattleDataGetter.GetLevelInfoData().LevelID) self.img_HeadBack:SetParent(self.group_Map[localIndex]:GetText().transform) self.img_HeadBack:SetLocalPosition(0, HeadPosY) self.img_HeadBack:SetParent(self.group_MapWorld.transform,true) end end --更新主角坐标 function UIMiniMap:UpdatePlayerPos() local levelInfoData = BattleDataGetter.GetLevelInfoData() local myPos = BattleDataGetter.GetMainPlayerLastLogicPos() if myPos == nil then return end local posX, posY = tonumberV2(myPos) local fixPosX = (posX - self.OffsetX) * self.OffsetSize local fixPosY = (posY - self.OffsetY) * self.OffsetSize local rotY = BattleDataGetter.GetMainExpEntityEulerAngleY() if (self.lastAngle == nil) or (self.lastAngle and self.lastAngle ~= rotY * (-1)) then self.lastAngle = rotY * (-1) self.img_SelfPoint:SetLocalEulerAngles(0, 0, self.lastAngle) end if ((self.lastPosX == nil) or (self.lastPosX and self.lastPosX ~= fixPosX)) or ((self.lastPosY == nil) or (self.lastPosY and self.lastPosY ~= fixPosY)) then self.img_SelfPoint:SetLocalPosition(fixPosX, fixPosY, 0) self.lastPosX = fixPosX self.lastPosY = fixPosY self.txt_Pos.text = string.format("%s(%s,%s)", UIUtils.GetLocalizedTxt(Const_IDS[levelInfoData.LevelNameIDS]), math.ceil(posX), math.ceil(posY)) end end function UIMiniMap:OnClickChangeLine() -- 未完成动画直接切换 if self.isDuringScrollAnimation == true then self:FinishScollAnimation() end if self.isShowScrollLine == false then NotSyncBattleSetter.SendGetSceneLineRequest() CTL.Sound.PlayGameSound("UI_expand") else self:ScrollClose() CTL.Sound.PlayGameSound("UI_fold") end end function UIMiniMap:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIMiniMap:OnButtonClicked(comp) if (comp == self.btn_Close) then self:CloseView() elseif (comp == self.btn_Change) then self.Index = self.Index == 0 and 1 or 0 self:SwitchContiner() elseif (comp == self.btn_ChangeLine) then self:OnClickChangeLine() elseif (comp == self.btn_Search) then --to do else --世界地图传送口 local index for i,item in ipairs(self.group_Map) do if item == comp then index = i break end end local config = DataSheetManager.WorldMap:GetDataByID(index) if config == nil then CTL.Tips.AddTipsMsg(Const_IDS["IDS_NotOpen"]) return end local mapID = config.CityID if MDL.MiniMap.CrossServerScene[index] then mapID = CTL.WarZone.IsWarZoneOpen() and MDL.MiniMap.CrossServerScene[index] or mapID end local curLevelID = BattleDataGetter.GetLevelInfoData().LevelID if curLevelID == mapID then CTL.Tips.AddTipsMsg(Const_IDS["IDS_InThisScene"]) else CTL.GuildEscort.GuildEscortQuit(function() if CTL.MiniMap.GoToMap(mapID) then self:CloseView() end end) end end end function UIMiniMap:GetMapOffsetPos(texSize) local miniMapData = self.miniMapData local mapSize = miniMapData.UIMapSize>0 and miniMapData.UIMapSize or texSize local uiMapRate = (miniMapData.OriMapSize>0 and miniMapData.UIMapSize>0) and (miniMapData.UIMapSize/miniMapData.OriMapSize) or 1 local OffsetSize = self.BGSize / texSize * uiMapRate local OffsetX local OffsetY if miniMapData.IsCombine == 1 then OffsetX = (mapSize/uiMapRate) / 2 + miniMapData.MapOffsetX OffsetY = (mapSize/uiMapRate) / 2 + miniMapData.MapOffsetY else local xMax, zMax, offsetX, offsetZ = BattleExt.GetCurMapInfo() OffsetX = xMax / 2 + offsetX OffsetY = zMax / 2 + offsetZ end return OffsetSize, OffsetX, OffsetY end function UIMiniMap:OnCellInit(scrollRect, index, cellTable, data) if self.ScrollType == ScrollType_Line then local isSelect = data.LineNum == BattleDataGetter.GetCurLine() if isSelect then cellTable.UIState:SetState(1) else cellTable.UIState:SetState(0) end if UNITY_EDITOR then cellTable.lab_Line.text = string.FormatByIdsId(Const_IDS.IDS_MapLine, data.LineNum) .. " " .. data.RoleNum else cellTable.lab_Line.text = string.FormatByIdsId(Const_IDS.IDS_MapLine, data.LineNum) end else self:ScrollClose() end end function UIMiniMap:OnCellClicked(scrollRect, index, cellTable, target, data) if self.ScrollType == ScrollType_Line then if CTL.GuildEscort.IsTransport() then if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIGuildEscortQuit) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildEscortQuit, {QuitCallBack = function() NotSyncBattleSetter.SendChangeSceneLineRequest(data.LineNum) end}) end else NotSyncBattleSetter.SendChangeSceneLineRequest(data.LineNum) end self:CloseView() end end --region 分线 function UIMiniMap:ScrollClose() if self.ID_CloseLines then self:PlayUIAnimation(self.ID_CloseLines) else self.ID_CloseLines = self:PlayUIAnimation("CloseLines", true) end self.isDuringScrollAnimation = true self.isShowScrollLine = false self:UpdateChangeLineImg() end function UIMiniMap:UpdateLineInfo(LineInfoList) self.ScrollType = ScrollType_Line self.loopScroll:ReloadAll(LineInfoList) if self.ID_OpenLines then self:PlayUIAnimation(self.ID_OpenLines) else self.ID_OpenLines = self:PlayUIAnimation("OpenLines", true) end self.isDuringScrollAnimation = true self.isShowScrollLine = true self:UpdateChangeLineImg() end function UIMiniMap:UpdateChangeLineImg() UIUtils.SetActive(self.img_ArrowUp, self.isShowScrollLine == true) UIUtils.SetActive(self.img_ArrowDown, self.isShowScrollLine == false) end function UIMiniMap:FinishScollAnimation() if self.isShowScrollLine then self:StopUIAnimation(self.ID_OpenLines, false, true) else self:StopUIAnimation(self.ID_CloseLines, false, true) end end function UIMiniMap:OnUIAnimationStoped() self.isDuringScrollAnimation = false end --endregion return UIMiniMap