---@class WBP_SelectDifficultyPanel_C:UUserWidget ---@field CanvasPanel_Area UCanvasPanel ---@field CanvasPanel_Main UCanvasPanel ---@field HorizontalBox_RemainTime UHorizontalBox ---@field ScrollBox_Range UScrollBox ---@field TextBlock_RemainTime UTextBlock ---@field TextBlock_SelectDifficultyTip UTextBlock ---@field TextBlock_Total UTextBlock ---@field UniformGridPanel_Items UUniformGridPanel ---@field WBP_WidgetHeader UWBP_WidgetHeader_C --Edit Below-- local WBP_SelectDifficultyPanel = { bInitDoOnce = false; GridItemWidgetClass = nil; -- 难度项的类 RangeItemClass = nil; -- Range 项的类 MaxDifficulty = 0; -- 最高难度 SelectDifficulty = 0; -- 是否选择过难度 TotalRangeNum = 0; -- 当前 Range Item 个数 RecommendLevel = 0; -- 推荐等级 CurrentRangeNum = 0; HadShow = false; -- 是否显示过 }; function WBP_SelectDifficultyPanel:Construct() WBP_SelectDifficultyPanel.SuperClass.Construct(self) self.WBP_WidgetHeader.UIType = EUIType.SelectDifficulty self.WBP_WidgetHeader.bIsCloseUITypeUI = false; self.WBP_WidgetHeader.CloseUIFunc = function() UIManager:GetPanel(EUIType.SelectDifficulty):CloseOtherWidget() end self.WBP_WidgetHeader:Construct() self.ScrollBox_Range:ClearChildren() self.GridItemWidgetClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/ChildWidgets/WBP_DifficultyItem.WBP_DifficultyItem_C')) self.RangeItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/ChildWidgets/WBP_DifficultyRangeItem.WBP_DifficultyRangeItem_C')) self:SetMaxDifficulty(66); self.TextBlock_Total:SetText(string.format("")) EventSystem:AddListener(EventType.PlayerDifficultySelectionChanged, self.OnPlayerDifficultySelectionChange, self) EventSystem:AddListener(EventType.OnGameReadyStageRemainTimeChanged, self.OnGameReadyStageRemainTimeChange, self) --self.UniformGridPanel_Items:ClearChildren() --for i = 1, 10 do -- local Widget = UserWidget.NewWidgetObjectBP(UGCGameSystem.GameState, self.GridItemWidgetClass) -- local Slot = self.UniformGridPanel_Items:AddChildToUniformGrid(Widget) -- Slot:SetColumn(0) -- Slot:SetRow(i - 1) --end end function WBP_SelectDifficultyPanel:OnShowPanel(...) self.HadShow = true; end -- 关闭除了倒计时的其他页面 function WBP_SelectDifficultyPanel:CloseOtherWidget() self.CanvasPanel_Main:SetVisibility(ESlateVisibility.Collapsed); self.TextBlock_SelectDifficultyTip:SetVisibility(ESlateVisibility.Collapsed) end -- function WBP_SelectDifficultyPanel:Tick(MyGeometry, InDeltaTime) -- end function WBP_SelectDifficultyPanel:Destruct() EventSystem:RemoveListener(EventType.PlayerDifficultySelectionChanged, WBP_SelectDifficultyPanel.OnPlayerDifficultySelectionChange, self) EventSystem:RemoveListener(EventType.OnGameReadyStageRemainTimeChanged, WBP_SelectDifficultyPanel.OnGameReadyStageRemainTimeChange, self) end function WBP_SelectDifficultyPanel:OnGameReadyStageRemainTimeChange(RemainTime) if RemainTime <= 0 then self.HorizontalBox_RemainTime:SetVisibility(ESlateVisibility.Collapsed) else self.HorizontalBox_RemainTime:SetVisibility(ESlateVisibility.SelfHitTestInvisible) self.TextBlock_RemainTime:SetText(tostring(RemainTime)) end end function WBP_SelectDifficultyPanel:SetMaxDifficulty(InNum) self.TotalRangeNum = (InNum + 9) // 10 self.MaxDifficulty = InNum for i = 1, self.TotalRangeNum do if UE.IsValid(self.RangeItemClass) and UE.IsValid(UGCGameSystem.GameState) then local RangeItem = UserWidget.NewWidgetObjectBP(UGCGameSystem.GameState, self.RangeItemClass) self.ScrollBox_Range:AddChild(RangeItem) RangeItem:SetRangeNum(i, self.MaxDifficulty) RangeItem:SetIsClick(false) end end self:GetRecommendLevel() end function WBP_SelectDifficultyPanel:GetRecommendLevel() -- 获取存档数据,然后检查之前玩过的局数,可解锁的局数 = 通关过的局数 + 1 local PS = GameDataManager.GetLocalPlayerState() if table.getCount(PS.ArchiveData.PlayedGames) > 0 then -- i: 难度;v: 局数 local MaxDiff = 0 for i, v in pairs(PS.ArchiveData.PlayedGames) do if i > MaxDiff and v > 0 then MaxDiff = i end end self.RecommendLevel = MaxDiff + 1 else self.RecommendLevel = 1 end -- 设置 Range Num过去 self:SetRangeNum((self.RecommendLevel + 9) // 10) end function WBP_SelectDifficultyPanel:SetRangeNum(InNum) print(string.format('[WBP_SelectDifficultyPanel:SetRangeNum] Num = %d', InNum)) if self.CurrentRangeNum == InNum then return end self.CurrentRangeNum = InNum if InNum == self.TotalRangeNum then for i = 1, 10 - self.MaxDifficulty % 10 do self.UniformGridPanel_Items:GetChildAt(10 - i):SetVisibility(ESlateVisibility.Hidden) end else for i = 1, 10 do self.UniformGridPanel_Items:GetChildAt(i - 1):SetVisibility(ESlateVisibility.SelfHitTestInvisible) end end for i = 1, 10 do if self.UniformGridPanel_Items:GetChildAt(i - 1):GetVisibility() == ESlateVisibility.SelfHitTestInvisible then local Difficult = (InNum - 1) * 10 + i self.UniformGridPanel_Items:GetChildAt(i - 1):SetDifficulty(Difficult) end end -- 显示状态 -- 判断最小的是否大于值 if (InNum - 1) * 10 + 1 > self.RecommendLevel then for i = 1, 10 do self.UniformGridPanel_Items:GetChildAt(i - 1):SetVisualType(0) end elseif InNum * 10 < self.RecommendLevel then -- 判断最大的是否小于值 for i = 1, 10 do self.UniformGridPanel_Items:GetChildAt(i - 1):SetVisualType(1) end else --就是在中间 for i = 1, 10 do local Val = self.UniformGridPanel_Items:GetChildAt(i - 1).Difficulty if Val <= self.RecommendLevel then self.UniformGridPanel_Items:GetChildAt(i - 1):SetVisualType(1) else self.UniformGridPanel_Items:GetChildAt(i - 1):SetVisualType(0) end end end -- 找到自己选择的 难度 if self.SelectDifficulty ~= 0 then if (InNum - 1) * 10 + 1 <= self.SelectDifficulty and self.SelectDifficulty <= InNum * 10 then for i = 1, 10 do if self.UniformGridPanel_Items:GetChildAt(i - 1).Difficulty == self.SelectDifficulty then self.UniformGridPanel_Items:GetChildAt(i - 1):SetVisualType(2) break end end end end end function WBP_SelectDifficultyPanel:SetCurrentDifficulty(InNum) print(string.format('[WBP_SelectDifficultyPanel:SetCurrentDifficulty] 选择的难度 = %d', InNum)) self.SelectDifficulty = InNum -- 设置当前的选项 local PC = GameDataManager.GetLocalPlayerController() UnrealNetwork.CallUnrealRPC(PC, PC, "ServerRPC_SelectGameDifficulty", InNum) end function WBP_SelectDifficultyPanel:OnPlayerDifficultySelectionChange(InData) -- 直接显示在最上面的文本框中 if table.getCount(InData) == 0 then return end -- i:难度,v:票数 local ToText = '' for i, v in pairs(InData) do ToText = ToText .. '难度'..tostring(i)..': '.. tostring(v) .. '\t' end self.TextBlock_Total:SetText(ToText) end return WBP_SelectDifficultyPanel;