232 lines
7.9 KiB
Lua
Raw Permalink Normal View History

2025-01-15 03:21:37 +08:00
---@class WB_WeaponConfiguration_C:UUserWidget
2025-02-05 00:23:25 +08:00
---@field CanvasPanel_TelescopeTip UCanvasPanel
2025-01-15 03:21:37 +08:00
---@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
2025-01-21 11:29:14 +08:00
---@field TextBlock_Parts UTextBlock
2025-01-15 03:21:37 +08:00
---@field TextBlock_WeaponName UTextBlock
2025-02-04 12:58:50 +08:00
---@field WB_DamageTextButton UWB_DamageTextButton_C
2025-02-04 17:59:01 +08:00
---@field WB_OpenOldWeaponParts UWB_OpenOldWeaponParts_C
2025-01-15 03:21:37 +08:00
--Edit Below--
local WB_WeaponConfiguration = {
2025-01-16 13:35:17 +08:00
bInitDoOnce = false;
PartTypeToPartItem = {};
2025-01-15 03:21:37 +08:00
};
function WB_WeaponConfiguration:Construct()
2025-01-16 13:35:17 +08:00
self:LuaInit()
2025-01-15 03:21:37 +08:00
end
-- function WB_WeaponConfiguration:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_WeaponConfiguration:Destruct()
-- end
function WB_WeaponConfiguration:OnShowPanel(WeaponID)
2025-01-21 11:29:14 +08:00
UGCLogSystem.Log("[WB_WeaponConfiguration_OnShowPanel] WeaponI = %s", tostring(WeaponID));
2025-01-15 03:21:37 +08:00
end
function WB_WeaponConfiguration:LuaInit()
2025-01-16 13:35:17 +08:00
if self.bInitDoOnce then return ; end
2025-01-15 03:21:37 +08:00
self.bInitDoOnce = true;
2025-01-16 13:35:17 +08:00
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
2025-02-04 17:59:01 +08:00
self.WB_OpenOldWeaponParts:LuaInit();
2025-01-15 03:21:37 +08:00
end
function WB_WeaponConfiguration:CloseSelf()
2025-01-16 13:35:17 +08:00
WidgetManager:ClosePanel(WidgetConfig.EUIType.WeaponConfiguration)
2025-01-15 03:21:37 +08:00
end
function WB_WeaponConfiguration:ClickSave()
2025-01-16 13:35:17 +08:00
local WeaponParts = self:GetAllParts()
local WeaponID = self.WeaponID
2025-01-21 11:29:14 +08:00
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(LocalPlayerKey);
2025-01-16 13:35:17 +08:00
if UE.IsValidPawn(Pawn) then
-- 发送 RPC
UnrealNetwork.CallUnrealRPC(LocalPlayerController, Pawn, "UpdateWeaponParts", WeaponID, WeaponParts);
2025-01-21 11:29:14 +08:00
UGCLogSystem.Log("[WB_WeaponConfiguration:ClickSave] 发送RPC WeaponID = %s", tostring(WeaponID));
UGCLogSystem.LogTree(string.format("[WB_WeaponConfiguration:ClickSave] WeaponParts ="), WeaponParts);
2025-01-16 13:35:17 +08:00
end
-- 关闭该UI
self:CloseSelf()
2025-01-15 03:21:37 +08:00
end
function WB_WeaponConfiguration:GetWeaponID()
2025-01-16 13:35:17 +08:00
return self.WeaponID
2025-01-15 03:21:37 +08:00
end
function WB_WeaponConfiguration:SetWeaponID(WeaponID)
2025-01-21 11:29:14 +08:00
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
2025-01-16 13:35:17 +08:00
end
2025-01-21 11:29:14 +08:00
end
for PartType, Item in pairs(self.PartTypeToPartItem) do
local ItemID = WeaponPartsMap[PartType]
Item:SetItemID(ItemID)
2025-02-05 00:23:25 +08:00
if PartType == EWeaponPartType.Telescope then
if ItemID == nil then
self.CanvasPanel_TelescopeTip:SetVisibility(ESlateVisibility.Collapsed)
else
self.CanvasPanel_TelescopeTip:SetVisibility(ESlateVisibility.HitTestInvisible)
end
end
2025-01-21 11:29:14 +08:00
-- 设置当前默认选择的Part
if ItemID and not UpdateSelectPartsOnce then
UpdateSelectPartsOnce = true
self:SetSelectPartType(PartType)
2025-01-16 13:35:17 +08:00
end
end
2025-01-21 11:29:14 +08:00
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))
2025-01-15 03:21:37 +08:00
end
function WB_WeaponConfiguration:ClickPart(PartID, PartType)
2025-01-16 13:35:17 +08:00
-- local PartType = MyWeaponSystem.GetPartType(PartID)
self:SetSelectPartType(PartType)
2025-01-15 03:21:37 +08:00
end
--- 设置选择修改的类型
function WB_WeaponConfiguration:SetSelectPartType(InPartType)
2025-01-16 13:35:17 +08:00
UGCLogSystem.Log("[WB_WeaponConfiguration_SetSelectPartType] InPartType:%s", tostring(InPartType))
self.SelectPartType = InPartType;
2025-01-16 13:35:17 +08:00
local ItemID = -1
if self.PartTypeToPartItem[InPartType] then
ItemID = self.PartTypeToPartItem[InPartType]:GetItemID()
end
2025-01-21 11:29:14 +08:00
local Info = WeaponTypeName[InPartType]
--UGCLogSystem.LogTree(string.format("[WB_WeaponConfiguration:SetSelectPartType] Info ="), Info)
2025-01-21 11:29:14 +08:00
if Info then
self.TextBlock_Parts:SetText('配件:' .. Info.Chinese);
else
self.TextBlock_Parts:SetText('可装配配件');
end
2025-01-16 13:35:17 +08:00
local Parts = MyWeaponSystem.GetWeaponCanUsePartFromPartType(self.WeaponID, InPartType)
UGCLogSystem.LogTree("[WB_WeaponConfiguration_SetSelectPartType]", Parts)
2025-01-16 13:35:17 +08:00
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
2025-01-15 03:21:37 +08:00
end
--- 修改显示的配件
function WB_WeaponConfiguration:ClickSelectPart(PartID)
2025-01-16 13:35:17 +08:00
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
2025-01-15 03:21:37 +08:00
end
--- 获取当前修改后的配件信息
function WB_WeaponConfiguration:GetAllParts()
2025-01-16 13:35:17 +08:00
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
2025-01-15 03:21:37 +08:00
end
function WB_WeaponConfiguration:UpdateCurrWeapon(WeaponIDs)
2025-01-16 13:35:17 +08:00
UGCLogSystem.LogTree("[WB_WeaponConfiguration_UpdateCurrWeapon]", WeaponIDs)
if WeaponIDs[LocalPlayerKey] then
2025-01-21 11:29:14 +08:00
self:SetWeaponID(WeaponIDs[LocalPlayerKey]);
2025-01-16 13:35:17 +08:00
end
end
2025-01-21 11:29:14 +08:00
---@param Weapon ASTExtraShootWeapon
2025-01-16 13:35:17 +08:00
function WB_WeaponConfiguration:OnPlayerChangeWeapon(InPawn, Slot, Weapon)
2025-01-21 11:29:14 +08:00
UGCLogSystem.Log("[WB_WeaponConfiguration:OnPlayerChangeWeapon] 玩家改变武器, Slot = %s", tostring(Slot));
if Weapon and Weapon then
self:SetWeaponID(Weapon:GetWeaponItemID());
end
2025-01-15 03:21:37 +08:00
end
return WB_WeaponConfiguration;