UGCProjects/ProjectTemp_T/Script/UI/ChildWidget/WB_SelectLevel_Item.lua

100 lines
2.8 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
---@class WB_SelectLevel_Item_C:UUserWidget
---@field Button_Main UButton
---@field CanvasPanel_Lock UCanvasPanel
---@field Image_Icon UImage
---@field Image_None UImage
---@field Image_Select UImage
---@field TextBlock_SelectNum UTextBlock
---@field TextBlock_Type UTextBlock
---@field WidgetSwitcher_Select UWidgetSwitcher
--Edit Below--
---@type WB_SelectLevel_Item_C
local WB_SelectLevel_Item = { bInitDoOnce = false; };
---@type ELevelType
WB_SelectLevel_Item.LevelIndex = -1;
---@type UUserWidget
WB_SelectLevel_Item.ParentWidget = nil;
---@type fun(InWidget: UUserWidget, InIndex: ELevelType)
WB_SelectLevel_Item.ClickCb = nil;
function WB_SelectLevel_Item:Construct()
UITool.BindButtonClicked(self.Button_Main, self.OnClickMain, self)
UITool.EnableButtonScroll(self.Button_Main);
UGCEventSystem.AddListener(EventTypes.UpdateSelectLevels, self.OnSelectMapCallback, self);
if self.LevelIndex ~= -1 then
self:Init(self.LevelIndex);
end
self.bInitDoOnce = true;
end
--- 初始化,且只执行一遍
---@param InIndex ELevelType
function WB_SelectLevel_Item:Init(InIndex, InParent, InFunc)
self.ParentWidget = InParent;
self.ClickCb = InFunc;
self.LevelIndex = InIndex;
if self.bInitDoOnce then
self.TextBlock_Type:SetText(LevelTable.LevelInfo[InIndex].ShowName);
self.TextBlock_SelectNum:SetText('0');
self.Image_Icon:SetBrushFromTexture(UE.LoadObject(LevelTable.LevelInfo[InIndex].Icon))
end
end
-- function WB_SelectLevel_Item:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_SelectLevel_Item:Destruct()
-- end
function WB_SelectLevel_Item:OnClickMain()
if self.ParentWidget then
self.ClickCb(self.ParentWidget, self, self.LevelIndex);
end
SoundSystem.PlaySound(SoundSystem.ESound.Click);
-- 发送出去
UnrealNetwork.CallUnrealRPC(LocalPlayerController, UGCGameSystem.GameState, "Server_SelectMap", LocalPlayerKey, self.LevelIndex);
end
---@param IsClick bool
---@param InParentIndex int32
function WB_SelectLevel_Item:SelectSelf(IsClick, InParentIndex)
if IsClick then
self.WidgetSwitcher_Select:SetActiveWidgetIndex(1)
else
self.WidgetSwitcher_Select:SetActiveWidgetIndex(0)
end
if InParentIndex == self.LevelIndex then
self.WidgetSwitcher_Select:SetActiveWidgetIndex(2);
end
end
--- 选择地图之后的回调
---@param InList table<PlayerKey, ELevelType>
function WB_SelectLevel_Item:OnSelectMapCallback(InList)
local SelectTable = {};
for PlayerKey, LevelType in pairs(InList) do
if SelectTable[LevelType] == nil then
SelectTable[LevelType] = 1;
else
SelectTable[LevelType] = SelectTable[LevelType] + 1;
end
end
local Count = SelectTable[self.LevelIndex];
if Count ~= nil then
self.TextBlock_SelectNum:SetText(tostring(Count));
else
self.TextBlock_SelectNum:SetText('0');
end
end
function WB_SelectLevel_Item:GetLevelIndex() return self.LevelIndex; end
return WB_SelectLevel_Item;