[gnome-nibbles/arnaudb/kill-preferences-dialog: 4/14] Add Speed panel.



commit bcc819d018afce205bbd15cd99d11c12f26b8c3e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Jun 2 16:25:32 2020 +0200

    Add Speed panel.

 data/gnome-nibbles.gresource.xml |   1 +
 data/nibbles.css                 |  42 ++++++++++
 data/nibbles.ui                  |  14 ++++
 data/preferences-dialog.ui       | 164 ---------------------------------------
 data/speed.ui                    | 158 +++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                   |   2 +
 po/POTFILES.skip                 |   1 +
 src/meson.build                  |   1 +
 src/nibbles-window.vala          |  32 +++++++-
 src/preferences-dialog.vala      |  50 ------------
 src/speed.vala                   |  72 +++++++++++++++++
 11 files changed, 320 insertions(+), 217 deletions(-)
---
diff --git a/data/gnome-nibbles.gresource.xml b/data/gnome-nibbles.gresource.xml
index 60b64d7..67baff8 100644
--- a/data/gnome-nibbles.gresource.xml
+++ b/data/gnome-nibbles.gresource.xml
@@ -10,6 +10,7 @@
     <file preprocess="xml-stripblanks"                  >player-score-box.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">preferences-dialog.ui</file>
     <file preprocess="xml-stripblanks"                  >scoreboard.ui</file>
+    <file preprocess="xml-stripblanks"                  >speed.ui</file>
   </gresource>
 </gresources>
 
