---@class WB_SelectWeapons_C:UUserWidget ---@field Button_Close UButton ---@field ScrollBox_Items UScrollBox ---@field TextBlock_WeaponSelect UTextBlock ---@field WB_PID UWB_PID_C --Edit Below-- ---@type WB_SelectWeapons_C local WB_SelectWeapons = { bInitDoOnce = false; }; WB_SelectWeapons.CurrClickItem = nil; WB_SelectWeapons.SelectWeapons = nil; WB_SelectWeapons.AutoHide = false; WB_SelectWeapons.IntervalTime = 0.5; function WB_SelectWeapons:Construct() UGCEventSystem.AddListener(EventTypes.AllPlayerKDAChange, self.OnAllPlayerKDAChange, self) UGCEventSystem.AddListener(EventTypes.UpdateCurrWeapon, self.OnUpdateCurrWeapon, self) self.WB_PID:LuaInit(); if self.AutoHide then self.Button_Close:SetVisibility(ESlateVisibility.Collapsed); else UITool.BindButtonClicked(self.Button_Close, self.OnClickClose, self); self.TextBlock_WeaponSelect:SetVisibility(ESlateVisibility.Collapsed); end -- 检测玩家当前有多少武器 UIManager:Register("WB_SelectWeapons", self); if self.Weapons then UGCLogSystem.Log("[WB_SelectWeapons:Construct] 执行") self:SetInitWeapons(self.Weapons); end local KDAs = GameState:HandleAllKDAs() if KDAs then self:OnAllPlayerKDAChange(KDAs); end end function WB_SelectWeapons:OnShowPanel(...) local vars = { ... }; -- 开启倒计时 if self.AutoHide then self:OnCountDown(vars[1]); end end function WB_SelectWeapons:OnClickClose() WidgetManager:ClosePanel(self.UIType) end WB_SelectWeapons.SelectWeaponItemClass = nil; function WB_SelectWeapons:GetItemClass() if self.SelectWeaponItemClass == nil then self.SelectWeaponItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapons/Child/WB_SelectWeaponItems.WB_SelectWeaponItems_C')); end return self.SelectWeaponItemClass; end WB_SelectWeapons.Weapons = nil; function WB_SelectWeapons:SetInitWeapons(InWeapons) if self.ScrollBox_Items == nil then self.Weapons = InWeapons; return ; end table.printTable(InWeapons); UITool.AdaptChildren(self.ScrollBox_Items, table.getCount(InWeapons), self:GetItemClass(), function(Widget, Index) Widget:Init(self, self.OnClickItem); end) local Weapons = {}; for i, v in pairs(InWeapons) do if EnglishNamedWeapon[i] then table.insert(Weapons, { ItemId = EnglishNamedWeapon[i].ItemId, Kill = v; }) end end table.sort(Weapons, function(a, b) return a.Kill < b.Kill; end) UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:SetInitWeapons] Weapons ="), Weapons) UITool.SetItemInfo(self.ScrollBox_Items, "SetWeaponItemInfo", Weapons); end WB_SelectWeapons.SetCount = 0; WB_SelectWeapons.WeaponItems = {}; function WB_SelectWeapons:LoadWeapons(InList) -- 加载有哪些枪 if table.isEmpty(InList) then local AllWeapons = GameState:GetMiniInfo("SelectWeapons"); UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadWeapons] AllWeapons ="), AllWeapons) if table.isEmpty(AllWeapons) then return ; end InList = AllWeapons[LocalPlayerKey]; -- 从列表中加载有哪些武器 UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadWeapons] SelfWeapons ="), InList) if table.isEmpty(InList) then return ; end end local WeaponCount = table.getCount(InList); UITool.HideAllChildren(self.ScrollBox_Items); UITool.AdaptChildren(self.ScrollBox_Items, WeaponCount, ObjectPath.WB_SelectWeaponItems); self.WeaponItems = {}; UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadWeapons] InList ="), InList) UITool.ForeachAllChildren(self.ScrollBox_Items, function(index, Widget) Widget:Init(self, self.OnClickItem); Widget:SetItemId(InList[index]); if InList[index] then Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible); UGCLogSystem.Log("[WB_SelectWeapons:LoadWeapons] InList[index] = %s", tostring(InList[index])); self.WeaponItems[InList[index]] = Widget; end end); end --- 倒计时 function WB_SelectWeapons:OnCountDown(InTime) UGCLogSystem.Log("[WB_SelectWeapons:OnCountDown] InTime = %s", tostring(InTime)); InTime = InTime - 1; self.TextBlock_WeaponSelect:SetText(string.format("%ds", InTime)); GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t) o.TextBlock_WeaponSelect:SetText(string.format("%ds", math.floor(t))); end, 1, InTime, function(o) o:OnClosed(); end); end WB_SelectWeapons.CurrItem = nil; --- 当点击 Item function WB_SelectWeapons:OnClickItem(ChildItem) if self.CurrItem == ChildItem then self:OnClickClose(); return ; end if self.CurrItem ~= nil then self.CurrItem:SetSelect(false); end self.CurrItem = ChildItem; self.CurrItem:SetSelect(true); GameState:SendMiniGameRPC("SelectCurrWeapon", LocalPlayerKey, self.CurrItem:GetItemIds()); self:OnClickClose(); end function WB_SelectWeapons:OnClosed() UGCLogSystem.Log("[WB_SelectWeapons:OnClosed] 当关闭的时候执行") WidgetManager:ClosePanel(self.UIType); if self.CurrItem ~= nil and UE.IsValid(self.CurrItem) then self.ScrollBox_Items:RemoveChild(self.CurrItem); GameState:SendMiniGameRPC("SelectCurrWeapon", LocalPlayerKey, self.CurrItem:GetItemIds()); -- 移除 self.WeaponItems[self.CurrItem:GetItemIds()] = nil; self.CurrItem = nil; else -- 发送 RPC GameState:SendMiniGameRPC("SelectCurrWeapon", LocalPlayerKey, nil); end end function WB_SelectWeapons:OnUpdateSelectWeapons(InList) if table.isEmpty(InList) then return ; end -- 进行加载 UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:OnUpdateSelectWeapons] InList ="), InList) self:LoadWeapons(InList[LocalPlayerKey]); end function WB_SelectWeapons:OnUpdateCurrWeapon(InWeapons) if table.isEmpty(InWeapons) then return ; end if InWeapons[LocalPlayerKey] then return ; end local Item = self.WeaponItems[InWeapons[LocalPlayerKey]]; if Item == nil then return end Item:SetSelect(false) self.ScrollBox_Items:RemoveChild(Item); self.WeaponItems[InWeapons[LocalPlayerKey]] = nil; end WB_SelectWeapons.LastKillCount = 0; function WB_SelectWeapons:OnAllPlayerKDAChange(InList) if table.isEmpty(InList) then return ; end if LocalKillNum == self.LastKillCount then return ; end UITool.ForeachAllChildren(self.ScrollBox_Items, function(index, Widget) Widget:SetKillNum(LocalKillNum); end); self.LastKillCount = LocalKillNum; end -- function WB_SelectWeapons:Tick(MyGeometry, InDeltaTime) -- end -- function WB_SelectWeapons:Destruct() -- end return WB_SelectWeapons;