Paused shellmap music when opening videos in the AssetBrowser

This commit is contained in:
penev92
2021-02-07 19:22:38 +02:00
committed by Matthias Mailänder
parent a058b1f5bd
commit 6907081c2b

View File

@@ -307,6 +307,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
if (isVideoLoaded) if (isVideoLoaded)
player.Stop(); player.Stop();
UnMuteSounds();
Ui.CloseWindow(); Ui.CloseWindow();
onExit(); onExit();
}; };
@@ -419,18 +421,26 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
currentVoxel = null; currentVoxel = null;
// Just in case we're switching away from a type of asset that forced the music to pause.
UnMuteSounds();
} }
else if (allowedModelExtensions.Contains(fileExtension)) else if (allowedModelExtensions.Contains(fileExtension))
{ {
var voxelName = Path.GetFileNameWithoutExtension(filename); var voxelName = Path.GetFileNameWithoutExtension(filename);
currentVoxel = world.ModelCache.GetModel(voxelName); currentVoxel = world.ModelCache.GetModel(voxelName);
currentSprites = null; currentSprites = null;
// Just in case we're switching away from a type of asset that forced the music to pause.
UnMuteSounds();
} }
else if (allowedVideoExtensions.Contains(fileExtension)) else if (allowedVideoExtensions.Contains(fileExtension))
{ {
var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), Game.ModData.VideoLoaders); var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), Game.ModData.VideoLoaders);
if (video != null) if (video != null)
{ {
// Pause music so it doesn't interfere with current asset.
MuteSounds();
player = panel.Get<VideoPlayerWidget>("PLAYER"); player = panel.Get<VideoPlayerWidget>("PLAYER");
player.Load(prefix + filename); player.Load(prefix + filename);
@@ -553,5 +563,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return name; return name;
} }
// Mute/UnMute code copied from MissionBrowserLogic.
float cachedMusicVolume;
void MuteSounds()
{
if (Game.Sound.MusicVolume > 0)
{
cachedMusicVolume = Game.Sound.MusicVolume;
Game.Sound.MusicVolume = 0;
}
}
void UnMuteSounds()
{
if (cachedMusicVolume > 0)
Game.Sound.MusicVolume = cachedMusicVolume;
}
} }
} }