Implement a common Interface for all MenuElements

Also remove CSongMenu and replace it with a factory class
This commit is contained in:
Flamefire committed 2014-10-19 17:17:39 +02:00
1 parent 9479f3b3ff
commit ae7a7fd390
52 files changed
+1043 -1855

No files matched your search

-220
View File
@@ -1,220 +0,0 @@
#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 VocaluxeLib.PartyModes;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu.SongMenu
{
public class CSongMenu : ISongMenu
{
private readonly int _PartyModeID;
private ISongMenu _SongMenu;
private ESongMenu _Type;
public CSongMenu(int partyModeID)
{
_PartyModeID = partyModeID;
_CreateSongMenu(new SThemeSongMenu());
}
public CSongMenu(SThemeSongMenu theme, int partyModeID)
{
_PartyModeID = partyModeID;
_CreateSongMenu(theme);
}
#region ISongMenu
public bool Selected
{
get { return _SongMenu.Selected; }
set { _SongMenu.Selected = value; }
}
public bool Visible
{
get { return _SongMenu.Visible; }
set { _SongMenu.Visible = value; }
}
public bool Active
{
get { return _SongMenu.Active; }
set { _SongMenu.Active = value; }
}
public bool SmallView
{
get { return _SongMenu.SmallView; }
set { _SongMenu.SmallView = value; }
}
public SRectF Rect
{
get { return _SongMenu.Rect; }
}
public bool ThemeLoaded
{
get { return _SongMenu.ThemeLoaded; }
}
public void Update(SScreenSongOptions songOptions)
{
_SongMenu.Update(songOptions);
}
public void OnShow()
{
_SongMenu.OnShow();
}
public void OnHide()
{
_SongMenu.OnHide();
}
public bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options)
{
return _SongMenu.HandleInput(ref keyEvent, options);
}
public bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions)
{
return _SongMenu.HandleMouse(ref mouseEvent, songOptions);
}
public void Draw()
{
_SongMenu.Draw();
}
public bool IsMouseOverSelectedSong(SMouseEvent mEvent)
{
return _SongMenu.IsMouseOverSelectedSong(mEvent);
}
public int GetPreviewSongNr()
{
return _SongMenu.GetPreviewSongNr();
}
public int GetSelectedSongNr()
{
return _SongMenu.GetSelectedSongNr();
}
public CStatic GetSelectedSongCover()
{
return _SongMenu.GetSelectedSongCover();
}
public void SetSelectedSong(int visibleSongNr)
{
_SongMenu.SetSelectedSong(visibleSongNr);
}
public int GetSelectedCategory()
{
return _SongMenu.GetSelectedCategory();
}
public void SetSelectedCategory(int categoryNr)
{
_SongMenu.SetSelectedCategory(categoryNr);
}
public bool EnterSelectedCategory()
{
return _SongMenu.EnterSelectedCategory();
}
public int GetPreviewSong()
{
return _SongMenu.GetPreviewSong();
}
#endregion ISongMenu
#region IMenuElement
public string GetThemeName()
{
return _SongMenu.GetThemeName();
}
public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader)
{
return _SongMenu.LoadTheme(xmlPath, elementName, xmlReader);
}
public void UnloadSkin()
{
_SongMenu.UnloadSkin();
}
public void LoadSkin()
{
_SongMenu.LoadSkin();
}
public void ReloadSkin()
{
_SongMenu.ReloadSkin();
}
public void MoveElement(int stepX, int stepY)
{
_SongMenu.MoveElement(stepX, stepY);
}
public void ResizeElement(int stepW, int stepH)
{
_SongMenu.ResizeElement(stepW, stepH);
}
public SThemeSongMenu GetTheme()
{
return _SongMenu.GetTheme();
}
#endregion IMenuElement
private void _CreateSongMenu(SThemeSongMenu theme)
{
if (_SongMenu != null)
_SongMenu.OnHide();
_Type = CBase.Config.GetSongMenuType();
switch (_Type)
{
//case ESongMenu.TR_CONFIG_LIST:
// _SongMenu = new CSongMenuList();
// break;
//case ESongMenu.TR_CONFIG_DREIDEL:
// _SongMenu = new CSongMenuDreidel();
// break;
case ESongMenu.TR_CONFIG_TILE_BOARD:
_SongMenu = new CSongMenuTileBoard(theme, _PartyModeID);
break;
//case ESongMenu.TR_CONFIG_BOOK:
// _SongMenu = new CSongMenuBook();
// break;
}
}
}
}
@@ -1,47 +0,0 @@
#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 VocaluxeLib.PartyModes;
namespace VocaluxeLib.Menu.SongMenu
{
class CSongMenuBook : CSongMenuFramework
{
public CSongMenuBook(int partyModeID)
: base(partyModeID) {}
public override float SelectedTileZoomFactor
{
get { return 1.2f; }
}
public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options)
{
return false;
}
public override bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions)
{
return false;
}
public override CStatic GetSelectedSongCover()
{
return null;
}
}
}
@@ -1,78 +0,0 @@
#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 VocaluxeLib.PartyModes;
namespace VocaluxeLib.Menu.SongMenu
{
class CSongMenuDreidel : CSongMenuFramework
{
/*
private SRectF _ScrollRect;
private CStatic _CoverBig;
private CStatic _TextBG;
private CStatic _DuetIcon;
private CStatic _VideoIcon;
private CText _Artist;
private CText _Title;
private CText _SongLength;
*/
public CSongMenuDreidel(int partyModeID)
: base(partyModeID) {}
// ReSharper disable RedundantOverridenMember
public override void Init()
{
base.Init();
/**
_CoverBig = _Theme.songMenuDreidel.StaticCoverBig;
_TextBG = _Theme.songMenuDreidel.StaticTextBG;
_DuetIcon = _Theme.songMenuDreidel.StaticDuetIcon;
_VideoIcon = _Theme.songMenuDreidel.StaticVideoIcon;
_Artist = _Theme.songMenuDreidel.TextArtist;
_Title = _Theme.songMenuDreidel.TextTitle;
_SongLength = _Theme.songMenuDreidel.TextSongLength;
**/
}
// ReSharper restore RedundantOverridenMember
public override float SelectedTileZoomFactor
{
get { return 1.2f; }
}
public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options)
{
return false;
}
public override bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions)
{
return false;
}
public override CStatic GetSelectedSongCover()
{
return null;
}
}
}
@@ -0,0 +1,71 @@
#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;
namespace VocaluxeLib.Menu.SongMenu
{
public static class CSongMenuFactory
{
public static ISongMenu GetSongMenu(SThemeSongMenu theme, int partyModeID)
{
switch (CBase.Config.GetSongMenuType())
{
//case ESongMenu.TR_CONFIG_LIST:
// _SongMenu = new CSongMenuList();
// break;
//case ESongMenu.TR_CONFIG_DREIDEL:
// _SongMenu = new CSongMenuDreidel();
// break;
case ESongMenu.TR_CONFIG_TILE_BOARD:
return new CSongMenuTileBoard(theme, partyModeID);
//case ESongMenu.TR_CONFIG_BOOK:
// _SongMenu = new CSongMenuBook();
// break;
}
throw new ArgumentException("Invalid songmenu type: " + CBase.Config.GetSongMenuType());
}
/// <summary>
/// Deprecated! Only used for old theme loading.
/// </summary>
/// <param name="partyModeID"></param>
/// <returns></returns>
public static ISongMenu GetSongMenu(int partyModeID)
{
switch (CBase.Config.GetSongMenuType())
{
//case ESongMenu.TR_CONFIG_LIST:
// _SongMenu = new CSongMenuList();
// break;
//case ESongMenu.TR_CONFIG_DREIDEL:
// _SongMenu = new CSongMenuDreidel();
// break;
case ESongMenu.TR_CONFIG_TILE_BOARD:
return new CSongMenuTileBoard(partyModeID);
//case ESongMenu.TR_CONFIG_BOOK:
// _SongMenu = new CSongMenuBook();
// break;
}
throw new ArgumentException("Invalid songmenu type: " + CBase.Config.GetSongMenuType());
}
}
}
+18 -39
View File
@@ -90,7 +90,7 @@ namespace VocaluxeLib.Menu.SongMenu
public SThemeStatic StaticMedleyTagIcon;
}
abstract class CSongMenuFramework : ISongMenu
public abstract class CSongMenuFramework : CMenuElementBase, ISongMenu
{
protected readonly int _PartyModeID;
protected SThemeSongMenu _Theme;
@@ -101,6 +101,11 @@ namespace VocaluxeLib.Menu.SongMenu
get { return _ThemeLoaded; }
}
public bool Selectable
{
get { return Visible; }
}
protected bool _Initialized;
private int _PreviewNrInternal = -1;
@@ -138,19 +143,6 @@ namespace VocaluxeLib.Menu.SongMenu
return _PreviewNr;
}
public SRectF Rect { get; protected set; }
public bool Active { get; set; }
private bool _Selected;
public bool Selected
{
get { return _Selected; }
set
{
_Selected = value;
Active = value;
}
}
public bool Visible { get; set; }
public virtual bool SmallView { get; set; }
public abstract float SelectedTileZoomFactor { get; }
// This is the nr of the current selection (song or category)
@@ -245,13 +237,9 @@ namespace VocaluxeLib.Menu.SongMenu
_Initialized = true;
}
public virtual void Update(SScreenSongOptions songOptions)
{
if (!_Initialized)
return;
}
public abstract void Update(SScreenSongOptions songOptions);
public virtual void OnShow() {}
public abstract void OnShow();
public virtual void OnHide()
{
@@ -398,33 +386,24 @@ namespace VocaluxeLib.Menu.SongMenu
}
#region ThemeEdit
private void _UpdateRect(SRectF rect)
{
Rect = rect;
Init();
}
public void MoveElement(int stepX, int stepY)
{
SRectF rect = Rect;
rect.X += stepX;
rect.Y += stepY;
_UpdateRect(rect);
X += stepX;
Y += stepY;
Init();
}
public void ResizeElement(int stepW, int stepH)
{
SRectF rect = Rect;
W += stepW;
if (W < 100)
W = 100;
rect.W += stepW;
if (rect.W < 100)
rect.W = 100;
H += stepH;
if (H < 100)
H = 100;
rect.H += stepH;
if (rect.H < 100)
rect.H = 100;
_UpdateRect(rect);
Init();
}
#endregion ThemeEdit
}
@@ -1,44 +0,0 @@
#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 VocaluxeLib.PartyModes;
namespace VocaluxeLib.Menu.SongMenu
{
class CSongMenuList : CSongMenuFramework
{
public CSongMenuList(int partyModeID)
: base(partyModeID) {}
public override float SelectedTileZoomFactor
{
get { return 1.2f; }
}
public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options)
{
return false;
}
public override bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) { return false; }
public override CStatic GetSelectedSongCover()
{
return null;
}
}
}
@@ -174,13 +174,13 @@ namespace VocaluxeLib.Menu.SongMenu
{
_NumH = _Theme.SongMenuTileBoard.NumHsmall;
_NumW = _Theme.SongMenuTileBoard.NumWsmall;
Rect = _Theme.SongMenuTileBoard.TileRectSmall;
MaxRect = _Theme.SongMenuTileBoard.TileRectSmall;
}
else
{
_NumH = _Theme.SongMenuTileBoard.NumH;
_NumW = _Theme.SongMenuTileBoard.NumW;
Rect = _Theme.SongMenuTileBoard.TileRect;
MaxRect = _Theme.SongMenuTileBoard.TileRect;
}
_TileW = (int)((Rect.W - _Theme.SongMenuTileBoard.SpaceW * (_NumW - 1)) / _NumW);
@@ -204,8 +204,6 @@ namespace VocaluxeLib.Menu.SongMenu
public override void Update(SScreenSongOptions songOptions)
{
base.Update(songOptions);
if (songOptions.Selection.RandomOnly)
_PreviewNr = _SelectionNr;
@@ -482,7 +480,7 @@ namespace VocaluxeLib.Menu.SongMenu
{
foreach (CStatic tile in _Tiles)
{
if (tile.Selected && Active)
if (tile.Selected && Selected)
tile.Draw(EAspect.Crop, SelectedTileZoomFactor, -0.1f);
else
{
+1 -6
View File
@@ -19,7 +19,7 @@ using VocaluxeLib.PartyModes;
namespace VocaluxeLib.Menu.SongMenu
{
interface ISongMenu : IMenuElement
public interface ISongMenu : IMenuElement,IThemeable
{
void Update(SScreenSongOptions songOptions);
void OnShow();
@@ -27,7 +27,6 @@ namespace VocaluxeLib.Menu.SongMenu
bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options);
bool HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions);
void Draw();
// The selected song is the song, where the mouse is hovering over
// The number is refering to the index in the visible songs array
@@ -45,10 +44,6 @@ namespace VocaluxeLib.Menu.SongMenu
// The song that is currently playing (set e.g. by clicking on a song)
int GetPreviewSong();
SRectF Rect { get; }
bool Active { get; set; }
bool Selected { get; set; }
bool Visible { get; set; }
bool SmallView { get; set; }
bool ThemeLoaded { get; }