UGCProjects/SoloKing/Script/UI/SelectWeapons/WB_WeaponSelect_New.lua
2025-01-04 23:00:19 +08:00

140 lines
5.1 KiB
Lua

---@class WB_WeaponSelect_C:UUserWidget
---@field Button_Custom UNewButton
---@field Button_Select UNewButton
---@field ScrollBox_Weapons UScrollBox
---@field TextBlock_Time UTextBlock
---@field UniformGridPanel_OtherParts UUniformGridPanel
--Edit Below--
local WB_WeaponSelect_New = {
bInitDoOnce = false;
CombinationType = 1;
ShowTime = 0;
SelectWeaponIndex = 1;
OtherPartsItemColNum = 6;
SelectTime = 15;
};
function WB_WeaponSelect_New:Construct()
WidgetLibrary.BindButtonClicked(self.Button_Select, self.SelectWeapon, self)
self:UpdateWeaponCombination()
-- 判断是否可以修改配置
WidgetLibrary.BindButtonClicked(self.Button_Custom, self.CustomWeaponComb, self)
end
function WB_WeaponSelect_New:OnShowPanel()
if self.SelectTimeHandle then
UGCEventSystem.StopTimer(self.SelectTimeHandle)
end
self.ShowTime = self.SelectTime
self.TextBlock_Time:SetText(self.ShowTime)
self.SelectTimeHandle = UGCEventSystem.SetTimerLoop(self, self.SelectTimeClock, 1)
end
function WB_WeaponSelect_New:SelectTimeClock()
self.ShowTime = self.ShowTime - 1
if self.ShowTime <= 0 then
UGCEventSystem.StopTimer(self.SelectTimeHandle)
self.SelectTimeHandle = nil
WidgetManager:ClosePanel(WidgetConfig.EUIType.SelectWeaponNew)
else
self.TextBlock_Time:SetText(self.ShowTime)
end
end
function WB_WeaponSelect_New:GetWeaponItemClass()
if self.ItemClass == nil then
self.ItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapons/Item/WB_WeaponSelectItem.WB_WeaponSelectItem_C'))
end
return self.ItemClass
end
function WB_WeaponSelect_New:GetOtherPartItemClass()
if self.OtherItemClass == nil then
self.OtherItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapons/Item/WB_OtherPartItem.WB_OtherPartItem_C'))
end
return self.OtherItemClass
end
function WB_WeaponSelect_New:UpdateWeaponCombination()
local WeaponCombinationInfo = WeaponSelectionCombinationConfig.WeaponCombinationList
for i = 1, self.ScrollBox_Weapons:GetChildrenCount() do
local Item = self.ScrollBox_Weapons:GetChildAt(i - 1)
Item:Init(i)
end
for i = self.ScrollBox_Weapons:GetChildrenCount() + 1, #WeaponCombinationInfo.Weapon do
local Item = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetWeaponItemClass());
if Item then
self.ScrollBox_Weapons:AddChild(Item)
Item:Init(i)
Item:BindSelectCallBack(self.SelectWeaponItem, self)
end
end
for i = #WeaponCombinationInfo.Weapon, self.ScrollBox_Weapons:GetChildrenCount() - 1 do
local Item = self.ScrollBox_Weapons:GetChildAt(i)
Item:SetVisibility(ESlateVisibility.Collapsed)
end
for i, ItemInfo in pairs(WeaponCombinationInfo.OtherParts) do
local Item
if self.UniformGridPanel_OtherParts:GetChildrenCount() < i then
Item = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetOtherPartItemClass());
self.UniformGridPanel_OtherParts:AddChild(Item)
local TargetUniformGridSlot = WidgetLayoutLibrary.SlotAsUniformGridSlot(Item)
-- 居中
TargetUniformGridSlot:SetVerticalAlignment(EVerticalAlignment.VAlign_Center)
TargetUniformGridSlot:SetHorizontalAlignment(EHorizontalAlignment.HAlign_Center)
-- 设置索引
TargetUniformGridSlot:SetColumn((i - 1) % self.OtherPartsItemColNum)
TargetUniformGridSlot:SetRow((i - 1) // self.OtherPartsItemColNum)
else
Item = self.UniformGridPanel_OtherParts:GetChildAt(i - 1)
Item:SetVisibility(ESlateVisibility.HitTestInvisible)
end
Item:SetItemID(ItemInfo.ItemID, ItemInfo.Count)
end
for i = #WeaponCombinationInfo.OtherParts, self.UniformGridPanel_OtherParts:GetChildrenCount() - 1 do
local Item = self.UniformGridPanel_OtherParts:GetChildAt(i)
Item:SetVisibility(ESlateVisibility.Collapsed)
end
self:SelectWeaponItem(1)
end
function WB_WeaponSelect_New:SelectWeaponItem(InIndex)
self.SelectWeaponIndex = InIndex
for i = 1, self.ScrollBox_Weapons:GetChildrenCount() do
local Item = self.ScrollBox_Weapons:GetChildAt(i - 1)
Item:SetSelect(Item:GetCombinationIndex() == InIndex)
end
end
function WB_WeaponSelect_New:SelectWeapon()
-- 在这里修改 发送RPC选择武器配置的索引
-- UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerSelectWeaponIndex", UGCSystemLibrary.GetLocalPlayerKey(), self.SelectWeaponIndex)
WidgetManager:ClosePanel(WidgetConfig.EUIType.SelectWeaponNew)
end
function WB_WeaponSelect_New:CustomWeaponComb()
WidgetManager:ShowPanel(WidgetConfig.EUIType.CustomSelectWeapon, false, self.SelectWeaponIndex)
WidgetManager:ClosePanel(WidgetConfig.EUIType.SelectWeaponNew)
end
-- function WB_WeaponSelect_New:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_WeaponSelect_New:Destruct()
-- end
return WB_WeaponSelect_New;