---@class WB_CustomWeapon_C:UUserWidget ---@field HorizontalBox_WeaponType UHorizontalBox ---@field NewButton_Close UNewButton ---@field NewButton_Reset UNewButton ---@field NewButton_Save UNewButton ---@field UniformGridPanel_SelectWeapon UUniformGridPanel ---@field VerticalBox_WeaponSocket UVerticalBox --Edit Below-- local WB_CustomWeapon = { bInitDoOnce = false; WeaponComb = {}; -- {WeaponID1, WeaponID2 SelectSaveWeaponItemCol = 4; WeaponSocketItems = {}; IsChange = false; } function WB_CustomWeapon:Construct() if GlobalConfigs.GameSetting.CanCustomWeapon then self:LuaInit() end end function WB_CustomWeapon:LuaInit() if self.bInitDoOnce then return; end self.bInitDoOnce = true; UGCLogSystem.Log("[WB_CustomWeapon_LuaInit]") -- 按键初始化 WidgetLibrary.BindButtonClicked(self.NewButton_Reset, self.ResetWeaponComb, self) WidgetLibrary.BindButtonClicked(self.NewButton_Save, self.SaveWeaponComb, self) WidgetLibrary.BindButtonClicked(self.NewButton_Close, self.ClickClose, self) local LocalPC = UGCSystemLibrary.GetLocalPlayerController() -- 武器类型中最大可选择的的武器数量 local MaxSelectItemCount = 0 -- 加载剪影的table local TableObjName = "/Game/CSV/BattleItem" local TableObj = UGCSystemLibrary.LoadAsset(TableObjName, true) local TableObjIsValid = UE.IsValid(TableObj) -- 武器类型选择的Item在水平框中的对齐方式 local WeaponTypeSlateChildSize = UE.CreateStruct("SlateChildSize"); WeaponTypeSlateChildSize.SizeRule = ESlateSizeRule.Fill for i, v in pairs(WeaponSelectionCombinationConfig.PlayerCustomWeapon) do -- 设置一下最大的选择武器Item数量 MaxSelectItemCount = math.max(MaxSelectItemCount, #v.WeaponIDs) -- 加载图片 for _, WeaponID in pairs(v.WeaponIDs) do -- 加载剪影 if TableObjIsValid then local ImageIconPath = STExtraBlueprintFunctionLibrary.GetTableData_FName(TableObj, self.WeaponID, "ItemWhiteIcon_n") UGCSystemLibrary.AsyncLoadAsset(ImageIconPath, nil, nil, true) end local ItemInfo = UGCItemSystem.GetItemData(WeaponID) if ItemInfo then UGCSystemLibrary.AsyncLoadAsset(ItemInfo.ItemBigIcon_n, nil, nil, true) end end -- 初始化武器类型 local WeaponTypeItem = nil if self.HorizontalBox_WeaponType:GetChildrenCount() < i then WeaponTypeItem = UserWidget.NewWidgetObjectBP(LocalPC, self:GetWeaponTypeItemClass()); self.HorizontalBox_WeaponType:AddChild(WeaponTypeItem) -- 设置对齐方式 local TargetHorizontalBoxSlot = WidgetLayoutLibrary.SlotAsHorizontalBoxSlot(WeaponTypeItem) TargetHorizontalBoxSlot:SetSize(WeaponTypeSlateChildSize) else WeaponTypeItem = self.HorizontalBox_WeaponType:GetChildAt(i - 1) end WeaponTypeItem:SetIndex(i) WeaponTypeItem:BindClickSelect(self.SelectWeaponType, self) end -- 隐藏多余武器选择项 for i = #WeaponSelectionCombinationConfig.PlayerCustomWeapon + 1, self.HorizontalBox_WeaponType:GetChildrenCount() do local WeaponTypeItem = self.HorizontalBox_WeaponType:GetChildAt(i - 1) WeaponTypeItem:SetVisibility(ESlateVisibility.Collapsed) end -- 初始化武器槽UI for i = 1, self.VerticalBox_WeaponSocket:GetChildrenCount() do local Item = self.VerticalBox_WeaponSocket:GetChildAt(i - 1) self.WeaponSocketItems[i] = Item Item:SetIndex(i) Item:BindClickSelect(self.SelectWeaponSocket, self) end -- 初始化武器选择Item for i = 1, MaxSelectItemCount do local Item = nil; if self.UniformGridPanel_SelectWeapon:GetChildrenCount() < i then Item = UserWidget.NewWidgetObjectBP(LocalPC, self:GetSelectSaveWeaponItemClass()); self.UniformGridPanel_SelectWeapon:AddChild(Item) local TargetUniformGridSlot = WidgetLayoutLibrary.SlotAsUniformGridSlot(Item) -- 居中 TargetUniformGridSlot:SetVerticalAlignment(EVerticalAlignment.VAlign_Center) TargetUniformGridSlot:SetHorizontalAlignment(EHorizontalAlignment.HAlign_Center) -- 设置索引 TargetUniformGridSlot:SetColumn((i - 1) % self.SelectSaveWeaponItemCol) TargetUniformGridSlot:SetRow((i - 1) // self.SelectSaveWeaponItemCol) else Item = self.UniformGridPanel_SelectWeapon:GetChildAt(i - 1) Item:SetVisibility(ESlateVisibility.HitTestInvisible) end Item:SetIndex(i) Item:BindClickSelect(self.ClickSelectSaveWeapon, self) end UGCLogSystem.Log("[WB_CustomWeapon_LuaInit] Finish") end function WB_CustomWeapon:OnShowPanel(ProgrammeIndex) UGCLogSystem.Log("[WB_CustomWeapon_OnShowPanel]") -- 设置配置索引 self:SetProgrammeIndex(ProgrammeIndex) UGCLogSystem.Log("[WB_CustomWeapon_OnShowPanel] Finish") end function WB_CustomWeapon:GetSelectSaveWeaponItemClass() if self.SelectSaveWeaponClass == nil then self.SelectSaveWeaponClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapon/SaveCustomWeaponItem/WB_SelectSaveWeapon.WB_SelectSaveWeapon_C')) end return self.SelectSaveWeaponClass end function WB_CustomWeapon:GetWeaponTypeItemClass() if self.WeaponTypeItemClass == nil then self.WeaponTypeItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapon/SaveCustomWeaponItem/WB_WeaponType.WB_WeaponType_C')) end return self.WeaponTypeItemClass end --- 设置配置ID function WB_CustomWeapon:SetProgrammeIndex(InProgrammeIndex) self.ProgrammeIndex = InProgrammeIndex local SavedWeaponComb = ArchiveDataConfig.GetPlayerArchiveDataFromType(UGCSystemLibrary.GetLocalPlayerKey(), ArchiveDataConfig.EArchiveType.WeaponComb) if SavedWeaponComb and SavedWeaponComb[self.ProgrammeIndex] then self.WeaponComb = SavedWeaponComb[self.ProgrammeIndex] else local WeaponCombinationType = UGCGameSystem.GameState:GetPlayerWeaponCombination(UGCSystemLibrary.GetLocalPlayerKey()) local CombinationList = WeaponSelectionCombinationConfig.WeaponCombinationList[WeaponCombinationType].Weapon if CombinationList and CombinationList[self.ProgrammeIndex] then self.WeaponComb = CombinationList[self.ProgrammeIndex] end end for i = #self.WeaponComb, 1, -1 do self:SetSelectWeapon(i, self.WeaponComb[i], (i == 1)) end end --- 点击选择插槽 function WB_CustomWeapon:SelectWeaponSocket(Index) if self.SelectWeaponSocketID ~= Index then self.SelectWeaponSocketID = Index local WeaponSocketItem = self.WeaponSocketItems[self.SelectWeaponSocketID] if WeaponSocketItem then self:SetSelectWeapon(self.SelectWeaponSocketID, WeaponSocketItem:GetWeaponID(), true) end end end --- 点击选择武器类型 function WB_CustomWeapon:SelectWeaponType(Index) if self.WeaponTypeIndex ~= Index then self.WeaponTypeIndex = Index for i = 1, self.HorizontalBox_WeaponType:GetChildrenCount() do local WeaponTypeItem = self.HorizontalBox_WeaponType:GetChildAt(i - 1) WeaponTypeItem:SetSelect(i == self.WeaponTypeIndex) end local CustomWeaponInfo = WeaponSelectionCombinationConfig.PlayerCustomWeapon[self.WeaponTypeIndex] if CustomWeaponInfo then for i = 1, self.UniformGridPanel_SelectWeapon:GetChildrenCount() do local WeaponID = CustomWeaponInfo.WeaponIDs[i] local WeaponItem = self.UniformGridPanel_SelectWeapon:GetChildAt(i - 1) if WeaponID then WeaponItem:SetWeaponID(WeaponID) WeaponItem:SetVisibility(ESlateVisibility.SelfHitTestInvisible) else WeaponItem:SetVisibility(ESlateVisibility.Collapsed) end end end end end --- 点击选择武器 function WB_CustomWeapon:ClickSelectSaveWeapon(Index) self.IsChange = true self:SelectSaveWeapon(Index) end function WB_CustomWeapon:SelectSaveWeapon(Index) local WeaponItem = self.UniformGridPanel_SelectWeapon:GetChildAt(Index - 1) local WeaponID = WeaponItem:GetWeaponID() for i = 1, self.UniformGridPanel_SelectWeapon:GetChildrenCount() do local TempWeaponItem = self.UniformGridPanel_SelectWeapon:GetChildAt(i - 1) TempWeaponItem:SetSelect(Index == i) end self:SetSelectWeapon(self.SelectWeaponSocketID, WeaponID, false) end --- 设置插槽内的武器 ---@param SocketID uint 插槽的索引 只有1和2 ---@param bUpdateSelectWeaponBar bool 是否更新武器选择栏 function WB_CustomWeapon:SetSelectWeapon(SocketID, WeaponID, bUpdateSelectWeaponBar) if bUpdateSelectWeaponBar then self.SelectWeaponSocketID = SocketID for i, v in pairs(self.WeaponSocketItems) do v:SetSelect(i == SocketID) end -- 获取武器ID类型和索引 local CustomWeaponTypeIndex = -1 local CustomWeaponIndex = -1; for WeaponTypeIndex, v in pairs(WeaponSelectionCombinationConfig.PlayerCustomWeapon) do -- 加载图片 for WeaponIndex, TempWeaponID in pairs(v.WeaponIDs) do if TempWeaponID == WeaponID then CustomWeaponIndex = WeaponIndex CustomWeaponTypeIndex = WeaponTypeIndex end end if CustomWeaponTypeIndex > 0 then break end end -- 更新选择栏 self:SelectWeaponType(CustomWeaponTypeIndex) self:SelectSaveWeapon(CustomWeaponIndex) else local SocketItem = self.WeaponSocketItems[SocketID] if SocketItem then SocketItem:SetWeaponID(WeaponID) end end end --- 重置武器配置 function WB_CustomWeapon:ResetWeaponComb() local WeaponCombinationType = UGCGameSystem.GameState:GetPlayerWeaponCombination(UGCSystemLibrary.GetLocalPlayerKey()) local CombinationList = WeaponSelectionCombinationConfig.WeaponCombinationList[WeaponCombinationType].Weapon if CombinationList and CombinationList[self.ProgrammeIndex] then local Comb = CombinationList[self.ProgrammeIndex] for i = #Comb, 1, -1 do self:SetSelectWeapon(i, Comb[i], (i == 1)) end end end function WB_CustomWeapon:SaveWeaponComb() local WeaponComb = {} for i, v in pairs(self.WeaponSocketItems) do WeaponComb[i] = v:GetWeaponID() end UGCLogSystem.LogTree("[WB_CustomWeapon_SaveWeaponComb]WeaponComb:", WeaponComb) -- 保存操作 UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerCustomWeapon", UGCSystemLibrary.GetLocalPlayerKey(), self.ProgrammeIndex, WeaponComb) -- 关闭UI self:CloseSelf() end function WB_CustomWeapon:ClickClose() if self.IsChange then local SecondaryConfirmationWidget = WidgetManager:GetPanel(WidgetConfig.EUIType.SecondaryConfirmation) SecondaryConfirmationWidget:SetTextInfo("该配置还未保存,是否保存后关闭页面?", "关闭", "保存") SecondaryConfirmationWidget:BindCancellationCallBack(self.CloseSelf, self) SecondaryConfirmationWidget:BindConfirmCallBack(self.SaveWeaponComb, self) WidgetManager:ShowPanel(WidgetConfig.EUIType.SecondaryConfirmation, false) else self:CloseSelf() end end function WB_CustomWeapon:CloseSelf() WidgetManager:ClosePanel(WidgetConfig.EUIType.CustomWeapon) self.IsChange = false end -- function WB_CustomWeapon:Tick(MyGeometry, InDeltaTime) -- end -- function WB_CustomWeapon:Destruct() -- end return WB_CustomWeapon