From b1e28ae7bc8696ce76f71156551598d7728ebf13 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Wed, 24 Apr 2013 00:41:08 +0200 Subject: [PATCH] More refactoring (mainly LINQ) --- .../PartyModeChallenge/CPartyModeChallenge.cs | 2 +- .../CPartyScreenChallengeMain.cs | 2 +- .../CChallengeRounds.cs | 44 +- .../CPartyModeChallengeMedley.cs | 19 +- .../CPartyScreenChallengeMedleyMain.cs | 4 +- .../CPartyScreenChallengeMedleyNames.cs | 8 +- .../PartyModeTicTacToe/CPartyModeTicTacToe.cs | 25 +- .../CPartyScreenTicTacToeMain.cs | 2 +- .../CPartyScreenTicTacToeNames.cs | 28 +- Vocaluxe/Base/CBackgroundMusic.cs | 8 +- Vocaluxe/Base/CDataBase.cs | 20 - Vocaluxe/Base/CFont.cs | 23 +- Vocaluxe/Base/CGraphics.cs | 8 - Vocaluxe/Base/CSongs.cs | 27 +- Vocaluxe/Base/CUtility.cs | 39 +- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 2 +- Vocaluxe/Lib/Input/CHIDAPI.cs | 22 +- Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs | 4 +- Vocaluxe/Lib/Sound/COpenALPlay.cs | 8 +- Vocaluxe/Lib/Sound/IRecord.cs | 2 + Vocaluxe/Lib/Sound/Portaudio/PortAudio.cs | 9 +- Vocaluxe/Lib/Video/CVideoDecoder.cs | 8 +- .../Video/Gstreamer/CGstreamerVideoWrapper.cs | 2 - Vocaluxe/Lib/Webcam/CAForgeNet.cs | 3 - Vocaluxe/Lib/Webcam/IWebcam.cs | 1 - Vocaluxe/Screens/CScreenHighscore.cs | 9 +- Vocaluxe/Screens/CScreenOptionsSound.cs | 2 - Vocaluxe/Screens/CScreenOptionsTheme.cs | 5 - Vocaluxe/Screens/CScreenProfiles.cs | 2 +- Vocaluxe/Screens/CScreenSing.cs | 4 +- Vocaluxe/Screens/CScreenSong.cs | 32 +- Vocaluxe/Screens/CScreenTest.cs | 35 +- VocaluxeLib/Menu/CButton.cs | 114 ++--- VocaluxeLib/Menu/CPlaylist.cs | 445 +++++++++--------- VocaluxeLib/Menu/CSelectSlide.cs | 2 +- VocaluxeLib/Menu/CText.cs | 12 +- VocaluxeLib/Menu/Enums.cs | 10 + VocaluxeLib/Menu/SingNotes/CNotes.cs | 24 +- VocaluxeLib/Menu/SingNotes/CSingNotes.cs | 27 +- VocaluxeLib/Menu/SongMenu/CSong.cs | 10 +- .../Menu/SongMenu/CSongMenuFramework.cs | 6 +- .../Menu/SongMenu/CSongMenuTileBoard.cs | 21 +- VocaluxeLib/Menu/Structs.cs | 70 +-- 43 files changed, 488 insertions(+), 662 deletions(-) diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index e94d81b3..500c3551 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -452,7 +452,7 @@ namespace VocaluxeLib.PartyModes.Challenge public override void SongSelected(int songID) { - EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + const EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; CBase.Game.Reset(); CBase.Game.ClearSongs(); diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs index b0cf21bd..edd15420 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs @@ -93,7 +93,7 @@ namespace VocaluxeLib.PartyModes.Challenge private SRectF _PlayerTableScrollArea; private int _RoundsTableOffset; private int _PlayerTableOffset; - private int _NumPlayerVisible = 10; + private const int _NumPlayerVisible = 10; private int _NumRoundsVisible = 3; public CPartyScreenChallengeMain() diff --git a/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs b/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs index 7b6310c1..2a3bc286 100644 --- a/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs +++ b/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Linq; namespace VocaluxeLib.PartyModes.ChallengeMedley { @@ -27,7 +28,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private readonly Random _Rand; private readonly int _NumPlayer; - public List Rounds; + public readonly List Rounds; public CChallengeRounds(int numRounds, int numPlayer, int numPlayerAtOnce) { @@ -72,12 +73,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley numPlayed[playerIndex]++; } - int max = 0; - foreach (int p in numPlayed) - { - if (p > max) - max = p; - } + int max = numPlayed.Max(); int num = Rounds[0].Player.Count; List result = new List(); @@ -162,28 +158,19 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley List combsFiltered = new List(); if (playerNrDemand != null) { - for (int i = 0; i < _Combs.Count; i++) - { - if (_Combs[i].IsAvailableAll(playerNrDemand)) - combsFiltered.Add(_Combs[i]); - } + combsFiltered.AddRange(_Combs.Where(t => t.IsAvailableAll(playerNrDemand))); } //1st fallback if (playerNrDemand != null && combsFiltered.Count == 0) { - for (int i = 0; i < _Combs.Count; i++) - { - if (_Combs[i].IsAvailableSomeone(playerNrDemand)) - combsFiltered.Add(_Combs[i]); - } + combsFiltered.AddRange(_Combs.Where(t => t.IsAvailableSomeone(playerNrDemand))); } //2nd fallback if (combsFiltered.Count == 0) { - for (int i = 0; i < _Combs.Count; i++) - combsFiltered.Add(_Combs[i]); + combsFiltered.AddRange(_Combs); } int num = combsFiltered.Count; @@ -220,7 +207,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public class CCombination { - public List Player; + public readonly List Player; public CCombination() { @@ -229,28 +216,17 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public bool IsAvailable(int playerIndex) { - foreach (int p in Player) - { - if (p == playerIndex) - return true; - } - return false; + return Player.Any(p => p == playerIndex); } public bool IsAvailableAll(IEnumerable playerIndices) { - bool result = true; - foreach (int p in playerIndices) - result &= IsAvailable(p); - return result; + return playerIndices.All(IsAvailable); } public bool IsAvailableSomeone(IEnumerable playerIndices) { - bool result = false; - foreach (int p in playerIndices) - result |= IsAvailable(p); - return result; + return playerIndices.Any(IsAvailable); } } } \ No newline at end of file diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index 4b549c4e..76d3fd64 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -59,7 +59,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public int Position; public int PlayerID; public int NumPlayed; - public int NumRounds; public int NumWon; public int NumSingPoints; public int NumGamePoints; @@ -102,7 +101,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public struct SFromScreenNames { public bool FadeToConfig; - public bool FadeToMain; public List ProfileIDs; } @@ -518,8 +516,8 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley if (CBase.Songs.GetNumVisibleSongs() < _NumSongs) CBase.Songs.ResetPartySongSung(); - EGameMode gm = EGameMode.TR_GAMEMODE_MEDLEY; - List iDs = new List(); + const EGameMode gm = EGameMode.TR_GAMEMODE_MEDLEY; + List ids = new List(); CSong[] visSongs = CBase.Songs.GetSongsNotSung(); if (visSongs == null) @@ -534,11 +532,11 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley foreach (EGameMode mode in visSongs[i].AvailableGameModes) { if (mode == EGameMode.TR_GAMEMODE_MEDLEY) - iDs.Add(visSongs[i].ID); + ids.Add(visSongs[i].ID); } } - if (iDs.Count == 0) + if (ids.Count == 0) { CBase.Log.LogError("CPartyChallengeMedleyMode Error: There are no medley songs!"); CBase.Graphics.FadeTo(EScreens.ScreenParty); @@ -546,12 +544,12 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley } int s = 0; - while (s < _NumSongs && iDs.Count > 0) + while (s < _NumSongs && ids.Count > 0) { - int songID = iDs[CBase.Game.GetRandom(iDs.Count)]; + int songID = ids[CBase.Game.GetRandom(ids.Count)]; CBase.Game.AddSong(songID, gm); CBase.Songs.AddPartySongSung(songID); - iDs.Remove(songID); + ids.Remove(songID); s++; } return true; @@ -630,7 +628,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { for (int i = 0; i < _GameData.NumPlayer; i++) { - CResultTableRow row = new CResultTableRow {PlayerID = _GameData.ProfileIDs[i], NumPlayed = 0, NumRounds = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0}; + CResultTableRow row = new CResultTableRow {PlayerID = _GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0}; _GameData.ResultTable.Add(row); } @@ -690,7 +688,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley row.NumPlayed++; row.NumWon += points[i].Won; - row.NumRounds += 1; row.NumSingPoints += points[i].SingPoints; row.NumGamePoints += points[i].GamePoints; diff --git a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs index 7b465fb1..aa5b60a8 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs @@ -93,7 +93,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private SRectF _PlayerTableScrollArea; private int _RoundsTableOffset; private int _PlayerTableOffset; - private int _NumPlayerVisible = 10; + private const int _NumPlayerVisible = 10; private int _NumRoundsVisible = 3; public CPartyScreenChallengeMedleyMain() @@ -598,7 +598,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley row.Pos.Text = _GameState.ResultTable[i + _PlayerTableOffset].Position + "."; row.Name.Text = profiles[_GameState.ResultTable[i + _PlayerTableOffset].PlayerID].PlayerName; - row.Rounds.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumRounds.ToString(); + row.Rounds.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumPlayed.ToString(); row.Won.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumWon.ToString(); row.SingPoints.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumSingPoints.ToString(); row.GamePoints.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumGamePoints.ToString(); diff --git a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs index 9617fa42..8ca5bfec 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs @@ -55,7 +55,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private const int _PlayerChooseButtonsFirstY = 105; private const int _PlayerChooseButtonsSpaceH = 15; private const int _PlayerChooseButtonsSpaceW = 25; - private int _PlayerChooseButtonsOffset = 0; + private const int _PlayerChooseButtonsOffset = 0; private CStatic _ChooseAvatarStatic; private bool _SelectingMouseActive; @@ -88,7 +88,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _ThemeButtons = new string[] {_ButtonBack, _ButtonNext, _ButtonPlayerDestination, _ButtonPlayerChoose}; _Data = new SDataFromScreen(); - SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, FadeToMain = false, ProfileIDs = new List()}; + SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, ProfileIDs = new List()}; _Data.ScreenNames = names; } @@ -339,7 +339,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private void _UpdateButtonPlayerChoose(int offset) { - int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH; + const int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH; if (offset < 0) offset = 0; @@ -501,14 +501,12 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private void _Back() { _Data.ScreenNames.FadeToConfig = true; - _Data.ScreenNames.FadeToMain = false; _PartyMode.DataFromScreen(ThemeName, _Data); } private void _Next() { _Data.ScreenNames.FadeToConfig = false; - _Data.ScreenNames.FadeToMain = true; _PartyMode.DataFromScreen(ThemeName, _Data); } } diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 750e1357..d403d7cb 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -81,8 +81,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe { public int CurrentRoundNr; public int Team; - public int NumPlayerTeam1; - public int NumPlayerTeam2; public int NumFields; public List Rounds; public List Songs; @@ -115,7 +113,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe public struct SFromScreenNames { public bool FadeToConfig; - public bool FadeToMain; public List ProfileIDsTeam1; public List ProfileIDsTeam2; } @@ -380,8 +377,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe CBase.Songs.ResetPartySongSung(); _GameData.CurrentRoundNr = 1; _ToScreenMain.CurrentRoundNr = 1; - _ToScreenMain.NumPlayerTeam1 = _GameData.NumPlayerTeam1; - _ToScreenMain.NumPlayerTeam2 = _GameData.NumPlayerTeam2; _ToScreenMain.NumFields = _GameData.NumFields; _ToScreenMain.ProfileIDsTeam1 = _GameData.ProfileIDsTeam1; _ToScreenMain.ProfileIDsTeam2 = _GameData.ProfileIDsTeam2; @@ -410,8 +405,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe _UpdateSongList(); _UpdatePlayerList(); _ToScreenMain.CurrentRoundNr = _GameData.CurrentRoundNr; - _ToScreenMain.NumPlayerTeam1 = _GameData.NumPlayerTeam1; - _ToScreenMain.NumPlayerTeam2 = _GameData.NumPlayerTeam2; _ToScreenMain.NumFields = _GameData.NumFields; _ToScreenMain.ProfileIDsTeam1 = _GameData.ProfileIDsTeam1; _ToScreenMain.ProfileIDsTeam2 = _GameData.ProfileIDsTeam2; @@ -588,23 +581,23 @@ namespace VocaluxeLib.PartyModes.TicTacToe case 1: { //Prepare Player-IDs - List iDs = new List(); + List ids = new List(); //Add IDs to team-list - while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && iDs.Count == 0) + while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && ids.Count == 0) { - if (iDs.Count == 0) + if (ids.Count == 0) { for (int i = 0; i < _GameData.NumPlayerTeam1; i++) - iDs.Add(i); + ids.Add(i); } if (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0]) { - int random = CBase.Game.GetRandom((iDs.Count - 1) * 10); + int random = CBase.Game.GetRandom((ids.Count - 1) * 10); int num = (int)Math.Round((double)random / 10); - if (num >= iDs.Count) - num = iDs.Count - 1; - _GameData.PlayerTeam1.Add(iDs[num]); - iDs.RemoveAt(num); + if (num >= ids.Count) + num = ids.Count - 1; + _GameData.PlayerTeam1.Add(ids[num]); + ids.RemoveAt(num); } } } diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index dd069796..a7dbf8e1 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -79,7 +79,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private List _Fields; private float _FieldFirstX = 25; private float _FieldFirstY = 25; - private int _FieldSpace = 10; + private const int _FieldSpace = 10; private float _FieldSize = 100; private int _PreviewStream = -1; diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs index 2025cdf7..588cc22f 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs @@ -93,7 +93,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _ThemeButtons = new string[] {_ButtonBack, _ButtonNext, _ButtonPlayerDestination, _ButtonPlayerChoose, _ButtonPlayerChooseScrollUp, _ButtonPlayerChooseScrollDown}; _Data = new SDataFromScreen(); - SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, FadeToMain = false, ProfileIDsTeam1 = new List(), ProfileIDsTeam2 = new List()}; + SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, ProfileIDsTeam1 = new List(), ProfileIDsTeam2 = new List()}; _Data.ScreenNames = names; } @@ -403,7 +403,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _UpdateButtonPlayerChoose(int offset) { - int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH; + const int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH; if (offset < 0) offset = 0; @@ -446,27 +446,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe //Show profile only if active if (CBase.Profiles.GetProfiles()[i].Active == EOffOn.TR_CONFIG_ON) { - visible = true; - - for (int p = 0; p < _Data.ScreenNames.ProfileIDsTeam1.Count; p++) - { - //Don't show profile if is selected - if (_Data.ScreenNames.ProfileIDsTeam1[p] == i) - { - visible = false; - break; - } - } - - for (int p = 0; p < _Data.ScreenNames.ProfileIDsTeam2.Count; p++) - { - //Don't show profile if is selected - if (_Data.ScreenNames.ProfileIDsTeam2[p] == i) - { - visible = false; - break; - } - } + visible = _Data.ScreenNames.ProfileIDsTeam1.All(t => t != i) && _Data.ScreenNames.ProfileIDsTeam2.All(t => t != i); } if (visible) _PlayerChooseButtonsVisibleProfiles.Add(i); @@ -642,14 +622,12 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _Back() { _Data.ScreenNames.FadeToConfig = true; - _Data.ScreenNames.FadeToMain = false; _PartyMode.DataFromScreen(ThemeName, _Data); } private void _Next() { _Data.ScreenNames.FadeToConfig = false; - _Data.ScreenNames.FadeToMain = true; _PartyMode.DataFromScreen(ThemeName, _Data); } } diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index d4679b96..0aa110b2 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using Vocaluxe.Base; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -477,12 +478,7 @@ namespace Vocaluxe.Base private static bool _IsBackgroundFile(CPlaylistElement element) { - foreach (CPlaylistElement elements in _BGMusicFileNames) - { - if (elements.MusicFilePath == element.MusicFilePath) - return true; - } - return false; + return _BGMusicFileNames.Any(elements => elements.MusicFilePath == element.MusicFilePath); } private static void _LoadVideo() diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index d44dce78..25bd8251 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -283,26 +283,6 @@ namespace Vocaluxe.Base return _GetDataBaseSongID(song.Artist, song.Title, 0, command); } - private static int _GetDataBaseSongID(string artist, string title, string filePath, int defNumPlayed) - { - using (SQLiteConnection connection = new SQLiteConnection()) - { - connection.ConnectionString = "Data Source=" + filePath; - - try - { - connection.Open(); - } - catch (Exception) - { - return -1; - } - - using (SQLiteCommand command = new SQLiteCommand(connection)) - return _GetDataBaseSongID(artist, title, defNumPlayed, command); - } - } - private static int _GetDataBaseSongID(string artist, string title, int defNumPlayed, SQLiteCommand command) { command.CommandText = "SELECT id FROM Songs WHERE [Title] = @title AND [Artist] = @artist"; diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/CFont.cs index 2495eb4f..68a8b44d 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/CFont.cs @@ -23,6 +23,7 @@ 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; @@ -39,8 +40,7 @@ namespace Vocaluxe.Base } public STexture Texture; - public char Chr; - public int Width; + public readonly int Width; public CGlyph(char chr, float maxHigh) { @@ -110,7 +110,6 @@ namespace Vocaluxe.Base * */ Texture = CDraw.AddTexture(bmp); //bmp.Save("test.png", ImageFormat.Png); - Chr = chr; Width = (int)((1f + outline / 2f) * sizeB.Width * Texture.Width / factor / bmp.Width); g.Dispose(); } @@ -158,7 +157,7 @@ namespace Vocaluxe.Base private FontFamily _Family; private readonly float _Sizeh; - public string FilePath; + public readonly string FilePath; public CFont(string file) { @@ -550,25 +549,15 @@ namespace Vocaluxe.Base public static float GetTextWidth(string text) { - float dx = 0; CFont font = _GetCurrentFont(); - foreach (char chr in text) - dx += font.GetWidth(chr); - return dx; + return text.Sum(chr => font.GetWidth(chr)); } public static float GetTextHeight(string text) { //return TextRenderer.MeasureText(text, GetFont()).Height; - float h = 0f; CFont font = _GetCurrentFont(); - foreach (char chr in text) - { - float hh = font.GetHeight(chr); - if (hh > h) - h = hh; - } - return h; + return text==""?0:text.Select(font.GetHeight).Max(); } private static void _LoadFontFiles(CXMLReader xmlReader, string fontFolder, string themeName = "", int partyModeId = -1) @@ -769,7 +758,7 @@ namespace Vocaluxe.Base private static void _BuildGlyphs() { - string text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWGXZ1234567890"; + const string text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWGXZ1234567890"; for (int i = 0; i < _Fonts.Count; i++) { diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 84f51c5a..a6743486 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -28,14 +28,6 @@ using VocaluxeLib.PartyModes; namespace Vocaluxe.Base { - enum EPopupScreens - { - PopupPlayerControl = 0, - PopupVolumeControl = 1, - - NoPopup = -1 - } - class CCursor { private readonly Stopwatch _CursorFadingTimer; diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 39ae8467..bdde132d 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -19,7 +19,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics; +using System.Linq; using System.Threading; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -28,7 +28,7 @@ namespace Vocaluxe.Base { public struct SSongPointer { - public int SongID; + public readonly int SongID; public string SortString; public int CatIndex; @@ -56,11 +56,9 @@ namespace Vocaluxe.Base private static int _CatIndex = -1; private static readonly List _CategoriesForRandom = new List(); - private static readonly Stopwatch _CoverLoadTimer = new Stopwatch(); - - public static CSongFilter Filter = new CSongFilter(); - public static CSongSorter Sorter = new CSongSorter(); - public static CSongCategorizer Categorizer = new CSongCategorizer(); + public static readonly CSongFilter Filter = new CSongFilter(); + public static readonly CSongSorter Sorter = new CSongSorter(); + public static readonly CSongCategorizer Categorizer = new CSongCategorizer(); private static Thread _CoverLoaderThread; @@ -93,13 +91,7 @@ namespace Vocaluxe.Base { get { - int result = 0; - foreach (SSongPointer sp in Sorter.SortedSongs) - { - if (sp.Visible) - result++; - } - return result; + return Sorter.SortedSongs.Count(sp => sp.Visible); } } @@ -210,12 +202,7 @@ namespace Vocaluxe.Base public static CSong GetSong(int songID) { - foreach (CSong song in _Songs) - { - if (song.ID == songID) - return song; - } - return null; + return _Songs.FirstOrDefault(song => song.ID == songID); } public static void AddPartySongSung(int songID) diff --git a/Vocaluxe/Base/CUtility.cs b/Vocaluxe/Base/CUtility.cs index 9dbce203..d811eee6 100644 --- a/Vocaluxe/Base/CUtility.cs +++ b/Vocaluxe/Base/CUtility.cs @@ -171,7 +171,9 @@ namespace Vocaluxe.Base _KeyPressed = true; } +// ReSharper disable UnusedParameter.Global public void KeyUp(KeyEventArgs e) +// ReSharper restore UnusedParameter.Global { _CheckModifiers(); _KeyPressed = false; @@ -206,9 +208,7 @@ namespace Vocaluxe.Base private readonly Object _CopyLock = new Object(); - private bool _ModAlt; - private bool _ModCtrl; - private bool _ModShift; + private EModifier _Mod; private readonly Stopwatch _Timer; @@ -216,22 +216,19 @@ namespace Vocaluxe.Base public CMouse() { - _ModAlt = false; - _ModCtrl = false; - _ModShift = false; - _EventsPool = new List(); _CurrentPool = new List(); _Timer = new Stopwatch(); } - private void _Add(bool alt, bool shift, bool ctrl, int x, int y, bool lb, bool ld, bool rb, int wheel, bool lbh, bool rbh, bool mb, bool mbh) + private void _Add(int x, int y, bool lb, bool ld, bool rb, int wheel, bool lbh, bool rbh, bool mb, bool mbh) { + _CheckModifiers(); x = (int)(x * (float)CSettings.RenderW / CDraw.GetScreenWidth()); y = (int)(y * (float)CSettings.RenderH / CDraw.GetScreenHeight()); - SMouseEvent pool = new SMouseEvent(ESender.Mouse, alt, shift, ctrl, x, y, lb, ld, rb, -wheel / 120, lbh, rbh, mb, mbh); + SMouseEvent pool = new SMouseEvent(ESender.Mouse, _Mod, x, y, lb, ld, rb, -wheel / 120, lbh, rbh, mb, mbh); lock (_CopyLock) { @@ -247,30 +244,28 @@ namespace Vocaluxe.Base private void _CheckModifiers() { Keys keys = Control.ModifierKeys; + _Mod = EModifier.None; - _ModShift = (keys & Keys.Shift) == Keys.Shift; - _ModAlt = (keys & Keys.Alt) == Keys.Alt; - _ModCtrl = (keys & Keys.Control) == Keys.Control; + if ((keys & Keys.Shift) != 0) + _Mod |= EModifier.Shift; + if ((keys & Keys.Alt) != 0) + _Mod |= EModifier.Alt; + if ((keys & Keys.Control) != 0) + _Mod |= EModifier.Ctrl; } public void MouseMove(MouseEventArgs e) { - _CheckModifiers(); - _Add(_ModAlt, _ModShift, _ModCtrl, e.X, e.Y, false, false, false, e.Delta, e.Button == MouseButtons.Left, e.Button == MouseButtons.Right, - false, e.Button == MouseButtons.Middle); + _Add(e.X, e.Y, false, false, false, 0, e.Button == MouseButtons.Left, e.Button == MouseButtons.Right, false, e.Button == MouseButtons.Middle); } public void MouseWheel(MouseEventArgs e) { - _CheckModifiers(); - _Add(_ModAlt, _ModShift, _ModCtrl, e.X, e.Y, false, false, false, e.Delta, e.Button == MouseButtons.Left, e.Button == MouseButtons.Right, - false, e.Button == MouseButtons.Middle); + _Add(e.X, e.Y, false, false, false, e.Delta, false, false, false, false); } public void MouseDown(MouseEventArgs e) { - _CheckModifiers(); - bool lb = e.Button == MouseButtons.Left; bool ld = false; if (lb) @@ -289,11 +284,13 @@ namespace Vocaluxe.Base else _Timer.Reset(); - _Add(_ModAlt, _ModShift, _ModCtrl, e.X, e.Y, lb, ld, e.Button == MouseButtons.Right, e.Delta, false, false, + _Add(e.X, e.Y, lb, ld, e.Button == MouseButtons.Right, e.Delta, false, false, e.Button == MouseButtons.Middle, false); } +// ReSharper disable UnusedParameter.Global public void MouseUp(MouseEventArgs e) +// ReSharper restore UnusedParameter.Global { //CheckModifiers(); //Add(_ModALT, _ModSHIFT, _ModCTRL, e.X, e.Y, e.Button == MouseButtons.Left, e.Button == MouseButtons.Right, e.Delta); diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 7c9b83bb..78203ff0 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -330,7 +330,7 @@ namespace Vocaluxe.Lib.Draw public void MakeScreenShot() { - string file = "Screenshot_"; + const string file = "Screenshot_"; string path = Path.Combine(Environment.CurrentDirectory, CSettings.FolderScreenshots); int i = 0; diff --git a/Vocaluxe/Lib/Input/CHIDAPI.cs b/Vocaluxe/Lib/Input/CHIDAPI.cs index 106994f7..cfdc847b 100644 --- a/Vocaluxe/Lib/Input/CHIDAPI.cs +++ b/Vocaluxe/Lib/Input/CHIDAPI.cs @@ -26,17 +26,19 @@ namespace Vocaluxe.Lib.Input [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct SHIDDeviceInfo { - [MarshalAs(UnmanagedType.LPTStr)] public String Path; - public ushort VendorString; - public ushort ProductID; - public String SerialNumber; - public ushort ReleaseNumber; - public String ManufacturerString; - public String ProductString; - public ushort UsagePage; - public ushort Usage; - public int InterfaceNumber; +// ReSharper disable MemberCanBePrivate.Global + [MarshalAs(UnmanagedType.LPTStr)] public readonly String Path; + public readonly ushort VendorString; + public readonly ushort ProductID; + public readonly String SerialNumber; + public readonly ushort ReleaseNumber; + public readonly String ManufacturerString; + public readonly String ProductString; + public readonly ushort UsagePage; + public readonly ushort Usage; + public readonly int InterfaceNumber; internal IntPtr Next; + // ReSharper restore MemberCanBePrivate.Global } public static class CHIDApi diff --git a/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs b/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs index 98cef67b..867458d6 100644 --- a/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs +++ b/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs @@ -277,12 +277,12 @@ namespace Vocaluxe.Lib.Input.WiiMote if (!lb && !rb && (p.X != _OldPosition.X || p.Y != _OldPosition.Y)) { - mpool = new SMouseEvent(ESender.WiiMote, false, false, false, x, y, false, false, false, wheel, lbh, false, false, false); + mpool = new SMouseEvent(ESender.WiiMote, EModifier.None, x, y, false, false, false, wheel, lbh, false, false, false); trigger = true; } else if (lb || rb) { - mpool = new SMouseEvent(ESender.WiiMote, false, false, false, x, y, lb, false, rb, wheel, false, false, false, false); + mpool = new SMouseEvent(ESender.WiiMote, EModifier.None, x, y, lb, false, rb, wheel, false, false, false, false); trigger = true; } diff --git a/Vocaluxe/Lib/Sound/COpenALPlay.cs b/Vocaluxe/Lib/Sound/COpenALPlay.cs index fffbd644..f1fe898b 100644 --- a/Vocaluxe/Lib/Sound/COpenALPlay.cs +++ b/Vocaluxe/Lib/Sound/COpenALPlay.cs @@ -17,6 +17,7 @@ // */ #endregion +using System.Linq; using OpenTK.Audio; using System; using System.Collections.Generic; @@ -312,12 +313,7 @@ namespace Vocaluxe.Lib.Sound private bool _AlreadyAdded(int stream) { - foreach (SAudioStreams st in _Streams) - { - if (st.Handle == stream) - return true; - } - return false; + return _Streams.Any(st => st.Handle == stream); } private int _GetStreamIndex(int stream) diff --git a/Vocaluxe/Lib/Sound/IRecord.cs b/Vocaluxe/Lib/Sound/IRecord.cs index 978fe81d..6d618901 100644 --- a/Vocaluxe/Lib/Sound/IRecord.cs +++ b/Vocaluxe/Lib/Sound/IRecord.cs @@ -46,7 +46,9 @@ namespace Vocaluxe.Lib.Sound public string InputName; public int Channel; +// ReSharper disable UnusedParameter.Local public SMicConfig(int dummy) +// ReSharper restore UnusedParameter.Local { DeviceName = String.Empty; DeviceDriver = String.Empty; diff --git a/Vocaluxe/Lib/Sound/Portaudio/PortAudio.cs b/Vocaluxe/Lib/Sound/Portaudio/PortAudio.cs index e8329a1a..a69b6a18 100644 --- a/Vocaluxe/Lib/Sound/Portaudio/PortAudio.cs +++ b/Vocaluxe/Lib/Sound/Portaudio/PortAudio.cs @@ -28,7 +28,9 @@ namespace Vocaluxe.Lib.Sound.PortAudio */ // ReSharper disable UnusedMember.Global - + // ReSharper disable FieldCanBeMadeReadOnly.Global +// ReSharper disable MemberCanBePrivate.Global + public static class CPortAudio { #region **** PORTAUDIO CALLBACKS **** @@ -50,7 +52,8 @@ namespace Vocaluxe.Lib.Sound.PortAudio public struct SPaDeviceInfo { public int StructVersion; - [MarshalAs(UnmanagedType.LPStr)] public string Name; + [MarshalAs(UnmanagedType.LPStr)] + public string Name; public int HostApi; public int MaxInputChannels; public int MaxOutputChannels; @@ -552,5 +555,7 @@ namespace Vocaluxe.Lib.Sound.PortAudio #endregion } // ReSharper restore UnusedMember.Global + // ReSharper restore FieldCanBeMadeReadOnly.Global + // ReSharper restore MemberCanBePrivate.Global } \ No newline at end of file diff --git a/Vocaluxe/Lib/Video/CVideoDecoder.cs b/Vocaluxe/Lib/Video/CVideoDecoder.cs index 2a23df81..53d96bef 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoder.cs @@ -18,6 +18,7 @@ #endregion using System.Collections.Generic; +using System.Linq; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video @@ -79,12 +80,7 @@ namespace Vocaluxe.Lib.Video protected bool _AlreadyAdded(int streamID) { - foreach (SVideoStreams st in _Streams) - { - if (st.Handle == streamID) - return true; - } - return false; + return _Streams.Any(st => st.Handle == streamID); } protected int _GetStreamIndex(int streamID) diff --git a/Vocaluxe/Lib/Video/Gstreamer/CGstreamerVideoWrapper.cs b/Vocaluxe/Lib/Video/Gstreamer/CGstreamerVideoWrapper.cs index c5cb5020..88c634d3 100644 --- a/Vocaluxe/Lib/Video/Gstreamer/CGstreamerVideoWrapper.cs +++ b/Vocaluxe/Lib/Video/Gstreamer/CGstreamerVideoWrapper.cs @@ -36,7 +36,6 @@ namespace Vocaluxe.Lib.Video.Gstreamer public struct SManagedFrame { public byte[] Buffer; - public int Size; public int Width; public int Height; public float Videotime; @@ -102,7 +101,6 @@ namespace Vocaluxe.Lib.Video.Gstreamer SManagedFrame m; m.Buffer = buffer; m.Height = f.Height; - m.Size = f.Size; m.Videotime = f.Videotime; m.Width = f.Width; return m; diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 446cf681..c53b16c6 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -87,17 +87,14 @@ namespace Vocaluxe.Lib.Webcam public bool Init() { _WebcamDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); - int num = 0; foreach (FilterInfo info in _WebcamDevices) { SWebcamDevice device = new SWebcamDevice { - ID = num, Name = info.Name, MonikerString = info.MonikerString, Capabilities = new List() }; - num++; VideoCaptureDevice tmpdev = new VideoCaptureDevice(info.MonikerString); foreach (VideoCapabilities capabilities in tmpdev.VideoCapabilities) diff --git a/Vocaluxe/Lib/Webcam/IWebcam.cs b/Vocaluxe/Lib/Webcam/IWebcam.cs index 15dd403d..32804bfc 100644 --- a/Vocaluxe/Lib/Webcam/IWebcam.cs +++ b/Vocaluxe/Lib/Webcam/IWebcam.cs @@ -25,7 +25,6 @@ namespace Vocaluxe.Lib.Webcam { struct SWebcamDevice { - public int ID; public string Name; public string MonikerString; public List Capabilities; diff --git a/Vocaluxe/Screens/CScreenHighscore.cs b/Vocaluxe/Screens/CScreenHighscore.cs index 83bfe915..b8eb3d14 100644 --- a/Vocaluxe/Screens/CScreenHighscore.cs +++ b/Vocaluxe/Screens/CScreenHighscore.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -207,13 +208,7 @@ namespace Vocaluxe.Screens private bool _IsNewEntry(int id) { - for (int i = 0; i < _NewEntryIDs.Count; i++) - { - if (_NewEntryIDs[i] == id) - return true; - } - - return false; + return _NewEntryIDs.Any(t => t == id); } private void _AddScoresToDB() diff --git a/Vocaluxe/Screens/CScreenOptionsSound.cs b/Vocaluxe/Screens/CScreenOptionsSound.cs index 370b0694..8d6ddfa0 100644 --- a/Vocaluxe/Screens/CScreenOptionsSound.cs +++ b/Vocaluxe/Screens/CScreenOptionsSound.cs @@ -40,7 +40,6 @@ namespace Vocaluxe.Screens private const string _ButtonExit = "ButtonExit"; private int _BackgroundMusicVolume; - private EOffOn _BackgroundMusic; public override void Init() { @@ -142,7 +141,6 @@ namespace Vocaluxe.Screens public override void OnShow() { base.OnShow(); - _BackgroundMusic = CConfig.BackgroundMusic; _BackgroundMusicVolume = CConfig.BackgroundMusicVolume; _SelectSlides[_SelectSlideGameMusicVolume].Selection = CConfig.GameMusicVolume / 5; diff --git a/Vocaluxe/Screens/CScreenOptionsTheme.cs b/Vocaluxe/Screens/CScreenOptionsTheme.cs index 199170c8..5beca6e7 100644 --- a/Vocaluxe/Screens/CScreenOptionsTheme.cs +++ b/Vocaluxe/Screens/CScreenOptionsTheme.cs @@ -242,10 +242,5 @@ namespace Vocaluxe.Screens _ResumeBG(); } } - - private void _AfterSkinReload() - { - _Active = true; - } } } \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index 7f8647ad..87ff1d71 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -259,7 +259,7 @@ namespace Vocaluxe.Screens private void _OnSaveSnapshot() { - string filename = "snapshot"; + const string filename = "snapshot"; int i = 0; while (File.Exists(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"))) i++; diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index f8530b27..6b297c31 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -90,7 +90,7 @@ namespace Vocaluxe.Screens private int _CurrentBeat; private int _CurrentStream = -1; //private int _NextStream = -1; - private float _Volume = 100f; + private const float _Volume = 100f; private int _CurrentVideo = -1; private EAspect _VideoAspect = EAspect.Crop; private STexture _CurrentVideoTexture = new STexture(-1); @@ -769,7 +769,7 @@ namespace Vocaluxe.Screens for (int j = 0; j < CGame.NumPlayer; j++) { if (CGame.Player[j].LineNr == i) - _SingNotes[_SingBars].AddLine(_NoteLines[j], line, nr, j); + _SingNotes[_SingBars].AddLine(_NoteLines[j], line, nr); } if (i == 0 && !song.IsDuet || i == 1 && song.IsDuet) diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index f9b69d1d..b626d906 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -853,13 +853,13 @@ namespace Vocaluxe.Screens CGame.Reset(); CGame.ClearSongs(); - List iDs = new List(); + List ids = new List(); for (int i = 0; i < CSongs.AllSongs.Length; i++) - iDs.Add(i); + ids.Add(i); - while (iDs.Count > 0) + while (ids.Count > 0) { - int songNr = iDs[CGame.Rand.Next(iDs.Count)]; + int songNr = ids[CGame.Rand.Next(ids.Count)]; EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; if (CSongs.AllSongs[songNr].IsDuet) @@ -867,7 +867,7 @@ namespace Vocaluxe.Screens CGame.AddSong(songNr, gm); - iDs.Remove(songNr); + ids.Remove(songNr); } if (CGame.GetNumSongs() > 0) @@ -879,13 +879,13 @@ namespace Vocaluxe.Screens CGame.Reset(); CGame.ClearSongs(); - List iDs = new List(); + List ids = new List(); for (int i = 0; i < CSongs.VisibleSongs.Length; i++) - iDs.Add(CSongs.VisibleSongs[i].ID); + ids.Add(CSongs.VisibleSongs[i].ID); - while (iDs.Count > 0) + while (ids.Count > 0) { - int songNr = iDs[CGame.Rand.Next(iDs.Count)]; + int songNr = ids[CGame.Rand.Next(ids.Count)]; EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; if (CSongs.AllSongs[songNr].IsDuet) @@ -893,7 +893,7 @@ namespace Vocaluxe.Screens CGame.AddSong(songNr, gm); - iDs.Remove(songNr); + ids.Remove(songNr); } if (CGame.GetNumSongs() > 0) @@ -905,21 +905,21 @@ namespace Vocaluxe.Screens CGame.Reset(); CGame.ClearSongs(); - List iDs = new List(); + List ids = new List(); if (allSongs) { for (int i = 0; i < CSongs.AllSongs.Length; i++) - iDs.Add(i); + ids.Add(i); } else { for (int i = 0; i < CSongs.VisibleSongs.Length; i++) - iDs.Add(CSongs.VisibleSongs[i].ID); + ids.Add(CSongs.VisibleSongs[i].ID); } int s = 0; - while (s < numSongs && iDs.Count > 0) + while (s < numSongs && ids.Count > 0) { - int songNr = iDs[CGame.Rand.Next(iDs.Count)]; + int songNr = ids[CGame.Rand.Next(ids.Count)]; foreach (EGameMode gm in CSongs.AllSongs[songNr].AvailableGameModes) { @@ -931,7 +931,7 @@ namespace Vocaluxe.Screens } } - iDs.Remove(songNr); + ids.Remove(songNr); } if (CGame.GetNumSongs() > 0) diff --git a/Vocaluxe/Screens/CScreenTest.cs b/Vocaluxe/Screens/CScreenTest.cs index 159594ad..fbc91fbb 100644 --- a/Vocaluxe/Screens/CScreenTest.cs +++ b/Vocaluxe/Screens/CScreenTest.cs @@ -18,7 +18,6 @@ #endregion using System; -using System.IO; using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -33,7 +32,9 @@ namespace Vocaluxe.Screens get { return 1; } } +/* private int _TestMusic = -1; +*/ public override bool HandleInput(SKeyEvent keyEvent) { @@ -85,23 +86,25 @@ namespace Vocaluxe.Screens return true; } - private void _PlayFile() - { - if (_TestMusic == -1) - _TestMusic = CSound.Load(Path.Combine(Environment.CurrentDirectory, "Test.mp3")); + /* + private void _PlayFile() + { + if (_TestMusic == -1) + _TestMusic = CSound.Load(Path.Combine(Environment.CurrentDirectory, "Test.mp3")); - CSound.Play(_TestMusic); - CSound.Fade(_TestMusic, 100f, 2f); - } + CSound.Play(_TestMusic); + CSound.Fade(_TestMusic, 100f, 2f); + } - private void _PauseFile() - { - CSound.Pause(_TestMusic); - } - private void _FadeAndPause() - { - CSound.FadeAndPause(_TestMusic, 0f, 2f); - } + private void _PauseFile() + { + CSound.Pause(_TestMusic); + } + + private void _FadeAndPause() + { + CSound.FadeAndPause(_TestMusic, 0f, 2f); + }*/ } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/CButton.cs b/VocaluxeLib/Menu/CButton.cs index a363dc1a..b3a69d15 100644 --- a/VocaluxeLib/Menu/CButton.cs +++ b/VocaluxeLib/Menu/CButton.cs @@ -45,17 +45,17 @@ namespace VocaluxeLib.Menu public SColorF Color; public SColorF SelColor; - public bool IsSelText; - public CText Text; - public CText SelText; + private bool _IsSelText; + public readonly CText Text; + private readonly CText _SelText; - public bool Reflection; - public float ReflectionSpace; - public float ReflectionHeight; + private bool _Reflection; + private float _ReflectionSpace; + private float _ReflectionHeight; - public bool SelReflection; - public float SelReflectionSpace; - public float SelReflectionHeight; + private bool _SelReflection; + private float _SelReflectionSpace; + private float _SelReflectionHeight; public bool Pressed; @@ -65,7 +65,7 @@ namespace VocaluxeLib.Menu set { Text.EditMode = value; - SelText.EditMode = value; + _SelText.EditMode = value; } } @@ -97,21 +97,21 @@ namespace VocaluxeLib.Menu Texture = new STexture(-1); SelTexture = new STexture(-1); - IsSelText = false; + _IsSelText = false; Text = new CText(_PartyModeID); - SelText = new CText(_PartyModeID); + _SelText = new CText(_PartyModeID); Selected = false; Visible = true; EditMode = false; Enabled = true; - Reflection = false; - ReflectionSpace = 0f; - ReflectionHeight = 0f; + _Reflection = false; + _ReflectionSpace = 0f; + _ReflectionHeight = 0f; - SelReflection = false; - SelReflectionSpace = 0f; - SelReflectionHeight = 0f; + _SelReflection = false; + _SelReflectionSpace = 0f; + _SelReflectionHeight = 0f; } public CButton(CButton button) @@ -131,22 +131,22 @@ namespace VocaluxeLib.Menu Texture = button.Texture; SelTexture = button.SelTexture; - IsSelText = false; + _IsSelText = false; Text = new CText(button.Text); - SelText = new CText(button.SelText); + _SelText = new CText(button._SelText); Selected = false; Visible = true; EditMode = false; _ThemeLoaded = false; Enabled = button.Enabled; - Reflection = button.Reflection; - ReflectionHeight = button.ReflectionHeight; - ReflectionSpace = button.ReflectionSpace; + _Reflection = button._Reflection; + _ReflectionHeight = button._ReflectionHeight; + _ReflectionSpace = button._ReflectionSpace; - SelReflection = button.SelReflection; - SelReflectionHeight = button.SelReflectionHeight; - SelReflectionSpace = button.SelReflectionSpace; + _SelReflection = button._SelReflection; + _SelReflectionHeight = button._SelReflectionHeight; + _SelReflectionSpace = button._SelReflectionSpace; } public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader, int skinIndex) @@ -187,30 +187,30 @@ namespace VocaluxeLib.Menu Text.Z = Rect.Z; if (xmlReader.ItemExists(item + "/SText")) { - IsSelText = true; - _ThemeLoaded &= SelText.LoadTheme(item, "SText", xmlReader, skinIndex, true); - SelText.Z = Rect.Z; + _IsSelText = true; + _ThemeLoaded &= _SelText.LoadTheme(item, "SText", xmlReader, skinIndex, true); + _SelText.Z = Rect.Z; } //Reflections if (xmlReader.ItemExists(item + "/Reflection")) { - Reflection = true; - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Reflection/Space", ref ReflectionSpace); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Reflection/Height", ref ReflectionHeight); + _Reflection = true; + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Reflection/Space", ref _ReflectionSpace); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Reflection/Height", ref _ReflectionHeight); } else - Reflection = false; + _Reflection = false; if (xmlReader.ItemExists(item + "/SReflection")) { - SelReflection = true; - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SReflection/Space", ref SelReflectionSpace); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SReflection/Height", ref SelReflectionHeight); + _SelReflection = true; + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SReflection/Space", ref _SelReflectionSpace); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SReflection/Height", ref _SelReflectionHeight); } else - SelReflection = false; + _SelReflection = false; if (_ThemeLoaded) { @@ -264,28 +264,28 @@ namespace VocaluxeLib.Menu } Text.SaveTheme(writer); - if (IsSelText) - SelText.SaveTheme(writer); + if (_IsSelText) + _SelText.SaveTheme(writer); writer.WriteComment(" If exists:"); writer.WriteComment(" : Reflection Space"); writer.WriteComment(" : Reflection Height"); - if (Reflection) + if (_Reflection) { writer.WriteStartElement("Reflection"); - writer.WriteElementString("Space", ReflectionSpace.ToString("#0")); - writer.WriteElementString("Height", ReflectionHeight.ToString("#0")); + writer.WriteElementString("Space", _ReflectionSpace.ToString("#0")); + writer.WriteElementString("Height", _ReflectionHeight.ToString("#0")); writer.WriteEndElement(); } writer.WriteComment(" If exists:"); writer.WriteComment(" : Reflection Space of selected button"); writer.WriteComment(" : Reflection Height of selected button"); - if (SelReflection) + if (_SelReflection) { writer.WriteStartElement("SReflection"); - writer.WriteElementString("Space", ReflectionSpace.ToString("#0")); - writer.WriteElementString("Height", ReflectionHeight.ToString("#0")); + writer.WriteElementString("Space", _ReflectionSpace.ToString("#0")); + writer.WriteElementString("Height", _ReflectionHeight.ToString("#0")); writer.WriteEndElement(); } @@ -309,41 +309,41 @@ namespace VocaluxeLib.Menu CBase.Drawing.DrawTexture(texture, Rect, Color); - if (Reflection) + if (_Reflection) { - CBase.Drawing.DrawTextureReflection(texture, Rect, Color, Rect, ReflectionSpace, ReflectionHeight); - Text.DrawRelative(Rect.X, Rect.Y, ReflectionSpace, ReflectionHeight, Rect.H); + CBase.Drawing.DrawTextureReflection(texture, Rect, Color, Rect, _ReflectionSpace, _ReflectionHeight); + Text.DrawRelative(Rect.X, Rect.Y, _ReflectionSpace, _ReflectionHeight, Rect.H); } else Text.DrawRelative(Rect.X, Rect.Y); } - else if (!IsSelText) + else if (!_IsSelText) { texture = Texture.Index != -1 ? Texture : CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); CBase.Drawing.DrawTexture(texture, Rect, SelColor); - if (Reflection) + if (_Reflection) { - CBase.Drawing.DrawTextureReflection(texture, Rect, SelColor, Rect, ReflectionSpace, ReflectionHeight); - Text.DrawRelative(Rect.X, Rect.Y, ReflectionSpace, ReflectionHeight, Rect.H); + CBase.Drawing.DrawTextureReflection(texture, Rect, SelColor, Rect, _ReflectionSpace, _ReflectionHeight); + Text.DrawRelative(Rect.X, Rect.Y, _ReflectionSpace, _ReflectionHeight, Rect.H); } else Text.DrawRelative(Rect.X, Rect.Y); } - else if (IsSelText) + else if (_IsSelText) { texture = SelTexture.Index != -1 ? SelTexture : CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); CBase.Drawing.DrawTexture(texture, Rect, SelColor); - if (Reflection) + if (_Reflection) { - CBase.Drawing.DrawTextureReflection(texture, Rect, SelColor, Rect, ReflectionSpace, ReflectionHeight); - SelText.DrawRelative(Rect.X, Rect.Y, ReflectionSpace, ReflectionHeight, Rect.H); + CBase.Drawing.DrawTextureReflection(texture, Rect, SelColor, Rect, _ReflectionSpace, _ReflectionHeight); + _SelText.DrawRelative(Rect.X, Rect.Y, _ReflectionSpace, _ReflectionHeight, Rect.H); } else - SelText.DrawRelative(Rect.X, Rect.Y); + _SelText.DrawRelative(Rect.X, Rect.Y); } } diff --git a/VocaluxeLib/Menu/CPlaylist.cs b/VocaluxeLib/Menu/CPlaylist.cs index 73063abf..b1a4184e 100644 --- a/VocaluxeLib/Menu/CPlaylist.cs +++ b/VocaluxeLib/Menu/CPlaylist.cs @@ -500,56 +500,141 @@ namespace VocaluxeLib.Menu { if (keyEvent.KeyPressed && !Char.IsControl(keyEvent.Unicode)) _Theme.ButtonPlaylistName.Text.Text = _Theme.ButtonPlaylistName.Text.Text + keyEvent.Unicode; - else if (keyEvent.Key == Keys.Enter) + else switch (keyEvent.Key) { - CBase.Playlist.SetPlaylistName(ActivePlaylistID, _Theme.ButtonPlaylistName.Text.Text); - CBase.Playlist.SavePlaylist(ActivePlaylistID); - EditMode = EEditMode.None; - _Theme.ButtonPlaylistName.EditMode = false; - } - else if (keyEvent.Key == Keys.Escape) - { - _Theme.ButtonPlaylistName.Text.Text = CBase.Playlist.GetPlaylistName(ActivePlaylistID); - EditMode = EEditMode.None; - _Theme.ButtonPlaylistName.EditMode = false; - } - else if (keyEvent.Key == Keys.Back || keyEvent.Key == Keys.Delete) - { - if (_Theme.ButtonPlaylistName.Text.Text != "") - _Theme.ButtonPlaylistName.Text.Text = _Theme.ButtonPlaylistName.Text.Text.Remove(_Theme.ButtonPlaylistName.Text.Text.Length - 1); + case Keys.Enter: + CBase.Playlist.SetPlaylistName(ActivePlaylistID, _Theme.ButtonPlaylistName.Text.Text); + CBase.Playlist.SavePlaylist(ActivePlaylistID); + EditMode = EEditMode.None; + _Theme.ButtonPlaylistName.EditMode = false; + break; + case Keys.Escape: + _Theme.ButtonPlaylistName.Text.Text = CBase.Playlist.GetPlaylistName(ActivePlaylistID); + EditMode = EEditMode.None; + _Theme.ButtonPlaylistName.EditMode = false; + break; + case Keys.Delete: + case Keys.Back: + if (_Theme.ButtonPlaylistName.Text.Text != "") + _Theme.ButtonPlaylistName.Text.Text = _Theme.ButtonPlaylistName.Text.Text.Remove(_Theme.ButtonPlaylistName.Text.Text.Length - 1); + break; } + return true; } - else + if (CurrentPlaylistElement == -1 || _PlaylistElementContents.Count == 0) { - if (CurrentPlaylistElement == -1 || _PlaylistElementContents.Count == 0) - { - //no song is selected - _Interactions.HandleInput(keyEvent); - CurrentPlaylistElement = _GetSelectedSelectionNr(); + //no song is selected + _Interactions.HandleInput(keyEvent); + CurrentPlaylistElement = _GetSelectedSelectionNr(); - if (CurrentPlaylistElement != -1) - return true; - } - else if (CurrentPlaylistElement != -1) - { - //a song is selected - int scrollLimit = _PlaylistElements.Count / 2; + if (CurrentPlaylistElement != -1) + return true; + } + else if (CurrentPlaylistElement != -1) + { + //a song is selected + int scrollLimit = _PlaylistElements.Count / 2; - //special actions if a song is selected - switch (keyEvent.Key) - { - case Keys.Up: - if (keyEvent.ModShift) + //special actions if a song is selected + switch (keyEvent.Key) + { + case Keys.Up: + if (keyEvent.ModShift) + { + _Interactions.SetInteractionToSelectSlide(_PlaylistElements[0].SelectSlide); + _Interactions.HandleInput(keyEvent); + CurrentPlaylistElement = _GetSelectedSelectionNr(); + } + else if (CurrentPlaylistElement > scrollLimit || _PlaylistElementContents.Count == 0) + { + _Interactions.HandleInput(keyEvent); + CurrentPlaylistElement = _GetSelectedSelectionNr(); + } + else if (CurrentPlaylistElement <= scrollLimit) + { + if (Offset > 0) + { + Offset--; + Update(); + } + else { - _Interactions.SetInteractionToSelectSlide(_PlaylistElements[0].SelectSlide); _Interactions.HandleInput(keyEvent); CurrentPlaylistElement = _GetSelectedSelectionNr(); } - else if (CurrentPlaylistElement > scrollLimit || _PlaylistElementContents.Count == 0) + } + break; + + case Keys.Down: + if (keyEvent.ModShift) + { + for (int i = _PlaylistElements.Count - 1; i >= 0; i--) + { + if (_PlaylistElements[i].SelectSlide.Visible) + { + _Interactions.SetInteractionToSelectSlide(_PlaylistElements[0].SelectSlide); + _Interactions.HandleInput(keyEvent); + CurrentPlaylistElement = _GetSelectedSelectionNr(); + } + } + } + else if (CurrentPlaylistElement >= scrollLimit) + { + if (Offset < _PlaylistElementContents.Count - _PlaylistElements.Count) + { + Offset++; + Update(); + } + else { _Interactions.HandleInput(keyEvent); CurrentPlaylistElement = _GetSelectedSelectionNr(); } + } + else if (CurrentPlaylistElement < scrollLimit) + { + _Interactions.HandleInput(keyEvent); + CurrentPlaylistElement = _GetSelectedSelectionNr(); + } + break; + + case Keys.Delete: + CBase.Playlist.DeletePlaylistSong(ActivePlaylistID, _PlaylistElements[CurrentPlaylistElement].Content); + UpdatePlaylist(); + + if (Offset > 0) + Offset--; + + Update(); + + if (_PlaylistElementContents.Count - 1 < CurrentPlaylistElement) + CurrentPlaylistElement = _PlaylistElementContents.Count - 1; + + if (CurrentPlaylistElement != -1) + _Interactions.SetInteractionToSelectSlide(_PlaylistElements[CurrentPlaylistElement].SelectSlide); + break; + + case Keys.Back: + ClosePlaylist(); //really? or better global? + break; + + case Keys.Enter: + _StartPlaylistSong(CurrentPlaylistElement); + break; + + case Keys.Add: //move the selected song up + if (_PlaylistElementContents.Count > 1 && (CurrentPlaylistElement > 0 || Offset > 0)) + { + CBase.Playlist.MovePlaylistSongUp(ActivePlaylistID, CurrentPlaylistElement + Offset); + UpdatePlaylist(); + + SKeyEvent key = new SKeyEvent {Key = Keys.Up}; + + if (CurrentPlaylistElement > scrollLimit) + { + _Interactions.HandleInput(key); + CurrentPlaylistElement = _GetSelectedSelectionNr(); + } else if (CurrentPlaylistElement <= scrollLimit) { if (Offset > 0) @@ -559,26 +644,22 @@ namespace VocaluxeLib.Menu } else { - _Interactions.HandleInput(keyEvent); + _Interactions.HandleInput(key); CurrentPlaylistElement = _GetSelectedSelectionNr(); } } - break; + } + break; - case Keys.Down: - if (keyEvent.ModShift) - { - for (int i = _PlaylistElements.Count - 1; i >= 0; i--) - { - if (_PlaylistElements[i].SelectSlide.Visible) - { - _Interactions.SetInteractionToSelectSlide(_PlaylistElements[0].SelectSlide); - _Interactions.HandleInput(keyEvent); - CurrentPlaylistElement = _GetSelectedSelectionNr(); - } - } - } - else if (CurrentPlaylistElement >= scrollLimit) + case Keys.Subtract: //move the selected song down + if (_PlaylistElementContents.Count > 1 && CurrentPlaylistElement + Offset < _PlaylistElementContents.Count - 1) + { + CBase.Playlist.MovePlaylistSongDown(ActivePlaylistID, CurrentPlaylistElement + Offset); + UpdatePlaylist(); + + SKeyEvent key = new SKeyEvent {Key = Keys.Down}; + + if (CurrentPlaylistElement >= scrollLimit) { if (Offset < _PlaylistElementContents.Count - _PlaylistElements.Count) { @@ -587,203 +668,127 @@ namespace VocaluxeLib.Menu } else { - _Interactions.HandleInput(keyEvent); + _Interactions.HandleInput(key); CurrentPlaylistElement = _GetSelectedSelectionNr(); } } else if (CurrentPlaylistElement < scrollLimit) { - _Interactions.HandleInput(keyEvent); + _Interactions.HandleInput(key); CurrentPlaylistElement = _GetSelectedSelectionNr(); } - break; + } + break; - case Keys.Delete: - CBase.Playlist.DeletePlaylistSong(ActivePlaylistID, _PlaylistElements[CurrentPlaylistElement].Content); - UpdatePlaylist(); + case Keys.PageUp: //scroll up + if (_PlaylistElementContents.Count > 0) + { + Offset -= _PlaylistElements.Count; - if (Offset > 0) - Offset--; + if (Offset < 0) + Offset = 0; + + Update(); + CurrentPlaylistElement = 0; + } + break; + + case Keys.PageDown: //scroll down + if (_PlaylistElementContents.Count > 0) + { + Offset += _PlaylistElements.Count; + + if (Offset > _PlaylistElementContents.Count - _PlaylistElements.Count) + Offset = _PlaylistElementContents.Count - _PlaylistElements.Count; + + if (Offset < 0) + Offset = 0; Update(); - if (_PlaylistElementContents.Count - 1 < CurrentPlaylistElement) - CurrentPlaylistElement = _PlaylistElementContents.Count - 1; - - if (CurrentPlaylistElement != -1) - _Interactions.SetInteractionToSelectSlide(_PlaylistElements[CurrentPlaylistElement].SelectSlide); - break; - - case Keys.Back: - ClosePlaylist(); //really? or better global? - break; - - case Keys.Enter: - _StartPlaylistSong(CurrentPlaylistElement); - break; - - case Keys.Add: //move the selected song up - if (_PlaylistElementContents.Count > 1 && (CurrentPlaylistElement > 0 || Offset > 0)) + for (int i = _PlaylistElements.Count - 1; i >= 0; i--) { - CBase.Playlist.MovePlaylistSongUp(ActivePlaylistID, CurrentPlaylistElement + Offset); - UpdatePlaylist(); - - SKeyEvent key = new SKeyEvent {Key = Keys.Up}; - - if (CurrentPlaylistElement > scrollLimit) + if (_PlaylistElements[i].SelectSlide.Visible) { - _Interactions.HandleInput(key); - CurrentPlaylistElement = _GetSelectedSelectionNr(); - } - else if (CurrentPlaylistElement <= scrollLimit) - { - if (Offset > 0) - { - Offset--; - Update(); - } - else - { - _Interactions.HandleInput(key); - CurrentPlaylistElement = _GetSelectedSelectionNr(); - } + CurrentPlaylistElement = i; + break; } } - break; + } + break; - case Keys.Subtract: //move the selected song down - if (_PlaylistElementContents.Count > 1 && CurrentPlaylistElement + Offset < _PlaylistElementContents.Count - 1) - { - CBase.Playlist.MovePlaylistSongDown(ActivePlaylistID, CurrentPlaylistElement + Offset); - UpdatePlaylist(); + case Keys.Left: + _Interactions.HandleInput(keyEvent); + CurrentPlaylistElement = _GetSelectedSelectionNr(); - SKeyEvent key = new SKeyEvent {Key = Keys.Down}; + if (CurrentPlaylistElement != -1) + { + CBase.Playlist.GetPlaylistSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = + _PlaylistElementContents[CurrentPlaylistElement + Offset].Modes[_PlaylistElements[CurrentPlaylistElement].SelectSlide.Selection]; + UpdatePlaylist(); + } + break; - if (CurrentPlaylistElement >= scrollLimit) - { - if (Offset < _PlaylistElementContents.Count - _PlaylistElements.Count) - { - Offset++; - Update(); - } - else - { - _Interactions.HandleInput(key); - CurrentPlaylistElement = _GetSelectedSelectionNr(); - } - } - else if (CurrentPlaylistElement < scrollLimit) - { - _Interactions.HandleInput(key); - CurrentPlaylistElement = _GetSelectedSelectionNr(); - } - } - break; + case Keys.Right: + _Interactions.HandleInput(keyEvent); + CurrentPlaylistElement = _GetSelectedSelectionNr(); - case Keys.PageUp: //scroll up - if (_PlaylistElementContents.Count > 0) - { - Offset -= _PlaylistElements.Count; - - if (Offset < 0) - Offset = 0; - - Update(); - CurrentPlaylistElement = 0; - } - break; - - case Keys.PageDown: //scroll down - if (_PlaylistElementContents.Count > 0) - { - Offset += _PlaylistElements.Count; - - if (Offset > _PlaylistElementContents.Count - _PlaylistElements.Count) - Offset = _PlaylistElementContents.Count - _PlaylistElements.Count; - - if (Offset < 0) - Offset = 0; - - Update(); - - for (int i = _PlaylistElements.Count - 1; i >= 0; i--) - { - if (_PlaylistElements[i].SelectSlide.Visible) - { - CurrentPlaylistElement = i; - break; - } - } - } - break; - - case Keys.Left: - _Interactions.HandleInput(keyEvent); - CurrentPlaylistElement = _GetSelectedSelectionNr(); - - if (CurrentPlaylistElement != -1) - { - CBase.Playlist.GetPlaylistSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = - _PlaylistElementContents[CurrentPlaylistElement + Offset].Modes[_PlaylistElements[CurrentPlaylistElement].SelectSlide.Selection]; - UpdatePlaylist(); - } - break; - - case Keys.Right: - _Interactions.HandleInput(keyEvent); - CurrentPlaylistElement = _GetSelectedSelectionNr(); - - if (CurrentPlaylistElement != -1) - { - CBase.Playlist.GetPlaylistSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = - _PlaylistElementContents[CurrentPlaylistElement + Offset].Modes[_PlaylistElements[CurrentPlaylistElement].SelectSlide.Selection]; - UpdatePlaylist(); - } - break; - } - return true; + if (CurrentPlaylistElement != -1) + { + CBase.Playlist.GetPlaylistSong(ActivePlaylistID, CurrentPlaylistElement + Offset).GameMode = + _PlaylistElementContents[CurrentPlaylistElement + Offset].Modes[_PlaylistElements[CurrentPlaylistElement].SelectSlide.Selection]; + UpdatePlaylist(); + } + break; } + return true; + } - //default actions - switch (keyEvent.Key) - { - case Keys.Back: - if (_Theme.ButtonPlaylistName.Selected) + //default actions + switch (keyEvent.Key) + { + case Keys.Back: + if (_Theme.ButtonPlaylistName.Selected) + { + EditMode = EEditMode.PlaylistName; + _Theme.ButtonPlaylistName.EditMode = true; + } + else + ClosePlaylist(); + break; + + case Keys.Enter: + if (_Theme.ButtonPlaylistClose.Selected) + ClosePlaylist(); + else if (_Theme.ButtonPlaylistSing.Selected) + _StartPlaylistSongs(); + else if (_Theme.ButtonPlaylistSave.Selected) + CBase.Playlist.SavePlaylist(ActivePlaylistID); + else if (_Theme.ButtonPlaylistDelete.Selected) + { + CBase.Playlist.DeletePlaylist(ActivePlaylistID); + ClosePlaylist(); + } + else if (_Theme.ButtonPlaylistName.Selected) + { + if (EditMode != EEditMode.PlaylistName) { EditMode = EEditMode.PlaylistName; _Theme.ButtonPlaylistName.EditMode = true; } else - ClosePlaylist(); - break; - - case Keys.Enter: - if (_Theme.ButtonPlaylistClose.Selected) - ClosePlaylist(); - else if (_Theme.ButtonPlaylistSing.Selected) - _StartPlaylistSongs(); - else if (_Theme.ButtonPlaylistSave.Selected) - CBase.Playlist.SavePlaylist(ActivePlaylistID); - else if (_Theme.ButtonPlaylistDelete.Selected) { - CBase.Playlist.DeletePlaylist(ActivePlaylistID); - ClosePlaylist(); + EditMode = EEditMode.None; + _Theme.ButtonPlaylistName.EditMode = false; } - else if (_Theme.ButtonPlaylistName.Selected) - { - if (EditMode != EEditMode.PlaylistName) - { - EditMode = EEditMode.PlaylistName; - _Theme.ButtonPlaylistName.EditMode = true; - } - else - { - EditMode = EEditMode.None; - _Theme.ButtonPlaylistName.EditMode = false; - } - } - break; - } + } + break; + case Keys.PageDown: + _SetSelectionToLastEntry(); + break; + case Keys.PageUp: + _SetSelectionToFirstEntry(); + break; } } return true; diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index 66ad5b95..7216166c 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -115,7 +115,7 @@ namespace VocaluxeLib.Menu private readonly List _ValueBounds = new List(); - public bool WithTextures; + public readonly bool WithTextures; private int _Selection = -1; public int Selection diff --git a/VocaluxeLib/Menu/CText.cs b/VocaluxeLib/Menu/CText.cs index bddbede2..ea864d79 100644 --- a/VocaluxeLib/Menu/CText.cs +++ b/VocaluxeLib/Menu/CText.cs @@ -40,13 +40,13 @@ namespace VocaluxeLib.Menu public float Width; public float Height; - public STextPosition(int dummy) + public STextPosition(float initVal) { - X = 0f; - Y = 0f; - TextHeight = 0f; - Width = 0f; - Height = 0f; + X = initVal; + Y = initVal; + TextHeight = initVal; + Width = initVal; + Height = initVal; } } diff --git a/VocaluxeLib/Menu/Enums.cs b/VocaluxeLib/Menu/Enums.cs index b42b9ec1..adb7e4a7 100644 --- a/VocaluxeLib/Menu/Enums.cs +++ b/VocaluxeLib/Menu/Enums.cs @@ -95,10 +95,12 @@ namespace VocaluxeLib.Menu public enum EColorDepth { +// ReSharper disable UnusedMember.Global Bit8 = 8, Bit16 = 16, Bit24 = 24, Bit32 = 32 + // ReSharper restore UnusedMember.Global } public enum ETextureQuality @@ -339,4 +341,12 @@ namespace VocaluxeLib.Menu ScreenNull = -1 } + + public enum EPopupScreens + { + PopupPlayerControl = 0, + PopupVolumeControl = 1, + + NoPopup = -1 + } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SingNotes/CNotes.cs b/VocaluxeLib/Menu/SingNotes/CNotes.cs index 1794834c..3dd5a648 100644 --- a/VocaluxeLib/Menu/SingNotes/CNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CNotes.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Linq; namespace VocaluxeLib.Menu.SingNotes { @@ -572,19 +573,8 @@ namespace VocaluxeLib.Menu.SingNotes if (_Lines.Count == 0) return 0; - int startbeat = int.MaxValue; - for (int i = 0; i < _Lines.Count; i++) - { - if (_Lines[i].FirstNoteBeat < startbeat) - startbeat = _Lines[i].FirstNoteBeat; - } - - int endbeat = int.MinValue; - for (int i = 0; i < _Lines.Count; i++) - { - if (_Lines[i].LastNoteBeat < endbeat) - endbeat = _Lines[i].LastNoteBeat; - } + int startbeat = _Lines.Max(line => line.FirstNoteBeat); + int endbeat = _Lines.Min(line => line.LastNoteBeat); int result = endbeat - startbeat; if (result > 0) @@ -609,13 +599,7 @@ namespace VocaluxeLib.Menu.SingNotes { get { - int num = 0; - foreach (CLine line in _Lines) - { - if (line.Points > 0f) - num++; - } - return num; + return _Lines.Count(line => line.Points > 0f); } } diff --git a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs index 06c227e8..573e11b8 100644 --- a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs @@ -195,13 +195,13 @@ namespace VocaluxeLib.Menu.SingNotes return false; } - public virtual void Reset() + public void Reset() { _PlayerNotes.Clear(); _ActID = 0; } - public virtual int AddPlayer(SRectF rect, SColorF color, int playerNr) + public int AddPlayer(SRectF rect, SColorF color, int playerNr) { SPlayerNotes notes = new SPlayerNotes { @@ -224,9 +224,7 @@ namespace VocaluxeLib.Menu.SingNotes return notes.ID; } - public virtual void RemovePlayer(int id) {} - - public virtual void AddLine(int id, CLine[] line, int lineNr, int player) + public void AddLine(int id, CLine[] line, int lineNr) { if (line == null) return; @@ -238,11 +236,11 @@ namespace VocaluxeLib.Menu.SingNotes if (lineNr == _PlayerNotes[n].LineNr) return; - SPlayerNotes notes = _PlayerNotes[n]; - if (line.Length <= lineNr) return; + SPlayerNotes notes = _PlayerNotes[n]; + notes.Lines = line; notes.LineNr = lineNr; notes.GoldenStars.Clear(); @@ -253,11 +251,7 @@ namespace VocaluxeLib.Menu.SingNotes _PlayerNotes.Add(notes); } - public virtual void RemoveLine(int id) {} - - public virtual void AddNote(int id, CNote note) {} - - public virtual void SetAlpha(int id, float alpha) + public void SetAlpha(int id, float alpha) { int n = _FindPlayerLine(id); if (n == -1) @@ -268,7 +262,7 @@ namespace VocaluxeLib.Menu.SingNotes _PlayerNotes[n] = pn; } - public virtual float GetAlpha(int id) + public float GetAlpha(int id) { int n = _FindPlayerLine(id); if (n == -1) @@ -277,12 +271,12 @@ namespace VocaluxeLib.Menu.SingNotes return _PlayerNotes[n].Alpha; } - public virtual void Draw(int id, int player) + public void Draw(int id, int player) { Draw(id, null, player); } - public virtual void Draw(int id, List singLine, int player) + public void Draw(int id, List singLine, int player) { int n = _FindPlayerLine(id); if (n == -1) @@ -463,9 +457,6 @@ namespace VocaluxeLib.Menu.SingNotes private int _FindPlayerLine(int id) { - if (id < 0 || id > _PlayerNotes.Count) - return -1; - for (int i = 0; i < _PlayerNotes.Count; i++) { if (_PlayerNotes[i].ID == id) diff --git a/VocaluxeLib/Menu/SongMenu/CSong.cs b/VocaluxeLib/Menu/SongMenu/CSong.cs index f0e14732..fdfb37cf 100644 --- a/VocaluxeLib/Menu/SongMenu/CSong.cs +++ b/VocaluxeLib/Menu/SongMenu/CSong.cs @@ -47,7 +47,7 @@ namespace VocaluxeLib.Menu.SongMenu public class CCategory { - public string Name = String.Empty; + public readonly string Name; private STexture _CoverTextureSmall = new STexture(-1); private STexture _CoverTextureBig = new STexture(-1); private bool _CoverBigLoaded; @@ -100,7 +100,9 @@ namespace VocaluxeLib.Menu.SongMenu public float FadeInTime; public float FadeOutTime; +// ReSharper disable UnusedParameter.Local public SMedley(int dummy) +// ReSharper restore UnusedParameter.Local { Source = EMedleySource.None; StartBeat = 0; @@ -210,11 +212,11 @@ namespace VocaluxeLib.Menu.SongMenu get { return Notes.Lines.Length > 1; } } - public List Edition = new List(); - public List Genre = new List(); + public readonly List Edition = new List(); + public readonly List Genre = new List(); public string Year = ""; - public List Language = new List(); + public readonly List Language = new List(); // Notes public readonly CNotes Notes = new CNotes(); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index e4cc0766..77d3f50b 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -95,7 +95,7 @@ namespace VocaluxeLib.Menu.SongMenu abstract class CSongMenuFramework : ISongMenu { - protected int _PartyModeID; + protected readonly int _PartyModeID; protected SThemeSongMenu _Theme; private bool _ThemeLoaded; @@ -164,7 +164,7 @@ namespace VocaluxeLib.Menu.SongMenu } } - protected virtual void _SetSelectedNow() + protected void _SetSelectedNow() { _Timer.Stop(); _Timer.Reset(); @@ -425,7 +425,7 @@ namespace VocaluxeLib.Menu.SongMenu _Initialized = true; } - public virtual void UpdateRect(SRectF rect) + public void UpdateRect(SRectF rect) { _Rect = rect; Init(); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 7ed861c6..6a81f68e 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using System.Windows.Forms; using VocaluxeLib.PartyModes; @@ -180,15 +181,7 @@ namespace VocaluxeLib.Menu.SongMenu keyEvent.Key == Keys.PageDown || keyEvent.Key == Keys.PageUp)) return; - bool sel = false; - foreach (CStatic tile in _Tiles) - { - if (tile.Selected) - { - sel = true; - break; - } - } + bool sel = _Tiles.Any(tile => tile.Selected); if ((_Locked == -1 || !sel) && (keyEvent.Key != Keys.Escape && keyEvent.Key != Keys.Back && keyEvent.Key != Keys.PageUp && keyEvent.Key != Keys.PageDown)) @@ -500,15 +493,7 @@ namespace VocaluxeLib.Menu.SongMenu protected void _SetSelectedTile(int itemNr) { - bool sel = false; - foreach (CStatic tile in _Tiles) - { - if (tile.Selected) - { - sel = true; - break; - } - } + bool sel = _Tiles.Any(tile => tile.Selected); if (_Locked == -1 || !sel) { diff --git a/VocaluxeLib/Menu/Structs.cs b/VocaluxeLib/Menu/Structs.cs index 38a334e6..daaf1eed 100644 --- a/VocaluxeLib/Menu/Structs.cs +++ b/VocaluxeLib/Menu/Structs.cs @@ -137,15 +137,15 @@ namespace VocaluxeLib.Menu #region Inputs public struct SKeyEvent { - public ESender Sender; - public bool ModAlt; - public bool ModShift; - public bool ModCtrl; - public bool KeyPressed; + public readonly ESender Sender; + public readonly bool ModAlt; + public readonly bool ModShift; + public readonly bool ModCtrl; + public readonly bool KeyPressed; public bool Handled; public Keys Key; - public Char Unicode; - public EModifier Mod; + public readonly Char Unicode; + public readonly EModifier Mod; public SKeyEvent(ESender sender, bool alt, bool shift, bool ctrl, bool pressed, char unicode, Keys key) { @@ -171,27 +171,25 @@ namespace VocaluxeLib.Menu public struct SMouseEvent { - public ESender Sender; + public readonly ESender Sender; public bool Handled; - public int X; - public int Y; - public bool LB; //left button click - public bool LD; //left button double click - public bool RB; //right button click - public bool MB; //middle button click + public readonly int X; + public readonly int Y; + public readonly bool LB; //left button click + public readonly bool LD; //left button double click + public readonly bool RB; //right button click + public readonly bool MB; //middle button click - public bool LBH; //left button hold (when moving) - public bool RBH; //right button hold (when moving) - public bool MBH; //middle button hold (when moving) + public readonly bool LBH; //left button hold (when moving) +// ReSharper disable MemberCanBePrivate.Global + public readonly bool RBH; //right button hold (when moving) + public readonly bool MBH; //middle button hold (when moving) + // ReSharper restore MemberCanBePrivate.Global - public bool ModAlt; - public bool ModShift; - public bool ModCtrl; + public readonly EModifier Mod; + public readonly int Wheel; - public EModifier Mod; - public int Wheel; - - public SMouseEvent(ESender sender, bool alt, bool shift, bool ctrl, int x, int y, bool lb, bool ld, bool rb, int wheel, bool lbh, bool rbh, bool mb, bool mbh) + public SMouseEvent(ESender sender, EModifier mod, int x, int y, bool lb, bool ld, bool rb, int wheel, bool lbh, bool rbh, bool mb, bool mbh) { Sender = sender; Handled = false; @@ -206,27 +204,7 @@ namespace VocaluxeLib.Menu RBH = rbh; MBH = mbh; - ModAlt = alt; - ModShift = shift; - ModCtrl = ctrl; - - EModifier mAlt = EModifier.None; - EModifier mShift = EModifier.None; - EModifier mCtrl = EModifier.None; - - if (alt) - mAlt = EModifier.Alt; - - if (shift) - mShift = EModifier.Shift; - - if (ctrl) - mCtrl = EModifier.Ctrl; - - if (!alt && !shift && !ctrl) - Mod = EModifier.None; - else - Mod = mAlt | mShift | mCtrl; + Mod = mod; Wheel = wheel; } @@ -250,7 +228,9 @@ namespace VocaluxeLib.Menu public string FileName; public STexture Texture; +// ReSharper disable UnusedParameter.Local public SAvatar(int dummy) +// ReSharper restore UnusedParameter.Local { FileName = String.Empty; Texture = new STexture(-1);