[iagno] Introduce GameActionBar.



commit ce076776a9b4363f33479ce5d0dd07bcadc0ad20
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Dec 6 17:12:56 2019 +0100

    Introduce GameActionBar.

 data/iagno.css            | 12 ++++---
 data/iagno.gresource.xml  |  1 +
 data/ui/game-actionbar.ui | 39 ++++++++++++++++++++
 src/game-actionbar.vala   | 91 +++++++++++++++++++++++++++++++++++++++++++++++
 src/game-headerbar.vala   | 22 +++++++-----
 src/game-window.vala      | 13 +++++--
 src/iagno.vala            | 24 ++++++++-----
 src/meson.build           |  1 +
 8 files changed, 180 insertions(+), 23 deletions(-)
---
diff --git a/data/iagno.css b/data/iagno.css
index f5092f8..e4abbfb 100644
--- a/data/iagno.css
+++ b/data/iagno.css
@@ -23,10 +23,6 @@ button.unfullscreen-button {
   margin:6px;
 }
 
-.extra-thin-window.thin-window button.history-button  { padding-left:12px; padding-right:12px; transition: 
padding 0 ease; }
-.extra-thin-window.thin-window button.new-game-button { padding-left:12px; padding-right:12px; transition: 
padding 0 ease;
-/* hack: fix the double spacing around the centerwidget box, on extra-thin window */
-                                                        margin-right:-12px; }
 /*\
 * * board generics; TODO move in game-window.css
 \*/
@@ -78,6 +74,14 @@ popover modelbutton {
              margin    0.3s ease;
 }
 
+/* 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/iagno.gresource.xml b/data/iagno.gresource.xml
index 50f66b1..e40753c 100644
--- a/data/iagno.gresource.xml
+++ b/data/iagno.gresource.xml
@@ -10,6 +10,7 @@
     <file preprocess="xml-stripblanks" compressed="true" alias="base-view.ui"               
ui/base-view.ui</file>
     <file compressed="true">base-window.css</file>
     <file preprocess="xml-stripblanks" compressed="true" alias="base-window.ui"             
ui/base-window.ui</file>
+    <file preprocess="xml-stripblanks" compressed="true" alias="game-actionbar.ui"          
ui/game-actionbar.ui</file>
     <file preprocess="xml-stripblanks" compressed="true" alias="game-headerbar.ui"          
ui/game-headerbar.ui</file>
     <file preprocess="xml-stripblanks" compressed="true" alias="history-button.ui"          
ui/history-button.ui</file>
     <file compressed="true">iagno.css</file>
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..314ab40
--- /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/Reversi/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 d1735f3..84b2f9a 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; }
@@ -102,6 +102,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);
     }
 
     /*\
@@ -115,8 +122,7 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
         current_view_is_new_game_screen = true;
 
      // new_game_button.hide ();
-        if (game_widget != null)
-            ((!) game_widget).hide ();
+        update_game_widget_visibility ();
 
         if (!game_finished && back_button.visible)
         {
@@ -133,8 +139,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)
         {
@@ -178,6 +183,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);
     }
 
@@ -228,16 +234,14 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
             }
             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 a16d416..06fc3a5 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -38,12 +38,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,
@@ -54,8 +56,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)
         {
@@ -85,6 +90,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);
     }
 
     /*\
@@ -126,6 +132,7 @@ private class GameWindow : BaseWindow, AdaptativeWidget
     {
         hide_notification ();
         headerbar.update_title (Iagno.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);
     }
@@ -260,6 +267,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);
     }
 
     /*\
diff --git a/src/iagno.vala b/src/iagno.vala
index 80a767f..5e11694 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -51,7 +51,8 @@ private class Iagno : Gtk.Application, BaseApplication
     private GameWindow window;
     private ReversiView view;
     private NewGameScreen new_game_screen;
-    private HistoryButton history_button;
+    private HistoryButton history_button_1;
+    private HistoryButton history_button_2;
 
     /* Computer player (if there is one) */
     internal ComputerPlayer? computer { internal get; private set; default = null; }
@@ -389,9 +390,12 @@ private class Iagno : Gtk.Application, BaseApplication
         appearance_menu.append_section (null, section);
         appearance_menu.freeze ();
 
-        history_button = new HistoryButton ();
-        view.notify_final_animation.connect ((undoing) => { history_button.update_menu (!undoing); });
-        history_button.show ();
+        history_button_1 = new HistoryButton ();
+        history_button_2 = new HistoryButton ();
+        view.notify_final_animation.connect ((undoing) => { history_button_1.update_menu (!undoing);
+                                                            history_button_2.update_menu (!undoing); });
+        history_button_1.show ();
+        history_button_2.show ();
 
         /* Window */
         init_night_mode ();
@@ -408,7 +412,8 @@ private class Iagno : Gtk.Application, BaseApplication
                                  (Box) new_game_screen,
                                  view,
                                  appearance_menu,
-                                 history_button,
+                                 history_button_1,
+                                 history_button_2,
                                  night_light_monitor);
 
         window.play.connect (start_game);
@@ -680,7 +685,8 @@ private class Iagno : Gtk.Application, BaseApplication
         game.turn_ended.connect (turn_ended_cb);
         view.game = game;
 
-        history_button.new_game ();
+        history_button_1.new_game ();
+        history_button_2.new_game ();
 
         if (two_players)
             computer = null;
@@ -824,7 +830,8 @@ private class Iagno : Gtk.Application, BaseApplication
         requires (game_is_set)
     {
         window.finish_game ();
-        history_button.update_label (Player.NONE);
+        history_button_1.update_label (Player.NONE);
+        history_button_2.update_label (Player.NONE);
 
         if ((!game.reverse && game.n_light_tiles > game.n_dark_tiles)
          || ( game.reverse && game.n_light_tiles < game.n_dark_tiles))
@@ -881,7 +888,8 @@ private class Iagno : Gtk.Application, BaseApplication
     {
         /* for the move that just ended */
         play_sound (Sound.FLIP);
-        history_button.update_label (game.current_color);
+        history_button_1.update_label (game.current_color);
+        history_button_2.update_label (game.current_color);
     }
 
     private void set_window_title ()
diff --git a/src/meson.build b/src/meson.build
index 4732e2d..3ab390b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -73,6 +73,7 @@ executable(meson.project_name(),
         'base-window.vala',
         'computer-player.vala',
         'computer-reversi.vala',
+        'game-actionbar.vala',
         'game-headerbar.vala',
         'game-view.vala',
         'game-window.vala',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]