[gnome-mines] Moved most of the game screen to the UI file



commit c9d0037b3f7affad7e54fa3b9f3c34cd58b9ee4b
Author: Robert Roth <robert roth off gmail com>
Date:   Wed Apr 23 17:34:31 2014 +0300

    Moved most of the game screen to the UI file

 data/interface.ui    |  453 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gnome-mines.vala |  108 +++----------
 2 files changed, 476 insertions(+), 85 deletions(-)
---
diff --git a/data/interface.ui b/data/interface.ui
new file mode 100644
index 0000000..3faa1b0
--- /dev/null
+++ b/data/interface.ui
@@ -0,0 +1,453 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.2 -->
+<interface>
+  <requires lib="gtk+" version="3.10"/>
+  <object class="GtkSizeGroup" id="buttons_size_group">
+    <property name="mode">both</property>
+    <widgets>
+      <widget name="play_pause_button"/>
+      <widget name="high_scores_button"/>
+      <widget name="new_game_button"/>
+      <widget name="replay_button"/>
+    </widgets>
+  </object>
+  <object class="GtkAlignment" id="main_game_screen">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkBox" id="main_hbox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">center</property>
+        <property name="border_width">12</property>
+        <property name="spacing">12</property>
+        <child>
+          <object class="GtkOverlay" id="minefield_overlay">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">end</property>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkApplicationWindow" id="main_window">
+    <property name="width_request">550</property>
+    <property name="height_request">475</property>
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">Mines</property>
+    <property name="icon_name">gnome-mines</property>
+    <child>
+      <object class="GtkBox" id="main_vbox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_left">12</property>
+        <property name="margin_right">12</property>
+        <property name="margin_top">12</property>
+        <property name="margin_bottom">12</property>
+        <property name="spacing">12</property>
+        <child>
+          <object class="GtkBox" id="view_box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkBox" id="main_screen">
+                <property name="can_focus">False</property>
+                <property name="spacing">12</property>
+                <child>
+                  <object class="GtkAspectFrame" id="minefield_aspect">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label_xalign">0</property>
+                    <property name="shadow_type">none</property>
+                    <property name="yalign">0.50999999046325684</property>
+                    <property name="obey_child">False</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkBox" id="buttons_box">
+                    <property name="width_request">115</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">start</property>
+                    <property name="margin_top">12</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">4</property>
+                    <child>
+                      <object class="GtkImage" id="flag_image">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">preferences-desktop-locale-symbolic</property>
+                        <property name="icon_size">5</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="flag_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="margin_bottom">12</property>
+                        <property name="label" translatable="yes">5/10</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkImage" id="clock_image">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">preferences-system-time-symbolic</property>
+                        <property name="icon_size">5</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="clock_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="margin_bottom">12</property>
+                        <property name="label" translatable="yes">0:00</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">3</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="play_pause_button">
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="action_name">app.pause</property>
+                        <property name="use_underline">True</property>
+                        <child>
+                          <object class="GtkLabel" id="play_pause_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xpad">24</property>
+                            <property name="ypad">12</property>
+                            <property name="label" translatable="yes">_Pause</property>
+                            <property name="use_underline">True</property>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="pack_type">end</property>
+                        <property name="position">4</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="high_scores_button">
+                        <property name="label" translatable="yes">_Best Times</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="action_name">app.scores</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="pack_type">end</property>
+                        <property name="position">5</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="new_game_button">
+                        <property name="label" translatable="yes">_Difficulty</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="action_name">app.new-game</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="pack_type">end</property>
+                        <property name="position">6</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="replay_button">
+                        <property name="label" translatable="yes">_Play Again</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="action_name">app.repeat-size</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="pack_type">end</property>
+                        <property name="position">7</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="pack_type">end</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkAspectFrame" id="new_game_screen">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <property name="obey_child">False</property>
+                <child>
+                  <object class="GtkGrid" id="new_game_grid">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="row_spacing">18</property>
+                    <property name="column_spacing">18</property>
+                    <property name="row_homogeneous">True</property>
+                    <property name="column_homogeneous">True</property>
+                    <child>
+                      <object class="GtkButton" id="small_size_btn">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="large_size_btn">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="medium_size_btn">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="custom_size_btn">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkAspectFrame" id="custom_game_screen">
+                <property name="can_focus">False</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkGrid" id="custom_game_grid">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">center</property>
+                    <property name="valign">center</property>
+                    <property name="row_spacing">6</property>
+                    <property name="column_spacing">12</property>
+                    <child>
+                      <object class="GtkLabel" id="width_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">_Width</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">width_spin_btn</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkSpinButton" id="width_spin_btn">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="height_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">_Height</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">height_spin_btn</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkSpinButton" id="height_spin_btn">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="percent_mines_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Percent _mines</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkSpinButton" id="mines_spin_btn">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkGrid" id="custom_buttons_grid">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="margin_top">12</property>
+                        <property name="row_spacing">5</property>
+                        <child>
+                          <object class="GtkButton" id="cancel_btn">
+                            <property name="label" translatable="yes">_Cancel</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="valign">center</property>
+                            <property name="hexpand">True</property>
+                            <property name="vexpand">True</property>
+                            <property name="use_underline">True</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkButton" id="play_game_btn">
+                            <property name="label" translatable="yes">_Play Game</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="valign">center</property>
+                            <property name="hexpand">True</property>
+                            <property name="vexpand">True</property>
+                            <property name="use_underline">True</property>
+                            <style>
+                              <class name="suggested-action"/>
+                            </style>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">0</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">3</property>
+                        <property name="width">2</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/gnome-mines.vala b/src/gnome-mines.vala
index c42b62b..e6540eb 100644
--- a/src/gnome-mines.vala
+++ b/src/gnome-mines.vala
@@ -26,8 +26,9 @@ public class Mines : Gtk.Application
     public static const string KEY_USE_OVERMINE_WARNING = "use-overmine-warning";
     public static const string KEY_USE_AUTOFLAG = "use-autoflag";
 
