[gnome-nibbles/arnaudb/kill-preferences-dialog: 8/8] Remove Preferences entry.



commit e578bb9d4f5d32c9c1048bfb249e7f626ce9f339
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jun 4 00:33:29 2020 +0200

    Remove Preferences entry.

 data/controls-grid.ui       | 217 +++++++++++++++++++++++---------------------
 data/controls.ui            |   2 +
 data/nibbles.css            |  24 +++++
 data/nibbles.ui             |   5 -
 data/preferences-dialog.ui  |  46 +++++++---
 src/controls.vala           |   4 +-
 src/nibbles-window.vala     |  14 +--
 src/preferences-dialog.vala |  12 ++-
 8 files changed, 190 insertions(+), 134 deletions(-)
---
diff --git a/data/controls-grid.ui b/data/controls-grid.ui
index 49d6547..fb18ae8 100644
--- a/data/controls-grid.ui
+++ b/data/controls-grid.ui
@@ -18,114 +18,125 @@
    with this GNOME Nibbles.  If not, see <https://www.gnu.org/licenses/>.
 -->
 <interface>
-  <template class="ControlsGrid" parent="GtkGrid">
+  <template class="ControlsGrid" parent="GtkButton">
     <property name="visible">True</property>
-    <property name="valign">center</property>
     <property name="halign">center</property>
-    <property name="vexpand">True</property>
-    <property name="row_spacing">5</property>
-    <property name="column_spacing">5</property>
-    <child>
-      <object class="GtkLabel" id="name_label">
-        <property name="visible">True</property>
-      </object>
-      <packing>
-        <property name="left-attach">0</property>
-        <property name="top-attach">0</property>
-        <property name="width">5</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkImage" id="arrow_up">
-        <property name="visible">True</property>
-      </object>
-      <packing>
-        <property name="left-attach">2</property>
-        <property name="top-attach">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="move_up_label">
-        <property name="visible">True</property>
-        <property name="height-request">45</property>
-        <property name="width-request">45</property>
-        <style>
-          <class name="controls-button"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left-attach">2</property>
-        <property name="top-attach">2</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkImage" id="arrow_left">
-        <property name="visible">True</property>
-      </object>
-      <packing>
-        <property name="left-attach">0</property>
-        <property name="top-attach">3</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="move_left_label">
-        <property name="visible">True</property>
-        <property name="height-request">45</property>
-        <property name="width-request">45</property>
-        <style>
-          <class name="controls-button"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left-attach">1</property>
-        <property name="top-attach">3</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="move_right_label">
-        <property name="visible">True</property>
-        <property name="height-request">45</property>
-        <property name="width-request">45</property>
-        <style>
-          <class name="controls-button"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left-attach">3</property>
-        <property name="top-attach">3</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkImage" id="arrow_right">
-        <property name="visible">True</property>
-      </object>
-      <packing>
-        <property name="left-attach">4</property>
-        <property name="top-attach">3</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="move_down_label">
-        <property name="visible">True</property>
-        <property name="height-request">45</property>
-        <property name="width-request">45</property>
-        <style>
-          <class name="controls-button"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left-attach">2</property>
-        <property name="top-attach">4</property>
-      </packing>
-    </child>
+    <property name="valign">center</property>
+    <property name="action-name">win.preferences</property>
+    <style>
+      <class name="controls-box"/>
+    </style>
     <child>
-      <object class="GtkImage" id="arrow_down">
+      <object class="GtkGrid">
         <property name="visible">True</property>
+        <property name="valign">center</property>
+        <property name="halign">center</property>
+        <property name="vexpand">True</property>
+        <property name="row_spacing">5</property>
+        <property name="column_spacing">5</property>
+        <child>
+          <object class="GtkLabel" id="name_label">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">0</property>
+            <property name="width">5</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage" id="arrow_up">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="left-attach">2</property>
+            <property name="top-attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="move_up_label">
+            <property name="visible">True</property>
+            <property name="height-request">45</property>
+            <property name="width-request">45</property>
+            <style>
+              <class name="controls-button"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">2</property>
+            <property name="top-attach">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage" id="arrow_left">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="move_left_label">
+            <property name="visible">True</property>
+            <property name="height-request">45</property>
+            <property name="width-request">45</property>
+            <style>
+              <class name="controls-button"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="move_right_label">
+            <property name="visible">True</property>
+            <property name="height-request">45</property>
+            <property name="width-request">45</property>
+            <style>
+              <class name="controls-button"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">3</property>
+            <property name="top-attach">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage" id="arrow_right">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="left-attach">4</property>
+            <property name="top-attach">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="move_down_label">
+            <property name="visible">True</property>
+            <property name="height-request">45</property>
+            <property name="width-request">45</property>
+            <style>
+              <class name="controls-button"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">2</property>
+            <property name="top-attach">4</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage" id="arrow_down">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="left-attach">2</property>
+            <property name="top-attach">5</property>
+          </packing>
+        </child>
       </object>
