[gnome-sudoku/vala-port] Removed 'Hint' and 'Help' buttons and related code



commit 3bfc6becfd0acab27c0544f19dd8029cd23e35c5
Author: Parin Porecha <parinporecha gmail com>
Date:   Tue May 20 17:46:43 2014 +0530

    Removed 'Hint' and 'Help' buttons and related code
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710624

 TODO                  |    9 ---
 data/gnome-sudoku.ui  |  114 +-----------------------------
 src/gnome-sudoku.vala |  185 +------------------------------------------------
 src/sudoku-game.vala  |   42 -----------
 src/sudoku-view.vala  |   41 +-----------
 5 files changed, 5 insertions(+), 386 deletions(-)
---
diff --git a/TODO b/TODO
index 884119f..65892f8 100644
--- a/TODO
+++ b/TODO
@@ -5,8 +5,6 @@ Undo/redo are clickable, even before starting a game
 
 The first number of a game is not updated on the screen before the selector is moved to a different place.
 
-The "Back" back seems to function like undo. Is that the case?
-
 The ingame Help: (I like it!)
   Should maybe have different name. Help is the common word for opening the help manual.
   Left align the text
@@ -36,9 +34,6 @@ Known Bugs -
   (http://i.imgur.com/FDLukf2.png)
   Will be resolved when the Popup window is replaced by popover
 
-- 'Back' button below number-pad and 'Undo' option in the Panel menu (don't know what to call it),
-  are redundant and have the same callback - 'undo_cb'.
-
 mcatanzaro: This number pad was from an earlier design; I think we can remove
             it completely.
 
@@ -54,10 +49,6 @@ mcatanzaro: This number pad was from an earlier design; I think we can remove
 
 - No icon is displayed in panel for vala-port
 
-- When 'Show possible numbers' is checked, the numbers are not displayed in an organized manner at the 
bottom.
-  (http://i.imgur.com/MYiloXw.png)
-  Instead, they are displayed at random positions in the cells (looks random, maybe there is a bug in 
display offsets)
-
 - Message Dialogs haven't been ported. Port gtk_goodies/dialog_extras.py
 
 - Are translations working? I think translations are probably not working, don't we need to bindtextdomain 
etc?
diff --git a/data/gnome-sudoku.ui b/data/gnome-sudoku.ui
index 1ffa558..9f82702 100644
--- a/data/gnome-sudoku.ui
+++ b/data/gnome-sudoku.ui
@@ -33,8 +33,8 @@
                                     </object>
                                 </child>
                                 <child>
-                                    <object class="GtkButton" id="back_button">
-                                        <property name="label" translatable="yes">Back</property>
+                                    <object class="GtkButton" id="undo_button">
+                                        <property name="label" translatable="yes">Undo</property>
                                         <property name="use_action_appearance">False</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">True</property>
@@ -47,40 +47,6 @@
                                         <property name="fill">False</property>
                                     </packing>
                                 </child>
-                                <child>
-                                    <object class="GtkButton" id="hint_button">
-                                        <property name="label" translatable="yes">Hint</property>
-                                        <property name="use_action_appearance">False</property>
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">True</property>
-                                        <property name="focus_on_click">False</property>
-                                        <property name="receives_default">True</property>
-                                        <property name="use_action_appearance">False</property>
-                                    </object>
-                                    <packing>
-                                        <property name="expand">False</property>
-                                        <property name="fill">False</property>
-                                        <property name="position">2</property>
-                                        <property name="pack_type">end</property>
-                                    </packing>
-                                </child>
-                                <child>
-                                    <object class="GtkButton" id="help_button">
-                                        <property name="label" translatable="yes">Help</property>
-                                        <property name="use_action_appearance">False</property>
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">True</property>
-                                        <property name="focus_on_click">False</property>
-                                        <property name="receives_default">True</property>
-                                        <property name="use_action_appearance">False</property>
-                                    </object>
-                                    <packing>
-                                        <property name="expand">False</property>
-                                        <property name="fill">False</property>
-                                        <property name="position">2</property>
-                                        <property name="pack_type">end</property>
-                                    </packing>
-                                </child>
                             </object>  <!-- End of controls_box -->
                             <packing>
                                 <property name="expand">False</property>
@@ -103,82 +69,6 @@
                         </child>
                     </object> <!-- End of game_box -->
                 </child>
-                <child>
-                    <object class="GtkBox" id="help_box">
-                        <property name="visible">False</property>
-                        <property name="spacing">2</property>
-                        <property name="orientation">vertical</property>
-                        <child>
-                            <object class="GtkExpander" id="naked_singles">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <child>
-                                    <object class="GtkBox" id="naked_single_items">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="orientation">vertical</property>
-                                        <child>
-                                            <placeholder/>
-                                        </child>
-                                    </object>
-                                </child>
-                                <child type="label">
-                                    <object class="GtkLabel" id="naked_singles_label">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="label" translatable="yes">Naked Singles</property>
-                                    </object>
-                                </child>
-                            </object>
-                        </child>
-                        <child>
-                            <object class="GtkExpander" id="hidden_singles">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <child>
-                                    <object class="GtkBox" id="hidden_single_items">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="orientation">vertical</property>
-                                        <child>
-                                            <placeholder/>
-                                        </child>
-                                    </object>
-                                </child>
-                                <child type="label">
-                                    <object class="GtkLabel" id="hidden_singles_label">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="label" translatable="yes">Hidden Singles</property>
-                                    </object>
-                                </child>
-                            </object>
-                        </child>
-                        <child>
-                            <object class="GtkExpander" id="naked_subsets">
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <child>
-                                    <object class="GtkBox" id="naked_subset_items">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="orientation">vertical</property>
-                                        <child>
-                                            <placeholder/>
-                                        </child>
-                                    </object>
-                                </child>
-                                <child type="label">
-                                    <object class="GtkLabel" id="naked_subsets_label">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="label" translatable="yes">Naked Subsets</property>
-                                    </object>
-                                </child>
-                            </object>
-                        </child>
-                    </object> <!-- End of help_box -->
-                </child>
             </object>
         </child>
     </object>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 3e42b20..7b31c17 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -18,7 +18,6 @@ public class Sudoku : Gtk.Application
     private HeaderBar header_bar;
     private Box game_box; // Holds the grid and controls boxes
     private Box grid_box; // Holds the view
-    private Box help_box;
 
     private Box controls_box; // Holds the controls (including the number picker)
     private NumberPicker number_picker;
@@ -27,11 +26,6 @@ public class Sudoku : Gtk.Application
 
     private SudokuSaver saver;
 
-    // Help Stuff
-    private Box naked_single_items;
-    private Box hidden_single_items;
-    private Box naked_subset_items;
-
     private const GLib.ActionEntry action_entries[] =
     {
         {"new-game", new_game_cb                                    },
@@ -80,29 +74,13 @@ public class Sudoku : Gtk.Application
         header_bar = (HeaderBar) builder.get_object ("headerbar");
         game_box = (Box) builder.get_object ("game_box");
         grid_box = (Box) builder.get_object ("grid_box");
-        help_box = (Box) builder.get_object ("help_box");
-
-        naked_single_items = (Box) builder.get_object ("naked_single_items");
-        hidden_single_items = (Box) builder.get_object ("hidden_single_items");
-        naked_subset_items = (Box) builder.get_object ("naked_subset_items");
-
         controls_box = (Box) builder.get_object ("number_picker_box");
 
-        var back_button = (Button) builder.get_object ("back_button");
-        back_button.clicked.connect (() => {
+        var undo_button = (Button) builder.get_object ("undo_button");
+        undo_button.clicked.connect (() => {
             undo_cb();
         });
 
-        var hint_button = (Button) builder.get_object ("hint_button");
-        hint_button.clicked.connect (() => {
-            view.hint ();
-        });
-
-        var help_button = (Button) builder.get_object ("help_button");
-        help_button.clicked.connect (() => {
-            help_box.visible = !help_box.visible;
-        });
-
         sudoku_store = new SudokuStore ();
         saver = new SudokuSaver ();
         //SudokuGenerator gen = new SudokuGenerator();
@@ -158,8 +136,6 @@ public class Sudoku : Gtk.Application
         view.show ();
         grid_box.pack_start (view);
 
-        update_help ();
-
         number_picker = new NumberPicker(ref game.board);
         controls_box.pack_start (number_picker);
 
@@ -168,11 +144,6 @@ public class Sudoku : Gtk.Application
             number_picker.sensitive = !game.board.is_fixed[row, col];
         });
 
-        view.cell_value_changed_event.connect ((row, col) => {
-            update_help ();
-        });
-
-
         number_picker.number_picked.connect ((number) => {
             view.set_cell_value (view.selected_x, view.selected_y, number);
         });
@@ -219,158 +190,6 @@ public class Sudoku : Gtk.Application
         });
     }
 
-    private void update_help ()
-    {
-        var logical_solver = new LogicalSudokuSolver(ref game.board);
-
-        view.reset_cell_background_colors ();
-        view.queue_draw ();
-
-        RGBA highlight_color = {0.47, 0.75, 1, 0};
-        RGBA highlight_fixed_color = {0.8, 0.8, 0.9, 0};
-
-        foreach (Widget w in naked_single_items.get_children())
-        {
-            naked_single_items.remove (w);
-        }
-
-        foreach (Cell? cell in logical_solver.naked_singles)
-        {
-            var event_box = new Gtk.EventBox ();
-
-            var label = new Gtk.Label ("%d is the only possiblility in %d, %d".printf (cell.val, 
cell.coord.col, cell.coord.row));
-
-            event_box.enter_notify_event.connect ((event) => {
-                view.cell_grab_focus (cell.coord.row, cell.coord.col);
-                return true;
-            });
-
-            label.use_markup = true;
-            event_box.add (label);
-            naked_single_items.add (event_box);
-            event_box.show ();
-            label.show ();
-        }
-
-        foreach (Widget w in hidden_single_items.get_children())
-        {
-            hidden_single_items.remove (w);
-        }
-
-        foreach (HiddenSingle? hidden_single in logical_solver.hidden_singles)
-        {
-            var event_box = new Gtk.EventBox ();
-
-            var description = "%d should go in %d, %d because its the only place it can go in the associated 
".printf (hidden_single.cell.val, hidden_single.cell.coord.col, hidden_single.cell.coord.row);
-            if (hidden_single.row && hidden_single.col && hidden_single.block)
-            {
-                description += "row, column and block";
-            }
-            else if (hidden_single.row && hidden_single.col)
-            {
-                description += "row and column";
-            }
-            else if (hidden_single.col && hidden_single.block)
-            {
-                description += "column and block";
-            }
-            else if (hidden_single.row && hidden_single.block)
-            {
-                description += "row and block";
-            }
-            else if (hidden_single.row)
-            {
-                description += "row";
-            }
-            else if (hidden_single.col)
-            {
-                description += "column";
-            }
-            else if (hidden_single.block)
-            {
-                description += "block";
-            }
-
-            var label = new Gtk.Label (description);
-
-            event_box.enter_notify_event.connect ((event) => {
-                view.cell_grab_focus (hidden_single.cell.coord.row, hidden_single.cell.coord.col);
-
-                if (hidden_single.row) {
-                    view.set_row_background_color (hidden_single.cell.coord.row, highlight_color, 
highlight_fixed_color);
-                }
-
-                if (hidden_single.col) {
-                    view.set_col_background_color (hidden_single.cell.coord.col, highlight_color, 
highlight_fixed_color);
-                }
-
-                if (hidden_single.block) {
-                    Coord block = game.board.get_block_for (hidden_single.cell.coord.row, 
hidden_single.cell.coord.col);
-                    view.set_block_background_color (block.row, block.col, highlight_color, 
highlight_fixed_color);
-                }
-
-                view.selected_x = hidden_single.cell.coord.col;
-                view.selected_y = hidden_single.cell.coord.row;
-
-                view.queue_draw ();
-
-                return true;
-            });
-
-            event_box.leave_notify_event.connect ((event) => {
-                view.reset_cell_background_colors ();
-                view.queue_draw ();
-
-                return true;
-            });
-
-            label.use_markup = true;
-            event_box.add (label);
-            hidden_single_items.add (event_box);
-            event_box.show ();
-            label.show ();
-        }
-
-        foreach (Widget w in naked_subset_items.get_children())
-        {
-            naked_subset_items.remove (w);
-        }
-
-        foreach (Subset? subset in logical_solver.get_naked_subsets()) {
-            var event_box = new Gtk.EventBox ();
-
-            var description = "naked subset";
-
-            var label = new Gtk.Label (description);
-
-            event_box.enter_notify_event.connect ((event) => {
-                foreach (Cell? cell in subset.eliminated_possibilities) {
-                    view.set_cell_background_color(cell.coord.row, cell.coord.col, {1, 0, 0, 0});
-                }
-
-                foreach (Coord? coord in subset.coords) {
-                    view.set_cell_background_color(coord.row, coord.col, {0, 1, 0, 0});
-                }
-
-                view.queue_draw ();
-
-                return true;
-            });
-
-            event_box.leave_notify_event.connect ((event) => {
-                view.reset_cell_background_colors ();
-                view.queue_draw ();
-
-                return true;
-            });
-
-            event_box.add (label);
-            naked_subset_items.add (event_box);
-            event_box.show ();
-            label.show ();
-        }
-    }
-
     public void new_game_cb ()
     {
         var random_difficulty = (DifficultyCatagory) Random.int_range (0, 4);
diff --git a/src/sudoku-game.vala b/src/sudoku-game.vala
index 005d1fa..37bda45 100644
--- a/src/sudoku-game.vala
+++ b/src/sudoku-game.vala
@@ -69,48 +69,6 @@ public class SudokuGame
         add_to_stack (ref undostack, -1, -1, count);
     }
 
-    public void hint (ref int row, ref int col)
-    {
-        var total_pos = new int [board.rows, board.cols];
-        var min = board.max_val + 1;
-        var count = 0;
-        for (var l1 = 0; l1 < board.rows; l1++)
-        {
-            for (var l2 = 0; l2 < board.cols; l2++)
-            {
-                total_pos [l1, l2] = board.count_possibilities (l1, l2);
-                if (total_pos [l1, l2] < min && total_pos [l1, l2] > 0)
-                {
-                    min = total_pos [l1, l2];
-                    count = 0;
-                }
-                if (total_pos [l1, l2] == min)
-                {
-                    count++;
-                }
-            }
-        }
-        if (count == 0)
-            return;
-        count = Random.int_range (1, count + 1);
-        for (var l1 = 0; l1 < board.rows; l1++)
-        {
-            for (var l2 = 0; l2 < board.cols; l2++)
-            {
-                if (total_pos[l1, l2] == min)
-                {
-                    count--;
-                    if (count == 0)
-                    {
-                        row = l1;
-                        col = l2;
-                        return;
-                    }
-                }
-            }
-        }
-    }
-
     public void cell_changed_cb (int row, int col, int old_val, int new_val)
     {
         cell_changed (row, col, old_val, new_val);
diff --git a/src/sudoku-view.vala b/src/sudoku-view.vala
index 9f4d6da..4f9ae41 100644
--- a/src/sudoku-view.vala
+++ b/src/sudoku-view.vala
@@ -496,30 +496,6 @@ private class SudokuCellView : Gtk.DrawingArea
             }
         }
     }
