205 lines
6.7 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---@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 = {
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]")
if WeaponID then
self:SetWeaponID(WeaponID)
else
-- 拿取本地玩家的武器
self:SetWeaponID(ItemTool.GetLocalPawnCurrWeaponID());
end
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
end
function WB_WeaponConfiguration:CloseSelf()
WidgetManager:ClosePanel(WidgetConfig.EUIType.WeaponConfiguration)
end
function WB_WeaponConfiguration:ClickSave()
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()
end
function WB_WeaponConfiguration:GetWeaponID()
return self.WeaponID
end
function WB_WeaponConfiguration:SetWeaponID(WeaponID)
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
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
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 Parts = MyWeaponSystem.GetWeaponCanUsePartFromPartType(self.WeaponID, InPartType)
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[1])
end
end
function WB_WeaponConfiguration:OnPlayerChangeWeapon(InPawn, Slot, Weapon)
UGCLogSystem.Log("[WB_WeaponConfiguration:OnPlayerChangeWeapon] 玩家改变武器")
self:SetWeaponID(WeaponId);
end
return WB_WeaponConfiguration;