[gnome-sudoku] Simplify New Game Screen
- From: Parin Porecha <parinporecha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku] Simplify New Game Screen
- Date: Tue, 24 Jun 2014 17:17:29 +0000 (UTC)
commit 85840ca5c49ad19ce495f8c3cee9ab477b50d335
Author: Parin Porecha <parinporecha gmail com>
Date: Thu Jun 12 21:13:04 2014 +0530
Simplify New Game Screen
https://bugzilla.gnome.org/show_bug.cgi?id=731214
data/gnome-sudoku.ui | 166 +++++++++++++++---------------------------------
src/gnome-sudoku.vala | 80 +++---------------------
2 files changed, 62 insertions(+), 184 deletions(-)
---
diff --git a/data/gnome-sudoku.ui b/data/gnome-sudoku.ui
index 936533b..fb37d81 100644
--- a/data/gnome-sudoku.ui
+++ b/data/gnome-sudoku.ui
@@ -92,125 +92,63 @@
<property name="orientation">vertical</property>
<property name="visible">False</property>
<property name="halign">center</property>
+ <property name="homogeneous">True</property>
+ <property name="margin">80</property>
+ <property name="width-request">350</property>
<child>
- <object class="GtkBox" id="new_game_box">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkBox" id="easy_medium_box">
- <property name="visible">True</property>
- <child>
- <object class="GtkBox" id="easy_grid">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkLabel" id="easy_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label"
translatable="yes">Easy</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="padding">20</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox" id="medium_grid">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <placeholder/>
- </child>
- <child>
- <object class="GtkLabel" id="medium_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label"
translatable="yes">Medium</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="padding">20</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="pack_type">start</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox" id="hard_veryhard_box">
- <property name="visible">True</property>
- <child>
- <object class="GtkBox" id="hard_grid">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <placeholder/>
- </child>
- <child>
- <object class="GtkLabel" id="hard_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label"
translatable="yes">Hard</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="padding">20</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox" id="very_hard_grid">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <placeholder/>
- </child>
- <child>
- <object class="GtkLabel" id="very_hard_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Very
Hard</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- </attributes>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="padding">20</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="pack_type">end</property>
- </packing>
- </child>
- </object> <!-- End of new game box -->
+ <object class="GtkButton" id="easy_button">
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <property name="label" translatable="yes">_Easy</property>
+ <property name="action-name">app.start-game</property>
+ <property name="action-target">0</property> <!-- 0 corresponds to enum
DifficultyCategory.EASY -->
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="medium_button">
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <property name="label" translatable="yes">_Medium</property>
+ <property name="action-name">app.start-game</property>
+ <property name="action-target">1</property> <!-- 1 corresponds to enum
DifficultyCategory.MEDIUM -->
+ </object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
- <property name="padding">20</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="hard_button">
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <property name="label" translatable="yes">_Hard</property>
+ <property name="action-name">app.start-game</property>
+ <property name="action-target">2</property> <!-- 2 corresponds to enum
DifficultyCategory.HARD -->
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="very_hard_button">
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <property name="label" translatable="yes">_Very Hard</property>
+ <property name="action-name">app.start-game</property>
+ <property name="action-target">3</property> <!-- 3 corresponds to enum
DifficultyCategory.VERY_HARD -->
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
</packing>
</child>
</object> <!-- End of new_start_box -->
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index ef9cbd6..e92cf6b 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -25,16 +25,6 @@ public class Sudoku : Gtk.Application
private Box undo_redo_box;
private Button back_button;
- private Box easy_grid;
- private Box medium_grid;
- private Box hard_grid;
- private Box very_hard_grid;
-
- private SudokuView easy_preview;
- private SudokuView medium_preview;
- private SudokuView hard_preview;
- private SudokuView very_hard_preview;
-
private SudokuStore sudoku_store;
private SudokuSaver saver;
@@ -49,6 +39,7 @@ public class Sudoku : Gtk.Application
private const GLib.ActionEntry action_entries[] =
{
{"new-game", new_game_cb },
+ {"start-game", start_game_cb, "i" },
{"reset", reset_cb },
{"back", back_cb },
{"undo", undo_cb },
@@ -182,39 +173,6 @@ public class Sudoku : Gtk.Application
saver = new SudokuSaver ();
//SudokuGenerator gen = new SudokuGenerator();
- easy_grid = (Box) builder.get_object ("easy_grid");
- medium_grid = (Box) builder.get_object ("medium_grid");
- hard_grid = (Box) builder.get_object ("hard_grid");
- very_hard_grid = (Box) builder.get_object ("very_hard_grid");
-
- easy_grid.button_press_event.connect ((event) => {
- if (event.button == 1)
- start_game (easy_preview.game.board);
-
- return false;
- });
-
- medium_grid.button_press_event.connect ((event) => {
- if (event.button == 1)
- start_game (medium_preview.game.board);
-
- return false;
- });
-
- hard_grid.button_press_event.connect ((event) => {
- if (event.button == 1)
- start_game (hard_preview.game.board);
-
- return false;
- });
-
- very_hard_grid.button_press_event.connect ((event) => {
- if (event.button == 1)
- start_game (very_hard_preview.game.board);
-
- return false;
- });
-
var savegame = saver.get_savedgame ();
if (savegame != null)
start_game (savegame.board);
@@ -318,34 +276,16 @@ public class Sudoku : Gtk.Application
header_bar_subtitle = header_bar.get_subtitle ();
header_bar.set_subtitle (null);
print_action.set_enabled (false);
+ }
- if (easy_preview != null)
- easy_preview.destroy ();
- var easy_board = sudoku_store.get_random_easy_board ();
- easy_preview = new SudokuView (new SudokuGame (easy_board), true);
- easy_preview.show ();
- easy_grid.pack_start (easy_preview);
-
- if (medium_preview != null)
- medium_preview.destroy ();
- var medium_board = sudoku_store.get_random_medium_board ();
- medium_preview = new SudokuView (new SudokuGame (medium_board), true);
- medium_preview.show ();
- medium_grid.pack_start (medium_preview);
-
- if (hard_preview != null)
- hard_preview.destroy ();
- var hard_board = sudoku_store.get_random_hard_board ();
- hard_preview = new SudokuView (new SudokuGame (hard_board), true);
- hard_preview.show ();
- hard_grid.pack_start (hard_preview);
-
- if (very_hard_preview != null)
- very_hard_preview.destroy ();
- var very_hard_board = sudoku_store.get_random_very_hard_board ();
- very_hard_preview = new SudokuView (new SudokuGame (very_hard_board), true);
- very_hard_preview.show ();
- very_hard_grid.pack_start (very_hard_preview);
+ private void start_game_cb (SimpleAction action, Variant? difficulty)
+ {
+ // Since we cannot have enums in .ui file, the 'action-target' property
+ // of new game buttons in data/gnome-sudoku.ui
+ // has been set to integers corresponding to the enums.
+ // Following line converts those ints to their DifficultyCategory
+ var selected_difficulty = (DifficultyCategory) difficulty.get_int32 ();
+ start_game (sudoku_store.get_random_board (selected_difficulty));
}
private void reset_cb ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]