[gnome-2048] Add animations speed setting
- From: Juan R. Garcia Blanco <juanrgar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-2048] Add animations speed setting
- Date: Sun, 22 Feb 2015 20:11:14 +0000 (UTC)
commit ae71537b1e8f7ac0189db68c0c7a2e8390de4fc2
Author: Juan R. GarcĂa Blanco <juanrgar gmail com>
Date: Sun Feb 22 21:08:00 2015 +0100
Add animations speed setting
* data/org.gnome.2048.gschema.xml: Add "animations-speed" key.
* data/preferences.ui: Add slider to adjust animations speed.
* src/application.vala: Bind animations-speed setting with
slider in preferences window.
* src/game.vala: configure animations according to animations
speed setting.
data/org.gnome.2048.gschema.xml | 5 ++++
data/preferences.ui | 49 +++++++++++++++++++++++++++++++-------
src/application.vala | 1 +
src/game.vala | 31 +++++++++++++++---------
4 files changed, 65 insertions(+), 21 deletions(-)
---
diff --git a/data/org.gnome.2048.gschema.xml b/data/org.gnome.2048.gschema.xml
index f9dc896..df0b3a6 100644
--- a/data/org.gnome.2048.gschema.xml
+++ b/data/org.gnome.2048.gschema.xml
@@ -35,5 +35,10 @@
<summary>Congrat on target tile</summary>
<description>Whether the user shall be congratulated on obtaining target tile.</description>
</key>
+ <key name="animations-speed" type="d">
+ <default>100.0</default>
+ <summary>Animations speed</summary>
+ <description>Duration of animations: show tile, move tile, and dim tile.</description>
+ </key>
</schema>
</schemalist>
diff --git a/data/preferences.ui b/data/preferences.ui
index 1b21516..ea51853 100644
--- a/data/preferences.ui
+++ b/data/preferences.ui
@@ -2,11 +2,12 @@
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
- <object class="GtkAdjustment" id="colsadj">
- <property name="lower">1</property>
- <property name="upper">8</property>
- <property name="step_increment">1</property>
- <property name="page_increment">1</property>
+ <object class="GtkAdjustment" id="animationsspeed">
+ <property name="lower">20</property>
+ <property name="upper">200</property>
+ <property name="value">100</property>
+ <property name="step_increment">5</property>
+ <property name="page_increment">10</property>
</object>
<object class="GtkDialog" id="preferencesdialog">
<property name="can_focus">False</property>
@@ -15,7 +16,6 @@
<property name="resizable">False</property>
<property name="window_position">center-on-parent</property>
<property name="type_hint">dialog</property>
- <property name="use-header-bar">1</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
@@ -81,7 +81,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">1</property>
+ <property name="top_attach">2</property>
</packing>
</child>
<child>
@@ -92,19 +92,50 @@
</object>
<packing>
<property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Animations speed</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScale" id="animsscale">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="adjustment">animationsspeed</property>
+ <property name="inverted">True</property>
+ <property name="round_digits">1</property>
+ <property name="draw_value">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
+ <object class="GtkAdjustment" id="colsadj">
+ <property name="lower">1</property>
+ <property name="upper">8</property>
+ <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>
diff --git a/src/application.vala b/src/application.vala
index 7679cc3..e3094fd 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -279,6 +279,7 @@ public class Application : Gtk.Application
});
_settings.bind ("do-congrat", builder.get_object ("congratswitch"), "active",
GLib.SettingsBindFlags.DEFAULT);
+ _settings.bind ("animations-speed", builder.get_object ("animationsspeed"), "value",
GLib.SettingsBindFlags.DEFAULT);
}
private void _create_congrats_dialog (Gtk.Builder builder)
diff --git a/src/game.vala b/src/game.vala
index e1a938f..dfd37af 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -47,6 +47,7 @@ public class Game : GLib.Object
private GameState _state;
private Clutter.TransitionGroup _show_hide_trans;
private Clutter.TransitionGroup _move_trans;
+ private int _animations_duration;
private GLib.Settings _settings;
@@ -67,6 +68,8 @@ public class Game : GLib.Object
int cols = _settings.get_int ("cols");
_grid = new Grid (rows, cols);
+ _animations_duration = (int)_settings.get_double ("animations-speed");
+
_settings.bind ("target-value", _grid, "target_value", GLib.SettingsBindFlags.DEFAULT);
_to_move = new Gee.LinkedList<TileMovement?> ();
@@ -165,8 +168,12 @@ public class Game : GLib.Object
public bool reload_settings ()
{
- int rows = _settings.get_int ("rows");
- int cols = _settings.get_int ("cols");
+ int rows, cols;
+
+ _animations_duration = (int)_settings.get_double ("animations-speed");
+
+ rows = _settings.get_int ("rows");
+ cols = _settings.get_int ("cols");
if ((rows != _grid.rows) || (cols != _grid.cols)) {
_clear_foreground ();
@@ -331,7 +338,7 @@ public class Game : GLib.Object
_move_trans = new Clutter.TransitionGroup ();
_move_trans.stopped.connect (_on_move_trans_stopped);
- _move_trans.set_duration (100);
+ _move_trans.set_duration (_animations_duration);
_grid.move_down (_to_move, _to_hide, _to_show);
@@ -357,7 +364,7 @@ public class Game : GLib.Object
_move_trans = new Clutter.TransitionGroup ();
_move_trans.stopped.connect (_on_move_trans_stopped);
- _move_trans.set_duration (100);
+ _move_trans.set_duration (_animations_duration);
_grid.move_up (_to_move, _to_hide, _to_show);
@@ -383,7 +390,7 @@ public class Game : GLib.Object
_move_trans = new Clutter.TransitionGroup ();
_move_trans.stopped.connect (_on_move_trans_stopped);
- _move_trans.set_duration (100);
+ _move_trans.set_duration (_animations_duration);
_grid.move_left (_to_move, _to_hide, _to_show);
@@ -409,7 +416,7 @@ public class Game : GLib.Object
_move_trans = new Clutter.TransitionGroup ();
_move_trans.stopped.connect (_on_move_trans_stopped);
- _move_trans.set_duration (100);
+ _move_trans.set_duration (_animations_duration);
_grid.move_right (_to_move, _to_hide, _to_show);
@@ -443,14 +450,14 @@ public class Game : GLib.Object
trans = new Clutter.PropertyTransition ("scale-x");
trans.set_from_value (1.0);
trans.set_to_value (1.1);
- trans.set_duration (100);
+ trans.set_duration (_animations_duration);
trans.set_animatable (view.actor);
_show_hide_trans.add_transition (trans);
trans = new Clutter.PropertyTransition ("scale-y");
trans.set_from_value (1.0);
trans.set_to_value (1.1);
- trans.set_duration (100);
+ trans.set_duration (_animations_duration);
trans.set_animatable (view.actor);
_show_hide_trans.add_transition (trans);
@@ -458,7 +465,7 @@ public class Game : GLib.Object
trans.set_from_value (0);
trans.set_to_value (255);
trans.set_remove_on_complete (true);
- trans.set_duration (50);
+ trans.set_duration (_animations_duration / 2);
view.actor.add_transition ("show", trans);
}
@@ -491,7 +498,7 @@ public class Game : GLib.Object
trans = new Clutter.PropertyTransition (trans_name);
trans.set_from_value (row_move ? rect_from.actor.y : rect_from.actor.x);
trans.set_to_value (row_move ? rect_to.actor.y : rect_to.actor.x);
- trans.set_duration (100);
+ trans.set_duration (_animations_duration);
trans.set_animatable (_foreground_cur[from.row,from.col].actor);
_move_trans.add_transition (trans);
}
@@ -508,7 +515,7 @@ public class Game : GLib.Object
trans = new Clutter.PropertyTransition ("opacity");
trans.set_from_value (actor.opacity);
trans.set_to_value (0);
- trans.set_duration (100);
+ trans.set_duration (_animations_duration);
trans.set_animatable (actor);
_show_hide_trans.add_transition (trans);
@@ -633,7 +640,7 @@ public class Game : GLib.Object
{
_show_hide_trans = new Clutter.TransitionGroup ();
_show_hide_trans.stopped.connect (_on_show_hide_trans_stopped);
- _show_hide_trans.set_duration (100);
+ _show_hide_trans.set_duration (_animations_duration);
}
private bool _finish_move ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]