---@class WB_SaveOtherWeaponItem_C:UUserWidget ---@field CanvasPanel_SelectPartsPanel UCanvasPanel ---@field CanvasPanel_WeaponInfo UCanvasPanel ---@field HorizontalBox_Part UHorizontalBox ---@field Image_IsSelect UImage ---@field Image_WeaponIcon UImage ---@field NewButton_Select UNewButton ---@field ScrollBox_SelectParts UScrollBox ---@field TextBlock_WeaponName UTextBlock --Edit Below-- local WB_SaveOtherWeaponItem = { bInitDoOnce = false; PartTypeToPartItem = {}; IsSelected = false; }; --[==[ Construct function WB_SaveOtherWeaponItem:Construct() end -- Construct ]==] -- function WB_SaveOtherWeaponItem:Tick(MyGeometry, InDeltaTime) -- end -- function WB_SaveOtherWeaponItem:Destruct() -- end function WB_SaveOtherWeaponItem:LuaInit() if self.bInitDoOnce then return ; end self.bInitDoOnce = true; WidgetLibrary.BindButtonClicked(self.NewButton_Select, self.ClickSelect, self) -- 设置配件类型 for i = 1, self.HorizontalBox_Part:GetChildrenCount() do local Item = self.HorizontalBox_Part:GetChildAt(i - 1) Item:LuaInit() Item:SetPartType(PartTypeDisplayOrder[i]) Item:BindSelectCallBack(self.ClickPart, self) if PartTypeDisplayOrder[i] then self.PartTypeToPartItem[PartTypeDisplayOrder[i]] = Item end 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 UGCEventSystem.AddListener(EventTypes.UpdateWeapons, self.OnUpdateWeapons, self) end function WB_SaveOtherWeaponItem:OnUpdateWeapons(WeaponID) UGCLogSystem.Log("[WB_SaveWeaponItem:OnUpdateWeapons] WeaponID = %d", WeaponID); self:SetWeaponID(self.WeaponID); end function WB_SaveOtherWeaponItem:SetIndex(InIndex) self.Index = InIndex self:LuaInit() end function WB_SaveOtherWeaponItem:GetIndex() return self.Index end function WB_SaveOtherWeaponItem:BindClickSelect(Func, Obj) self.SelectCallBackFunc = Func self.SelectCallBackObj = Obj end function WB_SaveOtherWeaponItem:ClickSelect() -- UGCLogSystem.Log("[WB_BuffSelectItem_ClickSelect]") if self.SelectCallBackFunc then if self.SelectCallBackObj then self.SelectCallBackFunc(self.SelectCallBackObj, self:GetIndex()) else self.SelectCallBackFunc(self:GetIndex()) end end end function WB_SaveOtherWeaponItem:SetSelect(IsSelect) if self.IsSelected ~= IsSelect then self.IsSelected = IsSelect if IsSelect then self.Image_IsSelect:SetVisibility(ESlateVisibility.SelfHitTestInvisible); --self.CanvasPanel_SelectPartsPanel:SetVisibility(ESlateVisibility.SelfHitTestInvisible); else self.Image_IsSelect:SetVisibility(ESlateVisibility.Collapsed); --self.CanvasPanel_SelectPartsPanel:SetVisibility(ESlateVisibility.Collapsed); -- self:SetSelectPartType(nil) end end end function WB_SaveOtherWeaponItem:GetWeaponID() return self.WeaponID end function WB_SaveOtherWeaponItem:SetWeaponID(WeaponID) self.WeaponID = WeaponID local WeaponParts = MyWeaponSystem.GetWeaponBastParts(self.WeaponID) -- 在这里修改 获取存档中的武器配件存档 CustomWeaponParts = {[WeaponID] = {PartID, PartID, PartID, ...}, ...} -- local CustomWeaponParts = ArchiveDataConfig.GetPlayerArchiveDataFromType(UGCSystemLibrary.GetLocalPlayerKey(), ArchiveDataConfig.EArchiveType.CustomWeaponParts) local CustomWeaponParts = nil if not table.isEmpty(ArchiveTable[LocalPlayerKey]) then CustomWeaponParts = ArchiveTable[LocalPlayerKey].Weapons end if CustomWeaponParts and CustomWeaponParts[self.WeaponID] then WeaponParts = CustomWeaponParts[self.WeaponID] end local WeaponPartsMap = MyWeaponSystem.PartListToPartMap(WeaponParts) local UpdateSelectPartsOnce = false for i = 1, self.HorizontalBox_Part:GetChildrenCount() do local Item = self.HorizontalBox_Part:GetChildAt(i - 1) local PartType = Item:GetPartType() local ItemID = WeaponPartsMap[PartType] Item:SetItemID(ItemID) -- 设置当前默认选择的Part if ItemID and not UpdateSelectPartsOnce then UpdateSelectPartsOnce = true self:SetSelectPartType(PartType) end end if not UpdateSelectPartsOnce then self:SetSelectPartType(nil) end MyWeaponSystem.AsyncLoadItemSmallIconToBrush(self.WeaponID, self.Image_WeaponIcon) self.TextBlock_WeaponName:SetText(MyWeaponSystem.GetItemName(self.WeaponID)) end function WB_SaveOtherWeaponItem:SetVisWeaponInfo(IsVis) if IsVis then self.CanvasPanel_WeaponInfo:SetVisibility(ESlateVisibility.HitTestInvisible) else self.CanvasPanel_WeaponInfo:SetVisibility(ESlateVisibility.Hidden) end end function WB_SaveOtherWeaponItem:ClickPart(PartID) if self.IsSelected then local PartType = MyWeaponSystem.GetPartType(PartID) self:SetSelectPartType(PartType) else self:ClickSelect() end end --- 设置选择修改的类型 function WB_SaveOtherWeaponItem:SetSelectPartType(InPartType) UGCLogSystem.Log("[WB_SaveOtherWeaponItem_SetSelectPartType] InPartType:%s", tostring(InPartType)) self.SelectPartType = InPartType local ItemID = -1 if self.PartTypeToPartItem[InPartType] then ItemID = self.PartTypeToPartItem[InPartType]:GetItemID() end local Parts = MyWeaponSystem.GetWeaponCanUsePartFromPartType(self.WeaponID, InPartType) for i = 1, self.ScrollBox_SelectParts:GetChildrenCount() do local Item = self.ScrollBox_SelectParts:GetChildAt(i - 1) Item:SetItemID(Parts[i]) Item:SetIsSelect(ItemID == Parts[i]) end for i = 1, self.HorizontalBox_Part:GetChildrenCount() do local Item = self.HorizontalBox_Part:GetChildAt(i - 1) Item:SetIsSelect(InPartType == Item:GetPartType()) end end --- 修改显示的配件 function WB_SaveOtherWeaponItem:ClickSelectPart(PartID) UGCLogSystem.Log("[WB_SaveOtherWeaponItem_ClickSelectPart] PartID:%s", tostring(PartID)) local PartType = MyWeaponSystem.GetPartType(PartID) local PartItem = self.PartTypeToPartItem[PartType] 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_SaveOtherWeaponItem:GetAllParts() local Res = {} for i = 1, self.HorizontalBox_Part:GetChildrenCount() do local Item = self.HorizontalBox_Part:GetChildAt(i - 1) local ItemID = Item:GetItemID() if ItemID and MyWeaponSystem.IsWeaponPartValid(ItemID) then Res[#Res + 1] = ItemID end end return Res end function WB_SaveOtherWeaponItem:SetWeaponSocketType(InSocketType) self.WeaponSocketType = InSocketType end function WB_SaveOtherWeaponItem:GetWeaponSocketType() return self.WeaponSocketType end return WB_SaveOtherWeaponItem;