diff --git a/data/nibbles.css b/data/nibbles.css
index bf379f2..7ed931c 100644
--- a/data/nibbles.css
+++ b/data/nibbles.css
@@ -31,8 +31,10 @@ window {
   font-size: 3em;
   font-weight: bold;
   font-family: Sans;
+
   padding: 1px 38px;
   background-image: linear-gradient(to bottom, #3e4444);
+
   color:@theme-fg-color;
 }
 .number-box:disabled {
@@ -45,6 +47,46 @@ window {
   background-image: linear-gradient(to bottom, #215d9c);
 }
 
+/*\
+* * speed screen
+\*/
+
+/* the speed buttons */
+.speed-box
+{
+  font-size: 1.5em;
+  font-weight: bold;
+  font-family: Sans;
+
+  min-width:20em;
+  padding: 1em 1.5em 1em 1.5em;
+  background-image: linear-gradient(to bottom, #3e4444);
+
+  color:@theme-fg-color;
+}
+.speed-box:disabled {
+  color:@theme-fg-color;
+}
+.speed-box:hover {
+  background-image: linear-gradient(to bottom, rgba(60, 69, 71, 0.8));
+}
+.speed-box:checked {
+  background-image: linear-gradient(to bottom, #215d9c);
+}
+
+/* the empty space */
+separator.speed-separator {
+  background-color:transparent;
+  border-color:transparent;
+  padding:0.2em;
+}
+
+/* the checkbutton */
+modelbutton.speed-box > check {
+  min-height: 1em;
+  min-width:  1em;
+}
+
 /*\
 * * controls screen
 \*/
diff --git a/data/nibbles.ui b/data/nibbles.ui
index 149f40a..20b334e 100644
--- a/data/nibbles.ui
+++ b/data/nibbles.ui
@@ -20,6 +20,12 @@
 -->
 <interface>
   <menu id="app-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Sound</attribute>
+        <attribute name="action">win.sound</attribute>
+      </item>
+    </section>
     <section>
       <item>
         <attribute name="label" translatable="yes">_Scores</attribute>
@@ -107,6 +113,14 @@
             <property name="name">number_of_players</property>
           </packing>
         </child>
+        <child>
+          <object class="Speed" id="speed">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="name">speed</property>
+          </packing>
+        </child>
         <child>
           <object class="Controls" id="controls">
             <property name="visible">True</property>
diff --git a/data/preferences-dialog.ui b/data/preferences-dialog.ui
index 93eae2b..36bb9bf 100644
--- a/data/preferences-dialog.ui
+++ b/data/preferences-dialog.ui
@@ -33,170 +33,6 @@
           <object class="GtkNotebook" id="notebook">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <child>
-              <object class="GtkBox" id="box_general">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="border_width">12</property>
-                <property name="spacing">50</property>
-                <property name="orientation">horizontal</property>
-                <property name="homogeneous">True</property>
-                <child>
-                  <object class="GtkBox" id="box_speed">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="border_width">0</property>
-                    <property name="spacing">4</property>
-                    <property name="orientation">vertical</property>
-                    <child>
-                      <object class="GtkLabel" id="speed_label">
-                        <property name="label" translatable="yes">Speed</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0.5</property>
-                        <property name="yalign">0.5</property>
-                        <property name="halign">start</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="pack-type">start</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkRadioButton" id="beginner_radio_button">
-                        <property name="use-underline">True</property>
-                        <property name="label" translatable="yes">_Beginner</property>
-                        <property name="visible">True</property>
-                        <property name="yalign">0.5</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="active">False</property>
-                        <property name="draw_indicator">True</property>
-                      </object>
-                      <packing>
-                        <property name="pack-type">start</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkRadioButton" id="slow_radio_button">
-                        <property name="use-underline">True</property>
-                        <property name="label" translatable="yes">_Slow</property>
-                        <property name="visible">True</property>
-                        <property name="yalign">0.5</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="active">False</property>
-                        <property name="draw_indicator">True</property>
-                        <property name="group">beginner_radio_button</property>
-                      </object>
-                      <packing>
-                        <property name="pack-type">start</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkRadioButton" id="medium_radio_button">
-                        <property name="use-underline">True</property>
-                        <property name="label" translatable="yes">_Medium</property>
-                        <property name="visible">True</property>
-                        <property name="yalign">0.5</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="active">False</property>
-                        <property name="draw_indicator">True</property>
-                        <property name="group">beginner_radio_button</property>
-                      </object>
-                      <packing>
-                        <property name="pack-type">start</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkRadioButton" id="fast_radio_button">
-                        <property name="use-underline">True</property>
-                        <property name="label" translatable="yes">_Fast</property>
-                        <property name="visible">True</property>
-                        <property name="yalign">0.5</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="active">False</property>
-                        <property name="draw_indicator">True</property>
-                        <property name="group">beginner_radio_button</property>
-                      </object>
-                      <packing>
-                        <property name="pack-type">start</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkBox" id="box_options">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="border_width">0</property>
-                    <property name="spacing">7</property>
-                    <property name="orientation">vertical</property>
-                    <child>
-                      <object class="GtkLabel" id="options_label">
-                        <property name="label" translatable="yes">Options</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0.5</property>
-                        <property name="yalign">0.5</property>
-                        <property name="halign">start</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="pack-type">start</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkCheckButton" id="sound_check_button">
-                        <property name="use-underline">True</property>
-                        <property name="label" translatable="yes">E_nable sounds</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="yalign">0.5</property>
-                      </object>
-                      <packing>
-                        <property name="pack-type">start</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkCheckButton" id="fakes_check_button">
-                        <property name="use-underline">True</property>
-                        <property name="label" translatable="yes">_Enable fake bonuses</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="yalign">0.5</property>
-                      </object>
-                      <packing>
-                        <property name="pack-type">start</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
-                </child>
-              </object>
-            </child>
-            <child type="tab">
-              <object class="GtkLabel" id="label_general">
-                <property name="use-underline">True</property>
-                <property name="label" translatable="yes">_General</property>
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-              </object>
-              <packing>
-                <property name="tab_fill">False</property>
-              </packing>
-            </child>
             <child>
               <object class="GtkBox" id="box_worm_1">
                 <property name="visible">True</property>
diff --git a/data/speed.ui b/data/speed.ui
new file mode 100644
index 0000000..db88a69
--- /dev/null
+++ b/data/speed.ui
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   This file is part of GNOME Nibbles.
+
+   Copyright (C) 2015-2016 Iulian Radu
+   Copyright (C) 2020 Arnaud Bonatti
+
+   GNOME Nibbles 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.
+
+   GNOME Nibbles 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 GNOME Nibbles.  If not, see <https://www.gnu.org/licenses/>.
+-->
+<interface>
+  <template class="Speed" parent="GtkBox">
+    <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">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Preferences</property>
+            <property name="valign">center</property>
+            <style>
+              <class name="menu-title"/>
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <property name="valign">center</property>
+            <property name="halign">center</property>
+            <property name="spacing">10</property>
+            <property name="vexpand">True</property>
+            <child>
+              <object class="GtkToggleButton" id="speed4">
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <property name="halign">fill</property>
+                <property name="xalign">0.0</property>
+                <property name="use-underline">True</property>
+                <property name="label" translatable="yes">_Beginner</property>
+                <property name="action-name">speed.change-speed</property>
+                <property name="action-target">@i 4</property>
+                <property name="sensitive" bind-source="speed4" bind-property="active" 
bind-flags="invert-boolean"/>
+                <style>
+                  <class name="speed-box"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkToggleButton" id="speed3">
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <property name="halign">fill</property>
+                <property name="xalign">0.0</property>
+                <property name="use-underline">True</property>
+                <property name="label" translatable="yes">_Slow</property>
+                <property name="action-name">speed.change-speed</property>
+                <property name="action-target">@i 3</property>
+                <property name="sensitive" bind-source="speed3" bind-property="active" 
bind-flags="invert-boolean"/>
+                <style>
+                  <class name="speed-box"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkToggleButton" id="speed2">
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <property name="halign">fill</property>
+                <property name="xalign">0.0</property>
+                <property name="use-underline">True</property>
+                <property name="label" translatable="yes">_Medium</property>
+                <property name="action-name">speed.change-speed</property>
+                <property name="action-target">@i 2</property>
+                <property name="sensitive" bind-source="speed2" bind-property="active" 
bind-flags="invert-boolean"/>
+                <style>
+                  <class name="speed-box"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkToggleButton" id="speed1">
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <property name="halign">fill</property>
+                <property name="xalign">0.0</property>
+                <property name="use-underline">True</property>
+                <property name="label" translatable="yes">_Fast</property>
+                <property name="action-name">speed.change-speed</property>
+                <property name="action-target">@i 1</property>
+                <property name="sensitive" bind-source="speed1" bind-property="active" 
bind-flags="invert-boolean"/>
+                <style>
+                  <class name="speed-box"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSeparator">
+                <property name="visible">True</property>
+                <property name="orientation">horizontal</property>
+                <style>
+                  <class name="speed-separator"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkModelButton" id="fakes_modelbutton">
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <property name="halign">fill</property>
+                <property name="use-underline">True</property>
+                <property name="text" translatable="yes">_Enable fake bonuses</property>
+                <property name="action-name">win.fakes</property>
+                <style>
+                  <class name="speed-box"/>
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkButton">
+        <property name="visible">True</property>
+        <property name="can-default">True</property>
+        <property name="use-underline">True</property>
+        <property name="label" translatable="yes">_Next</property>
+        <property name="action-name">win.next-screen</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>
+  </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3ff3477..37f7e98 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -10,6 +10,7 @@ data/org.gnome.Nibbles.gschema.xml
 data/players.ui
 data/player-score-box.ui
 data/preferences-dialog.ui
+data/speed.ui
 src/controls.vala
 src/gnome-nibbles.vala
 src/nibbles-view.vala
@@ -17,3 +18,4 @@ src/nibbles-window.vala
 src/players.vala
 src/preferences-dialog.vala
 src/scoreboard.vala
+src/speed.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 2a15376..45c1023 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -5,3 +5,4 @@ src/nibbles-window.c
 src/players.c
 src/preferences-dialog.c
 src/scoreboard.c
+src/speed.c
diff --git a/src/meson.build b/src/meson.build
index 0eb7db5..0d704c7 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -30,6 +30,7 @@ gnome_nibbles_sources = [
     'players.vala',
     'preferences-dialog.vala',
     'scoreboard.vala',
+    'speed.vala',
     'warp.vala',
     'worm.vala',
     resources,
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 878f5e6..0283d61 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -42,6 +42,7 @@ private class NibblesWindow : ApplicationWindow
 
     /* Pre-game screen widgets */
     [GtkChild] private Players players;
+    [GtkChild] private Speed speed;
     [GtkChild] private Controls controls;
 
     /* Statusbar widgets */
@@ -82,7 +83,7 @@ private class NibblesWindow : ApplicationWindow
         { "preferences",    preferences_cb  },
         { "scores",         scores_cb       },
 
-        { "next-screen",    next_screen_cb  },  // called from first-run, players and controls
+        { "next-screen",    next_screen_cb  },  // called from first-run, players, speed and controls
         { "back",           back_cb         }   // called on Escape pressed; disabled only during countdown 
(TODO pause?)
     };
 
@@ -95,6 +96,8 @@ private class NibblesWindow : ApplicationWindow
 
         settings = new GLib.Settings ("org.gnome.Nibbles");
         settings.changed.connect (settings_changed_cb);
+        add_action (settings.create_action ("sound"));
+        add_action (settings.create_action ("fakes"));
 
         worm_settings = new Gee.ArrayList<GLib.Settings> ();
         for (int i = 0; i < NibblesGame.MAX_WORMS; i++)
@@ -153,6 +156,10 @@ private class NibblesWindow : ApplicationWindow
         game.numai = numai;
         players.set_values (game.numhumans, numai);
 
+        /* Speed screen */
+        speed.set_values (settings.get_int ("speed"),
+                          settings.get_boolean ("fakes"));
+
         /* Controls screen */
         controls.load_pixmaps (view.tile_size);
 
@@ -441,6 +448,9 @@ private class NibblesWindow : ApplicationWindow
                 show_new_game_screen (/* after first run */ true);
                 break;
             case "number_of_players":
+                show_speed_screen ();
+                break;
+            case "speed":
                 show_controls_screen ();
                 break;
             case "controls":
@@ -479,7 +489,7 @@ private class NibblesWindow : ApplicationWindow
         main_stack.set_transition_type (StackTransitionType.SLIDE_UP);
     }
 
-    private void show_controls_screen ()
+    private void show_speed_screen ()
     {
         int numhumans, numai;
         players.get_values (out numhumans, out numai);
@@ -488,6 +498,19 @@ private class NibblesWindow : ApplicationWindow
         settings.set_int ("players", numhumans);
         settings.set_int ("ai",      numai);
 
+        main_stack.set_visible_child_name ("speed");
+    }
+
+    private void show_controls_screen ()
+    {
+        int game_speed;
+        bool fakes;
+        speed.get_values (out game_speed, out fakes);
+        game.speed = game_speed;
+        game.fakes = fakes;
+        settings.set_int ("speed", game_speed);
+        settings.set_boolean ("fakes", fakes);
+
         /* Create worms and load properties */
         game.create_worms ();
         game.load_worm_properties (worm_settings);
@@ -527,9 +550,12 @@ private class NibblesWindow : ApplicationWindow
                 break;
             case "number_of_players":
                 break;
-            case "controls":
+            case "speed":
                 main_stack.set_visible_child_name ("number_of_players");
                 break;
+            case "controls":
+                main_stack.set_visible_child_name ("speed");
+                break;
             case "game_box":
                 new_game_cb ();
                 break;
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index 3c91e6f..6f0d8cf 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -27,12 +27,6 @@ private class PreferencesDialog : Dialog
     private Gee.ArrayList<GLib.Settings> worm_settings;
 
     [GtkChild] private Notebook         notebook;
-    [GtkChild] private RadioButton      beginner_radio_button;
-    [GtkChild] private RadioButton      slow_radio_button;
-    [GtkChild] private RadioButton      medium_radio_button;
-    [GtkChild] private RadioButton      fast_radio_button;
-    [GtkChild] private CheckButton      sound_check_button;
-    [GtkChild] private CheckButton      fakes_check_button;
     [GtkChild] private Gtk.ListStore    list_store_1;
     [GtkChild] private Gtk.ListStore    list_store_2;
     [GtkChild] private Gtk.ListStore    list_store_3;
@@ -46,7 +40,6 @@ private class PreferencesDialog : Dialog
     [GtkChild] private ComboBoxText     combo_box_3;
     [GtkChild] private ComboBoxText     combo_box_4;
 
-    private Gee.ArrayList<RadioButton>      radio_buttons;
     private Gee.ArrayList<Gtk.ListStore>    list_stores;
     private Gee.ArrayList<TreeView>         tree_views;
     private Gee.ArrayList<ComboBoxText>     combo_boxes;
@@ -65,28 +58,6 @@ private class PreferencesDialog : Dialog
 
         this.set_transient_for (window);
 
-        /* Speed radio buttons */
-        radio_buttons = new Gee.ArrayList<RadioButton> ();
-        radio_buttons.add (beginner_radio_button);
-        radio_buttons.add (slow_radio_button);
-        radio_buttons.add (medium_radio_button);
-        radio_buttons.add (fast_radio_button);
-
-        foreach (var radio_button in radio_buttons)
-        {
-            var speed = NibblesGame.MAX_SPEED - radio_buttons.index_of (radio_button);
-            radio_button.set_active (speed == settings.get_int ("speed"));
-            radio_button.toggled.connect (radio_button_toggled_cb);
-        }
-
-        /* Sound check button */
-        sound_check_button.set_active (settings.get_boolean ("sound"));
-        sound_check_button.toggled.connect (sound_toggled_cb);
-
-        /* Fake bonuses check button */
-        fakes_check_button.set_active (settings.get_boolean ("fakes"));
-        fakes_check_button.toggled.connect (fakes_toggles_cb);
-
         /* Control keys */
         tree_views = new Gee.ArrayList<TreeView> ();
         tree_views.add (tree_view_1);
@@ -157,27 +128,6 @@ private class PreferencesDialog : Dialog
         }
     }
 
-    private void radio_button_toggled_cb (ToggleButton button)
-    {
-        if (button.get_active ())
-        {
-            var speed = NibblesGame.MAX_SPEED - radio_buttons.index_of ((RadioButton) button);
-            settings.set_int ("speed", speed);
-        }
-    }
-
-    private void sound_toggled_cb ()
-    {
-        var play_sound = sound_check_button.get_active ();
-        settings.set_boolean ("sound", play_sound);
-    }
-
-    private void fakes_toggles_cb ()
-    {
-        var has_fakes = fakes_check_button.get_active ();
-        settings.set_boolean ("fakes", has_fakes);
-    }
-
     private void accel_edited_cb (CellRendererAccel cell, string path_string, uint keyval,
                                   Gdk.ModifierType mask, uint hardware_keycode)
     {
diff --git a/src/speed.vala b/src/speed.vala
new file mode 100644
index 0000000..b8737d4
--- /dev/null
+++ b/src/speed.vala
@@ -0,0 +1,72 @@
+/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+
+   Gnome Nibbles: Gnome Worm Game
+   Copyright (C) 2020 Arnaud Bonatti <arnaud bonatti 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/speed.ui")]
+private class Speed : Box
+{
+    private SimpleAction speed_action;
+
+    [GtkChild] private ModelButton fakes_modelbutton;
+    private bool fakes;
+
+    private const GLib.ActionEntry [] players_action_entries =
+    {
+        { "change-speed", null,         "i", "4", change_speed },
+        { "fake-bonuses", allow_fakes }
+    };
+
+    construct
+    {
+        SimpleActionGroup action_group = new SimpleActionGroup ();
+        action_group.add_action_entries (players_action_entries, this);
+        insert_action_group ("speed", action_group);
+
+        speed_action = (SimpleAction) action_group.lookup_action ("change-speed");
+    }
+
+    internal inline void set_values (int speed, bool fakes)
+    {
+        speed_action.set_state (speed);
+
+        fakes_modelbutton.active = fakes;
+        this.fakes = fakes;
+    }
+
+    internal inline void get_values (out int speed, out bool fakes)
+    {
+        speed = speed_action.get_state ().get_int32 ();
+
+        fakes = this.fakes;
+    }
+
+    private inline void change_speed (SimpleAction _speed_action, Variant variant)
+    {
+        int speed = variant.get_int32 ();
+        if (speed < 1 || speed > 4)
+            assert_not_reached ();
+        _speed_action.set_state (speed);
+    }
+
+    private void allow_fakes (/* SimpleAction _speed_action, Variant? variant */)
+    {
+        fakes = fakes_modelbutton.active;
+    }
+}


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