166 lines
5.1 KiB
Lua
166 lines
5.1 KiB
Lua
---@class WB_PersistentUI_C:UUserWidget
|
|
---@field Button_Default UButton
|
|
---@field Button_Music UButton
|
|
---@field Button_NextSong UButton
|
|
---@field Image_Prohibit UImage
|
|
---@field TextBlock_BGMName UTextBlock
|
|
---@field TextBlock_Desc UTextBlock
|
|
---@field TextBlock_MiniGameName UTextBlock
|
|
---@field TextBlock_MiniGameTime UTextBlock
|
|
---@field TextBlock_MiniGameTipDesc UTextBlock
|
|
---@field TextBlock_Round UTextBlock
|
|
---@field WB_AchievementTasks UWB_AchievementTasks_C
|
|
---@field WidgetSwitcher_TurnBase UWidgetSwitcher
|
|
--Edit Below--
|
|
local WB_PersistentUI = {
|
|
bInitDoOnce = false;
|
|
LastGameTime = 0;
|
|
WillEndTime = 5;
|
|
bShowing = false,
|
|
|
|
|
|
-- BGM Param
|
|
MusicList = {};
|
|
IsOpenBGM = true,
|
|
BGMID = 0,
|
|
PlayingBGM = false,
|
|
NowBGMType = -1;
|
|
DefaultBGMType = -1;
|
|
MaxRound = 1;
|
|
};
|
|
|
|
|
|
function WB_PersistentUI:Construct()
|
|
UGCEventSystem.AddListener(EventEnum.NewMiniGame, self.UpdateMiniGameInfo, self)
|
|
UGCEventSystem.AddListener(EventEnum.MiniGameStart, self.PlayDefaultBGM, self)
|
|
UGCEventSystem.AddListener(EventEnum.MiniGameEnd, self.StopBGM, self)
|
|
|
|
WidgetLibrary.TextBlockBindingPropertyText(self.TextBlock_MiniGameTime, self.UpdateGameTime, self)
|
|
WidgetLibrary.TextBlockBindingPropertyText(self.TextBlock_Round, self.UpdateRound, self)
|
|
WidgetLibrary.BindButtonClicked(self.Button_Music, self.OpenBGM, self)
|
|
WidgetLibrary.BindButtonClicked(self.Button_Default, self.PlayDefaultBGM, self)
|
|
WidgetLibrary.BindButtonClicked(self.Button_NextSong, self.NextBGM, self)
|
|
for i, v in pairs(SoundSystem.EMusic) do
|
|
self.MusicList[#self.MusicList + 1] = v
|
|
end
|
|
end
|
|
|
|
function WB_PersistentUI:OnShowPanel()
|
|
self.bShowing = true
|
|
end
|
|
|
|
function WB_PersistentUI:OnClosePanel()
|
|
self.bShowing = false
|
|
end
|
|
|
|
function WB_PersistentUI:UpdateMiniGameInfo(NewMiniGameType)
|
|
local MiniGameInfo = MiniGameConfig.MiniGameInfo[NewMiniGameType]
|
|
if MiniGameInfo then
|
|
self.TextBlock_MiniGameName:SetText(MiniGameInfo.MiniGameName)
|
|
self.TextBlock_Desc:SetText(MiniGameInfo.DescText)
|
|
self.DefaultBGMType = MiniGameInfo.BGMType
|
|
if MiniGameInfo.IsTurnBase then
|
|
self.MaxRound = MiniGameInfo.GameParam.MaxRound
|
|
self.WidgetSwitcher_TurnBase:SetActiveWidgetIndex(1)
|
|
else
|
|
self.WidgetSwitcher_TurnBase:SetActiveWidgetIndex(0)
|
|
end
|
|
|
|
self.WB_AchievementTasks:SetMapType(NewMiniGameType)
|
|
if MiniGameInfo.TipDesc then
|
|
self.TextBlock_MiniGameTipDesc:SetText(MiniGameInfo.TipDesc)
|
|
else
|
|
self.TextBlock_MiniGameTipDesc:SetText("")
|
|
end
|
|
end
|
|
end
|
|
|
|
function WB_PersistentUI:UpdateGameTime()
|
|
if self.bShowing then
|
|
local GameTime = UGCGameSystem.GameState:GetGameTime()
|
|
if GameTime <= self.WillEndTime and GameTime ~= self.LastGameTime and not WidgetManager:IsVisiblePanel(WidgetConfig.EUIType.MiniGameLoading) then
|
|
if GameTime == 0 then
|
|
-- SoundSystem.PlaySound(SoundSystem.ESound.GameStart)
|
|
else
|
|
local MiniGameInfo = MiniGameConfig.MiniGameInfo[UGCGameSystem.GameState:GetNowMiniGameType()]
|
|
|
|
if MiniGameInfo and MiniGameInfo.EnableWillEndTip then
|
|
SoundSystem.PlaySound(SoundSystem.ESound.Clock)
|
|
end
|
|
end
|
|
end
|
|
self.LastGameTime = GameTime
|
|
return tostring(GameTime)
|
|
end
|
|
return "0"
|
|
end
|
|
|
|
function WB_PersistentUI:UpdateRound()
|
|
return string.format(tostring(UGCGameSystem.GameState:GetMiniGameInternalRound()) .. "/"..tostring(self.MaxRound))
|
|
end
|
|
|
|
-- function WB_PersistentUI:Tick(MyGeometry, InDeltaTime)
|
|
|
|
-- end
|
|
|
|
-- function WB_PersistentUI:Destruct()
|
|
|
|
-- end
|
|
|
|
function WB_PersistentUI:OpenBGM()
|
|
if self.IsOpenBGM then
|
|
self.IsOpenBGM = false
|
|
self.Image_Prohibit:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|
self:StopBGM()
|
|
else
|
|
self.IsOpenBGM = true
|
|
self.Image_Prohibit:SetVisibility(ESlateVisibility.Hidden)
|
|
self:PlayBGMFromType(self.NowBGMType)
|
|
end
|
|
end
|
|
|
|
function WB_PersistentUI:PlayDefaultBGM()
|
|
if self.IsOpenBGM and self.DefaultBGMType then
|
|
self:PlayBGMFromType(self.DefaultBGMType)
|
|
else
|
|
self.NowBGMType = self.DefaultBGMType
|
|
end
|
|
end
|
|
|
|
function WB_PersistentUI:GetNextBGM()
|
|
local Key = table.FindKey(self.MusicList, self.NowBGMType)
|
|
if Key then
|
|
return self.MusicList[(Key % #self.MusicList) + 1]
|
|
else
|
|
return self.MusicList[1]
|
|
end
|
|
end
|
|
|
|
function WB_PersistentUI:NextBGM()
|
|
self:PlayBGMFromType(self:GetNextBGM())
|
|
end
|
|
|
|
function WB_PersistentUI:PlayBGMFromType(SoundType)
|
|
if self.PlayingBGM then
|
|
UGCSoundManagerSystem.StopSoundByID(self.BGMID)
|
|
end
|
|
self.BGMID = SoundSystem.PlaySound(SoundType)
|
|
self.NowBGMType = SoundType
|
|
self.PlayingBGM = true
|
|
|
|
local MusicName = SoundSystem.MusicName[SoundType]
|
|
if MusicName == nil then
|
|
MusicName = "--"
|
|
end
|
|
self.TextBlock_BGMName:SetText(MusicName)
|
|
end
|
|
|
|
function WB_PersistentUI:StopBGM()
|
|
if self.PlayingBGM then
|
|
UGCSoundManagerSystem.StopSoundByID(self.BGMID)
|
|
end
|
|
self.PlayingBGM = false
|
|
end
|
|
|
|
|
|
return WB_PersistentUI; |