[gnome-taquin] Introduce GameActionBar.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-taquin] Introduce GameActionBar.
- Date: Sun, 8 Dec 2019 23:25:44 +0000 (UTC)
commit e4e75bfac97389bd239529611e4bfa3044806f7b
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sun Dec 8 12:58:29 2019 +0100
Introduce GameActionBar.
data/taquin.css | 11 ++++--
data/ui/game-actionbar.ui | 39 ++++++++++++++++++++
src/game-actionbar.vala | 91 +++++++++++++++++++++++++++++++++++++++++++++++
src/game-headerbar.vala | 27 +++++++-------
src/game-window.vala | 15 ++++++--
src/meson.build | 1 +
src/taquin-main.vala | 24 ++++++++-----
src/taquin.gresource.xml | 1 +
8 files changed, 183 insertions(+), 26 deletions(-)
---
diff --git a/data/taquin.css b/data/taquin.css
index 606a60f..cc33d96 100644
--- a/data/taquin.css
+++ b/data/taquin.css
@@ -21,9 +21,6 @@ button.unfullscreen-button {
margin:6px;
}
-/* hack: fix the double spacing around the centerwidget box, on extra-thin window (visible with big moves
count) */
-.extra-thin-window.thin-window button.new-game-button { margin-right:-6px; }
-
/*\
* * board generics; TODO move in game-window.css
\*/
@@ -55,6 +52,14 @@ button.unfullscreen-button {
.extra-thin-window button.start-game-button { margin-top:1.0rem; }
+/* TODO move in game-window.css */
+label.game-name-label:dir(ltr) {
+ margin-left : 12px;
+}
+label.game-name-label:dir(rtl) {
+ margin-right: 12px;
+}
+
/*\
* * games buttons
\*/
diff --git a/data/ui/game-actionbar.ui b/data/ui/game-actionbar.ui
new file mode 100644
index 0000000..e5b640b
--- /dev/null
+++ b/data/ui/game-actionbar.ui
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ This file is part of a GNOME game
+
+ Copyright (C) 2019 – Arnaud Bonatti <arnaud bonatti gmail com>
+
+ This application is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This application is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this application. If not, see <https://www.gnu.org/licenses/>.
+-->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <template class="GameActionBar" parent="GtkRevealer">
+ <property name="visible">True</property>
+ <property name="reveal-child">True</property>
+ <child>
+ <object class="GtkActionBar" id="action_bar">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="game_label">
+ <property name="visible">True</property>
+ <style>
+ <class name="game-name-label"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/game-actionbar.vala b/src/game-actionbar.vala
new file mode 100644
index 0000000..6197a89
--- /dev/null
+++ b/src/game-actionbar.vala
@@ -0,0 +1,91 @@
+/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+
+ This file is part of a GNOME game
+
+ Copyright (C) 2019 – Arnaud Bonatti <arnaud bonatti gmail com>
+
+ This application is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This application is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this application. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Taquin/ui/game-actionbar.ui")]
+private class GameActionBar : Revealer, AdaptativeWidget
+{
+ [CCode (notify = false)] public bool show_actionbar { private get; protected construct set; default =
false; }
+ [CCode (notify = false)] public bool window_has_name { private get; protected construct set; default =
false; }
+ [CCode (notify = false)] public string window_name { private get; protected construct set; default =
"" ; }
+ [CCode (notify = false)] public Widget? game_widget { private get; protected construct ; default =
null ; }
+
+ [GtkChild] private ActionBar action_bar;
+ [GtkChild] private Label game_label;
+
+ construct
+ {
+ if (game_widget != null)
+ action_bar.pack_end ((!) game_widget);
+
+ if (window_has_name)
+ game_label.set_label (window_name);
+
+ update_visibility ();
+ }
+
+ internal GameActionBar (string _game_name, Widget? _game_widget, bool _show_actionbar)
+ {
+ Object (window_has_name : _game_name != "",
+ window_name : _game_name,
+ game_widget : _game_widget,
+ show_actionbar : _show_actionbar);
+ }
+
+ /*\
+ * * adaptative stuff
+ \*/
+
+ private bool is_extra_thin = true;
+ protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
+ {
+// if (game_widget != null)
+// ((AdaptativeWidget) (!) game_widget).set_window_size (new_size);
+
+ bool _is_extra_thin = AdaptativeWidget.WindowSize.is_extra_thin (new_size);
+ if (_is_extra_thin == is_extra_thin)
+ return;
+ is_extra_thin = _is_extra_thin;
+ update_visibility ();
+ }
+
+ private void update_visibility ()
+ {
+ set_reveal_child (is_extra_thin && show_actionbar);
+ }
+
+ /*\
+ * * some internal calls
+ \*/
+
+ internal void update_title (string new_title)
+ {
+ window_name = new_title;
+ window_has_name = new_title != "";
+ game_label.set_label (window_name);
+ }
+
+ internal void set_visibility (bool new_visibility)
+ {
+ show_actionbar = new_visibility;
+ update_visibility ();
+ }
+}
diff --git a/src/game-headerbar.vala b/src/game-headerbar.vala
index dbf1951..94fb7de 100644
--- a/src/game-headerbar.vala
+++ b/src/game-headerbar.vala
@@ -26,7 +26,7 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
[GtkChild] private Button new_game_button;
[GtkChild] private Button back_button;
- [CCode (notify = false)] public bool window_has_name { private get; protected construct ; default =
false; }
+ [CCode (notify = false)] public bool window_has_name { private get; protected construct set; default =
false; }
[CCode (notify = false)] public string window_name { private get; protected construct set; default =
""; }
[CCode (notify = false)] public bool has_sound { private get; protected construct; default = false; }
@@ -96,6 +96,13 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
/* show info_button */ true,
/* show ltr_right_separator */ _this.disable_action_bar,
/* show quit_button_stack */ _this.disable_action_bar);
+ update_game_widget_visibility ();
+ }
+
+ private void update_game_widget_visibility ()
+ {
+ if (game_widget != null)
+ ((!) game_widget).set_visible (!is_extra_thin && !current_view_is_new_game_screen);
}
/*\
@@ -108,8 +115,7 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
{
current_view_is_new_game_screen = true;
- if (game_widget != null)
- ((!) game_widget).hide ();
+ update_game_widget_visibility ();
if (!game_finished && back_button.visible)
{
@@ -126,8 +132,7 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
back_button.hide (); // TODO transition?
new_game_button.show (); // TODO transition?
- if (game_widget != null)
- ((!) game_widget).show ();
+ update_game_widget_visibility ();
if (game_finished)
{
@@ -160,6 +165,7 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
internal void update_title (string new_title)
{
window_name = new_title;
+ window_has_name = new_title != "";
set_default_widgets_default_states (this);
}
@@ -178,14 +184,13 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
GLib.Menu section = new GLib.Menu ();
// if (appearance_menu != null)
- /* Translators: hamburger menu entry; "Appearance" submenu (with a mnemonic that appears
pressing Alt) */
+ // /* Translators: hamburger menu entry; "Appearance" submenu (with a mnemonic that appears
pressing Alt) */
// section.append_submenu (_("A_ppearance"), (!) appearance_menu);
+
if (has_sound)
- {
/* Translators: hamburger menu entry; sound togglebutton (with a mnemonic that appears pressing
Alt) */
section.append (_("_Sound"), "app.sound");
- }
section.freeze ();
menu.append_section (null, section);
@@ -209,16 +214,14 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
real_this.back_button.show ();
else
{
- if (real_this.game_widget != null)
- ((!) real_this.game_widget).show ();
+ real_this.update_game_widget_visibility ();
real_this.new_game_button.show ();
}
}
else
{
real_this.back_button.hide ();
- if (real_this.game_widget != null)
- ((!) real_this.game_widget).hide ();
+ real_this.update_game_widget_visibility ();
real_this.new_game_button.hide ();
}
}
diff --git a/src/game-window.vala b/src/game-window.vala
index 8db73d3..e1428c4 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -2,7 +2,7 @@
This file is part of a GNOME game
- Copyright (C) 2015-2016 – Arnaud Bonatti <arnaud bonatti gmail com>
+ Copyright (C) 2015-2019 – Arnaud Bonatti <arnaud bonatti gmail com>
This application is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,12 +35,14 @@ private class GameWindow : BaseWindow, AdaptativeWidget
/* private widgets */
private GameHeaderBar headerbar;
private GameView game_view;
+ private GameActionBar actionbar;
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, Widget?
game_widget, 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_1, Widget? game_widget_2, NightLightMonitor night_light_monitor)
{
- GameHeaderBar _headerbar = new GameHeaderBar (name, about_action_label, flags, appearance_menu,
game_widget, night_light_monitor);
+ GameHeaderBar _headerbar = new GameHeaderBar (name, about_action_label, flags, appearance_menu,
game_widget_1, night_light_monitor);
GameView _game_view = new GameView (flags, _new_game_screen, view_content);
+ GameActionBar _actionbar = new GameActionBar (name, game_widget_2, /* show actionbar */ start_now);
Object (nta_headerbar : (NightTimeAwareHeaderBar) _headerbar,
base_view : (BaseView) _game_view,
@@ -51,8 +53,11 @@ private class GameWindow : BaseWindow, AdaptativeWidget
headerbar = _headerbar;
game_view = _game_view;
+ actionbar = _actionbar;
new_game_screen = _new_game_screen;
+ add_to_main_grid (actionbar);
+
/* CSS */
if (css_resource != null)
{
@@ -82,6 +87,7 @@ private class GameWindow : BaseWindow, AdaptativeWidget
((AdaptativeWidget) new_game_screen).set_window_size (new_size);
((AdaptativeWidget) game_view).set_window_size (new_size);
+ ((AdaptativeWidget) actionbar).set_window_size (new_size);
}
/*\
@@ -128,6 +134,8 @@ private class GameWindow : BaseWindow, AdaptativeWidget
internal void update_title (string game_name)
{
headerbar.update_title (game_name);
+ actionbar.update_title (game_name);
+ actionbar.set_visibility (true);
}
/*\
@@ -138,6 +146,7 @@ private class GameWindow : BaseWindow, AdaptativeWidget
{
hide_notification ();
headerbar.update_title (Taquin.PROGRAM_NAME);
+ actionbar.set_visibility (false);
bool grabs_focus = headerbar.show_new_game_screen (game_finished);
game_view.show_new_game_box (/* grab focus */ !grabs_focus);
}
diff --git a/src/meson.build b/src/meson.build
index 2811963..c9368d3 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -20,6 +20,7 @@ executable(meson.project_name(),[
'base-headerbar.vala',
'base-view.vala',
'base-window.vala',
+ 'game-actionbar.vala',
'game-headerbar.vala',
'game-view.vala',
'game-window.vala',
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index 0b28ce4..4d343fb 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -37,7 +37,8 @@ private class Taquin : Gtk.Application, BaseApplication
private GameWindow window;
private TaquinView view;
private NewGameScreen new_game_screen;
- private HistoryButton history_button;
+ private HistoryButton history_button_1;
+ private HistoryButton history_button_2;
/* The game being played */
private Game? game = null;
@@ -184,8 +185,10 @@ private class Taquin : Gtk.Application, BaseApplication
size_menu,
theme_menu);
- history_button = new HistoryButton ();
- history_button.show ();
+ history_button_1 = new HistoryButton ();
+ history_button_2 = new HistoryButton ();
+ history_button_1.show ();
+ history_button_2.show ();
/* Window */
init_night_mode ();
@@ -200,7 +203,8 @@ private class Taquin : Gtk.Application, BaseApplication
(Box) new_game_screen,
view,
null, // appearance menu
- history_button,
+ history_button_1,
+ history_button_2,
night_light_monitor);
window.play.connect (start_game);
window.back.connect (back_cb);
@@ -318,7 +322,8 @@ private class Taquin : Gtk.Application, BaseApplication
SignalHandler.disconnect_by_func ((!) game, null, window);
}
- history_button.new_game ();
+ history_button_1.new_game ();
+ history_button_2.new_game ();
GameType type = (GameType) settings.get_enum ("type");
int8 size = (int8) settings.get_int ("size"); /* 2 <= size <= 9 */
@@ -326,7 +331,8 @@ private class Taquin : Gtk.Application, BaseApplication
set_window_title ();
view.game = (!) game;
window.move_done (0);
- history_button.set_moves_count (0);
+ history_button_1.set_moves_count (0);
+ history_button_2.set_moves_count (0);
move_done = false;
string filename = "";
@@ -387,7 +393,8 @@ 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);
+ history_button_1.set_moves_count (moves_count);
+ history_button_2.set_moves_count (moves_count);
play_sound (Sound.SLIDING_1); // TODO sliding-n??
move_done = true;
}
@@ -397,7 +404,8 @@ 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);
+ history_button_1.save_best_score (out best_score_string);
+ history_button_2.save_best_score (out best_score_string);
window.show_notification (best_score_string);
}
diff --git a/src/taquin.gresource.xml b/src/taquin.gresource.xml
index 16ab120..26d019b 100644
--- a/src/taquin.gresource.xml
+++ b/src/taquin.gresource.xml
@@ -10,6 +10,7 @@
<file preprocess="xml-stripblanks" alias="base-view.ui">../data/ui/base-view.ui</file>
<file alias="base-window.css">../data/base-window.css</file>
<file preprocess="xml-stripblanks" alias="base-window.ui">../data/ui/base-window.ui</file>
+ <file preprocess="xml-stripblanks" compressed="true"
alias="game-actionbar.ui">../data/ui/game-actionbar.ui</file>
<file preprocess="xml-stripblanks" alias="game-headerbar.ui">../data/ui/game-headerbar.ui</file>
<file preprocess="xml-stripblanks" alias="history-button.ui">../data/ui/history-button.ui</file>
<file alias="new-game-screen.css">../data/new-game-screen.css</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]