2025-01-15 03:21:37 +08:00
|
|
|
|
---@class WB_WeaponConfiguration_C:UUserWidget
|
|
|
|
|
---@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_WeaponName UTextBlock
|
|
|
|
|
--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-16 13:35:17 +08:00
|
|
|
|
UGCLogSystem.Log("[WB_WeaponConfiguration_OnShowPanel]")
|
|
|
|
|
if WeaponID then
|
|
|
|
|
self:SetWeaponID(WeaponID)
|
|
|
|
|
else
|
|
|
|
|
-- 拿取本地玩家的武器
|
|
|
|
|
self:SetWeaponID(ItemTool.GetLocalPawnCurrWeaponID());
|
|
|
|
|
end
|
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-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
|
|
|
|
|
-- 在这里修改 发送RPC到DS设置配件
|
|
|
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(LocalPlayerKey);
|
|
|
|
|
if UE.IsValidPawn(Pawn) then
|
|
|
|
|
-- 发送 RPC
|
|
|
|
|
UnrealNetwork.CallUnrealRPC(LocalPlayerController, Pawn, "UpdateWeaponParts", WeaponID, WeaponParts);
|
|
|
|
|
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-16 13:35:17 +08:00
|
|
|
|
if self.WeaponID ~= WeaponID then
|
|
|
|
|
self.WeaponID = WeaponID
|
|
|
|
|
local WeaponParts = MyWeaponSystem.GetWeaponBastParts(self.WeaponID)
|
|
|
|
|
|
|
|
|
|
if ArchiveTable[LocalPlayerKey] and not table.isEmpty(ArchiveTable[LocalPlayerKey].Weapons) then
|
|
|
|
|
WeaponParts = ArchiveTable[LocalPlayerKey].Weapons[self.WeaponID];
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
UGCLogSystem.LogTree("[WB_WeaponConfiguration_SetWeaponID]", WeaponParts)
|
|
|
|
|
|
|
|
|
|
local WeaponPartsMap = MyWeaponSystem.PartListToPartMap(WeaponParts)
|
|
|
|
|
local UpdateSelectPartsOnce = false
|
2025-01-18 23:19:35 +08:00
|
|
|
|
if WeaponSuits[WeaponID] then
|
|
|
|
|
for i, v in pairs(WeaponSuits[WeaponID]) do
|
|
|
|
|
if WeaponPartsMap[i] == nil then WeaponPartsMap[i] = 0 end
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-01-16 13:35:17 +08:00
|
|
|
|
|
|
|
|
|
for PartType, Item in pairs(self.PartTypeToPartItem) do
|
|
|
|
|
local ItemID = WeaponPartsMap[PartType]
|
|
|
|
|
Item:SetItemID(ItemID)
|
|
|
|
|
--UGCLogSystem.Log("[WB_WeaponConfiguration_SetWeaponID] ItemID:" .. tostring(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)
|
|
|
|
|
MyWeaponSystem.AsyncLoadItemWhiteIconToBrush(self.WeaponID, self.Image_WeaponIcon)
|
|
|
|
|
|
|
|
|
|
self.TextBlock_WeaponName:SetText(MyWeaponSystem.GetItemName(self.WeaponID))
|
|
|
|
|
end
|
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
|
|
|
|
|
local ItemID = -1
|
|
|
|
|
if self.PartTypeToPartItem[InPartType] then
|
|
|
|
|
ItemID = self.PartTypeToPartItem[InPartType]:GetItemID()
|
|
|
|
|
end
|
|
|
|
|
local Parts = MyWeaponSystem.GetWeaponCanUsePartFromPartType(self.WeaponID, InPartType)
|
2025-01-18 23:19:35 +08:00
|
|
|
|
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
|
|
|
|
|
self:SetWeaponID(WeaponIDs[1])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function WB_WeaponConfiguration:OnPlayerChangeWeapon(InPawn, Slot, Weapon)
|
|
|
|
|
UGCLogSystem.Log("[WB_WeaponConfiguration:OnPlayerChangeWeapon] 玩家改变武器")
|
|
|
|
|
self:SetWeaponID(WeaponId);
|
2025-01-15 03:21:37 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return WB_WeaponConfiguration;
|