[gnome-nibbles] Add scoreboard
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles] Add scoreboard
- Date: Mon, 26 Oct 2015 00:17:19 +0000 (UTC)
commit 9d70b60e1e027eb45b32ad40fcea2598c2df2803
Author: Iulian Radu <iulian radu67 gmail com>
Date: Tue Jul 21 17:45:21 2015 +0300
Add scoreboard
data/Makefile.am | 4 +-
data/nibbles.ui | 52 ++++++++++++++------
data/pix/Makefile.am | 5 ++-
data/pix/scoreboard-life.svg | 90 ++++++++++++++++++++++++++++++++++++
data/player-score-box.ui | 42 +++++++++++++++++
data/scoreboard.ui | 9 ++++
src/gnome-nibbles.gresource.xml.in | 4 +-
src/gnome-nibbles.vala | 76 +++++++++++++++++++++++++++---
src/nibbles-game.vala | 2 +-
src/nibbles-view.vala | 4 +-
10 files changed, 258 insertions(+), 30 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 2a86164..4754005 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -17,7 +17,9 @@ dist_man_MANS = gnome-nibbles.6
dist_noinst_DATA = \
nibbles.ui \
- nibbles.css
+ nibbles.css \
+ scoreboard.ui \
+ player-score-box.ui
EXTRA_DIST = \
$(gsettings_SCHEMAS)
diff --git a/data/nibbles.ui b/data/nibbles.ui
index b2a155d..20ba93d 100644
--- a/data/nibbles.ui
+++ b/data/nibbles.ui
@@ -234,27 +234,47 @@
<property name="name">controls</property>
</packing>
</child>
- </object> <!-- End of main_stack -->
- <packing>
- <property name="pack-type">start</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox" id="statusbar">
- <property name="visible">False</property>
- <!-- <property name="height-request">250</property> -->
- <property name="halign">center</property>
<child>
- <object class="GtkLabel" id="countdown">
+ <object class="GtkBox" id="game_box">
<property name="visible">True</property>
- <property name="label">5</property>
- <property name="halign">center</property>
- <style><class name="countdown"/></style>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkBox" id="statusbar">
+ <property name="visible">True</property>
+ <!-- <property name="height-request">250</property> -->
+ <property name="halign">center</property>
+ <child>
+ <object class="GtkStack" id="statusbar_stack">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="countdown">
+ <property name="visible">True</property>
+ <property name="label">5</property>
+ <property name="halign">center</property>
+ <style><class name="countdown"/></style>
+ </object>
+ </child>
+ <!-- <child> -->
+ <!-- <object class="Scoreboard" id="scoreboard"> -->
+ <!-- <property name="visible">True</property> -->
+ <!-- <property
name="orientation">horizontal</property> -->
+ <!-- </object> -->
+ <!-- </child> -->
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
</object>
+ <packing>
+ <property name="name">game_box</property>
+ </packing>
</child>
- </object>
+ </object> <!-- End of main_stack -->
<packing>
- <property name="pack-type">start</property>
+ <property name="pack-type">start</property>
</packing>
</child>
</object> <!-- End of vbox -->
diff --git a/data/pix/Makefile.am b/data/pix/Makefile.am
index 5435dc1..2e02f09 100644
--- a/data/pix/Makefile.am
+++ b/data/pix/Makefile.am
@@ -31,6 +31,9 @@ SMALL_PIX = \
wall-tee-right.svg \
wall-tee-up.svg
-dist_pixmap_DATA = ${BONUS_PIX} ${SMALL_PIX}
+SCOREBOARD_PIX = \
+ scoreboard-life.svg
+
+dist_pixmap_DATA = ${BONUS_PIX} ${SMALL_PIX} ${SCOREBOARD_PIX}
-include $(top_srcdir)/git.mk
diff --git a/data/pix/scoreboard-life.svg b/data/pix/scoreboard-life.svg
new file mode 100644
index 0000000..924d3b9
--- /dev/null
+++ b/data/pix/scoreboard-life.svg
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.1"
+ height="10.000000cm"
+ width="10.000000cm"
+ id="svg1">
+ <metadata
+ id="metadata13">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs3">
+ <linearGradient
+ id="linearGradient3634">
+ <stop
+ id="stop3636"
+ offset="0"
+ style="stop-color:#00b600;stop-opacity:1;" />
+ <stop
+ id="stop3638"
+ offset="1.0000000"
+ style="stop-color:#008900;stop-opacity:1.0000000;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient2068">
+ <stop
+ id="stop2070"
+ offset="0.0000000"
+ style="stop-color:#ff4853;stop-opacity:1.0000000;" />
+ <stop
+ id="stop2072"
+ offset="1.0000000"
+ style="stop-color:#aa002e;stop-opacity:1.0000000;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient589">
+ <stop
+ id="stop590"
+ offset="0.00000000"
+ style="stop-color:#ffcdcd;stop-opacity:1;" />
+ <stop
+ id="stop591"
+ offset="1.00000000"
+ style="stop-color:#ff0000;stop-opacity:1;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient592"
+ xlink:href="#linearGradient589" />
+ <radialGradient
+ gradientUnits="userSpaceOnUse"
+ fy="242.36936"
+ fx="250.17006"
+ r="72.911689"
+ cy="243.64851"
+ cx="248.89091"
+ id="radialGradient593"
+ xlink:href="#linearGradient589" />
+ <radialGradient
+ gradientUnits="userSpaceOnUse"
+ r="72.911689"
+ fy="242.36936"
+ fx="250.17006"
+ cy="243.64851"
+ cx="248.89091"
+ id="radialGradient1308"
+ xlink:href="#linearGradient589" />
+ </defs>
+ <path
+ style="display:inline;fill:#888a85;fill-opacity:1;stroke:none"
+ id="path10457"
+ d="m 112.65502,28.358413 c -56.479104,0 -79.508364,37.86135 -79.508364,81.210837 0,105.16266
81.236544,209.56268 110.175824,209.56268 28.93922,0 71.55765,-72.12637 71.55765,-72.12637 14.16794,34.57077
47.90132,72.12637 69.85467,72.12637 27.87069,0 39.18539,-10.94542 39.18539,-28.39668 0,-17.44861
-42.50747,-18.54386 -49.40797,-44.29669 -6.90032,-25.75285 -22.59676,-89.73007 -51.68138,-89.73007
-29.08267,0 -62.47072,52.81417 -62.47072,52.81417 0,-39.68354 18.74204,-52.73927 18.74204,-98.81719
0,-46.075707 -9.96626,-82.347057 -66.44714,-82.347057 z m -34.074964,54.52003 c 7.02942,0 13.33922,3.83116
18.17333,9.65368 4.834114,-5.82252 11.145544,-9.65368 18.173334,-9.65368 15.05648,0 27.26002,16.273615
27.26002,36.346687 0,20.07308 -12.20354,36.3467 -27.26002,36.3467 -7.02779,0 -13.33922,-3.83116
-18.173334,-9.65588 -4.83411,5.82472 -11.14391,9.65588 -18.17333,9.65588 -15.0548,0 -27.26002,-16.27362
-27.26002,-36.3467 0,-20.073072 12.20522,-36.346687 27.26002,-36.346687 z" />
+ <path
+ id="path4645"
+ d="m 72.155396,154.16885 c -9.0787,-3.24428 -16.00495,-11.77447 -19.04858,-23.45976 -1.47652,-5.66874
-1.45257,-17.21517 0.0477,-23.00496 2.63143,-10.154997 9.29839,-19.169938 16.66106,-22.528751
5.27765,-2.407641 12.84561,-2.255093 17.81754,0.359151 2.06443,1.085476 4.90303,3.171 6.308,4.6345 l
2.5545,2.660903 3.675094,-3.30422 c 4.88612,-4.393032 10.91761,-6.66666 16.26441,-6.13102 12.45646,1.247882
22.05746,12.43497 24.73545,28.821737 1.07309,6.56632 1.07254,7.8443 -0.006,14.18471 -2.09322,12.30373
-8.21149,21.9646 -16.73223,26.42034 -3.07629,1.60868 -4.8024,1.97404 -9.39863,1.98939 -4.81185,0.0161
-6.19341,-0.29332 -9.5045,-2.12839 -2.13083,-1.18096 -4.97037,-3.27811 -6.310094,-4.66034 l -2.43584,-2.51315
-3.98539,3.64243 c -6.10057,5.57557 -13.82594,7.45332 -20.64249,5.01743 z"
+ style="fill:#000000" />
+</svg>
diff --git a/data/player-score-box.ui b/data/player-score-box.ui
new file mode 100644
index 0000000..e615793
--- /dev/null
+++ b/data/player-score-box.ui
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="PlayerScoreBox" parent="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="width-request">96</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">horizontal</property>
+ <property name="spacing">4</property>
+ <child>
+ <object class="GtkLabel" id="name_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Worm</property>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="score_label">
+ <property name="visible">True</property>
+ <property name="label">0</property>
+ <property name="justify">right</property>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="lives_grid">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/data/scoreboard.ui b/data/scoreboard.ui
new file mode 100644
index 0000000..d908614
--- /dev/null
+++ b/data/scoreboard.ui
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="Scoreboard" parent="GtkBox">
+ <property name="orientation">horizontal</property>
+ <property name="spacing">16</property>
+ <property name="homogeneous">True</property>
+ <property name="width-request">644</property>
+ </template>
+</interface>
diff --git a/src/gnome-nibbles.gresource.xml.in b/src/gnome-nibbles.gresource.xml.in
index 58a5401..bb2abcb 100644
--- a/src/gnome-nibbles.gresource.xml.in
+++ b/src/gnome-nibbles.gresource.xml.in
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/nibbles/ui">
- <file preprocess="xml-stripblanks" alias="nibbles.ui">@top_srcdir@/data/nibbles.ui</file>
+ <file alias="nibbles.ui">@top_srcdir@/data/nibbles.ui</file>
<file alias="nibbles.css">@top_srcdir@/data/nibbles.css</file>
+ <file alias="scoreboard.ui">@top_srcdir@/data/scoreboard.ui</file>
+ <file alias="player-score-box.ui">@top_srcdir@/data/player-score-box.ui</file>
</gresource>
</gresources>
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index d9717bb..27fbdb8 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -29,9 +29,12 @@ public class Nibbles : Gtk.Application
private Gtk.ApplicationWindow window;
private Gtk.HeaderBar headerbar;
private Gtk.Stack main_stack;
+ private Gtk.Box game_box;
private Games.GridFrame frame;
- private Gtk.Box statusbar;
+ private Gtk.Stack statusbar_stack;
private Gtk.Label countdown;
+ private Scoreboard scoreboard;
+ private Gdk.Pixbuf scoreboard_life;
private Gee.LinkedList<Gtk.ToggleButton> number_of_players_buttons;
private Gtk.Revealer next_button_revealer;
@@ -111,7 +114,8 @@ public class Nibbles : Gtk.Application
headerbar = (Gtk.HeaderBar) builder.get_object ("headerbar");
main_stack = (Gtk.Stack) builder.get_object ("main_stack");
- statusbar = (Gtk.Box) builder.get_object ("statusbar");
+ game_box = (Gtk.Box) builder.get_object ("game_box");
+ statusbar_stack = (Gtk.Stack) builder.get_object ("statusbar_stack");
countdown = (Gtk.Label) builder.get_object ("countdown");
number_of_players_buttons = new Gee.LinkedList<Gtk.ToggleButton> ();
for (int i = 0; i < 2; i++)
@@ -133,7 +137,12 @@ public class Nibbles : Gtk.Application
view.show ();
frame = new Games.GridFrame (NibblesGame.WIDTH, NibblesGame.HEIGHT);
- main_stack.add_named (frame, "frame");
+ game_box.pack_start (frame);
+
+ scoreboard = new Scoreboard ();
+ scoreboard_life = view.load_pixmap_file ("scoreboard-life.svg", 2 * game.tile_size, 2 *
game.tile_size);
+ scoreboard.show ();
+ statusbar_stack.add_named (scoreboard, "scoreboard");
frame.add (view);
frame.show ();
@@ -231,15 +240,18 @@ public class Nibbles : Gtk.Application
view.new_level (game.current_level);
view.configure_event.connect (configure_event_cb);
+ game.load_worm_properties (worm_settings);
foreach (var worm in game.worms)
{
+ var color = game.worm_props.get (worm).color;
+ scoreboard.register (worm, NibblesView.colorval_name (color), scoreboard_life);
+
var actors = view.worm_actors.get (worm);
if (actors.get_stage () == null) {
view.stage.add_child (actors);
}
actors.show ();
}
- game.load_worm_properties (worm_settings);
game.add_worms ();
show_game_view ();
@@ -248,8 +260,7 @@ public class Nibbles : Gtk.Application
countdown.set_label ("%d".printf (seconds));
if (seconds == 0)
{
- countdown.set_label ("GO!");
- countdown.hide ();
+ statusbar_stack.set_visible_child_name ("scoreboard");
game.start ();
return Source.REMOVE;
}
@@ -285,8 +296,7 @@ public class Nibbles : Gtk.Application
private void show_game_view ()
{
- main_stack.set_visible_child_name ("frame");
- statusbar.set_visible (true);
+ main_stack.set_visible_child_name ("game_box");
}
private void change_number_of_players_cb (Gtk.ToggleButton button)
@@ -353,3 +363,53 @@ public class Nibbles : Gtk.Application
return new Nibbles ().run (args);
}
}
+
+[GtkTemplate (ui = "/org/gnome/nibbles/ui/scoreboard.ui")]
+public class Scoreboard : Gtk.Box
+{
+ private Gee.LinkedList<PlayerScoreBox> boxes;
+
+ public Scoreboard ()
+ {
+ boxes = new Gee.LinkedList<PlayerScoreBox> ();
+ }
+
+ public void register (Worm worm, string color_name, Gdk.Pixbuf life_pixbuf)
+ {
+ var color = Pango.Color ();
+ color.parse (color_name);
+
+ var box = new PlayerScoreBox ("Worm %d".printf (worm.id + 1), color, worm.score, worm.lives,
life_pixbuf);
+ add (box);
+ }
+}
+
+[GtkTemplate (ui = "/org/gnome/nibbles/ui/player-score-box.ui")]
+public class PlayerScoreBox : Gtk.Box
+{
+ [GtkChild]
+ private Gtk.Label name_label;
+ [GtkChild]
+ private Gtk.Label score_label;
+ [GtkChild]
+ private Gtk.Grid lives_grid;
+
+ private Gee.LinkedList<Gtk.Image> life_images;
+
+ public 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 ());
+
+ life_images = new Gee.LinkedList<Gtk.Image> ();
+
+ for (int i = 0; i < lives_left; i++)
+ {
+ var life = new Gtk.Image.from_pixbuf (life_pixbuf);
+ life.show ();
+
+ life_images.add (life);
+ lives_grid.attach (life, i % 6, i/6);
+ }
+ }
+}
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 0ee4fd1..85aec96 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -42,7 +42,7 @@ public class NibblesGame : Object
public const int GAMEDELAY = 35;
public const int BONUSDELAY = 100;
- public const int NUMWORMS = 2;
+ public const int NUMWORMS = 6;
public const int WIDTH = 92;
public const int HEIGHT = 66;
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 33cf6e5..85cb9bc 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -52,7 +52,7 @@ public class NibblesView : GtkClutter.Embed
"red",
"green",
"blue",
- "yellow",
+ "orange",
"cyan",
"purple",
"grey"
@@ -175,7 +175,7 @@ public class NibblesView : GtkClutter.Embed
load_level ();
}
- private Gdk.Pixbuf load_pixmap_file (string pixmap, int xsize, int ysize)
+ public Gdk.Pixbuf load_pixmap_file (string pixmap, int xsize, int ysize)
{
var filename = Path.build_filename (PKGDATADIR, "pixmaps", pixmap, null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]