2025-01-04 23:00:19 +08:00

194 lines
6.4 KiB
Lua

---@class WB_SaveWeaponItem_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_SaveWeaponItem = {
bInitDoOnce = false;
PartTypeToPartItem = {};
IsSelected = false;
};
--[==[ Construct
function WB_SaveWeaponItem:Construct()
end
-- Construct ]==]
-- function WB_SaveWeaponItem:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_SaveWeaponItem:Destruct()
-- end
function WB_SaveWeaponItem: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
end
function WB_SaveWeaponItem:SetIndex(InIndex)
self.Index = InIndex
self:LuaInit()
end
function WB_SaveWeaponItem:GetIndex()
return self.Index
end
function WB_SaveWeaponItem:BindClickSelect(Func, Obj)
self.SelectCallBackFunc = Func
self.SelectCallBackObj = Obj
end
function WB_SaveWeaponItem: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_SaveWeaponItem: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_SaveWeaponItem:GetWeaponID()
return self.WeaponID
end
function WB_SaveWeaponItem:SetWeaponID(WeaponID)
if self.WeaponID ~= WeaponID then
self.WeaponID = WeaponID
local WeaponParts = MyWeaponSystem.GetWeaponBastParts(self.WeaponID)
local CustomWeaponParts = ArchiveDataConfig.GetPlayerArchiveDataFromType(UGCSystemLibrary.GetLocalPlayerKey(), ArchiveDataConfig.EArchiveType.CustomWeaponParts)
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.AsyncLoadItemBigIconToBrush(self.WeaponID, self.Image_WeaponIcon)
self.TextBlock_WeaponName:SetText(MyWeaponSystem.GetItemName(self.WeaponID))
end
end
function WB_SaveWeaponItem:SetVisWeaponInfo(IsVis)
if IsVis then
self.CanvasPanel_WeaponInfo:SetVisibility(ESlateVisibility.HitTestInvisible)
else
self.CanvasPanel_WeaponInfo:SetVisibility(ESlateVisibility.Hidden)
end
end
function WB_SaveWeaponItem:ClickPart(PartID)
if self.IsSelected then
local PartType = MyWeaponSystem.GetPartType(PartID)
self:SetSelectPartType(PartType)
else
self:ClickSelect()
end
end
--- 设置选择修改的类型
function WB_SaveWeaponItem:SetSelectPartType(InPartType)
UGCLogSystem.Log("[WB_SaveWeaponItem_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_SaveWeaponItem:ClickSelectPart(PartID)
UGCLogSystem.Log("[WB_SaveWeaponItem_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_SaveWeaponItem: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
return WB_SaveWeaponItem;