From 193116f669b34df1c3ea0d4b542d5bbb09023be5 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 2 Dec 2012 19:21:37 +0100 Subject: [PATCH] added sort by mouse to playlists --- Vocaluxe/Lib/Playlist/CPlaylistFile.cs | 20 ++- Vocaluxe/Menu/CPlaylist.cs | 218 +++++++++++++++++-------- Vocaluxe/Menu/CSelectSlide.cs | 13 +- Vocaluxe/Menu/CStatic.cs | 17 ++ Vocaluxe/Menu/CText.cs | 31 ++++ Vocaluxe/Screens/CScreenNames.cs | 2 +- Vocaluxe/Screens/CScreenSong.cs | 4 +- 7 files changed, 230 insertions(+), 75 deletions(-) diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs index 79588ef1..2a7d607d 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs @@ -27,6 +27,12 @@ namespace Vocaluxe.Lib.Playlist { GameMode = EGameMode.TR_GAMEMODE_NORMAL; } + + public CPlaylistSong(CPlaylistSong ps) + { + SongID = ps.SongID; + GameMode = ps.GameMode; + } } public class CPlaylistFile @@ -236,7 +242,7 @@ namespace Vocaluxe.Lib.Playlist public void SongUp(int SongNr) { - if (SongNr != 0) + if (SongNr < Songs.Count - 1 && SongNr > 0) { Songs.Reverse(SongNr - 1, 2); } @@ -244,10 +250,20 @@ namespace Vocaluxe.Lib.Playlist public void SongDown(int SongNr) { - if (SongNr < Songs.Count - 1) + if (SongNr < Songs.Count - 1 && SongNr >= 0) { Songs.Reverse(SongNr, 2); } } + + public void SongMove(int SourceNr, int DestNr) + { + if (SourceNr < 0 || DestNr < 0 || SourceNr == DestNr || SourceNr > Songs.Count - 1 || DestNr > Songs.Count - 1) + return; + + CPlaylistSong ps = new CPlaylistSong(Songs[SourceNr]); + Songs.RemoveAt(SourceNr); + Songs.Insert(DestNr, ps); + } } } diff --git a/Vocaluxe/Menu/CPlaylist.cs b/Vocaluxe/Menu/CPlaylist.cs index 0e926d45..d257b397 100644 --- a/Vocaluxe/Menu/CPlaylist.cs +++ b/Vocaluxe/Menu/CPlaylist.cs @@ -63,6 +63,51 @@ namespace Vocaluxe.Menu public CText Text1; public CSelectSlide SelectSlide; public int Content; + + public PlaylistElement() + { + } + + public PlaylistElement(PlaylistElement pe) + { + Cover = new CStatic(pe.Cover); + Background = new CStatic(pe.Background); + Text1 = new CText(pe.Text1); + SelectSlide = new CSelectSlide(pe.SelectSlide); + Content = pe.Content; + } + + public void Draw() + { + Background.Draw(); + SelectSlide.Draw(); + Cover.Draw(); + Text1.Draw(); + } + + public void MouseMove(int PosX, int PosY, int OldPosX, int OldPosY) + { + int diffX = PosX - OldPosX; + int diffY = PosY - OldPosY; + + Cover.Rect.X += diffX; + Cover.Rect.Y += diffY; + + Background.Rect.X += diffX; + Background.Rect.Y += diffY; + + SelectSlide.Rect.X += diffX; + SelectSlide.Rect.Y += diffY; + + SelectSlide.RectArrowLeft.X += diffX; + SelectSlide.RectArrowLeft.Y += diffY; + + SelectSlide.RectArrowRight.X += diffX; + SelectSlide.RectArrowRight.Y += diffY; + + Text1.X += diffX; + Text1.Y += diffY; + } } private SThemePlaylist _Theme; @@ -93,17 +138,25 @@ namespace Vocaluxe.Menu { _Selected = value; _Interactions.Active = value; - if (CurrentPlaylistElement == -1 && _Selected && PlaylistElementContents.Count > 0) + CurrentPlaylistElement = GetSelectedSelectionNr(); + + if (!value) { - CurrentPlaylistElement = 0; + ChangeOrderSource = -1; + _EditMode = EEditMode.None; } } } public EEditMode _EditMode; - public int ActivePlaylistID = -1; - public int Offset = 0; - public int CurrentPlaylistElement = -1; + public int ActivePlaylistID; + public int Offset; + public int CurrentPlaylistElement; + + private PlaylistElement ChangeOrderElement; + private int ChangeOrderSource; + private int OldMousePosX; + private int OldMousePosY; public CPlaylist() { @@ -145,6 +198,15 @@ namespace Vocaluxe.Menu _Interactions.AddButton(_Theme.ButtonPlaylistDelete); _Interactions.AddButton(_Theme.ButtonPlaylistSave); _Interactions.AddButton(_Theme.ButtonPlaylistSing); + + ActivePlaylistID = -1; + Offset = 0; + CurrentPlaylistElement = -1; + + ChangeOrderElement = new PlaylistElement(); + OldMousePosX = 0; + OldMousePosY = 0; + ChangeOrderSource = -1; } public bool LoadTheme(string XmlPath, string ElementName, XPathNavigator navigator, int SkinIndex) @@ -355,8 +417,10 @@ namespace Vocaluxe.Menu PlaylistElements[i].Background.Color = BackgroundColor; } } - _Interactions.Draw(); + + if (_EditMode == EEditMode.ChangeOrder) + ChangeOrderElement.Draw(); } public bool IsMouseOver(MouseEvent MouseEvent) @@ -755,31 +819,55 @@ namespace Vocaluxe.Menu if (CHelper.IsInBounds(CompleteRect, MouseEvent) && Visible) { + //Scroll + if (MouseEvent.Wheel > 0) + { + if (PlaylistElements.Count + Offset + MouseEvent.Wheel <= PlaylistElementContents.Count) + { + Offset += MouseEvent.Wheel; + Update(); + } + return true; + } + else if (MouseEvent.Wheel < 0) + { + if (Offset + MouseEvent.Wheel >= 0) + { + Offset += MouseEvent.Wheel; + Update(); + } + return true; + } + + bool hover_set = false; + for (int i = 0; i < PlaylistElements.Count; i++) + { + //Hover for playlist-element + if (PlaylistElementContents.Count - 1 >= i && CHelper.IsInBounds(PlaylistElements[i].Background.Rect, MouseEvent)) + { + hover_set = true; + CurrentPlaylistElement = i; + _Interactions.SetInteractionToSelectSlide(PlaylistElements[CurrentPlaylistElement].SelectSlide); + } + + //Delete Entry with RB + if (CHelper.IsInBounds(PlaylistElements[i].Background.Rect, MouseEvent) && MouseEvent.RB && PlaylistElements[i].Content != -1) + { + CPlaylists.Playlists[ActivePlaylistID].DeleteSong(PlaylistElements[i].Content); + UpdatePlaylist(); + return true; + } + } + if (!hover_set) + { + CurrentPlaylistElement = -1; + } + switch (_EditMode) { //Normal mode case EEditMode.None: - //Scroll - if (MouseEvent.Wheel > 0) - { - if (PlaylistElements.Count + Offset + MouseEvent.Wheel <= PlaylistElementContents.Count) - { - Offset += MouseEvent.Wheel; - Update(); - return true; - } - return true; - } - else if (MouseEvent.Wheel < 0) - { - if (Offset + MouseEvent.Wheel >= 0) - { - Offset += MouseEvent.Wheel; - Update(); - return true; - } - return true; - } + //LB actions if (MouseEvent.LB) { @@ -816,30 +904,34 @@ namespace Vocaluxe.Menu return true; } } - //Actions according to playlist-element - bool hover_set = false; - for (int i = 0; i < PlaylistElements.Count; i++) - { - //Hover for playlist-element - if (PlaylistElementContents.Count - 1 >= i && CHelper.IsInBounds(PlaylistElements[i].Background.Rect, MouseEvent)) - { - hover_set = true; - CurrentPlaylistElement = i; - _Interactions.SetInteractionToSelectSlide(PlaylistElements[CurrentPlaylistElement].SelectSlide); - } - //Delete Entry with RB - if (CHelper.IsInBounds(PlaylistElements[i].Background.Rect, MouseEvent) && MouseEvent.RB && PlaylistElements[i].Content != -1) - { - CPlaylists.Playlists[ActivePlaylistID].DeleteSong(PlaylistElements[i].Content); - UpdatePlaylist(); - return true; - } - } - if(!hover_set) + //Change order with holding LB + if (MouseEvent.LBH && CurrentPlaylistElement != -1 && PlaylistElementContents.Count > 1) { - CurrentPlaylistElement = -1; + + ChangeOrderSource = CurrentPlaylistElement + Offset; + + //Update of Drag/Drop-Texture + if (ChangeOrderSource >= PlaylistElementContents.Count) + return true; + + ChangeOrderElement = new PlaylistElement(PlaylistElements[CurrentPlaylistElement]); + ChangeOrderElement.Background.Rect.Z = CSettings.zNear; + ChangeOrderElement.Cover.Rect.Z = CSettings.zNear; + ChangeOrderElement.SelectSlide.Rect.Z = CSettings.zNear; + ChangeOrderElement.SelectSlide.RectArrowLeft.Z = CSettings.zNear; + ChangeOrderElement.SelectSlide.RectArrowRight.Z = CSettings.zNear; + ChangeOrderElement.Text1.Z = CSettings.zNear; + + ChangeOrderElement.Background.Texture = CTheme.GetSkinTexture(_Theme.TextureBackgroundName); + ChangeOrderElement.Background.Color = BackgroundColor; + + OldMousePosX = MouseEvent.X; + OldMousePosY = MouseEvent.Y; + + _EditMode = EEditMode.ChangeOrder; } + break; case EEditMode.PlaylistName: @@ -869,28 +961,20 @@ namespace Vocaluxe.Menu case EEditMode.ChangeOrder: //Actions according to playlist-element - for (int i = 0; i < PlaylistElements.Count; i++) + + //Update coords for Drag/Drop-Texture + ChangeOrderElement.MouseMove(MouseEvent.X, MouseEvent.Y, OldMousePosX, OldMousePosY); + OldMousePosX = MouseEvent.X; + OldMousePosY = MouseEvent.Y; + + if (!MouseEvent.LBH) { - //Change order with holding LB - if (CHelper.IsInBounds(PlaylistElements[i].Background.Rect, MouseEvent) && MouseEvent.LBH && PlaylistElements[i].Content != -1 && _EditMode != EEditMode.ChangeOrder) + if (CurrentPlaylistElement != -1 && CurrentPlaylistElement + Offset != ChangeOrderSource) { - _EditMode = EEditMode.ChangeOrder; - CurrentPlaylistElement = i; - } - else if (CHelper.IsInBounds(PlaylistElements[i].Background.Rect, MouseEvent) && MouseEvent.LBH && PlaylistElements[i].Content != -1 && _EditMode == EEditMode.ChangeOrder) - { - /* - if (PlaylistElements.Count < CurrentPlaylistElement + 1) - { - } - else if (PlaylistElementContents.Count < CurrentPlaylistElement + 1 + Offset) - { - } - if (mevent.Y < PlaylistElements[CurrentPlaylistElement + 1].Background.Rect.Y) - { - } - */ + CPlaylists.Playlists[ActivePlaylistID].SongMove(ChangeOrderSource, CurrentPlaylistElement + Offset); + UpdatePlaylist(); } + _EditMode = EEditMode.None; } break; } diff --git a/Vocaluxe/Menu/CSelectSlide.cs b/Vocaluxe/Menu/CSelectSlide.cs index 28fb9493..166ad665 100644 --- a/Vocaluxe/Menu/CSelectSlide.cs +++ b/Vocaluxe/Menu/CSelectSlide.cs @@ -207,11 +207,16 @@ namespace Vocaluxe.Menu TextH = slide.TextH; MaxW = slide.MaxW; - _Selected = false; - _Textures = new List(); - _ValueIndexes = new List(); - _ValueNames = new List(); + _Selected = slide._Selected; + _Textures = new List(slide._Textures); + _ValueIndexes = new List(slide._ValueIndexes); + _ValueNames = new List(slide._ValueNames); + _ValueBounds = new List(slide._ValueBounds); + _Selection = slide._Selection; _NumVisible = slide._NumVisible; + + WithTextures = slide.WithTextures; + Visible = slide.Visible; } public bool LoadTheme(string XmlPath, string ElementName, XPathNavigator navigator, int SkinIndex) diff --git a/Vocaluxe/Menu/CStatic.cs b/Vocaluxe/Menu/CStatic.cs index 37d29d04..d9cddad7 100644 --- a/Vocaluxe/Menu/CStatic.cs +++ b/Vocaluxe/Menu/CStatic.cs @@ -70,6 +70,23 @@ namespace Vocaluxe.Menu Visible = true; } + public CStatic(CStatic s) + { + _Theme = new SThemeStatic(); + _ThemeLoaded = false; + + _Texture = s.Texture; + Color = new SColorF(s.Color); + Rect = new SRectF(s.Rect); + Reflection = s.Reflection; + ReflectionSpace = s.ReflectionHeight; + ReflectionHeight = s.ReflectionSpace; + + Selected = s.Selected; + Alpha = s.Alpha; + Visible = s.Visible; + } + public CStatic(STexture texture, SColorF color, SRectF rect) { _Theme = new SThemeStatic(); diff --git a/Vocaluxe/Menu/CText.cs b/Vocaluxe/Menu/CText.cs index c1ccb39a..478dd0c2 100644 --- a/Vocaluxe/Menu/CText.cs +++ b/Vocaluxe/Menu/CText.cs @@ -250,6 +250,37 @@ namespace Vocaluxe.Menu Alpha = 1f; } + public CText(CText text) + { + _Theme = new SThemeText(); + _ThemeLoaded = false; + _ButtonText = false; + + X = text._X; + Y = text._Y; + Z = text._Z; + Height = text._Height; + MaxWidth = text._MaxWidth; + Bounds = new SRectF(text._Bounds); + Align = text._Align; + HAlign = text._HAlign; + Style = text._Style; + Fon = text._Fon; + + Color = new SColorF(text.Color); + SColor = new SColorF(text.SColor); + Reflection = text.Reflection; + ReflectionSpace = text.ReflectionSpace; + ReflectionHeight = text.ReflectionHeight; + + Text = text._Text; + Selected = text.Selected; + Visible = text.Visible; + Alpha = text.Alpha; + + EditMode = text.EditMode; + } + public CText(float x, float y, float z, EAlignment align, float h, float mw, float r, float g, float b, float a, EStyle style, string font, string text, float rspace, float rheight) { _Theme = new SThemeText(); diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 51fe1850..4e838086 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -450,7 +450,7 @@ namespace Vocaluxe.Screens CStatic SelectedPlayer = NameSelections[htNameSelections(NameSelection)].TilePlayerAvatar(MouseEvent); chooseAvatarStatic.Visible = true; chooseAvatarStatic.Rect = SelectedPlayer.Rect; - chooseAvatarStatic.Rect.Z = CSettings.zNear + 1; + chooseAvatarStatic.Rect.Z = CSettings.zNear; chooseAvatarStatic.Color = new SColorF(1, 1, 1, 1); chooseAvatarStatic.Texture = SelectedPlayer.Texture; } diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index f4df4866..b559b027 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -95,6 +95,8 @@ namespace Vocaluxe.Screens Texts[htTexts(TextOptionsTitle)].Visible = false; Statics[htStatics(StaticOptionsBG)].Visible = false; Playlists[htPlaylists(Playlist)].Visible = false; + + Playlists[htPlaylists(Playlist)].Init(); } public override bool HandleInput(KeyEvent KeyEvent) @@ -395,7 +397,7 @@ namespace Vocaluxe.Screens CGame.EnterNormalGame(); SongMenus[htSongMenus(SongMenu)].OnShow(); SongMenus[htSongMenus(SongMenu)].SetActive(!_PlaylistActive); - Playlists[htPlaylists(Playlist)].Init(); + if (Playlists[htPlaylists(Playlist)].ActivePlaylistID != -1) Playlists[htPlaylists(Playlist)].LoadPlaylist(Playlists[htPlaylists(Playlist)].ActivePlaylistID); UpdatePlaylistNames();