[gnome-taquin] Make NewGameScreen generic.



commit 8962f5d0cef292d4f6a9a95975d61d63ae1ed8fd
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Aug 7 21:46:07 2019 +0200

    Make NewGameScreen generic.
    
    Also, should allow custom themes.

 data/new-game-screen.css                          | 128 ++++++++++++++++++++++
 data/taquin.css                                   | 127 ++++-----------------
 data/ui/{taquin-screens.ui => new-game-screen.ui} |  70 ++----------
 src/new-game-screen.vala                          |  70 ++++++++----
 src/taquin-main.vala                              |  82 ++++++++++++--
 src/taquin.gresource.xml                          |   3 +-
 6 files changed, 283 insertions(+), 197 deletions(-)
---
diff --git a/data/new-game-screen.css b/data/new-game-screen.css
new file mode 100644
index 0000000..bc26727
--- /dev/null
+++ b/data/new-game-screen.css
@@ -0,0 +1,128 @@
+/*
+  This file is part of a GNOME game.
+
+  This application 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 application 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 application.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+                               .new-game-screen { padding:0.5rem; }
+.extra-flat-window.flat-window .new-game-screen { padding:0.4rem; }
+
+button.radio-like-toggle,
+button.menubutton-like-combo {
+  border-radius:15px;
+  -gtk-outline-radius:13px;
+}
+
+.extra-thin-window label.section-header { margin-top:1.0rem; }  /* like start-game button */
+
+/*\
+* * games buttons
+\*/
+
+                                                       button.radio-like-toggle:backdrop { color: 
@theme_unfocused_fg_color; }
+                                                       button.radio-like-toggle          { color: 
@theme_fg_color;
+
+  background-repeat:no-repeat;
+  background-color:transparent;
+  min-width:10rem;
+
+  background-size:12rem;
+  background-position:center bottom;
+  min-height:13rem;
+  padding:0.5rem 1rem 1rem 1rem;
+}
+
+                                   .extra-thin-window  button.radio-like-toggle {
+  background-size:5rem;
+  background-position:0.4rem center;
+  min-height:3rem;
+  padding:1.8rem 0.6rem 1rem 5rem;
+}
+
+                  .flat-window:not(.extra-thin-window) button.radio-like-toggle {
+  background-size:8rem;              /*
+  background-position:center bottom; */
+  min-height:9rem;                   /*
+  padding:0.5rem 1rem 1rem 1rem;     */
+}
+
+.extra-flat-window.flat-window                         button.radio-like-toggle {
+  background-size:3rem;
+  background-position:0.3rem center;
+  min-height:2rem;
+  padding:0.6rem 0.5rem 0.5rem 4rem;
+}
+
+                                                       button.radio-like-toggle label { 
padding-bottom:10rem; }
+                                   .extra-thin-window  button.radio-like-toggle label { padding-bottom: 
1rem; }
+                  .flat-window:not(.extra-thin-window) button.radio-like-toggle label { padding-bottom: 
6rem; }
+.extra-flat-window.flat-window                         button.radio-like-toggle label { padding-bottom: 
0rem; }
+
+/* transitions */
+
+                                   .extra-thin-window  button.radio-like-toggle,
+                       .flat-window.extra-thin-window  button.radio-like-toggle,
+     .extra-flat-window.flat-window.extra-thin-window  button.radio-like-toggle,
+                 .flat-window                          button.radio-like-toggle,
+      window:not(.flat-window):not(.extra-thin-window) button.radio-like-toggle {
+  transition:background-size     0.3s,
+             min-height          0.3s,
+             padding             0.3s;
+}
+                                   .extra-thin-window  button.radio-like-toggle label,
+                       .flat-window.extra-thin-window  button.radio-like-toggle label,
+     .extra-flat-window.flat-window.extra-thin-window  button.radio-like-toggle label,
+                 .flat-window                          button.radio-like-toggle label,
+      window:not(.flat-window):not(.extra-thin-window) button.radio-like-toggle label {
+  transition:padding-bottom      0.3s ease 0.01s;
+}
+
+/* hack: 0.01s delay helps fixing the race between CSS and box orientation changes (warning if a label gets 
out of view) */
+                                                       button.radio-like-toggle {
+  transition-delay:                        0.01s;
+  transition-timing-function:         ease;
+}
+
+/*\
+* * menubuttons
+\*/
+
+/* copying start-game button */
+
+.extra-flat-window button.menubutton-like-combo {
+  min-height:2rem;
+}
+                   button.menubutton-like-combo {
+  min-height:3rem;
+  min-width:11rem;
+
+  transition:min-height          0.3s ease 0.01s;
+}
+
+/* styling */
+
+button.menubutton-like-combo:checked,
+button.menubutton-like-combo:hover {
+  color:#2e3436; /* gtk-contained.css’ theme_fg_color */
+  background:-gtk-gradient (radial, center center, 0, center center, 0.5, from(rgba (255, 255, 255, 1)), 
to(rgba (255, 255, 255, 0)));
+}
+button.menubutton-like-combo:checked:backdrop,
+button.menubutton-like-combo:hover:backdrop {
+  color:@theme_unfocused_fg_color;
+  background:-gtk-gradient (radial, center center, 0, center center, 0.5, from(rgba (255, 255, 255, 0.3)), 
to(rgba (255, 255, 255, 0)));
+}
+
+/*\
+* * the end
+\*/
diff --git a/data/taquin.css b/data/taquin.css
index 33deeab..606a60f 100644
--- a/data/taquin.css
+++ b/data/taquin.css
@@ -25,131 +25,42 @@ button.unfullscreen-button {
 .extra-thin-window.thin-window button.new-game-button { margin-right:-6px; }
 
 /*\
-* * new-game screen generics
+* * board generics; TODO move in game-window.css
 \*/
 
-                               .game-box                { transition:padding 0.3s; padding:1.5rem; }
-                  .thin-window .game-box                {                          padding:1.0rem; }
+                               .game-box { transition:padding 0.3s; padding:1.5rem; }
+                  .thin-window .game-box {                          padding:1.0rem; }
 .extra-thin-window.thin-window .game-box,
-                  .flat-window .game-box                {                          padding:0.5rem; }
-.extra-flat-window.flat-window .game-box                {                          padding:0.4rem; }
-
-                               .new-game-screen         {                          padding:0.5rem; }
-.extra-flat-window.flat-window .new-game-screen         {                          padding:0.4rem; }
-
-                               button.start-game-button { margin-top:1.5rem; margin-bottom:0.5rem;
-                                               transition:margin-top 0 ease, margin-bottom 0 ease; }
-                  .flat-window button.start-game-button { margin-top:0.5rem;                       }
-.extra-flat-window.flat-window button.start-game-button { margin-top:  0rem; margin-bottom:0.4rem; }
-
-.extra-thin-window             label.section-header,
-.extra-thin-window             button.start-game-button { margin-top:1.0rem; }
-
-button.radio-like-toggle,
-button.menubutton-like-combo {
-  border-radius:15px;
-  -gtk-outline-radius:13px;
-}
+                  .flat-window .game-box {                          padding:0.5rem; }
+.extra-flat-window.flat-window .game-box {                          padding:0.4rem; }
 
 /*\
-* * games buttons
+* * start-game button; TODO move in game-window.css
 \*/
 
-button.radio-like-toggle#radio-fifteen { background-image: 
url("resource://org/gnome/Taquin/images/15-Puzzle.png"); }
-button.radio-like-toggle#radio-sixteen { background-image: 
url("resource://org/gnome/Taquin/images/16-Puzzle.png"); }
-
-                                                       button.radio-like-toggle:backdrop { color: 
@theme_unfocused_fg_color; }
-                                                       button.radio-like-toggle          { color: 
@theme_fg_color;
-
-  background-repeat:no-repeat;
-  background-color:transparent;
-  min-width:10rem;
-
-  background-size:12rem;
-  background-position:center bottom;
-  min-height:13rem;
-  padding:0.5rem 1rem 1rem 1rem;
+.extra-flat-window             button.start-game-button {
+  min-height:2rem;
 }
-
-                                   .extra-thin-window  button.radio-like-toggle {
-  background-size:5rem;
-  background-position:0.4rem center;
+                               button.start-game-button {
   min-height:3rem;
-  padding:1.8rem 0.6rem 1rem 5rem;
-}
-
-                  .flat-window:not(.extra-thin-window) button.radio-like-toggle {
-  background-size:8rem;              /*
-  background-position:center bottom; */
-  min-height:9rem;                   /*
-  padding:0.5rem 1rem 1rem 1rem;     */
-}
+  min-width:11rem;
 
-.extra-flat-window.flat-window                         button.radio-like-toggle {
-  background-size:3rem;
-  background-position:0.3rem center;
-  min-height:2rem;
-  padding:0.6rem 0.5rem 0.5rem 4rem;
+  transition:min-height          0.3s ease 0.01s;
 }
 
-                                                       button.radio-like-toggle label { 
padding-bottom:10rem; }
-                                   .extra-thin-window  button.radio-like-toggle label { padding-bottom: 
1rem; }
-                  .flat-window:not(.extra-thin-window) button.radio-like-toggle label { padding-bottom: 
6rem; }
-.extra-flat-window.flat-window                         button.radio-like-toggle label { padding-bottom: 
0rem; }
-
-/* transitions */
-
-                                   .extra-thin-window  button.radio-like-toggle,
-                       .flat-window.extra-thin-window  button.radio-like-toggle,
-     .extra-flat-window.flat-window.extra-thin-window  button.radio-like-toggle,
-                 .flat-window                          button.radio-like-toggle,
-      window:not(.flat-window):not(.extra-thin-window) button.radio-like-toggle {
-  transition:background-size     0.3s,
-             min-height          0.3s,
-             padding             0.3s;
-}
-                                   .extra-thin-window  button.radio-like-toggle label,
-                       .flat-window.extra-thin-window  button.radio-like-toggle label,
-     .extra-flat-window.flat-window.extra-thin-window  button.radio-like-toggle label,
-                 .flat-window                          button.radio-like-toggle label,
-      window:not(.flat-window):not(.extra-thin-window) button.radio-like-toggle label {
-  transition:padding-bottom      0.3s ease 0.01s;
-}
+                               button.start-game-button { margin-top:1.5rem; margin-bottom:0.5rem;
+                                               transition:margin-top 0 ease, margin-bottom 0 ease; }
+                  .flat-window button.start-game-button { margin-top:0.5rem;                       }
+.extra-flat-window.flat-window button.start-game-button { margin-top:  0rem; margin-bottom:0.4rem; }
 
-/* hack: 0.01s delay helps fixing the race between CSS and box orientation changes (warning if a label gets 
out of view) */
-                                                       button.radio-like-toggle {
-  transition-delay:                        0.01s;
-  transition-timing-function:         ease;
-}
+.extra-thin-window             button.start-game-button { margin-top:1.0rem; }
 
 /*\
-* * options buttons
+* * games buttons
 \*/
 
-.extra-flat-window button.start-game-button,
-.extra-flat-window button.menubutton-like-combo {
-  min-height:2rem;
-}
-                   button.start-game-button,
-                   button.menubutton-like-combo {
-  min-height:3rem;
-  min-width:11rem;
-
-  transition:min-height          0.3s ease 0.01s;
-}
-
-/* styling */
-
-button.menubutton-like-combo:checked,
-button.menubutton-like-combo:hover {
-  color:#2e3436; /* gtk-contained.css’ theme_fg_color */
-  background:-gtk-gradient (radial, center center, 0, center center, 0.5, from(rgba (255, 255, 255, 1)), 
to(rgba (255, 255, 255, 0)));
-}
-button.menubutton-like-combo:checked:backdrop,
-button.menubutton-like-combo:hover:backdrop {
-  color:@theme_unfocused_fg_color;
-  background:-gtk-gradient (radial, center center, 0, center center, 0.5, from(rgba (255, 255, 255, 0.3)), 
to(rgba (255, 255, 255, 0)));
-}
+button.radio-like-toggle#radio-one { background-image: 
url("resource://org/gnome/Taquin/images/15-Puzzle.png"); }
+button.radio-like-toggle#radio-two { background-image: 
url("resource://org/gnome/Taquin/images/16-Puzzle.png"); }
 
 /*\
 * * the end
diff --git a/data/ui/taquin-screens.ui b/data/ui/new-game-screen.ui
similarity index 58%
rename from data/ui/taquin-screens.ui
rename to data/ui/new-game-screen.ui
index 7bc139c..abe1dd6 100644
--- a/data/ui/taquin-screens.ui
+++ b/data/ui/new-game-screen.ui
@@ -1,60 +1,22 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-  This file is part of GNOME Taquin
+  This file is part of a GNOME game.
 
-  GNOME Taquin is free software: you can redistribute it and/or modify
+  This application 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 Taquin is distributed in the hope that it will be useful,
+  This application 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 GNOME Taquin.  If not, see <https://www.gnu.org/licenses/>.
+  You should have received a copy of the GNU General Public License along
+  with this application.  If not, see <https://www.gnu.org/licenses/>.
 -->
 <interface>
   <requires lib="gtk+" version="3.12"/>
-  <menu id="size-menu"><!-- TODO 3/4/5 accels? -->
-    <section>
-      <item>
-        <!-- Translators: when configuring a new game, entry in the menu of the game size menubutton -->
-        <attribute name="label" translatable="yes">3 × 3</attribute>
-        <attribute name="action">app.change-size</attribute>
-        <attribute name="target">3</attribute>
-      </item>
-      <item>
-        <!-- Translators: when configuring a new game, entry in the menu of the game size menubutton -->
-        <attribute name="label" translatable="yes">4 × 4</attribute>
-        <attribute name="action">app.change-size</attribute>
-        <attribute name="target">4</attribute>
-      </item>
-      <item>
-        <!-- Translators: when configuring a new game, entry in the menu of the game size menubutton -->
-        <attribute name="label" translatable="yes">5 × 5</attribute>
-        <attribute name="action">app.change-size</attribute>
-        <attribute name="target">5</attribute>
-      </item>
-    </section>
-  </menu>
-  <menu id="theme-menu">
-    <section>
-      <item>
-        <!-- Translators: when configuring a new game, entry in the menu of the game theme menubutton; play 
with cats images -->
-        <attribute name="label" translatable="yes">Cats</attribute>
-        <attribute name="action">app.change-theme</attribute>
-        <attribute name="target">cats</attribute>
-      </item>
-      <item>
-        <!-- Translators: when configuring a new game, entry in the menu of the game theme menubutton; play 
with numbers -->
-        <attribute name="label" translatable="yes">Numbers</attribute>
-        <attribute name="action">app.change-theme</attribute>
-        <attribute name="target">numbers</attribute>
-      </item>
-    </section>
-  </menu>
   <template class="NewGameScreen" parent="GtkBox">
     <property name="orientation">vertical</property>
     <property name="visible">True</property>
@@ -81,35 +43,27 @@
         <property name="homogeneous">True</property>
         <property name="spacing">6</property>
         <child>
-          <object class="GtkModelButton">
+          <object class="GtkModelButton" id="modelbutton_one">
             <property name="visible">True</property>
-            <property name="name">radio-fifteen</property>
+            <property name="name">radio-one</property>
             <style>
               <class name="radio-like-toggle"/>
               <class name="flat"/>
             </style>
             <property name="focus-on-click">False</property>
-            <property name="action-name">app.type</property>
-            <property name="action-target">'fifteen'</property>
-            <!-- Translators: when configuring a new game, label of the first big button; name of the 
traditional Taquin game -->
-            <property name="text" translatable="yes">15-Puzzle</property>
             <property name="iconic">True</property>
             <property name="centered">True</property>
           </object>
         </child>
         <child>
-          <object class="GtkModelButton">
+          <object class="GtkModelButton" id="modelbutton_two">
             <property name="visible">True</property>
-            <property name="name">radio-sixteen</property>
+            <property name="name">radio-two</property>
             <style>
               <class name="radio-like-toggle"/>
               <class name="flat"/>
             </style>
             <property name="focus-on-click">False</property>
-            <property name="action-name">app.type</property>
-            <property name="action-target">'sixteen'</property>
-            <!-- Translators: when configuring a new game, label of the second big button; name of the 
non-traditional game -->
-            <property name="text" translatable="yes">16-Puzzle</property>
             <property name="iconic">True</property>
             <property name="centered">True</property>
           </object>
@@ -145,10 +99,9 @@
         <property name="homogeneous">True</property>
         <property name="spacing">6</property>
         <child>
-          <object class="GtkMenuButton" id="size_button">
+          <object class="GtkMenuButton" id="menubutton_one">
             <property name="visible">True</property>
             <property name="use-underline">True</property>
-            <property name="menu-model">size-menu</property>
             <style>
               <class name="menubutton-like-combo"/>
               <class name="flat"/>
@@ -160,10 +113,9 @@
           </packing>
         </child>
         <child>
-          <object class="GtkMenuButton" id="theme_button">
+          <object class="GtkMenuButton" id="menubutton_two">
             <property name="visible">True</property>
             <property name="use-underline">True</property>
-            <property name="menu-model">theme-menu</property>
             <style>
               <class name="menubutton-like-combo"/>
               <class name="flat"/>
diff --git a/src/new-game-screen.vala b/src/new-game-screen.vala
index a62abcf..c2c3d2b 100644
--- a/src/new-game-screen.vala
+++ b/src/new-game-screen.vala
@@ -20,42 +20,74 @@
 
 using Gtk;
 
-[GtkTemplate (ui = "/org/gnome/Taquin/ui/taquin-screens.ui")]
+[GtkTemplate (ui = "/org/gnome/Taquin/ui/new-game-screen.ui")]
 private class NewGameScreen : Box, AdaptativeWidget
 {
-    /*\
-    * * options buttons
-    \*/
+    [GtkChild] private ModelButton modelbutton_one;
+    [GtkChild] private ModelButton modelbutton_two;
 
