|
From: <Sil...@us...> - 2010-05-07 09:36:14
|
Revision: 3585
http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3585&view=rev
Author: SilentException
Date: 2010-05-07 09:36:03 +0000 (Fri, 07 May 2010)
Log Message:
-----------
Additional optimizations and improvements
Buttons with id 4 5 changed to select buttons
Added code to prevent locking when no music is available
Modified Paths:
--------------
trunk/plugins/MusicTrivia/Languages/en-US.xml
trunk/plugins/MusicTrivia/MusicTrivia/MusicTriviaGUI.cs
trunk/plugins/MusicTrivia/MusicTrivia/Translation.cs
trunk/plugins/MusicTrivia/Skin/Blue3wide/MusicTrivia.xml
Modified: trunk/plugins/MusicTrivia/Languages/en-US.xml
===================================================================
--- trunk/plugins/MusicTrivia/Languages/en-US.xml 2010-05-06 21:54:04 UTC (rev 3584)
+++ trunk/plugins/MusicTrivia/Languages/en-US.xml 2010-05-07 09:36:03 UTC (rev 3585)
@@ -67,6 +67,7 @@
<string Field="TimesUp">Time's Up!</string>
<string Field="Timer">Timer</string>
<string Field="TimeLeft">Time left</string>
+ <string Field="Timeout">Error (timeout) getting next track\nfor the game.\nIs your music available?</string>
<!-- U -->
@@ -78,6 +79,6 @@
<!-- Y -->
<string Field="YouEarnedPoints">You've earned {0} points.</string>
- <string Field="YouDontHaveEnoughSongs">You don't have enough songs\nof selected genre ({0})\nin your music database for the game!\nSelect different genre.</string>
+ <string Field="YouDontHaveEnoughSongs">You don't have enough tracks\nof selected genre ({0})\nin your music database for the game!\nSelect different genre.</string>
</strings>
Modified: trunk/plugins/MusicTrivia/MusicTrivia/MusicTriviaGUI.cs
===================================================================
--- trunk/plugins/MusicTrivia/MusicTrivia/MusicTriviaGUI.cs 2010-05-06 21:54:04 UTC (rev 3584)
+++ trunk/plugins/MusicTrivia/MusicTrivia/MusicTriviaGUI.cs 2010-05-07 09:36:03 UTC (rev 3585)
@@ -17,9 +17,14 @@
[SkinControlAttribute(3)]
GUIButtonControl stopBtn = null;
[SkinControlAttribute(4)]
- GUIButtonControl triesBtn = null;
+ GUISelectButtonControl triesBtn = null;
[SkinControlAttribute(5)]
- GUIButtonControl timerBtn = null;
+ GUISelectButtonControl timerBtn = null;
+ //optional - TODO
+ //[SkinControlAttribute(6)]
+ //GUIButtonControl genreSelectionButton = null;
+ //[SkinControlAttribute(7)]
+ //GUIButtonControl playerSelectionButton = null;
[SkinControlAttribute(11)]
GUILabelControl timerLabel = null;
@@ -65,6 +70,7 @@
private int scorePlayer1 = 0;
private int scorePlayer2 = 0;
private System.Windows.Forms.Timer countDownTimer = new System.Windows.Forms.Timer();
+ private System.Windows.Forms.Timer preventLockTimer = new System.Windows.Forms.Timer();
private System.Threading.Thread updateThread = null;
private int timerDelay;
private int tries;
@@ -78,6 +84,11 @@
private int answers;
private bool disableEvent = false;
private const string emptyGenreFilter = "SELECT * FROM tracks WHERE strGenre like '%| |%' ORDER BY strTitle ASC";
+ private const string checkValidSongsLastGenreDEF = "***";
+ private string checkValidSongsLastGenre = checkValidSongsLastGenreDEF;
+ private bool checkValidSongsLastResult = false;
+ private int[] validTries = { 1, 2, 3 };
+ private int[] validTimerDelays = { 10, 15, 30, 60 };
#endregion
#region Constructor
@@ -142,17 +153,20 @@
#region GUIWindow overrides
public override bool Init()
{
+ preventLockTimer.Interval = 5000;
Translation.TranslateSkin();
return Load(GUIGraphicsContext.Skin + "\\MusicTrivia.xml");
}
protected override void OnPageDestroy(int new_windowId)
{
- doStop();
+ doStop(false);
countDownTimer.Tick -= doCountDownTimer;
+ preventLockTimer.Tick -= doPreventLockTimer;
g_Player.PlayBackStopped -= g_Player_PlayBackStopped;
+ g_Player.PlayBackChanged -= g_Player_PlayBackChanged;
if (settingsChanged == true)
{
@@ -166,15 +180,22 @@
{
GUIPropertyManager.SetProperty("#currentmodule", "Music Trivia");
+ triesBtn.RestoreSelection = false;
+ timerBtn.RestoreSelection = false;
+
doStopSkinActions();
listBox.Clear();
listBox.Disabled = true;
countDownTimer.Tick += doCountDownTimer;
+ preventLockTimer.Tick += doPreventLockTimer;
g_Player.PlayBackStopped += new g_Player.StoppedHandler(g_Player_PlayBackStopped);
+ g_Player.PlayBackChanged += new g_Player.ChangedHandler(g_Player_PlayBackChanged);
+ checkValidSongsLastGenre = checkValidSongsLastGenreDEF;
+
gameType = "1p";
timerDelay = 15;
tries = 2;
@@ -185,6 +206,7 @@
loadSettings();
settingsChanged = false;
+ initSelectButtons();
timerBtn.Label = String.Format(Translation.Time, timerDelay.ToString());
triesBtn.Label = String.Format(Translation.Tries, tries.ToString());
@@ -208,6 +230,33 @@
setupText();
}
+ private void initSelectButtons()
+ {
+ int selected, i;
+
+ i = 0;
+ selected = 0;
+ foreach (int validTry in validTries)
+ {
+ GUIControl.AddItemLabelControl(GetID, triesBtn.GetID, String.Format(Translation.Tries, validTry.ToString()));
+ if (validTry == tries)
+ selected = i;
+ i++;
+ }
+ GUIControl.SelectItemControl(GetID, triesBtn.GetID, selected);
+
+ i = 0;
+ selected = 0;
+ foreach (int validTimerDelay in validTimerDelays)
+ {
+ GUIControl.AddItemLabelControl(GetID, timerBtn.GetID, String.Format(Translation.Time, validTimerDelay.ToString()));
+ if (validTimerDelay == timerDelay)
+ selected = i;
+ i++;
+ }
+ GUIControl.SelectItemControl(GetID, timerBtn.GetID, selected);
+ }
+
protected override void OnClicked(int controlId, MediaPortal.GUI.Library.GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
{
if (control == startBtn)
@@ -233,12 +282,19 @@
if (control == stopBtn)
{
- doStop();
+ doStop(true);
GUIControl.FocusControl(GetID, startBtn.GetID);
}
if (control == timerBtn)
{
+ GUIControl.SelectItemControl(GetID, timerBtn.GetID, timerBtn.SelectedItem);
+ timerDelay = validTimerDelays[timerBtn.SelectedItem];
+ timerBtn.Label = String.Format(Translation.Time, timerDelay.ToString());
+ settingsChanged = true;
+ clearStatistics();
+
+ /*
switch (timerDelay)
{
case 60:
@@ -257,10 +313,18 @@
timerBtn.Label = String.Format(Translation.Time, timerDelay.ToString());
settingsChanged = true;
clearStatistics();
+ */
}
if (control == triesBtn)
{
+ GUIControl.SelectItemControl(GetID, triesBtn.GetID, triesBtn.SelectedItem);
+ tries = validTries[triesBtn.SelectedItem];
+ triesBtn.Label = String.Format(Translation.Tries, tries.ToString());
+ settingsChanged = true;
+ clearStatistics();
+
+ /*
switch (tries)
{
case 1:
@@ -276,6 +340,7 @@
triesBtn.Label = String.Format(Translation.Tries, tries.ToString());
settingsChanged = true;
clearStatistics();
+ */
}
base.OnClicked(controlId, control, actionType);
@@ -727,18 +792,27 @@
}
}
- private void doStop()
+ private void doStop(bool alwaysStopGPlayer)
{
+ bool haveToStopGPlayer = isPlaying();
+
GUIPropertyManager.SetProperty("#MusicTrivia.Game.InProgress", false.ToString());
+ doStopCommonActions();
+
+ if (alwaysStopGPlayer || haveToStopGPlayer)
+ stopGPlayer();
+
+ doStopSkinActions();
+ clearGameLabels();
+ }
+
+ private void doStopCommonActions()
+ {
if (updateThread != null && updateThread.IsAlive)
updateThread.Abort();
countDownTimer.Stop();
- stopGPlayer();
-
- doStopSkinActions();
- clearGameLabels();
}
private void doStopSkinActions()
@@ -774,11 +848,19 @@
MediaPortal.Music.Database.Song randomwrong2 = new MediaPortal.Music.Database.Song();
MediaPortal.Music.Database.Song randomwrong3 = new MediaPortal.Music.Database.Song();
+ preventLockTimer.Start();
if (currGenre == Translation._ALL)
{
MediaPortal.Music.Database.MusicDatabase.Instance.GetRandomSong(ref randomPlayingSong);
while (randomPlayingSong.Duration < timerDelay * 2 || !System.IO.File.Exists(randomPlayingSong.FileName))
{
+ if (!preventLockTimer.Enabled)
+ {
+ doStop(true);
+ ShowOKDialog(Translation.Warning, Translation.Timeout);
+ return;
+ }
+ System.Windows.Forms.Application.DoEvents(); //timer
MediaPortal.Music.Database.MusicDatabase.Instance.GetRandomSong(ref randomPlayingSong);
}
@@ -791,6 +873,13 @@
randomPlayingSong = genreSongs[randomNum.Next(0, genreSongs.Count - 1)];
while (randomPlayingSong.Duration < timerDelay * 2 || !System.IO.File.Exists(randomPlayingSong.FileName))
{
+ if (!preventLockTimer.Enabled)
+ {
+ doStop(true);
+ ShowOKDialog(Translation.Warning, Translation.Timeout);
+ return;
+ }
+ System.Windows.Forms.Application.DoEvents(); //timer
randomPlayingSong = genreSongs[randomNum.Next(0, genreSongs.Count - 1)];
}
@@ -798,6 +887,7 @@
randomwrong2 = genreSongs[randomNum.Next(0, genreSongs.Count - 1)];
randomwrong3 = genreSongs[randomNum.Next(0, genreSongs.Count - 1)];
}
+ preventLockTimer.Stop();
System.Collections.ArrayList choices = new System.Collections.ArrayList();
choices.Add(randomPlayingSong);
@@ -985,6 +1075,11 @@
doStart();
}
+ private void doPreventLockTimer(object source, EventArgs e)
+ {
+ preventLockTimer.Stop();
+ }
+
private string getThumb(MediaPortal.Music.Database.Song song)
{
string thumb = string.Empty;
@@ -1006,6 +1101,9 @@
private bool checkValidSongs(string currentGenre, bool useDialog)
{
+ if (checkValidSongsLastGenre == currentGenre)
+ return checkValidSongsLastResult;
+
int foundSongs = 0;
List<MediaPortal.Music.Database.Song> songs = new List<MediaPortal.Music.Database.Song>();
@@ -1038,14 +1136,17 @@
}
}
+ checkValidSongsLastGenre = currentGenre;
if (foundSongs < 4)
{
if (useDialog)
{
ShowOKDialog(Translation.Warning, String.Format(Translation.YouDontHaveEnoughSongs, currentGenre));
}
+ checkValidSongsLastResult = false;
return false;
}
+ checkValidSongsLastResult = true;
return true;
}
@@ -1096,11 +1197,32 @@
private void playbackStoppedActions()
{
- doStop();
- GUIWindowManager.Process();
- GUIControl.DisableControl(GetID, listBox.GetID);
- GUIControl.FocusControl(GetID, 500);
+ if (isPlaying())
+ {
+ doStop(false);
+ GUIWindowManager.Process();
+ GUIControl.DisableControl(GetID, listBox.GetID);
+ GUIControl.FocusControl(GetID, 500);
+ }
}
+
+ void g_Player_PlayBackChanged(g_Player.MediaType type, int stoptime, string filename)
+ {
+ if (isPlaying())
+ {
+ doStopCommonActions();
+ doStopSkinActions();
+ clearGameLabels();
+ }
+ }
+
+ private static bool isPlaying()
+ {
+ string playing = GUIPropertyManager.GetProperty("#MusicTrivia.Game.InProgress");
+ if (!string.IsNullOrEmpty(playing) && playing == true.ToString())
+ return true;
+ return false;
+ }
#endregion
}
}
Modified: trunk/plugins/MusicTrivia/MusicTrivia/Translation.cs
===================================================================
--- trunk/plugins/MusicTrivia/MusicTrivia/Translation.cs 2010-05-06 21:54:04 UTC (rev 3584)
+++ trunk/plugins/MusicTrivia/MusicTrivia/Translation.cs 2010-05-07 09:36:03 UTC (rev 3585)
@@ -256,6 +256,7 @@
public static string TimesUp = "Time's Up!";
public static string Timer = "Timer";
public static string TimeLeft = "Time left";
+ public static string Timeout = "Error (timeout) getting next track\nfor the game.\nIs your music available?";
// U
@@ -267,7 +268,7 @@
// Y
public static string YouEarnedPoints = "You've earned {0} points.";
- public static string YouDontHaveEnoughSongs = "You don't have enough songs\nof selected genre ({0})\nin your music database for the game!\nSelect different genre.";
+ public static string YouDontHaveEnoughSongs = "You don't have enough tracks\nof selected genre ({0})\nin your music database for the game!\nSelect different genre.";
#endregion
}
}
\ No newline at end of file
Modified: trunk/plugins/MusicTrivia/Skin/Blue3wide/MusicTrivia.xml
===================================================================
--- trunk/plugins/MusicTrivia/Skin/Blue3wide/MusicTrivia.xml 2010-05-06 21:54:04 UTC (rev 3584)
+++ trunk/plugins/MusicTrivia/Skin/Blue3wide/MusicTrivia.xml 2010-05-07 09:36:03 UTC (rev 3585)
@@ -32,7 +32,7 @@
</control>
<control>
<description>Tries</description>
- <type>button</type>
+ <type>selectbutton</type>
<id>4</id>
<posX>60</posX>
<posY>201</posY>
@@ -44,7 +44,7 @@
</control>
<control>
<description>Time</description>
- <type>button</type>
+ <type>selectbutton</type>
<id>5</id>
<posX>60</posX>
<posY>241</posY>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|