[gnome-robots] encapsulate game properties in a class
- From: Andrey Kutejko <akutejko src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-robots] encapsulate game properties in a class
- Date: Tue, 6 Oct 2020 19:31:42 +0000 (UTC)
commit 3ad90c57f9d2c76d179e9428226d25e80469dd40
Author: Andrey Kutejko <andy128k gmail com>
Date: Sun Sep 27 14:25:45 2020 +0200
encapsulate game properties in a class
src/game-area.vala | 15 +-
src/meson.build | 1 +
src/properties-dialog.vala | 277 +++++++++++++++++++++++++++++
src/properties.vala | 421 ++++++++++-----------------------------------
src/robots.vala | 20 ++-
5 files changed, 386 insertions(+), 348 deletions(-)
---
diff --git a/src/game-area.vala b/src/game-area.vala
index eb7c61e..679cf9d 100644
--- a/src/game-area.vala
+++ b/src/game-area.vala
@@ -79,6 +79,7 @@ public class GameArea : DrawingArea {
}
private SoundPlayer sound_player;
+ private Properties properties;
public signal void updated (Game game);
@@ -87,7 +88,8 @@ public class GameArea : DrawingArea {
Bubble aieee_bubble,
Bubble yahoo_bubble,
Bubble splat_bubble,
- SoundPlayer sound_player
+ SoundPlayer sound_player,
+ Properties properties
) {
this.game = game;
this.theme = theme;
@@ -96,6 +98,7 @@ public class GameArea : DrawingArea {
this.yahoo_bubble = yahoo_bubble;
this.splat_bubble = splat_bubble;
this.sound_player = sound_player;
+ this.properties = properties;
add_events (Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK |
Gdk.EventMask.POINTER_MOTION_MASK);
configure_event.connect (event => resize_cb (event));
@@ -304,8 +307,8 @@ public class GameArea : DrawingArea {
public void player_command (PlayerCommand cmd) {
var safety =
- !properties_safe_moves () ? Game.MoveSafety.UNSAFE :
- properties_super_safe_moves () ? Game.MoveSafety.SUPER_SAFE :
+ !properties.safe_moves ? Game.MoveSafety.UNSAFE :
+ properties.super_safe_moves ? Game.MoveSafety.SUPER_SAFE :
Game.MoveSafety.SAFE;
if (game.player_command (cmd, safety)) {
@@ -355,9 +358,9 @@ public class GameArea : DrawingArea {
}
string key;
- if (properties_super_safe_moves ()) {
+ if (properties.super_safe_moves) {
key = game.config.description + "-super-safe";
- } else if (properties_safe_moves ()) {
+ } else if (properties.safe_moves) {
key = game.config.description + "-safe";
} else {
key = game.config.description;
@@ -375,7 +378,7 @@ public class GameArea : DrawingArea {
}
private void play_sound (Sound sound) {
- if (properties_sound ()) {
+ if (properties.sound) {
sound_player.play (sound);
}
}
diff --git a/src/meson.build b/src/meson.build
index dfa8035..3e3c459 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -21,6 +21,7 @@ sources = files(
'sound-player.vala',
'cursors.vala',
'properties.vala',
+ 'properties-dialog.vala',
'graphics.vala',
'arena.vala',
'game.vala',
diff --git a/src/properties-dialog.vala b/src/properties-dialog.vala
new file mode 100644
index 0000000..bf7e896
--- /dev/null
+++ b/src/properties-dialog.vala
@@ -0,0 +1,277 @@
+/*
+ * Copyright 2020 Andrey Kutejko <andy128k gmail com>
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * For more details see the file COPYING.
+ */
+
+using Gtk;
+using Gdk;
+
+public GameConfigs game_configs;
+
+void fill_typemenu (ComboBoxText menu, string selected_config) {
+ int active_index = 0;
+ for (int i = 0; i < game_configs.count (); ++i) {
+ var config = game_configs.@get ((uint)i);
+
+ var config_name = config.name ();
+ menu.append_text (config_name);
+
+ if (config_name == selected_config) {
+ active_index = i;
+ }
+ }
+ menu.set_active (active_index);
+}
+
+class ThemePicker : ComboBox {
+
+ private Themes themes;
+
+ public ThemePicker (Themes themes, string current_theme) {
+ Object (model: themes);
+ this.themes = themes;
+
+ var renderer = new CellRendererText ();
+ pack_start (renderer, true);
+ add_attribute (renderer, "text", 0);
+
+ TreeIter? iter = themes.find_iter_by_name (current_theme);
+ if (iter != null) {
+ set_active_iter (iter);
+ } else {
+ set_active (0);
+ }
+
+ changed.connect (theme_changed_cb);
+ }
+
+ public signal void theme_changed (Theme theme);
+
+ private void theme_changed_cb () {
+ TreeIter iter;
+ if (get_active_iter (out iter)) {
+ string theme_name;
+ string theme_path;
+ themes.get_values (iter, out theme_name, out theme_path);
+
+ try {
+ var theme = new Theme.from_file (theme_path, theme_name);
+ theme_changed (theme);
+ } catch (Error e) {
+ warning ("Cannot change theme to %s (placed at %s): %s",
+ theme_name,
+ theme_path,
+ e.message);
+ }
+ }
+ }
+}
+
+public class PropertiesDialog : Dialog {
+
+ private Properties properties;
+
+ public PropertiesDialog (Gtk.Window parent,
+ Themes themes,
+ Properties properties
+ ) {
+ Object (use_header_bar: 1,
+ title: _("Preferences"),
+ transient_for: parent,
+ modal: true,
+ border_width: 5);
+ this.properties = properties;
+
+ get_content_area ().set_spacing (2);
+
+ /* Set up notebook and add it to hbox of the gtk_dialog */
+ var notebook = new Notebook ();
+ notebook.border_width = 5;
+ get_content_area ().pack_start (notebook, true, true, 0);
+
+ /* The configuration page */
+ var cpage = new Box (Orientation.VERTICAL, 18);
+ cpage.border_width = 12;
+
+ var grid = new Grid ();
+ grid.set_row_spacing (6);
+ grid.set_column_spacing (12);
+ cpage.pack_start (grid, false, false, 0);
+
+ var label = new Label (_("Game Type"));
+ grid.attach (label, 0, 0, 1, 1);
+
+ var typemenu = new ComboBoxText ();
+ fill_typemenu (typemenu, properties.selected_config);
+ typemenu.changed.connect (() => {
+ game_config_changed(typemenu.get_active_text ());
+ });
+ grid.attach (typemenu, 1, 0, 1, 1);
+
+ var safe_chkbox = new CheckButton.with_mnemonic (_("_Use safe moves"));
+ safe_chkbox.set_active (properties.safe_moves);
+ safe_chkbox.set_tooltip_text (_("Prevent accidental moves that result in getting killed."));
+ grid.attach (safe_chkbox, 0, 1, 2, 1);
+
+ var super_safe_chkbox = new CheckButton.with_mnemonic (_("U_se super safe moves"));
+ super_safe_chkbox.set_active (properties.super_safe_moves);
+ super_safe_chkbox.set_tooltip_text (_("Prevents all moves that result in getting killed."));
+ super_safe_chkbox.set_sensitive (properties.safe_moves);
+ grid.attach (super_safe_chkbox, 0, 2, 2, 1);
+
+ safe_chkbox.toggled.connect ((toggle) => {
+ properties.safe_moves = toggle.active;
+ super_safe_chkbox.set_sensitive (properties.safe_moves);
+ });
+ super_safe_chkbox.toggled.connect ((toggle) => {
+ properties.super_safe_moves = toggle.get_active ();
+ });
+
+ var sound_chkbox = new CheckButton.with_mnemonic (_("_Enable sounds"));
+ sound_chkbox.set_active (properties.sound);
+ sound_chkbox.toggled.connect ((toggle) => {
+ properties.sound = toggle.active;
+ });
+ sound_chkbox.set_tooltip_text (_("Play sounds for events like winning a level and dying."));
+ grid.attach (sound_chkbox, 0, 3, 2, 1);
+
+ label = new Label.with_mnemonic (_("Game"));
+ notebook.append_page (cpage, label);
+
+ /* The graphics page */
+ var gpage = new Box (Orientation.VERTICAL, 18);
+ gpage.set_border_width (12);
+
+ grid = new Grid ();
+ grid.set_row_spacing (6);
+ grid.set_column_spacing (12);
+ gpage.pack_start (grid, false, false, 0);
+
+ label = new Label.with_mnemonic (_("_Image theme:"));
+ label.set_hexpand (true);
+ label.set_halign (Align.START);
+ grid.attach (label, 0, 0, 1, 1);
+
+ var theme_picker = new ThemePicker (themes, properties.theme);
+ theme_picker.theme_changed.connect (theme_changed);
+ label.set_mnemonic_widget (theme_picker);
+ grid.attach (theme_picker, 1, 0, 1, 1);
+
+ label = new Label.with_mnemonic (_("_Background color:"));
+ label.set_halign (Align.START);
+ grid.attach (label, 0, 1, 1, 1);
+
+ var w = new ColorButton ();
+ w.set_rgba (properties.bgcolour);
+ w.color_set.connect((color) => bg_color_changed(color));
+ label.set_mnemonic_widget (w);
+ grid.attach (w, 1, 1, 1, 1);
+
+ label = new Label.with_mnemonic (_("Appearance"));
+ notebook.append_page (gpage, label);
+
+ /* The keyboard page */
+ var kpage = new Box (Orientation.VERTICAL, 18);
+ kpage.set_border_width (12);
+
+ var vbox = new Box (Orientation.VERTICAL, 6);
+ kpage.pack_start (vbox, true, true, 0);
+
+ var controls_list = new GamesControlsList (settings);
+ controls_list.add_control ("key00", _("Key to move NW"));
+ controls_list.add_control ("key01", _("Key to move N"));
+ controls_list.add_control ("key02", _("Key to move NE"));
+ controls_list.add_control ("key03", _("Key to move W"));
+ controls_list.add_control ("key04", _("Key to hold"));
+ controls_list.add_control ("key05", _("Key to move E"));
+ controls_list.add_control ("key06", _("Key to move SW"));
+ controls_list.add_control ("key07", _("Key to move S"));
+ controls_list.add_control ("key08", _("Key to move SE"));
+
+ vbox.pack_start (controls_list, true, true, 0);
+
+ var hbox = new ButtonBox (Orientation.HORIZONTAL);
+ hbox.set_layout (ButtonBoxStyle.START);
+ vbox.pack_start (hbox, false, false, 0);
+
+ var dbut = new Button.with_mnemonic (_("_Restore Defaults"));
+ dbut.clicked.connect (reset_keys);
+ hbox.pack_start (dbut, false, false, 0);
+
+ label = new Label.with_mnemonic (_("Keyboard"));
+ notebook.append_page (kpage, label);
+ }
+
+ private void game_config_changed (string config_name) {
+ properties.selected_config = config_name;
+
+ game.config = game_configs.find_by_name (config_name);
+ game.start_new_game ();
+ game_area.queue_draw ();
+ }
+
+ private void theme_changed (Theme theme) {
+ /* FIXME: Should be de-suffixed. */
+ properties.theme = theme.name;
+
+ game_area.theme = theme;
+ game_area.queue_draw ();
+ }
+
+ private void bg_color_changed (ColorChooser color_chooser) {
+ properties.bgcolour = color_chooser.get_rgba ();
+
+ game_area.background_color = properties.bgcolour;
+ game_area.queue_draw ();
+ }
+
+ private void reset_keys () {
+ properties.reset_keys ();
+ keyboard_set (properties.keys);
+ }
+}
+
+/**
+ * show_properties_dialog
+ *
+ * Description:
+ * displays the properties dialog
+ **/
+public void show_properties_dialog (Properties properties) {
+ var themes = get_themes ();
+
+ var propbox = new PropertiesDialog (window, themes, properties);
+ propbox.show_all ();
+ propbox.run ();
+ propbox.destroy ();
+
+ keyboard_set (properties.keys);
+}
+
+public Theme get_theme_from_properties (Properties properties) throws Error {
+ var themes = get_themes ();
+ var iter = themes.find_best_match (properties.theme);
+
+ string theme_name;
+ string theme_path;
+ themes.get_values (iter, out theme_name, out theme_path);
+
+ properties.theme = theme_name;
+
+ return new Theme.from_file (theme_path, theme_name);
+}
+
diff --git a/src/properties.vala b/src/properties.vala
index 8c4fd8a..739081d 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -17,362 +17,117 @@
* For more details see the file COPYING.
*/
-using Gtk;
-using Gdk;
-
-public GameConfigs game_configs;
-
-const string KEY_BACKGROUND_COLOR = "background-color";
-const string KEY_CONFIGURATION = "configuration";
-const string KEY_ENABLE_SOUND = "enable-sound";
-const string KEY_SAFE_MOVES = "use-safe-moves";
-const string KEY_SHOW_TOOLBAR = "show-toolbar";
-const string KEY_SUPER_SAFE_MOVES = "use-super-safe-moves";
-const string KEY_THEME = "theme";
-const string KEY_CONTROL_KEY = "key%02d";
-
-const int N_KEYS = 9;
-
-struct Properties {
- bool safe_moves;
- bool super_safe_moves;
- bool sound;
- bool show_toolbar;
- Gdk.RGBA bgcolour;
- string selected_config;
- uint keys[9];
- string themename;
-}
-
-Properties properties;
-
-/**
- * handles configuration selection messages
- **/
-void type_selection (string config_name) {
- properties.selected_config = config_name;
- conf_set_configuration (config_name);
-
- game.config = game_configs.find_by_name (config_name);
- game.start_new_game ();
- game_area.queue_draw ();
-}
-
-/**
- * handles message from the default key buttons
- **/
-void defkey_cb () {
- for (int i = 0; i < N_KEYS; ++i) {
- string key = "key%02d".printf (i);
- settings.reset (key);
- properties.keys[i] = settings.get_default_value (key).get_int32 ();
+public class Properties {
+ const string KEY_BACKGROUND_COLOR = "background-color";
+ const string KEY_CONFIGURATION = "configuration";
+ const string KEY_ENABLE_SOUND = "enable-sound";
+ const string KEY_SAFE_MOVES = "use-safe-moves";
+ const string KEY_SHOW_TOOLBAR = "show-toolbar";
+ const string KEY_SUPER_SAFE_MOVES = "use-super-safe-moves";
+ const string KEY_THEME = "theme";
+ const string KEY_CONTROL_KEY = "key%02d";
+
+ const int N_KEYS = 9;
+
+ public bool safe_moves {
+ get {
+ return settings.get_boolean (KEY_SAFE_MOVES);
+ }
+ set {
+ settings.set_boolean (KEY_SAFE_MOVES, value);
+ }
}
- keyboard_set (properties.keys);
-}
-
-/**
- * fills the listbox with configuration names
- **/
-void fill_typemenu (ComboBoxText menu) {
- int active_index = 0;
- for (int i = 0; i < game_configs.count (); ++i) {
- var config = game_configs.@get ((uint)i);
-
- var config_name = config.name ();
- menu.append_text (config_name);
-
- if (config_name == properties.selected_config) {
- active_index = i;
+ public bool super_safe_moves {
+ get {
+ return settings.get_boolean (KEY_SUPER_SAFE_MOVES);
+ }
+ set {
+ settings.set_boolean (KEY_SUPER_SAFE_MOVES, value);
}
}
- menu.set_active (active_index);
-}
-
-class ThemePicker : ComboBox {
- private Themes themes;
-
- public ThemePicker (Themes themes, string current_theme) {
- Object (model: themes);
- this.themes = themes;
-
- var renderer = new CellRendererText ();
- pack_start (renderer, true);
- add_attribute (renderer, "text", 0);
-
- TreeIter? iter = themes.find_iter_by_name (current_theme);
- if (iter != null) {
- set_active_iter (iter);
- } else {
- set_active (0);
+ public bool sound {
+ get {
+ return settings.get_boolean (KEY_ENABLE_SOUND);
}
+ set {
+ settings.set_boolean (KEY_ENABLE_SOUND, value);
+ }
+ }
- changed.connect (theme_changed_cb);
+ public bool show_toolbar {
+ get {
+ return settings.get_boolean (KEY_SHOW_TOOLBAR);
+ }
+ set {
+ settings.set_boolean (KEY_SHOW_TOOLBAR, value);
+ }
}
- public signal void theme_changed (Theme theme);
+ public Gdk.RGBA bgcolour {
+ get {
+ return string_to_rgba (settings.get_string (KEY_BACKGROUND_COLOR));
+ }
+ set {
+ settings.set_string (KEY_BACKGROUND_COLOR, rgba_to_string (value));
+ }
+ }
- private void theme_changed_cb () {
- TreeIter iter;
- if (get_active_iter (out iter)) {
- string theme_name;
- string theme_path;
- themes.get_values (iter, out theme_name, out theme_path);
+ public string selected_config {
+ owned get {
+ return settings.get_string (KEY_CONFIGURATION);
+ }
+ set {
+ settings.set_string (KEY_CONFIGURATION, value);
+ }
+ }
- try {
- var theme = new Theme.from_file (theme_path, theme_name);
- theme_changed (theme);
- } catch (Error e) {
- warning ("Cannot change theme to %s (placed at %s): %s",
- theme_name,
- theme_path,
- e.message);
+ public uint[] keys {
+ get {
+ uint result[9];
+ for (int i = 0; i < N_KEYS; i++) {
+ result[i] = (uint) settings.get_int ("key%02d".printf (i));
+ }
+ return result;
+ }
+ set {
+ for (int i = 0; i < N_KEYS; i++) {
+ settings.set_int ("key%02d".printf (i), (int) value[i]);
}
}
}
-}
-
-public class PropertiesDialog : Dialog {
-
- public PropertiesDialog (Gtk.Window parent, Themes themes) {
- Object (use_header_bar: 1,
- title: _("Preferences"),
- transient_for: parent,
- modal: true,
- border_width: 5);
-
- get_content_area ().set_spacing (2);
- /* Set up notebook and add it to hbox of the gtk_dialog */
- var notebook = new Notebook ();
- notebook.border_width = 5;
- get_content_area ().pack_start (notebook, true, true, 0);
-
- /* The configuration page */
- var cpage = new Box (Orientation.VERTICAL, 18);
- cpage.border_width = 12;
-
- var grid = new Grid ();
- grid.set_row_spacing (6);
- grid.set_column_spacing (12);
- cpage.pack_start (grid, false, false, 0);
-
- var label = new Label (_("Game Type"));
- grid.attach (label, 0, 0, 1, 1);
-
- var typemenu = new ComboBoxText ();
- fill_typemenu (typemenu);
- typemenu.changed.connect (() => {
- type_selection(typemenu.get_active_text ());
- });
- grid.attach (typemenu, 1, 0, 1, 1);
-
- var safe_chkbox = new CheckButton.with_mnemonic (_("_Use safe moves"));
- safe_chkbox.set_active (properties.safe_moves);
- safe_chkbox.set_tooltip_text (_("Prevent accidental moves that result in getting killed."));
- grid.attach (safe_chkbox, 0, 1, 2, 1);
+ public string theme {
+ owned get {
+ return settings.get_string (KEY_THEME);
+ }
+ set {
+ settings.set_string (KEY_THEME, value);
+ }
+ }
- var super_safe_chkbox = new CheckButton.with_mnemonic (_("U_se super safe moves"));
- super_safe_chkbox.set_active (properties.super_safe_moves);
- super_safe_chkbox.set_tooltip_text (_("Prevents all moves that result in getting killed."));
- super_safe_chkbox.set_sensitive (properties.safe_moves);
- grid.attach (super_safe_chkbox, 0, 2, 2, 1);
+ private GLib.Settings settings;
+ private ulong notify_handler_id;
- safe_chkbox.toggled.connect ((toggle) => {
- properties.safe_moves = toggle.active;
- settings.set_boolean (KEY_SAFE_MOVES, properties.safe_moves);
- super_safe_chkbox.set_sensitive (properties.safe_moves);
- });
- super_safe_chkbox.toggled.connect ((toggle) => {
- properties.super_safe_moves = toggle.get_active ();
- settings.set_boolean (KEY_SUPER_SAFE_MOVES, properties.super_safe_moves);
- });
+ public signal void changed (Properties properties);
- var sound_chkbox = new CheckButton.with_mnemonic (_("_Enable sounds"));
- sound_chkbox.set_active (properties.sound);
- sound_chkbox.toggled.connect ((toggle) => {
- properties.sound = toggle.active;
- conf_set_enable_sound (properties.sound);
+ public Properties (GLib.Settings settings) {
+ this.settings = settings;
+ notify_handler_id = settings.changed.connect (() => {
+ changed(this);
});
- sound_chkbox.set_tooltip_text (_("Play sounds for events like winning a level and dying."));
- grid.attach (sound_chkbox, 0, 3, 2, 1);
-
- label = new Label.with_mnemonic (_("Game"));
- notebook.append_page (cpage, label);
-
- /* The graphics page */
- var gpage = new Box (Orientation.VERTICAL, 18);
- gpage.set_border_width (12);
-
- grid = new Grid ();
- grid.set_row_spacing (6);
- grid.set_column_spacing (12);
- gpage.pack_start (grid, false, false, 0);
-
- label = new Label.with_mnemonic (_("_Image theme:"));
- label.set_hexpand (true);
- label.set_halign (Align.START);
- grid.attach (label, 0, 0, 1, 1);
-
- var theme_picker = new ThemePicker (themes, properties.themename);
- theme_picker.theme_changed.connect (theme_changed);
- label.set_mnemonic_widget (theme_picker);
- grid.attach (theme_picker, 1, 0, 1, 1);
-
- label = new Label.with_mnemonic (_("_Background color:"));
- label.set_halign (Align.START);
- grid.attach (label, 0, 1, 1, 1);
-
- var w = new ColorButton ();
- w.set_rgba (properties.bgcolour);
- w.color_set.connect((color) => bg_color_changed(color));
- label.set_mnemonic_widget (w);
- grid.attach (w, 1, 1, 1, 1);
-
- label = new Label.with_mnemonic (_("Appearance"));
- notebook.append_page (gpage, label);
-
- /* The keyboard page */
- var kpage = new Box (Orientation.VERTICAL, 18);
- kpage.set_border_width (12);
-
- var vbox = new Box (Orientation.VERTICAL, 6);
- kpage.pack_start (vbox, true, true, 0);
-
- var controls_list = new GamesControlsList (settings);
- controls_list.add_control ("key00", _("Key to move NW"));
- controls_list.add_control ("key01", _("Key to move N"));
- controls_list.add_control ("key02", _("Key to move NE"));
- controls_list.add_control ("key03", _("Key to move W"));
- controls_list.add_control ("key04", _("Key to hold"));
- controls_list.add_control ("key05", _("Key to move E"));
- controls_list.add_control ("key06", _("Key to move SW"));
- controls_list.add_control ("key07", _("Key to move S"));
- controls_list.add_control ("key08", _("Key to move SE"));
-
- vbox.pack_start (controls_list, true, true, 0);
-
- var hbox = new ButtonBox (Orientation.HORIZONTAL);
- hbox.set_layout (ButtonBoxStyle.START);
- vbox.pack_start (hbox, false, false, 0);
-
- var dbut = new Button.with_mnemonic (_("_Restore Defaults"));
- dbut.clicked.connect (() => defkey_cb());
- hbox.pack_start (dbut, false, false, 0);
-
- label = new Label.with_mnemonic (_("Keyboard"));
- notebook.append_page (kpage, label);
- }
-
- private void theme_changed (Theme theme) {
- /* FIXME: Should be de-suffixed. */
- properties.themename = theme.name;
- settings.set_string (KEY_THEME, theme.name);
-
- game_area.theme = theme;
- game_area.queue_draw ();
}
- private void bg_color_changed (ColorChooser color_chooser) {
- properties.bgcolour = color_chooser.get_rgba ();
-
- var colour = rgba_to_string (properties.bgcolour);
- settings.set_string (KEY_BACKGROUND_COLOR, colour);
-
- game_area.background_color = properties.bgcolour;
- game_area.queue_draw ();
+ ~Properties () {
+ settings.disconnect (notify_handler_id);
}
-}
-
-/**
- * show_properties_dialog
- *
- * Description:
- * displays the properties dialog
- **/
-public void show_properties_dialog () {
- var themes = get_themes ();
-
- var propbox = new PropertiesDialog (window, themes);
- propbox.show_all ();
- propbox.run ();
- propbox.destroy ();
-
- keyboard_set (properties.keys);
-}
-
-public void load_properties () {
- for (int i = 0; i < N_KEYS; i++) {
- var key = "key%02d".printf (i);
- properties.keys[i] = settings.get_int (key);
+ public void reset_keys () {
+ for (int i = 0; i < N_KEYS; ++i) {
+ string key = "key%02d".printf (i);
+ settings.reset (key);
+ }
}
- properties.bgcolour = string_to_rgba (settings.get_string (KEY_BACKGROUND_COLOR));
- properties.themename = settings.get_string (KEY_THEME);
- properties.selected_config = settings.get_string (KEY_CONFIGURATION);
- properties.safe_moves = settings.get_boolean (KEY_SAFE_MOVES);
- properties.super_safe_moves = settings.get_boolean (KEY_SUPER_SAFE_MOVES);
- properties.sound = settings.get_boolean (KEY_ENABLE_SOUND);
- properties.show_toolbar = settings.get_boolean (KEY_SHOW_TOOLBAR);
-}
-
-public Theme get_theme_from_properties () throws Error {
- var themes = get_themes ();
- var iter = themes.find_best_match (properties.themename);
-
- string theme_path;
- themes.get_values (iter, out properties.themename, out theme_path);
-
- return new Theme.from_file (theme_path, properties.themename);
-}
-
-public void conf_set_configuration (string val) {
- settings.set_string (KEY_CONFIGURATION, val);
-}
-
-public void conf_set_enable_sound (bool val) {
- settings.set_boolean (KEY_ENABLE_SOUND, val);
-}
-
-/**
- * properties_safe_moves
- *
- * Description:
- * returns safe-moves setting
- *
- * Returns:
- * TRUE if safe-moves are selected
- **/
-public bool properties_safe_moves () {
- return properties.safe_moves;
-}
-
-
-/**
- * properties_super_safe_moves
- *
- * Description:
- * returns super-safe-moves setting
- *
- * Returns:
- * TRUE if safe-moves are selected
- **/
-public bool properties_super_safe_moves () {
- return properties.super_safe_moves;
-}
-
-
-/**
- * properties_sound
- *
- * Description:
- * returns sound setting
- *
- * Returns:
- * TRUE if sound is selected
- **/
-public bool properties_sound () {
- return properties.sound;
}
diff --git a/src/robots.vala b/src/robots.vala
index 0bbee8f..7caf520 100644
--- a/src/robots.vala
+++ b/src/robots.vala
@@ -247,6 +247,9 @@ void keyboard_set (uint[] keys) {
}
class RobotsApplication : Gtk.Application {
+
+ private Properties properties;
+
public RobotsApplication () {
Object (
application_id: "org.gnome.Robots",
@@ -259,6 +262,7 @@ class RobotsApplication : Gtk.Application {
Environment.set_application_name (_("Robots"));
settings = new GLib.Settings ("org.gnome.Robots");
+ properties = new Properties (settings);
Window.set_default_icon_name ("org.gnome.Robots");
@@ -287,14 +291,12 @@ class RobotsApplication : Gtk.Application {
}
protected override void activate () {
- load_properties ();
-
if (window != null) {
window.present_with_time (get_current_event_time ());
return;
}
- game_area = create_game_area ();
+ game_area = create_game_area (properties);
window = new RobotsWindow (this, game_area);
var importer = new Games.Scores.DirectoryImporter ();
@@ -336,10 +338,10 @@ class RobotsApplication : Gtk.Application {
GLib.Settings.sync ();
}
- private GameArea? create_game_area () {
+ private GameArea? create_game_area (Properties properties) {
try {
game = new Game ();
- Theme theme = get_theme_from_properties ();
+ Theme theme = get_theme_from_properties (properties);
Bubble yahoo_bubble = new Bubble.from_data_file ("yahoo.png");
Bubble aieee_bubble = new Bubble.from_data_file ("aieee.png");
Bubble splat_bubble = new Bubble.from_data_file ("splat.png");
@@ -349,7 +351,8 @@ class RobotsApplication : Gtk.Application {
aieee_bubble,
yahoo_bubble,
splat_bubble,
- sound_player);
+ sound_player,
+ properties);
} catch (Error e) {
critical ("%s", e.message);
// TODO message box
@@ -378,7 +381,7 @@ class RobotsApplication : Gtk.Application {
}
private void preferences_cb () {
- show_properties_dialog ();
+ show_properties_dialog (properties);
}
private void scores_cb () {
@@ -420,8 +423,7 @@ class RobotsApplication : Gtk.Application {
"documenters", documenters,
"translator-credits", _("translator-credits"),
"logo-icon-name", "org.gnome.Robots",
- "website",
- "https://wiki.gnome.org/Apps/Robots";);
+ "website", "https://wiki.gnome.org/Apps/Robots";);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]