Apply R# clean-up for reliability (#877)

* 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
This commit is contained in:
Quentin Bray authored and GitHub committed 2026-06-22 19:52:06 +02:00
1 parent b9b0f7c8df
commit 6ffa63b923
236 files changed
+14194 -7278

No files matched your search

+7 -14
View File
@@ -21,34 +21,27 @@ namespace VocaluxeLib.Menu.SongMenu
{
public static class CSongMenuFactory
{
public static ISongMenu CreateSongMenu(SThemeSongMenu theme, int partyModeID)
public static ISongMenu CreateSongMenu(SThemeSongMenu theme, int partyModeId)
{
switch (CBase.Config.GetSongMenuType())
{
case ESongMenu.TR_CONFIG_LIST:
return new CSongMenuList(theme, partyModeID);
//case ESongMenu.TR_CONFIG_DREIDEL:
// _SongMenu = new CSongMenuDreidel();
// break;
return new CSongMenuList(theme, partyModeId);
case ESongMenu.TR_CONFIG_TILE_BOARD:
return new CSongMenuTileBoard(theme, partyModeID);
//case ESongMenu.TR_CONFIG_BOOK:
// _SongMenu = new CSongMenuBook();
// break;
return new CSongMenuTileBoard(theme, partyModeId);
}
throw new ArgumentException("Invalid songmenu type: " + CBase.Config.GetSongMenuType());
}
/// <summary>
/// Deprecated! Only used for old theme loading.
/// </summary>
/// <param name="partyModeID"></param>
/// <param name="partyModeId"></param>
/// <returns></returns>
public static ISongMenu CreateSongMenu(int partyModeID)
public static ISongMenu CreateSongMenu(int partyModeId)
{
return new CSongMenuTileBoard(partyModeID);
return new CSongMenuTileBoard(partyModeId);
}
}
}
+82 -21
View File
@@ -18,14 +18,14 @@
using System.Diagnostics;
using System.Xml.Serialization;
using VocaluxeLib.PartyModes;
using VocaluxeLib.Songs;
namespace VocaluxeLib.Menu.SongMenu
{
[XmlType("SongMenu")]
public struct SThemeSongMenu
{
[XmlAttribute(AttributeName = "Name")] public string Name;
[XmlAttribute(AttributeName = "Name")]
public string Name;
public string CoverBackground;
public string CoverBigBackground;
@@ -43,6 +43,7 @@ namespace VocaluxeLib.Menu.SongMenu
public SThemeSongMenuList SongMenuList;
public SThemeSongMenuTileBoard SongMenuTileBoard;
}
public struct SThemeSongMenuList
{
/// <summary>
@@ -79,7 +80,6 @@ namespace VocaluxeLib.Menu.SongMenu
public SThemeStatic StaticMedleyTagIcon;
}
public struct SThemeSongMenuTileBoard
{
/// <summary>
@@ -133,7 +133,7 @@ namespace VocaluxeLib.Menu.SongMenu
public abstract class CSongMenuFramework : CMenuElementBase, ISongMenu
{
protected readonly int _PartyModeID;
protected readonly int _PartyModeId;
protected SThemeSongMenu _Theme;
public bool ThemeLoaded { get; private set; }
@@ -152,11 +152,17 @@ namespace VocaluxeLib.Menu.SongMenu
set
{
if (_PreviewNrInternal == value)
{
return;
}
if (CBase.Songs.IsInCategory())
{
if (value >= CBase.Songs.GetNumSongsVisible())
{
value = -1;
}
_PlaySong(value);
}
else if (value >= CBase.Songs.GetNumCategories())
@@ -188,16 +194,16 @@ namespace VocaluxeLib.Menu.SongMenu
// This is the nr of the current selection (song or category)
protected virtual int _SelectionNr { get; set; }
protected CSongMenuFramework(int partyModeID)
protected CSongMenuFramework(int partyModeId)
{
Visible = true;
_PartyModeID = partyModeID;
_PartyModeId = partyModeId;
}
protected CSongMenuFramework(SThemeSongMenu theme, int partyModeID)
protected CSongMenuFramework(SThemeSongMenu theme, int partyModeId)
{
Visible = true;
_PartyModeID = partyModeID;
_PartyModeId = partyModeId;
_Theme = theme;
ThemeLoaded = true;
@@ -228,11 +234,16 @@ namespace VocaluxeLib.Menu.SongMenu
public virtual void OnHide()
{
EScreen check = CBase.Graphics.GetNextScreenType();
var check = CBase.Graphics.GetNextScreenType();
if (CBase.Graphics.GetNextScreenType() == EScreen.Sing)
{
_ResetPreview(false);
else if ((CBase.Graphics.GetNextScreenType() != EScreen.Names && CBase.Graphics.GetNextScreenType() != EScreen.Highscore) || CBase.Config.GetBackgroundMusicStatus() == EBackgroundMusicOffOn.TR_CONFIG_OFF)
}
else if ((CBase.Graphics.GetNextScreenType() != EScreen.Names && CBase.Graphics.GetNextScreenType() != EScreen.Highscore) ||
CBase.Config.GetBackgroundMusicStatus() == EBackgroundMusicOffOn.TR_CONFIG_OFF)
{
_ResetPreview();
}
}
public abstract bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options);
@@ -242,29 +253,39 @@ namespace VocaluxeLib.Menu.SongMenu
public virtual void Draw()
{
if (!_Initialized || !Visible)
{
return;
}
if (CBase.BackgroundMusic.IsPlaying())
{
CBase.Drawing.DrawTexture(CBase.BackgroundMusic.GetVideoTexture(), new SRectF(0, 0, 1920, 1080, 0));
}
}
public virtual bool IsMouseOverSelectedSong(SMouseEvent mEvent)
{
CStatic selCov = GetSelectedSongCover();
var selCov = GetSelectedSongCover();
return selCov != null && CHelper.IsInBounds(selCov.Rect.Scale(SelectedTileZoomFactor), mEvent);
}
public int GetPreviewSongNr()
{
if (CBase.Songs.IsInCategory())
{
return _PreviewNr;
}
return -1;
}
public int GetSelectedSongNr()
{
if (CBase.Songs.IsInCategory())
{
return _SelectionNr;
}
return -1;
}
@@ -273,7 +294,10 @@ namespace VocaluxeLib.Menu.SongMenu
public int GetSelectedCategory()
{
if (!CBase.Songs.IsInCategory())
{
return _SelectionNr;
}
return -1;
}
@@ -281,9 +305,14 @@ namespace VocaluxeLib.Menu.SongMenu
{
Debug.Assert(CBase.Songs.IsInCategory());
if (visibleSongNr >= 0 && visibleSongNr < CBase.Songs.GetNumSongsVisible())
{
_SelectionNr = visibleSongNr;
}
else
{
_SelectionNr = -1;
}
_PreviewNr = _SelectionNr;
}
@@ -291,33 +320,44 @@ namespace VocaluxeLib.Menu.SongMenu
{
Debug.Assert(!CBase.Songs.IsInCategory());
if (categoryNr >= 0 && categoryNr < CBase.Songs.GetNumCategories())
{
_SelectionNr = categoryNr;
}
else
{
_SelectionNr = -1;
}
_PreviewNr = _SelectionNr;
}
public void LeaveSelectedCategory()
{
if (!CBase.Songs.IsInCategory())
{
return;
}
int oldCategory = CBase.Songs.GetCurrentCategoryIndex();
var oldCategory = CBase.Songs.GetCurrentCategoryIndex();
_LeaveCategory();
if (oldCategory >= 0 && oldCategory < CBase.Songs.GetNumCategories())
{
SetSelectedCategory(oldCategory);
}
else if (CBase.Songs.GetNumCategories() > 0)
{
SetSelectedCategory(0);
}
}
public virtual void UnloadSkin() {}
public virtual void UnloadSkin() { }
public virtual void LoadSkin()
{
Init();
_Theme.Color.Get(_PartyModeID, out _ColorInternal);
_Theme.Color.Get(_PartyModeId, out _ColorInternal);
}
public void ReloadSkin()
@@ -329,9 +369,15 @@ namespace VocaluxeLib.Menu.SongMenu
public bool EnterSelectedCategory()
{
if (!_Initialized)
{
return false;
}
if (CBase.Songs.IsInCategory() || GetSelectedCategory() < 0 || GetSelectedCategory() >= CBase.Songs.GetNumCategories())
{
return false;
}
_EnterCategory(GetSelectedCategory());
return true;
}
@@ -339,10 +385,14 @@ namespace VocaluxeLib.Menu.SongMenu
protected virtual void _EnterCategory(int categoryNr)
{
if (!_Initialized)
{
return;
}
if (categoryNr >= CBase.Songs.GetNumCategories())
{
return;
}
_ResetPreview(false);
CBase.Songs.SetCategory(categoryNr);
@@ -351,10 +401,14 @@ namespace VocaluxeLib.Menu.SongMenu
protected virtual void _LeaveCategory()
{
if (!_Initialized)
{
return;
}
if (!CBase.Songs.IsInCategory())
{
return;
}
_ResetPreview();
CBase.Songs.SetCategory(-1);
@@ -364,9 +418,11 @@ namespace VocaluxeLib.Menu.SongMenu
{
_PreviewNrInternal = -1;
CSong song = CBase.Songs.GetVisibleSong(nr);
var song = CBase.Songs.GetVisibleSong(nr);
if (song == null)
{
return;
}
CBase.BackgroundMusic.LoadPreview(song, song.Preview.StartTime);
}
@@ -374,12 +430,16 @@ namespace VocaluxeLib.Menu.SongMenu
protected void _ResetPreview(bool playBGagain = true)
{
if (_PreviewNrInternal == -1)
{
return;
}
CBase.BackgroundMusic.StopPreview();
CBase.Sound.SetGlobalVolume(CBase.Config.GetMusicVolume(EMusicType.Background));
if (playBGagain)
{
CBase.BackgroundMusic.Play();
}
//Make sure we don't have a preview here otherwise a change won't be recognized
//(e.g. leave a category with one song and set preview to 0 --> previewOld=previewNew=0 --> No change --> Old data shown
@@ -396,10 +456,7 @@ namespace VocaluxeLib.Menu.SongMenu
{
_AutoplayTimer.Interval = _AutoplayDelayinMs;
_AutoplayTimer.AutoReset = false;
_AutoplayTimer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) =>
{
_PreviewSelectedSong();
};
_AutoplayTimer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => { _PreviewSelectedSong(); };
}
protected void _AutoplayPreviewIfEnabled()
@@ -408,7 +465,7 @@ namespace VocaluxeLib.Menu.SongMenu
{
_PlayPreviewAfterDelay();
}
}
}
protected void _PlayPreviewAfterDelay()
{
@@ -435,14 +492,18 @@ namespace VocaluxeLib.Menu.SongMenu
{
W += stepW;
if (W < 100)
{
W = 100;
}
H += stepH;
if (H < 100)
{
H = 100;
}
Init();
}
#endregion ThemeEdit
}
}
}
+230 -91
View File
@@ -77,7 +77,7 @@ namespace VocaluxeLib.Menu.SongMenu
{
set
{
int max = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
var max = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
base._SelectionNr = value.Clamp(-1, max - 1, true);
//Update list in case we scrolled
_UpdateList();
@@ -91,7 +91,10 @@ namespace VocaluxeLib.Menu.SongMenu
set
{
if (SmallView == value)
{
return;
}
base.SmallView = value;
_InitTiles();
_UpdateList(true);
@@ -106,33 +109,38 @@ namespace VocaluxeLib.Menu.SongMenu
if (value == base._PreviewNr)
{
if (!CBase.BackgroundMusic.IsPlaying() && value != -1)
{
CBase.BackgroundMusic.Play();
}
return;
}
base._PreviewNr = value;
_UpdatePreview();
}
}
public CSongMenuList(SThemeSongMenu theme, int partyModeID) : base(theme, partyModeID)
public CSongMenuList(SThemeSongMenu theme, int partyModeId) : base(theme, partyModeId)
{
_ListLength = _Theme.SongMenuList.ListLength;
_SpaceW = _Theme.SongMenuList.SpaceW;
_SpaceH = _Theme.SongMenuList.SpaceH;
_Artist = new CText(_Theme.SongMenuList.TextArtist, _PartyModeID);
_Title = new CText(_Theme.SongMenuList.TextTitle, _PartyModeID);
_SongLength = new CText(_Theme.SongMenuList.TextSongLength, _PartyModeID);
_SongYear = new CText(_Theme.SongMenuList.TextSongYear, _PartyModeID);
_CoverBig = new CStatic(_Theme.SongMenuList.StaticCoverBig, _PartyModeID);
_TextBG = new CStatic(_Theme.SongMenuList.StaticTextBG, _PartyModeID);
_DuetIcon = new CStatic(_Theme.SongMenuList.StaticDuetIcon, _PartyModeID);
_RapIcon = new CStatic(_Theme.SongMenuList.StaticRapIcon, _PartyModeID);
_VideoIcon = new CStatic(_Theme.SongMenuList.StaticVideoIcon, _PartyModeID);
_MedleyCalcIcon = new CStatic(_Theme.SongMenuList.StaticMedleyCalcIcon, _PartyModeID);
_MedleyTagIcon = new CStatic(_Theme.SongMenuList.StaticMedleyTagIcon, _PartyModeID);
_InstrumentalIcon = new CStatic(_Theme.SongMenuList.StaticInstrumentalIcon, _PartyModeID);
_VocalsIcon = new CStatic(_Theme.SongMenuList.StaticVocalsIcon, _PartyModeID);
_SubElements.AddRange(new IMenuElement[] {_Artist, _Title, _SongLength, _SongYear, _DuetIcon, _RapIcon, _VideoIcon, _MedleyCalcIcon, _MedleyTagIcon, _InstrumentalIcon, _VocalsIcon});
_Artist = new CText(_Theme.SongMenuList.TextArtist, _PartyModeId);
_Title = new CText(_Theme.SongMenuList.TextTitle, _PartyModeId);
_SongLength = new CText(_Theme.SongMenuList.TextSongLength, _PartyModeId);
_SongYear = new CText(_Theme.SongMenuList.TextSongYear, _PartyModeId);
_CoverBig = new CStatic(_Theme.SongMenuList.StaticCoverBig, _PartyModeId);
_TextBG = new CStatic(_Theme.SongMenuList.StaticTextBG, _PartyModeId);
_DuetIcon = new CStatic(_Theme.SongMenuList.StaticDuetIcon, _PartyModeId);
_RapIcon = new CStatic(_Theme.SongMenuList.StaticRapIcon, _PartyModeId);
_VideoIcon = new CStatic(_Theme.SongMenuList.StaticVideoIcon, _PartyModeId);
_MedleyCalcIcon = new CStatic(_Theme.SongMenuList.StaticMedleyCalcIcon, _PartyModeId);
_MedleyTagIcon = new CStatic(_Theme.SongMenuList.StaticMedleyTagIcon, _PartyModeId);
_InstrumentalIcon = new CStatic(_Theme.SongMenuList.StaticInstrumentalIcon, _PartyModeId);
_VocalsIcon = new CStatic(_Theme.SongMenuList.StaticVocalsIcon, _PartyModeId);
_SubElements.AddRange(new IMenuElement[]
{ _Artist, _Title, _SongLength, _SongYear, _DuetIcon, _RapIcon, _VideoIcon, _MedleyCalcIcon, _MedleyTagIcon, _InstrumentalIcon, _VocalsIcon });
}
private void _ReadSubTheme()
@@ -173,36 +181,36 @@ namespace VocaluxeLib.Menu.SongMenu
_TileW = (int)((MaxRect.H - _SpaceH * (_ListLength - 1)) / _ListLength);
_TileH = _TileW;
float _ListTextWidth = MaxRect.W - (_TileW + _SpaceW);
var _ListTextWidth = MaxRect.W - (_TileW + _SpaceW);
_CoverBGTexture = CBase.Themes.GetSkinTexture(_Theme.CoverBackground, _PartyModeID);
_CoverBigBGTexture = CBase.Themes.GetSkinTexture(_Theme.CoverBigBackground, _PartyModeID);
_CoverBGTexture = CBase.Themes.GetSkinTexture(_Theme.CoverBackground, _PartyModeId);
_CoverBigBGTexture = CBase.Themes.GetSkinTexture(_Theme.CoverBigBackground, _PartyModeId);
//Create cover tiles
_RowBackgrounds = new List<CStatic>();
_Tiles = new List<CStatic>();
_Texts = new List<CText>();
for (int i = 0; i < _ListLength; i++)
for (var i = 0; i < _ListLength; i++)
{
//Create Cover
float y = Rect.Y + i * (_TileH + _SpaceH);
var y = Rect.Y + i * (_TileH + _SpaceH);
float bgHeight = _TileH + 8f;
var bgHeight = _TileH + 8f;
var rowRect = new SRectF(Rect.X, y - 4f, Rect.W, bgHeight, Rect.Z + 0.05f);
var rowBackground = new CStatic(_PartyModeID, _CoverBGTexture, _Color, rowRect);
var rowBackground = new CStatic(_PartyModeId, _CoverBGTexture, _Color, rowRect);
rowBackground.Color = new SColorF(1f, 1f, 1f, 0f);
_RowBackgrounds.Add(rowBackground);
var rect = new SRectF(Rect.X, y, _TileW, _TileH, Rect.Z);
var tile = new CStatic(_PartyModeID, _CoverBGTexture, _Color, rect);
var tile = new CStatic(_PartyModeId, _CoverBGTexture, _Color, rect);
_Tiles.Add(tile);
//Create text
var textRect = new SRectF(MaxRect.X + (_TileW + _SpaceW), y, _ListTextWidth, _TileH, Rect.Z);
CText text = new CText(textRect.X, textRect.Y, textRect.Z, textRect.H, textRect.W, EAlignment.Left, EStyle.Normal, "Normal", _Artist.Color, "");
var text = new CText(textRect.X, textRect.Y, textRect.Z, textRect.H, textRect.W, EAlignment.Left, EStyle.Normal, "Normal", _Artist.Color, "");
text.MaxRect = new SRectF(text.MaxRect.X, text.MaxRect.Y, MaxRect.W + MaxRect.X - text.Rect.X - 5f, text.MaxRect.H, text.MaxRect.Z);
text.ResizeAlign = EHAlignment.Center;
@@ -213,42 +221,50 @@ namespace VocaluxeLib.Menu.SongMenu
}
private void _UpdateTileSelection()
{
for (int i = 0; i < _Tiles.Count; i++)
{
_Tiles[i].Selected = false;
{
for (var i = 0; i < _Tiles.Count; i++)
{
_Tiles[i].Selected = false;
if (i < _RowBackgrounds.Count)
_RowBackgrounds[i].Color = new SColorF(1f, 1f, 1f, 0f);
}
if (i < _RowBackgrounds.Count)
{
_RowBackgrounds[i].Color = new SColorF(1f, 1f, 1f, 0f);
}
}
int tileNr = _SelectionNr - _Offset;
if (tileNr >= 0 && tileNr < _Tiles.Count)
{
_Tiles[tileNr].Selected = true;
var tileNr = _SelectionNr - _Offset;
if (tileNr >= 0 && tileNr < _Tiles.Count)
{
_Tiles[tileNr].Selected = true;
if (tileNr < _RowBackgrounds.Count)
_RowBackgrounds[tileNr].Color = new SColorF(1f, 1f, 1f, 0.25f);
}
}
if (tileNr < _RowBackgrounds.Count)
{
_RowBackgrounds[tileNr].Color = new SColorF(1f, 1f, 1f, 0.25f);
}
}
}
public override void Update(SScreenSongOptions songOptions)
{
if (songOptions.Selection.RandomOnly)
{
_PreviewSelectedSong();
}
if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.BackgroundMusic.GetLength() > 0)
{
_UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr));
}
}
private void _UpdatePreview()
{
//First hide everything so we just have to set what we actually want
_CoverBig.Texture = _CoverBigBGTexture;
_Artist.Text = String.Empty;
_Title.Text = String.Empty;
_SongLength.Text = String.Empty;
_SongYear.Text = String.Empty;
_Artist.Text = string.Empty;
_Title.Text = string.Empty;
_SongLength.Text = string.Empty;
_SongYear.Text = string.Empty;
_DuetIcon.Visible = false;
_RapIcon.Visible = false;
_VideoIcon.Visible = false;
@@ -260,23 +276,29 @@ namespace VocaluxeLib.Menu.SongMenu
//Check if nothing is selected (for preview)
if (_PreviewNr < 0)
{
return;
}
if (CBase.Songs.IsInCategory())
{
CSong song = CBase.Songs.GetVisibleSong(_PreviewNr);
var song = CBase.Songs.GetVisibleSong(_PreviewNr);
//Check if we have a valid song (song still visible, index >=0 etc is checked by framework)
if (song == null)
{
//Display at least the category
CCategory category = CBase.Songs.GetCategory(CBase.Songs.GetCurrentCategoryIndex());
var category = CBase.Songs.GetCategory(CBase.Songs.GetCurrentCategoryIndex());
//Check if we have a valid category
if (category == null)
{
return;
}
_CoverBig.Texture = category.CoverTextureBig;
_Artist.Text = category.Name;
return;
}
_CoverBig.Texture = song.CoverTextureBig;
_Artist.Text = song.Artist;
_Title.Text = song.Title;
@@ -293,15 +315,18 @@ namespace VocaluxeLib.Menu.SongMenu
}
else
{
CCategory category = CBase.Songs.GetCategory(_PreviewNr);
var category = CBase.Songs.GetCategory(_PreviewNr);
//Check if we have a valid category
if (category == null)
{
return;
}
_CoverBig.Texture = category.CoverTextureBig;
_Artist.Text = category.Name;
int num = category.GetNumSongsNotSung();
String songOrSongs = (num == 1) ? "TR_SCREENSONG_NUMSONG" : "TR_SCREENSONG_NUMSONGS";
var num = category.GetNumSongsNotSung();
var songOrSongs = num == 1 ? "TR_SCREENSONG_NUMSONG" : "TR_SCREENSONG_NUMSONGS";
_Title.Text = CBase.Language.Translate(songOrSongs).Replace("%v", num.ToString());
}
}
@@ -309,10 +334,15 @@ namespace VocaluxeLib.Menu.SongMenu
private void _UpdateLength(CSong song)
{
if (song == null)
{
return;
float time = CBase.BackgroundMusic.GetLength();
if (Math.Abs(song.Finish) > 0.001)
time = song.Finish;
}
var time = CBase.BackgroundMusic.GetLength();
if (Math.Abs(song.End) > 0.001)
{
time = song.End;
}
// The audiobackend is ready to return the length
if (time > 0)
@@ -324,7 +354,9 @@ namespace VocaluxeLib.Menu.SongMenu
_Length = time;
}
else
{
_SongLength.Text = "...";
}
}
public override void OnShow()
@@ -333,12 +365,20 @@ namespace VocaluxeLib.Menu.SongMenu
if (!CBase.Songs.IsInCategory())
{
if ((CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0) || CBase.Songs.GetNumCategories() == 1)
{
_EnterCategory(0);
}
}
if (CBase.Songs.IsInCategory())
{
SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr);
}
else
{
SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr);
}
_PreviewSelectedSong();
_UpdateListIfRequired();
}
@@ -346,14 +386,18 @@ namespace VocaluxeLib.Menu.SongMenu
public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options)
{
if (keyEvent.KeyPressed)
{
return false;
}
bool moveAllowed = !options.Selection.RandomOnly || (options.Selection.CategoryChangeAllowed && !CBase.Songs.IsInCategory());
bool catChangePossible = CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && options.Selection.CategoryChangeAllowed;
var moveAllowed = !options.Selection.RandomOnly || (options.Selection.CategoryChangeAllowed && !CBase.Songs.IsInCategory());
var catChangePossible = CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && options.Selection.CategoryChangeAllowed;
//If nothing selected set a reasonable default value
if (keyEvent.IsArrowKey() && moveAllowed && _SelectionNr < 0)
_SelectionNr = (_PreviewNr < 0) ? _Offset : _PreviewNr;
{
_SelectionNr = _PreviewNr < 0 ? _Offset : _PreviewNr;
}
switch (keyEvent.Key)
{
@@ -371,6 +415,7 @@ namespace VocaluxeLib.Menu.SongMenu
_EnterCategory(_PreviewNr);
keyEvent.Handled = true;
}
break;
case Keys.Escape:
@@ -380,6 +425,7 @@ namespace VocaluxeLib.Menu.SongMenu
LeaveSelectedCategory();
keyEvent.Handled = true;
}
break;
case Keys.PageUp:
@@ -390,12 +436,18 @@ namespace VocaluxeLib.Menu.SongMenu
}
else if (moveAllowed)
{
if ((_SelectionNr - _ListLength) <= 0)
if (_SelectionNr - _ListLength <= 0)
{
_SelectionNr = 0;
}
else
{
_SelectionNr = _SelectionNr - _ListLength;
}
keyEvent.Handled = true;
}
break;
case Keys.PageDown:
@@ -406,13 +458,20 @@ namespace VocaluxeLib.Menu.SongMenu
}
else if (moveAllowed)
{
int maxCount_PageDown = (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && !CBase.Songs.IsInCategory() ? CBase.Songs.GetNumCategories() : CBase.Songs.GetNumSongsVisible());
if ((_SelectionNr + _ListLength) >= maxCount_PageDown)
var maxCount_PageDown = CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && !CBase.Songs.IsInCategory() ? CBase.Songs.GetNumCategories()
: CBase.Songs.GetNumSongsVisible();
if (_SelectionNr + _ListLength >= maxCount_PageDown)
{
_SelectionNr = maxCount_PageDown - 1;
}
else
{
_SelectionNr = _SelectionNr + _ListLength;
}
keyEvent.Handled = true;
}
break;
case Keys.Home:
@@ -421,15 +480,18 @@ namespace VocaluxeLib.Menu.SongMenu
_SelectionNr = 0;
keyEvent.Handled = true;
}
break;
case Keys.End:
int maxCount_End = (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && !CBase.Songs.IsInCategory() ? CBase.Songs.GetNumCategories() : CBase.Songs.GetNumSongsVisible());
var maxCount_End = CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && !CBase.Songs.IsInCategory() ? CBase.Songs.GetNumCategories()
: CBase.Songs.GetNumSongsVisible();
if (moveAllowed)
{
_SelectionNr = maxCount_End - 1;
keyEvent.Handled = true;
}
break;
case Keys.Left:
@@ -440,6 +502,7 @@ namespace VocaluxeLib.Menu.SongMenu
_AutoplayPreviewIfEnabled();
keyEvent.Handled = true;
}
break;
case Keys.Right:
@@ -449,6 +512,7 @@ namespace VocaluxeLib.Menu.SongMenu
_AutoplayPreviewIfEnabled();
keyEvent.Handled = true;
}
break;
case Keys.Up:
@@ -466,6 +530,7 @@ namespace VocaluxeLib.Menu.SongMenu
_AutoplayPreviewIfEnabled();
keyEvent.Handled = true;
}
break;
case Keys.Down:
@@ -483,10 +548,15 @@ namespace VocaluxeLib.Menu.SongMenu
_AutoplayPreviewIfEnabled();
keyEvent.Handled = true;
}
break;
}
if (!CBase.Songs.IsInCategory())
{
_PreviewSelectedSong();
}
return keyEvent.Handled;
}
@@ -495,33 +565,46 @@ namespace VocaluxeLib.Menu.SongMenu
if (!songOptions.Selection.RandomOnly || (!CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed))
{
if (mouseEvent.Wheel != 0 && CHelper.IsInBounds(_ScrollRect, mouseEvent))
_UpdateList(_Offset + mouseEvent.Wheel);
{
_UpdateList(_Offset + mouseEvent.Wheel);
}
int lastSelection = _SelectionNr;
int i = 0;
bool somethingSelected = false;
var lastSelection = _SelectionNr;
var i = 0;
var somethingSelected = false;
foreach (CStatic tile in _Tiles)
foreach (var tile in _Tiles)
{
//create a rect including the cover and text of the song.
//(this way mouse over text should make a selection as well)
SRectF songRect = new SRectF(tile.Rect.X, tile.Rect.Y, Rect.W, tile.Rect.H, tile.Rect.Z);
var songRect = new SRectF(tile.Rect.X, tile.Rect.Y, Rect.W, tile.Rect.H, tile.Rect.Z);
if (tile.Texture != _CoverBGTexture && CHelper.IsInBounds(songRect, mouseEvent) && tile.Color.A != 0)
{
somethingSelected = true;
_SelectionNr = i + _Offset;
if (!CBase.Songs.IsInCategory())
{
_PreviewNr = i + _Offset;
}
break;
}
i++;
}
//Reset selection only if we moved out of the rect to avoid loosing it when selecting random songs
if (_MouseWasInRect && !somethingSelected)
{
_SelectionNr = -1;
}
if (mouseEvent.Sender == ESender.WiiMote && _SelectionNr != lastSelection && _SelectionNr != -1)
{
CBase.Controller.SetRumble(0.050f);
}
}
_MouseWasInRect = CHelper.IsInBounds(Rect, mouseEvent);
if (mouseEvent.RB)
@@ -532,6 +615,7 @@ namespace VocaluxeLib.Menu.SongMenu
LeaveSelectedCategory();
return true;
}
if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && !songOptions.Selection.PartyMode)
{
CBase.Graphics.FadeTo(EScreen.Main);
@@ -545,64 +629,93 @@ namespace VocaluxeLib.Menu.SongMenu
if (CBase.Songs.IsInCategory())
{
if (_PreviewNr == _SelectionNr)
{
return false;
}
_PreviewSelectedSong();
}
else
{
EnterSelectedCategory();
}
return true;
}
}
return false;
}
public override void Draw()
{
foreach (CStatic rowBackground in _RowBackgrounds)
foreach (var rowBackground in _RowBackgrounds)
{
rowBackground.Draw(EAspect.Stretch);
foreach (CStatic tile in _Tiles)
}
foreach (var tile in _Tiles)
{
if (tile.Selected)
{
tile.Draw(EAspect.Crop, SelectedTileZoomFactor, -0.1f);
}
else
{
EAspect aspect = (tile.Texture != _CoverBGTexture) ? EAspect.Crop : EAspect.Stretch;
var aspect = tile.Texture != _CoverBGTexture ? EAspect.Crop : EAspect.Stretch;
tile.Draw(aspect);
}
}
//highlight the text of the selected song
int i = 0;
foreach (CText text in _Texts)
var i = 0;
foreach (var text in _Texts)
{
if (i < _Tiles.Count && _Tiles[i].Selected)
{
text.Font.Style = EStyle.Bold;
}
else if (i < _Tiles.Count)
{
text.Font.Style = EStyle.Normal;
}
else
{
text.Text = "";
}
text.Draw();
i++;
}
_TextBG.Draw();
CTextureRef vidtex = null;
if (CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON)
vidtex = (CBase.BackgroundMusic.IsPlayingPreview() ? CBase.BackgroundMusic.GetVideoTexture() : null);
{
vidtex = CBase.BackgroundMusic.IsPlayingPreview() ? CBase.BackgroundMusic.GetVideoTexture() : null;
}
if (vidtex != null)
{
if (vidtex.Color.A < 1)
{
_CoverBig.Draw(EAspect.Crop);
SRectF rect = CHelper.FitInBounds(_CoverBig.Rect, vidtex.OrigAspect, EAspect.Crop);
}
var rect = CHelper.FitInBounds(_CoverBig.Rect, vidtex.OrigAspect, EAspect.Crop);
CBase.Drawing.DrawTexture(vidtex, rect, vidtex.Color, _CoverBig.Rect);
CBase.Drawing.DrawTextureReflection(vidtex, rect, vidtex.Color, _CoverBig.Rect, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight);
}
else
{
_CoverBig.Draw(EAspect.Crop);
}
foreach (IMenuElement element in _SubElements)
foreach (var element in _SubElements)
{
element.Draw();
}
}
public override CStatic GetSelectedSongCover()
@@ -612,12 +725,16 @@ namespace VocaluxeLib.Menu.SongMenu
public override bool IsMouseOverSelectedSong(SMouseEvent mEvent)
{
for (int i = 0; i < _Tiles.Count; i++)
for (var i = 0; i < _Tiles.Count; i++)
{
if (!_Tiles[i].Selected)
{
continue;
}
return CHelper.IsInBounds(_Tiles[i].Rect, mEvent) || CHelper.IsInBounds(_Texts[i].Rect, mEvent);
}
return false;
}
@@ -655,9 +772,11 @@ namespace VocaluxeLib.Menu.SongMenu
private void _UpdateListIfRequired()
{
int curElements = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
if ((_LastKnownElements == curElements) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex()))
var curElements = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
if (_LastKnownElements == curElements && _LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex())
{
return;
}
_LastKnownCategory = CBase.Songs.GetCurrentCategoryIndex();
_LastKnownElements = curElements;
@@ -667,63 +786,79 @@ namespace VocaluxeLib.Menu.SongMenu
private void _UpdateList(bool force = false)
{
bool isInCategory = CBase.Songs.IsInCategory();
int itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
int halfListLength = _ListLength / 2;
var isInCategory = CBase.Songs.IsInCategory();
var itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
var halfListLength = _ListLength / 2;
int offset;
if (_SelectionNr < _Offset && _SelectionNr >= 0)
{
if (_SelectionNr - halfListLength >= 0)
{
offset = _SelectionNr - halfListLength;
}
else
{
offset = 0;
}
}
else if (_SelectionNr >= _Offset + _ListLength)
{
if (_SelectionNr + halfListLength > itemCount)
{
offset = itemCount - _ListLength;
}
else
{
offset = _SelectionNr - halfListLength;
}
}
else
{
offset = _Offset;
}
_UpdateList(offset, force);
}
private void _UpdateList(int offset, bool force = false)
{
bool isInCategory = CBase.Songs.IsInCategory();
int itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
int totalSongNumber = CBase.Songs.GetNumSongs();
var isInCategory = CBase.Songs.IsInCategory();
var itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
var totalSongNumber = CBase.Songs.GetNumSongs();
offset = offset.Clamp(0, itemCount - _ListLength, true);
if (offset == _Offset && !force)
{
return;
}
for (int i = 0; i < _Tiles.Count; i++)
for (var i = 0; i < _Tiles.Count; i++)
{
if (i + offset < itemCount)
{
_Tiles[i].Color = new SColorF(1f, 1f, 1f, 1f);
if (isInCategory)
{
CSong currentSong = CBase.Songs.GetVisibleSong(i + offset);
var currentSong = CBase.Songs.GetVisibleSong(i + offset);
_Tiles[i].Texture = currentSong.CoverTextureSmall;
if (CBase.Config.GetSongSorting() == ESongSorting.TR_CONFIG_TITLE_LETTER)
{
_Texts[i].Text = currentSong.Title + " - " + currentSong.Artist;
}
else
{
_Texts[i].Text = currentSong.Artist + " - " + currentSong.Title;
}
}
else
{
CCategory currentCat = CBase.Songs.GetCategory(i + offset);
var currentCat = CBase.Songs.GetCategory(i + offset);
_Tiles[i].Texture = currentCat.CoverTextureSmall;
int num = currentCat.GetNumSongsNotSung();
String songOrSongs = (num == 1) ? "TR_SCREENSONG_NUMSONG" : "TR_SCREENSONG_NUMSONGS";
var num = currentCat.GetNumSongsNotSung();
var songOrSongs = num == 1 ? "TR_SCREENSONG_NUMSONG" : "TR_SCREENSONG_NUMSONGS";
_Texts[i].Text = currentCat.Name + " " + CBase.Language.Translate(songOrSongs).Replace("%v", num.ToString());
}
}
@@ -734,14 +869,18 @@ namespace VocaluxeLib.Menu.SongMenu
_Texts[i].Text = "";
}
}
_Offset = offset;
_UpdateTileSelection();
}
public override void LoadSkin()
{
foreach (IThemeable themeable in _SubElements.OfType<IThemeable>())
foreach (var themeable in _SubElements.OfType<IThemeable>())
{
themeable.LoadSkin();
}
// Those are drawn seperately so they are not in the above list
_CoverBig.LoadSkin();
_TextBG.LoadSkin();
@@ -749,4 +888,4 @@ namespace VocaluxeLib.Menu.SongMenu
base.LoadSkin();
}
}
}
}
+181 -62
View File
@@ -73,7 +73,7 @@ namespace VocaluxeLib.Menu.SongMenu
{
set
{
int max = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
var max = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
base._SelectionNr = value.Clamp(-1, max - 1, true);
//Update list in case we scrolled
_UpdateList();
@@ -87,7 +87,10 @@ namespace VocaluxeLib.Menu.SongMenu
set
{
if (SmallView == value)
{
return;
}
base.SmallView = value;
_InitTiles();
_UpdateList(true);
@@ -102,41 +105,51 @@ namespace VocaluxeLib.Menu.SongMenu
if (value == base._PreviewNr)
{
if (!CBase.BackgroundMusic.IsPlaying() && value != -1)
{
CBase.BackgroundMusic.Play();
}
return;
}
base._PreviewNr = value;
_UpdatePreview();
}
}
public CSongMenuTileBoard(int partyModeID) : base(partyModeID) {}
public CSongMenuTileBoard(int partyModeId) : base(partyModeId) { }
public CSongMenuTileBoard(SThemeSongMenu theme, int partyModeID) : base(theme, partyModeID)
public CSongMenuTileBoard(SThemeSongMenu theme, int partyModeId) : base(theme, partyModeId)
{
_Artist = new CText(_Theme.SongMenuTileBoard.TextArtist, _PartyModeID);
_Title = new CText(_Theme.SongMenuTileBoard.TextTitle, _PartyModeID);
_SongLength = new CText(_Theme.SongMenuTileBoard.TextSongLength, _PartyModeID);
_SongYear = new CText(_Theme.SongMenuTileBoard.TextSongYear, _PartyModeID);
_CoverBig = new CStatic(_Theme.SongMenuTileBoard.StaticCoverBig, _PartyModeID);
_TextBG = new CStatic(_Theme.SongMenuTileBoard.StaticTextBG, _PartyModeID);
_DuetIcon = new CStatic(_Theme.SongMenuTileBoard.StaticDuetIcon, _PartyModeID);
_RapIcon = new CStatic(_Theme.SongMenuTileBoard.StaticRapIcon, _PartyModeID);
_VideoIcon = new CStatic(_Theme.SongMenuTileBoard.StaticVideoIcon, _PartyModeID);
_MedleyCalcIcon = new CStatic(_Theme.SongMenuTileBoard.StaticMedleyCalcIcon, _PartyModeID);
_MedleyTagIcon = new CStatic(_Theme.SongMenuTileBoard.StaticMedleyTagIcon, _PartyModeID);
_InstrumentalIcon = new CStatic(_Theme.SongMenuTileBoard.StaticInstrumentalIcon, _PartyModeID);
_VocalsIcon = new CStatic(_Theme.SongMenuTileBoard.StaticVocalsIcon, _PartyModeID);
_SubElements.AddRange(new IMenuElement[] {_Artist, _Title, _SongLength, _SongYear, _DuetIcon, _RapIcon, _VideoIcon, _MedleyCalcIcon, _MedleyTagIcon, _InstrumentalIcon, _VocalsIcon});
_Artist = new CText(_Theme.SongMenuTileBoard.TextArtist, _PartyModeId);
_Title = new CText(_Theme.SongMenuTileBoard.TextTitle, _PartyModeId);
_SongLength = new CText(_Theme.SongMenuTileBoard.TextSongLength, _PartyModeId);
_SongYear = new CText(_Theme.SongMenuTileBoard.TextSongYear, _PartyModeId);
_CoverBig = new CStatic(_Theme.SongMenuTileBoard.StaticCoverBig, _PartyModeId);
_TextBG = new CStatic(_Theme.SongMenuTileBoard.StaticTextBG, _PartyModeId);
_DuetIcon = new CStatic(_Theme.SongMenuTileBoard.StaticDuetIcon, _PartyModeId);
_RapIcon = new CStatic(_Theme.SongMenuTileBoard.StaticRapIcon, _PartyModeId);
_VideoIcon = new CStatic(_Theme.SongMenuTileBoard.StaticVideoIcon, _PartyModeId);
_MedleyCalcIcon = new CStatic(_Theme.SongMenuTileBoard.StaticMedleyCalcIcon, _PartyModeId);
_MedleyTagIcon = new CStatic(_Theme.SongMenuTileBoard.StaticMedleyTagIcon, _PartyModeId);
_InstrumentalIcon = new CStatic(_Theme.SongMenuTileBoard.StaticInstrumentalIcon, _PartyModeId);
_VocalsIcon = new CStatic(_Theme.SongMenuTileBoard.StaticVocalsIcon, _PartyModeId);
_SubElements.AddRange(new IMenuElement[]
{ _Artist, _Title, _SongLength, _SongYear, _DuetIcon, _RapIcon, _VideoIcon, _MedleyCalcIcon, _MedleyTagIcon, _InstrumentalIcon, _VocalsIcon });
}
private void _UpdateTileSelection()
{
foreach (CStatic tile in _Tiles)
foreach (var tile in _Tiles)
{
tile.Selected = false;
int tileNr = _SelectionNr - _Offset;
}
var tileNr = _SelectionNr - _Offset;
if (tileNr >= 0 && tileNr < _Tiles.Count)
{
_Tiles[tileNr].Selected = true;
}
}
private void _ReadSubTheme()
@@ -188,39 +201,44 @@ namespace VocaluxeLib.Menu.SongMenu
_TileW = (int)((Rect.W - _Theme.SongMenuTileBoard.SpaceW * (_NumW - 1)) / _NumW);
_TileH = (int)((Rect.H - _Theme.SongMenuTileBoard.SpaceH * (_NumH - 1)) / _NumH);
_CoverBGTexture = CBase.Themes.GetSkinTexture(_Theme.CoverBackground, _PartyModeID);
_CoverBigBGTexture = CBase.Themes.GetSkinTexture(_Theme.CoverBigBackground, _PartyModeID);
_CoverBGTexture = CBase.Themes.GetSkinTexture(_Theme.CoverBackground, _PartyModeId);
_CoverBigBGTexture = CBase.Themes.GetSkinTexture(_Theme.CoverBigBackground, _PartyModeId);
_Tiles = new List<CStatic>();
for (int i = 0; i < _NumH; i++)
for (var i = 0; i < _NumH; i++)
{
for (int j = 0; j < _NumW; j++)
for (var j = 0; j < _NumW; j++)
{
var rect = new SRectF(Rect.X + j * (_TileW + _Theme.SongMenuTileBoard.SpaceW), Rect.Y + i * (_TileH + _Theme.SongMenuTileBoard.SpaceH), _TileW, _TileH, Rect.Z);
var tile = new CStatic(_PartyModeID, _CoverBGTexture, _Color, rect);
var tile = new CStatic(_PartyModeId, _CoverBGTexture, _Color, rect);
_Tiles.Add(tile);
}
}
_ScrollRect = CBase.Settings.GetRenderRect();
}
public override void Update(SScreenSongOptions songOptions)
{
if (songOptions.Selection.RandomOnly)
{
_PreviewSelectedSong();
}
if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.BackgroundMusic.GetLength() > 0)
{
_UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr));
}
}
private void _UpdatePreview()
{
//First hide everything so we just have to set what we actually want
_CoverBig.Texture = _CoverBigBGTexture;
_Artist.Text = String.Empty;
_Title.Text = String.Empty;
_SongLength.Text = String.Empty;
_SongYear.Text = String.Empty;
_Artist.Text = string.Empty;
_Title.Text = string.Empty;
_SongLength.Text = string.Empty;
_SongYear.Text = string.Empty;
_DuetIcon.Visible = false;
_RapIcon.Visible = false;
_VideoIcon.Visible = false;
@@ -232,23 +250,29 @@ namespace VocaluxeLib.Menu.SongMenu
//Check if nothing is selected (for preview)
if (_PreviewNr < 0)
{
return;
}
if (CBase.Songs.IsInCategory())
{
CSong song = CBase.Songs.GetVisibleSong(_PreviewNr);
var song = CBase.Songs.GetVisibleSong(_PreviewNr);
//Check if we have a valid song (song still visible, index >=0 etc is checked by framework)
if (song == null)
{
//Display at least the category
CCategory category = CBase.Songs.GetCategory(CBase.Songs.GetCurrentCategoryIndex());
var category = CBase.Songs.GetCategory(CBase.Songs.GetCurrentCategoryIndex());
//Check if we have a valid category
if (category == null)
{
return;
}
_CoverBig.Texture = category.CoverTextureBig;
_Artist.Text = category.Name;
return;
}
_CoverBig.Texture = song.CoverTextureBig;
_Artist.Text = song.Artist;
_Title.Text = song.Title;
@@ -265,15 +289,18 @@ namespace VocaluxeLib.Menu.SongMenu
}
else
{
CCategory category = CBase.Songs.GetCategory(_PreviewNr);
var category = CBase.Songs.GetCategory(_PreviewNr);
//Check if we have a valid category
if (category == null)
{
return;
}
_CoverBig.Texture = category.CoverTextureBig;
_Artist.Text = category.Name;
int num = category.GetNumSongsNotSung();
String songOrSongs = (num == 1) ? "TR_SCREENSONG_NUMSONG" : "TR_SCREENSONG_NUMSONGS";
var num = category.GetNumSongsNotSung();
var songOrSongs = num == 1 ? "TR_SCREENSONG_NUMSONG" : "TR_SCREENSONG_NUMSONGS";
_Title.Text = CBase.Language.Translate(songOrSongs).Replace("%v", num.ToString());
}
}
@@ -281,10 +308,15 @@ namespace VocaluxeLib.Menu.SongMenu
private void _UpdateLength(CSong song)
{
if (song == null)
{
return;
float time = CBase.BackgroundMusic.GetLength();
if (Math.Abs(song.Finish) > 0.001)
time = song.Finish;
}
var time = CBase.BackgroundMusic.GetLength();
if (Math.Abs(song.End) > 0.001)
{
time = song.End;
}
// The audiobackend is ready to return the length
if (time > 0)
@@ -296,7 +328,9 @@ namespace VocaluxeLib.Menu.SongMenu
_Length = time;
}
else
{
_SongLength.Text = "...";
}
}
public override void OnShow()
@@ -305,12 +339,20 @@ namespace VocaluxeLib.Menu.SongMenu
if (!CBase.Songs.IsInCategory())
{
if ((CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0) || CBase.Songs.GetNumCategories() == 1)
{
_EnterCategory(0);
}
}
if (CBase.Songs.IsInCategory())
{
SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr);
}
else
{
SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr);
}
_PreviewSelectedSong();
_UpdateListIfRequired();
}
@@ -318,14 +360,18 @@ namespace VocaluxeLib.Menu.SongMenu
public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options)
{
if (keyEvent.KeyPressed)
{
return false;
}
bool moveAllowed = !options.Selection.RandomOnly || (options.Selection.CategoryChangeAllowed && !CBase.Songs.IsInCategory());
bool catChangePossible = CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && options.Selection.CategoryChangeAllowed;
var moveAllowed = !options.Selection.RandomOnly || (options.Selection.CategoryChangeAllowed && !CBase.Songs.IsInCategory());
var catChangePossible = CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && options.Selection.CategoryChangeAllowed;
//If nothing selected set a reasonable default value
if (keyEvent.IsArrowKey() && moveAllowed && _SelectionNr < 0)
_SelectionNr = (_PreviewNr < 0) ? _Offset : _PreviewNr;
{
_SelectionNr = _PreviewNr < 0 ? _Offset : _PreviewNr;
}
switch (keyEvent.Key)
{
@@ -343,6 +389,7 @@ namespace VocaluxeLib.Menu.SongMenu
_EnterCategory(_PreviewNr);
keyEvent.Handled = true;
}
break;
case Keys.Escape:
@@ -352,6 +399,7 @@ namespace VocaluxeLib.Menu.SongMenu
LeaveSelectedCategory();
keyEvent.Handled = true;
}
break;
case Keys.PageUp:
@@ -362,13 +410,19 @@ namespace VocaluxeLib.Menu.SongMenu
}
else if (moveAllowed)
{
int numSongsPerPage = _NumH * _NumW;
if ((_SelectionNr - numSongsPerPage) <= 0)
var numSongsPerPage = _NumH * _NumW;
if (_SelectionNr - numSongsPerPage <= 0)
{
_SelectionNr = 0;
}
else
{
_SelectionNr = _SelectionNr - numSongsPerPage;
}
keyEvent.Handled = true;
}
break;
case Keys.PageDown:
@@ -379,14 +433,21 @@ namespace VocaluxeLib.Menu.SongMenu
}
else if (moveAllowed)
{
int numSongsPerPage = _NumH * _NumW;
int maxCount_PageDown = (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && !CBase.Songs.IsInCategory() ? CBase.Songs.GetNumCategories() : CBase.Songs.GetNumSongsVisible());
if ((_SelectionNr + numSongsPerPage) >= maxCount_PageDown)
var numSongsPerPage = _NumH * _NumW;
var maxCount_PageDown = CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && !CBase.Songs.IsInCategory() ? CBase.Songs.GetNumCategories()
: CBase.Songs.GetNumSongsVisible();
if (_SelectionNr + numSongsPerPage >= maxCount_PageDown)
{
_SelectionNr = maxCount_PageDown - 1;
}
else
{
_SelectionNr = _SelectionNr + numSongsPerPage;
}
keyEvent.Handled = true;
}
break;
case Keys.Home:
@@ -395,15 +456,18 @@ namespace VocaluxeLib.Menu.SongMenu
_SelectionNr = 0;
keyEvent.Handled = true;
}
break;
case Keys.End:
int maxCount_End = (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && !CBase.Songs.IsInCategory() ? CBase.Songs.GetNumCategories() : CBase.Songs.GetNumSongsVisible());
var maxCount_End = CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && !CBase.Songs.IsInCategory() ? CBase.Songs.GetNumCategories()
: CBase.Songs.GetNumSongsVisible();
if (moveAllowed)
{
_SelectionNr = maxCount_End - 1;
keyEvent.Handled = true;
}
break;
case Keys.Left:
@@ -414,6 +478,7 @@ namespace VocaluxeLib.Menu.SongMenu
_AutoplayPreviewIfEnabled();
keyEvent.Handled = true;
}
break;
case Keys.Right:
@@ -423,6 +488,7 @@ namespace VocaluxeLib.Menu.SongMenu
_AutoplayPreviewIfEnabled();
keyEvent.Handled = true;
}
break;
case Keys.Up:
@@ -440,6 +506,7 @@ namespace VocaluxeLib.Menu.SongMenu
_AutoplayPreviewIfEnabled();
keyEvent.Handled = true;
}
break;
case Keys.Down:
@@ -457,10 +524,15 @@ namespace VocaluxeLib.Menu.SongMenu
_AutoplayPreviewIfEnabled();
keyEvent.Handled = true;
}
break;
}
if (!CBase.Songs.IsInCategory())
{
_PreviewSelectedSong();
}
return keyEvent.Handled;
}
@@ -469,29 +541,42 @@ namespace VocaluxeLib.Menu.SongMenu
if (!songOptions.Selection.RandomOnly || (!CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed))
{
if (mouseEvent.Wheel != 0 && CHelper.IsInBounds(_ScrollRect, mouseEvent))
{
_UpdateList(_Offset + _NumW * mouseEvent.Wheel);
}
int lastSelection = _SelectionNr;
int i = 0;
bool somethingSelected = false;
foreach (CStatic tile in _Tiles)
var lastSelection = _SelectionNr;
var i = 0;
var somethingSelected = false;
foreach (var tile in _Tiles)
{
if (tile.Texture != _CoverBGTexture && CHelper.IsInBounds(tile.Rect, mouseEvent))
{
somethingSelected = true;
_SelectionNr = i + _Offset;
if (!CBase.Songs.IsInCategory())
{
_PreviewNr = i + _Offset;
}
break;
}
i++;
}
//Reset selection only if we moved out of the rect to avoid loosing it when selecting random songs
if (_MouseWasInRect && !somethingSelected)
{
_SelectionNr = -1;
}
if (mouseEvent.Sender == ESender.WiiMote && _SelectionNr != lastSelection && _SelectionNr != -1)
{
CBase.Controller.SetRumble(0.050f);
}
}
_MouseWasInRect = CHelper.IsInBounds(Rect, mouseEvent);
if (mouseEvent.RB)
@@ -502,6 +587,7 @@ namespace VocaluxeLib.Menu.SongMenu
LeaveSelectedCategory();
return true;
}
if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && !songOptions.Selection.PartyMode)
{
CBase.Graphics.FadeTo(EScreen.Main);
@@ -515,26 +601,35 @@ namespace VocaluxeLib.Menu.SongMenu
if (CBase.Songs.IsInCategory())
{
if (_PreviewNr == _SelectionNr)
{
return false;
}
_PreviewSelectedSong();
}
else
{
EnterSelectedCategory();
}
return true;
}
}
return false;
}
public override void Draw()
{
foreach (CStatic tile in _Tiles)
foreach (var tile in _Tiles)
{
if (tile.Selected)
{
tile.Draw(EAspect.Crop, SelectedTileZoomFactor, -0.1f);
}
else
{
EAspect aspect = (tile.Texture != _CoverBGTexture) ? EAspect.Crop : EAspect.Stretch;
var aspect = tile.Texture != _CoverBGTexture ? EAspect.Crop : EAspect.Stretch;
tile.Draw(aspect);
}
}
@@ -543,21 +638,30 @@ namespace VocaluxeLib.Menu.SongMenu
CTextureRef vidtex = null;
if (CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON)
vidtex = (CBase.BackgroundMusic.IsPlayingPreview() ? CBase.BackgroundMusic.GetVideoTexture() : null);
{
vidtex = CBase.BackgroundMusic.IsPlayingPreview() ? CBase.BackgroundMusic.GetVideoTexture() : null;
}
if (vidtex != null)
{
if (vidtex.Color.A < 1)
{
_CoverBig.Draw(EAspect.Crop);
SRectF rect = CHelper.FitInBounds(_CoverBig.Rect, vidtex.OrigAspect, EAspect.Crop);
}
var rect = CHelper.FitInBounds(_CoverBig.Rect, vidtex.OrigAspect, EAspect.Crop);
CBase.Drawing.DrawTexture(vidtex, rect, vidtex.Color, _CoverBig.Rect);
CBase.Drawing.DrawTextureReflection(vidtex, rect, vidtex.Color, _CoverBig.Rect, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight);
}
else
{
_CoverBig.Draw(EAspect.Crop);
}
foreach (IMenuElement element in _SubElements)
foreach (var element in _SubElements)
{
element.Draw();
}
}
public override CStatic GetSelectedSongCover()
@@ -599,9 +703,11 @@ namespace VocaluxeLib.Menu.SongMenu
private void _UpdateListIfRequired()
{
int curElements = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
if ((_LastKnownElements == curElements) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex()))
var curElements = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
if (_LastKnownElements == curElements && _LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex())
{
return;
}
_LastKnownCategory = CBase.Songs.GetCurrentCategoryIndex();
_LastKnownElements = curElements;
@@ -611,32 +717,41 @@ namespace VocaluxeLib.Menu.SongMenu
private int _GetOffsetForPosition(int index, int rowNum = 0)
{
return (index / _NumW) * _NumW - (_NumW * rowNum.Clamp(0, _NumH - 1, true));
return index / _NumW * _NumW - _NumW * rowNum.Clamp(0, _NumH - 1, true);
}
private void _UpdateList(bool force = false)
{
int offset;
if (_SelectionNr < _Offset && _SelectionNr >= 0)
{
offset = _GetOffsetForPosition(_SelectionNr);
}
else if (_SelectionNr >= _Offset + _NumW * _NumH)
{
offset = _GetOffsetForPosition(_SelectionNr, _NumH);
}
else
{
offset = _Offset;
}
_UpdateList(offset, force);
}
private void _UpdateList(int offset, bool force = false)
{
bool isInCategory = CBase.Songs.IsInCategory();
int itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
var isInCategory = CBase.Songs.IsInCategory();
var itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
offset = offset.Clamp(0, _GetOffsetForPosition(itemCount, _NumH - 1), true);
if (offset == _Offset && !force)
{
return;
}
for (int i = 0; i < _Tiles.Count; i++)
for (var i = 0; i < _Tiles.Count; i++)
{
if (itemCount > i + offset)
{
@@ -649,14 +764,18 @@ namespace VocaluxeLib.Menu.SongMenu
_Tiles[i].Color = _Color;
}
}
_Offset = offset;
}
public override void LoadSkin()
{
base.LoadSkin();
foreach (IThemeable themeable in _SubElements.OfType<IThemeable>())
foreach (var themeable in _SubElements.OfType<IThemeable>())
{
themeable.LoadSkin();
}
// Those are drawn seperately so they are not in the above list
_CoverBig.LoadSkin();
_TextBG.LoadSkin();
@@ -664,4 +783,4 @@ namespace VocaluxeLib.Menu.SongMenu
Init();
}
}
}
}