[libgames-support] scores: Remove short-lived DialogMode and Context.latest_score
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgames-support] scores: Remove short-lived DialogMode and Context.latest_score
- Date: Sun, 22 Feb 2015 19:12:06 +0000 (UTC)
commit e47e76b24ec8d8573f4eeb1107462a53c688c126
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Feb 22 13:09:07 2015 -0600
scores: Remove short-lived DialogMode and Context.latest_score
There is already a parameter to the dialog constructor we can use for
this purpose
scores/context.vala | 12 ++++--------
scores/dialog.vala | 31 ++++++++++---------------------
2 files changed, 14 insertions(+), 29 deletions(-)
---
diff --git a/scores/context.vala b/scores/context.vala
index a0a6f9b..d61cd29 100644
--- a/scores/context.vala
+++ b/scores/context.vala
@@ -32,7 +32,6 @@ public enum Style
public class Context : Object
{
/* All these variables are needed by dialog and as parameters to Dialog constructor. */
- private Score? last_score = null;
private Category? current_category = null;
private Style style;
private string dialog_label;
@@ -181,10 +180,7 @@ public class Context : Object
scores_per_category.set (category, new Gee.PriorityQueue<Score> ((owned) scorecmp));
if (scores_per_category[category].add (score))
- {
- last_score = score;
current_category = category;
- }
/* Don't save the score to file yet if it's a high score. Since the Player name be changed on
running dialog. */
if (!high_score_added)
@@ -194,7 +190,7 @@ public class Context : Object
}
else
{
- run_dialog_internal (DialogMode.HIGH_SCORE_ADDED);
+ run_dialog_internal (score);
return true;
}
}
@@ -294,7 +290,7 @@ public class Context : Object
return score_value > lowest;
}
- internal void run_dialog_internal (DialogMode mode)
+ internal void run_dialog_internal (Score? new_high_score)
{
if (!scores_loaded_from_file)
{
@@ -311,7 +307,7 @@ public class Context : Object
if (game_window != null)
{
- var dialog = new Dialog (this, dialog_label, style, last_score, current_category, game_window,
mode);
+ var dialog = new Dialog (this, dialog_label, style, new_high_score, current_category,
game_window);
dialog.run ();
dialog.destroy ();
}
@@ -319,7 +315,7 @@ public class Context : Object
public void run_dialog ()
{
- run_dialog_internal (DialogMode.CATEGORY_BROWSER);
+ run_dialog_internal (null);
}
public bool has_scores ()
diff --git a/scores/dialog.vala b/scores/dialog.vala
index 12704f3..13beaed 100644
--- a/scores/dialog.vala
+++ b/scores/dialog.vala
@@ -21,12 +21,6 @@
namespace Games {
namespace Scores {
-internal enum DialogMode
-{
- CATEGORY_BROWSER,
- HIGH_SCORE_ADDED
-}
-
private class Dialog : Gtk.Dialog
{
private Context context;
@@ -39,12 +33,10 @@ private class Dialog : Gtk.Dialog
private Gtk.Grid grid;
private Style scores_style;
- private Score? latest_score;
+ private Score? new_high_score;
private Category? scores_active_category;
- private DialogMode mode;
-
- public Dialog (Context context, string dialog_label, Style style, Score? latest_score, Category?
current_cat, Gtk.Window window, DialogMode mode)
+ public Dialog (Context context, string dialog_label, Style style, Score? new_high_score, Category?
current_cat, Gtk.Window window)
{
Object (use_header_bar : 1);
@@ -52,17 +44,16 @@ private class Dialog : Gtk.Dialog
this.context = context;
this.transient_for = window;
- this.latest_score = latest_score;
- this.mode = mode;
+ this.new_high_score = new_high_score;
scores_style = style;
scores_active_category = current_cat;
headerbar = (Gtk.HeaderBar) this.get_header_bar ();
- headerbar.show_close_button = (mode == DialogMode.CATEGORY_BROWSER);
+ headerbar.show_close_button = (new_high_score == null);
- if (mode == DialogMode.HIGH_SCORE_ADDED)
+ if (new_high_score != null)
/* Appears at the top of the dialog, as the heading of the dialog */
headerbar.title = _("Congratulations!");
else if (scores_style == Style.PLAIN_ASCENDING || scores_style == Style.PLAIN_DESCENDING)
@@ -87,7 +78,7 @@ private class Dialog : Gtk.Dialog
label.halign = Gtk.Align.CENTER;
catbar.pack_start (label, false, false, 0);
- if (mode == DialogMode.HIGH_SCORE_ADDED)
+ if (new_high_score != null)
{
category_label = new Gtk.Label (scores_active_category.name);
category_label.use_markup = true;
@@ -138,7 +129,7 @@ private class Dialog : Gtk.Dialog
grid.baseline_row = 0;
fill_grid_with_labels ();
- if (mode == DialogMode.HIGH_SCORE_ADDED)
+ if (new_high_score != null)
/* Appears on the top right corner of the dialog. Clicking the button closes the dialog. */
add_button (_("Done"), Gtk.ResponseType.OK).get_style_context ().add_class ("suggested-action");
@@ -187,7 +178,7 @@ private class Dialog : Gtk.Dialog
private void load_categories ()
{
/* If we are adding a high score, we don't wish to load all categories. We only wish to load scores
of active category. */
- if (mode == DialogMode.HIGH_SCORE_ADDED)
+ if (new_high_score != null)
{
load_scores ();
}
@@ -224,7 +215,7 @@ private class Dialog : Gtk.Dialog
/* loads the scores of current active_category */
private void load_scores ()
{
- if (mode == DialogMode.HIGH_SCORE_ADDED)
+ if (new_high_score != null)
active_category = new Category (scores_active_category.key, scores_active_category.name);
else
active_category = new Category (combo.get_active_id (), combo.get_active_text ());
@@ -253,9 +244,7 @@ private class Dialog : Gtk.Dialog
var score = (Gtk.Label) grid.get_child_at (1, row_count);
score.set_text (x.score.to_string ());
- if (mode == DialogMode.HIGH_SCORE_ADDED
- && latest_score != null
- && Score.equals (x, latest_score))
+ if (new_high_score != null && Score.equals (x, new_high_score))
{
if (no_scores > 1 && row_count == 1)
headerbar.subtitle = _("Your score is the best!");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]