diff --git a/Output/CreditsRessourcesDB.sqlite b/Output/CreditsRessourcesDB.sqlite index 3f960232..5701709f 100644 Binary files a/Output/CreditsRessourcesDB.sqlite and b/Output/CreditsRessourcesDB.sqlite differ diff --git a/Output/Languages/English.xml b/Output/Languages/English.xml index 42460ca7..c8eacb20 100644 --- a/Output/Languages/English.xml +++ b/Output/Languages/English.xml @@ -13,6 +13,7 @@ Max Volume Loaded songs Mouse + Memory usage Normal Duet Medley diff --git a/Output/Languages/German.xml b/Output/Languages/German.xml index 7fe3cf73..e19f5319 100644 --- a/Output/Languages/German.xml +++ b/Output/Languages/German.xml @@ -13,6 +13,7 @@ Max. Volume Geladene Songs Maus + Speicherverbrauch Normal Duett Medley diff --git a/Output/Themes/Ambient/Screens/ScreenSing.xml b/Output/Themes/Ambient/Screens/ScreenSing.xml index e5c7c0bf..f42d5a99 100644 --- a/Output/Themes/Ambient/Screens/ScreenSing.xml +++ b/Output/Themes/Ambient/Screens/ScreenSing.xml @@ -1,7 +1,7 @@  - 6 + 7 None @@ -988,6 +988,36 @@ + + + 640 + 18 + + -1,00 + + 32 + + + + + TextColor + + + TextSColor + + Left + + Center + + + + Outline + + + + + + 1214 @@ -2771,4 +2801,4 @@ - \ No newline at end of file + diff --git a/Output/Themes/Ambient/Screens/ScreenSong.xml b/Output/Themes/Ambient/Screens/ScreenSong.xml index e279174b..29173a81 100644 --- a/Output/Themes/Ambient/Screens/ScreenSong.xml +++ b/Output/Themes/Ambient/Screens/ScreenSong.xml @@ -1844,7 +1844,7 @@ Outline - + %a - %t diff --git a/Output/Themes/Changelog/Changelog_ScreenSing.txt b/Output/Themes/Changelog/Changelog_ScreenSing.txt index 85b859da..51b97fd8 100644 --- a/Output/Themes/Changelog/Changelog_ScreenSing.txt +++ b/Output/Themes/Changelog/Changelog_ScreenSing.txt @@ -1,5 +1,11 @@ ScreenSing ++++++++++ +Version 7 + +Add: + !text-position and size will be overwritten by vocaluxe! + +++++++++ Version 6 diff --git a/PartyModes/PartyModeChallenge/CChallengeRounds.cs b/PartyModes/PartyModeChallenge/CChallengeRounds.cs index 080084c4..ed122395 100644 --- a/PartyModes/PartyModeChallenge/CChallengeRounds.cs +++ b/PartyModes/PartyModeChallenge/CChallengeRounds.cs @@ -1,5 +1,25 @@ -using System; +#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.Linq; namespace VocaluxeLib.PartyModes.Challenge { @@ -8,7 +28,7 @@ namespace VocaluxeLib.PartyModes.Challenge private readonly Random _Rand; private readonly int _NumPlayer; - public List Rounds; + public readonly List Rounds; public CChallengeRounds(int numRounds, int numPlayer, int numPlayerAtOnce) { @@ -41,7 +61,7 @@ namespace VocaluxeLib.PartyModes.Challenge Rounds.Add(combinations.GetNextCombination(_GetPlayerDemand(i))); } - private List _GetPlayerDemand(int roundIndex) + private IEnumerable _GetPlayerDemand(int roundIndex) { List numPlayed = new List(_NumPlayer); for (int i = 0; i < _NumPlayer; i++) @@ -53,12 +73,7 @@ namespace VocaluxeLib.PartyModes.Challenge 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(); @@ -131,43 +146,26 @@ namespace VocaluxeLib.PartyModes.Challenge _Rand = rand; } - public CCombination GetNextCombination(List playerNrDemand) + public CCombination GetNextCombination(IEnumerable playerNrDemand) { if (_Combs.Count == 0) _Create(); - CCombination combs = new CCombination(); - if (_NumPlayer == _NumMics) return _Combs[0]; //filter against PlayerNrDemand 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; int rand = _Rand.Next(num); @@ -203,7 +201,7 @@ namespace VocaluxeLib.PartyModes.Challenge public class CCombination { - public List Player; + public readonly List Player; public CCombination() { @@ -212,28 +210,17 @@ namespace VocaluxeLib.PartyModes.Challenge 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(List playerIndices) + 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(List playerIndices) + 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/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index 5cf89c15..5782df18 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -1,3 +1,22 @@ +#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.Runtime.InteropServices; @@ -39,17 +58,15 @@ namespace VocaluxeLib.PartyModes.Challenge public int Position; public int PlayerID; public int NumPlayed; - public int NumRounds; public int NumWon; public int NumSingPoints; public int NumGamePoints; public int CompareTo(object obj) { - if (obj is CResultTableRow) + CResultTableRow row = obj as CResultTableRow; + if (row != null) { - CResultTableRow row = (CResultTableRow)obj; - int res = row.NumGamePoints.CompareTo(NumGamePoints); if (res == 0) { @@ -82,8 +99,7 @@ namespace VocaluxeLib.PartyModes.Challenge public struct SFromScreenNames { - public bool FadeToConfig; - public bool FadeToMain; + public bool FadeBack; public List ProfileIDs; } @@ -162,14 +178,7 @@ namespace VocaluxeLib.PartyModes.Challenge _ToScreenNames = new SDataToScreenNames(); _ToScreenMain = new SDataToScreenMain(); - _GameData = new SData(); - _GameData.NumPlayer = 4; - _GameData.NumPlayerAtOnce = 2; - _GameData.NumRounds = 2; - _GameData.CurrentRoundNr = 1; - _GameData.ProfileIDs = new List(); - _GameData.CatSongIndices = null; - _GameData.Results = null; + _GameData = new SData {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 2, CurrentRoundNr = 1, ProfileIDs = new List(), CatSongIndices = null, Results = null}; } public override bool Init() @@ -192,7 +201,7 @@ namespace VocaluxeLib.PartyModes.Challenge public override void DataFromScreen(string screenName, Object data) { - SDataFromScreen dataFrom = new SDataFromScreen(); + SDataFromScreen dataFrom; switch (screenName) { case "PartyScreenChallengeConfig": @@ -217,7 +226,7 @@ namespace VocaluxeLib.PartyModes.Challenge try { dataFrom = (SDataFromScreen)data; - if (dataFrom.ScreenNames.FadeToConfig) + if (dataFrom.ScreenNames.FadeBack) _Stage = EStage.NotStarted; else { @@ -352,10 +361,11 @@ namespace VocaluxeLib.PartyModes.Challenge return _ScreenSongOptions; } + // ReSharper disable RedundantAssignment public override void OnSongChange(int songIndex, ref SScreenSongOptions screenSongOptions) + // ReSharper restore RedundantAssignment { - if (_ScreenSongOptions.Selection.SongIndex != -1) - _ScreenSongOptions.Selection.SongIndex = -1; + _ScreenSongOptions.Selection.SongIndex = -1; if (_ScreenSongOptions.Selection.SelectNextRandomSong && songIndex != -1) { @@ -372,7 +382,9 @@ namespace VocaluxeLib.PartyModes.Challenge screenSongOptions = _ScreenSongOptions; } + // ReSharper disable RedundantAssignment public override void OnCategoryChange(int categoryIndex, ref SScreenSongOptions screenSongOptions) + // ReSharper restore RedundantAssignment { if (_GameData.CatSongIndices != null && categoryIndex != -1) { @@ -440,40 +452,29 @@ 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(); CBase.Game.AddSong(songID, gm); CBase.Game.SetNumPlayer(_GameData.NumPlayerAtOnce); - SPlayer[] player = CBase.Game.GetPlayer(); + SPlayer[] player = CBase.Game.GetPlayers(); if (player == null) return; if (player.Length < _GameData.NumPlayerAtOnce) return; - SProfile[] profiles = CBase.Profiles.GetProfiles(); CCombination c = _GameData.Rounds.GetRound(_GameData.CurrentRoundNr - 1); for (int i = 0; i < _GameData.NumPlayerAtOnce; i++) { - //default values - player[i].Name = "foobar"; - player[i].Difficulty = EGameDifficulty.TR_CONFIG_EASY; - player[i].ProfileID = -1; - //try to fill with the right data if (c != null) - { - if (_GameData.ProfileIDs[c.Player[i]] < profiles.Length) - { - player[i].Name = profiles[_GameData.ProfileIDs[c.Player[i]]].PlayerName; - player[i].Difficulty = profiles[_GameData.ProfileIDs[c.Player[i]]].Difficulty; - player[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; - } - } + player[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; + else + player[i].ProfileID = -1; } CBase.Songs.AddPartySongSung(songID); @@ -568,13 +569,7 @@ namespace VocaluxeLib.PartyModes.Challenge { for (int i = 0; i < _GameData.NumPlayer; i++) { - CResultTableRow row = new CResultTableRow(); - row.PlayerID = _GameData.ProfileIDs[i]; - row.NumPlayed = 0; - row.NumRounds = 0; - row.NumWon = 0; - row.NumSingPoints = 0; - row.NumGamePoints = 0; + CResultTableRow row = new CResultTableRow {PlayerID = _GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0}; _GameData.ResultTable.Add(row); } @@ -587,7 +582,7 @@ namespace VocaluxeLib.PartyModes.Challenge } else { - SPlayer[] results = CBase.Game.GetPlayer(); + SPlayer[] results = CBase.Game.GetPlayers(); if (results == null) return; @@ -611,18 +606,16 @@ namespace VocaluxeLib.PartyModes.Challenge } } - if (index != -1) - { - CResultTableRow row = _GameData.ResultTable[index]; + if (index == -1) + continue; + CResultTableRow row = _GameData.ResultTable[index]; - row.NumPlayed++; - row.NumWon += points[i].Won; - row.NumRounds += 1; - row.NumSingPoints += points[i].SingPoints; - row.NumGamePoints += points[i].GamePoints; + row.NumPlayed++; + row.NumWon += points[i].Won; + row.NumSingPoints += points[i].SingPoints; + row.NumGamePoints += points[i].GamePoints; - _GameData.ResultTable[index] = row; - } + _GameData.ResultTable[index] = row; } } @@ -632,13 +625,13 @@ namespace VocaluxeLib.PartyModes.Challenge int pos = 1; int lastPoints = 0; int lastSingPoints = 0; - for (int i = 0; i < _GameData.ResultTable.Count; i++) + foreach (CResultTableRow resultRow in _GameData.ResultTable) { - if (lastPoints > _GameData.ResultTable[i].NumGamePoints || lastSingPoints > _GameData.ResultTable[i].NumSingPoints) + if (lastPoints > resultRow.NumGamePoints || lastSingPoints > resultRow.NumSingPoints) pos++; - _GameData.ResultTable[i].Position = pos; - lastPoints = _GameData.ResultTable[i].NumGamePoints; - lastSingPoints = _GameData.ResultTable[i].NumSingPoints; + resultRow.Position = pos; + lastPoints = resultRow.NumGamePoints; + lastSingPoints = resultRow.NumSingPoints; } } @@ -647,15 +640,11 @@ namespace VocaluxeLib.PartyModes.Challenge List result = new List(); for (int i = 0; i < _GameData.NumPlayerAtOnce; i++) { - SStats stat = new SStats(); - stat.ProfileID = results[i].ProfileID; - stat.SingPoints = (int)Math.Round(results[i].Points); - stat.Won = 0; - stat.GamePoints = 0; + SStats stat = new SStats {ProfileID = results[i].ProfileID, SingPoints = (int)Math.Round(results[i].Points), Won = 0, GamePoints = 0}; result.Add(stat); } - result.Sort(delegate(SStats s1, SStats s2) { return s1.SingPoints.CompareTo(s2.SingPoints); }); + result.Sort((s1, s2) => s1.SingPoints.CompareTo(s2.SingPoints)); int current = result[result.Count - 1].SingPoints; int points = result.Count; diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeConfig.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeConfig.cs index 2351bd79..7e856321 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeConfig.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeConfig.cs @@ -1,10 +1,31 @@ +#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.Windows.Forms; using VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes.Challenge { + // ReSharper disable UnusedMember.Global public class CPartyScreenChallengeConfig : CMenuParty + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -32,20 +53,15 @@ namespace VocaluxeLib.PartyModes.Challenge _ThemeButtons = new string[] {_ButtonNext, _ButtonBack}; _Data = new SDataFromScreen(); - SFromScreenConfig config = new SFromScreenConfig(); - config.NumPlayer = 4; - config.NumPlayerAtOnce = 2; - config.NumRounds = 12; + SFromScreenConfig config = new SFromScreenConfig {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 12}; _Data.ScreenConfig = config; } public override void DataToScreen(object receivedData) { - SDataToScreenConfig config = new SDataToScreenConfig(); - try { - config = (SDataToScreenConfig)receivedData; + SDataToScreenConfig config = (SDataToScreenConfig)receivedData; _Data.ScreenConfig.NumPlayer = config.NumPlayer; _Data.ScreenConfig.NumPlayerAtOnce = config.NumPlayerAtOnce; _Data.ScreenConfig.NumRounds = config.NumRounds; @@ -73,10 +89,10 @@ namespace VocaluxeLib.PartyModes.Challenge case Keys.Enter: _UpdateSlides(); - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); break; @@ -96,13 +112,13 @@ namespace VocaluxeLib.PartyModes.Challenge { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { _UpdateSlides(); - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); } @@ -139,10 +155,10 @@ namespace VocaluxeLib.PartyModes.Challenge private void _RebuildSlides() { // build num player slide (min player ... max player); - SelectSlides[_SelectSlideNumPlayers].Clear(); + _SelectSlides[_SelectSlideNumPlayers].Clear(); for (int i = _PartyMode.GetMinPlayer(); i <= _PartyMode.GetMaxPlayer(); i++) - SelectSlides[_SelectSlideNumPlayers].AddValue(i.ToString()); - SelectSlides[_SelectSlideNumPlayers].Selection = _Data.ScreenConfig.NumPlayer - _PartyMode.GetMinPlayer(); + _SelectSlides[_SelectSlideNumPlayers].AddValue(i.ToString()); + _SelectSlides[_SelectSlideNumPlayers].Selection = _Data.ScreenConfig.NumPlayer - _PartyMode.GetMinPlayer(); _UpdateMicsAtOnce(); _SetRoundSteps(); @@ -153,9 +169,9 @@ namespace VocaluxeLib.PartyModes.Challenge { int player = _Data.ScreenConfig.NumPlayer; int mics = _Data.ScreenConfig.NumPlayerAtOnce; - _Data.ScreenConfig.NumPlayer = SelectSlides[_SelectSlideNumPlayers].Selection + _PartyMode.GetMinPlayer(); - _Data.ScreenConfig.NumPlayerAtOnce = SelectSlides[_SelectSlideNumMics].Selection + _PartyMode.GetMinPlayer(); - _Data.ScreenConfig.NumRounds = (SelectSlides[_SelectSlideNumRounds].Selection + 1) * _RoundSteps; + _Data.ScreenConfig.NumPlayer = _SelectSlides[_SelectSlideNumPlayers].Selection + _PartyMode.GetMinPlayer(); + _Data.ScreenConfig.NumPlayerAtOnce = _SelectSlides[_SelectSlideNumMics].Selection + _PartyMode.GetMinPlayer(); + _Data.ScreenConfig.NumRounds = (_SelectSlides[_SelectSlideNumRounds].Selection + 1) * _RoundSteps; _UpdateMicsAtOnce(); _SetRoundSteps(); @@ -182,19 +198,19 @@ namespace VocaluxeLib.PartyModes.Challenge _Data.ScreenConfig.NumPlayerAtOnce = maxNum; // build mics at once slide - SelectSlides[_SelectSlideNumMics].Clear(); + _SelectSlides[_SelectSlideNumMics].Clear(); for (int i = 1; i <= maxNum; i++) - SelectSlides[_SelectSlideNumMics].AddValue(i.ToString()); - SelectSlides[_SelectSlideNumMics].Selection = _Data.ScreenConfig.NumPlayerAtOnce - _PartyMode.GetMinPlayer(); + _SelectSlides[_SelectSlideNumMics].AddValue(i.ToString()); + _SelectSlides[_SelectSlideNumMics].Selection = _Data.ScreenConfig.NumPlayerAtOnce - _PartyMode.GetMinPlayer(); } private void _UpdateSlideRounds() { // build num rounds slide - SelectSlides[_SelectSlideNumRounds].Clear(); + _SelectSlides[_SelectSlideNumRounds].Clear(); for (int i = _RoundSteps; i <= _MaxNumRounds; i += _RoundSteps) - SelectSlides[_SelectSlideNumRounds].AddValue(i.ToString()); - SelectSlides[_SelectSlideNumRounds].Selection = _Data.ScreenConfig.NumRounds / _RoundSteps - 1; + _SelectSlides[_SelectSlideNumRounds].AddValue(i.ToString()); + _SelectSlides[_SelectSlideNumRounds].Selection = _Data.ScreenConfig.NumRounds / _RoundSteps - 1; } private void _SetRoundSteps() @@ -208,10 +224,7 @@ namespace VocaluxeLib.PartyModes.Challenge int res = _Data.ScreenConfig.NumPlayer / _Data.ScreenConfig.NumPlayerAtOnce; int mod = _Data.ScreenConfig.NumPlayer % _Data.ScreenConfig.NumPlayerAtOnce; - if (mod == 0) - _RoundSteps = res; - else - _RoundSteps = _Data.ScreenConfig.NumPlayer; + _RoundSteps = mod == 0 ? res : _Data.ScreenConfig.NumPlayer; } private void _Back() diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs index 26d04c1d..85730d80 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs @@ -1,3 +1,22 @@ +#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.Windows.Forms; @@ -22,7 +41,9 @@ namespace VocaluxeLib.PartyModes.Challenge public List TextScores; } + // ReSharper disable UnusedMember.Global public class CPartyScreenChallengeMain : CMenuParty + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -72,13 +93,12 @@ 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() { - _Data = new SDataFromScreen(); - _Data.ScreenMain = new SFromScreenMain(); + _Data = new SDataFromScreen {ScreenMain = new SFromScreenMain()}; } public override void Init() @@ -87,11 +107,15 @@ namespace VocaluxeLib.PartyModes.Challenge _ThemeTexts = new string[] { - _TextPosition, _TextPlayerName, _TextNumPlayed, _TextWon, _TextSingPoints, _TextGamePoints, _TextNextPlayer, _TextPopupReallyExit, _TextRoundNumber, _TextRoundPlayer, + _TextPosition, _TextPlayerName, _TextNumPlayed, _TextWon, _TextSingPoints, _TextGamePoints, _TextNextPlayer, _TextPopupReallyExit, _TextRoundNumber, + _TextRoundPlayer, _TextRoundScore, _TextFinishMessage, _TextFinishPlayerWin, _TextNextPlayerMessage }; _ThemeButtons = new string[] - {_ButtonNextRound, _ButtonBack, _ButtonExit, _ButtonPopupYes, _ButtonPopupNo, _ButtonPlayerScrollDown, _ButtonPlayerScrollUp, _ButtonRoundsScrollDown, _ButtonRoundsScrollUp}; + { + _ButtonNextRound, _ButtonBack, _ButtonExit, _ButtonPopupYes, _ButtonPopupNo, _ButtonPlayerScrollDown, _ButtonPlayerScrollUp, _ButtonRoundsScrollDown, + _ButtonRoundsScrollUp + }; _ThemeStatics = new string[] {_StaticPopupBG, _StaticNextPlayer}; } @@ -107,20 +131,18 @@ namespace VocaluxeLib.PartyModes.Challenge for (int i = 0; i < _PartyMode.GetMaxPlayer(); i++) { - _NextPlayerTexts.Add(GetNewText(Texts[_TextNextPlayer])); - AddText(_NextPlayerTexts[_NextPlayerTexts.Count - 1]); - _NextPlayerStatics.Add(GetNewStatic(Statics[_StaticNextPlayer])); - AddStatic(_NextPlayerStatics[_NextPlayerStatics.Count - 1]); + _NextPlayerTexts.Add(GetNewText(_Texts[_TextNextPlayer])); + _AddText(_NextPlayerTexts[_NextPlayerTexts.Count - 1]); + _NextPlayerStatics.Add(GetNewStatic(_Statics[_StaticNextPlayer])); + _AddStatic(_NextPlayerStatics[_NextPlayerStatics.Count - 1]); } } public override void DataToScreen(object receivedData) { - SDataToScreenMain data = new SDataToScreenMain(); - try { - data = (SDataToScreenMain)receivedData; + SDataToScreenMain data = (SDataToScreenMain)receivedData; _GameState = data; } catch (Exception e) @@ -154,26 +176,26 @@ namespace VocaluxeLib.PartyModes.Challenge case Keys.Enter: if (!_ExitPopupVisible) { - if (Buttons[_ButtonNextRound].Selected) + if (_Buttons[_ButtonNextRound].Selected) _NextRound(); - if (Buttons[_ButtonBack].Selected && _GameState.CurrentRoundNr == 1) + if (_Buttons[_ButtonBack].Selected && _GameState.CurrentRoundNr == 1) _Back(); - if (Buttons[_ButtonExit].Selected && _GameState.CurrentRoundNr > 1) + if (_Buttons[_ButtonExit].Selected && _GameState.CurrentRoundNr > 1) _ShowPopup(true); - if (Buttons[_ButtonPlayerScrollUp].Selected) + if (_Buttons[_ButtonPlayerScrollUp].Selected) _ScrollPlayerTable(-1); - if (Buttons[_ButtonPlayerScrollDown].Selected) + if (_Buttons[_ButtonPlayerScrollDown].Selected) _ScrollPlayerTable(1); - if (Buttons[_ButtonRoundsScrollUp].Selected) + if (_Buttons[_ButtonRoundsScrollUp].Selected) _ScrollRoundsTable(-1); - if (Buttons[_ButtonRoundsScrollDown].Selected) + if (_Buttons[_ButtonRoundsScrollDown].Selected) _ScrollRoundsTable(1); } else { - if (Buttons[_ButtonPopupYes].Selected) + if (_Buttons[_ButtonPopupYes].Selected) _EndParty(); - if (Buttons[_ButtonPopupNo].Selected) + if (_Buttons[_ButtonPopupNo].Selected) _ShowPopup(false); } break; @@ -186,30 +208,30 @@ namespace VocaluxeLib.PartyModes.Challenge { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { if (!_ExitPopupVisible) { - if (Buttons[_ButtonNextRound].Selected) + if (_Buttons[_ButtonNextRound].Selected) _NextRound(); - if (Buttons[_ButtonBack].Selected && _GameState.CurrentRoundNr == 1) + if (_Buttons[_ButtonBack].Selected && _GameState.CurrentRoundNr == 1) _Back(); - if (Buttons[_ButtonExit].Selected && _GameState.CurrentRoundNr > 1) + if (_Buttons[_ButtonExit].Selected && _GameState.CurrentRoundNr > 1) _ShowPopup(true); - if (Buttons[_ButtonPlayerScrollUp].Selected) + if (_Buttons[_ButtonPlayerScrollUp].Selected) _ScrollPlayerTable(-1); - if (Buttons[_ButtonPlayerScrollDown].Selected) + if (_Buttons[_ButtonPlayerScrollDown].Selected) _ScrollPlayerTable(1); - if (Buttons[_ButtonRoundsScrollUp].Selected) + if (_Buttons[_ButtonRoundsScrollUp].Selected) _ScrollRoundsTable(-1); - if (Buttons[_ButtonRoundsScrollDown].Selected) + if (_Buttons[_ButtonRoundsScrollDown].Selected) _ScrollRoundsTable(1); } else { - if (Buttons[_ButtonPopupYes].Selected) + if (_Buttons[_ButtonPopupYes].Selected) _EndParty(); - if (Buttons[_ButtonPopupNo].Selected) + if (_Buttons[_ButtonPopupNo].Selected) _ShowPopup(false); } } @@ -256,29 +278,29 @@ namespace VocaluxeLib.PartyModes.Challenge if (_GameState.CurrentRoundNr == 1) { - Buttons[_ButtonBack].Visible = true; - Buttons[_ButtonExit].Visible = false; + _Buttons[_ButtonBack].Visible = true; + _Buttons[_ButtonExit].Visible = false; } else { - Buttons[_ButtonBack].Visible = false; - Buttons[_ButtonExit].Visible = true; + _Buttons[_ButtonBack].Visible = false; + _Buttons[_ButtonExit].Visible = true; } if (_GameState.CurrentRoundNr <= _GameState.Combs.Count) { - Buttons[_ButtonNextRound].Visible = true; - Texts[_TextFinishMessage].Visible = false; - Texts[_TextFinishPlayerWin].Visible = false; - SetInteractionToButton(Buttons[_ButtonNextRound]); + _Buttons[_ButtonNextRound].Visible = true; + _Texts[_TextFinishMessage].Visible = false; + _Texts[_TextFinishPlayerWin].Visible = false; + _SetInteractionToButton(_Buttons[_ButtonNextRound]); } else { - Buttons[_ButtonNextRound].Visible = false; - Texts[_TextFinishMessage].Visible = true; - Texts[_TextFinishPlayerWin].Visible = true; - Texts[_TextFinishPlayerWin].Text = _GetPlayerWinString(); - SetInteractionToButton(Buttons[_ButtonExit]); + _Buttons[_ButtonNextRound].Visible = false; + _Texts[_TextFinishMessage].Visible = true; + _Texts[_TextFinishPlayerWin].Visible = true; + _Texts[_TextFinishPlayerWin].Text = _GetPlayerWinString(); + _SetInteractionToButton(_Buttons[_ButtonExit]); } _ShowPopup(false); @@ -311,13 +333,13 @@ namespace VocaluxeLib.PartyModes.Challenge { _ExitPopupVisible = visible; - Statics[_StaticPopupBG].Visible = _ExitPopupVisible; - Texts[_TextPopupReallyExit].Visible = _ExitPopupVisible; - Buttons[_ButtonPopupYes].Visible = _ExitPopupVisible; - Buttons[_ButtonPopupNo].Visible = _ExitPopupVisible; + _Statics[_StaticPopupBG].Visible = _ExitPopupVisible; + _Texts[_TextPopupReallyExit].Visible = _ExitPopupVisible; + _Buttons[_ButtonPopupYes].Visible = _ExitPopupVisible; + _Buttons[_ButtonPopupNo].Visible = _ExitPopupVisible; if (_ExitPopupVisible) - SetInteractionToButton(Buttons[_ButtonPopupNo]); + _SetInteractionToButton(_Buttons[_ButtonPopupNo]); } private void _Back() @@ -329,9 +351,9 @@ namespace VocaluxeLib.PartyModes.Challenge private void _UpdateNextPlayerPositions() { - float x = CBase.Settings.GetRenderW() / 2 - ((_GameState.NumPlayerAtOnce * Statics[_StaticNextPlayer].Rect.W) + ((_GameState.NumPlayerAtOnce - 1) * 15)) / 2; - float staticY = 590; - float textY = 550; + float x = (float)CBase.Settings.GetRenderW() / 2 - ((_GameState.NumPlayerAtOnce * _Statics[_StaticNextPlayer].Rect.W) + ((_GameState.NumPlayerAtOnce - 1) * 15)) / 2; + const float staticY = 590; + const float textY = 550; for (int i = 0; i < _GameState.NumPlayerAtOnce; i++) { //static @@ -339,11 +361,11 @@ namespace VocaluxeLib.PartyModes.Challenge _NextPlayerStatics[i].Rect.Y = staticY; _NextPlayerStatics[i].Visible = true; //text - _NextPlayerTexts[i].X = x + Statics[_StaticNextPlayer].Rect.W / 2; + _NextPlayerTexts[i].X = x + _Statics[_StaticNextPlayer].Rect.W / 2; _NextPlayerTexts[i].Y = textY; _NextPlayerTexts[i].Visible = true; - x += Statics[_StaticNextPlayer].Rect.W + 15; + x += _Statics[_StaticNextPlayer].Rect.W + 15; } for (int i = _GameState.NumPlayerAtOnce; i < _PartyMode.GetMaxPlayer(); i++) { @@ -356,7 +378,7 @@ namespace VocaluxeLib.PartyModes.Challenge { if (_GameState.CurrentRoundNr <= _GameState.Combs.Count) { - Texts[_TextNextPlayerMessage].Visible = true; + _Texts[_TextNextPlayerMessage].Visible = true; SProfile[] profiles = CBase.Profiles.GetProfiles(); for (int i = 0; i < _GameState.NumPlayerAtOnce; i++) { @@ -368,7 +390,7 @@ namespace VocaluxeLib.PartyModes.Challenge } else { - Texts[_TextNextPlayerMessage].Visible = false; + _Texts[_TextNextPlayerMessage].Visible = false; for (int i = 0; i < _GameState.NumPlayerAtOnce; i++) { _NextPlayerStatics[i].Visible = false; @@ -383,30 +405,28 @@ namespace VocaluxeLib.PartyModes.Challenge _RoundsTable = new List(); for (int i = 0; i < 5; i++) { - CRoundsTableRow rtr = new CRoundsTableRow(); - rtr.TextPlayer = new List(); - rtr.TextScores = new List(); + CRoundsTableRow rtr = new CRoundsTableRow {TextPlayer = new List(), TextScores = new List()}; _RoundsTable.Add(rtr); } //Create statics and texts for rounds - for (int round = 0; round < _RoundsTable.Count; round++) + foreach (CRoundsTableRow roundRow in _RoundsTable) { //Round-number - CText text = GetNewText(Texts[_TextRoundNumber]); - AddText(text); - _RoundsTable[round].Number = text; + CText text = GetNewText(_Texts[_TextRoundNumber]); + _AddText(text); + roundRow.Number = text; for (int row = 0; row < 2; row++) { for (int column = 0; column < 3; column++) { //Player - text = GetNewText(Texts[_TextRoundPlayer]); - AddText(text); - _RoundsTable[round].TextPlayer.Add(text); + text = GetNewText(_Texts[_TextRoundPlayer]); + _AddText(text); + roundRow.TextPlayer.Add(text); //Score - text = GetNewText(Texts[_TextRoundScore]); - AddText(text); - _RoundsTable[round].TextScores.Add(text); + text = GetNewText(_Texts[_TextRoundScore]); + _AddText(text); + roundRow.TextScores.Add(text); } } } @@ -416,30 +436,27 @@ namespace VocaluxeLib.PartyModes.Challenge { _RoundsTableScrollArea = new SRectF(); - int numPlayerInOneRow = 3; - if (_GameState.NumPlayerAtOnce <= numPlayerInOneRow) - _NumRoundsVisible = 5; - else - _NumRoundsVisible = 3; + const int numPlayerInOneRow = 3; + _NumRoundsVisible = _GameState.NumPlayerAtOnce <= numPlayerInOneRow ? 5 : 3; if (_NumRoundsVisible > _GameState.Combs.Count) _NumRoundsVisible = _GameState.Combs.Count; - float numberX = Texts[_TextRoundNumber].X; - float numberY = Texts[_TextRoundNumber].Y; + float numberX = _Texts[_TextRoundNumber].X; + float numberY = _Texts[_TextRoundNumber].Y; _RoundsTableScrollArea.X = numberX; _RoundsTableScrollArea.Y = numberY; - _RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - Texts[_TextRoundNumber].X - 20; + _RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20; - float delta = Texts[_TextRoundNumber].Height; + float delta = _Texts[_TextRoundNumber].Height; //Update statics and texts for rounds - for (int round = 0; round < _RoundsTable.Count; round++) + foreach (CRoundsTableRow roundRow in _RoundsTable) { //Round-number - _RoundsTable[round].Number.X = numberX; - _RoundsTable[round].Number.Y = numberY; + roundRow.Number.X = numberX; + roundRow.Number.Y = numberY; int numInnerRows = (int)Math.Ceiling(_GameState.NumPlayerAtOnce / ((double)numPlayerInOneRow)); for (int row = 0; row < numInnerRows; row++) { @@ -453,17 +470,17 @@ namespace VocaluxeLib.PartyModes.Challenge for (int column = row * numPlayerInOneRow; column < num; column++) { //Player - float x = numberX + 15 + (CBase.Settings.GetRenderW() - Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow * (column - row * numPlayerInOneRow) + - ((CBase.Settings.GetRenderW() - Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow) / 2; - float maxw = ((CBase.Settings.GetRenderW() - Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow) / 2 - 5; - _RoundsTable[round].TextPlayer[column].X = x; - _RoundsTable[round].TextPlayer[column].Y = numberY; - _RoundsTable[round].TextPlayer[column].MaxWidth = maxw; + float x = numberX + 15 + (CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow * (column - row * numPlayerInOneRow) + + ((CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow) / 2; + float maxw = ((CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow) / 2 - 5; + roundRow.TextPlayer[column].X = x; + roundRow.TextPlayer[column].Y = numberY; + roundRow.TextPlayer[column].MaxWidth = maxw; //Score - _RoundsTable[round].TextScores[column] = _RoundsTable[round].TextScores[column]; - _RoundsTable[round].TextScores[column].X = x; - _RoundsTable[round].TextScores[column].Y = numberY + delta; - _RoundsTable[round].TextScores[column].MaxWidth = maxw; + roundRow.TextScores[column] = roundRow.TextScores[column]; + roundRow.TextScores[column].X = x; + roundRow.TextScores[column].Y = numberY + delta; + roundRow.TextScores[column].MaxWidth = maxw; } numberY = numberY + delta + delta; } @@ -484,7 +501,7 @@ namespace VocaluxeLib.PartyModes.Challenge _RoundsTable[i].Number.Visible = true; _RoundsTable[i].TextPlayer[p].Visible = true; _RoundsTable[i].TextScores[p].Visible = true; - _RoundsTable[i].Number.Text = (i + 1 + _RoundsTableOffset).ToString() + ")"; + _RoundsTable[i].Number.Text = (i + 1 + _RoundsTableOffset) + ")"; int pID = _GameState.ProfileIDs[_GameState.Combs[i + _RoundsTableOffset].Player[p]]; _RoundsTable[i].TextPlayer[p].Text = profile[pID].PlayerName; if ((_GameState.CurrentRoundNr - 1) > i + _RoundsTableOffset) @@ -509,32 +526,30 @@ namespace VocaluxeLib.PartyModes.Challenge } } - Buttons[_ButtonRoundsScrollUp].Visible = _RoundsTableOffset > 0; - Buttons[_ButtonRoundsScrollDown].Visible = _GameState.Combs.Count - _NumRoundsVisible - _RoundsTableOffset > 0; + _Buttons[_ButtonRoundsScrollUp].Visible = _RoundsTableOffset > 0; + _Buttons[_ButtonRoundsScrollDown].Visible = _GameState.Combs.Count - _NumRoundsVisible - _RoundsTableOffset > 0; } private void _BuildPlayerTable() { - _PlayerTableScrollArea = new SRectF(); - _PlayerTableScrollArea.X = Texts[_TextPosition].X; - _PlayerTableScrollArea.Y = Texts[_TextPosition].Y; - _PlayerTableScrollArea.W = Texts[_TextGamePoints].X - Texts[_TextPosition].X; + _PlayerTableScrollArea = new SRectF {X = _Texts[_TextPosition].X, Y = _Texts[_TextPosition].Y, W = _Texts[_TextGamePoints].X - _Texts[_TextPosition].X}; _PlayerTable = new List(); - float delta = Texts[_TextPosition].Height * 1.2f; + float delta = _Texts[_TextPosition].Height * 1.2f; float h = 0; for (int i = 0; i < 10; i++) { - STableRow row = new STableRow(); - - row.Pos = GetNewText(Texts[_TextPosition]); - row.Name = GetNewText(Texts[_TextPlayerName]); - row.Rounds = GetNewText(Texts[_TextNumPlayed]); - row.Won = GetNewText(Texts[_TextWon]); - row.SingPoints = GetNewText(Texts[_TextSingPoints]); - row.GamePoints = GetNewText(Texts[_TextGamePoints]); + STableRow row = new STableRow + { + Pos = GetNewText(_Texts[_TextPosition]), + Name = GetNewText(_Texts[_TextPlayerName]), + Rounds = GetNewText(_Texts[_TextNumPlayed]), + Won = GetNewText(_Texts[_TextWon]), + SingPoints = GetNewText(_Texts[_TextSingPoints]), + GamePoints = GetNewText(_Texts[_TextGamePoints]) + }; row.Pos.Y += delta * (i + 1); row.Name.Y += delta * (i + 1); @@ -543,7 +558,7 @@ namespace VocaluxeLib.PartyModes.Challenge row.SingPoints.Y += delta * (i + 1); row.GamePoints.Y += delta * (i + 1); - row.Pos.Text = (i + 1).ToString() + "."; + row.Pos.Text = (i + 1) + "."; row.Pos.Visible = false; row.Name.Visible = false; @@ -552,12 +567,12 @@ namespace VocaluxeLib.PartyModes.Challenge row.SingPoints.Visible = false; row.GamePoints.Visible = false; - AddText(row.Pos); - AddText(row.Name); - AddText(row.Rounds); - AddText(row.Won); - AddText(row.SingPoints); - AddText(row.GamePoints); + _AddText(row.Pos); + _AddText(row.Name); + _AddText(row.Rounds); + _AddText(row.Won); + _AddText(row.SingPoints); + _AddText(row.GamePoints); _PlayerTable.Add(row); @@ -583,9 +598,9 @@ namespace VocaluxeLib.PartyModes.Challenge row.SingPoints.Visible = true; row.GamePoints.Visible = true; - row.Pos.Text = _GameState.ResultTable[i + _PlayerTableOffset].Position.ToString() + "."; + 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(); @@ -601,8 +616,8 @@ namespace VocaluxeLib.PartyModes.Challenge } } - Buttons[_ButtonPlayerScrollUp].Visible = _PlayerTableOffset > 0; - Buttons[_ButtonPlayerScrollDown].Visible = _GameState.ProfileIDs.Count - _NumPlayerVisible - _PlayerTableOffset > 0; + _Buttons[_ButtonPlayerScrollUp].Visible = _PlayerTableOffset > 0; + _Buttons[_ButtonPlayerScrollDown].Visible = _GameState.ProfileIDs.Count - _NumPlayerVisible - _PlayerTableOffset > 0; } private void _ScrollPlayerTable(int offset) diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeNames.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeNames.cs index 573f5430..08bf3f0d 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeNames.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeNames.cs @@ -1,11 +1,33 @@ +#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.Linq; using System.Windows.Forms; using VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes.Challenge { + // ReSharper disable UnusedMember.Global public class CPartyScreenChallengeNames : CMenuParty + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -22,7 +44,6 @@ namespace VocaluxeLib.PartyModes.Challenge private List _PlayerDestinationButtons; //PlayerDestinationButtons-Option private const int _PlayerDestinationButtonsNumH = 3; - private const int _PlayerDestinationButtonsNumW = 4; private const int _PlayerDestinationButtonsFirstX = 900; private const int _PlayerDestinationButtonsFirstY = 105; private const int _PlayerDestinationButtonsSpaceH = 15; @@ -35,7 +56,7 @@ namespace VocaluxeLib.PartyModes.Challenge 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; @@ -65,27 +86,19 @@ namespace VocaluxeLib.PartyModes.Challenge _Data.ScreenNames.ProfileIDs = new List(); - List buttons = new List(); _ThemeButtons = new string[] {_ButtonBack, _ButtonNext, _ButtonPlayerDestination, _ButtonPlayerChoose}; _Data = new SDataFromScreen(); - SFromScreenNames names = new SFromScreenNames(); - names.FadeToConfig = false; - names.FadeToMain = false; - names.ProfileIDs = new List(); + SFromScreenNames names = new SFromScreenNames {FadeBack = false, ProfileIDs = new List()}; _Data.ScreenNames = names; } public override void DataToScreen(object receivedData) { - SDataToScreenNames config = new SDataToScreenNames(); - try { - config = (SDataToScreenNames)receivedData; - _Data.ScreenNames.ProfileIDs = config.ProfileIDs; - if (_Data.ScreenNames.ProfileIDs == null) - _Data.ScreenNames.ProfileIDs = new List(); + SDataToScreenNames config = (SDataToScreenNames)receivedData; + _Data.ScreenNames.ProfileIDs = config.ProfileIDs ?? new List(); _NumPlayer = config.NumPlayer; @@ -113,10 +126,10 @@ namespace VocaluxeLib.PartyModes.Challenge break; case Keys.Enter: - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); if (!_OnAdd()) @@ -218,12 +231,12 @@ namespace VocaluxeLib.PartyModes.Challenge _ChooseAvatarStatic.Visible = false; } - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); if (!_OnAdd()) @@ -268,13 +281,13 @@ namespace VocaluxeLib.PartyModes.Challenge private void _AddButtonPlayerDestination() { - Buttons[_ButtonPlayerDestination].Visible = false; + _Buttons[_ButtonPlayerDestination].Visible = false; _PlayerDestinationButtons = new List(); int row = 0; int column = 0; for (int i = 1; i <= _PartyMode.GetMaxPlayer(); i++) { - CButton b = GetNewButton(Buttons[_ButtonPlayerDestination]); + CButton b = GetNewButton(_Buttons[_ButtonPlayerDestination]); b.Rect.X = _PlayerDestinationButtonsFirstX + column * (b.Rect.W + _PlayerDestinationButtonsSpaceH); b.Rect.Y = _PlayerDestinationButtonsFirstY + row * (b.Rect.H + _PlayerDestinationButtonsSpaceW); _PlayerDestinationButtons.Add(b); @@ -286,24 +299,22 @@ namespace VocaluxeLib.PartyModes.Challenge } b.Visible = true; b.Enabled = false; - AddButton(b); + _AddButton(b); } } private void _AddButtonPlayerChoose() { - Buttons[_ButtonPlayerChoose].Visible = false; + _Buttons[_ButtonPlayerChoose].Visible = false; _PlayerChooseButtons = new List(); int row = 0; int column = 0; for (int i = 1; i <= _PlayerChooseButtonsNumH * _PlayerChooseButtonsNumW; i++) { - CButton b = GetNewButton(Buttons[_ButtonPlayerChoose]); + CButton b = GetNewButton(_Buttons[_ButtonPlayerChoose]); b.Rect.X = _PlayerChooseButtonsFirstX + column * (b.Rect.W + _PlayerChooseButtonsSpaceH); b.Rect.Y = _PlayerChooseButtonsFirstY + row * (b.Rect.H + _PlayerChooseButtonsSpaceW); - CPlayerChooseButton pcb = new CPlayerChooseButton(); - pcb.Button = b; - pcb.ProfileID = -1; + CPlayerChooseButton pcb = new CPlayerChooseButton {Button = b, ProfileID = -1}; _PlayerChooseButtons.Add(pcb); column++; if (column >= _PlayerChooseButtonsNumH) @@ -313,7 +324,7 @@ namespace VocaluxeLib.PartyModes.Challenge } b.Visible = true; b.Enabled = false; - AddButton(b); + _AddButton(b); } } @@ -329,7 +340,7 @@ namespace VocaluxeLib.PartyModes.Challenge private void _UpdateButtonPlayerChoose(int offset) { - int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH; + const int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH; if (offset < 0) offset = 0; @@ -341,8 +352,10 @@ namespace VocaluxeLib.PartyModes.Challenge { _PlayerChooseButtons[i].ProfileID = _PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]; _PlayerChooseButtons[i].Button.Text.Text = CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].PlayerName; - _PlayerChooseButtons[i].Button.Texture = CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; - _PlayerChooseButtons[i].Button.SelTexture = CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; + _PlayerChooseButtons[i].Button.Texture = + CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; + _PlayerChooseButtons[i].Button.SelTexture = + CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; _PlayerChooseButtons[i].Button.Color = new SColorF(1, 1, 1, 0.6f); _PlayerChooseButtons[i].Button.SelColor = new SColorF(1, 1, 1, 1); _PlayerChooseButtons[i].Button.Enabled = true; @@ -351,10 +364,10 @@ namespace VocaluxeLib.PartyModes.Challenge { _PlayerChooseButtons[i].ProfileID = -1; _PlayerChooseButtons[i].Button.Text.Text = String.Empty; - _PlayerChooseButtons[i].Button.Texture = Buttons[_ButtonPlayerChoose].Texture; - _PlayerChooseButtons[i].Button.SelTexture = Buttons[_ButtonPlayerChoose].SelTexture; - _PlayerChooseButtons[i].Button.Color = Buttons[_ButtonPlayerChoose].Color; - _PlayerChooseButtons[i].Button.SelColor = Buttons[_ButtonPlayerChoose].SelColor; + _PlayerChooseButtons[i].Button.Texture = _Buttons[_ButtonPlayerChoose].Texture; + _PlayerChooseButtons[i].Button.SelTexture = _Buttons[_ButtonPlayerChoose].SelTexture; + _PlayerChooseButtons[i].Button.Color = _Buttons[_ButtonPlayerChoose].Color; + _PlayerChooseButtons[i].Button.SelColor = _Buttons[_ButtonPlayerChoose].SelColor; _PlayerChooseButtons[i].Button.Enabled = false; } } @@ -369,19 +382,7 @@ namespace VocaluxeLib.PartyModes.Challenge bool visible = false; //Show profile only if active if (CBase.Profiles.GetProfiles()[i].Active == EOffOn.TR_CONFIG_ON) - { - visible = true; - - for (int p = 0; p < _Data.ScreenNames.ProfileIDs.Count; p++) - { - //Don't show profile if is selected - if (_Data.ScreenNames.ProfileIDs[p] == i) - { - visible = false; - break; - } - } - } + visible = _Data.ScreenNames.ProfileIDs.All(profileID => profileID != i); if (visible) _PlayerChooseButtonsVisibleProfiles.Add(i); } @@ -418,10 +419,10 @@ namespace VocaluxeLib.PartyModes.Challenge } else { - _PlayerDestinationButtons[i].Color = Buttons[_ButtonPlayerDestination].Color; - _PlayerDestinationButtons[i].SelColor = Buttons[_ButtonPlayerDestination].SelColor; - _PlayerDestinationButtons[i].Texture = Buttons[_ButtonPlayerDestination].Texture; - _PlayerDestinationButtons[i].SelTexture = Buttons[_ButtonPlayerDestination].SelTexture; + _PlayerDestinationButtons[i].Color = _Buttons[_ButtonPlayerDestination].Color; + _PlayerDestinationButtons[i].SelColor = _Buttons[_ButtonPlayerDestination].SelColor; + _PlayerDestinationButtons[i].Texture = _Buttons[_ButtonPlayerDestination].Texture; + _PlayerDestinationButtons[i].SelTexture = _Buttons[_ButtonPlayerDestination].SelTexture; _PlayerDestinationButtons[i].Text.Text = String.Empty; _PlayerDestinationButtons[i].Enabled = false; } @@ -432,72 +433,63 @@ namespace VocaluxeLib.PartyModes.Challenge { if (_Data.ScreenNames.ProfileIDs.Count == _NumPlayer) { - Buttons[_ButtonNext].Visible = true; - SetInteractionToButton(Buttons[_ButtonNext]); + _Buttons[_ButtonNext].Visible = true; + _SetInteractionToButton(_Buttons[_ButtonNext]); } else - Buttons[_ButtonNext].Visible = false; + _Buttons[_ButtonNext].Visible = false; } private bool _OnAdd() { - for (int i = 0; i < _PlayerChooseButtons.Count; i++) + foreach (CPlayerChooseButton button in _PlayerChooseButtons) { - if (_PlayerChooseButtons[i].Button.Selected && _PlayerChooseButtons[i].ProfileID != -1) - { - if (_Data.ScreenNames.ProfileIDs.Count < _NumPlayer) - { - _Data.ScreenNames.ProfileIDs.Add(_PlayerChooseButtons[i].ProfileID); - int added = _Data.ScreenNames.ProfileIDs.Count - 1; - _UpdateButtonNext(); - //Update texture and name - _PlayerDestinationButtons[added].Color = new SColorF(1, 1, 1, 0.6f); - _PlayerDestinationButtons[added].SelColor = new SColorF(1, 1, 1, 1); - _PlayerDestinationButtons[added].Texture = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].Avatar.Texture; - _PlayerDestinationButtons[added].SelTexture = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].Avatar.Texture; - _PlayerDestinationButtons[added].Text.Text = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].PlayerName; - _PlayerDestinationButtons[added].Enabled = true; - //Update Tiles-List - _UpdateButtonPlayerChoose(); - CheckInteraction(); - return true; - } - } + if (!button.Button.Selected || button.ProfileID == -1 || _Data.ScreenNames.ProfileIDs.Count >= _NumPlayer) + continue; + _Data.ScreenNames.ProfileIDs.Add(button.ProfileID); + int added = _Data.ScreenNames.ProfileIDs.Count - 1; + _UpdateButtonNext(); + //Update texture and name + _PlayerDestinationButtons[added].Color = new SColorF(1, 1, 1, 0.6f); + _PlayerDestinationButtons[added].SelColor = new SColorF(1, 1, 1, 1); + _PlayerDestinationButtons[added].Texture = CBase.Profiles.GetProfiles()[button.ProfileID].Avatar.Texture; + _PlayerDestinationButtons[added].SelTexture = CBase.Profiles.GetProfiles()[button.ProfileID].Avatar.Texture; + _PlayerDestinationButtons[added].Text.Text = CBase.Profiles.GetProfiles()[button.ProfileID].PlayerName; + _PlayerDestinationButtons[added].Enabled = true; + //Update Tiles-List + _UpdateButtonPlayerChoose(); + _CheckInteraction(); + return true; } return false; } - private bool _OnRemove() + private void _OnRemove() { for (int i = 0; i < _PlayerDestinationButtons.Count; i++) { - if (_PlayerDestinationButtons[i].Selected) - { - if ((i + 1) <= _Data.ScreenNames.ProfileIDs.Count) - { - _Data.ScreenNames.ProfileIDs.RemoveAt(i); - _UpdateButtonNext(); - _UpdateButtonPlayerDestination(); - _UpdateButtonPlayerChoose(); - CheckInteraction(); - return true; - } - } + if (!_PlayerDestinationButtons[i].Selected) + continue; + if ((i + 1) > _Data.ScreenNames.ProfileIDs.Count) + continue; + _Data.ScreenNames.ProfileIDs.RemoveAt(i); + _UpdateButtonNext(); + _UpdateButtonPlayerDestination(); + _UpdateButtonPlayerChoose(); + _CheckInteraction(); + return; } - return false; } private void _Back() { - _Data.ScreenNames.FadeToConfig = true; - _Data.ScreenNames.FadeToMain = false; + _Data.ScreenNames.FadeBack = true; _PartyMode.DataFromScreen(ThemeName, _Data); } private void _Next() { - _Data.ScreenNames.FadeToConfig = false; - _Data.ScreenNames.FadeToMain = true; + _Data.ScreenNames.FadeBack = false; _PartyMode.DataFromScreen(ThemeName, _Data); } } diff --git a/PartyModes/PartyModeChallenge/GlobalSuppressions.cs b/PartyModes/PartyModeChallenge/GlobalSuppressions.cs index 21fb9bcd..a29227be 100644 Binary files a/PartyModes/PartyModeChallenge/GlobalSuppressions.cs and b/PartyModes/PartyModeChallenge/GlobalSuppressions.cs differ diff --git a/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs b/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs index 37ff59f5..4114320b 100644 --- a/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs +++ b/PartyModes/PartyModeChallengeMedley/CChallengeRounds.cs @@ -1,5 +1,25 @@ -using System; +#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.Linq; namespace VocaluxeLib.PartyModes.ChallengeMedley { @@ -8,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) { @@ -53,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(); @@ -136,38 +151,21 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley if (_Combs.Count == 0) _Create(); - CCombination combs = new CCombination(); - if (_NumPlayer == _NumMics) return _Combs[0]; //filter against PlayerNrDemand 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; int rand = _Rand.Next(num); @@ -203,7 +201,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public class CCombination { - public List Player; + public readonly List Player; public CCombination() { @@ -212,28 +210,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(List playerIndices) + 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(List playerIndices) + 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 5bfb505e..e733ddb3 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -1,3 +1,22 @@ +#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.Runtime.InteropServices; @@ -40,17 +59,15 @@ 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; public int CompareTo(object obj) { - if (obj is CResultTableRow) + CResultTableRow row = obj as CResultTableRow; + if (row != null) { - CResultTableRow row = (CResultTableRow)obj; - int res = row.NumGamePoints.CompareTo(NumGamePoints); if (res == 0) { @@ -84,7 +101,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public struct SFromScreenNames { public bool FadeToConfig; - public bool FadeToMain; public List ProfileIDs; } @@ -164,14 +180,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _ToScreenNames = new SDataToScreenNames(); _ToScreenMain = new SDataToScreenMain(); - _GameData = new SData(); - _GameData.NumPlayer = 4; - _GameData.NumPlayerAtOnce = 2; - _GameData.NumRounds = 2; - _GameData.CurrentRoundNr = 1; - _GameData.ProfileIDs = new List(); - _GameData.CatSongIndices = null; - _GameData.Results = null; + _GameData = new SData {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 2, CurrentRoundNr = 1, ProfileIDs = new List(), CatSongIndices = null, Results = null}; } public override bool Init() @@ -197,7 +206,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public override void DataFromScreen(string screenName, Object data) { - SDataFromScreen dataFrom = new SDataFromScreen(); + SDataFromScreen dataFrom; switch (screenName) { case "PartyScreenChallengeMedleyConfig": @@ -357,10 +366,11 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley return _ScreenSongOptions; } + // ReSharper disable RedundantAssignment public override void OnSongChange(int songIndex, ref SScreenSongOptions screenSongOptions) + // ReSharper restore RedundantAssignment { - if (_ScreenSongOptions.Selection.SongIndex != -1) - _ScreenSongOptions.Selection.SongIndex = -1; + _ScreenSongOptions.Selection.SongIndex = -1; if (_ScreenSongOptions.Selection.SelectNextRandomSong && songIndex != -1) { @@ -377,7 +387,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley screenSongOptions = _ScreenSongOptions; } + // ReSharper disable RedundantAssignment public override void OnCategoryChange(int categoryIndex, ref SScreenSongOptions screenSongOptions) + // ReSharper restore RedundantAssignment { if (_GameData.CatSongIndices != null && categoryIndex != -1) { @@ -470,33 +482,22 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley #region PlayerNames CBase.Game.SetNumPlayer(_GameData.NumPlayerAtOnce); - SPlayer[] player = CBase.Game.GetPlayer(); + SPlayer[] player = CBase.Game.GetPlayers(); if (player == null) return false; if (player.Length < _GameData.NumPlayerAtOnce) return false; - SProfile[] profiles = CBase.Profiles.GetProfiles(); CCombination c = _GameData.Rounds.GetRound(_GameData.CurrentRoundNr - 1); for (int i = 0; i < _GameData.NumPlayerAtOnce; i++) { - //default values - player[i].Name = "foobar"; - player[i].Difficulty = EGameDifficulty.TR_CONFIG_EASY; - player[i].ProfileID = -1; - //try to fill with the right data if (c != null) - { - if (_GameData.ProfileIDs[c.Player[i]] < profiles.Length) - { - player[i].Name = profiles[_GameData.ProfileIDs[c.Player[i]]].PlayerName; - player[i].Difficulty = profiles[_GameData.ProfileIDs[c.Player[i]]].Difficulty; - player[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; - } - } + player[i].ProfileID = _GameData.ProfileIDs[c.Player[i]]; + else + player[i].ProfileID = -1; } #endregion PlayerNames @@ -504,8 +505,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) @@ -520,11 +521,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); @@ -532,12 +533,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; @@ -616,13 +617,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { for (int i = 0; i < _GameData.NumPlayer; i++) { - CResultTableRow row = new CResultTableRow(); - row.PlayerID = _GameData.ProfileIDs[i]; - row.NumPlayed = 0; - row.NumRounds = 0; - row.NumWon = 0; - row.NumSingPoints = 0; - row.NumGamePoints = 0; + CResultTableRow row = new CResultTableRow {PlayerID = _GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0}; _GameData.ResultTable.Add(row); } @@ -682,7 +677,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; @@ -697,13 +691,13 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley int pos = 1; int lastPoints = 0; int lastSingPoints = 0; - for (int i = 0; i < _GameData.ResultTable.Count; i++) + foreach (CResultTableRow resultRow in _GameData.ResultTable) { - if (lastPoints > _GameData.ResultTable[i].NumGamePoints || lastSingPoints > _GameData.ResultTable[i].NumSingPoints) + if (lastPoints > resultRow.NumGamePoints || lastSingPoints > resultRow.NumSingPoints) pos++; - _GameData.ResultTable[i].Position = pos; - lastPoints = _GameData.ResultTable[i].NumGamePoints; - lastSingPoints = _GameData.ResultTable[i].NumSingPoints; + resultRow.Position = pos; + lastPoints = resultRow.NumGamePoints; + lastSingPoints = resultRow.NumSingPoints; } } @@ -712,15 +706,11 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley List result = new List(); for (int i = 0; i < _GameData.NumPlayerAtOnce; i++) { - SStats stat = new SStats(); - stat.ProfileID = results[i].ProfileID; - stat.SingPoints = (int)Math.Round(results[i].Points); - stat.Won = 0; - stat.GamePoints = 0; + SStats stat = new SStats {ProfileID = results[i].ProfileID, SingPoints = (int)Math.Round(results[i].Points), Won = 0, GamePoints = 0}; result.Add(stat); } - result.Sort(delegate(SStats s1, SStats s2) { return s1.SingPoints.CompareTo(s2.SingPoints); }); + result.Sort((s1, s2) => s1.SingPoints.CompareTo(s2.SingPoints)); int current = result[result.Count - 1].SingPoints; int points = result.Count; diff --git a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyConfig.cs b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyConfig.cs index 111049b5..ab99973c 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyConfig.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyConfig.cs @@ -1,10 +1,31 @@ +#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.Windows.Forms; using VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes.ChallengeMedley { + // ReSharper disable UnusedMember.Global public class CPartyScreenChallengeMedleyConfig : CMenuParty + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -32,20 +53,15 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _ThemeButtons = new string[] {_ButtonNext, _ButtonBack}; _Data = new SDataFromScreen(); - SFromScreenConfig config = new SFromScreenConfig(); - config.NumPlayer = 4; - config.NumPlayerAtOnce = 2; - config.NumRounds = 12; + SFromScreenConfig config = new SFromScreenConfig {NumPlayer = 4, NumPlayerAtOnce = 2, NumRounds = 12}; _Data.ScreenConfig = config; } public override void DataToScreen(object receivedData) { - SDataToScreenConfig config = new SDataToScreenConfig(); - try { - config = (SDataToScreenConfig)receivedData; + SDataToScreenConfig config = (SDataToScreenConfig)receivedData; _Data.ScreenConfig.NumPlayer = config.NumPlayer; _Data.ScreenConfig.NumPlayerAtOnce = config.NumPlayerAtOnce; _Data.ScreenConfig.NumRounds = config.NumRounds; @@ -73,10 +89,10 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley case Keys.Enter: _UpdateSlides(); - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); break; @@ -96,13 +112,13 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { _UpdateSlides(); - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); } @@ -139,10 +155,10 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private void _RebuildSlides() { // build num player slide (min player ... max player); - SelectSlides[_SelectSlideNumPlayers].Clear(); + _SelectSlides[_SelectSlideNumPlayers].Clear(); for (int i = _PartyMode.GetMinPlayer(); i <= _PartyMode.GetMaxPlayer(); i++) - SelectSlides[_SelectSlideNumPlayers].AddValue(i.ToString()); - SelectSlides[_SelectSlideNumPlayers].Selection = _Data.ScreenConfig.NumPlayer - _PartyMode.GetMinPlayer(); + _SelectSlides[_SelectSlideNumPlayers].AddValue(i.ToString()); + _SelectSlides[_SelectSlideNumPlayers].Selection = _Data.ScreenConfig.NumPlayer - _PartyMode.GetMinPlayer(); _UpdateMicsAtOnce(); _SetRoundSteps(); @@ -153,9 +169,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { int player = _Data.ScreenConfig.NumPlayer; int mics = _Data.ScreenConfig.NumPlayerAtOnce; - _Data.ScreenConfig.NumPlayer = SelectSlides[_SelectSlideNumPlayers].Selection + _PartyMode.GetMinPlayer(); - _Data.ScreenConfig.NumPlayerAtOnce = SelectSlides[_SelectSlideNumMics].Selection + _PartyMode.GetMinPlayer(); - _Data.ScreenConfig.NumRounds = (SelectSlides[_SelectSlideNumRounds].Selection + 1) * _RoundSteps; + _Data.ScreenConfig.NumPlayer = _SelectSlides[_SelectSlideNumPlayers].Selection + _PartyMode.GetMinPlayer(); + _Data.ScreenConfig.NumPlayerAtOnce = _SelectSlides[_SelectSlideNumMics].Selection + _PartyMode.GetMinPlayer(); + _Data.ScreenConfig.NumRounds = (_SelectSlides[_SelectSlideNumRounds].Selection + 1) * _RoundSteps; _UpdateMicsAtOnce(); _SetRoundSteps(); @@ -182,19 +198,19 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _Data.ScreenConfig.NumPlayerAtOnce = maxNum; // build mics at once slide - SelectSlides[_SelectSlideNumMics].Clear(); + _SelectSlides[_SelectSlideNumMics].Clear(); for (int i = 1; i <= maxNum; i++) - SelectSlides[_SelectSlideNumMics].AddValue(i.ToString()); - SelectSlides[_SelectSlideNumMics].Selection = _Data.ScreenConfig.NumPlayerAtOnce - _PartyMode.GetMinPlayer(); + _SelectSlides[_SelectSlideNumMics].AddValue(i.ToString()); + _SelectSlides[_SelectSlideNumMics].Selection = _Data.ScreenConfig.NumPlayerAtOnce - _PartyMode.GetMinPlayer(); } private void _UpdateSlideRounds() { // build num rounds slide - SelectSlides[_SelectSlideNumRounds].Clear(); + _SelectSlides[_SelectSlideNumRounds].Clear(); for (int i = _RoundSteps; i <= _MaxNumRounds; i += _RoundSteps) - SelectSlides[_SelectSlideNumRounds].AddValue(i.ToString()); - SelectSlides[_SelectSlideNumRounds].Selection = _Data.ScreenConfig.NumRounds / _RoundSteps - 1; + _SelectSlides[_SelectSlideNumRounds].AddValue(i.ToString()); + _SelectSlides[_SelectSlideNumRounds].Selection = _Data.ScreenConfig.NumRounds / _RoundSteps - 1; } private void _SetRoundSteps() @@ -208,10 +224,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley int res = _Data.ScreenConfig.NumPlayer / _Data.ScreenConfig.NumPlayerAtOnce; int mod = _Data.ScreenConfig.NumPlayer % _Data.ScreenConfig.NumPlayerAtOnce; - if (mod == 0) - _RoundSteps = res; - else - _RoundSteps = _Data.ScreenConfig.NumPlayer; + _RoundSteps = mod == 0 ? res : _Data.ScreenConfig.NumPlayer; } private void _Back() diff --git a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs index 4a0dd98f..02343aa0 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs @@ -1,3 +1,22 @@ +#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.Windows.Forms; @@ -22,7 +41,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley public List TextScores; } + // ReSharper disable UnusedMember.Global public class CPartyScreenChallengeMedleyMain : CMenuParty + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -72,13 +93,12 @@ 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() { - _Data = new SDataFromScreen(); - _Data.ScreenMain = new SFromScreenMain(); + _Data = new SDataFromScreen {ScreenMain = new SFromScreenMain()}; } public override void Init() @@ -87,11 +107,15 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _ThemeTexts = new string[] { - _TextPosition, _TextPlayerName, _TextNumPlayed, _TextWon, _TextSingPoints, _TextGamePoints, _TextNextPlayer, _TextPopupReallyExit, _TextRoundNumber, _TextRoundPlayer, + _TextPosition, _TextPlayerName, _TextNumPlayed, _TextWon, _TextSingPoints, _TextGamePoints, _TextNextPlayer, _TextPopupReallyExit, _TextRoundNumber, + _TextRoundPlayer, _TextRoundScore, _TextFinishMessage, _TextFinishPlayerWin, _TextNextPlayerMessage }; _ThemeButtons = new string[] - {_ButtonNextRound, _ButtonBack, _ButtonExit, _ButtonPopupYes, _ButtonPopupNo, _ButtonPlayerScrollDown, _ButtonPlayerScrollUp, _ButtonRoundsScrollDown, _ButtonRoundsScrollUp}; + { + _ButtonNextRound, _ButtonBack, _ButtonExit, _ButtonPopupYes, _ButtonPopupNo, _ButtonPlayerScrollDown, _ButtonPlayerScrollUp, _ButtonRoundsScrollDown, + _ButtonRoundsScrollUp + }; _ThemeStatics = new string[] {_StaticPopupBG, _StaticNextPlayer}; } @@ -107,20 +131,18 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley for (int i = 0; i < _PartyMode.GetMaxPlayer(); i++) { - _NextPlayerTexts.Add(GetNewText(Texts[_TextNextPlayer])); - AddText(_NextPlayerTexts[_NextPlayerTexts.Count - 1]); - _NextPlayerStatics.Add(GetNewStatic(Statics[_StaticNextPlayer])); - AddStatic(_NextPlayerStatics[_NextPlayerStatics.Count - 1]); + _NextPlayerTexts.Add(GetNewText(_Texts[_TextNextPlayer])); + _AddText(_NextPlayerTexts[_NextPlayerTexts.Count - 1]); + _NextPlayerStatics.Add(GetNewStatic(_Statics[_StaticNextPlayer])); + _AddStatic(_NextPlayerStatics[_NextPlayerStatics.Count - 1]); } } public override void DataToScreen(object receivedData) { - SDataToScreenMain data = new SDataToScreenMain(); - try { - data = (SDataToScreenMain)receivedData; + SDataToScreenMain data = (SDataToScreenMain)receivedData; _GameState = data; } catch (Exception e) @@ -154,26 +176,26 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley case Keys.Enter: if (!_ExitPopupVisible) { - if (Buttons[_ButtonNextRound].Selected) + if (_Buttons[_ButtonNextRound].Selected) _NextRound(); - if (Buttons[_ButtonBack].Selected && _GameState.CurrentRoundNr == 1) + if (_Buttons[_ButtonBack].Selected && _GameState.CurrentRoundNr == 1) _Back(); - if (Buttons[_ButtonExit].Selected && _GameState.CurrentRoundNr > 1) + if (_Buttons[_ButtonExit].Selected && _GameState.CurrentRoundNr > 1) _ShowPopup(true); - if (Buttons[_ButtonPlayerScrollUp].Selected) + if (_Buttons[_ButtonPlayerScrollUp].Selected) _ScrollPlayerTable(-1); - if (Buttons[_ButtonPlayerScrollDown].Selected) + if (_Buttons[_ButtonPlayerScrollDown].Selected) _ScrollPlayerTable(1); - if (Buttons[_ButtonRoundsScrollUp].Selected) + if (_Buttons[_ButtonRoundsScrollUp].Selected) _ScrollRoundsTable(-1); - if (Buttons[_ButtonRoundsScrollDown].Selected) + if (_Buttons[_ButtonRoundsScrollDown].Selected) _ScrollRoundsTable(1); } else { - if (Buttons[_ButtonPopupYes].Selected) + if (_Buttons[_ButtonPopupYes].Selected) _EndParty(); - if (Buttons[_ButtonPopupNo].Selected) + if (_Buttons[_ButtonPopupNo].Selected) _ShowPopup(false); } break; @@ -186,30 +208,30 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { if (!_ExitPopupVisible) { - if (Buttons[_ButtonNextRound].Selected) + if (_Buttons[_ButtonNextRound].Selected) _NextRound(); - if (Buttons[_ButtonBack].Selected && _GameState.CurrentRoundNr == 1) + if (_Buttons[_ButtonBack].Selected && _GameState.CurrentRoundNr == 1) _Back(); - if (Buttons[_ButtonExit].Selected && _GameState.CurrentRoundNr > 1) + if (_Buttons[_ButtonExit].Selected && _GameState.CurrentRoundNr > 1) _ShowPopup(true); - if (Buttons[_ButtonPlayerScrollUp].Selected) + if (_Buttons[_ButtonPlayerScrollUp].Selected) _ScrollPlayerTable(-1); - if (Buttons[_ButtonPlayerScrollDown].Selected) + if (_Buttons[_ButtonPlayerScrollDown].Selected) _ScrollPlayerTable(1); - if (Buttons[_ButtonRoundsScrollUp].Selected) + if (_Buttons[_ButtonRoundsScrollUp].Selected) _ScrollRoundsTable(-1); - if (Buttons[_ButtonRoundsScrollDown].Selected) + if (_Buttons[_ButtonRoundsScrollDown].Selected) _ScrollRoundsTable(1); } else { - if (Buttons[_ButtonPopupYes].Selected) + if (_Buttons[_ButtonPopupYes].Selected) _EndParty(); - if (Buttons[_ButtonPopupNo].Selected) + if (_Buttons[_ButtonPopupNo].Selected) _ShowPopup(false); } } @@ -256,29 +278,29 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley if (_GameState.CurrentRoundNr == 1) { - Buttons[_ButtonBack].Visible = true; - Buttons[_ButtonExit].Visible = false; + _Buttons[_ButtonBack].Visible = true; + _Buttons[_ButtonExit].Visible = false; } else { - Buttons[_ButtonBack].Visible = false; - Buttons[_ButtonExit].Visible = true; + _Buttons[_ButtonBack].Visible = false; + _Buttons[_ButtonExit].Visible = true; } if (_GameState.CurrentRoundNr <= _GameState.Combs.Count) { - Buttons[_ButtonNextRound].Visible = true; - Texts[_TextFinishMessage].Visible = false; - Texts[_TextFinishPlayerWin].Visible = false; - SetInteractionToButton(Buttons[_ButtonNextRound]); + _Buttons[_ButtonNextRound].Visible = true; + _Texts[_TextFinishMessage].Visible = false; + _Texts[_TextFinishPlayerWin].Visible = false; + _SetInteractionToButton(_Buttons[_ButtonNextRound]); } else { - Buttons[_ButtonNextRound].Visible = false; - Texts[_TextFinishMessage].Visible = true; - Texts[_TextFinishPlayerWin].Visible = true; - Texts[_TextFinishPlayerWin].Text = _GetPlayerWinString(); - SetInteractionToButton(Buttons[_ButtonExit]); + _Buttons[_ButtonNextRound].Visible = false; + _Texts[_TextFinishMessage].Visible = true; + _Texts[_TextFinishPlayerWin].Visible = true; + _Texts[_TextFinishPlayerWin].Text = _GetPlayerWinString(); + _SetInteractionToButton(_Buttons[_ButtonExit]); } _ShowPopup(false); @@ -311,13 +333,13 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { _ExitPopupVisible = visible; - Statics[_StaticPopupBG].Visible = _ExitPopupVisible; - Texts[_TextPopupReallyExit].Visible = _ExitPopupVisible; - Buttons[_ButtonPopupYes].Visible = _ExitPopupVisible; - Buttons[_ButtonPopupNo].Visible = _ExitPopupVisible; + _Statics[_StaticPopupBG].Visible = _ExitPopupVisible; + _Texts[_TextPopupReallyExit].Visible = _ExitPopupVisible; + _Buttons[_ButtonPopupYes].Visible = _ExitPopupVisible; + _Buttons[_ButtonPopupNo].Visible = _ExitPopupVisible; if (_ExitPopupVisible) - SetInteractionToButton(Buttons[_ButtonPopupNo]); + _SetInteractionToButton(_Buttons[_ButtonPopupNo]); } private void _Back() @@ -329,9 +351,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private void _UpdateNextPlayerPositions() { - float x = CBase.Settings.GetRenderW() / 2 - ((_GameState.NumPlayerAtOnce * Statics[_StaticNextPlayer].Rect.W) + ((_GameState.NumPlayerAtOnce - 1) * 15)) / 2; - float staticY = 590; - float textY = 550; + float x = (float)CBase.Settings.GetRenderW() / 2 - ((_GameState.NumPlayerAtOnce * _Statics[_StaticNextPlayer].Rect.W) + ((_GameState.NumPlayerAtOnce - 1) * 15)) / 2; + const float staticY = 590; + const float textY = 550; for (int i = 0; i < _GameState.NumPlayerAtOnce; i++) { //static @@ -339,11 +361,11 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _NextPlayerStatics[i].Rect.Y = staticY; _NextPlayerStatics[i].Visible = true; //text - _NextPlayerTexts[i].X = x + Statics[_StaticNextPlayer].Rect.W / 2; + _NextPlayerTexts[i].X = x + _Statics[_StaticNextPlayer].Rect.W / 2; _NextPlayerTexts[i].Y = textY; _NextPlayerTexts[i].Visible = true; - x += Statics[_StaticNextPlayer].Rect.W + 15; + x += _Statics[_StaticNextPlayer].Rect.W + 15; } for (int i = _GameState.NumPlayerAtOnce; i < _PartyMode.GetMaxPlayer(); i++) { @@ -356,7 +378,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { if (_GameState.CurrentRoundNr <= _GameState.Combs.Count) { - Texts[_TextNextPlayerMessage].Visible = true; + _Texts[_TextNextPlayerMessage].Visible = true; SProfile[] profiles = CBase.Profiles.GetProfiles(); for (int i = 0; i < _GameState.NumPlayerAtOnce; i++) { @@ -368,7 +390,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley } else { - Texts[_TextNextPlayerMessage].Visible = false; + _Texts[_TextNextPlayerMessage].Visible = false; for (int i = 0; i < _GameState.NumPlayerAtOnce; i++) { _NextPlayerStatics[i].Visible = false; @@ -383,30 +405,28 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _RoundsTable = new List(); for (int i = 0; i < 5; i++) { - CRoundsTableRow rtr = new CRoundsTableRow(); - rtr.TextPlayer = new List(); - rtr.TextScores = new List(); + CRoundsTableRow rtr = new CRoundsTableRow {TextPlayer = new List(), TextScores = new List()}; _RoundsTable.Add(rtr); } //Create statics and texts for rounds - for (int round = 0; round < _RoundsTable.Count; round++) + foreach (CRoundsTableRow roundRow in _RoundsTable) { //Round-number - CText text = GetNewText(Texts[_TextRoundNumber]); - AddText(text); - _RoundsTable[round].Number = text; + CText text = GetNewText(_Texts[_TextRoundNumber]); + _AddText(text); + roundRow.Number = text; for (int row = 0; row < 2; row++) { for (int column = 0; column < 3; column++) { //Player - text = GetNewText(Texts[_TextRoundPlayer]); - AddText(text); - _RoundsTable[round].TextPlayer.Add(text); + text = GetNewText(_Texts[_TextRoundPlayer]); + _AddText(text); + roundRow.TextPlayer.Add(text); //Score - text = GetNewText(Texts[_TextRoundScore]); - AddText(text); - _RoundsTable[round].TextScores.Add(text); + text = GetNewText(_Texts[_TextRoundScore]); + _AddText(text); + roundRow.TextScores.Add(text); } } } @@ -416,30 +436,27 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { _RoundsTableScrollArea = new SRectF(); - int numPlayerInOneRow = 3; - if (_GameState.NumPlayerAtOnce <= numPlayerInOneRow) - _NumRoundsVisible = 5; - else - _NumRoundsVisible = 3; + const int numPlayerInOneRow = 3; + _NumRoundsVisible = _GameState.NumPlayerAtOnce <= numPlayerInOneRow ? 5 : 3; if (_NumRoundsVisible > _GameState.Combs.Count) _NumRoundsVisible = _GameState.Combs.Count; - float numberX = Texts[_TextRoundNumber].X; - float numberY = Texts[_TextRoundNumber].Y; + float numberX = _Texts[_TextRoundNumber].X; + float numberY = _Texts[_TextRoundNumber].Y; _RoundsTableScrollArea.X = numberX; _RoundsTableScrollArea.Y = numberY; - _RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - Texts[_TextRoundNumber].X - 20; + _RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20; - float delta = Texts[_TextRoundNumber].Height; + float delta = _Texts[_TextRoundNumber].Height; //Update statics and texts for rounds - for (int round = 0; round < _RoundsTable.Count; round++) + foreach (CRoundsTableRow roundRow in _RoundsTable) { //Round-number - _RoundsTable[round].Number.X = numberX; - _RoundsTable[round].Number.Y = numberY; + roundRow.Number.X = numberX; + roundRow.Number.Y = numberY; int numInnerRows = (int)Math.Ceiling(_GameState.NumPlayerAtOnce / ((double)numPlayerInOneRow)); for (int row = 0; row < numInnerRows; row++) { @@ -453,17 +470,17 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley for (int column = row * numPlayerInOneRow; column < num; column++) { //Player - float x = numberX + 15 + (CBase.Settings.GetRenderW() - Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow * (column - row * numPlayerInOneRow) + - ((CBase.Settings.GetRenderW() - Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow) / 2; - float maxw = ((CBase.Settings.GetRenderW() - Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow) / 2 - 5; - _RoundsTable[round].TextPlayer[column].X = x; - _RoundsTable[round].TextPlayer[column].Y = numberY; - _RoundsTable[round].TextPlayer[column].MaxWidth = maxw; + float x = numberX + 15 + (CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow * (column - row * numPlayerInOneRow) + + ((CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow) / 2; + float maxw = ((CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20) / numPlayerInThisRow) / 2 - 5; + roundRow.TextPlayer[column].X = x; + roundRow.TextPlayer[column].Y = numberY; + roundRow.TextPlayer[column].MaxWidth = maxw; //Score - _RoundsTable[round].TextScores[column] = _RoundsTable[round].TextScores[column]; - _RoundsTable[round].TextScores[column].X = x; - _RoundsTable[round].TextScores[column].Y = numberY + delta; - _RoundsTable[round].TextScores[column].MaxWidth = maxw; + roundRow.TextScores[column] = roundRow.TextScores[column]; + roundRow.TextScores[column].X = x; + roundRow.TextScores[column].Y = numberY + delta; + roundRow.TextScores[column].MaxWidth = maxw; } numberY = numberY + delta + delta; } @@ -484,7 +501,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _RoundsTable[i].Number.Visible = true; _RoundsTable[i].TextPlayer[p].Visible = true; _RoundsTable[i].TextScores[p].Visible = true; - _RoundsTable[i].Number.Text = (i + 1 + _RoundsTableOffset).ToString() + ")"; + _RoundsTable[i].Number.Text = (i + 1 + _RoundsTableOffset) + ")"; int pID = _GameState.ProfileIDs[_GameState.Combs[i + _RoundsTableOffset].Player[p]]; _RoundsTable[i].TextPlayer[p].Text = profile[pID].PlayerName; if ((_GameState.CurrentRoundNr - 1) > i + _RoundsTableOffset) @@ -509,32 +526,30 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley } } - Buttons[_ButtonRoundsScrollUp].Visible = _RoundsTableOffset > 0; - Buttons[_ButtonRoundsScrollDown].Visible = _GameState.Combs.Count - _NumRoundsVisible - _RoundsTableOffset > 0; + _Buttons[_ButtonRoundsScrollUp].Visible = _RoundsTableOffset > 0; + _Buttons[_ButtonRoundsScrollDown].Visible = _GameState.Combs.Count - _NumRoundsVisible - _RoundsTableOffset > 0; } private void _BuildPlayerTable() { - _PlayerTableScrollArea = new SRectF(); - _PlayerTableScrollArea.X = Texts[_TextPosition].X; - _PlayerTableScrollArea.Y = Texts[_TextPosition].Y; - _PlayerTableScrollArea.W = Texts[_TextGamePoints].X - Texts[_TextPosition].X; + _PlayerTableScrollArea = new SRectF {X = _Texts[_TextPosition].X, Y = _Texts[_TextPosition].Y, W = _Texts[_TextGamePoints].X - _Texts[_TextPosition].X}; _PlayerTable = new List(); - float delta = Texts[_TextPosition].Height * 1.2f; + float delta = _Texts[_TextPosition].Height * 1.2f; float h = 0; for (int i = 0; i < 10; i++) { - STableRow row = new STableRow(); - - row.Pos = GetNewText(Texts[_TextPosition]); - row.Name = GetNewText(Texts[_TextPlayerName]); - row.Rounds = GetNewText(Texts[_TextNumPlayed]); - row.Won = GetNewText(Texts[_TextWon]); - row.SingPoints = GetNewText(Texts[_TextSingPoints]); - row.GamePoints = GetNewText(Texts[_TextGamePoints]); + STableRow row = new STableRow + { + Pos = GetNewText(_Texts[_TextPosition]), + Name = GetNewText(_Texts[_TextPlayerName]), + Rounds = GetNewText(_Texts[_TextNumPlayed]), + Won = GetNewText(_Texts[_TextWon]), + SingPoints = GetNewText(_Texts[_TextSingPoints]), + GamePoints = GetNewText(_Texts[_TextGamePoints]) + }; row.Pos.Y += delta * (i + 1); row.Name.Y += delta * (i + 1); @@ -543,7 +558,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley row.SingPoints.Y += delta * (i + 1); row.GamePoints.Y += delta * (i + 1); - row.Pos.Text = (i + 1).ToString() + "."; + row.Pos.Text = (i + 1) + "."; row.Pos.Visible = false; row.Name.Visible = false; @@ -552,12 +567,12 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley row.SingPoints.Visible = false; row.GamePoints.Visible = false; - AddText(row.Pos); - AddText(row.Name); - AddText(row.Rounds); - AddText(row.Won); - AddText(row.SingPoints); - AddText(row.GamePoints); + _AddText(row.Pos); + _AddText(row.Name); + _AddText(row.Rounds); + _AddText(row.Won); + _AddText(row.SingPoints); + _AddText(row.GamePoints); _PlayerTable.Add(row); @@ -583,9 +598,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley row.SingPoints.Visible = true; row.GamePoints.Visible = true; - row.Pos.Text = _GameState.ResultTable[i + _PlayerTableOffset].Position.ToString() + "."; + 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(); @@ -601,8 +616,8 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley } } - Buttons[_ButtonPlayerScrollUp].Visible = _PlayerTableOffset > 0; - Buttons[_ButtonPlayerScrollDown].Visible = _GameState.ProfileIDs.Count - _NumPlayerVisible - _PlayerTableOffset > 0; + _Buttons[_ButtonPlayerScrollUp].Visible = _PlayerTableOffset > 0; + _Buttons[_ButtonPlayerScrollDown].Visible = _GameState.ProfileIDs.Count - _NumPlayerVisible - _PlayerTableOffset > 0; } private void _ScrollPlayerTable(int offset) diff --git a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs index 45626757..e073f362 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyNames.cs @@ -1,3 +1,22 @@ +#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.Windows.Forms; @@ -5,7 +24,9 @@ using VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes.ChallengeMedley { + // ReSharper disable UnusedMember.Global public class CPartyScreenChallengeMedleyNames : CMenuParty + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -22,7 +43,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private List _PlayerDestinationButtons; //PlayerDestinationButtons-Option private const int _PlayerDestinationButtonsNumH = 3; - private const int _PlayerDestinationButtonsNumW = 4; private const int _PlayerDestinationButtonsFirstX = 900; private const int _PlayerDestinationButtonsFirstY = 105; private const int _PlayerDestinationButtonsSpaceH = 15; @@ -35,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; @@ -65,27 +85,19 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _Data.ScreenNames.ProfileIDs = new List(); - List buttons = new List(); _ThemeButtons = new string[] {_ButtonBack, _ButtonNext, _ButtonPlayerDestination, _ButtonPlayerChoose}; _Data = new SDataFromScreen(); - SFromScreenNames names = new SFromScreenNames(); - names.FadeToConfig = false; - names.FadeToMain = false; - names.ProfileIDs = new List(); + SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, ProfileIDs = new List()}; _Data.ScreenNames = names; } public override void DataToScreen(object receivedData) { - SDataToScreenNames config = new SDataToScreenNames(); - try { - config = (SDataToScreenNames)receivedData; - _Data.ScreenNames.ProfileIDs = config.ProfileIDs; - if (_Data.ScreenNames.ProfileIDs == null) - _Data.ScreenNames.ProfileIDs = new List(); + SDataToScreenNames config = (SDataToScreenNames)receivedData; + _Data.ScreenNames.ProfileIDs = config.ProfileIDs ?? new List(); _NumPlayer = config.NumPlayer; @@ -113,10 +125,10 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley break; case Keys.Enter: - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); if (!_OnAdd()) @@ -218,12 +230,12 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _ChooseAvatarStatic.Visible = false; } - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); if (!_OnAdd()) @@ -268,13 +280,13 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private void _AddButtonPlayerDestination() { - Buttons[_ButtonPlayerDestination].Visible = false; + _Buttons[_ButtonPlayerDestination].Visible = false; _PlayerDestinationButtons = new List(); int row = 0; int column = 0; for (int i = 1; i <= _PartyMode.GetMaxPlayer(); i++) { - CButton b = GetNewButton(Buttons[_ButtonPlayerDestination]); + CButton b = GetNewButton(_Buttons[_ButtonPlayerDestination]); b.Rect.X = _PlayerDestinationButtonsFirstX + column * (b.Rect.W + _PlayerDestinationButtonsSpaceH); b.Rect.Y = _PlayerDestinationButtonsFirstY + row * (b.Rect.H + _PlayerDestinationButtonsSpaceW); _PlayerDestinationButtons.Add(b); @@ -286,24 +298,22 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley } b.Visible = true; b.Enabled = false; - AddButton(b); + _AddButton(b); } } private void _AddButtonPlayerChoose() { - Buttons[_ButtonPlayerChoose].Visible = false; + _Buttons[_ButtonPlayerChoose].Visible = false; _PlayerChooseButtons = new List(); int row = 0; int column = 0; for (int i = 1; i <= _PlayerChooseButtonsNumH * _PlayerChooseButtonsNumW; i++) { - CButton b = GetNewButton(Buttons[_ButtonPlayerChoose]); + CButton b = GetNewButton(_Buttons[_ButtonPlayerChoose]); b.Rect.X = _PlayerChooseButtonsFirstX + column * (b.Rect.W + _PlayerChooseButtonsSpaceH); b.Rect.Y = _PlayerChooseButtonsFirstY + row * (b.Rect.H + _PlayerChooseButtonsSpaceW); - CPlayerChooseButton pcb = new CPlayerChooseButton(); - pcb.Button = b; - pcb.ProfileID = -1; + CPlayerChooseButton pcb = new CPlayerChooseButton {Button = b, ProfileID = -1}; _PlayerChooseButtons.Add(pcb); column++; if (column >= _PlayerChooseButtonsNumH) @@ -313,7 +323,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley } b.Visible = true; b.Enabled = false; - AddButton(b); + _AddButton(b); } } @@ -329,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; @@ -341,8 +351,10 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { _PlayerChooseButtons[i].ProfileID = _PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]; _PlayerChooseButtons[i].Button.Text.Text = CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].PlayerName; - _PlayerChooseButtons[i].Button.Texture = CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; - _PlayerChooseButtons[i].Button.SelTexture = CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; + _PlayerChooseButtons[i].Button.Texture = + CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; + _PlayerChooseButtons[i].Button.SelTexture = + CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; _PlayerChooseButtons[i].Button.Color = new SColorF(1, 1, 1, 0.6f); _PlayerChooseButtons[i].Button.SelColor = new SColorF(1, 1, 1, 1); _PlayerChooseButtons[i].Button.Enabled = true; @@ -351,10 +363,10 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { _PlayerChooseButtons[i].ProfileID = -1; _PlayerChooseButtons[i].Button.Text.Text = String.Empty; - _PlayerChooseButtons[i].Button.Texture = Buttons[_ButtonPlayerChoose].Texture; - _PlayerChooseButtons[i].Button.SelTexture = Buttons[_ButtonPlayerChoose].SelTexture; - _PlayerChooseButtons[i].Button.Color = Buttons[_ButtonPlayerChoose].Color; - _PlayerChooseButtons[i].Button.SelColor = Buttons[_ButtonPlayerChoose].SelColor; + _PlayerChooseButtons[i].Button.Texture = _Buttons[_ButtonPlayerChoose].Texture; + _PlayerChooseButtons[i].Button.SelTexture = _Buttons[_ButtonPlayerChoose].SelTexture; + _PlayerChooseButtons[i].Button.Color = _Buttons[_ButtonPlayerChoose].Color; + _PlayerChooseButtons[i].Button.SelColor = _Buttons[_ButtonPlayerChoose].SelColor; _PlayerChooseButtons[i].Button.Enabled = false; } } @@ -418,10 +430,10 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley } else { - _PlayerDestinationButtons[i].Color = Buttons[_ButtonPlayerDestination].Color; - _PlayerDestinationButtons[i].SelColor = Buttons[_ButtonPlayerDestination].SelColor; - _PlayerDestinationButtons[i].Texture = Buttons[_ButtonPlayerDestination].Texture; - _PlayerDestinationButtons[i].SelTexture = Buttons[_ButtonPlayerDestination].SelTexture; + _PlayerDestinationButtons[i].Color = _Buttons[_ButtonPlayerDestination].Color; + _PlayerDestinationButtons[i].SelColor = _Buttons[_ButtonPlayerDestination].SelColor; + _PlayerDestinationButtons[i].Texture = _Buttons[_ButtonPlayerDestination].Texture; + _PlayerDestinationButtons[i].SelTexture = _Buttons[_ButtonPlayerDestination].SelTexture; _PlayerDestinationButtons[i].Text.Text = String.Empty; _PlayerDestinationButtons[i].Enabled = false; } @@ -432,34 +444,34 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley { if (_Data.ScreenNames.ProfileIDs.Count == _NumPlayer) { - Buttons[_ButtonNext].Visible = true; - SetInteractionToButton(Buttons[_ButtonNext]); + _Buttons[_ButtonNext].Visible = true; + _SetInteractionToButton(_Buttons[_ButtonNext]); } else - Buttons[_ButtonNext].Visible = false; + _Buttons[_ButtonNext].Visible = false; } private bool _OnAdd() { - for (int i = 0; i < _PlayerChooseButtons.Count; i++) + foreach (CPlayerChooseButton chooseButton in _PlayerChooseButtons) { - if (_PlayerChooseButtons[i].Button.Selected && _PlayerChooseButtons[i].ProfileID != -1) + if (chooseButton.Button.Selected && chooseButton.ProfileID != -1) { if (_Data.ScreenNames.ProfileIDs.Count < _NumPlayer) { - _Data.ScreenNames.ProfileIDs.Add(_PlayerChooseButtons[i].ProfileID); + _Data.ScreenNames.ProfileIDs.Add(chooseButton.ProfileID); int added = _Data.ScreenNames.ProfileIDs.Count - 1; _UpdateButtonNext(); //Update texture and name _PlayerDestinationButtons[added].Color = new SColorF(1, 1, 1, 0.6f); _PlayerDestinationButtons[added].SelColor = new SColorF(1, 1, 1, 1); - _PlayerDestinationButtons[added].Texture = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].Avatar.Texture; - _PlayerDestinationButtons[added].SelTexture = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].Avatar.Texture; - _PlayerDestinationButtons[added].Text.Text = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].PlayerName; + _PlayerDestinationButtons[added].Texture = CBase.Profiles.GetProfiles()[chooseButton.ProfileID].Avatar.Texture; + _PlayerDestinationButtons[added].SelTexture = CBase.Profiles.GetProfiles()[chooseButton.ProfileID].Avatar.Texture; + _PlayerDestinationButtons[added].Text.Text = CBase.Profiles.GetProfiles()[chooseButton.ProfileID].PlayerName; _PlayerDestinationButtons[added].Enabled = true; //Update Tiles-List _UpdateButtonPlayerChoose(); - CheckInteraction(); + _CheckInteraction(); return true; } } @@ -479,7 +491,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _UpdateButtonNext(); _UpdateButtonPlayerDestination(); _UpdateButtonPlayerChoose(); - CheckInteraction(); + _CheckInteraction(); return true; } } @@ -490,14 +502,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/PartyModeChallengeMedley/GlobalSuppressions.cs b/PartyModes/PartyModeChallengeMedley/GlobalSuppressions.cs index 21fb9bcd..a29227be 100644 Binary files a/PartyModes/PartyModeChallengeMedley/GlobalSuppressions.cs and b/PartyModes/PartyModeChallengeMedley/GlobalSuppressions.cs differ diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 9adddc16..4dc7e99f 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -1,3 +1,22 @@ +#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.Runtime.InteropServices; @@ -33,7 +52,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe public int PointsTeam1; public int PointsTeam2; public int Winner; - public bool Finished = false; + public bool Finished; } #region Communication @@ -62,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; @@ -96,7 +113,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe public struct SFromScreenNames { public bool FadeToConfig; - public bool FadeToMain; public List ProfileIDsTeam1; public List ProfileIDsTeam2; } @@ -184,24 +200,26 @@ namespace VocaluxeLib.PartyModes.TicTacToe _ToScreenNames = new SDataToScreenNames(); _ToScreenMain = new SDataToScreenMain(); - _GameData = new SData(); - _GameData.NumFields = 9; - _GameData.NumPlayerTeam1 = 2; - _GameData.NumPlayerTeam2 = 2; - _GameData.ProfileIDsTeam1 = new List(); - _GameData.ProfileIDsTeam2 = new List(); - _GameData.PlayerTeam1 = new List(); - _GameData.PlayerTeam2 = new List(); - _GameData.CurrentRoundNr = 0; - _GameData.SingRoundNr = 0; - _GameData.SongSource = ESongSource.TR_ALLSONGS; - _GameData.PlaylistID = 0; - _GameData.CategoryID = 0; - _GameData.GameMode = EPartyGameMode.TR_GAMEMODE_NORMAL; - _GameData.Rounds = new List(); - _GameData.Songs = new List(); - _GameData.NumJokerRandom = new int[2]; - _GameData.NumJokerRetry = new int[2]; + _GameData = new SData + { + NumFields = 9, + NumPlayerTeam1 = 2, + NumPlayerTeam2 = 2, + ProfileIDsTeam1 = new List(), + ProfileIDsTeam2 = new List(), + PlayerTeam1 = new List(), + PlayerTeam2 = new List(), + CurrentRoundNr = 0, + SingRoundNr = 0, + SongSource = ESongSource.TR_ALLSONGS, + PlaylistID = 0, + CategoryID = 0, + GameMode = EPartyGameMode.TR_GAMEMODE_NORMAL, + Rounds = new List(), + Songs = new List(), + NumJokerRandom = new int[2], + NumJokerRetry = new int[2] + }; } public override bool Init() @@ -262,10 +280,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _Stage = EStage.NotStarted; else { - if (CBase.Game.GetRandom(100) < 50) - _GameData.Team = 0; - else - _GameData.Team = 1; + _GameData.Team = CBase.Game.GetRandom(100) < 50 ? 0 : 1; _GameData.ProfileIDsTeam1 = dataFrom.ScreenNames.ProfileIDsTeam1; _GameData.ProfileIDsTeam2 = dataFrom.ScreenNames.ProfileIDsTeam2; _Stage = EStage.Names; @@ -358,15 +373,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe _Screens.TryGetValue("CPartyScreenTicTacToeMain", out screen); if (screen != null) { - if (_GameData.Team == 1) - _GameData.Team = 0; - else - _GameData.Team = 1; + _GameData.Team = _GameData.Team == 1 ? 0 : 1; 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; @@ -391,15 +401,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe _Screens.TryGetValue("CPartyScreenTicTacToeMain", out screen); if (screen != null) { - if (_GameData.Team == 1) - _GameData.Team = 0; - else - _GameData.Team = 1; + _GameData.Team = _GameData.Team == 1 ? 0 : 1; _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; @@ -437,12 +442,16 @@ namespace VocaluxeLib.PartyModes.TicTacToe return _ScreenSongOptions; } + // ReSharper disable RedundantAssignment public override void OnSongChange(int songIndex, ref SScreenSongOptions screenSongOptions) + // ReSharper restore RedundantAssignment { screenSongOptions = _ScreenSongOptions; } + // ReSharper disable RedundantAssignment public override void OnCategoryChange(int categoryIndex, ref SScreenSongOptions screenSongOptions) + // ReSharper restore RedundantAssignment { screenSongOptions = _ScreenSongOptions; } @@ -522,99 +531,101 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _PreparePlayerList(int team) { - if (team == 0) + switch (team) { - _GameData.PlayerTeam1 = new List(); - _GameData.PlayerTeam2 = new List(); + case 0: + { + _GameData.PlayerTeam1 = new List(); + _GameData.PlayerTeam2 = new List(); - //Prepare Player-IDs - List iDs1 = new List(); - List iDs2 = new List(); - int num = 0; - int random = 0; - //Add IDs to team-list - while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && iDs1.Count == 0 && - _GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1] && iDs2.Count == 0) - { - if (iDs1.Count == 0) - { - for (int i = 0; i < _GameData.NumPlayerTeam1; i++) - iDs1.Add(i); + //Prepare Player-IDs + List ids1 = new List(); + List ids2 = new List(); + //Add IDs to team-list + while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && ids1.Count == 0 && + _GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1] && ids2.Count == 0) + { + if (ids1.Count == 0) + { + for (int i = 0; i < _GameData.NumPlayerTeam1; i++) + ids1.Add(i); + } + if (ids2.Count == 0) + { + for (int i = 0; i < _GameData.NumPlayerTeam2; i++) + ids2.Add(i); + } + int num; + int random; + if (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0]) + { + random = CBase.Game.GetRandom((ids1.Count - 1) * 10); + num = (int)Math.Round((double)random / 10); + if (num >= ids1.Count) + num = ids1.Count - 1; + _GameData.PlayerTeam1.Add(ids1[num]); + ids1.RemoveAt(num); + } + if (_GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1]) + { + random = CBase.Game.GetRandom((ids2.Count - 1) * 20); + num = (int)Math.Round((double)random / 20); + if (num >= ids2.Count) + num = ids2.Count - 1; + _GameData.PlayerTeam2.Add(ids2[num]); + ids2.RemoveAt(num); + } + } } - if (iDs2.Count == 0) + break; + case 1: { - for (int i = 0; i < _GameData.NumPlayerTeam2; i++) - iDs2.Add(i); + //Prepare Player-IDs + List ids = new List(); + //Add IDs to team-list + while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && ids.Count == 0) + { + if (ids.Count == 0) + { + for (int i = 0; i < _GameData.NumPlayerTeam1; i++) + ids.Add(i); + } + if (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0]) + { + 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 (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0]) + break; + case 2: { - random = CBase.Game.GetRandom((iDs1.Count - 1) * 10); - num = (int)Math.Round((double)random / 10); - if (num >= iDs1.Count) - num = iDs1.Count - 1; - _GameData.PlayerTeam1.Add(iDs1[num]); - iDs1.RemoveAt(num); + //Prepare Player-IDs + List ids = new List(); + //Add IDs to team-list + while (_GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1] && ids.Count == 0) + { + if (ids.Count == 0) + { + for (int i = 0; i < _GameData.NumPlayerTeam2; i++) + ids.Add(i); + } + if (_GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1]) + { + int random = CBase.Game.GetRandom((ids.Count - 1) * 20); + int num = (int)Math.Round((double)random / 20); + if (num >= ids.Count) + num = ids.Count - 1; + _GameData.PlayerTeam2.Add(ids[num]); + ids.RemoveAt(num); + } + } } - if (_GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1]) - { - random = CBase.Game.GetRandom((iDs2.Count - 1) * 20); - num = (int)Math.Round((double)random / 20); - if (num >= iDs2.Count) - num = iDs2.Count - 1; - _GameData.PlayerTeam2.Add(iDs2[num]); - iDs2.RemoveAt(num); - } - } - } - else if (team == 1) - { - //Prepare Player-IDs - List iDs = new List(); - int num = 0; - int random = 0; - //Add IDs to team-list - while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && iDs.Count == 0) - { - if (iDs.Count == 0) - { - for (int i = 0; i < _GameData.NumPlayerTeam1; i++) - iDs.Add(i); - } - if (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0]) - { - random = CBase.Game.GetRandom((iDs.Count - 1) * 10); - num = (int)Math.Round((double)random / 10); - if (num >= iDs.Count) - num = iDs.Count - 1; - _GameData.PlayerTeam1.Add(iDs[num]); - iDs.RemoveAt(num); - } - } - } - else if (team == 2) - { - //Prepare Player-IDs - List iDs = new List(); - int num = 0; - int random = 0; - //Add IDs to team-list - while (_GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1] && iDs.Count == 0) - { - if (iDs.Count == 0) - { - for (int i = 0; i < _GameData.NumPlayerTeam2; i++) - iDs.Add(i); - } - if (_GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1]) - { - random = CBase.Game.GetRandom((iDs.Count - 1) * 20); - num = (int)Math.Round((double)random / 20); - if (num >= iDs.Count) - num = iDs.Count - 1; - _GameData.PlayerTeam2.Add(iDs[num]); - iDs.RemoveAt(num); - } - } + break; } } @@ -707,7 +718,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe CBase.Game.SetNumPlayer(2); - SPlayer[] player = CBase.Game.GetPlayer(); + SPlayer[] player = CBase.Game.GetPlayers(); if (player == null) return; @@ -721,8 +732,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe for (int i = 0; i < 2; i++) { //default values - player[i].Name = "foobar"; - player[i].Difficulty = EGameDifficulty.TR_CONFIG_EASY; player[i].ProfileID = -1; } @@ -731,24 +740,18 @@ namespace VocaluxeLib.PartyModes.TicTacToe { if (_GameData.ProfileIDsTeam1[r.SingerTeam1] < profiles.Length) { - player[0].Name = profiles[_GameData.ProfileIDsTeam1[r.SingerTeam1]].PlayerName; - player[0].Difficulty = profiles[_GameData.ProfileIDsTeam1[r.SingerTeam1]].Difficulty; player[0].ProfileID = _GameData.ProfileIDsTeam1[r.SingerTeam1]; if (isDuet) player[0].LineNr = 0; } if (_GameData.ProfileIDsTeam2[r.SingerTeam2] < profiles.Length) { - player[1].Name = profiles[_GameData.ProfileIDsTeam2[r.SingerTeam2]].PlayerName; - player[1].Difficulty = profiles[_GameData.ProfileIDsTeam2[r.SingerTeam2]].Difficulty; player[1].ProfileID = _GameData.ProfileIDsTeam2[r.SingerTeam2]; if (isDuet) player[1].LineNr = 1; } SongSelected(r.SongID); } - else - return; } private void _SetNumJokers() @@ -783,7 +786,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe if (!_GameData.Rounds[_GameData.SingRoundNr].Finished) _GameData.CurrentRoundNr++; - SPlayer[] results = CBase.Game.GetPlayer(); + SPlayer[] results = CBase.Game.GetPlayers(); if (results == null) return; diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs index a1af9b1b..a03c839d 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs @@ -1,10 +1,33 @@ +#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.Linq; using System.Windows.Forms; using VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes.TicTacToe { + // ReSharper disable UnusedMember.Global public class CPartyScreenTicTacToeConfig : CMenuParty + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -31,28 +54,31 @@ namespace VocaluxeLib.PartyModes.TicTacToe base.Init(); _ThemeSelectSlides = new string[] - {_SelectSlideNumPlayerTeam1, _SelectSlideNumPlayerTeam2, _SelectSlideNumFields, _SelectSlideSongSource, _SelectSlidePlaylist, _SelectSlideCategory, _SelectSlideGameMode}; + { + _SelectSlideNumPlayerTeam1, _SelectSlideNumPlayerTeam2, _SelectSlideNumFields, _SelectSlideSongSource, _SelectSlidePlaylist, _SelectSlideCategory, + _SelectSlideGameMode + }; _ThemeButtons = new string[] {_ButtonNext, _ButtonBack}; _Data = new SDataFromScreen(); - SFromScreenConfig config = new SFromScreenConfig(); - config.PlaylistID = 0; - config.NumFields = 9; - config.NumPlayerTeam1 = 2; - config.NumPlayerTeam2 = 2; - config.GameMode = EPartyGameMode.TR_GAMEMODE_NORMAL; - config.CategoryID = 0; - config.SongSource = ESongSource.TR_ALLSONGS; + SFromScreenConfig config = new SFromScreenConfig + { + PlaylistID = 0, + NumFields = 9, + NumPlayerTeam1 = 2, + NumPlayerTeam2 = 2, + GameMode = EPartyGameMode.TR_GAMEMODE_NORMAL, + CategoryID = 0, + SongSource = ESongSource.TR_ALLSONGS + }; _Data.ScreenConfig = config; } public override void DataToScreen(object receivedData) { - SDataToScreenConfig config = new SDataToScreenConfig(); - try { - config = (SDataToScreenConfig)receivedData; + SDataToScreenConfig config = (SDataToScreenConfig)receivedData; _Data.ScreenConfig.NumFields = config.NumFields; _Data.ScreenConfig.NumPlayerTeam1 = config.NumPlayerTeam1; _Data.ScreenConfig.NumPlayerTeam2 = config.NumPlayerTeam2; @@ -84,10 +110,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe case Keys.Enter: _UpdateSlides(); - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); break; @@ -107,13 +133,13 @@ namespace VocaluxeLib.PartyModes.TicTacToe { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { _UpdateSlides(); - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); } @@ -136,7 +162,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe public override bool UpdateGame() { - Buttons[_ButtonNext].Visible = _ConfigOk; + _Buttons[_ButtonNext].Visible = _ConfigOk; return true; } @@ -149,72 +175,72 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _FillSlides() { // build num player slide (min player ... max player); - SelectSlides[_SelectSlideNumPlayerTeam1].Clear(); + _SelectSlides[_SelectSlideNumPlayerTeam1].Clear(); for (int i = _PartyMode.GetMinPlayer() / 2; i <= _PartyMode.GetMaxPlayer() / 2; i++) - SelectSlides[_SelectSlideNumPlayerTeam1].AddValue(i.ToString()); - SelectSlides[_SelectSlideNumPlayerTeam1].Selection = _Data.ScreenConfig.NumPlayerTeam1 - (_PartyMode.GetMinPlayer() / 2); + _SelectSlides[_SelectSlideNumPlayerTeam1].AddValue(i.ToString()); + _SelectSlides[_SelectSlideNumPlayerTeam1].Selection = _Data.ScreenConfig.NumPlayerTeam1 - (_PartyMode.GetMinPlayer() / 2); - SelectSlides[_SelectSlideNumPlayerTeam2].Clear(); + _SelectSlides[_SelectSlideNumPlayerTeam2].Clear(); for (int i = _PartyMode.GetMinPlayer() / 2; i <= _PartyMode.GetMaxPlayer() / 2; i++) - SelectSlides[_SelectSlideNumPlayerTeam2].AddValue(i.ToString()); - SelectSlides[_SelectSlideNumPlayerTeam2].Selection = _Data.ScreenConfig.NumPlayerTeam2 - (_PartyMode.GetMinPlayer() / 2); + _SelectSlides[_SelectSlideNumPlayerTeam2].AddValue(i.ToString()); + _SelectSlides[_SelectSlideNumPlayerTeam2].Selection = _Data.ScreenConfig.NumPlayerTeam2 - (_PartyMode.GetMinPlayer() / 2); - SelectSlides[_SelectSlideNumFields].Clear(); - SelectSlides[_SelectSlideNumFields].AddValue("9"); - SelectSlides[_SelectSlideNumFields].AddValue("16"); - SelectSlides[_SelectSlideNumFields].AddValue("25"); + _SelectSlides[_SelectSlideNumFields].Clear(); + _SelectSlides[_SelectSlideNumFields].AddValue("9"); + _SelectSlides[_SelectSlideNumFields].AddValue("16"); + _SelectSlides[_SelectSlideNumFields].AddValue("25"); if (_Data.ScreenConfig.NumFields == 9) - SelectSlides[_SelectSlideNumFields].Selection = 0; + _SelectSlides[_SelectSlideNumFields].Selection = 0; else if (_Data.ScreenConfig.NumFields == 16) - SelectSlides[_SelectSlideNumFields].Selection = 1; + _SelectSlides[_SelectSlideNumFields].Selection = 1; else if (_Data.ScreenConfig.NumFields == 25) - SelectSlides[_SelectSlideNumFields].Selection = 2; + _SelectSlides[_SelectSlideNumFields].Selection = 2; - SelectSlides[_SelectSlideSongSource].Clear(); - SelectSlides[_SelectSlideSongSource].SetValues((int)_Data.ScreenConfig.SongSource); + _SelectSlides[_SelectSlideSongSource].Clear(); + _SelectSlides[_SelectSlideSongSource].SetValues((int)_Data.ScreenConfig.SongSource); - string[] playlists = CBase.Playlist.GetPlaylistNames(); - SelectSlides[_SelectSlidePlaylist].Clear(); - for (int i = 0; i < playlists.Length; i++) + List playlists = CBase.Playlist.GetPlaylistNames(); + _SelectSlides[_SelectSlidePlaylist].Clear(); + for (int i = 0; i < playlists.Count; i++) { string value = playlists[i] + " (" + CBase.Playlist.GetPlaylistSongCount(i) + " " + CBase.Language.Translate("TR_SONGS", _PartyModeID) + ")"; - SelectSlides[_SelectSlidePlaylist].AddValue(value); + _SelectSlides[_SelectSlidePlaylist].AddValue(value); } - SelectSlides[_SelectSlidePlaylist].Selection = _Data.ScreenConfig.PlaylistID; - SelectSlides[_SelectSlidePlaylist].Visible = _Data.ScreenConfig.SongSource == ESongSource.TR_PLAYLIST; + _SelectSlides[_SelectSlidePlaylist].Selection = _Data.ScreenConfig.PlaylistID; + _SelectSlides[_SelectSlidePlaylist].Visible = _Data.ScreenConfig.SongSource == ESongSource.TR_PLAYLIST; string[] categories = new string[CBase.Songs.GetNumCategories()]; for (int i = 0; i < CBase.Songs.GetNumCategories(); i++) categories[i] = CBase.Songs.GetCategory(i).Name; - SelectSlides[_SelectSlideCategory].Clear(); + _SelectSlides[_SelectSlideCategory].Clear(); for (int i = 0; i < categories.Length; i++) { string value = categories[i] + " (" + CBase.Songs.NumSongsInCategory(i) + " " + CBase.Language.Translate("TR_SONGS", _PartyModeID) + ")"; - SelectSlides[_SelectSlideCategory].AddValue(value); + _SelectSlides[_SelectSlideCategory].AddValue(value); } - SelectSlides[_SelectSlideCategory].Selection = _Data.ScreenConfig.CategoryID; - SelectSlides[_SelectSlideCategory].Visible = _Data.ScreenConfig.SongSource == ESongSource.TR_CATEGORY; + _SelectSlides[_SelectSlideCategory].Selection = _Data.ScreenConfig.CategoryID; + _SelectSlides[_SelectSlideCategory].Visible = _Data.ScreenConfig.SongSource == ESongSource.TR_CATEGORY; - SelectSlides[_SelectSlideGameMode].Visible = true; - SelectSlides[_SelectSlideGameMode].SetValues((int)_Data.ScreenConfig.GameMode); + _SelectSlides[_SelectSlideGameMode].Visible = true; + _SelectSlides[_SelectSlideGameMode].SetValues((int)_Data.ScreenConfig.GameMode); } private void _UpdateSlides() { - _Data.ScreenConfig.NumPlayerTeam1 = SelectSlides[_SelectSlideNumPlayerTeam1].Selection + (_PartyMode.GetMinPlayer() / 2); - _Data.ScreenConfig.NumPlayerTeam2 = SelectSlides[_SelectSlideNumPlayerTeam2].Selection + (_PartyMode.GetMinPlayer() / 2); + _Data.ScreenConfig.NumPlayerTeam1 = _SelectSlides[_SelectSlideNumPlayerTeam1].Selection + (_PartyMode.GetMinPlayer() / 2); + _Data.ScreenConfig.NumPlayerTeam2 = _SelectSlides[_SelectSlideNumPlayerTeam2].Selection + (_PartyMode.GetMinPlayer() / 2); - if (SelectSlides[_SelectSlideNumFields].Selection == 0) + if (_SelectSlides[_SelectSlideNumFields].Selection == 0) _Data.ScreenConfig.NumFields = 9; - else if (SelectSlides[_SelectSlideNumFields].Selection == 1) + else if (_SelectSlides[_SelectSlideNumFields].Selection == 1) _Data.ScreenConfig.NumFields = 16; - else if (SelectSlides[_SelectSlideNumFields].Selection == 2) + else if (_SelectSlides[_SelectSlideNumFields].Selection == 2) _Data.ScreenConfig.NumFields = 25; - _Data.ScreenConfig.SongSource = (ESongSource)SelectSlides[_SelectSlideSongSource].Selection; - _Data.ScreenConfig.PlaylistID = SelectSlides[_SelectSlidePlaylist].Selection; - _Data.ScreenConfig.CategoryID = SelectSlides[_SelectSlideCategory].Selection; - _Data.ScreenConfig.GameMode = (EPartyGameMode)SelectSlides[_SelectSlideGameMode].Selection; + _Data.ScreenConfig.SongSource = (ESongSource)_SelectSlides[_SelectSlideSongSource].Selection; + _Data.ScreenConfig.PlaylistID = _SelectSlides[_SelectSlidePlaylist].Selection; + _Data.ScreenConfig.CategoryID = _SelectSlides[_SelectSlideCategory].Selection; + _Data.ScreenConfig.GameMode = (EPartyGameMode)_SelectSlides[_SelectSlideGameMode].Selection; EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; @@ -243,14 +269,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe for (int i = 0; i < CBase.Playlist.GetPlaylistSongCount(_Data.ScreenConfig.PlaylistID); i++) { int id = CBase.Playlist.GetPlaylistSong(_Data.ScreenConfig.PlaylistID, i).SongID; - foreach (EGameMode mode in CBase.Songs.GetSongByID(id).AvailableGameModes) - { - if (mode == gm) - { - _ConfigOk = true; - break; - } - } + _ConfigOk = CBase.Songs.GetSongByID(id).AvailableGameModes.Any(mode => mode == gm); if (_ConfigOk) break; } @@ -271,14 +290,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _ConfigOk = false; for (int i = 0; i < CBase.Songs.NumSongsInCategory(_Data.ScreenConfig.CategoryID); i++) { - foreach (EGameMode mode in CBase.Songs.GetVisibleSong(i).AvailableGameModes) - { - if (mode == gm) - { - _ConfigOk = true; - break; - } - } + _ConfigOk = CBase.Songs.GetVisibleSong(i).AvailableGameModes.Any(mode => mode == gm); if (_ConfigOk) break; } @@ -296,14 +308,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { for (int i = 0; i < CBase.Songs.GetNumSongs(); i++) { - foreach (EGameMode mode in CBase.Songs.GetSongByID(i).AvailableGameModes) - { - if (mode == gm) - { - _ConfigOk = true; - break; - } - } + _ConfigOk = CBase.Songs.GetSongByID(i).AvailableGameModes.Any(mode => mode == gm); if (_ConfigOk) break; } @@ -311,8 +316,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe else _ConfigOk = false; } - SelectSlides[_SelectSlideCategory].Visible = _Data.ScreenConfig.SongSource == ESongSource.TR_CATEGORY; - SelectSlides[_SelectSlidePlaylist].Visible = _Data.ScreenConfig.SongSource == ESongSource.TR_PLAYLIST; + _SelectSlides[_SelectSlideCategory].Visible = _Data.ScreenConfig.SongSource == ESongSource.TR_CATEGORY; + _SelectSlides[_SelectSlidePlaylist].Visible = _Data.ScreenConfig.SongSource == ESongSource.TR_PLAYLIST; } private void _Back() diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index 3e2fe436..a7dbf8e1 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -1,3 +1,22 @@ +#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.Windows.Forms; @@ -60,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; @@ -74,7 +93,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe { base.Init(); - _ThemeTexts = new string[] {_TextPopupReallyExit, _TextTeamChoosing, _TextFinishMessage, _TextNextPlayerT1, _TextNextPlayerT2, _TextNextPlayerNameT1, _TextNextPlayerNameT2}; + _ThemeTexts = new string[] + {_TextPopupReallyExit, _TextTeamChoosing, _TextFinishMessage, _TextNextPlayerT1, _TextNextPlayerT2, _TextNextPlayerNameT1, _TextNextPlayerNameT2}; _ThemeButtons = new string[] { _ButtonNextRound, _ButtonBack, _ButtonExit, _ButtonPopupYes, _ButtonPopupNo, _ButtonField, _ButtonJokerRandomT1, _ButtonJokerRandomT2, _ButtonJokerRetryT1, @@ -102,16 +122,14 @@ namespace VocaluxeLib.PartyModes.TicTacToe base.LoadTheme(xmlPath); _CreateFields(); - Buttons[_ButtonField].Visible = false; + _Buttons[_ButtonField].Visible = false; } public override void DataToScreen(object receivedData) { - SDataToScreenMain config = new SDataToScreenMain(); - try { - config = (SDataToScreenMain)receivedData; + SDataToScreenMain config = (SDataToScreenMain)receivedData; _GameData = config; } catch (Exception e) @@ -147,11 +165,11 @@ namespace VocaluxeLib.PartyModes.TicTacToe case Keys.Enter: if (!_ExitPopupVisible) { - if (Buttons[_ButtonNextRound].Selected) + if (_Buttons[_ButtonNextRound].Selected) _NextRound(); - if (Buttons[_ButtonBack].Selected && _GameData.CurrentRoundNr == 1 && _Status != EStatus.FieldSelected) + if (_Buttons[_ButtonBack].Selected && _GameData.CurrentRoundNr == 1 && _Status != EStatus.FieldSelected) _Back(); - if (Buttons[_ButtonExit].Selected && (_GameData.CurrentRoundNr > 1 || _Status == EStatus.FieldSelected) && _Status != EStatus.None) + if (_Buttons[_ButtonExit].Selected && (_GameData.CurrentRoundNr > 1 || _Status == EStatus.FieldSelected) && _Status != EStatus.None) _ShowPopup(true); else if (_Status == EStatus.None) _EndParty(); @@ -178,21 +196,21 @@ namespace VocaluxeLib.PartyModes.TicTacToe } if (_Status == EStatus.FieldSelected) { - if (Buttons[_ButtonJokerRandomT1].Selected) + if (_Buttons[_ButtonJokerRandomT1].Selected) _UseJoker(0, 0); - if (Buttons[_ButtonJokerRandomT2].Selected) + if (_Buttons[_ButtonJokerRandomT2].Selected) _UseJoker(1, 0); - if (Buttons[_ButtonJokerRetryT1].Selected) + if (_Buttons[_ButtonJokerRetryT1].Selected) _UseJoker(0, 1); - if (Buttons[_ButtonJokerRetryT2].Selected) + if (_Buttons[_ButtonJokerRetryT2].Selected) _UseJoker(1, 1); } } else { - if (Buttons[_ButtonPopupYes].Selected) + if (_Buttons[_ButtonPopupYes].Selected) _EndParty(); - if (Buttons[_ButtonPopupNo].Selected) + if (_Buttons[_ButtonPopupNo].Selected) _ShowPopup(false); } break; @@ -205,15 +223,15 @@ namespace VocaluxeLib.PartyModes.TicTacToe { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { if (!_ExitPopupVisible) { - if (Buttons[_ButtonNextRound].Selected) + if (_Buttons[_ButtonNextRound].Selected) _NextRound(); - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) { if (_Status == EStatus.None) _EndParty(); @@ -243,21 +261,21 @@ namespace VocaluxeLib.PartyModes.TicTacToe } if (_Status == EStatus.FieldSelected) { - if (Buttons[_ButtonJokerRandomT1].Selected) + if (_Buttons[_ButtonJokerRandomT1].Selected) _UseJoker(0, 0); - if (Buttons[_ButtonJokerRandomT2].Selected) + if (_Buttons[_ButtonJokerRandomT2].Selected) _UseJoker(1, 0); - if (Buttons[_ButtonJokerRetryT1].Selected) + if (_Buttons[_ButtonJokerRetryT1].Selected) _UseJoker(0, 1); - if (Buttons[_ButtonJokerRetryT2].Selected) + if (_Buttons[_ButtonJokerRetryT2].Selected) _UseJoker(1, 1); } } else { - if (Buttons[_ButtonPopupYes].Selected) + if (_Buttons[_ButtonPopupYes].Selected) _EndParty(); - if (Buttons[_ButtonPopupNo].Selected) + if (_Buttons[_ButtonPopupNo].Selected) _ShowPopup(false); } } @@ -292,15 +310,15 @@ namespace VocaluxeLib.PartyModes.TicTacToe { _BuildWinnerPossibilities(); _SelectedField = -1; - Buttons[_ButtonBack].Visible = true; - Buttons[_ButtonExit].Visible = false; - SetInteractionToButton(Buttons[_ButtonBack]); + _Buttons[_ButtonBack].Visible = true; + _Buttons[_ButtonExit].Visible = false; + _SetInteractionToButton(_Buttons[_ButtonBack]); } else { - Buttons[_ButtonBack].Visible = false; - Buttons[_ButtonExit].Visible = true; - SetInteractionToButton(Buttons[_ButtonExit]); + _Buttons[_ButtonBack].Visible = false; + _Buttons[_ButtonExit].Visible = true; + _SetInteractionToButton(_Buttons[_ButtonExit]); } _Status = EStatus.FieldChoosing; @@ -312,37 +330,37 @@ namespace VocaluxeLib.PartyModes.TicTacToe if (_GameData.CurrentRoundNr <= _GameData.NumFields && winner == 0) { _UpdateTeamChoosingMessage(); - Texts[_TextNextPlayerT1].Visible = false; - Texts[_TextNextPlayerT2].Visible = false; - Texts[_TextNextPlayerNameT1].Visible = false; - Texts[_TextNextPlayerNameT2].Visible = false; - Statics[_StaticAvatarT1].Visible = false; - Statics[_StaticAvatarT2].Visible = false; - Buttons[_ButtonJokerRandomT1].Visible = false; - Buttons[_ButtonJokerRandomT2].Visible = false; - Buttons[_ButtonJokerRetryT1].Visible = false; - Buttons[_ButtonJokerRetryT2].Visible = false; - Buttons[_ButtonNextRound].Visible = false; - Texts[_TextFinishMessage].Visible = false; + _Texts[_TextNextPlayerT1].Visible = false; + _Texts[_TextNextPlayerT2].Visible = false; + _Texts[_TextNextPlayerNameT1].Visible = false; + _Texts[_TextNextPlayerNameT2].Visible = false; + _Statics[_StaticAvatarT1].Visible = false; + _Statics[_StaticAvatarT2].Visible = false; + _Buttons[_ButtonJokerRandomT1].Visible = false; + _Buttons[_ButtonJokerRandomT2].Visible = false; + _Buttons[_ButtonJokerRetryT1].Visible = false; + _Buttons[_ButtonJokerRetryT2].Visible = false; + _Buttons[_ButtonNextRound].Visible = false; + _Texts[_TextFinishMessage].Visible = false; } else { _Status = EStatus.None; - Buttons[_ButtonNextRound].Visible = false; - Texts[_TextFinishMessage].Visible = true; - Texts[_TextTeamChoosing].Visible = false; + _Buttons[_ButtonNextRound].Visible = false; + _Texts[_TextFinishMessage].Visible = true; + _Texts[_TextTeamChoosing].Visible = false; if (winner > 0) { - Texts[_TextFinishMessage].Color = CBase.Theme.GetPlayerColor(winner); - Texts[_TextFinishMessage].Text = CBase.Language.Translate("TR_SCREENMAIN_WINNER", _PartyModeID) + " " + CBase.Language.Translate("TR_TEAM", _PartyModeID) + " " + - winner; + _Texts[_TextFinishMessage].Color = CBase.Theme.GetPlayerColor(winner); + _Texts[_TextFinishMessage].Text = CBase.Language.Translate("TR_SCREENMAIN_WINNER", _PartyModeID) + " " + CBase.Language.Translate("TR_TEAM", _PartyModeID) + " " + + winner; } else { - Texts[_TextFinishMessage].Color = new SColorF(1, 1, 1, 1); - Texts[_TextFinishMessage].Text = CBase.Language.Translate("TR_SCREENMAIN_NOWINNER", _PartyModeID); + _Texts[_TextFinishMessage].Color = new SColorF(1, 1, 1, 1); + _Texts[_TextFinishMessage].Text = CBase.Language.Translate("TR_SCREENMAIN_NOWINNER", _PartyModeID); } - SetInteractionToButton(Buttons[_ButtonExit]); + _SetInteractionToButton(_Buttons[_ButtonExit]); } _ShowPopup(false); @@ -370,11 +388,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe { for (int i = 0; i < 25; i++) { - CField f = new CField(); - f.Button = GetNewButton(Buttons[_ButtonField]); + CField f = new CField {Button = GetNewButton(_Buttons[_ButtonField])}; f.Button.Visible = false; f.Content = new CRound(); - AddButton(f.Button); + _AddButton(f.Button); _Fields.Add(f); } } @@ -382,13 +399,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _UpdateFields() { int numOneRow = (int)Math.Sqrt(_GameData.NumFields); - float fieldSizeY = (CBase.Settings.GetRenderH() - 150 - numOneRow * _FieldSpace) / numOneRow; - float fieldSizeX = (CBase.Settings.GetRenderW() - 300 - numOneRow * _FieldSpace) / numOneRow; - if (fieldSizeX < fieldSizeY) - _FieldSize = fieldSizeX; - else - _FieldSize = fieldSizeY; - _FieldFirstX = CBase.Settings.GetRenderW() / 2 - (numOneRow * _FieldSize + (numOneRow - 1) * _FieldSpace) / 2; + float fieldSizeY = ((float)CBase.Settings.GetRenderH() - 150 - numOneRow * _FieldSpace) / numOneRow; + float fieldSizeX = ((float)CBase.Settings.GetRenderW() - 300 - numOneRow * _FieldSpace) / numOneRow; + _FieldSize = Math.Min(fieldSizeX, fieldSizeY); + _FieldFirstX = (float)CBase.Settings.GetRenderW() / 2 - (numOneRow * _FieldSize + (numOneRow - 1) * _FieldSpace) / 2; _FieldFirstY = 140 + (CBase.Settings.GetRenderH() - 140) / 2 - (numOneRow * _FieldSize + numOneRow * _FieldSpace) / 2; int row = 0; int column = 0; @@ -428,9 +442,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe for (int i = 0; i < _GameData.Rounds.Count; i++) { _Fields[i].Button.Enabled = true; - _Fields[i].Button.Texture = Buttons[_ButtonField].Texture; - _Fields[i].Button.Color = Buttons[_ButtonField].Color; - _Fields[i].Button.SelColor = Buttons[_ButtonField].SelColor; + _Fields[i].Button.Texture = _Buttons[_ButtonField].Texture; + _Fields[i].Button.Color = _Buttons[_ButtonField].Color; + _Fields[i].Button.SelColor = _Buttons[_ButtonField].SelColor; _Fields[i].Content = _GameData.Rounds[i]; if (_Fields[i].Content.Finished) { @@ -495,25 +509,25 @@ namespace VocaluxeLib.PartyModes.TicTacToe _GameData.Rounds[_SelectedField].SingerTeam2 = singerTeam2; _UpdateFieldContents(); - Texts[_TextNextPlayerT1].Visible = true; - Texts[_TextNextPlayerT2].Visible = true; - Texts[_TextNextPlayerNameT1].Visible = true; - Texts[_TextNextPlayerNameT2].Visible = true; + _Texts[_TextNextPlayerT1].Visible = true; + _Texts[_TextNextPlayerT2].Visible = true; + _Texts[_TextNextPlayerNameT1].Visible = true; + _Texts[_TextNextPlayerNameT2].Visible = true; SProfile[] profiles = CBase.Profiles.GetProfiles(); - Texts[_TextNextPlayerNameT1].Text = profiles[_GameData.ProfileIDsTeam1[_GameData.Rounds[_SelectedField].SingerTeam1]].PlayerName; - Texts[_TextNextPlayerNameT2].Text = profiles[_GameData.ProfileIDsTeam2[_GameData.Rounds[_SelectedField].SingerTeam2]].PlayerName; - Statics[_StaticAvatarT1].Visible = true; - Statics[_StaticAvatarT2].Visible = true; - Statics[_StaticAvatarT1].Texture = profiles[_GameData.ProfileIDsTeam1[_GameData.Rounds[_SelectedField].SingerTeam1]].Avatar.Texture; - Statics[_StaticAvatarT2].Texture = profiles[_GameData.ProfileIDsTeam2[_GameData.Rounds[_SelectedField].SingerTeam2]].Avatar.Texture; + _Texts[_TextNextPlayerNameT1].Text = profiles[_GameData.ProfileIDsTeam1[_GameData.Rounds[_SelectedField].SingerTeam1]].PlayerName; + _Texts[_TextNextPlayerNameT2].Text = profiles[_GameData.ProfileIDsTeam2[_GameData.Rounds[_SelectedField].SingerTeam2]].PlayerName; + _Statics[_StaticAvatarT1].Visible = true; + _Statics[_StaticAvatarT2].Visible = true; + _Statics[_StaticAvatarT1].Texture = profiles[_GameData.ProfileIDsTeam1[_GameData.Rounds[_SelectedField].SingerTeam1]].Avatar.Texture; + _Statics[_StaticAvatarT2].Texture = profiles[_GameData.ProfileIDsTeam2[_GameData.Rounds[_SelectedField].SingerTeam2]].Avatar.Texture; _UpdateJokerButtons(); - Buttons[_ButtonNextRound].Visible = true; - Buttons[_ButtonExit].Visible = true; - Buttons[_ButtonBack].Visible = false; + _Buttons[_ButtonNextRound].Visible = true; + _Buttons[_ButtonExit].Visible = true; + _Buttons[_ButtonBack].Visible = false; - SetInteractionToButton(Buttons[_ButtonNextRound]); + _SetInteractionToButton(_Buttons[_ButtonNextRound]); } private void _FieldSelectedAgain() @@ -534,25 +548,25 @@ namespace VocaluxeLib.PartyModes.TicTacToe _GameData.Rounds[_SelectedField].SingerTeam2 = _GameData.Rounds[_OldSelectedField].SingerTeam2; _UpdateFieldContents(); - Texts[_TextNextPlayerT1].Visible = true; - Texts[_TextNextPlayerT2].Visible = true; - Texts[_TextNextPlayerNameT1].Visible = true; - Texts[_TextNextPlayerNameT2].Visible = true; + _Texts[_TextNextPlayerT1].Visible = true; + _Texts[_TextNextPlayerT2].Visible = true; + _Texts[_TextNextPlayerNameT1].Visible = true; + _Texts[_TextNextPlayerNameT2].Visible = true; SProfile[] profiles = CBase.Profiles.GetProfiles(); - Texts[_TextNextPlayerNameT1].Text = profiles[_GameData.ProfileIDsTeam1[_GameData.Rounds[_SelectedField].SingerTeam1]].PlayerName; - Texts[_TextNextPlayerNameT2].Text = profiles[_GameData.ProfileIDsTeam2[_GameData.Rounds[_SelectedField].SingerTeam2]].PlayerName; - Statics[_StaticAvatarT1].Visible = true; - Statics[_StaticAvatarT2].Visible = true; - Statics[_StaticAvatarT1].Texture = profiles[_GameData.ProfileIDsTeam1[_GameData.Rounds[_SelectedField].SingerTeam1]].Avatar.Texture; - Statics[_StaticAvatarT2].Texture = profiles[_GameData.ProfileIDsTeam2[_GameData.Rounds[_SelectedField].SingerTeam2]].Avatar.Texture; + _Texts[_TextNextPlayerNameT1].Text = profiles[_GameData.ProfileIDsTeam1[_GameData.Rounds[_SelectedField].SingerTeam1]].PlayerName; + _Texts[_TextNextPlayerNameT2].Text = profiles[_GameData.ProfileIDsTeam2[_GameData.Rounds[_SelectedField].SingerTeam2]].PlayerName; + _Statics[_StaticAvatarT1].Visible = true; + _Statics[_StaticAvatarT2].Visible = true; + _Statics[_StaticAvatarT1].Texture = profiles[_GameData.ProfileIDsTeam1[_GameData.Rounds[_SelectedField].SingerTeam1]].Avatar.Texture; + _Statics[_StaticAvatarT2].Texture = profiles[_GameData.ProfileIDsTeam2[_GameData.Rounds[_SelectedField].SingerTeam2]].Avatar.Texture; _UpdateJokerButtons(); - Buttons[_ButtonNextRound].Visible = true; - Buttons[_ButtonExit].Visible = true; - Buttons[_ButtonBack].Visible = false; + _Buttons[_ButtonNextRound].Visible = true; + _Buttons[_ButtonExit].Visible = true; + _Buttons[_ButtonBack].Visible = false; - SetInteractionToButton(Buttons[_ButtonNextRound]); + _SetInteractionToButton(_Buttons[_ButtonNextRound]); } private void _UseJoker(int teamNr, int jokerNum) @@ -590,29 +604,29 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _UpdateTeamChoosingMessage() { - Texts[_TextTeamChoosing].Color = CBase.Theme.GetPlayerColor(_GameData.Team + 1); - Texts[_TextTeamChoosing].Text = CBase.Language.Translate("TR_TEAM", _PartyModeID) + " " + (_GameData.Team + 1) + "! " + - CBase.Language.Translate("TR_SCREENMAIN_TEAM_CHOOSE", _PartyModeID); + _Texts[_TextTeamChoosing].Color = CBase.Theme.GetPlayerColor(_GameData.Team + 1); + _Texts[_TextTeamChoosing].Text = CBase.Language.Translate("TR_TEAM", _PartyModeID) + " " + (_GameData.Team + 1) + "! " + + CBase.Language.Translate("TR_SCREENMAIN_TEAM_CHOOSE", _PartyModeID); if (_Status == EStatus.JokerRetry || _Status == EStatus.FieldChoosing) - Texts[_TextTeamChoosing].Visible = true; + _Texts[_TextTeamChoosing].Visible = true; else - Texts[_TextTeamChoosing].Visible = false; + _Texts[_TextTeamChoosing].Visible = false; } private void _UpdateJokerButtons() { - Buttons[_ButtonJokerRandomT1].Visible = true; - Buttons[_ButtonJokerRandomT2].Visible = true; - Buttons[_ButtonJokerRandomT1].Text.Text = _GameData.NumJokerRandom[0].ToString(); - Buttons[_ButtonJokerRandomT2].Text.Text = _GameData.NumJokerRandom[1].ToString(); - Buttons[_ButtonJokerRandomT1].Enabled = _GameData.NumJokerRandom[0] > 0; - Buttons[_ButtonJokerRandomT2].Enabled = _GameData.NumJokerRandom[1] > 0; - Buttons[_ButtonJokerRetryT1].Visible = true; - Buttons[_ButtonJokerRetryT2].Visible = true; - Buttons[_ButtonJokerRetryT1].Text.Text = _GameData.NumJokerRetry[0].ToString(); - Buttons[_ButtonJokerRetryT2].Text.Text = _GameData.NumJokerRetry[1].ToString(); - Buttons[_ButtonJokerRetryT1].Enabled = _GameData.NumJokerRetry[0] > 0; - Buttons[_ButtonJokerRetryT2].Enabled = _GameData.NumJokerRetry[1] > 0; + _Buttons[_ButtonJokerRandomT1].Visible = true; + _Buttons[_ButtonJokerRandomT2].Visible = true; + _Buttons[_ButtonJokerRandomT1].Text.Text = _GameData.NumJokerRandom[0].ToString(); + _Buttons[_ButtonJokerRandomT2].Text.Text = _GameData.NumJokerRandom[1].ToString(); + _Buttons[_ButtonJokerRandomT1].Enabled = _GameData.NumJokerRandom[0] > 0; + _Buttons[_ButtonJokerRandomT2].Enabled = _GameData.NumJokerRandom[1] > 0; + _Buttons[_ButtonJokerRetryT1].Visible = true; + _Buttons[_ButtonJokerRetryT2].Visible = true; + _Buttons[_ButtonJokerRetryT1].Text.Text = _GameData.NumJokerRetry[0].ToString(); + _Buttons[_ButtonJokerRetryT2].Text.Text = _GameData.NumJokerRetry[1].ToString(); + _Buttons[_ButtonJokerRetryT1].Enabled = _GameData.NumJokerRetry[0] > 0; + _Buttons[_ButtonJokerRetryT2].Enabled = _GameData.NumJokerRetry[1] > 0; } private void _NextRound() @@ -638,13 +652,13 @@ namespace VocaluxeLib.PartyModes.TicTacToe { _ExitPopupVisible = visible; - Statics[_StaticPopupBG].Visible = _ExitPopupVisible; - Texts[_TextPopupReallyExit].Visible = _ExitPopupVisible; - Buttons[_ButtonPopupYes].Visible = _ExitPopupVisible; - Buttons[_ButtonPopupNo].Visible = _ExitPopupVisible; + _Statics[_StaticPopupBG].Visible = _ExitPopupVisible; + _Texts[_TextPopupReallyExit].Visible = _ExitPopupVisible; + _Buttons[_ButtonPopupYes].Visible = _ExitPopupVisible; + _Buttons[_ButtonPopupNo].Visible = _ExitPopupVisible; if (_ExitPopupVisible) - SetInteractionToButton(Buttons[_ButtonPopupNo]); + _SetInteractionToButton(_Buttons[_ButtonPopupNo]); } private void _Back() @@ -696,14 +710,13 @@ namespace VocaluxeLib.PartyModes.TicTacToe if (_Fields[_Possibilities[i, j]].Content.Winner > 0) check.Add(_Fields[_Possibilities[i, j]].Content.Winner); } - if (check.Count == _Possibilities.GetLength(1)) - { - //Check for winner - if (check.Contains(1) && !check.Contains(2)) - return 1; - else if (check.Contains(2) && !check.Contains(1)) - return 2; - } + if (check.Count != _Possibilities.GetLength(1)) + continue; + //Check for winner + if (check.Contains(1) && !check.Contains(2)) + return 1; + if (check.Contains(2) && !check.Contains(1)) + return 2; } return 0; } diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs index 05d5eb5b..9e29b916 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs @@ -1,11 +1,33 @@ +#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.Linq; using System.Windows.Forms; using VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes.TicTacToe { + // ReSharper disable UnusedMember.Global public class CPartyScreenTicTacToeNames : CMenuParty + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -24,7 +46,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe private List _PlayerDestinationButtons; //PlayerDestinationButtons-Option private const int _PlayerDestinationButtonsNumH = 10; - private const int _PlayerDestinationButtonsNumW = 2; private const int _PlayerDestinationButtonsFirstX = 58; private const int _PlayerDestinationButtonsFirstY = 380; private const int _PlayerDestinationButtonsSpaceH = 15; @@ -69,25 +90,18 @@ namespace VocaluxeLib.PartyModes.TicTacToe _Data.ScreenNames.ProfileIDsTeam1 = new List(); _Data.ScreenNames.ProfileIDsTeam2 = new List(); - List buttons = new List(); _ThemeButtons = new string[] {_ButtonBack, _ButtonNext, _ButtonPlayerDestination, _ButtonPlayerChoose, _ButtonPlayerChooseScrollUp, _ButtonPlayerChooseScrollDown}; _Data = new SDataFromScreen(); - SFromScreenNames names = new SFromScreenNames(); - names.FadeToConfig = false; - names.FadeToMain = false; - names.ProfileIDsTeam1 = new List(); - names.ProfileIDsTeam2 = new List(); + SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, ProfileIDsTeam1 = new List(), ProfileIDsTeam2 = new List()}; _Data.ScreenNames = names; } public override void DataToScreen(object receivedData) { - SDataToScreenNames config = new SDataToScreenNames(); - try { - config = (SDataToScreenNames)receivedData; + SDataToScreenNames config = (SDataToScreenNames)receivedData; _Data.ScreenNames.ProfileIDsTeam1 = config.ProfileIDsTeam1; _Data.ScreenNames.ProfileIDsTeam2 = config.ProfileIDsTeam2; if (_Data.ScreenNames.ProfileIDsTeam1 == null) @@ -124,16 +138,16 @@ namespace VocaluxeLib.PartyModes.TicTacToe break; case Keys.Enter: - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); - if (Buttons[_ButtonPlayerChooseScrollUp].Selected) + if (_Buttons[_ButtonPlayerChooseScrollUp].Selected) _Scroll(-1); - if (Buttons[_ButtonPlayerChooseScrollDown].Selected) + if (_Buttons[_ButtonPlayerChooseScrollDown].Selected) _Scroll(1); if (!_OnAdd()) @@ -159,18 +173,18 @@ namespace VocaluxeLib.PartyModes.TicTacToe _OldMouseX = mouseEvent.X; _OldMouseY = mouseEvent.Y; //Check if mouse if over tile - for (int i = 0; i < _PlayerChooseButtons.Count; i++) + foreach (CPlayerChooseButton chooseButton in _PlayerChooseButtons) { - if (_PlayerChooseButtons[i].Button.Selected) + if (chooseButton.Button.Selected) { - _SelectedPlayerNr = _PlayerChooseButtons[i].ProfileID; + _SelectedPlayerNr = chooseButton.ProfileID; if (_SelectedPlayerNr != -1) { //Activate mouse-selecting _SelectingMouseActive = true; //Update of Drag/Drop-Texture _ChooseAvatarStatic.Visible = true; - _ChooseAvatarStatic.Rect = _PlayerChooseButtons[i].Button.Rect; + _ChooseAvatarStatic.Rect = chooseButton.Button.Rect; _ChooseAvatarStatic.Rect.Z = -100; _ChooseAvatarStatic.Color = new SColorF(1, 1, 1, 1); _ChooseAvatarStatic.Texture = CBase.Profiles.GetProfiles()[_SelectedPlayerNr].Avatar.Texture; @@ -191,8 +205,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe return true; } - // LeftButton isn't hold anymore, but Selec-Mode is still active -> "Drop" of Avatar - else if (_SelectingMouseActive) + // LeftButton isn't hold anymore, but Selec-Mode is still active -> "Drop" of Avatar + if (_SelectingMouseActive) { //Check if really a player was selected if (_SelectedPlayerNr != -1) @@ -255,22 +269,22 @@ namespace VocaluxeLib.PartyModes.TicTacToe return true; } - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonBack].Selected) + if (_Buttons[_ButtonBack].Selected) _Back(); - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) _Next(); - if (Buttons[_ButtonPlayerChooseScrollUp].Selected) + if (_Buttons[_ButtonPlayerChooseScrollUp].Selected) _Scroll(-1); - if (Buttons[_ButtonPlayerChooseScrollDown].Selected) + if (_Buttons[_ButtonPlayerChooseScrollDown].Selected) _Scroll(1); } - if (mouseEvent.LD && IsMouseOver(mouseEvent)) + if (mouseEvent.LD && _IsMouseOver(mouseEvent)) { if (!_OnAdd()) _OnRemove(); @@ -328,13 +342,13 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _AddButtonPlayerDestination() { - Buttons[_ButtonPlayerDestination].Visible = false; + _Buttons[_ButtonPlayerDestination].Visible = false; _PlayerDestinationButtons = new List(); int row = 0; int column = 0; for (int i = 1; i <= _PartyMode.GetMaxPlayer(); i++) { - CButton b = GetNewButton(Buttons[_ButtonPlayerDestination]); + CButton b = GetNewButton(_Buttons[_ButtonPlayerDestination]); b.Rect.X = _PlayerDestinationButtonsFirstX + column * (b.Rect.W + _PlayerDestinationButtonsSpaceH); b.Rect.Y = _PlayerDestinationButtonsFirstY + row * (b.Rect.H + _PlayerDestinationButtonsSpaceW); _PlayerDestinationButtons.Add(b); @@ -346,24 +360,22 @@ namespace VocaluxeLib.PartyModes.TicTacToe } b.Visible = true; b.Enabled = false; - AddButton(b); + _AddButton(b); } } private void _AddButtonPlayerChoose() { - Buttons[_ButtonPlayerChoose].Visible = false; + _Buttons[_ButtonPlayerChoose].Visible = false; _PlayerChooseButtons = new List(); int row = 0; int column = 0; for (int i = 1; i <= _PlayerChooseButtonsNumH * _PlayerChooseButtonsNumW; i++) { - CButton b = GetNewButton(Buttons[_ButtonPlayerChoose]); + CButton b = GetNewButton(_Buttons[_ButtonPlayerChoose]); b.Rect.X = _PlayerChooseButtonsFirstX + column * (b.Rect.W + _PlayerChooseButtonsSpaceH); b.Rect.Y = _PlayerChooseButtonsFirstY + row * (b.Rect.H + _PlayerChooseButtonsSpaceW); - CPlayerChooseButton pcb = new CPlayerChooseButton(); - pcb.Button = b; - pcb.ProfileID = -1; + CPlayerChooseButton pcb = new CPlayerChooseButton {Button = b, ProfileID = -1}; _PlayerChooseButtons.Add(pcb); column++; if (column >= _PlayerChooseButtonsNumH) @@ -373,7 +385,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe } b.Visible = true; b.Enabled = false; - AddButton(b); + _AddButton(b); } } @@ -385,14 +397,14 @@ namespace VocaluxeLib.PartyModes.TicTacToe _UpdateButtonPlayerChoose(_PlayerChooseButtonsOffset - 1); else _UpdateButtonPlayerChoose(_PlayerChooseButtonsOffset); - Buttons[_ButtonPlayerChooseScrollUp].Enabled = _PlayerChooseButtonsOffset > 0; - Buttons[_ButtonPlayerChooseScrollDown].Enabled = _PlayerChooseButtonsVisibleProfiles.Count > - _PlayerChooseButtons.Count + _PlayerChooseButtonsOffset * _PlayerChooseButtonsNumH; + _Buttons[_ButtonPlayerChooseScrollUp].Enabled = _PlayerChooseButtonsOffset > 0; + _Buttons[_ButtonPlayerChooseScrollDown].Enabled = _PlayerChooseButtonsVisibleProfiles.Count > + _PlayerChooseButtons.Count + _PlayerChooseButtonsOffset * _PlayerChooseButtonsNumH; } private void _UpdateButtonPlayerChoose(int offset) { - int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH; + const int numButtonPlayerChoose = _PlayerChooseButtonsNumW * _PlayerChooseButtonsNumH; if (offset < 0) offset = 0; @@ -404,8 +416,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe { _PlayerChooseButtons[i].ProfileID = _PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]; _PlayerChooseButtons[i].Button.Text.Text = CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].PlayerName; - _PlayerChooseButtons[i].Button.Texture = CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; - _PlayerChooseButtons[i].Button.SelTexture = CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; + _PlayerChooseButtons[i].Button.Texture = + CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; + _PlayerChooseButtons[i].Button.SelTexture = + CBase.Profiles.GetProfiles()[_PlayerChooseButtonsVisibleProfiles[i + offset * numButtonPlayerChoose]].Avatar.Texture; _PlayerChooseButtons[i].Button.Color = new SColorF(1, 1, 1, 0.6f); _PlayerChooseButtons[i].Button.SelColor = new SColorF(1, 1, 1, 1); _PlayerChooseButtons[i].Button.Enabled = true; @@ -414,10 +428,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe { _PlayerChooseButtons[i].ProfileID = -1; _PlayerChooseButtons[i].Button.Text.Text = String.Empty; - _PlayerChooseButtons[i].Button.Texture = Buttons[_ButtonPlayerChoose].Texture; - _PlayerChooseButtons[i].Button.SelTexture = Buttons[_ButtonPlayerChoose].SelTexture; - _PlayerChooseButtons[i].Button.Color = Buttons[_ButtonPlayerChoose].Color; - _PlayerChooseButtons[i].Button.SelColor = Buttons[_ButtonPlayerChoose].SelColor; + _PlayerChooseButtons[i].Button.Texture = _Buttons[_ButtonPlayerChoose].Texture; + _PlayerChooseButtons[i].Button.SelTexture = _Buttons[_ButtonPlayerChoose].SelTexture; + _PlayerChooseButtons[i].Button.Color = _Buttons[_ButtonPlayerChoose].Color; + _PlayerChooseButtons[i].Button.SelColor = _Buttons[_ButtonPlayerChoose].SelColor; _PlayerChooseButtons[i].Button.Enabled = false; } } @@ -432,29 +446,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe bool visible = false; //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); } @@ -504,10 +496,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe } else { - _PlayerDestinationButtons[i].Color = Buttons[_ButtonPlayerDestination].Color; - _PlayerDestinationButtons[i].SelColor = Buttons[_ButtonPlayerDestination].SelColor; - _PlayerDestinationButtons[i].Texture = Buttons[_ButtonPlayerDestination].Texture; - _PlayerDestinationButtons[i].SelTexture = Buttons[_ButtonPlayerDestination].SelTexture; + _PlayerDestinationButtons[i].Color = _Buttons[_ButtonPlayerDestination].Color; + _PlayerDestinationButtons[i].SelColor = _Buttons[_ButtonPlayerDestination].SelColor; + _PlayerDestinationButtons[i].Texture = _Buttons[_ButtonPlayerDestination].Texture; + _PlayerDestinationButtons[i].SelTexture = _Buttons[_ButtonPlayerDestination].SelTexture; _PlayerDestinationButtons[i].Text.Text = String.Empty; _PlayerDestinationButtons[i].Enabled = false; } @@ -528,10 +520,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe } else { - _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].Color = Buttons[_ButtonPlayerDestination].Color; - _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].SelColor = Buttons[_ButtonPlayerDestination].SelColor; - _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].Texture = Buttons[_ButtonPlayerDestination].Texture; - _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].SelTexture = Buttons[_ButtonPlayerDestination].SelTexture; + _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].Color = _Buttons[_ButtonPlayerDestination].Color; + _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].SelColor = _Buttons[_ButtonPlayerDestination].SelColor; + _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].Texture = _Buttons[_ButtonPlayerDestination].Texture; + _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].SelTexture = _Buttons[_ButtonPlayerDestination].SelTexture; _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].Text.Text = String.Empty; _PlayerDestinationButtons[i + _PlayerDestinationButtonsNumH].Enabled = false; } @@ -542,53 +534,50 @@ namespace VocaluxeLib.PartyModes.TicTacToe { if (_Data.ScreenNames.ProfileIDsTeam1.Count == _NumPlayerTeam1 && _Data.ScreenNames.ProfileIDsTeam2.Count == _NumPlayerTeam2) { - Buttons[_ButtonNext].Visible = true; - SetInteractionToButton(Buttons[_ButtonNext]); + _Buttons[_ButtonNext].Visible = true; + _SetInteractionToButton(_Buttons[_ButtonNext]); } else - Buttons[_ButtonNext].Visible = false; + _Buttons[_ButtonNext].Visible = false; } private bool _OnAdd() { - for (int i = 0; i < _PlayerChooseButtons.Count; i++) + foreach (CPlayerChooseButton chooseButton in _PlayerChooseButtons.Where(chooseButton => chooseButton.Button.Selected && chooseButton.ProfileID != -1)) { - if (_PlayerChooseButtons[i].Button.Selected && _PlayerChooseButtons[i].ProfileID != -1) + if (_Data.ScreenNames.ProfileIDsTeam1.Count < _NumPlayerTeam1) { - if (_Data.ScreenNames.ProfileIDsTeam1.Count < _NumPlayerTeam1) - { - _Data.ScreenNames.ProfileIDsTeam1.Add(_PlayerChooseButtons[i].ProfileID); - int added = _Data.ScreenNames.ProfileIDsTeam1.Count - 1; - _UpdateButtonNext(); - //Update texture and name - _PlayerDestinationButtons[added].Color = new SColorF(1, 1, 1, 0.6f); - _PlayerDestinationButtons[added].SelColor = new SColorF(1, 1, 1, 1); - _PlayerDestinationButtons[added].Texture = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].Avatar.Texture; - _PlayerDestinationButtons[added].SelTexture = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].Avatar.Texture; - _PlayerDestinationButtons[added].Text.Text = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].PlayerName; - _PlayerDestinationButtons[added].Enabled = true; - //Update Tiles-List - _UpdateButtonPlayerChoose(); - CheckInteraction(); - return true; - } - else if (_Data.ScreenNames.ProfileIDsTeam2.Count < _NumPlayerTeam2) - { - _Data.ScreenNames.ProfileIDsTeam2.Add(_PlayerChooseButtons[i].ProfileID); - int added = (_Data.ScreenNames.ProfileIDsTeam2.Count - 1) + _PlayerDestinationButtonsNumH; - _UpdateButtonNext(); - //Update texture and name - _PlayerDestinationButtons[added].Color = new SColorF(1, 1, 1, 0.6f); - _PlayerDestinationButtons[added].SelColor = new SColorF(1, 1, 1, 1); - _PlayerDestinationButtons[added].Texture = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].Avatar.Texture; - _PlayerDestinationButtons[added].SelTexture = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].Avatar.Texture; - _PlayerDestinationButtons[added].Text.Text = CBase.Profiles.GetProfiles()[_PlayerChooseButtons[i].ProfileID].PlayerName; - _PlayerDestinationButtons[added].Enabled = true; - //Update Tiles-List - _UpdateButtonPlayerChoose(); - CheckInteraction(); - return true; - } + _Data.ScreenNames.ProfileIDsTeam1.Add(chooseButton.ProfileID); + int added = _Data.ScreenNames.ProfileIDsTeam1.Count - 1; + _UpdateButtonNext(); + //Update texture and name + _PlayerDestinationButtons[added].Color = new SColorF(1, 1, 1, 0.6f); + _PlayerDestinationButtons[added].SelColor = new SColorF(1, 1, 1, 1); + _PlayerDestinationButtons[added].Texture = CBase.Profiles.GetProfiles()[chooseButton.ProfileID].Avatar.Texture; + _PlayerDestinationButtons[added].SelTexture = CBase.Profiles.GetProfiles()[chooseButton.ProfileID].Avatar.Texture; + _PlayerDestinationButtons[added].Text.Text = CBase.Profiles.GetProfiles()[chooseButton.ProfileID].PlayerName; + _PlayerDestinationButtons[added].Enabled = true; + //Update Tiles-List + _UpdateButtonPlayerChoose(); + _CheckInteraction(); + return true; + } + if (_Data.ScreenNames.ProfileIDsTeam2.Count < _NumPlayerTeam2) + { + _Data.ScreenNames.ProfileIDsTeam2.Add(chooseButton.ProfileID); + int added = (_Data.ScreenNames.ProfileIDsTeam2.Count - 1) + _PlayerDestinationButtonsNumH; + _UpdateButtonNext(); + //Update texture and name + _PlayerDestinationButtons[added].Color = new SColorF(1, 1, 1, 0.6f); + _PlayerDestinationButtons[added].SelColor = new SColorF(1, 1, 1, 1); + _PlayerDestinationButtons[added].Texture = CBase.Profiles.GetProfiles()[chooseButton.ProfileID].Avatar.Texture; + _PlayerDestinationButtons[added].SelTexture = CBase.Profiles.GetProfiles()[chooseButton.ProfileID].Avatar.Texture; + _PlayerDestinationButtons[added].Text.Text = CBase.Profiles.GetProfiles()[chooseButton.ProfileID].PlayerName; + _PlayerDestinationButtons[added].Enabled = true; + //Update Tiles-List + _UpdateButtonPlayerChoose(); + _CheckInteraction(); + return true; } } return false; @@ -606,7 +595,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _UpdateButtonNext(); _UpdateButtonPlayerDestination(); _UpdateButtonPlayerChoose(); - CheckInteraction(); + _CheckInteraction(); return true; } } @@ -621,7 +610,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _UpdateButtonNext(); _UpdateButtonPlayerDestination(); _UpdateButtonPlayerChoose(); - CheckInteraction(); + _CheckInteraction(); return true; } } @@ -632,14 +621,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/PartyModes/PartyModeTicTacToe/GlobalSuppressions.cs b/PartyModes/PartyModeTicTacToe/GlobalSuppressions.cs index 21fb9bcd..a29227be 100644 Binary files a/PartyModes/PartyModeTicTacToe/GlobalSuppressions.cs and b/PartyModes/PartyModeTicTacToe/GlobalSuppressions.cs differ diff --git a/Re#Settings.DotSettings b/Vocaluxe.sln.DotSettings similarity index 100% rename from Re#Settings.DotSettings rename to Vocaluxe.sln.DotSettings diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index ece1cd16..0aa110b2 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -1,7 +1,27 @@ -using System; +#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.Diagnostics; using System.IO; +using System.Linq; using Vocaluxe.Base; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -26,7 +46,6 @@ namespace Vocaluxe.Base private static bool _OwnMusicAdded; private static bool _BackgroundMusicAdded; - private static bool _Playing; private static bool _Disabled; private static bool _CanSing; private static bool _RepeatSong; @@ -88,19 +107,15 @@ namespace Vocaluxe.Base get { return File.Exists(_CurrentPlaylistElement.VideoFilePath); } } - public static bool Playing - { - get { return _Playing; } - } + public static bool IsPlaying { get; private set; } public static string ArtistAndTitle { get { - if (_CurrentPlaylistElement.Artist.Length > 0 && _CurrentPlaylistElement.Title.Length > 0) + if (_CurrentPlaylistElement.Artist != "" && _CurrentPlaylistElement.Title != "") return _CurrentPlaylistElement.Artist + " - " + _CurrentPlaylistElement.Title; - else - return Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath); + return Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath); } } @@ -124,12 +139,12 @@ namespace Vocaluxe.Base if (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON) _VideoEnabled = true; - _Playing = false; + IsPlaying = false; } public static void Play() { - if (_Playing) + if (IsPlaying) return; if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) @@ -142,22 +157,19 @@ namespace Vocaluxe.Base CSound.Play(_CurrentMusicStream); if (_VideoEnabled && _Video != -1) CVideo.VdResume(_Video); - _Playing = true; + IsPlaying = true; } else Next(); - if (!_IsBackgroundFile(_CurrentPlaylistElement)) - _CanSing = true; - else - _CanSing = false; + _CanSing = !_IsBackgroundFile(_CurrentPlaylistElement); } } } public static void Stop() { - if (!_Playing) + if (!IsPlaying) return; if (_VideoEnabled && _Video != -1) @@ -170,12 +182,12 @@ namespace Vocaluxe.Base _CurrentMusicStream = -1; _CurrentPlaylistElement = new CPlaylistElement(); - _Playing = false; + IsPlaying = false; } public static void Pause() { - if (!_Playing) + if (!IsPlaying) return; if (_VideoEnabled && _Video != -1) @@ -184,7 +196,7 @@ namespace Vocaluxe.Base CVideo.VdSkip(_Video, CSound.GetPosition(_CurrentMusicStream) + CSettings.BackgroundMusicFadeTime, _CurrentPlaylistElement.VideoGap); } CSound.FadeAndPause(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime); - _Playing = false; + IsPlaying = false; } public static void Update() @@ -192,24 +204,24 @@ namespace Vocaluxe.Base if (_AllFileNames.Count > 0 && _CurrentMusicStream != -1) { float timeToPlay; - if (_CurrentPlaylistElement.Finish == 0f) //No End-Tag defined + if (Math.Abs(_CurrentPlaylistElement.Finish) < 0.001) //No End-Tag defined timeToPlay = CSound.GetLength(_CurrentMusicStream) - CSound.GetPosition(_CurrentMusicStream); else //End-Tag found timeToPlay = _CurrentPlaylistElement.Finish - CSound.GetPosition(_CurrentMusicStream); bool finished = CSound.IsFinished(_CurrentMusicStream); - if (_Playing && (timeToPlay <= CSettings.BackgroundMusicFadeTime || finished)) + if (IsPlaying && (timeToPlay <= CSettings.BackgroundMusicFadeTime || finished)) { if (_RepeatSong) { //Seek to #Start-Tag, if found - if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); else CSound.SetPosition(_CurrentMusicStream, 0); if (_VideoEnabled && _Video != -1) { - if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); else CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); @@ -250,7 +262,7 @@ namespace Vocaluxe.Base CSound.SetStreamVolumeMax(_CurrentMusicStream, CConfig.BackgroundMusicVolume); //Seek to #Start-Tag, if found - if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); if (_VideoEnabled) @@ -266,17 +278,16 @@ namespace Vocaluxe.Base { if (_PreviousFileNames.Count > 0 && _PreviousMusicIndex >= 0) { - float pos = CSound.GetPosition(_CurrentMusicStream); if (CSound.GetPosition(_CurrentMusicStream) >= 1.5f) { //Seek to #Start-Tag, if found - if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); else CSound.SetPosition(_CurrentMusicStream, 0); if (_VideoEnabled && _Video != -1) { - if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); else CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); @@ -302,13 +313,13 @@ namespace Vocaluxe.Base else if (_CurrentMusicStream != -1) { //Seek to #Start-Tag, if found - if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); else CSound.SetPosition(_CurrentMusicStream, 0); if (_VideoEnabled && _Video != -1) { - if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); else CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); @@ -345,7 +356,7 @@ namespace Vocaluxe.Base _NotPlayedFileNames.AddRange(_BGMusicFileNames); } - if (Playing && !_IsBackgroundFile(_CurrentPlaylistElement) || _AllFileNames.Count == 0) + if (IsPlaying && !_IsBackgroundFile(_CurrentPlaylistElement) || _AllFileNames.Count == 0) Next(); _OwnMusicAdded = false; @@ -370,7 +381,7 @@ namespace Vocaluxe.Base AddOwnMusic(); _BackgroundMusicAdded = false; - if (Playing && _IsBackgroundFile(_CurrentPlaylistElement) || _AllFileNames.Count == 0) + if (IsPlaying && _IsBackgroundFile(_CurrentPlaylistElement) || _AllFileNames.Count == 0) Next(); } } @@ -415,7 +426,7 @@ namespace Vocaluxe.Base Pause(); } - if (CConfig.BackgroundMusicVolume != newVolume) + if (Math.Abs(CConfig.BackgroundMusicVolume - newVolume) > 0.01) { CConfig.BackgroundMusicVolume = (int)newVolume; ApplyVolume(); @@ -441,7 +452,6 @@ namespace Vocaluxe.Base CVideo.VdClose(_Video); CDraw.RemoveTexture(ref _CurrentVideoTexture); _Video = -1; - return; } } else @@ -452,8 +462,8 @@ namespace Vocaluxe.Base { if (_Video != -1) { - float vtime = 0f; - CVideo.VdGetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), ref vtime); + float vtime; + CVideo.VdGetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime); if (_FadeTimer.ElapsedMilliseconds <= 3000L) _CurrentVideoTexture.Color.A = _FadeTimer.ElapsedMilliseconds / 3000f; else @@ -468,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() @@ -481,7 +486,7 @@ namespace Vocaluxe.Base if (_Video == -1) { _Video = CVideo.VdLoad(_CurrentPlaylistElement.VideoFilePath); - if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); else CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 9ee47abf..bf7964e7 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -1,6 +1,26 @@ -using System; +#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.IO; +using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -32,7 +52,7 @@ namespace Vocaluxe.Base public static int ScreenH = 576; public static EAntiAliasingModes AAMode = EAntiAliasingModes.X0; - public static EColorDeep Colors = EColorDeep.Bit32; + public static EColorDepth ColorDepth = EColorDepth.Bit32; public static EOffOn VSync = EOffOn.TR_CONFIG_ON; public static EOffOn FullScreen = EOffOn.TR_CONFIG_ON; @@ -56,8 +76,8 @@ namespace Vocaluxe.Base public static EPlaybackLib PlayBackLib = EPlaybackLib.Gstreamer; public static ERecordLib RecordLib = ERecordLib.PortAudio; public static EBufferSize AudioBufferSize = EBufferSize.B2048; - public static int AudioLatency = 0; - public static int BackgroundMusicVolume = 30; + public static int AudioLatency; + private static int _BackgroundMusicVolume = 30; public static EOffOn BackgroundMusic = EOffOn.TR_CONFIG_ON; public static EBackgroundMusicSource BackgroundMusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; public static EOffOn BackgroundMusicUseStart = EOffOn.TR_CONFIG_ON; @@ -65,7 +85,7 @@ namespace Vocaluxe.Base public static int GameMusicVolume = 80; // Game - public static List SongFolder = new List(); + public static readonly List SongFolder = new List(); public static ESongMenu SongMenu = ESongMenu.TR_CONFIG_TILE_BOARD; public static ESongSorting SongSorting = ESongSorting.TR_CONFIG_ARTIST; public static EOffOn IgnoreArticles = EOffOn.TR_CONFIG_ON; @@ -75,7 +95,7 @@ namespace Vocaluxe.Base public static EOffOn Tabs = EOffOn.TR_CONFIG_OFF; public static string Language = "English"; public static EOffOn LyricsOnTop = EOffOn.TR_CONFIG_OFF; - public static string[] Players = new string[CSettings.MaxNumPlayer]; + public static readonly string[] Players = new string[CSettings.MaxNumPlayer]; public static float MinLineBreakTime = 0.1f; //Minimum time to show the text before it is (to be) sung (if possible) @@ -98,6 +118,20 @@ namespace Vocaluxe.Base //Variables to save old values for commandline-parameters private static readonly List _SongFolderOld = new List(); + public static int BackgroundMusicVolume + { + get { return _BackgroundMusicVolume; } + set + { + if (value < 0) + _BackgroundMusicVolume = 0; + else if (value > 100) + _BackgroundMusicVolume = 100; + else + _BackgroundMusicVolume = value; + SaveConfig(); + } + } public static void Init() { @@ -113,17 +147,14 @@ namespace Vocaluxe.Base if (!File.Exists(CSettings.FileConfig)) SaveConfig(); - LoadConfig(); + _LoadConfig(); } - public static bool LoadConfig() + private static void _LoadConfig() { CXMLReader xmlReader = CXMLReader.OpenFile(CSettings.FileConfig); if (xmlReader == null) - return false; - - string value = string.Empty; - + return; xmlReader.TryGetEnumValue("//root/Debug/DebugLevel", ref DebugLevel); @@ -135,7 +166,7 @@ namespace Vocaluxe.Base xmlReader.TryGetIntValue("//root/Graphics/ScreenW", ref ScreenW); xmlReader.TryGetIntValue("//root/Graphics/ScreenH", ref ScreenH); xmlReader.TryGetEnumValue("//root/Graphics/AAMode", ref AAMode); - xmlReader.TryGetEnumValue("//root/Graphics/Colors", ref Colors); + xmlReader.TryGetEnumValue("//root/Graphics/Colors", ref ColorDepth); xmlReader.TryGetFloatValue("//root/Graphics/MaxFPS", ref MaxFPS); xmlReader.TryGetEnumValue("//root/Graphics/VSync", ref VSync); xmlReader.TryGetEnumValue("//root/Graphics/FullScreen", ref FullScreen); @@ -143,9 +174,9 @@ namespace Vocaluxe.Base #endregion Graphics #region Theme - xmlReader.GetValue("//root/Theme/Name", ref Theme, Theme); - xmlReader.GetValue("//root/Theme/Skin", ref Skin, Skin); - xmlReader.GetValue("//root/Theme/Cover", ref CoverTheme, CoverTheme); + xmlReader.GetValue("//root/Theme/Name", out Theme, Theme); + xmlReader.GetValue("//root/Theme/Skin", out Skin, Skin); + xmlReader.GetValue("//root/Theme/Cover", out CoverTheme, CoverTheme); xmlReader.TryGetEnumValue("//root/Theme/DrawNoteLines", ref DrawNoteLines); xmlReader.TryGetEnumValue("//root/Theme/DrawToneHelper", ref DrawToneHelper); xmlReader.TryGetEnumValue("//root/Theme/TimerLook", ref TimerLook); @@ -163,7 +194,7 @@ namespace Vocaluxe.Base xmlReader.TryGetIntValueRange("//root/Sound/AudioLatency", ref AudioLatency, -500, 500); xmlReader.TryGetEnumValue("//root/Sound/BackgroundMusic", ref BackgroundMusic); - xmlReader.TryGetIntValueRange("//root/Sound/BackgroundMusicVolume", ref BackgroundMusicVolume); + xmlReader.TryGetIntValueRange("//root/Sound/BackgroundMusicVolume", ref _BackgroundMusicVolume); xmlReader.TryGetEnumValue("//root/Sound/BackgroundMusicSource", ref BackgroundMusicSource); xmlReader.TryGetEnumValue("//root/Sound/BackgroundMusicUseStart", ref BackgroundMusicUseStart); xmlReader.TryGetIntValueRange("//root/Sound/PreviewMusicVolume", ref PreviewMusicVolume); @@ -172,9 +203,9 @@ namespace Vocaluxe.Base #region Game // Songfolder - value = string.Empty; + string value = string.Empty; int i = 1; - while (xmlReader.GetValue("//root/Game/SongFolder" + i.ToString(), ref value, value)) + while (xmlReader.GetValue("//root/Game/SongFolder" + i, out value, value)) { if (i == 1) SongFolder.Clear(); @@ -191,7 +222,7 @@ namespace Vocaluxe.Base xmlReader.TryGetEnumValue("//root/Game/TimerMode", ref TimerMode); xmlReader.TryGetIntValue("//root/Game/NumPlayer", ref NumPlayer); xmlReader.TryGetEnumValue("//root/Game/Tabs", ref Tabs); - xmlReader.GetValue("//root/Game/Language", ref Language, Language); + xmlReader.GetValue("//root/Game/Language", out Language, Language); xmlReader.TryGetEnumValue("//root/Game/LyricsOnTop", ref LyricsOnTop); xmlReader.TryGetFloatValue("//root/Game/MinLineBreakTime", ref MinLineBreakTime); @@ -212,7 +243,7 @@ namespace Vocaluxe.Base //Read players from config for (i = 1; i <= CSettings.MaxNumPlayer; i++) - xmlReader.GetValue("//root/Game/Players/Player" + i.ToString(), ref Players[i - 1], string.Empty); + xmlReader.GetValue("//root/Game/Players/Player" + i, out Players[i - 1], string.Empty); #endregion Game #region Video @@ -224,7 +255,7 @@ namespace Vocaluxe.Base xmlReader.TryGetEnumValue("//root/Video/WebcamLib", ref WebcamLib); WebcamConfig = new SWebcamConfig(); - xmlReader.GetValue("//root/Video/WebcamConfig/MonikerString", ref WebcamConfig.MonikerString, String.Empty); + xmlReader.GetValue("//root/Video/WebcamConfig/MonikerString", out WebcamConfig.MonikerString, String.Empty); xmlReader.TryGetIntValue("//root/Video/WebcamConfig/Framerate", ref WebcamConfig.Framerate); xmlReader.TryGetIntValue("//root/Video/WebcamConfig/Width", ref WebcamConfig.Width); xmlReader.TryGetIntValue("//root/Video/WebcamConfig/Height", ref WebcamConfig.Height); @@ -232,21 +263,18 @@ namespace Vocaluxe.Base #region Record MicConfig = new SMicConfig[CSettings.MaxNumPlayer]; - value = string.Empty; for (int p = 1; p <= CSettings.MaxNumPlayer; p++) { MicConfig[p - 1] = new SMicConfig(0); - xmlReader.GetValue("//root/Record/MicConfig" + p.ToString() + "/DeviceName", ref MicConfig[p - 1].DeviceName, String.Empty); - xmlReader.GetValue("//root/Record/MicConfig" + p.ToString() + "/DeviceDriver", ref MicConfig[p - 1].DeviceDriver, String.Empty); - xmlReader.GetValue("//root/Record/MicConfig" + p.ToString() + "/InputName", ref MicConfig[p - 1].InputName, String.Empty); - xmlReader.TryGetIntValue("//root/Record/MicConfig" + p.ToString() + "/Channel", ref MicConfig[p - 1].Channel); + xmlReader.GetValue("//root/Record/MicConfig" + p + "/DeviceName", out MicConfig[p - 1].DeviceName, String.Empty); + xmlReader.GetValue("//root/Record/MicConfig" + p + "/DeviceDriver", out MicConfig[p - 1].DeviceDriver, String.Empty); + xmlReader.GetValue("//root/Record/MicConfig" + p + "/InputName", out MicConfig[p - 1].InputName, String.Empty); + xmlReader.TryGetIntValue("//root/Record/MicConfig" + p + "/Channel", ref MicConfig[p - 1].Channel); } xmlReader.TryGetIntValueRange("//root/Record/MicDelay", ref MicDelay, 0, 500); MicDelay = (int)(20 * Math.Round(MicDelay / 20.0)); #endregion Record - - return true; } public static bool SaveConfig() @@ -302,8 +330,8 @@ namespace Vocaluxe.Base writer.WriteComment("AAMode: " + CHelper.ListStrings(Enum.GetNames(typeof(EAntiAliasingModes)))); writer.WriteElementString("AAMode", Enum.GetName(typeof(EAntiAliasingModes), AAMode)); - writer.WriteComment("Colors: " + CHelper.ListStrings(Enum.GetNames(typeof(EColorDeep)))); - writer.WriteElementString("Colors", Enum.GetName(typeof(EColorDeep), Colors)); + writer.WriteComment("Colors: " + CHelper.ListStrings(Enum.GetNames(typeof(EColorDepth)))); + writer.WriteElementString("Colors", Enum.GetName(typeof(EColorDepth), ColorDepth)); writer.WriteComment("MaxFPS should be between 1..200"); writer.WriteElementString("MaxFPS", MaxFPS.ToString("#")); @@ -407,14 +435,14 @@ namespace Vocaluxe.Base //Write "old" song-folders to config. writer.WriteComment("SongFolder: SongFolder1, SongFolder2, SongFolder3, ..."); for (int i = 0; i < _SongFolderOld.Count; i++) - writer.WriteElementString("SongFolder" + (i + 1).ToString(), _SongFolderOld[i]); + writer.WriteElementString("SongFolder" + (i + 1), _SongFolderOld[i]); } else { //Write "normal" song-folders to config. writer.WriteComment("SongFolder: SongFolder1, SongFolder2, SongFolder3, ..."); for (int i = 0; i < SongFolder.Count; i++) - writer.WriteElementString("SongFolder" + (i + 1).ToString(), SongFolder[i]); + writer.WriteElementString("SongFolder" + (i + 1), SongFolder[i]); } writer.WriteComment("SongMenu: " + CHelper.ListStrings(Enum.GetNames(typeof(ESongMenu)))); @@ -432,7 +460,7 @@ namespace Vocaluxe.Base writer.WriteComment("TimerMode: " + CHelper.ListStrings(Enum.GetNames(typeof(ETimerMode)))); writer.WriteElementString("TimerMode", Enum.GetName(typeof(ETimerMode), TimerMode)); - writer.WriteComment("NumPlayer: 1.." + CSettings.MaxNumPlayer.ToString()); + writer.WriteComment("NumPlayer: 1.." + CSettings.MaxNumPlayer); writer.WriteElementString("NumPlayer", NumPlayer.ToString()); writer.WriteComment("Order songs in tabs: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); @@ -444,10 +472,10 @@ namespace Vocaluxe.Base writer.WriteComment("MinLineBreakTime: Value >= 0 in s. Minimum time the text is shown before it is to be sung"); writer.WriteElementString("MinLineBreakTime", MinLineBreakTime.ToString()); - writer.WriteComment("Default profile for players 1..." + CSettings.MaxNumPlayer.ToString() + ":"); + writer.WriteComment("Default profile for players 1..." + CSettings.MaxNumPlayer + ":"); writer.WriteStartElement("Players"); for (int i = 1; i <= CSettings.MaxNumPlayer; i++) - writer.WriteElementString("Player" + i.ToString(), Path.GetFileName(Players[i - 1])); + writer.WriteElementString("Player" + i, Path.GetFileName(Players[i - 1])); writer.WriteEndElement(); writer.WriteEndElement(); @@ -491,9 +519,9 @@ namespace Vocaluxe.Base for (int p = 1; p <= CSettings.MaxNumPlayer; p++) { - if (MicConfig[p - 1].DeviceName.Length > 0 && MicConfig[p - 1].InputName.Length > 0 && MicConfig[p - 1].Channel > 0) + if (MicConfig[p - 1].DeviceName != "" && MicConfig[p - 1].InputName != "" && MicConfig[p - 1].Channel > 0) { - writer.WriteStartElement("MicConfig" + p.ToString()); + writer.WriteStartElement("MicConfig" + p); writer.WriteElementString("DeviceName", MicConfig[p - 1].DeviceName); writer.WriteElementString("DeviceDriver", MicConfig[p - 1].DeviceDriver); @@ -566,21 +594,30 @@ namespace Vocaluxe.Base if (devices == null) return false; - if (devices != null) + for (int dev = 0; dev < devices.Length; dev++) { - for (int dev = 0; dev < devices.Length; dev++) + for (int inp = 0; inp < devices[dev].Inputs.Count; inp++) { - for (int inp = 0; inp < devices[dev].Inputs.Count; inp++) - { - if (devices[dev].Inputs[inp].PlayerChannel1 == player || devices[dev].Inputs[inp].PlayerChannel2 == player) - return true; - } + if (devices[dev].Inputs[inp].PlayerChannel1 == player || devices[dev].Inputs[inp].PlayerChannel2 == player) + return true; } - return false; } return false; } + public static int GetMaxNumMics() + { + int max = 0; + for (int i = 1; i <= CSettings.MaxNumPlayer; i++) + { + if (IsMicConfig(i)) + max = i; + else + break; + } + return max; + } + /// /// Try to assign automatically player 1 and 2 to usb-mics. /// @@ -595,7 +632,7 @@ namespace Vocaluxe.Base for (int dev = 0; dev < devices.Length; dev++) { //Has Device some signal-names in name -> This could be a (usb-)mic - if (Regex.IsMatch(devices[dev].Name, @"ReplacedStr:::0:::", RegexOptions.IgnoreCase)) + if (Regex.IsMatch(devices[dev].Name, "Usb|Wireless", RegexOptions.IgnoreCase)) { //Check if there are inputs. if (devices[dev].Inputs.Count >= 1) @@ -619,11 +656,11 @@ namespace Vocaluxe.Base } } } - //If no usb-mics found -> Look for Devices with "ReplacedStr:::1:::" or "ReplacedStr:::2:::" + //If no usb-mics found -> Look for Devices with "mic" or "mik" for (int dev = 0; dev < devices.Length; dev++) { //Has Device some signal-names in name -> This could be a mic - if (Regex.IsMatch(devices[dev].Name, @"ReplacedStr:::3:::", RegexOptions.IgnoreCase)) + if (Regex.IsMatch(devices[dev].Name, "Mic|Mik", RegexOptions.IgnoreCase)) { //Check if there are inputs. if (devices[dev].Inputs.Count >= 1) @@ -661,30 +698,25 @@ namespace Vocaluxe.Base /// Parameters public static void LoadCommandLineParams(string[] args) { - Regex spliterParam = new Regex(@"ReplacedStr:::0:::", RegexOptions.IgnoreCase); + Regex spliterParam = new Regex(@"-{1,2}|\/", RegexOptions.IgnoreCase); //Complete argument string - string arguments = string.Empty; - foreach (string arg in args) - arguments += arg + " "; + string arguments = args.Aggregate(string.Empty, (current, arg) => current + (arg + " ")); args = spliterParam.Split(arguments); foreach (string text in args) { - Regex spliterVal = new Regex(@"ReplacedStr:::2:::", RegexOptions.IgnoreCase); - - //Array for parts of an arg - string[] parts; + Regex spliterVal = new Regex(@"\s", RegexOptions.IgnoreCase); //split arg with Spilter-Regex and save in parts - parts = spliterVal.Split(text, 2); + string[] parts = spliterVal.Split(text, 2); switch (parts.Length) { //Only found a parameter case 1: - if (!Regex.IsMatch(parts[0], @"ReplacedStr:::3:::") && parts[0].Length > 0) + if (parts[0] != "") { //Add parameter _Params.Add(parts[0]); @@ -697,7 +729,7 @@ namespace Vocaluxe.Base //Found parameter and value case 2: - if (!Regex.IsMatch(parts[0], @"ReplacedStr:::5:::") && parts[0].Length > 0) + if (parts[0] != "") { //Add parameter _Params.Add(parts[0]); @@ -793,11 +825,7 @@ namespace Vocaluxe.Base if (value.Contains(chars[i].ToString())) return false; } - if (Path.GetFileName(value).Length == 0) - return false; - if (!Path.HasExtension(value)) - return false; - return true; + return !String.IsNullOrEmpty(Path.GetFileName(value)) && Path.HasExtension(value); } /// @@ -805,22 +833,18 @@ namespace Vocaluxe.Base /// public static void UsePlayers() { - for (int i = 0; i < CProfiles.Profiles.Length; i++) + for (int j = 0; j < CSettings.MaxNumPlayer; j++) { - for (int j = 0; j < CSettings.MaxNumPlayer; j++) + CGame.Players[j].ProfileID = -1; + if (Players[j] == "") + continue; + for (int i = 0; i < CProfiles.Profiles.Length; i++) { - if (Players[j].Length > 0) + if (Path.GetFileName(CProfiles.Profiles[i].ProfileFile) == Players[j] && CProfiles.Profiles[i].Active == EOffOn.TR_CONFIG_ON) { - if (Path.GetFileName(CProfiles.Profiles[i].ProfileFile) == Players[j] && CProfiles.Profiles[i].Active == EOffOn.TR_CONFIG_ON) - { - //Update Game-infos with player - CGame.Player[j].Name = CProfiles.Profiles[i].PlayerName; - CGame.Player[j].Difficulty = CProfiles.Profiles[i].Difficulty; - CGame.Player[j].ProfileID = i; - } + //Update Game-infos with player + CGame.Players[j].ProfileID = i; } - else - CGame.Player[j].ProfileID = -1; } } } diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 962815ae..24f80d64 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -1,6 +1,26 @@ -using System; +#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.IO; +using System.Linq; using System.Text; using System.Xml; using VocaluxeLib.Menu; @@ -97,18 +117,12 @@ namespace Vocaluxe.Base /// /// Returns true if a cover with the given name exists. /// - public static bool CoverExists(string name) + private static bool _CoverExists(string name) { - STexture cov = _NoCover; lock (_MutexCover) { - foreach (SCover cover in _Cover) - { - if (cover.Name == name) - return true; - } + return _Cover.Any(cover => cover.Name == name); } - return false; } /// @@ -149,8 +163,8 @@ namespace Vocaluxe.Base { _CoverThemes.Clear(); - string path = CSettings.FolderCover; - List files = CHelper.ListFiles(path, "*.xml", false); + const string path = CSettings.FolderCover; + List files = CHelper.ListFiles(path, "*.xml"); foreach (string file in files) { @@ -160,10 +174,10 @@ namespace Vocaluxe.Base { SCoverTheme coverTheme = new SCoverTheme(); - xmlReader.GetValue("//root/Info/Name", ref coverTheme.Name, String.Empty); - xmlReader.GetValue("//root/Info/Folder", ref coverTheme.Folder, String.Empty); + xmlReader.GetValue("//root/Info/Name", out coverTheme.Name, String.Empty); + xmlReader.GetValue("//root/Info/Folder", out coverTheme.Folder, String.Empty); - if (coverTheme.Folder.Length > 0 && coverTheme.Name.Length > 0) + if (coverTheme.Folder != "" && coverTheme.Name != "") { coverTheme.File = file; @@ -178,69 +192,61 @@ namespace Vocaluxe.Base /// private static void _LoadCover(string coverThemeName) { - SCoverTheme coverTheme = new SCoverTheme(); + SCoverTheme coverTheme = _CoverTheme(coverThemeName); - coverTheme = _CoverTheme(coverThemeName); + if (coverTheme.Name == "") + return; + CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File)); - if (coverTheme.Name.Length > 0) + if (xmlReader != null) { - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File)); - - if (xmlReader != null) + lock (_MutexCover) { - lock (_MutexCover) - { - _Cover.Clear(); - List cover = xmlReader.GetValues("Cover"); - for (int i = 0; i < cover.Count; i++) - { - SCover sk = new SCover(); - string name = String.Empty; - string value = String.Empty; - xmlReader.GetValue("//root/Cover/" + cover[i] + "/Name", ref name, String.Empty); - xmlReader.GetValue("//root/Cover/" + cover[i] + "/Path", ref value, String.Empty); - sk.Name = name; - sk.Value = Path.Combine(coverTheme.Folder, value); - if (File.Exists(Path.Combine(CSettings.FolderCover, Path.Combine(coverTheme.Folder, value)))) - sk.Texture = CDraw.AddTexture(Path.Combine(CSettings.FolderCover, Path.Combine(coverTheme.Folder, value))); - else - sk.Texture = _NoCover; - - _Cover.Add(sk); - - if (sk.Name == "NoCover") - _NoCover = sk.Texture; - } - } - } - - List files = new List(); - - files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.FolderCover, coverTheme.Folder), "*.png", true, true)); - files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.FolderCover, coverTheme.Folder), "*.jpg", true, true)); - files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.FolderCover, coverTheme.Folder), "*.jpeg", true, true)); - files.AddRange(CHelper.ListFiles(Path.Combine(CSettings.FolderCover, coverTheme.Folder), "*.bmp", true, true)); - - - foreach (string file in files) - { - string name = Path.GetFileNameWithoutExtension(file); - - if (!CoverExists(name)) + _Cover.Clear(); + List cover = xmlReader.GetValues("Cover"); + foreach (string coverName in cover) { SCover sk = new SCover(); - - string value = String.Empty; - + string name; + string value; + xmlReader.GetValue("//root/Cover/" + coverName + "/Name", out name, String.Empty); + xmlReader.GetValue("//root/Cover/" + coverName + "/Path", out value, String.Empty); sk.Name = name; - sk.Value = Path.Combine(coverTheme.Folder, Path.GetFileName(file)); - - sk.Texture = CDraw.AddTexture(Path.Combine(CSettings.FolderCover, sk.Value)); + sk.Value = Path.Combine(coverTheme.Folder, value); + sk.Texture = File.Exists(Path.Combine(CSettings.FolderCover, sk.Value)) + ? CDraw.AddTexture(Path.Combine(CSettings.FolderCover, Path.Combine(coverTheme.Folder, value))) : _NoCover; _Cover.Add(sk); + + if (sk.Name == "NoCover") + _NoCover = sk.Texture; } } } + + List files = new List(); + + string path = Path.Combine(CSettings.FolderCover, coverTheme.Folder); + files.AddRange(CHelper.ListFiles(path, "*.png", true, true)); + files.AddRange(CHelper.ListFiles(path, "*.jpg", true, true)); + files.AddRange(CHelper.ListFiles(path, "*.jpeg", true, true)); + files.AddRange(CHelper.ListFiles(path, "*.bmp", true, true)); + + + foreach (string file in files) + { + string name = Path.GetFileNameWithoutExtension(file); + + if (_CoverExists(name)) + continue; + // ReSharper disable AssignNullToNotNullAttribute + SCover sk = new SCover {Name = name, Value = Path.Combine(coverTheme.Folder, Path.GetFileName(file))}; + // ReSharper restore AssignNullToNotNullAttribute + + sk.Texture = CDraw.AddTexture(Path.Combine(CSettings.FolderCover, sk.Value)); + + _Cover.Add(sk); + } } } } \ No newline at end of file diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 9df5747c..da72c5b6 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -1,4 +1,23 @@ -using System; +#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.Data; using System.Drawing; @@ -51,19 +70,9 @@ namespace Vocaluxe.Base } #region Highscores - public static int AddScore(string playerName, int score, int lineNr, long date, int medley, int duet, int shortSong, int diff, + public static int AddScore(string playerName, int score, int lineNr, long date, int medley, int duet, int shortSong, int difficulty, string artist, string title, int numPlayed, string filePath) { - SPlayer player = new SPlayer(); - player.Name = playerName; - player.Points = score; - player.LineNr = lineNr; - player.DateTicks = date; - player.Medley = medley == 1; - player.Duet = duet == 1; - player.ShortSong = shortSong == 1; - player.Difficulty = (EGameDifficulty)diff; - using (SQLiteConnection connection = new SQLiteConnection()) { connection.ConnectionString = "Data Source=" + filePath; @@ -80,7 +89,7 @@ namespace Vocaluxe.Base using (SQLiteCommand command = new SQLiteCommand(connection)) { int dataBaseSongID = _GetDataBaseSongID(artist, title, numPlayed, command); - int result = _AddScore(player, command, dataBaseSongID); + int result = _AddScore(playerName, score, lineNr, date, medley, duet, shortSong, difficulty, dataBaseSongID, command); return result; } } @@ -104,42 +113,30 @@ namespace Vocaluxe.Base using (SQLiteCommand command = new SQLiteCommand(connection)) { int dataBaseSongID = _GetDataBaseSongID(player, command); - int result = _AddScore(player, command, dataBaseSongID); - - return result; + return _AddScore(CProfiles.GetPlayerName(player.ProfileID), (int)Math.Round(player.Points), player.LineNr, player.DateTicks, player.Medley ? 1 : 0, + player.Duet ? 1 : 0, player.ShortSong ? 1 : 0, (int)CProfiles.GetDifficulty(player.ProfileID), dataBaseSongID, command); } } } - private static int _AddScore(SPlayer player, SQLiteCommand command, int dataBaseSongID) + private static int _AddScore(string playerName, int score, int lineNr, long date, int medley, int duet, int shortSong, int difficulty, + int dataBaseSongID, SQLiteCommand command) { int lastInsertID = -1; if (dataBaseSongID >= 0) { - int medley = 0; - if (player.Medley) - medley = 1; - - int duet = 0; - if (player.Duet) - duet = 1; - - int shortSong = 0; - if (player.ShortSong) - shortSong = 1; - command.CommandText = "SELECT id FROM Scores WHERE SongID = @SongID AND PlayerName = @PlayerName AND Score = @Score AND " + "LineNr = @LineNr AND Date = @Date AND Medley = @Medley AND Duet = @Duet AND ShortSong = @ShortSong AND Difficulty = @Difficulty"; command.Parameters.Add("@SongID", DbType.Int32, 0).Value = dataBaseSongID; - command.Parameters.Add("@PlayerName", DbType.String, 0).Value = player.Name; - command.Parameters.Add("@Score", DbType.Int32, 0).Value = (int)Math.Round(player.Points); - command.Parameters.Add("@LineNr", DbType.Int32, 0).Value = player.LineNr; - command.Parameters.Add("@Date", DbType.Int64, 0).Value = player.DateTicks; + command.Parameters.Add("@PlayerName", DbType.String, 0).Value = playerName; + command.Parameters.Add("@Score", DbType.Int32, 0).Value = score; + command.Parameters.Add("@LineNr", DbType.Int32, 0).Value = lineNr; + command.Parameters.Add("@Date", DbType.Int64, 0).Value = date; command.Parameters.Add("@Medley", DbType.Int32, 0).Value = medley; command.Parameters.Add("@Duet", DbType.Int32, 0).Value = duet; command.Parameters.Add("@ShortSong", DbType.Int32, 0).Value = shortSong; - command.Parameters.Add("@Difficulty", DbType.Int32, 0).Value = (int)player.Difficulty; + command.Parameters.Add("@Difficulty", DbType.Int32, 0).Value = difficulty; SQLiteDataReader reader = null; try @@ -155,22 +152,19 @@ namespace Vocaluxe.Base } if (reader != null) - { reader.Dispose(); - reader = null; - } command.CommandText = "INSERT INTO Scores (SongID, PlayerName, Score, LineNr, Date, Medley, Duet, ShortSong, Difficulty) " + "VALUES (@SongID, @PlayerName, @Score, @LineNr, @Date, @Medley, @Duet, @ShortSong, @Difficulty)"; command.Parameters.Add("@SongID", DbType.Int32, 0).Value = dataBaseSongID; - command.Parameters.Add("@PlayerName", DbType.String, 0).Value = player.Name; - command.Parameters.Add("@Score", DbType.Int32, 0).Value = (int)Math.Round(player.Points); - command.Parameters.Add("@LineNr", DbType.Int32, 0).Value = player.LineNr; - command.Parameters.Add("@Date", DbType.Int64, 0).Value = player.DateTicks; + command.Parameters.Add("@PlayerName", DbType.String, 0).Value = playerName; + command.Parameters.Add("@Score", DbType.Int32, 0).Value = score; + command.Parameters.Add("@LineNr", DbType.Int32, 0).Value = lineNr; + command.Parameters.Add("@Date", DbType.Int64, 0).Value = date; command.Parameters.Add("@Medley", DbType.Int32, 0).Value = medley; command.Parameters.Add("@Duet", DbType.Int32, 0).Value = duet; command.Parameters.Add("@ShortSong", DbType.Int32, 0).Value = shortSong; - command.Parameters.Add("@Difficulty", DbType.Int32, 0).Value = (int)player.Difficulty; + command.Parameters.Add("@Difficulty", DbType.Int32, 0).Value = difficulty; command.ExecuteNonQuery(); //Read last insert line @@ -189,7 +183,7 @@ namespace Vocaluxe.Base return lastInsertID; } - public static void LoadScore(ref List scores, SPlayer player) + public static void LoadScore(out List scores, SPlayer player) { using (SQLiteConnection connection = new SQLiteConnection()) { @@ -236,13 +230,15 @@ namespace Vocaluxe.Base { while (reader.Read()) { - SScores score = new SScores(); - score.Name = reader.GetString(0); - score.Score = reader.GetInt32(1); - score.Date = new DateTime(reader.GetInt64(2)).ToString("dd/MM/yyyy"); - score.Difficulty = (EGameDifficulty)reader.GetInt32(3); - score.LineNr = reader.GetInt32(4); - score.ID = reader.GetInt32(5); + SScores score = new SScores + { + Name = reader.GetString(0), + Score = reader.GetInt32(1), + Date = new DateTime(reader.GetInt64(2)).ToString("dd/MM/yyyy"), + Difficulty = (EGameDifficulty)reader.GetInt32(3), + LineNr = reader.GetInt32(4), + ID = reader.GetInt32(5) + }; scores.Add(score); } @@ -263,26 +259,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"; @@ -298,35 +274,29 @@ namespace Vocaluxe.Base reader.Dispose(); return id; } - else - { - if (reader != null) - reader.Close(); + if (reader != null) + reader.Close(); - command.CommandText = "INSERT INTO Songs (Title, Artist, NumPlayed) " + - "VALUES (@title, @artist, @numplayed)"; - command.Parameters.Add("@title", DbType.String, 0).Value = title; - command.Parameters.Add("@artist", DbType.String, 0).Value = artist; - command.Parameters.Add("@numplayed", DbType.Int32, 0).Value = defNumPlayed; - command.ExecuteNonQuery(); + command.CommandText = "INSERT INTO Songs (Title, Artist, NumPlayed) " + + "VALUES (@title, @artist, @numplayed)"; + command.Parameters.Add("@title", DbType.String, 0).Value = title; + command.Parameters.Add("@artist", DbType.String, 0).Value = artist; + command.Parameters.Add("@numplayed", DbType.Int32, 0).Value = defNumPlayed; + command.ExecuteNonQuery(); - command.CommandText = "SELECT id FROM Songs WHERE [Title] = @title AND [Artist] = @artist"; - command.Parameters.Add("@title", DbType.String, 0).Value = title; - command.Parameters.Add("@artist", DbType.String, 0).Value = artist; + command.CommandText = "SELECT id FROM Songs WHERE [Title] = @title AND [Artist] = @artist"; + command.Parameters.Add("@title", DbType.String, 0).Value = title; + command.Parameters.Add("@artist", DbType.String, 0).Value = artist; - reader = command.ExecuteReader(); - - if (reader != null) - { - reader.Read(); - int id = reader.GetInt32(0); - reader.Dispose(); - return id; - } - } + reader = command.ExecuteReader(); if (reader != null) + { + reader.Read(); + int id = reader.GetInt32(0); reader.Dispose(); + return id; + } return -1; } @@ -355,7 +325,7 @@ namespace Vocaluxe.Base command.CommandText = "SELECT Artist, Title, NumPlayed FROM Songs WHERE [id] = @id"; command.Parameters.Add("@id", DbType.String, 0).Value = songID; - SQLiteDataReader reader = null; + SQLiteDataReader reader; try { reader = command.ExecuteReader(); @@ -391,7 +361,7 @@ namespace Vocaluxe.Base { _CreateOrConvert(oldDBFilePath); _CreateOrConvert(_HighscoreFilePath); - _ImportData(oldDBFilePath, _HighscoreFilePath); + _ImportData(oldDBFilePath); File.Delete(oldDBFilePath); } @@ -497,11 +467,10 @@ namespace Vocaluxe.Base return false; } - SQLiteDataReader reader = null; using (SQLiteCommand command = new SQLiteCommand(connection)) { command.CommandText = "PRAGMA user_version"; - reader = command.ExecuteReader(); + SQLiteDataReader reader = command.ExecuteReader(); reader.Read(); int version = reader.GetInt32(0); @@ -617,24 +586,14 @@ namespace Vocaluxe.Base List scores = new List(); List songs = new List(); - SQLiteDataReader reader = null; command.CommandText = "SELECT id, PlayerName, Date FROM Scores"; - try - { - reader = command.ExecuteReader(); - } - catch (Exception) - { - throw; - } + SQLiteDataReader reader = command.ExecuteReader(); if (reader != null && reader.HasRows) { while (reader.Read()) { - SData data = new SData(); - data.Id = reader.GetInt32(0); - data.Str1 = reader.GetString(1); + SData data = new SData {Id = reader.GetInt32(0), Str1 = reader.GetString(1)}; Int64 ticks = 0; try @@ -658,10 +617,7 @@ namespace Vocaluxe.Base { while (reader.Read()) { - SData data = new SData(); - data.Id = reader.GetInt32(0); - data.Str1 = reader.GetString(1); - data.Str2 = reader.GetString(2); + SData data = new SData {Id = reader.GetInt32(0), Str1 = reader.GetString(1), Str2 = reader.GetString(2)}; songs.Add(data); } } @@ -792,21 +748,13 @@ namespace Vocaluxe.Base while (Sqlite3.sqlite3_step(stmt) == Sqlite3.SQLITE_ROW) { - SData data = new SData(); - - data.Id = Sqlite3.sqlite3_column_int(stmt, 0); + SData data = new SData {Id = Sqlite3.sqlite3_column_int(stmt, 0)}; byte[] bytes = Sqlite3.sqlite3_column_rawbytes(stmt, 1); - if (bytes != null) - data.Str1 = utf8.GetString(Encoding.Convert(cp1252, utf8, bytes)); - else - data.Str1 = "Someone"; + data.Str1 = bytes != null ? utf8.GetString(Encoding.Convert(cp1252, utf8, bytes)) : "Someone"; bytes = Sqlite3.sqlite3_column_rawbytes(stmt, 2); - if (bytes != null) - data.Str2 = utf8.GetString(Encoding.Convert(cp1252, utf8, bytes)); - else - data.Str2 = "Someone"; + data.Str2 = bytes != null ? utf8.GetString(Encoding.Convert(cp1252, utf8, bytes)) : "Someone"; songs.Add(data); } @@ -830,15 +778,10 @@ namespace Vocaluxe.Base while (Sqlite3.sqlite3_step(stmt) == Sqlite3.SQLITE_ROW) { - SData data = new SData(); - - data.Id = Sqlite3.sqlite3_column_int(stmt, 0); + SData data = new SData {Id = Sqlite3.sqlite3_column_int(stmt, 0)}; byte[] bytes = Sqlite3.sqlite3_column_rawbytes(stmt, 1); - if (bytes != null) - data.Str1 = utf8.GetString(Encoding.Convert(cp1252, utf8, bytes)); - else - data.Str1 = "Someone"; + data.Str1 = bytes != null ? utf8.GetString(Encoding.Convert(cp1252, utf8, bytes)) : "Someone"; if (dateExists) data.Ticks = _UnixTimeToTicks(Sqlite3.sqlite3_column_int(stmt, 2)); @@ -915,7 +858,7 @@ namespace Vocaluxe.Base return true; } - private static bool _ImportData(string sourceDBPath, string destinationDBPath) + private static bool _ImportData(string sourceDBPath) { #region open db using (SQLiteConnection connSource = new SQLiteConnection()) @@ -935,11 +878,9 @@ namespace Vocaluxe.Base using (SQLiteCommand cmdSource = new SQLiteCommand(connSource)) { - SQLiteDataReader source; - #region import table scores cmdSource.CommandText = "SELECT SongID, PlayerName, Score, LineNr, Date, Medley, Duet, ShortSong, Difficulty FROM Scores"; - source = cmdSource.ExecuteReader(); + SQLiteDataReader source = cmdSource.ExecuteReader(); if (source == null) return false; @@ -987,8 +928,7 @@ namespace Vocaluxe.Base if (_ConnectionCover == null) { - _ConnectionCover = new SQLiteConnection(); - _ConnectionCover.ConnectionString = "Data Source=" + _CoverFilePath; + _ConnectionCover = new SQLiteConnection {ConnectionString = "Data Source=" + _CoverFilePath}; _ConnectionCover.Open(); } @@ -1247,6 +1187,13 @@ namespace Vocaluxe.Base reader.Read(); byte[] data = _GetBytes(reader); tex = CDraw.AddTexture(w, h, ref data); + /*using (Bitmap bmp = new Bitmap(w, h)) + { + BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); + Marshal.Copy(data, 0, bmpData.Scan0, w * h * 4); + bmp.UnlockBits(bmpData); + bmp.Save(fileName); + }*/ } } @@ -1259,6 +1206,7 @@ namespace Vocaluxe.Base } //If you want to add an image to db, call this method! + /* private static bool _AddImageToCreditsDB(String imagePath) { bool result = false; @@ -1332,6 +1280,7 @@ namespace Vocaluxe.Base return result; } +*/ private static bool _InitCreditsRessourcesDB() { @@ -1387,6 +1336,7 @@ namespace Vocaluxe.Base return true; } + /* private static void _CreateCreditsRessourcesDB() { using (SQLiteConnection connection = new SQLiteConnection()) @@ -1421,16 +1371,17 @@ namespace Vocaluxe.Base } } } +*/ #endregion CreditsRessources private static byte[] _GetBytes(SQLiteDataReader reader) { const int chunkSize = 2 * 1024; byte[] buffer = new byte[chunkSize]; - long bytesRead; long fieldOffset = 0; using (MemoryStream stream = new MemoryStream()) { + long bytesRead; while ((bytesRead = reader.GetBytes(0, fieldOffset, buffer, 0, buffer.Length)) > 0) { byte[] actualRead = new byte[bytesRead]; diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index feb52eae..bc843f7f 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -1,4 +1,23 @@ -using System; +#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.Drawing; using System.IO; using System.Windows.Forms; @@ -255,7 +274,7 @@ namespace Vocaluxe.Base if (rect.Height <= 0f) return; - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, aspect); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, aspect); DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, staticBounds.Rect.Z), texture.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f), false); } diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/CFont.cs index 3cc030d6..7b9b8cf0 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/CFont.cs @@ -1,9 +1,29 @@ -using System; +#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; @@ -20,15 +40,14 @@ namespace Vocaluxe.Base } public STexture Texture; - public char Chr; - public int Width; + public readonly int Width; public CGlyph(char chr, float maxHigh) { _Sizeh = maxHigh; float outline = CFonts.Outline; - TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; + const TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; float factor = _GetFactor(chr, flags); CFonts.Height = Sizeh * factor; @@ -91,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(); } @@ -139,7 +157,7 @@ namespace Vocaluxe.Base private FontFamily _Family; private readonly float _Sizeh; - public string FilePath; + public readonly string FilePath; public CFont(string file) { @@ -322,37 +340,17 @@ namespace Vocaluxe.Base public static float Height { get { return _Height; } - set - { - if (value < 0f) - _Height = 0f; - else - _Height = value; - } + set { _Height = value < 0f ? 0f : value; } } public static float Outline { get { return _Fonts[_CurrentFont].Outline; } - set - { - SFont font = _Fonts[_CurrentFont]; - font.Outline = value; - if (font.Outline < 0f) - font.Outline = 0f; - if (font.Outline > 1f) - font.Outline = 1f; - } } public static SColorF OutlineColor { get { return _Fonts[_CurrentFont].OutlineColor; } - set - { - SFont font = _Fonts[_CurrentFont]; - font.OutlineColor = value; - } } public static void Init() @@ -412,7 +410,7 @@ namespace Vocaluxe.Base if (h <= 0f) return; - if (text.Length == 0) + if (text == "") return; Height = h; @@ -431,7 +429,7 @@ namespace Vocaluxe.Base if (h <= 0f) return; - if (text.Length == 0) + if (text == "") return; Height = h; @@ -450,7 +448,7 @@ namespace Vocaluxe.Base if (h <= 0f) return; - if (text.Length == 0) + if (text == "") return; Height = h; @@ -506,7 +504,7 @@ namespace Vocaluxe.Base public static void SetFont(string fontName) { - int index = -1; + int index; if (PartyModeID != -1) { @@ -551,77 +549,63 @@ 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) { string value = string.Empty; int i = 1; - while (xmlReader.GetValue("//root/Fonts/Font" + i.ToString() + "/Folder", ref value, value)) + while (xmlReader.GetValue("//root/Fonts/Font" + i + "/Folder", out value, value)) { - SFont sf = new SFont(); - sf.Folder = value; - sf.IsThemeFont = themeName.Length > 0; - sf.ThemeName = themeName; - sf.PartyModeID = partyModeId; + SFont sf = new SFont {Folder = value, IsThemeFont = themeName != "", ThemeName = themeName, PartyModeID = partyModeId}; bool ok = true; - string name = String.Empty; - ok &= xmlReader.GetValue("//root/Fonts/Font" + i.ToString() + "/Name", ref name, value); + string name; + ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/Name", out name, value); sf.Name = name; - ok &= xmlReader.GetValue("//root/Fonts/Font" + i.ToString() + "/FileNormal", ref value, value); + ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileNormal", out value, value); sf.FileNormal = value; value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value)); CFont f = new CFont(value); sf.Normal = f; - ok &= xmlReader.GetValue("//root/Fonts/Font" + i.ToString() + "/FileItalic", ref value, value); + ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileItalic", out value, value); sf.FileItalic = value; value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.Italic = f; - ok &= xmlReader.GetValue("//root/Fonts/Font" + i.ToString() + "/FileBold", ref value, value); + ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBold", out value, value); sf.FileBold = value; value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.Bold = f; - ok &= xmlReader.GetValue("//root/Fonts/Font" + i.ToString() + "/FileBoldItalic", ref value, value); + ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBoldItalic", out value, value); sf.FileBoldItalic = value; value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.BoldItalic = f; sf.Outline = 0f; - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i.ToString() + "/Outline", ref sf.Outline); + ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/Outline", ref sf.Outline); sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i.ToString() + "/OutlineColorR", ref sf.OutlineColor.R); - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i.ToString() + "/OutlineColorG", ref sf.OutlineColor.G); - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i.ToString() + "/OutlineColorB", ref sf.OutlineColor.B); - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i.ToString() + "/OutlineColorA", ref sf.OutlineColor.A); + ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorR", ref sf.OutlineColor.R); + ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorG", ref sf.OutlineColor.G); + ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorB", ref sf.OutlineColor.B); + ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorA", ref sf.OutlineColor.A); if (ok) _Fonts.Add(sf); @@ -630,11 +614,11 @@ namespace Vocaluxe.Base string fontTypes; if (partyModeId >= 0) fontTypes = "theme fonts for party mode"; - else if (themeName.Length > 0) + else if (themeName != "") fontTypes = "theme fonts for theme \"" + themeName + "\""; else fontTypes = "basic fonts"; - CLog.LogError("Error loading " + fontTypes + ": Error in Font" + i.ToString()); + CLog.LogError("Error loading " + fontTypes + ": Error in Font" + i); } i++; } @@ -696,7 +680,7 @@ namespace Vocaluxe.Base setStart = true; } - writer.WriteStartElement("Font" + fontNr.ToString()); + writer.WriteStartElement("Font" + fontNr); writer.WriteElementString("Name", _Fonts[index].Name); writer.WriteElementString("Folder", _Fonts[index].Folder); @@ -746,7 +730,7 @@ namespace Vocaluxe.Base private static int _GetFontIndex(string themeName, string fontName) { - if (themeName.Length == 0 || fontName.Length == 0) + if (themeName == "" || fontName == "") return -1; for (int i = 0; i < _Fonts.Count; i++) @@ -760,7 +744,7 @@ namespace Vocaluxe.Base private static int _GetFontIndexParty(int partyModeID, string fontName) { - if (partyModeID == -1 || fontName.Length == 0) + if (partyModeID == -1 || fontName == "") return -1; for (int i = 0; i < _Fonts.Count; i++) @@ -774,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/CGame.cs b/Vocaluxe/Base/CGame.cs index c741659d..ae909a92 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -1,4 +1,23 @@ -using System; +#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 Vocaluxe.GameModes; using VocaluxeLib.Menu; @@ -10,14 +29,8 @@ namespace Vocaluxe.Base static class CGame { private static IGameMode _GameMode; - private static SPlayer[] _Player; private static int _NumPlayer = CConfig.NumPlayer; - private static float _Beat; - private static int _CurrentBeat; - - private static float _MidBeatD; - private static int _CurrentBeatD; private static int _OldBeatD; private static readonly Random _Rand = new Random(); @@ -39,36 +52,21 @@ namespace Vocaluxe.Base return 0f; } - public static int CurrentBeat - { - get { return _CurrentBeat; } - } + public static int CurrentBeat { get; private set; } - public static float Beat - { - get { return _Beat; } - } + public static float Beat { get; private set; } - public static float MidBeatD - { - get { return _MidBeatD; } - } + public static float MidBeatD { get; private set; } - public static int ActBeatD - { - get { return _CurrentBeatD; } - } + public static int ActBeatD { get; private set; } - public static SPlayer[] Player - { - get { return _Player; } - } + public static SPlayer[] Players { get; private set; } public static void Init() { _GameMode = new CGameModeNormal(); _GameMode.Init(); - _Player = new SPlayer[CSettings.MaxNumPlayer]; + Players = new SPlayer[CSettings.MaxNumPlayer]; ResetPlayer(); CConfig.UsePlayers(); @@ -117,12 +115,12 @@ namespace Vocaluxe.Base public static void Start() { - _GameMode.Start(_Player); + _GameMode.Start(Players); } public static void NextRound() { - _GameMode.NextRound(_Player); + _GameMode.NextRound(Players); } public static bool IsFinished() @@ -177,63 +175,61 @@ namespace Vocaluxe.Base public static void ResetPlayer() { - for (int i = 0; i < _Player.Length; i++) + for (int i = 0; i < Players.Length; i++) { - _Player[i].Points = 0f; - _Player[i].PointsLineBonus = 0f; - _Player[i].PointsGoldenNotes = 0f; - _Player[i].LineNr = 0; - _Player[i].NoteDiff = 0; - _Player[i].SingLine = new List(); - _Player[i].CurrentLine = -1; - _Player[i].CurrentNote = -1; - _Player[i].SongID = -1; - _Player[i].Medley = false; - _Player[i].Duet = false; - _Player[i].ShortSong = false; - _Player[i].DateTicks = DateTime.Now.Ticks; - _Player[i].SongFinished = false; + Players[i].Points = 0f; + Players[i].PointsLineBonus = 0f; + Players[i].PointsGoldenNotes = 0f; + Players[i].LineNr = 0; + Players[i].NoteDiff = 0; + Players[i].SingLine = new List(); + Players[i].CurrentLine = -1; + Players[i].CurrentNote = -1; + Players[i].SongID = -1; + Players[i].Medley = false; + Players[i].Duet = false; + Players[i].ShortSong = false; + Players[i].DateTicks = DateTime.Now.Ticks; + Players[i].SongFinished = false; } _OldBeatD = -100; - _Beat = -100; - _CurrentBeat = -100; - _CurrentBeatD = -100; + Beat = -100; + CurrentBeat = -100; + ActBeatD = -100; } public static void UpdatePoints(float time) { - bool debugHit = false; - CSong song = _GameMode.GetSong(); if (song == null) return; float b = GetBeatFromTime(time, song.BPM, song.Gap); - if (b <= _Beat) + if (b <= Beat) return; - _Beat = b; - _CurrentBeat = (int)Math.Floor(_Beat); + Beat = b; + CurrentBeat = (int)Math.Floor(Beat); - _MidBeatD = -0.5f + GetBeatFromTime(time, song.BPM, song.Gap + CConfig.MicDelay / 1000f); - _CurrentBeatD = (int)Math.Floor(_MidBeatD); + MidBeatD = -0.5f + GetBeatFromTime(time, song.BPM, song.Gap + CConfig.MicDelay / 1000f); + ActBeatD = (int)Math.Floor(MidBeatD); for (int p = 0; p < _NumPlayer; p++) CSound.AnalyzeBuffer(p); - if (_OldBeatD >= _CurrentBeatD) + if (_OldBeatD >= ActBeatD) return; for (int p = 0; p < _NumPlayer; p++) { - for (int beat = _OldBeatD + 1; beat <= _CurrentBeatD; beat++) + 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)) - _Player[p].SongFinished = true; + Players[p].SongFinished = true; - CLine[] lines = song.Notes.GetLines(_Player[p].LineNr).Line; + CLine[] lines = song.Notes.GetVoice(Players[p].LineNr).Lines; int line = -1; for (int j = 0; j < lines.Length; j++) @@ -245,125 +241,121 @@ namespace Vocaluxe.Base } } - if (line >= 0) + if (line < 0) + continue; + if (line != Players[p].CurrentLine) + Players[p].CurrentNote = -1; + + Players[p].CurrentLine = line; + + while (Players[p].SingLine.Count <= line) + Players[p].SingLine.Add(new CLine()); + + CNote[] notes = lines[line].Notes; + int note = -1; + for (int j = 0; j < notes.Length; j++) { - if (line != _Player[p].CurrentLine) - _Player[p].CurrentNote = -1; - - _Player[p].CurrentLine = line; - - while (_Player[p].SingLine.Count <= line) - _Player[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) { - if (beat >= notes[j].StartBeat && beat <= notes[j].EndBeat) + note = j; + break; + } + } + + if (note >= 0) + { + Players[p].CurrentNote = note; + + if (line == lines.Length - 1) + { + if (note == lines[line].NoteCount - 1) { - note = j; - break; + if (notes[note].EndBeat == beat) + Players[p].SongFinished = true; } } - if (note >= 0) + if (notes[note].PointsForBeat > 0 && CSound.RecordToneValid(p)) { - _Player[p].CurrentNote = note; + int tone = notes[note].Tone; + int tonePlayer = CSound.RecordGetTone(p); - if (line == lines.Length - 1) + while (tonePlayer - tone > 6) + tonePlayer -= 12; + + while (tonePlayer - tone < -6) + tonePlayer += 12; + + Players[p].NoteDiff = Math.Abs(tone - tonePlayer); + bool hit = Players[p].NoteDiff <= (2 - (int)CProfiles.GetDifficulty(Players[p].ProfileID)); + if (hit) { - if (note == lines[line].NoteCount - 1) + // valid + //CSound.RecordSetTone(p, Tone); + double points = (CSettings.MaxScore - CSettings.LinebonusScore) * (double)notes[note].PointsForBeat / + song.Notes.GetVoice(Players[p].LineNr).Points; + if (notes[note].NoteType == ENoteType.Golden) + Players[p].PointsGoldenNotes += points; + + Players[p].Points += points; + + // update player notes (sung notes) + if (Players[p].SingLine[line].NoteCount > 0) { - if (notes[note].EndBeat == beat) - _Player[p].SongFinished = true; - } - } - - if (notes[note].PointsForBeat > 0 && (CSound.RecordToneValid(p) || debugHit)) - { - int tone = notes[note].Tone; - int tonePlayer = CSound.RecordGetTone(p); - - while (tonePlayer - tone > 6) - tonePlayer -= 12; - - while (tonePlayer - tone < -6) - tonePlayer += 12; - - if (debugHit) - tonePlayer = tone; - - _Player[p].NoteDiff = Math.Abs(tone - tonePlayer); - bool hit = _Player[p].NoteDiff <= (2 - (int)_Player[p].Difficulty); - if (hit) - { - // valid - //CSound.RecordSetTone(p, Tone); - double points = (CSettings.MaxScore - CSettings.LinebonusScore) * (double)notes[note].PointsForBeat / - song.Notes.GetLines(_Player[p].LineNr).Points; - if (notes[note].NoteType == ENoteType.Golden) - _Player[p].PointsGoldenNotes += points; - - _Player[p].Points += points; - - // update player notes (sung notes) - if (_Player[p].SingLine[line].NoteCount > 0) - { - CNote nt = _Player[p].SingLine[line].LastNote; - if (notes[note].StartBeat == beat || nt.EndBeat + 1 != beat || nt.Tone != tone || !nt.Hit) - _Player[p].SingLine[line].AddNote(new CNote(beat, 1, tone, String.Empty, true, notes[note].NoteType)); - else - _Player[p].SingLine[line].IncLastNoteLength(); - } + CNote lastNote = Players[p].SingLine[line].LastNote; + if (notes[note].StartBeat == beat || lastNote.EndBeat + 1 != beat || lastNote.Tone != tone || !lastNote.Hit) + Players[p].SingLine[line].AddNote(new CNote(beat, 1, tone, String.Empty, true, notes[note].NoteType)); else - _Player[p].SingLine[line].AddNote(new CNote(beat, 1, tone, String.Empty, true, notes[note].NoteType)); - - _Player[p].SingLine[line].LastNote.IsPerfect(notes[note]); - _Player[p].SingLine[line].IsPerfect(lines[line]); + Players[p].SingLine[line].IncLastNoteLength(); } else - { - if (_Player[p].SingLine[line].NoteCount > 0) - { - CNote nt = _Player[p].SingLine[line].LastNote; - if (nt.Tone == tonePlayer && nt.EndBeat + 1 == beat && !nt.Hit) - _Player[p].SingLine[line].IncLastNoteLength(); - else - _Player[p].SingLine[line].AddNote(new CNote(beat, 1, tonePlayer, String.Empty, false, ENoteType.Freestyle)); - } - else - _Player[p].SingLine[line].AddNote(new CNote(beat, 1, tonePlayer, String.Empty, false, ENoteType.Freestyle)); - } + Players[p].SingLine[line].AddNote(new CNote(beat, 1, tone, String.Empty, true, notes[note].NoteType)); + + Players[p].SingLine[line].LastNote.IsPerfect(notes[note]); + Players[p].SingLine[line].IsPerfect(lines[line]); } - - // Line Bonus - int numLinesWithPoints = song.Notes.GetNumLinesWithPoints(_Player[p].LineNr); - if (note == lines[line].NoteCount - 1 && numLinesWithPoints > 0) + else { - if (notes[note].EndBeat == beat && lines[line].Points > 0f) + if (Players[p].SingLine[line].NoteCount > 0) { - double factor = _Player[p].SingLine[line].Points / (double)lines[line].Points; - if (factor < 0.4) - factor = 0.0; - else if (factor > 0.9) - factor = 1.0; + CNote lastNote = Players[p].SingLine[line].LastNote; + if (lastNote.Tone == tonePlayer && lastNote.EndBeat + 1 == beat && !lastNote.Hit) + Players[p].SingLine[line].IncLastNoteLength(); else - { - factor -= 0.4; - factor *= 2; - factor *= factor; - } - - double points = CSettings.LinebonusScore * factor * 1f / numLinesWithPoints; - _Player[p].Points += points; - _Player[p].PointsLineBonus += points; + Players[p].SingLine[line].AddNote(new CNote(beat, 1, tonePlayer, String.Empty, false, ENoteType.Freestyle)); } + else + Players[p].SingLine[line].AddNote(new CNote(beat, 1, tonePlayer, String.Empty, false, ENoteType.Freestyle)); + } + } + + // Line Bonus + int numLinesWithPoints = song.Notes.GetNumLinesWithPoints(Players[p].LineNr); + if (note == lines[line].NoteCount - 1 && numLinesWithPoints > 0) + { + if (notes[note].EndBeat == beat && lines[line].Points > 0f) + { + double factor = Players[p].SingLine[line].Points / (double)lines[line].Points; + if (factor < 0.4) + factor = 0.0; + else if (factor > 0.9) + factor = 1.0; + else + { + factor -= 0.4; + factor *= 2; + factor *= factor; + } + + double points = CSettings.LinebonusScore * factor * 1f / numLinesWithPoints; + Players[p].Points += points; + Players[p].PointsLineBonus += points; } } } } } - _OldBeatD = _CurrentBeatD; + _OldBeatD = ActBeatD; } } } \ No newline at end of file diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 860fbf15..b228a042 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.Drawing; @@ -9,14 +28,6 @@ using VocaluxeLib.PartyModes; namespace Vocaluxe.Base { - enum EPopupScreens - { - PopupPlayerControl = 0, - PopupVolumeControl = 1, - - NoPopup = -1 - } - class CCursor { private readonly Stopwatch _CursorFadingTimer; @@ -103,7 +114,7 @@ namespace Vocaluxe.Base if (Math.Abs(_Cursor.Rect.X - x) > CSettings.MouseMoveDiffMin || Math.Abs(_Cursor.Rect.Y - y) > CSettings.MouseMoveDiffMin) { - if (_CursorTargetAlpha == 0f) + if (_CursorTargetAlpha < 0.01) _Fade(1f, 0.2f); _Movetimer.Reset(); @@ -254,41 +265,41 @@ namespace Vocaluxe.Base CLog.StopBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]); } - for (int i = 0; i < _PopupScreens.Count; i++) + foreach (IMenu popup in _PopupScreens) { - _PopupScreens[i].Init(); - _PopupScreens[i].LoadTheme(CTheme.GetThemeScreensPath(-1)); + popup.Init(); + popup.LoadTheme(CTheme.GetThemeScreensPath(-1)); } } public static void ReloadTheme() { _ReloadCursor(); - for (int i = 0; i < _Screens.Count; i++) - _Screens[i].ReloadTheme(CTheme.GetThemeScreensPath(-1)); + foreach (IMenu screen in _Screens) + screen.ReloadTheme(CTheme.GetThemeScreensPath(-1)); - for (int i = 0; i < _PopupScreens.Count; i++) - _PopupScreens[i].ReloadTheme(CTheme.GetThemeScreensPath(-1)); + foreach (IMenu popup in _PopupScreens) + popup.ReloadTheme(CTheme.GetThemeScreensPath(-1)); } public static void ReloadSkin() { _ReloadCursor(); - for (int i = 0; i < _Screens.Count; i++) - _Screens[i].ReloadTextures(); + foreach (IMenu menu in _Screens) + menu.ReloadTextures(); - for (int i = 0; i < _PopupScreens.Count; i++) - _PopupScreens[i].ReloadTextures(); + foreach (IMenu menu in _PopupScreens) + menu.ReloadTextures(); } public static void SaveTheme() { CTheme.SaveTheme(); - for (int i = 0; i < _Screens.Count; i++) - _Screens[i].SaveTheme(); + foreach (IMenu screen in _Screens) + screen.SaveTheme(); - for (int i = 0; i < _PopupScreens.Count; i++) - _PopupScreens[i].SaveTheme(); + foreach (IMenu popup in _PopupScreens) + popup.SaveTheme(); } public static void InitFirstScreen() @@ -393,7 +404,7 @@ namespace Vocaluxe.Base GC.Collect(); _CurrentScreen = _NextScreen; _NextScreen = EScreens.ScreenNull; - if (CBackgroundMusic.Playing) + if (CBackgroundMusic.IsPlaying) CBackgroundMusic.Play(); _Screens[(int)_CurrentScreen].OnShowFinish(); _Screens[(int)_CurrentScreen].ProcessMouseMove(_Cursor.X, _Cursor.Y); @@ -425,8 +436,8 @@ namespace Vocaluxe.Base _OldScreen = _Screens[(int)_CurrentScreen]; } - for (int i = 0; i < _PopupScreens.Count; i++) - _PopupScreens[i].Draw(); + foreach (IMenu popup in _PopupScreens) + popup.Draw(); _Cursor.Draw(); _DrawDebugInfos(); @@ -499,7 +510,7 @@ namespace Vocaluxe.Base bool resume = true; - bool eventsAvailable = false; + bool eventsAvailable; bool inputEventsAvailable = CInput.PollKeyEvent(ref inputKeyEvent); while ((eventsAvailable = keys.PollEvent(ref keyEvent)) || inputEventsAvailable) @@ -524,15 +535,15 @@ namespace Vocaluxe.Base if (popupPlayerControlAllowed && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) { if (keyEvent.Key == Keys.MediaNextTrack) - CMain.BackgroundMusic.Next(); + CBackgroundMusic.Next(); else if (keyEvent.Key == Keys.MediaPreviousTrack) - CMain.BackgroundMusic.Previous(); + CBackgroundMusic.Previous(); else if (keyEvent.Key == Keys.MediaPlayPause) { - if (CMain.BackgroundMusic.IsPlaying()) - CMain.BackgroundMusic.Pause(); + if (CBackgroundMusic.IsPlaying) + CBackgroundMusic.Pause(); else - CMain.BackgroundMusic.Play(); + CBackgroundMusic.Play(); } } @@ -582,7 +593,7 @@ namespace Vocaluxe.Base _VolumePopupTimer.Start(); } - CMain.BackgroundMusic.ApplyVolume(); + CBackgroundMusic.ApplyVolume(); } if (keyEvent.ModShift && (keyEvent.Key == Keys.F1)) @@ -727,125 +738,46 @@ namespace Vocaluxe.Base private static void _DrawDebugInfos() { - string txt = String.Empty; + if (CConfig.DebugLevel == EDebugLevel.TR_CONFIG_OFF) + return; + + List debugOutput = new List {CTime.GetFPS().ToString("FPS: 000")}; + + if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL1) + { + debugOutput.Add(CSound.GetStreamCount().ToString(CLanguage.Translate("TR_DEBUG_AUDIO_STREAMS") + ": 00")); + debugOutput.Add(CVideo.GetNumStreams().ToString(CLanguage.Translate("TR_DEBUG_VIDEO_STREAMS") + ": 00")); + debugOutput.Add(CDraw.TextureCount().ToString(CLanguage.Translate("TR_DEBUG_TEXTURES") + ": 00000")); + long memory = GC.GetTotalMemory(false); + debugOutput.Add((memory / 1000000L).ToString(CLanguage.Translate("TR_DEBUG_MEMORY") + ": 00000 MB")); + + if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL2) + { + debugOutput.Add(CSound.RecordGetToneAbs(0).ToString(CLanguage.Translate("TR_DEBUG_TONE_ABS") + " P1: 00")); + debugOutput.Add(CSound.RecordGetMaxVolume(0).ToString(CLanguage.Translate("TR_DEBUG_MAX_VOLUME") + " P1: 0.000")); + debugOutput.Add(CSound.RecordGetToneAbs(1).ToString(CLanguage.Translate("TR_DEBUG_TONE_ABS") + " P2: 00")); + debugOutput.Add(CSound.RecordGetMaxVolume(1).ToString(CLanguage.Translate("TR_DEBUG_MAX_VOLUME") + " P2: 0.000")); + + if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL3) + { + debugOutput.Add(CSongs.NumSongsWithCoverLoaded.ToString(CLanguage.Translate("TR_DEBUG_SONGS") + ": 00000")); + + if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL_MAX) + debugOutput.Add(_Cursor.X.ToString(CLanguage.Translate("TR_DEBUG_MOUSE") + " : (0000/") + _Cursor.Y.ToString("0000)")); + } + } + } CFonts.Style = EStyle.Normal; CFonts.SetFont("Normal"); + CFonts.Height = 30; SColorF gray = new SColorF(1f, 1f, 1f, 0.5f); - - float dy = 0; - if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_ONLY_FPS) + float y = 0; + foreach (string txt in debugOutput) { - txt = CTime.GetFPS().ToString("FPS: 000"); - CFonts.Height = 30f; - RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - + RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), y, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - } - - if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL1) - { - txt = CSound.GetStreamCount().ToString(CLanguage.Translate("TR_DEBUG_AUDIO_STREAMS") + ": 00"); - - RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - } - - if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL1) - { - txt = CVideo.GetNumStreams().ToString(CLanguage.Translate("TR_DEBUG_VIDEO_STREAMS") + ": 00"); - - RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - } - - if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL1) - { - txt = CDraw.TextureCount().ToString(CLanguage.Translate("TR_DEBUG_TEXTURES") + ": 00000"); - - RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - } - - if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL1) - { - long memory = GC.GetTotalMemory(false); - txt = (memory / 1000000L).ToString(CLanguage.Translate("TR_DEBUG_MEMORY") + ": 00000 MB"); - - RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - } - - if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL2) - { - txt = CSound.RecordGetToneAbs(0).ToString(CLanguage.Translate("TR_DEBUG_TONE_ABS") + " P1: 00"); - - RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - - - txt = CSound.RecordGetMaxVolume(0).ToString(CLanguage.Translate("TR_DEBUG_MAX_VOLUME") + " P1: 0.000"); - - rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - - txt = CSound.RecordGetToneAbs(1).ToString(CLanguage.Translate("TR_DEBUG_TONE_ABS") + " P2: 00"); - - rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - - - txt = CSound.RecordGetMaxVolume(1).ToString(CLanguage.Translate("TR_DEBUG_MAX_VOLUME") + " P2: 0.000"); - - rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - } - - if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL3) - { - txt = CSongs.NumSongsWithCoverLoaded.ToString(CLanguage.Translate("TR_DEBUG_SONGS") + ": 00000"); - - RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; - } - - if (CConfig.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL_MAX) - { - txt = _Cursor.X.ToString(CLanguage.Translate("TR_DEBUG_MOUSE") + " : (0000/") + _Cursor.Y.ToString("0000)"); - - RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), dy, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); - - CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); - dy += rect.Height; + y += rect.Height; } } @@ -853,10 +785,9 @@ namespace Vocaluxe.Base { _Cursor.UnloadTextures(); - if (CTheme.Cursor.Color.Length > 0) + if (CTheme.Cursor.Color != "") { - SColorF color; - color = CTheme.GetColor(CTheme.Cursor.Color, -1); + SColorF color = CTheme.GetColor(CTheme.Cursor.Color, -1); CTheme.Cursor.R = color.R; CTheme.Cursor.G = color.G; CTheme.Cursor.B = color.B; diff --git a/Vocaluxe/Base/CInput.cs b/Vocaluxe/Base/CInput.cs index 8ba98ba9..84632970 100644 --- a/Vocaluxe/Base/CInput.cs +++ b/Vocaluxe/Base/CInput.cs @@ -1,4 +1,23 @@ -using Vocaluxe.Lib.Input; +#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 Vocaluxe.Lib.Input; using Vocaluxe.Lib.Input.WiiMote; using VocaluxeLib.Menu; @@ -21,14 +40,14 @@ namespace Vocaluxe.Base _Input = null; } - public static bool Connect() + public static void Connect() { - return _Input.Connect(); + _Input.Connect(); } - public static bool Disconnect() + public static void Disconnect() { - return _Input.Disconnect(); + _Input.Disconnect(); } public static bool IsConnected() diff --git a/Vocaluxe/Base/CLanguage.cs b/Vocaluxe/Base/CLanguage.cs index a4d30909..c9024d67 100644 --- a/Vocaluxe/Base/CLanguage.cs +++ b/Vocaluxe/Base/CLanguage.cs @@ -1,4 +1,23 @@ -using System; +#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.IO; using System.Text; @@ -44,7 +63,7 @@ namespace Vocaluxe.Base return _Languages[lang].Name; } - public static string[] GetLanguageNames() + public static IEnumerable GetLanguageNames() { string[] languages = new string[_Languages.Count]; @@ -89,12 +108,7 @@ namespace Vocaluxe.Base return -1; } - public static string Translate(string keyWord) - { - return Translate(keyWord, -1); - } - - public static string Translate(string keyWord, int partyModeID) + public static string Translate(string keyWord, int partyModeID = -1) { if (keyWord == null) return "Error"; @@ -162,24 +176,23 @@ namespace Vocaluxe.Base return true; } - private static bool _LoadLanguageEntries(CXMLReader xmlReader, ref Dictionary texts) + private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary texts) { texts = new Dictionary(); - List names = xmlReader.GetAttributes("resources", "name"); - string value = string.Empty; + IEnumerable names = xmlReader.GetAttributes("resources", "name"); foreach (string name in names) { - if (xmlReader.GetValue("//resources/string[@name='" + name + "']", ref value, "")) + string value; + if (!xmlReader.GetValue("//resources/string[@name='" + name + "']", out value, "")) + continue; + try { - try - { - texts.Add(name, value); - } - catch (Exception e) - { - CLog.LogError("Error reading language file " + xmlReader.FileName + ": " + e.Message); - return false; - } + texts.Add(name, value); + } + catch (Exception e) + { + CLog.LogError("Error reading language file " + xmlReader.FileName + ": " + e.Message); + return false; } } return true; @@ -192,39 +205,34 @@ namespace Vocaluxe.Base return false; string value = string.Empty; - if (xmlReader.GetValue("//resources/string[@name='language']", ref value, value)) + if (xmlReader.GetValue("//resources/string[@name='language']", out value, value)) { int nr = GetLanguageNr(value); if (nr == -1) return true; - SPartyLanguage lang = new SPartyLanguage(); - lang.PartyModeID = partyModeID; - if (!_LoadLanguageEntries(xmlReader, ref lang.Texts)) + SPartyLanguage lang = new SPartyLanguage {PartyModeID = partyModeID}; + if (!_LoadLanguageEntries(xmlReader, out lang.Texts)) return false; _Languages[nr].PartyModeTexts.Add(lang); return true; } - else - { - CLog.LogError("Error reading Party Language File " + file); - return false; - } + CLog.LogError("Error reading Party Language File " + file); + return false; } private static void _LoadLanguageFile(string fileName) { - SLanguage lang = new SLanguage(); - lang.LanguageFilePath = Path.Combine(CSettings.FolderLanguages, fileName); + SLanguage lang = new SLanguage {LanguageFilePath = Path.Combine(CSettings.FolderLanguages, fileName)}; CXMLReader xmlReader = CXMLReader.OpenFile(lang.LanguageFilePath); if (xmlReader == null) return; string value = string.Empty; - if (xmlReader.GetValue("//resources/string[@name='language']", ref value, value)) + if (xmlReader.GetValue("//resources/string[@name='language']", out value, value)) { lang.Name = value; @@ -233,7 +241,7 @@ namespace Vocaluxe.Base lang.PartyModeTexts = new List(); - _LoadLanguageEntries(xmlReader, ref lang.Texts); + _LoadLanguageEntries(xmlReader, out lang.Texts); _Languages.Add(lang); } diff --git a/Vocaluxe/Base/CLog.cs b/Vocaluxe/Base/CLog.cs index c72f6a86..7e9bc0c8 100644 --- a/Vocaluxe/Base/CLog.cs +++ b/Vocaluxe/Base/CLog.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.IO; using System.Text; @@ -17,6 +36,15 @@ namespace Vocaluxe.Base _LogFileName = fileName; } + private void _Open() + { + _LogFile = new StreamWriter(Path.Combine(Environment.CurrentDirectory, _LogFileName), false, Encoding.UTF8); + + _LogFile.WriteLine(_LogName + " " + CSettings.GetFullVersionText() + " " + DateTime.Now); + _LogFile.WriteLine("----------------------------------------"); + _LogFile.WriteLine(); + } + public void Close() { if (_LogFile == null) @@ -34,21 +62,10 @@ namespace Vocaluxe.Base if (_LogFile == null) _Open(); - try - { - _LogFile.WriteLine(text); - _LogFile.Flush(); - } - catch (Exception) {} - } - - private void _Open() - { - _LogFile = new StreamWriter(Path.Combine(Environment.CurrentDirectory, _LogFileName), false, Encoding.UTF8); - - _LogFile.WriteLine(_LogName + " " + CSettings.GetFullVersionText() + " " + DateTime.Now); - _LogFile.WriteLine("----------------------------------------"); - _LogFile.WriteLine(); + // ReSharper disable PossibleNullReferenceException + _LogFile.WriteLine(text); + // ReSharper restore PossibleNullReferenceException + _LogFile.Flush(); } public void Dispose() @@ -139,7 +156,7 @@ namespace Vocaluxe.Base space += " "; float ms; - if (Stopwatch.IsHighResolution && _NanosecPerTick != 0.0) + if (Stopwatch.IsHighResolution && _NanosecPerTick > 0) ms = (float)((_NanosecPerTick * _BenchmarkTimer[benchmarkNr].ElapsedTicks) / (1000.0 * 1000.0)); else ms = _BenchmarkTimer[benchmarkNr].ElapsedMilliseconds; diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 1f0bc168..4e9b3521 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -1,4 +1,23 @@ -using System; +#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 VocaluxeLib.Menu; @@ -8,31 +27,30 @@ namespace Vocaluxe.Base { static class CMain { - public static IConfig Config = new CBconfig(); - public static ISettings Settings = new CBsettings(); - public static ITheme Theme = new CBtheme(); - public static IHelper Helper = new CBhelper(); - public static IBackgroundMusic BackgroundMusic = new CBbackgroundMusic(); - public static IDrawing Draw = new CBdraw(); - public static IGraphics Graphics = new CBGraphics(); - public static ILog Log = new CBlog(); - public static IFonts Fonts = new CBfonts(); - public static ILanguage Language = new CBlanguage(); - public static IGame Game = new CBGame(); - public static IProfiles Profiles = new CBprofiles(); - public static IRecording Record = new CBrecord(); - public static ISongs Songs = new CBsongs(); - public static IVideo Video = new CBvideo(); - public static ISound Sound = new CBsound(); - public static ICover Cover = new CBcover(); - public static IDataBase DataBase = new CBdataBase(); - public static IInputs Input = new CBinputs(); - public static IPlaylist Playlist = new CBplaylist(); + private static readonly IConfig _Config = new CBconfig(); + private static readonly ISettings _Settings = new CBsettings(); + private static readonly ITheme _Theme = new CBtheme(); + private static readonly IBackgroundMusic _BackgroundMusic = new CBbackgroundMusic(); + private static readonly IDrawing _Draw = new CBdraw(); + private static readonly IGraphics _Graphics = new CBGraphics(); + private static readonly ILog _Log = new CBlog(); + private static readonly IFonts _Fonts = new CBfonts(); + private static readonly ILanguage _Language = new CBlanguage(); + private static readonly IGame _Game = new CBGame(); + private static readonly IProfiles _Profiles = new CBprofiles(); + private static readonly IRecording _Record = new CBrecord(); + private static readonly ISongs _Songs = new CBsongs(); + private static readonly IVideo _Video = new CBvideo(); + private static readonly ISound _Sound = new CBsound(); + private static readonly ICover _Cover = new CBcover(); + private static readonly IDataBase _DataBase = new CBdataBase(); + private static readonly IInputs _Input = new CBinputs(); + private static readonly IPlaylist _Playlist = new CBplaylist(); public static void Init() { - CBase.Assign(Config, Settings, Theme, Helper, Log, BackgroundMusic, Draw, Graphics, Fonts, Language, - Game, Profiles, Record, Songs, Video, Sound, Cover, DataBase, Input, Playlist); + CBase.Assign(_Config, _Settings, _Theme, _Log, _BackgroundMusic, _Draw, _Graphics, _Fonts, _Language, + _Game, _Profiles, _Record, _Songs, _Video, _Sound, _Cover, _DataBase, _Input, _Playlist); } } @@ -40,14 +58,7 @@ namespace Vocaluxe.Base { public void SetBackgroundMusicVolume(int newVolume) { - if (newVolume < 0) - CConfig.BackgroundMusicVolume = 0; - else if (newVolume > 100) - CConfig.BackgroundMusicVolume = 100; - else - CConfig.BackgroundMusicVolume = newVolume; - - CConfig.SaveConfig(); + CConfig.BackgroundMusicVolume = newVolume; } public int GetBackgroundMusicVolume() @@ -95,7 +106,7 @@ namespace Vocaluxe.Base return CConfig.CoverSize; } - public List GetSongFolder() + public IEnumerable GetSongFolder() { return CConfig.SongFolder; } @@ -122,15 +133,7 @@ namespace Vocaluxe.Base public int GetMaxNumMics() { - int max = 0; - for (int i = 0; i < CSettings.MaxNumPlayer; i++) - { - if (CConfig.IsMicConfig(i + 1)) - max = i + 1; - else - break; - } - return max; + return CConfig.GetMaxNumMics(); } } @@ -275,8 +278,6 @@ namespace Vocaluxe.Base } } - class CBhelper : IHelper {} - class CBbackgroundMusic : IBackgroundMusic { public bool IsDisabled() @@ -286,7 +287,7 @@ namespace Vocaluxe.Base public bool IsPlaying() { - return CBackgroundMusic.Playing; + return CBackgroundMusic.IsPlaying; } public bool SongHasVideo() @@ -477,9 +478,9 @@ namespace Vocaluxe.Base CGame.NumPlayer = numPlayer; } - public SPlayer[] GetPlayer() + public SPlayer[] GetPlayers() { - return CGame.Player; + return CGame.Players; } public CPoints GetPoints() @@ -539,6 +540,16 @@ namespace Vocaluxe.Base { return CProfiles.Profiles; } + + public EGameDifficulty GetDifficulty(int profileID) + { + return CProfiles.GetDifficulty(profileID); + } + + public string GetPlayerName(int profileID, int playerNum = 0) + { + return CProfiles.GetPlayerName(profileID, playerNum); + } } class CBrecord : IRecording @@ -667,9 +678,9 @@ namespace Vocaluxe.Base return CVideo.VdSkip(videoStream, startPosition, videoGap); } - public bool GetFrame(int videoStream, ref STexture videoTexture, float time, ref float videoTime) + public bool GetFrame(int videoStream, ref STexture videoTexture, float time, out float videoTime) { - return CVideo.VdGetFrame(videoStream, ref videoTexture, time, ref videoTime); + return CVideo.VdGetFrame(videoStream, ref videoTexture, time, out videoTime); } public bool IsFinished(int videoStream) @@ -767,9 +778,9 @@ namespace Vocaluxe.Base CPlaylists.SetPlaylistName(playlistID, name); } - public string[] GetPlaylistNames() + public List GetPlaylistNames() { - return CPlaylists.GetPlaylistNames(); + return CPlaylists.PlaylistNames; } public string GetPlaylistName(int playlistID) diff --git a/Vocaluxe/Base/CObservable.cs b/Vocaluxe/Base/CObservable.cs index 5308ab84..239e15dc 100644 --- a/Vocaluxe/Base/CObservable.cs +++ b/Vocaluxe/Base/CObservable.cs @@ -1,4 +1,23 @@ -using System; +#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; namespace Vocaluxe.Base { @@ -7,7 +26,7 @@ namespace Vocaluxe.Base public event EventHandler ObjectChanged = delegate { }; protected bool _Changed = true; - protected void _NotifyObservers() + private void _NotifyObservers() { ObjectChanged.Invoke(this, null); } diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 8328f42c..1cbd1485 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -1,4 +1,23 @@ -using System; +#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.CodeDom.Compiler; using System.Collections.Generic; using System.IO; @@ -48,9 +67,7 @@ namespace Vocaluxe.Base _IDs.Enqueue(i); //add dummy normal game mode and set it as default - SPartyMode pm = new SPartyMode(); - pm.PartyMode = new CPartyModeNone(); - pm.ScreenFiles = new List(); + SPartyMode pm = new SPartyMode {PartyMode = new CPartyModeNone(), ScreenFiles = new List()}; pm.PartyMode.Initialize(); pm.PartyModeID = _IDs.Dequeue(); _NormalGameModeID = pm.PartyModeID; @@ -81,33 +98,33 @@ namespace Vocaluxe.Base { List infos = new List(); - int[] usedKeys = new int[_PartyModes.Count]; - _PartyModes.Keys.CopyTo(usedKeys, 0); + int[] pmIDs = new int[_PartyModes.Count]; + _PartyModes.Keys.CopyTo(pmIDs, 0); - for (int i = 0; i < usedKeys.Length; i++) + foreach (int pmID in pmIDs) { - if (usedKeys[i] != _NormalGameModeID) + if (pmID != _NormalGameModeID) { - SPartyMode mode = new SPartyMode(); - _PartyModes.TryGetValue(usedKeys[i], out mode); + SPartyMode mode; + _PartyModes.TryGetValue(pmID, out mode); if (mode.PartyMode != null) { - SPartyModeInfos info = new SPartyModeInfos(); - - info.Author = mode.Author; - info.Description = mode.Description; - info.Name = mode.Name; - info.PartyModeID = mode.PartyModeID; - info.Playable = mode.NoErrors; - info.VersionMajor = mode.PartyModeVersionMajor; - info.VersionMinor = mode.PartyModeVersionMinor; - - info.TargetAudience = mode.TargetAudience; - info.MaxPlayers = mode.PartyMode.GetMaxPlayer(); - info.MinPlayers = mode.PartyMode.GetMinPlayer(); - info.MaxTeams = mode.PartyMode.GetMaxTeams(); - info.MinTeams = mode.PartyMode.GetMinTeams(); + SPartyModeInfos info = new SPartyModeInfos + { + Author = mode.Author, + Description = mode.Description, + Name = mode.Name, + PartyModeID = mode.PartyModeID, + Playable = mode.NoErrors, + VersionMajor = mode.PartyModeVersionMajor, + VersionMinor = mode.PartyModeVersionMinor, + TargetAudience = mode.TargetAudience, + MaxPlayers = mode.PartyMode.GetMaxPlayer(), + MinPlayers = mode.PartyMode.GetMinPlayer(), + MaxTeams = mode.PartyMode.GetMaxTeams(), + MinTeams = mode.PartyMode.GetMinTeams() + }; infos.Add(info); } @@ -125,7 +142,7 @@ namespace Vocaluxe.Base public static void SetPartyMode(int partyModeID) { if (!_PartyModes.TryGetValue(partyModeID, out _CurrentPartyMode)) - CLog.LogError("CParty: Can't find party mode ID: " + partyModeID.ToString()); + CLog.LogError("CParty: Can't find party mode ID: " + partyModeID); _CurrentPartyMode.PartyMode.Init(); } @@ -213,10 +230,7 @@ namespace Vocaluxe.Base private static SPartyMode _LoadPartyMode(string file) { - SPartyMode pm = new SPartyMode(); - pm.PartyModeID = _IDs.Dequeue(); - pm.ScreenFiles = new List(); - pm.NoErrors = false; + SPartyMode pm = new SPartyMode {PartyModeID = _IDs.Dequeue(), ScreenFiles = new List(), NoErrors = false}; CXMLReader xmlReader = CXMLReader.OpenFile(file); @@ -227,15 +241,15 @@ namespace Vocaluxe.Base bool loaded = true; loaded &= xmlReader.TryGetIntValue("//root/PartyModeSystemVersion", ref pm.PartyModeSystemVersion); - loaded &= xmlReader.GetValue("//root/Info/Name", ref pm.Name, "ERROR Name"); - loaded &= xmlReader.GetValue("//root/Info/Description", ref pm.Description, "ERROR Description"); - loaded &= xmlReader.GetValue("//root/Info/Author", ref pm.Author, "ERROR Author"); - loaded &= xmlReader.GetValue("//root/Info/Folder", ref pm.Folder, "ERROR Folder"); - loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", ref pm.PartyModeFile, "ERROR PartyModeFile"); + loaded &= xmlReader.GetValue("//root/Info/Name", out pm.Name, "ERROR Name"); + loaded &= xmlReader.GetValue("//root/Info/Description", out pm.Description, "ERROR Description"); + loaded &= xmlReader.GetValue("//root/Info/Author", out pm.Author, "ERROR Author"); + loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder, "ERROR Folder"); + loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile, "ERROR PartyModeFile"); loaded &= xmlReader.GetInnerValues("PartyScreens", ref pm.ScreenFiles); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMajor", ref pm.PartyModeVersionMajor); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMinor", ref pm.PartyModeVersionMinor); - loaded &= xmlReader.GetValue("//root/Info/TargetAudience", ref pm.TargetAudience, "ERROR TargetAudience"); + loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience"); if (!loaded) { @@ -324,14 +338,12 @@ namespace Vocaluxe.Base private static Assembly _CompileFiles(string[] files) { - if (files == null) - return null; - - if (files.Length == 0) + if (files == null || files.Length == 0) return null; CompilerParameters compilerParams = new CompilerParameters(); compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll"); + compilerParams.ReferencedAssemblies.Add("System.Core.dll"); compilerParams.ReferencedAssemblies.Add("VocaluxeLib.dll"); compilerParams.GenerateInMemory = true; #if DEBUG @@ -340,7 +352,7 @@ namespace Vocaluxe.Base using (CodeDomProvider cdp = CodeDomProvider.CreateProvider("CSharp")) { - CompilerResults compileResult = null; + CompilerResults compileResult; try { @@ -374,7 +386,7 @@ namespace Vocaluxe.Base return null; } - CMenuParty screen = null; + CMenuParty screen; try { screen = (CMenuParty)instance; diff --git a/Vocaluxe/Base/CPlaylists.cs b/Vocaluxe/Base/CPlaylists.cs index 03532e71..a740bc97 100644 --- a/Vocaluxe/Base/CPlaylists.cs +++ b/Vocaluxe/Base/CPlaylists.cs @@ -1,4 +1,23 @@ -using System; +#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.IO; using System.Text; @@ -17,14 +36,14 @@ namespace Vocaluxe.Base get { return _Playlists.ToArray(); } } - public static string[] PlaylistNames + public static List PlaylistNames { get { List names = new List(); for (int i = 0; i < _Playlists.Count; i++) names.Add(_Playlists[i].PlaylistName); - return names.ToArray(); + return names; } } @@ -75,16 +94,6 @@ namespace Vocaluxe.Base return _Playlists[playlistID].PlaylistName; } - public static string[] GetPlaylistNames() - { - List result = new List(); - - foreach (CPlaylistFile playlist in _Playlists) - result.Add(playlist.PlaylistName); - - return result.ToArray(); - } - public static void SetPlaylistName(int playlistID, string name) { if (playlistID >= _Playlists.Count || playlistID < 0) @@ -97,7 +106,7 @@ namespace Vocaluxe.Base { if (playlistID < 0 || playlistID >= _Playlists.Count) return; - if (_Playlists[playlistID].PlaylistFile.Length > 0) + if (_Playlists[playlistID].PlaylistFile != "") { try { @@ -120,8 +129,7 @@ namespace Vocaluxe.Base public static int NewPlaylist() { - CPlaylistFile pl = new CPlaylistFile(); - pl.PlaylistName = "New Playlist"; + CPlaylistFile pl = new CPlaylistFile {PlaylistName = "New Playlist"}; _Playlists.Add(pl); return _Playlists.Count - 1; } @@ -209,7 +217,7 @@ namespace Vocaluxe.Base private static int _CompareByPlaylistName(CPlaylistFile a, CPlaylistFile b) { - return String.Compare(a.PlaylistName, b.PlaylistName); + return String.CompareOrdinal(a.PlaylistName, b.PlaylistName); } private static CPlaylistFile _ConvertUSDXPlaylist(string file) @@ -219,44 +227,42 @@ namespace Vocaluxe.Base if (!File.Exists(file)) return null; - StreamReader sr; try { + StreamReader sr; using (sr = new StreamReader(file, Encoding.Default, true)) { - int pos = -1; string line; while ((line = sr.ReadLine()) != null) { - pos = line.IndexOf(":"); - if (pos > 0) + int pos = line.IndexOf(":", StringComparison.Ordinal); + if (pos <= 0) + continue; + //Name or comment + if (line[0] == '#') { - //Name or comment - if (line[0] == '#') + string identifier = line.Substring(1, pos - 1).Trim(); + string value = line.Substring(pos + 1, line.Length - pos - 1).Trim(); + if (identifier.ToUpper() == "NAME") + pl.PlaylistName = value; + } + //Song + else + { + string artist = line.Substring(0, pos - 1).Trim(); + string title = line.Substring(pos + 1, line.Length - pos - 1).Trim(); + bool found = false; + foreach (CSong song in allSongs) { - string identifier = line.Substring(1, pos - 1).Trim(); - string value = line.Substring(pos + 1, line.Length - pos - 1).Trim(); - if (identifier.ToUpper() == "NAME") - pl.PlaylistName = value; - } - //Song - else - { - string artist = line.Substring(0, pos - 1).Trim(); - string title = line.Substring(pos + 1, line.Length - pos - 1).Trim(); - bool found = false; - for (int s = 0; s < allSongs.Length; s++) + if (song.Artist == artist && song.Title == title) { - if (allSongs[s].Artist == artist && allSongs[s].Title == title) - { - pl.AddSong(allSongs[s].ID); - found = true; - break; - } + pl.AddSong(song.ID); + found = true; + break; } - if (!found) - CLog.LogError("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + file); } + if (!found) + CLog.LogError("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + file); } } } diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index 176807e1..2944b0e7 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -1,4 +1,23 @@ -using System; +#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.IO; using System.Text; @@ -43,25 +62,27 @@ namespace Vocaluxe.Base LoadProfiles(); } - public static int NewProfile() + public static string GetPlayerName(int profileID, int playerNum = 0) { - return NewProfile(String.Empty); + if (IsProfileIDValid(profileID)) + return _Profiles[profileID].PlayerName; + string playerName = CLanguage.Translate("TR_SCREENNAMES_PLAYER"); + if (playerNum > 0) + playerName += " " + playerNum; + return playerName; } - public static int NewProfile(string fileName) + public static int NewProfile(string fileName = "") { - SProfile profile = new SProfile(); - - profile.PlayerName = String.Empty; - profile.Difficulty = EGameDifficulty.TR_CONFIG_EASY; - profile.Avatar = new SAvatar(-1); - profile.GuestProfile = EOffOn.TR_CONFIG_OFF; - profile.Active = EOffOn.TR_CONFIG_ON; - - if (fileName.Length > 0) - profile.ProfileFile = Path.Combine(CSettings.FolderProfiles, fileName); - else - profile.ProfileFile = String.Empty; + SProfile profile = new SProfile + { + PlayerName = String.Empty, + Difficulty = EGameDifficulty.TR_CONFIG_EASY, + Avatar = new SAvatar(-1), + GuestProfile = EOffOn.TR_CONFIG_OFF, + Active = EOffOn.TR_CONFIG_ON, + ProfileFile = fileName != "" ? Path.Combine(CSettings.FolderProfiles, fileName) : String.Empty + }; if (File.Exists(profile.ProfileFile)) return -1; @@ -110,133 +131,119 @@ namespace Vocaluxe.Base if (tex.Index != -1) { - SAvatar avatar = new SAvatar(); - avatar.Texture = tex; - avatar.FileName = Path.GetFileName(file); + SAvatar avatar = new SAvatar {Texture = tex, FileName = Path.GetFileName(file)}; _Avatars.Add(avatar); } } } - public static string AddGetPlayerName(int profileNr, char chr) + public static string AddGetPlayerName(int profileID, char chr) { - if (profileNr < 0 || profileNr >= _Profiles.Count) + if (!IsProfileIDValid(profileID)) return String.Empty; - SProfile profile = _Profiles[profileNr]; + SProfile profile = _Profiles[profileID]; profile.PlayerName += chr; - _Profiles[profileNr] = profile; + _Profiles[profileID] = profile; return profile.PlayerName; } - public static string GetPlayerName(int profileNr) + public static string GetDeleteCharInPlayerName(int profileID) { - if (profileNr < 0 || profileNr >= _Profiles.Count) + if (!IsProfileIDValid(profileID)) return String.Empty; - return _Profiles[profileNr].PlayerName; - } - - public static string GetDeleteCharInPlayerName(int profileNr) - { - if (profileNr < 0 || profileNr >= _Profiles.Count) - return String.Empty; - - SProfile profile = _Profiles[profileNr]; - if (profile.PlayerName.Length > 0) + SProfile profile = _Profiles[profileID]; + if (profile.PlayerName != "") profile.PlayerName = profile.PlayerName.Remove(profile.PlayerName.Length - 1); - _Profiles[profileNr] = profile; + _Profiles[profileID] = profile; return profile.PlayerName; } - public static EGameDifficulty GetDifficulty(int profileNr) + public static bool IsProfileIDValid(int profileID) { - if (profileNr < 0 || profileNr >= _Profiles.Count) - return EGameDifficulty.TR_CONFIG_NORMAL; - - return _Profiles[profileNr].Difficulty; + return profileID >= 0 && profileID < _Profiles.Count; } - public static void SetDifficulty(int profileNr, EGameDifficulty difficulty) + public static EGameDifficulty GetDifficulty(int profileID) { - if (profileNr < 0 || profileNr >= _Profiles.Count) + return IsProfileIDValid(profileID) ? _Profiles[profileID].Difficulty : EGameDifficulty.TR_CONFIG_NORMAL; + } + + public static void SetDifficulty(int profileID, EGameDifficulty difficulty) + { + if (!IsProfileIDValid(profileID)) return; - SProfile profile = _Profiles[profileNr]; + SProfile profile = _Profiles[profileID]; profile.Difficulty = difficulty; - _Profiles[profileNr] = profile; + _Profiles[profileID] = profile; } - public static EOffOn GetGuestProfile(int profileNr) + public static EOffOn GetGuestProfile(int profileID) { - if (profileNr < 0 || profileNr >= _Profiles.Count) - return EOffOn.TR_CONFIG_OFF; - - return _Profiles[profileNr].GuestProfile; + return IsProfileIDValid(profileID) ? _Profiles[profileID].GuestProfile : EOffOn.TR_CONFIG_OFF; } - public static EOffOn GetActive(int profileNr) + public static EOffOn GetActive(int profileID) { - if (profileNr < 0 || profileNr >= _Profiles.Count) - return EOffOn.TR_CONFIG_OFF; - - return _Profiles[profileNr].Active; + return IsProfileIDValid(profileID) ? _Profiles[profileID].Active : EOffOn.TR_CONFIG_OFF; } - public static void SetGuestProfile(int profileNr, EOffOn option) + public static void SetGuestProfile(int profileID, EOffOn option) { - if (profileNr < 0 || profileNr >= _Profiles.Count) + if (!IsProfileIDValid(profileID)) return; - SProfile profile = _Profiles[profileNr]; + SProfile profile = _Profiles[profileID]; profile.GuestProfile = option; - _Profiles[profileNr] = profile; + _Profiles[profileID] = profile; } - public static void SetActive(int profileNr, EOffOn option) + public static void SetActive(int profileID, EOffOn option) { - if (profileNr < 0 || profileNr >= _Profiles.Count) + if (!IsProfileIDValid(profileID)) return; - SProfile profile = _Profiles[profileNr]; + SProfile profile = _Profiles[profileID]; profile.Active = option; - _Profiles[profileNr] = profile; + _Profiles[profileID] = profile; } - public static bool IsGuestProfile(int profileNr) + public static bool IsGuestProfile(int profileID) { - if (profileNr < 0 || profileNr >= _Profiles.Count) + if (!IsProfileIDValid(profileID)) return true; // this will prevent from saving dummy profiles to highscore db - return _Profiles[profileNr].GuestProfile == EOffOn.TR_CONFIG_ON; + return _Profiles[profileID].GuestProfile == EOffOn.TR_CONFIG_ON; } - public static bool IsActive(int profileNr) + public static bool IsActive(int profileID) { - if (profileNr < 0 || profileNr >= _Profiles.Count) + if (!IsProfileIDValid(profileID)) return false; - return _Profiles[profileNr].Active == EOffOn.TR_CONFIG_ON; + return _Profiles[profileID].Active == EOffOn.TR_CONFIG_ON; } - public static void SetAvatar(int profileNr, int avatarNr) + public static void SetAvatar(int profileID, int avatarNr) { - if (profileNr < 0 || profileNr >= _Profiles.Count || avatarNr < 0 || avatarNr >= _Avatars.Count) + if (!IsProfileIDValid(profileID) || avatarNr < 0 || avatarNr >= _Avatars.Count) return; - SProfile profile = _Profiles[profileNr]; + SProfile profile = _Profiles[profileID]; profile.Avatar = _Avatars[avatarNr]; - _Profiles[profileNr] = profile; + _Profiles[profileID] = profile; } - public static int GetAvatarNr(int profileNr) + public static int GetAvatarNr(int profileID) { - if (profileNr < 0 || profileNr >= _Profiles.Count) + if (!IsProfileIDValid(profileID)) return 0; for (int i = 0; i < _Avatars.Count; i++) { - if (_Profiles[profileNr].Avatar.FileName == _Avatars[i].FileName) + if (_Profiles[profileID].Avatar.FileName == _Avatars[i].FileName) return i; } @@ -245,20 +252,36 @@ namespace Vocaluxe.Base public static void DeleteProfile(int profileID) { - if (profileID < 0 || profileID >= _Profiles.Count) + if (!IsProfileIDValid(profileID)) return; - if (_Profiles[profileID].ProfileFile.Length > 0) + if (_Profiles[profileID].ProfileFile == "") + return; + try { - try + //Check if profile saved in config + for (int i = 0; i < CConfig.Players.Length; i++) { - File.Delete(_Profiles[profileID].ProfileFile); - _Profiles.RemoveAt(profileID); + if (CConfig.Players[i] == _Profiles[profileID].ProfileFile) + { + CConfig.Players[i] = string.Empty; + CConfig.SaveConfig(); + } } - catch (Exception) + File.Delete(_Profiles[profileID].ProfileFile); + _Profiles.RemoveAt(profileID); + //Check if profile is selected in game + for (int i = 0; i < CGame.Players.Length; i++) { - CLog.LogError("Can't delete Profile File " + _Profiles[profileID].ProfileFile + ".xml"); + if (CGame.Players[i].ProfileID > profileID) + CGame.Players[i].ProfileID--; + else if (CGame.Players[i].ProfileID == profileID) + CGame.Players[i].ProfileID = -1; } } + catch (Exception) + { + CLog.LogError("Can't delete Profile File " + _Profiles[profileID].ProfileFile + ".xml"); + } } private static void _SortProfilesByName() @@ -268,7 +291,7 @@ namespace Vocaluxe.Base private static int _CompareByPlayerName(SProfile a, SProfile b) { - return String.Compare(a.PlayerName, b.PlayerName); + return String.CompareOrdinal(a.PlayerName, b.PlayerName); } #region private methods @@ -284,10 +307,10 @@ namespace Vocaluxe.Base private static void _SaveProfile(int profileID) { - if (profileID < 0 || profileID >= _Profiles.Count) + if (!IsProfileIDValid(profileID)) return; - if (_Profiles[profileID].ProfileFile.Length == 0) + if (_Profiles[profileID].ProfileFile == "") { string filename = string.Empty; foreach (char chr in _Profiles[profileID].PlayerName) @@ -296,7 +319,7 @@ namespace Vocaluxe.Base filename += chr.ToString(); } - if (filename.Length == 0) + if (filename == "") filename = "1"; int i = 0; @@ -343,21 +366,19 @@ namespace Vocaluxe.Base finally { writer.Close(); - writer = null; } } private static void _LoadProfile(string fileName) { - SProfile profile = new SProfile(); - profile.ProfileFile = Path.Combine(CSettings.FolderProfiles, fileName); + SProfile profile = new SProfile {ProfileFile = Path.Combine(CSettings.FolderProfiles, fileName)}; CXMLReader xmlReader = CXMLReader.OpenFile(profile.ProfileFile); if (xmlReader == null) return; string value = String.Empty; - if (xmlReader.GetValue("//root/Info/PlayerName", ref value, value)) + if (xmlReader.GetValue("//root/Info/PlayerName", out value, value)) { profile.PlayerName = value; @@ -365,7 +386,7 @@ namespace Vocaluxe.Base xmlReader.TryGetEnumValue("//root/Info/Difficulty", ref profile.Difficulty); profile.Avatar = new SAvatar(-1); - if (xmlReader.GetValue("//root/Info/Avatar", ref value, value)) + if (xmlReader.GetValue("//root/Info/Avatar", out value, value)) profile.Avatar = _GetAvatar(value); profile.GuestProfile = EOffOn.TR_CONFIG_OFF; diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index ff6e92fe..5fa38628 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -1,59 +1,77 @@ -using System; +#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.IO; +using System.Reflection; using VocaluxeLib.Menu; namespace Vocaluxe.Base { enum ERevision { + // ReSharper disable UnusedMember.Global Alpha, Beta, RC, Release + // ReSharper restore UnusedMember.Global } static class CSettings { #if ARCH_X86 - public const String Arch = "x86"; + private const String _Arch = "x86"; #endif #if ARCH_X64 - public const String Arch = "x64"; + private const String _Arch = "x64"; #endif public static EGameState GameState = EGameState.Start; - public const string ProgramName = "Vocaluxe"; - public const string ProgramCodeName = "Shining Heaven"; + //Adjusting of programName and version now in the assembly config. + //I'd use the major and minor for Main releases, build number for every public release and revision for every bugfix version without any features + //As it is different than before, this is open for discussion. + //TODO: Remove this when this is decided + private const string _ProgramCodeName = "Shining Heaven"; - public const int VersionMajor = 0; - public const int VersionMinor = 3; // milestones - public const int VersionSub = 0; // patches public const ERevision VersionRevision = ERevision.Alpha; - public const int Build = 78; // Increase on every published version! Never Reset! - public const int DatabaseHighscoreVersion = 2; public const int DatabaseCoverVersion = 1; public const int DatabaseCreditsRessourcesVersion = 1; - public static int RenderW = 1280; - public static int RenderH = 720; + public const int RenderW = 1280; + public const int RenderH = 720; public const int ZNear = -100; public const int ZFar = 100; - public static bool IsFullScreen = false; - public static int VertexBufferElements = 10000; + public static bool IsFullScreen; + public const int VertexBufferElements = 10000; public const string Icon = "Vocaluxe.ico"; public const string Logo = "Logo.png"; public const string FallbackLanguage = "English"; - public const string BassRegistration = "Registration.xml"; public static string FileConfig = "Config.xml"; - public const string FileCover = "Cover.xml"; public const string FileFonts = "Fonts.xml"; public const string FileOldHighscoreDB = "Ultrastar.db"; @@ -70,7 +88,6 @@ namespace Vocaluxe.Base public const string FolderGraphics = "Graphics"; public const string FolderFonts = "Fonts"; public const string FolderThemes = "Themes"; - public const string FolderSkins = "Skins"; public const string FolderThemeFonts = "Fonts"; public const string FolderScreens = "Screens"; public static string FolderProfiles = "Profiles"; @@ -109,11 +126,11 @@ namespace Vocaluxe.Base public const int MedleyMinSeriesLength = 3; public const float MedleyMinDuration = 40f; - public static bool TabNavigation = false; + public const bool TabNavigation = false; public const float BackgroundMusicFadeTime = 0.5f; - public static List MusicFileTypes = new List + public static readonly List MusicFileTypes = new List { "*.mp3", "*.wma", @@ -121,14 +138,32 @@ namespace Vocaluxe.Base "*.wav" }; - public static string GetVersionText() + private static AssemblyName _Assembly { - string version = "v" + VersionMajor.ToString() + "." + - VersionMinor.ToString() + "." + - VersionSub.ToString() + " (" + Arch + ")"; + get { return Assembly.GetExecutingAssembly().GetName(); } + } + public static string ProgramName + { + get { return _Assembly.Name; } + } + private static string _Version + { + get + { + Version v = _Assembly.Version; + return "v" + v.Major + "." + v.Minor + "." + v.Build; + } + } + + private static string _GetVersionText() + { + string version = _Version + " (" + _Arch + ")"; + + // ReSharper disable ConditionIsAlwaysTrueOrFalse if (VersionRevision != ERevision.Release) - version += " " + GetVersionStatus() + String.Format(" ({0:0000)}", Build); + // ReSharper restore ConditionIsAlwaysTrueOrFalse + version += " " + _GetVersionStatus() + String.Format(" ({0:0000)}", _Assembly.Version.Revision); return version; } @@ -137,17 +172,21 @@ namespace Vocaluxe.Base { string version = ProgramName; - if (ProgramCodeName.Length > 0) - version += " \"" + ProgramCodeName + "\""; + // ReSharper disable ConditionIsAlwaysTrueOrFalse + if (_ProgramCodeName != "") + // ReSharper restore ConditionIsAlwaysTrueOrFalse + version += " \"" + _ProgramCodeName + "\""; - return version + " " + GetVersionText(); + return version + " " + _GetVersionText(); } - public static string GetVersionStatus() + private static string _GetVersionStatus() { - string result = String.Empty; + string result; + // ReSharper disable ConditionIsAlwaysTrueOrFalse if (VersionRevision != ERevision.Release) + // ReSharper restore ConditionIsAlwaysTrueOrFalse result = Enum.GetName(typeof(ERevision), VersionRevision); return result; @@ -170,16 +209,7 @@ namespace Vocaluxe.Base public static void CreateFolders() { - List folders = new List(); - - folders.Add(FolderCover); - folders.Add(FolderFonts); - folders.Add(FolderProfiles); - folders.Add(FolderSongs); - folders.Add(FolderScreenshots); - folders.Add(FolderBackgroundMusic); - folders.Add(FolderSounds); - folders.Add(FolderPlaylists); + List folders = new List {FolderCover, FolderFonts, FolderProfiles, FolderSongs, FolderScreenshots, FolderBackgroundMusic, FolderSounds, FolderPlaylists}; foreach (string folder in folders) { diff --git a/Vocaluxe/Base/CSongCategorizer.cs b/Vocaluxe/Base/CSongCategorizer.cs index c51ab696..a9aedb6b 100644 --- a/Vocaluxe/Base/CSongCategorizer.cs +++ b/Vocaluxe/Base/CSongCategorizer.cs @@ -1,4 +1,23 @@ -using System; +#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.Text; using VocaluxeLib.Menu; @@ -79,7 +98,7 @@ namespace Vocaluxe.Base int noCategoryIndex = -1; for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++) { - if (CSongs.Sorter.SortedSongs[i].SortString.Length > 0) + if (CSongs.Sorter.SortedSongs[i].SortString != "") { if (CSongs.Sorter.SortedSongs[i].SortString != category) { @@ -135,7 +154,7 @@ namespace Vocaluxe.Base for (int i = 0; i < CSongs.Sorter.SortedSongs.Length; i++) { string year = CSongs.Sorter.SortedSongs[i].SortString; - if (year.Length > 0) + if (year != "") { year = year.Substring(0, 3); CSongs.Sorter.SortedSongs[i].SortString = year + "0 - " + year + "9"; diff --git a/Vocaluxe/Base/CSongFilter.cs b/Vocaluxe/Base/CSongFilter.cs index 6c9ec90e..03744ab0 100644 --- a/Vocaluxe/Base/CSongFilter.cs +++ b/Vocaluxe/Base/CSongFilter.cs @@ -1,5 +1,25 @@ -using System; +#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.Linq; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -65,7 +85,7 @@ namespace Vocaluxe.Base _FilteredSongs.Clear(); string[] searchStrings = null; - if (_SearchString.Length > 0) + if (_SearchString != "") searchStrings = _SearchString.ToUpper().Split(new char[] {' '}); foreach (CSong song in CSongs.Songs) @@ -78,11 +98,7 @@ namespace Vocaluxe.Base { string search = song.Title.ToUpper() + " " + song.Artist.ToUpper() + " " + song.FolderName.ToUpper() + " " + song.FileName.ToUpper(); - bool contains = true; - - foreach (string str in searchStrings) - contains &= search.Contains(str); - if (contains) + if (searchStrings.All(search.Contains)) _FilteredSongs.Add(song); } } diff --git a/Vocaluxe/Base/CSongSorter.cs b/Vocaluxe/Base/CSongSorter.cs index ec5a486b..6d10957b 100644 --- a/Vocaluxe/Base/CSongSorter.cs +++ b/Vocaluxe/Base/CSongSorter.cs @@ -1,4 +1,23 @@ -using System; +#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.Reflection; using VocaluxeLib.Menu; @@ -31,11 +50,10 @@ namespace Vocaluxe.Base get { return _IgnoreArticles; } set { - if (value != _IgnoreArticles) - { - _IgnoreArticles = value; - _SetChanged(); - } + if (value == _IgnoreArticles) + return; + _IgnoreArticles = value; + _SetChanged(); } } @@ -44,11 +62,10 @@ namespace Vocaluxe.Base get { return _SongSorting; } set { - if (value != _SongSorting) - { - _SongSorting = value; - _SetChanged(); - } + if (value == _SongSorting) + return; + _SongSorting = value; + _SetChanged(); } } @@ -69,51 +86,46 @@ namespace Vocaluxe.Base private int _SortByFieldArtistTitle(SSongPointer s1, SSongPointer s2) { - int res = s1.SortString.ToUpper().CompareTo(s2.SortString.ToUpper()); + int res = String.Compare(s1.SortString, s2.SortString, StringComparison.OrdinalIgnoreCase); if (res == 0) { if (_IgnoreArticles == EOffOn.TR_CONFIG_ON) { - res = CSongs.Songs[s1.SongID].ArtistSorting.ToUpper().CompareTo(CSongs.Songs[s2.SongID].ArtistSorting.ToUpper()); - if (res == 0) - return CSongs.Songs[s1.SongID].TitleSorting.ToUpper().CompareTo(CSongs.Songs[s2.SongID].TitleSorting.ToUpper()); - return res; - } - else - { - res = CSongs.Songs[s1.SongID].Artist.ToUpper().CompareTo(CSongs.Songs[s2.SongID].Artist.ToUpper()); - if (res == 0) - return CSongs.Songs[s1.SongID].Title.ToUpper().CompareTo(CSongs.Songs[s2.SongID].Title.ToUpper()); - return res; + res = String.Compare(CSongs.Songs[s1.SongID].ArtistSorting, CSongs.Songs[s2.SongID].ArtistSorting, StringComparison.OrdinalIgnoreCase); + return res != 0 ? res : String.Compare(CSongs.Songs[s1.SongID].TitleSorting, CSongs.Songs[s2.SongID].TitleSorting, StringComparison.OrdinalIgnoreCase); } + res = String.Compare(CSongs.Songs[s1.SongID].Artist, CSongs.Songs[s2.SongID].Artist, StringComparison.OrdinalIgnoreCase); + return res != 0 ? res : String.Compare(CSongs.Songs[s1.SongID].Title, CSongs.Songs[s2.SongID].Title, StringComparison.OrdinalIgnoreCase); } return res; } private int _SortByFieldTitle(SSongPointer s1, SSongPointer s2) { - int res = s1.SortString.ToUpper().CompareTo(s2.SortString.ToUpper()); + int res = String.Compare(s1.SortString, s2.SortString, StringComparison.OrdinalIgnoreCase); if (res == 0) { - if (_IgnoreArticles == EOffOn.TR_CONFIG_ON) - return CSongs.Songs[s1.SongID].TitleSorting.ToUpper().CompareTo(CSongs.Songs[s2.SongID].TitleSorting.ToUpper()); - else - return CSongs.Songs[s1.SongID].Title.ToUpper().CompareTo(CSongs.Songs[s2.SongID].Title.ToUpper()); + return _IgnoreArticles == EOffOn.TR_CONFIG_ON + ? String.Compare(CSongs.Songs[s1.SongID].TitleSorting, CSongs.Songs[s2.SongID].TitleSorting, StringComparison.OrdinalIgnoreCase) : + String.Compare(CSongs.Songs[s1.SongID].Title, CSongs.Songs[s2.SongID].Title, StringComparison.OrdinalIgnoreCase); } return res; } private List _CreateSortList(string fieldName) { - FieldInfo field = null; - bool isString = false; List sortList = new List(); - if (fieldName.Length == 0) - CSongs.Filter.FilteredSongs.ForEach((song) => sortList.Add(new SSongPointer(song.ID, ""))); + if (fieldName == "") + CSongs.Filter.FilteredSongs.ForEach(song => sortList.Add(new SSongPointer(song.ID, ""))); else { - field = typeof(CSong).GetField(fieldName, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); - isString = field.FieldType == typeof(string); + FieldInfo field = typeof(CSong).GetField(fieldName, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); + if (field == null) + { + CLog.LogError("Unknow sorting field: " + fieldName); + return _CreateSortList(""); + } + bool isString = field.FieldType == typeof(string); if (!isString && field.FieldType != typeof(List)) throw new Exception("Unkown sort field type"); foreach (CSong song in CSongs.Filter.FilteredSongs) @@ -128,7 +140,7 @@ namespace Vocaluxe.Base sortList.Add(new SSongPointer(song.ID, "")); else { - foreach (String sortString in (List)value) + foreach (String sortString in values) sortList.Add(new SSongPointer(song.ID, sortString)); } } @@ -155,16 +167,10 @@ namespace Vocaluxe.Base break; case ESongSorting.TR_CONFIG_ARTIST_LETTER: case ESongSorting.TR_CONFIG_ARTIST: - if (_IgnoreArticles == EOffOn.TR_CONFIG_ON) - fieldName = "ArtistSorting"; - else - fieldName = "Artist"; + fieldName = _IgnoreArticles == EOffOn.TR_CONFIG_ON ? "ArtistSorting" : "Artist"; break; case ESongSorting.TR_CONFIG_TITLE_LETTER: - if (_IgnoreArticles == EOffOn.TR_CONFIG_ON) - fieldName = "TitleSorting"; - else - fieldName = "Title"; + fieldName = _IgnoreArticles == EOffOn.TR_CONFIG_ON ? "TitleSorting" : "Title"; break; case ESongSorting.TR_CONFIG_YEAR: case ESongSorting.TR_CONFIG_DECADE: diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 8aa56dd6..b2780e53 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -1,8 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Threading; +#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.Linq; +using System.Threading; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -10,16 +28,16 @@ namespace Vocaluxe.Base { public struct SSongPointer { - public int SongID; + public readonly int SongID; public string SortString; public int CatIndex; public bool Visible; public bool PartyHidden; - public SSongPointer(int iD, string sortString) + public SSongPointer(int id, string sortString) { - SongID = iD; + SongID = id; SortString = sortString; CatIndex = -1; Visible = false; @@ -38,13 +56,11 @@ namespace Vocaluxe.Base private static int _CatIndex = -1; private static readonly List _CategoriesForRandom = new List(); - private static readonly Stopwatch _CoverLoadTimer = new Stopwatch(); + public static readonly CSongFilter Filter = new CSongFilter(); + public static readonly CSongSorter Sorter = new CSongSorter(); + public static readonly CSongCategorizer Categorizer = new CSongCategorizer(); - public static CSongFilter Filter = new CSongFilter(); - public static CSongSorter Sorter = new CSongSorter(); - public static CSongCategorizer Categorizer = new CSongCategorizer(); - - private static Thread _CoverLoaderThread = null; + private static Thread _CoverLoaderThread; public static List Songs { @@ -73,16 +89,7 @@ namespace Vocaluxe.Base public static int NumVisibleSongs { - get - { - int result = 0; - foreach (SSongPointer sp in Sorter.SortedSongs) - { - if (sp.Visible) - result++; - } - return result; - } + get { return Sorter.SortedSongs.Count(sp => sp.Visible); } } public static int NumCategories @@ -187,18 +194,12 @@ namespace Vocaluxe.Base { if ((Categorizer.Categories.Count > 0) && (_CatIndex >= 0) && (Categorizer.Categories.Count > _CatIndex)) return Categorizer.Categories[_CatIndex].Name; - else - return String.Empty; + return String.Empty; } 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) @@ -394,7 +395,7 @@ namespace Vocaluxe.Base if (song != null) { song.ID = _Songs.Count; - if(song.ReadNotes()) + if (song.ReadNotes()) _Songs.Add(song); } } @@ -427,14 +428,10 @@ namespace Vocaluxe.Base if (!SongsLoaded || CoverLoaded) return; - if (_CoverLoaderThread == null) - { - _CoverLoaderThread = new Thread(new ThreadStart(_LoadCover)); - _CoverLoaderThread.Name = "CoverLoader"; - _CoverLoaderThread.Priority = ThreadPriority.BelowNormal; - _CoverLoaderThread.IsBackground = true; - _CoverLoaderThread.Start(); - } + if (_CoverLoaderThread != null) + return; + _CoverLoaderThread = new Thread(_LoadCover) {Name = "CoverLoader", Priority = ThreadPriority.BelowNormal, IsBackground = true}; + _CoverLoaderThread.Start(); /* if (_CoverLoadTimer.ElapsedMilliseconds >= WaitTime) diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 2f5bf1cb..70b0e598 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.IO; using Vocaluxe.Lib.Sound; @@ -16,7 +35,7 @@ namespace Vocaluxe.Base #region Playback private static IPlayback _Playback; - public static bool PlaybackInit() + public static bool Init() { switch (CConfig.PlayBackLib) { @@ -36,7 +55,7 @@ namespace Vocaluxe.Base _Playback = new CPortAudioPlay(); break; } - return true; + return _Playback.Init(); } public static void SetGlobalVolume(float volume) @@ -164,7 +183,7 @@ namespace Vocaluxe.Base break; } - if (file.Length == 0) + if (file == "") return -1; int stream = Load(file); @@ -467,16 +486,19 @@ namespace Vocaluxe.Base _MaxVolume = volume; } - if (_MaxVolume >= 0.02f) - _AnalyzeByAutocorrelation(true); - else - _AnalyzeByAutocorrelation(false); + _AnalyzeByAutocorrelation(_MaxVolume >= 0.02f); } catch (Exception) {} } private void _AnalyzeByAutocorrelation(bool valid) { + if (!valid) + { + _ToneValid = false; + return; + } + const double halftoneBase = 1.05946309436; // 2^(1/12) -> HalftoneBase^12 = 2 (one octave) // prepare to analyze @@ -506,7 +528,7 @@ namespace Vocaluxe.Base weigth[toneIndex] = (float)curWeight; } - if (valid && maxWeight - minWeight > 0.01) + if (maxWeight - minWeight > 0.01) { for (int i = 0; i < weigth.Length; i++) _ToneWeigth[i] = weigth[i]; @@ -594,7 +616,7 @@ namespace Vocaluxe.Base float dt = Time; - float diff = _ExternTime.Time - dt; + float diff = et - dt; if (Math.Abs(diff) > 0.05f) { _Timer.Reset(); diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index bd4ec83f..c730d1d4 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -1,4 +1,23 @@ -using System; +#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.IO; using System.Text; @@ -115,7 +134,7 @@ namespace Vocaluxe.Base } } - public static SCursor Cursor = new SCursor(); + public static SCursor Cursor; #endregion Vars #region Theme and Skin loading and writing @@ -147,7 +166,7 @@ namespace Vocaluxe.Base if (xmlReader == null) return false; - string value = String.Empty; + string value; // load skins/textures @@ -157,7 +176,7 @@ namespace Vocaluxe.Base { try { - xmlReader.GetValue("//root/Skins/" + name, ref value, String.Empty); + xmlReader.GetValue("//root/Skins/" + name, out value, String.Empty); SSkinElement sk = _Skins[skinIndex].SkinList[name]; sk.Value = value; sk.VideoIndex = -1; @@ -177,10 +196,8 @@ namespace Vocaluxe.Base { try { - xmlReader.GetValue("//root/Videos/" + _Skins[skinIndex].VideoList[i].Name, ref value, String.Empty); - SSkinElement sk = new SSkinElement(); - sk.Name = _Skins[skinIndex].VideoList[i].Name; - sk.Value = value; + xmlReader.GetValue("//root/Videos/" + _Skins[skinIndex].VideoList[i].Name, out value, String.Empty); + SSkinElement sk = new SSkinElement {Name = _Skins[skinIndex].VideoList[i].Name, Value = value}; sk.VideoIndex = CVideo.VdLoad(Path.Combine(_Skins[skinIndex].Path, sk.Value)); CVideo.VdSetLoop(sk.VideoIndex, true); CVideo.VdPause(sk.VideoIndex); @@ -248,7 +265,7 @@ namespace Vocaluxe.Base { if (themeIndex < 0 || themeIndex >= _Themes.Count) { - CLog.LogError("Can't find Theme Index " + themeIndex.ToString()); + CLog.LogError("Can't find Theme Index " + themeIndex); return false; } @@ -387,7 +404,7 @@ namespace Vocaluxe.Base _Themes.Clear(); string path = Path.Combine(Directory.GetCurrentDirectory(), CSettings.FolderThemes); - List files = CHelper.ListFiles(path, "*.xml", false); + List files = CHelper.ListFiles(path, "*.xml"); foreach (string file in files) AddTheme(Path.Combine(path, file), -1); @@ -406,11 +423,11 @@ namespace Vocaluxe.Base if (version == _ThemeSystemVersion) { - xmlReader.GetValue("//root/Info/Name", ref theme.Name, String.Empty); - if (theme.Name.Length > 0) + xmlReader.GetValue("//root/Info/Name", out theme.Name, String.Empty); + if (theme.Name != "") { - xmlReader.GetValue("//root/Info/Author", ref theme.Author, String.Empty); - xmlReader.GetValue("//root/Info/SkinFolder", ref theme.SkinFolder, String.Empty); + xmlReader.GetValue("//root/Info/Author", out theme.Author, String.Empty); + xmlReader.GetValue("//root/Info/SkinFolder", out theme.SkinFolder, String.Empty); xmlReader.TryGetIntValue("//root/Info/ThemeVersionMajor", ref theme.ThemeVersionMajor); xmlReader.TryGetIntValue("//root/Info/ThemeVersionMinor", ref theme.ThemeVersionMinor); theme.Path = Path.GetDirectoryName(filePath); @@ -428,7 +445,7 @@ namespace Vocaluxe.Base else msg += "the file is for newer program versions! "; - msg += "Current ThemeSystemVersion is " + _ThemeSystemVersion.ToString() + " but found " + version; + msg += "Current ThemeSystemVersion is " + _ThemeSystemVersion + " but found " + version; CLog.LogError(msg); } return true; @@ -451,14 +468,14 @@ namespace Vocaluxe.Base { if (themeIndex < 0 || themeIndex >= _Themes.Count) { - CLog.LogError("Error List Skins. Can't find Theme index: " + themeIndex.ToString()); + CLog.LogError("Error List Skins. Can't find Theme index: " + themeIndex); return; } STheme theme = _Themes[themeIndex]; string path = Path.Combine(theme.Path, theme.SkinFolder); - List files = CHelper.ListFiles(path, "*.xml", false); + List files = CHelper.ListFiles(path, "*.xml"); foreach (string file in files) { @@ -473,10 +490,10 @@ namespace Vocaluxe.Base if (version == _SkinSystemVersion) { - xmlReader.GetValue("//root/Info/Name", ref skin.Name, String.Empty); - if (skin.Name.Length > 0) + xmlReader.GetValue("//root/Info/Name", out skin.Name, String.Empty); + if (skin.Name != "") { - xmlReader.GetValue("//root/Info/Author", ref skin.Author, String.Empty); + xmlReader.GetValue("//root/Info/Author", out skin.Author, String.Empty); xmlReader.TryGetIntValue("//root/Info/SkinVersionMajor", ref skin.SkinVersionMajor); xmlReader.TryGetIntValue("//root/Info/SkinVersionMinor", ref skin.SkinVersionMinor); @@ -489,9 +506,7 @@ namespace Vocaluxe.Base List names = xmlReader.GetValues("Skins"); foreach (string str in names) { - SSkinElement sk = new SSkinElement(); - sk.Name = str; - sk.Value = String.Empty; + SSkinElement sk = new SSkinElement {Name = str, Value = String.Empty}; skin.SkinList[str] = sk; } @@ -499,9 +514,7 @@ namespace Vocaluxe.Base names = xmlReader.GetValues("Videos"); foreach (string str in names) { - SSkinElement sk = new SSkinElement(); - sk.Name = str; - sk.Value = String.Empty; + SSkinElement sk = new SSkinElement {Name = str, Value = String.Empty}; skin.VideoList.Add(sk); } _Skins.Add(skin); @@ -515,7 +528,7 @@ namespace Vocaluxe.Base else msg += "the file is for newer program versions! "; - msg += "Current SkinSystemVersion is " + _SkinSystemVersion.ToString(); + msg += "Current SkinSystemVersion is " + _SkinSystemVersion; CLog.LogError(msg); } } @@ -529,7 +542,7 @@ namespace Vocaluxe.Base { if (partyModeID != -1 && _Skins[i].PartyModeID == partyModeID) return i; - else if (partyModeID == -1 && _Skins[i].Name == CConfig.Skin) + if (partyModeID == -1 && _Skins[i].Name == CConfig.Skin) return i; } @@ -542,7 +555,7 @@ namespace Vocaluxe.Base { if (partyModeID != -1 && _Themes[i].PartyModeID == partyModeID) return i; - else if (partyModeID == -1 && _Themes[i].Name == CConfig.Theme) + if (partyModeID == -1 && _Themes[i].Name == CConfig.Theme) return i; } @@ -578,22 +591,12 @@ namespace Vocaluxe.Base return _GetSkinFileName(skinName, GetSkinIndex(partyModeID), true); } - private static string _GetSkinFileName(string skinName, int skinIndex) - { - return _GetSkinFileName(skinName, skinIndex, false); - } - - private static string _GetSkinFileName(string skinName, int skinIndex, bool returnPath) + private static string _GetSkinFileName(string skinName, int skinIndex, bool returnPath = false) { foreach (SSkinElement sk in _Skins[skinIndex].SkinList.Values) { if (sk.Name == skinName) - { - if (!returnPath) - return sk.Value; - else - return Path.Combine(_Skins[skinIndex].Path, sk.Value); - } + return !returnPath ? sk.Value : Path.Combine(_Skins[skinIndex].Path, sk.Value); } CLog.LogError("Can't find Skin Element \"" + skinName); @@ -616,7 +619,7 @@ namespace Vocaluxe.Base sk.VideoIndex = CVideo.VdLoad(GetVideoFilePath(sk.Name, partyModeID)); CVideo.VdSetLoop(sk.VideoIndex, true); } - CVideo.VdGetFrame(sk.VideoIndex, ref sk.Texture, time, ref time); + CVideo.VdGetFrame(sk.VideoIndex, ref sk.Texture, time, out time); _Skins[skinIndex].VideoList[i] = sk; return sk.Texture; } @@ -676,22 +679,12 @@ namespace Vocaluxe.Base return _GetVideoFileName(videoName, GetSkinIndex(partyModeID), true); } - private static string _GetVideoFileName(string videoName, int skinIndex) - { - return _GetVideoFileName(videoName, skinIndex, false); - } - - private static string _GetVideoFileName(string videoName, int skinIndex, bool returnPath) + private static string _GetVideoFileName(string videoName, int skinIndex, bool returnPath = false) { foreach (SSkinElement sk in _Skins[skinIndex].VideoList) { if (sk.Name == videoName) - { - if (!returnPath) - return sk.Value; - else - return Path.Combine(_Skins[skinIndex].Path, sk.Value); - } + return !returnPath ? sk.Value : Path.Combine(_Skins[skinIndex].Path, sk.Value); } CLog.LogError("Can't find Video Element \"" + videoName); @@ -710,14 +703,13 @@ namespace Vocaluxe.Base float value = 0f; int i = 1; - while (xmlReader.TryGetFloatValue("//root/Colors/Player" + i.ToString() + "/R", ref value)) + while (xmlReader.TryGetFloatValue("//root/Colors/Player" + i + "/R", ref value)) { - SColorF color = new SColorF(); + SColorF color = new SColorF {R = value}; - color.R = value; - xmlReader.TryGetFloatValue("//root/Colors/Player" + i.ToString() + "/G", ref color.G); - xmlReader.TryGetFloatValue("//root/Colors/Player" + i.ToString() + "/B", ref color.B); - xmlReader.TryGetFloatValue("//root/Colors/Player" + i.ToString() + "/A", ref color.A); + xmlReader.TryGetFloatValue("//root/Colors/Player" + i + "/G", ref color.G); + xmlReader.TryGetFloatValue("//root/Colors/Player" + i + "/B", ref color.B); + xmlReader.TryGetFloatValue("//root/Colors/Player" + i + "/A", ref color.A); playerColors.Add(color); i++; @@ -729,8 +721,7 @@ namespace Vocaluxe.Base List names = xmlReader.GetValues("ColorSchemes"); foreach (string str in names) { - SColorScheme scheme = new SColorScheme(); - scheme.Name = str; + SColorScheme scheme = new SColorScheme {Name = str}; xmlReader.TryGetFloatValue("//root/ColorSchemes/" + str + "/R", ref scheme.Color.R); xmlReader.TryGetFloatValue("//root/ColorSchemes/" + str + "/G", ref scheme.Color.G); @@ -747,12 +738,12 @@ namespace Vocaluxe.Base private static void _LoadCursor(CXMLReader xmlReader, int skinIndex) { string value = String.Empty; - xmlReader.GetValue("//root/Cursor/Skin", ref Cursor.SkinName, value); + xmlReader.GetValue("//root/Cursor/Skin", out Cursor.SkinName, value); xmlReader.TryGetFloatValue("//root/Cursor/W", ref Cursor.W); xmlReader.TryGetFloatValue("//root/Cursor/H", ref Cursor.H); - if (xmlReader.GetValue("//root/Cursor/Color", ref value, value)) + if (xmlReader.GetValue("//root/Cursor/Color", out value, value)) { SColorF color = GetColor(value, _Skins[skinIndex].PartyModeID); Cursor.R = color.R; @@ -780,7 +771,7 @@ namespace Vocaluxe.Base writer.WriteStartElement("Colors"); for (int i = 0; i < _Skins[skinIndex].ThemeColors.Player.Length; i++) { - writer.WriteStartElement("Player" + (i + 1).ToString()); + writer.WriteStartElement("Player" + (i + 1)); writer.WriteElementString("R", _Skins[skinIndex].ThemeColors.Player[i].R.ToString("#0.000")); writer.WriteElementString("G", _Skins[skinIndex].ThemeColors.Player[i].G.ToString("#0.000")); @@ -816,7 +807,7 @@ namespace Vocaluxe.Base writer.WriteElementString("W", Cursor.W.ToString("#0.000")); writer.WriteElementString("H", Cursor.H.ToString("#0.000")); - if (Cursor.Color.Length > 0) + if (Cursor.Color != "") writer.WriteElementString("Color", Cursor.Color); else { diff --git a/Vocaluxe/Base/CUtility.cs b/Vocaluxe/Base/CUtility.cs index 2bda8739..17dfae81 100644 --- a/Vocaluxe/Base/CUtility.cs +++ b/Vocaluxe/Base/CUtility.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.Windows.Forms; @@ -40,21 +59,17 @@ namespace Vocaluxe.Base long ticks = _Stopwatch.ElapsedTicks; if (Stopwatch.IsHighResolution && ticks != 0) return (float)((_NanosecPerTick * ticks) / (1000.0 * 1000.0)); - else - return _Stopwatch.ElapsedMilliseconds; + return _Stopwatch.ElapsedMilliseconds; } - else - return 0f; + return 0f; } - public static float CalculateFPS() + public static void CalculateFPS() { float ms = GetMilliseconds(); if (ms > 0) _Fps = 1 / ms; - - return _Fps * 1000f; } public static double GetFPS() @@ -136,17 +151,12 @@ namespace Vocaluxe.Base { _CheckModifiers(); - bool repeat = false; - if (_Keys == e.KeyCode) - repeat = true; + bool repeat = _Keys == e.KeyCode; if (!_Timer.IsRunning || (_Timer.ElapsedMilliseconds > 75) || !repeat) { _Keys = e.KeyCode; - if (repeat) - _Add(_ModAlt, _ModShift, _ModCtrl, _KeyPressed, _Char, _Keys); - else - _Add(_ModAlt, _ModShift, _ModCtrl, _KeyPressed, Char.MinValue, _Keys); + _Add(_ModAlt, _ModShift, _ModCtrl, _KeyPressed, repeat ? _Char : Char.MinValue, _Keys); } } @@ -159,7 +169,9 @@ namespace Vocaluxe.Base _KeyPressed = true; } + // ReSharper disable UnusedParameter.Global public void KeyUp(KeyEventArgs e) + // ReSharper restore UnusedParameter.Global { _CheckModifiers(); _KeyPressed = false; @@ -173,8 +185,7 @@ namespace Vocaluxe.Base _Del(0); return true; } - else - return false; + return false; } public void CopyEvents() @@ -193,54 +204,34 @@ namespace Vocaluxe.Base private readonly List _EventsPool; private readonly List _CurrentPool; - private int _X; - private int _Y; - private readonly Object _CopyLock = new Object(); - private bool _ModAlt; - private bool _ModCtrl; - private bool _ModShift; + private EModifier _Mod; private readonly Stopwatch _Timer; - public int X - { - get { return _X; } - } - - public int Y - { - get { return _Y; } - } - - public bool Visible = false; + public bool Visible; 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) { _EventsPool.Add(pool); } - _X = x; - _Y = y; } private void _Del(int index) @@ -251,30 +242,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) @@ -293,11 +282,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, - e.Button == MouseButtons.Middle, 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); @@ -305,14 +296,11 @@ namespace Vocaluxe.Base public bool PollEvent(ref SMouseEvent mouseEvent) { - if (_CurrentPool.Count > 0) - { - mouseEvent = _CurrentPool[0]; - _Del(0); - return true; - } - else + if (_CurrentPool.Count <= 0) return false; + mouseEvent = _CurrentPool[0]; + _Del(0); + return true; } public void CopyEvents() diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index bd4e136a..db7390fb 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -1,4 +1,23 @@ -using System.Diagnostics; +#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.Diagnostics; using System.Drawing; using Vocaluxe.Lib.Video; using VocaluxeLib.Menu; @@ -61,9 +80,9 @@ namespace Vocaluxe.Base return _VideoDecoder.GetLength(streamID); } - public static bool VdGetFrame(int streamID, ref STexture frame, float time, ref float videoTime) + public static bool VdGetFrame(int streamID, ref STexture frame, float time, out float videoTime) { - return _VideoDecoder.GetFrame(streamID, ref frame, time, ref videoTime); + return _VideoDecoder.GetFrame(streamID, ref frame, time, out videoTime); } public static bool VdSkip(int streamID, float start, float gap) @@ -157,9 +176,8 @@ namespace Vocaluxe.Base float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; _Finished = CVideo.VdFinished(_VideoStream); - STexture tex = new STexture(-1); - tex.Height = 0f; - CVideo.VdGetFrame(_VideoStream, ref tex, videoTime, ref videoTime); + STexture tex = new STexture(-1) {Height = 0f}; + CVideo.VdGetFrame(_VideoStream, ref tex, videoTime, out videoTime); if (tex.Height > 0) { @@ -169,7 +187,7 @@ namespace Vocaluxe.Base } RectangleF bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); RectangleF rect = new RectangleF(0f, 0f, _VideoTexture.Width, _VideoTexture.Height); - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); CDraw.DrawTexture(_VideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CSettings.ZFar / 4)); } @@ -179,8 +197,8 @@ namespace Vocaluxe.Base float videoTime = 0f; while (_VideoTexture.Index == -1 && videoTime < 1f) { - float dummy = 0f; - CVideo.VdGetFrame(_VideoStream, ref _VideoTexture, 0, ref dummy); + float dummy; + CVideo.VdGetFrame(_VideoStream, ref _VideoTexture, 0, out dummy); videoTime += 0.05f; } } diff --git a/Vocaluxe/Base/CWebcam.cs b/Vocaluxe/Base/CWebcam.cs index 8d481d65..0a361c68 100644 --- a/Vocaluxe/Base/CWebcam.cs +++ b/Vocaluxe/Base/CWebcam.cs @@ -1,4 +1,23 @@ -using System.Drawing; +#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.Drawing; using Vocaluxe.Lib.Webcam; using VocaluxeLib.Menu; @@ -67,5 +86,10 @@ namespace Vocaluxe.Base { return _Webcam.GetDevices(); } + + public static bool IsDeviceAvailable() + { + return _Webcam.IsDeviceAvailable(); + } } } \ No newline at end of file diff --git a/Vocaluxe/CSplashScreen.cs b/Vocaluxe/CSplashScreen.cs index e6206794..938588e4 100644 --- a/Vocaluxe/CSplashScreen.cs +++ b/Vocaluxe/CSplashScreen.cs @@ -1,4 +1,23 @@ -using System; +#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.Drawing; using System.IO; using System.Windows.Forms; @@ -52,6 +71,18 @@ namespace Vocaluxe Show(); } + public override sealed string Text + { + get { return base.Text; } + set { base.Text = value; } + } + + public override sealed Color BackColor + { + get { return base.BackColor; } + set { base.BackColor = value; } + } + protected override void OnPaint(PaintEventArgs e) {} protected override void OnPaintBackground(PaintEventArgs e) diff --git a/Vocaluxe/GameModes/CGameMode.cs b/Vocaluxe/GameModes/CGameMode.cs index b4e2ca55..2d6f2527 100644 --- a/Vocaluxe/GameModes/CGameMode.cs +++ b/Vocaluxe/GameModes/CGameMode.cs @@ -1,4 +1,23 @@ -using System.Collections.Generic; +#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.Collections.Generic; using Vocaluxe.Base; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -7,8 +26,8 @@ namespace Vocaluxe.GameModes { struct SSongQueque { - public int SongID; - public EGameMode GameMode; + public readonly int SongID; + public readonly EGameMode GameMode; public SSongQueque(int songID, EGameMode gameMode) { @@ -19,10 +38,9 @@ namespace Vocaluxe.GameModes abstract class CGameMode : IGameMode { - protected bool _Initialized = false; - protected List _SongQueque; - protected int _CurrentSong; - protected CPoints _Points; + private List _SongQueque; + private int _CurrentSong; + private CPoints _Points; #region Implementation public virtual void Init() @@ -181,7 +199,7 @@ namespace Vocaluxe.GameModes song.Finish = CGame.GetTimeFromBeats(song.ShortEnd, song.BPM) + CSettings.DefaultMedleyFadeOutTime + song.Gap; // set lines to medley mode - song.Notes.SetMedley(song.Notes.GetLines(0).Line[0].FirstNoteBeat, song.ShortEnd); + song.Notes.SetMedley(song.Notes.GetVoice(0).Lines[0].FirstNoteBeat, song.ShortEnd); break; } @@ -216,7 +234,5 @@ namespace Vocaluxe.GameModes return _Points; } #endregion Implementation - - protected virtual void _SongManipulation(int songIndex) {} } } \ No newline at end of file diff --git a/Vocaluxe/GameModes/CGameModeNormal.cs b/Vocaluxe/GameModes/CGameModeNormal.cs index 0178569b..e728a923 100644 --- a/Vocaluxe/GameModes/CGameModeNormal.cs +++ b/Vocaluxe/GameModes/CGameModeNormal.cs @@ -1,13 +1,24 @@ -namespace Vocaluxe.GameModes +#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 - { - public override void Init() - { - base.Init(); - - _Initialized = true; - } - } + class CGameModeNormal : CGameMode {} } \ No newline at end of file diff --git a/Vocaluxe/GameModes/IGameMode.cs b/Vocaluxe/GameModes/IGameMode.cs index 16db3898..b9732b15 100644 --- a/Vocaluxe/GameModes/IGameMode.cs +++ b/Vocaluxe/GameModes/IGameMode.cs @@ -1,4 +1,23 @@ -using VocaluxeLib.Menu; +#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 VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; namespace Vocaluxe.GameModes diff --git a/Vocaluxe/GlobalSuppressions.cs b/Vocaluxe/GlobalSuppressions.cs index b6e8fd45..ed290a90 100644 --- a/Vocaluxe/GlobalSuppressions.cs +++ b/Vocaluxe/GlobalSuppressions.cs @@ -1,12 +1,22 @@ -// Diese Datei wird von der Codeanalyse zur Wartung der SuppressMessage- -// Attribute verwendet, die auf dieses Projekt angewendet werden. -// Unterdrückungen auf Projektebene haben entweder kein Ziel oder -// erhalten ein spezifisches Ziel mit Namespace-, Typ-, Memberbereich usw. -// -// Wenn Sie dieser Datei eine Unterdrückung hinzufügen möchten, klicken Sie mit der -// rechten Maustaste auf die Meldung in der Fehlerliste, zeigen Sie auf -// "Meldung(en) unterdrücken", und klicken Sie auf "In Projektunterdrückungsdatei". -// Sie müssen dieser Datei nicht manuell Unterdrückungen hinzufügen. +#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.Diagnostics.CodeAnalysis; [assembly: diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 057f1ff7..53cca0ac 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -126,19 +126,21 @@ namespace Vocaluxe.Lib.Draw ClientSize = new Size(CConfig.ScreenW, CConfig.ScreenH); _SizeBeforeMinimize = ClientSize; - _PresentParameters = new PresentParameters(); - _PresentParameters.Windowed = true; - _PresentParameters.SwapEffect = SwapEffect.Discard; - _PresentParameters.BackBufferHeight = CConfig.ScreenH; - _PresentParameters.BackBufferWidth = CConfig.ScreenW; - _PresentParameters.BackBufferFormat = _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format; - _PresentParameters.Multisample = MultisampleType.None; - _PresentParameters.MultisampleQuality = 0; + _PresentParameters = new PresentParameters + { + Windowed = true, + SwapEffect = SwapEffect.Discard, + BackBufferHeight = CConfig.ScreenH, + BackBufferWidth = CConfig.ScreenW, + BackBufferFormat = _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, + Multisample = MultisampleType.None, + MultisampleQuality = 0 + }; //Apply antialiasing and check if antialiasing mode is supported #region Antialiasing - int quality = 1; + int quality; MultisampleType msType; switch (CConfig.AAMode) { @@ -174,18 +176,11 @@ namespace Vocaluxe.Lib.Draw #endregion Antialiasing //Apply the VSync configuration - if (CConfig.VSync == EOffOn.TR_CONFIG_ON) - _PresentParameters.PresentationInterval = PresentInterval.Default; - else - _PresentParameters.PresentationInterval = PresentInterval.Immediate; + _PresentParameters.PresentationInterval = CConfig.VSync == EOffOn.TR_CONFIG_ON ? PresentInterval.Default : PresentInterval.Immediate; //GMA 950 graphics devices can only process vertices in software mode Capabilities caps = _D3D.GetDeviceCaps(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware); - CreateFlags flags = CreateFlags.None; - if ((caps.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) - flags = CreateFlags.HardwareVertexProcessing; - else - flags = CreateFlags.SoftwareVertexProcessing; + CreateFlags flags = (caps.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0 ? CreateFlags.HardwareVertexProcessing : CreateFlags.SoftwareVertexProcessing; //Check if Pow2 textures are needed _NonPowerOf2TextureSupported = true; @@ -290,7 +285,7 @@ namespace Vocaluxe.Lib.Draw _PresentParameters.BackBufferHeight = ClientSize.Height; ClearScreen(); //To set new PresentParameters the device has to be resetted - Reset(); + _Reset(); //All configurations got flushed due to Reset(), so apply them again Init(); @@ -417,82 +412,80 @@ namespace Vocaluxe.Lib.Draw /// True if it succeeded else false public bool Init() { - if (!_Device.Disposed) - { - Text = CSettings.GetFullVersionText(); - SlimDX.Matrix translate = SlimDX.Matrix.Translation(new Vector3(-CSettings.RenderW / 2, CSettings.RenderH / 2, 0)); - SlimDX.Matrix projection = SlimDX.Matrix.OrthoOffCenterLH(-CSettings.RenderW / 2, CSettings.RenderW / 2, -CSettings.RenderH / 2, CSettings.RenderH / 2, - CSettings.ZNear, CSettings.ZFar); - _VertexBuffer = new VertexBuffer(_Device, CSettings.VertexBufferElements * (4 * Marshal.SizeOf(typeof(STexturedColoredVertex))), Usage.WriteOnly | Usage.Dynamic, - VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Diffuse, Pool.Default); - - if (_Device.SetStreamSource(0, _VertexBuffer, 0, Marshal.SizeOf(typeof(STexturedColoredVertex))).IsFailure) - CLog.LogError("Failed to set stream source"); - _Device.VertexDeclaration = STexturedColoredVertex.GetDeclaration(_Device); - if (_Device.SetTransform(TransformState.Projection, projection).IsFailure) - CLog.LogError("Failed to set orthogonal matrix"); - if (_Device.SetTransform(TransformState.World, translate).IsFailure) - CLog.LogError("Failed to set translation matrix"); - if (_Device.SetRenderState(RenderState.CullMode, Cull.None).IsFailure) - CLog.LogError("Failed to set cull mode"); - if (_Device.SetRenderState(RenderState.AlphaBlendEnable, true).IsFailure) - CLog.LogError("Failed to enable alpha blending"); - if (_Device.SetRenderState(RenderState.Lighting, false).IsFailure) - CLog.LogError("Failed to disable lighting"); - if (_Device.SetRenderState(RenderState.DestinationBlend, SlimDX.Direct3D9.Blend.InverseSourceAlpha).IsFailure) - CLog.LogError("Failed to set destination blend"); - if (_Device.SetRenderState(RenderState.SourceBlend, SlimDX.Direct3D9.Blend.SourceAlpha).IsFailure) - CLog.LogError("Failed to set source blend"); - if (_PresentParameters.Multisample != MultisampleType.None) - { - if (_Device.SetRenderState(RenderState.MultisampleAntialias, true).IsFailure) - CLog.LogError("Failed to set antialiasing"); - } - if (_Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear).IsFailure) - CLog.LogError("Failed to set min filter"); - if (_Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear).IsFailure) - CLog.LogError("Failed to set mag filter"); - if (_Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear).IsFailure) - CLog.LogError("Failed to set mip filter"); - if (_Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp).IsFailure) - CLog.LogError("Failed to set clamping on u"); - if (_Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp).IsFailure) - CLog.LogError("Failed to set claming on v"); - if (_Device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture).IsFailure) - CLog.LogError("Failed to set alpha argument 1"); - if (_Device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse).IsFailure) - CLog.LogError("Failed to set alpha argument 2"); - if (_Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate).IsFailure) - CLog.LogError("Failed to set alpha operation"); - - Int16[] indices = new Int16[6]; - indices[0] = 0; - indices[1] = 1; - indices[2] = 2; - indices[3] = 0; - indices[4] = 2; - indices[5] = 3; - - _IndexBuffer = new IndexBuffer(_Device, 6 * sizeof(Int16), Usage.WriteOnly, Pool.Managed, true); - - DataStream stream = _IndexBuffer.Lock(0, 0, LockFlags.Discard); - stream.WriteRange(indices); - _IndexBuffer.Unlock(); - _Device.Indices = _IndexBuffer; - - //This creates a new white texture and adds it to the texture pool - //This texture is used for the DrawRect method - using (Bitmap blankMap = new Bitmap(1, 1)) - { - Graphics g = Graphics.FromImage(blankMap); - g.Clear(Color.White); - g.Dispose(); - _BlankTexture = AddTexture(blankMap); - } - return true; - } - else + if (_Device.Disposed) return false; + Text = CSettings.GetFullVersionText(); + SlimDX.Matrix translate = SlimDX.Matrix.Translation(new Vector3(-(float)CSettings.RenderW / 2, (float)CSettings.RenderH / 2, 0)); + SlimDX.Matrix projection = SlimDX.Matrix.OrthoOffCenterLH(-(float)CSettings.RenderW / 2, (float)CSettings.RenderW / 2, -(float)CSettings.RenderH / 2, + (float)CSettings.RenderH / 2, + CSettings.ZNear, CSettings.ZFar); + _VertexBuffer = new VertexBuffer(_Device, CSettings.VertexBufferElements * (4 * Marshal.SizeOf(typeof(STexturedColoredVertex))), Usage.WriteOnly | Usage.Dynamic, + VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Diffuse, Pool.Default); + + if (_Device.SetStreamSource(0, _VertexBuffer, 0, Marshal.SizeOf(typeof(STexturedColoredVertex))).IsFailure) + CLog.LogError("Failed to set stream source"); + _Device.VertexDeclaration = STexturedColoredVertex.GetDeclaration(_Device); + if (_Device.SetTransform(TransformState.Projection, projection).IsFailure) + CLog.LogError("Failed to set orthogonal matrix"); + if (_Device.SetTransform(TransformState.World, translate).IsFailure) + CLog.LogError("Failed to set translation matrix"); + if (_Device.SetRenderState(RenderState.CullMode, Cull.None).IsFailure) + CLog.LogError("Failed to set cull mode"); + if (_Device.SetRenderState(RenderState.AlphaBlendEnable, true).IsFailure) + CLog.LogError("Failed to enable alpha blending"); + if (_Device.SetRenderState(RenderState.Lighting, false).IsFailure) + CLog.LogError("Failed to disable lighting"); + if (_Device.SetRenderState(RenderState.DestinationBlend, SlimDX.Direct3D9.Blend.InverseSourceAlpha).IsFailure) + CLog.LogError("Failed to set destination blend"); + if (_Device.SetRenderState(RenderState.SourceBlend, SlimDX.Direct3D9.Blend.SourceAlpha).IsFailure) + CLog.LogError("Failed to set source blend"); + if (_PresentParameters.Multisample != MultisampleType.None) + { + if (_Device.SetRenderState(RenderState.MultisampleAntialias, true).IsFailure) + CLog.LogError("Failed to set antialiasing"); + } + if (_Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear).IsFailure) + CLog.LogError("Failed to set min filter"); + if (_Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear).IsFailure) + CLog.LogError("Failed to set mag filter"); + if (_Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear).IsFailure) + CLog.LogError("Failed to set mip filter"); + if (_Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp).IsFailure) + CLog.LogError("Failed to set clamping on u"); + if (_Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp).IsFailure) + CLog.LogError("Failed to set claming on v"); + if (_Device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture).IsFailure) + CLog.LogError("Failed to set alpha argument 1"); + if (_Device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse).IsFailure) + CLog.LogError("Failed to set alpha argument 2"); + if (_Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate).IsFailure) + CLog.LogError("Failed to set alpha operation"); + + Int16[] indices = new Int16[6]; + indices[0] = 0; + indices[1] = 1; + indices[2] = 2; + indices[3] = 0; + indices[4] = 2; + indices[5] = 3; + + _IndexBuffer = new IndexBuffer(_Device, 6 * sizeof(Int16), Usage.WriteOnly, Pool.Managed, true); + + DataStream stream = _IndexBuffer.Lock(0, 0, LockFlags.Discard); + stream.WriteRange(indices); + _IndexBuffer.Unlock(); + _Device.Indices = _IndexBuffer; + + //This creates a new white texture and adds it to the texture pool + //This texture is used for the DrawRect method + using (Bitmap blankMap = new Bitmap(1, 1)) + { + Graphics g = Graphics.FromImage(blankMap); + g.Clear(Color.White); + g.Dispose(); + _BlankTexture = AddTexture(blankMap); + } + return true; } /// @@ -511,61 +504,57 @@ namespace Vocaluxe.Lib.Draw } //Resize window if aspect ratio is incorrect - if (_W / (float)_H != CSettings.GetRenderAspect()) + if (Math.Abs(_W / (float)_H - CSettings.GetRenderAspect()) > 0.01) _DoResize(); while (_Run) { Application.DoEvents(); - - if (_Run) + //Clear the previous Frame + ClearScreen(); + //We want to begin drawing + if (_Device.BeginScene().IsFailure) + CLog.LogError("Failed to begin scene"); + _CheckQueque(); + _Run = _Run && CGraphics.Draw(); + _RenderVertexBuffer(); + //We finished drawing the frame + if (_Device.EndScene().IsFailure) + CLog.LogError("Failed to end scene"); + _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); + try { - //Clear the previous Frame - ClearScreen(); - //We want to begin drawing - if (_Device.BeginScene().IsFailure) - CLog.LogError("Failed to begin scene"); - _CheckQueque(); - _Run = _Run && CGraphics.Draw(); - _RenderVertexBuffer(); - //We finished drawing the frame - if (_Device.EndScene().IsFailure) - CLog.LogError("Failed to end scene"); - _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); - try - { - //Now push the frame to the Viewport - _Device.Present(); - } - catch (Direct3D9Exception) - { - //In Direct3D devices can get lost. - //This happens for example when opening the Task Manager in Vista/Windows 7 or if a UAC message is opening - //We need to reset the device to get it to workable state again - //After a reset Init() needs to be called because all data in the Direct3D default pool are lost and need to be recreated - if (_Device.TestCooperativeLevel() == ResultCode.DeviceNotReset) - { - Reset(); - Init(); - } - } - //Apply fullscreen mode - if (CSettings.IsFullScreen != _Fullscreen) - { - if (!_Fullscreen) - _EnterFullScreen(); - else - _LeaveFullScreen(); - } - if (CTime.IsRunning()) - delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); - - if (delay >= 1 && CConfig.VSync == EOffOn.TR_CONFIG_OFF) - Thread.Sleep(delay); - //Calculate the FPS Rate and restart the timer after a frame - CTime.CalculateFPS(); - CTime.Restart(); + //Now push the frame to the Viewport + _Device.Present(); } + catch (Direct3D9Exception) + { + //In Direct3D devices can get lost. + //This happens for example when opening the Task Manager in Vista/Windows 7 or if a UAC message is opening + //We need to reset the device to get it to workable state again + //After a reset Init() needs to be called because all data in the Direct3D default pool are lost and need to be recreated + if (_Device.TestCooperativeLevel() == ResultCode.DeviceNotReset) + { + _Reset(); + Init(); + } + } + //Apply fullscreen mode + if (CSettings.IsFullScreen != _Fullscreen) + { + if (!_Fullscreen) + _EnterFullScreen(); + else + _LeaveFullScreen(); + } + if (CTime.IsRunning()) + delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); + + if (delay >= 1 && CConfig.VSync == EOffOn.TR_CONFIG_OFF) + Thread.Sleep(delay); + //Calculate the FPS Rate and restart the timer after a frame + CTime.CalculateFPS(); + CTime.Restart(); } Close(); } @@ -573,7 +562,7 @@ namespace Vocaluxe.Lib.Draw /// /// Resets the device, all objects in the Direct3D default pool get flushed and need to be recreated /// - public void Reset() + private void _Reset() { //Dispose all objects in the default pool, those need to be recreated STexturedColoredVertex.GetDeclaration(_Device).Dispose(); @@ -670,31 +659,30 @@ namespace Vocaluxe.Lib.Draw /// private void _RenderVertexBuffer() { - if (_Vertices.Count > 0) - { - //The vertex buffer locks are slow actions, its better to lock once per frame and write all vertices to the buffer at once - DataStream stream = _VertexBuffer.Lock(0, _Vertices.Count * Marshal.SizeOf(typeof(STexturedColoredVertex)), LockFlags.Discard); - stream.WriteRange(_Vertices.ToArray()); - _VertexBuffer.Unlock(); - stream.Dispose(); + if (_Vertices.Count <= 0) + return; + //The vertex buffer locks are slow actions, its better to lock once per frame and write all vertices to the buffer at once + DataStream stream = _VertexBuffer.Lock(0, _Vertices.Count * Marshal.SizeOf(typeof(STexturedColoredVertex)), LockFlags.Discard); + stream.WriteRange(_Vertices.ToArray()); + _VertexBuffer.Unlock(); + stream.Dispose(); - for (int i = 0; i < _Vertices.Count; i += 4) - { - //Apply rotation - if (_Device.SetTransform(TransformState.World, _VerticesRotationMatrices.Dequeue()).IsFailure) - CLog.LogError("Failed to set world transformation"); - //Apply texture - if (_Device.SetTexture(0, _VerticesTextures.Dequeue()).IsFailure) - CLog.LogError("Failed to set texture"); - //Draw 2 triangles from vertexbuffer - if (_Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, i, 0, 4, 0, 2).IsFailure) - CLog.LogError("Failed to draw quad"); - } - //Clear the queues for the next frame - _Vertices.Clear(); - _VerticesTextures.Clear(); - _VerticesRotationMatrices.Clear(); + for (int i = 0; i < _Vertices.Count; i += 4) + { + //Apply rotation + if (_Device.SetTransform(TransformState.World, _VerticesRotationMatrices.Dequeue()).IsFailure) + CLog.LogError("Failed to set world transformation"); + //Apply texture + if (_Device.SetTexture(0, _VerticesTextures.Dequeue()).IsFailure) + CLog.LogError("Failed to set texture"); + //Draw 2 triangles from vertexbuffer + if (_Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, i, 0, 4, 0, 2).IsFailure) + CLog.LogError("Failed to draw quad"); } + //Clear the queues for the next frame + _Vertices.Clear(); + _VerticesTextures.Clear(); + _VerticesRotationMatrices.Clear(); } #endregion main stuff @@ -744,7 +732,7 @@ namespace Vocaluxe.Lib.Draw /// The texture in which the frame is copied to public void CopyScreen(ref STexture texture) { - if (!_TextureExists(ref texture) || (texture.Width != GetScreenWidth()) || (texture.Height != GetScreenHeight())) + if (!_TextureExists(ref texture) || (int)texture.Width != GetScreenWidth() || (int)texture.Height != GetScreenHeight()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -762,7 +750,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; @@ -794,7 +782,7 @@ namespace Vocaluxe.Lib.Draw /// The end y-value public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) { - SColorF color = new SColorF(a / 255, g / 255, b / 255, a / 255); + SColorF color = new SColorF((float)a / 255, (float)g / 255, (float)b / 255, (float)a / 255); DrawTexture(_BlankTexture, new SRectF(x1, y1, x2, y2, 1), color); } @@ -805,20 +793,8 @@ namespace Vocaluxe.Lib.Draw /// The text's x-position /// The text's y-position /// The text's height - public void DrawText(string text, int x, int y, int h) - { - DrawText(text, x, y, h, 0f); - } - - /// - /// Draws a text string - /// - /// The text to be drawn - /// The text's x-position - /// The text's y-position - /// The text's height - /// The text's x-position - public void DrawText(string text, int x, int y, float h, float z) + /// The text's z-position + public void DrawText(string text, int x, int y, int h, int z = 0) { CFonts.DrawText(text, h, x, y, z, new SColorF(1f, 1f, 1f, 1f)); } @@ -871,7 +847,7 @@ namespace Vocaluxe.Lib.Draw STexture s; try { - s = AddTexture(bmp, texturePath); + s = AddTexture(bmp); } finally { @@ -887,9 +863,8 @@ namespace Vocaluxe.Lib.Draw /// Adds a texture and stores it in the Vram /// /// The Bitmap of which the texure will be created from - /// The path to the texture /// A STexture object containing the added texture - public STexture AddTexture(Bitmap bmp, string texturePath) + public STexture AddTexture(Bitmap bmp) { if (bmp.Height == 0 || bmp.Width == 0) return new STexture(-1); @@ -919,29 +894,35 @@ namespace Vocaluxe.Lib.Draw int w = bmp.Width; int h = bmp.Height; + float ratio = (float)w / h; + int newW = w; + int newH = h; if (w > maxSize && w > h) - { - h = (int)Math.Round((float)maxSize / bmp.Width * bmp.Height); - w = maxSize; - } - - if (h > maxSize) - { - w = (int)Math.Round((float)maxSize / bmp.Height * bmp.Width); - h = maxSize; - } - - //Older graphics card can only handle textures with sizes being powers of two - w = (int)_CheckForNextPowerOf2(w); - h = (int)_CheckForNextPowerOf2(h); + newW = maxSize; + else if (h > maxSize) + newH = maxSize; + else if (w > h) + newW = (int)_CheckForNextPowerOf2(w); + else + newH = (int)_CheckForNextPowerOf2(h); Bitmap bmp2 = null; byte[] data; try { - if (w != bmp.Width || h != bmp.Height) + if (w != newW || h != newH) { + if (w != newW) + { + w = newW; + h = (int)Math.Round(w / ratio); + } + else + { + h = newH; + w = (int)Math.Round(h * ratio); + } //Create a new Bitmap with the new sizes bmp2 = new Bitmap(w, h); //Scale the texture @@ -965,22 +946,9 @@ namespace Vocaluxe.Lib.Draw bmp2.Dispose(); } - if (data == null) - return new STexture(-1); - return AddTexture(w, h, ref data); } - /// - /// Adds a texture and stores it in the Vram - /// - /// The Bitmap of which the texure will be created from - /// A STexture object containing the added texture - public STexture AddTexture(Bitmap bmp) - { - return AddTexture(bmp, String.Empty); - } - public STexture AddTexture(int w, int h, IntPtr data) { byte[] pointerData = new Byte[4 * w * h]; @@ -1045,11 +1013,8 @@ namespace Vocaluxe.Lib.Draw public STexture QuequeTexture(int w, int h, ref byte[] data) { STexture texture = new STexture(-1); - STextureQueque queque = new STextureQueque(); + STextureQueque queque = new STextureQueque {Data = data, Height = h, Width = w}; - queque.Data = data; - queque.Height = h; - queque.Width = w; texture.Height = h; texture.Width = w; @@ -1125,8 +1090,7 @@ namespace Vocaluxe.Lib.Draw s.UnlockRectangle(); return true; */ } - else - return false; + return false; } #endregion updating @@ -1325,36 +1289,35 @@ namespace Vocaluxe.Lib.Draw /// A Value ranging from 0 to 1 containing the ending of the texture public void DrawTexture(STexture texture, SRectF rect, SColorF color, float begin, float end) { - if (_TextureExists(ref texture)) - { - if (_D3DTextures[texture.Index] == null) - return; + if (!_TextureExists(ref texture)) + return; + if (_D3DTextures[texture.Index] == null) + return; - float x1 = 0f + begin * texture.WidthRatio; - float x2 = texture.WidthRatio * end; - float y1 = 0f; - float y2 = texture.HeightRatio; + float x1 = 0f + begin * texture.WidthRatio; + float x2 = texture.WidthRatio * end; + const float y1 = 0f; + float y2 = texture.HeightRatio; - float rx1 = rect.X + begin * rect.W; - float rx2 = rect.X + end * rect.W; - float ry1 = rect.Y; - float ry2 = rect.Y + rect.H; + float rx1 = rect.X + begin * rect.W; + float rx2 = rect.X + end * rect.W; + float ry1 = rect.Y; + float ry2 = rect.Y + rect.H; - //Align the pixels because Direct3D expects the pixels to be the left top corner - rx1 -= 0.5f; - ry1 -= 0.5f; - rx2 -= 0.5f; - ry2 -= 0.5f; + //Align the pixels because Direct3D expects the pixels to be the left top corner + rx1 -= 0.5f; + ry1 -= 0.5f; + rx2 -= 0.5f; + ry2 -= 0.5f; - Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - STexturedColoredVertex[] vert = new STexturedColoredVertex[4]; - vert[0] = new STexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()); - vert[1] = new STexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()); - vert[2] = new STexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()); - vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()); - _AddToVertexBuffer(vert, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); - } + STexturedColoredVertex[] vert = new STexturedColoredVertex[4]; + vert[0] = new STexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()); + vert[1] = new STexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()); + vert[2] = new STexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()); + vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()); + _AddToVertexBuffer(vert, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); } /// @@ -1368,76 +1331,76 @@ namespace Vocaluxe.Lib.Draw /// The height of the reflection public void DrawTextureReflection(STexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) { + if (!_TextureExists(ref texture)) + return; + if (_D3DTextures[texture.Index] == null) + return; + + if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(bounds.H) < float.Epsilon || Math.Abs(bounds.W) < float.Epsilon || + Math.Abs(color.A) < float.Epsilon || height <= 0f) + return; + + if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X) + return; + + if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) + return; + + if (height > bounds.H) + height = bounds.H; + if (_TextureExists(ref texture)) { - if (_D3DTextures[texture.Index] == null) - return; + float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio; + float x2 = (bounds.X + bounds.W - rect.X) / rect.W * texture.WidthRatio; + float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * texture.HeightRatio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * texture.HeightRatio; - if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f) - return; + if (x1 < 0) + x1 = 0f; - if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X) - return; + if (x2 > texture.WidthRatio) + x2 = texture.WidthRatio; - if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) - return; + if (y1 < 0) + y1 = 0f; - if (height > bounds.H) - height = bounds.H; - - if (_TextureExists(ref texture)) - { - float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio; - float x2 = (bounds.X + bounds.W - rect.X) / rect.W * texture.WidthRatio; - float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * texture.HeightRatio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * texture.HeightRatio; - - if (x1 < 0) - x1 = 0f; - - if (x2 > texture.WidthRatio) - x2 = texture.WidthRatio; - - if (y1 < 0) - y1 = 0f; - - if (y2 > texture.HeightRatio) - y2 = texture.HeightRatio; + if (y2 > texture.HeightRatio) + y2 = texture.HeightRatio; - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y + rect.H + space; - float ry2 = rect.Y + rect.H + space + height; + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y + rect.H + space; + float ry2 = rect.Y + rect.H + space + height; - if (rx1 < bounds.X) - rx1 = bounds.X; + if (rx1 < bounds.X) + rx1 = bounds.X; - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; - if (ry1 < bounds.Y + space) - ry1 = bounds.Y + space; + if (ry1 < bounds.Y + space) + ry1 = bounds.Y + space; - if (ry2 > bounds.Y + bounds.H + space + height) - ry2 = bounds.Y + bounds.H + space + height; + if (ry2 > bounds.Y + bounds.H + space + height) + ry2 = bounds.Y + bounds.H + space + height; - //Align the pixels because Direct3D expects the pixels to be the left top corner - rx1 -= 0.5f; - ry1 -= 0.5f; - rx2 -= 0.5f; - ry2 -= 0.5f; + //Align the pixels because Direct3D expects the pixels to be the left top corner + rx1 -= 0.5f; + ry1 -= 0.5f; + rx2 -= 0.5f; + ry2 -= 0.5f; - Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - Color transparent = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + Color transparent = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - STexturedColoredVertex[] vert = new STexturedColoredVertex[4]; - vert[0] = new STexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()); - vert[1] = new STexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb()); - vert[2] = new STexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb()); - vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()); - _AddToVertexBuffer(vert, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); - } + STexturedColoredVertex[] vert = new STexturedColoredVertex[4]; + vert[0] = new STexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()); + vert[1] = new STexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb()); + vert[2] = new STexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb()); + vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()); + _AddToVertexBuffer(vert, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); } } #endregion drawing @@ -1484,20 +1447,17 @@ namespace Vocaluxe.Lib.Draw /// The next power of two private float _CheckForNextPowerOf2(float n) { - if (!_NonPowerOf2TextureSupported) - { - if (n < 0) - throw new ArgumentOutOfRangeException("n", "Must be positive."); - return (float)Math.Pow(2, Math.Ceiling(Math.Log(n, 2))); - } - else + if (_NonPowerOf2TextureSupported) return n; + if (n < 0) + throw new ArgumentOutOfRangeException("n", "Must be positive."); + return (float)Math.Pow(2, Math.Ceiling(Math.Log(n, 2))); } private SlimDX.Matrix _CalculateRotationMatrix(float rot, float rx1, float rx2, float ry1, float ry2) { - SlimDX.Matrix originTranslation = SlimDX.Matrix.Translation(new Vector3(-CSettings.RenderW / 2, CSettings.RenderH / 2, 0)); - if (rot != 0) + SlimDX.Matrix originTranslation = SlimDX.Matrix.Translation(new Vector3(-(float)CSettings.RenderW / 2, (float)CSettings.RenderH / 2, 0)); + if (Math.Abs(rot) > float.Epsilon) { float rotation = rot * (float)Math.PI / 180; float centerX = (rx1 + rx2) / 2f; @@ -1519,10 +1479,10 @@ namespace Vocaluxe.Lib.Draw #endregion utility #region TexturedColoredVertex - public struct STexturedColoredVertex + private struct STexturedColoredVertex { private static VertexDeclaration _Declaration; - public static VertexElement[] Elements = + private static readonly VertexElement[] _Elements = { new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0), new VertexElement(0, sizeof(float) * 3, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), @@ -1530,21 +1490,23 @@ namespace Vocaluxe.Lib.Draw VertexElement.VertexDeclarationEnd }; - public Vector3 Position; - public Vector2 Texture; - public int Color; + // ReSharper disable NotAccessedField.Local + private Vector3 _Position; + private Vector2 _Texture; + private int _Color; + // ReSharper restore NotAccessedField.Local public STexturedColoredVertex(Vector3 position, Vector2 texture, int color) { - Position = position; - Texture = texture; - Color = color; + _Position = position; + _Texture = texture; + _Color = color; } public static VertexDeclaration GetDeclaration(Device device) { if (_Declaration == null || _Declaration.Disposed) - _Declaration = new VertexDeclaration(device, Elements); + _Declaration = new VertexDeclaration(device, _Elements); return _Declaration; } diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 2c0741b3..78203ff0 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -1,4 +1,23 @@ -using System; +#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.ComponentModel; using System.Drawing; @@ -300,7 +319,7 @@ namespace Vocaluxe.Lib.Draw public void CopyScreen(ref STexture texture) { - if ((texture.Index == 0) || (texture.Width != GetScreenWidth()) || (texture.Height != GetScreenHeight())) + if (texture.Index == 0 || (int)texture.Width != GetScreenWidth() || (int)texture.Height != GetScreenHeight()) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -311,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; @@ -327,13 +346,7 @@ namespace Vocaluxe.Lib.Draw } // Draw Basic Text - public void DrawText(string text, int x, int y, int h) - { - DrawText(text, x, y, h, 0f); - } - - // Draw Basic Text - public void DrawText(string text, int x, int y, float h, float z) + public void DrawText(string text, int x, int y, int h, int z = 0) { CFonts.DrawText(text, h, x, y, z, new SColorF(1, 1, 1, 1)); } @@ -346,15 +359,9 @@ namespace Vocaluxe.Lib.Draw { Bitmap bmp2 = new Bitmap(bmp); _Bitmaps.Add(bmp2); - STexture texture = new STexture(); - - texture.Index = _Bitmaps.Count - 1; - - texture.Width = bmp.Width; - texture.Height = bmp.Height; + STexture texture = new STexture {Index = _Bitmaps.Count - 1, Width = bmp.Width, Height = bmp.Height, Color = new SColorF(1f, 1f, 1f, 1f)}; // Add to Texture List - texture.Color = new SColorF(1f, 1f, 1f, 1f); texture.Rect = new SRectF(0f, 0f, texture.Width, texture.Height, 0f); texture.TexturePath = String.Empty; @@ -437,7 +444,7 @@ namespace Vocaluxe.Lib.Draw if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) { BitmapData bmpData = _Bitmaps[texture.Index].LockBits(new Rectangle(0, 0, _Bitmaps[texture.Index].Width, _Bitmaps[texture.Index].Height), - ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); + ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Marshal.Copy(data, 0, bmpData.Scan0, data.Length); _Bitmaps[texture.Index].UnlockBits(bmpData); } @@ -499,12 +506,7 @@ namespace Vocaluxe.Lib.Draw using (Graphics g = Graphics.FromImage(newBitmap)) { - ColorMatrix cm = new ColorMatrix(); - cm.Matrix33 = color.A; - cm.Matrix00 = color.R; - cm.Matrix11 = color.G; - cm.Matrix22 = color.B; - cm.Matrix44 = 1; + ColorMatrix cm = new ColorMatrix {Matrix33 = color.A, Matrix00 = color.R, Matrix11 = color.G, Matrix22 = color.B, Matrix44 = 1}; using (ImageAttributes ia = new ImageAttributes()) { diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 1de47f3d..54056001 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -1,8 +1,26 @@ -using System.Drawing.Drawing2D; +#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.Drawing.Drawing2D; using System.Threading; using OpenTK; using OpenTK.Graphics; -using OpenTK.Graphics.OpenGL; using System; using System.Collections.Generic; using System.ComponentModel; @@ -70,14 +88,12 @@ namespace Vocaluxe.Lib.Draw //Check AA Mode CConfig.AAMode = (EAntiAliasingModes)_CheckAntiAliasingMode((int)CConfig.AAMode); - - ColorFormat cf = new ColorFormat(32); - GraphicsMode gm; + CConfig.ColorDepth = (EColorDepth)_CheckColorDepth((int)CConfig.ColorDepth); bool ok = false; try { - gm = new GraphicsMode(cf, 24, 0, (int)CConfig.AAMode); + GraphicsMode gm = new GraphicsMode((int)CConfig.ColorDepth, 24, 0, (int)CConfig.AAMode); _Control = new GLControl(gm, 2, 1, GraphicsContextFlags.Default); if (_Control.GraphicsMode != null) ok = true; @@ -121,127 +137,60 @@ namespace Vocaluxe.Lib.Draw #region Helpers private int _CheckAntiAliasingMode(int setValue) { - int result = 0; - GraphicsMode mode = null; - bool done = false; + int samples = 0; - while (!done && (result <= 32)) + if (setValue > 32) + setValue = 32; + + while (samples <= setValue) { + GraphicsMode mode; try { - mode = new GraphicsMode(16, 0, 0, result); + mode = new GraphicsMode(16, 0, 0, samples); } catch (Exception) { - done = true; - result /= 2; - if (result == 1) - result = 0; + break; } - if (mode != null) - { - try - { - if (mode.Samples == result) - { - if (result == 0) - result = 2; - else - result *= 2; - } - else - { - done = true; - result /= 2; - if (result == 1) - result = 0; - } - } - catch (Exception) - { - done = true; - result /= 2; - if (result == 1) - result = 0; - } - } + if (mode.Samples != samples) + break; + if (samples == 0) + samples = 2; else - { - done = true; - result /= 2; - if (result == 1) - result = 0; - } + samples *= 2; } - if (result > 64) - result = 32; - - if (setValue < result) - return setValue; - else - return result; + if (samples == 2) + return 0; + return samples / 2; } - private int _CheckColorDeep(int setValue) + private int _CheckColorDepth(int setValue) { - int result = 8; - GraphicsMode mode = null; - bool done = false; + int result = 16; - while (!done && (result <= 32)) + if (setValue > 32) + setValue = 32; + + while (result <= setValue) { + GraphicsMode mode; try { mode = new GraphicsMode(result, 0, 0, 0); } catch (Exception) { - done = true; - result -= 8; - if (result == 0) - result = 8; - } - - if (mode != null) - { - try - { - if (mode.ColorFormat == result) - result += 8; - else - { - done = true; - result -= 8; - if (result == 0) - result = 8; - } - } - catch (Exception) - { - done = true; - result -= 8; - if (result == 0) - result = 8; - } - } - else - { - done = true; - result -= 8; - if (result == 0) - result = 8; + break; } + if (mode.ColorFormat != result) + break; + result += 8; } - if (result > 32) - result = 32; - - if (setValue < result) - return setValue; - else - return result; + return result - 8; } private void _ToggleFullScreen() @@ -571,7 +520,7 @@ namespace Vocaluxe.Lib.Draw public void CopyScreen(ref STexture texture) { - if (!_TextureExists(ref texture) || (texture.Width != GetScreenWidth()) || (texture.Height != GetScreenHeight())) + if (!_TextureExists(ref texture) || Math.Abs(texture.Width - GetScreenWidth()) > 1 || Math.Abs(texture.Height - GetScreenHeight()) > 1) { RemoveTexture(ref texture); texture = CopyScreen(); @@ -589,7 +538,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; @@ -614,12 +563,7 @@ namespace Vocaluxe.Lib.Draw public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) {} // Draw Basic Text (must be deleted later) - public void DrawText(string text, int x, int y, int h) - { - DrawText(text, x, y, h, 0f); - } - - public void DrawText(string text, int x, int y, float h, float z) + public void DrawText(string text, int x, int y, int h, int z = 0) { CFonts.DrawText(text, h, x, y, z, new SColorF(1, 1, 1, 1)); } @@ -664,7 +608,7 @@ namespace Vocaluxe.Lib.Draw OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Blend); - if (rect.Rotation != 0f) + if (Math.Abs(rect.Rotation) > 0.001) { OpenTK.Graphics.OpenGL.GL.Translate(0.5f, 0.5f, 0); OpenTK.Graphics.OpenGL.GL.Rotate(-rect.Rotation, 0f, 0f, 1f); @@ -710,7 +654,7 @@ namespace Vocaluxe.Lib.Draw } try { - return AddTexture(bmp, texturePath); + return AddTexture(bmp); } finally { @@ -722,11 +666,6 @@ namespace Vocaluxe.Lib.Draw } public STexture AddTexture(Bitmap bmp) - { - return AddTexture(bmp, String.Empty); - } - - public STexture AddTexture(Bitmap bmp, string texturePath) { STexture texture = new STexture(-1); @@ -971,11 +910,8 @@ namespace Vocaluxe.Lib.Draw public STexture QuequeTexture(int w, int h, ref byte[] data) { STexture texture = new STexture(-1); - STextureQueque queque = new STextureQueque(); + STextureQueque queque = new STextureQueque {Data = data, Height = h, Width = w}; - queque.Data = data; - queque.Height = h; - queque.Width = w; texture.Height = h; texture.Width = w; @@ -1057,29 +993,21 @@ namespace Vocaluxe.Lib.Draw { if (_UsePBO) { - try - { - OpenTK.Graphics.OpenGL.GL.BindBuffer(OpenTK.Graphics.OpenGL.BufferTarget.PixelUnpackBuffer, texture.PBO); + OpenTK.Graphics.OpenGL.GL.BindBuffer(OpenTK.Graphics.OpenGL.BufferTarget.PixelUnpackBuffer, texture.PBO); - IntPtr buffer = OpenTK.Graphics.OpenGL.GL.MapBuffer(OpenTK.Graphics.OpenGL.BufferTarget.PixelUnpackBuffer, OpenTK.Graphics.OpenGL.BufferAccess.WriteOnly); - Marshal.Copy(data, 0, buffer, data.Length); + IntPtr buffer = OpenTK.Graphics.OpenGL.GL.MapBuffer(OpenTK.Graphics.OpenGL.BufferTarget.PixelUnpackBuffer, OpenTK.Graphics.OpenGL.BufferAccess.WriteOnly); + Marshal.Copy(data, 0, buffer, data.Length); - OpenTK.Graphics.OpenGL.GL.UnmapBuffer(OpenTK.Graphics.OpenGL.BufferTarget.PixelUnpackBuffer); + OpenTK.Graphics.OpenGL.GL.UnmapBuffer(OpenTK.Graphics.OpenGL.BufferTarget.PixelUnpackBuffer); - OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, texture.ID); - OpenTK.Graphics.OpenGL.GL.TexSubImage2D(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, 0, 0, 0, (int)texture.Width, (int)texture.Height, - OpenTK.Graphics.OpenGL.PixelFormat.Bgra, OpenTK.Graphics.OpenGL.PixelType.UnsignedByte, IntPtr.Zero); + OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, texture.ID); + OpenTK.Graphics.OpenGL.GL.TexSubImage2D(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, 0, 0, 0, (int)texture.Width, (int)texture.Height, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, OpenTK.Graphics.OpenGL.PixelType.UnsignedByte, IntPtr.Zero); - OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, 0); - OpenTK.Graphics.OpenGL.GL.BindBuffer(OpenTK.Graphics.OpenGL.BufferTarget.PixelUnpackBuffer, 0); + OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, 0); + OpenTK.Graphics.OpenGL.GL.BindBuffer(OpenTK.Graphics.OpenGL.BufferTarget.PixelUnpackBuffer, 0); - return true; - } - catch (Exception) - { - throw; - //_UsePBO = false; - } + return true; } OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, texture.ID); @@ -1166,7 +1094,8 @@ namespace Vocaluxe.Lib.Draw public void DrawTexture(STexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored) { - if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f) + if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(bounds.H) < float.Epsilon || Math.Abs(bounds.W) < float.Epsilon || + Math.Abs(color.A) < float.Epsilon) return; if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X) @@ -1220,7 +1149,7 @@ namespace Vocaluxe.Lib.Draw OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Texture); OpenTK.Graphics.OpenGL.GL.PushMatrix(); - if (rect.Rotation != 0f) + if (Math.Abs(rect.Rotation) > float.Epsilon) { OpenTK.Graphics.OpenGL.GL.Translate(0.5f, 0.5f, 0); OpenTK.Graphics.OpenGL.GL.Rotate(-rect.Rotation, 0f, 0f, 1f); @@ -1305,7 +1234,8 @@ namespace Vocaluxe.Lib.Draw public void DrawTextureReflection(STexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) { - if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f) + if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(bounds.H) < float.Epsilon || Math.Abs(bounds.W) < float.Epsilon || + Math.Abs(color.A) < float.Epsilon || height <= float.Epsilon) return; if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X) @@ -1361,7 +1291,7 @@ namespace Vocaluxe.Lib.Draw OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Texture); OpenTK.Graphics.OpenGL.GL.PushMatrix(); - if (rect.Rotation != 0f) + if (Math.Abs(rect.Rotation) > float.Epsilon) { OpenTK.Graphics.OpenGL.GL.Translate(0.5f, 0.5f, 0); OpenTK.Graphics.OpenGL.GL.Rotate(-rect.Rotation, 0f, 0f, 1f); diff --git a/Vocaluxe/Lib/Draw/IDraw.cs b/Vocaluxe/Lib/Draw/IDraw.cs index 6b55cbb1..6da270b0 100644 --- a/Vocaluxe/Lib/Draw/IDraw.cs +++ b/Vocaluxe/Lib/Draw/IDraw.cs @@ -1,4 +1,23 @@ -using System; +#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.Drawing; using VocaluxeLib.Menu; @@ -27,7 +46,7 @@ namespace Vocaluxe.Lib.Draw void MakeScreenShot(); // Draw Basic Text (must be deleted later) - void DrawText(string text, int x, int y, int h); + void DrawText(string text, int x, int y, int h, int z = 0); STexture AddTexture(string texturePath); STexture AddTexture(Bitmap bitmap); diff --git a/Vocaluxe/Lib/Input/CHIDAPI.cs b/Vocaluxe/Lib/Input/CHIDAPI.cs index 12caadf1..d90e50d7 100644 --- a/Vocaluxe/Lib/Input/CHIDAPI.cs +++ b/Vocaluxe/Lib/Input/CHIDAPI.cs @@ -1,4 +1,23 @@ -using System; +#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.Runtime.InteropServices; using Vocaluxe.Base; @@ -7,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 @@ -47,7 +68,7 @@ namespace Vocaluxe.Lib.Input public static bool Init() { - int result = -1; + int result; try { result = hid_init(); @@ -58,10 +79,7 @@ namespace Vocaluxe.Lib.Input return false; } - if (result == 0) - return true; - - return false; + return result == 0; } [DllImport(_HIDApiDll, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, EntryPoint = "hid_exit", CharSet = CharSet.Unicode)] @@ -69,7 +87,7 @@ namespace Vocaluxe.Lib.Input public static bool Exit() { - int result = -1; + int result; try { result = hid_exit(); @@ -80,10 +98,7 @@ namespace Vocaluxe.Lib.Input return false; } - if (result == 0) - return true; - - return false; + return result == 0; } [DllImport(_HIDApiDll, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, EntryPoint = "hid_enumerate", CharSet = CharSet.Ansi)] @@ -150,7 +165,7 @@ namespace Vocaluxe.Lib.Input data = new byte[length]; IntPtr dataPtr = Marshal.AllocHGlobal(length); - int result = -1; + int result; try { result = hid_read_timeout(device, dataPtr, length, milliseconds); @@ -178,7 +193,7 @@ namespace Vocaluxe.Lib.Input data = new byte[length]; IntPtr dataPtr = Marshal.AllocHGlobal(length); - int result = -1; + int result; try { result = hid_read(device, dataPtr, length); diff --git a/Vocaluxe/Lib/Input/IInput.cs b/Vocaluxe/Lib/Input/IInput.cs index e81c0509..a78a5018 100644 --- a/Vocaluxe/Lib/Input/IInput.cs +++ b/Vocaluxe/Lib/Input/IInput.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.Drawing; using VocaluxeLib.Menu; @@ -15,10 +34,10 @@ namespace Vocaluxe.Lib.Input interface IInput { - bool Init(); + void Init(); void Close(); - bool Connect(); - bool Disconnect(); + void Connect(); + void Disconnect(); bool IsConnected(); void Update(); @@ -38,7 +57,7 @@ namespace Vocaluxe.Lib.Input { get { - if (!_Timer.IsRunning && _Duration != 0f) + if (!_Timer.IsRunning && Math.Abs(_Duration) > float.Epsilon) { _Timer.Start(); return true; diff --git a/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs b/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs index f93b0c46..867458d6 100644 --- a/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs +++ b/Vocaluxe/Lib/Input/WiiMote/CWiiMote.cs @@ -1,4 +1,23 @@ -using System; +#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.Threading; @@ -31,15 +50,13 @@ namespace Vocaluxe.Lib.Input.WiiMote private CGesture _Gesture; - public bool Init() + public void Init() { _Sync = new Object(); _RumbleTimer = new CRumbleTimer(); _Gesture = new CGesture(); - _Active = true; - _HandlerThread = new Thread(_MainLoop); - _HandlerThread.Priority = ThreadPriority.BelowNormal; + _HandlerThread = new Thread(_MainLoop) {Priority = ThreadPriority.BelowNormal}; _KeysPool = new List(); _CurrentKeysPool = new List(); @@ -49,10 +66,6 @@ namespace Vocaluxe.Lib.Input.WiiMote _ButtonStates = new bool[11]; _OldPosition = new Point(); - - _HandlerThread.Start(); - - return true; } public void Close() @@ -60,20 +73,17 @@ namespace Vocaluxe.Lib.Input.WiiMote _Active = false; } - public bool Connect() + public void Connect() { - if (!_Active) - { - _Active = true; - _HandlerThread.Start(); - } - return true; + if (_Active) + return; + _Active = true; + _HandlerThread.Start(); } - public bool Disconnect() + public void Disconnect() { _Active = false; - return true; } public bool IsConnected() @@ -94,8 +104,7 @@ namespace Vocaluxe.Lib.Input.WiiMote _CurrentKeysPool.RemoveAt(0); return true; } - else - return false; + return false; } public bool PollMouseEvent(ref SMouseEvent mouseEvent) @@ -106,8 +115,7 @@ namespace Vocaluxe.Lib.Input.WiiMote _CurrentMousePool.RemoveAt(0); return true; } - else - return false; + return false; } public void SetRumble(float duration) @@ -134,8 +142,8 @@ namespace Vocaluxe.Lib.Input.WiiMote } else { - bool startRumble = false; - bool stopRumble = false; + bool startRumble; + bool stopRumble; lock (_Sync) { startRumble = _RumbleTimer.ShouldStart; @@ -192,13 +200,6 @@ namespace Vocaluxe.Lib.Input.WiiMote Point p = ws.IRState.Position; p.X = 1023 - p.X; - //key events - bool alt = false; - bool shift = false; - bool ctrl = false; - bool pressed = false; - char unicode = char.MinValue; - EGesture gesture = _Gesture.GetGesture(p); bool lb = false; bool rb = gesture == EGesture.Back; @@ -243,9 +244,9 @@ namespace Vocaluxe.Lib.Input.WiiMote _ButtonStates[10] = ws.ButtonState.Two; - if (alt || shift || ctrl || pressed || unicode != char.MinValue || key != Keys.None) + if (key != Keys.None) { - SKeyEvent pool = new SKeyEvent(ESender.WiiMote, alt, shift, ctrl, pressed, unicode, key); + SKeyEvent pool = new SKeyEvent(ESender.WiiMote, false, false, false, false, char.MinValue, key); lock (_KeyCopyLock) { @@ -254,8 +255,8 @@ namespace Vocaluxe.Lib.Input.WiiMote } //mouse events - float reducing = 0.15f; - float factor = 1f / (1f - reducing * 2f); + const float reducing = 0.15f; + const float factor = 1f / (1f - reducing * 2f); float rx = ((p.X / 1024f) - reducing) * factor; float ry = ((p.Y / 768f) - reducing) * factor; @@ -263,11 +264,7 @@ namespace Vocaluxe.Lib.Input.WiiMote int y = (int)(ry * CSettings.RenderH); - bool ld = false; bool lbh = !lb && ws.ButtonState.A; - bool rbh = false; - bool mb = false; - bool mbh = false; int wheel = 0; if (gesture == EGesture.ScrollUp) @@ -280,12 +277,12 @@ namespace Vocaluxe.Lib.Input.WiiMote if (!lb && !rb && (p.X != _OldPosition.X || p.Y != _OldPosition.Y)) { - mpool = new SMouseEvent(ESender.WiiMote, alt, shift, ctrl, x, y, false, false, false, wheel, lbh, rbh, false, mbh); + 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, alt, shift, ctrl, x, y, lb, ld, rb, wheel, false, false, mb, 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/Input/WiiMote/WiiMoteLib.cs b/Vocaluxe/Lib/Input/WiiMote/WiiMoteLib.cs index 9ac7d4d6..622f7f17 100644 --- a/Vocaluxe/Lib/Input/WiiMote/WiiMoteLib.cs +++ b/Vocaluxe/Lib/Input/WiiMote/WiiMoteLib.cs @@ -1,4 +1,23 @@ -using System; +#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.Drawing; using System.Threading; using Vocaluxe.Base; @@ -10,15 +29,17 @@ namespace Vocaluxe.Lib.Input.WiiMote #region DataTypes public class CWiiMoteStatus { - public SAccelCalibrationInfo AccelCalibrationInfo = new SAccelCalibrationInfo(); + public SAccelCalibrationInfo AccelCalibrationInfo; - public SAccelStatus AccelState = new SAccelStatus(); + public SAccelStatus AccelState; - public SButtons ButtonState = new SButtons(); + public SButtons ButtonState; - public SIRState IRState = new SIRState(); + public SIRState IRState; + // ReSharper disable NotAccessedField.Global public byte Battery; + // ReSharper restore NotAccessedField.Global public bool Rumble; @@ -49,7 +70,9 @@ namespace Vocaluxe.Lib.Input.WiiMote { public bool Active; public Point Position; // X: 0-1023; Y: 0-767 + // ReSharper disable NotAccessedField.Global public int Width; // 0-15 + // ReSharper restore NotAccessedField.Global } public struct SIRState @@ -63,7 +86,9 @@ namespace Vocaluxe.Lib.Input.WiiMote public struct SAccelStatus { public SPoint3 RawValues; //0-255 + // ReSharper disable NotAccessedField.Global public SPoint3F Values; //0-3 + // ReSharper restore NotAccessedField.Global } public struct SAccelCalibrationInfo @@ -105,7 +130,7 @@ namespace Vocaluxe.Lib.Input.WiiMote #region Events public class CWiiMoteChangedEventArgs : EventArgs { - public CWiiMoteStatus WiiMoteState; + public readonly CWiiMoteStatus WiiMoteState; public CWiiMoteChangedEventArgs(CWiiMoteStatus ws) { @@ -114,11 +139,11 @@ namespace Vocaluxe.Lib.Input.WiiMote } #endregion Events - public class CWiiMoteLib : IDisposable + public sealed class CWiiMoteLib : IDisposable { -// ReSharper disable InconsistentNaming + // ReSharper disable InconsistentNaming private const ushort _VID = 0x057e; -// ReSharper restore InconsistentNaming + // ReSharper restore InconsistentNaming private const ushort _PID = 0x0306; //Wiimotion private const ushort _PIDPlus = 0x0330; //Wiimotion Plus @@ -133,9 +158,10 @@ namespace Vocaluxe.Lib.Input.WiiMote // output commands private enum EOutputReport : byte { -// ReSharper disable InconsistentNaming + // ReSharper disable UnusedMember.Local + // ReSharper disable InconsistentNaming LEDs = 0x11, -// ReSharper restore InconsistentNaming + // ReSharper restore InconsistentNaming Type = 0x12, IR = 0x13, Status = 0x15, @@ -144,6 +170,7 @@ namespace Vocaluxe.Lib.Input.WiiMote SpeakerData = 0x18, SpeakerMute = 0x19, IR2 = 0x1a, + // ReSharper restore UnusedMember.Local }; // data handling @@ -157,11 +184,7 @@ namespace Vocaluxe.Lib.Input.WiiMote private bool _Active; private bool _Error; - private bool _Connected; - public bool Connected - { - get { return _Connected; } - } + public bool Connected { get; private set; } private readonly CWiiMoteStatus _WiiMoteState = new CWiiMoteStatus(); private readonly AutoResetEvent _ReadDone = new AutoResetEvent(false); @@ -170,13 +193,18 @@ namespace Vocaluxe.Lib.Input.WiiMote #region Interface public CWiiMoteLib() { - _Connected = false; + Connected = false; _Active = true; _Error = false; _Reader = new Thread(_ReaderLoop); _Reader.Start(); } + ~CWiiMoteLib() + { + Dispose(false); + } + private bool _TryConnect(ushort pid) { bool connected = CHIDApi.Open(_VID, pid, out _Handle); @@ -191,7 +219,7 @@ namespace Vocaluxe.Lib.Input.WiiMote public bool Connect() { - _Connected = false; + Connected = false; if (_Error) return false; @@ -201,7 +229,7 @@ namespace Vocaluxe.Lib.Input.WiiMote if (!CHIDApi.Init()) { CLog.LogError("WiiMoteLib: Can't initialize HID API"); - string msg = "Please install the Visual C++ Redistributable Packages 2008!"; + const string msg = "Please install the Visual C++ Redistributable Packages 2008!"; CLog.LogError(msg); _Active = false; @@ -210,25 +238,25 @@ namespace Vocaluxe.Lib.Input.WiiMote } //Try WiiMotion - _Connected = _TryConnect(_PID); + Connected = _TryConnect(_PID); //Try WiiMotion Plus - if (!_Connected) - _Connected = _TryConnect(_PIDPlus); + if (!Connected) + Connected = _TryConnect(_PIDPlus); - return _Connected; + return Connected; } public void Disconnect() { - _Connected = false; + Connected = false; _Active = false; CHIDApi.Exit(); } public void SetReportType(EInputReport type, EIRSensitivity irSensitivity, bool continuous) { - if (!_Connected) + if (!Connected) return; switch (type) @@ -256,18 +284,17 @@ namespace Vocaluxe.Lib.Input.WiiMote _WiiMoteState.LEDState.LED3 = led3; _WiiMoteState.LEDState.LED4 = led4; - if (!_Connected) + if (!Connected) return; _ClearReport(); _Buff[0] = (byte)EOutputReport.LEDs; - _Buff[1] = (byte)( - (led1 ? 0x10 : 0x00) | - (led2 ? 0x20 : 0x00) | - (led3 ? 0x40 : 0x00) | - (led4 ? 0x80 : 0x00) | - _RumbleBit); + _Buff[1] = (byte)((led1 ? 0x10 : 0x00) | + (led2 ? 0x20 : 0x00) | + (led3 ? 0x40 : 0x00) | + (led4 ? 0x80 : 0x00) | + _RumbleBit); CHIDApi.Write(_Handle, _Buff); } @@ -282,11 +309,6 @@ namespace Vocaluxe.Lib.Input.WiiMote _WiiMoteState.LEDState.LED3, _WiiMoteState.LEDState.LED4); } - - public CWiiMoteStatus WiiMoteState - { - get { return _WiiMoteState; } - } #endregion Interface #region Private stuff @@ -296,7 +318,7 @@ namespace Vocaluxe.Lib.Input.WiiMote { Thread.Sleep(5); - if (_Handle != IntPtr.Zero && _Connected) + if (_Handle != IntPtr.Zero && Connected) { byte[] buff = new byte[_ReportLength]; @@ -322,7 +344,7 @@ namespace Vocaluxe.Lib.Input.WiiMote { if (buff == null) { - _Connected = false; + Connected = false; return false; } @@ -389,6 +411,7 @@ namespace Vocaluxe.Lib.Input.WiiMote return true; } + /* private byte[] _DecryptBuffer(byte[] buff) { for (int i = 0; i < buff.Length; i++) @@ -396,6 +419,7 @@ namespace Vocaluxe.Lib.Input.WiiMote return buff; } +*/ private void _ParseButtons(byte[] buff) { @@ -431,14 +455,15 @@ namespace Vocaluxe.Lib.Input.WiiMote switch (_WiiMoteState.IRState.Mode) { case EIRMode.Basic: - if (_WiiMoteState.IRState.Sensors[0].Active = !(buff[6] == 0xff && buff[7] == 0xff)) + _WiiMoteState.IRState.Sensors[0].Active = !(buff[6] == 0xff && buff[7] == 0xff); + if (_WiiMoteState.IRState.Sensors[0].Active) { _WiiMoteState.IRState.Sensors[0].Position.X = buff[6] | ((buff[8] >> 4) & 0x03) << 8; _WiiMoteState.IRState.Sensors[0].Position.Y = buff[7] | ((buff[8] >> 6) & 0x03) << 8; _WiiMoteState.IRState.Sensors[0].Width = 0; } - - if (_WiiMoteState.IRState.Sensors[1].Active = !(buff[9] == 0xff && buff[10] == 0xff)) + _WiiMoteState.IRState.Sensors[1].Active = !(buff[9] == 0xff && buff[10] == 0xff); + if (_WiiMoteState.IRState.Sensors[1].Active) { _WiiMoteState.IRState.Sensors[1].Position.X = buff[9] | ((buff[8] >> 0) & 0x03) << 8; _WiiMoteState.IRState.Sensors[1].Position.Y = buff[10] | ((buff[8] >> 2) & 0x03) << 8; @@ -448,12 +473,12 @@ namespace Vocaluxe.Lib.Input.WiiMote case EIRMode.Extended: for (int i = 0; i < 4; i++) { - if (_WiiMoteState.IRState.Sensors[i].Active = !(buff[6 + i * 3] == 0xff && buff[7 + i * 3] == 0xff && buff[8 + i * 3] == 0xff)) - { - _WiiMoteState.IRState.Sensors[i].Position.X = buff[6 + i * 3] | ((buff[8 + i * 3] >> 4) & 0x03) << 8; - _WiiMoteState.IRState.Sensors[i].Position.Y = buff[7 + i * 3] | ((buff[8 + i * 3] >> 6) & 0x03) << 8; - _WiiMoteState.IRState.Sensors[i].Width = buff[8 + i * 3] & 0x0f; - } + _WiiMoteState.IRState.Sensors[i].Active = !(buff[6 + i * 3] == 0xff && buff[7 + i * 3] == 0xff && buff[8 + i * 3] == 0xff); + if (!_WiiMoteState.IRState.Sensors[i].Active) + continue; + _WiiMoteState.IRState.Sensors[i].Position.X = buff[6 + i * 3] | ((buff[8 + i * 3] >> 4) & 0x03) << 8; + _WiiMoteState.IRState.Sensors[i].Position.Y = buff[7 + i * 3] | ((buff[8 + i * 3] >> 6) & 0x03) << 8; + _WiiMoteState.IRState.Sensors[i].Width = buff[8 + i * 3] & 0x0f; } break; } @@ -485,13 +510,13 @@ namespace Vocaluxe.Lib.Input.WiiMote if ((buff[3] & 0x08) != 0) { CLog.LogError("Error reading data from WiiMote: Bytes do not exist"); - _Connected = false; + Connected = false; } if ((buff[3] & 0x07) != 0) { CLog.LogError("Error reading data from WiiMote: Attempt to read from write-only registers."); - _Connected = false; + Connected = false; } int size = (buff[3] >> 4) + 1; @@ -505,12 +530,7 @@ namespace Vocaluxe.Lib.Input.WiiMote private byte _RumbleBit { - get - { - if (_WiiMoteState.Rumble) - return 0x1; - return 0x0; - } + get { return (byte)(_WiiMoteState.Rumble ? 1 : 0); } } private bool _ReadCalibration() @@ -630,7 +650,7 @@ namespace Vocaluxe.Lib.Input.WiiMote if (!_ReadDone.WaitOne(1000, false)) { - _Connected = false; + Connected = false; return null; } @@ -667,9 +687,9 @@ namespace Vocaluxe.Lib.Input.WiiMote GC.SuppressFinalize(this); } -// ReSharper disable InconsistentNaming - protected virtual void Dispose(bool disposing) -// ReSharper restore InconsistentNaming + // ReSharper disable InconsistentNaming + private void Dispose(bool disposing) + // ReSharper restore InconsistentNaming { if (disposing) { diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs index 6959db3b..08593a50 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs @@ -1,4 +1,23 @@ -using System; +#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.IO; using System.Text; @@ -40,7 +59,7 @@ namespace Vocaluxe.Lib.Playlist public void SavePlaylist() { - if (PlaylistFile.Length == 0) + if (PlaylistFile == "") { string filename = string.Empty; foreach (char chr in PlaylistName) @@ -49,7 +68,7 @@ namespace Vocaluxe.Lib.Playlist filename += chr.ToString(); } - if (filename.Length == 0) + if (filename == "") filename = "1"; int i = 0; @@ -74,12 +93,6 @@ namespace Vocaluxe.Lib.Playlist return; } - if (writer == null) - { - CLog.LogError("Error creating/opening Playlist File " + PlaylistFile); - return; - } - try { writer.WriteStartDocument(); @@ -95,7 +108,7 @@ namespace Vocaluxe.Lib.Playlist CSong song = CSongs.GetSong(Songs[i].SongID); if (song != null) { - writer.WriteStartElement("Song" + (i + 1).ToString()); + writer.WriteStartElement("Song" + (i + 1)); writer.WriteElementString("Artist", song.Artist); writer.WriteElementString("Title", song.Title); writer.WriteElementString("GameMode", Enum.GetName(typeof(EGameMode), Songs[i].GameMode)); @@ -124,40 +137,38 @@ namespace Vocaluxe.Lib.Playlist return; string value = String.Empty; - if (xmlReader.GetValue("//root/Info/PlaylistName", ref value, value)) + if (xmlReader.GetValue("//root/Info/PlaylistName", out value, value)) { PlaylistName = value; Songs = new List(); List songs = xmlReader.GetValues("Songs"); - string artist = String.Empty; - string title = String.Empty; EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; - for (int i = 0; i < songs.Count; i++) + foreach (string song in songs) { - xmlReader.GetValue("//root/Songs/" + songs[i] + "/Artist", ref artist, String.Empty); - xmlReader.GetValue("//root/Songs/" + songs[i] + "/Title", ref title, String.Empty); - xmlReader.TryGetEnumValue("//root/Songs/" + songs[i] + "/GameMode", ref gm); + string artist; + string title; + xmlReader.GetValue("//root/Songs/" + song + "/Artist", out artist, String.Empty); + xmlReader.GetValue("//root/Songs/" + song + "/Title", out title, String.Empty); + xmlReader.TryGetEnumValue("//root/Songs/" + song + "/GameMode", ref gm); - CPlaylistSong song = new CPlaylistSong(); - song.SongID = -1; + CPlaylistSong playlistSong = new CPlaylistSong {SongID = -1}; CSong[] allSongs = CSongs.AllSongs; - for (int s = 0; s < allSongs.Length; s++) + foreach (CSong curSong in allSongs) { - if (allSongs[s].Artist == artist && allSongs[s].Title == title) - { - song.SongID = allSongs[s].ID; - break; - } + if (curSong.Artist != artist || curSong.Title != title) + continue; + playlistSong.SongID = curSong.ID; + break; } - if (song.SongID != -1) + if (playlistSong.SongID != -1) { - song.GameMode = gm; - Songs.Add(song); + playlistSong.GameMode = gm; + Songs.Add(playlistSong); } else CLog.LogError("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + PlaylistFile); @@ -169,21 +180,14 @@ namespace Vocaluxe.Lib.Playlist public void AddSong(int songID) { - CPlaylistSong song = new CPlaylistSong(); - song.SongID = songID; - if (CSongs.GetSong(songID).IsDuet) - song.GameMode = EGameMode.TR_GAMEMODE_DUET; - else - song.GameMode = EGameMode.TR_GAMEMODE_NORMAL; + CPlaylistSong song = new CPlaylistSong {SongID = songID, GameMode = CSongs.GetSong(songID).IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL}; Songs.Add(song); } public void AddSong(int songID, EGameMode gm) { - CPlaylistSong song = new CPlaylistSong(); - song.SongID = songID; - song.GameMode = gm; + CPlaylistSong song = new CPlaylistSong {SongID = songID, GameMode = gm}; Songs.Add(song); } diff --git a/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs b/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs index 6ef21510..746e4bca 100644 --- a/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs +++ b/Vocaluxe/Lib/Sound/CDirectSoundRecord.cs @@ -1,4 +1,23 @@ -using SlimDX.DirectSound; +#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 SlimDX.DirectSound; using SlimDX.Multimedia; using System; using System.Collections.Generic; @@ -36,15 +55,9 @@ namespace Vocaluxe.Lib.Sound { using (DirectSoundCapture ds = new DirectSoundCapture(dev.DriverGuid)) { - SRecordDevice device = new SRecordDevice(); - device.Driver = dev.DriverGuid.ToString(); - device.ID = id; - device.Name = dev.Description; - device.Inputs = new List(); + SRecordDevice device = new SRecordDevice {Driver = dev.DriverGuid.ToString(), ID = id, Name = dev.Description, Inputs = new List()}; - SInput inp = new SInput(); - inp.Name = "Default"; - inp.Channels = ds.Capabilities.Channels; + SInput inp = new SInput {Name = "Default", Channels = ds.Capabilities.Channels}; if (inp.Channels > 2) inp.Channels = 2; //more are not supported in vocaluxe @@ -77,8 +90,8 @@ namespace Vocaluxe.Lib.Sound if (!_Initialized) return false; - for (int i = 0; i < _Buffer.Length; i++) - _Buffer[i].Reset(); + foreach (CBuffer buffer in _Buffer) + buffer.Reset(); _DeviceConfig = deviceConfig; bool[] active = new bool[deviceConfig.Length]; @@ -101,8 +114,7 @@ namespace Vocaluxe.Lib.Sound { if (active[i]) { - CSoundCardSource source = new CSoundCardSource(guid[i], channels[i]); - source.SampleRateKhz = 44.1; + CSoundCardSource source = new CSoundCardSource(guid[i], channels[i]) {SampleRateKhz = 44.1}; source.SampleDataReady += _OnDataReady; source.Start(); @@ -265,8 +277,8 @@ namespace Vocaluxe.Lib.Sound public CSoundCardSource(Guid guid, short channels) { - this._Guid = guid; - this._Channels = channels; + _Guid = guid; + _Channels = channels; _WaveFormat = new WaveFormat(); SampleRateKhz = 44.1; _BufferSize = 2048; @@ -317,9 +329,7 @@ namespace Vocaluxe.Lib.Sound for (int i = 0; i < _BufferPortionCount; i++) { - NotificationPosition notification = new NotificationPosition(); - notification.Offset = _BufferPortionCount - 1 + (_BufferPortionSize * i); - notification.Event = new AutoResetEvent(false); + NotificationPosition notification = new NotificationPosition {Offset = _BufferPortionCount - 1 + (_BufferPortionSize * i), Event = new AutoResetEvent(false)}; _Notifications.Add(notification); } @@ -329,8 +339,7 @@ namespace Vocaluxe.Lib.Sound for (int i = 0; i < _Notifications.Count; i++) _WaitHandles[i] = _Notifications[i].Event; - _CaptureThread = new Thread(_DoCapture); - _CaptureThread.IsBackground = true; + _CaptureThread = new Thread(_DoCapture) {IsBackground = true}; _Running = true; _CaptureThread.Start(); @@ -354,8 +363,8 @@ namespace Vocaluxe.Lib.Sound if (_Notifications != null) { - for (int i = 0; i < _Notifications.Count; i++) - _Notifications[i].Event.Close(); + foreach (NotificationPosition notification in _Notifications) + notification.Event.Close(); _Notifications.Clear(); _Notifications = null; @@ -374,13 +383,12 @@ namespace Vocaluxe.Lib.Sound // Buffer type must match this.waveFormat.FormatTag and this.waveFormat.BitsPerSample byte[] bufferPortion = new byte[bufferPortionSamples]; - int bufferPortionIndex; _CaptureBuffer.Start(true); while (_Running) { - bufferPortionIndex = WaitHandle.WaitAny(_WaitHandles); + int bufferPortionIndex = WaitHandle.WaitAny(_WaitHandles); _CaptureBuffer.Read( bufferPortion, @@ -400,9 +408,9 @@ namespace Vocaluxe.Lib.Sound GC.SuppressFinalize(this); } -// ReSharper disable InconsistentNaming - protected virtual void Dispose(bool disposing) -// ReSharper restore InconsistentNaming + // ReSharper disable InconsistentNaming + protected void Dispose(bool disposing) + // ReSharper restore InconsistentNaming { if (disposing) { diff --git a/Vocaluxe/Lib/Sound/CGstreamerAudio.cs b/Vocaluxe/Lib/Sound/CGstreamerAudio.cs index e2b180a0..cc207e3e 100644 --- a/Vocaluxe/Lib/Sound/CGstreamerAudio.cs +++ b/Vocaluxe/Lib/Sound/CGstreamerAudio.cs @@ -1,4 +1,23 @@ -using System; +#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 Vocaluxe.Base; using Vocaluxe.Lib.Sound.Gstreamer; @@ -7,10 +26,9 @@ namespace Vocaluxe.Lib.Sound class CGstreamerAudio : IPlayback { //static float LastPosition; - #region log - public CGstreamerAudioWrapper.LogCallback Log; - private void _LogHandler(string text) + #region log + private static void _LogHandler(string text) { CLog.LogError(text); } @@ -18,11 +36,9 @@ namespace Vocaluxe.Lib.Sound public CGstreamerAudio() { - Init(); - Log = _LogHandler; //Is this really needed? CodaAnalyzer complains about it... //GC.SuppressFinalize(Log); - CGstreamerAudioWrapper.SetLogCallback(Log); + CGstreamerAudioWrapper.SetLogCallback(_LogHandler); } public bool Init() diff --git a/Vocaluxe/Lib/Sound/COpenALPlay.cs b/Vocaluxe/Lib/Sound/COpenALPlay.cs index 18518cac..f1fe898b 100644 --- a/Vocaluxe/Lib/Sound/COpenALPlay.cs +++ b/Vocaluxe/Lib/Sound/COpenALPlay.cs @@ -1,4 +1,24 @@ -using OpenTK.Audio; +#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.Linq; +using OpenTK.Audio; using System; using System.Collections.Generic; using System.Diagnostics; @@ -21,11 +41,6 @@ namespace Vocaluxe.Lib.Sound private List _Streams; - public COpenALPlay() - { - Init(); - } - public bool Init() { if (_Initialized) @@ -100,7 +115,6 @@ namespace Vocaluxe.Lib.Sound { _Decoder.Add(decoder); stream.Handle = _Count++; - stream.File = media; _Streams.Add(stream); return stream.Handle; } @@ -299,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) @@ -317,15 +326,6 @@ namespace Vocaluxe.Lib.Sound return -1; } - private void _EndSync(int handle, int stream, int data, IntPtr user) - { - if (_Initialized) - { - if (_AlreadyAdded(stream)) - Close(stream); - } - } - private void _CloseProc(int streamID) { if (_Initialized) @@ -380,7 +380,6 @@ namespace Vocaluxe.Lib.Sound private Closeproc _Closeproc; private int _StreamID; - private string _FileName; private IAudioDecoder _Decoder; private float _BytesPerSecond; private bool _NoMoreData; @@ -422,7 +421,7 @@ namespace Vocaluxe.Lib.Sound _Closeproc = closeProc; _StreamID = streamID; _Terminated = true; - this._CloseMutex = closeMutex; + _CloseMutex = closeMutex; } public float Length @@ -487,7 +486,7 @@ namespace Vocaluxe.Lib.Sound { if (Finished) _Timer.Stop(); - + //TODO: Why not use Decoder.GetPosition()? return _CurrentTime + _Timer.ElapsedMilliseconds / 1000f; } } @@ -567,9 +566,6 @@ namespace Vocaluxe.Lib.Sound if (!File.Exists(fileName)) return -1; - if (_FileOpened) - return -1; - _Decoder = new CAudioDecoderFFmpeg(); _Decoder.Init(); @@ -590,7 +586,6 @@ namespace Vocaluxe.Lib.Sound return -1; } - _FileName = fileName; _Decoder.Open(fileName); _Duration = _Decoder.GetLength(); @@ -600,9 +595,7 @@ namespace Vocaluxe.Lib.Sound _CurrentTime = 0f; _Timer.Reset(); - SAudioStreams stream = new SAudioStreams(0); - - stream.Handle = _Buffers[0]; + SAudioStreams stream = new SAudioStreams(0) {Handle = _Buffers[0]}; if (stream.Handle != 0) { @@ -615,6 +608,7 @@ namespace Vocaluxe.Lib.Sound return stream.Handle; } + _Initialized = true; return -1; } @@ -739,6 +733,7 @@ namespace Vocaluxe.Lib.Sound AL.DeleteSource(_Source); AL.DeleteBuffers(_Buffers); } + _Decoder.Close(); } _Closeproc(_StreamID); @@ -773,7 +768,7 @@ namespace Vocaluxe.Lib.Sound if (_Paused) return; - int queuedCount = 0; + int queuedCount; bool doit = true; AL.GetSource(_Source, ALGetSourcei.BuffersQueued, out queuedCount); @@ -782,7 +777,7 @@ namespace Vocaluxe.Lib.Sound { AL.GetSource(_Source, ALGetSourcei.BuffersProcessed, out processedCount); doit = false; - Console.WriteLine("Buffers Processed on Stream " + _Source.ToString() + " = " + processedCount.ToString()); + Console.WriteLine("Buffers Processed on Stream " + _Source + " = " + processedCount); if (processedCount < 1) return; } @@ -820,7 +815,7 @@ namespace Vocaluxe.Lib.Sound } - int buffer = 0; + int buffer; if (!doit) buffer = AL.SourceUnqueueBuffer(_Source); else @@ -831,11 +826,9 @@ namespace Vocaluxe.Lib.Sound if (buffer != 0) { - if (_Format.ChannelCount == 2) - AL.BufferData(buffer, ALFormat.Stereo16, buf, buf.Length, _Format.SamplesPerSecond); - else - AL.BufferData(buffer, ALFormat.Mono16, buf, buf.Length, _Format.SamplesPerSecond); - Console.WriteLine("Write to Buffer: " + buffer.ToString()); + ALFormat alFormat = (_Format.ChannelCount == 2) ? ALFormat.Stereo16 : ALFormat.Mono16; + AL.BufferData(buffer, alFormat, buf, buf.Length, _Format.SamplesPerSecond); + Console.WriteLine("Write to Buffer: " + buffer); AL.SourceQueueBuffer(_Source, buffer); } } diff --git a/Vocaluxe/Lib/Sound/COpenALRecord.cs b/Vocaluxe/Lib/Sound/COpenALRecord.cs deleted file mode 100644 index 16afc859..00000000 --- a/Vocaluxe/Lib/Sound/COpenALRecord.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace Vocaluxe.Lib.Sound -{ - class COpenALRecord {} -} \ No newline at end of file diff --git a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs index 1c498b0a..54ab8263 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs @@ -1,12 +1,32 @@ -using PortAudioSharp; +#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.Diagnostics; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using System.Threading; using Vocaluxe.Base; using Vocaluxe.Lib.Sound.Decoder; +using Vocaluxe.Lib.Sound.PortAudio; namespace Vocaluxe.Lib.Sound { @@ -21,11 +41,6 @@ namespace Vocaluxe.Lib.Sound private List _Streams; - public CPortAudioPlay() - { - Init(); - } - public bool Init() { if (_Initialized) @@ -85,7 +100,6 @@ namespace Vocaluxe.Lib.Sound { _Decoder.Add(decoder); stream.Handle = _Count++; - stream.File = media; _Streams.Add(stream); return stream.Handle; } @@ -284,12 +298,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) @@ -302,15 +311,6 @@ namespace Vocaluxe.Lib.Sound return -1; } - private void _EndSync(int handle, int stream, int data, IntPtr user) - { - if (_Initialized) - { - if (_AlreadyAdded(stream)) - Close(stream); - } - } - private void _CloseProc(int streamID) { if (_Initialized) @@ -354,11 +354,9 @@ namespace Vocaluxe.Lib.Sound private static CPortAudio.SPaDeviceInfo _OutputDeviceInfo; private IntPtr _Ptr = new IntPtr(0); - private Closeproc _Closeproc; private CPortAudio.PaStreamCallbackDelegate _PaStreamCallback; private int _StreamID; - private string _FileName; private IAudioDecoder _Decoder; private float _BytesPerSecond; private bool _NoMoreData; @@ -471,7 +469,7 @@ namespace Vocaluxe.Lib.Sound { if (Finished) _SyncTimer.Pause(); - + //TODO: Why not use Decoder.GetPosition()? return _SyncTimer.Time; } } @@ -589,7 +587,6 @@ namespace Vocaluxe.Lib.Sound return -1; } - _FileName = fileName; _Decoder.Open(fileName); _Duration = _Decoder.GetLength(); @@ -606,11 +603,13 @@ namespace Vocaluxe.Lib.Sound IntPtr data = new IntPtr(0); - CPortAudio.SPaStreamParameters outputParams = new CPortAudio.SPaStreamParameters(); - outputParams.ChannelCount = format.ChannelCount; - outputParams.Device = _ApiInfo.DefaultOutputDevice; - outputParams.SampleFormat = CPortAudio.EPaSampleFormat.PaInt16; - outputParams.SuggestedLatency = _OutputDeviceInfo.DefaultLowOutputLatency; + CPortAudio.SPaStreamParameters outputParams = new CPortAudio.SPaStreamParameters + { + ChannelCount = format.ChannelCount, + Device = _ApiInfo.DefaultOutputDevice, + SampleFormat = CPortAudio.EPaSampleFormat.PaInt16, + SuggestedLatency = _OutputDeviceInfo.DefaultLowOutputLatency + }; uint bufsize = (uint)CConfig.AudioBufferSize; lock (_Mutex) @@ -782,6 +781,7 @@ namespace Vocaluxe.Lib.Sound _Initialized = false; } } + _Decoder.Close(); } _Closeproc(_StreamID); diff --git a/Vocaluxe/Lib/Sound/CPortAudioRecord.cs b/Vocaluxe/Lib/Sound/CPortAudioRecord.cs index 03a1063f..5508dfce 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioRecord.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioRecord.cs @@ -1,9 +1,28 @@ -using System.Threading; -using PortAudioSharp; +#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.Threading; using System; using System.Collections.Generic; using System.Runtime.InteropServices; using Vocaluxe.Base; +using Vocaluxe.Lib.Sound.PortAudio; namespace Vocaluxe.Lib.Sound { @@ -54,17 +73,10 @@ namespace Vocaluxe.Lib.Sound CPortAudio.SPaDeviceInfo info = CPortAudio.PaGetDeviceInfo(i); if (info.HostApi == hostAPI && info.MaxInputChannels > 0) { - SRecordDevice dev = new SRecordDevice(); + SRecordDevice dev = new SRecordDevice {ID = i, Name = info.Name, Driver = info.Name + i, Inputs = new List()}; - dev.ID = i; - dev.Name = info.Name; - dev.Driver = info.Name + i.ToString(); - dev.Inputs = new List(); + SInput inp = new SInput {Name = "Default", Channels = info.MaxInputChannels}; - SInput inp = new SInput(); - inp.Name = "Default"; - - inp.Channels = info.MaxInputChannels; if (inp.Channels > 2) inp.Channels = 2; //more are not supported in vocaluxe @@ -101,19 +113,16 @@ namespace Vocaluxe.Lib.Sound if (deviceConfig == null) return false; - if (_RecHandle == null) + if (_RecHandle == null || _RecHandle.Length == 0) return false; - if (_RecHandle.Length == 0) - return false; + foreach (CBuffer buffer in _Buffer) + buffer.Reset(); - for (int i = 0; i < _Buffer.Length; i++) - _Buffer[i].Reset(); - - for (int i = 0; i < _RecHandle.Length; i++) + foreach (IntPtr handle in _RecHandle) { int waitcount = 0; - while (waitcount < 5 && CPortAudio.Pa_IsStreamStopped(_RecHandle[i]) == CPortAudio.EPaError.PaStreamIsNotStopped) + while (waitcount < 5 && CPortAudio.Pa_IsStreamStopped(handle) == CPortAudio.EPaError.PaStreamIsNotStopped) { Thread.Sleep(1); waitcount++; @@ -136,16 +145,17 @@ namespace Vocaluxe.Lib.Sound } } - bool result = true; for (int i = 0; i < _RecHandle.Length; i++) { if (active[i]) { - CPortAudio.SPaStreamParameters inputParams = new CPortAudio.SPaStreamParameters(); - inputParams.ChannelCount = _DeviceConfig[i].Inputs[0].Channels; - inputParams.Device = _DeviceConfig[i].ID; - inputParams.SampleFormat = CPortAudio.EPaSampleFormat.PaInt16; - inputParams.SuggestedLatency = CPortAudio.PaGetDeviceInfo(_DeviceConfig[i].ID).DefaultLowInputLatency; + CPortAudio.SPaStreamParameters inputParams = new CPortAudio.SPaStreamParameters + { + ChannelCount = _DeviceConfig[i].Inputs[0].Channels, + Device = _DeviceConfig[i].ID, + SampleFormat = CPortAudio.EPaSampleFormat.PaInt16, + SuggestedLatency = CPortAudio.PaGetDeviceInfo(_DeviceConfig[i].ID).DefaultLowInputLatency + }; if (_ErrorCheck("OpenStream (rec)", CPortAudio.Pa_OpenStream( out _RecHandle[i], @@ -162,7 +172,7 @@ namespace Vocaluxe.Lib.Sound return false; } } - return result; + return true; } /// @@ -174,8 +184,8 @@ namespace Vocaluxe.Lib.Sound if (!_Initialized) return false; - for (int i = 0; i < _RecHandle.Length; i++) - CPortAudio.Pa_StopStream(_RecHandle[i]); + foreach (IntPtr handle in _RecHandle) + CPortAudio.Pa_StopStream(handle); return true; } diff --git a/Vocaluxe/Lib/Sound/Decoder/CAudioDecoder.cs b/Vocaluxe/Lib/Sound/Decoder/CAudioDecoder.cs deleted file mode 100644 index 695337cd..00000000 --- a/Vocaluxe/Lib/Sound/Decoder/CAudioDecoder.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace Vocaluxe.Lib.Sound.Decoder -{ - abstract class CAudioDecoder : IAudioDecoder - { - protected bool _Initialized; - - public virtual void Init() {} - - public virtual void Close() {} - - public void Open(string fileName) - { - Open(fileName, false); - } - - public virtual void Open(string fileName, bool loop) {} - - public virtual SFormatInfo GetFormatInfo() - { - return new SFormatInfo(); - } - - public virtual float GetLength() - { - return 0f; - } - - public virtual void SetPosition(float time) {} - - public virtual float GetPosition() - { - return 0f; - } - - public virtual void Decode(out byte[] buffer, out float timeStamp) - { - buffer = null; - timeStamp = 0f; - } - } -} \ No newline at end of file diff --git a/Vocaluxe/Lib/Sound/Decoder/CAudioDecoderFFmpeg.cs b/Vocaluxe/Lib/Sound/Decoder/CAudioDecoderFFmpeg.cs index 7a77af27..22787416 100644 --- a/Vocaluxe/Lib/Sound/Decoder/CAudioDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Sound/Decoder/CAudioDecoderFFmpeg.cs @@ -1,12 +1,30 @@ -using System; -using System.IO; +#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.Runtime.InteropServices; using Vocaluxe.Base; using Vocaluxe.Lib.Video.Acinerella; namespace Vocaluxe.Lib.Sound.Decoder { - class CAudioDecoderFFmpeg : CAudioDecoder, IDisposable + class CAudioDecoderFFmpeg : IAudioDecoder, IDisposable { private IntPtr _InstancePtr = IntPtr.Zero; private IntPtr _Audiodecoder = IntPtr.Zero; @@ -18,17 +36,10 @@ namespace Vocaluxe.Lib.Sound.Decoder private string _FileName; private bool _FileOpened; - public override void Init() - { - _FileOpened = false; - _Initialized = true; - } + public void Init() {} - public override void Open(string fileName, bool loop) + public void Open(string fileName) { - if (!_Initialized) - return; - _FileName = fileName; try @@ -42,7 +53,7 @@ namespace Vocaluxe.Lib.Sound.Decoder CLog.LogError("Error opening audio file: " + _FileName); return; } - + if (!_Instance.Opened) { @@ -50,7 +61,7 @@ namespace Vocaluxe.Lib.Sound.Decoder return; } - int audioStreamIndex = -1; + int audioStreamIndex; SACDecoder audiodecoder; try { @@ -70,11 +81,12 @@ namespace Vocaluxe.Lib.Sound.Decoder return; } - _FormatInfo = new SFormatInfo(); - - _FormatInfo.SamplesPerSecond = audiodecoder.StreamInfo.AudioInfo.SamplesPerSecond; - _FormatInfo.BitDepth = audiodecoder.StreamInfo.AudioInfo.BitDepth; - _FormatInfo.ChannelCount = audiodecoder.StreamInfo.AudioInfo.ChannelCount; + _FormatInfo = new SFormatInfo + { + SamplesPerSecond = audiodecoder.StreamInfo.AudioInfo.SamplesPerSecond, + BitDepth = audiodecoder.StreamInfo.AudioInfo.BitDepth, + ChannelCount = audiodecoder.StreamInfo.AudioInfo.ChannelCount + }; _CurrentTime = 0f; @@ -86,13 +98,8 @@ namespace Vocaluxe.Lib.Sound.Decoder _FileOpened = true; } - public override void Close() + public void Close() { - if (!_Initialized) - return; - - _Initialized = false; - if (!_FileOpened) return; @@ -108,25 +115,25 @@ namespace Vocaluxe.Lib.Sound.Decoder _FileOpened = false; } - public override SFormatInfo GetFormatInfo() + public SFormatInfo GetFormatInfo() { - if (!_Initialized && !_FileOpened) + if (!_FileOpened) return new SFormatInfo(); return _FormatInfo; } - public override float GetLength() + public float GetLength() { - if (!_Initialized && !_FileOpened) + if (!_FileOpened) return 0f; return _Instance.Info.Duration / 1000f; } - public override void SetPosition(float time) + public void SetPosition(float time) { - if (!_Initialized && !_FileOpened) + if (!_FileOpened) return; try @@ -140,24 +147,21 @@ namespace Vocaluxe.Lib.Sound.Decoder } } - public override float GetPosition() + public float GetPosition() { - if (!_Initialized && !_FileOpened) - return 0f; - - return _CurrentTime; + return !_FileOpened ? 0f : _CurrentTime; } - public override void Decode(out byte[] buffer, out float timeStamp) + public void Decode(out byte[] buffer, out float timeStamp) { - if (!_Initialized && !_FileOpened) + if (!_FileOpened) { buffer = null; timeStamp = 0f; return; } - int frameFinished = 0; + int frameFinished; try { frameFinished = CAcinerella.AcGetAudioFrame(_InstancePtr, _Audiodecoder); @@ -173,7 +177,7 @@ namespace Vocaluxe.Lib.Sound.Decoder timeStamp = (float)decoder.Timecode; _CurrentTime = timeStamp; - //Console.WriteLine(_CurrentTime.ToString("ReplacedStr:::0:::") + "ReplacedStr:::1:::" + Decoder.buffer_size.ToString()); + //Console.WriteLine(_CurrentTime.ToString("#0.000") + " Buffer size: " + Decoder.buffer_size.ToString()); buffer = new byte[decoder.BufferSize]; if (decoder.BufferSize > 0) @@ -186,8 +190,6 @@ namespace Vocaluxe.Lib.Sound.Decoder timeStamp = 0f; } - public void Dispose() - { - } + public void Dispose() {} } } \ No newline at end of file diff --git a/Vocaluxe/Lib/Sound/Decoder/IAudioDecoder.cs b/Vocaluxe/Lib/Sound/Decoder/IAudioDecoder.cs index b2db7363..5ebcda20 100644 --- a/Vocaluxe/Lib/Sound/Decoder/IAudioDecoder.cs +++ b/Vocaluxe/Lib/Sound/Decoder/IAudioDecoder.cs @@ -1,4 +1,23 @@ -namespace Vocaluxe.Lib.Sound.Decoder +#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.Lib.Sound.Decoder { struct SFormatInfo { @@ -13,7 +32,6 @@ void Close(); void Open(string fileName); - void Open(string fileName, bool loop); SFormatInfo GetFormatInfo(); float GetLength(); diff --git a/Vocaluxe/Lib/Sound/Gstreamer/CGstreamerAudioWrapper.cs b/Vocaluxe/Lib/Sound/Gstreamer/CGstreamerAudioWrapper.cs index fc4e80f9..0793da9f 100644 --- a/Vocaluxe/Lib/Sound/Gstreamer/CGstreamerAudioWrapper.cs +++ b/Vocaluxe/Lib/Sound/Gstreamer/CGstreamerAudioWrapper.cs @@ -1,4 +1,23 @@ -using System.Runtime.InteropServices; +#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.Runtime.InteropServices; namespace Vocaluxe.Lib.Sound.Gstreamer { @@ -21,7 +40,7 @@ namespace Vocaluxe.Lib.Sound.Gstreamer [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate void LogCallback(string message); - [DllImport(_Dll, CallingConvention=CallingConvention.Cdecl)] + [DllImport(_Dll, CallingConvention = CallingConvention.Cdecl)] public static extern void SetLogCallback(LogCallback c); [DllImport(_Dll, CallingConvention = CallingConvention.Cdecl)] diff --git a/Vocaluxe/Lib/Sound/IPlayback.cs b/Vocaluxe/Lib/Sound/IPlayback.cs index a3062906..d6f6d563 100644 --- a/Vocaluxe/Lib/Sound/IPlayback.cs +++ b/Vocaluxe/Lib/Sound/IPlayback.cs @@ -1,16 +1,31 @@ -using System; +#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.Lib.Sound { struct SAudioStreams { public int Handle; - public string File; public SAudioStreams(int stream) { Handle = stream; - File = String.Empty; } } diff --git a/Vocaluxe/Lib/Sound/IRecord.cs b/Vocaluxe/Lib/Sound/IRecord.cs index 30df7caf..2246f3e3 100644 --- a/Vocaluxe/Lib/Sound/IRecord.cs +++ b/Vocaluxe/Lib/Sound/IRecord.cs @@ -1,4 +1,23 @@ -using System; +#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; namespace Vocaluxe.Lib.Sound @@ -27,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 fc7966b8..8b357690 100644 --- a/Vocaluxe/Lib/Sound/Portaudio/PortAudio.cs +++ b/Vocaluxe/Lib/Sound/Portaudio/PortAudio.cs @@ -1,35 +1,37 @@ -/* - * PortAudioSharp - PortAudio bindings for .NET - * Copyright 2006-2011 Riccardo Gerosa and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +#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.Runtime.InteropServices; -namespace PortAudioSharp +namespace Vocaluxe.Lib.Sound.PortAudio { /** PortAudio v.19 bindings for .NET */ - public partial class CPortAudio + // ReSharper disable UnusedMember.Global + // ReSharper disable FieldCanBeMadeReadOnly.Global + // ReSharper disable MemberCanBePrivate.Global + + public static class CPortAudio { #region **** PORTAUDIO CALLBACKS **** [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -550,10 +552,9 @@ namespace PortAudioSharp [DllImport(_PaDll, CallingConvention = CallingConvention.Cdecl)] public static extern void Pa_Sleep(int msec); #endregion - - private CPortAudio() - { - // This is a static class - } } + + // ReSharper restore UnusedMember.Global + // ReSharper restore FieldCanBeMadeReadOnly.Global + // ReSharper restore MemberCanBePrivate.Global } \ No newline at end of file diff --git a/Vocaluxe/Lib/Sound/Portaudio/PortAudioASIO.cs b/Vocaluxe/Lib/Sound/Portaudio/PortAudioASIO.cs deleted file mode 100644 index 081ce0b0..00000000 --- a/Vocaluxe/Lib/Sound/Portaudio/PortAudioASIO.cs +++ /dev/null @@ -1,100 +0,0 @@ -/* - * PortAudioSharp - PortAudio bindings for .NET - * Copyright 2006-2011 Riccardo Gerosa and individual contributors as indicated - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -using System; -using System.Runtime.InteropServices; - -namespace PortAudioSharp -{ - /// PortAudio v.19 bindings for .NET - ASIO bindings - public partial class CPortAudio - { - #region **** PORTAUDIO DATA STRUCTURES **** - [StructLayout(LayoutKind.Sequential)] - public struct SPaAsioStreamInfo - { - public ulong Size; /**< sizeof(PaAsioStreamInfo) */ - public int HostApiType; /**< paASIO */ - public ulong Version; /**< 1 */ - public ulong Flags; - - /// Support for opening only specific channels of an ASIO device. - /// If the paAsioUseChannelSelectors flag is set, channelSelectors is a - /// pointer to an array of integers specifying the device channels to use. - /// When used, the length of the channelSelectors array must match the - /// corresponding channelCount parameter to Pa_OpenStream() otherwise a - /// crash may result. - /// The values in the selectors array must specify channels within the - /// range of supported channels for the device or paInvalidChannelCount will - /// result. - private readonly IntPtr _ChannelSelectors; - } - #endregion - - #region **** PORTAUDIO DEFINES **** - public const int PaAsioUseChannelSelectors = 0x01; - #endregion - - #region **** PORTAUDIO FUNCTIONS **** - // /// Retrieve legal latency settings for the specificed device, in samples. - // /// The global index of the device about which the query is being made. - // /// A pointer to the location which will recieve the minimum latency value. - // /// A pointer to the location which will recieve the maximum latency value. - // /// A pointer to the location which will recieve the preferred latency value. - // /// A pointer to the location which will recieve the granularity. This value - // /// determines which values between minLatency and maxLatency are available. ie the step size, - // /// if granularity is -1 then available latency settings are powers of two. - // /// See ASIOGetBufferSize in the ASIO SDK. - // PaError PaAsio_GetAvailableLatencyValues( PaDeviceIndex device, long *minLatency, long *maxLatency, - // long *preferredLatency, long *granularity ); - - /// Display the ASIO control panel for the specified device. - /// The global index of the device whose control panel is to be displayed. - /// - /// On Windows, the calling application's main window handle, - /// on Macintosh this value should be zero. - /// - [DllImport("PortAudio.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern EPaError PaAsio_ShowControlPanel(int device, IntPtr systemSpecific); - - // /// Retrieve a pointer to a string containing the name of the specified input channel. - // /// The string is valid until Pa_Terminate is called. - // /// The string will be no longer than 32 characters including the null terminator. - // PaError PaAsio_GetInputChannelName(PaDeviceIndex device, int channelIndex, const char** channelName ); - - // /// Retrieve a pointer to a string containing the name of the specified input channel. - // /// The string is valid until Pa_Terminate is called. - // /// The string will be no longer than 32 characters including the null terminator. - // PaError PaAsio_GetOutputChannelName( PaDeviceIndex device, int channelIndex, const char** channelName ); - - /// Set the sample rate of an open paASIO stream. - /// - /// The stream to operate on. - /// - /// The new sample rate. - /// Note that this function may fail if the stream is alredy running and the - /// ASIO driver does not support switching the sample rate of a running stream. - /// paIncompatibleStreamHostApi if stream is not a paASIO stream. - [DllImport("PortAudio.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern EPaError PaAsio_SetStreamSampleRate(IntPtr stream, double sampleRate); - #endregion - } -} \ No newline at end of file diff --git a/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs b/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs index 0ad3e00b..3851b485 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs @@ -1,8 +1,28 @@ -using System; +#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.Runtime.InteropServices; namespace Vocaluxe.Lib.Video.Acinerella { + // ReSharper disable UnusedMember.Global public enum EACStreamType : sbyte { /*The type of the media stream is not known. This kind of stream can not be @@ -32,12 +52,14 @@ namespace Vocaluxe.Lib.Video.Acinerella ACOutputBGra32 = 3 } + // ReSharper disable MemberCanBePrivate.Global + // Contains information about the whole file/stream that has been opened. Default // values are "" for strings and -1 for integer values. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct SACFileInfo { - public Int64 Duration; + public readonly Int64 Duration; } // TAc_instance represents an Acinerella instance. Each instance can open and @@ -47,12 +69,12 @@ namespace Vocaluxe.Lib.Video.Acinerella public struct SACInstance { //If true, the instance currently opened a media file - public bool Opened; + public readonly bool Opened; //Contains the count of streams the media file has. This value is available //after calling the ac_open function. - public Int32 StreamCount; + public readonly Int32 StreamCount; //Set this value to change the image output format - public EACOutputFormat OutputFormat; + public readonly EACOutputFormat OutputFormat; //Contains information about the opened stream/file public SACFileInfo Info; } @@ -62,11 +84,11 @@ namespace Vocaluxe.Lib.Video.Acinerella public struct SACAudioStreamInfo { //Samples per second. Default values are 44100 or 48000. - public Int32 SamplesPerSecond; + public readonly Int32 SamplesPerSecond; //Bits per sample. Can be 8 or 16 Bit. - public Int32 BitDepth; + public readonly Int32 BitDepth; //Count of channels in the audio stream. - public Int32 ChannelCount; + public readonly Int32 ChannelCount; } // Contains information about an Acinerella video stream. @@ -74,13 +96,13 @@ namespace Vocaluxe.Lib.Video.Acinerella public struct SACVideoStreamInfo { //The width of one frame. - public Int32 FrameWidth; + public readonly Int32 FrameWidth; //The height of one frame. - public Int32 FrameHeight; + public readonly Int32 FrameHeight; //The width of one pixel. 1.07 for 4:3 format, 1,42 for the 16:9 format - public float PixelAspect; + public readonly float PixelAspect; //Frames per second that should be played. - public double FramesPerSecond; + public readonly double FramesPerSecond; } // Contains information about an Acinerella stream. @@ -88,7 +110,8 @@ namespace Vocaluxe.Lib.Video.Acinerella public struct SACStreamInfo { //Contains the type of the stream. - public EACStreamType StreamType; + public readonly EACStreamType StreamType; + //Additional info about the stream public SACAudioStreamInfo AudioInfo; public SACVideoStreamInfo VideoInfo; @@ -101,22 +124,22 @@ namespace Vocaluxe.Lib.Video.Acinerella //Pointer on the Acinerella instance private readonly IntPtr _ACInstancePtr; //Contains the type of the decoder. - public EACDecoderType DecType; + public readonly EACDecoderType DecType; //The timecode of the currently decoded picture in seconds. - public double Timecode; + public readonly double Timecode; - public double VideoClock; + public readonly double VideoClock; //Contains information about the stream the decoder is attached to. public SACStreamInfo StreamInfo; //The index of the stream the decoder is attached to. - public Int32 StreamIndex; + public readonly Int32 StreamIndex; //Pointer to the buffer which contains the data. internal IntPtr Buffer; //Size of the data in the buffer. - public Int32 BufferSize; + public readonly Int32 BufferSize; } // Contains information about an Acinerella package. @@ -124,9 +147,11 @@ namespace Vocaluxe.Lib.Video.Acinerella public struct SACPackage { //The stream the package belongs to. - public Int32 StreamIndex; + public readonly Int32 StreamIndex; } + // ReSharper restore MemberCanBePrivate.Global + // Callback function used to ask the application to read data. Should return // the number of bytes read or an value smaller than zero if an error occured. //TAc_read_callback = function(sender: Pointer; byte[] buf, int size): integer; cdecl; @@ -254,7 +279,9 @@ namespace Vocaluxe.Lib.Video.Acinerella string filename ); + // ReSharper disable UnusedMethodReturnValue.Global public static Int32 AcOpen2( + // ReSharper restore UnusedMethodReturnValue.Global IntPtr pAcInstance, string filename ) @@ -314,7 +341,6 @@ namespace Vocaluxe.Lib.Video.Acinerella [DllImport(_AcDll, EntryPoint = "ac_free_package", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] public static extern void ac_free_package(IntPtr pAcPackage); - [DllImport(_AcDll, EntryPoint = "ac_create_video_decoder", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] private static extern IntPtr _ac_create_video_decoder(IntPtr pAcInstance); @@ -405,7 +431,9 @@ namespace Vocaluxe.Lib.Video.Acinerella [DllImport(_AcDll, EntryPoint = "ac_seek", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] private static extern Int32 _ac_seek(IntPtr pAcDecoder, Int32 dir, Int64 targetPos); + // ReSharper disable UnusedMethodReturnValue.Global public static Int32 AcSeek(IntPtr pAcDecoder, Int32 dir, Int64 targetPos) + // ReSharper restore UnusedMethodReturnValue.Global { lock (_Lock) { @@ -423,4 +451,6 @@ namespace Vocaluxe.Lib.Video.Acinerella out Int32 scoreMax ); } + + // ReSharper restore UnusedMember.Global } \ No newline at end of file diff --git a/Vocaluxe/Lib/Video/CVideoDecoder.cs b/Vocaluxe/Lib/Video/CVideoDecoder.cs index 9956ee48..53d96bef 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoder.cs @@ -1,4 +1,24 @@ -using System.Collections.Generic; +#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.Collections.Generic; +using System.Linq; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video @@ -6,7 +26,7 @@ namespace Vocaluxe.Lib.Video abstract class CVideoDecoder : IVideoDecoder { protected List _Streams = new List(); - protected bool _Initialized = false; + protected bool _Initialized; public virtual bool Init() { @@ -38,10 +58,7 @@ namespace Vocaluxe.Lib.Video return 0f; } - public virtual bool GetFrame(int streamID, ref STexture frame, float time, ref float videoTime) - { - return true; - } + public abstract bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime); public virtual bool Skip(int streamID, float start, float gap) { @@ -63,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/CVideoDecoderFFmpeg.cs b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs index faf7fa14..135d3129 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.IO; @@ -48,7 +67,6 @@ namespace Vocaluxe.Lib.Video { _Decoder.Add(decoder); stream.Handle = _Count++; - stream.File = videoFileName; _Streams.Add(stream); return stream.Handle; } @@ -72,14 +90,15 @@ namespace Vocaluxe.Lib.Video return false; } - public override bool GetFrame(int streamID, ref STexture frame, float time, ref float videoTime) + public override bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime) { + videoTime = 0; if (_Initialized) { lock (_MutexDecoder) { if (_AlreadyAdded(streamID)) - return _Decoder[_GetStreamIndex(streamID)].GetFrame(ref frame, time, ref videoTime); + return _Decoder[_GetStreamIndex(streamID)].GetFrame(ref frame, time, out videoTime); } } return false; @@ -212,7 +231,6 @@ namespace Vocaluxe.Lib.Video private bool _Paused; private bool _NoMoreFrames; - private bool _Finished; private bool _BeforeLoop; private int _Width; @@ -220,7 +238,6 @@ namespace Vocaluxe.Lib.Video private float _SetTime; private float _SetGap; private float _SetStart; - private bool _SetLoop; private bool _SetSkip; private bool _Terminated; @@ -245,18 +262,11 @@ namespace Vocaluxe.Lib.Video public float Length { - get - { - if (_FileOpened) - return _Duration; - - return 0f; - } + get { return _FileOpened ? _Duration : 0f; } } public bool Paused { - get { return _Paused; } set { lock (_MutexSyncSignals) @@ -270,16 +280,9 @@ namespace Vocaluxe.Lib.Video } } - public bool Loop - { - get { return _SetLoop; } - set { _SetLoop = value; } - } + public bool Loop { private get; set; } - public bool Finished - { - get { return _Finished; } - } + public bool Finished { get; private set; } public bool Open(string fileName) { @@ -296,15 +299,16 @@ namespace Vocaluxe.Lib.Video return true; } - public bool GetFrame(ref STexture frame, float time, ref float videoTime) + public bool GetFrame(ref STexture frame, float time, out float videoTime) { + videoTime = 0; if (!_FileOpened) return false; if (_Paused) return false; - if (_SetLoop) + if (Loop) { lock (_MutexSyncSignals) { @@ -322,7 +326,7 @@ namespace Vocaluxe.Lib.Video return true; } - if (_SetTime != time) + if (Math.Abs(_SetTime - time) > float.Epsilon) { lock (_MutexSyncSignals) { @@ -344,7 +348,7 @@ namespace Vocaluxe.Lib.Video _SetGap = gap; _SetSkip = true; _NoMoreFrames = false; - _Finished = false; + Finished = false; } //EventDecode.Set(); return true; @@ -422,7 +426,7 @@ namespace Vocaluxe.Lib.Video _SetSkip = false; _Gap = _SetGap; _Start = _SetStart; - _Loop = _SetLoop; + _Loop = Loop; } if (_Skip) @@ -442,7 +446,7 @@ namespace Vocaluxe.Lib.Video private void _DoOpen() { - bool ok = false; + bool ok; SACInstance instance = new SACInstance(); try { @@ -467,7 +471,7 @@ namespace Vocaluxe.Lib.Video _Duration = instance.Info.Duration / 1000f; - int videoStreamIndex = -1; + int videoStreamIndex; SACDecoder videodecoder; try { @@ -522,9 +526,7 @@ namespace Vocaluxe.Lib.Video float myTime = _Time + _VideoSkipTime; float timeDifference = myTime - _VideoDecoderTime; - bool dropFrame = false; - if (timeDifference >= (framedropcount - 1) * _VideoTimeBase) - dropFrame = true; + bool dropFrame = timeDifference >= (framedropcount - 1) * _VideoTimeBase; if (_Terminated) return; @@ -591,7 +593,6 @@ namespace Vocaluxe.Lib.Video } else _NoMoreFrames = true; - return; } else { @@ -660,7 +661,7 @@ namespace Vocaluxe.Lib.Video if (num >= 0) { - if (frame.Index == -1 || _Width != frame.Width || _Height != frame.Height) + if (frame.Index == -1 || _Width != (int)frame.Width || _Height != (int)frame.Height) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(_Width, _Height, ref _FrameBuffer[num].Data); @@ -672,12 +673,12 @@ namespace Vocaluxe.Lib.Video { _CurrentVideoTime = _FrameBuffer[num].Time; } - _Finished = false; + Finished = false; } else { if (_NoMoreFrames) - _Finished = true; + Finished = true; } } } @@ -725,8 +726,6 @@ namespace Vocaluxe.Lib.Video } #endregion Threading - public void Dispose() - { - } + public void Dispose() {} } } \ No newline at end of file diff --git a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs index 079229d5..ac5b15cf 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs @@ -1,4 +1,23 @@ -using System; +#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 Vocaluxe.Base; using Vocaluxe.Lib.Video.Gstreamer; using VocaluxeLib.Menu; @@ -8,7 +27,7 @@ namespace Vocaluxe.Lib.Video class CVideoDecoderGstreamer : IVideoDecoder { #region log - public CGstreamerVideoWrapper.LogCallback Log; + private CGstreamerVideoWrapper.LogCallback _Log; private void _LogHandler(string text) { @@ -19,10 +38,10 @@ namespace Vocaluxe.Lib.Video public bool Init() { bool retval = CGstreamerVideoWrapper.InitVideo(); - Log = _LogHandler; + _Log = _LogHandler; //Really needed? CodeAnalysis complains //GC.SuppressFinalize(Log); - CGstreamerVideoWrapper.SetVideoLogCallback(Log); + CGstreamerVideoWrapper.SetVideoLogCallback(_Log); return retval; } @@ -59,7 +78,7 @@ namespace Vocaluxe.Lib.Video return CGstreamerVideoWrapper.GetVideoLength(streamID); } - public bool GetFrame(int streamID, ref STexture frame, float time, ref float videoTime) + public bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime) { SManagedFrame managedFrame = CGstreamerVideoWrapper.GetFrame(streamID, time); videoTime = managedFrame.Videotime; @@ -102,7 +121,7 @@ namespace Vocaluxe.Lib.Video { if (data != null) { - if (frame.Index == -1 || width != frame.Width || height != frame.Height || data.Length == 0) + if (frame.Index == -1 || width != (int)frame.Width || height != (int)frame.Height || data.Length == 0) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(width, height, ref data); diff --git a/Vocaluxe/Lib/Video/Gstreamer/CGstreamerVideoWrapper.cs b/Vocaluxe/Lib/Video/Gstreamer/CGstreamerVideoWrapper.cs index d58f4fa6..88c634d3 100644 --- a/Vocaluxe/Lib/Video/Gstreamer/CGstreamerVideoWrapper.cs +++ b/Vocaluxe/Lib/Video/Gstreamer/CGstreamerVideoWrapper.cs @@ -1,21 +1,41 @@ -using System; +#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.Runtime.InteropServices; namespace Vocaluxe.Lib.Video.Gstreamer { public struct SNativeFrame { + // ReSharper disable UnassignedField.Global internal IntPtr Buffer; public int Size; public int Width; public int Height; public float Videotime; + // ReSharper restore UnassignedField.Global } public struct SManagedFrame { public byte[] Buffer; - public int Size; public int Width; public int Height; public float Videotime; @@ -81,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/Video/IVideoDecoder.cs b/Vocaluxe/Lib/Video/IVideoDecoder.cs index d81dce74..4dc3905a 100644 --- a/Vocaluxe/Lib/Video/IVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/IVideoDecoder.cs @@ -1,4 +1,22 @@ -using System; +#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 VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video @@ -6,12 +24,10 @@ namespace Vocaluxe.Lib.Video struct SVideoStreams { public int Handle; - public string File; public SVideoStreams(int stream) { Handle = stream; - File = String.Empty; } } @@ -25,7 +41,7 @@ namespace Vocaluxe.Lib.Video int GetNumStreams(); float GetLength(int streamID); - bool GetFrame(int streamID, ref STexture frame, float time, ref float videoTime); + bool GetFrame(int streamID, ref STexture frame, float time, out float videoTime); bool Skip(int streamID, float start, float gap); void SetLoop(int streamID, bool loop); void Pause(int streamID); diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 72712685..c53b16c6 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -1,4 +1,23 @@ -using AForge.Video; +#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 AForge.Video; using AForge.Video.DirectShow; using System.Collections.Generic; using System.Drawing; @@ -37,7 +56,7 @@ namespace Vocaluxe.Lib.Webcam { lock (_MutexData) { - if (frame.Index == -1 || _Width != frame.Width || _Height != frame.Height) + if (frame.Index == -1 || _Width != (int)frame.Width || _Height != (int)frame.Height) { CDraw.RemoveTexture(ref frame); frame = CDraw.AddTexture(_Width, _Height, ref _Data); @@ -62,33 +81,29 @@ namespace Vocaluxe.Lib.Webcam return bmp; } } - else - return null; + return null; } 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); - for (int i = 0; i < tmpdev.VideoCapabilities.Length; i++) + foreach (VideoCapabilities capabilities in tmpdev.VideoCapabilities) { SCapabilities item = new SCapabilities { - Framerate = tmpdev.VideoCapabilities[i].FrameRate, - Height = tmpdev.VideoCapabilities[i].FrameSize.Height, - Width = tmpdev.VideoCapabilities[i].FrameSize.Width + Framerate = capabilities.FrameRate, + Height = capabilities.FrameSize.Height, + Width = capabilities.FrameSize.Width }; device.Capabilities.Add(item); } @@ -144,6 +159,11 @@ namespace Vocaluxe.Lib.Webcam return _Devices.ToArray(); } + public bool IsDeviceAvailable() + { + return _Devices.Count > 0; + } + public bool Select(SWebcamConfig config) { //Close old camera connection @@ -155,10 +175,7 @@ namespace Vocaluxe.Lib.Webcam return false; //No MonikerString found, try first webcam - if (config.MonikerString.Length == 0) - _Webcam = new VideoCaptureDevice(_WebcamDevices[0].MonikerString); - else //Found MonikerString - _Webcam = new VideoCaptureDevice(config.MonikerString); + _Webcam = config.MonikerString == "" ? new VideoCaptureDevice(_WebcamDevices[0].MonikerString) : new VideoCaptureDevice(config.MonikerString); if (_Webcam == null) return false; diff --git a/Vocaluxe/Lib/Webcam/IWebcam.cs b/Vocaluxe/Lib/Webcam/IWebcam.cs index 8b0ecc1c..32804bfc 100644 --- a/Vocaluxe/Lib/Webcam/IWebcam.cs +++ b/Vocaluxe/Lib/Webcam/IWebcam.cs @@ -1,4 +1,23 @@ -using System.Collections.Generic; +#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.Collections.Generic; using System.Drawing; using VocaluxeLib.Menu; @@ -6,7 +25,6 @@ namespace Vocaluxe.Lib.Webcam { struct SWebcamDevice { - public int ID; public string Name; public string MonikerString; public List Capabilities; @@ -40,6 +58,7 @@ namespace Vocaluxe.Lib.Webcam Bitmap GetBitmap(); SWebcamConfig GetConfig(); SWebcamDevice[] GetDevices(); + bool IsDeviceAvailable(); bool Select(SWebcamConfig webcamConfig); } diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index bb715000..34c5f627 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -114,7 +114,7 @@ namespace Vocaluxe // Init Playback CLog.StartBenchmark(0, "Init Playback"); - CSound.PlaybackInit(); + CSound.Init(); CLog.StopBenchmark(0, "Init Playback"); Application.DoEvents(); @@ -185,6 +185,7 @@ namespace Vocaluxe // Init Input CLog.StartBenchmark(0, "Init Input"); CInput.Init(); + CInput.Connect(); CLog.StopBenchmark(0, "Init Input"); // Init Game; @@ -252,13 +253,12 @@ namespace Vocaluxe string[] arr = args.Name.Split(new char[] {','}); if (arr.Length > 0) { - #if ARCH_X86 - string path="x86"; + string path = "x86"; #endif #if ARCH_X64 - string path="x64"; + string path = "x64"; #endif path = Path.Combine(path, arr[0] + ".dll"); try @@ -277,7 +277,7 @@ namespace Vocaluxe } catch (Exception e) { - CLog.LogError("Cannot load assembly "+args.Name+" from "+path+": "+e); + CLog.LogError("Cannot load assembly " + args.Name + " from " + path + ": " + e); } } return null; diff --git a/Vocaluxe/Properties/AssemblyInfo.cs b/Vocaluxe/Properties/AssemblyInfo.cs index 8b5da9e1..7f74a4d8 100644 --- a/Vocaluxe/Properties/AssemblyInfo.cs +++ b/Vocaluxe/Properties/AssemblyInfo.cs @@ -1,9 +1,29 @@ -using System.Reflection; +#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.Reflection; using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // die mit einer Assembly verknüpft sind. + [assembly: AssemblyTitle("Vocaluxe")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] @@ -16,9 +36,11 @@ using System.Runtime.InteropServices; // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. + [assembly: ComVisible(false)] // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird + [assembly: Guid("da631594-f891-4994-9869-c37e626e44f9")] // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: @@ -28,5 +50,6 @@ using System.Runtime.InteropServices; // Buildnummer // Revision // -[assembly: AssemblyVersion("0.3.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file + +[assembly: AssemblyVersion("0.3.0.78")] +[assembly: AssemblyFileVersion("0.3.0.78")] \ No newline at end of file diff --git a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs index dbdae6c9..023ee4e2 100644 --- a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs +++ b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs @@ -1,5 +1,23 @@ -using System; -using System.Collections.Generic; +#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.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -72,23 +90,14 @@ namespace Vocaluxe.Screens _ThemeStatics = new string[] {_StaticBG, _StaticCover}; _ThemeTexts = new string[] {_TextCurrentSong}; - List buttons = new List(); - buttons.Add(_ButtonPlay); - buttons.Add(_ButtonPause); - buttons.Add(_ButtonPrevious); - buttons.Add(_ButtonNext); - buttons.Add(_ButtonRepeat); - buttons.Add(_ButtonShowVideo); - buttons.Add(_ButtonSing); - buttons.Add(_ButtonToBackgroundVideo); - _ThemeButtons = buttons.ToArray(); + _ThemeButtons = new string[] {_ButtonPlay, _ButtonPause, _ButtonPrevious, _ButtonNext, _ButtonRepeat, _ButtonShowVideo, _ButtonSing, _ButtonToBackgroundVideo}; } public override void LoadTheme(string xmlPath) { base.LoadTheme(xmlPath); - _ScreenArea = Statics[_StaticBG].Rect; + _ScreenArea = _Statics[_StaticBG].Rect; } public override bool HandleInput(SKeyEvent keyEvent) @@ -105,21 +114,21 @@ namespace Vocaluxe.Screens return false; case Keys.Enter: - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) CBackgroundMusic.Next(); - if (Buttons[_ButtonPrevious].Selected) + if (_Buttons[_ButtonPrevious].Selected) CBackgroundMusic.Previous(); - if (Buttons[_ButtonPlay].Selected) + if (_Buttons[_ButtonPlay].Selected) CBackgroundMusic.Play(); - if (Buttons[_ButtonPause].Selected) + if (_Buttons[_ButtonPause].Selected) CBackgroundMusic.Pause(); - if (Buttons[_ButtonRepeat].Selected) + if (_Buttons[_ButtonRepeat].Selected) CBackgroundMusic.RepeatSong = !CBackgroundMusic.RepeatSong; - if (Buttons[_ButtonShowVideo].Selected) + if (_Buttons[_ButtonShowVideo].Selected) _VideoPreview = !_VideoPreview; - if (Buttons[_ButtonSing].Selected) - _StartSong(CBackgroundMusic.SongID, CBackgroundMusic.Duet); - if (Buttons[_ButtonToBackgroundVideo].Selected) + if (_Buttons[_ButtonSing].Selected) + _StartSong(CBackgroundMusic.SongID); + if (_Buttons[_ButtonToBackgroundVideo].Selected) _VideoBackground = !_VideoBackground; break; } @@ -131,23 +140,23 @@ namespace Vocaluxe.Screens public override bool HandleMouse(SMouseEvent mouseEvent) { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonNext].Selected) + if (_Buttons[_ButtonNext].Selected) CBackgroundMusic.Next(); - if (Buttons[_ButtonPrevious].Selected) + if (_Buttons[_ButtonPrevious].Selected) CBackgroundMusic.Previous(); - if (Buttons[_ButtonPlay].Selected) + if (_Buttons[_ButtonPlay].Selected) CBackgroundMusic.Play(); - if (Buttons[_ButtonPause].Selected) + if (_Buttons[_ButtonPause].Selected) CBackgroundMusic.Pause(); - if (Buttons[_ButtonRepeat].Selected) + if (_Buttons[_ButtonRepeat].Selected) CBackgroundMusic.RepeatSong = !CBackgroundMusic.RepeatSong; - if (Buttons[_ButtonShowVideo].Selected) + if (_Buttons[_ButtonShowVideo].Selected) _VideoPreview = !_VideoPreview; - if (Buttons[_ButtonSing].Selected) - _StartSong(CBackgroundMusic.SongID, CBackgroundMusic.Duet); - if (Buttons[_ButtonToBackgroundVideo].Selected) + if (_Buttons[_ButtonSing].Selected) + _StartSong(CBackgroundMusic.SongID); + if (_Buttons[_ButtonToBackgroundVideo].Selected) _VideoBackground = !_VideoBackground; } else if (mouseEvent.LB) @@ -165,11 +174,11 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { - Statics[_StaticCover].Visible = !_VideoPreviewInt || !CBackgroundMusic.SongHasVideo; - Buttons[_ButtonToBackgroundVideo].Pressed = _VideoBackground; - Buttons[_ButtonShowVideo].Pressed = _VideoPreviewInt; - Buttons[_ButtonRepeat].Pressed = CBackgroundMusic.RepeatSong; - Buttons[_ButtonSing].Visible = CBackgroundMusic.CanSing && CParty.CurrentPartyModeID == -1; + _Statics[_StaticCover].Visible = !_VideoPreviewInt || !CBackgroundMusic.SongHasVideo; + _Buttons[_ButtonToBackgroundVideo].Pressed = _VideoBackground; + _Buttons[_ButtonShowVideo].Pressed = _VideoPreviewInt; + _Buttons[_ButtonRepeat].Pressed = CBackgroundMusic.RepeatSong; + _Buttons[_ButtonSing].Visible = CBackgroundMusic.CanSing && CParty.CurrentPartyModeID == -1; return true; } @@ -177,31 +186,30 @@ namespace Vocaluxe.Screens { if (!_Active) return false; - Statics[_StaticCover].Texture = CBackgroundMusic.Cover; + _Statics[_StaticCover].Texture = CBackgroundMusic.Cover; if (CBackgroundMusic.VideoEnabled && _VideoPreview && CBackgroundMusic.SongHasVideo) - CDraw.DrawTexture(Statics[_StaticCover], CBackgroundMusic.GetVideoTexture(), EAspect.Crop); - Buttons[_ButtonPause].Visible = CBackgroundMusic.Playing; - Buttons[_ButtonPlay].Visible = !CBackgroundMusic.Playing; - Texts[_TextCurrentSong].Text = CBackgroundMusic.ArtistAndTitle; + CDraw.DrawTexture(_Statics[_StaticCover], CBackgroundMusic.GetVideoTexture(), EAspect.Crop); + _Buttons[_ButtonPause].Visible = CBackgroundMusic.IsPlaying; + _Buttons[_ButtonPlay].Visible = !CBackgroundMusic.IsPlaying; + _Texts[_TextCurrentSong].Text = CBackgroundMusic.ArtistAndTitle; return base.Draw(); } - private void _StartSong(int songNr, bool duet) + private void _StartSong(int songNr) { - if (songNr >= 0 && CSongs.SongsLoaded) - { - CGame.Reset(); - CGame.ClearSongs(); + if (songNr < 0 || !CSongs.SongsLoaded) + return; + CGame.Reset(); + CGame.ClearSongs(); - EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; - if (CSongs.AllSongs[songNr].IsDuet) - gm = EGameMode.TR_GAMEMODE_DUET; + EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + if (CSongs.AllSongs[songNr].IsDuet) + gm = EGameMode.TR_GAMEMODE_DUET; - CGame.AddSong(songNr, gm); + CGame.AddSong(songNr, gm); - CGraphics.FadeTo(EScreens.ScreenNames); - } + CGraphics.FadeTo(EScreens.ScreenNames); } } } \ No newline at end of file diff --git a/Vocaluxe/Screens/CPopupScreenVolumeControl.cs b/Vocaluxe/Screens/CPopupScreenVolumeControl.cs index d1f477ea..b3213950 100644 --- a/Vocaluxe/Screens/CPopupScreenVolumeControl.cs +++ b/Vocaluxe/Screens/CPopupScreenVolumeControl.cs @@ -1,4 +1,23 @@ -using Vocaluxe.Base; +#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 Vocaluxe.Base; using VocaluxeLib.Menu; namespace Vocaluxe.Screens @@ -27,8 +46,8 @@ namespace Vocaluxe.Screens { base.LoadTheme(xmlPath); - _ScreenArea = Statics[_StaticBG].Rect; - SelectSlides[_SelectSlideVolume].AddValues(new string[] + _ScreenArea = _Statics[_StaticBG].Rect; + _SelectSlides[_SelectSlideVolume].AddValues(new string[] {"0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"}); } @@ -46,27 +65,25 @@ namespace Vocaluxe.Screens _SaveConfig(); return true; } - else if (mouseEvent.Wheel > 0 && CHelper.IsInBounds(_ScreenArea, mouseEvent)) + if (mouseEvent.Wheel > 0 && CHelper.IsInBounds(_ScreenArea, mouseEvent)) { - if (SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel >= 0) - SelectSlides[_SelectSlideVolume].Selection = SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel; - else if (SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel < 0) - SelectSlides[_SelectSlideVolume].Selection = 0; + if (_SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel >= 0) + _SelectSlides[_SelectSlideVolume].Selection = _SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel; + else if (_SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel < 0) + _SelectSlides[_SelectSlideVolume].Selection = 0; _SaveConfig(); return true; } - else if (mouseEvent.Wheel < 0 && CHelper.IsInBounds(_ScreenArea, mouseEvent)) + if (mouseEvent.Wheel < 0 && CHelper.IsInBounds(_ScreenArea, mouseEvent)) { - if (SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel < SelectSlides[_SelectSlideVolume].NumValues) - SelectSlides[_SelectSlideVolume].Selection = SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel; - else if (SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel >= SelectSlides[_SelectSlideVolume].NumValues) - SelectSlides[_SelectSlideVolume].Selection = SelectSlides[_SelectSlideVolume].NumValues - 1; + if (_SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel < _SelectSlides[_SelectSlideVolume].NumValues) + _SelectSlides[_SelectSlideVolume].Selection = _SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel; + else if (_SelectSlides[_SelectSlideVolume].Selection - mouseEvent.Wheel >= _SelectSlides[_SelectSlideVolume].NumValues) + _SelectSlides[_SelectSlideVolume].Selection = _SelectSlides[_SelectSlideVolume].NumValues - 1; _SaveConfig(); return true; } - else if (mouseEvent.RB) - return false; - return true; + return !mouseEvent.RB; } public override void OnShow() @@ -95,20 +112,20 @@ namespace Vocaluxe.Screens { case EScreens.ScreenSong: if (CSongs.IsInCategory) - CConfig.PreviewMusicVolume = SelectSlides[_SelectSlideVolume].Selection * 5; + CConfig.PreviewMusicVolume = _SelectSlides[_SelectSlideVolume].Selection * 5; else { - CConfig.BackgroundMusicVolume = SelectSlides[_SelectSlideVolume].Selection * 5; + CConfig.BackgroundMusicVolume = _SelectSlides[_SelectSlideVolume].Selection * 5; CBackgroundMusic.ApplyVolume(); } break; case EScreens.ScreenSing: - CConfig.GameMusicVolume = SelectSlides[_SelectSlideVolume].Selection * 5; + CConfig.GameMusicVolume = _SelectSlides[_SelectSlideVolume].Selection * 5; break; default: - CConfig.BackgroundMusicVolume = SelectSlides[_SelectSlideVolume].Selection * 5; + CConfig.BackgroundMusicVolume = _SelectSlides[_SelectSlideVolume].Selection * 5; CBackgroundMusic.ApplyVolume(); break; } @@ -121,17 +138,17 @@ namespace Vocaluxe.Screens { case EScreens.ScreenSong: if (CSongs.IsInCategory) - SelectSlides[_SelectSlideVolume].Selection = CConfig.PreviewMusicVolume / 5; + _SelectSlides[_SelectSlideVolume].Selection = CConfig.PreviewMusicVolume / 5; else - SelectSlides[_SelectSlideVolume].Selection = CConfig.BackgroundMusicVolume / 5; + _SelectSlides[_SelectSlideVolume].Selection = CConfig.BackgroundMusicVolume / 5; break; case EScreens.ScreenSing: - SelectSlides[_SelectSlideVolume].Selection = CConfig.GameMusicVolume / 5; + _SelectSlides[_SelectSlideVolume].Selection = CConfig.GameMusicVolume / 5; break; default: - SelectSlides[_SelectSlideVolume].Selection = CConfig.BackgroundMusicVolume / 5; + _SelectSlides[_SelectSlideVolume].Selection = CConfig.BackgroundMusicVolume / 5; break; } } diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index 10342170..b37fdeb3 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.Windows.Forms; @@ -115,6 +134,7 @@ namespace Vocaluxe.Screens private STexture _TexNameBrunzel; private STexture _TexNameDarkice; private STexture _TexNameFlokuep; + private STexture _TexNameFlamefire; private STexture _TexNameMesand; private STexture _TexNameBohning; private STexture _TexNameBabene03; @@ -133,13 +153,10 @@ namespace Vocaluxe.Screens _ParagraphTexts = new List(); _Paragraphs = new List(); - string paragraph; - string[] words; - - paragraph = "Inspired by the achievements of UltraStar Deluxe and its variants and pursuing the goal of making " + - "a good thing even better, we ended up rewriting the game from scratch. And a new implementation in a new " + - "programming language called for a new name - and VOCALUXE [ˈvoʊˈkəˈlʌks] it is!"; - words = paragraph.Split(new char[] {' '}); + string paragraph = "Inspired by the achievements of UltraStar Deluxe and its variants and pursuing the goal of making " + + "a good thing even better, we ended up rewriting the game from scratch. And a new implementation in a new " + + "programming language called for a new name - and VOCALUXE [ˈvoʊˈkəˈlʌks] it is!"; + string[] words = paragraph.Split(new char[] {' '}); _Paragraphs.Add(words); paragraph = "This first public version has already implemented many of the original features and it is fully " + @@ -177,6 +194,7 @@ namespace Vocaluxe.Screens CDataBase.GetCreditsRessource("brunzel.png", ref _TexNameBrunzel); CDataBase.GetCreditsRessource("Darkice.png", ref _TexNameDarkice); CDataBase.GetCreditsRessource("flokuep.png", ref _TexNameFlokuep); + CDataBase.GetCreditsRessource("flamefire.png", ref _TexNameFlamefire); CDataBase.GetCreditsRessource("bohning.png", ref _TexNameBohning); CDataBase.GetCreditsRessource("mesand.png", ref _TexNameMesand); CDataBase.GetCreditsRessource("babene03.png", ref _TexNameBabene03); @@ -185,35 +203,34 @@ namespace Vocaluxe.Screens //Prepare Text int lastY = 280; - for (int i = 0; i < _Paragraphs.Count; i++) + foreach (string[] paragraph in _Paragraphs) { string line = ""; - for (int e = 0; e < _Paragraphs[i].Length; e++) + for (int e = 0; e < paragraph.Length; e++) { - if (_Paragraphs[i][e] != null) + if (paragraph[e] == null) + continue; + string newLine = " " + paragraph[e]; + CText text = GetNewText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line); + if (CDraw.GetTextBounds(text).Width < (CSettings.RenderW - 220)) { - string newline = line + " " + _Paragraphs[i][e]; - CText text = GetNewText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line); - if (CDraw.GetTextBounds(text).Width < (CSettings.RenderW - 220)) - { - line = line + " " + _Paragraphs[i][e]; + line += newLine; - //Check if all words are used - if ((e + 1) == _Paragraphs[i].Length) - { - text.Text = line; - _ParagraphTexts.Add(text); - line = ""; - lastY += 40; - } - } - else + //Check if all words are used + if ((e + 1) == paragraph.Length) { + text.Text = line; _ParagraphTexts.Add(text); - line = " " + _Paragraphs[i][e]; - lastY += 27; + line = ""; + lastY += 40; } } + else + { + _ParagraphTexts.Add(text); + line = newLine; + lastY += 27; + } } } } @@ -257,7 +274,7 @@ namespace Vocaluxe.Screens return true; } - public CParticleEffect GetStarParticles(int numStars, bool isRed, SRectF rect, bool bigParticles) + private CParticleEffect _GetStarParticles(int numStars, bool isRed, SRectF rect, bool bigParticles) { SColorF partColor = isRed ? new SColorF(1, 0, 0, 1) : new SColorF(0.149f, 0.415f, 0.819f, 1); int partSize = bigParticles ? 35 : 25; @@ -274,10 +291,9 @@ namespace Vocaluxe.Screens CStatic image = GetNewStatic(texture, new SColorF(1, 1, 1, 1), new SRectF(-1, -1, 400, 120, -4)); SRectF particleRect = new SRectF(-1, -1, partRectSize, partRectSize, -6); - SRectF imgDotRect = new SRectF(particleRect); - imgDotRect.Z = -5; + SRectF imgDotRect = new SRectF(particleRect) {Z = -5}; CStatic imgDot = GetNewStatic(texDot, new SColorF(1, 1, 1, 1), imgDotRect); - CParticleEffect particle = GetStarParticles(partCount, isRight, particleRect, bigParticles); + CParticleEffect particle = _GetStarParticles(partCount, isRight, particleRect, bigParticles); CCreditName credit = new CCreditName(image, imgDot, particle, particleOffsetX, particleOffsetY); @@ -305,8 +321,8 @@ namespace Vocaluxe.Screens //Little stars for logo int numstars = (int)(_Logo.Rect.W * 0.25f / 2f); SRectF partRect = new SRectF(_Logo.Rect.X, _Logo.Rect.Y, _Logo.Rect.W, _Logo.Rect.H, -1); - _StarsRed = GetStarParticles(numstars, true, partRect, true); - _StarsBlue = GetStarParticles(numstars, false, partRect, true); + _StarsRed = _GetStarParticles(numstars, true, partRect, true); + _StarsBlue = _GetStarParticles(numstars, false, partRect, true); //Credit names _CreditNames = new List(); @@ -314,6 +330,7 @@ namespace Vocaluxe.Screens _AddNewCreditName(_TexNameBrunzel, 502, 29, true); _AddNewCreditName(_TexNameDarkice, 360, 55, true); _AddNewCreditName(_TexNameFlokuep, 214, 14, true); + _AddNewCreditName(_TexNameFlamefire, 496, 46, true); _AddNewCreditName(_TexNameBohning, 383, 54, false); _AddNewCreditName(_TexNameMesand, 525, 13, false); _AddNewCreditName(_TexNameBabene03, 33, 26, false); @@ -352,8 +369,8 @@ namespace Vocaluxe.Screens //Draw Text if (_TextTimer.IsRunning) { - for (int i = 0; i < _ParagraphTexts.Count; i++) - _ParagraphTexts[i].Draw(); + foreach (CText text in _ParagraphTexts) + text.Draw(); } return true; } @@ -432,7 +449,6 @@ namespace Vocaluxe.Screens //Start Text-Timer _TextTimer.Start(); - active = true; } } else if (_CreditNames[i].Y <= 360f) diff --git a/Vocaluxe/Screens/CScreenHighscore.cs b/Vocaluxe/Screens/CScreenHighscore.cs index a568d68a..b8eb3d14 100644 --- a/Vocaluxe/Screens/CScreenHighscore.cs +++ b/Vocaluxe/Screens/CScreenHighscore.cs @@ -1,5 +1,25 @@ -using System; +#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.Linq; using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -34,41 +54,39 @@ namespace Vocaluxe.Screens { base.Init(); - List texts = new List(); - texts.Add(_TextSongName); - texts.Add(_TextSongMode); + List texts = new List {_TextSongName, _TextSongMode}; _TextNumber = new string[_NumEntrys]; for (int i = 0; i < _NumEntrys; i++) { - _TextNumber[i] = "TextNumber" + (i + 1).ToString(); + _TextNumber[i] = "TextNumber" + (i + 1); texts.Add(_TextNumber[i]); } _TextName = new string[_NumEntrys]; for (int i = 0; i < _NumEntrys; i++) { - _TextName[i] = "TextName" + (i + 1).ToString(); + _TextName[i] = "TextName" + (i + 1); texts.Add(_TextName[i]); } _TextScore = new string[_NumEntrys]; for (int i = 0; i < _NumEntrys; i++) { - _TextScore[i] = "TextScore" + (i + 1).ToString(); + _TextScore[i] = "TextScore" + (i + 1); texts.Add(_TextScore[i]); } _TextDate = new string[_NumEntrys]; for (int i = 0; i < _NumEntrys; i++) { - _TextDate[i] = "TextDate" + (i + 1).ToString(); + _TextDate[i] = "TextDate" + (i + 1); texts.Add(_TextDate[i]); } _ParticleEffectNew = new string[_NumEntrys]; for (int i = 0; i < _NumEntrys; i++) - _ParticleEffectNew[i] = "ParticleEffectNew" + (i + 1).ToString(); + _ParticleEffectNew[i] = "ParticleEffectNew" + (i + 1); _ThemeTexts = texts.ToArray(); _ThemeParticleEffects = _ParticleEffectNew; @@ -112,7 +130,7 @@ namespace Vocaluxe.Screens public override bool HandleMouse(SMouseEvent mouseEvent) { - if (mouseEvent.LB && IsMouseOver(mouseEvent)) {} + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) {} if (mouseEvent.LB) _LeaveScreen(); @@ -141,34 +159,31 @@ namespace Vocaluxe.Screens { if (_Pos + p < _Scores[_Round].Count) { - Texts[_TextNumber[p]].Visible = true; - Texts[_TextName[p]].Visible = true; - Texts[_TextScore[p]].Visible = true; - Texts[_TextDate[p]].Visible = true; + _Texts[_TextNumber[p]].Visible = true; + _Texts[_TextName[p]].Visible = true; + _Texts[_TextScore[p]].Visible = true; + _Texts[_TextDate[p]].Visible = true; - Texts[_TextNumber[p]].Text = (_Pos + p + 1).ToString(); + _Texts[_TextNumber[p]].Text = (_Pos + p + 1).ToString(); string name = _Scores[_Round][_Pos + p].Name; name += " [" + CLanguage.Translate(Enum.GetName(typeof(EGameDifficulty), _Scores[_Round][_Pos + p].Difficulty)) + "]"; if (_IsDuet) - name += " (P" + (_Scores[_Round][_Pos + p].LineNr + 1).ToString() + ")"; - Texts[_TextName[p]].Text = name; + name += " (P" + (_Scores[_Round][_Pos + p].LineNr + 1) + ")"; + _Texts[_TextName[p]].Text = name; - Texts[_TextScore[p]].Text = _Scores[_Round][_Pos + p].Score.ToString("00000"); - Texts[_TextDate[p]].Text = _Scores[_Round][_Pos + p].Date; + _Texts[_TextScore[p]].Text = _Scores[_Round][_Pos + p].Score.ToString("00000"); + _Texts[_TextDate[p]].Text = _Scores[_Round][_Pos + p].Date; - if (_IsNewEntry(_Scores[_Round][_Pos + p].ID)) - ParticleEffects[_ParticleEffectNew[p]].Visible = true; - else - ParticleEffects[_ParticleEffectNew[p]].Visible = false; + _ParticleEffects[_ParticleEffectNew[p]].Visible = _IsNewEntry(_Scores[_Round][_Pos + p].ID); } else { - Texts[_TextNumber[p]].Visible = false; - Texts[_TextName[p]].Visible = false; - Texts[_TextScore[p]].Visible = false; - Texts[_TextDate[p]].Visible = false; - ParticleEffects[_ParticleEffectNew[p]].Visible = false; + _Texts[_TextNumber[p]].Visible = false; + _Texts[_TextName[p]].Visible = false; + _Texts[_TextScore[p]].Visible = false; + _Texts[_TextDate[p]].Visible = false; + _ParticleEffects[_ParticleEffectNew[p]].Visible = false; } } return true; @@ -193,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() @@ -230,7 +239,7 @@ namespace Vocaluxe.Screens for (int round = 0; round < points.NumRounds; round++) { SPlayer player = points.GetPlayer(round, CGame.NumPlayer)[0]; - CDataBase.LoadScore(ref _Scores[round], player); + CDataBase.LoadScore(out _Scores[round], player); } } @@ -238,36 +247,35 @@ namespace Vocaluxe.Screens { _IsDuet = false; CPoints points = CGame.GetPoints(); - SPlayer player = points.GetPlayer(_Round, CGame.NumPlayer)[0]; CSong song = CGame.GetSong(_Round + 1); if (song == null) return; - Texts[_TextSongName].Text = song.Artist + " - " + song.Title; + _Texts[_TextSongName].Text = song.Artist + " - " + song.Title; if (points.NumRounds > 1) - Texts[_TextSongName].Text += " (" + (_Round + 1) + "/" + points.NumRounds + ")"; + _Texts[_TextSongName].Text += " (" + (_Round + 1) + "/" + points.NumRounds + ")"; switch (CGame.GetGameMode(_Round)) { case EGameMode.TR_GAMEMODE_NORMAL: - Texts[_TextSongMode].Text = "TR_GAMEMODE_NORMAL"; + _Texts[_TextSongMode].Text = "TR_GAMEMODE_NORMAL"; break; case EGameMode.TR_GAMEMODE_MEDLEY: - Texts[_TextSongMode].Text = "TR_GAMEMODE_MEDLEY"; + _Texts[_TextSongMode].Text = "TR_GAMEMODE_MEDLEY"; break; case EGameMode.TR_GAMEMODE_DUET: - Texts[_TextSongMode].Text = "TR_GAMEMODE_DUET"; + _Texts[_TextSongMode].Text = "TR_GAMEMODE_DUET"; _IsDuet = true; break; case EGameMode.TR_GAMEMODE_SHORTSONG: - Texts[_TextSongMode].Text = "TR_GAMEMODE_SHORTSONG"; + _Texts[_TextSongMode].Text = "TR_GAMEMODE_SHORTSONG"; break; default: - Texts[_TextSongMode].Text = "TR_GAMEMODE_NORMAL"; + _Texts[_TextSongMode].Text = "TR_GAMEMODE_NORMAL"; break; } diff --git a/Vocaluxe/Screens/CScreenLoad.cs b/Vocaluxe/Screens/CScreenLoad.cs index 3e81c722..1f25f6d1 100644 --- a/Vocaluxe/Screens/CScreenLoad.cs +++ b/Vocaluxe/Screens/CScreenLoad.cs @@ -1,4 +1,23 @@ -using System.Diagnostics; +#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.Diagnostics; using System.Threading; using System.Windows.Forms; using Vocaluxe.Base; @@ -13,7 +32,6 @@ namespace Vocaluxe.Screens { get { return 1; } } - private const float _WaitTime = 0.5f; //wait time before starting first video private const string _TextStatus = "TextStatus"; @@ -84,12 +102,11 @@ namespace Vocaluxe.Screens } } - _SongLoaderThread = new Thread(CSongs.LoadSongs); - _SongLoaderThread.Name = "SongLoader"; + _SongLoaderThread = new Thread(CSongs.LoadSongs) {Name = "SongLoader"}; - Texts[_TextStatus].Text = CLanguage.Translate("TR_SCREENLOAD_TOTAL") + ": 0 " + - CLanguage.Translate("TR_SCREENLOAD_SONGS") + " (0 " + - CLanguage.Translate("TR_SCREENLOAD_LOADED") + ")"; + _Texts[_TextStatus].Text = CLanguage.Translate("TR_SCREENLOAD_TOTAL") + ": 0 " + + CLanguage.Translate("TR_SCREENLOAD_SONGS") + " (0 " + + CLanguage.Translate("TR_SCREENLOAD_LOADED") + ")"; _SkipIntro = false; _CurrentIntroVideoNr = -1; @@ -110,8 +127,8 @@ namespace Vocaluxe.Screens if (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON) { - for (int i = 0; i < _Intros.Length; i++) - _Intros[i].PreLoad(); + foreach (CVideoPlayer videoPlayer in _Intros) + videoPlayer.PreLoad(); } CLog.StartBenchmark(0, "Load Songs Full"); @@ -124,7 +141,7 @@ namespace Vocaluxe.Screens { CBackgroundMusic.AddOwnMusic(); - if (!CBackgroundMusic.Playing) + if (!CBackgroundMusic.IsPlaying) CBackgroundMusic.Next(); _BGMusicStartet = true; @@ -150,8 +167,8 @@ namespace Vocaluxe.Screens if (CSettings.GameState == EGameState.Normal) CGraphics.FadeTo(EScreens.ScreenMain); - Texts[_TextStatus].Text = - CLanguage.Translate("TR_SCREENLOAD_TOTAL") + ": " + CSongs.NumAllSongs.ToString() + " " + + _Texts[_TextStatus].Text = + CLanguage.Translate("TR_SCREENLOAD_TOTAL") + ": " + CSongs.NumAllSongs + " " + CLanguage.Translate("TR_SCREENLOAD_SONGS") + " (" + CSongs.NumSongsWithCoverLoaded + " " + CLanguage.Translate("TR_SCREENLOAD_LOADED") + ")"; @@ -160,7 +177,7 @@ namespace Vocaluxe.Screens { CBackgroundMusic.AddOwnMusic(); - if (!CBackgroundMusic.Playing) + if (!CBackgroundMusic.IsPlaying) CBackgroundMusic.Next(); _BGMusicStartet = true; @@ -171,12 +188,12 @@ namespace Vocaluxe.Screens public override bool Draw() { - DrawBG(); + _DrawBG(); - for (int i = 0; i < _Intros.Length; i++) - _Intros[i].Draw(); + foreach (CVideoPlayer videoPlayer in _Intros) + videoPlayer.Draw(); - DrawFG(); + _DrawFG(); return true; } @@ -186,8 +203,8 @@ namespace Vocaluxe.Screens _Timer.Stop(); _Timer.Reset(); - for (int i = 0; i < _Intros.Length; i++) - _Intros[i].Close(); + foreach (CVideoPlayer videoPlayer in _Intros) + videoPlayer.Close(); CBackgroundMusic.CanSing = true; diff --git a/Vocaluxe/Screens/CScreenMain.cs b/Vocaluxe/Screens/CScreenMain.cs index e9a4ac57..807ec508 100644 --- a/Vocaluxe/Screens/CScreenMain.cs +++ b/Vocaluxe/Screens/CScreenMain.cs @@ -1,4 +1,23 @@ -using System.Windows.Forms; +#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.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -53,22 +72,22 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonSing].Selected) + if (_Buttons[_ButtonSing].Selected) { CParty.SetNormalGameMode(); CGraphics.FadeTo(EScreens.ScreenSong); } - if (Buttons[_ButtonParty].Selected) + if (_Buttons[_ButtonParty].Selected) CGraphics.FadeTo(EScreens.ScreenParty); - if (Buttons[_ButtonOptions].Selected) + if (_Buttons[_ButtonOptions].Selected) CGraphics.FadeTo(EScreens.ScreenOptions); - if (Buttons[_ButtonProfiles].Selected) + if (_Buttons[_ButtonProfiles].Selected) CGraphics.FadeTo(EScreens.ScreenProfiles); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) return false; break; @@ -81,30 +100,31 @@ namespace Vocaluxe.Screens { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonSing].Selected) + if (_Buttons[_ButtonSing].Selected) { CParty.SetNormalGameMode(); CGraphics.FadeTo(EScreens.ScreenSong); } - if (Buttons[_ButtonParty].Selected) + if (_Buttons[_ButtonParty].Selected) CGraphics.FadeTo(EScreens.ScreenParty); - if (Buttons[_ButtonOptions].Selected) + if (_Buttons[_ButtonOptions].Selected) CGraphics.FadeTo(EScreens.ScreenOptions); - if (Buttons[_ButtonProfiles].Selected) + if (_Buttons[_ButtonProfiles].Selected) CGraphics.FadeTo(EScreens.ScreenProfiles); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) return false; } return true; } + // ReSharper disable RedundantOverridenMember public override void OnShow() { base.OnShow(); @@ -113,6 +133,8 @@ namespace Vocaluxe.Screens // Snowflakes.Resume(); } + // ReSharper restore RedundantOverridenMember + public override bool UpdateGame() { return true; @@ -120,16 +142,18 @@ namespace Vocaluxe.Screens public override bool Draw() { - DrawBG(); + _DrawBG(); //if (Snowflakes == null) // Snowflakes = new CParticleEffect(300, new SColorF(1, 1, 1, 1), new SRectF(0, 0, CSettings.iRenderW, 0, 0.5f), "Snowflake", 25, EParticeType.Snow); //Snowflakes.Update(); //Snowflakes.Draw(); - DrawFG(); + _DrawFG(); + // ReSharper disable ConditionIsAlwaysTrueOrFalse if (CSettings.VersionRevision != ERevision.Release) + // ReSharper restore ConditionIsAlwaysTrueOrFalse { CFonts.SetFont("Normal"); CFonts.Style = EStyle.Normal; @@ -139,6 +163,7 @@ namespace Vocaluxe.Screens return true; } + // ReSharper disable RedundantOverridenMember public override void OnClose() { base.OnClose(); @@ -146,5 +171,7 @@ namespace Vocaluxe.Screens //if (Snowflakes != null) // Snowflakes.Pause(); } + + // ReSharper restore RedundantOverridenMember } } \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 064c9b7d..9f7fc909 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -1,4 +1,23 @@ -using System; +#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.Windows.Forms; using Vocaluxe.Base; @@ -36,37 +55,30 @@ namespace Vocaluxe.Screens {"SelectSlideDuetPlayer1", "SelectSlideDuetPlayer2", "SelectSlideDuetPlayer3", "SelectSlideDuetPlayer4", "SelectSlideDuetPlayer5", "SelectSlideDuetPlayer6"}; private readonly STexture[] _OriginalPlayerAvatarTextures = new STexture[CSettings.MaxNumPlayer]; - private bool _SelectingMouseActive; private bool _SelectingKeyboardActive; private bool _SelectingKeyboardUnendless; private int _SelectingKeyboardPlayerNr; private int _SelectedPlayerNr; - private int[] _PlayerNr; - public override void Init() { base.Init(); List statics = new List(); - foreach (string text in _StaticPlayer) - statics.Add(text); - foreach (string text in _StaticPlayerAvatar) - statics.Add(text); + statics.AddRange(_StaticPlayerAvatar); + statics.AddRange(_StaticPlayer); statics.Add(_StaticWarningMics); statics.Add(_StaticWarningProfiles); _ThemeStatics = statics.ToArray(); - List texts = new List(); - texts.Add(_SelectSlidePlayerNumber); + List texts = new List {_SelectSlidePlayerNumber}; texts.AddRange(_SelectSlideDuetPlayer); _ThemeSelectSlides = texts.ToArray(); texts.Clear(); texts.Add(_TextWarningMics); texts.Add(_TextWarningProfiles); - foreach (string text in _TextPlayer) - texts.Add(text); + texts.AddRange(_TextPlayer); _ThemeTexts = texts.ToArray(); texts.Clear(); @@ -91,15 +103,11 @@ namespace Vocaluxe.Screens { base.LoadTheme(xmlPath); - _PlayerNr = new int[CSettings.MaxNumPlayer]; - for (int i = 0; i < _PlayerNr.Length; i++) - _PlayerNr[i] = i; - for (int i = 0; i < CSettings.MaxNumPlayer; i++) - _OriginalPlayerAvatarTextures[i] = Statics[_StaticPlayerAvatar[i]].Texture; + _OriginalPlayerAvatarTextures[i] = _Statics[_StaticPlayerAvatar[i]].Texture; for (int i = 1; i <= CSettings.MaxNumPlayer; i++) - Equalizers["EqualizerPlayer" + i].ScreenHandles = true; + _Equalizers["EqualizerPlayer" + i].ScreenHandles = true; } public override bool HandleInput(SKeyEvent keyEvent) @@ -109,20 +117,20 @@ namespace Vocaluxe.Screens case Keys.Add: if (CConfig.NumPlayer + 1 <= CSettings.MaxNumPlayer) { - SelectSlides[_SelectSlidePlayerNumber].Selection = CConfig.NumPlayer; + _SelectSlides[_SelectSlidePlayerNumber].Selection = CConfig.NumPlayer; _UpdatePlayerNumber(); //Update Tiles-List - NameSelections[_NameSelection].UpdateList(); + _NameSelections[_NameSelection].UpdateList(); } break; case Keys.Subtract: if (CConfig.NumPlayer - 1 > 0) { - SelectSlides[_SelectSlidePlayerNumber].Selection = CConfig.NumPlayer - 2; + _SelectSlides[_SelectSlidePlayerNumber].Selection = CConfig.NumPlayer - 2; _UpdatePlayerNumber(); //Update Tiles-List - NameSelections[_NameSelection].UpdateList(); + _NameSelections[_NameSelection].UpdateList(); } break; @@ -138,7 +146,7 @@ namespace Vocaluxe.Screens _SelectingKeyboardPlayerNr++; else _SelectingKeyboardPlayerNr = 1; - NameSelections[_NameSelection].KeyboardSelection(true, _SelectingKeyboardPlayerNr); + _NameSelections[_NameSelection].KeyboardSelection(true, _SelectingKeyboardPlayerNr); } break; } @@ -146,203 +154,128 @@ namespace Vocaluxe.Screens if (_SelectingKeyboardActive) { //Handle left/right/up/down - NameSelections[_NameSelection].HandleInput(keyEvent); + _NameSelections[_NameSelection].HandleInput(keyEvent); + int numberPressed = -1; + bool resetSelection = false; switch (keyEvent.Key) { case Keys.Enter: //Check, if a player is selected - if (NameSelections[_NameSelection].Selection > -1) + if (_NameSelections[_NameSelection].Selection > -1) { - _SelectedPlayerNr = NameSelections[_NameSelection].Selection; + _SelectedPlayerNr = _NameSelections[_NameSelection].Selection; //Update Game-infos with new player - CGame.Player[_SelectingKeyboardPlayerNr - 1].Name = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; - CGame.Player[_SelectingKeyboardPlayerNr - 1].Difficulty = CProfiles.Profiles[_SelectedPlayerNr].Difficulty; - CGame.Player[_SelectingKeyboardPlayerNr - 1].ProfileID = _SelectedPlayerNr; + CGame.Players[_SelectingKeyboardPlayerNr - 1].ProfileID = _SelectedPlayerNr; //Update config for default players. CConfig.Players[_SelectingKeyboardPlayerNr - 1] = CProfiles.Profiles[_SelectedPlayerNr].ProfileFile; CConfig.SaveConfig(); //Update texture and name - Statics[_StaticPlayerAvatar[_SelectingKeyboardPlayerNr - 1]].Texture = CProfiles.Profiles[_SelectedPlayerNr].Avatar.Texture; - Texts[_TextPlayer[_SelectingKeyboardPlayerNr - 1]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; + _Statics[_StaticPlayerAvatar[_SelectingKeyboardPlayerNr - 1]].Texture = CProfiles.Profiles[_SelectedPlayerNr].Avatar.Texture; + _Texts[_TextPlayer[_SelectingKeyboardPlayerNr - 1]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; //Update profile-warning _CheckPlayers(); //Update Tiles-List - NameSelections[_NameSelection].UpdateList(); - SetInteractionToButton(Buttons[_ButtonStart]); + _NameSelections[_NameSelection].UpdateList(); + _SetInteractionToButton(_Buttons[_ButtonStart]); } //Started selecting with 'P' if (_SelectingKeyboardUnendless) { if (_SelectingKeyboardPlayerNr == CGame.NumPlayer) - { - //Reset all values - _SelectingKeyboardPlayerNr = 0; - _SelectingKeyboardActive = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); - } + resetSelection = true; else { _SelectingKeyboardPlayerNr++; - NameSelections[_NameSelection].KeyboardSelection(true, _SelectingKeyboardPlayerNr); + _NameSelections[_NameSelection].KeyboardSelection(true, _SelectingKeyboardPlayerNr); } } else - { - //Reset all values - _SelectingKeyboardPlayerNr = 0; - _SelectingKeyboardActive = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); - } + resetSelection = true; break; case Keys.D1: case Keys.NumPad1: - if (_SelectingKeyboardPlayerNr == 1) - { - //Reset all values - _SelectingKeyboardPlayerNr = 0; - _SelectingKeyboardActive = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); - } - else - { - _SelectingKeyboardPlayerNr = 1; - NameSelections[_NameSelection].KeyboardSelection(true, 1); - } - _SelectingKeyboardUnendless = false; + numberPressed = 1; break; case Keys.D2: case Keys.NumPad2: - if (_SelectingKeyboardPlayerNr == 2) - { - //Reset all values - _SelectingKeyboardPlayerNr = 0; - _SelectingKeyboardActive = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); - } - else - { - _SelectingKeyboardPlayerNr = 2; - NameSelections[_NameSelection].KeyboardSelection(true, 2); - } - _SelectingKeyboardUnendless = false; + numberPressed = 2; break; case Keys.D3: case Keys.NumPad3: - if (_SelectingKeyboardPlayerNr == 3) - { - //Reset all values - _SelectingKeyboardPlayerNr = 0; - _SelectingKeyboardActive = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); - } - else - { - _SelectingKeyboardPlayerNr = 3; - NameSelections[_NameSelection].KeyboardSelection(true, 3); - } - _SelectingKeyboardUnendless = false; + numberPressed = 3; break; case Keys.D4: case Keys.NumPad4: - if (_SelectingKeyboardPlayerNr == 4) - { - //Reset all values - _SelectingKeyboardPlayerNr = 0; - _SelectingKeyboardActive = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); - } - else - { - _SelectingKeyboardPlayerNr = 4; - NameSelections[_NameSelection].KeyboardSelection(true, 4); - } - _SelectingKeyboardUnendless = false; + numberPressed = 4; break; case Keys.D5: case Keys.NumPad5: - if (_SelectingKeyboardPlayerNr == 5) - { - //Reset all values - _SelectingKeyboardPlayerNr = 0; - _SelectingKeyboardActive = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); - } - else - { - _SelectingKeyboardPlayerNr = 5; - NameSelections[_NameSelection].KeyboardSelection(true, 5); - } - _SelectingKeyboardUnendless = false; + numberPressed = 5; break; case Keys.D6: case Keys.NumPad6: - if (_SelectingKeyboardPlayerNr == 6) - { - //Reset all values - _SelectingKeyboardPlayerNr = 0; - _SelectingKeyboardActive = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); - } - else - { - _SelectingKeyboardPlayerNr = 6; - NameSelections[_NameSelection].KeyboardSelection(true, 6); - } - _SelectingKeyboardUnendless = false; + numberPressed = 6; break; case Keys.Escape: - //Reset all values - _SelectingKeyboardPlayerNr = 0; - _SelectingKeyboardActive = false; - _SelectingKeyboardUnendless = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); + resetSelection = true; break; case Keys.Delete: //Delete profile-selection - CGame.Player[_SelectingKeyboardPlayerNr - 1].ProfileID = -1; - CGame.Player[_SelectingKeyboardPlayerNr - 1].Name = String.Empty; - CGame.Player[_SelectingKeyboardPlayerNr - 1].Difficulty = EGameDifficulty.TR_CONFIG_EASY; + CGame.Players[_SelectingKeyboardPlayerNr - 1].ProfileID = -1; //Update config for default players. CConfig.Players[_SelectingKeyboardPlayerNr - 1] = String.Empty; CConfig.SaveConfig(); //Update texture and name - Statics[_StaticPlayerAvatar[_SelectingKeyboardPlayerNr - 1]].Texture = _OriginalPlayerAvatarTextures[_SelectingKeyboardPlayerNr - 1]; - Texts[_TextPlayer[_SelectingKeyboardPlayerNr - 1]].Text = CLanguage.Translate("TR_SCREENNAMES_PLAYER") + " " + _SelectingKeyboardPlayerNr.ToString(); + _Statics[_StaticPlayerAvatar[_SelectingKeyboardPlayerNr - 1]].Texture = _OriginalPlayerAvatarTextures[_SelectingKeyboardPlayerNr - 1]; + _Texts[_TextPlayer[_SelectingKeyboardPlayerNr - 1]].Text = CProfiles.GetPlayerName(-1, _SelectingKeyboardPlayerNr); //Update profile-warning _CheckPlayers(); //Reset all values _SelectingKeyboardPlayerNr = 0; _SelectingKeyboardActive = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); + _NameSelections[_NameSelection].KeyboardSelection(false, -1); //Update Tiles-List - NameSelections[_NameSelection].UpdateList(); + _NameSelections[_NameSelection].UpdateList(); break; case Keys.F10: if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) { - if (SelectSlides[_SelectSlideDuetPlayer[_SelectingKeyboardPlayerNr - 1]].Selection == 0) - SelectSlides[_SelectSlideDuetPlayer[_SelectingKeyboardPlayerNr - 1]].Selection = 1; - else - SelectSlides[_SelectSlideDuetPlayer[_SelectingKeyboardPlayerNr - 1]].Selection = 0; + CSelectSlide selectSlideDuetPart = _SelectSlides[_SelectSlideDuetPlayer[_SelectingKeyboardPlayerNr - 1]]; + selectSlideDuetPart.Selection = (selectSlideDuetPart.Selection + 1) % 2; //Reset all values _SelectingKeyboardPlayerNr = 0; _SelectingKeyboardActive = false; _SelectingKeyboardUnendless = false; - NameSelections[_NameSelection].KeyboardSelection(false, -1); - SetInteractionToButton(Buttons[_ButtonStart]); + _NameSelections[_NameSelection].KeyboardSelection(false, -1); + _SetInteractionToButton(_Buttons[_ButtonStart]); } break; } + if (numberPressed > 0 || resetSelection) + { + if (numberPressed == _SelectingKeyboardPlayerNr || resetSelection) + { + //Reset all values + _SelectingKeyboardPlayerNr = 0; + _SelectingKeyboardActive = false; + _NameSelections[_NameSelection].KeyboardSelection(false, -1); + } + else if (numberPressed <= CConfig.NumPlayer) + { + _SelectingKeyboardPlayerNr = numberPressed; + _NameSelections[_NameSelection].KeyboardSelection(true, numberPressed); + } + _SelectingKeyboardUnendless = false; + } } //Normal Keyboard handling else { base.HandleInput(keyEvent); - bool processed = false; switch (keyEvent.Key) { case Keys.Escape: @@ -352,17 +285,10 @@ namespace Vocaluxe.Screens case Keys.Enter: - if (!processed && Buttons[_ButtonBack].Selected) - { - processed = true; + if (_Buttons[_ButtonBack].Selected) CGraphics.FadeTo(EScreens.ScreenSong); - } - - if (!processed /* && Buttons[ButtonStart].Selected */) - { - processed = true; + else _StartSong(); - } break; @@ -395,15 +321,16 @@ namespace Vocaluxe.Screens case Keys.NumPad6: _SelectingKeyboardPlayerNr = 6; break; + default: + _UpdatePlayerNumber(); + break; } - if (!processed) - _UpdatePlayerNumber(); if (_SelectingKeyboardPlayerNr > 0 && _SelectingKeyboardPlayerNr <= CConfig.NumPlayer) { _SelectingKeyboardActive = true; - NameSelections[_NameSelection].KeyboardSelection(true, _SelectingKeyboardPlayerNr); + _NameSelections[_NameSelection].KeyboardSelection(true, _SelectingKeyboardPlayerNr); } } @@ -415,23 +342,20 @@ namespace Vocaluxe.Screens base.HandleMouse(mouseEvent); //Check if LeftButton is hold and Select-Mode inactive - if (mouseEvent.LBH && !_SelectingMouseActive) + if (mouseEvent.LBH && _SelectedPlayerNr < 0) { //Save mouse-coords _OldMouseX = mouseEvent.X; _OldMouseY = mouseEvent.Y; //Check if mouse if over tile - if (NameSelections[_NameSelection].IsOverTile(mouseEvent)) + if (_NameSelections[_NameSelection].IsOverTile(mouseEvent)) { //Get player-number of tile - _SelectedPlayerNr = NameSelections[_NameSelection].TilePlayerNr(mouseEvent); + _SelectedPlayerNr = _NameSelections[_NameSelection].TilePlayerNr(mouseEvent); if (_SelectedPlayerNr != -1) { - //Activate mouse-selecting - _SelectingMouseActive = true; - //Update of Drag/Drop-Texture - CStatic selectedPlayer = NameSelections[_NameSelection].TilePlayerAvatar(mouseEvent); + CStatic selectedPlayer = _NameSelections[_NameSelection].TilePlayerAvatar(mouseEvent); _ChooseAvatarStatic.Visible = true; _ChooseAvatarStatic.Rect = selectedPlayer.Rect; _ChooseAvatarStatic.Rect.Z = CSettings.ZNear; @@ -442,7 +366,7 @@ namespace Vocaluxe.Screens } //Check if LeftButton is hold and Select-Mode active - if (mouseEvent.LBH && _SelectingMouseActive) + if (mouseEvent.LBH && _SelectedPlayerNr >= 0) { //Update coords for Drag/Drop-Texture _ChooseAvatarStatic.Rect.X += mouseEvent.X - _OldMouseX; @@ -450,67 +374,47 @@ namespace Vocaluxe.Screens _OldMouseX = mouseEvent.X; _OldMouseY = mouseEvent.Y; } - // LeftButton isn't hold anymore, but Selec-Mode is still active -> "ReplacedStr:::0:::" of Avatar - else if (_SelectingMouseActive) + // LeftButton isn't hold anymore, but Selec-Mode is still active -> "Drop" of Avatar + else if (_SelectedPlayerNr >= 0) { - //Check if really a player was selected - if (_SelectedPlayerNr != -1) + //Foreach Drop-Area + for (int i = 0; i < _StaticPlayer.Length; i++) { - //Foreach Drop-Area - for (int i = 0; i < _StaticPlayer.Length; i++) + //Check first, if area is "Active" + if (!_Statics[_StaticPlayer[i]].Visible) + continue; + //Check if Mouse is in area + if (CHelper.IsInBounds(_Statics[_StaticPlayer[i]].Rect, mouseEvent)) { - //Check first, if area is "ReplacedStr:::1:::" - if (Statics[_StaticPlayer[i]].Visible) - { - //Check if Mouse is in area - if (CHelper.IsInBounds(Statics[_StaticPlayer[i]].Rect, mouseEvent)) - { - //Update Game-infos with new player - CGame.Player[i].Name = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; - CGame.Player[i].Difficulty = CProfiles.Profiles[_SelectedPlayerNr].Difficulty; - CGame.Player[i].ProfileID = _SelectedPlayerNr; - //Update config for default players. - CConfig.Players[i] = CProfiles.Profiles[_SelectedPlayerNr].ProfileFile; - CConfig.SaveConfig(); - //Update texture and name - Statics[_StaticPlayerAvatar[i]].Texture = _ChooseAvatarStatic.Texture; - Texts[_TextPlayer[i]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; - //Update profile-warning - _CheckPlayers(); - //Update Tiles-List - NameSelections[_NameSelection].UpdateList(); - } - } + //Update Game-infos with new player + CGame.Players[i].ProfileID = _SelectedPlayerNr; + //Update config for default players. + CConfig.Players[i] = CProfiles.Profiles[_SelectedPlayerNr].ProfileFile; + CConfig.SaveConfig(); + //Update texture and name + _Statics[_StaticPlayerAvatar[i]].Texture = _ChooseAvatarStatic.Texture; + _Texts[_TextPlayer[i]].Text = CProfiles.Profiles[_SelectedPlayerNr].PlayerName; + //Update profile-warning + _CheckPlayers(); + //Update Tiles-List + _NameSelections[_NameSelection].UpdateList(); } - _SelectedPlayerNr = -1; } + _SelectedPlayerNr = -1; //Reset variables - _SelectingMouseActive = false; _ChooseAvatarStatic.Visible = false; } - if (mouseEvent.LB && IsMouseOver(mouseEvent)) {} - - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - bool processed = false; - - if (!processed && Buttons[_ButtonBack].Selected) - { - processed = true; + if (_Buttons[_ButtonBack].Selected) CGraphics.FadeTo(EScreens.ScreenSong); - } - - if (!processed && Buttons[_ButtonStart].Selected) - { - processed = true; + else if (_Buttons[_ButtonStart].Selected) _StartSong(); - } - - if (!processed) + else _UpdatePlayerNumber(); //Update Tiles-List - NameSelections[_NameSelection].UpdateList(); + _NameSelections[_NameSelection].UpdateList(); } if (mouseEvent.RB) @@ -519,21 +423,19 @@ namespace Vocaluxe.Screens //Remove profile-selection for (int i = 0; i < CConfig.NumPlayer; i++) { - if (CHelper.IsInBounds(Statics[_StaticPlayer[i]].Rect, mouseEvent)) + if (CHelper.IsInBounds(_Statics[_StaticPlayer[i]].Rect, mouseEvent)) { - CGame.Player[i].ProfileID = -1; - CGame.Player[i].Name = String.Empty; - CGame.Player[i].Difficulty = EGameDifficulty.TR_CONFIG_EASY; + CGame.Players[i].ProfileID = -1; //Update config for default players. CConfig.Players[i] = String.Empty; CConfig.SaveConfig(); //Update texture and name - Statics[_StaticPlayerAvatar[i]].Texture = _OriginalPlayerAvatarTextures[i]; - Texts[_TextPlayer[i]].Text = CLanguage.Translate("TR_SCREENNAMES_PLAYER") + " " + (i + 1).ToString(); + _Statics[_StaticPlayerAvatar[i]].Texture = _OriginalPlayerAvatarTextures[i]; + _Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(-1, i + 1); //Update profile-warning _CheckPlayers(); //Update Tiles-List - NameSelections[_NameSelection].UpdateList(); + _NameSelections[_NameSelection].UpdateList(); exit = false; } } @@ -544,10 +446,10 @@ namespace Vocaluxe.Screens //Check mouse-wheel for scrolling if (mouseEvent.Wheel != 0) { - if (CHelper.IsInBounds(NameSelections[_NameSelection].Rect, mouseEvent)) + if (CHelper.IsInBounds(_NameSelections[_NameSelection].Rect, mouseEvent)) { - int offset = NameSelections[_NameSelection].Offset + mouseEvent.Wheel; - NameSelections[_NameSelection].UpdateList(offset); + int offset = _NameSelections[_NameSelection].Offset + mouseEvent.Wheel; + _NameSelections[_NameSelection].UpdateList(offset); } } return true; @@ -558,7 +460,7 @@ namespace Vocaluxe.Screens for (int i = 1; i <= CGame.NumPlayer; i++) { CSound.AnalyzeBuffer(i - 1); - Equalizers["EqualizerPlayer" + i].Update(CSound.ToneWeigth(i - 1)); + _Equalizers["EqualizerPlayer" + i].Update(CSound.ToneWeigth(i - 1)); } return true; } @@ -568,7 +470,7 @@ namespace Vocaluxe.Screens base.OnShow(); CSound.RecordStart(); - NameSelections[_NameSelection].Init(); + _NameSelections[_NameSelection].Init(); _UpdateSlides(); _UpdatePlayerNumber(); @@ -577,34 +479,23 @@ namespace Vocaluxe.Screens for (int i = 0; i < CSettings.MaxNumPlayer; i++) { - //Update texture and name - if (CConfig.Players[i].Length > 0) - { - if (CGame.Player[i].ProfileID > -1 && CProfiles.NumProfiles > CGame.Player[i].ProfileID) - { - Statics[_StaticPlayerAvatar[i]].Texture = CProfiles.Profiles[CGame.Player[i].ProfileID].Avatar.Texture; - Texts[_TextPlayer[i]].Text = CProfiles.Profiles[CGame.Player[i].ProfileID].PlayerName; - } - } + _Statics[_StaticPlayerAvatar[i]].Texture = CProfiles.IsProfileIDValid(CGame.Players[i].ProfileID) ? + CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture : + _OriginalPlayerAvatarTextures[i]; + _Texts[_TextPlayer[i]].Text = CProfiles.GetPlayerName(CGame.Players[i].ProfileID, i + 1); if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) { - SelectSlides[_SelectSlideDuetPlayer[i]].Clear(); - if (i + 1 <= CGame.NumPlayer) - SelectSlides[_SelectSlideDuetPlayer[i]].Visible = true; - else - SelectSlides[_SelectSlideDuetPlayer[i]].Visible = false; - SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart1); - SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart2); - if ((i + 1) % 2 == 0) - SelectSlides[_SelectSlideDuetPlayer[i]].Selection = 1; - else - SelectSlides[_SelectSlideDuetPlayer[i]].Selection = 0; + _SelectSlides[_SelectSlideDuetPlayer[i]].Clear(); + _SelectSlides[_SelectSlideDuetPlayer[i]].Visible = i + 1 <= CGame.NumPlayer; + _SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart1); + _SelectSlides[_SelectSlideDuetPlayer[i]].AddValue(CGame.GetSong(1).DuetPart2); + _SelectSlides[_SelectSlideDuetPlayer[i]].Selection = i % 2; } else - SelectSlides[_SelectSlideDuetPlayer[i]].Visible = false; + _SelectSlides[_SelectSlideDuetPlayer[i]].Visible = false; } - SetInteractionToButton(Buttons[_ButtonStart]); + _SetInteractionToButton(_Buttons[_ButtonStart]); } public override void OnClose() @@ -620,7 +511,7 @@ namespace Vocaluxe.Screens if (_ChooseAvatarStatic.Visible) _ChooseAvatarStatic.Draw(); for (int i = 1; i <= CGame.NumPlayer; i++) - Equalizers["EqualizerPlayer" + i].Draw(); + _Equalizers["EqualizerPlayer" + i].Draw(); return true; } @@ -628,20 +519,8 @@ namespace Vocaluxe.Screens { for (int i = 0; i < CGame.NumPlayer; i++) { - if (CGame.Player[i].ProfileID < 0) - { - CGame.Player[i].Name = "Player " + (i + 1).ToString(); - CGame.Player[i].Difficulty = EGameDifficulty.TR_CONFIG_EASY; - CGame.Player[i].ProfileID = -1; - } - else - { - //Just a work-around for not crashing the game - if (CGame.Player[i].Name == null) - CGame.Player[i].Name = ""; - } if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) - CGame.Player[i].LineNr = SelectSlides[_SelectSlideDuetPlayer[i]].Selection; + CGame.Players[i].LineNr = _SelectSlides[_SelectSlideDuetPlayer[i]].Selection; } CGraphics.FadeTo(EScreens.ScreenSing); @@ -649,36 +528,36 @@ namespace Vocaluxe.Screens private void _UpdateSlides() { - SelectSlides[_SelectSlidePlayerNumber].Clear(); + _SelectSlides[_SelectSlidePlayerNumber].Clear(); for (int i = 1; i <= CSettings.MaxNumPlayer; i++) - SelectSlides[_SelectSlidePlayerNumber].AddValue(CLanguage.Translate("TR_SCREENNAMES_" + i + "PLAYER")); - SelectSlides[_SelectSlidePlayerNumber].Selection = CConfig.NumPlayer - 1; + _SelectSlides[_SelectSlidePlayerNumber].AddValue(CLanguage.Translate("TR_SCREENNAMES_" + i + "PLAYER")); + _SelectSlides[_SelectSlidePlayerNumber].Selection = CConfig.NumPlayer - 1; } private void _UpdatePlayerNumber() { - CConfig.NumPlayer = SelectSlides[_SelectSlidePlayerNumber].Selection + 1; - CGame.NumPlayer = SelectSlides[_SelectSlidePlayerNumber].Selection + 1; + CConfig.NumPlayer = _SelectSlides[_SelectSlidePlayerNumber].Selection + 1; + CGame.NumPlayer = _SelectSlides[_SelectSlidePlayerNumber].Selection + 1; for (int i = 1; i <= CSettings.MaxNumPlayer; i++) { if (i <= CGame.NumPlayer) { - Statics["StaticPlayer" + i].Visible = true; - Statics["StaticPlayerAvatar" + i].Visible = true; - Texts["TextPlayer" + i].Visible = true; - if (Texts["TextPlayer" + i].Text.Length == 0) - Texts["TextPlayer" + i].Text = CLanguage.Translate("TR_SCREENNAMES_PLAYER") + " " + i.ToString(); - Equalizers["EqualizerPlayer" + i].Visible = true; + _Statics["StaticPlayer" + i].Visible = true; + _Statics["StaticPlayerAvatar" + i].Visible = true; + _Texts["TextPlayer" + i].Visible = true; + if (_Texts["TextPlayer" + i].Text == "") + _Texts["TextPlayer" + i].Text = CProfiles.GetPlayerName(-1, i); + _Equalizers["EqualizerPlayer" + i].Visible = true; if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet) - SelectSlides["SelectSlideDuetPlayer" + i].Visible = true; + _SelectSlides["SelectSlideDuetPlayer" + i].Visible = true; } else { - Statics["StaticPlayer" + i].Visible = false; - Statics["StaticPlayerAvatar" + i].Visible = false; - Texts["TextPlayer" + i].Visible = false; - Equalizers["EqualizerPlayer" + i].Visible = false; - SelectSlides["SelectSlideDuetPlayer" + i].Visible = false; + _Statics["StaticPlayer" + i].Visible = false; + _Statics["StaticPlayerAvatar" + i].Visible = false; + _Texts["TextPlayer" + i].Visible = false; + _Equalizers["EqualizerPlayer" + i].Visible = false; + _SelectSlides["SelectSlideDuetPlayer" + i].Visible = false; } } CConfig.SaveConfig(); @@ -696,8 +575,8 @@ namespace Vocaluxe.Screens } if (playerWithoutMicro.Count > 0) { - Statics[_StaticWarningMics].Visible = true; - Texts[_TextWarningMics].Visible = true; + _Statics[_StaticWarningMics].Visible = true; + _Texts[_TextWarningMics].Visible = true; if (playerWithoutMicro.Count > 1) { @@ -707,20 +586,20 @@ namespace Vocaluxe.Screens if (playerWithoutMicro.Count - 1 == i) playerNums += playerWithoutMicro[i].ToString(); else if (playerWithoutMicro.Count - 2 == i) - playerNums += playerWithoutMicro[i].ToString() + " " + CLanguage.Translate("TR_GENERAL_AND") + " "; + playerNums += playerWithoutMicro[i] + " " + CLanguage.Translate("TR_GENERAL_AND") + " "; else - playerNums += playerWithoutMicro[i].ToString() + ", "; + playerNums += playerWithoutMicro[i] + ", "; } - Texts[_TextWarningMics].Text = CLanguage.Translate("TR_SCREENNAMES_WARNING_MICS_PL").Replace("%v", playerNums); + _Texts[_TextWarningMics].Text = CLanguage.Translate("TR_SCREENNAMES_WARNING_MICS_PL").Replace("%v", playerNums); } else - Texts[_TextWarningMics].Text = CLanguage.Translate("TR_SCREENNAMES_WARNING_MICS_SG").Replace("%v", playerWithoutMicro[0].ToString()); + _Texts[_TextWarningMics].Text = CLanguage.Translate("TR_SCREENNAMES_WARNING_MICS_SG").Replace("%v", playerWithoutMicro[0].ToString()); } else { - Statics[_StaticWarningMics].Visible = false; - Texts[_TextWarningMics].Visible = false; + _Statics[_StaticWarningMics].Visible = false; + _Texts[_TextWarningMics].Visible = false; } } @@ -729,14 +608,14 @@ namespace Vocaluxe.Screens List playerWithoutProfile = new List(); for (int player = 0; player < CConfig.NumPlayer; player++) { - if (CGame.Player[player].ProfileID < 0) + if (CGame.Players[player].ProfileID < 0) playerWithoutProfile.Add(player + 1); } if (playerWithoutProfile.Count > 0) { - Statics[_StaticWarningProfiles].Visible = true; - Texts[_TextWarningProfiles].Visible = true; + _Statics[_StaticWarningProfiles].Visible = true; + _Texts[_TextWarningProfiles].Visible = true; if (playerWithoutProfile.Count > 1) { @@ -746,20 +625,20 @@ namespace Vocaluxe.Screens if (playerWithoutProfile.Count - 1 == i) playerNums += playerWithoutProfile[i].ToString(); else if (playerWithoutProfile.Count - 2 == i) - playerNums += playerWithoutProfile[i].ToString() + " " + CLanguage.Translate("TR_GENERAL_AND") + " "; + playerNums += playerWithoutProfile[i] + " " + CLanguage.Translate("TR_GENERAL_AND") + " "; else - playerNums += playerWithoutProfile[i].ToString() + ", "; + playerNums += playerWithoutProfile[i] + ", "; } - Texts[_TextWarningProfiles].Text = CLanguage.Translate("TR_SCREENNAMES_WARNING_PROFILES_PL").Replace("%v", playerNums); + _Texts[_TextWarningProfiles].Text = CLanguage.Translate("TR_SCREENNAMES_WARNING_PROFILES_PL").Replace("%v", playerNums); } else - Texts[_TextWarningProfiles].Text = CLanguage.Translate("TR_SCREENNAMES_WARNING_PROFILES_SG").Replace("%v", playerWithoutProfile[0].ToString()); + _Texts[_TextWarningProfiles].Text = CLanguage.Translate("TR_SCREENNAMES_WARNING_PROFILES_SG").Replace("%v", playerWithoutProfile[0].ToString()); } else { - Statics[_StaticWarningProfiles].Visible = false; - Texts[_TextWarningProfiles].Visible = false; + _Statics[_StaticWarningProfiles].Visible = false; + _Texts[_TextWarningProfiles].Visible = false; } } } diff --git a/Vocaluxe/Screens/CScreenOptions.cs b/Vocaluxe/Screens/CScreenOptions.cs index 4d324f53..ece463af 100644 --- a/Vocaluxe/Screens/CScreenOptions.cs +++ b/Vocaluxe/Screens/CScreenOptions.cs @@ -1,4 +1,23 @@ -using System.Windows.Forms; +#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.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -46,22 +65,22 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonOptionsGame].Selected) + if (_Buttons[_ButtonOptionsGame].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsGame); - if (Buttons[_ButtonOptionsSound].Selected) + if (_Buttons[_ButtonOptionsSound].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsSound); - if (Buttons[_ButtonOptionsRecord].Selected) + if (_Buttons[_ButtonOptionsRecord].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsRecord); - if (Buttons[_ButtonOptionsVideo].Selected) + if (_Buttons[_ButtonOptionsVideo].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsVideo); - if (Buttons[_ButtonOptionsLyrics].Selected) + if (_Buttons[_ButtonOptionsLyrics].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsLyrics); - if (Buttons[_ButtonOptionsTheme].Selected) + if (_Buttons[_ButtonOptionsTheme].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsTheme); break; @@ -74,24 +93,24 @@ namespace Vocaluxe.Screens { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonOptionsGame].Selected) + if (_Buttons[_ButtonOptionsGame].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsGame); - if (Buttons[_ButtonOptionsSound].Selected) + if (_Buttons[_ButtonOptionsSound].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsSound); - if (Buttons[_ButtonOptionsRecord].Selected) + if (_Buttons[_ButtonOptionsRecord].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsRecord); - if (Buttons[_ButtonOptionsVideo].Selected) + if (_Buttons[_ButtonOptionsVideo].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsVideo); - if (Buttons[_ButtonOptionsLyrics].Selected) + if (_Buttons[_ButtonOptionsLyrics].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsLyrics); - if (Buttons[_ButtonOptionsTheme].Selected) + if (_Buttons[_ButtonOptionsTheme].Selected) CGraphics.FadeTo(EScreens.ScreenOptionsTheme); } diff --git a/Vocaluxe/Screens/CScreenOptionsGame.cs b/Vocaluxe/Screens/CScreenOptionsGame.cs index 02371d0c..a350026a 100644 --- a/Vocaluxe/Screens/CScreenOptionsGame.cs +++ b/Vocaluxe/Screens/CScreenOptionsGame.cs @@ -1,4 +1,23 @@ -using System.Windows.Forms; +#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.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -33,14 +52,14 @@ namespace Vocaluxe.Screens { base.LoadTheme(xmlPath); - SelectSlides[_SelectSlideLanguage].AddValues(CLanguage.GetLanguageNames()); - SelectSlides[_SelectSlideLanguage].Selection = CLanguage.LanguageId; + _SelectSlides[_SelectSlideLanguage].AddValues(CLanguage.GetLanguageNames()); + _SelectSlides[_SelectSlideLanguage].Selection = CLanguage.LanguageId; - SelectSlides[_SelectSlideDebugLevel].SetValues((int)CConfig.DebugLevel); - SelectSlides[_SelectSlideSongMenu].SetValues((int)CConfig.SongMenu); - SelectSlides[_SelectSlideSongSorting].SetValues((int)CConfig.SongSorting); - SelectSlides[_SelectSlideTabs].SetValues((int)CConfig.Tabs); - SelectSlides[_SelectSlideTimerMode].SetValues((int)CConfig.TimerMode); + _SelectSlides[_SelectSlideDebugLevel].SetValues((int)CConfig.DebugLevel); + _SelectSlides[_SelectSlideSongMenu].SetValues((int)CConfig.SongMenu); + _SelectSlides[_SelectSlideSongSorting].SetValues((int)CConfig.SongSorting); + _SelectSlides[_SelectSlideTabs].SetValues((int)CConfig.Tabs); + _SelectSlides[_SelectSlideTimerMode].SetValues((int)CConfig.TimerMode); } public override bool HandleInput(SKeyEvent keyEvent) @@ -63,7 +82,7 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) { _SaveConfig(); CGraphics.FadeTo(EScreens.ScreenOptions); @@ -92,10 +111,10 @@ namespace Vocaluxe.Screens CGraphics.FadeTo(EScreens.ScreenOptions); } - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { _SaveConfig(); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) CGraphics.FadeTo(EScreens.ScreenOptions); } return true; @@ -114,13 +133,13 @@ namespace Vocaluxe.Screens private void _SaveConfig() { - CLanguage.LanguageId = SelectSlides[_SelectSlideLanguage].Selection; + CLanguage.LanguageId = _SelectSlides[_SelectSlideLanguage].Selection; CConfig.Language = CLanguage.GetLanguageName(CLanguage.LanguageId); - CConfig.DebugLevel = (EDebugLevel)SelectSlides[_SelectSlideDebugLevel].Selection; - CConfig.SongMenu = (ESongMenu)SelectSlides[_SelectSlideSongMenu].Selection; - CConfig.SongSorting = (ESongSorting)SelectSlides[_SelectSlideSongSorting].Selection; - CConfig.Tabs = (EOffOn)SelectSlides[_SelectSlideTabs].Selection; - CConfig.TimerMode = (ETimerMode)SelectSlides[_SelectSlideTimerMode].Selection; + CConfig.DebugLevel = (EDebugLevel)_SelectSlides[_SelectSlideDebugLevel].Selection; + CConfig.SongMenu = (ESongMenu)_SelectSlides[_SelectSlideSongMenu].Selection; + CConfig.SongSorting = (ESongSorting)_SelectSlides[_SelectSlideSongSorting].Selection; + CConfig.Tabs = (EOffOn)_SelectSlides[_SelectSlideTabs].Selection; + CConfig.TimerMode = (ETimerMode)_SelectSlides[_SelectSlideTimerMode].Selection; CConfig.SaveConfig(); diff --git a/Vocaluxe/Screens/CScreenOptionsLyrics.cs b/Vocaluxe/Screens/CScreenOptionsLyrics.cs index 60fc0208..718b9b2d 100644 --- a/Vocaluxe/Screens/CScreenOptionsLyrics.cs +++ b/Vocaluxe/Screens/CScreenOptionsLyrics.cs @@ -1,4 +1,23 @@ -using System.Windows.Forms; +#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.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -28,8 +47,8 @@ namespace Vocaluxe.Screens public override void LoadTheme(string xmlPath) { base.LoadTheme(xmlPath); - SelectSlides[_SelectSlideLyricStyle].SetValues((int)CConfig.LyricStyle); - SelectSlides[_SelectSlideLyricsOnTop].SetValues((int)CConfig.LyricsOnTop); + _SelectSlides[_SelectSlideLyricStyle].SetValues((int)CConfig.LyricStyle); + _SelectSlides[_SelectSlideLyricsOnTop].SetValues((int)CConfig.LyricsOnTop); } public override bool HandleInput(SKeyEvent keyEvent) @@ -53,7 +72,7 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) { _SaveConfig(); CGraphics.FadeTo(EScreens.ScreenOptions); @@ -81,10 +100,10 @@ namespace Vocaluxe.Screens _SaveConfig(); CGraphics.FadeTo(EScreens.ScreenOptions); } - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { _SaveConfig(); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) CGraphics.FadeTo(EScreens.ScreenOptions); } return true; @@ -103,8 +122,8 @@ namespace Vocaluxe.Screens private void _SaveConfig() { - CConfig.LyricsOnTop = (EOffOn)SelectSlides[_SelectSlideLyricsOnTop].Selection; - CConfig.LyricStyle = (ELyricStyle)SelectSlides[_SelectSlideLyricStyle].Selection; + CConfig.LyricsOnTop = (EOffOn)_SelectSlides[_SelectSlideLyricsOnTop].Selection; + CConfig.LyricStyle = (ELyricStyle)_SelectSlides[_SelectSlideLyricStyle].Selection; CConfig.SaveConfig(); } } diff --git a/Vocaluxe/Screens/CScreenOptionsRecord.cs b/Vocaluxe/Screens/CScreenOptionsRecord.cs index a44017b7..a1ced44f 100644 --- a/Vocaluxe/Screens/CScreenOptionsRecord.cs +++ b/Vocaluxe/Screens/CScreenOptionsRecord.cs @@ -1,4 +1,23 @@ -using System.Collections.Generic; +#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.Collections.Generic; using System.Diagnostics; using System.Windows.Forms; using Vocaluxe.Base; @@ -56,8 +75,7 @@ namespace Vocaluxe.Screens { base.Init(); - List values = new List(); - values.Add(_StaticWarning); + List values = new List {_StaticWarning}; values.AddRange(_StaticEnergyChannel); _ThemeStatics = values.ToArray(); @@ -75,31 +93,31 @@ namespace Vocaluxe.Screens if (max > 7) max = 7; - SelectSlides[_SelectSlideRecordChannel1].NumVisible = max; - SelectSlides[_SelectSlideRecordChannel2].NumVisible = max; + _SelectSlides[_SelectSlideRecordChannel1].NumVisible = max; + _SelectSlides[_SelectSlideRecordChannel2].NumVisible = max; - SelectSlides[_SelectSlideRecordChannel1].AddValue(CLanguage.Translate("TR_CONFIG_OFF")); - SelectSlides[_SelectSlideRecordChannel2].AddValue(CLanguage.Translate("TR_CONFIG_OFF")); + _SelectSlides[_SelectSlideRecordChannel1].AddValue(CLanguage.Translate("TR_CONFIG_OFF")); + _SelectSlides[_SelectSlideRecordChannel2].AddValue(CLanguage.Translate("TR_CONFIG_OFF")); for (int i = 1; i <= CSettings.MaxNumPlayer; i++) { - SelectSlides[_SelectSlideRecordChannel1].AddValue(i.ToString()); - SelectSlides[_SelectSlideRecordChannel2].AddValue(i.ToString()); + _SelectSlides[_SelectSlideRecordChannel1].AddValue(i.ToString()); + _SelectSlides[_SelectSlideRecordChannel2].AddValue(i.ToString()); } for (int i = 0; i < 26; i++) - SelectSlides[_SelectSlideDelay].AddValue((i * 20).ToString() + " ms"); + _SelectSlides[_SelectSlideDelay].AddValue((i * 20) + " ms"); _ChannelEnergy = new float[_StaticEnergyChannel.Length]; for (int i = 0; i < _ChannelEnergy.Length; i++) { - Statics[_StaticEnergyChannel[i]].Visible = false; + _Statics[_StaticEnergyChannel[i]].Visible = false; _ChannelEnergy[i] = 0f; } - Equalizers[_EqualizerChannel1].ScreenHandles = true; - Equalizers[_EqualizerChannel2].ScreenHandles = true; + _Equalizers[_EqualizerChannel1].ScreenHandles = true; + _Equalizers[_EqualizerChannel2].ScreenHandles = true; } public override bool HandleInput(SKeyEvent keyEvent) @@ -123,13 +141,13 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) { _SaveMicConfig(); CGraphics.FadeTo(EScreens.ScreenOptions); } - if (Buttons[_ButtonDelayTest].Selected) + if (_Buttons[_ButtonDelayTest].Selected) _TestDelay(); break; @@ -139,32 +157,32 @@ namespace Vocaluxe.Screens break; case Keys.Left: - if (SelectSlides[_SelectSlideRecordDevices].Selected) + if (_SelectSlides[_SelectSlideRecordDevices].Selected) _OnDeviceEvent(); - if (SelectSlides[_SelectSlideRecordInputs].Selected) + if (_SelectSlides[_SelectSlideRecordInputs].Selected) _OnInputEvent(); - if (SelectSlides[_SelectSlideRecordChannel1].Selected || - SelectSlides[_SelectSlideRecordChannel2].Selected) + if (_SelectSlides[_SelectSlideRecordChannel1].Selected || + _SelectSlides[_SelectSlideRecordChannel2].Selected) _SetMicConfig(); - if (SelectSlides[_SelectSlideDelay].Selected) + if (_SelectSlides[_SelectSlideDelay].Selected) _SaveDelayConfig(); break; case Keys.Right: - if (SelectSlides[_SelectSlideRecordDevices].Selected) + if (_SelectSlides[_SelectSlideRecordDevices].Selected) _OnDeviceEvent(); - if (SelectSlides[_SelectSlideRecordInputs].Selected) + if (_SelectSlides[_SelectSlideRecordInputs].Selected) _OnInputEvent(); - if (SelectSlides[_SelectSlideRecordChannel1].Selected || - SelectSlides[_SelectSlideRecordChannel2].Selected) + if (_SelectSlides[_SelectSlideRecordChannel1].Selected || + _SelectSlides[_SelectSlideRecordChannel2].Selected) _SetMicConfig(); - if (SelectSlides[_SelectSlideDelay].Selected) + if (_SelectSlides[_SelectSlideDelay].Selected) _SaveDelayConfig(); break; } @@ -182,28 +200,28 @@ namespace Vocaluxe.Screens CGraphics.FadeTo(EScreens.ScreenOptions); } - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (SelectSlides[_SelectSlideRecordDevices].Selected) + if (_SelectSlides[_SelectSlideRecordDevices].Selected) _OnDeviceEvent(); - if (SelectSlides[_SelectSlideRecordInputs].Selected) + if (_SelectSlides[_SelectSlideRecordInputs].Selected) _OnInputEvent(); - if (SelectSlides[_SelectSlideRecordChannel1].Selected || - SelectSlides[_SelectSlideRecordChannel2].Selected) + if (_SelectSlides[_SelectSlideRecordChannel1].Selected || + _SelectSlides[_SelectSlideRecordChannel2].Selected) _SetMicConfig(); - if (SelectSlides[_SelectSlideDelay].Selected) + if (_SelectSlides[_SelectSlideDelay].Selected) _SaveDelayConfig(); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) { _SaveMicConfig(); CGraphics.FadeTo(EScreens.ScreenOptions); } - if (Buttons[_ButtonDelayTest].Selected) + if (_Buttons[_ButtonDelayTest].Selected) _TestDelay(); } return true; @@ -230,10 +248,10 @@ namespace Vocaluxe.Screens { int player = 0; if (i == 0) - player = SelectSlides[_SelectSlideRecordChannel1].Selection; + player = _SelectSlides[_SelectSlideRecordChannel1].Selection; if (i == 1) - player = SelectSlides[_SelectSlideRecordChannel2].Selection; + player = _SelectSlides[_SelectSlideRecordChannel2].Selection; if (_DelayTest[i].Timer.ElapsedMilliseconds > _MaxDelayTime * 1000f || player == 0) { @@ -250,39 +268,39 @@ namespace Vocaluxe.Screens } } } - Texts[_TextDelayChannel1].Text = _DelayTest[0].Delay.ToString("000") + " ms"; - Texts[_TextDelayChannel2].Text = _DelayTest[1].Delay.ToString("000") + " ms"; + _Texts[_TextDelayChannel1].Text = _DelayTest[0].Delay.ToString("000") + " ms"; + _Texts[_TextDelayChannel2].Text = _DelayTest[1].Delay.ToString("000") + " ms"; } if (_CheckMicConfig()) { _ChannelEnergy[0] = 0f; - int player = SelectSlides[_SelectSlideRecordChannel1].Selection; + int player = _SelectSlides[_SelectSlideRecordChannel1].Selection; if (player > 0) { _ChannelEnergy[0] = CSound.RecordGetMaxVolume(player - 1); - Equalizers[_EqualizerChannel1].Update(CSound.ToneWeigth(player - 1)); + _Equalizers[_EqualizerChannel1].Update(CSound.ToneWeigth(player - 1)); } else - Equalizers[_EqualizerChannel1].Reset(); + _Equalizers[_EqualizerChannel1].Reset(); _ChannelEnergy[1] = 0f; - player = SelectSlides[_SelectSlideRecordChannel2].Selection; + player = _SelectSlides[_SelectSlideRecordChannel2].Selection; if (player > 0) { _ChannelEnergy[1] = CSound.RecordGetMaxVolume(player - 1); - Equalizers[_EqualizerChannel2].Update(CSound.ToneWeigth(player - 1)); + _Equalizers[_EqualizerChannel2].Update(CSound.ToneWeigth(player - 1)); } else - Equalizers[_EqualizerChannel2].Reset(); + _Equalizers[_EqualizerChannel2].Reset(); } else { for (int i = 0; i < _ChannelEnergy.Length; i++) _ChannelEnergy[i] = 0f; - Equalizers[_EqualizerChannel1].Reset(); - Equalizers[_EqualizerChannel2].Reset(); + _Equalizers[_EqualizerChannel1].Reset(); + _Equalizers[_EqualizerChannel2].Reset(); } return true; @@ -292,8 +310,8 @@ namespace Vocaluxe.Screens { base.OnShow(); - SelectSlides[_SelectSlideRecordDevices].Clear(); - SelectSlides[_SelectSlideRecordInputs].Clear(); + _SelectSlides[_SelectSlideRecordDevices].Clear(); + _SelectSlides[_SelectSlideRecordInputs].Clear(); for (int i = 0; i < _ChannelEnergy.Length; i++) _ChannelEnergy[i] = 0f; @@ -309,20 +327,20 @@ namespace Vocaluxe.Screens _GetFirstConfiguredRecordDevice(ref _DeviceNr, ref _InputNr); for (int dev = 0; dev < _Devices.Length; dev++) - SelectSlides[_SelectSlideRecordDevices].AddValue(_Devices[dev].Name); - SelectSlides[_SelectSlideRecordDevices].Selection = _DeviceNr; + _SelectSlides[_SelectSlideRecordDevices].AddValue(_Devices[dev].Name); + _SelectSlides[_SelectSlideRecordDevices].Selection = _DeviceNr; for (int inp = 0; inp < _Devices[0].Inputs.Count; inp++) - SelectSlides[_SelectSlideRecordInputs].AddValue(_Devices[0].Inputs[inp].Name); - SelectSlides[_SelectSlideRecordInputs].Selection = _InputNr; + _SelectSlides[_SelectSlideRecordInputs].AddValue(_Devices[0].Inputs[inp].Name); + _SelectSlides[_SelectSlideRecordInputs].Selection = _InputNr; _UpdateChannels(); } - SelectSlides[_SelectSlideRecordChannel1].Visible = _Devices != null; - SelectSlides[_SelectSlideRecordChannel2].Visible = _Devices != null; + _SelectSlides[_SelectSlideRecordChannel1].Visible = _Devices != null; + _SelectSlides[_SelectSlideRecordChannel2].Visible = _Devices != null; - Statics[_StaticWarning].Visible = false; - Texts[_TextWarning].Visible = false; + _Statics[_StaticWarning].Visible = false; + _Texts[_TextWarning].Visible = false; _DelayTest = null; if (_Devices != null) @@ -335,7 +353,7 @@ namespace Vocaluxe.Screens } } - SelectSlides[_SelectSlideDelay].Selection = CConfig.MicDelay / 20; + _SelectSlides[_SelectSlideDelay].Selection = CConfig.MicDelay / 20; _DelayTestRunning = false; _DelaySound = -1; @@ -349,38 +367,38 @@ namespace Vocaluxe.Screens public override bool Draw() { - DrawBG(); + _DrawBG(); if (!_CheckMicConfig()) { - Statics[_StaticWarning].Visible = true; - Texts[_TextWarning].Visible = true; + _Statics[_StaticWarning].Visible = true; + _Texts[_TextWarning].Visible = true; } else { - Statics[_StaticWarning].Visible = false; - Texts[_TextWarning].Visible = false; + _Statics[_StaticWarning].Visible = false; + _Texts[_TextWarning].Visible = false; } for (int i = 0; i < _StaticEnergyChannel.Length; i++) { if (_ChannelEnergy[i] > 0f) { - SRectF rect = new SRectF(Statics[_StaticEnergyChannel[i]].Rect.X, - Statics[_StaticEnergyChannel[i]].Rect.Y, - Statics[_StaticEnergyChannel[i]].Rect.W * _ChannelEnergy[i], - Statics[_StaticEnergyChannel[i]].Rect.H, - Statics[_StaticEnergyChannel[i]].Rect.Z); + SRectF rect = new SRectF(_Statics[_StaticEnergyChannel[i]].Rect.X, + _Statics[_StaticEnergyChannel[i]].Rect.Y, + _Statics[_StaticEnergyChannel[i]].Rect.W * _ChannelEnergy[i], + _Statics[_StaticEnergyChannel[i]].Rect.H, + _Statics[_StaticEnergyChannel[i]].Rect.Z); - CDraw.DrawTexture(Statics[_StaticEnergyChannel[i]].Texture, Statics[_StaticEnergyChannel[i]].Rect, + CDraw.DrawTexture(_Statics[_StaticEnergyChannel[i]].Texture, _Statics[_StaticEnergyChannel[i]].Rect, new SColorF(1f, 1f, 1f, 1f), rect); } } - Equalizers[_EqualizerChannel1].Draw(); - Equalizers[_EqualizerChannel2].Draw(); + _Equalizers[_EqualizerChannel1].Draw(); + _Equalizers[_EqualizerChannel2].Draw(); - DrawFG(); + _DrawFG(); return true; } @@ -396,25 +414,25 @@ namespace Vocaluxe.Screens private void _OnDeviceEvent() { - if (SelectSlides[_SelectSlideRecordDevices].Selection != _DeviceNr) + if (_SelectSlides[_SelectSlideRecordDevices].Selection != _DeviceNr) { - SelectSlides[_SelectSlideRecordInputs].Clear(); - _DeviceNr = SelectSlides[_SelectSlideRecordDevices].Selection; + _SelectSlides[_SelectSlideRecordInputs].Clear(); + _DeviceNr = _SelectSlides[_SelectSlideRecordDevices].Selection; _InputNr = 0; for (int inp = 0; inp < _Devices[_DeviceNr].Inputs.Count; inp++) - SelectSlides[_SelectSlideRecordInputs].AddValue(_Devices[_DeviceNr].Inputs[inp].Name); + _SelectSlides[_SelectSlideRecordInputs].AddValue(_Devices[_DeviceNr].Inputs[inp].Name); _InputNr = 0; - SelectSlides[_SelectSlideRecordInputs].Selection = 0; + _SelectSlides[_SelectSlideRecordInputs].Selection = 0; _UpdateChannels(); } } private void _OnInputEvent() { - if (SelectSlides[_SelectSlideRecordInputs].Selection != _InputNr) + if (_SelectSlides[_SelectSlideRecordInputs].Selection != _InputNr) { - _InputNr = SelectSlides[_SelectSlideRecordInputs].Selection; + _InputNr = _SelectSlides[_SelectSlideRecordInputs].Selection; _UpdateChannels(); } @@ -422,7 +440,7 @@ namespace Vocaluxe.Screens private void _SaveDelayConfig() { - CConfig.MicDelay = SelectSlides[_SelectSlideDelay].Selection * 20; + CConfig.MicDelay = _SelectSlides[_SelectSlideDelay].Selection * 20; CConfig.SaveConfig(); } @@ -470,15 +488,15 @@ namespace Vocaluxe.Screens if (_DeviceNr < 0) return; SInput input = _Devices[_DeviceNr].Inputs[_InputNr]; - input.PlayerChannel1 = SelectSlides[_SelectSlideRecordChannel1].Selection; - input.PlayerChannel2 = SelectSlides[_SelectSlideRecordChannel2].Selection; + input.PlayerChannel1 = _SelectSlides[_SelectSlideRecordChannel1].Selection; + input.PlayerChannel2 = _SelectSlides[_SelectSlideRecordChannel2].Selection; _Devices[_DeviceNr].Inputs[_InputNr] = input; } private void _UpdateChannels() { - SelectSlides[_SelectSlideRecordChannel1].Selection = _Devices[_DeviceNr].Inputs[_InputNr].PlayerChannel1; - SelectSlides[_SelectSlideRecordChannel2].Selection = _Devices[_DeviceNr].Inputs[_InputNr].PlayerChannel2; + _SelectSlides[_SelectSlideRecordChannel1].Selection = _Devices[_DeviceNr].Inputs[_InputNr].PlayerChannel1; + _SelectSlides[_SelectSlideRecordChannel2].Selection = _Devices[_DeviceNr].Inputs[_InputNr].PlayerChannel2; _SaveMicConfig(); } diff --git a/Vocaluxe/Screens/CScreenOptionsSound.cs b/Vocaluxe/Screens/CScreenOptionsSound.cs index 49886ea5..8d6ddfa0 100644 --- a/Vocaluxe/Screens/CScreenOptionsSound.cs +++ b/Vocaluxe/Screens/CScreenOptionsSound.cs @@ -1,4 +1,23 @@ -using System.Windows.Forms; +#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.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -21,7 +40,6 @@ namespace Vocaluxe.Screens private const string _ButtonExit = "ButtonExit"; private int _BackgroundMusicVolume; - private EOffOn _BackgroundMusic; public override void Init() { @@ -35,18 +53,18 @@ namespace Vocaluxe.Screens public override void LoadTheme(string xmlPath) { base.LoadTheme(xmlPath); - SelectSlides[_SelectSlideBackgroundMusic].SetValues((int)CConfig.BackgroundMusic); - SelectSlides[_SelectSlideBackgroundMusicVolume].AddValues(new string[] + _SelectSlides[_SelectSlideBackgroundMusic].SetValues((int)CConfig.BackgroundMusic); + _SelectSlides[_SelectSlideBackgroundMusicVolume].AddValues(new string[] {"0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"}); - SelectSlides[_SelectSlideBackgroundMusicVolume].Selection = CConfig.BackgroundMusicVolume / 5; - SelectSlides[_SelectSlideBackgroundMusicSource].SetValues((int)CConfig.BackgroundMusicSource); - SelectSlides[_SelectSlideBackgroundMusicSource].Selection = (int)CConfig.BackgroundMusicSource; - SelectSlides[_SelectSlidePreviewMusicVolume].AddValues(new string[] + _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection = CConfig.BackgroundMusicVolume / 5; + _SelectSlides[_SelectSlideBackgroundMusicSource].SetValues((int)CConfig.BackgroundMusicSource); + _SelectSlides[_SelectSlideBackgroundMusicSource].Selection = (int)CConfig.BackgroundMusicSource; + _SelectSlides[_SelectSlidePreviewMusicVolume].AddValues(new string[] {"0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"}); - SelectSlides[_SelectSlidePreviewMusicVolume].Selection = CConfig.PreviewMusicVolume / 5; - SelectSlides[_SelectSlideGameMusicVolume].AddValues(new string[] + _SelectSlides[_SelectSlidePreviewMusicVolume].Selection = CConfig.PreviewMusicVolume / 5; + _SelectSlides[_SelectSlideGameMusicVolume].AddValues(new string[] {"0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"}); - SelectSlides[_SelectSlideGameMusicVolume].Selection = CConfig.GameMusicVolume / 5; + _SelectSlides[_SelectSlideGameMusicVolume].Selection = CConfig.GameMusicVolume / 5; } public override bool HandleInput(SKeyEvent keyEvent) @@ -70,7 +88,7 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) { _SaveConfig(); CGraphics.FadeTo(EScreens.ScreenOptions); @@ -98,10 +116,10 @@ namespace Vocaluxe.Screens _SaveConfig(); CGraphics.FadeTo(EScreens.ScreenOptions); } - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { _SaveConfig(); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) CGraphics.FadeTo(EScreens.ScreenOptions); } return true; @@ -110,7 +128,7 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { if (_BackgroundMusicVolume != CConfig.BackgroundMusicVolume) - SelectSlides[_SelectSlideBackgroundMusicVolume].Selection = CConfig.BackgroundMusicVolume / 5; + _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection = CConfig.BackgroundMusicVolume / 5; return true; } @@ -123,22 +141,21 @@ namespace Vocaluxe.Screens public override void OnShow() { base.OnShow(); - _BackgroundMusic = CConfig.BackgroundMusic; _BackgroundMusicVolume = CConfig.BackgroundMusicVolume; - SelectSlides[_SelectSlideGameMusicVolume].Selection = CConfig.GameMusicVolume / 5; - SelectSlides[_SelectSlidePreviewMusicVolume].Selection = CConfig.PreviewMusicVolume / 5; + _SelectSlides[_SelectSlideGameMusicVolume].Selection = CConfig.GameMusicVolume / 5; + _SelectSlides[_SelectSlidePreviewMusicVolume].Selection = CConfig.PreviewMusicVolume / 5; } private void _SaveConfig() { - CConfig.GameMusicVolume = SelectSlides[_SelectSlideGameMusicVolume].Selection * 5; - CConfig.PreviewMusicVolume = SelectSlides[_SelectSlidePreviewMusicVolume].Selection * 5; + CConfig.GameMusicVolume = _SelectSlides[_SelectSlideGameMusicVolume].Selection * 5; + CConfig.PreviewMusicVolume = _SelectSlides[_SelectSlidePreviewMusicVolume].Selection * 5; CConfig.SaveConfig(); - EOffOn newOffOn = (EOffOn)SelectSlides[_SelectSlideBackgroundMusic].Selection; - EBackgroundMusicSource newSource = (EBackgroundMusicSource)SelectSlides[_SelectSlideBackgroundMusicSource].Selection; - float newVolume = SelectSlides[_SelectSlideBackgroundMusicVolume].Selection * 5; + EOffOn newOffOn = (EOffOn)_SelectSlides[_SelectSlideBackgroundMusic].Selection; + EBackgroundMusicSource newSource = (EBackgroundMusicSource)_SelectSlides[_SelectSlideBackgroundMusicSource].Selection; + float newVolume = _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection * 5; CBackgroundMusic.CheckAndApplyConfig(newOffOn, newSource, newVolume); } diff --git a/Vocaluxe/Screens/CScreenOptionsTheme.cs b/Vocaluxe/Screens/CScreenOptionsTheme.cs index b2b28262..5beca6e7 100644 --- a/Vocaluxe/Screens/CScreenOptionsTheme.cs +++ b/Vocaluxe/Screens/CScreenOptionsTheme.cs @@ -1,4 +1,23 @@ -using System; +#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.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -52,19 +71,19 @@ namespace Vocaluxe.Screens { base.LoadTheme(xmlPath); - SelectSlides[_SelectSlideTheme].AddValues(CTheme.ThemeNames); - SelectSlides[_SelectSlideTheme].Selection = CTheme.GetThemeIndex(-1); + _SelectSlides[_SelectSlideTheme].AddValues(CTheme.ThemeNames); + _SelectSlides[_SelectSlideTheme].Selection = CTheme.GetThemeIndex(-1); - SelectSlides[_SelectSlideSkin].AddValues(CTheme.SkinNames); - SelectSlides[_SelectSlideSkin].Selection = CTheme.GetSkinIndex(-1); + _SelectSlides[_SelectSlideSkin].AddValues(CTheme.SkinNames); + _SelectSlides[_SelectSlideSkin].Selection = CTheme.GetSkinIndex(-1); - SelectSlides[_SelectSlideCover].AddValues(CCover.CoverThemes); - SelectSlides[_SelectSlideCover].Selection = CCover.GetCoverThemeIndex(); - SelectSlides[_SelectSlideNoteLines].SetValues((int)CConfig.DrawNoteLines); - SelectSlides[_SelectSlideToneHelper].SetValues((int)CConfig.DrawToneHelper); - SelectSlides[_SelectSlideTimerLook].SetValues((int)CConfig.TimerLook); - SelectSlides[_SelectSlideFadeInfo].SetValues((int)CConfig.FadePlayerInfo); - SelectSlides[_SelectSlideCoverLoading].SetValues((int)CConfig.CoverLoading); + _SelectSlides[_SelectSlideCover].AddValues(CCover.CoverThemes); + _SelectSlides[_SelectSlideCover].Selection = CCover.GetCoverThemeIndex(); + _SelectSlides[_SelectSlideNoteLines].SetValues((int)CConfig.DrawNoteLines); + _SelectSlides[_SelectSlideToneHelper].SetValues((int)CConfig.DrawToneHelper); + _SelectSlides[_SelectSlideTimerLook].SetValues((int)CConfig.TimerLook); + _SelectSlides[_SelectSlideFadeInfo].SetValues((int)CConfig.FadePlayerInfo); + _SelectSlides[_SelectSlideCoverLoading].SetValues((int)CConfig.CoverLoading); } public override bool HandleInput(SKeyEvent keyEvent) @@ -87,7 +106,7 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) _Close(); break; @@ -110,9 +129,9 @@ namespace Vocaluxe.Screens if (mouseEvent.RB) _Close(); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) _Close(); else _OnChange(); @@ -149,18 +168,18 @@ namespace Vocaluxe.Screens private void _SaveConfig() { - CConfig.Theme = CTheme.ThemeNames[SelectSlides[_SelectSlideTheme].Selection]; - CConfig.Skin = CTheme.SkinNames[SelectSlides[_SelectSlideSkin].Selection]; - CConfig.CoverTheme = CCover.CoverThemes[SelectSlides[_SelectSlideCover].Selection]; - CConfig.DrawNoteLines = (EOffOn)SelectSlides[_SelectSlideNoteLines].Selection; - CConfig.DrawToneHelper = (EOffOn)SelectSlides[_SelectSlideToneHelper].Selection; - CConfig.TimerLook = (ETimerLook)SelectSlides[_SelectSlideTimerLook].Selection; - CConfig.FadePlayerInfo = (EFadePlayerInfo)SelectSlides[_SelectSlideFadeInfo].Selection; - CConfig.CoverLoading = (ECoverLoading)SelectSlides[_SelectSlideCoverLoading].Selection; + CConfig.Theme = CTheme.ThemeNames[_SelectSlides[_SelectSlideTheme].Selection]; + CConfig.Skin = CTheme.SkinNames[_SelectSlides[_SelectSlideSkin].Selection]; + CConfig.CoverTheme = CCover.CoverThemes[_SelectSlides[_SelectSlideCover].Selection]; + CConfig.DrawNoteLines = (EOffOn)_SelectSlides[_SelectSlideNoteLines].Selection; + CConfig.DrawToneHelper = (EOffOn)_SelectSlides[_SelectSlideToneHelper].Selection; + CConfig.TimerLook = (ETimerLook)_SelectSlides[_SelectSlideTimerLook].Selection; + CConfig.FadePlayerInfo = (EFadePlayerInfo)_SelectSlides[_SelectSlideFadeInfo].Selection; + CConfig.CoverLoading = (ECoverLoading)_SelectSlides[_SelectSlideCoverLoading].Selection; CConfig.SaveConfig(); - if (_OldCoverTheme != SelectSlides[_SelectSlideCover].Selection) + if (_OldCoverTheme != _SelectSlides[_SelectSlideCover].Selection) { CCover.ReloadCover(); CSongs.Filter.SearchString = String.Empty; @@ -168,10 +187,10 @@ namespace Vocaluxe.Screens CSongs.Categorizer.Tabs = CConfig.Tabs; } - if (_OldTheme != SelectSlides[_SelectSlideTheme].Selection) + if (_OldTheme != _SelectSlides[_SelectSlideTheme].Selection) { - CConfig.Theme = CTheme.ThemeNames[SelectSlides[_SelectSlideTheme].Selection]; - _OldTheme = SelectSlides[_SelectSlideTheme].Selection; + CConfig.Theme = CTheme.ThemeNames[_SelectSlides[_SelectSlideTheme].Selection]; + _OldTheme = _SelectSlides[_SelectSlideTheme].Selection; CTheme.UnloadSkins(); CFonts.UnloadThemeFonts(CConfig.Theme); @@ -185,16 +204,15 @@ namespace Vocaluxe.Screens CTheme.LoadSkins(); CTheme.LoadTheme(); CGraphics.ReloadTheme(); - return; } } private void _OnChange() { - if (_OldTheme != SelectSlides[_SelectSlideTheme].Selection) + if (_OldTheme != _SelectSlides[_SelectSlideTheme].Selection) { - CConfig.Theme = CTheme.ThemeNames[SelectSlides[_SelectSlideTheme].Selection]; - _OldTheme = SelectSlides[_SelectSlideTheme].Selection; + CConfig.Theme = CTheme.ThemeNames[_SelectSlides[_SelectSlideTheme].Selection]; + _OldTheme = _SelectSlides[_SelectSlideTheme].Selection; CTheme.UnloadSkins(); CFonts.UnloadThemeFonts(CConfig.Theme); @@ -214,9 +232,9 @@ namespace Vocaluxe.Screens return; } - if (_TempSkin != SelectSlides[_SelectSlideSkin].Selection) + if (_TempSkin != _SelectSlides[_SelectSlideSkin].Selection) { - _TempSkin = SelectSlides[_SelectSlideSkin].Selection; + _TempSkin = _SelectSlides[_SelectSlideSkin].Selection; _PauseBG(); CConfig.Skin = CTheme.SkinNames[_TempSkin]; @@ -224,10 +242,5 @@ namespace Vocaluxe.Screens _ResumeBG(); } } - - private void _AfterSkinReload() - { - _Active = true; - } } } \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenOptionsVideo.cs b/Vocaluxe/Screens/CScreenOptionsVideo.cs index 0b91cd2a..3367edc2 100644 --- a/Vocaluxe/Screens/CScreenOptionsVideo.cs +++ b/Vocaluxe/Screens/CScreenOptionsVideo.cs @@ -1,4 +1,23 @@ -using System; +#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.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Lib.Webcam; @@ -47,10 +66,10 @@ namespace Vocaluxe.Screens { base.LoadTheme(xmlPath); - SelectSlides[_SelectSlideVideoBackgrounds].SetValues((int)CConfig.VideoBackgrounds); - SelectSlides[_SelectSlideVideoPreview].SetValues((int)CConfig.VideoPreview); - SelectSlides[_SelectSlideVideosInSongs].SetValues((int)CConfig.VideosInSongs); - SelectSlides[_SelectSlideVideosToBackground].SetValues((int)CConfig.VideosToBackground); + _SelectSlides[_SelectSlideVideoBackgrounds].SetValues((int)CConfig.VideoBackgrounds); + _SelectSlides[_SelectSlideVideoPreview].SetValues((int)CConfig.VideoPreview); + _SelectSlides[_SelectSlideVideosInSongs].SetValues((int)CConfig.VideosInSongs); + _SelectSlides[_SelectSlideVideosToBackground].SetValues((int)CConfig.VideosToBackground); } public override bool HandleInput(SKeyEvent keyEvent) @@ -74,7 +93,7 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) { _SaveConfig(); CGraphics.FadeTo(EScreens.ScreenOptions); @@ -82,17 +101,17 @@ namespace Vocaluxe.Screens break; case Keys.Left: - if (SelectSlides[_SelectSlideWebcamDevices].Selected) + if (_SelectSlides[_SelectSlideWebcamDevices].Selected) _OnDeviceEvent(); - if (SelectSlides[_SelectSlideWebcamCapabilities].Selected) + if (_SelectSlides[_SelectSlideWebcamCapabilities].Selected) _OnCapabilitiesEvent(); _SaveConfig(); break; case Keys.Right: - if (SelectSlides[_SelectSlideWebcamDevices].Selected) + if (_SelectSlides[_SelectSlideWebcamDevices].Selected) _OnDeviceEvent(); - if (SelectSlides[_SelectSlideWebcamCapabilities].Selected) + if (_SelectSlides[_SelectSlideWebcamCapabilities].Selected) _OnCapabilitiesEvent(); _SaveConfig(); break; @@ -111,14 +130,14 @@ namespace Vocaluxe.Screens CGraphics.FadeTo(EScreens.ScreenOptions); } - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (SelectSlides[_SelectSlideWebcamDevices].Selected) + if (_SelectSlides[_SelectSlideWebcamDevices].Selected) _OnDeviceEvent(); - if (SelectSlides[_SelectSlideWebcamCapabilities].Selected) + if (_SelectSlides[_SelectSlideWebcamCapabilities].Selected) _OnCapabilitiesEvent(); _SaveConfig(); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) CGraphics.FadeTo(EScreens.ScreenOptions); } return true; @@ -127,8 +146,8 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { CWebcam.GetFrame(ref _WebcamTexture); - Statics[_StaticWebcamOutput].Texture = _WebcamTexture; - SelectSlides[_SelectSlideVideosToBackground].Selection = (int)CConfig.VideosToBackground; + _Statics[_StaticWebcamOutput].Texture = _WebcamTexture; + _SelectSlides[_SelectSlideVideosToBackground].Selection = (int)CConfig.VideosToBackground; return true; } @@ -148,57 +167,56 @@ namespace Vocaluxe.Screens public override void OnShow() { base.OnShow(); - SelectSlides[_SelectSlideWebcamDevices].Clear(); - SelectSlides[_SelectSlideWebcamCapabilities].Clear(); + _SelectSlides[_SelectSlideWebcamDevices].Clear(); + _SelectSlides[_SelectSlideWebcamCapabilities].Clear(); _DeviceNr = -1; _CapabilityNr = -1; SWebcamDevice[] devices = CWebcam.GetDevices(); + bool ssVisible = false; try { - if (devices != null) + if (devices != null && devices.Length > 0) { - if (devices.Length > 0) - { - _DeviceNr = 0; - _CapabilityNr = 0; - _GetFirstConfiguredWebcamDevice(ref _DeviceNr, ref _CapabilityNr); + _DeviceNr = 0; + _CapabilityNr = 0; + _GetFirstConfiguredWebcamDevice(ref _DeviceNr, ref _CapabilityNr); - foreach (SWebcamDevice d in devices) - SelectSlides[_SelectSlideWebcamDevices].AddValue(d.Name); - SelectSlides[_SelectSlideWebcamDevices].Selection = _DeviceNr; + foreach (SWebcamDevice d in devices) + _SelectSlides[_SelectSlideWebcamDevices].AddValue(d.Name); + _SelectSlides[_SelectSlideWebcamDevices].Selection = _DeviceNr; - foreach (SCapabilities c in devices[_DeviceNr].Capabilities) - SelectSlides[_SelectSlideWebcamCapabilities].AddValue(c.Width.ToString() + " x " + c.Height.ToString() + " @ " + c.Framerate.ToString() + " FPS "); - _Config.MonikerString = devices[SelectSlides[_SelectSlideWebcamDevices].Selection].MonikerString; - _Config.Width = devices[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[SelectSlides[_SelectSlideWebcamCapabilities].Selection].Width; - _Config.Height = devices[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[SelectSlides[_SelectSlideWebcamCapabilities].Selection].Height; - _Config.Framerate = devices[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[SelectSlides[_SelectSlideWebcamCapabilities].Selection].Framerate; - CWebcam.Close(); - CWebcam.Select(CConfig.WebcamConfig); - CWebcam.Start(); - } + foreach (SCapabilities c in devices[_DeviceNr].Capabilities) + _SelectSlides[_SelectSlideWebcamCapabilities].AddValue(c.Width + " x " + c.Height + " @ " + c.Framerate + " FPS "); + _Config.MonikerString = devices[_SelectSlides[_SelectSlideWebcamDevices].Selection].MonikerString; + _Config.Width = devices[_SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[_SelectSlides[_SelectSlideWebcamCapabilities].Selection].Width; + _Config.Height = devices[_SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[_SelectSlides[_SelectSlideWebcamCapabilities].Selection].Height; + _Config.Framerate = + devices[_SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[_SelectSlides[_SelectSlideWebcamCapabilities].Selection].Framerate; + CWebcam.Close(); + CWebcam.Select(CConfig.WebcamConfig); + CWebcam.Start(); + ssVisible = true; } } catch (Exception e) { CLog.LogError("Error on listing webcam capabilities: " + e.Message); - devices = null; } - SelectSlides[_SelectSlideWebcamDevices].Visible = devices != null && devices.Length > 0; - SelectSlides[_SelectSlideWebcamCapabilities].Visible = devices != null && devices.Length > 0; - Statics[_StaticWebcamOutput].Visible = devices != null && devices.Length > 0; + _SelectSlides[_SelectSlideWebcamDevices].Visible = ssVisible; + _SelectSlides[_SelectSlideWebcamCapabilities].Visible = ssVisible; + _Statics[_StaticWebcamOutput].Visible = ssVisible; } private void _SaveConfig() { - CConfig.VideoBackgrounds = (EOffOn)SelectSlides[_SelectSlideVideoBackgrounds].Selection; - CConfig.VideoPreview = (EOffOn)SelectSlides[_SelectSlideVideoPreview].Selection; - CConfig.VideosInSongs = (EOffOn)SelectSlides[_SelectSlideVideosInSongs].Selection; - CConfig.VideosToBackground = (EOffOn)SelectSlides[_SelectSlideVideosToBackground].Selection; + CConfig.VideoBackgrounds = (EOffOn)_SelectSlides[_SelectSlideVideoBackgrounds].Selection; + CConfig.VideoPreview = (EOffOn)_SelectSlides[_SelectSlideVideoPreview].Selection; + CConfig.VideosInSongs = (EOffOn)_SelectSlides[_SelectSlideVideosInSongs].Selection; + CConfig.VideosToBackground = (EOffOn)_SelectSlides[_SelectSlideVideosToBackground].Selection; CConfig.WebcamConfig = _Config; CBackgroundMusic.VideoEnabled = true; @@ -208,24 +226,24 @@ namespace Vocaluxe.Screens private void _OnDeviceEvent() { - if (SelectSlides[_SelectSlideWebcamDevices].Selection != _DeviceNr) + if (_SelectSlides[_SelectSlideWebcamDevices].Selection != _DeviceNr) { - SelectSlides[_SelectSlideWebcamCapabilities].Clear(); - _DeviceNr = SelectSlides[_SelectSlideWebcamDevices].Selection; + _SelectSlides[_SelectSlideWebcamCapabilities].Clear(); + _DeviceNr = _SelectSlides[_SelectSlideWebcamDevices].Selection; _CapabilityNr = 0; - SWebcamDevice[] d = CWebcam.GetDevices(); - for (int i = 0; i < d[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities.Count; i++) + SWebcamDevice d = CWebcam.GetDevices()[_DeviceNr]; + for (int i = 0; i < d.Capabilities.Count; i++) { - SelectSlides[_SelectSlideWebcamCapabilities].AddValue(d[_DeviceNr].Capabilities[i].Width.ToString() + " x " + d[_DeviceNr].Capabilities[i].Height.ToString() + - " @ " + d[_DeviceNr].Capabilities[i].Framerate.ToString() + "FPS"); + _SelectSlides[_SelectSlideWebcamCapabilities].AddValue(d.Capabilities[i].Width + " x " + d.Capabilities[i].Height + + " @ " + d.Capabilities[i].Framerate + "FPS"); } - SelectSlides[_SelectSlideWebcamCapabilities].Selection = 0; + _SelectSlides[_SelectSlideWebcamCapabilities].Selection = 0; - _Config.MonikerString = d[SelectSlides[_SelectSlideWebcamDevices].Selection].MonikerString; - _Config.Width = d[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[SelectSlides[_SelectSlideWebcamCapabilities].Selection].Width; - _Config.Height = d[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[SelectSlides[_SelectSlideWebcamCapabilities].Selection].Height; - _Config.Framerate = d[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[SelectSlides[_SelectSlideWebcamCapabilities].Selection].Framerate; + _Config.MonikerString = d.MonikerString; + _Config.Width = d.Capabilities[_SelectSlides[_SelectSlideWebcamCapabilities].Selection].Width; + _Config.Height = d.Capabilities[_SelectSlides[_SelectSlideWebcamCapabilities].Selection].Height; + _Config.Framerate = d.Capabilities[_SelectSlides[_SelectSlideWebcamCapabilities].Selection].Framerate; CWebcam.Close(); CWebcam.Select(_Config); @@ -235,15 +253,15 @@ namespace Vocaluxe.Screens private void _OnCapabilitiesEvent() { - if (SelectSlides[_SelectSlideWebcamCapabilities].Selection != _CapabilityNr) + if (_SelectSlides[_SelectSlideWebcamCapabilities].Selection != _CapabilityNr) { - _CapabilityNr = SelectSlides[_SelectSlideWebcamCapabilities].Selection; + _CapabilityNr = _SelectSlides[_SelectSlideWebcamCapabilities].Selection; - SWebcamDevice[] d = CWebcam.GetDevices(); - _Config.MonikerString = d[SelectSlides[_SelectSlideWebcamDevices].Selection].MonikerString; - _Config.Width = d[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[SelectSlides[_SelectSlideWebcamCapabilities].Selection].Width; - _Config.Height = d[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[SelectSlides[_SelectSlideWebcamCapabilities].Selection].Height; - _Config.Framerate = d[SelectSlides[_SelectSlideWebcamDevices].Selection].Capabilities[SelectSlides[_SelectSlideWebcamCapabilities].Selection].Framerate; + SWebcamDevice d = CWebcam.GetDevices()[_SelectSlides[_SelectSlideWebcamDevices].Selection]; + _Config.MonikerString = d.MonikerString; + _Config.Width = d.Capabilities[_SelectSlides[_SelectSlideWebcamCapabilities].Selection].Width; + _Config.Height = d.Capabilities[_SelectSlides[_SelectSlideWebcamCapabilities].Selection].Height; + _Config.Framerate = d.Capabilities[_SelectSlides[_SelectSlideWebcamCapabilities].Selection].Framerate; CWebcam.Close(); CWebcam.Select(_Config); @@ -260,17 +278,16 @@ namespace Vocaluxe.Screens for (int i = 0; i < devices.Length; i++) { - if (devices[i].MonikerString == CConfig.WebcamConfig.MonikerString) + if (devices[i].MonikerString != CConfig.WebcamConfig.MonikerString) + continue; + for (int j = 0; j < devices[i].Capabilities.Count; j++) { - for (int j = 0; j < devices[i].Capabilities.Count; j++) + if (devices[i].Capabilities[j].Framerate == CConfig.WebcamConfig.Framerate && devices[i].Capabilities[j].Width == CConfig.WebcamConfig.Width && + devices[i].Capabilities[j].Height == CConfig.WebcamConfig.Height) { - if (devices[i].Capabilities[j].Framerate == CConfig.WebcamConfig.Framerate && devices[i].Capabilities[j].Width == CConfig.WebcamConfig.Width && - devices[i].Capabilities[j].Height == CConfig.WebcamConfig.Height) - { - device = i; - capabilities = j; - return; - } + device = i; + capabilities = j; + return; } } } diff --git a/Vocaluxe/Screens/CScreenParty.cs b/Vocaluxe/Screens/CScreenParty.cs index 0d3892e1..f6e37116 100644 --- a/Vocaluxe/Screens/CScreenParty.cs +++ b/Vocaluxe/Screens/CScreenParty.cs @@ -1,4 +1,23 @@ -using System.Collections.Generic; +#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.Collections.Generic; using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -50,16 +69,16 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonStart].Selected) + if (_Buttons[_ButtonStart].Selected) _StartPartyMode(); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) CGraphics.FadeTo(EScreens.ScreenMain); break; case Keys.Left: case Keys.Right: - if (SelectSlides[_SelectSlideModes].Selected) + if (_SelectSlides[_SelectSlideModes].Selected) _UpdateSelection(); break; } @@ -71,15 +90,15 @@ namespace Vocaluxe.Screens { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonStart].Selected) + if (_Buttons[_ButtonStart].Selected) _StartPartyMode(); - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) CGraphics.FadeTo(EScreens.ScreenMain); - if (SelectSlides[_SelectSlideModes].Selected) + if (_SelectSlides[_SelectSlideModes].Selected) _UpdateSelection(); } @@ -95,13 +114,13 @@ namespace Vocaluxe.Screens _PartyModeInfos = CParty.GetPartyModeInfos(); - SelectSlides[_SelectSlideModes].Clear(); + _SelectSlides[_SelectSlideModes].Clear(); foreach (SPartyModeInfos info in _PartyModeInfos) - SelectSlides[_SelectSlideModes].AddValue(info.Name, info.PartyModeID); - SelectSlides[_SelectSlideModes].Selection = 0; + _SelectSlides[_SelectSlideModes].AddValue(info.Name, info.PartyModeID); + _SelectSlides[_SelectSlideModes].Selection = 0; _UpdateSelection(); - SetInteractionToSelectSlide(SelectSlides[_SelectSlideModes]); + _SetInteractionToSelectSlide(_SelectSlides[_SelectSlideModes]); } public override bool UpdateGame() @@ -121,49 +140,49 @@ namespace Vocaluxe.Screens if (_PartyModeInfos.Count == 0) return; - int index = SelectSlides[_SelectSlideModes].Selection; + int index = _SelectSlides[_SelectSlideModes].Selection; if (index >= _PartyModeInfos.Count) return; //Description - Texts[_TextDescription].Text = _PartyModeInfos[index].Description; - Texts[_TextDescription].TranslationID = _PartyModeInfos[index].PartyModeID; + _Texts[_TextDescription].Text = _PartyModeInfos[index].Description; + _Texts[_TextDescription].TranslationID = _PartyModeInfos[index].PartyModeID; //TargetAudience - Texts[_TextTargetAudience].TranslationID = _PartyModeInfos[index].PartyModeID; - Texts[_TextTargetAudience].Text = _PartyModeInfos[index].TargetAudience; + _Texts[_TextTargetAudience].TranslationID = _PartyModeInfos[index].PartyModeID; + _Texts[_TextTargetAudience].Text = _PartyModeInfos[index].TargetAudience; //NumTeams if (_PartyModeInfos[index].MaxTeams == 0) - Texts[_TextNumTeams].Text = "TR_SCREENPARTY_NOTEAMS"; + _Texts[_TextNumTeams].Text = "TR_SCREENPARTY_NOTEAMS"; else if (_PartyModeInfos[index].MaxTeams == _PartyModeInfos[index].MinTeams) - Texts[_TextNumTeams].Text = _PartyModeInfos[index].MaxTeams.ToString(); + _Texts[_TextNumTeams].Text = _PartyModeInfos[index].MaxTeams.ToString(); else if (_PartyModeInfos[index].MaxTeams > _PartyModeInfos[index].MinTeams) - Texts[_TextNumTeams].Text = _PartyModeInfos[index].MinTeams + " - " + _PartyModeInfos[index].MaxTeams; + _Texts[_TextNumTeams].Text = _PartyModeInfos[index].MinTeams + " - " + _PartyModeInfos[index].MaxTeams; //NumPlayers if (_PartyModeInfos[index].MaxPlayers == _PartyModeInfos[index].MinPlayers) - Texts[_TextNumPlayers].Text = _PartyModeInfos[index].MaxTeams.ToString(); + _Texts[_TextNumPlayers].Text = _PartyModeInfos[index].MaxTeams.ToString(); else if (_PartyModeInfos[index].MaxPlayers > _PartyModeInfos[index].MinPlayers) - Texts[_TextNumPlayers].Text = _PartyModeInfos[index].MinPlayers + " - " + _PartyModeInfos[index].MaxPlayers; + _Texts[_TextNumPlayers].Text = _PartyModeInfos[index].MinPlayers + " - " + _PartyModeInfos[index].MaxPlayers; //Author - Texts[_TextAuthor].Text = _PartyModeInfos[index].Author; - Texts[_TextAuthor].TranslationID = _PartyModeInfos[index].PartyModeID; + _Texts[_TextAuthor].Text = _PartyModeInfos[index].Author; + _Texts[_TextAuthor].TranslationID = _PartyModeInfos[index].PartyModeID; //Version - Texts[_TextVersion].Text = _PartyModeInfos[index].VersionMajor + "." + _PartyModeInfos[index].VersionMinor; - Texts[_TextVersion].TranslationID = _PartyModeInfos[index].PartyModeID; + _Texts[_TextVersion].Text = _PartyModeInfos[index].VersionMajor + "." + _PartyModeInfos[index].VersionMinor; + _Texts[_TextVersion].TranslationID = _PartyModeInfos[index].PartyModeID; if (!_PartyModeInfos[index].Playable) { - Buttons[_ButtonStart].Visible = false; - Texts[_TextError].Visible = true; + _Buttons[_ButtonStart].Visible = false; + _Texts[_TextError].Visible = true; } else { - Buttons[_ButtonStart].Visible = true; - Texts[_TextError].Visible = false; + _Buttons[_ButtonStart].Visible = true; + _Texts[_TextError].Visible = false; } } @@ -172,19 +191,15 @@ namespace Vocaluxe.Screens if (_PartyModeInfos.Count == 0) return; - int index = SelectSlides[_SelectSlideModes].Selection; + int index = _SelectSlides[_SelectSlideModes].Selection; if (index >= _PartyModeInfos.Count) return; - if (CMain.Config.GetMaxNumMics() == 0) + if (CConfig.GetMaxNumMics() == 0) return; //TODO: Add message! - if (_PartyModeInfos[index].Playable) - { - CParty.SetPartyMode(_PartyModeInfos[index].PartyModeID); - CGraphics.FadeTo(EScreens.ScreenPartyDummy); - } - //TODO: else Message! + CParty.SetPartyMode(_PartyModeInfos[index].PartyModeID); + CGraphics.FadeTo(EScreens.ScreenPartyDummy); } } } \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index cdf9b8ec..87ff1d71 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -1,4 +1,23 @@ -using System; +#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.Drawing; using System.Drawing.Imaging; using System.IO; @@ -60,16 +79,13 @@ namespace Vocaluxe.Screens { base.LoadTheme(xmlPath); - Buttons[_ButtonSaveSnapshot].Visible = false; - Buttons[_ButtonDiscardSnapshot].Visible = false; - Buttons[_ButtonTakeSnapshot].Visible = false; - if (CWebcam.GetDevices().Length > 0) - Buttons[_ButtonWebcam].Visible = true; - else - Buttons[_ButtonWebcam].Visible = false; - SelectSlides[_SelectSlideDifficulty].SetValues(0); - SelectSlides[_SelectSlideGuestProfile].SetValues(0); - SelectSlides[_SelectSlideActive].SetValues(0); + _Buttons[_ButtonSaveSnapshot].Visible = false; + _Buttons[_ButtonDiscardSnapshot].Visible = false; + _Buttons[_ButtonTakeSnapshot].Visible = false; + _Buttons[_ButtonWebcam].Visible = CWebcam.IsDeviceAvailable(); + _SelectSlides[_SelectSlideDifficulty].SetValues(0); + _SelectSlides[_SelectSlideGuestProfile].SetValues(0); + _SelectSlides[_SelectSlideActive].SetValues(0); } public override bool HandleInput(SKeyEvent keyEvent) @@ -84,8 +100,8 @@ namespace Vocaluxe.Screens case EEditMode.None: break; case EEditMode.PlayerName: - SelectSlides[_SelectSlideProfiles].RenameValue( - CProfiles.AddGetPlayerName(SelectSlides[_SelectSlideProfiles].Selection, keyEvent.Unicode)); + _SelectSlides[_SelectSlideProfiles].RenameValue( + CProfiles.AddGetPlayerName(_SelectSlides[_SelectSlideProfiles].Selection, keyEvent.Unicode)); break; } } @@ -98,36 +114,36 @@ namespace Vocaluxe.Screens break; case Keys.Enter: - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) CGraphics.FadeTo(EScreens.ScreenMain); - else if (Buttons[_ButtonSave].Selected) + else if (_Buttons[_ButtonSave].Selected) _SaveProfiles(); - else if (Buttons[_ButtonNew].Selected) + else if (_Buttons[_ButtonNew].Selected) _NewProfile(); - else if (Buttons[_ButtonPlayerName].Selected) + else if (_Buttons[_ButtonPlayerName].Selected) { if (CProfiles.NumProfiles > 0 && _EditMode != EEditMode.PlayerName) _EditMode = EEditMode.PlayerName; else _EditMode = EEditMode.None; } - else if (Buttons[_ButtonDelete].Selected) + else if (_Buttons[_ButtonDelete].Selected) _DeleteProfile(); - else if (Buttons[_ButtonWebcam].Selected && CWebcam.GetDevices().Length > 0) + else if (_Buttons[_ButtonWebcam].Selected && CWebcam.IsDeviceAvailable()) _OnWebcam(); - else if (Buttons[_ButtonSaveSnapshot].Selected && CWebcam.GetDevices().Length > 0) + else if (_Buttons[_ButtonSaveSnapshot].Selected && CWebcam.IsDeviceAvailable()) _OnSaveSnapshot(); - else if (Buttons[_ButtonDiscardSnapshot].Selected && CWebcam.GetDevices().Length > 0) + else if (_Buttons[_ButtonDiscardSnapshot].Selected && CWebcam.IsDeviceAvailable()) _OnDiscardSnapshot(); - else if (Buttons[_ButtonTakeSnapshot].Selected && CWebcam.GetDevices().Length > 0) + else if (_Buttons[_ButtonTakeSnapshot].Selected && CWebcam.IsDeviceAvailable()) _OnTakeSnapshot(); break; case Keys.Back: if (_EditMode == EEditMode.PlayerName) { - SelectSlides[_SelectSlideProfiles].RenameValue( - CProfiles.GetDeleteCharInPlayerName(SelectSlides[_SelectSlideProfiles].Selection)); + _SelectSlides[_SelectSlideProfiles].RenameValue( + CProfiles.GetDeleteCharInPlayerName(_SelectSlides[_SelectSlideProfiles].Selection)); } else CGraphics.FadeTo(EScreens.ScreenMain); @@ -137,25 +153,25 @@ namespace Vocaluxe.Screens _DeleteProfile(); break; } - if (SelectSlides[_SelectSlideDifficulty].Selected) + if (_SelectSlides[_SelectSlideDifficulty].Selected) { - CProfiles.SetDifficulty(SelectSlides[_SelectSlideProfiles].Selection, - (EGameDifficulty)SelectSlides[_SelectSlideDifficulty].Selection); + CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection, + (EGameDifficulty)_SelectSlides[_SelectSlideDifficulty].Selection); } - else if (SelectSlides[_SelectSlideAvatars].Selected) + else if (_SelectSlides[_SelectSlideAvatars].Selected) { - CProfiles.SetAvatar(SelectSlides[_SelectSlideProfiles].Selection, - SelectSlides[_SelectSlideAvatars].Selection); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, + _SelectSlides[_SelectSlideAvatars].Selection); } - else if (SelectSlides[_SelectSlideGuestProfile].Selected) + else if (_SelectSlides[_SelectSlideGuestProfile].Selected) { - CProfiles.SetGuestProfile(SelectSlides[_SelectSlideProfiles].Selection, - (EOffOn)SelectSlides[_SelectSlideGuestProfile].Selection); + CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection, + (EOffOn)_SelectSlides[_SelectSlideGuestProfile].Selection); } - else if (SelectSlides[_SelectSlideActive].Selected) + else if (_SelectSlides[_SelectSlideActive].Selected) { - CProfiles.SetActive(SelectSlides[_SelectSlideProfiles].Selection, - (EOffOn)SelectSlides[_SelectSlideActive].Selection); + CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].Selection, + (EOffOn)_SelectSlides[_SelectSlideActive].Selection); } } @@ -167,52 +183,52 @@ namespace Vocaluxe.Screens if (_EditMode == EEditMode.None) base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonExit].Selected) + if (_Buttons[_ButtonExit].Selected) CGraphics.FadeTo(EScreens.ScreenMain); - else if (Buttons[_ButtonSave].Selected) + else if (_Buttons[_ButtonSave].Selected) _SaveProfiles(); - else if (Buttons[_ButtonNew].Selected) + else if (_Buttons[_ButtonNew].Selected) _NewProfile(); - else if (Buttons[_ButtonDelete].Selected) + else if (_Buttons[_ButtonDelete].Selected) _DeleteProfile(); - else if (Buttons[_ButtonPlayerName].Selected) + else if (_Buttons[_ButtonPlayerName].Selected) { if (CProfiles.NumProfiles > 0 && _EditMode != EEditMode.PlayerName) _EditMode = EEditMode.PlayerName; else _EditMode = EEditMode.None; } - else if (SelectSlides[_SelectSlideDifficulty].Selected) + else if (_SelectSlides[_SelectSlideDifficulty].Selected) { - CProfiles.SetDifficulty(SelectSlides[_SelectSlideProfiles].Selection, - (EGameDifficulty)SelectSlides[_SelectSlideDifficulty].Selection); + CProfiles.SetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection, + (EGameDifficulty)_SelectSlides[_SelectSlideDifficulty].Selection); } - else if (SelectSlides[_SelectSlideAvatars].Selected) + else if (_SelectSlides[_SelectSlideAvatars].Selected) { - CProfiles.SetAvatar(SelectSlides[_SelectSlideProfiles].Selection, - SelectSlides[_SelectSlideAvatars].Selection); - if (CWebcam.GetDevices().Length > 0 && _WebcamTexture.Index > 0) + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, + _SelectSlides[_SelectSlideAvatars].Selection); + if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0) _OnDiscardSnapshot(); } - else if (SelectSlides[_SelectSlideGuestProfile].Selected) + else if (_SelectSlides[_SelectSlideGuestProfile].Selected) { - CProfiles.SetGuestProfile(SelectSlides[_SelectSlideProfiles].Selection, - (EOffOn)SelectSlides[_SelectSlideGuestProfile].Selection); + CProfiles.SetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection, + (EOffOn)_SelectSlides[_SelectSlideGuestProfile].Selection); } - else if (SelectSlides[_SelectSlideActive].Selected) + else if (_SelectSlides[_SelectSlideActive].Selected) { - CProfiles.SetActive(SelectSlides[_SelectSlideProfiles].Selection, - (EOffOn)SelectSlides[_SelectSlideActive].Selection); + CProfiles.SetActive(_SelectSlides[_SelectSlideProfiles].Selection, + (EOffOn)_SelectSlides[_SelectSlideActive].Selection); } - else if (Buttons[_ButtonWebcam].Selected && CWebcam.GetDevices().Length > 0) + else if (_Buttons[_ButtonWebcam].Selected && CWebcam.IsDeviceAvailable()) _OnWebcam(); - else if (Buttons[_ButtonSaveSnapshot].Selected && CWebcam.GetDevices().Length > 0) + else if (_Buttons[_ButtonSaveSnapshot].Selected && CWebcam.IsDeviceAvailable()) _OnSaveSnapshot(); - else if (Buttons[_ButtonDiscardSnapshot].Selected && CWebcam.GetDevices().Length > 0) + else if (_Buttons[_ButtonDiscardSnapshot].Selected && CWebcam.IsDeviceAvailable()) _OnDiscardSnapshot(); - else if (Buttons[_ButtonTakeSnapshot].Selected && CWebcam.GetDevices().Length > 0) + else if (_Buttons[_ButtonTakeSnapshot].Selected && CWebcam.IsDeviceAvailable()) _OnTakeSnapshot(); } @@ -223,10 +239,10 @@ namespace Vocaluxe.Screens private void _OnTakeSnapshot() { - Buttons[_ButtonSaveSnapshot].Visible = true; - Buttons[_ButtonDiscardSnapshot].Visible = true; - Buttons[_ButtonWebcam].Visible = false; - Buttons[_ButtonTakeSnapshot].Visible = false; + _Buttons[_ButtonSaveSnapshot].Visible = true; + _Buttons[_ButtonDiscardSnapshot].Visible = true; + _Buttons[_ButtonWebcam].Visible = false; + _Buttons[_ButtonTakeSnapshot].Visible = false; _Snapshot = CWebcam.GetBitmap(); } @@ -235,15 +251,15 @@ namespace Vocaluxe.Screens CWebcam.Stop(); CDraw.RemoveTexture(ref _WebcamTexture); _Snapshot = null; - Buttons[_ButtonSaveSnapshot].Visible = false; - Buttons[_ButtonDiscardSnapshot].Visible = false; - Buttons[_ButtonTakeSnapshot].Visible = false; - Buttons[_ButtonWebcam].Visible = true; + _Buttons[_ButtonSaveSnapshot].Visible = false; + _Buttons[_ButtonDiscardSnapshot].Visible = false; + _Buttons[_ButtonTakeSnapshot].Visible = false; + _Buttons[_ButtonWebcam].Visible = true; } private void _OnSaveSnapshot() { - string filename = "snapshot"; + const string filename = "snapshot"; int i = 0; while (File.Exists(Path.Combine(CSettings.FolderProfiles, filename + i + ".png"))) i++; @@ -258,15 +274,15 @@ namespace Vocaluxe.Screens { if (CProfiles.Avatars[j].FileName == (filename + i + ".png")) { - CProfiles.SetAvatar(SelectSlides[_SelectSlideProfiles].Selection, j); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, j); break; } } - Buttons[_ButtonSaveSnapshot].Visible = false; - Buttons[_ButtonDiscardSnapshot].Visible = false; - Buttons[_ButtonTakeSnapshot].Visible = false; - Buttons[_ButtonWebcam].Visible = true; + _Buttons[_ButtonSaveSnapshot].Visible = false; + _Buttons[_ButtonDiscardSnapshot].Visible = false; + _Buttons[_ButtonTakeSnapshot].Visible = false; + _Buttons[_ButtonWebcam].Visible = true; } private void _OnWebcam() @@ -274,38 +290,38 @@ namespace Vocaluxe.Screens _Snapshot = null; CWebcam.Start(); CWebcam.GetFrame(ref _WebcamTexture); - Buttons[_ButtonSaveSnapshot].Visible = false; - Buttons[_ButtonDiscardSnapshot].Visible = false; - Buttons[_ButtonTakeSnapshot].Visible = true; - Buttons[_ButtonWebcam].Visible = false; + _Buttons[_ButtonSaveSnapshot].Visible = false; + _Buttons[_ButtonDiscardSnapshot].Visible = false; + _Buttons[_ButtonTakeSnapshot].Visible = true; + _Buttons[_ButtonWebcam].Visible = false; } public override bool UpdateGame() { - if (SelectSlides[_SelectSlideProfiles].Selection > -1) + if (_SelectSlides[_SelectSlideProfiles].Selection > -1) { - Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(SelectSlides[_SelectSlideProfiles].Selection); + _Buttons[_ButtonPlayerName].Text.Text = CProfiles.GetPlayerName(_SelectSlides[_SelectSlideProfiles].Selection); if (_EditMode == EEditMode.PlayerName) - Buttons[_ButtonPlayerName].Text.Text += "|"; + _Buttons[_ButtonPlayerName].Text.Text += "|"; - SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(SelectSlides[_SelectSlideProfiles].Selection); - SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(SelectSlides[_SelectSlideProfiles].Selection); - SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].Selection); - int avatarNr = CProfiles.GetAvatarNr(SelectSlides[_SelectSlideProfiles].Selection); - SelectSlides[_SelectSlideAvatars].Selection = avatarNr; - if (CWebcam.GetDevices().Length > 0 && _WebcamTexture.Index > 0) + int avatarNr = CProfiles.GetAvatarNr(_SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideAvatars].Selection = avatarNr; + if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0) { if (_Snapshot == null) CWebcam.GetFrame(ref _WebcamTexture); - Statics[_StaticAvatar].Texture = _WebcamTexture; + _Statics[_StaticAvatar].Texture = _WebcamTexture; RectangleF bounds = new RectangleF(_WebcamTexture.Rect.X, _WebcamTexture.Rect.Y, _WebcamTexture.Rect.W, _WebcamTexture.Rect.H); RectangleF rect = new RectangleF(0f, 0f, _WebcamTexture.Rect.W, _WebcamTexture.Rect.H); - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); } else - Statics[_StaticAvatar].Texture = CProfiles.Avatars[avatarNr].Texture; + _Statics[_StaticAvatar].Texture = CProfiles.Avatars[avatarNr].Texture; } return true; @@ -338,7 +354,7 @@ namespace Vocaluxe.Screens private void _DeleteProfile() { - CProfiles.DeleteProfile(SelectSlides[_SelectSlideProfiles].Selection); + CProfiles.DeleteProfile(_SelectSlides[_SelectSlideProfiles].Selection); _LoadProfiles(); UpdateGame(); } @@ -346,25 +362,25 @@ namespace Vocaluxe.Screens private void _LoadProfiles() { _EditMode = EEditMode.None; - SelectSlides[_SelectSlideProfiles].Clear(); + _SelectSlides[_SelectSlideProfiles].Clear(); for (int i = 0; i < CProfiles.NumProfiles; i++) - SelectSlides[_SelectSlideProfiles].AddValue(CProfiles.GetPlayerName(i)); + _SelectSlides[_SelectSlideProfiles].AddValue(CProfiles.GetPlayerName(i)); if (CProfiles.NumProfiles > 0 && CProfiles.NumAvatars > 0) { - SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(SelectSlides[_SelectSlideProfiles].Selection); - SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(SelectSlides[_SelectSlideProfiles].Selection); - SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(SelectSlides[_SelectSlideProfiles].Selection); - SelectSlides[_SelectSlideAvatars].Selection = CProfiles.GetAvatarNr(SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideDifficulty].Selection = (int)CProfiles.GetDifficulty(_SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideGuestProfile].Selection = (int)CProfiles.GetGuestProfile(_SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideActive].Selection = (int)CProfiles.GetActive(_SelectSlides[_SelectSlideProfiles].Selection); + _SelectSlides[_SelectSlideAvatars].Selection = CProfiles.GetAvatarNr(_SelectSlides[_SelectSlideProfiles].Selection); } } private void _LoadAvatars() { - SelectSlides[_SelectSlideAvatars].Clear(); + _SelectSlides[_SelectSlideAvatars].Clear(); for (int i = 0; i < CProfiles.NumAvatars; i++) - SelectSlides[_SelectSlideAvatars].AddValue(CProfiles.Avatars[i].FileName); + _SelectSlides[_SelectSlideAvatars].AddValue(CProfiles.Avatars[i].FileName); } private void _NewProfile() @@ -372,12 +388,12 @@ namespace Vocaluxe.Screens _EditMode = EEditMode.None; CProfiles.NewProfile(); _LoadProfiles(); - SelectSlides[_SelectSlideProfiles].LastValue(); + _SelectSlides[_SelectSlideProfiles].LastValue(); - CProfiles.SetAvatar(SelectSlides[_SelectSlideProfiles].Selection, - SelectSlides[_SelectSlideAvatars].Selection); + CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, + _SelectSlides[_SelectSlideAvatars].Selection); - SetInteractionToButton(Buttons[_ButtonPlayerName]); + _SetInteractionToButton(_Buttons[_ButtonPlayerName]); _EditMode = EEditMode.PlayerName; } } diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index 9083e554..e02f912c 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.Windows.Forms; @@ -39,8 +58,7 @@ namespace Vocaluxe.Screens { base.Init(); - List texts = new List(); - texts.Add(_TextSong); + List texts = new List {_TextSong}; _BuildTextStrings(ref texts); @@ -100,10 +118,7 @@ namespace Vocaluxe.Screens public override void OnShow() { base.OnShow(); - if (CGame.NumRounds > 1) - _Round = 0; - else - _Round = 1; + _Round = CGame.NumRounds > 1 ? 0 : 1; _Points = CGame.GetPoints(); _SetVisibility(); @@ -137,19 +152,19 @@ namespace Vocaluxe.Screens if (_StaticPointsBarDrawnPoints[p] > player[p].Points) _StaticPointsBarDrawnPoints[p] = player[p].Points; - string direction = (string)ScreenSettings[_ScreenSettingAnimationDirection].GetValue(); + string direction = (string)_ScreenSettings[_ScreenSettingAnimationDirection].GetValue(); if (direction.ToLower() == "vertical") { - Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.W = ((float)_StaticPointsBarDrawnPoints[p]) * - (Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.W / 10000); + _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.W = ((float)_StaticPointsBarDrawnPoints[p]) * + (_Statics[_StaticPointsBarBG[p, CGame.NumPlayer - 1]].Rect.W / 10000); } else { - Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H = ((float)_StaticPointsBarDrawnPoints[p]) * - (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; + _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H = ((float)_StaticPointsBarDrawnPoints[p]) * + (_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; } } } @@ -163,7 +178,7 @@ namespace Vocaluxe.Screens return true; } - public string GetRating(double points) + private static string _GetRating(double points) { string rating = String.Empty; @@ -203,7 +218,7 @@ namespace Vocaluxe.Screens { if (player <= numplayer) { - string target = "P" + (player + 1).ToString() + "N" + (numplayer + 1).ToString(); + string target = "P" + (player + 1) + "N" + (numplayer + 1); _TextNames[player, numplayer] = "TextName" + target; _TextScores[player, numplayer] = "TextScore" + target; _TextRatings[player, numplayer] = "TextRating" + target; @@ -228,17 +243,16 @@ namespace Vocaluxe.Screens { for (int player = 0; player < CSettings.MaxNumPlayer; player++) { - if (player <= numplayer) - { - string target = "P" + (player + 1).ToString() + "N" + (numplayer + 1).ToString(); - _StaticPointsBarBG[player, numplayer] = "StaticPointsBarBG" + target; - _StaticPointsBar[player, numplayer] = "StaticPointsBar" + target; - _StaticAvatar[player, numplayer] = "StaticAvatar" + target; + if (player > numplayer) + continue; + string target = "P" + (player + 1) + "N" + (numplayer + 1); + _StaticPointsBarBG[player, numplayer] = "StaticPointsBarBG" + target; + _StaticPointsBar[player, numplayer] = "StaticPointsBar" + target; + _StaticAvatar[player, numplayer] = "StaticAvatar" + target; - statics.Add(_StaticPointsBarBG[player, numplayer]); - statics.Add(_StaticPointsBar[player, numplayer]); - statics.Add(_StaticAvatar[player, numplayer]); - } + statics.Add(_StaticPointsBarBG[player, numplayer]); + statics.Add(_StaticPointsBar[player, numplayer]); + statics.Add(_StaticAvatar[player, numplayer]); } } } @@ -253,25 +267,21 @@ namespace Vocaluxe.Screens if (song == null) return; - Texts[_TextSong].Text = song.Artist + " - " + song.Title; + _Texts[_TextSong].Text = song.Artist + " - " + song.Title; if (_Points.NumRounds > 1) - Texts[_TextSong].Text += " (" + _Round + "/" + _Points.NumRounds + ")"; + _Texts[_TextSong].Text += " (" + _Round + "/" + _Points.NumRounds + ")"; player = _Points.GetPlayer(_Round - 1, CGame.NumPlayer); } else { - Texts[_TextSong].Text = "TR_SCREENSCORE_OVERALLSCORE"; + _Texts[_TextSong].Text = "TR_SCREENSCORE_OVERALLSCORE"; for (int i = 0; i < CGame.NumRounds; i++) { SPlayer[] points = _Points.GetPlayer(i, CGame.NumPlayer); for (int p = 0; p < player.Length; p++) { if (i < 1) - { player[p].ProfileID = points[p].ProfileID; - player[p].Name = points[p].Name; - player[p].Difficulty = points[p].Difficulty; - } player[p].Points += points[p].Points; } } @@ -281,62 +291,58 @@ namespace Vocaluxe.Screens for (int p = 0; p < player.Length; p++) { - if (song != null) + string name = CProfiles.GetPlayerName(player[p].ProfileID, p); + if (song != null && song.IsDuet) { - if (!song.IsDuet) - Texts[_TextNames[p, CGame.NumPlayer - 1]].Text = player[p].Name; - else if (player[p].LineNr == 0 && song.DuetPart1 != "Part 1") - Texts[_TextNames[p, CGame.NumPlayer - 1]].Text = player[p].Name + " (" + song.DuetPart1 + ")"; + if (player[p].LineNr == 0 && song.DuetPart1 != "Part 1") + name += " (" + song.DuetPart1 + ")"; else if (player[p].LineNr == 1 && song.DuetPart2 != "Part 2") - Texts[_TextNames[p, CGame.NumPlayer - 1]].Text = player[p].Name + " (" + song.DuetPart2 + ")"; - else - Texts[_TextNames[p, CGame.NumPlayer - 1]].Text = player[p].Name; + name += " (" + song.DuetPart2 + ")"; } - else - Texts[_TextNames[p, CGame.NumPlayer - 1]].Text = player[p].Name; + _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"); + 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"); else - Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(player[p].Points)).ToString("0000"); - if (CGame.NumPlayer < (int)ScreenSettings[_ScreenSettingShortDifficulty].GetValue()) + _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = ((int)Math.Round(player[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(player[p].Difficulty.ToString()); + _Texts[_TextDifficulty[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate("TR_SCREENSCORE_GAMEDIFFICULTY") + ": " + + CLanguage.Translate(CProfiles.GetDifficulty(player[p].ProfileID).ToString()); } else - Texts[_TextDifficulty[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(player[p].Difficulty.ToString()); - if (CGame.NumPlayer < (int)ScreenSettings[_ScreenSettingShortRating].GetValue()) + _Texts[_TextDifficulty[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate(CProfiles.GetDifficulty(player[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))); + _Texts[_TextRatings[p, CGame.NumPlayer - 1]].Text = CLanguage.Translate("TR_SCREENSCORE_RATING") + ": " + + CLanguage.Translate(_GetRating((int)Math.Round(player[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(player[p].Points))); _StaticPointsBarDrawnPoints[p] = 0.0; - string direction = (string)ScreenSettings[_ScreenSettingAnimationDirection].GetValue(); + string direction = (string)_ScreenSettings[_ScreenSettingAnimationDirection].GetValue(); if (direction.ToLower() == "vertical") - Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.W = 0; + _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.W = 0; else { - Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H = 0; - 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; + _Statics[_StaticPointsBar[p, CGame.NumPlayer - 1]].Rect.H = 0; + _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; } - if (player[p].ProfileID >= 0 && player[p].ProfileID < CProfiles.NumProfiles) - Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[player[p].ProfileID].Avatar.Texture; + if (CProfiles.IsProfileIDValid(player[p].ProfileID)) + _Statics[_StaticAvatar[p, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[player[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.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; + _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.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; } } @@ -353,15 +359,15 @@ namespace Vocaluxe.Screens { if (player <= numplayer) { - Texts[_TextNames[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - Texts[_TextScores[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - Texts[_TextRatings[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - Texts[_TextDifficulty[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - Statics[_StaticPointsBar[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - Statics[_StaticPointsBarBG[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - Statics[_StaticAvatar[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; + _Texts[_TextNames[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; + _Texts[_TextScores[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; + _Texts[_TextRatings[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; + _Texts[_TextDifficulty[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; + _Statics[_StaticPointsBar[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; + _Statics[_StaticPointsBarBG[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; + _Statics[_StaticAvatar[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - Statics[_StaticAvatar[player, numplayer]].Texture = new STexture(-1); + _Statics[_StaticAvatar[player, numplayer]].Texture = new STexture(-1); } } } diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index e9769d91..119e5406 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -1,8 +1,28 @@ -using System; +#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.Diagnostics; using System.Drawing; using System.IO; +using System.Linq; using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -16,7 +36,7 @@ namespace Vocaluxe.Screens // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion { - get { return 6; } + get { return 7; } } private struct STimeRect @@ -31,6 +51,7 @@ namespace Vocaluxe.Screens private const string _TextPause = "TextPause"; private const string _TextDuetName1 = "TextDuetName1"; private const string _TextDuetName2 = "TextDuetName2"; + private const string _TextMedleyCountdown = "TextMedleyCountdown"; private string[,] _TextScores; private string[,] _TextNames; @@ -71,7 +92,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); @@ -99,36 +120,30 @@ namespace Vocaluxe.Screens { base.Init(); - List texts = new List(); - texts.Add(_TextSongName); - texts.Add(_TextTime); - texts.Add(_TextPause); - texts.Add(_TextDuetName1); - texts.Add(_TextDuetName2); - _BuildTextStrings(ref texts); + List texts = new List {_TextSongName, _TextTime, _TextPause, _TextDuetName1, _TextDuetName2, _TextMedleyCountdown}; + _BuildTextStrings(texts); _ThemeTexts = texts.ToArray(); - List statics = new List(); - statics.Add(_StaticSongText); - statics.Add(_StaticLyrics); - statics.Add(_StaticLyricsDuet); - statics.Add(_StaticLyricsTop); - statics.Add(_StaticTimeBar); - statics.Add(_StaticTimeLine); - statics.Add(_StaticTimeLineExpandedNormal); - statics.Add(_StaticTimeLineExpandedHighlighted); - statics.Add(_StaticTimePointer); - statics.Add(_StaticLyricHelper); - statics.Add(_StaticLyricHelperDuet); - statics.Add(_StaticLyricHelperTop); - statics.Add(_StaticPauseBG); + List statics = new List + { + _StaticSongText, + _StaticLyrics, + _StaticLyricsDuet, + _StaticLyricsTop, + _StaticTimeBar, + _StaticTimeLine, + _StaticTimeLineExpandedNormal, + _StaticTimeLineExpandedHighlighted, + _StaticTimePointer, + _StaticLyricHelper, + _StaticLyricHelperDuet, + _StaticLyricHelperTop, + _StaticPauseBG + }; _BuildStaticStrings(ref statics); _ThemeStatics = statics.ToArray(); - List buttons = new List(); - buttons.Add(_ButtonCancel); - buttons.Add(_ButtonContinue); - buttons.Add(_ButtonSkip); + List buttons = new List {_ButtonCancel, _ButtonContinue, _ButtonSkip}; _ThemeButtons = buttons.ToArray(); _ThemeLyrics = new string[] {_LyricMain, _LyricSub, _LyricMainDuet, _LyricSubDuet, _LyricMainTop, _LyricSubTop}; @@ -144,17 +159,17 @@ namespace Vocaluxe.Screens { base.LoadTheme(xmlPath); - Statics[_StaticTimeLine].Visible = false; - Statics[_StaticTimeLineExpandedNormal].Visible = false; - Statics[_StaticTimeLineExpandedHighlighted].Visible = false; - Statics[_StaticPauseBG].Visible = false; - Texts[_TextPause].Visible = false; + _Statics[_StaticTimeLine].Visible = false; + _Statics[_StaticTimeLineExpandedNormal].Visible = false; + _Statics[_StaticTimeLineExpandedHighlighted].Visible = false; + _Statics[_StaticPauseBG].Visible = false; + _Texts[_TextPause].Visible = false; - Statics[_StaticPauseBG].Visible = false; - Texts[_TextPause].Visible = false; + _Statics[_StaticPauseBG].Visible = false; + _Texts[_TextPause].Visible = false; - Buttons[_ButtonCancel].Visible = false; - Buttons[_ButtonContinue].Visible = false; + _Buttons[_ButtonCancel].Visible = false; + _Buttons[_ButtonContinue].Visible = false; } public override bool HandleInput(SKeyEvent keyEvent) @@ -172,13 +187,13 @@ namespace Vocaluxe.Screens case Keys.Escape: _TogglePause(); if (_Pause) - SetInteractionToButton(Buttons[_ButtonCancel]); + _SetInteractionToButton(_Buttons[_ButtonCancel]); break; case Keys.P: _TogglePause(); if (_Pause) - SetInteractionToButton(Buttons[_ButtonContinue]); + _SetInteractionToButton(_Buttons[_ButtonContinue]); break; case Keys.T: @@ -211,7 +226,7 @@ namespace Vocaluxe.Screens } break; case Keys.W: - if (CWebcam.GetDevices().Length > 0) + if (CWebcam.IsDeviceAvailable()) { _Webcam = !_Webcam; if (_Webcam) @@ -221,11 +236,11 @@ namespace Vocaluxe.Screens } break; case Keys.Enter: - if (Buttons[_ButtonContinue].Selected && _Pause) + if (_Buttons[_ButtonContinue].Selected && _Pause) _TogglePause(); - if (Buttons[_ButtonCancel].Selected && _Pause) + if (_Buttons[_ButtonCancel].Selected && _Pause) _Stop(); - if (Buttons[_ButtonSkip].Selected && _Pause) + if (_Buttons[_ButtonSkip].Selected && _Pause) { _LoadNextSong(); _TogglePause(); @@ -269,18 +284,18 @@ namespace Vocaluxe.Screens { _TogglePause(); if (_Pause) - SetInteractionToButton(Buttons[_ButtonContinue]); + _SetInteractionToButton(_Buttons[_ButtonContinue]); } - if (mouseEvent.LB && IsMouseOver(mouseEvent) && _Pause) + if (mouseEvent.LB && _IsMouseOver(mouseEvent) && _Pause) { - if (Buttons[_ButtonContinue].Selected && _Pause) + if (_Buttons[_ButtonContinue].Selected && _Pause) _TogglePause(); - if (Buttons[_ButtonCancel].Selected && _Pause) + if (_Buttons[_ButtonCancel].Selected && _Pause) _Stop(); - if (Buttons[_ButtonSkip].Selected && _Pause) + if (_Buttons[_ButtonSkip].Selected && _Pause) { _LoadNextSong(); _TogglePause(); @@ -298,7 +313,7 @@ namespace Vocaluxe.Screens { _CurrentTime = CSound.GetPosition(_CurrentStream); - if (_FinishTime != 0 && _CurrentTime >= _FinishTime) + if (_FinishTime > 0.001 && _CurrentTime >= _FinishTime) finish = true; } else @@ -320,64 +335,64 @@ namespace Vocaluxe.Screens float[] alpha = _CalcFadingAlpha(); if (alpha != null) { - Lyrics[_LyricMain].Alpha = alpha[0]; - Lyrics[_LyricSub].Alpha = alpha[1]; + _Lyrics[_LyricMain].Alpha = alpha[0]; + _Lyrics[_LyricSub].Alpha = alpha[1]; - Lyrics[_LyricMainTop].Alpha = alpha[0]; - Lyrics[_LyricSubTop].Alpha = alpha[1]; + _Lyrics[_LyricMainTop].Alpha = alpha[0]; + _Lyrics[_LyricSubTop].Alpha = alpha[1]; - Statics[_StaticLyrics].Alpha = alpha[0]; - Statics[_StaticLyricsTop].Alpha = alpha[0]; + _Statics[_StaticLyrics].Alpha = alpha[0]; + _Statics[_StaticLyricsTop].Alpha = alpha[0]; - Statics[_StaticLyricHelper].Alpha = alpha[0]; - Statics[_StaticLyricHelperTop].Alpha = alpha[0]; + _Statics[_StaticLyricHelper].Alpha = alpha[0]; + _Statics[_StaticLyricHelperTop].Alpha = alpha[0]; for (int p = 0; p < CGame.NumPlayer; p++) { - SingNotes[_SingBars].SetAlpha(_NoteLines[p], alpha[CGame.Player[p].LineNr * 2]); + _SingNotes[_SingBars].SetAlpha(_NoteLines[p], alpha[CGame.Players[p].LineNr * 2]); if (CConfig.FadePlayerInfo == EFadePlayerInfo.TR_CONFIG_FADEPLAYERINFO_INFO || CConfig.FadePlayerInfo == EFadePlayerInfo.TR_CONFIG_FADEPLAYERINFO_ALL) { - Statics[_StaticAvatars[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Player[p].LineNr * 2]; - Texts[_TextNames[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Player[p].LineNr * 2]; + _Statics[_StaticAvatars[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Players[p].LineNr * 2]; + _Texts[_TextNames[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Players[p].LineNr * 2]; } if (CConfig.FadePlayerInfo == EFadePlayerInfo.TR_CONFIG_FADEPLAYERINFO_ALL) { - Statics[_StaticScores[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Player[p].LineNr * 2]; - Statics[_StaticAvatars[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Player[p].LineNr * 2]; - Texts[_TextNames[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Player[p].LineNr * 2]; - Texts[_TextScores[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Player[p].LineNr * 2]; + _Statics[_StaticScores[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Players[p].LineNr * 2]; + _Statics[_StaticAvatars[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Players[p].LineNr * 2]; + _Texts[_TextNames[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Players[p].LineNr * 2]; + _Texts[_TextScores[p, CGame.NumPlayer - 1]].Alpha = alpha[CGame.Players[p].LineNr * 2]; } } if (alpha.Length > 2) { - Lyrics[_LyricMainDuet].Alpha = alpha[0]; - Lyrics[_LyricSubDuet].Alpha = alpha[1]; + _Lyrics[_LyricMainDuet].Alpha = alpha[0]; + _Lyrics[_LyricSubDuet].Alpha = alpha[1]; - Statics[_StaticLyricsDuet].Alpha = alpha[0]; - Statics[_StaticLyricHelperDuet].Alpha = alpha[0]; + _Statics[_StaticLyricsDuet].Alpha = alpha[0]; + _Statics[_StaticLyricHelperDuet].Alpha = alpha[0]; - Lyrics[_LyricMain].Alpha = alpha[2]; - Lyrics[_LyricSub].Alpha = alpha[3]; + _Lyrics[_LyricMain].Alpha = alpha[2]; + _Lyrics[_LyricSub].Alpha = alpha[3]; - Statics[_StaticLyrics].Alpha = alpha[2]; - Statics[_StaticLyricHelper].Alpha = alpha[2]; + _Statics[_StaticLyrics].Alpha = alpha[2]; + _Statics[_StaticLyricHelper].Alpha = alpha[2]; } } for (int p = 0; p < CGame.NumPlayer; p++) { - if (CGame.Player[p].Points < 10000) - Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = CGame.Player[p].Points.ToString("0000"); + if (CGame.Players[p].Points < 10000) + _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = CGame.Players[p].Points.ToString("0000"); else - Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = CGame.Player[p].Points.ToString("00000"); + _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = CGame.Players[p].Points.ToString("00000"); } if (_CurrentVideo != -1 && !_FadeOut && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON) { - float vtime = 0f; - CVideo.VdGetFrame(_CurrentVideo, ref _CurrentVideoTexture, _CurrentTime, ref vtime); + float vtime; + CVideo.VdGetFrame(_CurrentVideo, ref _CurrentVideoTexture, _CurrentTime, out vtime); } if (_Webcam) @@ -404,15 +419,15 @@ namespace Vocaluxe.Screens _TimeRects.Clear(); - SingNotes[_SingBars].Reset(); + _SingNotes[_SingBars].Reset(); for (int i = 0; i < CSettings.MaxNumPlayer; i++) _NoteLines[i] = -1; - foreach (CLyric lyric in Lyrics) + foreach (CLyric lyric in _Lyrics) lyric.LyricStyle = CConfig.LyricStyle; for (int p = 0; p < CGame.NumPlayer; p++) - Statics[_StaticAvatars[p, CGame.NumPlayer - 1]].Aspect = EAspect.Crop; + _Statics[_StaticAvatars[p, CGame.NumPlayer - 1]].Aspect = EAspect.Crop; _SetVisibility(); _UpdateAvatars(); @@ -435,11 +450,13 @@ 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); RectangleF rect = new RectangleF(0f, 0f, _CurrentVideoTexture.Width, _CurrentVideoTexture.Height); - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, _VideoAspect); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, _VideoAspect); CDraw.DrawTexture(_CurrentVideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f), _CurrentVideoTexture.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f), false); @@ -448,7 +465,7 @@ namespace Vocaluxe.Screens { RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); RectangleF rect = new RectangleF(0f, 0f, _CurrentWebcamFrameTexture.Width, _CurrentWebcamFrameTexture.Height); - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, _VideoAspect); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, _VideoAspect); CDraw.DrawTexture(_CurrentWebcamFrameTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f), _CurrentVideoTexture.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f), false); @@ -458,56 +475,59 @@ namespace Vocaluxe.Screens // Draw Background RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); RectangleF rect = new RectangleF(0f, 0f, _Background.Width, _Background.Height); - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); CDraw.DrawTexture(_Background, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f), _Background.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f), false); } } - DrawBG(); + _DrawBG(); - foreach (CStatic stat in Statics) + foreach (CStatic stat in _Statics) stat.Draw(); - foreach (CText text in Texts) + foreach (CText text in _Texts) text.Draw(); switch (CConfig.TimerLook) { case ETimerLook.TR_CONFIG_TIMERLOOK_NORMAL: - CDraw.DrawTexture(Statics[_StaticTimeLine].Texture, Statics[_StaticTimeLine].Rect, new SColorF(1, 1, 1, 1), _TimeLineRect); + CDraw.DrawTexture(_Statics[_StaticTimeLine].Texture, _Statics[_StaticTimeLine].Rect, new SColorF(1, 1, 1, 1), _TimeLineRect); break; case ETimerLook.TR_CONFIG_TIMERLOOK_EXPANDED: for (int i = 0; i < _TimeRects.Count; i++) - CDraw.DrawTexture(_TimeRects[i].Rect.Texture, Statics[_StaticTimeLine].Rect, _TimeRects[i].Rect.Color, _TimeRects[i].Rect.Rect); + CDraw.DrawTexture(_TimeRects[i].Rect.Texture, _Statics[_StaticTimeLine].Rect, _TimeRects[i].Rect.Color, _TimeRects[i].Rect.Rect); break; } - Lyrics[_LyricSub].Draw(-100); - Lyrics[_LyricMain].Draw(CGame.Beat); + _Lyrics[_LyricSub].Draw(-100); + _Lyrics[_LyricMain].Draw(CGame.Beat); - Lyrics[_LyricSubDuet].Draw(-100); - Lyrics[_LyricMainDuet].Draw(CGame.Beat); + _Lyrics[_LyricSubDuet].Draw(-100); + _Lyrics[_LyricMainDuet].Draw(CGame.Beat); - Lyrics[_LyricSubTop].Draw(-100); - Lyrics[_LyricMainTop].Draw(CGame.Beat); + _Lyrics[_LyricSubTop].Draw(-100); + _Lyrics[_LyricMainTop].Draw(CGame.Beat); for (int i = 0; i < CGame.NumPlayer; i++) - SingNotes[_SingBars].Draw(_NoteLines[i], CGame.Player[i].SingLine, i); + _SingNotes[_SingBars].Draw(_NoteLines[i], CGame.Players[i].SingLine, i); _DrawLyricHelper(); + if (CGame.GameMode == EGameMode.TR_GAMEMODE_MEDLEY) + _Texts[_TextMedleyCountdown].Draw(); + if (_Pause) { - Statics[_StaticPauseBG].ForceDraw(); - Texts[_TextPause].ForceDraw(); + _Statics[_StaticPauseBG].ForceDraw(); + _Texts[_TextPause].ForceDraw(); - foreach (CButton button in Buttons) + foreach (CButton button in _Buttons) button.Draw(); - foreach (CSelectSlide slide in SelectSlides) + foreach (CSelectSlide slide in _SelectSlides) slide.Draw(); } @@ -538,15 +558,15 @@ namespace Vocaluxe.Screens } CDraw.RemoveTexture(ref _Background); - Lyrics[_LyricMain].Clear(); - Lyrics[_LyricSub].Clear(); - Lyrics[_LyricMainDuet].Clear(); - Lyrics[_LyricSubDuet].Clear(); - Lyrics[_LyricMainTop].Clear(); - Lyrics[_LyricSubTop].Clear(); - Texts[_TextSongName].Text = String.Empty; - Texts[_TextDuetName1].Text = String.Empty; - Texts[_TextDuetName2].Text = String.Empty; + _Lyrics[_LyricMain].Clear(); + _Lyrics[_LyricSub].Clear(); + _Lyrics[_LyricMainDuet].Clear(); + _Lyrics[_LyricSubDuet].Clear(); + _Lyrics[_LyricMainTop].Clear(); + _Lyrics[_LyricSubTop].Clear(); + _Texts[_TextSongName].Text = String.Empty; + _Texts[_TextDuetName1].Text = String.Empty; + _Texts[_TextDuetName2].Text = String.Empty; GC.Collect(); } @@ -573,8 +593,8 @@ namespace Vocaluxe.Screens string songname = song.Artist + " - " + song.Title; int rounds = CGame.GetNumSongs(); if (rounds > 1) - songname += " (" + CGame.RoundNr + "/" + rounds.ToString() + ")"; - Texts[_TextSongName].Text = songname; + songname += " (" + CGame.RoundNr + "/" + rounds + ")"; + _Texts[_TextSongName].Text = songname; _CurrentStream = CSound.Load(song.GetMP3(), true); CSound.SetStreamVolumeMax(_CurrentStream, CConfig.GameMusicVolume); @@ -589,13 +609,13 @@ namespace Vocaluxe.Screens { //Save duet-assignment before resetting for (int i = 0; i < duetPlayer.Length; i++) - duetPlayer[i] = CGame.Player[i].LineNr; + duetPlayer[i] = CGame.Players[i].LineNr; } CGame.ResetPlayer(); CDraw.RemoveTexture(ref _CurrentVideoTexture); - if (song.VideoFileName.Length > 0) + if (song.VideoFileName != "") { _CurrentVideo = CVideo.VdLoad(Path.Combine(song.Folder, song.VideoFileName)); CVideo.VdSkip(_CurrentVideo, song.Start, song.VideoGap); @@ -603,43 +623,33 @@ namespace Vocaluxe.Screens } CDraw.RemoveTexture(ref _Background); - if (song.BackgroundFileName.Length > 0) + if (song.BackgroundFileName != "") _Background = CDraw.AddTexture(Path.Combine(song.Folder, song.BackgroundFileName)); - SingNotes[_SingBars].Reset(); + _SingNotes[_SingBars].Reset(); if (song.IsDuet) { - Texts[_TextDuetName1].Text = song.DuetPart1; - Texts[_TextDuetName2].Text = song.DuetPart2; + _Texts[_TextDuetName1].Text = song.DuetPart1; + _Texts[_TextDuetName2].Text = song.DuetPart2; //More than one song: Player is not assigned to line by user //Otherwise, this is done by CScreenNames if (CGame.GetNumSongs() > 1) { for (int i = 0; i < CGame.NumPlayer; i++) - { - if ((i % 2) == 0) - CGame.Player[i].LineNr = 1; - else - CGame.Player[i].LineNr = 0; - } + CGame.Players[i].LineNr = (i + 1) % 2; } else { for (int i = 0; i < CGame.NumPlayer; i++) - CGame.Player[i].LineNr = duetPlayer[i]; + CGame.Players[i].LineNr = duetPlayer[i]; } } _SetDuetLyricsVisibility(song.IsDuet); for (int p = 0; p < CGame.NumPlayer; p++) - { - _NoteLines[p] = SingNotes[_SingBars].AddPlayer( - SingNotes[_SingBars].BarPos[p, CGame.NumPlayer - 1], - CTheme.GetPlayerColor(p + 1), - p); - } + _NoteLines[p] = _SingNotes[_SingBars].AddPlayer(_SingNotes[_SingBars].BarPos[p, CGame.NumPlayer - 1], CTheme.GetPlayerColor(p + 1), p); /* case 4: @@ -656,7 +666,7 @@ namespace Vocaluxe.Screens _TimerDuetText2.Stop(); _TimerDuetText2.Reset(); - if (song.Notes.Lines.Length != 2) + if (song.Notes.Voices.Length != 2) _TimerSongText.Start(); _StartSong(); @@ -664,22 +674,22 @@ namespace Vocaluxe.Screens private void _SetDuetLyricsVisibility(bool isDuet) { - Statics[_StaticLyricsDuet].Visible = isDuet; - Lyrics[_LyricMainDuet].Visible = isDuet; - Lyrics[_LyricSubDuet].Visible = isDuet; + _Statics[_StaticLyricsDuet].Visible = isDuet; + _Lyrics[_LyricMainDuet].Visible = isDuet; + _Lyrics[_LyricSubDuet].Visible = isDuet; if (isDuet) { - Lyrics[_LyricMainTop].Visible = false; - Lyrics[_LyricSubTop].Visible = false; - Statics[_StaticLyricsTop].Visible = false; + _Lyrics[_LyricMainTop].Visible = false; + _Lyrics[_LyricSubTop].Visible = false; + _Statics[_StaticLyricsTop].Visible = false; } else { bool lyricsOnTop = (CGame.NumPlayer != 1) && CConfig.LyricsOnTop == EOffOn.TR_CONFIG_ON; - Lyrics[_LyricMainTop].Visible = lyricsOnTop; - Lyrics[_LyricSubTop].Visible = lyricsOnTop; - Statics[_StaticLyricsTop].Visible = lyricsOnTop; + _Lyrics[_LyricMainTop].Visible = lyricsOnTop; + _Lyrics[_LyricSubTop].Visible = lyricsOnTop; + _Statics[_StaticLyricsTop].Visible = lyricsOnTop; } } @@ -710,21 +720,21 @@ namespace Vocaluxe.Screens CWebcam.Close(); } - private int _FindCurrentLine(CLines lines, CLine[] line, CSong song) + private int _FindCurrentLine(CVoice voice, CLine[] lines, CSong song) { float currentTime = _CurrentTime - song.Gap; //We are only interested in the last matching line, so either do not check further after line[j].StartBeat > _CurrentBeat or go backwards! - int j = lines.FindPreviousLine(_CurrentBeat); + int j = voice.FindPreviousLine(_CurrentBeat); for (; j >= 0; j--) { - float firstNoteTime = CGame.GetTimeFromBeats(line[j].FirstNoteBeat, song.BPM); + float firstNoteTime = CGame.GetTimeFromBeats(lines[j].FirstNoteBeat, song.BPM); //Earlist possible line break is 10s before first note if (firstNoteTime <= currentTime + 10f) { //First line has no predecessor or line has to be shown if (j == 0 || firstNoteTime - CConfig.MinLineBreakTime <= currentTime) return j; - float lastNoteTime = CGame.GetTimeFromBeats(line[j - 1].LastNoteBeat, song.BPM); + float lastNoteTime = CGame.GetTimeFromBeats(lines[j - 1].LastNoteBeat, song.BPM); //No line break if last line is not fully evaluated (with 50% tolerance -> tested so notes are drawn) if (lastNoteTime + CConfig.MicDelay / 1000f * 1.5f >= currentTime) return j - 1; @@ -751,65 +761,65 @@ namespace Vocaluxe.Screens if (i > 1) break; // for later - CLines lines = song.Notes.GetLines(i); - CLine[] line = lines.Line; + CVoice voice = song.Notes.GetVoice(i); + CLine[] lines = voice.Lines; // find current line - int nr = _FindCurrentLine(lines, line, song); + int nr = _FindCurrentLine(voice, lines, song); if (nr != -1) { for (int j = 0; j < CGame.NumPlayer; j++) { - if (CGame.Player[j].LineNr == i) - SingNotes[_SingBars].AddLine(_NoteLines[j], line, nr, j); + if (CGame.Players[j].LineNr == i) + _SingNotes[_SingBars].SetLines(_NoteLines[j], lines, nr); } if (i == 0 && !song.IsDuet || i == 1 && song.IsDuet) { - Lyrics[_LyricMain].SetLine(line[nr]); - Lyrics[_LyricMainTop].SetLine(line[nr]); - _TimeToFirstNote = CGame.GetTimeFromBeats(line[nr].FirstNoteBeat - line[nr].StartBeat, song.BPM); - _RemainingTimeToFirstNote = CGame.GetTimeFromBeats(line[nr].FirstNoteBeat - CGame.GetBeatFromTime(_CurrentTime, song.BPM, song.Gap), song.BPM); + _Lyrics[_LyricMain].SetLine(lines[nr]); + _Lyrics[_LyricMainTop].SetLine(lines[nr]); + _TimeToFirstNote = CGame.GetTimeFromBeats(lines[nr].FirstNoteBeat - lines[nr].StartBeat, song.BPM); + _RemainingTimeToFirstNote = CGame.GetTimeFromBeats(lines[nr].FirstNoteBeat - CGame.GetBeatFromTime(_CurrentTime, song.BPM, song.Gap), song.BPM); - if (line.Length >= nr + 2) + if (lines.Length >= nr + 2) { - Lyrics[_LyricSub].SetLine(line[nr + 1]); - Lyrics[_LyricSubTop].SetLine(line[nr + 1]); + _Lyrics[_LyricSub].SetLine(lines[nr + 1]); + _Lyrics[_LyricSubTop].SetLine(lines[nr + 1]); } else { - Lyrics[_LyricSub].Clear(); - Lyrics[_LyricSubTop].Clear(); + _Lyrics[_LyricSub].Clear(); + _Lyrics[_LyricSubTop].Clear(); } } if (i == 0 && song.IsDuet) { - Lyrics[_LyricMainDuet].SetLine(line[nr]); - _TimeToFirstNoteDuet = CGame.GetTimeFromBeats(line[nr].FirstNoteBeat - line[nr].StartBeat, song.BPM); - _RemainingTimeToFirstNoteDuet = CGame.GetTimeFromBeats(line[nr].FirstNoteBeat - CGame.GetBeatFromTime(_CurrentTime, song.BPM, song.Gap), song.BPM); + _Lyrics[_LyricMainDuet].SetLine(lines[nr]); + _TimeToFirstNoteDuet = CGame.GetTimeFromBeats(lines[nr].FirstNoteBeat - lines[nr].StartBeat, song.BPM); + _RemainingTimeToFirstNoteDuet = CGame.GetTimeFromBeats(lines[nr].FirstNoteBeat - CGame.GetBeatFromTime(_CurrentTime, song.BPM, song.Gap), song.BPM); - if (line.Length >= nr + 2) - Lyrics[_LyricSubDuet].SetLine(line[nr + 1]); + if (lines.Length >= nr + 2) + _Lyrics[_LyricSubDuet].SetLine(lines[nr + 1]); else - Lyrics[_LyricSubDuet].Clear(); + _Lyrics[_LyricSubDuet].Clear(); } } else { if (i == 0 && !song.IsDuet || i == 1 && song.IsDuet) { - Lyrics[_LyricMain].Clear(); - Lyrics[_LyricSub].Clear(); - Lyrics[_LyricMainTop].Clear(); - Lyrics[_LyricSubTop].Clear(); + _Lyrics[_LyricMain].Clear(); + _Lyrics[_LyricSub].Clear(); + _Lyrics[_LyricMainTop].Clear(); + _Lyrics[_LyricSubTop].Clear(); _TimeToFirstNote = 0f; } if (i == 0 && song.IsDuet) { - Lyrics[_LyricMainDuet].Clear(); - Lyrics[_LyricSubDuet].Clear(); + _Lyrics[_LyricMainDuet].Clear(); + _Lyrics[_LyricSubDuet].Clear(); _TimeToFirstNoteDuet = 0f; } } @@ -821,25 +831,25 @@ namespace Vocaluxe.Screens _Pause = !_Pause; if (_Pause) { - Buttons[_ButtonCancel].Visible = true; - Buttons[_ButtonContinue].Visible = true; + _Buttons[_ButtonCancel].Visible = true; + _Buttons[_ButtonContinue].Visible = true; if (CGame.NumRounds > CGame.RoundNr && CGame.NumRounds > 1) - Buttons[_ButtonSkip].Visible = true; + _Buttons[_ButtonSkip].Visible = true; else - Buttons[_ButtonSkip].Visible = false; + _Buttons[_ButtonSkip].Visible = false; CSound.Pause(_CurrentStream); } else { - Buttons[_ButtonCancel].Visible = false; - Buttons[_ButtonContinue].Visible = false; - Buttons[_ButtonSkip].Visible = false; + _Buttons[_ButtonCancel].Visible = false; + _Buttons[_ButtonContinue].Visible = false; + _Buttons[_ButtonSkip].Visible = false; CSound.Play(_CurrentStream); CWebcam.Start(); } } - private void _BuildTextStrings(ref List texts) + private void _BuildTextStrings(List texts) { _TextScores = new string[CSettings.MaxNumPlayer,CSettings.MaxNumPlayer]; _TextNames = new string[CSettings.MaxNumPlayer,CSettings.MaxNumPlayer]; @@ -850,7 +860,7 @@ namespace Vocaluxe.Screens { if (player <= numplayer) { - string target = "P" + (player + 1).ToString() + "N" + (numplayer + 1).ToString(); + string target = "P" + (player + 1) + "N" + (numplayer + 1); _TextScores[player, numplayer] = "TextScore" + target; _TextNames[player, numplayer] = "TextName" + target; @@ -872,7 +882,7 @@ namespace Vocaluxe.Screens { if (player <= numplayer) { - string target = "P" + (player + 1).ToString() + "N" + (numplayer + 1).ToString(); + string target = "P" + (player + 1) + "N" + (numplayer + 1); _StaticScores[player, numplayer] = "StaticScore" + target; _StaticAvatars[player, numplayer] = "StaticAvatar" + target; @@ -885,17 +895,17 @@ namespace Vocaluxe.Screens private void _SetVisibility() { - Statics[_StaticLyricsDuet].Visible = false; - Statics[_StaticLyricHelper].Visible = false; - Statics[_StaticLyricHelperDuet].Visible = false; - Statics[_StaticLyricHelperTop].Visible = false; - Lyrics[_LyricMainDuet].Visible = false; - Lyrics[_LyricSubDuet].Visible = false; + _Statics[_StaticLyricsDuet].Visible = false; + _Statics[_StaticLyricHelper].Visible = false; + _Statics[_StaticLyricHelperDuet].Visible = false; + _Statics[_StaticLyricHelperTop].Visible = false; + _Lyrics[_LyricMainDuet].Visible = false; + _Lyrics[_LyricSubDuet].Visible = false; - Statics[_StaticSongText].Visible = false; - Texts[_TextSongName].Visible = false; - Texts[_TextDuetName1].Visible = false; - Texts[_TextDuetName2].Visible = false; + _Statics[_StaticSongText].Visible = false; + _Texts[_TextSongName].Visible = false; + _Texts[_TextDuetName1].Visible = false; + _Texts[_TextDuetName2].Visible = false; for (int numplayer = 0; numplayer < CSettings.MaxNumPlayer; numplayer++) { @@ -903,37 +913,63 @@ namespace Vocaluxe.Screens { if (player <= numplayer) { - Texts[_TextScores[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - Texts[_TextNames[player, numplayer]].Visible = (numplayer + 1 == CGame.NumPlayer) - && - (CConfig.PlayerInfo == EPlayerInfo.TR_CONFIG_PLAYERINFO_BOTH || - CConfig.PlayerInfo == EPlayerInfo.TR_CONFIG_PLAYERINFO_NAME); - Statics[_StaticScores[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; - Statics[_StaticAvatars[player, numplayer]].Visible = (numplayer + 1 == CGame.NumPlayer) - && - (CConfig.PlayerInfo == EPlayerInfo.TR_CONFIG_PLAYERINFO_BOTH || - CConfig.PlayerInfo == EPlayerInfo.TR_CONFIG_PLAYERINFO_AVATAR); + _Texts[_TextScores[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; + _Texts[_TextNames[player, numplayer]].Visible = (numplayer + 1 == CGame.NumPlayer) + && + (CConfig.PlayerInfo == EPlayerInfo.TR_CONFIG_PLAYERINFO_BOTH || + CConfig.PlayerInfo == EPlayerInfo.TR_CONFIG_PLAYERINFO_NAME); + _Statics[_StaticScores[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; + _Statics[_StaticAvatars[player, numplayer]].Visible = (numplayer + 1 == CGame.NumPlayer) + && + (CConfig.PlayerInfo == EPlayerInfo.TR_CONFIG_PLAYERINFO_BOTH || + CConfig.PlayerInfo == EPlayerInfo.TR_CONFIG_PLAYERINFO_AVATAR); } } } - Lyrics[_LyricMain].Alpha = 0f; - Lyrics[_LyricSub].Alpha = 0f; + _Lyrics[_LyricMain].Alpha = 0f; + _Lyrics[_LyricSub].Alpha = 0f; - Lyrics[_LyricMainTop].Alpha = 0f; - Lyrics[_LyricSubTop].Alpha = 0f; + _Lyrics[_LyricMainTop].Alpha = 0f; + _Lyrics[_LyricSubTop].Alpha = 0f; - Statics[_StaticLyrics].Alpha = 0f; - Statics[_StaticLyricsTop].Alpha = 0f; + _Statics[_StaticLyrics].Alpha = 0f; + _Statics[_StaticLyricsTop].Alpha = 0f; - Statics[_StaticLyricHelper].Alpha = 0f; - Statics[_StaticLyricHelperTop].Alpha = 0f; + _Statics[_StaticLyricHelper].Alpha = 0f; + _Statics[_StaticLyricHelperTop].Alpha = 0f; - Lyrics[_LyricMainDuet].Alpha = 0f; - Lyrics[_LyricSubDuet].Alpha = 0f; + _Lyrics[_LyricMainDuet].Alpha = 0f; + _Lyrics[_LyricSubDuet].Alpha = 0f; - Statics[_StaticLyricsDuet].Alpha = 0f; - Statics[_StaticLyricHelperDuet].Alpha = 0f; + _Statics[_StaticLyricsDuet].Alpha = 0f; + _Statics[_StaticLyricHelperDuet].Alpha = 0f; + } + + private void _UpdateMedleyCountdown() + { + if (CGame.GetSong() != null) + { + CSong song = CGame.GetSong(); + 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; + } } private void _DrawLyricHelper() @@ -962,28 +998,28 @@ namespace Vocaluxe.Screens if (time > totaltime) time = totaltime; - SRectF rect = Statics[_StaticLyricHelper].Rect; + SRectF rect = _Statics[_StaticLyricHelper].Rect; SColorF color = new SColorF( - Statics[_StaticLyricHelper].Color.R, - Statics[_StaticLyricHelper].Color.G, - Statics[_StaticLyricHelper].Color.B, - Statics[_StaticLyricHelper].Color.A * Statics[_StaticLyricHelper].Alpha * alpha); + _Statics[_StaticLyricHelper].Color.R, + _Statics[_StaticLyricHelper].Color.G, + _Statics[_StaticLyricHelper].Color.B, + _Statics[_StaticLyricHelper].Color.A * _Statics[_StaticLyricHelper].Alpha * alpha); - float distance = Lyrics[_LyricMain].GetCurrentLyricPosX() - rect.X - rect.W; - CDraw.DrawTexture(Statics[_StaticLyricHelper].Texture, + float distance = _Lyrics[_LyricMain].GetCurrentLyricPosX() - rect.X - rect.W; + CDraw.DrawTexture(_Statics[_StaticLyricHelper].Texture, new SRectF(rect.X + distance * (1f - time / totaltime), rect.Y, rect.W, rect.H, rect.Z), color); - if (Statics[_StaticLyricsTop].Visible) + if (_Statics[_StaticLyricsTop].Visible) { - rect = Statics[_StaticLyricHelperTop].Rect; + rect = _Statics[_StaticLyricHelperTop].Rect; color = new SColorF( - Statics[_StaticLyricHelperTop].Color.R, - Statics[_StaticLyricHelperTop].Color.G, - Statics[_StaticLyricHelperTop].Color.B, - Statics[_StaticLyricHelperTop].Color.A * Statics[_StaticLyricHelper].Alpha * alpha); + _Statics[_StaticLyricHelperTop].Color.R, + _Statics[_StaticLyricHelperTop].Color.G, + _Statics[_StaticLyricHelperTop].Color.B, + _Statics[_StaticLyricHelperTop].Color.A * _Statics[_StaticLyricHelper].Alpha * alpha); - distance = Lyrics[_LyricMainTop].GetCurrentLyricPosX() - rect.X - rect.W; - CDraw.DrawTexture(Statics[_StaticLyricHelperTop].Texture, + distance = _Lyrics[_LyricMainTop].GetCurrentLyricPosX() - rect.X - rect.W; + CDraw.DrawTexture(_Statics[_StaticLyricHelperTop].Texture, new SRectF(rect.X + distance * (1f - time / totaltime), rect.Y, rect.W, rect.H, rect.Z), color); } } @@ -1001,16 +1037,16 @@ namespace Vocaluxe.Screens if (time > totaltime) time = totaltime; - SRectF rect = Statics[_StaticLyricHelperDuet].Rect; + SRectF rect = _Statics[_StaticLyricHelperDuet].Rect; SColorF color = new SColorF( - Statics[_StaticLyricHelperDuet].Color.R, - Statics[_StaticLyricHelperDuet].Color.G, - Statics[_StaticLyricHelperDuet].Color.B, - Statics[_StaticLyricHelperDuet].Color.A * Statics[_StaticLyricHelperDuet].Alpha * alpha); + _Statics[_StaticLyricHelperDuet].Color.R, + _Statics[_StaticLyricHelperDuet].Color.G, + _Statics[_StaticLyricHelperDuet].Color.B, + _Statics[_StaticLyricHelperDuet].Color.A * _Statics[_StaticLyricHelperDuet].Alpha * alpha); - float distance = Lyrics[_LyricMainDuet].GetCurrentLyricPosX() - rect.X - rect.W; - CDraw.DrawTexture(Statics[_StaticLyricHelperDuet].Texture, + float distance = _Lyrics[_LyricMainDuet].GetCurrentLyricPosX() - rect.X - rect.W; + CDraw.DrawTexture(_Statics[_StaticLyricHelperDuet].Texture, new SRectF(rect.X + distance * (1f - time / totaltime), rect.Y, rect.W, rect.H, rect.Z), color); } @@ -1019,31 +1055,29 @@ namespace Vocaluxe.Screens private float[] _CalcFadingAlpha() { - float dt = 4f; - float rt = dt * 0.8f; + const float dt = 4f; + const float rt = dt * 0.8f; CSong song = CGame.GetSong(); - if (song == null) - return null; - else if (!song.NotesLoaded) + if (song == null || !song.NotesLoaded) return null; - float[] alpha = new float[song.Notes.Lines.Length * 2]; + float[] alpha = new float[song.Notes.Voices.Length * 2]; float currentTime = _CurrentTime - song.Gap; for (int i = 0; i < song.Notes.LinesCount; i++) { - CLines lines = song.Notes.GetLines(i); - CLine[] line = lines.Line; + CVoice voice = song.Notes.GetVoice(i); + CLine[] lines = voice.Lines; // find current line for lyric sub fading - int currentLineSub = _FindCurrentLine(lines, line, song); + int currentLineSub = _FindCurrentLine(voice, lines, song); // find current line for lyric main fading int currentLine = 0; - for (int j = 0; j < line.Length; j++) + for (int j = 0; j < lines.Length; j++) { - if (line[j].FirstNoteBeat <= _CurrentBeat) + if (lines[j].FirstNoteBeat <= _CurrentBeat) currentLine = j; } @@ -1052,31 +1086,31 @@ namespace Vocaluxe.Screens alpha[i * 2 + 1] = 1f; // main line alpha - if (currentLine == 0 && currentTime < CGame.GetTimeFromBeats(line[currentLine].FirstNoteBeat, song.BPM)) + if (currentLine == 0 && currentTime < CGame.GetTimeFromBeats(lines[currentLine].FirstNoteBeat, song.BPM)) { // first main line and fist note is not reached // => fade in - float diff = CGame.GetTimeFromBeats(line[currentLine].FirstNoteBeat, song.BPM) - currentTime; + float diff = CGame.GetTimeFromBeats(lines[currentLine].FirstNoteBeat, song.BPM) - currentTime; if (diff > dt) alpha[i * 2] = 1f - (diff - dt) / rt; } - else if (currentLine < line.Length - 1 && CGame.GetTimeFromBeats(line[currentLine].LastNoteBeat, song.BPM) < currentTime && - CGame.GetTimeFromBeats(line[currentLine + 1].FirstNoteBeat, song.BPM) > currentTime) + else if (currentLine < lines.Length - 1 && CGame.GetTimeFromBeats(lines[currentLine].LastNoteBeat, song.BPM) < currentTime && + CGame.GetTimeFromBeats(lines[currentLine + 1].FirstNoteBeat, song.BPM) > currentTime) { // current position is between two lines // time between the to lines - float diff = CGame.GetTimeFromBeats(line[currentLine + 1].FirstNoteBeat, song.BPM) - - CGame.GetTimeFromBeats(line[currentLine].LastNoteBeat, song.BPM); + float diff = CGame.GetTimeFromBeats(lines[currentLine + 1].FirstNoteBeat, song.BPM) - + CGame.GetTimeFromBeats(lines[currentLine].LastNoteBeat, song.BPM); // fade only if there is enough time for fading if (diff > 3.3f * dt) { // time elapsed since last line - float last = currentTime - CGame.GetTimeFromBeats(line[currentLine].LastNoteBeat, song.BPM); + float last = currentTime - CGame.GetTimeFromBeats(lines[currentLine].LastNoteBeat, song.BPM); // time to next line - float next = CGame.GetTimeFromBeats(line[currentLine + 1].FirstNoteBeat, song.BPM) - currentTime; + float next = CGame.GetTimeFromBeats(lines[currentLine + 1].FirstNoteBeat, song.BPM) - currentTime; if (last < next) { @@ -1091,19 +1125,18 @@ namespace Vocaluxe.Screens } } } - else if (currentLine == line.Length - 1 && CGame.GetTimeFromBeats(line[currentLine].LastNoteBeat, song.BPM) < currentTime) + else if (currentLine == lines.Length - 1 && CGame.GetTimeFromBeats(lines[currentLine].LastNoteBeat, song.BPM) < currentTime) { // last main line and last note was reached // => fade out - float diff = currentTime - CGame.GetTimeFromBeats(line[currentLine].LastNoteBeat, song.BPM); + float diff = currentTime - CGame.GetTimeFromBeats(lines[currentLine].LastNoteBeat, song.BPM); alpha[i * 2] = 1f - diff / rt; } // sub - if (currentLineSub < line.Length - 2) + if (currentLineSub < lines.Length - 2) { - float diff = 0f; - diff = CGame.GetTimeFromBeats(line[currentLineSub + 1].FirstNoteBeat, song.BPM) - currentTime; + float diff = CGame.GetTimeFromBeats(lines[currentLineSub + 1].FirstNoteBeat, song.BPM) - currentTime; if (diff > dt) alpha[i * 2 + 1] = 1f - (diff - dt) / rt; @@ -1121,36 +1154,36 @@ namespace Vocaluxe.Screens private void _UpdateSongText() { - if (_TimerSongText.IsRunning && !Lyrics[_LyricMainDuet].Visible && !Lyrics[_LyricMainTop].Visible) + if (_TimerSongText.IsRunning && !_Lyrics[_LyricMainDuet].Visible && !_Lyrics[_LyricMainTop].Visible) { float t = _TimerSongText.ElapsedMilliseconds / 1000f; if (t < 10f) { - Statics[_StaticSongText].Visible = true; - Texts[_TextSongName].Visible = true; + _Statics[_StaticSongText].Visible = true; + _Texts[_TextSongName].Visible = true; if (t < 7f) { - Statics[_StaticSongText].Color.A = 1f; - Texts[_TextSongName].Color.A = 1f; + _Statics[_StaticSongText].Color.A = 1f; + _Texts[_TextSongName].Color.A = 1f; } else { - Statics[_StaticSongText].Color.A = (3f - (t - 7f)) / 3f; - Texts[_TextSongName].Color.A = (3f - (t - 7f)) / 3f; + _Statics[_StaticSongText].Color.A = (3f - (t - 7f)) / 3f; + _Texts[_TextSongName].Color.A = (3f - (t - 7f)) / 3f; } } else { - Statics[_StaticSongText].Visible = false; - Texts[_TextSongName].Visible = false; + _Statics[_StaticSongText].Visible = false; + _Texts[_TextSongName].Visible = false; _TimerSongText.Stop(); } } else { - Statics[_StaticSongText].Visible = false; - Texts[_TextSongName].Visible = false; + _Statics[_StaticSongText].Visible = false; + _Texts[_TextSongName].Visible = false; } } @@ -1164,50 +1197,50 @@ namespace Vocaluxe.Screens float t = _TimerDuetText1.ElapsedMilliseconds / 1000f; if (t < 10f) { - Texts[_TextDuetName1].Visible = true; + _Texts[_TextDuetName1].Visible = true; if (t < 3f) - Texts[_TextDuetName1].Color.A = (3f - (3f - t)) / 3f; + _Texts[_TextDuetName1].Color.A = (3f - (3f - t)) / 3f; else if (t < 7f) - Texts[_TextDuetName1].Color.A = 1f; + _Texts[_TextDuetName1].Color.A = 1f; else - Texts[_TextDuetName1].Color.A = (3f - (t - 7f)) / 3f; + _Texts[_TextDuetName1].Color.A = (3f - (t - 7f)) / 3f; } else { - Texts[_TextDuetName1].Visible = false; + _Texts[_TextDuetName1].Visible = false; _TimerDuetText1.Stop(); } } - else if (!_TimerDuetText1.IsRunning && _TimerDuetText1.ElapsedMilliseconds == 0 && Lyrics[_LyricMainDuet].Alpha > 0 && CGame.GetSong().IsDuet) + else if (!_TimerDuetText1.IsRunning && _TimerDuetText1.ElapsedMilliseconds == 0 && _Lyrics[_LyricMainDuet].Alpha > 0 && CGame.GetSong().IsDuet) _TimerDuetText1.Start(); else - Texts[_TextDuetName1].Visible = false; + _Texts[_TextDuetName1].Visible = false; //Timer for second duet-part if (_TimerDuetText2.IsRunning) { float t = _TimerDuetText2.ElapsedMilliseconds / 1000f; if (t < 10f) { - Texts[_TextDuetName2].Visible = true; + _Texts[_TextDuetName2].Visible = true; if (t < 3f) - Texts[_TextDuetName2].Color.A = (3f - (3f - t)) / 3f; + _Texts[_TextDuetName2].Color.A = (3f - (3f - t)) / 3f; else if (t < 7f) - Texts[_TextDuetName2].Color.A = 1f; + _Texts[_TextDuetName2].Color.A = 1f; else - Texts[_TextDuetName2].Color.A = (3f - (t - 7f)) / 3f; + _Texts[_TextDuetName2].Color.A = (3f - (t - 7f)) / 3f; } else { - Texts[_TextDuetName2].Visible = false; + _Texts[_TextDuetName2].Visible = false; _TimerDuetText2.Stop(); } } - else if (!_TimerDuetText2.IsRunning && _TimerDuetText2.ElapsedMilliseconds == 0 && Lyrics[_LyricMain].Alpha > 0 && CGame.GetSong().IsDuet) + else if (!_TimerDuetText2.IsRunning && _TimerDuetText2.ElapsedMilliseconds == 0 && _Lyrics[_LyricMain].Alpha > 0 && CGame.GetSong().IsDuet) _TimerDuetText2.Start(); else - Texts[_TextDuetName2].Visible = false; + _Texts[_TextDuetName2].Visible = false; } } @@ -1219,7 +1252,7 @@ namespace Vocaluxe.Screens return; float totalTime = CSound.GetLength(_CurrentStream); - if (song.Finish != 0) + if (Math.Abs(song.Finish) > 0.001) totalTime = song.Finish; float remainingTime = totalTime - _CurrentTime; @@ -1234,19 +1267,19 @@ namespace Vocaluxe.Screens case ETimerMode.TR_CONFIG_TIMERMODE_CURRENT: int min = (int)Math.Floor(currentTime / 60f); int sec = (int)(currentTime - min * 60f); - Texts[_TextTime].Text = min.ToString("00") + ":" + sec.ToString("00"); + _Texts[_TextTime].Text = min.ToString("00") + ":" + sec.ToString("00"); break; case ETimerMode.TR_CONFIG_TIMERMODE_REMAINING: min = (int)Math.Floor(remainingTime / 60f); sec = (int)(remainingTime - min * 60f); - Texts[_TextTime].Text = "-" + min.ToString("00") + ":" + sec.ToString("00"); + _Texts[_TextTime].Text = "-" + min.ToString("00") + ":" + sec.ToString("00"); break; case ETimerMode.TR_CONFIG_TIMERMODE_TOTAL: min = (int)Math.Floor(totalTime / 60f); sec = (int)(totalTime - min * 60f); - Texts[_TextTime].Text = "#" + min.ToString("00") + ":" + sec.ToString("00"); + _Texts[_TextTime].Text = "#" + min.ToString("00") + ":" + sec.ToString("00"); break; } @@ -1254,43 +1287,43 @@ namespace Vocaluxe.Screens switch (CConfig.TimerLook) { case ETimerLook.TR_CONFIG_TIMERLOOK_NORMAL: - _TimeLineRect.W = Statics[_StaticTimeLine].Rect.W * (currentTime / totalTime); + _TimeLineRect.W = _Statics[_StaticTimeLine].Rect.W * (currentTime / totalTime); break; case ETimerLook.TR_CONFIG_TIMERLOOK_EXPANDED: - CStatic stat = Statics[_StaticTimeLine]; + CStatic stat = _Statics[_StaticTimeLine]; int currentBeat = CGame.CurrentBeat; for (int i = 0; i < _TimeRects.Count; i++) { if (currentBeat >= _TimeRects[i].StartBeat && currentBeat <= _TimeRects[i].EndBeat) { - _TimeRects[i].Rect.Texture = Statics[_StaticTimeLineExpandedHighlighted].Texture; - _TimeRects[i].Rect.Color = Statics[_StaticTimeLineExpandedHighlighted].Color; + _TimeRects[i].Rect.Texture = _Statics[_StaticTimeLineExpandedHighlighted].Texture; + _TimeRects[i].Rect.Color = _Statics[_StaticTimeLineExpandedHighlighted].Color; } else { - _TimeRects[i].Rect.Texture = Statics[_StaticTimeLineExpandedNormal].Texture; - _TimeRects[i].Rect.Color = Statics[_StaticTimeLineExpandedNormal].Color; + _TimeRects[i].Rect.Texture = _Statics[_StaticTimeLineExpandedNormal].Texture; + _TimeRects[i].Rect.Color = _Statics[_StaticTimeLineExpandedNormal].Color; } } - Statics[_StaticTimePointer].Rect.X = stat.Rect.X + stat.Rect.W * (currentTime / totalTime); + _Statics[_StaticTimePointer].Rect.X = stat.Rect.X + stat.Rect.W * (currentTime / totalTime); break; } } private void _PrepareTimeLine() { - CStatic stat = Statics[_StaticTimeLine]; + CStatic stat = _Statics[_StaticTimeLine]; switch (CConfig.TimerLook) { case ETimerLook.TR_CONFIG_TIMERLOOK_NORMAL: _TimeLineRect = new SRectF(stat.Rect.X, stat.Rect.Y, 0f, stat.Rect.H, stat.Rect.Z); - Statics[_StaticTimePointer].Visible = false; + _Statics[_StaticTimePointer].Visible = false; break; case ETimerLook.TR_CONFIG_TIMERLOOK_EXPANDED: _TimeRects.Clear(); - Statics[_StaticTimePointer].Visible = true; + _Statics[_StaticTimePointer].Visible = true; CSong song = CGame.GetSong(); @@ -1298,7 +1331,7 @@ namespace Vocaluxe.Screens return; float totalTime = CSound.GetLength(_CurrentStream); - if (song.Finish != 0) + if (Math.Abs(song.Finish) > 0.001) totalTime = song.Finish; totalTime -= song.Start; @@ -1306,29 +1339,21 @@ namespace Vocaluxe.Screens if (totalTime <= 0f) return; - CLines[] lines = new CLines[song.Notes.Lines.Length]; - lines = song.Notes.Lines; - for (int i = 0; i < lines.Length; i++) + foreach (CVoice voice in song.Notes.Voices) { - CLine[] line = lines[i].Line; - for (int j = 0; j < line.Length; j++) + foreach (CLine line in voice.Lines.Where(line => line.VisibleInTimeLine)) { - if (line[j].VisibleInTimeLine) - { - STimeRect trect = new STimeRect(); - trect.StartBeat = line[j].FirstNoteBeat; - trect.EndBeat = line[j].EndBeat; - trect.Rect = GetNewStatic(new STexture(-1), - new SColorF(1f, 1f, 1f, 1f), - new SRectF( - stat.Rect.X + stat.Rect.W * ((CGame.GetTimeFromBeats(trect.StartBeat, song.BPM) + song.Gap - song.Start) / totalTime), - stat.Rect.Y, - stat.Rect.W * (CGame.GetTimeFromBeats(trect.EndBeat - trect.StartBeat, song.BPM) / totalTime), - stat.Rect.H, - stat.Rect.Z)); + STimeRect trect = new STimeRect {StartBeat = line.FirstNoteBeat, EndBeat = line.EndBeat}; + trect.Rect = GetNewStatic(new STexture(-1), + new SColorF(1f, 1f, 1f, 1f), + new SRectF( + stat.Rect.X + stat.Rect.W * ((CGame.GetTimeFromBeats(trect.StartBeat, song.BPM) + song.Gap - song.Start) / totalTime), + stat.Rect.Y, + stat.Rect.W * (CGame.GetTimeFromBeats(trect.EndBeat - trect.StartBeat, song.BPM) / totalTime), + stat.Rect.H, + stat.Rect.Z)); - _TimeRects.Add(trect); - } + _TimeRects.Add(trect); } } break; @@ -1339,10 +1364,10 @@ namespace Vocaluxe.Screens { for (int i = 0; i < CGame.NumPlayer; i++) { - if (CGame.Player[i].ProfileID > -1 && CProfiles.NumProfiles > CGame.Player[i].ProfileID) - Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[CGame.Player[i].ProfileID].Avatar.Texture; + if (CProfiles.IsProfileIDValid(CGame.Players[i].ProfileID)) + _Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Texture = CProfiles.Profiles[CGame.Players[i].ProfileID].Avatar.Texture; else - Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Visible = false; + _Statics[_StaticAvatars[i, CGame.NumPlayer - 1]].Visible = false; } } @@ -1350,10 +1375,10 @@ namespace Vocaluxe.Screens { for (int i = 0; i < CGame.NumPlayer; i++) { - if (CGame.Player[i].ProfileID > -1 && CProfiles.NumProfiles > CGame.Player[i].ProfileID) - Texts[_TextNames[i, CGame.NumPlayer - 1]].Text = CProfiles.Profiles[CGame.Player[i].ProfileID].PlayerName; + if (CProfiles.IsProfileIDValid(CGame.Players[i].ProfileID)) + _Texts[_TextNames[i, CGame.NumPlayer - 1]].Text = CProfiles.Profiles[CGame.Players[i].ProfileID].PlayerName; else - Texts[_TextNames[i, CGame.NumPlayer - 1]].Visible = false; + _Texts[_TextNames[i, CGame.NumPlayer - 1]].Visible = false; } } } diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index b4c973af..054fddf3 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -1,4 +1,23 @@ -using System; +#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.Windows.Forms; using Vocaluxe.Base; @@ -81,7 +100,7 @@ namespace Vocaluxe.Screens base.Init(); _ButtonsJoker.Clear(); - for (int i = 0; i < CMain.Settings.GetMaxNumPlayer(); i++) + for (int i = 0; i < CSettings.MaxNumPlayer; i++) _ButtonsJoker.Add("ButtonJoker" + (i + 1)); List blist = new List(); blist.AddRange(_ButtonsJoker); @@ -99,7 +118,7 @@ namespace Vocaluxe.Screens blist.Add(_ButtonOptionsStartMedley); _TextsPlayer.Clear(); - for (int i = 0; i < CMain.Settings.GetMaxNumPlayer(); i++) + for (int i = 0; i < CSettings.MaxNumPlayer; i++) _TextsPlayer.Add("TextPlayer" + (i + 1)); List tlist = new List(); tlist.AddRange(_TextsPlayer); @@ -121,11 +140,11 @@ namespace Vocaluxe.Screens { base.LoadTheme(xmlPath); _ToggleSongOptions(ESongOptionsView.None); - Playlists[_Playlist].Visible = false; + _Playlists[_Playlist].Visible = false; _DragAndDropCover = GetNewStatic(); - Playlists[_Playlist].Init(); + _Playlists[_Playlist].Init(); _AvailableGameModes.Clear(); @@ -140,7 +159,7 @@ namespace Vocaluxe.Screens if (_PlaylistActive) { - Playlists[_Playlist].HandleInput(keyEvent); + _Playlists[_Playlist].HandleInput(keyEvent); return true; } @@ -158,7 +177,7 @@ namespace Vocaluxe.Screens } else { - SongMenus[_SongMenu].HandleInput(ref keyEvent, _Sso); + _SongMenus[_SongMenu].HandleInput(ref keyEvent, _Sso); _UpdatePartyModeOptions(); if (keyEvent.Handled) @@ -184,19 +203,19 @@ namespace Vocaluxe.Screens { if (i < _Sso.Selection.NumJokers.Length) { - if (Buttons[_ButtonsJoker[i]].Selected) + if (_Buttons[_ButtonsJoker[i]].Selected) { _SelectNextRandom(i); return true; } } } - if (Buttons[_ButtonStart].Selected) - _HandlePartySongSelection(SongMenus[_SongMenu].GetSelectedSong()); + if (_Buttons[_ButtonStart].Selected) + _HandlePartySongSelection(_SongMenus[_SongMenu].GetSelectedSong()); } if (CSongs.NumVisibleSongs > 0 && !_Sso.Selection.PartyMode) { - if (SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive) + if (_SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive) { if (!_Sso.Selection.PartyMode) _ToggleSongOptions(ESongOptionsView.Song); @@ -205,16 +224,16 @@ namespace Vocaluxe.Screens break; case Keys.Tab: - if (Playlists[_Playlist].Visible) + if (_Playlists[_Playlist].Visible) { _PlaylistActive = !_PlaylistActive; - Playlists[_Playlist].Selected = _PlaylistActive; - SongMenus[_SongMenu].SetActive(!_PlaylistActive); + _Playlists[_Playlist].Selected = _PlaylistActive; + _SongMenus[_SongMenu].SetActive(!_PlaylistActive); } break; case Keys.Back: - if (_SearchActive && _SearchText.Length > 0) + if (_SearchActive && _SearchText != "") _ApplyNewSearchFilter(_SearchText.Remove(_SearchText.Length - 1)); if ((CSongs.Category < 0 || _Sso.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) && !_Sso.Selection.PartyMode && !_SearchActive) @@ -258,7 +277,7 @@ namespace Vocaluxe.Screens case Keys.S: if (keyEvent.Mod == EModifier.Ctrl && CSongs.NumVisibleSongs > 0 && !_Sso.Selection.PartyMode) - _StartMedleySong(SongMenus[_SongMenu].GetSelectedSong()); + _StartMedleySong(_SongMenus[_SongMenu].GetSelectedSong()); break; case Keys.D1: @@ -293,39 +312,39 @@ namespace Vocaluxe.Screens switch (keyEvent.Key) { case Keys.Enter: - if (Buttons[_ButtonOptionsClose].Selected) + if (_Buttons[_ButtonOptionsClose].Selected) _ToggleSongOptions(ESongOptionsView.None); - else if (Buttons[_ButtonOptionsSing].Selected) + else if (_Buttons[_ButtonOptionsSing].Selected) { _ToggleSongOptions(ESongOptionsView.None); - _StartSong(SongMenus[_SongMenu].GetSelectedSong()); + _StartSong(_SongMenus[_SongMenu].GetSelectedSong()); } - else if (Buttons[_ButtonOptionsPlaylist].Selected) + else if (_Buttons[_ButtonOptionsPlaylist].Selected) { _ToggleSongOptions(ESongOptionsView.None); _OpenAndAddPlaylistAction(); } - else if (Buttons[_ButtonOptionsRandom].Selected) + else if (_Buttons[_ButtonOptionsRandom].Selected) { if (CSongs.IsInCategory) - SongMenus[_SongMenu].SetSelectedSong(CSongs.GetRandomSong()); + _SongMenus[_SongMenu].SetSelectedSong(CSongs.GetRandomSong()); else - SongMenus[_SongMenu].SetSelectedCategory(CSongs.GetRandomCategory()); + _SongMenus[_SongMenu].SetSelectedCategory(CSongs.GetRandomCategory()); } - else if (Buttons[_ButtonOptionsSingAll].Selected) + else if (_Buttons[_ButtonOptionsSingAll].Selected) _StartRandomAllSongs(); - else if (Buttons[_ButtonOptionsSingAllVisible].Selected) + else if (_Buttons[_ButtonOptionsSingAllVisible].Selected) _StartRandomVisibleSongs(); - else if (Buttons[_ButtonOptionsOpenSelectedItem].Selected) + else if (_Buttons[_ButtonOptionsOpenSelectedItem].Selected) _HandleSelectButton(); - else if (SelectSlides[_SelectSlideOptionsPlaylistOpen].Selected) + else if (_SelectSlides[_SelectSlideOptionsPlaylistOpen].Selected) _OpenPlaylistAction(); - else if (Buttons[_ButtonOptionsRandomMedley].Selected) + else if (_Buttons[_ButtonOptionsRandomMedley].Selected) _ToggleSongOptions(ESongOptionsView.Medley); - else if (Buttons[_ButtonOptionsStartMedley].Selected) + else if (_Buttons[_ButtonOptionsStartMedley].Selected) { _ToggleSongOptions(ESongOptionsView.None); - _StartRandomMedley(SelectSlides[_SelectSlideOptionsNumMedleySongs].Selection + 1, !CSongs.IsInCategory); + _StartRandomMedley(_SelectSlides[_SelectSlideOptionsNumMedleySongs].Selection + 1, !CSongs.IsInCategory); } break; @@ -369,24 +388,24 @@ namespace Vocaluxe.Screens _OldMousePosX = mouseEvent.X; _OldMousePosY = mouseEvent.Y; - if (Playlists[_Playlist].Visible && Playlists[_Playlist].IsMouseOver(mouseEvent)) + if (_Playlists[_Playlist].Visible && _Playlists[_Playlist].IsMouseOver(mouseEvent)) { _PlaylistActive = true; - Playlists[_Playlist].Selected = _PlaylistActive; - SongMenus[_SongMenu].SetActive(!_PlaylistActive); + _Playlists[_Playlist].Selected = _PlaylistActive; + _SongMenus[_SongMenu].SetActive(!_PlaylistActive); _ToggleSongOptions(ESongOptionsView.None); } - else if (CHelper.IsInBounds(SongMenus[_SongMenu].Rect, mouseEvent.X, mouseEvent.Y)) + else if (CHelper.IsInBounds(_SongMenus[_SongMenu].Rect, mouseEvent.X, mouseEvent.Y)) { _PlaylistActive = false; - Playlists[_Playlist].Selected = _PlaylistActive; - SongMenus[_SongMenu].SetActive(!_PlaylistActive); + _Playlists[_Playlist].Selected = _PlaylistActive; + _SongMenus[_SongMenu].SetActive(!_PlaylistActive); } - if (Playlists[_Playlist].Visible && _PlaylistActive) + if (_Playlists[_Playlist].Visible && _PlaylistActive) { - if (Playlists[_Playlist].HandleMouse(mouseEvent)) + if (_Playlists[_Playlist].HandleMouse(mouseEvent)) return true; } @@ -421,15 +440,15 @@ 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.NumVisibleSongs > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1) { _ToggleSongOptions(ESongOptionsView.None); - _StartVisibleSong(SongMenus[_SongMenu].GetActualSelection()); + _StartVisibleSong(_SongMenus[_SongMenu].GetActualSelection()); return true; } } - SongMenus[_SongMenu].HandleMouse(ref mouseEvent, _Sso); + _SongMenus[_SongMenu].HandleMouse(ref mouseEvent, _Sso); _UpdatePartyModeOptions(); if (mouseEvent.Handled) @@ -437,84 +456,84 @@ namespace Vocaluxe.Screens if (mouseEvent.LB) { - if (IsMouseOver(mouseEvent)) + if (_IsMouseOver(mouseEvent)) { - if (Buttons[_ButtonOpenOptions].Selected) + if (_Buttons[_ButtonOpenOptions].Selected) { _ToggleSongOptions(ESongOptionsView.General); return true; } - else if (Buttons[_ButtonOptionsClose].Selected) + if (_Buttons[_ButtonOptionsClose].Selected) { _ToggleSongOptions(ESongOptionsView.None); return true; } - else if (Buttons[_ButtonOptionsSing].Selected) + if (_Buttons[_ButtonOptionsSing].Selected) { _ToggleSongOptions(ESongOptionsView.None); - _StartSong(SongMenus[_SongMenu].GetSelectedSong()); + _StartSong(_SongMenus[_SongMenu].GetSelectedSong()); return true; } - else if (Buttons[_ButtonOptionsPlaylist].Selected) + if (_Buttons[_ButtonOptionsPlaylist].Selected) { _ToggleSongOptions(ESongOptionsView.None); _OpenAndAddPlaylistAction(); return true; } - else if (Buttons[_ButtonOptionsRandom].Selected) + if (_Buttons[_ButtonOptionsRandom].Selected) { if (CSongs.IsInCategory) { - SongMenus[_SongMenu].SetSelectedSong(CSongs.GetRandomSong()); + _SongMenus[_SongMenu].SetSelectedSong(CSongs.GetRandomSong()); return true; } } - else if (Buttons[_ButtonOptionsRandomCategory].Selected) + else if (_Buttons[_ButtonOptionsRandomCategory].Selected) { if (!CSongs.IsInCategory) { - SongMenus[_SongMenu].SetSelectedCategory(CSongs.GetRandomCategory()); + _SongMenus[_SongMenu].SetSelectedCategory(CSongs.GetRandomCategory()); return true; } } - else if (Buttons[_ButtonOptionsSingAll].Selected) + else if (_Buttons[_ButtonOptionsSingAll].Selected) { _ToggleSongOptions(ESongOptionsView.None); _StartRandomAllSongs(); return true; } - else if (Buttons[_ButtonOptionsSingAllVisible].Selected) + else if (_Buttons[_ButtonOptionsSingAllVisible].Selected) { _ToggleSongOptions(ESongOptionsView.None); _StartRandomVisibleSongs(); return true; } - else if (Buttons[_ButtonOptionsOpenSelectedItem].Selected) + else if (_Buttons[_ButtonOptionsOpenSelectedItem].Selected) { _HandleSelectButton(); return true; } - else if (SelectSlides[_SelectSlideOptionsPlaylistOpen].ValueSelected) + else if (_SelectSlides[_SelectSlideOptionsPlaylistOpen].ValueSelected) { _OpenPlaylistAction(); return true; } - else if (Buttons[_ButtonOptionsRandomMedley].Selected) + else if (_Buttons[_ButtonOptionsRandomMedley].Selected) { _ToggleSongOptions(ESongOptionsView.Medley); return true; } - else if (Buttons[_ButtonOptionsStartMedley].Selected) + else if (_Buttons[_ButtonOptionsStartMedley].Selected) { _ToggleSongOptions(ESongOptionsView.None); - _StartRandomMedley(SelectSlides[_SelectSlideOptionsNumMedleySongs].Selection + 1, !CSongs.IsInCategory); + _StartRandomMedley(_SelectSlides[_SelectSlideOptionsNumMedleySongs].Selection + 1, !CSongs.IsInCategory); return true; } else if (_Sso.Selection.RandomOnly && _Sso.Selection.NumJokers != null) { - if (Buttons[_ButtonStart].Selected) + if (_Buttons[_ButtonStart].Selected) { - _HandlePartySongSelection(SongMenus[_SongMenu].GetSelectedSong()); + _HandlePartySongSelection(_SongMenus[_SongMenu].GetSelectedSong()); return true; } @@ -522,7 +541,7 @@ namespace Vocaluxe.Screens { if (i < _Sso.Selection.NumJokers.Length) { - if (Buttons[_ButtonsJoker[i]].Selected) + if (_Buttons[_ButtonsJoker[i]].Selected) { _SelectNextRandom(i); return true; @@ -532,28 +551,25 @@ namespace Vocaluxe.Screens } } - if (CSongs.NumVisibleSongs > 0 && SongMenus[_SongMenu].GetActualSelection() != -1 && !_Sso.Selection.PartyMode) + if (CSongs.NumVisibleSongs > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1 && !_Sso.Selection.PartyMode) { - if (SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive) + if (_SongMenus[_SongMenu].GetSelectedSong() != -1 && !_SongOptionsActive) { _ToggleSongOptions(ESongOptionsView.Song); return true; } - else - { - _ToggleSongOptions(ESongOptionsView.None); - return true; - } + _ToggleSongOptions(ESongOptionsView.None); + return true; } } if (mouseEvent.LBH) { - if (!_DragAndDropActive && Playlists[_Playlist].Visible && CSongs.NumVisibleSongs > 0 && SongMenus[_SongMenu].GetActualSelection() != -1) + if (!_DragAndDropActive && _Playlists[_Playlist].Visible && CSongs.NumVisibleSongs > 0 && _SongMenus[_SongMenu].GetActualSelection() != -1) { - _DragAndDropCover = SongMenus[_SongMenu].GetSelectedSongCover(); + _DragAndDropCover = _SongMenus[_SongMenu].GetSelectedSongCover(); _DragAndDropCover.Rect.Z = CSettings.ZNear; - Playlists[_Playlist].DragAndDropSongID = CSongs.VisibleSongs[SongMenus[_SongMenu].GetActualSelection()].ID; + _Playlists[_Playlist].DragAndDropSongID = CSongs.VisibleSongs[_SongMenus[_SongMenu].GetActualSelection()].ID; _DragAndDropActive = true; return true; } @@ -563,7 +579,7 @@ namespace Vocaluxe.Screens if (!mouseEvent.LBH && _DragAndDropActive) { _DragAndDropActive = false; - Playlists[_Playlist].DragAndDropSongID = -1; + _Playlists[_Playlist].DragAndDropSongID = -1; return true; } @@ -580,7 +596,7 @@ namespace Vocaluxe.Screens else if (_Sso.Selection.CategoryChangeAllowed) { _ToggleSongOptions(ESongOptionsView.None); - SongMenus[_SongMenu].EnterCurrentCategory(); + _SongMenus[_SongMenu].EnterCurrentCategory(); } } @@ -597,7 +613,7 @@ namespace Vocaluxe.Screens _SearchText = _Sso.Sorting.SearchString; CGame.EnterNormalGame(); - SongMenus[_SongMenu].OnShow(); + _SongMenus[_SongMenu].OnShow(); if (_Sso.Selection.PartyMode) _PlaylistActive = false; @@ -605,52 +621,52 @@ namespace Vocaluxe.Screens if (_Sso.Selection.PartyMode) _ToggleSongOptions(ESongOptionsView.None); - SongMenus[_SongMenu].SetActive(!_PlaylistActive); - SongMenus[_SongMenu].SetSmallView(Playlists[_Playlist].Visible); + _SongMenus[_SongMenu].SetActive(!_PlaylistActive); + _SongMenus[_SongMenu].SetSmallView(_Playlists[_Playlist].Visible); - if (Playlists[_Playlist].ActivePlaylistID != -1) - Playlists[_Playlist].LoadPlaylist(Playlists[_Playlist].ActivePlaylistID); + if (_Playlists[_Playlist].ActivePlaylistID != -1) + _Playlists[_Playlist].LoadPlaylist(_Playlists[_Playlist].ActivePlaylistID); _DragAndDropActive = false; - Playlists[_Playlist].DragAndDropSongID = -1; + _Playlists[_Playlist].DragAndDropSongID = -1; UpdateGame(); } public override bool UpdateGame() { - if (SongMenus[_SongMenu].IsSmallView()) + if (_SongMenus[_SongMenu].IsSmallView()) CheckPlaylist(); - Texts[_TextCategory].Text = CSongs.GetCurrentCategoryName(); + _Texts[_TextCategory].Text = CSongs.GetCurrentCategoryName(); if (CSongs.Category > -1 || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) CBackgroundMusic.Disabled = true; else CBackgroundMusic.Disabled = false; - int song = SongMenus[_SongMenu].GetActualSelection(); + int song = _SongMenus[_SongMenu].GetActualSelection(); if ((CSongs.Category >= 0 || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) && song >= 0 && song < CSongs.VisibleSongs.Length) - Texts[_TextSelection].Text = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title; + _Texts[_TextSelection].Text = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title; else if (!CSongs.IsInCategory && song >= 0 && song < CSongs.Categories.Length) - Texts[_TextSelection].Text = CSongs.Categories[song].Name; + _Texts[_TextSelection].Text = CSongs.Categories[song].Name; else - Texts[_TextSelection].Text = String.Empty; + _Texts[_TextSelection].Text = String.Empty; - Texts[_TextSearchBar].Text = _SearchText; + _Texts[_TextSearchBar].Text = _SearchText; if (_SearchActive) { - Texts[_TextSearchBar].Text += '|'; + _Texts[_TextSearchBar].Text += '|'; - Texts[_TextSearchBar].Visible = true; - Texts[_TextSearchBarTitle].Visible = true; - Statics[_StaticSearchBar].Visible = true; + _Texts[_TextSearchBar].Visible = true; + _Texts[_TextSearchBarTitle].Visible = true; + _Statics[_StaticSearchBar].Visible = true; } else { - Texts[_TextSearchBar].Visible = false; - Texts[_TextSearchBarTitle].Visible = false; - Statics[_StaticSearchBar].Visible = false; + _Texts[_TextSearchBar].Visible = false; + _Texts[_TextSearchBarTitle].Visible = false; + _Statics[_StaticSearchBar].Visible = false; } _UpdatePartyModeOptions(); @@ -672,12 +688,12 @@ namespace Vocaluxe.Screens { base.OnClose(); CBackgroundMusic.Disabled = false; - SongMenus[_SongMenu].OnHide(); + _SongMenus[_SongMenu].OnHide(); } public override void ApplyVolume() { - SongMenus[_SongMenu].ApplyVolume(CConfig.PreviewMusicVolume); + _SongMenus[_SongMenu].ApplyVolume(CConfig.PreviewMusicVolume); } private void _HandlePartySongSelection(int songNr) @@ -704,12 +720,12 @@ namespace Vocaluxe.Screens _SelectNextRandomSong(); if (_Sso.Selection.SongIndex != -1) - SongMenus[_SongMenu].SetSelectedSong(_Sso.Selection.SongIndex); + _SongMenus[_SongMenu].SetSelectedSong(_Sso.Selection.SongIndex); } - if (_SelectedSongID != SongMenus[_SongMenu].GetSelectedSong() && CSongs.Category > -1) + if (_SelectedSongID != _SongMenus[_SongMenu].GetSelectedSong() && CSongs.Category > -1) { - _SelectedSongID = SongMenus[_SongMenu].GetSelectedSong(); + _SelectedSongID = _SongMenus[_SongMenu].GetSelectedSong(); CParty.OnSongChange(_SelectedSongID, ref _Sso); } @@ -726,55 +742,55 @@ namespace Vocaluxe.Screens _ToggleSongOptions(ESongOptionsView.None); } - SongMenus[_SongMenu].Update(_Sso); + _SongMenus[_SongMenu].Update(_Sso); if (_Sso.Selection.RandomOnly && _Sso.Selection.NumJokers != null) { - Buttons[_ButtonStart].Visible = true; + _Buttons[_ButtonStart].Visible = true; - if (!SongMenus[_SongMenu].IsSmallView()) - SongMenus[_SongMenu].SetSmallView(true); + if (!_SongMenus[_SongMenu].IsSmallView()) + _SongMenus[_SongMenu].SetSmallView(true); - for (int i = 0; i < CMain.Settings.GetMaxNumPlayer(); i++) + for (int i = 0; i < CSettings.MaxNumPlayer; i++) { if (i < _Sso.Selection.NumJokers.Length) { - Buttons[_ButtonsJoker[i]].Visible = true; - Buttons[_ButtonsJoker[i]].Text.Text = _Sso.Selection.NumJokers[i].ToString(); - Texts[_TextsPlayer[i]].Visible = true; + _Buttons[_ButtonsJoker[i]].Visible = true; + _Buttons[_ButtonsJoker[i]].Text.Text = _Sso.Selection.NumJokers[i].ToString(); + _Texts[_TextsPlayer[i]].Visible = true; bool nameExists = false; if (_Sso.Selection.TeamNames != null) { if (_Sso.Selection.TeamNames.Length > i) { - Texts[_TextsPlayer[i]].Text = _Sso.Selection.TeamNames[i]; + _Texts[_TextsPlayer[i]].Text = _Sso.Selection.TeamNames[i]; nameExists = true; } } if (!nameExists) - Texts[_TextsPlayer[i]].Text = i.ToString(); + _Texts[_TextsPlayer[i]].Text = i.ToString(); } else { - Buttons[_ButtonsJoker[i]].Visible = false; - Texts[_TextsPlayer[i]].Visible = false; + _Buttons[_ButtonsJoker[i]].Visible = false; + _Texts[_TextsPlayer[i]].Visible = false; } } } else { - if (_Sso.Selection.PartyMode && SongMenus[_SongMenu].IsSmallView()) - SongMenus[_SongMenu].SetSmallView(false); + if (_Sso.Selection.PartyMode && _SongMenus[_SongMenu].IsSmallView()) + _SongMenus[_SongMenu].SetSmallView(false); - for (int i = 0; i < CMain.Settings.GetMaxNumPlayer(); i++) + for (int i = 0; i < CSettings.MaxNumPlayer; i++) { - Buttons[_ButtonsJoker[i]].Visible = false; - Texts[_TextsPlayer[i]].Visible = false; + _Buttons[_ButtonsJoker[i]].Visible = false; + _Texts[_TextsPlayer[i]].Visible = false; } - Buttons[_ButtonStart].Visible = false; + _Buttons[_ButtonStart].Visible = false; } } @@ -783,15 +799,10 @@ namespace Vocaluxe.Screens if ((CSongs.Category >= 0) && (songNr >= 0)) { EGameMode gm; - if (_AvailableGameModes.Count >= SelectSlides[_SelectSlideOptionsMode].Selection) - gm = _AvailableGameModes[SelectSlides[_SelectSlideOptionsMode].Selection]; + if (_AvailableGameModes.Count >= _SelectSlides[_SelectSlideOptionsMode].Selection) + gm = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; else - { - if (CSongs.VisibleSongs[songNr].IsDuet) - gm = EGameMode.TR_GAMEMODE_DUET; - else - gm = EGameMode.TR_GAMEMODE_NORMAL; - } + gm = CSongs.VisibleSongs[songNr].IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL; CGame.Reset(); CGame.ClearSongs(); @@ -806,11 +817,7 @@ namespace Vocaluxe.Screens { if (CSongs.Category >= 0 && songNr >= 0 && CSongs.NumVisibleSongs > songNr) { - EGameMode gm; - if (CSongs.VisibleSongs[songNr].IsDuet) - gm = EGameMode.TR_GAMEMODE_DUET; - else - gm = EGameMode.TR_GAMEMODE_NORMAL; + EGameMode gm = CSongs.VisibleSongs[songNr].IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL; CGame.Reset(); CGame.ClearSongs(); @@ -844,13 +851,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) @@ -858,7 +865,7 @@ namespace Vocaluxe.Screens CGame.AddSong(songNr, gm); - iDs.Remove(songNr); + ids.Remove(songNr); } if (CGame.GetNumSongs() > 0) @@ -870,13 +877,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) @@ -884,7 +891,7 @@ namespace Vocaluxe.Screens CGame.AddSong(songNr, gm); - iDs.Remove(songNr); + ids.Remove(songNr); } if (CGame.GetNumSongs() > 0) @@ -896,21 +903,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) { @@ -922,7 +929,7 @@ namespace Vocaluxe.Screens } } - iDs.Remove(songNr); + ids.Remove(songNr); } if (CGame.GetNumSongs() > 0) @@ -957,7 +964,7 @@ namespace Vocaluxe.Screens if (CSongs.IsInCategory) { _ToggleSongOptions(ESongOptionsView.None); - SongMenus[_SongMenu].SetSelectedSong(CSongs.GetRandomSong()); + _SongMenus[_SongMenu].SetSelectedSong(CSongs.GetRandomSong()); return true; } return false; @@ -968,7 +975,7 @@ namespace Vocaluxe.Screens if (!CSongs.IsInCategory) { _ToggleSongOptions(ESongOptionsView.None); - SongMenus[_SongMenu].SetSelectedCategory(CSongs.GetRandomCategory()); + _SongMenus[_SongMenu].SetSelectedCategory(CSongs.GetRandomCategory()); return true; } return false; @@ -977,7 +984,7 @@ namespace Vocaluxe.Screens private void _JumpTo(char letter) { int start = 0; - int curSelected = SongMenus[_SongMenu].GetActualSelection(); + int curSelected = _SongMenus[_SongMenu].GetActualSelection(); if (CSongs.IsInCategory) { //TODO: Check and use sorting method @@ -993,7 +1000,7 @@ namespace Vocaluxe.Screens if (visibleID < 0 && start > 1) visibleID = Array.FindIndex(songs, 0, start - 1, element => element.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); if (visibleID > -1) - SongMenus[_SongMenu].SetSelectedSong(visibleID); + _SongMenus[_SongMenu].SetSelectedSong(visibleID); } else { @@ -1005,7 +1012,7 @@ namespace Vocaluxe.Screens if (visibleID < 0 && start > 1) visibleID = Array.FindIndex(categories, 0, start - 1, element => element.Name.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); if (visibleID > -1) - SongMenus[_SongMenu].SetSelectedCategory(visibleID); + _SongMenus[_SongMenu].SetSelectedCategory(visibleID); } } @@ -1017,18 +1024,18 @@ namespace Vocaluxe.Screens bool refresh = false; _SearchText = newFilterString; - int songIndex = SongMenus[_SongMenu].GetSelectedSong(); + int songIndex = _SongMenus[_SongMenu].GetSelectedSong(); int songID = -1; if (songIndex != -1 && CSongs.NumVisibleSongs > 0 && CSongs.NumVisibleSongs > songIndex) songID = CSongs.VisibleSongs[songIndex].ID; - if (newFilterString.Length == 0 && _Sso.Sorting.Tabs == EOffOn.TR_CONFIG_ON) + if (newFilterString == "" && _Sso.Sorting.Tabs == EOffOn.TR_CONFIG_ON) { CSongs.Category = -1; refresh = true; } - if (newFilterString.Length > 0 && CSongs.Category != 0) + if (newFilterString != "" && CSongs.Category != 0) { CSongs.Category = 0; refresh = true; @@ -1040,30 +1047,30 @@ namespace Vocaluxe.Screens refresh = true; if (refresh) - SongMenus[_SongMenu].OnHide(); + _SongMenus[_SongMenu].OnHide(); - SongMenus[_SongMenu].OnShow(); + _SongMenus[_SongMenu].OnShow(); } private void _ToggleSongOptions(ESongOptionsView view) { - SelectSlides[_SelectSlideOptionsMode].Visible = false; - SelectSlides[_SelectSlideOptionsPlaylistAdd].Visible = false; - SelectSlides[_SelectSlideOptionsPlaylistOpen].Visible = false; - SelectSlides[_SelectSlideOptionsNumMedleySongs].Visible = false; - Buttons[_ButtonOptionsClose].Visible = false; - Buttons[_ButtonOptionsSing].Visible = false; - Buttons[_ButtonOptionsPlaylist].Visible = false; - Buttons[_ButtonOptionsRandom].Visible = false; - Buttons[_ButtonOptionsRandomCategory].Visible = false; - Buttons[_ButtonOptionsSingAll].Visible = false; - Buttons[_ButtonOptionsSingAllVisible].Visible = false; - Buttons[_ButtonOptionsOpenSelectedItem].Visible = false; - Buttons[_ButtonOptionsRandomMedley].Visible = false; - Buttons[_ButtonOptionsStartMedley].Visible = false; - Texts[_TextOptionsTitle].Visible = false; - Statics[_StaticOptionsBG].Visible = false; - Buttons[_ButtonOpenOptions].Visible = true; + _SelectSlides[_SelectSlideOptionsMode].Visible = false; + _SelectSlides[_SelectSlideOptionsPlaylistAdd].Visible = false; + _SelectSlides[_SelectSlideOptionsPlaylistOpen].Visible = false; + _SelectSlides[_SelectSlideOptionsNumMedleySongs].Visible = false; + _Buttons[_ButtonOptionsClose].Visible = false; + _Buttons[_ButtonOptionsSing].Visible = false; + _Buttons[_ButtonOptionsPlaylist].Visible = false; + _Buttons[_ButtonOptionsRandom].Visible = false; + _Buttons[_ButtonOptionsRandomCategory].Visible = false; + _Buttons[_ButtonOptionsSingAll].Visible = false; + _Buttons[_ButtonOptionsSingAllVisible].Visible = false; + _Buttons[_ButtonOptionsOpenSelectedItem].Visible = false; + _Buttons[_ButtonOptionsRandomMedley].Visible = false; + _Buttons[_ButtonOptionsStartMedley].Visible = false; + _Texts[_TextOptionsTitle].Visible = false; + _Statics[_StaticOptionsBG].Visible = false; + _Buttons[_ButtonOpenOptions].Visible = true; _SongOptionsActive = view != ESongOptionsView.None; @@ -1072,10 +1079,10 @@ namespace Vocaluxe.Screens //Has to be done here otherwhise changed playlist names will not appear until OnShow is called! _UpdatePlaylistNames(); - Texts[_TextOptionsTitle].Visible = true; - Buttons[_ButtonOptionsClose].Visible = true; - Statics[_StaticOptionsBG].Visible = true; - Buttons[_ButtonOpenOptions].Visible = false; + _Texts[_TextOptionsTitle].Visible = true; + _Buttons[_ButtonOptionsClose].Visible = true; + _Statics[_StaticOptionsBG].Visible = true; + _Buttons[_ButtonOpenOptions].Visible = false; if (view == ESongOptionsView.Song) _ShowSongOptionsSong(); else if (view == ESongOptionsView.General) @@ -1089,88 +1096,88 @@ namespace Vocaluxe.Screens { EGameMode lastMode = EGameMode.TR_GAMEMODE_NORMAL; if (_AvailableGameModes.Count > 0) - lastMode = _AvailableGameModes[SelectSlides[_SelectSlideOptionsMode].Selection]; - SetInteractionToButton(Buttons[_ButtonOptionsSing]); + lastMode = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; + _SetInteractionToButton(_Buttons[_ButtonOptionsSing]); _AvailableGameModes.Clear(); - SelectSlides[_SelectSlideOptionsMode].Clear(); - if (CSongs.VisibleSongs[SongMenus[_SongMenu].GetSelectedSong()].IsDuet) + _SelectSlides[_SelectSlideOptionsMode].Clear(); + if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].IsDuet) { - SelectSlides[_SelectSlideOptionsMode].AddValue(Enum.GetName(typeof(EGameMode), EGameMode.TR_GAMEMODE_DUET)); + _SelectSlides[_SelectSlideOptionsMode].AddValue(Enum.GetName(typeof(EGameMode), EGameMode.TR_GAMEMODE_DUET)); _AvailableGameModes.Add(EGameMode.TR_GAMEMODE_DUET); } else { - SelectSlides[_SelectSlideOptionsMode].AddValue(Enum.GetName(typeof(EGameMode), EGameMode.TR_GAMEMODE_NORMAL)); + _SelectSlides[_SelectSlideOptionsMode].AddValue(Enum.GetName(typeof(EGameMode), EGameMode.TR_GAMEMODE_NORMAL)); _AvailableGameModes.Add(EGameMode.TR_GAMEMODE_NORMAL); - SelectSlides[_SelectSlideOptionsMode].AddValue(Enum.GetName(typeof(EGameMode), EGameMode.TR_GAMEMODE_SHORTSONG)); + _SelectSlides[_SelectSlideOptionsMode].AddValue(Enum.GetName(typeof(EGameMode), EGameMode.TR_GAMEMODE_SHORTSONG)); _AvailableGameModes.Add(EGameMode.TR_GAMEMODE_SHORTSONG); } - if (CSongs.VisibleSongs[SongMenus[_SongMenu].GetSelectedSong()].Medley.Source != EMedleySource.None) + if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].Medley.Source != EMedleySource.None) { - SelectSlides[_SelectSlideOptionsMode].AddValue(Enum.GetName(typeof(EGameMode), EGameMode.TR_GAMEMODE_MEDLEY)); + _SelectSlides[_SelectSlideOptionsMode].AddValue(Enum.GetName(typeof(EGameMode), EGameMode.TR_GAMEMODE_MEDLEY)); _AvailableGameModes.Add(EGameMode.TR_GAMEMODE_MEDLEY); } //Set SelectSlide-Selection to last selected game-mode if possible for (int i = 0; i < _AvailableGameModes.Count; i++) { if (_AvailableGameModes[i] == lastMode) - SelectSlides[_SelectSlideOptionsMode].SetSelectionByValueIndex(i); + _SelectSlides[_SelectSlideOptionsMode].SetSelectionByValueIndex(i); } - SelectSlides[_SelectSlideOptionsMode].Visible = true; - SelectSlides[_SelectSlideOptionsPlaylistAdd].Visible = true; - Buttons[_ButtonOptionsSing].Visible = true; - Buttons[_ButtonOptionsPlaylist].Visible = true; - SetInteractionToButton(Buttons[_ButtonOptionsSing]); + _SelectSlides[_SelectSlideOptionsMode].Visible = true; + _SelectSlides[_SelectSlideOptionsPlaylistAdd].Visible = true; + _Buttons[_ButtonOptionsSing].Visible = true; + _Buttons[_ButtonOptionsPlaylist].Visible = true; + _SetInteractionToButton(_Buttons[_ButtonOptionsSing]); } private void _ShowSongOptionsGeneral() { if (CSongs.IsInCategory) { - Buttons[_ButtonOptionsRandom].Visible = true; - Buttons[_ButtonOptionsSingAllVisible].Visible = true; + _Buttons[_ButtonOptionsRandom].Visible = true; + _Buttons[_ButtonOptionsSingAllVisible].Visible = true; } else - Buttons[_ButtonOptionsRandomCategory].Visible = true; - Buttons[_ButtonOptionsSingAll].Visible = true; - Buttons[_ButtonOptionsRandomMedley].Visible = true; - Buttons[_ButtonOptionsOpenSelectedItem].Visible = true; + _Buttons[_ButtonOptionsRandomCategory].Visible = true; + _Buttons[_ButtonOptionsSingAll].Visible = true; + _Buttons[_ButtonOptionsRandomMedley].Visible = true; + _Buttons[_ButtonOptionsOpenSelectedItem].Visible = true; - if (SelectSlides[_SelectSlideOptionsPlaylistOpen].NumValues > 0) - SelectSlides[_SelectSlideOptionsPlaylistOpen].Visible = true; + if (_SelectSlides[_SelectSlideOptionsPlaylistOpen].NumValues > 0) + _SelectSlides[_SelectSlideOptionsPlaylistOpen].Visible = true; - if (Buttons[_ButtonOptionsRandom].Visible) - SetInteractionToButton(Buttons[_ButtonOptionsRandom]); + if (_Buttons[_ButtonOptionsRandom].Visible) + _SetInteractionToButton(_Buttons[_ButtonOptionsRandom]); else - SetInteractionToButton(Buttons[_ButtonOptionsRandomCategory]); + _SetInteractionToButton(_Buttons[_ButtonOptionsRandomCategory]); } private void _ShowSongOptionsMedley() { - Buttons[_ButtonOptionsStartMedley].Visible = true; - SelectSlides[_SelectSlideOptionsNumMedleySongs].Visible = true; - SelectSlides[_SelectSlideOptionsNumMedleySongs].Clear(); + _Buttons[_ButtonOptionsStartMedley].Visible = true; + _SelectSlides[_SelectSlideOptionsNumMedleySongs].Visible = true; + _SelectSlides[_SelectSlideOptionsNumMedleySongs].Clear(); if (CSongs.IsInCategory) { for (int i = 1; i <= CSongs.VisibleSongs.Length; i++) - SelectSlides[_SelectSlideOptionsNumMedleySongs].AddValue(i.ToString()); + _SelectSlides[_SelectSlideOptionsNumMedleySongs].AddValue(i.ToString()); } else { for (int i = 1; i <= CSongs.AllSongs.Length; i++) - SelectSlides[_SelectSlideOptionsNumMedleySongs].AddValue(i.ToString()); + _SelectSlides[_SelectSlideOptionsNumMedleySongs].AddValue(i.ToString()); } - if (SelectSlides[_SelectSlideOptionsNumMedleySongs].NumValues >= 5) - SelectSlides[_SelectSlideOptionsNumMedleySongs].SetSelectionByValueIndex(4); + if (_SelectSlides[_SelectSlideOptionsNumMedleySongs].NumValues >= 5) + _SelectSlides[_SelectSlideOptionsNumMedleySongs].SetSelectionByValueIndex(4); else - SelectSlides[_SelectSlideOptionsNumMedleySongs].SetSelectionByValueIndex(SelectSlides[_SelectSlideOptionsNumMedleySongs].NumValues - 1); - SetInteractionToButton(Buttons[_ButtonOptionsStartMedley]); + _SelectSlides[_SelectSlideOptionsNumMedleySongs].SetSelectionByValueIndex(_SelectSlides[_SelectSlideOptionsNumMedleySongs].NumValues - 1); + _SetInteractionToButton(_Buttons[_ButtonOptionsStartMedley]); } #region Playlist Actions public void CheckPlaylist() { - if (Playlists[_Playlist].ActivePlaylistID == -1 && _PlaylistActive) + if (_Playlists[_Playlist].ActivePlaylistID == -1 && _PlaylistActive) _ClosePlaylist(); } @@ -1178,100 +1185,100 @@ namespace Vocaluxe.Screens { if (CPlaylists.Playlists.Length > playlistID && playlistID > -1) { - Playlists[_Playlist].LoadPlaylist(playlistID); - SongMenus[_SongMenu].SetSmallView(true); - Playlists[_Playlist].Visible = true; + _Playlists[_Playlist].LoadPlaylist(playlistID); + _SongMenus[_SongMenu].SetSmallView(true); + _Playlists[_Playlist].Visible = true; } } private void _ClosePlaylist() { - if (Playlists[_Playlist].Visible || _PlaylistActive) + if (_Playlists[_Playlist].Visible || _PlaylistActive) { - SongMenus[_SongMenu].SetSmallView(false); + _SongMenus[_SongMenu].SetSmallView(false); _PlaylistActive = false; - Playlists[_Playlist].Selected = _PlaylistActive; - SongMenus[_SongMenu].SetActive(!_PlaylistActive); - Playlists[_Playlist].ClosePlaylist(); + _Playlists[_Playlist].Selected = _PlaylistActive; + _SongMenus[_SongMenu].SetActive(!_PlaylistActive); + _Playlists[_Playlist].ClosePlaylist(); } } private void _UpdatePlaylistNames() { - SelectSlides[_SelectSlideOptionsPlaylistAdd].Clear(); - SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValue("TR_SCREENSONG_NEWPLAYLIST"); - SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValues(CPlaylists.PlaylistNames); - SelectSlides[_SelectSlideOptionsPlaylistOpen].Clear(); - SelectSlides[_SelectSlideOptionsPlaylistOpen].AddValues(CPlaylists.PlaylistNames); + _SelectSlides[_SelectSlideOptionsPlaylistAdd].Clear(); + _SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValue("TR_SCREENSONG_NEWPLAYLIST"); + _SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValues(CPlaylists.PlaylistNames); + _SelectSlides[_SelectSlideOptionsPlaylistOpen].Clear(); + _SelectSlides[_SelectSlideOptionsPlaylistOpen].AddValues(CPlaylists.PlaylistNames); } private void _OpenPlaylistAction() { //Open a playlist - if (Playlists[_Playlist].ActivePlaylistID != SelectSlides[_SelectSlideOptionsPlaylistOpen].Selection) + if (_Playlists[_Playlist].ActivePlaylistID != _SelectSlides[_SelectSlideOptionsPlaylistOpen].Selection) { - Playlists[_Playlist].ActivePlaylistID = SelectSlides[_SelectSlideOptionsPlaylistOpen].Selection; + _Playlists[_Playlist].ActivePlaylistID = _SelectSlides[_SelectSlideOptionsPlaylistOpen].Selection; _SetSelectSlidePlaylistToCurrentPlaylist(); //Open playlist - _OpenPlaylist(Playlists[_Playlist].ActivePlaylistID); + _OpenPlaylist(_Playlists[_Playlist].ActivePlaylistID); } } private void _OpenAndAddPlaylistAction() { //Open an existing playlist and add song - if (Playlists[_Playlist].ActivePlaylistID != (SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) && - (SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) != -1) + if (_Playlists[_Playlist].ActivePlaylistID != (_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) && + (_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) != -1) { //Check selected game-mode EGameMode gm; - if (_AvailableGameModes.Count >= SelectSlides[_SelectSlideOptionsMode].Selection) - gm = _AvailableGameModes[SelectSlides[_SelectSlideOptionsMode].Selection]; - else if (CSongs.VisibleSongs[SongMenus[_SongMenu].GetSelectedSong()].IsDuet) + if (_AvailableGameModes.Count >= _SelectSlides[_SelectSlideOptionsMode].Selection) + gm = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; + else if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].IsDuet) gm = EGameMode.TR_GAMEMODE_DUET; else gm = EGameMode.TR_GAMEMODE_NORMAL; //Check if Playlist really exists - if (SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1 >= 0) + if (_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1 >= 0) { - Playlists[_Playlist].ActivePlaylistID = SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1; + _Playlists[_Playlist].ActivePlaylistID = _SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1; //Add song to playlist - CPlaylists.Playlists[Playlists[_Playlist].ActivePlaylistID].AddSong(CSongs.VisibleSongs[SongMenus[_SongMenu].GetSelectedSong()].ID, gm); + CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].AddSong(CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].ID, gm); //Open playlist - _OpenPlaylist(Playlists[_Playlist].ActivePlaylistID); + _OpenPlaylist(_Playlists[_Playlist].ActivePlaylistID); _SetSelectSlidePlaylistToCurrentPlaylist(); - Playlists[_Playlist].ScrollToBottom(); + _Playlists[_Playlist].ScrollToBottom(); } } //Create a new playlist and add song - else if ((SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) == -1) + else if ((_SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection - 1) == -1) { //Check selected game-mode EGameMode gm; - if (_AvailableGameModes.Count >= SelectSlides[_SelectSlideOptionsMode].Selection) - gm = _AvailableGameModes[SelectSlides[_SelectSlideOptionsMode].Selection]; - else if (CSongs.VisibleSongs[SongMenus[_SongMenu].GetSelectedSong()].IsDuet) + if (_AvailableGameModes.Count >= _SelectSlides[_SelectSlideOptionsMode].Selection) + gm = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; + else if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].IsDuet) gm = EGameMode.TR_GAMEMODE_DUET; else gm = EGameMode.TR_GAMEMODE_NORMAL; //Create new playlist - Playlists[_Playlist].ActivePlaylistID = CPlaylists.NewPlaylist(); + _Playlists[_Playlist].ActivePlaylistID = CPlaylists.NewPlaylist(); //Add song to playlist - CPlaylists.Playlists[Playlists[_Playlist].ActivePlaylistID].AddSong(CSongs.VisibleSongs[SongMenus[_SongMenu].GetSelectedSong()].ID, gm); + CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].AddSong(CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].ID, gm); //Open playlist - _OpenPlaylist(Playlists[_Playlist].ActivePlaylistID); + _OpenPlaylist(_Playlists[_Playlist].ActivePlaylistID); //Add new playlist to select-slide - SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValue(CPlaylists.Playlists[Playlists[_Playlist].ActivePlaylistID].PlaylistName); - SelectSlides[_SelectSlideOptionsPlaylistOpen].AddValue(CPlaylists.Playlists[Playlists[_Playlist].ActivePlaylistID].PlaylistName); + _SelectSlides[_SelectSlideOptionsPlaylistAdd].AddValue(CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].PlaylistName); + _SelectSlides[_SelectSlideOptionsPlaylistOpen].AddValue(CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].PlaylistName); _SetSelectSlidePlaylistToCurrentPlaylist(); } @@ -1280,24 +1287,24 @@ namespace Vocaluxe.Screens { //Check selected game-mode EGameMode gm; - if (_AvailableGameModes.Count >= SelectSlides[_SelectSlideOptionsMode].Selection) - gm = _AvailableGameModes[SelectSlides[_SelectSlideOptionsMode].Selection]; - else if (CSongs.VisibleSongs[SongMenus[_SongMenu].GetSelectedSong()].IsDuet) + if (_AvailableGameModes.Count >= _SelectSlides[_SelectSlideOptionsMode].Selection) + gm = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; + else if (CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].IsDuet) gm = EGameMode.TR_GAMEMODE_DUET; else gm = EGameMode.TR_GAMEMODE_NORMAL; - CPlaylists.Playlists[Playlists[_Playlist].ActivePlaylistID].AddSong(CSongs.VisibleSongs[SongMenus[_SongMenu].GetSelectedSong()].ID, gm); - Playlists[_Playlist].UpdatePlaylist(); - Playlists[_Playlist].ScrollToBottom(); + CPlaylists.Playlists[_Playlists[_Playlist].ActivePlaylistID].AddSong(CSongs.VisibleSongs[_SongMenus[_SongMenu].GetSelectedSong()].ID, gm); + _Playlists[_Playlist].UpdatePlaylist(); + _Playlists[_Playlist].ScrollToBottom(); } } private void _SetSelectSlidePlaylistToCurrentPlaylist() { - if (Playlists[_Playlist].ActivePlaylistID > -1) - SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection = Playlists[_Playlist].ActivePlaylistID + 1; + if (_Playlists[_Playlist].ActivePlaylistID > -1) + _SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection = _Playlists[_Playlist].ActivePlaylistID + 1; else - SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection = 0; + _SelectSlides[_SelectSlideOptionsPlaylistAdd].Selection = 0; } #endregion Playlist Actions } diff --git a/Vocaluxe/Screens/CScreenTest.cs b/Vocaluxe/Screens/CScreenTest.cs index febd8ccf..3fa3f2e4 100644 --- a/Vocaluxe/Screens/CScreenTest.cs +++ b/Vocaluxe/Screens/CScreenTest.cs @@ -1,5 +1,23 @@ -using System; -using System.IO; +#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.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; @@ -14,7 +32,9 @@ namespace Vocaluxe.Screens get { return 1; } } + /* private int _TestMusic = -1; +*/ public override bool HandleInput(SKeyEvent keyEvent) { @@ -51,7 +71,7 @@ namespace Vocaluxe.Screens public override bool HandleMouse(SMouseEvent mouseEvent) { - if (mouseEvent.LB && IsMouseOver(mouseEvent)) {} + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) {} if (mouseEvent.LB) CGraphics.FadeTo(EScreens.ScreenMain); @@ -66,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/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index beac3ace..58fa7a40 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -220,11 +220,9 @@ - - @@ -264,8 +262,7 @@ Designer - - + diff --git a/VocaluxeLib/GlobalSuppressions.cs b/VocaluxeLib/GlobalSuppressions.cs index f43b3e9e..c5b4da19 100644 --- a/VocaluxeLib/GlobalSuppressions.cs +++ b/VocaluxeLib/GlobalSuppressions.cs @@ -1,11 +1,22 @@ -// Diese Datei wird von der Codeanalyse zur Wartung der SuppressMessage- -// Attribute verwendet, die auf dieses Projekt angewendet werden. -// Unterdrückungen auf Projektebene haben entweder kein Ziel oder -// erhalten ein spezifisches Ziel mit Namespace-, Typ-, Memberbereich usw. -// Wenn Sie dieser Datei eine Unterdrückung hinzufügen möchten, klicken Sie mit der -// rechten Maustaste auf die Meldung in der Fehlerliste, zeigen Sie auf -// "Meldung(en) unterdrücken", und klicken Sie auf "In Projektunterdrückungsdatei". -// Sie müssen dieser Datei nicht manuell Unterdrückungen hinzufügen. +#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.Diagnostics.CodeAnalysis; [assembly: diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index a936bbb5..11cf7124 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -1,4 +1,23 @@ -using System; +#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.Drawing; using System.Xml; @@ -56,11 +75,11 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Type", ref _Theme.Type); - bool vid = xmlReader.GetValue(item + "/Video", ref _Theme.VideoName, String.Empty); - bool tex = xmlReader.GetValue(item + "/Skin", ref _Theme.TextureName, String.Empty); + bool vid = xmlReader.GetValue(item + "/Video", out _Theme.VideoName, String.Empty); + bool tex = xmlReader.GetValue(item + "/Skin", out _Theme.TextureName, String.Empty); _ThemeLoaded &= vid || tex || _Theme.Type == EBackgroundTypes.None; - if (xmlReader.GetValue(item + "/Color", ref _Theme.ColorName, String.Empty)) + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else { @@ -99,7 +118,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Background color for type \"Color\" from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("Color", _Theme.ColorName); else { @@ -120,13 +139,13 @@ namespace VocaluxeLib.Menu public void Resume() { - if (_Theme.Type == EBackgroundTypes.Video && _Theme.VideoName.Length > 0 && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON) + if (_Theme.Type == EBackgroundTypes.Video && _Theme.VideoName != "" && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON) CBase.Theme.SkinVideoResume(_Theme.VideoName, _PartyModeID); } public void Pause() { - if (_Theme.VideoName.Length > 0) + if (_Theme.VideoName != "") CBase.Theme.SkinVideoPause(_Theme.VideoName, _PartyModeID); } @@ -146,7 +165,7 @@ namespace VocaluxeLib.Menu ok = _DrawVideo(); } - if (_Theme.TextureName.Length > 0 && + if (_Theme.TextureName != "" && (_Theme.Type == EBackgroundTypes.Texture || (_Theme.Type == EBackgroundTypes.Video && (CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF || !ok)))) ok = _DrawTexture(); @@ -162,7 +181,7 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } @@ -188,7 +207,7 @@ namespace VocaluxeLib.Menu { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect = new RectangleF(0f, 0f, texture.Width, texture.Height); - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; @@ -203,7 +222,7 @@ namespace VocaluxeLib.Menu { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect = new RectangleF(0f, 0f, videoTexture.Width, videoTexture.Height); - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; @@ -218,7 +237,7 @@ namespace VocaluxeLib.Menu { RectangleF bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); RectangleF rect = new RectangleF(0f, 0f, videoTexture.Width, videoTexture.Height); - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); return true; diff --git a/VocaluxeLib/Menu/CBasic.cs b/VocaluxeLib/Menu/CBasic.cs index 85021d45..db31f26b 100644 --- a/VocaluxeLib/Menu/CBasic.cs +++ b/VocaluxeLib/Menu/CBasic.cs @@ -1,11 +1,29 @@ -namespace VocaluxeLib.Menu +#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 VocaluxeLib.Menu { public static class CBase { public static IConfig Config; public static ISettings Settings; public static ITheme Theme; - public static IHelper Helper; public static ILog Log; public static IBackgroundMusic BackgroundMusic; public static IDrawing Drawing; @@ -23,14 +41,13 @@ public static IInputs Input; public static IPlaylist Playlist; - public static void Assign(IConfig config, ISettings settings, ITheme theme, IHelper helper, ILog log, IBackgroundMusic backgroundMusic, + public static void Assign(IConfig config, ISettings settings, ITheme theme, ILog log, IBackgroundMusic backgroundMusic, IDrawing draw, IGraphics graphics, IFonts fonts, ILanguage language, IGame game, IProfiles profiles, IRecording record, ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IInputs input, IPlaylist playlist) { Config = config; Settings = settings; Theme = theme; - Helper = helper; Log = log; BackgroundMusic = backgroundMusic; Drawing = draw; diff --git a/VocaluxeLib/Menu/CButton.cs b/VocaluxeLib/Menu/CButton.cs index 27761750..b3a69d15 100644 --- a/VocaluxeLib/Menu/CButton.cs +++ b/VocaluxeLib/Menu/CButton.cs @@ -1,4 +1,23 @@ -using System; +#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.Xml; namespace VocaluxeLib.Menu @@ -26,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; @@ -46,7 +65,7 @@ namespace VocaluxeLib.Menu set { Text.EditMode = value; - SelText.EditMode = value; + _SelText.EditMode = value; } } @@ -78,31 +97,33 @@ 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) { _PartyModeID = button._PartyModeID; - _Theme = new SThemeButton(); - _Theme.ColorName = button._Theme.ColorName; - _Theme.SelColorName = button._Theme.SelColorName; - _Theme.TextureName = button._Theme.TextureName; - _Theme.SelTextureName = button._Theme.SelTextureName; + _Theme = new SThemeButton + { + ColorName = button._Theme.ColorName, + SelColorName = button._Theme.SelColorName, + TextureName = button._Theme.TextureName, + SelTextureName = button._Theme.SelTextureName + }; Rect = new SRectF(button.Rect); Color = new SColorF(button.Color); @@ -110,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) @@ -133,8 +154,8 @@ namespace VocaluxeLib.Menu string item = xmlPath + "/" + elementName; _ThemeLoaded = true; - _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", ref _Theme.TextureName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinSelected", ref _Theme.SelTextureName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", out _Theme.TextureName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinSelected", out _Theme.SelTextureName, String.Empty); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/X", ref Rect.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Y", ref Rect.Y); @@ -142,7 +163,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref Rect.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref Rect.H); - if (xmlReader.GetValue(item + "/Color", ref _Theme.ColorName, String.Empty)) + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else { @@ -152,7 +173,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref Color.A); } - if (xmlReader.GetValue(item + "/SColor", ref _Theme.SelColorName, String.Empty)) + if (xmlReader.GetValue(item + "/SColor", out _Theme.SelColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.SelColorName, skinIndex, out SelColor); else { @@ -166,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) { @@ -220,7 +241,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Button color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("Color", _Theme.ColorName); else { @@ -232,7 +253,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected button color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorName.Length > 0) + if (_Theme.SelColorName != "") writer.WriteElementString("SColor", _Theme.SelColorName); else { @@ -243,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(); } @@ -275,73 +296,54 @@ namespace VocaluxeLib.Menu return false; } - public void Draw() - { - Draw(false); - } - - public void ForceDraw() - { - Draw(true); - } - - public void Draw(bool forceDraw) + public void Draw(bool forceDraw = false) { if (!Visible && CBase.Settings.GetGameState() != EGameState.EditTheme && !forceDraw) return; - STexture texture = new STexture(-1); + STexture texture; if (!Selected && !Pressed || !Enabled) { - if (Texture.Index != -1) - texture = Texture; - else - texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); + texture = Texture.Index != -1 ? Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); 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) { - if (Texture.Index != -1) - texture = Texture; - else - texture = CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); + 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) { - if (SelTexture.Index != -1) - texture = SelTexture; - else - texture = CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID); + 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); } } @@ -359,10 +361,10 @@ namespace VocaluxeLib.Menu { Text.LoadTextures(); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SelColorName.Length > 0) + if (_Theme.SelColorName != "") SelColor = CBase.Theme.GetColor(_Theme.SelColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CEqualizer.cs b/VocaluxeLib/Menu/CEqualizer.cs index a496deb9..5c258229 100644 --- a/VocaluxeLib/Menu/CEqualizer.cs +++ b/VocaluxeLib/Menu/CEqualizer.cs @@ -1,4 +1,23 @@ -using System; +#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.Xml; namespace VocaluxeLib.Menu @@ -72,7 +91,7 @@ namespace VocaluxeLib.Menu string item = xmlPath + "/" + elementName; _ThemeLoaded = true; - _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", ref _Theme.TextureName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", out _Theme.TextureName, String.Empty); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/X", ref Rect.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Y", ref Rect.Y); @@ -88,7 +107,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/DrawNegative", ref _Theme.DrawNegative); - if (xmlReader.GetValue(item + "/Color", ref _Theme.ColorName, String.Empty)) + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else { @@ -98,7 +117,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref Color.A); } - if (xmlReader.GetValue(item + "/MaxColor", ref _Theme.MaxColorName, String.Empty)) + if (xmlReader.GetValue(item + "/MaxColor", out _Theme.MaxColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else { @@ -156,7 +175,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Equalizer color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("Color", _Theme.ColorName); else { @@ -167,7 +186,7 @@ namespace VocaluxeLib.Menu } writer.WriteComment(": Equalizer color for maximal volume from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("MaxColor", _Theme.ColorName); else { @@ -222,7 +241,7 @@ namespace VocaluxeLib.Menu public void Draw() { - if (_Bars == null) + if (_Bars == null || _Theme.Style != EEqualizerStyle.Collums) return; float dx = Rect.W / _Bars.Length; @@ -255,10 +274,10 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.MaxColorName.Length > 0) + if (_Theme.MaxColorName != "") MaxColor = CBase.Theme.GetColor(_Theme.MaxColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CHelper.cs b/VocaluxeLib/Menu/CHelper.cs index 29297b0f..bdf1a007 100644 --- a/VocaluxeLib/Menu/CHelper.cs +++ b/VocaluxeLib/Menu/CHelper.cs @@ -1,4 +1,23 @@ -using System; +#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.Globalization; @@ -49,7 +68,6 @@ namespace VocaluxeLib.Menu public static int TryReadInt(StreamReader sr) { - char chr = '0'; string value = String.Empty; try @@ -58,7 +76,7 @@ namespace VocaluxeLib.Menu //Check for ' ', ?, ?, \n, \r while (tmp != 32 && tmp != 19 && tmp != 16 && tmp != 13 && tmp != 10) { - chr = (char)sr.Read(); + char chr = (char)sr.Read(); value += chr.ToString(); tmp = sr.Peek(); } @@ -67,20 +85,18 @@ namespace VocaluxeLib.Menu { return 0; } - int result = 0; - if (int.TryParse(value, out result)) - return result; - return 0; + int result; + return int.TryParse(value, out result) ? result : 0; } - public static void SetRect(RectangleF bounds, ref RectangleF rect, float rectAspect, EAspect aspect) + public static void SetRect(RectangleF bounds, out RectangleF rect, float rectAspect, EAspect aspect) { float rW = bounds.Right - bounds.Left; float rH = bounds.Bottom - bounds.Top; float rA = rW / rH; - float scaledWidth = rW; - float scaledHeight = rH; + float scaledWidth; + float scaledHeight; switch (aspect) { @@ -123,17 +139,7 @@ namespace VocaluxeLib.Menu rect = new RectangleF(left, upper, rigth - left, lower - upper); } - public static List ListFiles(string path, string cast) - { - return ListFiles(path, cast, false, false); - } - - public static List ListFiles(string path, string cast, bool recursive) - { - return ListFiles(path, cast, recursive, false); - } - - public static List ListFiles(string path, string cast, bool recursive, bool fullpath) + public static List ListFiles(string path, string cast, bool recursive = false, bool fullpath = false) { List files = new List(); DirectoryInfo dir = new DirectoryInfo(path); @@ -141,17 +147,12 @@ namespace VocaluxeLib.Menu try { foreach (FileInfo file in dir.GetFiles(cast)) - { - if (!fullpath) - files.Add(file.Name); - else - files.Add(file.FullName); - } + files.Add(!fullpath ? file.Name : file.FullName); if (recursive) { foreach (DirectoryInfo di in dir.GetDirectories()) - files.AddRange(ListFiles(di.FullName, cast, recursive, fullpath)); + files.AddRange(ListFiles(di.FullName, cast, true, fullpath)); } } catch (Exception) {} diff --git a/VocaluxeLib/Menu/CInteraction.cs b/VocaluxeLib/Menu/CInteraction.cs index 586efc60..b84e3892 100644 --- a/VocaluxeLib/Menu/CInteraction.cs +++ b/VocaluxeLib/Menu/CInteraction.cs @@ -1,4 +1,23 @@ -namespace VocaluxeLib.Menu +#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 VocaluxeLib.Menu { public enum EType { diff --git a/VocaluxeLib/Menu/CLyric.cs b/VocaluxeLib/Menu/CLyric.cs index e858284d..2d18e6ec 100644 --- a/VocaluxeLib/Menu/CLyric.cs +++ b/VocaluxeLib/Menu/CLyric.cs @@ -1,4 +1,23 @@ -using System; +#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.Xml; @@ -39,7 +58,6 @@ namespace VocaluxeLib.Menu private float _H; private float _Width; - private ELyricStyle _Style; private float _Alpha = 1f; @@ -51,7 +69,7 @@ namespace VocaluxeLib.Menu public SRectF Rect { get { return new SRectF(_X, _Y, _MaxW, _H, _Z); } - set + private set { _X = value.X; _Y = value.Y; @@ -61,8 +79,8 @@ namespace VocaluxeLib.Menu } } - public SColorF Color; - public SColorF ColorProcessed; + private SColorF _Color; + private SColorF _ColorProcessed; public bool Selected; public bool Visible = true; @@ -77,19 +95,15 @@ namespace VocaluxeLib.Menu } } - public ELyricStyle LyricStyle - { - get { return _Style; } - set { _Style = value; } - } + public ELyricStyle LyricStyle { get; set; } public CLyric(int partyModeID) { _PartyModeID = partyModeID; _Theme = new SThemeLyrics(); _ThemeLoaded = false; - Color = new SColorF(); - ColorProcessed = new SColorF(); + _Color = new SColorF(); + _ColorProcessed = new SColorF(); _X = 0f; _Y = 0f; @@ -100,7 +114,7 @@ namespace VocaluxeLib.Menu _Notes = new List(); _Text = new CText(_PartyModeID); - _Style = ELyricStyle.Fill; + LyricStyle = ELyricStyle.Fill; } public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader, int skinIndex) @@ -114,31 +128,31 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref _MaxW); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref _H); - if (xmlReader.GetValue(item + "/Color", ref _Theme.ColorName, String.Empty)) - _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) + _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out _Color); else { - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/R", ref Color.R); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/G", ref Color.G); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/B", ref Color.B); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref Color.A); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/R", ref _Color.R); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/G", ref _Color.G); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/B", ref _Color.B); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref _Color.A); } - if (xmlReader.GetValue(item + "/SColor", ref _Theme.SelColorName, String.Empty)) - _ThemeLoaded &= CBase.Theme.GetColor(_Theme.SelColorName, skinIndex, out ColorProcessed); + if (xmlReader.GetValue(item + "/SColor", out _Theme.SelColorName, String.Empty)) + _ThemeLoaded &= CBase.Theme.GetColor(_Theme.SelColorName, skinIndex, out _ColorProcessed); else { - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SR", ref ColorProcessed.R); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SG", ref ColorProcessed.G); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SB", ref ColorProcessed.B); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SA", ref ColorProcessed.A); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SR", ref _ColorProcessed.R); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SG", ref _ColorProcessed.G); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SB", ref _ColorProcessed.B); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SA", ref _ColorProcessed.A); } if (_ThemeLoaded) { _Theme.Name = elementName; LoadTextures(); - _Text = new CText(_X, _Y, _Z, _H, _MaxW, EAlignment.Left, EStyle.Bold, "Normal", Color, String.Empty); + _Text = new CText(_X, _Y, _Z, _H, _MaxW, EAlignment.Left, EStyle.Bold, "Normal", _Color, String.Empty); } return _ThemeLoaded; } @@ -158,26 +172,26 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Lyric text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("Color", _Theme.ColorName); else { - writer.WriteElementString("R", Color.R.ToString("#0.00")); - writer.WriteElementString("G", Color.G.ToString("#0.00")); - writer.WriteElementString("B", Color.B.ToString("#0.00")); - writer.WriteElementString("A", Color.A.ToString("#0.00")); + writer.WriteElementString("R", _Color.R.ToString("#0.00")); + writer.WriteElementString("G", _Color.G.ToString("#0.00")); + writer.WriteElementString("B", _Color.B.ToString("#0.00")); + writer.WriteElementString("A", _Color.A.ToString("#0.00")); } writer.WriteComment(": Highlighted lyric color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorName.Length > 0) + if (_Theme.SelColorName != "") writer.WriteElementString("SColor", _Theme.SelColorName); else { - writer.WriteElementString("SR", ColorProcessed.R.ToString("#0.00")); - writer.WriteElementString("SG", ColorProcessed.G.ToString("#0.00")); - writer.WriteElementString("SB", ColorProcessed.B.ToString("#0.00")); - writer.WriteElementString("SA", ColorProcessed.A.ToString("#0.00")); + writer.WriteElementString("SR", _ColorProcessed.R.ToString("#0.00")); + writer.WriteElementString("SG", _ColorProcessed.G.ToString("#0.00")); + writer.WriteElementString("SB", _ColorProcessed.B.ToString("#0.00")); + writer.WriteElementString("SA", _ColorProcessed.A.ToString("#0.00")); } writer.WriteEndElement(); @@ -194,13 +208,7 @@ namespace VocaluxeLib.Menu _Width = 0f; foreach (CNote note in line.Notes) { - SNote n = new SNote(); - - n.Text = note.Text; - n.StartBeat = note.StartBeat; - n.EndBeat = note.EndBeat; - n.Duration = note.Duration; - n.Type = note.NoteType; + SNote n = new SNote {Text = note.Text, StartBeat = note.StartBeat, EndBeat = note.EndBeat, Duration = note.Duration, Type = note.NoteType}; _Text.Text = note.Text; _Text.Style = EStyle.Bold; @@ -229,7 +237,7 @@ namespace VocaluxeLib.Menu { if (Visible || CBase.Settings.GetGameState() == EGameState.EditTheme) { - switch (_Style) + switch (LyricStyle) { case ELyricStyle.Fill: _DrawFill(actualBeat); @@ -268,28 +276,28 @@ namespace VocaluxeLib.Menu { if (currentBeat <= note.EndBeat) { - _Text.Color = ColorProcessed; + _Text.Color = _ColorProcessed; float diff = note.EndBeat - note.StartBeat; - if (diff == 0) + if (Math.Abs(diff) < float.Epsilon) _Text.Draw(0f, 1f); else { _Text.Draw(0f, (currentBeat - note.StartBeat) / diff); - _Text.Color = Color; + _Text.Color = _Color; _Text.Draw((currentBeat - note.StartBeat) / diff, 1f); } } else { - _Text.Color = ColorProcessed; + _Text.Color = _ColorProcessed; _Text.Draw(); } } else { - _Text.Color = Color; + _Text.Color = _Color; _Text.Draw(); } @@ -325,7 +333,6 @@ namespace VocaluxeLib.Menu if (currentBeat >= _Notes[note].StartBeat) { - bool last = note == _Notes.Count - 1; int endbeat = _Notes[note].EndBeat; if (note < _Notes.Count - 1) endbeat = _Notes[note + 1].StartBeat - 1; @@ -339,10 +346,7 @@ namespace VocaluxeLib.Menu else { // already passed - if (note == lastNote) - _Text.Color = ColorProcessed; - else - _Text.Color = Color; + _Text.Color = note == lastNote ? _ColorProcessed : _Color; _Text.Draw(); } @@ -350,7 +354,7 @@ namespace VocaluxeLib.Menu else { // not passed - _Text.Color = Color; + _Text.Color = _Color; _Text.Draw(); } @@ -364,7 +368,7 @@ namespace VocaluxeLib.Menu _Text.X = zoomx; _Text.Text = _Notes[zoomNote].Text; - _Text.Color = ColorProcessed; + _Text.Color = _ColorProcessed; _Text.Style = EStyle.Bold; if (_Notes[zoomNote].Type == ENoteType.Freestyle) @@ -418,13 +422,13 @@ namespace VocaluxeLib.Menu if (currentBeat >= note.StartBeat) { - _Text.Color = ColorProcessed; + _Text.Color = _ColorProcessed; _Text.Draw(); } else { // not passed - _Text.Color = Color; + _Text.Color = _Color; _Text.Draw(); } @@ -445,7 +449,6 @@ namespace VocaluxeLib.Menu } int jumpNote = -1; - int endBeat = -1; float jumpx = 0f; for (int note = 0; note < _Notes.Count; note++) @@ -460,24 +463,15 @@ namespace VocaluxeLib.Menu if (currentBeat >= _Notes[note].StartBeat) { - bool last = note == _Notes.Count - 1; - int endbeat = _Notes[note].EndBeat; - if (note < _Notes.Count - 1) - endbeat = _Notes[note + 1].StartBeat - 1; - if (currentBeat <= _Notes[note].EndBeat) { jumpNote = note; - endBeat = endbeat; jumpx = _Text.X; } else { // already passed - if (note == lastNote) - _Text.Color = ColorProcessed; - else - _Text.Color = Color; + _Text.Color = note == lastNote ? _ColorProcessed : _Color; _Text.Draw(); } @@ -485,45 +479,40 @@ namespace VocaluxeLib.Menu else { // not passed - _Text.Color = Color; + _Text.Color = _Color; _Text.Draw(); } x += rect.Width; } - if (jumpNote > -1) + if (jumpNote < 0) + return; + if (_Notes[jumpNote].Duration == 0) + return; + + _Text.X = jumpx; + _Text.Text = _Notes[jumpNote].Text; + _Text.Color = _ColorProcessed; + _Text.Style = EStyle.Bold; + + if (_Notes[jumpNote].Type == ENoteType.Freestyle) + _Text.Style = EStyle.BoldItalic; + + int diff = _Notes[jumpNote].EndBeat - _Notes[jumpNote].StartBeat; + if (diff <= 0) + diff = 1; + + float p = 1f - (currentBeat - _Notes[jumpNote].StartBeat) / diff; + + if (Math.Abs(p) < float.Epsilon) + _Text.Draw(); + else { - if (_Notes[jumpNote].Duration == 0) - return; - - _Text.X = jumpx; - _Text.Text = _Notes[jumpNote].Text; - _Text.Color = ColorProcessed; - _Text.Style = EStyle.Bold; - - if (_Notes[jumpNote].Type == ENoteType.Freestyle) - _Text.Style = EStyle.BoldItalic; - - float diff = _Notes[jumpNote].EndBeat - _Notes[jumpNote].StartBeat; - if (diff <= 0f) - diff = 1f; - - float p = (currentBeat - _Notes[jumpNote].StartBeat) / diff; - if (p > 1f) - p = 1f; - - p = 1f - p; - - if (diff == 1) - _Text.Draw(); - else - { - float y = _Text.Y; - _Text.Y -= _Text.Height * 0.1f * p; - _Text.Draw(); - _Text.Y = y; - } + float y = _Text.Y; + _Text.Y -= _Text.Height * 0.1f * p; + _Text.Draw(); + _Text.Y = y; } } #endregion draw @@ -532,11 +521,11 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName.Length > 0) - Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); + if (_Theme.ColorName != "") + _Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SelColorName.Length > 0) - ColorProcessed = CBase.Theme.GetColor(_Theme.SelColorName, _PartyModeID); + if (_Theme.SelColorName != "") + _ColorProcessed = CBase.Theme.GetColor(_Theme.SelColorName, _PartyModeID); } public void ReloadTextures() diff --git a/VocaluxeLib/Menu/CMenu.cs b/VocaluxeLib/Menu/CMenu.cs index 8f00d04a..e17e6aec 100644 --- a/VocaluxeLib/Menu/CMenu.cs +++ b/VocaluxeLib/Menu/CMenu.cs @@ -1,4 +1,23 @@ -using System; +#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.IO; @@ -23,35 +42,18 @@ namespace VocaluxeLib.Menu private string _ThemePath = String.Empty; protected int _PartyModeID = -1; - private COrderedDictionaryLite _Backgrounds; - private COrderedDictionaryLite _Buttons; - private COrderedDictionaryLite _Texts; - private COrderedDictionaryLite _Statics; - private COrderedDictionaryLite _SelectSlides; - private COrderedDictionaryLite _SongMenus; - private COrderedDictionaryLite _Lyrics; - private COrderedDictionaryLite _SingNotes; - private COrderedDictionaryLite _NameSelections; - private COrderedDictionaryLite _Equalizers; - private COrderedDictionaryLite _Playlists; - private COrderedDictionaryLite _ParticleEffects; - private COrderedDictionaryLite _ScreenSettings; - private int _PrevMouseX; private int _PrevMouseY; - protected int _MouseDX; - protected int _MouseDY; + private int _MouseDX; + private int _MouseDY; protected bool _Active; protected abstract int _ScreenVersion { get; } - private string _ThemeName; - public string ThemeName - { - get { return _ThemeName; } - } + public string ThemeName { get; private set; } + // ReSharper disable MemberCanBePrivate.Global protected string[] _ThemeBackgrounds; protected string[] _ThemeStatics; protected string[] _ThemeTexts; @@ -66,22 +68,32 @@ namespace VocaluxeLib.Menu protected string[] _ThemeParticleEffects; protected string[] _ThemeScreenSettings; + protected COrderedDictionaryLite _Buttons { get; private set; } + protected COrderedDictionaryLite _Texts { get; private set; } + protected COrderedDictionaryLite _Backgrounds { get; private set; } + protected COrderedDictionaryLite _Statics { get; private set; } + protected COrderedDictionaryLite _SelectSlides { get; private set; } + protected COrderedDictionaryLite _SongMenus { get; private set; } + protected COrderedDictionaryLite _Lyrics { get; private set; } + protected COrderedDictionaryLite _SingNotes { get; private set; } + protected COrderedDictionaryLite _NameSelections { get; private set; } + protected COrderedDictionaryLite _Equalizers { get; private set; } + protected COrderedDictionaryLite _Playlists { get; private set; } + protected COrderedDictionaryLite _ParticleEffects { get; private set; } + protected COrderedDictionaryLite _ScreenSettings { get; private set; } + // ReSharper restore MemberCanBePrivate.Global + protected SRectF _ScreenArea; public SRectF ScreenArea { get { return _ScreenArea; } } - public int ThemeScreenVersion - { - get { return _ScreenVersion; } - } - public virtual void Init() { - _ThemeName = GetType().Name; - if (_ThemeName[0] == 'C' && Char.IsUpper(_ThemeName[1])) - _ThemeName = _ThemeName.Remove(0, 1); + ThemeName = GetType().Name; + if (ThemeName[0] == 'C' && Char.IsUpper(ThemeName[1])) + ThemeName = ThemeName.Remove(0, 1); _Interactions = new List(); _Selection = 0; @@ -130,9 +142,9 @@ namespace VocaluxeLib.Menu } #region ThemeHandler - protected delegate void AddElementHandler(T element, String key); + private delegate void AddElementHandler(T element, String key); - private void _LoadThemeElement(string[] elements, AddElementHandler addElementHandler, CXMLReader xmlReader, int skinIndex) where T : IMenuElement + private void _LoadThemeElement(IEnumerable elements, AddElementHandler addElementHandler, CXMLReader xmlReader, int skinIndex) where T : IMenuElement { if (elements != null) { @@ -155,8 +167,7 @@ namespace VocaluxeLib.Menu if (xmlReader == null) return; - bool versionCheck = false; - versionCheck = _CheckVersion(_ScreenVersion, xmlReader); + bool versionCheck = _CheckVersion(_ScreenVersion, xmlReader); int skinIndex = CBase.Theme.GetSkinIndex(_PartyModeID); @@ -165,31 +176,28 @@ namespace VocaluxeLib.Menu _ThemePath = xmlPath; _LoadThemeBasics(xmlReader, skinIndex); - _LoadThemeElement(_ThemeBackgrounds, AddBackground, xmlReader, skinIndex); - _LoadThemeElement(_ThemeStatics, AddStatic, xmlReader, skinIndex); - _LoadThemeElement(_ThemeTexts, AddText, xmlReader, skinIndex); - _LoadThemeElement(_ThemeButtons, AddButton, xmlReader, skinIndex); - _LoadThemeElement(_ThemeSelectSlides, AddSelectSlide, xmlReader, skinIndex); - _LoadThemeElement(_ThemeSongMenus, AddSongMenu, xmlReader, skinIndex); - _LoadThemeElement(_ThemeLyrics, AddLyric, xmlReader, skinIndex); - _LoadThemeElement(_ThemeSingNotes, AddSingNote, xmlReader, skinIndex); - _LoadThemeElement(_ThemeNameSelections, AddNameSelection, xmlReader, skinIndex); - _LoadThemeElement(_ThemeEqualizers, AddEqualizer, xmlReader, skinIndex); - _LoadThemeElement(_ThemePlaylists, AddPlaylist, xmlReader, skinIndex); - _LoadThemeElement(_ThemeParticleEffects, AddParticleEffect, xmlReader, skinIndex); - _LoadThemeElement(_ThemeScreenSettings, AddScreenSetting, xmlReader, skinIndex); + _LoadThemeElement(_ThemeBackgrounds, _AddBackground, xmlReader, skinIndex); + _LoadThemeElement(_ThemeStatics, _AddStatic, xmlReader, skinIndex); + _LoadThemeElement(_ThemeTexts, _AddText, xmlReader, skinIndex); + _LoadThemeElement(_ThemeButtons, _AddButton, xmlReader, skinIndex); + _LoadThemeElement(_ThemeSelectSlides, _AddSelectSlide, xmlReader, skinIndex); + _LoadThemeElement(_ThemeSongMenus, _AddSongMenu, xmlReader, skinIndex); + _LoadThemeElement(_ThemeLyrics, _AddLyric, xmlReader, skinIndex); + _LoadThemeElement(_ThemeSingNotes, _AddSingNote, xmlReader, skinIndex); + _LoadThemeElement(_ThemeNameSelections, _AddNameSelection, xmlReader, skinIndex); + _LoadThemeElement(_ThemeEqualizers, _AddEqualizer, xmlReader, skinIndex); + _LoadThemeElement(_ThemePlaylists, _AddPlaylist, xmlReader, skinIndex); + _LoadThemeElement(_ThemeParticleEffects, _AddParticleEffect, xmlReader, skinIndex); + _LoadThemeElement(_ThemeScreenSettings, _AddScreenSetting, xmlReader, skinIndex); } } public virtual void SaveTheme() { - if (_ThemePath.Length == 0) + if (_ThemePath == "") return; - XmlWriterSettings settings = new XmlWriterSettings(); - settings.Indent = true; - settings.Encoding = Encoding.UTF8; - settings.ConformanceLevel = ConformanceLevel.Document; + XmlWriterSettings settings = new XmlWriterSettings {Indent = true, Encoding = Encoding.UTF8, ConformanceLevel = ConformanceLevel.Document}; string file = Path.Combine(_ThemePath, ThemeName + ".xml"); using (XmlWriter writer = XmlWriter.Create(file, settings)) @@ -349,7 +357,7 @@ namespace VocaluxeLib.Menu public virtual void ReloadTheme(string xmlPath) { - if (_ThemePath.Length == 0) + if (_ThemePath == "") return; UnloadTextures(); @@ -428,12 +436,14 @@ namespace VocaluxeLib.Menu #region ElementHandler #region Create Elements + // ReSharper disable UnusedMember.Global + // ReSharper disable MemberCanBeProtected.Global public CButton GetNewButton() { return new CButton(_PartyModeID); } - public CButton GetNewButton(CButton button) + public static CButton GetNewButton(CButton button) { return new CButton(button); } @@ -443,12 +453,12 @@ namespace VocaluxeLib.Menu return new CText(_PartyModeID); } - public CText GetNewText(CText text) + public static CText GetNewText(CText text) { return new CText(text); } - public CText GetNewText(float x, float y, float z, float h, float mw, EAlignment align, EStyle style, string font, SColorF col, string text) + public static CText GetNewText(float x, float y, float z, float h, float mw, EAlignment align, EStyle style, string font, SColorF col, string text) { return new CText(x, y, z, h, mw, align, style, font, col, text); } @@ -463,7 +473,7 @@ namespace VocaluxeLib.Menu return new CStatic(_PartyModeID); } - public CStatic GetNewStatic(CStatic oldStatic) + public static CStatic GetNewStatic(CStatic oldStatic) { return new CStatic(oldStatic); } @@ -478,7 +488,7 @@ namespace VocaluxeLib.Menu return new CSelectSlide(_PartyModeID); } - public CSelectSlide GetNewSelectSlide(CSelectSlide slide) + public static CSelectSlide GetNewSelectSlide(CSelectSlide slide) { return new CSelectSlide(slide); } @@ -517,75 +527,11 @@ namespace VocaluxeLib.Menu { return new CParticleEffect(_PartyModeID, maxNumber, color, area, texture, size, type); } + + // ReSharper restore MemberCanBeProtected.Global + // ReSharper restore UnusedMember.Global #endregion Create Elements - #region Get Elements - public COrderedDictionaryLite Buttons - { - get { return _Buttons; } - } - - public COrderedDictionaryLite Texts - { - get { return _Texts; } - } - - public COrderedDictionaryLite Backgrounds - { - get { return _Backgrounds; } - } - - public COrderedDictionaryLite Statics - { - get { return _Statics; } - } - - public COrderedDictionaryLite SelectSlides - { - get { return _SelectSlides; } - } - - public COrderedDictionaryLite SongMenus - { - get { return _SongMenus; } - } - - public COrderedDictionaryLite Lyrics - { - get { return _Lyrics; } - } - - public COrderedDictionaryLite SingNotes - { - get { return _SingNotes; } - } - - public COrderedDictionaryLite NameSelections - { - get { return _NameSelections; } - } - - public COrderedDictionaryLite Equalizers - { - get { return _Equalizers; } - } - - public COrderedDictionaryLite Playlists - { - get { return _Playlists; } - } - - public COrderedDictionaryLite ParticleEffects - { - get { return _ParticleEffects; } - } - - public COrderedDictionaryLite ScreenSettings - { - get { return _ScreenSettings; } - } - #endregion Get Arrays - #endregion ElementHandler #region MenuHandler @@ -807,18 +753,18 @@ namespace VocaluxeLib.Menu #region Drawing public virtual bool Draw() { - DrawBG(); - DrawFG(); + _DrawBG(); + _DrawFG(); return true; } - public void DrawBG() + protected void _DrawBG() { foreach (CBackground bg in _Backgrounds) bg.Draw(); } - public void DrawFG() + protected void _DrawFG() { if (_Interactions.Count <= 0) return; @@ -827,29 +773,20 @@ namespace VocaluxeLib.Menu for (int i = 0; i < _Interactions.Count; i++) { - if (_IsVisible(i) && ( - _Interactions[i].Type == EType.Button || - _Interactions[i].Type == EType.SelectSlide || - _Interactions[i].Type == EType.Static || - _Interactions[i].Type == EType.NameSelection || - _Interactions[i].Type == EType.Text || - _Interactions[i].Type == EType.SongMenu || - _Interactions[i].Type == EType.Equalizer || - _Interactions[i].Type == EType.Playlist || - _Interactions[i].Type == EType.ParticleEffect)) - { - SZSort zs = new SZSort(); - zs.ID = i; - zs.Z = _GetZValue(i); - items.Add(zs); - } + if (!_IsVisible(i) || + (_Interactions[i].Type != EType.Button && _Interactions[i].Type != EType.SelectSlide && _Interactions[i].Type != EType.Static && + _Interactions[i].Type != EType.NameSelection && _Interactions[i].Type != EType.Text && _Interactions[i].Type != EType.SongMenu && + _Interactions[i].Type != EType.Equalizer && _Interactions[i].Type != EType.Playlist && _Interactions[i].Type != EType.ParticleEffect)) + continue; + SZSort zs = new SZSort {ID = i, Z = _GetZValue(i)}; + items.Add(zs); } if (items.Count <= 0) return; - items.Sort(delegate(SZSort s1, SZSort s2) { return s2.Z.CompareTo(s1.Z); }); + items.Sort((s1, s2) => s2.Z.CompareTo(s1.Z)); for (int i = 0; i < items.Count; i++) _DrawInteraction(items[i].ID); @@ -857,139 +794,77 @@ namespace VocaluxeLib.Menu #endregion Drawing #region Elements - public void AddBackground(CBackground bg) - { - AddBackground(bg, null); - } - - public void AddButton(CButton button) - { - AddButton(button, null); - } - - public void AddSelectSlide(CSelectSlide slide) - { - AddSelectSlide(slide, null); - } - - public void AddStatic(CStatic stat) - { - AddStatic(stat, null); - } - - public void AddText(CText text) - { - AddText(text, null); - } - - public void AddSongMenu(CSongMenu songmenu) - { - AddSongMenu(songmenu, null); - } - - public void AddLyric(CLyric lyric) - { - AddLyric(lyric, null); - } - - public void AddSingNote(CSingNotes sn) - { - AddSingNote(sn, null); - } - - public void AddNameSelection(CNameSelection ns) - { - AddNameSelection(ns, null); - } - - public void AddEqualizer(CEqualizer eq) - { - AddEqualizer(eq, null); - } - - public void AddPlaylist(CPlaylist pls) - { - AddPlaylist(pls, null); - } - - public void AddParticleEffect(CParticleEffect pe) - { - AddParticleEffect(pe, null); - } - - public void AddScreenSetting(CScreenSetting se) - { - AddScreenSetting(se, null); - } - - public void AddBackground(CBackground bg, String key) + // ReSharper disable MemberCanBePrivate.Global + protected void _AddBackground(CBackground bg, String key = null) { _AddInteraction(_Backgrounds.Add(bg, key), EType.Background); } - public void AddButton(CButton button, String key) + protected void _AddButton(CButton button, String key = null) { _AddInteraction(_Buttons.Add(button, key), EType.Button); } - public void AddSelectSlide(CSelectSlide slide, String key) + protected void _AddSelectSlide(CSelectSlide slide, String key = null) { _AddInteraction(_SelectSlides.Add(slide, key), EType.SelectSlide); } - public void AddStatic(CStatic stat, String key) + protected void _AddStatic(CStatic stat, String key = null) { _AddInteraction(_Statics.Add(stat, key), EType.Static); } - public void AddText(CText text, String key) + protected void _AddText(CText text, String key = null) { _AddInteraction(_Texts.Add(text, key), EType.Text); } - public void AddSongMenu(CSongMenu songmenu, String key) + protected void _AddSongMenu(CSongMenu songmenu, String key = null) { _AddInteraction(_SongMenus.Add(songmenu, key), EType.SongMenu); } - public void AddLyric(CLyric lyric, String key) + protected void _AddLyric(CLyric lyric, String key = null) { _AddInteraction(_Lyrics.Add(lyric, key), EType.Lyric); } - public void AddSingNote(CSingNotes sn, String key) + protected void _AddSingNote(CSingNotes sn, String key = null) { _AddInteraction(_SingNotes.Add(sn, key), EType.SingNote); } - public void AddNameSelection(CNameSelection ns, String key) + protected void _AddNameSelection(CNameSelection ns, String key = null) { _AddInteraction(_NameSelections.Add(ns, key), EType.NameSelection); } - public void AddEqualizer(CEqualizer eq, String key) + protected void _AddEqualizer(CEqualizer eq, String key = null) { _AddInteraction(_Equalizers.Add(eq, key), EType.Equalizer); } - public void AddPlaylist(CPlaylist pls, String key) + protected void _AddPlaylist(CPlaylist pls, String key = null) { _AddInteraction(_Playlists.Add(pls, key), EType.Playlist); } - public void AddParticleEffect(CParticleEffect pe, String key) + protected void _AddParticleEffect(CParticleEffect pe, String key = null) { _AddInteraction(_ParticleEffects.Add(pe, key), EType.ParticleEffect); } - public void AddScreenSetting(CScreenSetting se, String key) + protected void _AddScreenSetting(CScreenSetting se, String key = null) { _ScreenSettings.Add(se, key); } + + // ReSharper restore MemberCanBePrivate.Global #endregion Elements #region InteractionHandling - public void CheckInteraction() + protected void _CheckInteraction() { if (!_IsEnabled(_Selection) || !_IsVisible(_Selection)) PrevInteraction(); @@ -1031,26 +906,23 @@ namespace VocaluxeLib.Menu return false; } - public bool SetInteractionToButton(CButton button) + protected void _SetInteractionToButton(CButton button) { for (int i = 0; i < _Interactions.Count; i++) { - if (_Interactions[i].Type == EType.Button) - { - if (_Buttons[_Interactions[i].Num] == button) - { - _UnsetSelected(); - _UnsetHighlighted(_Selection); - _Selection = i; - _SetSelected(); - return true; - } - } + if (_Interactions[i].Type != EType.Button) + continue; + if (_Buttons[_Interactions[i].Num] != button) + continue; + _UnsetSelected(); + _UnsetHighlighted(_Selection); + _Selection = i; + _SetSelected(); + return; } - return false; } - public bool SetInteractionToSelectSlide(CSelectSlide slide) + protected void _SetInteractionToSelectSlide(CSelectSlide slide) { for (int i = 0; i < _Interactions.Count; i++) { @@ -1062,11 +934,10 @@ namespace VocaluxeLib.Menu _UnsetHighlighted(_Selection); _Selection = i; _SetSelected(); - return true; + return; } } } - return false; } public void ProcessMouseClick(int x, int y) @@ -1083,7 +954,7 @@ namespace VocaluxeLib.Menu public void ProcessMouseMove(int x, int y) { - SelectByMouse(x, y); + _SelectByMouse(x, y); if (_Selection >= _Interactions.Count || _Selection < 0) return; @@ -1095,41 +966,35 @@ namespace VocaluxeLib.Menu } } - public void SelectByMouse(int x, int y) + private void _SelectByMouse(int x, int y) { float z = CBase.Settings.GetZFar(); for (int i = 0; i < _Interactions.Count; i++) { - if ((CBase.Settings.GetGameState() == EGameState.EditTheme) || (!_Interactions[i].ThemeEditorOnly && _IsVisible(i) && _IsEnabled(i))) - { - if (_IsMouseOver(x, y, _Interactions[i])) - { - if (_GetZValue(_Interactions[i]) <= z) - { - z = _GetZValue(_Interactions[i]); - _UnsetSelected(); - _Selection = i; - _SetSelected(); - } - } - } + if ((CBase.Settings.GetGameState() != EGameState.EditTheme) && (_Interactions[i].ThemeEditorOnly || !_IsVisible(i) || !_IsEnabled(i))) + continue; + if (!_IsMouseOver(x, y, _Interactions[i])) + continue; + if (_GetZValue(_Interactions[i]) > z) + continue; + z = _GetZValue(_Interactions[i]); + _UnsetSelected(); + _Selection = i; + _SetSelected(); } } - public bool IsMouseOver(SMouseEvent mouseEvent) + protected bool _IsMouseOver(SMouseEvent mouseEvent) { - return IsMouseOver(mouseEvent.X, mouseEvent.Y); + return _IsMouseOver(mouseEvent.X, mouseEvent.Y); } - public bool IsMouseOver(int x, int y) + private bool _IsMouseOver(int x, int y) { if (_Selection >= _Interactions.Count || _Selection < 0) return false; - if (_Interactions.Count > 0) - return _IsMouseOver(x, y, _Interactions[_Selection]); - else - return false; + return _Interactions.Count > 0 && _IsMouseOver(x, y, _Interactions[_Selection]); } private bool _IsMouseOver(int x, int y, CInteraction interact) @@ -1295,7 +1160,6 @@ namespace VocaluxeLib.Menu int element = _Selection; int stage = int.MaxValue; - float distance = float.MaxValue; int direction = -1; int mute = -1; @@ -1321,7 +1185,6 @@ namespace VocaluxeLib.Menu { stage = stages[i]; element = elements[i]; - distance = distances[i]; direction = i; } } @@ -1450,10 +1313,7 @@ namespace VocaluxeLib.Menu inDirection = true; break; } - if (!inDirection) - return float.MaxValue; - else - return distance; + return !inDirection ? float.MaxValue : distance; } private float _GetDistance180(SKeyEvent key, SRectF actualRect, SRectF targetRect) @@ -1486,10 +1346,7 @@ namespace VocaluxeLib.Menu inDirection = true; break; } - if (!inDirection) - return float.MaxValue; - else - return distance; + return !inDirection ? float.MaxValue : distance; } /// @@ -1660,6 +1517,7 @@ namespace VocaluxeLib.Menu } } + // ReSharper disable UnusedMember.Local private void _ToggleHighlighted() { if (_Selection >= _Interactions.Count || _Selection < 0) @@ -1674,12 +1532,11 @@ namespace VocaluxeLib.Menu if (_Selection >= _Interactions.Count || _Selection < 0) return false; - if (_Interactions[_Selection].Type == EType.SelectSlide) - return _SelectSlides[_Interactions[_Selection].Num].Highlighted; - - return false; + return _Interactions[_Selection].Type == EType.SelectSlide && _SelectSlides[_Interactions[_Selection].Num].Highlighted; } + // ReSharper restore UnusedMember.Local + private bool _IsVisible(int interaction) { if (_Selection >= _Interactions.Count || _Selection < 0) @@ -1969,30 +1826,25 @@ namespace VocaluxeLib.Menu if (actualVersion == reqVersion) return true; + string msg = "Can't load screen file of screen \"" + ThemeName + "\", "; + if (actualVersion < reqVersion) + msg += "the file ist outdated! "; else - { - string msg = "Can't load screen file of screen \"" + ThemeName + "\", "; - if (actualVersion < reqVersion) - msg += "the file ist outdated! "; - else - msg += "the file is for newer program versions! "; + msg += "the file is for newer program versions! "; - msg += "Current screen version is " + reqVersion.ToString(); - CBase.Log.LogError(msg); - } + msg += "Current screen version is " + reqVersion; + CBase.Log.LogError(msg); return false; } private void _LoadThemeBasics(CXMLReader xmlReader, int skinIndex) { - string value = String.Empty; - // Backgrounds CBackground background = new CBackground(_PartyModeID); int i = 1; - while (background.LoadTheme("//root/" + ThemeName, "Background" + i.ToString(), xmlReader, skinIndex)) + while (background.LoadTheme("//root/" + ThemeName, "Background" + i, xmlReader, skinIndex)) { - AddBackground(background); + _AddBackground(background); background = new CBackground(_PartyModeID); i++; } @@ -2000,9 +1852,9 @@ namespace VocaluxeLib.Menu // Statics CStatic stat = new CStatic(_PartyModeID); i = 1; - while (stat.LoadTheme("//root/" + ThemeName, "Static" + i.ToString(), xmlReader, skinIndex)) + while (stat.LoadTheme("//root/" + ThemeName, "Static" + i, xmlReader, skinIndex)) { - AddStatic(stat); + _AddStatic(stat); stat = new CStatic(_PartyModeID); i++; } @@ -2010,9 +1862,9 @@ namespace VocaluxeLib.Menu // Texts CText text = new CText(_PartyModeID); i = 1; - while (text.LoadTheme("//root/" + ThemeName, "Text" + i.ToString(), xmlReader, skinIndex)) + while (text.LoadTheme("//root/" + ThemeName, "Text" + i, xmlReader, skinIndex)) { - AddText(text); + _AddText(text); text = new CText(_PartyModeID); i++; } @@ -2020,9 +1872,9 @@ namespace VocaluxeLib.Menu // ParticleEffects CParticleEffect partef = new CParticleEffect(_PartyModeID); i = 1; - while (partef.LoadTheme("//root/" + ThemeName, "ParticleEffect" + i.ToString(), xmlReader, skinIndex)) + while (partef.LoadTheme("//root/" + ThemeName, "ParticleEffect" + i, xmlReader, skinIndex)) { - AddParticleEffect(partef); + _AddParticleEffect(partef); partef = new CParticleEffect(_PartyModeID); i++; } diff --git a/VocaluxeLib/Menu/CMenuParty.cs b/VocaluxeLib/Menu/CMenuParty.cs index 5a2e491f..965f6175 100644 --- a/VocaluxeLib/Menu/CMenuParty.cs +++ b/VocaluxeLib/Menu/CMenuParty.cs @@ -1,4 +1,23 @@ -using System; +#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 VocaluxeLib.PartyModes; namespace VocaluxeLib.Menu @@ -7,7 +26,7 @@ namespace VocaluxeLib.Menu { protected IPartyMode _PartyMode; - public CMenuParty() + protected CMenuParty() { _PartyMode = new CPartyModeNone(); } @@ -17,11 +36,6 @@ namespace VocaluxeLib.Menu _PartyModeID = partyModeID; } - public int GetPartyModeID() - { - return _PartyModeID; - } - public void AssingPartyMode(IPartyMode partyMode) { _PartyMode = partyMode; diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index a55d8994..aeea2e33 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -1,4 +1,23 @@ -using System; +#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.Windows.Forms; using System.Xml; @@ -27,8 +46,6 @@ namespace VocaluxeLib.Menu public readonly CStatic Avatar; public readonly CText Name; - public CTile() {} - public CTile(CStatic av, CText tex, int pl) { Avatar = av; @@ -46,7 +63,7 @@ namespace VocaluxeLib.Menu return _Theme.Name; } - public bool Selected = false; + public bool Selected; public bool Visible = true; public SRectF Rect; @@ -66,7 +83,7 @@ namespace VocaluxeLib.Menu private int _TileW; private int _TileH; - public int Offset = 0; + public int Offset; private int _ActualSelection = -1; public int Selection = -1; @@ -89,10 +106,12 @@ namespace VocaluxeLib.Menu { _PrepareTiles(); - _PlayerSelector = new CStatic(_PartyModeID); - _PlayerSelector.Texture = _TextureTileSelected; - _PlayerSelector.Rect = new SRectF(0, 0, _TileW + 6, _TileH + 6, Rect.Z - 0.5f); - _PlayerSelector.Visible = false; + _PlayerSelector = new CStatic(_PartyModeID) + { + Texture = _TextureTileSelected, + Rect = new SRectF(0, 0, _TileW + 6, _TileH + 6, Rect.Z - 0.5f), + Visible = false + }; _UpdateVisibleProfiles(); @@ -110,9 +129,9 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref Rect.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref Rect.H); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinEmptyTile", ref _Theme.TextureEmptyTileName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinEmptyTile", out _Theme.TextureEmptyTileName, String.Empty); - if (xmlReader.GetValue(item + "/ColorEmptyTile", ref _Theme.ColorEmptyTileName, String.Empty)) + if (xmlReader.GetValue(item + "/ColorEmptyTile", out _Theme.ColorEmptyTileName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorEmptyTileName, skinIndex, out ColorEmptyTile); else { @@ -122,7 +141,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref ColorEmptyTile.A); } - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinTileSelected", ref _Theme.TextureTileSelectedName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinTileSelected", out _Theme.TextureTileSelectedName, String.Empty); _ThemeLoaded &= xmlReader.TryGetIntValue(item + "/Tiles/W", ref _TileW); _ThemeLoaded &= xmlReader.TryGetIntValue(item + "/Tiles/H", ref _TileH); @@ -132,9 +151,9 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/SpaceH", ref _SpaceH); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/Name/Space", ref _Theme.NameSpace); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/Name/H", ref _Theme.NameHeight); - _ThemeLoaded &= xmlReader.GetValue(item + "/Tiles/Name/Font", ref _Theme.NameFont, "Normal"); + _ThemeLoaded &= xmlReader.GetValue(item + "/Tiles/Name/Font", out _Theme.NameFont, "Normal"); _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Tiles/Name/Style", ref _Theme.NameStyle); - if (xmlReader.GetValue(item + "/Tiles/Name/Color", ref _Theme.NameColorName, String.Empty)) + if (xmlReader.GetValue(item + "/Tiles/Name/Color", out _Theme.NameColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.NameColorName, skinIndex, out _Theme.NameColor); else { @@ -173,7 +192,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Static color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorEmptyTileName.Length > 0) + if (_Theme.ColorEmptyTileName != "") writer.WriteElementString("ColorEmptyTile", _Theme.ColorEmptyTileName); else { @@ -204,7 +223,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Text font name"); writer.WriteElementString("Font", _Theme.NameFont); writer.WriteComment(": Text color from ColorScheme (high priority)"); - if (_Theme.NameColorName.Length > 0) + if (_Theme.NameColorName != "") writer.WriteElementString("Color", _Theme.NameColorName); else { @@ -227,16 +246,6 @@ namespace VocaluxeLib.Menu } public void Draw() - { - Draw(false); - } - - public void ForceDraw() - { - Draw(true); - } - - public void Draw(bool forceDraw) { int i = 0; foreach (CTile tile in _Tiles) @@ -438,10 +447,10 @@ namespace VocaluxeLib.Menu _TextureEmptyTile = CBase.Theme.GetSkinTexture(_Theme.TextureEmptyTileName, _PartyModeID); _TextureTileSelected = CBase.Theme.GetSkinTexture(_Theme.TextureTileSelectedName, _PartyModeID); - if (_Theme.ColorEmptyTileName.Length > 0) + if (_Theme.ColorEmptyTileName != "") ColorEmptyTile = CBase.Theme.GetColor(_Theme.ColorEmptyTileName, _PartyModeID); - if (_Theme.NameColorName.Length > 0) + if (_Theme.NameColorName != "") _Theme.NameColor = CBase.Theme.GetColor(_Theme.NameColorName, _PartyModeID); } @@ -474,15 +483,16 @@ namespace VocaluxeLib.Menu _VisibleProfiles.Clear(); for (int i = 0; i < CBase.Profiles.GetProfiles().Length; i++) { - bool visible = false; - //Show profile only if active - if (CBase.Profiles.GetProfiles()[i].Active == EOffOn.TR_CONFIG_ON) - visible = true; - for (int p = 0; p < CBase.Game.GetNumPlayer(); p++) + bool visible = CBase.Profiles.GetProfiles()[i].Active == EOffOn.TR_CONFIG_ON; + if (visible) { - //Don't show profile if is selected, but if selected and guest - if (CBase.Game.GetPlayer()[p].ProfileID == i && CBase.Profiles.GetProfiles()[i].GuestProfile == EOffOn.TR_CONFIG_OFF) - visible = false; + //Show profile only if active + for (int p = 0; p < CBase.Game.GetNumPlayer(); p++) + { + //Don't show profile if is selected, but if selected and guest + if (CBase.Game.GetPlayers()[p].ProfileID == i && CBase.Profiles.GetProfiles()[i].GuestProfile == EOffOn.TR_CONFIG_OFF) + visible = false; + } } if (visible) _VisibleProfiles.Add(i); diff --git a/VocaluxeLib/Menu/CObjectInteractions.cs b/VocaluxeLib/Menu/CObjectInteractions.cs index a5d9e722..1aafbb94 100644 --- a/VocaluxeLib/Menu/CObjectInteractions.cs +++ b/VocaluxeLib/Menu/CObjectInteractions.cs @@ -1,4 +1,23 @@ -using System; +#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.Windows.Forms; @@ -301,9 +320,7 @@ namespace VocaluxeLib.Menu _Interactions[i].Type == EType.SongMenu || _Interactions[i].Type == EType.Equalizer)) { - SZSort zs = new SZSort(); - zs.ID = i; - zs.Z = _GetZValue(i); + SZSort zs = new SZSort {ID = i, Z = _GetZValue(i)}; items.Add(zs); } } @@ -312,7 +329,7 @@ namespace VocaluxeLib.Menu return; - items.Sort(delegate(SZSort s1, SZSort s2) { return s2.Z.CompareTo(s1.Z); }); + items.Sort((s1, s2) => s2.Z.CompareTo(s1.Z)); for (int i = 0; i < items.Count; i++) _DrawInteraction(items[i].ID); @@ -481,10 +498,7 @@ namespace VocaluxeLib.Menu if (_Selection >= _Interactions.Count || _Selection < 0) return false; - if (_Interactions.Count > 0) - return _IsMouseOver(x, y, _Interactions[_Selection]); - else - return false; + return _Interactions.Count > 0 && _IsMouseOver(x, y, _Interactions[_Selection]); } private bool _IsMouseOver(int x, int y, CInteraction interact) @@ -617,7 +631,6 @@ namespace VocaluxeLib.Menu int element = _Selection; int stage = int.MaxValue; - float distance = float.MaxValue; int direction = -1; int mute = -1; @@ -643,7 +656,6 @@ namespace VocaluxeLib.Menu { stage = stages[i]; element = elements[i]; - distance = distances[i]; direction = i; } } @@ -772,10 +784,7 @@ namespace VocaluxeLib.Menu inDirection = true; break; } - if (!inDirection) - return float.MaxValue; - else - return distance; + return !inDirection ? float.MaxValue : distance; } private float _GetDistance180(SKeyEvent key, SRectF actualRect, SRectF targetRect) @@ -808,10 +817,7 @@ namespace VocaluxeLib.Menu inDirection = true; break; } - if (!inDirection) - return float.MaxValue; - else - return distance; + return !inDirection ? float.MaxValue : distance; } /// @@ -1020,7 +1026,7 @@ namespace VocaluxeLib.Menu private void _DrawInteraction(int interaction) { - bool sel = false; + bool sel; switch (_Interactions[interaction].Type) { case EType.Static: diff --git a/VocaluxeLib/Menu/COrderedDictionaryLite.cs b/VocaluxeLib/Menu/COrderedDictionaryLite.cs index 025b76c9..76ef3a88 100644 --- a/VocaluxeLib/Menu/COrderedDictionaryLite.cs +++ b/VocaluxeLib/Menu/COrderedDictionaryLite.cs @@ -1,4 +1,23 @@ -using System; +#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; using System.Collections.Generic; @@ -17,13 +36,6 @@ namespace VocaluxeLib.Menu _Parent = parent; } - public COrderedDictionaryLite(COrderedDictionaryLite dict) - { - _Items = new List(dict._Items); - _HtIndex = new Dictionary(dict._HtIndex); - _Parent = dict._Parent; - } - public T this[int index] { get { return _Items[index]; } diff --git a/VocaluxeLib/Menu/CParticle.cs b/VocaluxeLib/Menu/CParticle.cs index 31ba6d42..d33001f0 100644 --- a/VocaluxeLib/Menu/CParticle.cs +++ b/VocaluxeLib/Menu/CParticle.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.Xml; @@ -86,7 +105,7 @@ namespace VocaluxeLib.Menu public bool IsAlive { - get { return _Age < _MaxAge || _MaxAge == 0f; } + get { return _Age < _MaxAge || Math.Abs(_MaxAge) < float.Epsilon; } } #endregion public vars @@ -199,7 +218,7 @@ namespace VocaluxeLib.Menu if (Math.Round(Y) < maxy) { float vdx = 0f; - if (_Vx != 0) + if (Math.Abs(_Vx) > float.Epsilon) vdx = (float)Math.Sin(currentTime / _Vx * Math.PI); X += _Vx * timediff * (0.5f + vdx); @@ -223,7 +242,7 @@ namespace VocaluxeLib.Menu // update size - if (_Vsize != 0f) + if (Math.Abs(_Vsize) > float.Epsilon) { float size = _Size; switch (_Type) @@ -256,7 +275,7 @@ namespace VocaluxeLib.Menu } // update rotation - if (_Vr != 0f) + if (Math.Abs(_Vr) > 0.01) { float r = currentTime * _Vr / 60f; _Angle = _Rotation + 360f * (r - (float)Math.Floor(r)); @@ -278,7 +297,7 @@ namespace VocaluxeLib.Menu public void Draw() { - if (_TextureName.Length > 0) + if (_TextureName != "") CBase.Drawing.DrawTexture(CBase.Theme.GetSkinTexture(_TextureName, _PartyModeID), _Rect, new SColorF(_Color.R, _Color.G, _Color.B, _Color.A * Alpha2 * _Alpha)); else CBase.Drawing.DrawTexture(_Texture, _Rect, new SColorF(_Color.R, _Color.G, _Color.B, _Color.A * Alpha2 * _Alpha)); @@ -332,8 +351,8 @@ namespace VocaluxeLib.Menu _PartyModeID = partyModeID; _Theme = new SThemeParticleEffect(); _Stars = new List(); - this.Rect = rect; - this.Color = color; + Rect = rect; + Color = color; _Theme.TextureName = textureName; Texture = new STexture(-1); _MaxNumber = maxNumber; @@ -349,10 +368,10 @@ namespace VocaluxeLib.Menu _PartyModeID = partyModeID; _Theme = new SThemeParticleEffect(); _Stars = new List(); - this.Rect = rect; - this.Color = color; + Rect = rect; + Color = color; _Theme.TextureName = String.Empty; - this.Texture = texture; + Texture = texture; _MaxNumber = maxNumber; _Size = size; _Type = type; @@ -366,7 +385,7 @@ namespace VocaluxeLib.Menu string item = xmlPath + "/" + elementName; _ThemeLoaded = true; - _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", ref _Theme.TextureName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", out _Theme.TextureName, String.Empty); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/X", ref Rect.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Y", ref Rect.Y); @@ -374,7 +393,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref Rect.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref Rect.H); - if (xmlReader.GetValue(item + "/Color", ref _Theme.ColorName, String.Empty)) + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else { @@ -414,7 +433,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": ParticleEffect color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("Color", _Theme.ColorName); else { @@ -525,7 +544,7 @@ namespace VocaluxeLib.Menu h = 0; CParticle star; - if (_Theme.TextureName.Length > 0) + if (_Theme.TextureName != "") { star = new CParticle(_PartyModeID, _Theme.TextureName, Color, CBase.Game.GetRandom(w) + Rect.X - size / 4f, @@ -586,9 +605,9 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.TextureName.Length > 0) + if (_Theme.TextureName != "") Texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CPlaylist.cs b/VocaluxeLib/Menu/CPlaylist.cs index cf9f32e7..95f02019 100644 --- a/VocaluxeLib/Menu/CPlaylist.cs +++ b/VocaluxeLib/Menu/CPlaylist.cs @@ -1,4 +1,23 @@ -using System; +#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.Windows.Forms; using System.Xml; @@ -20,7 +39,7 @@ namespace VocaluxeLib.Menu public CPlaylistSong(int songID, EGameMode gm) { - this.SongID = songID; + SongID = songID; GameMode = gm; } @@ -170,7 +189,7 @@ namespace VocaluxeLib.Menu public EEditMode EditMode; public int ActivePlaylistID = -1; - public int Offset = 0; + public int Offset; public int CurrentPlaylistElement = -1; private CPlaylistElement _ChangeOrderElement; @@ -184,17 +203,19 @@ namespace VocaluxeLib.Menu public CPlaylist(int partyModeID) { _PartyModeID = partyModeID; - _Theme = new SThemePlaylist(); - _Theme.Text1 = new CText(_PartyModeID); - _Theme.StaticCover = new CStatic(_PartyModeID); - _Theme.StaticPlaylistFooter = new CStatic(_PartyModeID); - _Theme.StaticPlaylistHeader = new CStatic(_PartyModeID); - _Theme.ButtonPlaylistName = new CButton(_PartyModeID); - _Theme.ButtonPlaylistClose = new CButton(_PartyModeID); - _Theme.ButtonPlaylistDelete = new CButton(_PartyModeID); - _Theme.ButtonPlaylistSave = new CButton(_PartyModeID); - _Theme.ButtonPlaylistSing = new CButton(_PartyModeID); - _Theme.SelectSlideGameMode = new CSelectSlide(_PartyModeID); + _Theme = new SThemePlaylist + { + Text1 = new CText(_PartyModeID), + StaticCover = new CStatic(_PartyModeID), + StaticPlaylistFooter = new CStatic(_PartyModeID), + StaticPlaylistHeader = new CStatic(_PartyModeID), + ButtonPlaylistName = new CButton(_PartyModeID), + ButtonPlaylistClose = new CButton(_PartyModeID), + ButtonPlaylistDelete = new CButton(_PartyModeID), + ButtonPlaylistSave = new CButton(_PartyModeID), + ButtonPlaylistSing = new CButton(_PartyModeID), + SelectSlideGameMode = new CSelectSlide(_PartyModeID) + }; CompleteRect = new SRectF(); Rect = new SRectF(); @@ -230,15 +251,15 @@ namespace VocaluxeLib.Menu string item = xmlPath + "/" + elementName; _ThemeLoaded = true; - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackground", ref _Theme.TextureBackgroundName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackgroundSelected", ref _Theme.SelTextureBackgroundName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackground", out _Theme.TextureBackgroundName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackgroundSelected", out _Theme.SelTextureBackgroundName, String.Empty); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/X", ref Rect.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Y", ref Rect.Y); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Z", ref Rect.Z); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref Rect.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref Rect.H); - if (xmlReader.GetValue(item + "/ColorBackground", ref _Theme.ColorBackgroundName, String.Empty)) + if (xmlReader.GetValue(item + "/ColorBackground", out _Theme.ColorBackgroundName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorBackgroundName, skinIndex, out BackgroundColor); else { @@ -247,7 +268,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/BackgroundB", ref BackgroundColor.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/BackgroundA", ref BackgroundColor.A); } - if (xmlReader.GetValue(item + "/SColorBackground", ref _Theme.SelColorBackgroundName, String.Empty)) + if (xmlReader.GetValue(item + "/SColorBackground", out _Theme.SelColorBackgroundName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.SelColorBackgroundName, skinIndex, out BackgroundSelColor); else { @@ -351,7 +372,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Button color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorBackgroundName.Length > 0) + if (_Theme.ColorBackgroundName != "") writer.WriteElementString("ColorBackground", _Theme.ColorBackgroundName); else { @@ -363,7 +384,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected paylist-entry color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorBackgroundName.Length > 0) + if (_Theme.SelColorBackgroundName != "") writer.WriteElementString("SColorBackground", _Theme.SelColorBackgroundName); else { @@ -393,17 +414,7 @@ namespace VocaluxeLib.Menu return false; } - public void Draw() - { - Draw(false); - } - - public void ForceDraw() - { - Draw(true); - } - - public void Draw(bool forceDraw) + public void Draw(bool forceDraw = false) { if (_PlaylistElements.Count <= 0) LoadPlaylist(0); @@ -452,10 +463,10 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorBackgroundName.Length > 0) + if (_Theme.ColorBackgroundName != "") BackgroundColor = CBase.Theme.GetColor(_Theme.ColorBackgroundName, _PartyModeID); - if (_Theme.SelColorBackgroundName.Length > 0) + if (_Theme.SelColorBackgroundName != "") BackgroundSelColor = CBase.Theme.GetColor(_Theme.SelColorBackgroundName, _PartyModeID); _Theme.Text1.LoadTextures(); @@ -489,56 +500,144 @@ 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 { - 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.Length > 0) - _Theme.ButtonPlaylistName.Text.Text = _Theme.ButtonPlaylistName.Text.Text.Remove(_Theme.ButtonPlaylistName.Text.Text.Length - 1); - } - } - else - { - if (CurrentPlaylistElement == -1 || _PlaylistElementContents.Count == 0) - { - //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; - - //special actions if a song is selected switch (keyEvent.Key) { - case Keys.Up: - if (keyEvent.ModShift) + 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; + } + if (CurrentPlaylistElement == -1 || _PlaylistElementContents.Count == 0) + { + //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; + + //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) @@ -548,26 +647,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) { @@ -576,205 +671,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.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.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; @@ -786,10 +803,7 @@ namespace VocaluxeLib.Menu return; int off = _PlaylistElementContents.Count - _PlaylistElements.Count; - if (off >= 0) - Offset = off; - else - Offset = 0; + Offset = off >= 0 ? off : 0; Update(); @@ -830,10 +844,7 @@ namespace VocaluxeLib.Menu return; int off = _PlaylistElementContents.Count - _PlaylistElements.Count; - if (off >= 0) - Offset = off; - else - Offset = 0; + Offset = off >= 0 ? off : 0; Update(); } @@ -854,7 +865,7 @@ namespace VocaluxeLib.Menu } return true; } - else if (mouseEvent.Wheel < 0) + if (mouseEvent.Wheel < 0) { if (Offset + mouseEvent.Wheel >= 0) { @@ -906,23 +917,23 @@ namespace VocaluxeLib.Menu ClosePlaylist(); return true; } - else if (_Theme.ButtonPlaylistSing.Selected) + if (_Theme.ButtonPlaylistSing.Selected) { _StartPlaylistSongs(); return true; } - else if (_Theme.ButtonPlaylistSave.Selected) + if (_Theme.ButtonPlaylistSave.Selected) { CBase.Playlist.SavePlaylist(ActivePlaylistID); return true; } - else if (_Theme.ButtonPlaylistDelete.Selected) + if (_Theme.ButtonPlaylistDelete.Selected) { CBase.Playlist.DeletePlaylist(ActivePlaylistID); ClosePlaylist(); return true; } - else if (_Theme.ButtonPlaylistName.Selected) + if (_Theme.ButtonPlaylistName.Selected) { EditMode = EEditMode.PlaylistName; _Theme.ButtonPlaylistName.EditMode = true; @@ -1091,12 +1102,13 @@ namespace VocaluxeLib.Menu for (int i = 0; i < Math.Floor(Rect.H / _Theme.EntryHeight); i++) { - CPlaylistElement en = new CPlaylistElement(); + CPlaylistElement en = new CPlaylistElement + { + Background = new CStatic(_PartyModeID, _Theme.TextureBackgroundName, BackgroundColor, + new SRectF(Rect.X, Rect.Y + (i * _Theme.EntryHeight), Rect.W, _Theme.EntryHeight, Rect.Z)), + Cover = new CStatic(_Theme.StaticCover) + }; - en.Background = new CStatic(_PartyModeID, _Theme.TextureBackgroundName, BackgroundColor, - new SRectF(Rect.X, Rect.Y + (i * _Theme.EntryHeight), Rect.W, _Theme.EntryHeight, Rect.Z)); - - en.Cover = new CStatic(_Theme.StaticCover); en.Cover.Rect.Y += Rect.Y + (i * _Theme.EntryHeight); en.Cover.Rect.X += Rect.X; @@ -1131,17 +1143,18 @@ namespace VocaluxeLib.Menu _PlaylistElementContents.Clear(); for (int i = 0; i < CBase.Playlist.GetPlaylistSongCount(ActivePlaylistID); i++) { - CPlaylistElementContent pec = new CPlaylistElementContent(); - pec.SongID = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID; - pec.Modes = CBase.Songs.GetSongByID(CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID).AvailableGameModes; - pec.Mode = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).GameMode; + CPlaylistElementContent pec = new CPlaylistElementContent + { + SongID = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID, + Modes = CBase.Songs.GetSongByID(CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID).AvailableGameModes, + Mode = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).GameMode + }; _PlaylistElementContents.Add(pec); } Update(); return true; } - else - return false; + return false; } public void UpdatePlaylist() @@ -1149,8 +1162,7 @@ namespace VocaluxeLib.Menu _PlaylistElementContents.Clear(); for (int i = 0; i < CBase.Playlist.GetPlaylistSongCount(ActivePlaylistID); i++) { - CPlaylistElementContent pec = new CPlaylistElementContent(); - pec.SongID = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID; + CPlaylistElementContent pec = new CPlaylistElementContent {SongID = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).SongID}; pec.Modes = CBase.Songs.GetSongByID(pec.SongID).AvailableGameModes; pec.Mode = CBase.Playlist.GetPlaylistSong(ActivePlaylistID, i).GameMode; _PlaylistElementContents.Add(pec); @@ -1208,7 +1220,7 @@ namespace VocaluxeLib.Menu CSong song = CBase.Songs.GetSongByID(pec.SongID); _PlaylistElements[i].Cover.Texture = song.CoverTextureSmall; string t1 = _Theme.Text1.Text.Replace("%a", song.Artist).Replace("%t", song.Title); - _PlaylistElements[i].Text1.Text = /*(Offset + i + 1).ToString() + ") " + */ song.Artist + " - " + song.Title; //TODO: Add text field for the number + _PlaylistElements[i].Text1.Text = /*(Offset + i + 1) + ") " + */ t1; //TODO: Add text field for the number _PlaylistElements[i].SelectSlide.Clear(); for (int g = 0; g < pec.Modes.Length; g++) { diff --git a/VocaluxeLib/Menu/CPoints.cs b/VocaluxeLib/Menu/CPoints.cs index 1ac00827..b9ff4b41 100644 --- a/VocaluxeLib/Menu/CPoints.cs +++ b/VocaluxeLib/Menu/CPoints.cs @@ -1,6 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Text; +#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; namespace VocaluxeLib.Menu { @@ -10,15 +27,13 @@ namespace VocaluxeLib.Menu public CPoints(int numRounds, SPlayer[] players) { - _Rounds = new SPlayer[numRounds, players.Length]; + _Rounds = new SPlayer[numRounds,players.Length]; for (int round = 0; round < numRounds; round++) { for (int player = 0; player < players.Length; player++) { _Rounds[round, player].ProfileID = players[player].ProfileID; - _Rounds[round, player].Name = players[player].Name; - _Rounds[round, player].Difficulty = players[player].Difficulty; _Rounds[round, player].Points = 0f; _Rounds[round, player].PointsGoldenNotes = 0f; _Rounds[round, player].PointsLineBonus = 0f; @@ -69,13 +84,11 @@ namespace VocaluxeLib.Menu for (int p = 0; p < player.Length; p++) { - player[p].Name = _Rounds[round, p].Name; 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].Difficulty = _Rounds[round, p].Difficulty; player[p].Medley = _Rounds[round, p].Medley; player[p].Duet = _Rounds[round, p].Duet; player[p].ShortSong = _Rounds[round, p].ShortSong; @@ -86,4 +99,4 @@ namespace VocaluxeLib.Menu return player; } } -} +} \ No newline at end of file diff --git a/VocaluxeLib/Menu/CScreenSetting.cs b/VocaluxeLib/Menu/CScreenSetting.cs index abda8752..691074f9 100644 --- a/VocaluxeLib/Menu/CScreenSetting.cs +++ b/VocaluxeLib/Menu/CScreenSetting.cs @@ -1,4 +1,23 @@ -using System; +#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.Xml; namespace VocaluxeLib.Menu @@ -18,7 +37,10 @@ namespace VocaluxeLib.Menu public ESettingType Type; } + // ReSharper disable ClassNeverInstantiated.Global + //Instantiated by reflection public class CScreenSetting : IMenuElement + // ReSharper restore ClassNeverInstantiated.Global { private readonly int _PartyModeID; @@ -37,19 +59,12 @@ namespace VocaluxeLib.Menu _ThemeLoaded = false; } - public CScreenSetting(CScreenSetting ts) - { - _PartyModeID = ts._PartyModeID; - _Theme = ts._Theme; - _ThemeLoaded = ts._ThemeLoaded; - } - public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader, int skinIndex) { string item = xmlPath + "/" + elementName; _ThemeLoaded = true; - _ThemeLoaded &= xmlReader.GetValue(item + "/Value", ref _Theme.Value, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/Value", out _Theme.Value, String.Empty); _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Type", ref _Theme.Type); if (_ThemeLoaded) diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index ed049e8e..7216166c 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -1,4 +1,23 @@ -using System; +#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.Xml; @@ -84,7 +103,7 @@ namespace VocaluxeLib.Menu } public bool Visible = true; - public bool Highlighted = false; + public bool Highlighted; private bool _ArrowLeftSelected; private bool _ArrowRightSelected; @@ -96,7 +115,7 @@ namespace VocaluxeLib.Menu private readonly List _ValueBounds = new List(); - public bool WithTextures = false; + public readonly bool WithTextures; private int _Selection = -1; public int Selection @@ -115,8 +134,7 @@ namespace VocaluxeLib.Menu { if (_Selection >= 0 && _ValueIndexes.Count > _Selection) return _ValueIndexes[_Selection]; - else - return -1; + return -1; } } @@ -169,29 +187,24 @@ namespace VocaluxeLib.Menu public CSelectSlide(CSelectSlide slide) { _PartyModeID = slide._PartyModeID; - _Theme = new SThemeSelectSlide(); - - _Theme.TextureArrowLeftName = slide._Theme.TextureArrowLeftName; - _Theme.TextureArrowRightName = slide._Theme.TextureArrowRightName; - - _Theme.SelTextureName = slide._Theme.SelTextureName; - _Theme.SelTextureArrowLeftName = slide._Theme.SelTextureArrowLeftName; - _Theme.SelTextureArrowRightName = slide._Theme.SelTextureArrowRightName; - - _Theme.HighlightTextureName = slide._Theme.HighlightTextureName; - - _Theme.ColorName = slide._Theme.ColorName; - _Theme.SelColorName = slide._Theme.SelColorName; - _Theme.HighlightColorName = slide._Theme.HighlightColorName; - - _Theme.ArrowColorName = slide._Theme.ArrowColorName; - _Theme.SelArrowColorName = slide._Theme.SelArrowColorName; - - _Theme.TextColorName = slide._Theme.TextColorName; - _Theme.SelTextColorName = slide._Theme.SelTextColorName; - - _Theme.TextFont = slide._Theme.TextFont; - _Theme.TextStyle = slide._Theme.TextStyle; + _Theme = new SThemeSelectSlide + { + TextureArrowLeftName = slide._Theme.TextureArrowLeftName, + TextureArrowRightName = slide._Theme.TextureArrowRightName, + SelTextureName = slide._Theme.SelTextureName, + SelTextureArrowLeftName = slide._Theme.SelTextureArrowLeftName, + SelTextureArrowRightName = slide._Theme.SelTextureArrowRightName, + HighlightTextureName = slide._Theme.HighlightTextureName, + ColorName = slide._Theme.ColorName, + SelColorName = slide._Theme.SelColorName, + HighlightColorName = slide._Theme.HighlightColorName, + ArrowColorName = slide._Theme.ArrowColorName, + SelArrowColorName = slide._Theme.SelArrowColorName, + TextColorName = slide._Theme.TextColorName, + SelTextColorName = slide._Theme.SelTextColorName, + TextFont = slide._Theme.TextFont, + TextStyle = slide._Theme.TextStyle + }; _ThemeLoaded = false; @@ -230,15 +243,15 @@ namespace VocaluxeLib.Menu string item = xmlPath + "/" + elementName; _ThemeLoaded = true; - _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", ref _Theme.TextureName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowLeft", ref _Theme.TextureArrowLeftName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowRight", ref _Theme.TextureArrowRightName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", out _Theme.TextureName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowLeft", out _Theme.TextureArrowLeftName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowRight", out _Theme.TextureArrowRightName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinSelected", ref _Theme.SelTextureName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowLeftSelected", ref _Theme.SelTextureArrowLeftName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowRightSelected", ref _Theme.SelTextureArrowRightName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinSelected", out _Theme.SelTextureName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowLeftSelected", out _Theme.SelTextureArrowLeftName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinArrowRightSelected", out _Theme.SelTextureArrowRightName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinHighlighted", ref _Theme.HighlightTextureName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinHighlighted", out _Theme.HighlightTextureName, String.Empty); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/X", ref Rect.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Y", ref Rect.Y); @@ -246,7 +259,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref Rect.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref Rect.H); - if (xmlReader.GetValue(item + "/Color", ref _Theme.ColorName, String.Empty)) + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else { @@ -256,7 +269,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref Color.A); } - if (xmlReader.GetValue(item + "/SColor", ref _Theme.SelColorName, String.Empty)) + if (xmlReader.GetValue(item + "/SColor", out _Theme.SelColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.SelColorName, skinIndex, out SelColor); else { @@ -266,7 +279,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/SA", ref SelColor.A); } - if (xmlReader.GetValue(item + "/HColor", ref _Theme.HighlightColorName, String.Empty)) + if (xmlReader.GetValue(item + "/HColor", out _Theme.HighlightColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.HighlightColorName, skinIndex, out HighlightColor); else { @@ -288,7 +301,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowRightW", ref RectArrowRight.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowRightH", ref RectArrowRight.H); - if (xmlReader.GetValue(item + "/ArrowColor", ref _Theme.ArrowColorName, String.Empty)) + if (xmlReader.GetValue(item + "/ArrowColor", out _Theme.ArrowColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ArrowColorName, skinIndex, out ColorArrow); else { @@ -298,7 +311,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowA", ref ColorArrow.A); } - if (xmlReader.GetValue(item + "/ArrowSColor", ref _Theme.SelArrowColorName, String.Empty)) + if (xmlReader.GetValue(item + "/ArrowSColor", out _Theme.SelArrowColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.SelArrowColorName, skinIndex, out SelColorArrow); else { @@ -308,7 +321,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/ArrowSA", ref SelColorArrow.A); } - if (xmlReader.GetValue(item + "/TextColor", ref _Theme.TextColorName, String.Empty)) + if (xmlReader.GetValue(item + "/TextColor", out _Theme.TextColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.TextColorName, skinIndex, out TextColor); else { @@ -318,7 +331,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextA", ref TextColor.A); } - if (xmlReader.GetValue(item + "/TextSColor", ref _Theme.SelTextColorName, String.Empty)) + if (xmlReader.GetValue(item + "/TextSColor", out _Theme.SelTextColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.SelTextColorName, skinIndex, out SelTextColor); else { @@ -334,7 +347,7 @@ namespace VocaluxeLib.Menu if (xmlReader.TryGetFloatValue(item + "/TextRelativeY", ref TextRelativeY)) _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextRelativeY", ref TextRelativeY); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/TextMaxW", ref MaxW); - _ThemeLoaded &= xmlReader.GetValue(item + "/TextFont", ref _Theme.TextFont, "Normal"); + _ThemeLoaded &= xmlReader.GetValue(item + "/TextFont", out _Theme.TextFont, "Normal"); _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/TextStyle", ref _Theme.TextStyle); _ThemeLoaded &= xmlReader.TryGetIntValue(item + "/NumVisible", ref _NumVisible); @@ -398,7 +411,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("Color", _Theme.ColorName); else { @@ -410,7 +423,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorName.Length > 0) + if (_Theme.SelColorName != "") writer.WriteElementString("SColor", _Theme.SelColorName); else { @@ -422,7 +435,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Highlighted SelectSlide color from ColorScheme (high priority)"); writer.WriteComment("or
, , , (lower priority)"); - if (_Theme.HighlightColorName.Length > 0) + if (_Theme.HighlightColorName != "") writer.WriteElementString("HColor", _Theme.HighlightColorName); else { @@ -434,7 +447,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Arrow color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ArrowColorName.Length > 0) + if (_Theme.ArrowColorName != "") writer.WriteElementString("ArrowColor", _Theme.ArrowColorName); else { @@ -446,7 +459,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected arrow color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelArrowColorName.Length > 0) + if (_Theme.SelArrowColorName != "") writer.WriteElementString("ArrowSColor", _Theme.SelArrowColorName); else { @@ -458,7 +471,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.TextColorName.Length > 0) + if (_Theme.TextColorName != "") writer.WriteElementString("TextColor", _Theme.TextColorName); else { @@ -470,7 +483,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelTextColorName.Length > 0) + if (_Theme.SelTextColorName != "") writer.WriteElementString("TextSColor", _Theme.SelTextColorName); else { @@ -484,11 +497,11 @@ namespace VocaluxeLib.Menu writer.WriteElementString("TextH", TextH.ToString("#0.00")); writer.WriteComment(": Text relative x-position"); - if (TextRelativeX != 0) + if (Math.Abs(TextRelativeX) > 0.01) writer.WriteElementString("TextRelativeX", TextRelativeX.ToString("#0.00")); writer.WriteComment(": Text relative y-position"); - if (TextRelativeY != 0) + if (Math.Abs(TextRelativeY) > 0.01) writer.WriteElementString("TextRelativeY", TextRelativeY.ToString("#0.00")); writer.WriteComment(": Maximum text width (if exists)"); @@ -543,7 +556,7 @@ namespace VocaluxeLib.Menu _ValueBounds.Clear(); } - public void AddValues(string[] values) + public void AddValues(IEnumerable values) { foreach (string value in values) _AddValue(value, new STexture(-1), _PartyModeID); @@ -778,25 +791,25 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SelColorName.Length > 0) + if (_Theme.SelColorName != "") SelColor = CBase.Theme.GetColor(_Theme.SelColorName, _PartyModeID); - if (_Theme.HighlightColorName.Length > 0) + if (_Theme.HighlightColorName != "") HighlightColor = CBase.Theme.GetColor(_Theme.HighlightColorName, _PartyModeID); - if (_Theme.ArrowColorName.Length > 0) + if (_Theme.ArrowColorName != "") ColorArrow = CBase.Theme.GetColor(_Theme.ArrowColorName, _PartyModeID); - if (_Theme.SelArrowColorName.Length > 0) + if (_Theme.SelArrowColorName != "") SelColorArrow = CBase.Theme.GetColor(_Theme.SelArrowColorName, _PartyModeID); - if (_Theme.TextColorName.Length > 0) + if (_Theme.TextColorName != "") TextColor = CBase.Theme.GetColor(_Theme.TextColorName, _PartyModeID); - if (_Theme.SelColorName.Length > 0) + if (_Theme.SelColorName != "") SelTextColor = CBase.Theme.GetColor(_Theme.SelTextColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CStatic.cs b/VocaluxeLib/Menu/CStatic.cs index 20c900c0..78827930 100644 --- a/VocaluxeLib/Menu/CStatic.cs +++ b/VocaluxeLib/Menu/CStatic.cs @@ -1,4 +1,23 @@ -using System; +#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.Drawing; using System.Xml; @@ -26,13 +45,7 @@ namespace VocaluxeLib.Menu private STexture _Texture; public STexture Texture { - get - { - if (_Texture.Index != -1) - return _Texture; - else - return CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); - } + get { return _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } set { _Texture = value; } } @@ -108,8 +121,7 @@ namespace VocaluxeLib.Menu public CStatic(int partyModeID, string textureSkinName, SColorF color, SRectF rect) { _PartyModeID = partyModeID; - _Theme = new SThemeStatic(); - _Theme.TextureName = textureSkinName; + _Theme = new SThemeStatic {TextureName = textureSkinName}; _ThemeLoaded = false; _Texture = new STexture(-1); @@ -129,7 +141,7 @@ namespace VocaluxeLib.Menu string item = xmlPath + "/" + elementName; _ThemeLoaded = true; - _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", ref _Theme.TextureName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/Skin", out _Theme.TextureName, String.Empty); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/X", ref Rect.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Y", ref Rect.Y); @@ -137,7 +149,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref Rect.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref Rect.H); - if (xmlReader.GetValue(item + "/Color", ref _Theme.ColorName, String.Empty)) + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else { @@ -182,7 +194,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Static color from ColorScheme (high priority)"); writer.WriteComment("or , , ,
(lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("Color", _Theme.ColorName); else { @@ -231,11 +243,7 @@ namespace VocaluxeLib.Menu public void Draw(float scale, float z, EAspect aspect, bool forceDraw) { - STexture texture; - if (_Texture.Index != -1) - texture = _Texture; - else - texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); + STexture texture = _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); SRectF bounds = new SRectF( Rect.X - Rect.W * (scale - 1f), @@ -249,8 +257,8 @@ namespace VocaluxeLib.Menu if (aspect != EAspect.Stretch) { RectangleF bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H); - RectangleF rect2 = new RectangleF(0f, 0f, texture.Width, texture.Height); - CHelper.SetRect(bounds2, ref rect2, texture.Width / texture.Height, aspect); + RectangleF rect2; + CHelper.SetRect(bounds2, out rect2, texture.Width / texture.Height, aspect); rect.X = rect2.X; rect.Y = rect2.Y; @@ -274,7 +282,7 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } diff --git a/VocaluxeLib/Menu/CText.cs b/VocaluxeLib/Menu/CText.cs index 667119ab..ea864d79 100644 --- a/VocaluxeLib/Menu/CText.cs +++ b/VocaluxeLib/Menu/CText.cs @@ -1,4 +1,23 @@ -using System; +#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.Drawing; using System.Xml; @@ -21,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; } } @@ -55,7 +74,7 @@ namespace VocaluxeLib.Menu get { return _X; } set { - if (_X != value) + if (Math.Abs(_X - value) > 0.01) { _X = value; _PositionNeedsUpdate = true; @@ -70,7 +89,7 @@ namespace VocaluxeLib.Menu get { return _Y; } set { - if (_Y != value) + if (Math.Abs(_Y - value) > 0.01) { _Y = value; _PositionNeedsUpdate = true; @@ -91,7 +110,7 @@ namespace VocaluxeLib.Menu get { return _Height; } set { - if (_Height != value) + if (Math.Abs(_Height - value) > 0.01) { _Height = value; _PositionNeedsUpdate = true; @@ -105,7 +124,7 @@ namespace VocaluxeLib.Menu get { return _MaxWidth; } set { - if (_MaxWidth != value) + if (Math.Abs(_MaxWidth - value) > 0.01) { _MaxWidth = value; if (_MaxWidth > 0) @@ -124,7 +143,8 @@ namespace VocaluxeLib.Menu get { return _Bounds; } set { - if (_Bounds.X != value.X || _Bounds.Y != value.Y || _Bounds.W != value.W || _Bounds.H != value.H || _Bounds.Z != value.Z) + if (Math.Abs(_Bounds.X - value.X) > 0.01 || Math.Abs(_Bounds.Y - value.Y) > 0.01 || Math.Abs(_Bounds.W - value.W) > 0.01 || Math.Abs(_Bounds.H - value.H) > 0.01 || + Math.Abs(_Bounds.Z - value.Z) > 0.01) { _Bounds = value; _PositionNeedsUpdate = true; @@ -191,7 +211,7 @@ namespace VocaluxeLib.Menu public SColorF Color; //normal Color public SColorF SelColor; //selected Color for Buttons - public bool Reflection = false; + public bool Reflection; public float ReflectionSpace; public float ReflectionHeight; @@ -230,7 +250,7 @@ namespace VocaluxeLib.Menu } } - public bool Selected = false; + public bool Selected; public bool Visible = true; private bool _EditMode; public bool EditMode @@ -442,7 +462,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref _Height); xmlReader.TryGetFloatValue(item + "/MaxW", ref _MaxWidth); - if (xmlReader.GetValue(item + "/Color", ref _Theme.ColorName, String.Empty)) + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else { @@ -452,7 +472,7 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref Color.A); } - if (xmlReader.GetValue(item + "/SColor", ref _Theme.SelColorName, String.Empty)) + if (xmlReader.GetValue(item + "/SColor", out _Theme.SelColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.SelColorName, skinIndex, out SelColor); else { @@ -467,9 +487,9 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Align", ref _Align); xmlReader.TryGetEnumValue(item + "/HAlign", ref _HAlign); _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Style", ref _Style); - _ThemeLoaded &= xmlReader.GetValue(item + "/Font", ref _Font, "Normal"); + _ThemeLoaded &= xmlReader.GetValue(item + "/Font", out _Font, "Normal"); - _ThemeLoaded &= xmlReader.GetValue(item + "/Text", ref _Theme.Text, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/Text", out _Theme.Text, String.Empty); if (xmlReader.ItemExists(item + "/Reflection") && !buttonText) { @@ -522,7 +542,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("Color", _Theme.ColorName); else { @@ -534,7 +554,7 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Selected Text color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.SelColorName.Length > 0) + if (_Theme.SelColorName != "") writer.WriteElementString("SColor", _Theme.SelColorName); else { @@ -557,10 +577,7 @@ namespace VocaluxeLib.Menu writer.WriteElementString("Font", Font); writer.WriteComment(": Nothing or translation tag"); - if (CBase.Language.TranslationExists(_Theme.Text)) - writer.WriteElementString("Text", _Theme.Text); - else - writer.WriteElementString("Text", string.Empty); + writer.WriteElementString("Text", CBase.Language.TranslationExists(_Theme.Text) ? _Theme.Text : string.Empty); if (!_ButtonText) { @@ -673,17 +690,12 @@ namespace VocaluxeLib.Menu CBase.Drawing.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(x, Y, bounds.Width, bounds.Height, Z)); } - public void DrawRelative(float x, float y) - { - DrawRelative(x, y, false, 0f, 0f, 0f); - } - public void DrawRelative(float x, float y, float reflectionSpace, float reflectionHeigth, float rectHeight) { DrawRelative(x, y, true, reflectionSpace, reflectionHeigth, rectHeight); } - public void DrawRelative(float rx, float ry, bool reflection, float reflectionSpace, float reflectionHeight, float rectHeight) + public void DrawRelative(float rx, float ry, bool reflection = false, float reflectionSpace = 0f, float reflectionHeight = 0f, float rectHeight = 0f) { // Update Text Text = Text; @@ -757,10 +769,10 @@ namespace VocaluxeLib.Menu public void LoadTextures() { - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); - if (_Theme.SelColorName.Length > 0) + if (_Theme.SelColorName != "") SelColor = CBase.Theme.GetColor(_Theme.SelColorName, _PartyModeID); } @@ -787,7 +799,7 @@ namespace VocaluxeLib.Menu private void _UpdateTextPosition() { - if (_Text.Length == 0) + if (_Text == "") return; CBase.Fonts.SetFont(Font); diff --git a/VocaluxeLib/Menu/CXMLReader.cs b/VocaluxeLib/Menu/CXMLReader.cs index 6ef54d0c..6173699b 100644 --- a/VocaluxeLib/Menu/CXMLReader.cs +++ b/VocaluxeLib/Menu/CXMLReader.cs @@ -1,4 +1,23 @@ -using System; +#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.Xml.XPath; @@ -43,8 +62,8 @@ namespace VocaluxeLib.Menu public bool TryGetEnumValue(string cast, ref T value) where T : struct { - string val = String.Empty; - if (GetValue(cast, ref val, Enum.GetName(typeof(T), value))) + string val; + if (GetValue(cast, out val, Enum.GetName(typeof(T), value))) { CHelper.TryParse(val, out value, true); return true; @@ -54,8 +73,8 @@ namespace VocaluxeLib.Menu public bool TryGetIntValue(string cast, ref int value) { - string val = String.Empty; - if (GetValue(cast, ref val, value.ToString())) + string val; + if (GetValue(cast, out val, value.ToString())) return int.TryParse(val, out value); return false; } @@ -75,37 +94,31 @@ namespace VocaluxeLib.Menu public bool TryGetFloatValue(string cast, ref float value) { - string val = String.Empty; - if (GetValue(cast, ref val, value.ToString())) - return CHelper.TryParse(val, out value); - return false; + string val; + return GetValue(cast, out val, value.ToString()) && CHelper.TryParse(val, out value); } - public bool GetValue(string cast, ref string value, string defaultValue) + public bool GetValue(string cast, out string value, string defaultValue) { - XPathNodeIterator iterator; - int results = 0; + int resultCt = 0; string val = string.Empty; _Navigator.MoveToFirstChild(); - iterator = _Navigator.Select(cast); + XPathNodeIterator iterator = _Navigator.Select(cast); while (iterator.MoveNext()) { val = iterator.Current.Value; - results++; + resultCt++; } - if ((results == 0) || (results > 1)) + if (resultCt != 1) { value = defaultValue; return false; } - else - { - value = val; - return true; - } + value = val; + return true; } public List GetValues(string cast) @@ -128,7 +141,7 @@ namespace VocaluxeLib.Menu return values; } - public List GetAttributes(string cast, string attribute) + public IEnumerable GetAttributes(string cast, string attribute) { List values = new List(); @@ -167,11 +180,10 @@ namespace VocaluxeLib.Menu public bool ItemExists(string cast) { - XPathNodeIterator iterator; int results = 0; _Navigator.MoveToFirstChild(); - iterator = _Navigator.Select(cast); + XPathNodeIterator iterator = _Navigator.Select(cast); while (iterator.MoveNext()) results++; diff --git a/VocaluxeLib/Menu/Enums.cs b/VocaluxeLib/Menu/Enums.cs index 4387d4b2..469b2084 100644 --- a/VocaluxeLib/Menu/Enums.cs +++ b/VocaluxeLib/Menu/Enums.cs @@ -1,7 +1,27 @@ -using System; +#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; namespace VocaluxeLib.Menu { + #region Inputs [Flags] public enum EModifier @@ -16,8 +36,7 @@ namespace VocaluxeLib.Menu { Mouse, Keyboard, - WiiMote, - Gamepad + WiiMote } #endregion Inputs @@ -74,12 +93,14 @@ namespace VocaluxeLib.Menu X32 = 32 } - public enum EColorDeep + public enum EColorDepth { + // ReSharper disable UnusedMember.Global Bit8 = 8, Bit16 = 16, Bit24 = 24, Bit32 = 32 + // ReSharper restore UnusedMember.Global } public enum ETextureQuality @@ -106,7 +127,9 @@ namespace VocaluxeLib.Menu // ReSharper disable InconsistentNaming // don't change the order! TR_CONFIG_OFF, //no debug infos + // ReSharper disable UnusedMember.Global TR_CONFIG_ONLY_FPS, + // ReSharper restore UnusedMember.Global TR_CONFIG_LEVEL1, TR_CONFIG_LEVEL2, TR_CONFIG_LEVEL3, @@ -116,6 +139,7 @@ namespace VocaluxeLib.Menu public enum EBufferSize { + // ReSharper disable UnusedMember.Global B0 = 0, B512 = 512, B1024 = 1024, @@ -125,6 +149,7 @@ namespace VocaluxeLib.Menu B3072 = 3072, B3584 = 3584, B4096 = 4096 + // ReSharper restore UnusedMember.Global } public enum EPlaybackLib @@ -191,7 +216,9 @@ namespace VocaluxeLib.Menu public enum ECoverLoading { // ReSharper disable InconsistentNaming + // ReSharper disable UnusedMember.Global TR_CONFIG_COVERLOADING_ONDEMAND, + // ReSharper restore UnusedMember.Global TR_CONFIG_COVERLOADING_ATSTART, TR_CONFIG_COVERLOADING_DYNAMIC // ReSharper restore InconsistentNaming @@ -200,9 +227,11 @@ namespace VocaluxeLib.Menu public enum EGameDifficulty { // ReSharper disable InconsistentNaming + // ReSharper disable UnusedMember.Global TR_CONFIG_EASY, TR_CONFIG_NORMAL, TR_CONFIG_HARD + // ReSharper restore UnusedMember.Global // ReSharper restore InconsistentNaming } @@ -238,7 +267,9 @@ namespace VocaluxeLib.Menu TR_CONFIG_PLAYERINFO_BOTH, TR_CONFIG_PLAYERINFO_NAME, TR_CONFIG_PLAYERINFO_AVATAR, + // ReSharper disable UnusedMember.Global TR_CONFIG_PLAYERINFO_OFF + // ReSharper restore UnusedMember.Global // ReSharper restore InconsistentNaming } @@ -310,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/IMenu.cs b/VocaluxeLib/Menu/IMenu.cs index 39287afc..38af4ff1 100644 --- a/VocaluxeLib/Menu/IMenu.cs +++ b/VocaluxeLib/Menu/IMenu.cs @@ -1,8 +1,25 @@ -using System; +#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.Windows.Forms; -using VocaluxeLib.Menu.SingNotes; using VocaluxeLib.Menu.SongMenu; using VocaluxeLib.PartyModes; @@ -69,7 +86,7 @@ namespace VocaluxeLib.Menu int GetCoverSize(); - List GetSongFolder(); + IEnumerable GetSongFolder(); ESongSorting GetSongSorting(); EOffOn GetTabs(); EOffOn GetIgnoreArticles(); @@ -121,8 +138,6 @@ namespace VocaluxeLib.Menu void LoadTheme(); } - public interface IHelper {} - public interface IBackgroundMusic { bool IsDisabled(); @@ -194,7 +209,7 @@ namespace VocaluxeLib.Menu { int GetNumPlayer(); void SetNumPlayer(int numPlayer); - SPlayer[] GetPlayer(); + SPlayer[] GetPlayers(); CPoints GetPoints(); float GetMidBeatD(); int GetCurrentBeatD(); @@ -218,6 +233,8 @@ namespace VocaluxeLib.Menu public interface IProfiles { SProfile[] GetProfiles(); + EGameDifficulty GetDifficulty(int profileID); + string GetPlayerName(int profileID, int playerNum = 0); } public interface ISongs @@ -254,7 +271,7 @@ namespace VocaluxeLib.Menu { int Load(string videoFileName); bool Skip(int videoStream, float startPosition, float videoGap); - bool GetFrame(int videoStream, ref STexture videoTexture, float time, ref float videoTime); + bool GetFrame(int videoStream, ref STexture videoTexture, float time, out float videoTime); bool IsFinished(int videoStream); bool Close(int videoStream); } @@ -293,7 +310,7 @@ namespace VocaluxeLib.Menu public interface IPlaylist { string GetPlaylistName(int playlistID); - string[] GetPlaylistNames(); + List GetPlaylistNames(); void SetPlaylistName(int playlistID, string name); void DeletePlaylist(int playlistID); diff --git a/VocaluxeLib/Menu/IMenuElement.cs b/VocaluxeLib/Menu/IMenuElement.cs index 73bbcb3e..7222b2ca 100644 --- a/VocaluxeLib/Menu/IMenuElement.cs +++ b/VocaluxeLib/Menu/IMenuElement.cs @@ -1,4 +1,23 @@ -using System.Xml; +#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.Xml; namespace VocaluxeLib.Menu { diff --git a/VocaluxeLib/Menu/SingNotes/CNotes.cs b/VocaluxeLib/Menu/SingNotes/CNotes.cs index 6730b9c8..0ba6dfb6 100644 --- a/VocaluxeLib/Menu/SingNotes/CNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CNotes.cs @@ -1,77 +1,97 @@ -using System; +#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.Linq; namespace VocaluxeLib.Menu.SingNotes { public class CNotes { - private readonly List _Lines = new List(); + private readonly List _Voices = new List(); - public CLines[] Lines + public CVoice[] Voices { - get { return _Lines.ToArray(); } + get { return _Voices.ToArray(); } } public CNotes() {} public int LinesCount { - get { return _Lines.Count; } + get { return _Voices.Count; } } public CNotes(CNotes notes) { - foreach (CLines lines in notes._Lines) - _Lines.Add(new CLines(lines)); + foreach (CVoice voice in notes._Voices) + _Voices.Add(new CVoice(voice)); } - public CLines GetLines(int index) + public CVoice GetVoice(int index) { - while (index >= _Lines.Count) - _Lines.Add(new CLines()); + while (index >= _Voices.Count) + _Voices.Add(new CVoice()); - return _Lines[index]; + return _Voices[index]; } public int GetPoints(int index) { - if (index >= _Lines.Count) + if (index >= _Voices.Count) return 0; - return _Lines[index].Points; + return _Voices[index].Points; } public int GetNumLinesWithPoints(int index) { - if (index >= _Lines.Count) + if (index >= _Voices.Count) return 0; - return _Lines[index].NumLinesWithPoints; + return _Voices[index].NumLinesWithPoints; } - public void AddLines(CLines lines) + public void AddVoice(CVoice voice) { - _Lines.Add(lines); + _Voices.Add(voice); } - public bool ReplaceLinesAt(int index, CLines lines) + public bool ReplaceVoiceAt(int index, CVoice voice) { - if (index >= _Lines.Count) + if (index >= _Voices.Count) return false; - _Lines[index] = lines; + _Voices[index] = voice; return true; } public void Reset() { - _Lines.Clear(); + _Voices.Clear(); } public void SetMedley(int startBeat, int endBeat) { - foreach (CLines lines in _Lines) - lines.SetMedley(startBeat, endBeat); + foreach (CVoice voice in _Voices) + voice.SetMedley(startBeat, endBeat); } } @@ -111,35 +131,35 @@ namespace VocaluxeLib.Menu.SingNotes public CNote(int startBeat, int duration, int tone, string text) : this() { - this.StartBeat = startBeat; - this.Duration = duration; - this.Tone = tone; + StartBeat = startBeat; + Duration = duration; + Tone = tone; NoteType = ENoteType.Normal; - this.Text = text; + Text = text; } public CNote(int startBeat, int duration, int tone, string text, bool hit) : this() { - this.StartBeat = startBeat; - this.Duration = duration; - this.Tone = tone; + StartBeat = startBeat; + Duration = duration; + Tone = tone; NoteType = ENoteType.Normal; - this.Text = text; - this.Hit = hit; + Text = text; + Hit = hit; } public CNote(int startBeat, int duration, int tone, string text, ENoteType noteType) : this(startBeat, duration, tone, text) { - this.NoteType = noteType; + NoteType = noteType; } public CNote(int startBeat, int duration, int tone, string text, bool hit, ENoteType noteType) : this(startBeat, duration, tone, text) { - this.NoteType = noteType; - this.Hit = hit; + NoteType = noteType; + Hit = hit; } #endregion Constructors @@ -239,10 +259,7 @@ namespace VocaluxeLib.Menu.SingNotes #region Methods public bool IsPerfect(CNote compareNote) { - bool result = true; - - if (!Hit) - result = false; + bool result = Hit; if (StartBeat != compareNote.StartBeat) result = false; @@ -363,24 +380,12 @@ namespace VocaluxeLib.Menu.SingNotes public CNote FirstNote { - get - { - if (_Notes.Count > 0) - return _Notes[0]; - else - return null; - } + get { return _Notes.Count > 0 ? _Notes[0] : null; } } public CNote LastNote { - get - { - if (_Notes.Count > 0) - return _Notes[_Notes.Count - 1]; - else - return null; - } + get { return _Notes.Count > 0 ? _Notes[_Notes.Count - 1] : null; } } public int BaseLine @@ -537,23 +542,23 @@ namespace VocaluxeLib.Menu.SingNotes #endregion Methods } - public class CLines + public class CVoice { private readonly List _Lines = new List(); - public CLines() {} + public CVoice() {} - public CLines(CLines lines) + public CVoice(CVoice voice) { - foreach (CLine line in lines._Lines) + foreach (CLine line in voice._Lines) _Lines.Add(new CLine(line)); } - public CLine[] Line + public CLine[] Lines { get { return _Lines.ToArray(); } } - public int LineCount + public int NumLines { get { return _Lines.Count; } } @@ -568,51 +573,22 @@ 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) - return result; - - return 0; + return result > 0 ? result : 0; } } public int Points { - get - { - int points = 0; - foreach (CLine line in _Lines) - points += line.Points; - return points; - } + get { return _Lines.Sum(line => line.Points); } } public int NumLinesWithPoints { - get - { - int num = 0; - foreach (CLine line in _Lines) - { - if (line.Points > 0f) - num++; - } - return num; - } + get { return _Lines.Count(line => line.Points > 0f); } } #region Methods @@ -674,8 +650,7 @@ namespace VocaluxeLib.Menu.SingNotes if (lineIndex < 0) { //Note is before ALL lines - CLine line = new CLine(); - line.StartBeat = note.StartBeat; + CLine line = new CLine {StartBeat = note.StartBeat}; line.AddNote(note); _Lines.Insert(0, line); } @@ -704,7 +679,6 @@ namespace VocaluxeLib.Menu.SingNotes public void UpdateTimings() { CNote lastNote; - int min, max, s; if (_Lines.Count > 0) _Lines[0].StartBeat = -10000; @@ -716,9 +690,10 @@ namespace VocaluxeLib.Menu.SingNotes if ((lastNote != null) && (firstNote != null)) { - min = lastNote.EndBeat; - max = firstNote.StartBeat; + int min = lastNote.EndBeat; + int max = firstNote.StartBeat; + int s; switch (max - min) { case 0: diff --git a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs index 0df5b15c..457fb7fc 100644 --- a/VocaluxeLib/Menu/SingNotes/CSingNotes.cs +++ b/VocaluxeLib/Menu/SingNotes/CSingNotes.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.Xml; @@ -38,30 +57,24 @@ namespace VocaluxeLib.Menu.SingNotes public string SkinPerfectNoteStarName; } - public abstract class CSingNotes : ISingNotes, IMenuElement + public abstract class CSingNotes : IMenuElement { - protected int _PartyModeID; + protected readonly int _PartyModeID; private SThemeSingBar _Theme; private bool _ThemeLoaded; private readonly List _PlayerNotes; private int _ActID; - private SRectF[,] _BarPos; - /// /// Player bar positions /// /// /// first index = player number; second index = num players seen on screen /// - public SRectF[,] BarPos - { - get { return _BarPos; } - set { _BarPos = value; } - } + public SRectF[,] BarPos { get; set; } - public CSingNotes(int partyModeID) + protected CSingNotes(int partyModeID) { _PartyModeID = partyModeID; _Theme = new SThemeSingBar(); @@ -81,32 +94,32 @@ namespace VocaluxeLib.Menu.SingNotes string item = xmlPath + "/" + elementName; _ThemeLoaded = true; - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinLeft", ref _Theme.SkinLeftName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinMiddle", ref _Theme.SkinMiddleName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinRight", ref _Theme.SkinRightName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinLeft", out _Theme.SkinLeftName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinMiddle", out _Theme.SkinMiddleName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinRight", out _Theme.SkinRightName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackgroundLeft", ref _Theme.SkinBackgroundLeftName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackgroundMiddle", ref _Theme.SkinBackgroundMiddleName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackgroundRight", ref _Theme.SkinBackgroundRightName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackgroundLeft", out _Theme.SkinBackgroundLeftName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackgroundMiddle", out _Theme.SkinBackgroundMiddleName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinBackgroundRight", out _Theme.SkinBackgroundRightName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinGoldenStar", ref _Theme.SkinGoldenStarName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinToneHelper", ref _Theme.SkinToneHelperName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/SkinPerfectNoteStar", ref _Theme.SkinPerfectNoteStarName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinGoldenStar", out _Theme.SkinGoldenStarName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinToneHelper", out _Theme.SkinToneHelperName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/SkinPerfectNoteStar", out _Theme.SkinPerfectNoteStarName, String.Empty); - _BarPos = new SRectF[CBase.Settings.GetMaxNumPlayer(),CBase.Settings.GetMaxNumPlayer()]; + BarPos = new SRectF[CBase.Settings.GetMaxNumPlayer(),CBase.Settings.GetMaxNumPlayer()]; for (int numplayer = 0; numplayer < CBase.Settings.GetMaxNumPlayer(); numplayer++) { for (int player = 0; player < CBase.Settings.GetMaxNumPlayer(); player++) { if (player <= numplayer) { - _BarPos[player, numplayer] = new SRectF(); - string target = "/BarPositions/P" + (player + 1).ToString() + "N" + (numplayer + 1).ToString(); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "X", ref _BarPos[player, numplayer].X); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "Y", ref _BarPos[player, numplayer].Y); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "Z", ref _BarPos[player, numplayer].Z); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "W", ref _BarPos[player, numplayer].W); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "H", ref _BarPos[player, numplayer].H); + BarPos[player, numplayer] = new SRectF(); + string target = "/BarPositions/P" + (player + 1) + "N" + (numplayer + 1); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "X", ref BarPos[player, numplayer].X); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "Y", ref BarPos[player, numplayer].Y); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "Z", ref BarPos[player, numplayer].Z); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "W", ref BarPos[player, numplayer].W); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + target + "H", ref BarPos[player, numplayer].H); } } } @@ -161,16 +174,15 @@ namespace VocaluxeLib.Menu.SingNotes { for (int player = 0; player < CBase.Settings.GetMaxNumPlayer(); player++) { - if (player <= numplayer) - { - string target = "P" + (player + 1).ToString() + "N" + (numplayer + 1).ToString(); + if (player > numplayer) + continue; + string target = "P" + (player + 1) + "N" + (numplayer + 1); - writer.WriteElementString(target + "X", _BarPos[player, numplayer].X.ToString("#0")); - writer.WriteElementString(target + "Y", _BarPos[player, numplayer].Y.ToString("#0")); - writer.WriteElementString(target + "Z", _BarPos[player, numplayer].Z.ToString("#0.00")); - writer.WriteElementString(target + "W", _BarPos[player, numplayer].W.ToString("#0")); - writer.WriteElementString(target + "H", _BarPos[player, numplayer].H.ToString("#0")); - } + writer.WriteElementString(target + "X", BarPos[player, numplayer].X.ToString("#0")); + writer.WriteElementString(target + "Y", BarPos[player, numplayer].Y.ToString("#0")); + writer.WriteElementString(target + "Z", BarPos[player, numplayer].Z.ToString("#0.00")); + writer.WriteElementString(target + "W", BarPos[player, numplayer].W.ToString("#0")); + writer.WriteElementString(target + "H", BarPos[player, numplayer].H.ToString("#0")); } } writer.WriteEndElement(); //BarPositions @@ -183,53 +195,53 @@ 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(); + SPlayerNotes notes = new SPlayerNotes + { + Rect = rect, + Color = color, + Alpha = 1f, + ID = ++_ActID, + Lines = null, + LineNr = -1, + PlayerNr = playerNr, + Timer = new Stopwatch(), + GoldenStars = new List(), + Flares = new List(), + PerfectNoteEffect = new List(), + PerfectLineTwinkle = new List() + }; - notes.Rect = rect; - notes.Color = color; - notes.Alpha = 1f; - notes.ID = ++_ActID; - notes.Lines = null; - notes.LineNr = -1; - notes.PlayerNr = playerNr; - notes.Timer = new Stopwatch(); - notes.GoldenStars = new List(); - notes.Flares = new List(); - notes.PerfectNoteEffect = new List(); - notes.PerfectLineTwinkle = new List(); _PlayerNotes.Add(notes); return notes.ID; } - public virtual void RemovePlayer(int iD) {} - - public virtual void AddLine(int iD, CLine[] line, int lineNr, int player) + public void SetLines(int id, CLine[] lines, int lineNr) { - if (line == null) + if (lines == null) return; - int n = _FindPlayerLine(iD); + int n = _FindPlayerNotes(id); if (n == -1) return; if (lineNr == _PlayerNotes[n].LineNr) return; - SPlayerNotes notes = _PlayerNotes[n]; - - if (line.Length == 0 || line.Length <= lineNr) + if (lines.Length <= lineNr) return; - notes.Lines = line; + SPlayerNotes notes = _PlayerNotes[n]; + + notes.Lines = lines; notes.LineNr = lineNr; notes.GoldenStars.Clear(); notes.Flares.Clear(); @@ -239,13 +251,9 @@ 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); + int n = _FindPlayerNotes(id); if (n == -1) return; @@ -254,23 +262,23 @@ namespace VocaluxeLib.Menu.SingNotes _PlayerNotes[n] = pn; } - public virtual float GetAlpha(int iD) + public float GetAlpha(int id) { - int n = _FindPlayerLine(iD); + int n = _FindPlayerNotes(id); if (n == -1) return 0f; return _PlayerNotes[n].Alpha; } - public virtual void Draw(int iD, int player) + public void Draw(int id, int player) { - Draw(iD, null, player); + Draw(id, null, player); } - public virtual void Draw(int iD, List singLine, int player) + public void Draw(int id, List singLines, int player) { - int n = _FindPlayerLine(iD); + int n = _FindPlayerNotes(id); if (n == -1) return; @@ -293,11 +301,12 @@ namespace VocaluxeLib.Menu.SingNotes float w = _PlayerNotes[n].Rect.W; float h = _PlayerNotes[n].Rect.H; - float dh = h / CBase.Settings.GetNumNoteLines() * (2f - (int)CBase.Game.GetPlayer()[_PlayerNotes[n].PlayerNr].Difficulty) / 4f; + int profileID = CBase.Game.GetPlayers()[_PlayerNotes[n].PlayerNr].ProfileID; + float dh = h / CBase.Settings.GetNumNoteLines() * (2f - (int)CBase.Profiles.GetDifficulty(profileID)) / 4f; float beats = line.LastNoteBeat - line.FirstNoteBeat + 1; - if (beats == 0) + if (beats < 1) return; SColorF color = new SColorF( @@ -348,7 +357,7 @@ namespace VocaluxeLib.Menu.SingNotes foreach (CParticleEffect perfline in _PlayerNotes[n].PerfectLineTwinkle) perfline.Draw(); - if (singLine == null || singLine.Count == 0 || CBase.Game.GetPlayer()[player].CurrentLine == -1 || singLine.Count <= CBase.Game.GetPlayer()[player].CurrentLine) + if (singLines == null || singLines.Count == 0 || CBase.Game.GetPlayers()[player].CurrentLine == -1 || singLines.Count <= CBase.Game.GetPlayers()[player].CurrentLine) { foreach (CParticleEffect stars in _PlayerNotes[n].GoldenStars) { @@ -358,7 +367,7 @@ namespace VocaluxeLib.Menu.SingNotes return; } - foreach (CNote note in singLine[CBase.Game.GetPlayer()[player].CurrentLine].Notes) + foreach (CNote note in singLines[CBase.Game.GetPlayers()[player].CurrentLine].Notes) { if (note.StartBeat >= line.FirstNoteBeat && note.EndBeat <= line.LastNoteBeat) { @@ -383,8 +392,7 @@ namespace VocaluxeLib.Menu.SingNotes if (note.EndBeat >= CBase.Game.GetCurrentBeatD() && note.Hit && note.NoteType == ENoteType.Golden) { - SRectF re = new SRectF(rect); - re.W = (CBase.Game.GetMidBeatD() - note.StartBeat) / beats * w; + SRectF re = new SRectF(rect) {W = (CBase.Game.GetMidBeatD() - note.StartBeat) / beats * w}; _AddFlare(re, n); } @@ -396,13 +404,13 @@ namespace VocaluxeLib.Menu.SingNotes } } - int currentLine = CBase.Game.GetPlayer()[player].SingLine.Count - 1; + int currentLine = CBase.Game.GetPlayers()[player].SingLine.Count - 1; if (currentLine > 0) { - if (CBase.Game.GetPlayer()[player].SingLine[currentLine - 1].PerfectLine) + if (CBase.Game.GetPlayers()[player].SingLine[currentLine - 1].PerfectLine) { _AddPerfectLine(n); - CBase.Game.GetPlayer()[player].SingLine[currentLine - 1].PerfectLine = false; + CBase.Game.GetPlayers()[player].SingLine[currentLine - 1].PerfectLine = false; } } @@ -448,30 +456,18 @@ namespace VocaluxeLib.Menu.SingNotes LoadTextures(); } - private int _FindPlayerLine(int iD) + private int _FindPlayerNotes(int id) { - if (iD < 0 || iD > _PlayerNotes.Count) - return -1; - - int n = -1; for (int i = 0; i < _PlayerNotes.Count; i++) { - if (_PlayerNotes[i].ID == iD) - { - n = i; - break; - } + if (_PlayerNotes[i].ID == id) + return i; } - return n; + return -1; } - private void _DrawNote(SRectF rect, SColorF color) - { - _DrawNote(rect, color, 1f); - } - - private void _DrawNote(SRectF rect, SColorF color, float factor) + private void _DrawNote(SRectF rect, SColorF color, float factor = 1f) { const int spacing = 0; @@ -565,12 +561,7 @@ namespace VocaluxeLib.Menu.SingNotes } } - private void _AddGoldenNote(SRectF rect, int n, int nr) - { - _AddGoldenNote(rect, n, nr, 1f); - } - - private void _AddGoldenNote(SRectF rect, int n, int nr, float factor) + private void _AddGoldenNote(SRectF rect, int n, int nr, float factor = 1f) { const int spacing = 0; @@ -596,12 +587,7 @@ namespace VocaluxeLib.Menu.SingNotes } } - private void _AddFlare(SRectF rect, int n) - { - _AddFlare(rect, n, 1f); - } - - private void _AddFlare(SRectF rect, int n, float factor) + private void _AddFlare(SRectF rect, int n, float factor = 1f) { const int spacing = 0; @@ -623,12 +609,7 @@ namespace VocaluxeLib.Menu.SingNotes _PlayerNotes[n].Flares.Add(flares); } - private void _AddPerfectNote(SRectF rect, int n) - { - _AddPerfectNote(rect, n, 1f); - } - - private void _AddPerfectNote(SRectF rect, int n, float factor) + private void _AddPerfectNote(SRectF rect, int n, float factor = 1f) { const int spacing = 0; diff --git a/VocaluxeLib/Menu/SingNotes/CSingNotesClassic.cs b/VocaluxeLib/Menu/SingNotes/CSingNotesClassic.cs index 53cc55fa..b13a8b59 100644 --- a/VocaluxeLib/Menu/SingNotes/CSingNotesClassic.cs +++ b/VocaluxeLib/Menu/SingNotes/CSingNotesClassic.cs @@ -1,4 +1,23 @@ -namespace VocaluxeLib.Menu.SingNotes +#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 VocaluxeLib.Menu.SingNotes { class CSingNotesClassic : CSingNotes { diff --git a/VocaluxeLib/Menu/SingNotes/ISingNotes.cs b/VocaluxeLib/Menu/SingNotes/ISingNotes.cs deleted file mode 100644 index 0a814f4b..00000000 --- a/VocaluxeLib/Menu/SingNotes/ISingNotes.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; - -namespace VocaluxeLib.Menu.SingNotes -{ - public interface ISingNotes - { - void Reset(); - int AddPlayer(SRectF rect, SColorF color, int playerNr); - void RemovePlayer(int iD); - - void AddLine(int iD, CLine[] line, int lineNr, int player); - void RemoveLine(int iD); - - void AddNote(int iD, CNote note); - - void SetAlpha(int iD, float alpha); - float GetAlpha(int iD); - - void Draw(int iD, int player); - void Draw(int iD, List singLine, int player); - } -} \ No newline at end of file diff --git a/VocaluxeLib/Menu/SongMenu/CSong.cs b/VocaluxeLib/Menu/SongMenu/CSong.cs index 3e2ac247..126a53c7 100644 --- a/VocaluxeLib/Menu/SongMenu/CSong.cs +++ b/VocaluxeLib/Menu/SongMenu/CSong.cs @@ -1,4 +1,23 @@ -using System; +#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.IO; using System.Text; @@ -28,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; @@ -47,13 +66,7 @@ namespace VocaluxeLib.Menu.SongMenu public STexture CoverTextureBig { - get - { - if (_CoverBigLoaded) - return _CoverTextureBig; - else - return _CoverTextureSmall; - } + get { return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } set { if (value.Index != -1) @@ -87,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; @@ -108,9 +123,9 @@ namespace VocaluxeLib.Menu.SongMenu public SMedley Medley = new SMedley(0); public bool CalculateMedley = true; - public float PreviewStart = 0f; + public float PreviewStart; - public int ShortEnd = 0; + public int ShortEnd; public Encoding Encoding = Encoding.Default; public string Folder = String.Empty; @@ -160,8 +175,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (_CoverBigLoaded) return _CoverTextureBig; - else - return _CoverTextureSmall; + return _CoverTextureSmall; } set { @@ -176,46 +190,42 @@ namespace VocaluxeLib.Menu.SongMenu public string TitleSorting = String.Empty; public string ArtistSorting = String.Empty; - public float Start = 0f; - public float Finish = 0f; + public float Start; + public float Finish; public float BPM = 1f; - public float Gap = 0f; - public float VideoGap = 0f; + public float Gap; + public float VideoGap; public string DuetPart1 = String.Empty; public string DuetPart2 = String.Empty; - public List Comment = new List(); + private readonly List _Comment = new List(); // Sorting public int ID; - public bool Visible = true; - public int CatIndex = -1; - public bool Selected = false; + private readonly bool _Visible = true; + private readonly int _CatIndex = -1; + private readonly bool _Selected; public bool IsDuet { - get { return Notes.Lines.Length > 1; } + get { return Notes.Voices.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 CNotes Notes = new CNotes(); + public readonly CNotes Notes = new CNotes(); public EGameMode[] AvailableGameModes { get { - List gms = new List(); - if (IsDuet) - gms.Add(EGameMode.TR_GAMEMODE_DUET); - else - gms.Add(EGameMode.TR_GAMEMODE_NORMAL); + List gms = new List {IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL}; if (Medley.Source != EMedleySource.None) gms.Add(EGameMode.TR_GAMEMODE_MEDLEY); gms.Add(EGameMode.TR_GAMEMODE_SHORTSONG); @@ -238,12 +248,14 @@ namespace VocaluxeLib.Menu.SongMenu _CoverTextureSmall = song._CoverTextureSmall; _CoverTextureBig = song._CoverTextureBig; - Medley = new SMedley(); - Medley.Source = song.Medley.Source; - Medley.StartBeat = song.Medley.StartBeat; - Medley.EndBeat = song.Medley.EndBeat; - Medley.FadeInTime = song.Medley.FadeInTime; - Medley.FadeOutTime = song.Medley.FadeOutTime; + Medley = new SMedley + { + Source = song.Medley.Source, + StartBeat = song.Medley.StartBeat, + EndBeat = song.Medley.EndBeat, + FadeInTime = song.Medley.FadeInTime, + FadeOutTime = song.Medley.FadeOutTime + }; CalculateMedley = song.CalculateMedley; PreviewStart = song.PreviewStart; @@ -278,14 +290,14 @@ namespace VocaluxeLib.Menu.SongMenu Gap = song.Gap; VideoGap = song.VideoGap; - Comment = new List(); - foreach (string value in song.Comment) - Comment.Add(value); + _Comment = new List(); + foreach (string value in song._Comment) + _Comment.Add(value); ID = song.ID; - Visible = song.Visible; - CatIndex = song.CatIndex; - Selected = song.Selected; + _Visible = song._Visible; + _CatIndex = song._CatIndex; + _Selected = song._Selected; Edition = new List(); foreach (string value in song.Edition) @@ -320,23 +332,24 @@ namespace VocaluxeLib.Menu.SongMenu return false; Folder = Path.GetDirectoryName(filePath); + if (Folder == null) + return false; foreach (string folder in CBase.Config.GetSongFolder()) { - if (Folder.Contains(folder)) + if (!Folder.Contains(folder)) + continue; + if (Folder.Length == folder.Length) + FolderName = "Songs"; + else { - if (Folder.Length == folder.Length) - FolderName = "Songs"; - else - { - FolderName = Folder.Substring(folder.Length + 1, Folder.Length - folder.Length - 1); + FolderName = Folder.Substring(folder.Length + 1, Folder.Length - folder.Length - 1); - int pos = FolderName.IndexOf("\\"); - if (pos >= 0) - FolderName = FolderName.Substring(0, pos); - } - break; + int pos = FolderName.IndexOf("\\", StringComparison.Ordinal); + if (pos >= 0) + FolderName = FolderName.Substring(0, pos); } + break; } FileName = Path.GetFileName(filePath); @@ -347,184 +360,176 @@ namespace VocaluxeLib.Menu.SongMenu { sr = new StreamReader(filePath, Encoding.Default, true); - string line; - - int pos = -1; - string identifier = String.Empty; - string value = String.Empty; - while (!sr.EndOfStream) { - line = sr.ReadLine(); - if (line.Length == 0) + string line = sr.ReadLine(); + if (line == "") continue; if (!line[0].ToString().Equals("#")) break; - pos = line.IndexOf(":"); + int pos = line.IndexOf(":", StringComparison.Ordinal); - if (pos > 0) + if (pos <= 0) + continue; + string identifier = line.Substring(1, pos - 1).Trim().ToUpper(); + string value = line.Substring(pos + 1, line.Length - pos - 1).Trim(); + + if (value != "") { - identifier = line.Substring(1, pos - 1).Trim().ToUpper(); - value = line.Substring(pos + 1, line.Length - pos - 1).Trim(); - - if (value.Length > 0) + switch (identifier) { - switch (identifier) - { - case "ENCODING": - Encoding = CEncoding.GetEncoding(value); - sr.Dispose(); - sr = null; - sr = new StreamReader(filePath, Encoding); - identifier = String.Empty; + case "ENCODING": + Encoding = CEncoding.GetEncoding(value); + sr.Dispose(); + sr = null; + sr = new StreamReader(filePath, Encoding); - //Scip everything till encoding - while (!sr.EndOfStream) + //Scip everything till encoding + while (!sr.EndOfStream) + { + line = sr.ReadLine(); + if (line == "") + continue; + if (!line[0].ToString().Equals("#")) + break; + + pos = line.IndexOf(":", StringComparison.Ordinal); + + if (pos > 0) { - line = sr.ReadLine(); - if (line.Length == 0) - continue; - if (!line[0].ToString().Equals("#")) + identifier = line.Substring(1, pos - 1).Trim().ToUpper(); + if (identifier == "ENCODING") break; - - pos = line.IndexOf(":"); - - if (pos > 0) - { - identifier = line.Substring(1, pos - 1).Trim().ToUpper(); - if (identifier == "ENCODING") - break; - } - } - break; - case "TITLE": - if (value.Length > 0) - { - Title = value; - headerFlags |= EHeaderFlags.Title; - } - break; - case "ARTIST": - if (value.Length > 0) - { - Artist = value; - headerFlags |= EHeaderFlags.Artist; - } - break; - case "TITLE-ON-SORTING": - if (value.Length > 0) - TitleSorting = value; - break; - case "ARTIST-ON-SORTING": - if (value.Length > 0) - ArtistSorting = value; - break; - case "P1": - if (value.Length > 0) - DuetPart1 = value; - break; - case "P2": - if (value.Length > 0) - DuetPart2 = value; - break; - case "MP3": - if (File.Exists(Path.Combine(Folder, value))) - { - MP3FileName = value; - headerFlags |= EHeaderFlags.MP3; } + } + break; + case "TITLE": + if (value != "") + { + Title = value; + headerFlags |= EHeaderFlags.Title; + } + break; + case "ARTIST": + if (value != "") + { + Artist = value; + headerFlags |= EHeaderFlags.Artist; + } + break; + case "TITLE-ON-SORTING": + if (value != "") + TitleSorting = value; + break; + case "ARTIST-ON-SORTING": + if (value != "") + ArtistSorting = value; + break; + case "P1": + if (value != "") + DuetPart1 = value; + break; + case "P2": + if (value != "") + DuetPart2 = value; + break; + case "MP3": + if (File.Exists(Path.Combine(Folder, value))) + { + MP3FileName = value; + headerFlags |= EHeaderFlags.MP3; + } + else + { + CBase.Log.LogError("Can't find audio file: " + Path.Combine(Folder, value)); + return false; + } + break; + case "BPM": + if (CHelper.TryParse(value, out BPM)) + { + BPM *= 4; + headerFlags |= EHeaderFlags.BPM; + } + break; + case "EDITION": + if (value.Length > 1) + Edition.Add(value); + break; + case "GENRE": + if (value.Length > 1) + Genre.Add(value); + break; + case "YEAR": + int num; + if (value.Length == 4 && int.TryParse(value, out num) && num != 0) + Year = value; + break; + case "LANGUAGE": + if (value.Length > 1) + Language.Add(value); + break; + case "COMMENT": + if (value.Length > 1) + _Comment.Add(value); + break; + case "GAP": + if (CHelper.TryParse(value, out Gap)) + Gap /= 1000f; + break; + case "COVER": + if (File.Exists(Path.Combine(Folder, value))) + CoverFileName = value; + break; + case "BACKGROUND": + if (File.Exists(Path.Combine(Folder, value))) + BackgroundFileName = value; + break; + case "VIDEO": + if (File.Exists(Path.Combine(Folder, value))) + VideoFileName = value; + else + CBase.Log.LogError("Can't find video file: " + Path.Combine(Folder, value)); + break; + case "VIDEOGAP": + CHelper.TryParse(value, out VideoGap); + break; + case "VIDEOASPECT": + CHelper.TryParse(value, out VideoAspect, true); + break; + case "START": + CHelper.TryParse(value, out Start); + break; + case "END": + if (CHelper.TryParse(value, out Finish)) + Finish /= 1000f; + break; + case "PREVIEWSTART": + if (CHelper.TryParse(value, out PreviewStart)) + { + if (PreviewStart < 0f) + PreviewStart = 0f; else - { - CBase.Log.LogError("Can't find audio file: " + Path.Combine(Folder, value)); - return false; - } - break; - case "BPM": - if (CHelper.TryParse(value, out BPM)) - { - BPM *= 4; - headerFlags |= EHeaderFlags.BPM; - } - break; - case "EDITION": - if (value.Length > 1) - Edition.Add(value); - break; - case "GENRE": - if (value.Length > 1) - Genre.Add(value); - break; - case "YEAR": - int num = 0; - if (value.Length == 4 && int.TryParse(value, out num) && num != 0) - Year = value; - break; - case "LANGUAGE": - if (value.Length > 1) - Language.Add(value); - break; - case "COMMENT": - if (value.Length > 1) - Comment.Add(value); - break; - case "GAP": - if (CHelper.TryParse(value, out Gap)) - Gap /= 1000f; - break; - case "COVER": - if (File.Exists(Path.Combine(Folder, value))) - CoverFileName = value; - break; - case "BACKGROUND": - if (File.Exists(Path.Combine(Folder, value))) - BackgroundFileName = value; - break; - case "VIDEO": - if (File.Exists(Path.Combine(Folder, value))) - VideoFileName = value; - else - CBase.Log.LogError("Can't find video file: " + Path.Combine(Folder, value)); - break; - case "VIDEOGAP": - CHelper.TryParse(value, out VideoGap); - break; - case "VIDEOASPECT": - CHelper.TryParse(value, out VideoAspect, true); - break; - case "START": - CHelper.TryParse(value, out Start); - break; - case "END": - if (CHelper.TryParse(value, out Finish)) - Finish /= 1000f; - break; - case "PREVIEWSTART": - if (CHelper.TryParse(value, out PreviewStart)) - { - if (PreviewStart < 0f) - PreviewStart = 0f; - else - headerFlags |= EHeaderFlags.PreviewStart; - } - break; - case "MEDLEYSTARTBEAT": - if (int.TryParse(value, out Medley.StartBeat)) - headerFlags |= EHeaderFlags.MedleyStartBeat; - break; - case "MEDLEYENDBEAT": - if (int.TryParse(value, out Medley.EndBeat)) - headerFlags |= EHeaderFlags.MedleyEndBeat; - break; - case "CALCMEDLEY": - if (value.ToUpper() == "OFF") - CalculateMedley = false; - break; - case "RELATIVE": - if (value.ToUpper() == "YES" && value.ToUpper() != "NO") - Relative = EOffOn.TR_CONFIG_ON; - break; - } + headerFlags |= EHeaderFlags.PreviewStart; + } + break; + case "MEDLEYSTARTBEAT": + if (int.TryParse(value, out Medley.StartBeat)) + headerFlags |= EHeaderFlags.MedleyStartBeat; + break; + case "MEDLEYENDBEAT": + if (int.TryParse(value, out Medley.EndBeat)) + headerFlags |= EHeaderFlags.MedleyEndBeat; + break; + case "CALCMEDLEY": + if (value.ToUpper() == "OFF") + CalculateMedley = false; + break; + case "RELATIVE": + if (value.ToUpper() == "YES" && value.ToUpper() != "NO") + Relative = EOffOn.TR_CONFIG_ON; + break; } } } //end of while @@ -570,15 +575,10 @@ namespace VocaluxeLib.Menu.SongMenu } } - if ((headerFlags & EHeaderFlags.PreviewStart) == 0 || PreviewStart == 0f) + if ((headerFlags & EHeaderFlags.PreviewStart) == 0 || Math.Abs(PreviewStart) < float.Epsilon) { //PreviewStart is not set or <=0 - if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0) - //fallback to MedleyStart - PreviewStart = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM); - else - //else set to 0, it will be set in FindRefrainStart - PreviewStart = 0f; + PreviewStart = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) : 0f; } if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0) @@ -602,10 +602,10 @@ namespace VocaluxeLib.Menu.SongMenu _CheckFiles(); //Before saving this tags to .txt: Check, if ArtistSorting and Artist are equal, then don't save this tag. - if (ArtistSorting.Length == 0) + if (ArtistSorting == "") ArtistSorting = Artist; - if (TitleSorting.Length == 0) + if (TitleSorting == "") TitleSorting = Title; return true; @@ -629,14 +629,9 @@ namespace VocaluxeLib.Menu.SongMenu } char tempC = char.MinValue; - int param1 = 0; - int param2 = 0; - int param3 = 0; int currentPos = 0; - string paramS = String.Empty; bool isNewSentence = false; - string line = String.Empty; int player = 0; int fileLineNo = 0; @@ -650,7 +645,7 @@ namespace VocaluxeLib.Menu.SongMenu //Search for Note Beginning while (!sr.EndOfStream) { - line = sr.ReadLine(); + sr.ReadLine(); fileLineNo++; tempC = (char)sr.Peek(); @@ -665,16 +660,18 @@ namespace VocaluxeLib.Menu.SongMenu if (sr.EndOfStream) { - CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo.ToString() + ". No lyrics/notes found: " + filePath); + CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". No lyrics/notes found: " + filePath); return false; } do { - char chr; + int param2; + int param1; switch (tempC) { case 'P': + char chr; while ((chr = (char)sr.Read()) == ' ') {} int.TryParse(chr.ToString(), out param1); @@ -686,7 +683,7 @@ namespace VocaluxeLib.Menu.SongMenu player = 2; else { - CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo.ToString() + ". Wrong or missing number after \"P\": " + filePath); + CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". Wrong or missing number after \"P\": " + filePath); return false; } sr.ReadLine(); @@ -701,10 +698,10 @@ namespace VocaluxeLib.Menu.SongMenu param2 = CHelper.TryReadInt(sr); sr.Read(); - param3 = CHelper.TryReadInt(sr); + int param3 = CHelper.TryReadInt(sr); sr.Read(); - paramS = sr.ReadLine(); + string paramS = sr.ReadLine(); ENoteType noteType; @@ -732,7 +729,7 @@ namespace VocaluxeLib.Menu.SongMenu case '-': if (isNewSentence) { - CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo.ToString() + ". Double sentence break: " + filePath); + CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". Double sentence break: " + filePath); return false; } sr.Read(); @@ -760,10 +757,10 @@ namespace VocaluxeLib.Menu.SongMenu sr.ReadLine(); break; default: - CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo.ToString() + ". Unexpected or missing character (" + tempC + "): " + filePath); + CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". Unexpected or missing character (" + tempC + "): " + filePath); return false; } - int c = 0; + int c; do { c = sr.Read(); @@ -772,12 +769,12 @@ namespace VocaluxeLib.Menu.SongMenu fileLineNo++; } while (!sr.EndOfStream && (tempC != 'E')); - foreach (CLines lines in Notes.Lines) - lines.UpdateTimings(); + foreach (CVoice voice in Notes.Voices) + voice.UpdateTimings(); } catch (Exception e) { - CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo.ToString() + ". An unhandled exception occured (" + e.Message + "): " + filePath); + CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". An unhandled exception occured (" + e.Message + "): " + filePath); if (sr != null) sr.Dispose(); return false; @@ -802,23 +799,22 @@ namespace VocaluxeLib.Menu.SongMenu private bool _ParseNote(int player, ENoteType noteType, int start, int length, int tone, string text) { CNote note = new CNote(start, length, tone, text, noteType); - CLines lines = Notes.GetLines(player); - return lines.AddNote(note); + CVoice voice = Notes.GetVoice(player); + return voice.AddNote(note); } private void _NewSentence(int player, int start) { - CLines lines = Notes.GetLines(player); - CLine line = new CLine(); - line.StartBeat = start; - lines.AddLine(line); + CVoice voice = Notes.GetVoice(player); + CLine line = new CLine {StartBeat = start}; + voice.AddLine(line); } public void LoadSmallCover() { if (_CoverSmallLoaded) return; - if (CoverFileName.Length > 0) + if (CoverFileName != "") { if (!CBase.DataBase.GetCover(Path.Combine(Folder, CoverFileName), ref _CoverTextureSmall, CBase.Config.GetCoverSize())) _CoverTextureSmall = CBase.Cover.GetNoCover(); @@ -831,10 +827,10 @@ namespace VocaluxeLib.Menu.SongMenu private void _CheckFiles() { - if (CoverFileName.Length == 0) + if (CoverFileName == "") { - List files = CHelper.ListFiles(Folder, "*.jpg", false); - files.AddRange(CHelper.ListFiles(Folder, "*.png", false)); + List files = CHelper.ListFiles(Folder, "*.jpg"); + files.AddRange(CHelper.ListFiles(Folder, "*.png")); foreach (String file in files) { if (Regex.IsMatch(file, @".[CO].", RegexOptions.IgnoreCase) && @@ -843,10 +839,10 @@ namespace VocaluxeLib.Menu.SongMenu } } - if (BackgroundFileName.Length == 0) + if (BackgroundFileName == "") { - List files = CHelper.ListFiles(Folder, "*.jpg", false); - files.AddRange(CHelper.ListFiles(Folder, "*.png", false)); + List files = CHelper.ListFiles(Folder, "*.jpg"); + files.AddRange(CHelper.ListFiles(Folder, "*.png")); foreach (String file in files) { if (Regex.IsMatch(file, @".[BG].", RegexOptions.IgnoreCase) && @@ -858,12 +854,12 @@ namespace VocaluxeLib.Menu.SongMenu private void _CheckDuet() { - if (DuetPart1.Length == 0) + if (DuetPart1 == "") { DuetPart1 = "Part 1"; CBase.Log.LogError("Warning: Can't find #P1-tag for duets in \"" + Artist + " - " + Title + "\"."); } - if (DuetPart2.Length == 0) + if (DuetPart2 == "") { DuetPart2 = "Part 2"; CBase.Log.LogError("Warning: Can't find #P2-tag for duets in \"" + Artist + " - " + Title + "\"."); @@ -879,50 +875,42 @@ namespace VocaluxeLib.Menu.SongMenu private List _GetSeries() { - CLines lines = Notes.GetLines(0); + CVoice voice = Notes.GetVoice(0); - if (lines.LineCount == 0) + if (voice.NumLines == 0) return null; // build sentences list List sentences = new List(); - foreach (CLine line in lines.Line) - { - if (line.Points != 0) - sentences.Add(line.Lyrics); - else - sentences.Add(String.Empty); - } + foreach (CLine line in voice.Lines) + sentences.Add(line.Points != 0 ? line.Lyrics : String.Empty); // find equal sentences series List series = new List(); - for (int i = 0; i < lines.LineCount - 1; i++) + for (int i = 0; i < voice.NumLines - 1; i++) { - for (int j = i + 1; j < lines.LineCount; j++) + for (int j = i + 1; j < voice.NumLines; j++) { - if (sentences[i] == sentences[j] && sentences[i].Length > 0) + if (sentences[i] != sentences[j] || sentences[i] == "") + continue; + SSeries tempSeries = new SSeries {Start = i, End = i}; + + int max; + if (j + j - i > voice.NumLines) + max = voice.NumLines - 1 - j; + else + max = j - i - 1; + + for (int k = 1; k <= max; k++) { - SSeries tempSeries = new SSeries(); - tempSeries.Start = i; - tempSeries.End = i; - - int max = 0; - if (j + j - i - 1 > lines.LineCount - 1) - max = lines.LineCount - 1 - j; + if (sentences[i + k] == sentences[j + k] && sentences[i + k] != "") + tempSeries.End = i + k; else - max = j - i - 1; - - for (int k = 1; k <= max; k++) - { - if (sentences[i + k] == sentences[j + k] && sentences[i + k].Length > 0) - tempSeries.End = i + k; - else - break; - } - - tempSeries.Length = tempSeries.End - tempSeries.Start + 1; - series.Add(tempSeries); + break; } + + tempSeries.Length = tempSeries.End - tempSeries.Start + 1; + series.Add(tempSeries); } } return series; @@ -954,30 +942,28 @@ namespace VocaluxeLib.Menu.SongMenu longest = i; } - CLines lines = Notes.GetLines(0); + CVoice voice = Notes.GetVoice(0); // set medley vars if (series.Count > 0 && series[longest].Length > CBase.Settings.GetMedleyMinSeriesLength()) { - Medley.StartBeat = lines.Line[series[longest].Start].FirstNoteBeat; - Medley.EndBeat = lines.Line[series[longest].End].LastNoteBeat; + Medley.StartBeat = voice.Lines[series[longest].Start].FirstNoteBeat; + Medley.EndBeat = voice.Lines[series[longest].End].LastNoteBeat; - bool foundEnd = false; + bool foundEnd = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) + CBase.Settings.GetMedleyMinDuration() > + CBase.Game.GetTimeFromBeats(Medley.EndBeat, BPM); // set end if duration > MedleyMinDuration - if (CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) + CBase.Settings.GetMedleyMinDuration() > - CBase.Game.GetTimeFromBeats(Medley.EndBeat, BPM)) - foundEnd = true; if (!foundEnd) { - for (int i = series[longest].Start + 1; i < lines.LineCount - 1; i++) + for (int i = series[longest].Start + 1; i < voice.NumLines - 1; i++) { if (CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) + CBase.Settings.GetMedleyMinDuration() > - CBase.Game.GetTimeFromBeats(lines.Line[i].LastNoteBeat, BPM)) + CBase.Game.GetTimeFromBeats(voice.Lines[i].LastNoteBeat, BPM)) { foundEnd = true; - Medley.EndBeat = lines.Line[i].LastNoteBeat; + Medley.EndBeat = voice.Lines[i].LastNoteBeat; } } } @@ -990,7 +976,7 @@ namespace VocaluxeLib.Menu.SongMenu } } - if (PreviewStart == 0f) + if (Math.Abs(PreviewStart) < 0.001) { if (Medley.Source == EMedleySource.Calculated) PreviewStart = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM); @@ -1003,45 +989,37 @@ namespace VocaluxeLib.Menu.SongMenu if (series == null) return; - CLines lines = Notes.GetLines(0); + CVoice voice = Notes.GetVoice(0); //Calculate length of singing - int stop = (lines.Line[lines.Line.Length - 1].LastNoteBeat - lines.Line[0].FirstNote.StartBeat) / 2 + lines.Line[0].FirstNote.StartBeat; + int stop = (voice.Lines[voice.Lines.Length - 1].LastNoteBeat - voice.Lines[0].FirstNote.StartBeat) / 2 + voice.Lines[0].FirstNote.StartBeat; //Check if stop is in series for (int i = 0; i < series.Count; i++) { - if (lines.Line[series[i].Start].FirstNoteBeat < stop && lines.Line[series[i].End].LastNoteBeat > stop) + if (voice.Lines[series[i].Start].FirstNoteBeat < stop && voice.Lines[series[i].End].LastNoteBeat > stop) { - if (stop < (lines.Line[series[i].Start].FirstNoteBeat + ((lines.Line[series[i].End].LastNoteBeat - lines.Line[series[i].Start].FirstNoteBeat) / 2))) + if (stop < (voice.Lines[series[i].Start].FirstNoteBeat + ((voice.Lines[series[i].End].LastNoteBeat - voice.Lines[series[i].Start].FirstNoteBeat) / 2))) { - ShortEnd = lines.Line[series[i].Start - 1].LastNote.EndBeat; - return; - } - else - { - ShortEnd = lines.Line[series[i].End].LastNote.EndBeat; + ShortEnd = voice.Lines[series[i].Start - 1].LastNote.EndBeat; return; } + ShortEnd = voice.Lines[series[i].End].LastNote.EndBeat; + return; } } //Check if stop is in line - for (int i = 0; i < lines.Line.Length; i++) + foreach (CLine line in voice.Lines) { - if (lines.Line[i].FirstNoteBeat < stop && lines.Line[i].LastNoteBeat > stop) + if (line.FirstNoteBeat < stop && line.LastNoteBeat > stop) { - ShortEnd = lines.Line[i].LastNoteBeat; + ShortEnd = line.LastNoteBeat; return; } } ShortEnd = stop; } - - public object Clone() - { - return MemberwiseClone(); - } } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs index 4c46093b..d70f4393 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs @@ -1,4 +1,23 @@ -using System.Xml; +#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.Xml; using VocaluxeLib.PartyModes; namespace VocaluxeLib.Menu.SongMenu diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuBook.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuBook.cs index e8503b9b..5bb8bb93 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuBook.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuBook.cs @@ -1,4 +1,23 @@ -namespace VocaluxeLib.Menu.SongMenu +#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 VocaluxeLib.Menu.SongMenu { class CSongMenuBook : CSongMenuFramework { diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuDreidel.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuDreidel.cs index b38a53fd..bfbad2a0 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuDreidel.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuDreidel.cs @@ -1,4 +1,23 @@ -namespace VocaluxeLib.Menu.SongMenu +#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 VocaluxeLib.Menu.SongMenu { class CSongMenuDreidel : CSongMenuFramework { @@ -21,9 +40,11 @@ return _actualSelection; } */ + public CSongMenuDreidel(int partyModeID) : base(partyModeID) {} + // ReSharper disable RedundantOverridenMember public override void Init() { base.Init(); @@ -38,5 +59,7 @@ _SongLength = _Theme.songMenuDreidel.TextSongLength; **/ } + + // ReSharper restore RedundantOverridenMember } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 3ada6f36..77d3f50b 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -1,4 +1,23 @@ -using System; +#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.Diagnostics; using System.IO; @@ -27,12 +46,6 @@ namespace VocaluxeLib.Menu.SongMenu public SThemeSongMenuTileBoard SongMenuTileBoard; } - struct SThemeSongMenuBook {} - - struct SThemeSongMenuDreidel {} - - struct SThemeSongMenuList {} - struct SThemeSongMenuTileBoard { /// @@ -82,7 +95,7 @@ namespace VocaluxeLib.Menu.SongMenu abstract class CSongMenuFramework : ISongMenu { - protected int _PartyModeID; + protected readonly int _PartyModeID; protected SThemeSongMenu _Theme; private bool _ThemeLoaded; @@ -93,19 +106,19 @@ namespace VocaluxeLib.Menu.SongMenu private int _Actsongstream = -1; protected STexture _Vidtex = new STexture(-1); - protected bool _Initialized = false; - protected int _LastKnownNumSongs = 0; + protected bool _Initialized; + protected int _LastKnownNumSongs; protected int _LastKnownCategory = -1; - protected SRectF _Rect = new SRectF(); - protected SColorF _Color = new SColorF(); + protected SRectF _Rect; + protected SColorF _Color; private int _SelectedInternal = -1; private int _SelectedPending = -1; protected long _PendingTime = 500L; private int _LockedInternal = -1; - protected bool _Active = false; + protected bool _Active; protected float _MaxVolume = 100f; @@ -151,7 +164,7 @@ namespace VocaluxeLib.Menu.SongMenu } } - protected virtual void _SetSelectedNow() + protected void _SetSelectedNow() { _Timer.Stop(); _Timer.Reset(); @@ -221,21 +234,24 @@ namespace VocaluxeLib.Menu.SongMenu _Visible = visible; } - public CSongMenuFramework(int partyModeID) + protected CSongMenuFramework(int partyModeID) { _PartyModeID = partyModeID; - _Theme = new SThemeSongMenu(); - - _Theme.SongMenuTileBoard.TextArtist = new CText(_PartyModeID); - _Theme.SongMenuTileBoard.TextTitle = new CText(_PartyModeID); - _Theme.SongMenuTileBoard.TextSongLength = new CText(_PartyModeID); - - _Theme.SongMenuTileBoard.StaticCoverBig = new CStatic(_PartyModeID); - _Theme.SongMenuTileBoard.StaticTextBG = new CStatic(_PartyModeID); - _Theme.SongMenuTileBoard.StaticDuetIcon = new CStatic(_PartyModeID); - _Theme.SongMenuTileBoard.StaticVideoIcon = new CStatic(_PartyModeID); - _Theme.SongMenuTileBoard.StaticMedleyCalcIcon = new CStatic(_PartyModeID); - _Theme.SongMenuTileBoard.StaticMedleyTagIcon = new CStatic(_PartyModeID); + _Theme = new SThemeSongMenu + { + SongMenuTileBoard = + { + TextArtist = new CText(_PartyModeID), + TextTitle = new CText(_PartyModeID), + TextSongLength = new CText(_PartyModeID), + StaticCoverBig = new CStatic(_PartyModeID), + StaticTextBG = new CStatic(_PartyModeID), + StaticDuetIcon = new CStatic(_PartyModeID), + StaticVideoIcon = new CStatic(_PartyModeID), + StaticMedleyCalcIcon = new CStatic(_PartyModeID), + StaticMedleyTagIcon = new CStatic(_PartyModeID) + } + }; _ThemeLoaded = false; } @@ -250,14 +266,14 @@ namespace VocaluxeLib.Menu.SongMenu string item = xmlPath + "/" + elementName; _ThemeLoaded = true; - _ThemeLoaded &= xmlReader.GetValue(item + "/CoverBackground", ref _Theme.CoverBackgroundName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/CoverBigBackground", ref _Theme.CoverBigBackgroundName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/DuetIcon", ref _Theme.DuetIconName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/VideoIcon", ref _Theme.VideoIconName, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/MedleyCalcIcon", ref _Theme.MedleyCalcIcon, String.Empty); - _ThemeLoaded &= xmlReader.GetValue(item + "/MedleyTagIcon", ref _Theme.MedleyTagIcon, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/CoverBackground", out _Theme.CoverBackgroundName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/CoverBigBackground", out _Theme.CoverBigBackgroundName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/DuetIcon", out _Theme.DuetIconName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/VideoIcon", out _Theme.VideoIconName, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/MedleyCalcIcon", out _Theme.MedleyCalcIcon, String.Empty); + _ThemeLoaded &= xmlReader.GetValue(item + "/MedleyTagIcon", out _Theme.MedleyTagIcon, String.Empty); - if (xmlReader.GetValue(item + "/Color", ref _Theme.ColorName, String.Empty)) + if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out _Color); else { @@ -336,7 +352,7 @@ namespace VocaluxeLib.Menu.SongMenu writer.WriteComment(": Tile color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") writer.WriteElementString("Color", _Theme.ColorName); else { @@ -409,7 +425,7 @@ namespace VocaluxeLib.Menu.SongMenu _Initialized = true; } - public virtual void UpdateRect(SRectF rect) + public void UpdateRect(SRectF rect) { _Rect = rect; Init(); @@ -434,8 +450,8 @@ namespace VocaluxeLib.Menu.SongMenu float time = CBase.Sound.GetPosition(_Actsongstream); - float vtime = 0f; - CBase.Video.GetFrame(_Video, ref _Vidtex, time, ref vtime); + float vtime; + CBase.Video.GetFrame(_Video, ref _Vidtex, time, out vtime); if (_VideoFadeTimer.ElapsedMilliseconds <= 3000L) _Vidtex.Color.A = _VideoFadeTimer.ElapsedMilliseconds / 3000f; else @@ -468,17 +484,9 @@ namespace VocaluxeLib.Menu.SongMenu _SelectedInternal = _SelectedPending; } - public virtual void HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions songOptions) - { - if (!_Initialized) - return; - } + public virtual void HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions songOptions) {} - public virtual void HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) - { - if (!_Initialized) - return; - } + public virtual void HandleMouse(ref SMouseEvent mouseEvent, SScreenSongOptions songOptions) {} public virtual void Draw() { @@ -522,23 +530,11 @@ namespace VocaluxeLib.Menu.SongMenu return -1; } - public virtual void SetSelectedSong(int visibleSongNr) - { - if (!_Initialized) - return; - } + public virtual void SetSelectedSong(int visibleSongNr) {} - public virtual void SetSelectedCategory(int categoryNr) - { - if (!_Initialized) - return; - } + public virtual void SetSelectedCategory(int categoryNr) {} - public virtual void SetSmallView(bool smallView) - { - if (!_Initialized) - return; - } + public virtual void SetSmallView(bool smallView) {} public virtual bool IsSmallView() { @@ -551,7 +547,7 @@ namespace VocaluxeLib.Menu.SongMenu { Init(); - if (_Theme.ColorName.Length > 0) + if (_Theme.ColorName != "") _Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); } @@ -623,7 +619,7 @@ namespace VocaluxeLib.Menu.SongMenu float startposition = CBase.Songs.GetVisibleSong(_Actsong).PreviewStart; - if (startposition == 0f) + if (Math.Abs(startposition) < 0.001) startposition = CBase.Sound.GetLength(stream) / 4f; CBase.Sound.SetPosition(stream, startposition); @@ -632,7 +628,7 @@ namespace VocaluxeLib.Menu.SongMenu _Streams.Add(stream); _Actsongstream = stream; - if (CBase.Songs.GetVisibleSong(_Actsong).VideoFileName.Length > 0 && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON) + if (CBase.Songs.GetVisibleSong(_Actsong).VideoFileName != "" && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON) { _Video = CBase.Video.Load(Path.Combine(CBase.Songs.GetVisibleSong(_Actsong).Folder, CBase.Songs.GetVisibleSong(_Actsong).VideoFileName)); if (_Video == -1) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs index 3111472a..ea8b83a5 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuList.cs @@ -1,4 +1,23 @@ -namespace VocaluxeLib.Menu.SongMenu +#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 VocaluxeLib.Menu.SongMenu { class CSongMenuList : CSongMenuFramework { diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index ec382871..6a81f68e 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -1,6 +1,26 @@ -using System; +#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.Linq; using System.Windows.Forms; using VocaluxeLib.PartyModes; @@ -135,7 +155,7 @@ namespace VocaluxeLib.Menu.SongMenu _MedleyTagIcon.Visible = false; } - if (CBase.Songs.GetNumVisibleSongs() == 0 && CBase.Songs.GetSearchFilter().Length > 0) + if (CBase.Songs.GetNumVisibleSongs() == 0 && CBase.Songs.GetSearchFilter() != "") { _CoverBig.Texture = _CoverBigTexture; _Artist.Text = String.Empty; @@ -161,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)) @@ -348,7 +360,7 @@ namespace VocaluxeLib.Menu.SongMenu mouseEvent.Handled = true; return; } - else if (mouseEvent.RB && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && !songOptions.Selection.PartyMode) + if (mouseEvent.RB && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && !songOptions.Selection.PartyMode) CBase.Graphics.FadeTo(EScreens.ScreenMain); else if (_PreviewSelected != -1 && mouseEvent.LB && CBase.Songs.GetCurrentCategoryIndex() != -1 && !songOptions.Selection.PartyMode) { @@ -399,12 +411,12 @@ namespace VocaluxeLib.Menu.SongMenu _Artist.Text = song.Artist; _Title.Text = song.Title; _DuetIcon.Visible = song.IsDuet; - _VideoIcon.Visible = song.VideoFileName.Length > 0; + _VideoIcon.Visible = song.VideoFileName != ""; _MedleyCalcIcon.Visible = song.Medley.Source == EMedleySource.Calculated; _MedleyTagIcon.Visible = song.Medley.Source == EMedleySource.Tag; float time = CBase.Sound.GetLength(_SongStream); - if (song.Finish != 0) + if (Math.Abs(song.Finish) > 0.001) time = song.Finish; time -= song.Start; @@ -444,7 +456,7 @@ namespace VocaluxeLib.Menu.SongMenu _CoverBig.Draw(1f, EAspect.Crop); RectangleF bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H); RectangleF rect = new RectangleF(0f, 0f, _Vidtex.Width, _Vidtex.Height); - CHelper.SetRect(bounds, ref rect, rect.Width / rect.Height, EAspect.Crop); + CHelper.SetRect(bounds, out rect, rect.Width / rect.Height, EAspect.Crop); SRectF vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); SRectF vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); @@ -481,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/SongMenu/ISongMenu.cs b/VocaluxeLib/Menu/SongMenu/ISongMenu.cs index c24c8d51..060a8cf4 100644 --- a/VocaluxeLib/Menu/SongMenu/ISongMenu.cs +++ b/VocaluxeLib/Menu/SongMenu/ISongMenu.cs @@ -1,4 +1,23 @@ -using VocaluxeLib.PartyModes; +#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 VocaluxeLib.PartyModes; namespace VocaluxeLib.Menu.SongMenu { diff --git a/VocaluxeLib/Menu/Structs.cs b/VocaluxeLib/Menu/Structs.cs index fc792831..76dbc466 100644 --- a/VocaluxeLib/Menu/Structs.cs +++ b/VocaluxeLib/Menu/Structs.cs @@ -1,11 +1,30 @@ -using System; +#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.Windows.Forms; - using VocaluxeLib.Menu.SingNotes; namespace VocaluxeLib.Menu { + #region Drawing public struct SColorF { @@ -118,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) { @@ -152,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; @@ -187,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; } @@ -231,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); @@ -243,8 +242,6 @@ namespace VocaluxeLib.Menu public struct SPlayer { public int ProfileID; - public string Name; - public EGameDifficulty Difficulty; public double Points; public double PointsLineBonus; public double PointsGoldenNotes; diff --git a/VocaluxeLib/PartyModes/CPartyMode.cs b/VocaluxeLib/PartyModes/CPartyMode.cs index 32c425f9..cbc74a52 100644 --- a/VocaluxeLib/PartyModes/CPartyMode.cs +++ b/VocaluxeLib/PartyModes/CPartyMode.cs @@ -1,4 +1,23 @@ -using System; +#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 VocaluxeLib.Menu; @@ -7,16 +26,12 @@ namespace VocaluxeLib.PartyModes public abstract class CPartyMode : IPartyMode { protected SScreenSongOptions _ScreenSongOptions; - protected Dictionary _Screens; - protected string _Folder; + protected readonly Dictionary _Screens; - public CPartyMode() + protected CPartyMode() { _Screens = new Dictionary(); - _Folder = String.Empty; - _ScreenSongOptions = new SScreenSongOptions(); - _ScreenSongOptions.Selection = new SSelectionOptions(); - _ScreenSongOptions.Sorting = new SSortingOptions(); + _ScreenSongOptions = new SScreenSongOptions {Selection = new SSelectionOptions(), Sorting = new SSortingOptions()}; } #region Implementation diff --git a/VocaluxeLib/PartyModes/CPartyModeNone.cs b/VocaluxeLib/PartyModes/CPartyModeNone.cs index 00422ab8..bb75b0b0 100644 --- a/VocaluxeLib/PartyModes/CPartyModeNone.cs +++ b/VocaluxeLib/PartyModes/CPartyModeNone.cs @@ -1,4 +1,23 @@ -using System; +#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 VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes diff --git a/VocaluxeLib/PartyModes/CScreenPartyDummy.cs b/VocaluxeLib/PartyModes/CScreenPartyDummy.cs index b67deb71..e27fa1ce 100644 --- a/VocaluxeLib/PartyModes/CScreenPartyDummy.cs +++ b/VocaluxeLib/PartyModes/CScreenPartyDummy.cs @@ -1,4 +1,23 @@ -using System.Windows.Forms; +#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.Windows.Forms; using VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes @@ -23,7 +42,7 @@ namespace VocaluxeLib.PartyModes _Warning.Color = new SColorF(1f, 0f, 0f, 1f); _Warning.SelColor = new SColorF(1f, 0f, 0f, 1f); _Warning.Text = "SOMETHING WENT WRONG!"; - AddText(_Warning); + _AddText(_Warning); } public override void ReloadTheme(string xmlPath) {} @@ -56,7 +75,7 @@ namespace VocaluxeLib.PartyModes { base.HandleMouse(mouseEvent); - if (mouseEvent.LB && IsMouseOver(mouseEvent)) {} + if (mouseEvent.LB && _IsMouseOver(mouseEvent)) {} if (mouseEvent.RB) _FadeTo(EScreens.ScreenParty); diff --git a/VocaluxeLib/PartyModes/IPartyMode.cs b/VocaluxeLib/PartyModes/IPartyMode.cs index 5d2fa8bb..a747638d 100644 --- a/VocaluxeLib/PartyModes/IPartyMode.cs +++ b/VocaluxeLib/PartyModes/IPartyMode.cs @@ -1,4 +1,23 @@ -using System; +#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 VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes diff --git a/VocaluxeLib/Properties/AssemblyInfo.cs b/VocaluxeLib/Properties/AssemblyInfo.cs index 48dc08f0..0820e156 100644 --- a/VocaluxeLib/Properties/AssemblyInfo.cs +++ b/VocaluxeLib/Properties/AssemblyInfo.cs @@ -1,9 +1,29 @@ -using System.Reflection; +#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.Reflection; using System.Runtime.InteropServices; // Allgemeine Informationen über eine Assembly werden über die folgenden // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // die mit einer Assembly verknüpft sind. + [assembly: AssemblyTitle("VocaluxeLib")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] @@ -16,9 +36,11 @@ using System.Runtime.InteropServices; // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. + [assembly: ComVisible(false)] // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird + [assembly: Guid("3fb7cd34-186d-4f89-beb5-8830b8e5593b")] // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: @@ -31,5 +53,6 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] + [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index 038db9ed..e9d4bd1e 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -137,7 +137,6 @@ -