293 lines
12 KiB
Lua
293 lines
12 KiB
Lua
---@class WB_CustomWeapon_C:UUserWidget
|
||
---@field HorizontalBox_WeaponType UHorizontalBox
|
||
---@field NewButton_Close UNewButton
|
||
---@field NewButton_Reset UNewButton
|
||
---@field NewButton_Save UNewButton
|
||
---@field UniformGridPanel_SelectWeapon UUniformGridPanel
|
||
---@field VerticalBox_WeaponSocket UVerticalBox
|
||
--Edit Below--
|
||
local WB_CustomWeapon_New = {
|
||
bInitDoOnce = false;
|
||
WeaponComb = {}; -- {WeaponID1, WeaponID2
|
||
SelectSaveWeaponItemCol = 4;
|
||
WeaponSocketItems = {};
|
||
IsChange = false;
|
||
}
|
||
|
||
|
||
function WB_CustomWeapon_New:Construct()
|
||
self:LuaInit()
|
||
end
|
||
|
||
function WB_CustomWeapon_New:LuaInit()
|
||
if self.bInitDoOnce then
|
||
return;
|
||
end
|
||
self.bInitDoOnce = true;
|
||
|
||
UGCLogSystem.Log("[WB_CustomWeapon_LuaInit]")
|
||
|
||
-- 按键初始化
|
||
WidgetLibrary.BindButtonClicked(self.NewButton_Reset, self.ResetWeaponComb, self)
|
||
WidgetLibrary.BindButtonClicked(self.NewButton_Save, self.SaveWeaponComb, self)
|
||
WidgetLibrary.BindButtonClicked(self.NewButton_Close, self.ClickClose, self)
|
||
|
||
-- 初始化Item
|
||
self:InitItem()
|
||
UGCLogSystem.Log("[WB_CustomWeapon_LuaInit] Finish")
|
||
end
|
||
|
||
function WB_CustomWeapon_New:OnShowPanel(ProgrammeIndex)
|
||
UGCLogSystem.Log("[WB_CustomWeapon_OnShowPanel]")
|
||
-- 设置配置索引
|
||
self:SetProgrammeIndex(ProgrammeIndex)
|
||
UGCLogSystem.Log("[WB_CustomWeapon_OnShowPanel] Finish")
|
||
end
|
||
|
||
function WB_CustomWeapon_New:InitItem()
|
||
local LocalPC = UGCSystemLibrary.GetLocalPlayerController()
|
||
|
||
|
||
-- 武器类型中最大可选择的的武器数量
|
||
local MaxSelectItemCount = 0
|
||
|
||
-- 武器类型选择的Item在水平框中的对齐方式
|
||
local WeaponTypeSlateChildSize = UE.CreateStruct("SlateChildSize");
|
||
WeaponTypeSlateChildSize.SizeRule = ESlateSizeRule.Fill
|
||
|
||
for i, v in pairs(WeaponSelectionCombinationConfig.PlayerCustomWeapon) do
|
||
-- 设置一下最大的选择武器Item数量
|
||
MaxSelectItemCount = math.max(MaxSelectItemCount, #v.WeaponIDs)
|
||
-- 加载图片
|
||
for _, WeaponID in pairs(v.WeaponIDs) do
|
||
-- 加载剪影
|
||
MyWeaponSystem.AsyncLoadItemWhiteIconToBrush(WeaponID)
|
||
-- 加载大图
|
||
MyWeaponSystem.AsyncLoadItemBigIconToBrush(WeaponID)
|
||
end
|
||
-- 初始化武器类型
|
||
local WeaponTypeItem = nil
|
||
if self.HorizontalBox_WeaponType:GetChildrenCount() < i then
|
||
WeaponTypeItem = UserWidget.NewWidgetObjectBP(LocalPC, self:GetWeaponTypeItemClass());
|
||
self.HorizontalBox_WeaponType:AddChild(WeaponTypeItem)
|
||
-- 设置对齐方式
|
||
local TargetHorizontalBoxSlot = WidgetLayoutLibrary.SlotAsHorizontalBoxSlot(WeaponTypeItem)
|
||
TargetHorizontalBoxSlot:SetSize(WeaponTypeSlateChildSize)
|
||
else
|
||
WeaponTypeItem = self.HorizontalBox_WeaponType:GetChildAt(i - 1)
|
||
end
|
||
WeaponTypeItem:SetIndex(i)
|
||
WeaponTypeItem:BindClickSelect(self.SelectWeaponType, self)
|
||
end
|
||
|
||
-- 初始化武器槽UI
|
||
for i = 1, self.VerticalBox_WeaponSocket:GetChildrenCount() do
|
||
local Item = self.VerticalBox_WeaponSocket:GetChildAt(i - 1)
|
||
self.WeaponSocketItems[i] = Item
|
||
Item:SetIndex(i)
|
||
Item:BindClickSelect(self.SelectWeaponSocket, self)
|
||
end
|
||
-- 初始化武器选择Item
|
||
for i = 1, MaxSelectItemCount do
|
||
local Item = nil;
|
||
if self.UniformGridPanel_SelectWeapon:GetChildrenCount() < i then
|
||
Item = UserWidget.NewWidgetObjectBP(LocalPC, self:GetSelectSaveWeaponItemClass());
|
||
self.UniformGridPanel_SelectWeapon:AddChild(Item)
|
||
local TargetUniformGridSlot = WidgetLayoutLibrary.SlotAsUniformGridSlot(Item)
|
||
-- 居中
|
||
TargetUniformGridSlot:SetVerticalAlignment(EVerticalAlignment.VAlign_Center)
|
||
TargetUniformGridSlot:SetHorizontalAlignment(EHorizontalAlignment.HAlign_Center)
|
||
-- 设置索引
|
||
TargetUniformGridSlot:SetColumn((i - 1) % self.SelectSaveWeaponItemCol)
|
||
TargetUniformGridSlot:SetRow((i - 1) // self.SelectSaveWeaponItemCol)
|
||
else
|
||
Item = self.UniformGridPanel_SelectWeapon:GetChildAt(i - 1)
|
||
Item:SetVisibility(ESlateVisibility.HitTestInvisible)
|
||
end
|
||
Item:SetIndex(i)
|
||
Item:BindClickSelect(self.ClickSelectSaveWeapon, self)
|
||
end
|
||
UGCLogSystem.Log("[WB_CustomWeapon_InitItem] Finish")
|
||
end
|
||
|
||
|
||
function WB_CustomWeapon_New:GetSelectSaveWeaponItemClass()
|
||
if self.SelectSaveWeaponClass == nil then
|
||
self.SelectSaveWeaponClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapons/SaveCustomWeaponItem/WB_SelectSaveWeapon.WB_SelectSaveWeapon_C'))
|
||
end
|
||
return self.SelectSaveWeaponClass
|
||
end
|
||
|
||
function WB_CustomWeapon_New:GetWeaponTypeItemClass()
|
||
if self.WeaponTypeItemClass == nil then
|
||
self.WeaponTypeItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapons/SaveCustomWeaponItem/WB_WeaponType.WB_WeaponType_C'))
|
||
end
|
||
return self.WeaponTypeItemClass
|
||
end
|
||
|
||
--- 设置配置ID
|
||
function WB_CustomWeapon_New:SetProgrammeIndex(InProgrammeIndex)
|
||
self.ProgrammeIndex = InProgrammeIndex
|
||
-- 在这里修改 这里获取存档中双武器配置 结构为 CombinationType为 {[CombinationType] = {[组合索引] = {WeaponID1, WeaponID2 },}, }
|
||
-- local SavedWeaponComb = ArchiveDataConfig.GetPlayerArchiveDataFromType(UGCSystemLibrary.GetLocalPlayerKey(), ArchiveDataConfig.EArchiveType.WeaponCombs)
|
||
local SavedWeaponComb = nil
|
||
|
||
if SavedWeaponComb and SavedWeaponComb[self.ProgrammeIndex] then
|
||
self.WeaponComb = SavedWeaponComb[self.ProgrammeIndex]
|
||
else
|
||
local CombinationList = WeaponSelectionCombinationConfig.WeaponCombinationList.Weapon
|
||
if CombinationList and CombinationList[self.ProgrammeIndex] then
|
||
self.WeaponComb = CombinationList[self.ProgrammeIndex]
|
||
end
|
||
end
|
||
for i = #self.WeaponComb, 1, -1 do
|
||
self:SetSelectWeapon(i, self.WeaponComb[i], (i == 1))
|
||
end
|
||
end
|
||
|
||
--- 点击选择插槽
|
||
function WB_CustomWeapon_New:SelectWeaponSocket(Index)
|
||
if self.SelectWeaponSocketID ~= Index then
|
||
self.SelectWeaponSocketID = Index
|
||
local WeaponSocketItem = self.WeaponSocketItems[self.SelectWeaponSocketID]
|
||
if WeaponSocketItem then
|
||
self:SetSelectWeapon(self.SelectWeaponSocketID, WeaponSocketItem:GetWeaponID(), true)
|
||
end
|
||
end
|
||
end
|
||
--- 点击选择武器类型
|
||
function WB_CustomWeapon_New:SelectWeaponType(Index)
|
||
if self.WeaponTypeIndex ~= Index then
|
||
self.WeaponTypeIndex = Index
|
||
for i = 1, self.HorizontalBox_WeaponType:GetChildrenCount() do
|
||
local WeaponTypeItem = self.HorizontalBox_WeaponType:GetChildAt(i - 1)
|
||
WeaponTypeItem:SetSelect(i == self.WeaponTypeIndex)
|
||
end
|
||
local CustomWeaponInfo = WeaponSelectionCombinationConfig.PlayerCustomWeapon[self.WeaponTypeIndex]
|
||
local SocketWeaponID = -1
|
||
local WeaponSocketItem = self.WeaponSocketItems[self.SelectWeaponSocketID]
|
||
if WeaponSocketItem then
|
||
SocketWeaponID = WeaponSocketItem:GetWeaponID()
|
||
end
|
||
if CustomWeaponInfo then
|
||
for i = 1, self.UniformGridPanel_SelectWeapon:GetChildrenCount() do
|
||
local WeaponID = CustomWeaponInfo.WeaponIDs[i]
|
||
local WeaponItem = self.UniformGridPanel_SelectWeapon:GetChildAt(i - 1)
|
||
if WeaponID then
|
||
WeaponItem:SetWeaponID(WeaponID)
|
||
WeaponItem:SetSelect(SocketWeaponID == WeaponID)
|
||
WeaponItem:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||
else
|
||
WeaponItem:SetVisibility(ESlateVisibility.Collapsed)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
--- 点击选择武器
|
||
function WB_CustomWeapon_New:ClickSelectSaveWeapon(Index)
|
||
self.IsChange = true
|
||
self:SelectSaveWeapon(Index)
|
||
end
|
||
function WB_CustomWeapon_New:SelectSaveWeapon(Index)
|
||
local WeaponItem = self.UniformGridPanel_SelectWeapon:GetChildAt(Index - 1)
|
||
local WeaponID = WeaponItem:GetWeaponID()
|
||
for i = 1, self.UniformGridPanel_SelectWeapon:GetChildrenCount() do
|
||
local TempWeaponItem = self.UniformGridPanel_SelectWeapon:GetChildAt(i - 1)
|
||
TempWeaponItem:SetSelect(Index == i)
|
||
end
|
||
self:SetSelectWeapon(self.SelectWeaponSocketID, WeaponID, false)
|
||
end
|
||
|
||
|
||
--- 设置插槽内的武器
|
||
---@param SocketID uint 插槽的索引 只有1和2
|
||
---@param bUpdateSelectWeaponBar bool 是否更新武器选择栏
|
||
function WB_CustomWeapon_New:SetSelectWeapon(SocketID, WeaponID, bUpdateSelectWeaponBar)
|
||
if bUpdateSelectWeaponBar then
|
||
self.SelectWeaponSocketID = SocketID
|
||
for i, v in pairs(self.WeaponSocketItems) do
|
||
v:SetSelect(i == SocketID)
|
||
end
|
||
-- 获取武器ID类型和索引
|
||
local CustomWeaponTypeIndex = -1
|
||
local CustomWeaponIndex = -1;
|
||
for WeaponTypeIndex, v in pairs(WeaponSelectionCombinationConfig.PlayerCustomWeapon) do
|
||
-- 加载图片
|
||
for WeaponIndex, TempWeaponID in pairs(v.WeaponIDs) do
|
||
if TempWeaponID == WeaponID then
|
||
CustomWeaponIndex = WeaponIndex
|
||
CustomWeaponTypeIndex = WeaponTypeIndex
|
||
end
|
||
end
|
||
if CustomWeaponTypeIndex > 0 then
|
||
break
|
||
end
|
||
end
|
||
-- 更新选择栏
|
||
self:SelectWeaponType(CustomWeaponTypeIndex)
|
||
self:SelectSaveWeapon(CustomWeaponIndex)
|
||
else
|
||
local SocketItem = self.WeaponSocketItems[SocketID]
|
||
if SocketItem then
|
||
SocketItem:SetWeaponID(WeaponID)
|
||
end
|
||
end
|
||
end
|
||
|
||
|
||
|
||
--- 重置武器配置
|
||
function WB_CustomWeapon_New:ResetWeaponComb()
|
||
local CombinationList = WeaponSelectionCombinationConfig.Weapon
|
||
if CombinationList and CombinationList[self.ProgrammeIndex] then
|
||
local Comb = CombinationList[self.ProgrammeIndex]
|
||
for i = #Comb, 1, -1 do
|
||
self:SetSelectWeapon(i, Comb[i], (i == 1))
|
||
end
|
||
end
|
||
end
|
||
|
||
function WB_CustomWeapon_New:SaveWeaponComb()
|
||
local WeaponComb = {}
|
||
local PartsComb = {}
|
||
for i, v in pairs(self.WeaponSocketItems) do
|
||
WeaponComb[i] = v:GetWeaponID()
|
||
PartsComb[i] = v:GetAllParts()
|
||
end
|
||
UGCLogSystem.LogTree("[WB_CustomWeapon_SaveWeaponComb]WeaponComb:", WeaponComb)
|
||
-- 保存操作
|
||
-- 在这里修改 发送RPC保存武器配件到存档并自动选择对应保存的配置 ProgrammeIndex:配置索引, WeaponComb = {WeaponID1, WeaponID2} ,PartsComb = {[WeaponID1] = {PartID, PartID, PartID, ... }, [WeaponID2] = {}, ...}
|
||
-- UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerCustomWeapon", UGCSystemLibrary.GetLocalPlayerKey(), self.ProgrammeIndex, WeaponComb, PartsComb)
|
||
|
||
-- 关闭UI
|
||
self:CloseSelf()
|
||
end
|
||
|
||
function WB_CustomWeapon_New:ClickClose()
|
||
if self.IsChange then
|
||
local SecondaryConfirmationWidget = WidgetManager:GetPanel(WidgetConfig.EUIType.SecondaryConfirmation)
|
||
SecondaryConfirmationWidget:SetTextInfo("该配置还未保存,是否保存后关闭页面?", "关闭", "保存")
|
||
SecondaryConfirmationWidget:BindCancellationCallBack(self.CloseSelf, self)
|
||
SecondaryConfirmationWidget:BindConfirmCallBack(self.SaveWeaponComb, self)
|
||
WidgetManager:ShowPanel(WidgetConfig.EUIType.SecondaryConfirmation, false)
|
||
else
|
||
self:CloseSelf()
|
||
end
|
||
end
|
||
|
||
function WB_CustomWeapon_New:CloseSelf()
|
||
WidgetManager:ClosePanel(WidgetConfig.EUIType.CustomSelectWeapon)
|
||
self.IsChange = false
|
||
end
|
||
|
||
|
||
-- function WB_CustomWeapon_New:Tick(MyGeometry, InDeltaTime)
|
||
|
||
-- end
|
||
|
||
-- function WB_CustomWeapon_New:Destruct()
|
||
|
||
-- end
|
||
|
||
return WB_CustomWeapon_New |