[gnome-nibbles/wip/vala: 41/64] Add screen for selecting number of players



commit 3e06ffe3d9c0629d4274202f31402e458cc8aeb2
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Sun Jul 12 15:04:07 2015 +0300

    Add screen for selecting number of players

 data/nibbles.css                   |    8 ++-
 data/nibbles.ui                    |  101 +++++++++++++++++++++++++++++++++--
 data/org.gnome.nibbles.gschema.xml |    5 ++
 src/gnome-nibbles.vala             |   64 +++++++++++++++++++++--
 4 files changed, 166 insertions(+), 12 deletions(-)
---
diff --git a/data/nibbles.css b/data/nibbles.css
index 0537d79..d941968 100644
--- a/data/nibbles.css
+++ b/data/nibbles.css
@@ -1,8 +1,8 @@
 GtkApplicationWindow.main-window {
     background: rgba (255, 255, 255, 0);
 }
-.welcome {
-  font-size:1.5em;
+.title {
+  font-size: 3em;
 }
 .tip {
   font-size: 1em;
@@ -10,3 +10,7 @@ GtkApplicationWindow.main-window {
 .play {
   font-size: 1em;
 }
+GtkToggleButton.number-box {
+    font-size: 5em;
+    color: rgba(229, 229, 229, 1);
+}
diff --git a/data/nibbles.ui b/data/nibbles.ui
index 789f69c..d7b314c 100644
--- a/data/nibbles.ui
+++ b/data/nibbles.ui
@@ -17,9 +17,9 @@
                         <property name="margin">25</property>
                         <property name="expand">True</property>
                         <child>
-                            <object class="GtkBox" id="start_box">
-                                <property name="orientation">vertical</property>
+                            <object class="GtkBox" id="first_run">
                                 <property name="visible">True</property>
+                                <property name="orientation">vertical</property>
                                 <property name="halign">center</property>
                                 <property name="valign">center</property>
                                 <property name="homogeneous">True</property>
@@ -42,8 +42,7 @@
                                     <object class="GtkLabel">
                                         <property name="visible">True</property>
                                         <property name="label" translatable="yes">Welcome, worms.</property>
-
-                                        <style><class name="welcome"/></style>
+                                        <style><class name="title"/></style>
                                     </object>
                                     <packing>
                                         <property name="pack-type">start</property>
@@ -65,7 +64,7 @@
                                         <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.start-game</property>
+                                        <property name="action-name">app.show-new-game-screen</property>
                                         <property name="halign">3</property>
                                         <property name="valign">3</property>
                                         <property name="width-request">140</property>
@@ -81,7 +80,97 @@
                                 </child>
                             </object>
                             <packing>
-                                <property name="name">start_box</property>
+                                <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="width-request">350</property>
+                                <property name="height-request">350</property>
+                                <child>
+                                    <object class="GtkLabel">
+                                        <property name="visible">True</property>
+                                        <property name="label" translatable="yes">Number of 
players</property>
+                                        <property name="valign">3</property>
+                                        <style><class name="title"/></style>
+                                    </object>
+                                    <packing>
+                                        <property name="pack-type">start</property>
+                                    </packing>
+                                </child>
+                                <child>
+                                    <object class="GtkBox" id="number_of_players_box">
+                                        <property name="visible">True</property>
+                                        <property name="orientation">horizontal</property>
+                                        <property name="width-request">250</property>
+                                        <property name="height-request">250</property>
+                                        <property name="valign">3</property>
+                                        <property name="halign">3</property>
+                                        <property name="spacing">10</property>
+                                        <child>
+                                            <object class="GtkToggleButton" id="players1">
+                                                <property name="visible">True</property>
+                                                <property name="label" translatable="yes">1</property>
+                                                <property name="width-request">200</property>
+                                                <property name="height-request">120</property>
+                                                <property name="valign">3</property>
+                                                <property name="halign">3</property>
+                                                <style><class name="number-box"/></style>
+                                            </object>
+                                            <packing>
+                                                <property name="pack-type">start</property>
+                                            </packing>
+                                        </child>
+                                        <child>
+                                            <object class="GtkToggleButton" id="players2">
+                                                <property name="visible">True</property>
+                                                <property name="label" translatable="yes">2</property>
+                                                <property name="width-request">200</property>
+                                                <property name="height-request">120</property>
+                                                <property name="valign">3</property>
+                                                <property name="halign">3</property>
+                                                <style><class name="number-box"/></style>
+                                            </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_1_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.start-game</property>
+                                                <property name="halign">3</property>
+                                                <property name="valign">3</property>
+                                                <property name="width-request">140</property>
+                                                <property name="height-request">40</property>
+                                                <style>
+                                                    <class name="suggested-action"/>
+                                                    <class name="play"/>
+                                                </style>
+                                            </object>
+                                        </child>
+                                    </object>
+                                    <packing>
+                                        <property name="pack-type">end</property>
+                                    </packing>
+                                </child>
+                            </object>
+                            <packing>
+                                <property name="name">number_of_players</property>
                             </packing>
                         </child>
                     </object> <!-- End of main_stack -->
diff --git a/data/org.gnome.nibbles.gschema.xml b/data/org.gnome.nibbles.gschema.xml
index 686663a..011d2d2 100644
--- a/data/org.gnome.nibbles.gschema.xml
+++ b/data/org.gnome.nibbles.gschema.xml
@@ -15,6 +15,11 @@
       <summary>true if the window is maximized</summary>
       <description>true if the window is maximized.</description>
     </key>
+    <key name="first-run" type="b">
+      <default>true</default>
+      <summary>Is this the first run</summary>
+      <description>Setting to decide whether to show first-run hint dialog or not.</description>
+    </key>
     <key name="tile-size" type="i">
       <default>7</default>
       <range min="7"/>
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 36ddaaa..75c0db2 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -31,6 +31,9 @@ public class Nibbles : Gtk.Application
     private Gtk.Stack main_stack;
     private Games.GridFrame frame;
 
+    private Gee.LinkedList<Gtk.ToggleButton> number_of_players_buttons;
+    private Gtk.Revealer next_button_1_revealer;
+
     private NibblesView? view;
     private NibblesGame? game = null;
 
@@ -40,6 +43,11 @@ public class Nibbles : Gtk.Application
         {"quit", quit}
     };
 
+    private const ActionEntry menu_entries[] =
+    {
+        {"show-new-game-screen", show_new_game_screen_cb}
+    };
+
     private static const OptionEntry[] option_entries =
     {
         { "version", 'v', 0, OptionArg.NONE, null,
@@ -77,6 +85,7 @@ public class Nibbles : Gtk.Application
         Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, 
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
 
         add_action_entries (action_entries, this);
+        add_action_entries (menu_entries, this);
 
         settings = new Settings ("org.gnome.nibbles");
         worm_settings = new Gee.ArrayList<Settings> ();
@@ -93,16 +102,30 @@ public class Nibbles : Gtk.Application
         window.size_allocate.connect (size_allocate_cb);
         window.window_state_event.connect (window_state_event_cb);
         window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
-
-        var rgba = Gdk.RGBA () { red = 1, green = 1, blue = 1, alpha = 1 };
         if (settings.get_boolean ("window-is-maximized"))
             window.maximize ();
 
         headerbar = builder.get_object ("headerbar") as Gtk.HeaderBar;
         main_stack = builder.get_object ("main_stack") as Gtk.Stack;
+
+        number_of_players_buttons = new Gee.LinkedList<Gtk.ToggleButton> ();
+        for (int i = 0; i < 2; i++)
+        {
+            var button = (Gtk.ToggleButton) builder.get_object ("players%d".printf (i + 1));
+            button.toggled.connect (change_number_of_players_cb);
+            number_of_players_buttons.add (button);
+        }
+        next_button_1_revealer = (Gtk.Revealer) builder.get_object ("next_button_1_revealer");
+
         window.set_titlebar (headerbar);
 
         add_window (window);
+
+        var first_run = settings.get_boolean ("first-run");
+        if (first_run)
+            show_first_run_screen ();
+        else
+            show_new_game_screen_cb ();
     }
 
     protected override void activate ()
@@ -174,12 +197,20 @@ public class Nibbles : Gtk.Application
 
     private void start_game_cb ()
     {
+        settings.set_boolean ("first-run", false);
         start_game ();
     }
 
-    private void show_new_game_screen ()
+    private void show_first_run_screen ()
     {
-        main_stack.set_visible_child_name ("start_box");
+        main_stack.set_visible_child_name ("first_run");
+    }
+
+    private void show_new_game_screen_cb ()
+    {
+        main_stack.set_transition_type (Gtk.StackTransitionType.SLIDE_UP);
+        main_stack.set_transition_duration (500);
+        main_stack.set_visible_child_name ("number_of_players");
     }
 
     private void show_game_view ()
@@ -229,6 +260,31 @@ public class Nibbles : Gtk.Application
         game.start ();
     }
 
+    private void change_number_of_players_cb (Gtk.ToggleButton button)
+    {
+        if (!button.get_active () && button.get_style_context ().has_class ("suggested-action"))
+        {
+            button.set_active (true);
+        }
+        else if (button.get_active () && !button.get_style_context ().has_class ("suggested-action"))
+        {
+            next_button_1_revealer.set_reveal_child (true);
+            button.get_style_context ().add_class ("suggested-action");
+            foreach (var other_button in number_of_players_buttons)
+            {
+                if (button != other_button)
+                {
+                    if (other_button.get_active ())
+                    {
+                        other_button.get_style_context ().remove_class ("suggested-action");
+                        other_button.set_active (false);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
     public static int main (string[] args)
     {
         var context = new OptionContext ("");


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