gbrainy r322 - trunk/src



Author: jmas
Date: Fri May  9 10:49:34 2008
New Revision: 322
URL: http://svn.gnome.org/viewvc/gbrainy?rev=322&view=rev

Log:
2008-05-09 Jordi Mas <jmas softcatala org>

	* PlayerHistory.cs: New clean method and use preference settings
	* Preferences.cs: Player's history preferences
	* PreferencesDialog.cs: Player's history preferences
	* gbrainy.glade: Player's history preferences



Modified:
   trunk/src/ChangeLog
   trunk/src/PlayerHistory.cs
   trunk/src/Preferences.cs
   trunk/src/PreferencesDialog.cs
   trunk/src/gbrainy.glade

Modified: trunk/src/PlayerHistory.cs
==============================================================================
--- trunk/src/PlayerHistory.cs	(original)
+++ trunk/src/PlayerHistory.cs	Fri May  9 10:49:34 2008
@@ -52,11 +52,17 @@
 		get { return games; }
 	}
 
+	public void Clean ()
+	{
+		games.Clear ();
+		Save ();
+	}
+
 	public void SaveGameSession (GameSession session)
 	{
 		GameHistory history = new GameHistory ();
 
-		if (session.GamesPlayed == 0)
+		if (session.GamesPlayed < gbrainy.preferences.GetIntValue (Preferences.MinPlayedGamesKey))
 			return;
 	
 		history.games_played = session.GamesPlayed;
@@ -69,11 +75,15 @@
 		if (!Directory.Exists (config_path))
 			Directory.CreateDirectory (config_path);
 
-		if (games.Count >= 20) // Record the last 20 games
+		if (games.Count >= gbrainy.preferences.GetIntValue (Preferences.MaxStoredGamesKey))
 			games.RemoveAt (0);
 
 		games.Add (history);
+		Save ();
+	}
 
