2025-01-04 23:00:19 +08:00

127 lines
4.9 KiB
Lua

---@class WB_WeaponSelect_C:UUserWidget
---@field Button_Select UButton
---@field ScrollBox_Weapons UScrollBox
---@field TextBlock_Time UTextBlock
---@field UniformGridPanel_OtherParts UUniformGridPanel
--Edit Below--
local WB_WeaponSelect = {
bInitDoOnce = false;
CombinationType = 1;
ShowTime = 0;
SelectWeaponIndex = 1;
OtherPartsItemColNum = 6;
};
function WB_WeaponSelect:Construct()
UGCEventSystem.AddListener(EventEnum.PlayerWeaponCombinationUpdate, self.UpdateWeaponCombination, self)
WidgetLibrary.BindButtonClicked(self.Button_Select, self.SelectWeapon, self)
self:UpdateWeaponCombination()
end
function WB_WeaponSelect:OnShowPanel()
if self.SelectTimeHandle then
UGCEventSystem.StopTimer(self.SelectTimeHandle)
end
self.ShowTime = GlobalConfigs.GameSetting.WeaponSelectTime
self.TextBlock_Time:SetText(self.ShowTime)
self.SelectTimeHandle = UGCEventSystem.SetTimerLoop(self, self.SelectTimeClock, 1)
end
function WB_WeaponSelect:SelectTimeClock()
self.ShowTime = self.ShowTime - 1
if self.ShowTime <= 0 then
UGCEventSystem.StopTimer(self.SelectTimeHandle)
self.SelectTimeHandle = nil
WidgetManager:ClosePanel(WidgetConfig.EUIType.WeaponSelect)
else
self.TextBlock_Time:SetText(self.ShowTime)
end
end
function WB_WeaponSelect:GetWeaponItemClass()
if self.ItemClass == nil then
self.ItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapon/WB_WeaponSelectItem.WB_WeaponSelectItem_C'))
end
return self.ItemClass
end
function WB_WeaponSelect:GetOtherPartItemClass()
if self.OtherItemClass == nil then
self.OtherItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectWeapon/WB_OtherPartItem.WB_OtherPartItem_C'))
end
return self.OtherItemClass
end
function WB_WeaponSelect:UpdateWeaponCombination()
local WeaponCombinationType = UGCGameSystem.GameState:GetPlayerWeaponCombination(UGCSystemLibrary.GetLocalPlayerKey())
if WeaponCombinationType ~= self.WeaponCombinationType then
self.WeaponCombinationType = WeaponCombinationType
local WeaponCombinationInfo = WeaponSelectionCombinationConfig.WeaponCombinationList[WeaponCombinationType]
for i = 1, self.ScrollBox_Weapons:GetChildrenCount() do
local Item = self.ScrollBox_Weapons:GetChildAt(i - 1)
Item:Init(WeaponCombinationType, 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(WeaponCombinationType, i)
Item:BindSelectCallBack(self.SelectWeaponItem, self)
end
end
local PartsIndex = 0
for i, ItemInfo in pairs(WeaponCombinationInfo.OtherParts) do
PartsIndex = PartsIndex + 1
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 % self.OtherPartsItemColNum)
TargetUniformGridSlot:SetRow(i // self.OtherPartsItemColNum)
else
Item = self.UniformGridPanel_OtherParts:GetChildAt(i - 1)
Item:SetVisibility(ESlateVisibility.HitTestInvisible)
end
Item:SetItemID(ItemInfo.ItemID, ItemInfo.Count)
end
for i = PartsIndex, self.UniformGridPanel_OtherParts:GetChildrenCount() - 1 do
local Item = self.UniformGridPanel_OtherParts:GetChildAt(i)
Item:SetVisibility(ESlateVisibility.Collapsed)
end
self:SelectWeaponItem(1)
end
end
function WB_WeaponSelect: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:SelectWeapon()
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerSelectWeaponIndex", UGCSystemLibrary.GetLocalPlayerKey(), self.SelectWeaponIndex)
WidgetManager:ClosePanel(WidgetConfig.EUIType.WeaponSelect)
end
-- function WB_WeaponSelect:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_WeaponSelect:Destruct()
-- end
return WB_WeaponSelect;