-    private Gtk.Box buttons_box;
+    private Gtk.Box main_screen;
     private Gtk.Button play_pause_button;
+    private Gtk.Label play_pause_label;
     private Gtk.Button replay_button;
     private Gtk.Button high_scores_button;
     private Gtk.Button new_game_button;
@@ -152,15 +153,12 @@ public class Mines : Gtk.Application
         add_accelerator ("<Primary>w", "app.quit", null);
         add_accelerator ("<Primary>q", "app.quit", null);
 
-        window = new Gtk.ApplicationWindow (this);
-        window.title = _("Mines");
-        window.icon_name = "gnome-mines";
+        window = (Gtk.ApplicationWindow) ui_builder.get_object ("main_window");
         window.configure_event.connect (window_configure_event_cb);
         window.window_state_event.connect (window_state_event_cb);
         window.focus_out_event.connect (window_focus_out_event_cb);
         window.focus_in_event.connect (window_focus_in_event_cb);
         window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
-        window.set_size_request (550, 475);
         if (settings.get_boolean ("window-is-maximized"))
             window.maximize ();
 
@@ -174,16 +172,6 @@ public class Mines : Gtk.Application
 
         add_window (window);
 
-        var main_vbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
-        main_vbox.margin = 12;
-        window.add (main_vbox);
-        main_vbox.show ();
-
-        var view_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
-        view_box.border_width = 3;
-        view_box.show ();
-        main_vbox.pack_start (view_box, true, true, 0);
-
         minefield_view = new MinefieldView (settings);
         minefield_view.show ();
 
@@ -191,9 +179,9 @@ public class Mines : Gtk.Application
         minefield_overlay.add (minefield_view);
         minefield_overlay.show ();
 
-        minefield_aspect = new Gtk.AspectFrame (null, 0.5f, 0.5f, 1.0f , false);
-        minefield_aspect.set_shadow_type (Gtk.ShadowType.NONE);
+        minefield_aspect = (Gtk.AspectFrame) ui_builder.get_object ("minefield_aspect");
         minefield_aspect.add (minefield_overlay);
+        minefield_aspect.show ();
 
         var paused_label = new Gtk.Label (_("Paused"));
         paused_label.halign = Gtk.Align.CENTER;
@@ -208,67 +196,26 @@ public class Mines : Gtk.Application
 
         minefield_overlay.add_overlay (paused_box);
 
-        view_box.pack_start (minefield_aspect, true, true, 0);
+        main_screen = (Gtk.Box) ui_builder.get_object ("main_screen");
 
         /* Initialize New Game Screen */
         startup_new_game_screen (ui_builder);
-        view_box.pack_start (new_game_screen, true, true, 0);
 
         /* Initialize Custom Game Screen */
         startup_custom_game_screen (ui_builder);
-        view_box.pack_start (custom_game_screen, false, false);
 
         history = new History (Path.build_filename (Environment.get_user_data_dir (), "gnome-mines", 
"history"));
         history.load ();
 
