---@class WB_WeaponSelect_C:UUserWidget ---@field Button_Custom UNewButton ---@field Button_Select UNewButton ---@field ScrollBox_Weapons UScrollBox ---@field TextBlock_Time UTextBlock ---@field UniformGridPanel_OtherParts UUniformGridPanel --Edit Below-- local WB_WeaponSelect = { bInitDoOnce = false; CombinationType = 1; ShowTime = 0; SelectWeaponIndex = 1; OtherPartsItemColNum = 6; }; function WB_WeaponSelect:Construct() UGCEventSystem.AddListener(EventEnum.PlayerWeaponCombinationUpdate, self.UpdateWeaponCombination, self) WidgetLibrary.BindButtonClicked(self.Button_Select, self.SelectWeapon, self) self:UpdateWeaponCombination() -- 判断是否可以修改配置 if GlobalConfigs.GameSetting.CanCustomWeapon then WidgetLibrary.BindButtonClicked(self.Button_Custom, self.CustomWeaponComb, self) else self.Button_Custom:SetVisibility(ESlateVisibility.Collapsed) end end function WB_WeaponSelect:OnShowPanel() if self.SelectTimeHandle then UGCEventSystem.StopTimer(self.SelectTimeHandle) end self.ShowTime = GlobalConfigs.GameSetting.WeaponSelectTime self.TextBlock_Time:SetText(self.ShowTime) self.SelectTimeHandle = UGCEventSystem.SetTimerLoop(self, self.SelectTimeClock, 1) end function WB_WeaponSelect:SelectTimeClock() self.ShowTime = self.ShowTime - 1 if self.ShowTime <= 0 then UGCEventSystem.StopTimer(self.SelectTimeHandle) self.SelectTimeHandle = nil WidgetManager:ClosePanel(WidgetConfig.EUIType.WeaponSelect) else self.TextBlock_Time:SetText(self.ShowTime) end end function WB_WeaponSelect:GetWeaponItemClass() if self.ItemClass == nil then self.ItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapon/Item/WB_WeaponSelectItem.WB_WeaponSelectItem_C')) end return self.ItemClass end function WB_WeaponSelect:GetOtherPartItemClass() if self.OtherItemClass == nil then self.OtherItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapon/Item/WB_OtherPartItem.WB_OtherPartItem_C')) end return self.OtherItemClass end function WB_WeaponSelect:UpdateWeaponCombination() local WeaponCombinationType = UGCGameSystem.GameState:GetPlayerWeaponCombination(UGCSystemLibrary.GetLocalPlayerKey()) if WeaponCombinationType ~= self.WeaponCombinationType then UGCLogSystem.Log("[WB_WeaponSelect_UpdateWeaponCombination] LastWeaponCombinationType:%s, NowWeaponCombinationType:%s", tostring(self.WeaponCombinationType), tostring(WeaponCombinationType)) self.WeaponCombinationType = WeaponCombinationType local WeaponCombinationInfo = WeaponSelectionCombinationConfig.WeaponCombinationList[WeaponCombinationType] for i = 1, self.ScrollBox_Weapons:GetChildrenCount() do local Item = self.ScrollBox_Weapons:GetChildAt(i - 1) Item:Init(WeaponCombinationType, i) end for i = self.ScrollBox_Weapons:GetChildrenCount() + 1, #WeaponCombinationInfo.Weapon do local Item = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetWeaponItemClass()); if Item then self.ScrollBox_Weapons:AddChild(Item) Item:Init(WeaponCombinationType, i) Item:BindSelectCallBack(self.SelectWeaponItem, self) end end for i = #WeaponCombinationInfo.Weapon, self.ScrollBox_Weapons:GetChildrenCount() - 1 do local Item = self.ScrollBox_Weapons:GetChildAt(i) Item:SetVisibility(ESlateVisibility.Collapsed) end for i, ItemInfo in pairs(WeaponCombinationInfo.OtherParts) do local Item if self.UniformGridPanel_OtherParts:GetChildrenCount() < i then Item = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetOtherPartItemClass()); self.UniformGridPanel_OtherParts:AddChild(Item) local TargetUniformGridSlot = WidgetLayoutLibrary.SlotAsUniformGridSlot(Item) -- 居中 TargetUniformGridSlot:SetVerticalAlignment(EVerticalAlignment.VAlign_Center) TargetUniformGridSlot:SetHorizontalAlignment(EHorizontalAlignment.HAlign_Center) -- 设置索引 TargetUniformGridSlot:SetColumn((i - 1) % self.OtherPartsItemColNum) TargetUniformGridSlot:SetRow((i - 1) // self.OtherPartsItemColNum) else Item = self.UniformGridPanel_OtherParts:GetChildAt(i - 1) Item:SetVisibility(ESlateVisibility.HitTestInvisible) end Item:SetItemID(ItemInfo.ItemID, ItemInfo.Count) end for i = #WeaponCombinationInfo.OtherParts, self.UniformGridPanel_OtherParts:GetChildrenCount() - 1 do local Item = self.UniformGridPanel_OtherParts:GetChildAt(i) Item:SetVisibility(ESlateVisibility.Collapsed) end self:SelectWeaponItem(1) end end function WB_WeaponSelect:SelectWeaponItem(InIndex) self.SelectWeaponIndex = InIndex for i = 1, self.ScrollBox_Weapons:GetChildrenCount() do local Item = self.ScrollBox_Weapons:GetChildAt(i - 1) Item:SetSelect(Item:GetCombinationIndex() == InIndex) end end function WB_WeaponSelect:SelectWeapon() UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerSelectWeaponIndex", UGCSystemLibrary.GetLocalPlayerKey(), self.SelectWeaponIndex) WidgetManager:ClosePanel(WidgetConfig.EUIType.WeaponSelect) end function WB_WeaponSelect:CustomWeaponComb() WidgetManager:ShowPanel(WidgetConfig.EUIType.CustomWeapon, false, self.SelectWeaponIndex) WidgetManager:ClosePanel(WidgetConfig.EUIType.WeaponSelect) end -- function WB_WeaponSelect:Tick(MyGeometry, InDeltaTime) -- end -- function WB_WeaponSelect:Destruct() -- end return WB_WeaponSelect;