---@class WB_SelectGameMode_C:UUserWidget ---@field HorizontalBox_EnemySelectMode UHorizontalBox ---@field HorizontalBox_ModeType UHorizontalBox ---@field NewButton_Select UNewButton ---@field TextBlock_Enemy UTextBlock ---@field TextBlock_Feature UTextBlock --Edit Below-- local WB_SelectGameMode = { bInitDoOnce = false } function WB_SelectGameMode:Construct() self:LuaInit() end function WB_SelectGameMode:LuaInit() if self.bInitDoOnce then return ; end self.bInitDoOnce = true; UGCLogSystem.Log("[WB_SelectGameMode_LuaInit]") UGCEventSystem.AddListener(EventTypes.UpdateArchiveData, self.OnUpdateArchiveData, self); UGCEventSystem.AddListener(EventTypes.UpdateSelectModes, self.OnUpdateSelectModes, self); -- 按键初始化 UITool.BindButtonClicked(self.NewButton_Select, self.ClickSelectMode, self) -- 初始化Item self:InitItem() self:OnUpdateArchiveData(); UGCLogSystem.Log("[WB_SelectGameMode_LuaInit] Finish") end function WB_SelectGameMode:InitItem() UGCLogSystem.Log("[WB_SelectGameMode_InitItem]") -- 武器类型选择的Item在水平框中的对齐方式 local ModeTypeSlateChildSize = UE.CreateStruct("SlateChildSize"); ModeTypeSlateChildSize.SizeRule = ESlateSizeRule.Fill local ModeCount = 0 for ModeType = 1, table.getCount(GameModeConfig.EGameModeType) do UGCLogSystem.Log("[WB_SelectGameMode_InitItem] ModeType:%s", tostring(ModeType)) ModeCount = ModeCount + 1 -- 初始化武器类型 local ModeTypeItem = nil if self.HorizontalBox_ModeType:GetChildrenCount() < ModeCount then ModeTypeItem = UserWidget.NewWidgetObjectBP(LocalPlayerController, self:GetModeTypeItemClass()); self.HorizontalBox_ModeType:AddChild(ModeTypeItem) -- 设置对齐方式 local TargetHorizontalBoxSlot = WidgetLayoutLibrary.SlotAsHorizontalBoxSlot(ModeTypeItem) TargetHorizontalBoxSlot:SetSize(ModeTypeSlateChildSize) else ModeTypeItem = self.HorizontalBox_ModeType:GetChildAt(ModeCount - 1) end ModeTypeItem:SetIndex(ModeType) ModeTypeItem:BindClickSelect(self.SelectModeType, self) end end -- function WB_SelectGameMode:Tick(MyGeometry, InDeltaTime) -- end -- function WB_SelectGameMode:Destruct() -- end function WB_SelectGameMode:GetModeTypeItemClass() if self.ModeTypeItemClas == nil then self.ModeTypeItemClas = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/SelectGameMode/WB_ModeType.WB_ModeType_C')) end return self.ModeTypeItemClas end --- 点击选择武器类型 function WB_SelectGameMode:SelectModeType(Index) UGCLogSystem.Log("[WB_SelectGameMode_SelectModeType] ModeTypeIndex:%s", tostring(Index)) if self.ModeTypeIndex ~= Index then self.ModeTypeIndex = Index for i = 1, self.HorizontalBox_ModeType:GetChildrenCount() do local ModeTypeItem = self.HorizontalBox_ModeType:GetChildAt(i - 1) ModeTypeItem:SetSelect(ModeTypeItem:GetIndex() == self.ModeTypeIndex) end self.TextBlock_Feature:SetText(tostring(GameModeConfig.GameModeInfo[self.ModeTypeIndex].Feature)) end end function WB_SelectGameMode:ClickSelectMode() GameState:SendMiniGameRPC("SelectMode", LocalPlayerKey, self.ModeTypeIndex); -- 选择后直接隐藏 self:SetVisibility(ESlateVisibility.Collapsed) end function WB_SelectGameMode:OnUpdateArchiveData() local SelectMode = GameModeConfig.EGameModeType.DefaultMode; local Archive = ArchiveTable[LocalPlayerKey] if Archive then if Archive.ModeType ~= nil then SelectMode = Archive.ModeType; end end self:SelectModeType(SelectMode); end function WB_SelectGameMode:OnUpdateSelectModes(SelectModes) for i, v in pairs(SelectModes) do self.TextBlock_Enemy:SetText(GameModeConfig.GameModeInfo[v].Name); self.HorizontalBox_EnemySelectMode:SetVisibility(ESlateVisibility.HitTestInvisible); break; end end return WB_SelectGameMode