-    [GtkChild] private MenuButton size_button;
-    [GtkChild] private MenuButton theme_button;
+    [GtkChild] private Gtk.MenuButton menubutton_one;
+    [GtkChild] private Gtk.MenuButton menubutton_two;
 
-    internal void update_size_button_label (int size)
+    construct
     {
-        /* Translators: when configuring a new game, button label for the size of the game ("3 × 3", or 4, 
or 5) */
-        size_button.set_label (_("Size: %d × %d ▾").printf (size, size));
-     // size_button.set_label (_("Size: %hhu × %hhu ▾").printf (size, size));   // TODO uint8
+        CssProvider css_provider = new CssProvider ();
+        css_provider.load_from_resource ("/org/gnome/Taquin/ui/new-game-screen.css");
+        Gdk.Screen? gdk_screen = Gdk.Screen.get_default ();
+        if (gdk_screen != null) // else..?
+            StyleContext.add_provider_for_screen ((!) gdk_screen, css_provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+        fix_race ();
     }
 
-    internal void update_theme (string theme)
+    internal NewGameScreen (string      modelbutton_one_label,
+                            string      modelbutton_one_action,
+                            string      modelbutton_two_label,
+                            string      modelbutton_two_action,
+                            GLib.Menu   menu_one,
+                            GLib.Menu   menu_two)
     {
-        switch (theme)
-        {
-            /* Translators: when configuring a new game, button label for the theme, if the current theme is 
Cats */
-            case "cats":    theme_button.set_label (_("Theme: Cats ▾")); break;
+        modelbutton_one.text = modelbutton_one_label;
+        modelbutton_two.text = modelbutton_two_label;
+
+        modelbutton_one.set_detailed_action_name (modelbutton_one_action);
+        modelbutton_two.set_detailed_action_name (modelbutton_two_action);
+
+        menubutton_one.set_menu_model (menu_one);
+        menubutton_two.set_menu_model (menu_two);
+    }
+
+    /*\
+    * * options buttons
+    \*/
 
-            /* Translators: when configuring a new game, button label for the theme, if the current theme is 
Numbers */
-            case "numbers": theme_button.set_label (_("Theme: Numbers ▾")); break;
+    public enum MenuButton {
+        ONE,
+        TWO;
+    }
 
-            default: warn_if_reached (); break;
+    internal void update_menubutton_label (MenuButton button, string label)
+    {
+        switch (button)
+        {
+            case MenuButton.ONE: menubutton_one.set_label (label); return;
+            case MenuButton.TWO: menubutton_two.set_label (label); return;
         }
     }
 
+    // that is a quite usual menubutton label, so put it here
+    internal static inline string get_size_button_label (int size)
+    {
+        /* Translators: when configuring a new game, button label for the size of the game ("3 × 3", or 4, 
or 5) */
+        return _("Size: %d × %d ▾").printf (size, size);
+     // return _("Size: %hhu × %hhu ▾").printf (size, size));   // TODO uint8
+    }
+
     /*\
     * * adaptative stuff
     \*/
 
-    construct   // FIXME things are a bit racy between the CSS and the box orientation changes, so delay 
games_box redraw
+    private void fix_race ()   // FIXME things are a bit racy between the CSS and the box orientation 
changes, so delay games_box redraw
     {
         size_allocate.connect_after (() => games_box.show ());
         map.connect (() => games_box.show ());
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index cd3dcb2..4b7561b 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -151,7 +151,37 @@ private class Taquin : Gtk.Application, BaseApplication
 
         /* UI parts */
         view = new TaquinView ();
-        new_game_screen = new NewGameScreen ();
+
+        GLib.Menu size_menu = new GLib.Menu ();
+        /* Translators: when configuring a new game, entry in the menu of the game size menubutton */
+        size_menu.append (_("3 × 3"), "app.change-size('3')");
+
+        /* Translators: when configuring a new game, entry in the menu of the game size menubutton */
+        size_menu.append (_("4 × 4"), "app.change-size('4')");
+
+        /* Translators: when configuring a new game, entry in the menu of the game size menubutton */
+        size_menu.append (_("5 × 5"), "app.change-size('5')");
+        size_menu.freeze ();
+
+        GLib.Menu theme_menu = new GLib.Menu ();
+        /* Translators: when configuring a new game, entry in the menu of the game theme menubutton; play 
with cats images */
+        theme_menu.append (_("Cats"), "app.change-theme('cats')");
+
+
+        /* Translators: when configuring a new game, entry in the menu of the game theme menubutton; play 
with numbers */
+        theme_menu.append (_("Numbers"), "app.change-theme('numbers')");
+        theme_menu.freeze ();
+
+        /* Translators: when configuring a new game, label of the first big button; name of the traditional 
Taquin game */
+        new_game_screen = new NewGameScreen (_("15-Puzzle"),
+                                             "app.type('fifteen')",
+
+        /* Translators: when configuring a new game, label of the second big button; name of the 
non-traditional game */
+                                             _("16-Puzzle"),
+                                             "app.type('sixteen')",
+
+                                             size_menu,
+                                             theme_menu);
 
         /* Window */
         init_night_mode ();
@@ -197,10 +227,10 @@ private class Taquin : Gtk.Application, BaseApplication
         /* New-game screen signals */
         settings.changed ["size"].connect (() => {
             if (!size_changed)
-                new_game_screen.update_size_button_label (settings.get_int ("size") /* 2 <= size <= 9 */);
+                update_size_button_label (settings.get_int ("size") /* 2 <= size <= 9 */);
             size_changed = false;
         });
-        new_game_screen.update_size_button_label (settings.get_int ("size") /* 2 <= size <= 9 */);
+        update_size_button_label (settings.get_int ("size") /* 2 <= size <= 9 */);
 
         settings.changed ["theme"].connect (() => {
             if (!theme_changed)
@@ -388,27 +418,43 @@ private class Taquin : Gtk.Application, BaseApplication
     {
         size_changed = true;
         int size = int.parse (((!) variant).get_string ());
-        new_game_screen.update_size_button_label (size /* 3 <= size <= 5 */);
+        update_size_button_label (size /* 3 <= size <= 5 */);
         settings.set_int ("size", size);
     }
+    private void update_size_button_label (int size)
+    {
+        new_game_screen.update_menubutton_label (NewGameScreen.MenuButton.ONE,
+                                                 NewGameScreen.get_size_button_label (size));
+    }
 
     private void change_theme_cb (SimpleAction action, Variant? variant)
         requires (variant != null)
+    {
+        update_theme (((!) variant).get_string ());
+    }
+    private void update_theme (string theme_id)
     {
         theme_changed = true;
-        string name = ((!) variant).get_string ();
-        update_theme (name);
-        settings.set_string ("theme", name);
+        if (_update_theme (theme_id))
+            settings.set_string ("theme", theme_id);
+        else
+        {
+            if (!_update_theme ("cats"))
+                assert_not_reached ();
+            settings.set_string ("theme", "cats");
+        }
     }
-    private void update_theme (string theme)
+    private bool _update_theme (string theme_id)
     {
-        new_game_screen.update_theme (theme);
+        new_game_screen.update_menubutton_label (NewGameScreen.MenuButton.TWO,
+                                                 get_theme_button_label (theme_id));
 
         Dir dir;
         theme_dirlist = new List<string> ();
+        bool success = false;
         try
         {
-            dir = Dir.open (Path.build_filename (DATA_DIRECTORY, "themes", theme));
+            dir = Dir.open (Path.build_filename (DATA_DIRECTORY, "themes", theme_id));
             while (true)
             {
                 string? filename = dir.read_name ();
@@ -416,11 +462,27 @@ private class Taquin : Gtk.Application, BaseApplication
                     break;
                 theme_dirlist.append ((!) filename);
             }
+            success = true;
         }
         catch (FileError e)
         {
             warning ("Failed to load images: %s", e.message);
         }
+        return success;
+    }
+    private static inline string get_theme_button_label (string theme_id)
+    {
+        switch (theme_id)
+        {
+            /* Translators: when configuring a new game, button label for the theme, if the current theme is 
Cats */
+            case "cats":    return _("Theme: Cats ▾");
+
+            /* Translators: when configuring a new game, button label for the theme, if the current theme is 
Numbers */
+            case "numbers": return _("Theme: Numbers ▾");
+
+            /* Translators: when configuring a new game, button label for the theme, if the current theme 
has been added by the user; the %s is replaced by the theme name */
+            default:        return _("Theme: %s ▾").printf (theme_id);
+        }
     }
 
     /*\
diff --git a/src/taquin.gresource.xml b/src/taquin.gresource.xml
index bebaf62..8e03495 100644
--- a/src/taquin.gresource.xml
+++ b/src/taquin.gresource.xml
@@ -11,10 +11,11 @@
     <file alias="base-window.css">../data/base-window.css</file>
     <file preprocess="xml-stripblanks" alias="base-window.ui">../data/ui/base-window.ui</file>
     <file preprocess="xml-stripblanks" alias="game-headerbar.ui">../data/ui/game-headerbar.ui</file>
+    <file alias="new-game-screen.css">../data/new-game-screen.css</file>
+    <file preprocess="xml-stripblanks" alias="new-game-screen.ui">../data/ui/new-game-screen.ui</file>
     <file preprocess="xml-stripblanks" 
alias="notifications-revealer.ui">../data/ui/notifications-revealer.ui</file>
     <file preprocess="xml-stripblanks" alias="overlayed-list.ui">../data/ui/overlayed-list.ui</file>
     <file preprocess="xml-stripblanks" 
alias="registry-placeholder.ui">../data/ui/registry-placeholder.ui</file>
-    <file preprocess="xml-stripblanks" alias="taquin-screens.ui">../data/ui/taquin-screens.ui</file>
     <file alias="taquin.css">../data/taquin.css</file>
   </gresource>
   <gresource prefix="/org/gnome/Taquin/gtk">


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