---@class WB_Backpack1_C:UUserWidget ---@field Button_Select UButton ---@field HorizontalBox_Bombs UHorizontalBox ---@field HorizontalBox_Defences UHorizontalBox ---@field HorizontalBox_Medication UHorizontalBox ---@field ScrollBox_Items UScrollBox ---@field TextBlock_WeaponSelect UTextBlock --Edit Below-- ---@type WB_Backpack1_C local WB_Backpack1 = { bInitDoOnce = false; }; WB_Backpack1.CurrClickItem = nil; WB_Backpack1.SelectWeapons = nil; WB_Backpack1.IntervalTime = 0.5; function WB_Backpack1:Construct() UITool.BindButtonClicked(self.Button_Select, self.OnClickSelect, self) end function WB_Backpack1:OnShowPanel(...) -- 这个是没有的 self:OnCloseCountDown(); local SoldierType = UGCGameSystem.GameState.PlayerSoldierType[LocalPlayerKey]; UGCLogSystem.Log("[WB_Backpack1:OnShowPanel] %s", tostring(SoldierType)); if SoldierType == nil then return; end self:FillWeapons(SoldierType); self:FillBombs(SoldierType); self:FillMedications(SoldierType); self:SetDefences(SoldierType); UITool.ButtonSetEnable(self.Button_Select, true); end function WB_Backpack1:FillWeapons(InType) local WeaponLimits = SoldierConfig.WeaponLimits[InType]; local Count = SoldierConfig.WeaponCount[InType] local WeaponSelect = {}; if Count == 1 then for Index, TypeNew in pairs(WeaponLimits) do local Weapons = GetWeaponListByTypeNew(TypeNew, WeaponTable); -- 检查是一把武器还是两把武器 for _, WeaponId in pairs(Weapons) do WeaponSelect[#WeaponSelect + 1] = { WeaponId }; end end elseif Count == 2 then WeaponSelect = SoldierConfig.WeaponSet[InType] end self:FillWeaponItems(WeaponSelect); end function WB_Backpack1:FillWeaponItems(InWeapons) -- 设置数据进去 UGCLogSystem.LogTree(string.format("[WB_Backpack1:FillWeaponItems] InWeapons ="), InWeapons) local ItemCount = UITool.GetChildrenCount(self.ScrollBox_Items); local WeaponCount = table.getCount(InWeapons); if WeaponCount > ItemCount then local TheCount = WeaponCount - ItemCount; for i = 1, TheCount do UITool.AddWidgetItem(self.ScrollBox_Items, ObjectPath.WB_Backpack_Item1, self); end end for i = 1, UITool.GetChildrenCount(self.ScrollBox_Items) do local Item = self.ScrollBox_Items:GetChildAt(i - 1); local Weapon = InWeapons[i]; if Weapon ~= nil then if Item.bInitDoOnce then Item:SetParent(self, self.OnClickCallback); Item:SetWeaponIds(Weapon); else Item.Weapons = Weapon; Item.ParentWidget = self; Item.OnClickFunc = self.OnClickCallback; end else Item:SetVisibility(ESlateVisibility.Collapsed); end if i == 1 then self:OnClickCallback(Item) end end end function WB_Backpack1:OnCloseCountDown() self.CloseTime = DefaultSettings.SelectWeaponShowTime; if self.OnCloseTimer ~= nil then UGCEventSystem.StopTimer(self.OnCloseTimer); self.OnCloseTimer = nil; end -- 关闭页面 self.OnCloseTimer = UGCEventSystem.SetTimerLoop(self, function() self.CloseTime = self.CloseTime - self.IntervalTime; self.TextBlock_WeaponSelect:SetText(tostring(math.floor(self.CloseTime - 1))..'s'); if self.CloseTime <= 1 then if self.OnCloseTimer ~= nil then UGCEventSystem.StopTimer(self.OnCloseTimer); WidgetManager:ClosePanel(WidgetConfig.EUIType.Backpack); end end end, self.IntervalTime); end function WB_Backpack1:ClearItemsSelect() for i = 1, UITool.GetChildrenCount(self.ScrollBox_Items) do local Item = self.ScrollBox_Items:GetChildAt(i - 1); Item:SetIsSelect(false); end end -- function WB_Backpack1:Tick(MyGeometry, InDeltaTime) -- end -- function WB_Backpack1:Destruct() -- end function WB_Backpack1:OnClickSelect() -- 发送选择的武器 if table.isEmpty(self.SelectWeapons) then return; end UGCSendRPCSystem.ActorRPCNotify(nil, LocalPlayerController, "Server_SelectWeapons", self.SelectWeapons) UITool.ButtonSetEnable(self.Button_Select, false); SoundSystem.PlaySound(SoundSystem.ESound.OK) --WidgetManager:ClosePanel(WidgetConfig.EUIType.Backpack); end ---填充药品 ---@param InType ESoldierType 兵种类型 function WB_Backpack1:FillMedications(InType) self:FillInternalBox(InType, self.HorizontalBox_Medication, SoldierConfig.Medications); end ---填充炸弹 ---@param InType ESoldierType 兵种类型 function WB_Backpack1:FillBombs(InType) self:FillInternalBox(InType, self.HorizontalBox_Bombs, SoldierConfig.Bombs); end ---@private ---@param InType ESoldierType 兵种类型 ---@param InBox UHorizontalBox ---@param InTable table> function WB_Backpack1:FillInternalBox(InType, InBox, InTable) local Table = InTable[InType] local Num = 0; for Id, Count in pairs(Table) do if Count > 0 then local Item = InBox:GetChildAt(Num); Item:SetVisibility(ESlateVisibility.Visible); Item:SetOtherItemType(Id, Count); Num = Num + 1; end end for i = Num, UITool.GetChildrenCount(InBox) - 1 do local Item = InBox:GetChildAt(i); Item:SetVisibility(ESlateVisibility.Collapsed); end end function WB_Backpack1:SetDefences(InType) local Func = function(InVal, InIndex) local HelmetItem = self.HorizontalBox_Defences:GetChildAt(InIndex); if InVal == nil then HelmetItem:SetVisibility(ESlateVisibility.Collapsed); else HelmetItem:SetVisibility(ESlateVisibility.Visible); HelmetItem:SetOtherItemType(InVal); end end Func(SoldierConfig.DefenceItems[InType].Helmet, 0); Func(SoldierConfig.DefenceItems[InType].Armor, 1); end ---@param InItem WB_Backpack_Item1_C function WB_Backpack1:OnClickCallback(InItem) if self.CurrClickItem ~= nil then self.CurrClickItem:SetIsSelect(false); end self.CurrClickItem = InItem; InItem:SetIsSelect(true); self.SelectWeapons = InItem.Weapons; -- 设置为选择 self:OnClickSelect(); end return WB_Backpack1;