Commit 3e3a186c authored by Arnaud B.'s avatar Arnaud B. Committed by Michael Catanzaro
Browse files

Use actions for new-game screen buttons.

https://bugzilla.gnome.org/show_bug.cgi?id=664976
parent 32cb5165
......@@ -87,6 +87,8 @@
<property name="valign">center</property>
<property name="width-request">120</property>
<property name="height-request">60</property>
<property name="action-name">app.change-mode</property>
<property name="action-target">'first'</property>
<property name="draw-indicator">False</property>
<style>
<class name="button"/>
......@@ -100,7 +102,7 @@
</packing>
</child>
<child>
<object class="GtkRadioButton" id="play_light">
<object class="GtkRadioButton">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="label" translatable="yes">Play _Light</property>
......@@ -108,6 +110,8 @@
<property name="valign">center</property>
<property name="width-request">120</property>
<property name="height-request">60</property>
<property name="action-name">app.change-mode</property>
<property name="action-target">'second'</property>
<property name="group">play_dark</property>
<property name="draw-indicator">False</property>
<style>
......@@ -122,7 +126,7 @@
</packing>
</child>
<child>
<object class="GtkRadioButton" id="two_players">
<object class="GtkRadioButton">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="label" translatable="yes">_Two Players</property>
......@@ -130,6 +134,8 @@
<property name="valign">center</property>
<property name="width-request">120</property>
<property name="height-request">60</property>
<property name="action-name">app.change-mode</property>
<property name="action-target">'two-players'</property>
<property name="group">play_dark</property>
<property name="draw-indicator">False</property>
<style>
......@@ -165,6 +171,8 @@
<property name="valign">center</property>
<property name="width-request">120</property>
<property name="height-request">60</property>
<property name="action-name">app.change-difficulty</property>
<property name="action-target">'1'</property>
<property name="draw-indicator">False</property>
<style>
<class name="button"/>
......@@ -178,7 +186,7 @@
</packing>
</child>
<child>
<object class="GtkRadioButton" id="medium">
<object class="GtkRadioButton">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="label" translatable="yes">_Medium</property>
......@@ -186,6 +194,8 @@
<property name="valign">center</property>
<property name="width-request">120</property>
<property name="height-request">60</property>
<property name="action-name">app.change-difficulty</property>
<property name="action-target">'2'</property>
<property name="group">easy</property>
<property name="draw-indicator">False</property>
<style>
......@@ -200,7 +210,7 @@
</packing>
</child>
<child>
<object class="GtkRadioButton" id="hard">
<object class="GtkRadioButton">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="label" translatable="yes">_Hard</property>
......@@ -208,6 +218,8 @@
<property name="valign">center</property>
<property name="width-request">120</property>
<property name="height-request">60</property>
<property name="action-name">app.change-difficulty</property>
<property name="action-target">'3'</property>
<property name="group">easy</property>
<property name="draw-indicator">False</property>
<style>
......
......@@ -40,12 +40,6 @@ public class Iagno : Gtk.Application
private Gtk.Button back_button;
private Gtk.Button undo_button;
private Gtk.RadioButton play_dark_button;
private Gtk.RadioButton play_light_button;
private Gtk.RadioButton two_players_button;
private Gtk.RadioButton easy_button;
private Gtk.RadioButton medium_button;
private Gtk.RadioButton hard_button;
private SimpleAction back_action;
......@@ -75,11 +69,18 @@ public class Iagno : Gtk.Application
private const GLib.ActionEntry app_actions[] =
{
/* http://valadoc.org/#!api=gio-2.0/GLib.SimpleActionChangeStateCallback
* TODO SimpleActionChangeStateCallback is deprecated... */
{"change-mode", change_mode_cb, "s"},
{"change-difficulty", change_difficulty_cb, "s"},
{"new-game", new_game_cb},
{"start-game", start_game_cb},
{"undo-move", undo_move_cb},
{"preferences", preferences_cb},
{"back", back_cb},
{"preferences", preferences_cb},
{"help", help_cb},
{"about", about_cb},
{"quit", quit_cb}
......@@ -186,21 +187,6 @@ public class Iagno : Gtk.Application
main_stack = builder.get_object ("main_stack") as Gtk.Stack;
back_button = builder.get_object ("back_button") as Gtk.Button;
undo_button = builder.get_object ("undo_button") as Gtk.Button;
play_dark_button = builder.get_object ("play_dark") as Gtk.RadioButton;
play_light_button = builder.get_object ("play_light") as Gtk.RadioButton;
two_players_button = builder.get_object ("two_players") as Gtk.RadioButton;
play_dark_button.toggled.connect (play_dark_button_toggled_cb);
play_light_button.toggled.connect (play_light_button_toggled_cb);
two_players_button.toggled.connect (two_players_button_toggled_cb);
easy_button = builder.get_object ("easy") as Gtk.RadioButton;
medium_button = builder.get_object ("medium") as Gtk.RadioButton;
hard_button = builder.get_object ("hard") as Gtk.RadioButton;
easy_button.toggled.connect (easy_button_toggled_cb);
medium_button.toggled.connect (medium_button_toggled_cb);
hard_button.toggled.connect (hard_button_toggled_cb);
play_dark_button.set_active (true);
easy_button.set_active (true);
back_action = (SimpleAction) lookup_action ("back");
......@@ -214,34 +200,15 @@ public class Iagno : Gtk.Application
show_new_game_screen ();
}
private void play_light_button_toggled_cb ()
{
settings.set_string ("play-as", "second");
}
private void play_dark_button_toggled_cb ()
{
settings.set_string ("play-as", "first");
}
private void two_players_button_toggled_cb ()
{
settings.set_string ("play-as", "two-players");
}
private void easy_button_toggled_cb ()
{
settings.set_int ("computer-level", 1);
}
private void medium_button_toggled_cb ()
private void change_mode_cb (SimpleAction action, Variant? variant)
{
settings.set_int ("computer-level", 2);
settings.set_string ("play-as", variant.get_string ());
}
private void hard_button_toggled_cb ()
private void change_difficulty_cb (SimpleAction action, Variant? variant)
{
settings.set_int ("computer-level", 3);
var difficulty = int.parse (variant.get_string ());
settings.set_int ("computer-level", difficulty);
}
protected override void activate ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment