[gnome-taquin] Manage History button from application.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-taquin] Manage History button from application.
- Date: Sun, 8 Dec 2019 23:25:39 +0000 (UTC)
commit e6b9a320937061e10e09c304bae40ad1f89a6cb5
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Dec 7 17:22:17 2019 +0100
Manage History button from application.
data/ui/game-headerbar.ui | 9 ---------
src/game-headerbar.vala | 38 ++++++++++++++++++--------------------
src/game-window.vala | 8 ++------
src/history-button.vala | 2 +-
src/taquin-main.vala | 12 ++++++++++++
5 files changed, 33 insertions(+), 36 deletions(-)
---
diff --git a/data/ui/game-headerbar.ui b/data/ui/game-headerbar.ui
index aecd423..eff023f 100644
--- a/data/ui/game-headerbar.ui
+++ b/data/ui/game-headerbar.ui
@@ -65,14 +65,5 @@
</child>
</object>
</child>
- <child>
- <object class="HistoryButton" id="history_button">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="pack-type">end</property>
- <property name="position">5</property>
- </packing>
- </child>
</template>
</interface>
diff --git a/src/game-headerbar.vala b/src/game-headerbar.vala
index 8ab01d8..dbf1951 100644
--- a/src/game-headerbar.vala
+++ b/src/game-headerbar.vala
@@ -23,7 +23,6 @@ using Gtk;
[GtkTemplate (ui = "/org/gnome/Taquin/ui/game-headerbar.ui")]
private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
{
- [GtkChild] private HistoryButton history_button;
[GtkChild] private Button new_game_button;
[GtkChild] private Button back_button;
@@ -32,18 +31,24 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
[CCode (notify = false)] public bool has_sound { private get; protected construct; default = false; }
+ [CCode (notify = false)] public Widget? game_widget { private get; protected construct; default = null; }
+
construct
{
init_modes ();
if (window_name != "")
window_has_name = true;
+
+ if (game_widget != null)
+ pack_end ((!) game_widget);
}
internal GameHeaderBar (string _window_name,
string _about_action_label,
GameWindowFlags flags,
GLib.Menu? _appearance_menu,
+ Widget? _game_widget,
NightLightMonitor _night_light_monitor)
{
Object (about_action_label: _about_action_label,
@@ -52,6 +57,7 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
has_sound: GameWindowFlags.HAS_SOUND in flags,
has_help: GameWindowFlags.SHOW_HELP in flags, // TODO rename show_help
appearance_menu: _appearance_menu,
+ game_widget: _game_widget,
window_name: _window_name);
}
@@ -64,6 +70,9 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
{
base.set_window_size (new_size);
+// if (game_widget != null)
+// ((AdaptativeWidget) (!) game_widget).set_window_size (new_size);
+
if (!window_has_name)
return;
@@ -99,7 +108,8 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
{
current_view_is_new_game_screen = true;
- history_button.hide ();
+ if (game_widget != null)
+ ((!) game_widget).hide ();
if (!game_finished && back_button.visible)
{
@@ -116,7 +126,8 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
back_button.hide (); // TODO transition?
new_game_button.show (); // TODO transition?
- history_button.show ();
+ if (game_widget != null)
+ ((!) game_widget).show ();
if (game_finished)
{
@@ -135,7 +146,6 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
{
back_button.show ();
new_game_button.hide (); // TODO transition?
- history_button.new_game ();
}
/*\
@@ -147,11 +157,6 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
new_game_button.grab_focus ();
}
- internal void set_moves_count (ref uint moves_count)
- {
- history_button.set_moves_count (ref moves_count);
- }
-
internal void update_title (string new_title)
{
window_name = new_title;
@@ -204,24 +209,17 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
real_this.back_button.show ();
else
{
- real_this.history_button.show ();
+ if (real_this.game_widget != null)
+ ((!) real_this.game_widget).show ();
real_this.new_game_button.show ();
}
}
else
{
real_this.back_button.hide ();
- real_this.history_button.hide ();
+ if (real_this.game_widget != null)
+ ((!) real_this.game_widget).hide ();
real_this.new_game_button.hide ();
}
}
-
- /*\
- * * moves menu
- \*/
-
- internal void save_best_score (out string best_score_string)
- {
- history_button.save_best_score (out best_score_string);
- }
}
diff --git a/src/game-window.vala b/src/game-window.vala
index 8fae7ac..8db73d3 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -37,9 +37,9 @@ private class GameWindow : BaseWindow, AdaptativeWidget
private GameView game_view;
private Box new_game_screen;
- internal GameWindow (string? css_resource, string name, string about_action_label, bool start_now,
GameWindowFlags flags, Box _new_game_screen, Widget view_content, GLib.Menu? appearance_menu,
NightLightMonitor night_light_monitor)
+ internal GameWindow (string? css_resource, string name, string about_action_label, bool start_now,
GameWindowFlags flags, Box _new_game_screen, Widget view_content, GLib.Menu? appearance_menu, Widget?
game_widget, NightLightMonitor night_light_monitor)
{
- GameHeaderBar _headerbar = new GameHeaderBar (name, about_action_label, flags, appearance_menu,
night_light_monitor);
+ GameHeaderBar _headerbar = new GameHeaderBar (name, about_action_label, flags, appearance_menu,
game_widget, night_light_monitor);
GameView _game_view = new GameView (flags, _new_game_screen, view_content);
Object (nta_headerbar : (NightTimeAwareHeaderBar) _headerbar,
@@ -90,7 +90,6 @@ private class GameWindow : BaseWindow, AdaptativeWidget
internal void move_done (uint moves_count)
{
- headerbar.set_moves_count (ref moves_count);
hide_notification ();
bool undo_possible = moves_count != 0;
restart_action.set_enabled (undo_possible);
@@ -103,9 +102,6 @@ private class GameWindow : BaseWindow, AdaptativeWidget
{
game_finished = true;
headerbar.new_game_button_grab_focus ();
- string best_score_string;
- headerbar.save_best_score (out best_score_string);
- show_notification (best_score_string);
}
protected override bool escape_pressed ()
diff --git a/src/history-button.vala b/src/history-button.vala
index 7e816a0..83f4c50 100644
--- a/src/history-button.vala
+++ b/src/history-button.vala
@@ -150,7 +150,7 @@ private class HistoryButton : MenuButton
}
private uint last_moves_count = 0;
- internal void set_moves_count (ref uint moves_count)
+ internal void set_moves_count (uint moves_count)
{
update_state (/* label */ get_moves_count_string (ref moves_count),
/* sensitive */ (moves_count != 0) || (best_score != 0));
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index 2c941b1..0b28ce4 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -37,6 +37,7 @@ private class Taquin : Gtk.Application, BaseApplication
private GameWindow window;
private TaquinView view;
private NewGameScreen new_game_screen;
+ private HistoryButton history_button;
/* The game being played */
private Game? game = null;
@@ -183,6 +184,9 @@ private class Taquin : Gtk.Application, BaseApplication
size_menu,
theme_menu);
+ history_button = new HistoryButton ();
+ history_button.show ();
+
/* Window */
init_night_mode ();
window = new GameWindow ("/org/gnome/Taquin/ui/taquin.css",
@@ -196,6 +200,7 @@ private class Taquin : Gtk.Application, BaseApplication
(Box) new_game_screen,
view,
null, // appearance menu
+ history_button,
night_light_monitor);
window.play.connect (start_game);
window.back.connect (back_cb);
@@ -313,12 +318,15 @@ private class Taquin : Gtk.Application, BaseApplication
SignalHandler.disconnect_by_func ((!) game, null, window);
}
+ history_button.new_game ();
+
GameType type = (GameType) settings.get_enum ("type");
int8 size = (int8) settings.get_int ("size"); /* 2 <= size <= 9 */
game = new Game (type, size);
set_window_title ();
view.game = (!) game;
window.move_done (0);
+ history_button.set_moves_count (0);
move_done = false;
string filename = "";
@@ -379,6 +387,7 @@ private class Taquin : Gtk.Application, BaseApplication
private void move_cb (bool x_axis, int8 number, int8 x_gap, int8 y_gap, uint moves_count, bool
disable_animation)
{
window.move_done (moves_count);
+ history_button.set_moves_count (moves_count);
play_sound (Sound.SLIDING_1); // TODO sliding-n??
move_done = true;
}
@@ -387,6 +396,9 @@ private class Taquin : Gtk.Application, BaseApplication
{
window.finish_game ();
play_sound (Sound.GAME_OVER);
+ string best_score_string;
+ history_button.save_best_score (out best_score_string);
+ window.show_notification (best_score_string);
}
private bool move_done = false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]