From 124ed1c3d3de4b42682e28815c40a46c944ae4d6 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 26 Apr 2013 18:13:22 +0200 Subject: [PATCH 01/10] Renamed CGameMode to CSongQueue as this is what it actually is --- Vocaluxe/Base/CGame.cs | 54 +++++++++---------- Vocaluxe/GameModes/CGameModeNormal.cs | 24 --------- Vocaluxe/Screens/CScreenSong.cs | 2 +- .../CGameMode.cs => SongQueue/CSongQueue.cs} | 22 ++++---- .../IGameMode.cs => SongQueue/ISongQueue.cs} | 4 +- Vocaluxe/Vocaluxe.csproj | 5 +- 6 files changed, 40 insertions(+), 71 deletions(-) delete mode 100644 Vocaluxe/GameModes/CGameModeNormal.cs rename Vocaluxe/{GameModes/CGameMode.cs => SongQueue/CSongQueue.cs} (92%) rename Vocaluxe/{GameModes/IGameMode.cs => SongQueue/ISongQueue.cs} (96%) diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index ae909a92..d8403a9f 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -19,7 +19,7 @@ using System; using System.Collections.Generic; -using Vocaluxe.GameModes; +using Vocaluxe.SongQueue; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SingNotes; using VocaluxeLib.Menu.SongMenu; @@ -28,7 +28,7 @@ namespace Vocaluxe.Base { static class CGame { - private static IGameMode _GameMode; + private static ISongQueue _SongQueue; private static int _NumPlayer = CConfig.NumPlayer; private static int _OldBeatD; @@ -64,103 +64,97 @@ namespace Vocaluxe.Base public static void Init() { - _GameMode = new CGameModeNormal(); - _GameMode.Init(); + _SongQueue = new CSongQueue(); + _SongQueue.Init(); Players = new SPlayer[CSettings.MaxNumPlayer]; ResetPlayer(); CConfig.UsePlayers(); } - public static void EnterNormalGame() - { - _GameMode = new CGameModeNormal(); - _GameMode.Init(); - } - public static EGameMode GameMode { - get { return _GameMode.GetCurrentGameMode(); } + get { return _SongQueue.GetCurrentGameMode(); } } public static bool AddVisibleSong(int visibleIndex, EGameMode gameMode) { - return _GameMode.AddVisibleSong(visibleIndex, gameMode); + return _SongQueue.AddVisibleSong(visibleIndex, gameMode); } public static bool AddSong(int absoluteIndex, EGameMode gameMode) { - return _GameMode.AddSong(absoluteIndex, gameMode); + return _SongQueue.AddSong(absoluteIndex, gameMode); } public static bool RemoveVisibleSong(int visibleIndex) { - return _GameMode.RemoveVisibleSong(visibleIndex); + return _SongQueue.RemoveVisibleSong(visibleIndex); } public static bool RemoveSong(int absoluteIndex) { - return _GameMode.RemoveSong(absoluteIndex); + return _SongQueue.RemoveSong(absoluteIndex); } public static void ClearSongs() { - _GameMode.ClearSongs(); + _SongQueue.ClearSongs(); } public static void Reset() { - _GameMode.Reset(); + _SongQueue.Reset(); } public static void Start() { - _GameMode.Start(Players); + _SongQueue.Start(Players); } public static void NextRound() { - _GameMode.NextRound(Players); + _SongQueue.NextRound(Players); } public static bool IsFinished() { - return _GameMode.IsFinished(); + return _SongQueue.IsFinished(); } public static int RoundNr { - get { return _GameMode.GetCurrentRoundNr(); } + get { return _SongQueue.GetCurrentRoundNr(); } } public static CSong GetSong() { - return _GameMode.GetSong(); + return _SongQueue.GetSong(); } public static CSong GetSong(int num) { - return _GameMode.GetSong(num); + return _SongQueue.GetSong(num); } public static EGameMode GetGameMode(int num) { - return _GameMode.GetGameMode(num); + return _SongQueue.GetGameMode(num); } public static int GetNumSongs() { - return _GameMode.GetNumSongs(); + return _SongQueue.GetNumSongs(); } public static CPoints GetPoints() { - return _GameMode.GetPoints(); + return _SongQueue.GetPoints(); } public static int NumRounds { - get { return _GameMode.GetNumSongs(); } + get { return _SongQueue.GetNumSongs(); } } public static int NumPlayer @@ -200,7 +194,7 @@ namespace Vocaluxe.Base public static void UpdatePoints(float time) { - CSong song = _GameMode.GetSong(); + CSong song = _SongQueue.GetSong(); if (song == null) return; @@ -225,8 +219,8 @@ namespace Vocaluxe.Base { for (int beat = _OldBeatD + 1; beat <= ActBeatD; beat++) { - if ((_GameMode.GetCurrentGameMode() == EGameMode.TR_GAMEMODE_MEDLEY && song.Medley.EndBeat == beat) || - (_GameMode.GetCurrentGameMode() == EGameMode.TR_GAMEMODE_SHORTSONG && song.ShortEnd == beat)) + if ((_SongQueue.GetCurrentGameMode() == EGameMode.TR_GAMEMODE_MEDLEY && song.Medley.EndBeat == beat) || + (_SongQueue.GetCurrentGameMode() == EGameMode.TR_GAMEMODE_SHORTSONG && song.ShortEnd == beat)) Players[p].SongFinished = true; CLine[] lines = song.Notes.GetVoice(Players[p].LineNr).Lines; diff --git a/Vocaluxe/GameModes/CGameModeNormal.cs b/Vocaluxe/GameModes/CGameModeNormal.cs deleted file mode 100644 index e728a923..00000000 --- a/Vocaluxe/GameModes/CGameModeNormal.cs +++ /dev/null @@ -1,24 +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 . -// */ -#endregion - -namespace Vocaluxe.GameModes -{ - // Nomal singing - class CGameModeNormal : CGameMode {} -} \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 054fddf3..852e6ebb 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -612,7 +612,7 @@ namespace Vocaluxe.Screens _SearchActive = _Sso.Sorting.SearchActive; _SearchText = _Sso.Sorting.SearchString; - CGame.EnterNormalGame(); + CGame.Reset(); _SongMenus[_SongMenu].OnShow(); if (_Sso.Selection.PartyMode) diff --git a/Vocaluxe/GameModes/CGameMode.cs b/Vocaluxe/SongQueue/CSongQueue.cs similarity index 92% rename from Vocaluxe/GameModes/CGameMode.cs rename to Vocaluxe/SongQueue/CSongQueue.cs index 2d6f2527..e8ad77f2 100644 --- a/Vocaluxe/GameModes/CGameMode.cs +++ b/Vocaluxe/SongQueue/CSongQueue.cs @@ -22,30 +22,30 @@ using Vocaluxe.Base; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; -namespace Vocaluxe.GameModes +namespace Vocaluxe.SongQueue { - struct SSongQueque + struct SSongQueueEntry { public readonly int SongID; public readonly EGameMode GameMode; - public SSongQueque(int songID, EGameMode gameMode) + public SSongQueueEntry(int songID, EGameMode gameMode) { SongID = songID; GameMode = gameMode; } } - abstract class CGameMode : IGameMode + class CSongQueue : ISongQueue { - private List _SongQueque; + private List _SongQueque; private int _CurrentSong; private CPoints _Points; #region Implementation public virtual void Init() { - _SongQueque = new List(); + _SongQueque = new List(); Reset(); } @@ -64,7 +64,7 @@ namespace Vocaluxe.GameModes if (gameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(songID).IsDuet) return false; - _SongQueque.Add(new SSongQueque(songID, gameMode)); + _SongQueque.Add(new SSongQueueEntry(songID, gameMode)); return true; } return false; @@ -78,7 +78,7 @@ namespace Vocaluxe.GameModes if (gameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(songID).IsDuet) return false; - _SongQueque.Add(new SSongQueque(songID, gameMode)); + _SongQueque.Add(new SSongQueueEntry(songID, gameMode)); return true; } return false; @@ -215,7 +215,7 @@ namespace Vocaluxe.GameModes public virtual CSong GetSong(int num) { - if (num - 1 < _SongQueque.Count && num - 1 > -1) + if (num - 1 < _SongQueque.Count && num > 0) return CSongs.GetSong(_SongQueque[num - 1].SongID); return null; @@ -223,8 +223,8 @@ namespace Vocaluxe.GameModes public virtual EGameMode GetGameMode(int num) { - if (num - 1 < _SongQueque.Count && num > -1) - return _SongQueque[num].GameMode; + if (num - 1 < _SongQueque.Count && num > 0) + return _SongQueque[num - 1].GameMode; return EGameMode.TR_GAMEMODE_NORMAL; } diff --git a/Vocaluxe/GameModes/IGameMode.cs b/Vocaluxe/SongQueue/ISongQueue.cs similarity index 96% rename from Vocaluxe/GameModes/IGameMode.cs rename to Vocaluxe/SongQueue/ISongQueue.cs index b9732b15..40bf808d 100644 --- a/Vocaluxe/GameModes/IGameMode.cs +++ b/Vocaluxe/SongQueue/ISongQueue.cs @@ -20,9 +20,9 @@ using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; -namespace Vocaluxe.GameModes +namespace Vocaluxe.SongQueue { - interface IGameMode + interface ISongQueue { void Init(); diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 58fa7a40..1e170ebb 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -198,9 +198,8 @@ Form - - - + + Form From 780a179fcb84956d60119a65ba925ff4f67f87ef Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 26 Apr 2013 18:56:33 +0200 Subject: [PATCH 02/10] Added Gamemode-Classes --- .../PartyModeChallenge/CPartyModeChallenge.cs | 10 +- .../CPartyModeChallengeMedley.cs | 10 +- .../PartyModeTicTacToe/CPartyModeTicTacToe.cs | 16 +- Vocaluxe/Base/CGame.cs | 12 +- Vocaluxe/Base/CSongs.cs | 27 ++- Vocaluxe/GameModes/CGameMode.cs | 24 +++ Vocaluxe/GameModes/CGameModes.cs | 81 +++++++++ Vocaluxe/GameModes/IGameMode.cs | 9 + Vocaluxe/Screens/CScreenHighscore.cs | 8 +- Vocaluxe/Screens/CScreenScore.cs | 62 +++---- Vocaluxe/SongQueue/CSongQueue.cs | 163 ++++++------------ Vocaluxe/SongQueue/ISongQueue.cs | 4 +- Vocaluxe/Vocaluxe.csproj | 3 + VocaluxeLib/Menu/CPoints.cs | 28 +-- VocaluxeLib/Menu/SingNotes/CNotes.cs | 1 + VocaluxeLib/Menu/SongMenu/CSong.cs | 24 +-- 16 files changed, 258 insertions(+), 224 deletions(-) create mode 100644 Vocaluxe/GameModes/CGameMode.cs create mode 100644 Vocaluxe/GameModes/CGameModes.cs create mode 100644 Vocaluxe/GameModes/IGameMode.cs diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index 5782df18..8479323b 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -459,11 +459,11 @@ namespace VocaluxeLib.PartyModes.Challenge CBase.Game.AddSong(songID, gm); CBase.Game.SetNumPlayer(_GameData.NumPlayerAtOnce); - SPlayer[] player = CBase.Game.GetPlayers(); - if (player == null) + SPlayer[] players = CBase.Game.GetPlayers(); + if (players == null) return; - if (player.Length < _GameData.NumPlayerAtOnce) + if (players.Length < _GameData.NumPlayerAtOnce) return; CCombination c = _GameData.Rounds.GetRound(_GameData.CurrentRoundNr - 1); @@ -472,9 +472,9 @@ namespace VocaluxeLib.PartyModes.Challenge { //try to fill with the right data if (c != null) - player[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; + players[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; else - player[i].ProfileID = -1; + players[i].ProfileID = -1; } CBase.Songs.AddPartySongSung(songID); diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index e733ddb3..89b4b1a0 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -482,11 +482,11 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley #region PlayerNames CBase.Game.SetNumPlayer(_GameData.NumPlayerAtOnce); - SPlayer[] player = CBase.Game.GetPlayers(); - if (player == null) + SPlayer[] players = CBase.Game.GetPlayers(); + if (players == null) return false; - if (player.Length < _GameData.NumPlayerAtOnce) + if (players.Length < _GameData.NumPlayerAtOnce) return false; CCombination c = _GameData.Rounds.GetRound(_GameData.CurrentRoundNr - 1); @@ -495,9 +495,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { //try to fill with the right data if (c != null) - player[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; + players[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; else - player[i].ProfileID = -1; + players[i].ProfileID = -1; } #endregion PlayerNames diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 4dc7e99f..21e9f455 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -718,11 +718,11 @@ namespace VocaluxeLib.PartyModes.TicTacToe CBase.Game.SetNumPlayer(2); - SPlayer[] player = CBase.Game.GetPlayers(); - if (player == null) + SPlayer[] players = CBase.Game.GetPlayers(); + if (players == null) return; - if (player.Length < 2) + if (players.Length < 2) return; SProfile[] profiles = CBase.Profiles.GetProfiles(); @@ -732,7 +732,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe for (int i = 0; i < 2; i++) { //default values - player[i].ProfileID = -1; + players[i].ProfileID = -1; } //try to fill with the right data @@ -740,15 +740,15 @@ namespace VocaluxeLib.PartyModes.TicTacToe { if (_GameData.ProfileIDsTeam1[r.SingerTeam1] < profiles.Length) { - player[0].ProfileID = _GameData.ProfileIDsTeam1[r.SingerTeam1]; + players[0].ProfileID = _GameData.ProfileIDsTeam1[r.SingerTeam1]; if (isDuet) - player[0].LineNr = 0; + players[0].LineNr = 0; } if (_GameData.ProfileIDsTeam2[r.SingerTeam2] < profiles.Length) { - player[1].ProfileID = _GameData.ProfileIDsTeam2[r.SingerTeam2]; + players[1].ProfileID = _GameData.ProfileIDsTeam2[r.SingerTeam2]; if (isDuet) - player[1].LineNr = 1; + players[1].LineNr = 1; } SongSelected(r.SongID); } diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index d8403a9f..672ac815 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -246,15 +246,9 @@ namespace Vocaluxe.Base Players[p].SingLine.Add(new CLine()); CNote[] notes = lines[line].Notes; - int note = -1; - for (int j = 0; j < notes.Length; j++) - { - if (beat >= notes[j].StartBeat && beat <= notes[j].EndBeat) - { - note = j; - break; - } - } + int note = lines[line].FindPreviousNote(beat); + if (notes[note].EndBeat < beat) + note = -1; if (note >= 0) { diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index b2780e53..876464ed 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -52,7 +52,6 @@ namespace Vocaluxe.Base private static bool _SongsLoaded; private static bool _CoverLoaded; - private static int _CoverLoadIndex; private static int _CatIndex = -1; private static readonly List _CategoriesForRandom = new List(); @@ -157,20 +156,17 @@ namespace Vocaluxe.Base if (!SongsLoaded) return -1; - if (_CoverLoadIndex < _Songs.Count) + if (NumSongsWithCoverLoaded < _Songs.Count) { - song = _Songs[_CoverLoadIndex]; - _CoverLoadIndex++; - return _CoverLoadIndex; + song = _Songs[NumSongsWithCoverLoaded]; + NumSongsWithCoverLoaded++; + return NumSongsWithCoverLoaded; } return -2; } - public static int NumSongsWithCoverLoaded - { - get { return _CoverLoadIndex; } - } + public static int NumSongsWithCoverLoaded { get; private set; } public static void SetCoverSmall(int songIndex, STexture texture) { @@ -392,12 +388,11 @@ namespace Vocaluxe.Base foreach (string file in files) { CSong song = CSong.LoadSong(file); - if (song != null) - { - song.ID = _Songs.Count; - if (song.ReadNotes()) - _Songs.Add(song); - } + if (song == null) + continue; + song.ID = _Songs.Count; + if (song.ReadNotes()) + _Songs.Add(song); } CLog.StopBenchmark(2, "Read TXTs"); @@ -460,7 +455,7 @@ namespace Vocaluxe.Base foreach (CSong song in _Songs) { song.LoadSmallCover(); - _CoverLoadIndex++; + NumSongsWithCoverLoaded++; } GC.Collect(); _CoverLoaded = true; diff --git a/Vocaluxe/GameModes/CGameMode.cs b/Vocaluxe/GameModes/CGameMode.cs new file mode 100644 index 00000000..b14830cf --- /dev/null +++ b/Vocaluxe/GameModes/CGameMode.cs @@ -0,0 +1,24 @@ +using Vocaluxe.Base; +using VocaluxeLib.Menu.SongMenu; + +namespace Vocaluxe.GameModes +{ + abstract class CGameMode : IGameMode + { + private CSong _LastSong; + private int _LastSongID; + + public CSong GetSong(int songID) + { + if (songID != _LastSongID) + { + CSong song = CSongs.GetSong(songID); + _LastSong = _PrepareSong(song); + _LastSongID = songID; + } + return _LastSong; + } + + protected abstract CSong _PrepareSong(CSong song); + } +} \ No newline at end of file diff --git a/Vocaluxe/GameModes/CGameModes.cs b/Vocaluxe/GameModes/CGameModes.cs new file mode 100644 index 00000000..18b1b980 --- /dev/null +++ b/Vocaluxe/GameModes/CGameModes.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Vocaluxe.Base; +using VocaluxeLib.Menu; +using VocaluxeLib.Menu.SongMenu; + +namespace Vocaluxe.GameModes +{ + static class CGameModes + { + private static Dictionary _GameModes; + + public static void Init() + { + _GameModes = new Dictionary + { + {EGameMode.TR_GAMEMODE_NORMAL, new CGameModeNormal()}, + {EGameMode.TR_GAMEMODE_DUET, new CGameModeDuet()}, + {EGameMode.TR_GAMEMODE_SHORTSONG, new CGameModeShort()}, + {EGameMode.TR_GAMEMODE_MEDLEY, new CGameModeMedley()} + }; + } + + public static IGameMode Get(EGameMode gameMode) + { + if (_GameModes == null) + return null; + IGameMode result; + if (!_GameModes.TryGetValue(gameMode, out result)) + result = _GameModes[EGameMode.TR_GAMEMODE_NORMAL]; + return result; + } + } + + class CGameModeNormal : CGameMode + { + protected override CSong _PrepareSong(CSong song) + { + return song; + } + } + + class CGameModeDuet : CGameMode + { + protected override CSong _PrepareSong(CSong song) + { + return (song.IsDuet) ? song : null; + } + } + + class CGameModeShort : CGameMode + { + protected override CSong _PrepareSong(CSong song) + { + CSong newSong = new CSong(song) {Finish = CGame.GetTimeFromBeats(song.ShortEnd, song.BPM) + CSettings.DefaultMedleyFadeOutTime + song.Gap}; + // set lines to short mode + newSong.Notes.SetMedley(song.Notes.GetVoice(0).Lines[0].FirstNoteBeat, song.ShortEnd); + + return newSong; + } + } + + class CGameModeMedley : CGameMode + { + protected override CSong _PrepareSong(CSong song) + { + CSong newSong = new CSong(song) {Start = CGame.GetTimeFromBeats(song.Medley.StartBeat, song.BPM) - song.Medley.FadeInTime + song.Gap}; + if (newSong.Start < 0f) + newSong.Start = 0f; + + newSong.Finish = CGame.GetTimeFromBeats(song.Medley.EndBeat, song.BPM) + song.Medley.FadeOutTime + song.Gap; + + // set lines to medley mode + newSong.Notes.SetMedley(song.Medley.StartBeat, song.Medley.EndBeat); + + return newSong; + } + } +} \ No newline at end of file diff --git a/Vocaluxe/GameModes/IGameMode.cs b/Vocaluxe/GameModes/IGameMode.cs new file mode 100644 index 00000000..940bc1f1 --- /dev/null +++ b/Vocaluxe/GameModes/IGameMode.cs @@ -0,0 +1,9 @@ +using VocaluxeLib.Menu.SongMenu; + +namespace Vocaluxe.GameModes +{ + interface IGameMode + { + CSong GetSong(int songID); + } +} \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenHighscore.cs b/Vocaluxe/Screens/CScreenHighscore.cs index b8eb3d14..0f3bb0c4 100644 --- a/Vocaluxe/Screens/CScreenHighscore.cs +++ b/Vocaluxe/Screens/CScreenHighscore.cs @@ -219,12 +219,12 @@ namespace Vocaluxe.Screens for (int round = 0; round < points.NumRounds; round++) { - SPlayer[] player = points.GetPlayer(round, CGame.NumPlayer); + SPlayer[] players = points.GetPlayer(round, CGame.NumPlayer); - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { - if (player[p].Points > CSettings.MinScoreForDB && player[p].SongFinished && !CProfiles.IsGuestProfile(player[p].ProfileID)) - _NewEntryIDs.Add(CDataBase.AddScore(player[p])); + if (players[p].Points > CSettings.MinScoreForDB && players[p].SongFinished && !CProfiles.IsGuestProfile(players[p].ProfileID)) + _NewEntryIDs.Add(CDataBase.AddScore(players[p])); } } } diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index e02f912c..57764cac 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -127,31 +127,31 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { - SPlayer[] player = new SPlayer[CGame.NumPlayer]; + SPlayer[] players = new SPlayer[CGame.NumPlayer]; if (_Round != 0) - player = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); + players = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); else { for (int i = 0; i < CGame.NumRounds; i++) { SPlayer[] points = _Points.GetPlayer(i, CGame.NumPlayer); - for (int p = 0; p < player.Length; p++) - player[p].Points += points[p].Points; + for (int p = 0; p < players.Length; p++) + players[p].Points += points[p].Points; } - for (int p = 0; p < player.Length; p++) - player[p].Points = (int)(player[p].Points / CGame.NumRounds); + for (int p = 0; p < players.Length; p++) + players[p].Points = (int)(players[p].Points / CGame.NumRounds); } - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { - if (_StaticPointsBarDrawnPoints[p] < player[p].Points) + if (_StaticPointsBarDrawnPoints[p] < players[p].Points) { if (CConfig.ScoreAnimationTime >= 1) { _StaticPointsBarDrawnPoints[p] = (_Timer.ElapsedMilliseconds / 1000f) / CConfig.ScoreAnimationTime * 10000; - if (_StaticPointsBarDrawnPoints[p] > player[p].Points) - _StaticPointsBarDrawnPoints[p] = player[p].Points; + if (_StaticPointsBarDrawnPoints[p] > players[p].Points) + _StaticPointsBarDrawnPoints[p] = players[p].Points; string direction = (string)_ScreenSettings[_ScreenSettingAnimationDirection].GetValue(); if (direction.ToLower() == "vertical") { @@ -260,7 +260,7 @@ namespace Vocaluxe.Screens private void _UpdateRatings() { CSong song = null; - SPlayer[] player = new SPlayer[CGame.NumPlayer]; + SPlayer[] players = new SPlayer[CGame.NumPlayer]; if (_Round != 0) { song = CGame.GetSong(_Round); @@ -270,7 +270,7 @@ namespace Vocaluxe.Screens _Texts[_TextSong].Text = song.Artist + " - " + song.Title; if (_Points.NumRounds > 1) _Texts[_TextSong].Text += " (" + _Round + "/" + _Points.NumRounds + ")"; - player = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); + players = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); } else { @@ -278,47 +278,47 @@ namespace Vocaluxe.Screens for (int i = 0; i < CGame.NumRounds; i++) { SPlayer[] points = _Points.GetPlayer(i, CGame.NumPlayer); - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { if (i < 1) - player[p].ProfileID = points[p].ProfileID; - player[p].Points += points[p].Points; + players[p].ProfileID = points[p].ProfileID; + players[p].Points += points[p].Points; } } - for (int p = 0; p < player.Length; p++) - player[p].Points = (int)Math.Round(player[p].Points / CGame.NumRounds); + for (int p = 0; p < players.Length; p++) + players[p].Points = (int)Math.Round(players[p].Points / CGame.NumRounds); } - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { - string name = CProfiles.GetPlayerName(player[p].ProfileID, p); + string name = CProfiles.GetPlayerName(players[p].ProfileID, p); if (song != null && song.IsDuet) { - if (player[p].LineNr == 0 && song.DuetPart1 != "Part 1") + if (players[p].LineNr == 0 && song.DuetPart1 != "Part 1") name += " (" + song.DuetPart1 + ")"; - else if (player[p].LineNr == 1 && song.DuetPart2 != "Part 2") + else if (players[p].LineNr == 1 && song.DuetPart2 != "Part 2") name += " (" + song.DuetPart2 + ")"; } _Texts[_TextNames[p, CGame.NumPlayer - 1]].Text = name; if (CGame.NumPlayer < (int)_ScreenSettings[_ScreenSettingShortScore].GetValue()) - _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(player[p].Points)).ToString("0000") + " " + CLanguage.Translate("TR_SCREENSCORE_POINTS"); + _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(players[p].Points)).ToString("0000") + " " + CLanguage.Translate("TR_SCREENSCORE_POINTS"); else - _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(player[p].Points)).ToString("0000"); + _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(players[p].Points)).ToString("0000"); if (CGame.NumPlayer < (int)_ScreenSettings[_ScreenSettingShortDifficulty].GetValue()) { _Texts[_TextDifficulty[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate("TR_SCREENSCORE_GAMEDIFFICULTY") + ": " + - CLanguage.Translate(CProfiles.GetDifficulty(player[p].ProfileID).ToString()); + CLanguage.Translate(CProfiles.GetDifficulty(players[p].ProfileID).ToString()); } else - _Texts[_TextDifficulty[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(CProfiles.GetDifficulty(player[p].ProfileID).ToString()); + _Texts[_TextDifficulty[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(CProfiles.GetDifficulty(players[p].ProfileID).ToString()); if (CGame.NumPlayer < (int)_ScreenSettings[_ScreenSettingShortRating].GetValue()) { _Texts[_TextRatings[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate("TR_SCREENSCORE_RATING") + ": " + - CLanguage.Translate(_GetRating((int)Math.Round(player[p].Points))); + CLanguage.Translate(_GetRating((int)Math.Round(players[p].Points))); } else - _Texts[_TextRatings[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(_GetRating((int)Math.Round(player[p].Points))); + _Texts[_TextRatings[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(_GetRating((int)Math.Round(players[p].Points))); _StaticPointsBarDrawnPoints[p] = 0.0; string direction = (string)_ScreenSettings[_ScreenSettingAnimationDirection].GetValue(); @@ -331,19 +331,19 @@ namespace Vocaluxe.Screens _Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.Y - _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H; } - if (CProfiles.IsProfileIDValid(player[p].ProfileID)) - _Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[player[p].ProfileID].Avatar.Texture; + if (CProfiles.IsProfileIDValid(players[p].ProfileID)) + _Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[players[p].ProfileID].Avatar.Texture; } if (CConfig.ScoreAnimationTime < 1) { for (int p = 0; p < CGame.NumPlayer; p++) { - _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H = ((float)player[p].Points) * (_Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.H / 10000); + _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H = ((float)players[p].Points) * (_Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.H / 10000); _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.Y = _Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.H + _Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.Y - _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H; - _StaticPointsBarDrawnPoints[p] = player[p].Points; + _StaticPointsBarDrawnPoints[p] = players[p].Points; } } diff --git a/Vocaluxe/SongQueue/CSongQueue.cs b/Vocaluxe/SongQueue/CSongQueue.cs index e8ad77f2..0217fc47 100644 --- a/Vocaluxe/SongQueue/CSongQueue.cs +++ b/Vocaluxe/SongQueue/CSongQueue.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using Vocaluxe.Base; +using Vocaluxe.GameModes; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -43,110 +44,77 @@ namespace Vocaluxe.SongQueue private CPoints _Points; #region Implementation - public virtual void Init() + public void Init() { _SongQueque = new List(); Reset(); + CGameModes.Init(); } - public virtual EGameMode GetCurrentGameMode() + public EGameMode GetCurrentGameMode() { if (_CurrentSong >= 0 && _CurrentSong < _SongQueque.Count) return _SongQueque[_CurrentSong].GameMode; return EGameMode.TR_GAMEMODE_NORMAL; } - public virtual bool AddVisibleSong(int visibleIndex, EGameMode gameMode) + public bool AddVisibleSong(int visibleIndex, EGameMode gameMode) { - if (CSongs.VisibleSongs.Length > visibleIndex) - { - int songID = CSongs.VisibleSongs[visibleIndex].ID; - if (gameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(songID).IsDuet) - return false; + return CSongs.VisibleSongs.Length > visibleIndex && _AddSong(CSongs.VisibleSongs[visibleIndex].ID, gameMode); + } - _SongQueque.Add(new SSongQueueEntry(songID, gameMode)); + public bool AddSong(int absoluteIndex, EGameMode gameMode) + { + return CSongs.AllSongs.Length > absoluteIndex && _AddSong(CSongs.AllSongs[absoluteIndex].ID, gameMode); + } + + private bool _AddSong(int songID, EGameMode gameMode) + { + if (gameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(songID).IsDuet) + return false; + + _SongQueque.Add(new SSongQueueEntry(songID, gameMode)); + return true; + } + + public bool RemoveVisibleSong(int visibleIndex) + { + return CSongs.VisibleSongs.Length > visibleIndex && _RemoveSong(CSongs.VisibleSongs[visibleIndex].ID); + } + + public bool RemoveSong(int absoluteIndex) + { + return CSongs.AllSongs.Length > absoluteIndex && _RemoveSong(CSongs.AllSongs[absoluteIndex].ID); + } + + private bool _RemoveSong(int songID) + { + for (int i = 0; i < _SongQueque.Count; i++) + { + if (_SongQueque[i].SongID != songID) + continue; + _SongQueque.RemoveAt(i); return true; } return false; } - public virtual bool AddSong(int absoluteIndex, EGameMode gameMode) - { - if (CSongs.AllSongs.Length > absoluteIndex) - { - int songID = CSongs.AllSongs[absoluteIndex].ID; - if (gameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(songID).IsDuet) - return false; - - _SongQueque.Add(new SSongQueueEntry(songID, gameMode)); - return true; - } - return false; - } - - public virtual bool RemoveVisibleSong(int visibleIndex) - { - if (CSongs.VisibleSongs.Length > visibleIndex) - { - int index = -1; - int songID = CSongs.VisibleSongs[visibleIndex].ID; - for (int i = 0; i < _SongQueque.Count; i++) - { - if (_SongQueque[i].SongID == songID) - { - index = i; - break; - } - } - - if (index == -1) - return false; - - _SongQueque.RemoveAt(index); - return true; - } - return false; - } - - public virtual bool RemoveSong(int absoluteIndex) - { - if (CSongs.AllSongs.Length > absoluteIndex) - { - int index = -1; - int songID = CSongs.AllSongs[absoluteIndex].ID; - for (int i = 0; i < _SongQueque.Count; i++) - { - if (_SongQueque[i].SongID == songID) - { - index = i; - break; - } - } - if (index == -1) - return false; - - _SongQueque.RemoveAt(index); - return true; - } - return false; - } - - public virtual void ClearSongs() + public void ClearSongs() { _SongQueque.Clear(); } - public virtual void Reset() + public void Reset() { _CurrentSong = -1; } - public virtual void Start(SPlayer[] player) + public void Start(SPlayer[] players) { - _Points = new CPoints(_SongQueque.Count, player); + _Points = new CPoints(_SongQueque.Count, players); } - public virtual void NextRound(SPlayer[] player) + public void NextRound(SPlayer[] players) { if (_CurrentSong < _SongQueque.Count && _SongQueque.Count > 0) { @@ -155,7 +123,7 @@ namespace Vocaluxe.SongQueue _Points.SetPoints( _CurrentSong, _SongQueque[_CurrentSong].SongID, - player, + players, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_MEDLEY, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_DUET, _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_SHORTSONG); @@ -164,56 +132,29 @@ namespace Vocaluxe.SongQueue } } - public virtual bool IsFinished() + public bool IsFinished() { return _CurrentSong == _SongQueque.Count || _SongQueque.Count == 0; } - public virtual int GetCurrentRoundNr() + public int GetCurrentRoundNr() { return _CurrentSong + 1; } - public virtual CSong GetSong() + public CSong GetSong() { if (_CurrentSong >= 0 && _CurrentSong < _SongQueque.Count) - { - CSong song = CSongs.GetSong(_SongQueque[_CurrentSong].SongID); - song = new CSong(song); - - switch (GetCurrentGameMode()) - { - case EGameMode.TR_GAMEMODE_MEDLEY: - // set medley mode timings - song.Start = CGame.GetTimeFromBeats(song.Medley.StartBeat, song.BPM) - song.Medley.FadeInTime + song.Gap; - if (song.Start < 0f) - song.Start = 0f; - - song.Finish = CGame.GetTimeFromBeats(song.Medley.EndBeat, song.BPM) + song.Medley.FadeOutTime + song.Gap; - - // set lines to medley mode - song.Notes.SetMedley(song.Medley.StartBeat, song.Medley.EndBeat); - break; - - case EGameMode.TR_GAMEMODE_SHORTSONG: - song.Finish = CGame.GetTimeFromBeats(song.ShortEnd, song.BPM) + CSettings.DefaultMedleyFadeOutTime + song.Gap; - - // set lines to medley mode - song.Notes.SetMedley(song.Notes.GetVoice(0).Lines[0].FirstNoteBeat, song.ShortEnd); - break; - } - - return song; - } + CGameModes.Get(GetCurrentGameMode()).GetSong(_SongQueque[_CurrentSong].SongID); return null; } - public virtual int GetNumSongs() + public int GetNumSongs() { return _SongQueque.Count; } - public virtual CSong GetSong(int num) + public CSong GetSong(int num) { if (num - 1 < _SongQueque.Count && num > 0) return CSongs.GetSong(_SongQueque[num - 1].SongID); @@ -221,7 +162,7 @@ namespace Vocaluxe.SongQueue return null; } - public virtual EGameMode GetGameMode(int num) + public EGameMode GetGameMode(int num) { if (num - 1 < _SongQueque.Count && num > 0) return _SongQueque[num - 1].GameMode; @@ -229,7 +170,7 @@ namespace Vocaluxe.SongQueue return EGameMode.TR_GAMEMODE_NORMAL; } - public virtual CPoints GetPoints() + public CPoints GetPoints() { return _Points; } diff --git a/Vocaluxe/SongQueue/ISongQueue.cs b/Vocaluxe/SongQueue/ISongQueue.cs index 40bf808d..05d48111 100644 --- a/Vocaluxe/SongQueue/ISongQueue.cs +++ b/Vocaluxe/SongQueue/ISongQueue.cs @@ -35,8 +35,8 @@ namespace Vocaluxe.SongQueue void ClearSongs(); void Reset(); - void Start(SPlayer[] player); - void NextRound(SPlayer[] player); + void Start(SPlayer[] players); + void NextRound(SPlayer[] players); bool IsFinished(); int GetCurrentRoundNr(); diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 1e170ebb..e77012f6 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -198,7 +198,10 @@ Form + + + diff --git a/VocaluxeLib/Menu/CPoints.cs b/VocaluxeLib/Menu/CPoints.cs index b9ff4b41..f6ab17fb 100644 --- a/VocaluxeLib/Menu/CPoints.cs +++ b/VocaluxeLib/Menu/CPoints.cs @@ -80,23 +80,23 @@ namespace VocaluxeLib.Menu if (round >= NumRounds) return new SPlayer[1]; - SPlayer[] player = new SPlayer[numPlayer]; + SPlayer[] players = new SPlayer[numPlayer]; - for (int p = 0; p < player.Length; p++) + for (int p = 0; p < players.Length; p++) { - player[p].Points = _Rounds[round, p].Points; - player[p].PointsGoldenNotes = _Rounds[round, p].PointsGoldenNotes; - player[p].PointsLineBonus = _Rounds[round, p].PointsLineBonus; - player[p].SongID = _Rounds[round, p].SongID; - player[p].LineNr = _Rounds[round, p].LineNr; - player[p].Medley = _Rounds[round, p].Medley; - player[p].Duet = _Rounds[round, p].Duet; - player[p].ShortSong = _Rounds[round, p].ShortSong; - player[p].DateTicks = _Rounds[round, p].DateTicks; - player[p].SongFinished = _Rounds[round, p].SongFinished; - player[p].ProfileID = _Rounds[round, p].ProfileID; + players[p].Points = _Rounds[round, p].Points; + players[p].PointsGoldenNotes = _Rounds[round, p].PointsGoldenNotes; + players[p].PointsLineBonus = _Rounds[round, p].PointsLineBonus; + players[p].SongID = _Rounds[round, p].SongID; + players[p].LineNr = _Rounds[round, p].LineNr; + players[p].Medley = _Rounds[round, p].Medley; + players[p].Duet = _Rounds[round, p].Duet; + players[p].ShortSong = _Rounds[round, p].ShortSong; + players[p].DateTicks = _Rounds[round, p].DateTicks; + players[p].SongFinished = _Rounds[round, p].SongFinished; + players[p].ProfileID = _Rounds[round, p].ProfileID; } - return player; + return players; } } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SingNotes/CNotes.cs b/VocaluxeLib/Menu/SingNotes/CNotes.cs index 0ba6dfb6..0de66cf3 100644 --- a/VocaluxeLib/Menu/SingNotes/CNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CNotes.cs @@ -423,6 +423,7 @@ namespace VocaluxeLib.Menu.SingNotes return _PerfectLine; } + //Find last note with StartBeat<=Beat public int FindPreviousNote(int beat) { //If no notes -> No previous note diff --git a/VocaluxeLib/Menu/SongMenu/CSong.cs b/VocaluxeLib/Menu/SongMenu/CSong.cs index 126a53c7..e4396d48 100644 --- a/VocaluxeLib/Menu/SongMenu/CSong.cs +++ b/VocaluxeLib/Menu/SongMenu/CSong.cs @@ -116,7 +116,6 @@ namespace VocaluxeLib.Menu.SongMenu { private bool _CoverSmallLoaded; private bool _CoverBigLoaded; - private bool _NotesLoaded; private STexture _CoverTextureSmall = new STexture(-1); private STexture _CoverTextureBig = new STexture(-1); @@ -140,18 +139,7 @@ namespace VocaluxeLib.Menu.SongMenu public EAspect VideoAspect = EAspect.Crop; - public bool CoverSmallLoaded - { - get { return _CoverSmallLoaded; } - } - public bool CoverBigLoaded - { - get { return _CoverBigLoaded; } - } - public bool NotesLoaded - { - get { return _NotesLoaded; } - } + public bool NotesLoaded { get; private set; } public STexture CoverTextureSmall { @@ -173,9 +161,7 @@ namespace VocaluxeLib.Menu.SongMenu { get { - if (_CoverBigLoaded) - return _CoverTextureBig; - return _CoverTextureSmall; + return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } set { @@ -278,7 +264,7 @@ namespace VocaluxeLib.Menu.SongMenu VideoAspect = song.VideoAspect; _CoverSmallLoaded = song._CoverSmallLoaded; _CoverBigLoaded = song._CoverBigLoaded; - _NotesLoaded = song._NotesLoaded; + NotesLoaded = song.NotesLoaded; Artist = song.Artist; Title = song.Title; @@ -619,7 +605,7 @@ namespace VocaluxeLib.Menu.SongMenu private bool _ReadNotes(string filePath, bool forceReload = false) { //Skip loading if already done and no reload is forced - if (_NotesLoaded && !forceReload) + if (NotesLoaded && !forceReload) return true; if (!File.Exists(filePath)) @@ -784,7 +770,7 @@ namespace VocaluxeLib.Menu.SongMenu { _FindRefrain(); _FindShortEnd(); - _NotesLoaded = true; + NotesLoaded = true; if (IsDuet) _CheckDuet(); } From 5f28c5a10316da334afdb4dd54bcb73a46faf104 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 28 Apr 2013 12:23:10 +0200 Subject: [PATCH 03/10] Fixed DX Close Bug and some typos closes #15 --- .../CPartyModeChallengeMedley.cs | 4 +- Vocaluxe/Base/CDataBase.cs | 4 +- Vocaluxe/Base/CDraw.cs | 4 +- Vocaluxe/Base/CSongs.cs | 2 +- Vocaluxe/Lib/Draw/CDirect3D.cs | 33 +++++++------ Vocaluxe/Lib/Draw/CDrawWinForm.cs | 2 +- Vocaluxe/Lib/Draw/COpenGL.cs | 30 ++++++------ Vocaluxe/Lib/Draw/IDraw.cs | 2 +- Vocaluxe/Screens/CScreenSing.cs | 6 +-- Vocaluxe/SongQueue/CSongQueue.cs | 46 +++++++++---------- 10 files changed, 69 insertions(+), 64 deletions(-) diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index 89b4b1a0..cd0e61f3 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -501,7 +501,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley } #endregion PlayerNames - #region SongQueque + #region SongQueue if (CBase.Songs.GetNumVisibleSongs() < _NumSongs) CBase.Songs.ResetPartySongSung(); @@ -542,7 +542,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley s++; } return true; - #endregion SongQueque + #endregion SongQueue } private void _SetNumJokers() diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index da72c5b6..7d9ecdda 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -956,7 +956,7 @@ namespace Vocaluxe.Base reader.Read(); byte[] data = _GetBytes(reader); reader.Dispose(); - tex = CDraw.QuequeTexture(w, h, ref data); + tex = CDraw.EnqueueTexture(w, h, ref data); return true; } } @@ -1006,7 +1006,7 @@ namespace Vocaluxe.Base origin.Dispose(); } - tex = CDraw.QuequeTexture(w, h, ref data); + tex = CDraw.EnqueueTexture(w, h, ref data); command.CommandText = "INSERT INTO Cover (Path, width, height) VALUES (@path, @w, @h)"; command.Parameters.Add("@w", DbType.Int32).Value = w; diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index bc843f7f..0bed36e9 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -211,9 +211,9 @@ namespace Vocaluxe.Base return _Draw.AddTexture(w, h, ref data); } - public static STexture QuequeTexture(int w, int h, ref byte[] data) + public static STexture EnqueueTexture(int w, int h, ref byte[] data) { - return _Draw.QuequeTexture(w, h, ref data); + return _Draw.EnqueueTexture(w, h, ref data); } public static bool UpdateTexture(ref STexture texture, ref byte[] data) diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 876464ed..c498eafb 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -418,7 +418,7 @@ namespace Vocaluxe.Base public static void LoadCover() { if (CConfig.Renderer == ERenderer.TR_CONFIG_SOFTWARE) - return; //should be removed as soon as the other renderer are ready for queque + return; //should be removed as soon as the other renderer are ready for queue if (!SongsLoaded || CoverLoaded) return; diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 53cca0ac..7a084bca 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -29,12 +29,13 @@ using System.Drawing.Imaging; using System.IO; using System.Runtime.InteropServices; using System.Windows.Forms; +using SlimDX.Windows; using Vocaluxe.Base; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Draw { - class CDirect3D : Form, IDraw + class CDirect3D : RenderForm, IDraw { #region private vars private readonly CKeys _Keys; @@ -51,7 +52,7 @@ namespace Vocaluxe.Lib.Draw private readonly Dictionary _Textures; private readonly Dictionary _D3DTextures; - private readonly List _Queque; + private readonly List _Queue; private readonly Queue _IDs; private readonly Object _MutexTexture = new Object(); @@ -81,7 +82,7 @@ namespace Vocaluxe.Lib.Draw Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); _Textures = new Dictionary(); _D3DTextures = new Dictionary(); - _Queque = new List(); + _Queue = new List(); _IDs = new Queue(); //Fill Queue with 100000 IDs @@ -97,7 +98,7 @@ namespace Vocaluxe.Lib.Draw { _D3D = new Direct3D(); } - catch (Direct3D9NotFoundException e) + catch (Direct3DX9NotFoundException e) { MessageBox.Show("No DirectX runtimes were found, please download and install them " + "from http://www.microsoft.com/download/en/details.aspx?id=8109", @@ -515,13 +516,15 @@ namespace Vocaluxe.Lib.Draw //We want to begin drawing if (_Device.BeginScene().IsFailure) CLog.LogError("Failed to begin scene"); - _CheckQueque(); - _Run = _Run && CGraphics.Draw(); + _CheckQueue(); + if (!CGraphics.Draw()) + _Run = false; _RenderVertexBuffer(); //We finished drawing the frame if (_Device.EndScene().IsFailure) CLog.LogError("Failed to end scene"); - _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); + if (!CGraphics.UpdateGameLogic(_Keys, _Mouse)) + _Run = false; try { //Now push the frame to the Viewport @@ -1010,10 +1013,10 @@ namespace Vocaluxe.Lib.Draw return t; } - public STexture QuequeTexture(int w, int h, ref byte[] data) + public STexture EnqueueTexture(int w, int h, ref byte[] data) { STexture texture = new STexture(-1); - STextureQueque queque = new STextureQueque {Data = data, Height = h, Width = w}; + STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; texture.Height = h; texture.Width = w; @@ -1022,8 +1025,8 @@ namespace Vocaluxe.Lib.Draw { _D3DTextures.Add(_IDs.Peek(), null); texture.Index = _IDs.Dequeue(); - queque.ID = texture.Index; - _Queque.Add(queque); + queue.ID = texture.Index; + _Queue.Add(queue); _Textures[texture.Index] = texture; } return texture; @@ -1405,14 +1408,14 @@ namespace Vocaluxe.Lib.Draw } #endregion drawing - private void _CheckQueque() + private void _CheckQueue() { lock (_MutexTexture) { - if (_Queque.Count == 0) + if (_Queue.Count == 0) return; - STextureQueque q = _Queque[0]; + STextureQueue q = _Queue[0]; STexture texture; if (_Textures.ContainsKey(q.ID)) texture = _Textures[q.ID]; @@ -1423,7 +1426,7 @@ namespace Vocaluxe.Lib.Draw _D3DTextures[q.ID] = t; _Textures[texture.Index] = texture; - _Queque.RemoveAt(0); + _Queue.RemoveAt(0); } } diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 78203ff0..cb79cbc2 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -418,7 +418,7 @@ namespace Vocaluxe.Lib.Draw return new STexture(-1); } - public STexture QuequeTexture(int w, int h, ref byte[] data) + public STexture EnqueueTexture(int w, int h, ref byte[] data) { return AddTexture(w, h, ref data); } diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 54056001..13ee6f35 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -41,7 +41,7 @@ namespace Vocaluxe.Lib.Draw public int Height; }; - struct STextureQueque + struct STextureQueue { public int ID; public int Width; @@ -63,7 +63,7 @@ namespace Vocaluxe.Lib.Draw private readonly Dictionary _Textures; private readonly Queue _IDs; - private readonly List _Queque; + private readonly List _Queue; private readonly Object _MutexTexture = new Object(); @@ -80,7 +80,7 @@ namespace Vocaluxe.Lib.Draw Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon)); _Textures = new Dictionary(); - _Queque = new List(); + _Queue = new List(); _IDs = new Queue(1000000); for (int i = 1; i < 1000000; i++) @@ -412,15 +412,17 @@ namespace Vocaluxe.Lib.Draw if (_Run) { ClearScreen(); - _Run = _Run && CGraphics.Draw(); + if (!CGraphics.Draw()) + _Run = false; + if (!CGraphics.UpdateGameLogic(_Keys, _Mouse)) + _Run = false; - _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); _Control.SwapBuffers(); if ((CSettings.IsFullScreen && !_Fullscreen) || (!CSettings.IsFullScreen && _Fullscreen)) _ToggleFullScreen(); - _CheckQueque(); + _CheckQueue(); if (CTime.IsRunning()) delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); @@ -907,10 +909,10 @@ namespace Vocaluxe.Lib.Draw return texture; } - public STexture QuequeTexture(int w, int h, ref byte[] data) + public STexture EnqueueTexture(int w, int h, ref byte[] data) { STexture texture = new STexture(-1); - STextureQueque queque = new STextureQueque {Data = data, Height = h, Width = w}; + STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; texture.Height = h; texture.Width = w; @@ -918,8 +920,8 @@ namespace Vocaluxe.Lib.Draw lock (_MutexTexture) { texture.Index = _IDs.Dequeue(); - queque.ID = texture.Index; - _Queque.Add(queque); + queue.ID = texture.Index; + _Queue.Add(queue); _Textures[texture.Index] = texture; } @@ -1333,14 +1335,14 @@ namespace Vocaluxe.Lib.Draw return _Textures.Count; } - private void _CheckQueque() + private void _CheckQueue() { lock (_MutexTexture) { - if (_Queque.Count == 0) + if (_Queue.Count == 0) return; - STextureQueque q = _Queque[0]; + STextureQueue q = _Queue[0]; STexture texture = new STexture(-1); if (_Textures.ContainsKey(q.ID)) texture = _Textures[q.ID]; @@ -1407,7 +1409,7 @@ namespace Vocaluxe.Lib.Draw _Textures[texture.Index] = texture; q.Data = null; - _Queque.RemoveAt(0); + _Queue.RemoveAt(0); } } #endregion Textures diff --git a/Vocaluxe/Lib/Draw/IDraw.cs b/Vocaluxe/Lib/Draw/IDraw.cs index 6da270b0..1230145c 100644 --- a/Vocaluxe/Lib/Draw/IDraw.cs +++ b/Vocaluxe/Lib/Draw/IDraw.cs @@ -52,7 +52,7 @@ namespace Vocaluxe.Lib.Draw STexture AddTexture(Bitmap bitmap); STexture AddTexture(int w, int h, IntPtr data); STexture AddTexture(int w, int h, ref byte[] data); - STexture QuequeTexture(int w, int h, ref byte[] data); + STexture EnqueueTexture(int w, int h, ref byte[] data); bool UpdateTexture(ref STexture texture, ref byte[] data); bool UpdateTexture(ref STexture texture, IntPtr data); diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 119e5406..2a00110a 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -948,9 +948,9 @@ namespace Vocaluxe.Screens private void _UpdateMedleyCountdown() { - if (CGame.GetSong() != null) - { - CSong song = CGame.GetSong(); + CSong song = CGame.GetSong(); + if (song != null) + { float currentTime = _CurrentTime - song.Start; float timeToFirstMedleyNote = (CGame.GetTimeFromBeats(song.Medley.StartBeat, song.BPM) + song.Gap - song.Start); if (currentTime < timeToFirstMedleyNote && CGame.GameMode == EGameMode.TR_GAMEMODE_MEDLEY) diff --git a/Vocaluxe/SongQueue/CSongQueue.cs b/Vocaluxe/SongQueue/CSongQueue.cs index 0217fc47..30f6f509 100644 --- a/Vocaluxe/SongQueue/CSongQueue.cs +++ b/Vocaluxe/SongQueue/CSongQueue.cs @@ -39,22 +39,22 @@ namespace Vocaluxe.SongQueue class CSongQueue : ISongQueue { - private List _SongQueque; + private List _SongQueue; private int _CurrentSong; private CPoints _Points; #region Implementation public void Init() { - _SongQueque = new List(); + _SongQueue = new List(); Reset(); CGameModes.Init(); } public EGameMode GetCurrentGameMode() { - if (_CurrentSong >= 0 && _CurrentSong < _SongQueque.Count) - return _SongQueque[_CurrentSong].GameMode; + if (_CurrentSong >= 0 && _CurrentSong < _SongQueue.Count) + return _SongQueue[_CurrentSong].GameMode; return EGameMode.TR_GAMEMODE_NORMAL; } @@ -73,7 +73,7 @@ namespace Vocaluxe.SongQueue if (gameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(songID).IsDuet) return false; - _SongQueque.Add(new SSongQueueEntry(songID, gameMode)); + _SongQueue.Add(new SSongQueueEntry(songID, gameMode)); return true; } @@ -89,11 +89,11 @@ namespace Vocaluxe.SongQueue private bool _RemoveSong(int songID) { - for (int i = 0; i < _SongQueque.Count; i++) + for (int i = 0; i < _SongQueue.Count; i++) { - if (_SongQueque[i].SongID != songID) + if (_SongQueue[i].SongID != songID) continue; - _SongQueque.RemoveAt(i); + _SongQueue.RemoveAt(i); return true; } return false; @@ -101,7 +101,7 @@ namespace Vocaluxe.SongQueue public void ClearSongs() { - _SongQueque.Clear(); + _SongQueue.Clear(); } public void Reset() @@ -111,22 +111,22 @@ namespace Vocaluxe.SongQueue public void Start(SPlayer[] players) { - _Points = new CPoints(_SongQueque.Count, players); + _Points = new CPoints(_SongQueue.Count, players); } public void NextRound(SPlayer[] players) { - if (_CurrentSong < _SongQueque.Count && _SongQueque.Count > 0) + if (_CurrentSong < _SongQueue.Count && _SongQueue.Count > 0) { if (_CurrentSong > -1) { _Points.SetPoints( _CurrentSong, - _SongQueque[_CurrentSong].SongID, + _SongQueue[_CurrentSong].SongID, players, - _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_MEDLEY, - _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_DUET, - _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_SHORTSONG); + _SongQueue[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_MEDLEY, + _SongQueue[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_DUET, + _SongQueue[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_SHORTSONG); } _CurrentSong++; } @@ -134,7 +134,7 @@ namespace Vocaluxe.SongQueue public bool IsFinished() { - return _CurrentSong == _SongQueque.Count || _SongQueque.Count == 0; + return _CurrentSong == _SongQueue.Count || _SongQueue.Count == 0; } public int GetCurrentRoundNr() @@ -144,28 +144,28 @@ namespace Vocaluxe.SongQueue public CSong GetSong() { - if (_CurrentSong >= 0 && _CurrentSong < _SongQueque.Count) - CGameModes.Get(GetCurrentGameMode()).GetSong(_SongQueque[_CurrentSong].SongID); + if (_CurrentSong >= 0 && _CurrentSong < _SongQueue.Count) + CGameModes.Get(GetCurrentGameMode()).GetSong(_SongQueue[_CurrentSong].SongID); return null; } public int GetNumSongs() { - return _SongQueque.Count; + return _SongQueue.Count; } public CSong GetSong(int num) { - if (num - 1 < _SongQueque.Count && num > 0) - return CSongs.GetSong(_SongQueque[num - 1].SongID); + if (num - 1 < _SongQueue.Count && num > 0) + return CSongs.GetSong(_SongQueue[num - 1].SongID); return null; } public EGameMode GetGameMode(int num) { - if (num - 1 < _SongQueque.Count && num > 0) - return _SongQueque[num - 1].GameMode; + if (num - 1 < _SongQueue.Count && num > 0) + return _SongQueue[num - 1].GameMode; return EGameMode.TR_GAMEMODE_NORMAL; } From 5cea9e6775d55e2f265ddb1f29ae45641a03c400 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 28 Apr 2013 13:12:45 +0200 Subject: [PATCH 04/10] Added better playlist Open-Option Fixed Bug with GameModes --- Vocaluxe/GameModes/CGameMode.cs | 2 +- Vocaluxe/Screens/CScreenSong.cs | 35 ++++++++++++-------------------- Vocaluxe/SongQueue/CSongQueue.cs | 2 +- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Vocaluxe/GameModes/CGameMode.cs b/Vocaluxe/GameModes/CGameMode.cs index b14830cf..c246c3f0 100644 --- a/Vocaluxe/GameModes/CGameMode.cs +++ b/Vocaluxe/GameModes/CGameMode.cs @@ -6,7 +6,7 @@ namespace Vocaluxe.GameModes abstract class CGameMode : IGameMode { private CSong _LastSong; - private int _LastSongID; + private int _LastSongID = -1; public CSong GetSong(int songID) { diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 852e6ebb..6f0d83b7 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -338,7 +338,9 @@ namespace Vocaluxe.Screens else if (_Buttons[_ButtonOptionsOpenSelectedItem].Selected) _HandleSelectButton(); else if (_SelectSlides[_SelectSlideOptionsPlaylistOpen].Selected) - _OpenPlaylistAction(); + _OpenPlaylist(_SelectSlides[_SelectSlideOptionsPlaylistOpen].Selection); + else if (_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selected) + _OpenPlaylist(_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1); else if (_Buttons[_ButtonOptionsRandomMedley].Selected) _ToggleSongOptions(ESongOptionsView.Medley); else if (_Buttons[_ButtonOptionsStartMedley].Selected) @@ -515,7 +517,12 @@ namespace Vocaluxe.Screens } else if (_SelectSlides[_SelectSlideOptionsPlaylistOpen].ValueSelected) { - _OpenPlaylistAction(); + _OpenPlaylist(_SelectSlides[_SelectSlideOptionsPlaylistOpen].Selection); + return true; + } + else if (_SelectSlides[_SelectSlideOptionsPlaylistAdd].ValueSelected) + { + _OpenPlaylist(_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1); return true; } else if (_Buttons[_ButtonOptionsRandomMedley].Selected) @@ -832,15 +839,12 @@ namespace Vocaluxe.Screens { if ((CSongs.Category >= 0) && (songNr >= 0)) { - EGameMode gm; - if (CSongs.VisibleSongs[songNr].Medley.Source != EMedleySource.None) - gm = EGameMode.TR_GAMEMODE_MEDLEY; - else + if (CSongs.VisibleSongs[songNr].Medley.Source == EMedleySource.None) return; CGame.Reset(); CGame.ClearSongs(); - CGame.AddVisibleSong(songNr, gm); + CGame.AddVisibleSong(songNr, EGameMode.TR_GAMEMODE_MEDLEY); CGraphics.FadeTo(EScreens.ScreenNames); } @@ -1097,7 +1101,6 @@ namespace Vocaluxe.Screens EGameMode lastMode = EGameMode.TR_GAMEMODE_NORMAL; if (_AvailableGameModes.Count > 0) lastMode = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; - _SetInteractionToButton(_Buttons[_ButtonOptionsSing]); _AvailableGameModes.Clear(); _SelectSlides[_SelectSlideOptionsMode].Clear(); if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].IsDuet) @@ -1183,11 +1186,12 @@ namespace Vocaluxe.Screens private void _OpenPlaylist(int playlistID) { - if (CPlaylists.Playlists.Length > playlistID && playlistID > -1) + if (CPlaylists.Playlists.Length > playlistID && playlistID >= 0) { _Playlists[_Playlist].LoadPlaylist(playlistID); _SongMenus[_SongMenu].SetSmallView(true); _Playlists[_Playlist].Visible = true; + _SetSelectSlidePlaylistToCurrentPlaylist(); } } @@ -1212,19 +1216,6 @@ namespace Vocaluxe.Screens _SelectSlides[_SelectSlideOptionsPlaylistOpen].AddValues(CPlaylists.PlaylistNames); } - private void _OpenPlaylistAction() - { - //Open a playlist - if (_Playlists[_Playlist].ActivePlaylistID != _SelectSlides[_SelectSlideOptionsPlaylistOpen].Selection) - { - _Playlists[_Playlist].ActivePlaylistID = _SelectSlides[_SelectSlideOptionsPlaylistOpen].Selection; - _SetSelectSlidePlaylistToCurrentPlaylist(); - - //Open playlist - _OpenPlaylist(_Playlists[_Playlist].ActivePlaylistID); - } - } - private void _OpenAndAddPlaylistAction() { //Open an existing playlist and add song diff --git a/Vocaluxe/SongQueue/CSongQueue.cs b/Vocaluxe/SongQueue/CSongQueue.cs index 30f6f509..62a3814c 100644 --- a/Vocaluxe/SongQueue/CSongQueue.cs +++ b/Vocaluxe/SongQueue/CSongQueue.cs @@ -145,7 +145,7 @@ namespace Vocaluxe.SongQueue public CSong GetSong() { if (_CurrentSong >= 0 && _CurrentSong < _SongQueue.Count) - CGameModes.Get(GetCurrentGameMode()).GetSong(_SongQueue[_CurrentSong].SongID); + return CGameModes.Get(_SongQueue[_CurrentSong].GameMode).GetSong(_SongQueue[_CurrentSong].SongID); return null; } From 5bc9044d895ef9abb1dfbf9fc36a467dac26a824 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 28 Apr 2013 13:17:58 +0200 Subject: [PATCH 05/10] Bugfix for index check in Points calculation --- Vocaluxe/Base/CGame.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index 672ac815..58bc9c2d 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -247,7 +247,7 @@ namespace Vocaluxe.Base CNote[] notes = lines[line].Notes; int note = lines[line].FindPreviousNote(beat); - if (notes[note].EndBeat < beat) + if (note >= 0 && notes[note].EndBeat < beat) note = -1; if (note >= 0) From 6634e4081d514892fdc7edba1791cc9aec1aa6fe Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 28 Apr 2013 13:33:18 +0200 Subject: [PATCH 06/10] Some small optimizing to medley countdown --- Vocaluxe/Screens/CScreenSing.cs | 44 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 2a00110a..42eb3de7 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -450,8 +450,6 @@ namespace Vocaluxe.Screens { if (_Active) { - _UpdateMedleyCountdown(); - if (_CurrentVideo != -1 && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON && !_Webcam) { RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); @@ -517,7 +515,10 @@ namespace Vocaluxe.Screens _DrawLyricHelper(); if (CGame.GameMode == EGameMode.TR_GAMEMODE_MEDLEY) + { + _UpdateMedleyCountdown(); _Texts[_TextMedleyCountdown].Draw(); + } if (_Pause) { @@ -949,27 +950,26 @@ namespace Vocaluxe.Screens private void _UpdateMedleyCountdown() { CSong song = CGame.GetSong(); - if (song != null) - { - float currentTime = _CurrentTime - song.Start; - float timeToFirstMedleyNote = (CGame.GetTimeFromBeats(song.Medley.StartBeat, song.BPM) + song.Gap - song.Start); - if (currentTime < timeToFirstMedleyNote && CGame.GameMode == EGameMode.TR_GAMEMODE_MEDLEY) - { - float timeDiff = timeToFirstMedleyNote - currentTime + 1; - double t = timeDiff - Math.Truncate(timeDiff); - _Texts[_TextMedleyCountdown].Visible = true; - _Texts[_TextMedleyCountdown].Text = Math.Round((decimal)(timeDiff - t)).ToString(); - float h = (float)(t * CSettings.RenderH); - float w = CFonts.GetTextBounds(_Texts[_TextMedleyCountdown], h).Width; - float x = CSettings.RenderW / 2 - w / 2; - float y = CSettings.RenderH / 2 - h / 2; - _Texts[_TextMedleyCountdown].X = x; - _Texts[_TextMedleyCountdown].Y = y; - _Texts[_TextMedleyCountdown].Height = h; - } - else - _Texts[_TextMedleyCountdown].Visible = false; + if (song == null) + return; + float timeToFirstMedleyNote = CGame.GetTimeFromBeats(song.Medley.StartBeat, song.BPM) + song.Gap; + if (_CurrentTime < timeToFirstMedleyNote) + { + float timeDiff = timeToFirstMedleyNote - _CurrentTime + 1; + float fullSeconds = (float)Math.Truncate(timeDiff); + float partSeconds = timeDiff - fullSeconds; + _Texts[_TextMedleyCountdown].Visible = true; + _Texts[_TextMedleyCountdown].Text = fullSeconds.ToString(); + float h = partSeconds * CSettings.RenderH; + float w = CFonts.GetTextBounds(_Texts[_TextMedleyCountdown], h).Width; + float x = CSettings.RenderW / 2 - w / 2; + float y = CSettings.RenderH / 2 - h / 2; + _Texts[_TextMedleyCountdown].X = x; + _Texts[_TextMedleyCountdown].Y = y; + _Texts[_TextMedleyCountdown].Height = h; } + else + _Texts[_TextMedleyCountdown].Visible = false; } private void _DrawLyricHelper() From 2f3f121f887e549d66e90fa4049f5602deeef8d8 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 28 Apr 2013 14:02:27 +0200 Subject: [PATCH 07/10] Split Font-File --- Vocaluxe/Base/CGraphics.cs | 1 + Vocaluxe/Base/CMain.cs | 1 + Vocaluxe/Base/CTheme.cs | 1 + Vocaluxe/Base/Font/CFont.cs | 193 +++++++++++++ Vocaluxe/Base/{CFont.cs => Font/CFonts.cs} | 312 +-------------------- Vocaluxe/Base/Font/CGlyph.cs | 128 +++++++++ Vocaluxe/Lib/Draw/CDirect3D.cs | 1 + Vocaluxe/Lib/Draw/CDrawWinForm.cs | 1 + Vocaluxe/Lib/Draw/COpenGL.cs | 1 + Vocaluxe/Program.cs | 1 + Vocaluxe/Screens/CScreenMain.cs | 1 + Vocaluxe/Screens/CScreenOptionsTheme.cs | 1 + Vocaluxe/Screens/CScreenSing.cs | 5 +- Vocaluxe/Vocaluxe.csproj | 4 +- VocaluxeLib/Menu/CStatic.cs | 15 +- VocaluxeLib/Menu/CText.cs | 5 - 16 files changed, 343 insertions(+), 328 deletions(-) create mode 100644 Vocaluxe/Base/Font/CFont.cs rename Vocaluxe/Base/{CFont.cs => Font/CFonts.cs} (60%) create mode 100644 Vocaluxe/Base/Font/CGlyph.cs diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index b228a042..bab0a646 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; +using Vocaluxe.Base.Font; using Vocaluxe.Screens; using VocaluxeLib.Menu; using VocaluxeLib.PartyModes; diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 4e9b3521..84ee348e 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using Vocaluxe.Base.Font; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index c730d1d4..30ce2f20 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -23,6 +23,7 @@ using System.IO; using System.Text; using System.Windows.Forms; using System.Xml; +using Vocaluxe.Base.Font; using VocaluxeLib.Menu; namespace Vocaluxe.Base diff --git a/Vocaluxe/Base/Font/CFont.cs b/Vocaluxe/Base/Font/CFont.cs new file mode 100644 index 00000000..fb4fc0ee --- /dev/null +++ b/Vocaluxe/Base/Font/CFont.cs @@ -0,0 +1,193 @@ +#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 . +// */ +#endregion + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Text; +using VocaluxeLib.Menu; + +namespace Vocaluxe.Base.Font +{ + class CFont : IDisposable + { + private readonly Dictionary _Glyphs; + private PrivateFontCollection _Fonts; + private FontFamily _Family; + private readonly float _Sizeh; + + public readonly string FilePath; + + public CFont(string file) + { + FilePath = file; + + _Glyphs = new Dictionary(); + + switch (CConfig.TextureQuality) + { + case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST: + _Sizeh = 25f; + break; + case ETextureQuality.TR_CONFIG_TEXTURE_LOW: + _Sizeh = 50f; + break; + case ETextureQuality.TR_CONFIG_TEXTURE_MEDIUM: + _Sizeh = 100f; + break; + case ETextureQuality.TR_CONFIG_TEXTURE_HIGH: + _Sizeh = 200f; + break; + case ETextureQuality.TR_CONFIG_TEXTURE_HIGHEST: + _Sizeh = 400f; + break; + default: + _Sizeh = 100f; + break; + } + } + + public System.Drawing.Font GetFont() + { + if (_Fonts == null) + { + _Fonts = new PrivateFontCollection(); + try + { + _Fonts.AddFontFile(FilePath); + _Family = _Fonts.Families[0]; + } + catch (Exception e) + { + CLog.LogError("Error opening font file " + FilePath + ": " + e.Message); + } + } + + return new System.Drawing.Font(_Family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel); + } + + public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color) + { + STexture texture; + SRectF rect; + _GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect); + CDraw.DrawTexture(texture, rect, color); + } + + public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color, float begin, float end) + { + STexture texture; + SRectF rect; + _GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect); + CDraw.DrawTexture(texture, rect, color, begin, end); + } + + public void DrawGlyphReflection(char chr, float x, float y, float h, float z, SColorF color, float rspace, float rheight) + { + STexture texture; + SRectF rect; + _GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect); + CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight); + } + + private void _GetGlyphTextureAndRect(char chr, float x, float y, float z, float h, out STexture texture, out SRectF rect) + { + AddGlyph(chr); + + CFonts.Height = h; + CGlyph glyph = _Glyphs[chr]; + texture = glyph.Texture; + float factor = h / texture.Height; + float width = texture.Width * factor; + float d = glyph.Sizeh / 5f * factor; + rect = new SRectF(x - d, y, width, h, z); + } + + public float GetWidth(char chr) + { + AddGlyph(chr); + + CGlyph glyph = _Glyphs[chr]; + float factor = CFonts.Height / glyph.Texture.Height; + return glyph.Width * factor; + } + + public float GetHeight(char chr) + { + return CFonts.Height; + /*WTF??? + AddGlyph(chr); + + CGlyph glyph = _Glyphs[chr]; + float factor = CFonts.Height / glyph.Texture.height; + return glyph.Texture.height * factor;*/ + } + + public void AddGlyph(char chr) + { + if (_Glyphs.ContainsKey(chr)) + return; + + float h = CFonts.Height; + _Glyphs.Add(chr, new CGlyph(chr, _Sizeh)); + CFonts.Height = h; + } + + public void UnloadAllGlyphs() + { + foreach (CGlyph glyph in _Glyphs.Values) + glyph.UnloadTexture(); + _Glyphs.Clear(); + } + + public void Dispose() + { + if (_Fonts != null) + { + _Fonts.Dispose(); + _Fonts = null; + UnloadAllGlyphs(); + } + GC.SuppressFinalize(this); + } + } + + struct SFont + { + public string Name; + + public bool IsThemeFont; + public int PartyModeID; + public string ThemeName; + + public string Folder; + public string FileNormal; + public string FileItalic; + public string FileBold; + public string FileBoldItalic; + + public float Outline; //0..1, 0=not outline 1=100% outline + public SColorF OutlineColor; + + public CFont Normal; + public CFont Italic; + public CFont Bold; + public CFont BoldItalic; + } +} \ No newline at end of file diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/Font/CFonts.cs similarity index 60% rename from Vocaluxe/Base/CFont.cs rename to Vocaluxe/Base/Font/CFonts.cs index 7b9b8cf0..8012af02 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/Font/CFonts.cs @@ -1,321 +1,13 @@ -#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 . -// */ -#endregion - -using System; using System.Collections.Generic; using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Text; using System.IO; using System.Linq; using System.Text; -using System.Windows.Forms; using System.Xml; using VocaluxeLib.Menu; -namespace Vocaluxe.Base +namespace Vocaluxe.Base.Font { - class CGlyph - { - private readonly float _Sizeh = 50f; - public float Sizeh - { - get { return _Sizeh; } - } - - public STexture Texture; - public readonly int Width; - - public CGlyph(char chr, float maxHigh) - { - _Sizeh = maxHigh; - - float outline = CFonts.Outline; - const TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; - - float factor = _GetFactor(chr, flags); - CFonts.Height = Sizeh * factor; - Font fo; - Size sizeB; - SizeF size; - using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) - { - fo = CFonts.GetFont(); - sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); - - size = g.MeasureString(chr.ToString(), fo); - } - - using (Bitmap bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height)) - { - Graphics g = Graphics.FromImage(bmp); - g.Clear(Color.Transparent); - - g.SmoothingMode = SmoothingMode.AntiAlias; - g.InterpolationMode = InterpolationMode.HighQualityBicubic; - g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; - CFonts.Height = Sizeh; - fo = CFonts.GetFont(); - - PointF point = new PointF( - outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + Sizeh / 5f, - (sizeB.Height - size.Height - (size.Height + Sizeh / 4f) * (1f - factor)) / 2f); - - using (GraphicsPath path = new GraphicsPath()) - { - path.AddString( - chr.ToString(), - fo.FontFamily, - (int)fo.Style, - Sizeh, - point, - new StringFormat()); - - using (Pen pen = new Pen( - Color.FromArgb( - (int)CFonts.OutlineColor.A * 255, - (int)CFonts.OutlineColor.R * 255, - (int)CFonts.OutlineColor.G * 255, - (int)CFonts.OutlineColor.B * 255), - Sizeh * outline)) - { - pen.LineJoin = LineJoin.Round; - g.DrawPath(pen, path); - g.FillPath(Brushes.White, path); - } - } - - /* - g.DrawString( - chr.ToString(), - fo, - Brushes.White, - point); - * */ - Texture = CDraw.AddTexture(bmp); - //bmp.Save("test.png", ImageFormat.Png); - Width = (int)((1f + outline / 2f) * sizeB.Width * Texture.Width / factor / bmp.Width); - g.Dispose(); - } - fo.Dispose(); - } - - public void UnloadTexture() - { - CDraw.RemoveTexture(ref Texture); - } - - private float _GetFactor(char chr, TextFormatFlags flags) - { - if (CFonts.Style == EStyle.Normal) - return 1f; - - EStyle style = CFonts.Style; - - CFonts.Style = EStyle.Normal; - CFonts.Height = Sizeh; - float hStyle, hNormal; - using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) - { - Font fo = CFonts.GetFont(); - Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); - //SizeF size = g.MeasureString(chr.ToString(), fo); - hNormal = sizeB.Height; - } - CFonts.Style = style; - using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) - { - Font fo = CFonts.GetFont(); - Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); - //size = g.MeasureString(chr.ToString(), fo); - hStyle = sizeB.Height; - } - return hNormal / hStyle; - } - } - - class CFont : IDisposable - { - private readonly Dictionary _Glyphs; - private PrivateFontCollection _Fonts; - private FontFamily _Family; - private readonly float _Sizeh; - - public readonly string FilePath; - - public CFont(string file) - { - FilePath = file; - - _Glyphs = new Dictionary(); - - switch (CConfig.TextureQuality) - { - case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST: - _Sizeh = 25f; - break; - case ETextureQuality.TR_CONFIG_TEXTURE_LOW: - _Sizeh = 50f; - break; - case ETextureQuality.TR_CONFIG_TEXTURE_MEDIUM: - _Sizeh = 100f; - break; - case ETextureQuality.TR_CONFIG_TEXTURE_HIGH: - _Sizeh = 200f; - break; - case ETextureQuality.TR_CONFIG_TEXTURE_HIGHEST: - _Sizeh = 400f; - break; - default: - _Sizeh = 100f; - break; - } - } - - public Font GetFont() - { - if (_Fonts == null) - { - _Fonts = new PrivateFontCollection(); - try - { - _Fonts.AddFontFile(FilePath); - _Family = _Fonts.Families[0]; - } - catch (Exception e) - { - CLog.LogError("Error opening font file " + FilePath + ": " + e.Message); - } - } - - return new Font(_Family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel); - } - - public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color) - { - STexture texture; - SRectF rect; - _GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect); - CDraw.DrawTexture(texture, rect, color); - } - - public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color, float begin, float end) - { - STexture texture; - SRectF rect; - _GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect); - CDraw.DrawTexture(texture, rect, color, begin, end); - } - - public void DrawGlyphReflection(char chr, float x, float y, float h, float z, SColorF color, float rspace, float rheight) - { - STexture texture; - SRectF rect; - _GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect); - CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight); - } - - private void _GetGlyphTextureAndRect(char chr, float x, float y, float z, float h, out STexture texture, out SRectF rect) - { - AddGlyph(chr); - - CFonts.Height = h; - CGlyph glyph = _Glyphs[chr]; - texture = glyph.Texture; - float factor = h / texture.Height; - float width = texture.Width * factor; - float d = glyph.Sizeh / 5f * factor; - rect = new SRectF(x - d, y, width, h, z); - } - - public float GetWidth(char chr) - { - AddGlyph(chr); - - CGlyph glyph = _Glyphs[chr]; - float factor = CFonts.Height / glyph.Texture.Height; - return glyph.Width * factor; - } - - public float GetHeight(char chr) - { - return CFonts.Height; - /*WTF??? - AddGlyph(chr); - - CGlyph glyph = _Glyphs[chr]; - float factor = CFonts.Height / glyph.Texture.height; - return glyph.Texture.height * factor;*/ - } - - public void AddGlyph(char chr) - { - if (_Glyphs.ContainsKey(chr)) - return; - - float h = CFonts.Height; - _Glyphs.Add(chr, new CGlyph(chr, _Sizeh)); - CFonts.Height = h; - } - - public void UnloadAllGlyphs() - { - foreach (CGlyph glyph in _Glyphs.Values) - glyph.UnloadTexture(); - _Glyphs.Clear(); - } - - public void Dispose() - { - if (_Fonts != null) - { - _Fonts.Dispose(); - _Fonts = null; - UnloadAllGlyphs(); - } - GC.SuppressFinalize(this); - } - } - - struct SFont - { - public string Name; - - public bool IsThemeFont; - public int PartyModeID; - public string ThemeName; - - public string Folder; - public string FileNormal; - public string FileItalic; - public string FileBold; - public string FileBoldItalic; - - public float Outline; //0..1, 0=not outline 1=100% outline - public SColorF OutlineColor; - - public CFont Normal; - public CFont Italic; - public CFont Bold; - public CFont BoldItalic; - } - static class CFonts { private static readonly XmlWriterSettings _Settings = new XmlWriterSettings(); @@ -372,7 +64,7 @@ namespace Vocaluxe.Base _LoadFontList(); } - public static Font GetFont() + public static System.Drawing.Font GetFont() { return _GetCurrentFont().GetFont(); } diff --git a/Vocaluxe/Base/Font/CGlyph.cs b/Vocaluxe/Base/Font/CGlyph.cs new file mode 100644 index 00000000..0eb61054 --- /dev/null +++ b/Vocaluxe/Base/Font/CGlyph.cs @@ -0,0 +1,128 @@ +using System; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Drawing.Text; +using System.Windows.Forms; +using VocaluxeLib.Menu; + +namespace Vocaluxe.Base.Font +{ + class CGlyph + { + private readonly float _Sizeh = 50f; + public float Sizeh + { + get { return _Sizeh; } + } + + public STexture Texture; + public readonly int Width; + + public CGlyph(char chr, float maxHigh) + { + _Sizeh = maxHigh; + + float outline = CFonts.Outline; + const TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; + + float factor = _GetFactor(chr, flags); + CFonts.Height = Sizeh * factor; + System.Drawing.Font fo; + Size sizeB; + SizeF size; + using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) + { + fo = CFonts.GetFont(); + sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); + + size = g.MeasureString(chr.ToString(), fo); + } + + using (Bitmap bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height)) + { + Graphics g = Graphics.FromImage(bmp); + g.Clear(Color.Transparent); + + g.SmoothingMode = SmoothingMode.AntiAlias; + g.InterpolationMode = InterpolationMode.HighQualityBicubic; + g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; + CFonts.Height = Sizeh; + fo = CFonts.GetFont(); + + PointF point = new PointF( + outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + Sizeh / 5f, + (sizeB.Height - size.Height - (size.Height + Sizeh / 4f) * (1f - factor)) / 2f); + + using (GraphicsPath path = new GraphicsPath()) + { + path.AddString( + chr.ToString(), + fo.FontFamily, + (int)fo.Style, + Sizeh, + point, + new StringFormat()); + + using (Pen pen = new Pen( + Color.FromArgb( + (int)CFonts.OutlineColor.A * 255, + (int)CFonts.OutlineColor.R * 255, + (int)CFonts.OutlineColor.G * 255, + (int)CFonts.OutlineColor.B * 255), + Sizeh * outline)) + { + pen.LineJoin = LineJoin.Round; + g.DrawPath(pen, path); + g.FillPath(Brushes.White, path); + } + } + + /* + g.DrawString( + chr.ToString(), + fo, + Brushes.White, + point); + * */ + Texture = CDraw.AddTexture(bmp); + //bmp.Save("test.png", ImageFormat.Png); + Width = (int)((1f + outline / 2f) * sizeB.Width * Texture.Width / factor / bmp.Width); + g.Dispose(); + } + fo.Dispose(); + } + + public void UnloadTexture() + { + CDraw.RemoveTexture(ref Texture); + } + + private float _GetFactor(char chr, TextFormatFlags flags) + { + if (CFonts.Style == EStyle.Normal) + return 1f; + + EStyle style = CFonts.Style; + + CFonts.Style = EStyle.Normal; + CFonts.Height = Sizeh; + float hStyle, hNormal; + using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) + { + System.Drawing.Font fo = CFonts.GetFont(); + Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); + //SizeF size = g.MeasureString(chr.ToString(), fo); + hNormal = sizeB.Height; + } + CFonts.Style = style; + using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) + { + System.Drawing.Font fo = CFonts.GetFont(); + Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); + //size = g.MeasureString(chr.ToString(), fo); + hStyle = sizeB.Height; + } + return hNormal / hStyle; + } + } +} \ No newline at end of file diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 7a084bca..1d4974d2 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -31,6 +31,7 @@ using System.Runtime.InteropServices; using System.Windows.Forms; using SlimDX.Windows; using Vocaluxe.Base; +using Vocaluxe.Base.Font; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Draw diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index cb79cbc2..55a26fe5 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -27,6 +27,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; using Vocaluxe.Base; +using Vocaluxe.Base.Font; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Draw diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 13ee6f35..87042f2d 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -30,6 +30,7 @@ using System.IO; using System.Runtime.InteropServices; using System.Windows.Forms; using Vocaluxe.Base; +using Vocaluxe.Base.Font; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Draw diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index 34c5f627..04c0b881 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -25,6 +25,7 @@ using System.Reflection; using System.Windows.Forms; using Vocaluxe.Base; using System.Runtime.ExceptionServices; +using Vocaluxe.Base.Font; namespace Vocaluxe { diff --git a/Vocaluxe/Screens/CScreenMain.cs b/Vocaluxe/Screens/CScreenMain.cs index 807ec508..977cb417 100644 --- a/Vocaluxe/Screens/CScreenMain.cs +++ b/Vocaluxe/Screens/CScreenMain.cs @@ -19,6 +19,7 @@ using System.Windows.Forms; using Vocaluxe.Base; +using Vocaluxe.Base.Font; using VocaluxeLib.Menu; namespace Vocaluxe.Screens diff --git a/Vocaluxe/Screens/CScreenOptionsTheme.cs b/Vocaluxe/Screens/CScreenOptionsTheme.cs index 5beca6e7..1ba85dd1 100644 --- a/Vocaluxe/Screens/CScreenOptionsTheme.cs +++ b/Vocaluxe/Screens/CScreenOptionsTheme.cs @@ -20,6 +20,7 @@ using System; using System.Windows.Forms; using Vocaluxe.Base; +using Vocaluxe.Base.Font; using VocaluxeLib.Menu; namespace Vocaluxe.Screens diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 42eb3de7..21aff197 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -25,6 +25,7 @@ using System.IO; using System.Linq; using System.Windows.Forms; using Vocaluxe.Base; +using Vocaluxe.Base.Font; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SingNotes; using VocaluxeLib.Menu.SongMenu; @@ -522,8 +523,8 @@ namespace Vocaluxe.Screens if (_Pause) { - _Statics[_StaticPauseBG].ForceDraw(); - _Texts[_TextPause].ForceDraw(); + _Statics[_StaticPauseBG].Draw(true); + _Texts[_TextPause].Draw(true); foreach (CButton button in _Buttons) button.Draw(); diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index e77012f6..1d1164c9 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -176,7 +176,7 @@ - + @@ -195,6 +195,8 @@ + + Form diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index 78827930..8dfa8d07 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -221,27 +221,22 @@ namespace VocaluxeLib.Menu return false; } - public void Draw() + public void Draw(bool forceDraw = false) { - Draw(1f, Rect.Z, Aspect, false); + Draw(1f, Rect.Z, Aspect, forceDraw); } public void Draw(EAspect aspect) { - Draw(1f, Rect.Z, aspect, false); + Draw(1f, Rect.Z, aspect); } public void Draw(float scale, EAspect aspect) { - Draw(scale, Rect.Z, aspect, false); + Draw(scale, Rect.Z, aspect); } - public void ForceDraw() - { - Draw(1f, Rect.Z, Aspect, true); - } - - public void Draw(float scale, float z, EAspect aspect, bool forceDraw) + public void Draw(float scale, float z, EAspect aspect, bool forceDraw = false) { STexture texture = _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); diff --git a/VocaluxeLib/Menu/CText.cs b/VocaluxeLib/Menu/CText.cs index ea864d79..c164bfba 100644 --- a/VocaluxeLib/Menu/CText.cs +++ b/VocaluxeLib/Menu/CText.cs @@ -601,11 +601,6 @@ namespace VocaluxeLib.Menu return false; } - public void ForceDraw() - { - Draw(true); - } - public void Draw(bool forceDraw = false) { if (!forceDraw && !Visible && CBase.Settings.GetGameState() != EGameState.EditTheme) From 3956fa17d104d8afc90fc1f8510d913a86240e41 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 28 Apr 2013 14:25:49 +0200 Subject: [PATCH 08/10] Small Font fixes --- Vocaluxe/Base/Font/CFonts.cs | 62 ++++++++++++------------------------ Vocaluxe/Base/Font/CGlyph.cs | 11 +++---- 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/Vocaluxe/Base/Font/CFonts.cs b/Vocaluxe/Base/Font/CFonts.cs index 8012af02..85d7fde3 100644 --- a/Vocaluxe/Base/Font/CFonts.cs +++ b/Vocaluxe/Base/Font/CFonts.cs @@ -20,15 +20,6 @@ namespace Vocaluxe.Base.Font public static EStyle Style = EStyle.Normal; - public static int CurrentFont - { - get { return _CurrentFont; } - set - { - if ((value >= 0) && (value < _Fonts.Count)) - _CurrentFont = value; - } - } public static float Height { get { return _Height; } @@ -196,35 +187,13 @@ namespace Vocaluxe.Base.Font public static void SetFont(string fontName) { - int index; - - if (PartyModeID != -1) - { - index = _GetFontIndexParty(PartyModeID, fontName); - - if (index >= 0 && index < _Fonts.Count) - { - _CurrentFont = index; - return; - } - } - - index = _GetFontIndex(CConfig.Theme, fontName); - - if (index >= 0 && index < _Fonts.Count) - { + int index = _GetPartyFontIndex(PartyModeID, fontName); + if (index < 0) + index = _GetThemeFontIndex(CConfig.Theme, fontName); + if (index < 0) + index = _GetFontIndex(fontName); + if (index >= 0) _CurrentFont = index; - return; - } - - for (int i = 0; i < _Fonts.Count; i++) - { - if (!_Fonts[i].IsThemeFont && _Fonts[i].Name == fontName) - { - _CurrentFont = i; - return; - } - } } public static RectangleF GetTextBounds(CText text) @@ -420,7 +389,18 @@ namespace Vocaluxe.Base.Font } } - private static int _GetFontIndex(string themeName, string fontName) + private static int _GetFontIndex(string fontName) + { + for (int i = 0; i < _Fonts.Count; i++) + { + if (!_Fonts[i].IsThemeFont && _Fonts[i].Name == fontName) + return i; + } + + return -1; + } + + private static int _GetThemeFontIndex(string themeName, string fontName) { if (themeName == "" || fontName == "") return -1; @@ -434,14 +414,14 @@ namespace Vocaluxe.Base.Font return -1; } - private static int _GetFontIndexParty(int partyModeID, string fontName) + private static int _GetPartyFontIndex(int partyModeID, string fontName) { if (partyModeID == -1 || fontName == "") return -1; for (int i = 0; i < _Fonts.Count; i++) { - if (!_Fonts[i].IsThemeFont && _Fonts[i].Name == fontName && _Fonts[i].PartyModeID == partyModeID) + if (!_Fonts[i].IsThemeFont && _Fonts[i].PartyModeID == partyModeID && _Fonts[i].Name == fontName) return i; } @@ -454,7 +434,7 @@ namespace Vocaluxe.Base.Font for (int i = 0; i < _Fonts.Count; i++) { - CurrentFont = i; + _CurrentFont = i; foreach (char chr in text) { diff --git a/Vocaluxe/Base/Font/CGlyph.cs b/Vocaluxe/Base/Font/CGlyph.cs index 0eb61054..56ac78cd 100644 --- a/Vocaluxe/Base/Font/CGlyph.cs +++ b/Vocaluxe/Base/Font/CGlyph.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; +using System.Drawing.Imaging; using System.Drawing.Text; using System.Windows.Forms; using VocaluxeLib.Menu; @@ -9,18 +10,14 @@ namespace Vocaluxe.Base.Font { class CGlyph { - private readonly float _Sizeh = 50f; - public float Sizeh - { - get { return _Sizeh; } - } + public float Sizeh { get; private set; } public STexture Texture; public readonly int Width; public CGlyph(char chr, float maxHigh) { - _Sizeh = maxHigh; + Sizeh = maxHigh; float outline = CFonts.Outline; const TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; @@ -85,7 +82,7 @@ namespace Vocaluxe.Base.Font point); * */ Texture = CDraw.AddTexture(bmp); - //bmp.Save("test.png", ImageFormat.Png); + bmp.Save("font/" + chr + CFonts.Style + ".png", ImageFormat.Png); Width = (int)((1f + outline / 2f) * sizeB.Width * Texture.Width / factor / bmp.Width); g.Dispose(); } From 5172f17da7ae7bf8183f8ae2d2cd7baa6136054d Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 28 Apr 2013 17:19:22 +0200 Subject: [PATCH 09/10] Fixed and changed category handling and visible songs --- .../PartyModeChallenge/CPartyModeChallenge.cs | 2 +- .../CPartyModeChallengeMedley.cs | 26 ++- .../PartyModeTicTacToe/CPartyModeTicTacToe.cs | 2 +- Vocaluxe/Base/CGraphics.cs | 2 +- Vocaluxe/Base/CMain.cs | 15 +- Vocaluxe/Base/CPlaylists.cs | 2 +- Vocaluxe/Base/CSongCategorizer.cs | 73 ++++---- Vocaluxe/Base/CSongSorter.cs | 22 +-- Vocaluxe/Base/CSongs.cs | 173 +++++------------- Vocaluxe/Base/Font/CGlyph.cs | 2 +- Vocaluxe/Lib/Playlist/CPlaylistFile.cs | 3 +- Vocaluxe/Screens/CScreenOptionsTheme.cs | 5 - Vocaluxe/Screens/CScreenSong.cs | 71 +++---- Vocaluxe/SongQueue/CSongQueue.cs | 8 +- VocaluxeLib/Menu/IMenu.cs | 9 +- VocaluxeLib/Menu/SongMenu/CSong.cs | 80 ++------ VocaluxeLib/Menu/SongMenu/CSongMenu.cs | 6 - .../Menu/SongMenu/CSongMenuFramework.cs | 6 +- .../Menu/SongMenu/CSongMenuTileBoard.cs | 17 +- VocaluxeLib/VocaluxeLib.csproj | 1 + 20 files changed, 189 insertions(+), 336 deletions(-) diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index 8479323b..29ca14c1 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -308,7 +308,7 @@ namespace VocaluxeLib.PartyModes.Challenge _Screens.TryGetValue("CPartyScreenChallengeMain", out screen); if (screen != null) { - CBase.Songs.ResetPartySongSung(); + CBase.Songs.ResetSongSung(); _ToScreenMain.ResultTable = new List(); _GameData.ResultTable = new List(); _GameData.Rounds = new CChallengeRounds(_GameData.NumRounds, _GameData.NumPlayer, _GameData.NumPlayerAtOnce); diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index cd0e61f3..0803558d 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -187,14 +187,11 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { _Stage = EStage.NotStarted; - _ScreenSongOptions.Sorting.IgnoreArticles = CBase.Config.GetIgnoreArticles(); - _ScreenSongOptions.Sorting.SongSorting = CBase.Config.GetSongSorting(); + _ScreenSongOptions.Sorting.IgnoreArticles = EOffOn.TR_CONFIG_OFF; + _ScreenSongOptions.Sorting.SongSorting = ESongSorting.TR_CONFIG_NONE; _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_OFF; _ScreenSongOptions.Selection.SongIndex = -1; - if (CBase.Config.GetTabs() == EOffOn.TR_CONFIG_ON && _ScreenSongOptions.Sorting.SongSorting != ESongSorting.TR_CONFIG_NONE) - _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON; - _ToScreenMain.ResultTable = new List(); _GameData.ResultTable = new List(); @@ -313,7 +310,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _Screens.TryGetValue("CPartyScreenChallengeMedleyMain", out screen); if (screen != null) { - CBase.Songs.ResetPartySongSung(); + CBase.Songs.ResetSongSung(); _ToScreenMain.ResultTable = new List(); _GameData.ResultTable = new List(); _GameData.Rounds = new CChallengeRounds(_GameData.NumRounds, _GameData.NumPlayer, _GameData.NumPlayerAtOnce); @@ -502,26 +499,25 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley #endregion PlayerNames #region SongQueue - if (CBase.Songs.GetNumVisibleSongs() < _NumSongs) - CBase.Songs.ResetPartySongSung(); + if (CBase.Songs.GetNumSongsVisible() < _NumSongs) + CBase.Songs.ResetSongSung(); - const EGameMode gm = EGameMode.TR_GAMEMODE_MEDLEY; List ids = new List(); - CSong[] visSongs = CBase.Songs.GetSongsNotSung(); - if (visSongs == null) + var visibleSongs = CBase.Songs.GetVisibleSongs(); + if (visibleSongs.Count == 0) { CBase.Log.LogError("CPartyChallengeMedleyMode Error: There are no songs!"); CBase.Graphics.FadeTo(EScreens.ScreenParty); return false; } - for (int i = 0; i < visSongs.Length; i++) + foreach (CSong song in visibleSongs) { - foreach (EGameMode mode in visSongs[i].AvailableGameModes) + foreach (EGameMode mode in song.AvailableGameModes) { if (mode == EGameMode.TR_GAMEMODE_MEDLEY) - ids.Add(visSongs[i].ID); + ids.Add(song.ID); } } @@ -536,7 +532,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley while (s < _NumSongs && ids.Count > 0) { int songID = ids[CBase.Game.GetRandom(ids.Count)]; - CBase.Game.AddSong(songID, gm); + CBase.Game.AddSong(songID, EGameMode.TR_GAMEMODE_MEDLEY); CBase.Songs.AddPartySongSung(songID); ids.Remove(songID); s++; diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 21e9f455..649cce67 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -374,7 +374,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe if (screen != null) { _GameData.Team = _GameData.Team == 1 ? 0 : 1; - CBase.Songs.ResetPartySongSung(); + CBase.Songs.ResetSongSung(); _GameData.CurrentRoundNr = 1; _ToScreenMain.CurrentRoundNr = 1; _ToScreenMain.NumFields = _GameData.NumFields; diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index bab0a646..23e0c7ec 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -505,7 +505,7 @@ namespace Vocaluxe.Base bool popupVolumeControlAllowed = _CurrentScreen != EScreens.ScreenCredits && _CurrentScreen != EScreens.ScreenOptionsRecord; //Hide volume control for bg-music if bg-music is disabled - if (popupVolumeControlAllowed && (_CurrentScreen != EScreens.ScreenSong || (_CurrentScreen == EScreens.ScreenSong && CSongs.Category == -1)) + if (popupVolumeControlAllowed && (_CurrentScreen != EScreens.ScreenSong || CSongs.Category == -1) && _CurrentScreen != EScreens.ScreenSing && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) popupVolumeControlAllowed = false; diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 84ee348e..6b3781a8 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Drawing; using Vocaluxe.Base.Font; using VocaluxeLib.Menu; @@ -568,9 +569,9 @@ namespace Vocaluxe.Base return CSongs.NumAllSongs; } - public int GetNumVisibleSongs() + public int GetNumSongsVisible() { - return CSongs.NumVisibleSongs; + return CSongs.NumSongsVisible; } public int GetNumCategories() @@ -618,14 +619,14 @@ namespace Vocaluxe.Base return CSongs.GetSong(songID); } - public CSong[] GetSongs() + public ReadOnlyCollection GetSongs() { return CSongs.AllSongs; } - public CSong[] GetSongsNotSung() + public ReadOnlyCollection GetVisibleSongs() { - return CSongs.SongsNotSung; + return CSongs.VisibleSongs; } public CCategory GetCategory(int index) @@ -641,12 +642,12 @@ namespace Vocaluxe.Base CSongs.AddPartySongSung(songID); } - public void ResetPartySongSung() + public void ResetSongSung() { CSongs.ResetPartySongSung(); } - public void ResetPartySongSung(int catIndex) + public void ResetSongSung(int catIndex) { CSongs.ResetPartySongSung(catIndex); } diff --git a/Vocaluxe/Base/CPlaylists.cs b/Vocaluxe/Base/CPlaylists.cs index a740bc97..ca3e8e34 100644 --- a/Vocaluxe/Base/CPlaylists.cs +++ b/Vocaluxe/Base/CPlaylists.cs @@ -223,7 +223,7 @@ namespace Vocaluxe.Base private static CPlaylistFile _ConvertUSDXPlaylist(string file) { CPlaylistFile pl = new CPlaylistFile(); - CSong[] allSongs = CSongs.AllSongs; + var allSongs = CSongs.AllSongs; if (!File.Exists(file)) return null; diff --git a/Vocaluxe/Base/CSongCategorizer.cs b/Vocaluxe/Base/CSongCategorizer.cs index a9aedb6b..3e4e4706 100644 --- a/Vocaluxe/Base/CSongCategorizer.cs +++ b/Vocaluxe/Base/CSongCategorizer.cs @@ -32,7 +32,7 @@ namespace Vocaluxe.Base public CSongCategorizer() { - CSongs.Filter.ObjectChanged += _HandleSortedSongsChanged; + CSongs.Sorter.ObjectChanged += _HandleSortedSongsChanged; } public List Categories @@ -49,11 +49,10 @@ namespace Vocaluxe.Base get { return _Tabs; } set { - if (value != _Tabs) - { - _Tabs = value; - _SetChanged(); - } + if (value == _Tabs) + return; + _Tabs = value; + _SetChanged(); } } @@ -64,58 +63,55 @@ namespace Vocaluxe.Base private void _CreateCategoriesLetter() { - string category = ""; - int notLetterCat = -1; + CCategory lastCategory = null; + CCategory notLetterCat = null; for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++) { Char firstLetter = Char.ToUpper(CSongs.Sorter.SortedSongs[i].SortString.Normalize(NormalizationForm.FormD)[0]); - - if (!Char.IsLetter(firstLetter)) - firstLetter = '#'; - if (firstLetter.ToString() != category) + if (Char.IsLetter(firstLetter)) { - if (firstLetter != '#' || notLetterCat == -1) + if (lastCategory == null || CSongs.Sorter.SortedSongs[i].SortString != lastCategory.Name) { - category = firstLetter.ToString(); - _Categories.Add(new CCategory(category)); - - CSongs.Sorter.SortedSongs[i].CatIndex = _Categories.Count - 1; - - if (firstLetter == '#') - notLetterCat = CSongs.Sorter.SortedSongs[i].CatIndex; + lastCategory = new CCategory(CSongs.Sorter.SortedSongs[i].SortString); + _Categories.Add(lastCategory); } - else - CSongs.Sorter.SortedSongs[i].CatIndex = notLetterCat; + lastCategory.Songs.Add(CSongs.Sorter.SortedSongs[i]); } else - CSongs.Sorter.SortedSongs[i].CatIndex = _Categories.Count - 1; + { + if (notLetterCat == null) + { + notLetterCat = new CCategory("#"); + _Categories.Add(notLetterCat); + } + notLetterCat.Songs.Add(CSongs.Sorter.SortedSongs[i]); + } } } private void _CreateCategoriesNormal(string noCategoryName) { - string category = ""; - int noCategoryIndex = -1; + CCategory lastCategory = null; + CCategory noCategory = null; for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++) { if (CSongs.Sorter.SortedSongs[i].SortString != "") { - if (CSongs.Sorter.SortedSongs[i].SortString != category) + if (lastCategory == null || CSongs.Sorter.SortedSongs[i].SortString != lastCategory.Name) { - category = CSongs.Sorter.SortedSongs[i].SortString; - _Categories.Add(new CCategory(category)); + lastCategory = new CCategory(CSongs.Sorter.SortedSongs[i].SortString); + _Categories.Add(lastCategory); } - CSongs.Sorter.SortedSongs[i].CatIndex = _Categories.Count - 1; + lastCategory.Songs.Add(CSongs.Sorter.SortedSongs[i]); } else { - if (noCategoryIndex < 0) + if (noCategory == null) { - category = noCategoryName; - _Categories.Add(new CCategory(category)); - noCategoryIndex = _Categories.Count - 1; + noCategory = new CCategory(noCategoryName); + _Categories.Add(noCategory); } - CSongs.Sorter.SortedSongs[i].CatIndex = noCategoryIndex; + noCategory.Songs.Add(CSongs.Sorter.SortedSongs[i]); } } } @@ -172,15 +168,14 @@ namespace Vocaluxe.Base _Categories.Clear(); - if (_Tabs == EOffOn.TR_CONFIG_OFF) + if (_Tabs != EOffOn.TR_CONFIG_OFF) + _CreateCategories(); + else { //No categories. So don't create them! _Categories.Add(new CCategory("")); - for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++) - CSongs.Sorter.SortedSongs[i].CatIndex = 0; + _Categories[0].Songs.AddRange(CSongs.Sorter.SortedSongs); } - else - _CreateCategories(); foreach (CCategory cat in _Categories) cat.CoverTextureSmall = CCover.Cover(cat.Name); diff --git a/Vocaluxe/Base/CSongSorter.cs b/Vocaluxe/Base/CSongSorter.cs index 6d10957b..743f9506 100644 --- a/Vocaluxe/Base/CSongSorter.cs +++ b/Vocaluxe/Base/CSongSorter.cs @@ -27,7 +27,7 @@ namespace Vocaluxe.Base { class CSongSorter : CObservable { - private SSongPointer[] _SortedSongs = new SSongPointer[0]; + private CSongPointer[] _SortedSongs = new CSongPointer[0]; private EOffOn _IgnoreArticles = CConfig.IgnoreArticles; private ESongSorting _SongSorting = CConfig.SongSorting; @@ -36,7 +36,7 @@ namespace Vocaluxe.Base CSongs.Filter.ObjectChanged += _HandleFilteredSongsChanged; } - public SSongPointer[] SortedSongs + public CSongPointer[] SortedSongs { get { @@ -84,7 +84,7 @@ namespace Vocaluxe.Base _SetChanged(); } - private int _SortByFieldArtistTitle(SSongPointer s1, SSongPointer s2) + private int _SortByFieldArtistTitle(CSongPointer s1, CSongPointer s2) { int res = String.Compare(s1.SortString, s2.SortString, StringComparison.OrdinalIgnoreCase); if (res == 0) @@ -100,7 +100,7 @@ namespace Vocaluxe.Base return res; } - private int _SortByFieldTitle(SSongPointer s1, SSongPointer s2) + private int _SortByFieldTitle(CSongPointer s1, CSongPointer s2) { int res = String.Compare(s1.SortString, s2.SortString, StringComparison.OrdinalIgnoreCase); if (res == 0) @@ -112,11 +112,11 @@ namespace Vocaluxe.Base return res; } - private List _CreateSortList(string fieldName) + private List _CreateSortList(string fieldName) { - List sortList = new List(); + List sortList = new List(); if (fieldName == "") - CSongs.Filter.FilteredSongs.ForEach(song => sortList.Add(new SSongPointer(song.ID, ""))); + CSongs.Filter.FilteredSongs.ForEach(song => sortList.Add(new CSongPointer(song.ID, ""))); else { FieldInfo field = typeof(CSong).GetField(fieldName, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); @@ -132,16 +132,16 @@ namespace Vocaluxe.Base { object value = field.GetValue(song); if (isString) - sortList.Add(new SSongPointer(song.ID, (String)value)); + sortList.Add(new CSongPointer(song.ID, (String)value)); else { List values = (List)value; if (values.Count == 0) - sortList.Add(new SSongPointer(song.ID, "")); + sortList.Add(new CSongPointer(song.ID, "")); else { foreach (String sortString in values) - sortList.Add(new SSongPointer(song.ID, sortString)); + sortList.Add(new CSongPointer(song.ID, sortString)); } } } @@ -183,7 +183,7 @@ namespace Vocaluxe.Base fieldName = ""; break; } - List sortList = _CreateSortList(fieldName); + List sortList = _CreateSortList(fieldName); switch (_SongSorting) { case ESongSorting.TR_CONFIG_ARTIST_LETTER: diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index c498eafb..b52dbd36 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Threading; using VocaluxeLib.Menu; @@ -26,31 +27,11 @@ using VocaluxeLib.Menu.SongMenu; namespace Vocaluxe.Base { - public struct SSongPointer - { - public readonly int SongID; - public string SortString; - - public int CatIndex; - public bool Visible; - public bool PartyHidden; - - public SSongPointer(int id, string sortString) - { - SongID = id; - SortString = sortString; - CatIndex = -1; - Visible = false; - PartyHidden = false; - } - } - static class CSongs { private static readonly List _Songs = new List(); private static readonly List _SongsForRandom = new List(); - private static bool _SongsLoaded; private static bool _CoverLoaded; private static int _CatIndex = -1; private static readonly List _CategoriesForRandom = new List(); @@ -66,16 +47,13 @@ namespace Vocaluxe.Base get { return _Songs; } } - public static bool SongsLoaded - { - get { return _SongsLoaded; } - } + public static bool SongsLoaded { get; private set; } public static bool CoverLoaded { get { - if (_SongsLoaded && NumAllSongs == 0) + if (SongsLoaded && NumAllSongs == 0) _CoverLoaded = true; return _CoverLoaded; } @@ -86,14 +64,14 @@ namespace Vocaluxe.Base get { return _Songs.Count; } } - public static int NumVisibleSongs + public static int NumSongsVisible { - get { return Sorter.SortedSongs.Count(sp => sp.Visible); } + get { return _CatIndex < 0 ? 0 : Categories[_CatIndex].Songs.Count(sp => !sp.IsSung); } } public static int NumCategories { - get { return Categorizer.Categories.Count; } + get { return Categories.Count; } } public static int Category @@ -101,13 +79,8 @@ namespace Vocaluxe.Base get { return _CatIndex; } set { - if (value >= -1 && value < Categorizer.Categories.Count) - { + if (value == -1 || IsCatIndexValid(value)) _CatIndex = value; - - for (int i = 0; i < Sorter.SortedSongs.Length; i++) - Sorter.SortedSongs[i].Visible = Sorter.SortedSongs[i].CatIndex == _CatIndex && !Sorter.SortedSongs[i].PartyHidden; - } } } @@ -116,6 +89,11 @@ namespace Vocaluxe.Base get { return _CatIndex >= 0; } } + private static bool IsCatIndexValid(int catIndex) + { + return catIndex >= 0 && catIndex < Categories.Count; + } + /// /// Returns the number of song in the category specified with CatIndex /// @@ -123,21 +101,12 @@ namespace Vocaluxe.Base /// public static int NumSongsInCategory(int catIndex) { - if (Categorizer.Categories.Count <= catIndex || catIndex < 0) - return 0; - - int num = 0; - for (int i = 0; i < Sorter.SortedSongs.Length; i++) - { - if (Sorter.SortedSongs[i].CatIndex == catIndex && !Sorter.SortedSongs[i].PartyHidden) - num++; - } - return num; + return IsCatIndexValid(catIndex) ? Categories[catIndex].Songs.Count(sp => !sp.IsSung) : 0; } public static void NextCategory() { - if (Category == Categorizer.Categories.Count - 1) + if (Category == Categories.Count - 1) Category = 0; else Category++; @@ -146,7 +115,7 @@ namespace Vocaluxe.Base public static void PrevCategory() { if (Category == 0) - Category = Categorizer.Categories.Count - 1; + Category = Categories.Count - 1; else Category--; } @@ -168,29 +137,9 @@ namespace Vocaluxe.Base public static int NumSongsWithCoverLoaded { get; private set; } - public static void SetCoverSmall(int songIndex, STexture texture) - { - if (!_SongsLoaded) - return; - - if (songIndex < _Songs.Count) - _Songs[songIndex].CoverTextureSmall = texture; - } - - public static void SetCoverBig(int songIndex, STexture texture) - { - if (!_SongsLoaded) - return; - - if (songIndex < _Songs.Count) - _Songs[songIndex].CoverTextureBig = texture; - } - public static string GetCurrentCategoryName() { - if ((Categorizer.Categories.Count > 0) && (_CatIndex >= 0) && (Categorizer.Categories.Count > _CatIndex)) - return Categorizer.Categories[_CatIndex].Name; - return String.Empty; + return IsCatIndexValid(_CatIndex) ? Categories[_CatIndex].Name : ""; } public static CSong GetSong(int songID) @@ -200,43 +149,31 @@ namespace Vocaluxe.Base public static void AddPartySongSung(int songID) { - int cat = -1; - for (int i = 0; i < Sorter.SortedSongs.Length; i++) + foreach (CCategory category in Categories) { - if (songID == Sorter.SortedSongs[i].SongID) + foreach (CSongPointer song in category.Songs.Where(song => song.SongID == songID)) { - Sorter.SortedSongs[i].PartyHidden = true; - Sorter.SortedSongs[i].Visible = false; - cat = Sorter.SortedSongs[i].CatIndex; - break; + song.IsSung = true; + int catIndex = _GetCategoryNumber(category); + if (NumSongsInCategory(catIndex) == 0) + ResetPartySongSung(catIndex); + return; } } - - if (cat != -1) - { - if (NumSongsInCategory(cat) == 0) - ResetPartySongSung(cat); - } } public static void ResetPartySongSung() { - for (int i = 0; i < Sorter.SortedSongs.Length; i++) - { - Sorter.SortedSongs[i].PartyHidden = false; - Sorter.SortedSongs[i].Visible = Sorter.SortedSongs[i].CatIndex == _CatIndex && !Sorter.SortedSongs[i].PartyHidden; - } + foreach (CSongPointer song in Sorter.SortedSongs) + song.IsSung = false; } public static void ResetPartySongSung(int catIndex) { - for (int i = 0; i < Sorter.SortedSongs.Length; i++) + if (IsCatIndexValid(catIndex)) { - if (Sorter.SortedSongs[i].CatIndex == catIndex) - { - Sorter.SortedSongs[i].PartyHidden = false; - Sorter.SortedSongs[i].Visible = Sorter.SortedSongs[i].CatIndex == _CatIndex && !Sorter.SortedSongs[i].PartyHidden; - } + foreach (CSongPointer song in Categories[catIndex].Songs) + song.IsSung = false; } } @@ -292,7 +229,7 @@ namespace Vocaluxe.Base private static int _GetCategoryNumber(CCategory category) { - for (int i = 0; i < Categories.Length; i++) + for (int i = 0; i < Categories.Count; i++) { if (Categories[i] == category) return i; @@ -300,59 +237,39 @@ namespace Vocaluxe.Base return -1; } - public static CSong[] AllSongs + public static ReadOnlyCollection AllSongs { - get { return _Songs.ToArray(); } + get { return _Songs.AsReadOnly(); } } - public static CSong[] SongsNotSung + public static ReadOnlyCollection VisibleSongs { get { List songs = new List(); - foreach (SSongPointer sp in Sorter.SortedSongs) + if (IsCatIndexValid(_CatIndex)) { - if (sp.Visible) - songs.Add(_Songs[sp.SongID]); + foreach (CSongPointer sp in Categories[_CatIndex].Songs) + { + if (!sp.IsSung) + songs.Add(_Songs[sp.SongID]); + } } - return songs.ToArray(); + return songs.AsReadOnly(); } } - public static CSong[] VisibleSongs + public static ReadOnlyCollection Categories { - get - { - List songs = new List(); - foreach (SSongPointer sp in Sorter.SortedSongs) - { - if (sp.Visible) - songs.Add(_Songs[sp.SongID]); - } - return songs.ToArray(); - } - } - - public static CCategory[] Categories - { - get { return Categorizer.Categories.ToArray(); } + get { return Categorizer.Categories.AsReadOnly(); } } public static CSong GetVisibleSongByIndex(int index) { if (index < 0) return null; - - foreach (SSongPointer sp in Sorter.SortedSongs) - { - if (sp.Visible) - { - if (index == 0) - return _Songs[sp.SongID]; - index--; - } - } - return null; + var visSongs = VisibleSongs; + return (index < visSongs.Count) ? visSongs[index] : null; } private static void _HandleCategoriesChanged(object sender, EventArgs args) @@ -371,7 +288,7 @@ namespace Vocaluxe.Base public static void LoadSongs() { CLog.StartBenchmark(1, "Load Songs"); - _SongsLoaded = false; + SongsLoaded = false; _Songs.Clear(); CLog.StartBenchmark(2, "List Songs"); @@ -403,7 +320,7 @@ namespace Vocaluxe.Base Categorizer.ObjectChanged += _HandleCategoriesChanged; CLog.StopBenchmark(2, "Sort Songs"); Category = -1; - _SongsLoaded = true; + SongsLoaded = true; if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART) { diff --git a/Vocaluxe/Base/Font/CGlyph.cs b/Vocaluxe/Base/Font/CGlyph.cs index 56ac78cd..bca65ad9 100644 --- a/Vocaluxe/Base/Font/CGlyph.cs +++ b/Vocaluxe/Base/Font/CGlyph.cs @@ -82,7 +82,7 @@ namespace Vocaluxe.Base.Font point); * */ Texture = CDraw.AddTexture(bmp); - bmp.Save("font/" + chr + CFonts.Style + ".png", ImageFormat.Png); + //bmp.Save("font/" + chr + CFonts.Style + ".png", ImageFormat.Png); Width = (int)((1f + outline / 2f) * sizeB.Width * Texture.Width / factor / bmp.Width); g.Dispose(); } diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs index 08593a50..f0603d78 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs @@ -155,9 +155,8 @@ namespace Vocaluxe.Lib.Playlist xmlReader.TryGetEnumValue("//root/Songs/" + song + "/GameMode", ref gm); CPlaylistSong playlistSong = new CPlaylistSong {SongID = -1}; - CSong[] allSongs = CSongs.AllSongs; - foreach (CSong curSong in allSongs) + foreach (CSong curSong in CSongs.AllSongs) { if (curSong.Artist != artist || curSong.Title != title) continue; diff --git a/Vocaluxe/Screens/CScreenOptionsTheme.cs b/Vocaluxe/Screens/CScreenOptionsTheme.cs index 1ba85dd1..5ad72a24 100644 --- a/Vocaluxe/Screens/CScreenOptionsTheme.cs +++ b/Vocaluxe/Screens/CScreenOptionsTheme.cs @@ -181,12 +181,7 @@ namespace Vocaluxe.Screens CConfig.SaveConfig(); if (_OldCoverTheme != _SelectSlides[_SelectSlideCover].Selection) - { CCover.ReloadCover(); - CSongs.Filter.SearchString = String.Empty; - CSongs.Sorter.SetOptions(CConfig.SongSorting, CConfig.IgnoreArticles); - CSongs.Categorizer.Tabs = CConfig.Tabs; - } if (_OldTheme != _SelectSlides[_SelectSlideTheme].Selection) { diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 6f0d83b7..6495e45a 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -213,7 +213,7 @@ namespace Vocaluxe.Screens if (_Buttons[_ButtonStart].Selected) _HandlePartySongSelection(_SongMenus[_SongMenu].GetSelectedSong()); } - if (CSongs.NumVisibleSongs > 0 && !_Sso.Selection.PartyMode) + if (CSongs.NumSongsVisible > 0 && !_Sso.Selection.PartyMode) { if (_SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive) { @@ -276,7 +276,7 @@ namespace Vocaluxe.Screens break; case Keys.S: - if (keyEvent.Mod == EModifier.Ctrl && CSongs.NumVisibleSongs > 0 && !_Sso.Selection.PartyMode) + if (keyEvent.Mod == EModifier.Ctrl && CSongs.NumSongsVisible > 0 && !_Sso.Selection.PartyMode) _StartMedleySong(_SongMenus[_SongMenu].GetSelectedSong()); break; @@ -442,7 +442,7 @@ namespace Vocaluxe.Screens { //TODO: Causes Bug if you select a song (e.g. with Select random song) and double click a normal button. //E.g. clicking to fast on Select random song starts the next random song. is this OK? - if (CSongs.NumVisibleSongs > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1) + if (CSongs.NumSongsVisible > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1) { _ToggleSongOptions(ESongOptionsView.None); _StartVisibleSong(_SongMenus[_SongMenu].GetActualSelection()); @@ -558,7 +558,7 @@ namespace Vocaluxe.Screens } } - if (CSongs.NumVisibleSongs > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1 && !_Sso.Selection.PartyMode) + if (CSongs.NumSongsVisible > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1 && !_Sso.Selection.PartyMode) { if (_SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive) { @@ -572,7 +572,7 @@ namespace Vocaluxe.Screens if (mouseEvent.LBH) { - if (!_DragAndDropActive && _Playlists[_Playlist].Visible && CSongs.NumVisibleSongs > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1) + if (!_DragAndDropActive && _Playlists[_Playlist].Visible && CSongs.NumSongsVisible > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1) { _DragAndDropCover = _SongMenus[_SongMenu].GetSelectedSongCover(); _DragAndDropCover.Rect.Z = CSettings.ZNear; @@ -653,9 +653,9 @@ namespace Vocaluxe.Screens CBackgroundMusic.Disabled = false; int song = _SongMenus[_SongMenu].GetActualSelection(); - if ((CSongs.Category >= 0 || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) && song >= 0 && song < CSongs.VisibleSongs.Length) + if ((CSongs.Category >= 0 || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) && song >= 0 && song < CSongs.VisibleSongs.Count) _Texts[_TextSelection].Text = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title; - else if (!CSongs.IsInCategory && song >= 0 && song < CSongs.Categories.Length) + else if (!CSongs.IsInCategory && song >= 0 && song < CSongs.Categories.Count) _Texts[_TextSelection].Text = CSongs.Categories[song].Name; else _Texts[_TextSelection].Text = String.Empty; @@ -822,7 +822,7 @@ namespace Vocaluxe.Screens private void _StartVisibleSong(int songNr) { - if (CSongs.Category >= 0 && songNr >= 0 && CSongs.NumVisibleSongs > songNr) + if (CSongs.Category >= 0 && songNr >= 0 && CSongs.NumSongsVisible > songNr) { EGameMode gm = CSongs.VisibleSongs[songNr].IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL; @@ -856,7 +856,7 @@ namespace Vocaluxe.Screens CGame.ClearSongs(); List ids = new List(); - for (int i = 0; i < CSongs.AllSongs.Length; i++) + for (int i = 0; i < CSongs.AllSongs.Count; i++) ids.Add(i); while (ids.Count > 0) @@ -882,7 +882,7 @@ namespace Vocaluxe.Screens CGame.ClearSongs(); List ids = new List(); - for (int i = 0; i < CSongs.VisibleSongs.Length; i++) + for (int i = 0; i < CSongs.VisibleSongs.Count; i++) ids.Add(CSongs.VisibleSongs[i].ID); while (ids.Count > 0) @@ -910,12 +910,12 @@ namespace Vocaluxe.Screens List ids = new List(); if (allSongs) { - for (int i = 0; i < CSongs.AllSongs.Length; i++) + for (int i = 0; i < CSongs.AllSongs.Count; i++) ids.Add(i); } else { - for (int i = 0; i < CSongs.VisibleSongs.Length; i++) + for (int i = 0; i < CSongs.VisibleSongs.Count; i++) ids.Add(CSongs.VisibleSongs[i].ID); } int s = 0; @@ -985,6 +985,21 @@ namespace Vocaluxe.Screens return false; } + private int _FindIndex(IList list, int start, Predicate match) + { + for (int i = start; i < list.Count; i++) + { + if (match(list[i])) + return i; + } + for (int i = 0; i < start; i++) + { + if (match(list[i])) + return i; + } + return -1; + } + private void _JumpTo(char letter) { int start = 0; @@ -992,29 +1007,21 @@ namespace Vocaluxe.Screens if (CSongs.IsInCategory) { //TODO: Check and use sorting method - CSong[] songs = CSongs.VisibleSongs; - int ct = songs.Length; - if (curSelected >= 0 && curSelected < ct - 1) - { - CSong currentSong = CSongs.GetVisibleSongByIndex(curSelected); - if (currentSong != null && currentSong.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)) - start = curSelected + 1; - } - int visibleID = Array.FindIndex(songs, start, ct - start, element => element.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); - if (visibleID < 0 && start > 1) - visibleID = Array.FindIndex(songs, 0, start - 1, element => element.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); + var songs = CSongs.VisibleSongs; + int ct = songs.Count; + if (curSelected >= 0 && curSelected < ct - 1 && songs[curSelected].Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)) + start = curSelected + 1; + int visibleID = _FindIndex(songs, start, element => element.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); if (visibleID > -1) _SongMenus[_SongMenu].SetSelectedSong(visibleID); } else { - CCategory[] categories = CSongs.Categories; - int ct = categories.Length; + var categories = CSongs.Categories; + int ct = categories.Count; if (curSelected >= 0 && curSelected < ct - 1 && categories[curSelected].Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)) start = curSelected + 1; - int visibleID = Array.FindIndex(categories, start, ct - start, element => element.Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); - if (visibleID < 0 && start > 1) - visibleID = Array.FindIndex(categories, 0, start - 1, element => element.Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); + int visibleID = _FindIndex(categories, start, element => element.Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); if (visibleID > -1) _SongMenus[_SongMenu].SetSelectedCategory(visibleID); } @@ -1030,7 +1037,7 @@ namespace Vocaluxe.Screens int songIndex = _SongMenus[_SongMenu].GetSelectedSong(); int songID = -1; - if (songIndex != -1 && CSongs.NumVisibleSongs > 0 && CSongs.NumVisibleSongs > songIndex) + if (songIndex != -1 && CSongs.NumSongsVisible > 0 && CSongs.NumSongsVisible > songIndex) songID = CSongs.VisibleSongs[songIndex].ID; if (newFilterString == "" && _Sso.Sorting.Tabs == EOffOn.TR_CONFIG_ON) @@ -1047,7 +1054,7 @@ namespace Vocaluxe.Screens CSongs.Sort(_Sso.Sorting.SongSorting, _Sso.Sorting.Tabs, _Sso.Sorting.IgnoreArticles, newFilterString, _Sso.Sorting.DuetOptions); - if (songID == -1 || CSongs.NumVisibleSongs == 0 || CSongs.NumVisibleSongs <= songIndex || CSongs.GetVisibleSongByIndex(songIndex).ID != songID) + if (songID == -1 || CSongs.NumSongsVisible == 0 || CSongs.NumSongsVisible <= songIndex || CSongs.GetVisibleSongByIndex(songIndex).ID != songID) refresh = true; if (refresh) @@ -1162,12 +1169,12 @@ namespace Vocaluxe.Screens _SelectSlides[_SelectSlideOptionsNumMedleySongs].Clear(); if (CSongs.IsInCategory) { - for (int i = 1; i <= CSongs.VisibleSongs.Length; i++) + for (int i = 1; i <= CSongs.VisibleSongs.Count; i++) _SelectSlides[_SelectSlideOptionsNumMedleySongs].AddValue(i.ToString()); } else { - for (int i = 1; i <= CSongs.AllSongs.Length; i++) + for (int i = 1; i <= CSongs.AllSongs.Count; i++) _SelectSlides[_SelectSlideOptionsNumMedleySongs].AddValue(i.ToString()); } if (_SelectSlides[_SelectSlideOptionsNumMedleySongs].NumValues >= 5) diff --git a/Vocaluxe/SongQueue/CSongQueue.cs b/Vocaluxe/SongQueue/CSongQueue.cs index 62a3814c..eb32c0e5 100644 --- a/Vocaluxe/SongQueue/CSongQueue.cs +++ b/Vocaluxe/SongQueue/CSongQueue.cs @@ -60,12 +60,12 @@ namespace Vocaluxe.SongQueue public bool AddVisibleSong(int visibleIndex, EGameMode gameMode) { - return CSongs.VisibleSongs.Length > visibleIndex && _AddSong(CSongs.VisibleSongs[visibleIndex].ID, gameMode); + return CSongs.VisibleSongs.Count > visibleIndex && _AddSong(CSongs.VisibleSongs[visibleIndex].ID, gameMode); } public bool AddSong(int absoluteIndex, EGameMode gameMode) { - return CSongs.AllSongs.Length > absoluteIndex && _AddSong(CSongs.AllSongs[absoluteIndex].ID, gameMode); + return CSongs.AllSongs.Count > absoluteIndex && _AddSong(CSongs.AllSongs[absoluteIndex].ID, gameMode); } private bool _AddSong(int songID, EGameMode gameMode) @@ -79,12 +79,12 @@ namespace Vocaluxe.SongQueue public bool RemoveVisibleSong(int visibleIndex) { - return CSongs.VisibleSongs.Length > visibleIndex && _RemoveSong(CSongs.VisibleSongs[visibleIndex].ID); + return CSongs.VisibleSongs.Count > visibleIndex && _RemoveSong(CSongs.VisibleSongs[visibleIndex].ID); } public bool RemoveSong(int absoluteIndex) { - return CSongs.AllSongs.Length > absoluteIndex && _RemoveSong(CSongs.AllSongs[absoluteIndex].ID); + return CSongs.AllSongs.Count > absoluteIndex && _RemoveSong(CSongs.AllSongs[absoluteIndex].ID); } private bool _RemoveSong(int songID) diff --git a/VocaluxeLib/Menu/IMenu.cs b/VocaluxeLib/Menu/IMenu.cs index 38af4ff1..979328e2 100644 --- a/VocaluxeLib/Menu/IMenu.cs +++ b/VocaluxeLib/Menu/IMenu.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Drawing; using VocaluxeLib.Menu.SongMenu; using VocaluxeLib.PartyModes; @@ -240,7 +241,7 @@ namespace VocaluxeLib.Menu public interface ISongs { int GetNumSongs(); - int GetNumVisibleSongs(); + int GetNumSongsVisible(); int GetNumCategories(); int NumSongsInCategory(int categoryIndex); @@ -253,13 +254,11 @@ namespace VocaluxeLib.Menu CSong GetVisibleSong(int visibleIndex); CSong GetSongByID(int songID); - CSong[] GetSongs(); - CSong[] GetSongsNotSung(); + ReadOnlyCollection GetVisibleSongs(); CCategory GetCategory(int index); void AddPartySongSung(int songID); - void ResetPartySongSung(); - void ResetPartySongSung(int catIndex); + void ResetSongSung(int catIndex = -1); void SortSongs(ESongSorting sorting, EOffOn tabs, EOffOn ignoreArticles, String searchString, EDuetOptions duetOptions); diff --git a/VocaluxeLib/Menu/SongMenu/CSong.cs b/VocaluxeLib/Menu/SongMenu/CSong.cs index e4396d48..c3598585 100644 --- a/VocaluxeLib/Menu/SongMenu/CSong.cs +++ b/VocaluxeLib/Menu/SongMenu/CSong.cs @@ -26,6 +26,19 @@ using VocaluxeLib.Menu.SingNotes; namespace VocaluxeLib.Menu.SongMenu { + public class CSongPointer + { + public readonly int SongID; + public string SortString; + public bool IsSung; + + public CSongPointer(int id, string sortString) + { + SongID = id; + SortString = sortString; + } + } + [Flags] enum EHeaderFlags { @@ -40,58 +53,11 @@ namespace VocaluxeLib.Menu.SongMenu public enum EMedleySource { - None, + None = 0, Calculated, Tag } - public class CCategory - { - public readonly string Name; - private STexture _CoverTextureSmall = new STexture(-1); - private STexture _CoverTextureBig = new STexture(-1); - private bool _CoverBigLoaded; - - public CCategory(string name) - { - Name = name; - } - - public STexture CoverTextureSmall - { - get { return _CoverTextureSmall; } - - set { _CoverTextureSmall = value; } - } - - public STexture CoverTextureBig - { - get { return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } - set - { - if (value.Index != -1) - { - _CoverTextureBig = value; - _CoverBigLoaded = true; - } - } - } - - public CCategory(string name, STexture coverSmall, STexture coverBig) - { - Name = name; - CoverTextureSmall = coverSmall; - CoverTextureBig = coverBig; - } - - public CCategory(CCategory cat) - { - Name = cat.Name; - CoverTextureSmall = cat.CoverTextureSmall; - CoverTextureBig = cat.CoverTextureBig; - } - } - public struct SMedley { public EMedleySource Source; @@ -99,17 +65,6 @@ namespace VocaluxeLib.Menu.SongMenu public int EndBeat; public float FadeInTime; public float FadeOutTime; - - // ReSharper disable UnusedParameter.Local - public SMedley(int dummy) - // ReSharper restore UnusedParameter.Local - { - Source = EMedleySource.None; - StartBeat = 0; - EndBeat = 0; - FadeInTime = 0f; - FadeOutTime = 0f; - } } public class CSong @@ -119,7 +74,7 @@ namespace VocaluxeLib.Menu.SongMenu private STexture _CoverTextureSmall = new STexture(-1); private STexture _CoverTextureBig = new STexture(-1); - public SMedley Medley = new SMedley(0); + public SMedley Medley; public bool CalculateMedley = true; public float PreviewStart; @@ -159,10 +114,7 @@ namespace VocaluxeLib.Menu.SongMenu public STexture CoverTextureBig { - get - { - return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; - } + get { return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } set { _CoverTextureBig = value; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs index d70f4393..b4c3f32a 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs @@ -35,12 +35,6 @@ namespace VocaluxeLib.Menu.SongMenu _CreateSongMenu(); } - public void UpdateSongMenuType() - { - if (_Type != CBase.Config.GetSongMenuType()) - _CreateSongMenu(); - } - public bool Selected { get { return _SongMenu.IsSelected(); } diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 77d3f50b..e3329358 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -252,8 +252,6 @@ namespace VocaluxeLib.Menu.SongMenu StaticMedleyTagIcon = new CStatic(_PartyModeID) } }; - - _ThemeLoaded = false; } public string GetThemeName() @@ -598,7 +596,7 @@ namespace VocaluxeLib.Menu.SongMenu protected void _SelectSong(int nr) { - if (CBase.Songs.GetCurrentCategoryIndex() >= 0 && (CBase.Songs.GetNumVisibleSongs() > 0) && (nr >= 0) && ((_Actsong != nr) || (_Streams.Count == 0))) + if (CBase.Songs.GetCurrentCategoryIndex() >= 0 && (CBase.Songs.GetNumSongsVisible() > 0) && (nr >= 0) && ((_Actsong != nr) || (_Streams.Count == 0))) { _Streams.ForEach(soundStream => CBase.Sound.FadeAndStop(soundStream, 0f, 1f)); _Streams.Clear(); @@ -609,7 +607,7 @@ namespace VocaluxeLib.Menu.SongMenu CBase.Drawing.RemoveTexture(ref _Vidtex); _Actsong = nr; - if (_Actsong >= CBase.Songs.GetNumVisibleSongs()) + if (_Actsong >= CBase.Songs.GetNumSongsVisible()) _Actsong = 0; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 6a81f68e..35932a34 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -138,7 +138,6 @@ namespace VocaluxeLib.Menu.SongMenu //AfterCategoryChange(); SetSelectedSong(_ActSong); _AfterCategoryChange(); - CBase.Songs.UpdateRandomSongList(); int actcat = _PreviewSelected; if ((CBase.Songs.GetNumCategories() > 0) && (actcat < 0)) @@ -155,7 +154,7 @@ namespace VocaluxeLib.Menu.SongMenu _MedleyTagIcon.Visible = false; } - if (CBase.Songs.GetNumVisibleSongs() == 0 && CBase.Songs.GetSearchFilter() != "") + if (CBase.Songs.GetNumSongsVisible() == 0 && CBase.Songs.GetSearchFilter() != "") { _CoverBig.Texture = _CoverBigTexture; _Artist.Text = String.Empty; @@ -253,7 +252,7 @@ namespace VocaluxeLib.Menu.SongMenu } else { - if (CBase.Songs.GetCurrentCategoryIndex() != -1 && _Locked < CBase.Songs.GetNumVisibleSongs() - 1 && !songOptions.Selection.RandomOnly) + if (CBase.Songs.GetCurrentCategoryIndex() != -1 && _Locked < CBase.Songs.GetNumSongsVisible() - 1 && !songOptions.Selection.RandomOnly) { _Locked++; _UpdateList(); @@ -291,7 +290,7 @@ namespace VocaluxeLib.Menu.SongMenu _UpdateList(); } } - else if (_Locked < CBase.Songs.GetNumVisibleSongs() - _NumW && !songOptions.Selection.RandomOnly) + else if (_Locked < CBase.Songs.GetNumSongsVisible() - _NumW && !songOptions.Selection.RandomOnly) { _Locked += _NumW; _UpdateList(); @@ -403,7 +402,7 @@ namespace VocaluxeLib.Menu.SongMenu if (CBase.Songs.GetCurrentCategoryIndex() >= 0) { int actsong = _PreviewSelected; - if ((CBase.Songs.GetNumVisibleSongs() > actsong) && (actsong >= 0)) + if ((CBase.Songs.GetNumSongsVisible() > actsong) && (actsong >= 0)) { CSong song = CBase.Songs.GetVisibleSong(actsong); @@ -529,7 +528,7 @@ namespace VocaluxeLib.Menu.SongMenu { base.SetSelectedSong(visibleSongNr); - if (visibleSongNr >= 0 && visibleSongNr < CBase.Songs.GetNumVisibleSongs()) + if (visibleSongNr >= 0 && visibleSongNr < CBase.Songs.GetNumSongsVisible()) _SetSelectedTile(visibleSongNr); } @@ -592,11 +591,11 @@ namespace VocaluxeLib.Menu.SongMenu if (_ActualSelection >= 0 && _ActualSelection < _Tiles.Count) _Tiles[_ActualSelection].Selected = true; - if ((_LastKnownNumSongs == CBase.Songs.GetNumVisibleSongs()) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex())) + if ((_LastKnownNumSongs == CBase.Songs.GetNumSongsVisible()) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex())) return; _LastKnownCategory = CBase.Songs.GetCurrentCategoryIndex(); - _LastKnownNumSongs = CBase.Songs.GetNumVisibleSongs(); + _LastKnownNumSongs = CBase.Songs.GetNumSongsVisible(); _UpdateList(0, true); CBase.Songs.UpdateRandomSongList(); } @@ -609,7 +608,7 @@ namespace VocaluxeLib.Menu.SongMenu private void _UpdateList(int offset, bool force = false) { bool isInCategory = CBase.Songs.GetCurrentCategoryIndex() >= 0; - int itemCount = isInCategory ? CBase.Songs.GetNumVisibleSongs() : CBase.Songs.GetNumCategories(); + int itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories(); if (offset >= (itemCount / _NumW) * _NumW - (_NumW * (_NumH - 1))) offset = (itemCount / _NumW) * _NumW - (_NumW * (_NumH - 1)); diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index e9d4bd1e..2c437927 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -137,6 +137,7 @@ + From 34c75ec7c579bdfa4cac5a99eada16232270695e Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 28 Apr 2013 17:23:55 +0200 Subject: [PATCH 10/10] Fixed Bug with window not closing after error --- Vocaluxe.sln.DotSettings | 2 +- Vocaluxe/Lib/Draw/CDirect3D.cs | 5 +++++ Vocaluxe/Lib/Draw/CDrawWinForm.cs | 5 +++++ Vocaluxe/Lib/Draw/COpenGL.cs | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Vocaluxe.sln.DotSettings b/Vocaluxe.sln.DotSettings index 0ca89a5f..3dfb002c 100644 --- a/Vocaluxe.sln.DotSettings +++ b/Vocaluxe.sln.DotSettings @@ -10,7 +10,7 @@ DO_NOT_SHOW DO_NOT_SHOW <?xml version="1.0" encoding="utf-16"?><Profile name="Cleanup"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUseVar><BehavourStyle>CAN_CHANGE_TO_EXPLICIT</BehavourStyle><LocalVariableStyle>ALWAYS_EXPLICIT</LocalVariableStyle><ForeachVariableStyle>ALWAYS_EXPLICIT</ForeachVariableStyle></CSUseVar><CSOptimizeUsings><OptimizeUsings>False</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments><CSShortenReferences>True</CSShortenReferences><StyleCop.Documentation><SA1600ElementsMustBeDocumented>False</SA1600ElementsMustBeDocumented><SA1604ElementDocumentationMustHaveSummary>False</SA1604ElementDocumentationMustHaveSummary><SA1609PropertyDocumentationMustHaveValueDocumented>False</SA1609PropertyDocumentationMustHaveValueDocumented><SA1611ElementParametersMustBeDocumented>False</SA1611ElementParametersMustBeDocumented><SA1615ElementReturnValueMustBeDocumented>False</SA1615ElementReturnValueMustBeDocumented><SA1617VoidReturnValueMustNotBeDocumented>False</SA1617VoidReturnValueMustNotBeDocumented><SA1618GenericTypeParametersMustBeDocumented>False</SA1618GenericTypeParametersMustBeDocumented><SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes>False</SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes><SA1628DocumentationTextMustBeginWithACapitalLetter>False</SA1628DocumentationTextMustBeginWithACapitalLetter><SA1629DocumentationTextMustEndWithAPeriod>False</SA1629DocumentationTextMustEndWithAPeriod><SA1633SA1641UpdateFileHeader>Ignore</SA1633SA1641UpdateFileHeader><SA1639FileHeaderMustHaveSummary>False</SA1639FileHeaderMustHaveSummary><SA1642ConstructorSummaryDocumentationMustBeginWithStandardText>False</SA1642ConstructorSummaryDocumentationMustBeginWithStandardText><SA1643DestructorSummaryDocumentationMustBeginWithStandardText>False</SA1643DestructorSummaryDocumentationMustBeginWithStandardText><SA1644DocumentationHeadersMustNotContainBlankLines>False</SA1644DocumentationHeadersMustNotContainBlankLines></StyleCop.Documentation><StyleCop.Layout><SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine>False</SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine><SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine>True</SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine><SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine>True</SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine><SA1511WhileDoFooterMustNotBePrecededByBlankLine>True</SA1511WhileDoFooterMustNotBePrecededByBlankLine><SA1512SingleLineCommentsMustNotBeFollowedByBlankLine>True</SA1512SingleLineCommentsMustNotBeFollowedByBlankLine><SA1513ClosingCurlyBracketMustBeFollowedByBlankLine>False</SA1513ClosingCurlyBracketMustBeFollowedByBlankLine><SA1514ElementDocumentationHeaderMustBePrecededByBlankLine>False</SA1514ElementDocumentationHeaderMustBePrecededByBlankLine><SA1515SingleLineCommentMustBeProceededByBlankLine>False</SA1515SingleLineCommentMustBeProceededByBlankLine></StyleCop.Layout><StyleCop.Readability><SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists>True</SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists><SA1106CodeMustNotContainEmptyStatements>True</SA1106CodeMustNotContainEmptyStatements><SA1108BlockStatementsMustNotContainEmbeddedComments>True</SA1108BlockStatementsMustNotContainEmbeddedComments><SA1109BlockStatementsMustNotContainEmbeddedRegions>True</SA1109BlockStatementsMustNotContainEmbeddedRegions><SA1120CommentsMustContainText>False</SA1120CommentsMustContainText><SA1121UseBuiltInTypeAlias>False</SA1121UseBuiltInTypeAlias><SA1122UseStringEmptyForEmptyStrings>False</SA1122UseStringEmptyForEmptyStrings><SA1123DoNotPlaceRegionsWithinElements>False</SA1123DoNotPlaceRegionsWithinElements><SA1124CodeMustNotContainEmptyRegions>True</SA1124CodeMustNotContainEmptyRegions></StyleCop.Readability><StyleCop.Spacing><SA1001CommasMustBeSpacedCorrectly>False</SA1001CommasMustBeSpacedCorrectly><SA1005SingleLineCommentsMustBeginWithSingleSpace>False</SA1005SingleLineCommentsMustBeginWithSingleSpace><SA1006PreprocessorKeywordsMustNotBePrecededBySpace>True</SA1006PreprocessorKeywordsMustNotBePrecededBySpace><SA1021NegativeSignsMustBeSpacedCorrectly>True</SA1021NegativeSignsMustBeSpacedCorrectly><SA1022PositiveSignsMustBeSpacedCorrectly>True</SA1022PositiveSignsMustBeSpacedCorrectly><SA1025CodeMustNotContainMultipleWhitespaceInARow>True</SA1025CodeMustNotContainMultipleWhitespaceInARow></StyleCop.Spacing><StyleCop.Ordering><AlphabeticalUsingDirectives>Ignore</AlphabeticalUsingDirectives><ExpandUsingDirectives>Ignore</ExpandUsingDirectives><SA1212PropertyAccessorsMustFollowOrder>True</SA1212PropertyAccessorsMustFollowOrder><SA1213EventAccessorsMustFollowOrder>True</SA1213EventAccessorsMustFollowOrder></StyleCop.Ordering><CSUpdateFileHeader>True</CSUpdateFileHeader></Profile> - <?xml version="1.0" encoding="utf-16"?><Profile name="Simple Reformat"><CSOptimizeUsings><OptimizeUsings>False</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><StyleCop.Documentation><SA1600ElementsMustBeDocumented>False</SA1600ElementsMustBeDocumented><SA1604ElementDocumentationMustHaveSummary>False</SA1604ElementDocumentationMustHaveSummary><SA1609PropertyDocumentationMustHaveValueDocumented>False</SA1609PropertyDocumentationMustHaveValueDocumented><SA1611ElementParametersMustBeDocumented>False</SA1611ElementParametersMustBeDocumented><SA1615ElementReturnValueMustBeDocumented>False</SA1615ElementReturnValueMustBeDocumented><SA1617VoidReturnValueMustNotBeDocumented>False</SA1617VoidReturnValueMustNotBeDocumented><SA1618GenericTypeParametersMustBeDocumented>False</SA1618GenericTypeParametersMustBeDocumented><SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes>False</SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes><SA1628DocumentationTextMustBeginWithACapitalLetter>False</SA1628DocumentationTextMustBeginWithACapitalLetter><SA1629DocumentationTextMustEndWithAPeriod>False</SA1629DocumentationTextMustEndWithAPeriod><SA1633SA1641UpdateFileHeader>Ignore</SA1633SA1641UpdateFileHeader><SA1639FileHeaderMustHaveSummary>False</SA1639FileHeaderMustHaveSummary><SA1642ConstructorSummaryDocumentationMustBeginWithStandardText>False</SA1642ConstructorSummaryDocumentationMustBeginWithStandardText><SA1643DestructorSummaryDocumentationMustBeginWithStandardText>False</SA1643DestructorSummaryDocumentationMustBeginWithStandardText><SA1644DocumentationHeadersMustNotContainBlankLines>False</SA1644DocumentationHeadersMustNotContainBlankLines></StyleCop.Documentation><StyleCop.Spacing><SA1001CommasMustBeSpacedCorrectly>False</SA1001CommasMustBeSpacedCorrectly><SA1005SingleLineCommentsMustBeginWithSingleSpace>False</SA1005SingleLineCommentsMustBeginWithSingleSpace><SA1006PreprocessorKeywordsMustNotBePrecededBySpace>True</SA1006PreprocessorKeywordsMustNotBePrecededBySpace><SA1021NegativeSignsMustBeSpacedCorrectly>True</SA1021NegativeSignsMustBeSpacedCorrectly><SA1022PositiveSignsMustBeSpacedCorrectly>True</SA1022PositiveSignsMustBeSpacedCorrectly><SA1025CodeMustNotContainMultipleWhitespaceInARow>True</SA1025CodeMustNotContainMultipleWhitespaceInARow></StyleCop.Spacing><StyleCop.Readability><SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists>True</SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists><SA1106CodeMustNotContainEmptyStatements>True</SA1106CodeMustNotContainEmptyStatements><SA1108BlockStatementsMustNotContainEmbeddedComments>True</SA1108BlockStatementsMustNotContainEmbeddedComments><SA1109BlockStatementsMustNotContainEmbeddedRegions>True</SA1109BlockStatementsMustNotContainEmbeddedRegions><SA1120CommentsMustContainText>False</SA1120CommentsMustContainText><SA1121UseBuiltInTypeAlias>False</SA1121UseBuiltInTypeAlias><SA1122UseStringEmptyForEmptyStrings>False</SA1122UseStringEmptyForEmptyStrings><SA1123DoNotPlaceRegionsWithinElements>False</SA1123DoNotPlaceRegionsWithinElements><SA1124CodeMustNotContainEmptyRegions>True</SA1124CodeMustNotContainEmptyRegions></StyleCop.Readability><StyleCop.Layout><SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine>False</SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine><SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine>True</SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine><SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine>True</SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine><SA1511WhileDoFooterMustNotBePrecededByBlankLine>True</SA1511WhileDoFooterMustNotBePrecededByBlankLine><SA1512SingleLineCommentsMustNotBeFollowedByBlankLine>True</SA1512SingleLineCommentsMustNotBeFollowedByBlankLine><SA1513ClosingCurlyBracketMustBeFollowedByBlankLine>False</SA1513ClosingCurlyBracketMustBeFollowedByBlankLine><SA1514ElementDocumentationHeaderMustBePrecededByBlankLine>False</SA1514ElementDocumentationHeaderMustBePrecededByBlankLine><SA1515SingleLineCommentMustBeProceededByBlankLine>False</SA1515SingleLineCommentMustBeProceededByBlankLine></StyleCop.Layout><StyleCop.Ordering><AlphabeticalUsingDirectives>Ignore</AlphabeticalUsingDirectives><ExpandUsingDirectives>Ignore</ExpandUsingDirectives><SA1212PropertyAccessorsMustFollowOrder>True</SA1212PropertyAccessorsMustFollowOrder><SA1213EventAccessorsMustFollowOrder>True</SA1213EventAccessorsMustFollowOrder></StyleCop.Ordering></Profile> + <?xml version="1.0" encoding="utf-16"?><Profile name="Simple Reformat"><CSOptimizeUsings><OptimizeUsings>False</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><StyleCop.Documentation><SA1600ElementsMustBeDocumented>False</SA1600ElementsMustBeDocumented><SA1604ElementDocumentationMustHaveSummary>False</SA1604ElementDocumentationMustHaveSummary><SA1609PropertyDocumentationMustHaveValueDocumented>False</SA1609PropertyDocumentationMustHaveValueDocumented><SA1611ElementParametersMustBeDocumented>False</SA1611ElementParametersMustBeDocumented><SA1615ElementReturnValueMustBeDocumented>False</SA1615ElementReturnValueMustBeDocumented><SA1617VoidReturnValueMustNotBeDocumented>False</SA1617VoidReturnValueMustNotBeDocumented><SA1618GenericTypeParametersMustBeDocumented>False</SA1618GenericTypeParametersMustBeDocumented><SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes>False</SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes><SA1628DocumentationTextMustBeginWithACapitalLetter>False</SA1628DocumentationTextMustBeginWithACapitalLetter><SA1629DocumentationTextMustEndWithAPeriod>False</SA1629DocumentationTextMustEndWithAPeriod><SA1633SA1641UpdateFileHeader>Ignore</SA1633SA1641UpdateFileHeader><SA1639FileHeaderMustHaveSummary>False</SA1639FileHeaderMustHaveSummary><SA1642ConstructorSummaryDocumentationMustBeginWithStandardText>False</SA1642ConstructorSummaryDocumentationMustBeginWithStandardText><SA1643DestructorSummaryDocumentationMustBeginWithStandardText>False</SA1643DestructorSummaryDocumentationMustBeginWithStandardText><SA1644DocumentationHeadersMustNotContainBlankLines>False</SA1644DocumentationHeadersMustNotContainBlankLines></StyleCop.Documentation><StyleCop.Spacing><SA1001CommasMustBeSpacedCorrectly>False</SA1001CommasMustBeSpacedCorrectly><SA1005SingleLineCommentsMustBeginWithSingleSpace>False</SA1005SingleLineCommentsMustBeginWithSingleSpace><SA1006PreprocessorKeywordsMustNotBePrecededBySpace>True</SA1006PreprocessorKeywordsMustNotBePrecededBySpace><SA1021NegativeSignsMustBeSpacedCorrectly>True</SA1021NegativeSignsMustBeSpacedCorrectly><SA1022PositiveSignsMustBeSpacedCorrectly>True</SA1022PositiveSignsMustBeSpacedCorrectly><SA1025CodeMustNotContainMultipleWhitespaceInARow>True</SA1025CodeMustNotContainMultipleWhitespaceInARow></StyleCop.Spacing><StyleCop.Readability><SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists>True</SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists><SA1106CodeMustNotContainEmptyStatements>True</SA1106CodeMustNotContainEmptyStatements><SA1108BlockStatementsMustNotContainEmbeddedComments>True</SA1108BlockStatementsMustNotContainEmbeddedComments><SA1109BlockStatementsMustNotContainEmbeddedRegions>True</SA1109BlockStatementsMustNotContainEmbeddedRegions><SA1120CommentsMustContainText>False</SA1120CommentsMustContainText><SA1121UseBuiltInTypeAlias>False</SA1121UseBuiltInTypeAlias><SA1122UseStringEmptyForEmptyStrings>False</SA1122UseStringEmptyForEmptyStrings><SA1123DoNotPlaceRegionsWithinElements>False</SA1123DoNotPlaceRegionsWithinElements><SA1124CodeMustNotContainEmptyRegions>True</SA1124CodeMustNotContainEmptyRegions></StyleCop.Readability><StyleCop.Layout><SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine>False</SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine><SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine>True</SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine><SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine>True</SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine><SA1511WhileDoFooterMustNotBePrecededByBlankLine>True</SA1511WhileDoFooterMustNotBePrecededByBlankLine><SA1512SingleLineCommentsMustNotBeFollowedByBlankLine>True</SA1512SingleLineCommentsMustNotBeFollowedByBlankLine><SA1513ClosingCurlyBracketMustBeFollowedByBlankLine>False</SA1513ClosingCurlyBracketMustBeFollowedByBlankLine><SA1514ElementDocumentationHeaderMustBePrecededByBlankLine>False</SA1514ElementDocumentationHeaderMustBePrecededByBlankLine><SA1515SingleLineCommentMustBeProceededByBlankLine>False</SA1515SingleLineCommentMustBeProceededByBlankLine></StyleCop.Layout><StyleCop.Ordering><AlphabeticalUsingDirectives>Ignore</AlphabeticalUsingDirectives><ExpandUsingDirectives>Ignore</ExpandUsingDirectives><SA1212PropertyAccessorsMustFollowOrder>True</SA1212PropertyAccessorsMustFollowOrder><SA1213EventAccessorsMustFollowOrder>True</SA1213EventAccessorsMustFollowOrder></StyleCop.Ordering><CSShortenReferences>True</CSShortenReferences></Profile> Cleanup Simple Reformat 0 diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 1d4974d2..37a09046 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -582,6 +582,11 @@ namespace Vocaluxe.Lib.Draw /// public bool Unload() { + try + { + Close(); + } + catch {} //Dispose all textures foreach (KeyValuePair p in _D3DTextures) { diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 55a26fe5..6032aeb6 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -267,6 +267,11 @@ namespace Vocaluxe.Lib.Draw public bool Unload() { + try + { + Close(); + } + catch {} Dispose(); return true; } diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 87042f2d..2d963a42 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -440,6 +440,11 @@ namespace Vocaluxe.Lib.Draw public bool Unload() { + try + { + Close(); + } + catch {} STexture[] textures = new STexture[_Textures.Count]; _Textures.Values.CopyTo(textures, 0); for (int i = 0; i < _Textures.Count; i++)