[gnome-taquin] A size menu by game.



commit 64d41c50a3420f97e1c22048c61b9429f0587296
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Dec 7 13:16:20 2019 +0100

    A size menu by game.

 src/new-game-screen.vala | 33 +++++++++++++++++++++++----------
 src/taquin-main.vala     | 39 ++++++++++++++++++++++++++++++---------
 2 files changed, 53 insertions(+), 19 deletions(-)
---
diff --git a/src/new-game-screen.vala b/src/new-game-screen.vala
index c2c3d2b..3e56b2f 100644
--- a/src/new-game-screen.vala
+++ b/src/new-game-screen.vala
@@ -40,21 +40,16 @@ private class NewGameScreen : Box, AdaptativeWidget
         fix_race ();
     }
 
-    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)
+    internal NewGameScreen (string modelbutton_one_label,
+                            string modelbutton_one_action,
+                            string modelbutton_two_label,
+                            string modelbutton_two_action)
     {
         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);
     }
 
     /*\
@@ -66,7 +61,7 @@ private class NewGameScreen : Box, AdaptativeWidget
         TWO;
     }
 
-    internal void update_menubutton_label (MenuButton button, string label)
+    internal inline void update_menubutton_label (MenuButton button, string label)
     {
         switch (button)
         {
@@ -75,6 +70,24 @@ private class NewGameScreen : Box, AdaptativeWidget
         }
     }
 
+    internal inline void update_menubutton_menu (MenuButton button, GLib.Menu menu)
+    {
+        switch (button)
+        {
+            case MenuButton.ONE: menubutton_one.set_menu_model (menu); return;
+            case MenuButton.TWO: menubutton_two.set_menu_model (menu); return;
+        }
+    }
+
+    internal inline void update_menubutton_sensitivity (MenuButton button, bool new_sensitivity)
+    {
+        switch (button)
+        {
+            case MenuButton.ONE: menubutton_one.set_sensitive (new_sensitivity); return;
+            case MenuButton.TWO: menubutton_two.set_sensitive (new_sensitivity); return;
+        }
+    }
+
     // that is a quite usual menubutton label, so put it here
     internal static inline string get_size_button_label (int size)
     {
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index 4d343fb..afc73eb 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -39,6 +39,8 @@ private class Taquin : Gtk.Application, BaseApplication
     private NewGameScreen new_game_screen;
     private HistoryButton history_button_1;
     private HistoryButton history_button_2;
+    private GLib.Menu size_menu_fifteen;
+    private GLib.Menu size_menu_sixteen;
 
     /* The game being played */
     private Game? game = null;
@@ -154,16 +156,27 @@ private class Taquin : Gtk.Application, BaseApplication
         /* UI parts */
         view = new TaquinView ();
 
-        GLib.Menu size_menu = new GLib.Menu ();
+        size_menu_fifteen = new GLib.Menu ();
         /* Translators: when configuring a new game, entry in the menu of the game size menubutton; the "\t" 
is a tabulation; after is indicated an estimated time for solving the puzzle (1 minute) */
-        size_menu.append (_("3 × 3\t1 minute"), "app.change-size('3')");
+        size_menu_fifteen.append (_("3 × 3\t1 minute"), "app.change-size('3')");
 
         /* Translators: when configuring a new game, entry in the menu of the game size menubutton; the "\t" 
is a tabulation; after is indicated an estimated time for solving the puzzle (5 minutes) */
-        size_menu.append (_("4 × 4\t5 minutes"), "app.change-size('4')");
+        size_menu_fifteen.append (_("4 × 4\t5 minutes"), "app.change-size('4')");
 
         /* Translators: when configuring a new game, entry in the menu of the game size menubutton; the "\t" 
is a tabulation; after is indicated an estimated time for solving the puzzle (15 minutes) */
-        size_menu.append (_("5 × 5\t15 minutes"), "app.change-size('5')");
-        size_menu.freeze ();
+        size_menu_fifteen.append (_("5 × 5\t15 minutes"), "app.change-size('5')");
+        size_menu_fifteen.freeze ();
+
+        size_menu_sixteen = new GLib.Menu ();
+        /* Translators: when configuring a new game, entry in the menu of the game size menubutton; the "\t" 
is a tabulation; after is indicated an estimated time for solving the puzzle (1 minute) */
+        size_menu_sixteen.append (_("3 × 3\t1 minute"), "app.change-size('3')");
+
+        /* Translators: when configuring a new game, entry in the menu of the game size menubutton; the "\t" 
is a tabulation; after is indicated an estimated time for solving the puzzle (5 minutes) */
+        size_menu_sixteen.append (_("4 × 4\t3 minutes"), "app.change-size('4')");
+
+        /* Translators: when configuring a new game, entry in the menu of the game size menubutton; the "\t" 
is a tabulation; after is indicated an estimated time for solving the puzzle (5 minutes) */
+        size_menu_sixteen.append (_("5 × 5\t5 minutes"), "app.change-size('5')");
+        size_menu_sixteen.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 */
@@ -180,10 +193,18 @@ private class Taquin : Gtk.Application, BaseApplication
 
         /* 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);
+                                             "app.type('sixteen')");
+
+        settings.changed ["type"].connect (() => {
+                new_game_screen.update_menubutton_menu (NewGameScreen.MenuButton.ONE,
+                                                        (GameType) settings.get_enum ("type") == 
GameType.FIFTEEN ? size_menu_fifteen :
+                                                                                                             
       size_menu_sixteen);
+            });
+        new_game_screen.update_menubutton_menu (NewGameScreen.MenuButton.ONE,
+                                                (GameType) settings.get_enum ("type") == GameType.FIFTEEN ? 
size_menu_fifteen :
+                                                                                                            
size_menu_sixteen);
+        new_game_screen.update_menubutton_menu (NewGameScreen.MenuButton.TWO,
+                                                theme_menu);
 
         history_button_1 = new HistoryButton ();
         history_button_2 = new HistoryButton ();


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