[iagno] Introduce NewGameScreen.



commit a69d586235cfc631b9e82244bf0703e67e0bd066
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Mar 3 16:01:15 2019 +0100

    Introduce NewGameScreen.

 data/ui/iagno-screens.ui |  8 ++++----
 src/iagno.vala           | 19 ++++++++-----------
 src/meson.build          |  1 +
 src/new-game-screen.vala | 36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/iagno-screens.ui b/data/ui/iagno-screens.ui
index f3629d8..eb3d9f5 100644
--- a/data/ui/iagno-screens.ui
+++ b/data/ui/iagno-screens.ui
@@ -19,7 +19,7 @@
 -->
 <interface>
   <requires lib="gtk+" version="3.12"/>
-  <object class="GtkBox" id="new-game-screen">
+  <template class="NewGameScreen" parent="GtkBox">
     <property name="orientation">vertical</property>
     <property name="visible">True</property>
     <property name="homogeneous">True</property>
@@ -97,7 +97,7 @@
           </object>
         </child>
         <child>
-          <object class="GtkBox" id="difficulty-box">
+          <object class="GtkBox" id="level_box">
             <property name="visible">True</property>
             <property name="homogeneous">True</property>
             <property name="spacing">12</property>
@@ -161,7 +161,7 @@
           </object>
         </child>
         <child>
-          <object class="GtkBox" id="color-box">
+          <object class="GtkBox" id="color_box">
             <property name="visible">True</property>
             <property name="homogeneous">True</property>
             <property name="spacing">12</property>
@@ -196,5 +196,5 @@
         </child>
       </object>
     </child>
-  </object>
+  </template>
 </interface>
diff --git a/src/iagno.vala b/src/iagno.vala
index ac6cca5..427c1dc 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -45,6 +45,7 @@ private class Iagno : Gtk.Application
     /* Widgets */
     private GameWindow window;
     private ReversiView view;
+    private NewGameScreen new_game_screen;
 
     /* Computer player (if there is one) */
     internal ComputerPlayer? computer { internal get; private set; default = null; }
@@ -204,12 +205,12 @@ private class Iagno : Gtk.Application
         }
 
         /* UI parts */
-        Builder builder = new Builder.from_resource ("/org/gnome/Reversi/ui/iagno-screens.ui");
-
         view = new ReversiView (this);
         view.move.connect (player_move_cb);
         view.clear_impossible_to_move_here_warning.connect (clear_impossible_to_move_here_warning);
 
+        new_game_screen = new NewGameScreen ();
+
         if (settings.get_boolean ("sound"))
             init_sound ();
 
@@ -287,7 +288,7 @@ private class Iagno : Gtk.Application
                                  GameWindowFlags.SHOW_START_BUTTON
                                  | GameWindowFlags.SHOW_HELP
                                  | GameWindowFlags.SHOW_UNDO,
-                                 (Box) builder.get_object ("new-game-screen"),
+                                 (Box) new_game_screen,
                                  view,
                                  appearance_menu);
 
@@ -318,16 +319,12 @@ private class Iagno : Gtk.Application
         settings.bind ("highlight-turnable-tiles", view, "show-turnable-tiles", SettingsBindFlags.GET);
         settings.bind ("theme",                    view, "theme",               SettingsBindFlags.GET);
 
-        Box level_box = (Box) builder.get_object ("difficulty-box");
-        Box color_box = (Box) builder.get_object ("color-box");
         settings.changed ["num-players"].connect (() => {
-            bool solo = settings.get_int ("num-players") == 1;
-            level_box.sensitive = solo;
-            color_box.sensitive = solo;
-        });
+                bool solo = settings.get_int ("num-players") == 1;
+                new_game_screen.update_sensitivity (solo);
+            });
         bool solo = settings.get_int ("num-players") == 1;
-        level_box.sensitive = solo;
-        color_box.sensitive = solo;
+        new_game_screen.update_sensitivity (solo);
 
         if (start_now)
             start_game ();
diff --git a/src/meson.build b/src/meson.build
index b79ce82..e908760 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -26,6 +26,7 @@ executable(meson.project_name(),
         'game-window.vala',
         'game.vala',
         'iagno.vala',
+        'new-game-screen.vala',
         'player.vala',
         'reversi-view.vala'
     ] + resources,
diff --git a/src/new-game-screen.vala b/src/new-game-screen.vala
new file mode 100644
index 0000000..1f9bf7b
--- /dev/null
+++ b/src/new-game-screen.vala
@@ -0,0 +1,36 @@
+/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+   This file is part of GNOME Reversi, also known as Iagno.
+
+   Copyright 2010-2013 Robert Ancell
+   Copyright 2013-2014 Michael Catanzaro
+   Copyright 2014-2019 Arnaud Bonatti
+
+   GNOME Reversi 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 Reversi 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 Reversi.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Reversi/ui/iagno-screens.ui")]
+private class NewGameScreen : Box
+{
+    [GtkChild] private Box level_box;
+    [GtkChild] private Box color_box;
+
+    internal void update_sensitivity (bool new_sensitivity)
+    {
+        level_box.sensitive = new_sensitivity;
+        color_box.sensitive = new_sensitivity;
+    }
+}


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