+	private void Save ()
+	{
 		try {
 
 			using (FileStream str = File.Create (file))

Modified: trunk/src/Preferences.cs
==============================================================================
--- trunk/src/Preferences.cs	(original)
+++ trunk/src/Preferences.cs	Fri May  9 10:49:34 2008
@@ -32,6 +32,8 @@
 	static public string MemQuestionWarnKey = "MemQuestionWarn";
 	static public string MemQuestionTimeKey = "MemQuestionTime";
 	static public string DifficultyKey = "Difficulty";
+	static public string MinPlayedGamesKey = "MinPlayedGames";
+	static public string MaxStoredGamesKey = "MaxStoredGamesKey";
 
 	static private string element_item = "item";
 	static private string element_key = "key";
@@ -150,19 +152,22 @@
 	{
 		properties.Add (MemQuestionWarnKey, true.ToString ());
 		properties.Add (MemQuestionTimeKey, "4");
-		properties.Add (DifficultyKey, ((int)(Game.Difficulty.Medium)).ToString ());		
+		properties.Add (DifficultyKey, ((int)(Game.Difficulty.Medium)).ToString ());
+		properties.Add (MinPlayedGamesKey, "5");
+		properties.Add (MaxStoredGamesKey, "50");	
 	}
 
 	private void Load ()
 	{
 		try {
+			LoadDefaultValues ();
 			XmlTextReader reader = new XmlTextReader (file);
 			properties.ReadXml (reader);
 			reader.Close ();
 		}
 		catch (Exception)
 		{
-			LoadDefaultValues ();
+			
 		}
 	}
 	

Modified: trunk/src/PreferencesDialog.cs
==============================================================================
--- trunk/src/PreferencesDialog.cs	(original)
+++ trunk/src/PreferencesDialog.cs	Fri May  9 10:49:34 2008
@@ -26,6 +26,8 @@
 public class PreferencesDialog : GtkDialog
 {
 	[Glade.Widget] Gtk.SpinButton prefspinbutton;
+	[Glade.Widget] Gtk.SpinButton maxstoredspinbutton;
+	[Glade.Widget] Gtk.SpinButton minplayedspinbutton;
 	[Glade.Widget] Gtk.CheckButton prefcheckbutton;
 	[Glade.Widget] Gtk.RadioButton rb_easy;
 	[Glade.Widget] Gtk.RadioButton rb_medium;
@@ -35,6 +37,8 @@
 	{
 		prefspinbutton.Value = gbrainy.preferences.GetIntValue (Preferences.MemQuestionTimeKey);
 		prefcheckbutton.Active = gbrainy.preferences.GetBoolValue (Preferences.MemQuestionWarnKey);
+		maxstoredspinbutton.Value = gbrainy.preferences.GetIntValue (Preferences.MaxStoredGamesKey);
+		minplayedspinbutton.Value = gbrainy.preferences.GetIntValue (Preferences.MinPlayedGamesKey);
 			
 		switch ((Game.Difficulty) gbrainy.preferences.GetIntValue (Preferences.DifficultyKey)) {
 		case Game.Difficulty.Easy:
@@ -62,11 +66,19 @@
 		}
 	}
 
+
+	private void OnCleanHistory (object sender, EventArgs args)
+	{
+		gbrainy.history.Clean ();
+	}
+
 	private void OnOK (object sender, EventArgs args)
 	{
 		gbrainy.preferences.SetIntValue (Preferences.MemQuestionTimeKey, (int) prefspinbutton.Value);
 		gbrainy.preferences.SetBoolValue (Preferences.MemQuestionWarnKey, prefcheckbutton.Active);
 		gbrainy.preferences.SetIntValue (Preferences.DifficultyKey, (int) Difficulty);
+		gbrainy.preferences.SetIntValue (Preferences.MaxStoredGamesKey, (int) maxstoredspinbutton.Value);
+		gbrainy.preferences.SetIntValue (Preferences.MinPlayedGamesKey, (int) minplayedspinbutton.Value);
 		gbrainy.preferences.Save ();
 	}
 }

Modified: trunk/src/gbrainy.glade
==============================================================================
--- trunk/src/gbrainy.glade	(original)
+++ trunk/src/gbrainy.glade	Fri May  9 10:49:34 2008
@@ -1078,7 +1078,7 @@
 		      <property name="update_policy">GTK_UPDATE_ALWAYS</property>
 		      <property name="snap_to_ticks">False</property>
 		      <property name="wrap">False</property>
-		      <property name="adjustment">4 4 60 1 10 10</property>
+		      <property name="adjustment">0 4 60 1 10 10</property>
 		    </widget>
 		    <packing>
 		      <property name="padding">0</property>
@@ -1126,6 +1126,211 @@
 	  <property name="fill">True</property>
 	</packing>
       </child>
+
+      <child>
+	<widget class="GtkVBox" id="vbox12">
+	  <property name="visible">True</property>
+	  <property name="homogeneous">False</property>
+	  <property name="spacing">0</property>
+
+	  <child>
+	    <widget class="GtkLabel" id="label29">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">&lt;b&gt;Player's history&lt;/b&gt;</property>
+	      <property name="use_underline">False</property>
+	      <property name="use_markup">True</property>
+	      <property name="justify">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap">False</property>
+	      <property name="selectable">False</property>
+	      <property name="xalign">0</property>
+	      <property name="yalign">0</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">5</property>
+	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+	      <property name="width_chars">-1</property>
+	      <property name="single_line_mode">False</property>
+	      <property name="angle">0</property>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">False</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkHBox" id="hbox11">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
+
+	      <child>
+		<widget class="GtkTable" id="table5">
+		  <property name="visible">True</property>
+		  <property name="n_rows">2</property>
+		  <property name="n_columns">2</property>
+		  <property name="homogeneous">False</property>
+		  <property name="row_spacing">0</property>
+		  <property name="column_spacing">0</property>
+
+		  <child>
+		    <widget class="GtkLabel" id="label31">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">Minimum number of played games to store the game:</property>
+		      <property name="use_underline">False</property>
+		      <property name="use_markup">False</property>
+		      <property name="justify">GTK_JUSTIFY_LEFT</property>
+		      <property name="wrap">False</property>
+		      <property name="selectable">False</property>
+		      <property name="xalign">0</property>
+		      <property name="yalign">0.5</property>
+		      <property name="xpad">5</property>
+		      <property name="ypad">0</property>
+		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		      <property name="width_chars">-1</property>
+		      <property name="single_line_mode">False</property>
+		      <property name="angle">0</property>
+		    </widget>
+		    <packing>
+		      <property name="left_attach">0</property>
+		      <property name="right_attach">1</property>
+		      <property name="top_attach">0</property>
+		      <property name="bottom_attach">1</property>
+		      <property name="x_options">fill</property>
+		      <property name="y_options"></property>
+		    </packing>
+		  </child>
+
+		  <child>
+		    <widget class="GtkLabel" id="label32">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">Maximum number of stored games in the player's history:</property>
+		      <property name="use_underline">False</property>
+		      <property name="use_markup">False</property>
+		      <property name="justify">GTK_JUSTIFY_LEFT</property>
+		      <property name="wrap">False</property>
+		      <property name="selectable">False</property>
+		      <property name="xalign">0</property>
+		      <property name="yalign">0.5</property>
+		      <property name="xpad">5</property>
+		      <property name="ypad">0</property>
+		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		      <property name="width_chars">-1</property>
+		      <property name="single_line_mode">False</property>
+		      <property name="angle">0</property>
+		    </widget>
+		    <packing>
+		      <property name="left_attach">0</property>
+		      <property name="right_attach">1</property>
+		      <property name="top_attach">1</property>
+		      <property name="bottom_attach">2</property>
+		      <property name="x_options">fill</property>
+		      <property name="y_options"></property>
+		    </packing>
+		  </child>
+
+		  <child>
+		    <widget class="GtkSpinButton" id="maxstoredspinbutton">
+		      <property name="visible">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="climb_rate">1</property>
+		      <property name="digits">0</property>
+		      <property name="numeric">False</property>
+		      <property name="update_policy">GTK_UPDATE_ALWAYS</property>
+		      <property name="snap_to_ticks">False</property>
+		      <property name="wrap">False</property>
+		      <property name="adjustment">0 10 100 1 10 10</property>
+		    </widget>
+		    <packing>
+		      <property name="left_attach">1</property>
+		      <property name="right_attach">2</property>
+		      <property name="top_attach">1</property>
+		      <property name="bottom_attach">2</property>
+		      <property name="y_options"></property>
+		    </packing>
+		  </child>
+
+		  <child>
+		    <widget class="GtkSpinButton" id="minplayedspinbutton">
+		      <property name="visible">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="climb_rate">1</property>
+		      <property name="digits">0</property>
+		      <property name="numeric">False</property>
+		      <property name="update_policy">GTK_UPDATE_ALWAYS</property>
+		      <property name="snap_to_ticks">False</property>
+		      <property name="wrap">False</property>
+		      <property name="adjustment">0 3 50 1 10 10</property>
+		    </widget>
+		    <packing>
+		      <property name="left_attach">1</property>
+		      <property name="right_attach">2</property>
+		      <property name="top_attach">0</property>
+		      <property name="bottom_attach">1</property>
+		      <property name="y_options"></property>
+		    </packing>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">True</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkHBox" id="hbox12">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
+
+	      <child>
+		<widget class="GtkHButtonBox" id="hbuttonbox2">
+		  <property name="border_width">1</property>
+		  <property name="visible">True</property>
+		  <property name="layout_style">GTK_BUTTONBOX_START</property>
+		  <property name="spacing">0</property>
+
+		  <child>
+		    <widget class="GtkButton" id="clear_button">
+		      <property name="visible">True</property>
+		      <property name="can_default">True</property>
+		      <property name="can_focus">True</property>
+		      <property name="label" translatable="yes">Clear player's history</property>
+		      <property name="use_underline">True</property>
+		      <property name="relief">GTK_RELIEF_NORMAL</property>
+		      <property name="focus_on_click">True</property>
+		      <signal name="clicked" handler="OnCleanHistory" last_modification_time="Fri, 09 May 2008 10:19:47 GMT"/>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">5</property>
+		  <property name="expand">True</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">True</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">True</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
     </widget>
   </child>
 </widget>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]