[gnome-nibbles/wip/vala] game: replace level completed dialog with an overlay
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/wip/vala] game: replace level completed dialog with an overlay
- Date: Sun, 16 Aug 2015 20:11:13 +0000 (UTC)
commit 02f9a330bf8587d7f5e44ecd7165852f335ff54e
Author: Iulian Radu <iulian radu67 gmail com>
Date: Sun Aug 16 21:56:11 2015 +0300
game: replace level completed dialog with an overlay
data/nibbles.ui | 467 ++++++++++++++++++++++++------------------------
src/gnome-nibbles.vala | 44 ++++--
src/nibbles-view.vala | 2 +-
3 files changed, 269 insertions(+), 244 deletions(-)
---
diff --git a/data/nibbles.ui b/data/nibbles.ui
index a56710b..326b81b 100644
--- a/data/nibbles.ui
+++ b/data/nibbles.ui
@@ -31,332 +31,337 @@
<property name="title" translatable="yes">Nibbles</property>
<style><class name="main-window"/></style>
<child>
- <object class="GtkBox" id="vbox">
+ <object class="GtkOverlay" id="main_overlay">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
- <object class="GtkStack" id="main_stack">
+ <object class="GtkBox" id="vbox">
<property name="visible">True</property>
- <property name="homogeneous">True</property>
- <property name="margin">25</property>
- <property name="expand">True</property>
- <property name="transition-type">5</property> <!-- SLIDE_UP -->
- <property name="transition-duration">500</property>
+ <property name="orientation">vertical</property>
<child>
- <object class="GtkBox" id="first_run">
+ <object class="GtkStack" id="main_stack">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="width-request">350</property>
- <property name="height-request">350</property>
+ <property name="homogeneous">True</property>
+ <property name="margin">25</property>
+ <property name="expand">True</property>
+ <property name="transition-type">5</property> <!-- SLIDE_UP -->
+ <property name="transition-duration">500</property>
<child>
- <object class="GtkButton">
- <property name="visible">True</property>
- <property name="use-underline">True</property>
- <property name="label" translatable="yes">Let's _Play</property>
- <property name="action-name">app.show-new-game-screen</property>
- <property name="halign">center</property>
- <property name="valign">end</property>
- <property name="width-request">140</property>
- <property name="height-request">40</property>
- <style>
- <class name="suggested-action"/>
- <class name="play"/>
- </style>
- </object>
- <packing>
- <property name="pack-type">end</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox">
+ <object class="GtkBox" id="first_run">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="homogeneous">True</property>
- <property name="valign">center</property>
- <property name="vexpand">True</property>
+ <property name="width-request">350</property>
+ <property name="height-request">350</property>
<child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">gnome-nibbles</property>
- <property name="icon-size">6</property> <!-- DIALOG -->
- <property name="pixel-size">96</property>
- </object>
- <packing>
- <property name="pack-type">start</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Welcome,
worms.</property>
- <style><class name="menu-title"/></style>
- </object>
- <packing>
- <property name="pack-type">start</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel">
+ <object class="GtkButton">
<property name="visible">True</property>
- <property name="label" translatable="yes">Eat the treats
before the other worms, but don't hit anything!</property>
- <property name="valign">1</property> <!-- START -->
- <style><class name="tip"/></style>
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">Let's
_Play</property>
+ <property
name="action-name">app.show-new-game-screen</property>
+ <property name="halign">center</property>
+ <property name="valign">end</property>
+ <property name="width-request">140</property>
+ <property name="height-request">40</property>
+ <style>
+ <class name="suggested-action"/>
+ <class name="play"/>
+ </style>
</object>
<packing>
- <property name="pack-type">start</property>
+ <property name="pack-type">end</property>
</packing>
</child>
- </object>
- <packing>
- <property name="pack-type">end</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="name">first_run</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox" id="number_of_players">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="halign">center</property>
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="valign">center</property>
- <property name="spacing">60</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="spacing">10</property>
+ <property name="homogeneous">True</property>
+ <property name="valign">center</property>
+ <property name="vexpand">True</property>
<child>
- <object class="GtkLabel">
+ <object class="GtkImage">
<property name="visible">True</property>
- <property name="label" translatable="yes">Number of
players</property>
- <style><class name="menu-title"/></style>
+ <property name="icon-name">gnome-nibbles</property>
+ <property name="icon-size">6</property> <!-- DIALOG
-->
+ <property name="pixel-size">96</property>
</object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
- <property name="label" translatable="yes">Select the
number of human players.</property>
+ <property name="label" translatable="yes">Welcome,
worms.</property>
+ <style><class name="menu-title"/></style>
</object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
</child>
- </object>
- </child>
- <child>
- <object class="GtkBox" id="number_of_players_box">
- <property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <property name="width-request">630</property>
- <property name="height-request">90</property>
- <property name="valign">center</property>
- <property name="spacing">10</property>
- <property name="vexpand">True</property>
<child>
- <object class="GtkToggleButton" id="players1">
+ <object class="GtkLabel">
<property name="visible">True</property>
- <property name="use-underline">True</property>
- <property name="label">_1</property>
- <property name="width-request">150</property>
- <style>
- <class name="number-box"/>
- <class name="osd"/>
- </style>
+ <property name="label" translatable="yes">Eat the
treats before the other worms, but don't hit anything!</property>
+ <property name="valign">1</property> <!-- START -->
+ <style><class name="tip"/></style>
</object>
<packing>
<property name="pack-type">start</property>
</packing>
</child>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="name">first_run</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="number_of_players">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="halign">center</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="valign">center</property>
+ <property name="spacing">60</property>
<child>
- <object class="GtkToggleButton" id="players2">
+ <object class="GtkBox">
<property name="visible">True</property>
- <property name="use-underline">True</property>
- <property name="label">_2</property>
- <property name="width-request">150</property>
- <style>
- <class name="number-box"/>
- <class name="osd"/>
- </style>
+ <property name="orientation">vertical</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label"
translatable="yes">Number of players</property>
+ <style><class name="menu-title"/></style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label"
translatable="yes">Select the number of human players.</property>
+ </object>
+ </child>
</object>
- <packing>
- <property name="pack-type">start</property>
- </packing>
</child>
<child>
- <object class="GtkToggleButton" id="players3">
+ <object class="GtkBox" id="number_of_players_box">
<property name="visible">True</property>
- <property name="use-underline">True</property>
- <property name="label">_3</property>
- <property name="width-request">150</property>
- <style>
- <class name="number-box"/>
- <class name="osd"/>
- </style>
+ <property name="orientation">horizontal</property>
+ <property name="width-request">630</property>
+ <property name="height-request">90</property>
+ <property name="valign">center</property>
+ <property name="spacing">10</property>
+ <property name="vexpand">True</property>
+ <child>
+ <object class="GtkToggleButton" id="players1">
+ <property name="visible">True</property>
+ <property
name="use-underline">True</property>
+ <property name="label">_1</property>
+ <property name="width-request">150</property>
+ <style>
+ <class name="number-box"/>
+ <class name="osd"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="players2">
+ <property name="visible">True</property>
+ <property
name="use-underline">True</property>
+ <property name="label">_2</property>
+ <property name="width-request">150</property>
+ <style>
+ <class name="number-box"/>
+ <class name="osd"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="players3">
+ <property name="visible">True</property>
+ <property
name="use-underline">True</property>
+ <property name="label">_3</property>
+ <property name="width-request">150</property>
+ <style>
+ <class name="number-box"/>
+ <class name="osd"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="players4">
+ <property name="visible">True</property>
+ <property
name="use-underline">True</property>
+ <property name="label">_4</property>
+ <property name="width-request">150</property>
+ <style>
+ <class name="number-box"/>
+ <class name="osd"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="pack-type">start</property>
</packing>
</child>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRevealer" id="next_button_revealer">
+ <property name="visible">True</property>
+ <property name="transition-type">4</property> <!-- SLIDE_UP
-->
+ <property name="transition-duration">500</property>
<child>
- <object class="GtkToggleButton" id="players4">
+ <object class="GtkButton">
<property name="visible">True</property>
<property name="use-underline">True</property>
- <property name="label">_4</property>
- <property name="width-request">150</property>
+ <property name="label"
translatable="yes">_Next</property>
+ <property
name="action-name">app.show-controls-screen</property>
+ <property name="width-request">116</property>
+ <property name="height-request">34</property>
+ <property name="halign">center</property>
<style>
- <class name="number-box"/>
- <class name="osd"/>
+ <class name="suggested-action"/>
+ <class name="play"/>
</style>
</object>
- <packing>
- <property name="pack-type">start</property>
- </packing>
</child>
</object>
<packing>
- <property name="pack-type">start</property>
+ <property name="pack-type">end</property>
</packing>
</child>
- </object>
- <packing>
- <property name="pack-type">start</property>
- </packing>
- </child>
- <child>
- <object class="GtkRevealer" id="next_button_revealer">
- <property name="visible">True</property>
- <property name="transition-type">4</property> <!-- SLIDE_UP -->
- <property name="transition-duration">500</property>
- <child>
- <object class="GtkButton">
- <property name="visible">True</property>
- <property name="use-underline">True</property>
- <property name="label" translatable="yes">_Next</property>
- <property
name="action-name">app.show-controls-screen</property>
- <property name="width-request">116</property>
- <property name="height-request">34</property>
- <property name="halign">center</property>
- <style>
- <class name="suggested-action"/>
- <class name="play"/>
- </style>
- </object>
- </child>
</object>
<packing>
- <property name="pack-type">end</property>
+ <property name="name">number_of_players</property>
</packing>
</child>
- </object>
- <packing>
- <property name="name">number_of_players</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
- <property name="valign">center</property>
- <property name="spacing">25</property>
<child>
- <object class="GtkLabel">
+ <object class="GtkBox">
<property name="visible">True</property>
- <property name="label" translatable="yes">Controls</property>
+ <property name="orientation">vertical</property>
<property name="valign">center</property>
- <style><class name="menu-title"/></style>
+ <property name="spacing">25</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label"
translatable="yes">Controls</property>
+ <property name="valign">center</property>
+ <style><class name="menu-title"/></style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox" id="grids_box">
+ <property name="visible">True</property>
+ <property name="orientation">horizontal</property>
+ <property name="homogeneous">True</property>
+ <property name="valign">center</property>
+ </object>
+ </child>
</object>
</child>
<child>
- <object class="GtkBox" id="grids_box">
+ <object class="GtkButton">
<property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <property name="homogeneous">True</property>
- <property name="valign">center</property>
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">_Start</property>
+ <property name="action-name">app.start-game</property>
+ <property name="halign">center</property>
+ <property name="width-request">116</property>
+ <property name="height-request">34</property>
+ <style>
+ <class name="suggested-action"/>
+ <class name="play"/>
+ </style>
</object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
</child>
</object>
- </child>
- <child>
- <object class="GtkButton">
- <property name="visible">True</property>
- <property name="use-underline">True</property>
- <property name="label" translatable="yes">_Start</property>
- <property name="action-name">app.start-game</property>
- <property name="halign">center</property>
- <property name="width-request">116</property>
- <property name="height-request">34</property>
- <style>
- <class name="suggested-action"/>
- <class name="play"/>
- </style>
- </object>
<packing>
- <property name="pack-type">end</property>
+ <property name="name">controls</property>
</packing>
</child>
- </object>
- <packing>
- <property name="name">controls</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox" id="game_box">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
- <object class="GtkBox" id="statusbar">
+ <object class="GtkBox" id="game_box">
<property name="visible">True</property>
- <property name="halign">center</property>
+ <property name="orientation">vertical</property>
<child>
- <object class="GtkStack" id="statusbar_stack">
+ <object class="GtkBox" id="statusbar">
<property name="visible">True</property>
+ <property name="halign">center</property>
<child>
- <object class="GtkLabel" id="countdown">
- <property name="visible">True</property>
- <property name="label">3</property>
- <property name="halign">center</property>
- <style><class name="countdown"/></style>
- </object>
- <packing>
- <property name="name">countdown</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel">
+ <object class="GtkStack" id="statusbar_stack">
<property name="visible">True</property>
- <property name="label"
translatable="yes">Paused</property>
- <style><class name="menu-title"/></style>
+ <child>
+ <object class="GtkLabel" id="countdown">
+ <property name="visible">True</property>
+ <property name="label">3</property>
+ <property name="halign">center</property>
+ <style><class name="countdown"/></style>
+ </object>
+ <packing>
+ <property name="name">countdown</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label"
translatable="yes">Paused</property>
+ <style><class name="menu-title"/></style>
+ </object>
+ <packing>
+ <property name="name">paused</property>
+ </packing>
+ </child>
</object>
- <packing>
- <property name="name">paused</property>
- </packing>
</child>
</object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
</child>
</object>
<packing>
- <property name="pack-type">end</property>
+ <property name="name">game_box</property>
</packing>
</child>
- </object>
+ </object> <!-- End of main_stack -->
<packing>
- <property name="name">game_box</property>
+ <property name="pack-type">start</property>
</packing>
</child>
- </object> <!-- End of main_stack -->
- <packing>
- <property name="pack-type">start</property>
- </packing>
+ </object> <!-- End of vbox -->
</child>
- </object> <!-- End of vbox -->
+ </object>
</child>
</object> <!-- End of nibbles_app -->
</interface>
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index e7055e1..08283c5 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -28,6 +28,7 @@ public class Nibbles : Gtk.Application
private Gtk.ApplicationWindow window;
private Gtk.HeaderBar headerbar;
+ private Gtk.Overlay overlay;
private Gtk.Button new_game_button;
private Gtk.Button pause_button;
private Gtk.Stack main_stack;
@@ -139,6 +140,7 @@ public class Nibbles : Gtk.Application
window.maximize ();
headerbar = (Gtk.HeaderBar) builder.get_object ("headerbar");
+ overlay = (Gtk.Overlay) builder.get_object ("main_overlay");
new_game_button = (Gtk.Button) builder.get_object ("new_game_button");
pause_button = (Gtk.Button) builder.get_object ("pause_button");
main_stack = (Gtk.Stack) builder.get_object ("main_stack");
@@ -608,21 +610,39 @@ public class Nibbles : Gtk.Application
public void level_completed_cb ()
{
- var dialog = new Gtk.MessageDialog (window,
- Gtk.DialogFlags.MODAL,
- Gtk.MessageType.INFO,
- Gtk.ButtonsType.NONE,
- _("Level %d Completed!").printf (game.current_level));
-
- dialog.add_button (_("Next level"), Gtk.ResponseType.OK);
- dialog.response.connect ((response_id) => {
- if (response_id == Gtk.ResponseType.OK)
- restart_game_cb ();
+ new_game_action.set_enabled (false);
+ pause_action.set_enabled (false);
- dialog.destroy ();
+ var label = new Gtk.Label (_(@"Level $(game.current_level) Completed!"));
+ label.halign = Gtk.Align.CENTER;
+ label.valign = Gtk.Align.START;
+ label.set_margin_top (150);
+ label.get_style_context ().add_class ("menu-title");
+ label.show ();
+
+ var button = new Gtk.Button.with_label (_("_Next Level"));
+ button.set_use_underline (true);
+ button.halign = Gtk.Align.CENTER;
+ button.valign = Gtk.Align.END;
+ button.set_margin_bottom (100);
+ button.get_style_context ().add_class ("suggested-action");
+ button.clicked.connect (() => {
+ label.destroy ();
+ button.destroy ();
+
+ new_game_action.set_enabled (true);
+ pause_action.set_enabled (true);
+
+ restart_game_cb ();
});
+ button.show ();
- dialog.show ();
+ overlay.add_overlay (label);
+ overlay.add_overlay (button);
+
+ button.grab_focus ();
+
+ overlay.show ();
}
public void game_over_cb ()
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 12d10b2..f4e17f8 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -49,7 +49,7 @@ public class NibblesView : GtkClutter.Embed
public Gee.HashMap<Worm, WormActor> worm_actors;
public Gee.HashMap<Bonus, BonusTexture> bonus_actors;
- public const int NUM_COLORS = 7;
+ public const int NUM_COLORS = 6;
public static string[] color_lookup =
{
"red",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]