---@class WB_SelectMap_C:UUserWidget ---@field Image_1 UImage ---@field TextBlock_Cooldown UTextBlock ---@field UniformGridPanel_Items UUniformGridPanel ---@field WrapBox_Items UWrapBox --Edit Below-- ---@type WB_SelectMap_C local WB_SelectMap = { bInitDoOnce = false; Row = 2; } function WB_SelectMap:Construct() self:LuaInit(); end function WB_SelectMap:LuaInit() if self.bInitDoOnce then return ; end self.bInitDoOnce = true; UGCLogSystem.Log("[WB_SelectMap:LuaInit] 执行111") UITool.ForeachAllChildren(self.UniformGridPanel_Items, function(index, Widget) Widget:LuaInit(); Widget:SetOwnerWidget(self, self.OnClickItem); Widget:SetVisibility(ESlateVisibility.Collapsed); end); self:FillItems(); local PlayerSelectMaps = UE.GetMiniRepData("PlayerSelectMaps") if PlayerSelectMaps then UGCLogSystem.LogTree(string.format("[WB_SelectMap:LuaInit] PlayerSelectMaps ="), PlayerSelectMaps) self:OnPlayerSelectMap(PlayerSelectMaps); else UGCLogSystem.LogTree(string.format("[WB_SelectMap:LuaInit] GameState.MiniInfo ="), GameState.MiniInfo) end end WB_SelectMap.MapNameMap = {}; function WB_SelectMap:GetItemClass() if self.ItemClass == nil then self.ItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/Tool/Child/WB_SelectMapItem.WB_SelectMapItem_C')) end return self.ItemClass end function WB_SelectMap:FillItems() -- 尝试拿到所有的地图 UGCLogSystem.Log("[WB_SelectMap:FillItems] 执行") if table.getCount(MiniGameConfig) == 1 then local MapIndex = 0; local MapNames = {}; for MiniIndex, Info in pairs(MiniGameConfig) do MapNames = Info.Map.MapName; end local MapCount = table.getCount(MapNames); local MaxCol = MapCount // self.Row if MapCount % self.Row > 0 then MaxCol = MaxCol + 1 end for i = 1, #LevelTable.LevelInfo do local Info = LevelTable.LevelInfo[i]; if MapNames[Info.MapName] ~= nil and MapNames[Info.MapName] > 0 then local Item = UITool.GetChildAt(self.UniformGridPanel_Items, MapIndex); if Item == nil then Item = UserWidget.NewWidgetObjectBP(LocalPlayerController, self:GetItemClass()); self.UniformGridPanel_Items:AddChild(Item); Item:SetOwnerWidget(self, self.OnClickItem); end local Slot = WidgetLayoutLibrary.SlotAsUniformGridSlot(Item) Slot:SetColumn(MapIndex % MaxCol) Slot:SetRow(MapIndex // MaxCol) Slot:SetVerticalAlignment(EVerticalAlignment.VAlign_Center) Slot:SetHorizontalAlignment(EHorizontalAlignment.HAlign_Center) Item:SetMapName(Info.MapName); self.MapNameMap[Info.MapName] = Item; MapIndex = MapIndex + 1 Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible); end end end end WB_SelectMap.LastSelectItems = {}; function WB_SelectMap:OnPlayerSelectMap(InList) UGCLogSystem.Log("[WB_SelectMap:OnPlayerSelectMap] 执行") if table.isEmpty(InList) then return ; end local MapToPlayerKeys = {} for PlayerKey, MapName in pairs(InList) do if MapToPlayerKeys[MapName] == nil then MapToPlayerKeys[MapName] = {}; end MapToPlayerKeys[MapName][#MapToPlayerKeys[MapName] + 1] = PlayerKey end for MapName, Item in pairs(self.MapNameMap) do Item:UpdateSelectBG(MapToPlayerKeys) end if InList[LocalPlayerKey] then self:OnClickItem(self.MapNameMap[InList[LocalPlayerKey]]); end end WB_SelectMap.Owner = nil; WB_SelectMap.SelectMapCb = nil; function WB_SelectMap:SetOwnerWidget(InOwner, InFunc) UGCLogSystem.Log("[WB_SelectMap:SetOwnerWidget] 设置信息") self.SelectMapCb = InFunc; self.Owner = InOwner; end WB_SelectMap.CurrItem = nil; function WB_SelectMap:OnClickItem(Item) UGCLogSystem.Log("[WB_SelectMap:OnClickItem] 执行") if self.CurrItem ~= Item then if self.CurrItem then self.CurrItem:SetSelect(false); end self.CurrItem = Item; self.CurrItem:SetSelect(true); -- 设置界面显示 if self.SelectMapCb and self.Owner then UGCLogSystem.Log("[WB_SelectMap:OnClickItem] 展示图片") self.SelectMapCb(self.Owner, Item:GetMapName()); -- 发送 RPC else UGCLogSystem.Log("[WB_SelectMap:OnClickItem] 不存在"); if self.Owner then UGCLogSystem.Log("[WB_SelectMap:OnClickItem] 选择") self.Owner:OnSelectMap(Item:GetMapName()); end end GameState:SendMiniGameRPC("OnPlayerSelectMaps", LocalPlayerKey, Item:GetMapName()) end end function WB_SelectMap:EnableItems(Enable) UITool.ForeachAllChildren(self.UniformGridPanel_Items, function(index, Widget) Widget:EnableItem(Enable); end); end function WB_SelectMap:UpdateSelectCountDown(InTime) self.TextBlock_Cooldown:SetText(string.format('%ds', InTime)); end function WB_SelectMap:SetRandomMapName(InName) if self.MapNameMap[InName] then self.MapNameMap[InName]:OnClickItem(); end end -- function WB_SelectMap:Tick(MyGeometry, InDeltaTime) -- end -- function WB_SelectMap:Destruct() -- end return WB_SelectMap