---@class WB_WeaponConfiguration_C:UUserWidget ---@field CanvasPanel_TelescopeTip UCanvasPanel ---@field CanvasPanel_WeaponInfo UCanvasPanel ---@field Image_WeaponIcon UImage ---@field NewButton_Close UNewButton ---@field NewButton_Close_Old UNewButton ---@field NewButton_Save UNewButton ---@field PartItem_ButtStock UWB_WeaponConfigPartItem_C ---@field PartItem_Grip UWB_WeaponConfigPartItem_C ---@field PartItem_Magazine UWB_WeaponConfigPartItem_C ---@field PartItem_Muzzle UWB_WeaponConfigPartItem_C ---@field PartItem_SubTelescope UWB_WeaponConfigPartItem_C ---@field PartItem_Telescope UWB_WeaponConfigPartItem_C ---@field ScrollBox_SelectParts UScrollBox ---@field TextBlock_Parts UTextBlock ---@field TextBlock_WeaponName UTextBlock ---@field WB_DamageTextButton UWB_DamageTextButton_C ---@field WB_OpenOldWeaponParts UWB_OpenOldWeaponParts_C --Edit Below-- local WB_WeaponConfiguration = { bInitDoOnce = false; PartTypeToPartItem = {}; }; function WB_WeaponConfiguration:Construct() self:LuaInit() end -- function WB_WeaponConfiguration:Tick(MyGeometry, InDeltaTime) -- end -- function WB_WeaponConfiguration:Destruct() -- end function WB_WeaponConfiguration:OnShowPanel(WeaponID) UGCLogSystem.Log("[WB_WeaponConfiguration_OnShowPanel] WeaponI = %s", tostring(WeaponID)); end function WB_WeaponConfiguration:LuaInit() if self.bInitDoOnce then return ; end self.bInitDoOnce = true; WidgetLibrary.BindButtonClicked(self.NewButton_Save, self.ClickSave, self) WidgetLibrary.BindButtonClicked(self.NewButton_Close, self.CloseSelf, self) self.PartTypeToPartItem = { [EWeaponPartType.Telescope] = self.PartItem_Telescope, [EWeaponPartType.Muzzle] = self.PartItem_Muzzle, [EWeaponPartType.Magazine] = self.PartItem_Magazine, [EWeaponPartType.Grip] = self.PartItem_Grip, [EWeaponPartType.ButtStock] = self.PartItem_ButtStock, [EWeaponPartType.SubTelescope] = self.PartItem_SubTelescope, } UGCEventSystem.AddListener(EventTypes.PlayerChangeWeapon, self.OnPlayerChangeWeapon, self) -- 设置配件类型 for PartType, Item in pairs(self.PartTypeToPartItem) do Item:LuaInit() Item:SetPartType(PartType) Item:BindSelectCallBack(self.ClickPart, self) end for i = 1, self.ScrollBox_SelectParts:GetChildrenCount() do local Item = self.ScrollBox_SelectParts:GetChildAt(i - 1) Item:LuaInit() Item:SetSelectStyle(1) Item:BindSelectCallBack(self.ClickSelectPart, self) end self.WB_OpenOldWeaponParts:LuaInit(); end function WB_WeaponConfiguration:CloseSelf() WidgetManager:ClosePanel(WidgetConfig.EUIType.WeaponConfiguration) end function WB_WeaponConfiguration:ClickSave() local WeaponParts = self:GetAllParts() local WeaponID = self.WeaponID local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(LocalPlayerKey); if UE.IsValidPawn(Pawn) then -- 发送 RPC UnrealNetwork.CallUnrealRPC(LocalPlayerController, Pawn, "UpdateWeaponParts", WeaponID, WeaponParts); UGCLogSystem.Log("[WB_WeaponConfiguration:ClickSave] 发送RPC WeaponID = %s", tostring(WeaponID)); UGCLogSystem.LogTree(string.format("[WB_WeaponConfiguration:ClickSave] WeaponParts ="), WeaponParts); end -- 关闭该UI self:CloseSelf() end function WB_WeaponConfiguration:GetWeaponID() return self.WeaponID end function WB_WeaponConfiguration:SetWeaponID(WeaponID) UGCLogSystem.Log("[WB_WeaponConfiguration:SetWeaponID] WeaponID = %s", tostring(WeaponID)); self.WeaponID = WeaponID local WeaponParts = MyWeaponSystem.GetWeaponBastParts(self.WeaponID) local Parts = nil; if not table.isEmpty(ArchiveTable[LocalPlayerKey]) and not table.isEmpty(ArchiveTable[LocalPlayerKey].Weapons) then Parts = ArchiveTable[LocalPlayerKey].Weapons[self.WeaponID]; end if not table.isEmpty(Parts) then WeaponParts = Parts; end UGCLogSystem.Log("[WB_WeaponConfiguration:SetWeaponID] 输出 WeaponParts") table.printTable(WeaponParts); --UGCLogSystem.LogTree("[WB_WeaponConfiguration_SetWeaponID]", WeaponParts) local WeaponPartsMap = MyWeaponSystem.PartListToPartMap(WeaponParts) local UpdateSelectPartsOnce = false if WeaponSuits[WeaponID] then for i, v in pairs(WeaponSuits[WeaponID]) do if WeaponPartsMap[i] == nil then WeaponPartsMap[i] = 0 end end end for PartType, Item in pairs(self.PartTypeToPartItem) do local ItemID = WeaponPartsMap[PartType] Item:SetItemID(ItemID) if PartType == EWeaponPartType.Telescope then if ItemID == nil then self.CanvasPanel_TelescopeTip:SetVisibility(ESlateVisibility.Collapsed) else self.CanvasPanel_TelescopeTip:SetVisibility(ESlateVisibility.HitTestInvisible) end end -- 设置当前默认选择的Part if ItemID and not UpdateSelectPartsOnce then UpdateSelectPartsOnce = true self:SetSelectPartType(PartType) end end if not UpdateSelectPartsOnce then self:SetSelectPartType(nil) end --MyWeaponSystem.AsyncLoadItemBigIconToBrush(self.WeaponID, self.Image_WeaponIcon) MyWeaponSystem.AsyncLoadItemWhiteIconToBrush(self.WeaponID, self.Image_WeaponIcon) self.TextBlock_WeaponName:SetText(MyWeaponSystem.GetItemName(self.WeaponID)) end function WB_WeaponConfiguration:ClickPart(PartID, PartType) -- local PartType = MyWeaponSystem.GetPartType(PartID) self:SetSelectPartType(PartType) end --- 设置选择修改的类型 function WB_WeaponConfiguration:SetSelectPartType(InPartType) UGCLogSystem.Log("[WB_WeaponConfiguration_SetSelectPartType] InPartType:%s", tostring(InPartType)) self.SelectPartType = InPartType; local ItemID = -1 if self.PartTypeToPartItem[InPartType] then ItemID = self.PartTypeToPartItem[InPartType]:GetItemID() end local Info = WeaponTypeName[InPartType] --UGCLogSystem.LogTree(string.format("[WB_WeaponConfiguration:SetSelectPartType] Info ="), Info) if Info then self.TextBlock_Parts:SetText('配件:' .. Info.Chinese); else self.TextBlock_Parts:SetText('可装配配件'); end local Parts = MyWeaponSystem.GetWeaponCanUsePartFromPartType(self.WeaponID, InPartType) UGCLogSystem.LogTree("[WB_WeaponConfiguration_SetSelectPartType]", Parts) for i = 1, self.ScrollBox_SelectParts:GetChildrenCount() do local Item = self.ScrollBox_SelectParts:GetChildAt(i - 1) if i == 1 then -- 在这里修改 这里默认取消配件为 0,就是不装这个配件 不能改成负数 Item:SetItemID(0) Item:SetIsSelect(ItemID == 0) else Item:SetItemID(Parts[i - 1]) Item:SetIsSelect(ItemID == Parts[i - 1]) end end for PartType, Item in pairs(self.PartTypeToPartItem) do Item:SetIsSelect(InPartType == PartType) end end --- 修改显示的配件 function WB_WeaponConfiguration:ClickSelectPart(PartID) UGCLogSystem.Log("[WB_WeaponConfiguration_ClickSelectPart] PartID:%s, PartType:%s", tostring(PartID), tostring(PartType)) --local PartType = MyWeaponSystem.GetPartType(PartID) local PartItem = self.PartTypeToPartItem[self.SelectPartType] if PartItem then PartItem:SetItemID(PartID) -- 设置已选择 for i = 1, self.ScrollBox_SelectParts:GetChildrenCount() do local Item = self.ScrollBox_SelectParts:GetChildAt(i - 1) Item:SetIsSelect(PartID == Item:GetItemID()) end end end --- 获取当前修改后的配件信息 function WB_WeaponConfiguration:GetAllParts() local Res = {} for PartType, Item in pairs(self.PartTypeToPartItem) do local ItemID = Item:GetItemID() if ItemID and MyWeaponSystem.IsWeaponPartValid(ItemID) then Res[#Res + 1] = ItemID end end return Res end function WB_WeaponConfiguration:UpdateCurrWeapon(WeaponIDs) UGCLogSystem.LogTree("[WB_WeaponConfiguration_UpdateCurrWeapon]", WeaponIDs) if WeaponIDs[LocalPlayerKey] then self:SetWeaponID(WeaponIDs[LocalPlayerKey]); end end ---@param Weapon ASTExtraShootWeapon function WB_WeaponConfiguration:OnPlayerChangeWeapon(InPawn, Slot, Weapon) UGCLogSystem.Log("[WB_WeaponConfiguration:OnPlayerChangeWeapon] 玩家改变武器, Slot = %s", tostring(Slot)); if Weapon and Weapon then self:SetWeaponID(Weapon:GetWeaponItemID()); end end return WB_WeaponConfiguration;