[four-in-a-row: 53/72] made Prefs make more sense
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row: 53/72] made Prefs make more sense
- Date: Sun, 16 Dec 2018 21:01:14 +0000 (UTC)
commit acab857b8361164f91df5ab6e487ef7c799f5204
Author: Jacob Humphrey <jacob ryan humphrey gmail com>
Date: Sat Dec 15 03:32:16 2018 -0600
made Prefs make more sense
src/four-in-a-row.vala | 14 +++++++-------
src/main.vala | 2 +-
src/prefs.vala | 31 ++++++++++++++++---------------
3 files changed, 24 insertions(+), 23 deletions(-)
---
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index 62872ae..3abba0b 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -747,7 +747,7 @@ class FourInARow : Gtk.Application {
frame.add(GameBoardView.instance);
GameBoardView.instance.column_clicked.connect(column_clicked_cb);
- GameBoardView.instance.key_press_event.connect(on_key_press);
+ window.key_press_event.connect(on_key_press);
hint_action.set_enabled(false);
undo_action.set_enabled(false);
@@ -757,9 +757,9 @@ class FourInARow : Gtk.Application {
bool on_key_press(Gdk.EventKey e) {
if ((player_active) || timeout != 0 ||
- (e.keyval != Prefs.instance.keypress[Move.LEFT] &&
- e.keyval != Prefs.instance.keypress[Move.RIGHT] &&
- e.keyval != Prefs.instance.keypress[Move.DROP])) {
+ (e.keyval != Prefs.instance.keypress_left &&
+ e.keyval != Prefs.instance.keypress_right &&
+ e.keyval != Prefs.instance.keypress_drop)) {
return false;
}
@@ -768,13 +768,13 @@ class FourInARow : Gtk.Application {
return true;
}
- if (e.keyval == Prefs.instance.keypress[Move.LEFT] && column != 0) {
+ if (e.keyval == Prefs.instance.keypress_left && column != 0) {
column_moveto--;
move_cursor(column_moveto);
- } else if (e.keyval == Prefs.instance.keypress[Move.RIGHT] && column < 6) {
+ } else if (e.keyval == Prefs.instance.keypress_right && column < 6) {
column_moveto++;
move_cursor(column_moveto);
- } else if (e.keyval == Prefs.instance.keypress[Move.DROP]) {
+ } else if (e.keyval == Prefs.instance.keypress_drop) {
game_process_move(column);
}
return true;
diff --git a/src/main.vala b/src/main.vala
index 7846fbb..ce796ce 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -60,7 +60,7 @@ public enum Tile {
public enum Move {
LEFT,
RIGHT,
- DROP
+ //DROP
}
public enum SoundID {
diff --git a/src/prefs.vala b/src/prefs.vala
index 0bb128f..c390324 100644
--- a/src/prefs.vala
+++ b/src/prefs.vala
@@ -21,16 +21,19 @@
class Prefs : Object {
public bool do_sound{ get; set;}
+ int _theme_id;
public int theme_id {
get{
- return settings.get_int("theme-id");
+ return sane_theme_id(_theme_id);
}
set{
- settings.set_int("theme-id", value);
+ _theme_id = sane_theme_id(value);
}
}
public Level level[2];
- public int keypress[3];
+ public int keypress_drop { get; set; }
+ public int keypress_right { get; set; }
+ public int keypress_left { get; set; }
public Settings settings;
static Once<Prefs> _instance;
@@ -44,20 +47,24 @@ class Prefs : Object {
settings = new GLib.Settings("org.gnome.four-in-a-row");
level[PlayerID.PLAYER1] = Level.HUMAN; /* Human. Always human. */
level[PlayerID.PLAYER2] = (Level) settings.get_int("opponent");
- keypress[Move.LEFT] = settings.get_int("key-left");
- keypress[Move.RIGHT] = settings.get_int("key-right");
- keypress[Move.DROP] = settings.get_int("key-drop");
theme_id = settings.get_int("theme-id");
settings.changed.connect(settings_changed_cb);
settings.bind("sound", this, "do_sound", SettingsBindFlags.DEFAULT);
+ settings.bind("theme-id", this, "theme-id", SettingsBindFlags.DEFAULT);
+ settings.bind("key-drop", this, "keypress_drop", SettingsBindFlags.DEFAULT);
+ settings.bind("key-right", this, "keypress_right", SettingsBindFlags.DEFAULT);
+ settings.bind("key-left", this, "keypress_left", SettingsBindFlags.DEFAULT);
level[PlayerID.PLAYER1] = sane_player_level(level[PlayerID.PLAYER1]);
level[PlayerID.PLAYER2] = sane_player_level(level[PlayerID.PLAYER2]);
theme_id = sane_theme_id(theme_id);
+ notify["theme_id"].connect(() =>{
+ GameBoardView.instance.change_theme();
+ });
}
- int sane_theme_id(int val) {
+ static int sane_theme_id(int val) {
if (val < 0 || val >= theme.length)
return DEFAULT_THEME_ID;
return val;
@@ -73,16 +80,10 @@ class Prefs : Object {
public signal void theme_changed(int theme_id);
public void settings_changed_cb(string key) {
- if (key == "key-left") {
- keypress[Move.LEFT] = settings.get_int("key-left");
- } else if (key == "key-right") {
- keypress[Move.RIGHT] = settings.get_int("key-right");
- } else if (key == "key-drop") {
- keypress[Move.DROP] = settings.get_int("key-drop");
- } else if (key == "theme-id") {
+ if (key == "theme-id") {
int val = sane_theme_id(settings.get_int("theme-id"));
if (val != theme_id) {
- theme_id = val;
+ theme_id = val;
if (!GameBoardView.instance.change_theme())
return;
theme_changed(theme_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]