-
-    public void hint ()
-    {
-        show_hint ();
-        Timeout.add (200, remove_hint);
-        Timeout.add (400, show_hint);
-        Timeout.add (600, remove_hint);
-        Timeout.add (800, show_hint);
-        Timeout.add (1000, remove_hint);
-    }
-
-    private bool show_hint ()
-    {
-        background_color = { 1.0, 0.0, 0.0, 0.0 };
-        queue_draw ();
-        return false;
-    }
-
-    private bool remove_hint ()
-    {
-        background_color = { 1.0, 1.0, 1.0, 0.0 };
-        queue_draw ();
-        return false;
-    }
 }
 
 public class SudokuView : Gtk.AspectFrame
@@ -651,7 +627,6 @@ public class SudokuView : Gtk.AspectFrame
                                     if (_show_warnings && cells[i,j].value == 0 && 
game.board.count_possibilities (cells[i,j].row, cells[i,j].col) == 0) {
                                         if (!cells[i,j].warn_about_unfillable_squares) {
                                             cells[i,j].warn_about_unfillable_squares = true;
-                                            cells[i,j].hint ();
                                         }
                                     }
                                     else
@@ -663,6 +638,7 @@ public class SudokuView : Gtk.AspectFrame
                             previous_board_broken_state = game.board.broken;
                         }
                         cell_value_changed_event(cell_row, cell_col);
+                        queue_draw ();
                     });
                 }
 
@@ -692,13 +668,6 @@ public class SudokuView : Gtk.AspectFrame
         set { _show_highlights = value; }
     }
 
-    private bool _show_hints = false;
-    public bool show_hints
-    {
-        get { return _show_hints; }
-        set { _show_hints = value; }
-    }
-
     private bool _show_warnings = false;
     public bool show_warnings
     {
@@ -712,7 +681,6 @@ public class SudokuView : Gtk.AspectFrame
                     if (_show_warnings && cells[i,j].value == 0 && game.board.count_possibilities 
(cells[i,j].row, cells[i,j].col) == 0)
                     {
                         cells[i,j].warn_about_unfillable_squares = true;
-                        cells[i,j].hint ();
                     }
                     else
                     {
@@ -743,13 +711,6 @@ public class SudokuView : Gtk.AspectFrame
         }
     }
 
-    public void hint ()
-    {
-        int row=0, col=0;
-        game.hint (ref row, ref col);
-        cells [row, col].hint ();
-    }
-
     public bool dance () {
         if (dance_step < 90)
         {


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