90 lines
2.3 KiB
Lua
90 lines
2.3 KiB
Lua
---@class WB_PlaySong_C:UUserWidget
|
|
---@field Button_Default UButton
|
|
---@field Button_Music UButton
|
|
---@field Button_NextSong UButton
|
|
---@field Image_Prohibit UImage
|
|
---@field TextBlock_BGMName UTextBlock
|
|
--Edit Below--
|
|
local WB_PlaySong = {
|
|
bInitDoOnce = false;
|
|
MusicList = {};
|
|
};
|
|
|
|
|
|
function WB_PlaySong:Construct()
|
|
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
|
|
self.DefaultBGMType = SoundSystem.EMusic.Music14
|
|
self:PlayBGMFromType(self.DefaultBGMType)
|
|
end
|
|
|
|
|
|
-- function WB_PlaySong:Tick(MyGeometry, InDeltaTime)
|
|
|
|
-- end
|
|
|
|
-- function WB_PlaySong:Destruct()
|
|
|
|
-- end
|
|
|
|
|
|
function WB_PlaySong: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_PlaySong:PlayDefaultBGM()
|
|
if self.IsOpenBGM and self.DefaultBGMType then
|
|
self:PlayBGMFromType(self.DefaultBGMType)
|
|
else
|
|
self.NowBGMType = self.DefaultBGMType
|
|
end
|
|
end
|
|
|
|
function WB_PlaySong: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_PlaySong:NextBGM()
|
|
self:PlayBGMFromType(self:GetNextBGM())
|
|
end
|
|
|
|
function WB_PlaySong: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_PlaySong:StopBGM()
|
|
if self.PlayingBGM then
|
|
UGCSoundManagerSystem.StopSoundByID(self.BGMID)
|
|
end
|
|
self.PlayingBGM = false
|
|
end
|
|
|
|
return WB_PlaySong; |