-        buttons_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 4);
-        buttons_box.margin_right = 6;
-        buttons_box.margin_left = 6;
-        buttons_box.set_size_request (115, -1);
-
-        main_vbox.pack_start (buttons_box, false, false, 0);
-
-        var size = new Gtk.SizeGroup (Gtk.SizeGroupMode.BOTH);
-
-        var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 2);
-        // Obviously a FIXME image
-        var image = new Gtk.Image.from_icon_name ("preferences-desktop-locale-symbolic", Gtk.IconSize.DND);
-        box.pack_start (image, false, false, 0);
-        flag_label = new Gtk.Label ("");
-        box.pack_start (flag_label, false, false, 0);
-        buttons_box.pack_start (box, false, false, 8);
-        box.show_all ();
-
-        box = new Gtk.Box (Gtk.Orientation.VERTICAL, 2);
-        image = new Gtk.Image.from_icon_name ("preferences-system-time-symbolic", Gtk.IconSize.DND);
-        box.pack_start (image, false, false, 0);
-        clock_label = new Gtk.Label ("");
-        clock_label.show ();
-        box.pack_start (clock_label, false, false, 0);
-        buttons_box.pack_start (box, false, false, 8);
-        box.show_all ();
-        box.margin_bottom = 18;
-
-        play_pause_button = new Gtk.Button ();
-        buttons_box.pack_end (play_pause_button, false, false, 0);
-        size.add_widget (play_pause_button);
-        play_pause_button.use_underline = true;
-
-        high_scores_button = new Gtk.Button.with_mnemonic (_("_Best Times"));
-        buttons_box.pack_end (high_scores_button, false, false, 0);
-        high_scores_button.action_name = "app.scores";
-        size.add_widget (high_scores_button);
-
-        new_game_button = new Gtk.Button.with_mnemonic (_("_Difficulty"));
-        buttons_box.pack_end (new_game_button, false, false, 0);
-        size.add_widget (new_game_button);
-        new_game_button.action_name = "app.new-game";
-        new_game_button.show ();
+        flag_label = (Gtk.Label) ui_builder.get_object ("flag_label");
+        clock_label = (Gtk.Label) ui_builder.get_object ("clock_label");
 
-        replay_button = new Gtk.Button.with_mnemonic (_("_Play Again"));
-        buttons_box.pack_end (replay_button, false, false, 0);
-        replay_button.action_name = "app.repeat-size";
-        size.add_widget (replay_button);
+        play_pause_button = (Gtk.Button) ui_builder.get_object ("play_pause_button");
+        play_pause_label = (Gtk.Label) ui_builder.get_object ("play_pause_label");
+
+        high_scores_button = (Gtk.Button) ui_builder.get_object ("high_scores_button");
+        replay_button = (Gtk.Button) ui_builder.get_object ("replay_button");
+        new_game_button = (Gtk.Button) ui_builder.get_object ("new_game_button");
     }
 
     private void startup_new_game_screen (Gtk.Builder builder)
@@ -448,7 +395,7 @@ public class Mines : Gtk.Application
     {
         is_new_game_screen = false;
         custom_game_screen.show ();
-        minefield_aspect.hide ();
+        main_screen.hide ();
         new_game_screen.hide ();
     }
 
@@ -490,7 +437,7 @@ public class Mines : Gtk.Application
 
         is_new_game_screen = true;
         custom_game_screen.hide ();
-        minefield_aspect.hide ();
+        main_screen.hide ();
         new_game_screen.show ();
         window.resize (window_width, window_height);
 
@@ -499,7 +446,7 @@ public class Mines : Gtk.Application
         new_game_action.set_enabled (false);
         repeat_size_action.set_enabled (false);
         pause_action.set_enabled (false);
-        buttons_box.hide ();
+        main_screen.hide ();
     }
 
     private void start_game ()
@@ -507,14 +454,14 @@ public class Mines : Gtk.Application
         is_new_game_screen = false;
         custom_game_screen.hide ();
         window_skip_configure = true;
-        minefield_aspect.show ();
+        main_screen.show ();
         minefield_view.has_focus = true;
         new_game_screen.hide ();
-        play_pause_button.hide ();
+        play_pause_button.hide();
         replay_button.hide ();
         new_game_button.hide ();
         high_scores_button.hide ();
-        buttons_box.show ();
+        main_screen.show ();
 
         tick_cb ();
 
@@ -789,12 +736,8 @@ public class Mines : Gtk.Application
         new_game_button.hide ();
 
         play_pause_button.show ();
-        play_pause_button.action_name = "app.pause";
-        play_pause_button.label = _("_Pause");
-        var label = (Gtk.Label)play_pause_button.get_child ();
-        label.margin = 12;
-        label.margin_left = 24;
-        label.margin_right = 24;
+        play_pause_label.label = _("_Pause");
+        
     }
 
     private void display_unpause_button ()
@@ -803,12 +746,7 @@ public class Mines : Gtk.Application
         new_game_button.show ();
 
         play_pause_button.show ();
-        play_pause_button.action_name = "app.pause";
-        play_pause_button.label = _("_Resume");
-        var label = (Gtk.Label)play_pause_button.get_child ();
-        label.margin = 12;
-        label.margin_left = 24;
-        label.margin_right = 24;
+        play_pause_label.label = _("_Resume");
     }
 
     public static int main (string[] args)


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