[iagno] Highlight playable tiles.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Highlight playable tiles.
- Date: Mon, 9 Dec 2019 17:27:58 +0000 (UTC)
commit a5e02dcdc5c274f5296fcd9ffb5cc66681a764f0
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Dec 9 17:29:17 2019 +0100
Highlight playable tiles.
data/org.gnome.Reversi.gschema.xml | 7 +++++++
src/iagno.vala | 8 +++++++-
src/reversi-view.vala | 41 +++++++++++++++++++++++++++++++++-----
3 files changed, 50 insertions(+), 6 deletions(-)
---
diff --git a/data/org.gnome.Reversi.gschema.xml b/data/org.gnome.Reversi.gschema.xml
index aad02ce..d7b39d8 100644
--- a/data/org.gnome.Reversi.gschema.xml
+++ b/data/org.gnome.Reversi.gschema.xml
@@ -66,6 +66,13 @@
<!-- Translators: description of a settings key, see 'dconf-editor /org/gnome/iagno/computer-level' -->
<description>From 1, the easiest, to 3, the hardest.</description>
</key>
+ <key name="highlight-playable-tiles" type="b">
+ <default>false</default>
+ <!-- Translators: summary of a settings key, see 'dconf-editor
/org/gnome/iagno/highlight-playable-tiles' -->
+ <summary>A flag to highlight playable tiles</summary>
+ <!-- Translators: description of a settings key, see 'dconf-editor
/org/gnome/iagno/highlight-playable-tiles' -->
+ <description>If “true”, the tiles where you can play are highlighted.</description>
+ </key>
<key name="highlight-turnable-tiles" type="b">
<default>false</default>
<!-- Translators: summary of a settings key, see 'dconf-editor
/org/gnome/iagno/highlight-turnable-tiles'; these are not the playable tiles, but the one that could be
captured by a play -->
diff --git a/src/iagno.vala b/src/iagno.vala
index d7decd3..bee15c7 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -384,11 +384,15 @@ private class Iagno : Gtk.Application, BaseApplication
appearance_menu.append_section (null, section);
section = new GLib.Menu ();
+ /* Translators: hamburger menu "Appearance" submenu entry, in the "Highlight" section;
highlight-playable-tiles togglebutton (with a mnemonic that appears pressing Alt) */
+ section.append (_("Pla_yable tiles"), "app.highlight-playable-tiles");
+
+
/* Translators: hamburger menu "Appearance" submenu entry, in the "Highlight" section;
highlight-capturable-tiles togglebutton (with a mnemonic that appears pressing Alt); these are not the
playable tiles, but the one that could be captured by a play */
section.append (_("_Capturable tiles"), "app.highlight-turnable-tiles");
section.freeze ();
- /* Translators: hamburger menu "Appearance" submenu section header; the section will list several
game helpers that are done by highlighting tiles on the board; currently, there is only one helper,
"Capturable tiles"; "Highlights" is probably better understood as a noun than as a verb here */
+ /* Translators: hamburger menu "Appearance" submenu section header; the section lists several game
helpers that are done by highlighting tiles on the board: "Capturable tiles" and "Playable tiles";
"Highlights" is probably better understood as a noun than as a verb here */
appearance_menu.append_section (_("Highlights"), section);
appearance_menu.freeze ();
@@ -436,6 +440,7 @@ private class Iagno : Gtk.Application, BaseApplication
set_accels_for_action ("base.toggle-hamburger", { "F10" });
// set_accels_for_action ("app.help", { "F1" });
// set_accels_for_action ("base.about", { "<Shift>F1" });
+ add_action (settings.create_action ("highlight-playable-tiles"));
add_action (settings.create_action ("highlight-turnable-tiles"));
if (!alternative_start && !random_start && !usual_start)
add_action (settings.create_action ("random-start-position"));
@@ -443,6 +448,7 @@ private class Iagno : Gtk.Application, BaseApplication
add_action (settings.create_action ("theme"));
add_action (settings.create_action ("type")); // TODO window action?
+ settings.bind ("highlight-playable-tiles", view, "show-playable-tiles", SettingsBindFlags.GET);
settings.bind ("highlight-turnable-tiles", view, "show-turnable-tiles", SettingsBindFlags.GET);
settings.bind ("theme", view, "theme", SettingsBindFlags.GET);
diff --git a/src/reversi-view.vala b/src/reversi-view.vala
index 7cb5937..a302c2c 100644
--- a/src/reversi-view.vala
+++ b/src/reversi-view.vala
@@ -22,6 +22,12 @@
private class ReversiView : Gtk.DrawingArea
{
+ private bool _show_playable_tiles = false;
+ [CCode (notify = false)] internal bool show_playable_tiles
+ {
+ private get { return _show_playable_tiles; }
+ internal set { _show_playable_tiles = value; if (game_is_set) highlight_playable_tiles (); }
+ }
[CCode (notify = false)] internal bool show_turnable_tiles { private get; internal set; default = false;
}
/* Theme */
@@ -193,6 +199,9 @@ private class ReversiView : Gtk.DrawingArea
humans_opening_intensity = 0;
queue_draw ();
+
+ if (show_playable_tiles)
+ highlight_playable_tiles ();
}
}
@@ -633,7 +642,7 @@ private class ReversiView : Gtk.DrawingArea
private inline void add_highlights (Cairo.Context cr)
{
- if (playable_tiles_highlight_state == 0)
+ if (!show_playable_tiles && playable_tiles_highlight_state == 0)
return;
if (iagno_instance.computer != null && iagno_instance.player_one != game.current_color)
{
@@ -641,6 +650,15 @@ private class ReversiView : Gtk.DrawingArea
return;
}
+ if (show_playable_tiles && show_turnable_tiles)
+ {
+ unowned PossibleMove move;
+ if (show_mouse_highlight && game.test_placing_tile (mouse_highlight_x, mouse_highlight_y, out
move))
+ return;
+ if (show_highlight && game.test_placing_tile (highlight_x, highlight_y, out move))
+ return;
+ }
+
bool decreasing = playable_tiles_highlight_state > HIGHLIGHT_MAX;
uint8 intensity;
if (decreasing)
@@ -654,7 +672,9 @@ private class ReversiView : Gtk.DrawingArea
if (decreasing && intensity == 1)
init_possible_moves ();
- else
+ else if (!show_playable_tiles)
+ playable_tiles_highlight_state++;
+ else if (playable_tiles_highlight_state < HIGHLIGHT_MAX)
playable_tiles_highlight_state++;
}
private inline void add_highlight (Cairo.Context cr, uint8 x, uint8 y, uint8 intensity)
@@ -941,6 +961,13 @@ private class ReversiView : Gtk.DrawingArea
show_highlight = true;
else if (!show_highlight)
show_mouse_highlight = true;
+
+ // reload playable tiles
+ if (show_playable_tiles)
+ {
+ init_possible_moves (); // clears previous highlights
+ highlight_playable_tiles (/* force reload */ true);
+ }
}
private void get_missing_tile (out uint8 x, out uint8 y)
{
@@ -1010,8 +1037,11 @@ private class ReversiView : Gtk.DrawingArea
if (!no_draw)
{
update_squares ();
+ playable_tiles_highlight_state = 0;
if (undoing)
update_highlight_after_undo ();
+ else if (show_playable_tiles)
+ highlight_playable_tiles ();
}
last_state = game.current_state;
@@ -1176,6 +1206,7 @@ private class ReversiView : Gtk.DrawingArea
notify_final_animation (/* undoing */ true);
flip_final_result_now = false;
update_squares ();
+ highlight_playable_tiles ();
return true;
}
@@ -1268,7 +1299,7 @@ private class ReversiView : Gtk.DrawingArea
Source.remove (timeout_id);
timeout_id = 0;
}
- timeout_id = Timeout.add (200, () => {
+ timeout_id = Timeout.add (show_playable_tiles ? 50 : 200, () => {
if (mouse_is_in)
_on_motion (x, y, /* force redraw */ false);
timeout_id = 0;
@@ -1708,9 +1739,9 @@ private class ReversiView : Gtk.DrawingArea
move (x, y);
}
- private inline void highlight_playable_tiles ()
+ private inline void highlight_playable_tiles (bool force_reload = false)
{
- if (playable_tiles_highlight_state != 0)
+ if (!force_reload && playable_tiles_highlight_state != 0)
return;
SList<PossibleMove?> moves;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]