[gbrainy] PlayerHistory should depend on Core
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gbrainy] PlayerHistory should depend on Core
- Date: Sun, 22 Nov 2009 20:52:34 +0000 (UTC)
commit 729bcc95141422870a2aa44dc3ecd34331a5e34c
Author: Jordi Mas <jmas softcatala org>
Date: Sun Nov 22 21:52:45 2009 +0100
PlayerHistory should depend on Core
.../Classical/Dialogs/PlayerHistoryDialog.cs | 14 ++++++++++----
src/Clients/Classical/Dialogs/PreferencesDialog.cs | 7 +++++--
src/Clients/Classical/gbrainy.cs | 12 +++---------
src/Core/Main/GameSession.cs | 9 +++++++++
4 files changed, 27 insertions(+), 15 deletions(-)
---
diff --git a/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs b/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
index 0b4b732..7158e5e 100644
--- a/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
+++ b/src/Clients/Classical/Dialogs/PlayerHistoryDialog.cs
@@ -38,17 +38,19 @@ namespace gbrainy.Clients.Classical
[Glade.Widget] Gtk.CheckButton checkbutton_verbal;
CairoPreview drawing_area;
+ PlayerHistory history;
- public PlayerHistoryDialog () : base ("playerhistory")
+ public PlayerHistoryDialog (PlayerHistory history) : base ("playerhistory")
{
string label;
+ this.history = history;
label = Catalog.GetString ("The graphic below shows the player's game score evolution. ");
label += Catalog.GetPluralString ("You need more than one game recorded to see the score evolution.",
"It is built using the results of {0} last recorded games.",
- GtkClient.history.Games.Count < 2 ? 1 : 2);
+ PlayerHistory.Games.Count < 2 ? 1 : 2);
- label_playerhistory.Text = String.Format (label, GtkClient.history.Games.Count);
+ label_playerhistory.Text = String.Format (label, PlayerHistory.Games.Count);
drawing_area = new CairoPreview (this);
history_preview.Add (drawing_area);
@@ -63,6 +65,10 @@ namespace gbrainy.Clients.Classical
checkbutton_total.Active = checkbutton_memory.Active = checkbutton_logic.Active = checkbutton_calculation.Active = checkbutton_verbal.Active = true;
}
+ public PlayerHistory PlayerHistory {
+ get {return history; }
+ }
+
void OnTotalToggled (object sender, EventArgs args)
{
drawing_area.QueueDraw ();
@@ -161,7 +167,7 @@ namespace gbrainy.Clients.Classical
private void DrawLines (CairoContextEx cr, double x, double y)
{
double px, py;
- PlayerHistory history = GtkClient.history;
+ PlayerHistory history = dlg.PlayerHistory;
double ratio;
if (history.Games.Count == 0)
diff --git a/src/Clients/Classical/Dialogs/PreferencesDialog.cs b/src/Clients/Classical/Dialogs/PreferencesDialog.cs
index 8e1ca2a..121e79a 100644
--- a/src/Clients/Classical/Dialogs/PreferencesDialog.cs
+++ b/src/Clients/Classical/Dialogs/PreferencesDialog.cs
@@ -36,8 +36,11 @@ namespace gbrainy.Clients.Classical
[Glade.Widget] Gtk.RadioButton rb_medium;
[Glade.Widget] Gtk.RadioButton rb_master;
- public PreferencesDialog () : base ("preferences")
+ PlayerHistory history;
+
+ public PreferencesDialog (PlayerHistory history) : base ("preferences")
{
+ this.history = history;
prefspinbutton.Value = Preferences.GetIntValue (Preferences.MemQuestionTimeKey);
prefcheckbutton.Active = Preferences.GetBoolValue (Preferences.MemQuestionWarnKey);
maxstoredspinbutton.Value = Preferences.GetIntValue (Preferences.MaxStoredGamesKey);
@@ -72,7 +75,7 @@ namespace gbrainy.Clients.Classical
private void OnCleanHistory (object sender, EventArgs args)
{
- GtkClient.history.Clean ();
+ history.Clean ();
}
private void OnOK (object sender, EventArgs args)
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index b185d1b..1fcfbd2 100644
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -68,8 +68,6 @@ namespace gbrainy.Clients.Classical
SimpleLabel solution_label;
bool margins = false;
- public static PlayerHistory history = null;
-
public GtkClient (string [] args, params object [] props)
: base ("gbrainy", Defines.VERSION, Modules.UI, args, props)
{
@@ -87,9 +85,6 @@ namespace gbrainy.Clients.Classical
session.UpdateGameQuestion += SessionUpdateGameQuestion;
session.SynchronizingObject = new GtkSynchronize ();
- if (history == null)
- history = new PlayerHistory ();
-
session.GameManager.Difficulty = (Game.Difficulty) Preferences.GetIntValue (Preferences.DifficultyKey);
drawing_area = new DrawingArea ();
drawing_area.ExposeEvent += OnDrawingAreaExposeEvent;
@@ -433,7 +428,7 @@ namespace gbrainy.Clients.Classical
{
PreferencesDialog dialog;
- dialog = new PreferencesDialog ();
+ dialog = new PreferencesDialog (session.PlayerHistory);
if (dialog.Run () == ResponseType.Ok) {
session.GameManager.Difficulty = (Game.Difficulty) Preferences.GetIntValue (Preferences.DifficultyKey);
}
@@ -482,8 +477,7 @@ namespace gbrainy.Clients.Classical
}
void OnEndGame (object sender, EventArgs args)
- {
- history.SaveGameSession (session);
+ {
session.EndSession ();
UpdateSolution (String.Empty);
@@ -533,7 +527,7 @@ namespace gbrainy.Clients.Classical
{
PlayerHistoryDialog dialog;
- dialog = new PlayerHistoryDialog ();
+ dialog = new PlayerHistoryDialog (session.PlayerHistory);
dialog.Run ();
dialog.Dialog.Destroy ();
}
diff --git a/src/Core/Main/GameSession.cs b/src/Core/Main/GameSession.cs
index 3b5591d..60e1485 100644
--- a/src/Core/Main/GameSession.cs
+++ b/src/Core/Main/GameSession.cs
@@ -76,6 +76,7 @@ namespace gbrainy.Core.Main
private SessionStatus status;
private ViewsControler controler;
private ISynchronizeInvoke synchronize;
+ private PlayerHistory history;
public event EventHandler DrawRequest;
public event EventHandler <UpdateGameQuestionEventArgs> UpdateGameQuestion;
@@ -93,6 +94,12 @@ namespace gbrainy.Core.Main
games = new int [(int) ScoresType.Last];
controler = new ViewsControler (this);
Status = SessionStatus.NotPlaying;
+ history = new PlayerHistory ();
+ }
+
+ public PlayerHistory PlayerHistory {
+ set { history = value; }
+ get { return history; }
}
public ISynchronizeInvoke SynchronizingObject {
@@ -239,6 +246,8 @@ namespace gbrainy.Core.Main
public void EndSession ()
{
+ history.SaveGameSession (this);
+
if (CurrentGame != null)
CurrentGame.Finish ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]