-      <packing>
-        <property name="left-attach">2</property>
-        <property name="top-attach">5</property>
-      </packing>
     </child>
   </template>
 </interface>
diff --git a/data/controls.ui b/data/controls.ui
index f80a87a..5568284 100644
--- a/data/controls.ui
+++ b/data/controls.ui
@@ -41,7 +41,9 @@
             <property name="visible">True</property>
             <property name="orientation">horizontal</property>
             <property name="homogeneous">True</property>
+            <property name="halign">center</property>
             <property name="valign">center</property>
+            <property name="spacing">20</property>
           </object>
         </child>
       </object>
diff --git a/data/nibbles.css b/data/nibbles.css
index e50de50..7101123 100644
--- a/data/nibbles.css
+++ b/data/nibbles.css
@@ -91,6 +91,30 @@ modelbutton.speed-box > check {
 * * controls screen
 \*/
 
+/* the controls buttons */
+button.controls-box {
+  background-image:-gtk-icontheme('emblem-system-symbolic');
+  background-size:2.5em;
+  background-repeat:no-repeat;
+  background-position:calc(100%-1em) calc(100%-1em);
+  background-color:transparent;
+
+  padding-top:1em;
+
+  border-radius:2em;
+  border-width:6px;
+
+  transition:all 0s;    /* looks impossible to transition the background image color, so disable transitions 
*/
+
+  border-color:#3e4444;
+  color:@insensitive_fg_color;
+}
+button.controls-box:hover {
+  border-color:#215d9c;
+  color:@theme_fg_color;
+}
+
+/* key indicators */
 .controls-button {
   padding: 4px 8px;
   border: 1px solid;
diff --git a/data/nibbles.ui b/data/nibbles.ui
index 71e31be..7f00add 100644
--- a/data/nibbles.ui
+++ b/data/nibbles.ui
@@ -35,11 +35,6 @@
       </item>
     </section>
     <section>
-      <item>
-        <!-- Translators: entry of the hamburger menu (with a mnemonic that appears when pressing Alt); 
opens the Preferences dialog -->
-        <attribute name="label" translatable="yes">_Preferences</attribute>
-        <attribute name="action">win.preferences</attribute>
-      </item>
       <item>
         <!-- Translators: entry of the hamburger menu (with a mnemonic that appears when pressing Alt); 
opens the help of the application -->
         <attribute name="label" translatable="yes">_Help</attribute>
diff --git a/data/preferences-dialog.ui b/data/preferences-dialog.ui
index 4b5d25f..fb9ace2 100644
--- a/data/preferences-dialog.ui
+++ b/data/preferences-dialog.ui
@@ -19,20 +19,38 @@
    with this GNOME Nibbles.  If not, see <https://www.gnu.org/licenses/>.
 -->
 <interface>
-  <object class="GtkComboBoxText" id="worm_combobox">
+  <object class="GtkStack" id="headerbar_stack">
     <property name="visible">True</property>
-    <property name="active-id">worm1</property>
-    <items>
-      <!-- Translators: item in the title-combobox of the Preferences dialog; allows to configure 1st worm 
controls and color -->
-      <item translatable="yes" id="worm1">Worm 1</item>
-      <!-- Translators: item in the title-combobox of the Preferences dialog; allows to configure 2nd worm 
controls and color -->
-      <item translatable="yes" id="worm2">Worm 2</item>
-      <!-- Translators: item in the title-combobox of the Preferences dialog; allows to configure 3rd worm 
controls and color -->
-      <item translatable="yes" id="worm3">Worm 3</item>
-      <!-- Translators: item in the title-combobox of the Preferences dialog; allows to configure 4th worm 
controls and color -->
-      <item translatable="yes" id="worm4">Worm 4</item>
-    </items>
-    <signal name="changed" handler="on_worm_change"/>
+    <child>
+      <object class="GtkComboBoxText" id="worm_combobox">
+        <property name="visible">True</property>
+        <property name="active-id">worm1</property>
+        <items>
+          <!-- Translators: item in the title-combobox of the Controls configuration dialog; allows to 
configure 1st worm controls and color -->
+          <item translatable="yes" id="worm1">Worm 1</item>
+          <!-- Translators: item in the title-combobox of the Controls configuration dialog; allows to 
configure 2nd worm controls and color -->
+          <item translatable="yes" id="worm2">Worm 2</item>
+          <!-- Translators: item in the title-combobox of the Controls configuration dialog; allows to 
configure 3rd worm controls and color -->
+          <item translatable="yes" id="worm3">Worm 3</item>
+          <!-- Translators: item in the title-combobox of the Controls configuration dialog; allows to 
configure 4th worm controls and color -->
+          <item translatable="yes" id="worm4">Worm 4</item>
+        </items>
+        <signal name="changed" handler="on_worm_change"/>
+      </object>
+      <packing>
+        <property name="name">preferences-combo</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <!-- Translators: title of the Controls configuration dialog, if there is only one worm; allows to 
configure the worm controls and color -->
+        <property name="label" translatable="yes">Controls</property>
+      </object>
+      <packing>
+        <property name="name">preferences-label</property>
+      </packing>
+    </child>
   </object>
   <template class="PreferencesDialog" parent="GtkWindow">
     <property name="can_focus">False</property>
@@ -43,7 +61,7 @@
       <object class="GtkHeaderBar">
         <property name="visible">True</property>
         <property name="show-close-button">True</property>
-        <property name="custom-title">worm_combobox</property>
+        <property name="custom-title">headerbar_stack</property>
       </object>
     </child>
     <child>
diff --git a/src/controls.vala b/src/controls.vala
index 7762245..c14a0db 100644
--- a/src/controls.vala
+++ b/src/controls.vala
@@ -59,7 +59,7 @@ private class Controls : Box
 }
 
 [GtkTemplate (ui = "/org/gnome/nibbles/ui/controls-grid.ui")]
-private class ControlsGrid : Grid
+private class ControlsGrid : Button
 {
     [GtkChild] private Label name_label;
     [GtkChild] private Image arrow_up;
@@ -82,6 +82,8 @@ private class ControlsGrid : Grid
     {
         this.worm_props = worm_props;
 
+        set_action_target ("i", worm_id + 1);
+
         /* Translators: text displayed in a screen showing the keys used by the players; the %d is replaced 
by the number that identifies the player */
         var player_id = _("Player %d").printf (worm_id + 1);
         color_handler = worm_props.notify ["color"].connect (() => {
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 7507da2..7942f89 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -78,7 +78,7 @@ private class NibblesWindow : ApplicationWindow
     {
         { "new-game",       new_game_cb     },  // the "New Game" button
         { "pause",          pause_cb        },
-        { "preferences",    preferences_cb  },
+        { "preferences",    preferences_cb, "i" },
         { "scores",         scores_cb       },
 
         { "next-screen",    next_screen_cb  },  // called from first-run, players and speed
@@ -789,7 +789,8 @@ private class NibblesWindow : ApplicationWindow
         });
     }
 
-    private void preferences_cb ()
+    private void preferences_cb (SimpleAction action, Variant? variant)
+        requires (variant != null)
     {
         var should_unpause = false;
         if (game.is_running)
@@ -797,19 +798,12 @@ private class NibblesWindow : ApplicationWindow
             pause_action.activate (null);
             should_unpause = true;
         }
-        else if (countdown_id != 0)
-        {
-            Source.remove (countdown_id);
-            countdown_id = 0;
-        }
 
-        PreferencesDialog preferences_dialog = new PreferencesDialog (this, settings, worm_settings);
+        PreferencesDialog preferences_dialog = new PreferencesDialog (this, settings, worm_settings, ((!) 
variant).get_int32 (), game.numhumans);
 
         preferences_dialog.destroy.connect (() => {
                 if (should_unpause)
                     pause_action.activate (null);
-                else if (seconds != 0)
-                    countdown_id = Timeout.add_seconds (1, countdown_cb);
             });
 
         preferences_dialog.present ();
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index ff91f9a..2cbc772 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -27,6 +27,7 @@ private class PreferencesDialog : Window
     private Gee.ArrayList<GLib.Settings> worm_settings;
 
     [GtkChild] private Stack            stack;
+    [GtkChild] private Stack            headerbar_stack;
     [GtkChild] private ComboBoxText     worm_combobox;
     [GtkChild] private Gtk.ListStore    list_store_1;
     [GtkChild] private Gtk.ListStore    list_store_2;
@@ -71,7 +72,7 @@ private class PreferencesDialog : Window
         combo_boxes.add (combo_box_4);
     }
 
-    internal PreferencesDialog (ApplicationWindow window, GLib.Settings settings, 
Gee.ArrayList<GLib.Settings> worm_settings)
+    internal PreferencesDialog (ApplicationWindow window, GLib.Settings settings, 
Gee.ArrayList<GLib.Settings> worm_settings, int worm_id, int n_worms)
     {
         Object (transient_for: window);
 
@@ -79,6 +80,12 @@ private class PreferencesDialog : Window
         this.worm_settings = worm_settings;
         this.window = window;
 
+        if (n_worms == 1)
+            headerbar_stack.set_visible_child_name ("preferences-label");
+        else if (n_worms != 4)
+            for (int i = 3; i > n_worms - 1; i--)
+                worm_combobox.remove (i);
+
         /* Control keys */
         foreach (var list_store in list_stores)
         {
@@ -128,6 +135,9 @@ private class PreferencesDialog : Window
             combo_box.set_active (color);
             combo_box.changed.connect (combo_box_changed_cb);
         }
+
+        /* Choose correct worm */
+        worm_combobox.set_active (worm_id - 1);
     }
 
     private inline bool on_key_pressed (EventControllerKey _key_controller, uint keyval, uint keycode, 
Gdk.ModifierType state)


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