[gnome-nibbles/arnaudb/modernize-code] Rationalize a bit actions.



commit b8d485a5ddfcd3e20f5fff5412330501151ec0eb
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Jun 2 15:31:59 2020 +0200

    Rationalize a bit actions.

 data/controls.ui        |  2 +-
 data/first-run.ui       |  2 +-
 data/players.ui         |  2 +-
 src/nibbles-window.vala | 42 +++++++++++++++++++++++++++---------------
 4 files changed, 30 insertions(+), 18 deletions(-)
---
diff --git a/data/controls.ui b/data/controls.ui
index 4679165..17cdeae 100644
--- a/data/controls.ui
+++ b/data/controls.ui
@@ -51,7 +51,7 @@
         <property name="can-default">True</property>
         <property name="use-underline">True</property>
         <property name="label" translatable="yes">_Start</property>
-        <property name="action-name">win.start-game</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>
diff --git a/data/first-run.ui b/data/first-run.ui
index 71b0f92..6f7df6b 100644
--- a/data/first-run.ui
+++ b/data/first-run.ui
@@ -28,7 +28,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">win.show-new-game-screen</property>
+        <property name="action-name">win.next-screen</property>
         <property name="halign">center</property>
         <property name="valign">end</property>
         <property name="width-request">140</property>
diff --git a/data/players.ui b/data/players.ui
index ff22fcf..b703f42 100644
--- a/data/players.ui
+++ b/data/players.ui
@@ -191,7 +191,7 @@
         <property name="can-default">True</property>
         <property name="use-underline">True</property>
         <property name="label" translatable="yes">_Next</property>
-        <property name="action-name">win.show-controls-screen</property>
+        <property name="action-name">win.next-screen</property>
         <property name="width-request">116</property>
         <property name="height-request">34</property>
         <property name="halign">center</property>
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 3260103..f3ec096 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -77,15 +77,13 @@ private class NibblesWindow : ApplicationWindow
 
     private const GLib.ActionEntry menu_entries[] =
     {
-        {"start-game", start_game_cb},
-        {"new-game", new_game_cb},
-        {"pause", pause_cb},
-        {"preferences", preferences_cb},
-        {"scores", scores_cb},
-
-        {"show-new-game-screen", show_new_game_screen_cb},
-        {"show-controls-screen", show_controls_screen_cb},
-        {"back", back_cb}
+        { "new-game",       new_game_cb     },  // the "New Game" button
+        { "pause",          pause_cb        },
+        { "preferences",    preferences_cb  },
+        { "scores",         scores_cb       },
+
+        { "next-screen",    next_screen_cb  },  // called from first-run, players and controls
+        { "back",           back_cb         }   // called on Escape pressed; disabled only during countdown 
(TODO pause?)
     };
 
     construct
@@ -164,7 +162,7 @@ private class NibblesWindow : ApplicationWindow
         {
             FirstRun first_run_panel = new FirstRun ();
             first_run_panel.show ();
-            main_stack.add (first_run_panel);
+            main_stack.add_named (first_run_panel, "first-run");
             main_stack.set_visible_child (first_run_panel);
         }
         else
@@ -244,7 +242,7 @@ private class NibblesWindow : ApplicationWindow
         return false;
     }
 
-    private void start_game_cb ()
+    private void start_game ()
     {
         settings.set_boolean ("first-run", false);
 
@@ -430,9 +428,23 @@ private class NibblesWindow : ApplicationWindow
     * * Switching the stack
     \*/
 
-    private inline void show_new_game_screen_cb ()
+    private inline void next_screen_cb ()
     {
-        show_new_game_screen (/* after first run */ true);
+        var child_name = main_stack.get_visible_child_name ();
+        switch (child_name)
+        {
+            case "first-run":
+                show_new_game_screen (/* after first run */ true);
+                break;
+            case "number_of_players":
+                show_controls_screen ();
+                break;
+            case "controls":
+                start_game ();
+                break;
+            default:
+                return;
+        }
     }
 
     private void show_new_game_screen (bool after_first_run = false)
@@ -463,7 +475,7 @@ private class NibblesWindow : ApplicationWindow
         main_stack.set_transition_type (StackTransitionType.SLIDE_UP);
     }
 
-    private void show_controls_screen_cb ()
+    private void show_controls_screen ()
     {
         int numhumans, numai;
         players.get_values (out numhumans, out numai);
@@ -507,7 +519,7 @@ private class NibblesWindow : ApplicationWindow
         var child_name = main_stack.get_visible_child_name ();
         switch (child_name)
         {
-            case "first_run":
+            case "first-run":
                 break;
             case "number_of_players":
                 break;


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