[five-or-more/gsoc-vala-port: 15/29] Add headerbar hints



commit 6c0018f88e3b54a780817cbb31c1eb7aa1317d50
Author: Ruxandra Simion <ruxandra simion93 gmail com>
Date:   Wed Aug 1 23:57:12 2018 +0300

    Add headerbar hints

 src-vala/game.vala   | 14 ++++++++++++++
 src-vala/view.vala   |  3 +++
 src-vala/window.vala | 16 ++++++++++++++++
 3 files changed, 33 insertions(+)
---
diff --git a/src-vala/game.vala b/src-vala/game.vala
index d4ae94e..2ada601 100644
--- a/src-vala/game.vala
+++ b/src-vala/game.vala
@@ -65,6 +65,8 @@ public class Game : Object
     public int n_categories = 3;
     public string score_current_category = null;
 
+    public StatusMessage status_message { get; set; }
+
     public Game (Settings settings)
     {
         this.settings = settings;
@@ -90,6 +92,8 @@ public class Game : Object
         this.score = 0;
         this.score_current_category = scorecats[size - 1].key;
 
+        this.status_message = DESCRIPTION;
+
         next_pieces_generator = new NextPiecesGenerator (game_difficulty[size].n_next_pieces,
                                                          game_difficulty[size].n_types);
         generate_next_pieces ();
@@ -143,6 +147,7 @@ public class Game : Object
 
             if (check_game_over ())
             {
+                status_message = GAME_OVER;
                 board.grid_changed ();
                 return;
             }
@@ -180,6 +185,7 @@ public class Game : Object
 
         if (current_path == null || current_path.size == 0)
         {
+            status_message = NO_PATH;
             return false;
         }
 
@@ -261,3 +267,11 @@ struct KeyValue
   public string key;
   public string name;
 }
+
+public enum StatusMessage
+{
+    DESCRIPTION = 0,
+    NO_PATH = 1,
+    GAME_OVER = 2,
+    NONE = 3,
+}
diff --git a/src-vala/view.vala b/src-vala/view.vala
index 600eaf4..b6464a7 100644
--- a/src-vala/view.vala
+++ b/src-vala/view.vala
@@ -94,6 +94,9 @@ public class View : Gtk.DrawingArea
         if (cell_x >= game.n_cols || cell_y >= game.n_rows)
             return false;
 
+        if (game.status_message != StatusMessage.NONE)
+            game.status_message = StatusMessage.NONE;
+
         /* if selected cell is not empty, set start */
         if (game.board.get_piece (cell_y, cell_x) != null)
         {
diff --git a/src-vala/window.vala b/src-vala/window.vala
index 5cc204d..eec6db7 100644
--- a/src-vala/window.vala
+++ b/src-vala/window.vala
@@ -1,6 +1,9 @@
 [GtkTemplate (ui = "/org/gnome/five-or-more/ui/five-or-more-vala.ui")]
 public class GameWindow : Gtk.ApplicationWindow
 {
+    [GtkChild]
+    private Gtk.HeaderBar headerbar;
+
     [GtkChild]
     private Gtk.Box preview_hbox;
 
@@ -16,6 +19,12 @@ public class GameWindow : Gtk.ApplicationWindow
     private ThemeRenderer? theme = null;
 
     private Games.Scores.Context highscores;
+    private const string status[] = {
+            "Match five objects of the same type in a row to score!",
+            "You can't move there!",
+            "Game Over!",
+            null
+    };
 
     public GameWindow (Gtk.Application app, Settings settings)
     {
@@ -36,6 +45,8 @@ public class GameWindow : Gtk.ApplicationWindow
         game.notify["n-cols"].connect ((s, p) => { grid_frame.set (game.n_cols, game.n_rows); });
         game.notify["n-rows"].connect ((s, p) => { grid_frame.set (game.n_cols, game.n_rows); });
         game.notify["score"].connect ((s, p) => { scorelabel.set_text (game.score.to_string ()); });
+        game.notify["status-message"].connect ((s, p) => { set_status_message 
(_(status[game.status_message])); });
+        set_status_message (_(status[game.status_message]));
         hbox.pack_start (grid_frame);
 
         View game_view = new View (settings, game, theme);
@@ -71,6 +82,11 @@ public class GameWindow : Gtk.ApplicationWindow
         game.restart ();
     }
 
+    private void set_status_message (string? message)
+    {
+        headerbar.set_subtitle (message);
+    }
+
     public void show_scores ()
     {
         highscores.run_dialog ();


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