* Apply R# clean-up for reliability - Migrate to NUnit4 Assert.That - Update dependencise versions - Fix LangVersion to 9.0 (until net core migration) - Reformat code - Apply 'var' style (easier for refactoring) - Remove redundant parentheses - Add braces on every condition blocks (1 line) - Uses new null checking patterns - Uses AutoProperties when possible - Uses string scalar type instead of class - Clean usings - Add .orig files in git ignore - Rename some properties to respect defined conventions and US format definition - ID -> Id - BPM -> Bpm - Finish -> End * Update R# settings according to the clean-up made
347 lines
9.7 KiB
C#
347 lines
9.7 KiB
C#
#region license
|
|
// This file is part of Vocaluxe.
|
|
//
|
|
// Vocaluxe is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Vocaluxe is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
|
#endregion
|
|
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Xml.Serialization;
|
|
using VocaluxeLib.Draw;
|
|
|
|
namespace VocaluxeLib.Menu
|
|
{
|
|
public enum EBackgroundTypes
|
|
{
|
|
None,
|
|
Color,
|
|
Texture,
|
|
SlideShow,
|
|
Video
|
|
}
|
|
|
|
[XmlType("Background")]
|
|
public struct SThemeBackground
|
|
{
|
|
[XmlAttribute(AttributeName = "Name")]
|
|
public string Name;
|
|
public EBackgroundTypes Type;
|
|
[XmlArray]
|
|
public List<string> SlideShowTextures;
|
|
[XmlElement("Video")]
|
|
public string VideoName;
|
|
public string Skin;
|
|
public SThemeColor Color;
|
|
}
|
|
|
|
public class CBackground : CMenuElementBase, IMenuElement, IThemeable
|
|
{
|
|
private readonly int _PartyModeId;
|
|
private SThemeBackground _Theme;
|
|
|
|
private int _SlideShowCurrent;
|
|
private readonly Stopwatch _SlideShowTimer = new Stopwatch();
|
|
private readonly List<CTextureRef> _SlideShowTextures = new List<CTextureRef>();
|
|
|
|
private CVideoStream _VideoStream;
|
|
|
|
public bool Selectable
|
|
{
|
|
get { return false; }
|
|
}
|
|
|
|
public SColorF Color;
|
|
public bool ThemeLoaded { get; private set; }
|
|
|
|
public string GetThemeName()
|
|
{
|
|
return _Theme.Name;
|
|
}
|
|
|
|
#region Constructors
|
|
public CBackground(int partyModeId)
|
|
{
|
|
_PartyModeId = partyModeId;
|
|
ThemeLoaded = false;
|
|
_Theme = new SThemeBackground { SlideShowTextures = new List<string>() };
|
|
|
|
Color = new SColorF(0f, 0f, 0f, 1f);
|
|
}
|
|
|
|
public CBackground(SThemeBackground theme, int partyModeId)
|
|
{
|
|
_Theme = theme;
|
|
_PartyModeId = partyModeId;
|
|
|
|
ThemeLoaded = true;
|
|
}
|
|
#endregion Constructors
|
|
|
|
#region public
|
|
public void Resume()
|
|
{
|
|
if (_VideoStream != null)
|
|
{
|
|
CBase.Video.Resume(_VideoStream);
|
|
}
|
|
}
|
|
|
|
public void Pause()
|
|
{
|
|
if (_VideoStream != null)
|
|
{
|
|
CBase.Video.Pause(_VideoStream);
|
|
}
|
|
}
|
|
|
|
public void Draw()
|
|
{
|
|
var ok = false;
|
|
if (_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON)
|
|
{
|
|
if (CBase.Config.GetVideosToBackground() == EOffOn.TR_CONFIG_ON && CBase.BackgroundMusic.IsPlaying() && CBase.BackgroundMusic.SongHasVideo() &&
|
|
CBase.BackgroundMusic.VideoEnabled())
|
|
{
|
|
Pause();
|
|
ok = _DrawBackgroundMusicVideo();
|
|
}
|
|
else
|
|
{
|
|
Resume();
|
|
ok = _DrawVideo();
|
|
}
|
|
}
|
|
else if (_Theme.Type == EBackgroundTypes.SlideShow && _SlideShowTextures.Count > 0)
|
|
{
|
|
ok = _DrawSlideShow();
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(_Theme.Skin) && (_Theme.Type == EBackgroundTypes.Texture || !ok))
|
|
{
|
|
ok = _DrawTexture();
|
|
}
|
|
|
|
if (_Theme.Type == EBackgroundTypes.Color || !ok)
|
|
{
|
|
_DrawColor();
|
|
}
|
|
}
|
|
|
|
public void UnloadSkin()
|
|
{
|
|
if (!ThemeLoaded)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_SlideShowTextures.Clear();
|
|
CBase.Video.Close(ref _VideoStream);
|
|
}
|
|
|
|
public void LoadSkin()
|
|
{
|
|
if (!ThemeLoaded)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_Theme.Color.Get(_PartyModeId, out Color);
|
|
|
|
if (_Theme.Type == EBackgroundTypes.SlideShow)
|
|
{
|
|
foreach (var s in _Theme.SlideShowTextures)
|
|
{
|
|
_SlideShowTextures.Add(CBase.Themes.GetSkinTexture(s, _PartyModeId));
|
|
}
|
|
}
|
|
|
|
if (_Theme.Type == EBackgroundTypes.Video)
|
|
{
|
|
_VideoStream = CBase.Themes.GetSkinVideo(_Theme.VideoName, _PartyModeId, true);
|
|
}
|
|
}
|
|
|
|
public void AddSlideShowTexture(string image)
|
|
{
|
|
_Theme.Type = EBackgroundTypes.SlideShow;
|
|
if (!string.IsNullOrEmpty(image))
|
|
{
|
|
var texture = _SlideShowTextures.Count == 0 ? CBase.Drawing.AddTexture(image) : CBase.Drawing.EnqueueTexture(image);
|
|
if (texture != null)
|
|
{
|
|
_SlideShowTextures.Add(texture);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RemoveSlideShowTextures()
|
|
{
|
|
foreach (var tex in _SlideShowTextures)
|
|
{
|
|
var texture = tex;
|
|
CBase.Drawing.RemoveTexture(ref texture);
|
|
}
|
|
|
|
_SlideShowTextures.Clear();
|
|
}
|
|
|
|
public void ReloadSkin()
|
|
{
|
|
UnloadSkin();
|
|
LoadSkin();
|
|
}
|
|
|
|
public object GetTheme()
|
|
{
|
|
return _Theme;
|
|
}
|
|
#endregion public
|
|
|
|
#region internal
|
|
public override float X
|
|
{
|
|
get { return 0; }
|
|
}
|
|
public override float Y
|
|
{
|
|
get { return 0; }
|
|
}
|
|
public override float Z
|
|
{
|
|
get { return CBase.Settings.GetZFar() / 4; }
|
|
}
|
|
public override float W
|
|
{
|
|
get { return CBase.Settings.GetRenderW(); }
|
|
}
|
|
public override float H
|
|
{
|
|
get { return CBase.Settings.GetRenderH(); }
|
|
}
|
|
|
|
private void _DrawColor()
|
|
{
|
|
CBase.Drawing.DrawRect(Color, Rect);
|
|
}
|
|
|
|
private bool _DrawTexture()
|
|
{
|
|
var texture = CBase.Themes.GetSkinTexture(_Theme.Skin, _PartyModeId);
|
|
if (texture != null)
|
|
{
|
|
CBase.Drawing.DrawTexture(texture, Rect, EAspect.Crop);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private bool _DrawSlideShow()
|
|
{
|
|
if (_SlideShowTextures.Count > 0)
|
|
{
|
|
if (!_SlideShowTimer.IsRunning)
|
|
{
|
|
_SlideShowTimer.Start();
|
|
_SlideShowCurrent = 0;
|
|
}
|
|
|
|
if (_SlideShowTimer.ElapsedMilliseconds >= CBase.Settings.GetSlideShowFadeTime() + CBase.Settings.GetSlideShowImageTime())
|
|
{
|
|
_SlideShowTimer.Restart();
|
|
if (_SlideShowCurrent + 1 < _SlideShowTextures.Count)
|
|
{
|
|
_SlideShowCurrent++;
|
|
}
|
|
else
|
|
{
|
|
_SlideShowCurrent = 0;
|
|
}
|
|
}
|
|
|
|
var texture = _SlideShowTextures[_SlideShowCurrent];
|
|
|
|
if (texture == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
CBase.Drawing.DrawTexture(texture, Rect, EAspect.Crop);
|
|
|
|
if (_SlideShowTimer.ElapsedMilliseconds >= CBase.Settings.GetSlideShowImageTime())
|
|
{
|
|
if (_SlideShowCurrent + 1 < _SlideShowTextures.Count)
|
|
{
|
|
texture = _SlideShowTextures[_SlideShowCurrent + 1];
|
|
}
|
|
else if (_SlideShowCurrent != 0)
|
|
{
|
|
texture = _SlideShowTextures[0];
|
|
}
|
|
else
|
|
{
|
|
texture = null;
|
|
}
|
|
|
|
if (texture != null)
|
|
{
|
|
var color = texture.Color;
|
|
color.A = (_SlideShowTimer.ElapsedMilliseconds - CBase.Settings.GetSlideShowImageTime()) / CBase.Settings.GetSlideShowFadeTime();
|
|
CBase.Drawing.DrawTexture(texture, Rect, EAspect.Crop, color);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private bool _DrawVideo()
|
|
{
|
|
if (_VideoStream != null)
|
|
{
|
|
CBase.Video.GetFrame(_VideoStream, _VideoStream.VideoTime);
|
|
if (_VideoStream.Texture != null)
|
|
{
|
|
CBase.Drawing.DrawTexture(_VideoStream.Texture, Rect, EAspect.Crop);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private bool _DrawBackgroundMusicVideo()
|
|
{
|
|
var videoTexture = CBase.BackgroundMusic.GetVideoTexture();
|
|
if (videoTexture != null)
|
|
{
|
|
CBase.Drawing.DrawTexture(videoTexture, Rect, EAspect.Crop);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
#endregion internal
|
|
|
|
#region ThemeEdit
|
|
public void MoveElement(int stepX, int stepY) { }
|
|
|
|
public void ResizeElement(int stepW, int stepH) { }
|
|
#endregion ThemeEdit
|
|
}
|
|
} |