[gnome-nibbles/arnaudb/modernize-code: 27/58] Move Scoreboard in its own file.



commit 8a5c9be7e9a128a8a5baa5925b551c1139fa632e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed May 27 16:54:29 2020 +0200

    Move Scoreboard in its own file.

 po/POTFILES.in         |   1 +
 po/POTFILES.skip       |   1 +
 src/gnome-nibbles.vala |  88 ----------------------------------------
 src/meson.build        |   1 +
 src/scoreboard.vala    | 107 +++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 110 insertions(+), 88 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2dc1dce..f80997d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -10,3 +10,4 @@ data/preferences-dialog.ui
 src/gnome-nibbles.vala
 src/nibbles-view.vala
 src/preferences-dialog.vala
+src/scoreboard.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index f14bc9e..f5f5b9c 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,3 +1,4 @@
 src/gnome-nibbles.c
 src/nibbles-view.c
 src/preferences-dialog.c
+src/scoreboard.c
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index dd69df2..4c1ced6 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -1113,94 +1113,6 @@ private class Nibbles : Gtk.Application
     }
 }
 
-[GtkTemplate (ui = "/org/gnome/nibbles/ui/scoreboard.ui")]
-private class Scoreboard : Box
-{
-    private Gee.HashMap<PlayerScoreBox, Worm> boxes = new Gee.HashMap<PlayerScoreBox, Worm> ();
-
-    internal void register (Worm worm, string color_name, Gdk.Pixbuf life_pixbuf)
-    {
-        var color = Pango.Color ();
-        color.parse (color_name);
-
-        /* Translators: text displayed under the game view, presenting the number of remaining lives; the %d 
is replaced by the number that identifies the player */
-        var box = new PlayerScoreBox (_("Player %d").printf (worm.id + 1), color, worm.score, worm.lives, 
life_pixbuf); // FIXME: Consider changing this to "Worm %d"; It's set to "Player %d" for now to avoid a 
string change for 3.20.
-        boxes.@set (box, worm);
-        add (box);
-    }
-
-    internal void update ()
-    {
-        foreach (var entry in boxes.entries)
-        {
-            var box = entry.key;
-            var worm = entry.@value;
-
-            box.update (worm.score, worm.lives);
-        }
-    }
-
-    internal void clear ()
-    {
-        foreach (var entry in boxes.entries)
-        {
-            var box = entry.key;
-            box.destroy ();
-        }
-        boxes.clear ();
-    }
-}
-
-[GtkTemplate (ui = "/org/gnome/nibbles/ui/player-score-box.ui")]
-private class PlayerScoreBox : Box
-{
-    [GtkChild] private Label name_label;
-    [GtkChild] private Label score_label;
-    [GtkChild] private Grid lives_grid;
-
-    private Gee.LinkedList<Image> life_images = new Gee.LinkedList<Image> ();
-
-    internal PlayerScoreBox (string name, Pango.Color color, int score, int lives_left, Gdk.Pixbuf 
life_pixbuf)
-    {
-        name_label.set_markup ("<span color=\"" + color.to_string () + "\">" + name + "</span>");
-        score_label.set_label (score.to_string ());
-
-        for (int i = 0; i < Worm.MAX_LIVES; i++)
-        {
-            var life = new Image.from_pixbuf (life_pixbuf);
-            life.show ();
-
-            if (i >= Worm.STARTING_LIVES)
-                life.set_opacity (0);
-
-            life_images.add (life);
-            lives_grid.attach (life, i % 6, i / 6);
-        }
-    }
-
-    internal void update (int score, int lives_left)
-    {
-        update_score (score);
-        update_lives (lives_left);
-    }
-
-    internal inline void update_score (int score)
-    {
-        score_label.set_label (score.to_string ());
-    }
-
-    internal void update_lives (int lives_left)
-    {
-        /* Remove lost lives - if any */
-        for (int i = life_images.size - 1; i >= lives_left; i--)
-            life_images[i].set_opacity (0);
-
-        /* Add new lives - if any */
-        for (int i = 0; i < lives_left; i++)
-            life_images[i].set_opacity (1);
-    }
-}
-
 [GtkTemplate (ui = "/org/gnome/nibbles/ui/controls-grid.ui")]
 private class ControlsGrid : Grid
 {
diff --git a/src/meson.build b/src/meson.build
index 3f1b248..5b76a47 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -7,6 +7,7 @@ gnome_nibbles_sources = [
     'nibbles-game.vala',
     'nibbles-view.vala',
     'preferences-dialog.vala',
+    'scoreboard.vala',
     'warp.vala',
     'worm.vala',
     resources,
diff --git a/src/scoreboard.vala b/src/scoreboard.vala
new file mode 100644
index 0000000..7c6b13d
--- /dev/null
+++ b/src/scoreboard.vala
@@ -0,0 +1,107 @@
+/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * Gnome Nibbles: Gnome Worm Game
+ * Copyright (C) 2015 Iulian-Gabriel Radu <iulian radu67 gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/nibbles/ui/scoreboard.ui")]
+private class Scoreboard : Box
+{
+    private Gee.HashMap<PlayerScoreBox, Worm> boxes = new Gee.HashMap<PlayerScoreBox, Worm> ();
+
+    internal void register (Worm worm, string color_name, Gdk.Pixbuf life_pixbuf)
+    {
+        var color = Pango.Color ();
+        color.parse (color_name);
+
+        /* Translators: text displayed under the game view, presenting the number of remaining lives; the %d 
is replaced by the number that identifies the player */
+        var box = new PlayerScoreBox (_("Player %d").printf (worm.id + 1), color, worm.score, worm.lives, 
life_pixbuf); // FIXME: Consider changing this to "Worm %d"; It's set to "Player %d" for now to avoid a 
string change for 3.20.
+        boxes.@set (box, worm);
+        add (box);
+    }
+
+    internal void update ()
+    {
+        foreach (var entry in boxes.entries)
+        {
+            var box = entry.key;
+            var worm = entry.@value;
+
+            box.update (worm.score, worm.lives);
+        }
+    }
+
+    internal void clear ()
+    {
+        foreach (var entry in boxes.entries)
+        {
+            var box = entry.key;
+            box.destroy ();
+        }
+        boxes.clear ();
+    }
+}
+
+[GtkTemplate (ui = "/org/gnome/nibbles/ui/player-score-box.ui")]
+private class PlayerScoreBox : Box
+{
+    [GtkChild] private Label name_label;
+    [GtkChild] private Label score_label;
+    [GtkChild] private Grid lives_grid;
+
+    private Gee.LinkedList<Image> life_images = new Gee.LinkedList<Image> ();
+
+    internal PlayerScoreBox (string name, Pango.Color color, int score, int lives_left, Gdk.Pixbuf 
life_pixbuf)
+    {
+        name_label.set_markup ("<span color=\"" + color.to_string () + "\">" + name + "</span>");
+        score_label.set_label (score.to_string ());
+
+        for (int i = 0; i < Worm.MAX_LIVES; i++)
+        {
+            var life = new Image.from_pixbuf (life_pixbuf);
+            life.show ();
+
+            if (i >= Worm.STARTING_LIVES)
+                life.set_opacity (0);
+
+            life_images.add (life);
+            lives_grid.attach (life, i % 6, i / 6);
+        }
+    }
+
+    internal void update (int score, int lives_left)
+    {
+        update_score (score);
+        update_lives (lives_left);
+    }
+
+    internal inline void update_score (int score)
+    {
+        score_label.set_label (score.to_string ());
+    }
+
+    internal void update_lives (int lives_left)
+    {
+        /* Remove lost lives - if any */
+        for (int i = life_images.size - 1; i >= lives_left; i--)
+            life_images[i].set_opacity (0);
+
+        /* Add new lives - if any */
+        for (int i = 0; i < lives_left; i++)
+            life_images[i].set_opacity (1);
+    }
+}


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