---@class WB_SelectAllWeapon_C:UUserWidget ---@field HorizontalBox_DisableLIst UHorizontalBox ---@field HorizontalBox_EnemyDisable UHorizontalBox ---@field Image_BG UImage ---@field NewButton_Ready UNewButton ---@field ScrollBox_EnemyWeapons UScrollBox ---@field ScrollBox_SelfWeapons UScrollBox ---@field ScrollBox_Types UScrollBox ---@field TextBlock_CountDown UTextBlock ---@field TextBlock_MapName UTextBlock ---@field TextBlock_Ready UTextBlock ---@field TextBlock_Selected UTextBlock ---@field TextBlock_Tips UTextBlock ---@field TextBlock_Title UTextBlock ---@field WB_PID UWB_PID_C ---@field WB_SelectGameMode UWB_SelectGameMode_C ---@field WB_SelectMap UWB_SelectMap_C ---@field WidgetSwitcher_IsGangUpMode UWidgetSwitcher ---@field WidgetSwitcher_SelectMap UWidgetSwitcher --Edit Below-- ---@type WB_SelectAllWeapon_C local WB_SelectAllWeapon = { bInitDoOnce = false; }; WB_SelectAllWeapon.TypeItems = {}; ---@type table WB_SelectAllWeapon.CurrSelectItems = {}; --- 玩家武器最多限制 WB_SelectAllWeapon.WeaponLimitCount = 0; WB_SelectAllWeapon.ReadyTexts = { [1] = "两方就绪之后快速进入游戏", [2] = "对方已就绪", [3] = "已就绪,等待对方就绪", [4] = "等待开始游戏", } function WB_SelectAllWeapon:Construct() UGCLogSystem.Log("[WB_SelectAllWeapon:Construct] self = %s", UE.GetName(self)); self:LuaInit(); end function WB_SelectAllWeapon:LuaInit() if self.bInitDoOnce then return ; end self.bInitDoOnce = true; UGCEventSystem.AddListener(EventTypes.UpdateSelectWeapons, self.OnUpdateSelectWeapons, self) UGCEventSystem.AddListener(EventTypes.GameCountDownTimeChange, self.OnCountDownChange, self) UGCEventSystem.AddListener(EventTypes.OnMapLoaded, self.OnMapLoaded, self) UGCEventSystem.AddListener(EventTypes.PlayerDisable, self.OnPlayerDisable, self) UGCEventSystem.AddListener(EventTypes.UpdateModeType, self.SetIsGangUpMode, self) UGCEventSystem.AddListener(EventTypes.UpdateArchiveData, self.OnUpdateArchiveData, self) if table.isEmpty(WeaponIdTable) then GetWeaponIdTable(); end UITool.ForeachAllChildren(self.ScrollBox_SelfWeapons, function(index, Widget) Widget:SetVisibility(ESlateVisibility.Collapsed); end); UITool.ForeachAllChildren(self.ScrollBox_EnemyWeapons, function(index, Widget) Widget:SetVisibility(ESlateVisibility.Collapsed); end); --- 默认显示为 0 self.WidgetSwitcher_IsGangUpMode:SetActiveWidgetIndex(0); UGCLogSystem.Log("[WB_SelectAllWeapon:LuaInit] 开始初始化选择地图") self.WB_SelectMap:SetOwnerWidget(self, self.OnSelectMap); self.WB_SelectMap:LuaInit(); self:FillDisables(); -- 防止没有初始化 self.WB_SelectGameMode:LuaInit(); self.WB_PID:LuaInit(); --- 更新存档数据 self:OnUpdateArchiveData(); UITool.BindButtonClicked(self.NewButton_Ready, self.OnClickReady, self); local AlreadyPlayers = GameState:GetMiniInfo("AlreadyPlayers") if AlreadyPlayers then local Count = table.getCount(AlreadyPlayers); if Count == 1 then self.TextBlock_Tips:SetText(self.ReadyTexts[2]); end end UGCEventSystem.AddListener(EventTypes.UpdatePlayerReady, self.OnUpdatePlayerReady, self); end function WB_SelectAllWeapon:OnUpdateArchiveData() if table.isEmpty(ArchiveTable) and table.isEmpty(GameState.ArchiveData) then return ; end local PlayerSelectMap = {}; UGCLogSystem.Log("[WB_SelectAllWeapon:LuaInit] 执行"); local Disables = {}; for PlayerKey, Data in pairs(ArchiveTable) do PlayerSelectMap[PlayerKey] = Data.LastSelectMap; Disables[PlayerKey] = Data.Disables; end UGCLogSystem.Log("[WB_SelectAllWeapon:LuaInit] printTable = PlayerSelectMap Start") if PlayerSelectMap then table.printTable(PlayerSelectMap); end UGCLogSystem.Log("[WB_SelectAllWeapon:LuaInit] printTable = PlayerSelectMap End") self:OnPlayerSelectMap(PlayerSelectMap) UGCLogSystem.Log("[WB_SelectAllWeapon:LuaInit] printTable Disables Start") if Disables then table.printTable(Disables); end UGCLogSystem.Log("[WB_SelectAllWeapon:LuaInit] printTable Disables End") -- 加载选择 Disables self:OnPlayerDisable(Disables); local LocalMap = PlayerSelectMap[LocalPlayerKey]; if LocalMap then UGCLogSystem.Log("[WB_SelectAllWeapon:OnUpdateArchiveData] 之前选择的地图:%s", tostring(LocalMap)); self:OnMapLoaded(LocalMap); end end function WB_SelectAllWeapon:OnMapLoaded(MapName) for i, v in pairs(LevelTable.LevelInfo) do if v.MapName == MapName then UGCLogSystem.Log("[WB_SelectAllWeapon:OnMapLoaded] v.MapName = %s", v.MapName); self.TextBlock_MapName:SetText(v.ShowName); UE.AsyncLoadObject_Cached(v.MiniMapInfo.BG_Path, function(TargetObject) self.Image_BG:SetBrushFromTexture(TargetObject, true); end); end end end function WB_SelectAllWeapon:FillDisables() local Table = {}; for i = 1, EDisableType.Max - 1 do if DisableInfo[i] and DisableInfo[i].Enable then table.insert(Table, i); end end UGCLogSystem.LogTree(string.format("[WB_SelectAllWeapon:FillDisables] Table ="), Table) UITool.ForeachAllChildren(self.HorizontalBox_DisableLIst, function(index, Widget) Widget:LuaInit(); Widget:SetDisableType(Table[index]); end); UITool.ForeachAllChildren(self.HorizontalBox_EnemyDisable, function(index, Widget) Widget:LuaInit(); Widget:SetDisableType(Table[index]); end) end function WB_SelectAllWeapon:OnSelectMap(InMapName) UGCLogSystem.Log("[WB_SelectAllWeapon:OnSelectMap] InMapName = %s", InMapName); self:OnMapLoaded(InMapName); end function WB_SelectAllWeapon:OnShowPanel(...) local vars = { ... }; -- 检查一下可以使用的类型 local WeaponTypes = {}; for i, v in pairs(WeaponIdTable) do local Info = WeaponTable[v]; if WeaponTypes[Info.TypeNew] == nil then WeaponTypes[Info.TypeNew] = {}; end table.insert(WeaponTypes[Info.TypeNew], v); end local TypeList = {}; for i, v in pairs(WeaponTypes) do table.sort(v); table.insert(TypeList, { Type = i; List = v; }) end table.sort(TypeList, function(a, b) return a.Type < b.Type; end); ObjectPath.AddFunc("WB_AllWeapon_Type", function(TargetClass) UGCLogSystem.Log("[WB_SelectAllWeapon:OnShowPanel] 执行"); UITool.AdaptChildren(self.ScrollBox_Types, table.getCount(TypeList), TargetClass); UITool.ForeachAllChildren(self.ScrollBox_Types, function(index, Widget) Widget:Init(self, self.OnClickItem) Widget:SetType(TypeList[index].Type, TypeList[index].List); self.TypeItems[TypeList[index].Type] = Widget; end); end) -- 获取当前选择的数量 self.WeaponLimitCount = vars[1]; self.TextBlock_Title:SetText(tostring(self.WeaponLimitCount)); self.TextBlock_Selected:SetText(string.format("0/%d", self.WeaponLimitCount)); end --function WB_SelectAllWeapon:OnClosePanel() --end ---@param InItemId int32 物品 ID function WB_SelectAllWeapon:GetWeaponItemByItemId(InItemId) for i = 1, UITool.GetChildrenCount(self.ScrollBox_Types) do local Item = UITool.GetChildAt(self.ScrollBox_Types, i - 1); if Item:GetType() == WeaponTable[InItemId].TypeNew then return Item:GetItemByWeaponId(InItemId); end end return nil; end function WB_SelectAllWeapon:OnUpdateSelectWeapons(InList) UITool.HideAllChildren(self.ScrollBox_SelfWeapons) UITool.HideAllChildren(self.ScrollBox_EnemyWeapons) if table.isEmpty(InList) then return ; end self:SetAllNoSelect(); if not table.isEmpty(InList[LocalPlayerKey]) then UITool.ForeachAllChildren(self.ScrollBox_SelfWeapons, function(index, Widget) if InList[LocalPlayerKey][index] ~= nil then UGCLogSystem.Log("[WB_SelectAllWeapon:OnUpdateSelectWeapons] Item = %d", InList[LocalPlayerKey][index]); Widget:SetItemId(InList[LocalPlayerKey][index]); Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible); else Widget:SetVisibility(ESlateVisibility.Collapsed); end end) for i, v in pairs(InList[LocalPlayerKey]) do -- 获取类型 local Item = self:GetWeaponItemByItemId(v) if Item ~= nil and UE.IsValid(Item) then Item:SetSelect(true); end end end local EnemyPlayerKey = nil; for PlayerKey, WeaponList in pairs(InList) do if PlayerKey ~= LocalPlayerKey then EnemyPlayerKey = PlayerKey end end if EnemyPlayerKey ~= nil and not table.isEmpty(InList[EnemyPlayerKey]) then UITool.ForeachAllChildren(self.ScrollBox_EnemyWeapons, function(index, Widget) if InList[EnemyPlayerKey][index] ~= nil then Widget:SetItemId(InList[EnemyPlayerKey][index], true); Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible); else Widget:SetVisibility(ESlateVisibility.Collapsed); end end) end UGCLogSystem.LogTree(string.format("[WB_SelectAllWeapon:OnUpdateSelectWeapons] InList ="), InList) -- 让所有的都设置为非选择 end function WB_SelectAllWeapon:SetAllNoSelect() UITool.ForeachAllChildren(self.ScrollBox_Types, function(index, Widget) Widget:SetAllNoSelect(); end); end --- 倒计时 ---@param InTime int function WB_SelectAllWeapon:OnCountDownChange(InTime) self.TextBlock_CountDown:SetText(tostring(InTime) .. 's'); -- 检查当前是什么状态 UGCLogSystem.Log("[WB_SelectAllWeapon:OnCountDownChange] InTime = %s", tostring(InTime)); if MiniManager then -- 关闭当前界面 if MiniManager.State >= MiniGameState.ROUND_PREPARE then self:CloseSelf(); end else UGCLogSystem.Log("[WB_SelectAllWeapon:OnCountDownChange] InTime = %s", tostring(InTime)); end if InTime <= GameStateTimes.GangUp.SelectMapTime then self.NewButton_Ready:SetVisibility(ESlateVisibility.Collapsed); self.TextBlock_Tips:SetVisibility(ESlateVisibility.Collapsed); end if InTime > 100 then self:CloseSelf(); end end WB_SelectAllWeapon.TickCountNum = 0; WB_SelectAllWeapon.TickInterval = 1; function WB_SelectAllWeapon:Tick(MyGeometry, InDeltaTime) if GameDataTable.PID == nil or GameDataTable.BID == nil then self.TickCountNum = self.TickCountNum + InDeltaTime; if self.TickCountNum > self.TickInterval then self.TickCountNum = self.TickCountNum - self.TickInterval; self.WB_PID:SetIDs(); end end end function WB_SelectAllWeapon:Destruct() ObjectPath.WB_AllWeapon_Type = nil; ObjectPath.WB_AllWeapon_Item = nil; ObjectPath.WB_SelectWeaponItems = nil; -- 清空自身的 self.WidgetSwitcher_IsGangUpMode:ClearChildren(); self.ScrollBox_SelfWeapons:ClearChildren(); self.ScrollBox_EnemyWeapons:ClearChildren(); self.ScrollBox_Types:ClearChildren(); self.HorizontalBox_EnemyDisable:ClearChildren(); self.HorizontalBox_DisableLIst:ClearChildren(); end WB_SelectAllWeapon.Colors = { [1] = { 1, 0, 0, 1 }, [2] = { 0, 0.168678, 1, 1 }, } function WB_SelectAllWeapon:CloseSelf() self:SetVisibility(ESlateVisibility.Collapsed); if self.UIType then WidgetManager:ClosePanel(self.UIType); else WidgetManager:ClosePanel(WidgetConfig.EUIType.AllWeapon); end end ---@param InItem WB_AllWeapon_Item_C function WB_SelectAllWeapon:OnClickItem(InItem) -- 检测当前是否大于 if GameState and GameState.MiniState and GameState.MiniState >= MiniGameState.ROUND_PREPARE then self:CloseSelf(); return ; end local ItemId = InItem:GetItemId() if self.CurrSelectItems[ItemId] == nil then -- 判断当前是否存在 if table.getCount(self.CurrSelectItems) < self.WeaponLimitCount then self.CurrSelectItems[ItemId] = InItem; InItem:SetSelect(true); -- 发送 RPC GameState:SendMiniGameRPC("OnSelectWeapons", LocalPlayerKey, ItemId, true); else -- 提示当前无法添加了 UGCWidgetManagerSystem.ShowTipsUI(string.format('当前已经添加到上限了,请取消已选择的再进行添加~')); end else self.CurrSelectItems[ItemId]:SetSelect(false) GameState:SendMiniGameRPC("OnSelectWeapons", LocalPlayerKey, ItemId, false); self.CurrSelectItems[ItemId] = nil; end local CurrCount = table.getCount(self.CurrSelectItems); self.TextBlock_Selected:SetText(string.format("%d/%d", CurrCount, self.WeaponLimitCount)); end function WB_SelectAllWeapon:OnPlayerSelectMap(List) if self.WB_SelectMap then self.WB_SelectMap:OnPlayerSelectMap(List); end end function WB_SelectAllWeapon:SetSelectMapEnable(Enable) if self.WB_SelectMap then self.WB_SelectMap:EnableItems(Enable) self.WB_SelectMap:UpdateSelectCountDown(0) end end function WB_SelectAllWeapon:UpdateSelectCountDown(InTime) if self.WB_SelectMap then if InTime == nil or InTime < 0 then InTime = 0 end self.WB_SelectMap:UpdateSelectCountDown(InTime) end end WB_SelectAllWeapon.RandomMapName = nil; function WB_SelectAllWeapon:SetRandomMapName(InName) UGCLogSystem.Log("[WB_SelectAllWeapon:SetRandomMapName] InName = %s", InName); self.RandomMapName = InName; self.WB_SelectMap:SetRandomMapName(InName); end function WB_SelectAllWeapon:SwitchSelectMap() self.WidgetSwitcher_SelectMap:SetActiveWidgetIndex(1); end function WB_SelectAllWeapon:OnPlayerDisable(Disables) if table.isEmpty(Disables) then return ; end UGCLogSystem.LogTree(string.format("[WB_SelectAllWeapon:OnPlayerDisable] Disables ="), Disables) for PlayerKey, Table in pairs(Disables) do if PlayerKey == LocalPlayerKey then -- 是自己 for Type, Enable in pairs(Table) do local Item = UITool.FindItem(self.HorizontalBox_DisableLIst, function(Widget) return Widget:GetDisableType() == Type; end) if Item then Item:SetInitSelected(Enable); end end else for Type, Enable in pairs(Table) do local Item = UITool.FindItem(self.HorizontalBox_EnemyDisable, function(Widget) return Widget:GetDisableType() == Type; end); if Item then Item:SetInitDisable(Enable); end end end end end function WB_SelectAllWeapon:SetIsGangUpMode(ModeType) if ModeType ~= GameModeConfig.EGameModeType.DefaultMode then self.WidgetSwitcher_IsGangUpMode:SetActiveWidgetIndex(1); end GlobalModeType = ModeType; end function WB_SelectAllWeapon:OnClickReady() GameState:SendMiniGameRPC("OnPlayerAlready", LocalPlayerKey); self.NewButton_Ready:SetIsEnabled(false); self.TextBlock_Tips:SetText(self.ReadyTexts[3]); end function WB_SelectAllWeapon:OnUpdatePlayerReady(AlreadyPlayers) if table.getCount(AlreadyPlayers) == 1 and AlreadyPlayers ~= nil and AlreadyPlayers[LocalPlayerKey] == nil then self.TextBlock_Tips:SetText(self.ReadyTexts[2]); end if table.getCount(AlreadyPlayers) == 2 then self.TextBlock_Tips:SetText(self.ReadyTexts[4]); end end return WB_SelectAllWeapon;