[gnome-2048] Constraint grid size



commit 086c60d75ba192cbf150e4aee79f53c1e5ef7ab7
Author: Juan R. GarcĂ­a Blanco <juanrgar gmail com>
Date:   Sun Feb 15 22:56:21 2015 +0100

    Constraint grid size
    
    Allow the user to select a grid size from a pre-defined set.

 data/preferences.ui  |  220 +++++++++++--------------------------------------
 src/application.vala |   35 +++++++-
 2 files changed, 82 insertions(+), 173 deletions(-)
---
diff --git a/data/preferences.ui b/data/preferences.ui
index c951206..1b21516 100644
--- a/data/preferences.ui
+++ b/data/preferences.ui
@@ -8,13 +8,6 @@
     <property name="step_increment">1</property>
     <property name="page_increment">1</property>
   </object>
-  <object class="GtkAdjustment" id="rowsadj">
-    <property name="lower">1</property>
-    <property name="upper">8</property>
-    <property name="value">4</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">1</property>
-  </object>
   <object class="GtkDialog" id="preferencesdialog">
     <property name="can_focus">False</property>
     <property name="border_width">12</property>
@@ -50,178 +43,58 @@
           <object class="GtkGrid" id="grid1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="column_homogeneous">True</property>
+            <property name="row_spacing">12</property>
+            <property name="column_spacing">6</property>
             <child>
-              <object class="GtkBox" id="box1">
+              <object class="GtkLabel" id="label1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="border_width">12</property>
-                <property name="orientation">vertical</property>
-                <property name="spacing">12</property>
-                <child>
-                  <object class="GtkFrame" id="frame1">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="label_xalign">0</property>
-                    <property name="shadow_type">none</property>
-                    <child>
-                      <object class="GtkAlignment" id="alignment3">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="left_padding">12</property>
-                        <child>
-                          <object class="GtkGrid" id="grid3">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="border_width">6</property>
-                            <property name="row_spacing">6</property>
-                            <property name="column_spacing">12</property>
-                            <child>
-                              <object class="GtkLabel" id="label6">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="xalign">1</property>
-                                <property name="label" translatable="yes">Columns</property>
-                              </object>
-                              <packing>
-                                <property name="left_attach">0</property>
-                                <property name="top_attach">1</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkSpinButton" id="colsspin">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="progress_pulse_step">0.070000000000000007</property>
-                                <property name="input_purpose">digits</property>
-                                <property name="adjustment">colsadj</property>
-                                <property name="climb_rate">1</property>
-                                <property name="numeric">True</property>
-                                <property name="update_policy">if-valid</property>
-                                <property name="value">4</property>
-                              </object>
-                              <packing>
-                                <property name="left_attach">1</property>
-                                <property name="top_attach">1</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkLabel" id="label7">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="xalign">1</property>
-                                <property name="label" translatable="yes">Rows</property>
-                              </object>
-                              <packing>
-                                <property name="left_attach">0</property>
-                                <property name="top_attach">0</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkSpinButton" id="rowsspin">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="input_purpose">number</property>
-                                <property name="adjustment">rowsadj</property>
-                                <property name="climb_rate">1</property>
-                                <property name="numeric">True</property>
-                                <property name="update_policy">if-valid</property>
-                                <property name="value">4</property>
-                              </object>
-                              <packing>
-                                <property name="left_attach">1</property>
-                                <property name="top_attach">0</property>
-                              </packing>
-                            </child>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                    <child type="label">
-                      <object class="GtkLabel" id="label5">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Grid</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkFrame" id="frame2">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="label_xalign">0</property>
-                    <property name="shadow_type">none</property>
-                    <child>
-                      <object class="GtkAlignment" id="alignment1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="left_padding">12</property>
-                        <child>
-                          <object class="GtkGrid" id="grid2">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="border_width">6</property>
-                            <property name="row_spacing">6</property>
-                            <property name="column_spacing">12</property>
-                            <child>
-                              <object class="GtkLabel" id="label2">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="xalign">1</property>
-                                <property name="label" translatable="yes">Display congrats</property>
-                              </object>
-                              <packing>
-                                <property name="left_attach">0</property>
-                                <property name="top_attach">0</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkSwitch" id="congratswitch">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="active">True</property>
-                              </object>
-                              <packing>
-                                <property name="left_attach">1</property>
-                                <property name="top_attach">0</property>
-                              </packing>
-                            </child>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                    <child type="label">
-                      <object class="GtkLabel" id="label3">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Interface</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
+                <property name="xalign">1</property>
+                <property name="label" translatable="yes">Grid size</property>
               </object>
               <packing>
                 <property name="left_attach">0</property>
                 <property name="top_attach">0</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkComboBoxText" id="gridsizecombo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="active">0</property>
+                <items>
+                  <item id="0" translatable="yes">4 x 4</item>
+                  <item id="1" translatable="yes">5 x 5</item>
+                </items>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">1</property>
+                <property name="label" translatable="yes">Display congrats</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSwitch" id="congratswitch">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="active">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">True</property>
@@ -232,4 +105,11 @@
       </object>
     </child>
   </object>
+  <object class="GtkAdjustment" id="rowsadj">
+    <property name="lower">1</property>
+    <property name="upper">8</property>
+    <property name="value">4</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">1</property>
+  </object>
 </interface>
diff --git a/src/application.vala b/src/application.vala
index 9410e5d..584a48a 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -28,6 +28,7 @@ public class Application : Gtk.Application
   private Gtk.Dialog _congrats_dialog;
   private Gtk.Label _congrats_message;
   private Gtk.Label _score;
+  private Gtk.ComboBoxText _grid_size_combo;
 
   private int _window_width;
   private int _window_height;
@@ -229,18 +230,32 @@ public class Application : Gtk.Application
     _preferences_dialog = builder.get_object ("preferencesdialog") as Gtk.Dialog;
     _preferences_dialog.set_transient_for (_window);
 
+    _grid_size_combo = builder.get_object ("gridsizecombo") as Gtk.ComboBoxText;
+
     _preferences_dialog.response.connect ((response_id) => {
       _preferences_dialog.hide_on_delete ();
     });
     _preferences_dialog.delete_event.connect ((response_id) => {
-      bool settings_changed = _game.reload_settings ();
+      int grid_size;
+      int rows, cols;
+      bool settings_changed;
+
+      grid_size = _grid_size_combo.get_active ();
+      if (grid_size == 0) {
+        rows = cols = 4;
+      } else {
+        rows = cols = 5;
+      }
+
+      _settings.set_int ("rows", rows);
+      _settings.set_int ("cols", cols);
+
+      settings_changed = _game.reload_settings ();
       if (settings_changed)
         _game.new_game ();
       return _preferences_dialog.hide_on_delete ();
     });
 
-    _settings.bind ("rows", builder.get_object ("rowsspin"), "value", GLib.SettingsBindFlags.DEFAULT);
-    _settings.bind ("cols", builder.get_object ("colsspin"), "value", GLib.SettingsBindFlags.DEFAULT);
     _settings.bind ("do-congrat", builder.get_object ("congratswitch"), "active", 
GLib.SettingsBindFlags.DEFAULT);
   }
 
@@ -281,6 +296,20 @@ public class Application : Gtk.Application
 
   private void preferences_cb ()
   {
+    int grid_size;
+    int rows, cols;
+
+    rows = _settings.get_int ("rows");
+    cols = _settings.get_int ("cols");
+
+    if (rows == 4) {
+      grid_size = 0;
+    } else {
+      grid_size = 1;
+    }
+
+    _grid_size_combo.set_active (grid_size);
+
     _preferences_dialog.present ();
   }
 


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