[iagno] Allow playing on small screen.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Allow playing on small screen.
- Date: Sat, 3 Aug 2019 09:05:12 +0000 (UTC)
commit b5b8acfaedfe0437ac1d15baef355c33e8283487
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Jul 29 23:04:32 2019 +0200
Allow playing on small screen.
data/iagno.css | 10 +++++
data/ui/game-headerbar.ui | 13 +++---
data/ui/iagno-screens.ui | 83 ++++++++++++++++++++++++++++++++---
src/game-headerbar.vala | 21 +++++++--
src/game-view.vala | 1 -
src/game-window.vala | 6 ---
src/iagno.vala | 42 ++++++++++++++++++
src/new-game-screen.vala | 109 ++++++++++++++++++++++++++++++++++++++++++++++
src/reversi-view.vala | 2 -
9 files changed, 262 insertions(+), 25 deletions(-)
---
diff --git a/data/iagno.css b/data/iagno.css
index 1f176ea..1063069 100644
--- a/data/iagno.css
+++ b/data/iagno.css
@@ -27,10 +27,20 @@ button.unfullscreen-button {
padding:1.5rem;
}
+.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; }
/*\
* * new-game screen generics
\*/
+ .main-grid { transition:padding 0.3s; padding:1.5rem; }
+ .thin-window .main-grid { padding:1.0rem; }
+.extra-thin-window.thin-window .main-grid,
+ .flat-window .main-grid { padding:0.5rem; }
+.extra-flat-window.flat-window .main-grid { padding:0.4rem; }
+
button.start-game-button { margin-top:1.5rem; margin-bottom:0.5rem;
transition:margin-top 0 ease, margin-bottom 0 ease; }
.flat-window button.start-game-button { margin-top:0.5rem; }
diff --git a/data/ui/game-headerbar.ui b/data/ui/game-headerbar.ui
index ffb41ab..9703d21 100644
--- a/data/ui/game-headerbar.ui
+++ b/data/ui/game-headerbar.ui
@@ -36,6 +36,9 @@
<property name="can-default">True</property>
<!-- Translators: during a game, tooltip text of the Start Over button -->
<property name="tooltip-text" translatable="yes">Start a new game</property>
+ <style>
+ <class name="new-game-button"/>
+ </style>
</object>
</child>
<child>
@@ -66,13 +69,9 @@
<property name="valign">center</property>
<property name="can-focus">True</property>
<property name="focus-on-click">False</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">document-open-recent-symbolic</property> <!-- or
content-loading-symbolic -->
- <property name="icon-size">1</property>
- </object>
- </child>
+ <style>
+ <class name="history-button"/>
+ </style>
</object>
<packing>
<property name="pack-type">end</property>
diff --git a/data/ui/iagno-screens.ui b/data/ui/iagno-screens.ui
index eb3d9f5..23df838 100644
--- a/data/ui/iagno-screens.ui
+++ b/data/ui/iagno-screens.ui
@@ -25,11 +25,79 @@
<property name="homogeneous">True</property>
<property name="valign">fill</property>
<property name="spacing">18</property>
- <property name="margin-bottom">25</property><!-- TODO better -->
- <property name="height-request">263</property>
- <property name="width-request">400</property>
+ <property name="margin-bottom">22</property><!-- TODO better -->
+ <property name="margin-top">4</property>
<child>
- <object class="GtkBox">
+ <object class="GtkBox" id="infos_section">
+ <property name="orientation">vertical</property>
+ <property name="visible">True</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ <!-- Translators: when configuring a new game, on a thin window, header of the row for choosing
the number of players -->
+ <property name="label" translatable="yes">Game type</property>
+ <style>
+ <class name="bold-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="vexpand">True</property>
+ <property name="homogeneous">True</property>
+ <property name="spacing">0</property>
+ <property name="orientation">vertical</property>
+ <style>
+ <class name="linked"/>
+ </style>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <!-- Translators: when configuring a new game, on a thin window, group "Game type", label of
the button to choose to play first (with a mnemonic that appears pressing Alt) -->
+ <property name="text" translatable="yes">Play _first</property>
+ <property name="action-name">app.game-type</property>
+ <property name="action-target">'dark'</property>
+ <property name="iconic">True</property>
+ <property name="centered">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <!-- Translators: when configuring a new game, on a thin window, group "Game type", label of
the button to choose to play second (with a mnemonic that appears pressing Alt) -->
+ <property name="text" translatable="yes">Play _second</property>
+ <property name="action-name">app.game-type</property>
+ <property name="action-target">'light'</property>
+ <property name="iconic">True</property>
+ <property name="centered">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <!-- Translators: when configuring a new game, on a thin window, group "Game type", label of
the button to choose a two-players game (with a mnemonic that appears pressing Alt) -->
+ <property name="text" translatable="yes">_Two players</property>
+ <property name="action-name">app.game-type</property>
+ <property name="action-target">'two'</property>
+ <property name="iconic">True</property>
+ <property name="centered">True</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox" id="users_section">
<property name="orientation">vertical</property>
<property name="visible">True</property>
<property name="spacing">6</property>
@@ -45,8 +113,9 @@
</object>
</child>
<child>
- <object class="GtkBox">
+ <object class="GtkBox" id="users_box">
<property name="visible">True</property>
+ <property name="vexpand">True</property>
<property name="homogeneous">True</property>
<property name="spacing">12</property>
<child>
@@ -99,6 +168,7 @@
<child>
<object class="GtkBox" id="level_box">
<property name="visible">True</property>
+ <property name="vexpand">True</property>
<property name="homogeneous">True</property>
<property name="spacing">12</property>
<child>
@@ -145,7 +215,7 @@
</object>
</child>
<child>
- <object class="GtkBox">
+ <object class="GtkBox" id="color_section">
<property name="orientation">vertical</property>
<property name="visible">True</property>
<property name="spacing">6</property>
@@ -163,6 +233,7 @@
<child>
<object class="GtkBox" id="color_box">
<property name="visible">True</property>
+ <property name="vexpand">True</property>
<property name="homogeneous">True</property>
<property name="spacing">12</property>
<child>
diff --git a/src/game-headerbar.vala b/src/game-headerbar.vala
index fc4edde..90c5de0 100644
--- a/src/game-headerbar.vala
+++ b/src/game-headerbar.vala
@@ -270,10 +270,25 @@ private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
{
switch (player)
{
- case Player.LIGHT: history_button.set_label (history_button_light_label); return;
- case Player.DARK: history_button.set_label (history_button_dark_label); return;
- case Player.NONE: history_button.set_label (_("Finished!")); return;
+ case Player.LIGHT:
+ history_button.set_label (history_button_light_label); break;
+ case Player.DARK:
+ history_button.set_label (history_button_dark_label); break;
+ case Player.NONE:
+ if (is_extra_thin)
+ /* Translators: label of the game status button (in the headerbar, next to the hamburger
button), at the end of the game; this string is for when the window is really small, so keep the string as
small as possible (3~5 characters) */
+ history_button.set_label (_("End!"));
+
+ else
+ /* Translators: label of the game status button (in the headerbar, next to the hamburger
button), at the end of the game, if the window is not too thin */
+ history_button.set_label (_("Finished!")); break;
default: assert_not_reached ();
}
+
+ Widget? history_label = history_button.get_child ();
+ if ((history_label != null)
+ && (!) history_label is Label)
+ ((Label) (!) history_label).set_ellipsize (Pango.EllipsizeMode.END);
+ // else assert_not_reached ();
}
}
diff --git a/src/game-view.vala b/src/game-view.vala
index 18dbf8a..7c8ea94 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -69,7 +69,6 @@ private class GameView : BaseView, AdaptativeWidget
}
game_content = content;
- game_content.margin = 20; // FIXME
game_stack.add (content);
content.can_focus = true;
content.show ();
diff --git a/src/game-window.vala b/src/game-window.vala
index c953392..363cadf 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -40,12 +40,6 @@ private class GameWindow : BaseWindow, AdaptativeWidget
private GameView game_view;
private Box new_game_screen;
- construct
- {
- height_request = 560;
- width_request = 560;
- }
-
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)
{
GameHeaderBar _headerbar = new GameHeaderBar (name, about_action_label, flags, appearance_menu,
night_light_monitor);
diff --git a/src/iagno.vala b/src/iagno.vala
index 54dfd96..ea3f921 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -93,6 +93,7 @@ private class Iagno : Gtk.Application, BaseApplication
private const GLib.ActionEntry app_actions [] =
{
+ { "game-type", null, "s", "'dark'", change_game_type },
{ "set-use-night-mode", set_use_night_mode, "b" },
{ "quit", quit }
@@ -324,13 +325,37 @@ private class Iagno : Gtk.Application, BaseApplication
settings.bind ("highlight-turnable-tiles", view, "show-turnable-tiles", SettingsBindFlags.GET);
settings.bind ("theme", view, "theme", SettingsBindFlags.GET);
+ game_type_action = (SimpleAction) lookup_action ("game-type");
+
+ settings.changed ["color"].connect (() => {
+ if (settings.get_int ("num-players") == 2)
+ return;
+ if (settings.get_string ("color") == "dark")
+ game_type_action.set_state (new Variant.string ("dark"));
+ else
+ game_type_action.set_state (new Variant.string ("light"));
+ });
+
settings.changed ["num-players"].connect (() => {
bool solo = settings.get_int ("num-players") == 1;
new_game_screen.update_sensitivity (solo);
+ if (!solo)
+ game_type_action.set_state (new Variant.string ("two"));
+ else if (settings.get_string ("color") == "dark")
+ game_type_action.set_state (new Variant.string ("dark"));
+ else
+ game_type_action.set_state (new Variant.string ("light"));
});
bool solo = settings.get_int ("num-players") == 1;
new_game_screen.update_sensitivity (solo);
+ if (settings.get_int ("num-players") == 2)
+ game_type_action.set_state (new Variant.string ("two"));
+ else if (settings.get_string ("color") == "dark")
+ game_type_action.set_state (new Variant.string ("dark"));
+ else
+ game_type_action.set_state (new Variant.string ("light"));
+
if (start_now)
start_game ();
@@ -369,6 +394,23 @@ private class Iagno : Gtk.Application, BaseApplication
* * Internal calls
\*/
+ private SimpleAction game_type_action;
+ private void change_game_type (SimpleAction action, Variant? gvariant)
+ requires (gvariant != null)
+ {
+ string type = ((!) gvariant).get_string ();
+// game_type_action.set_state ((!) gvariant);
+ switch (type)
+ {
+ case "dark": settings.set_int ("num-players", 1); new_game_screen.update_sensitivity (true);
+ settings.set_string ("color", "dark");
return;
+ case "light": settings.set_int ("num-players", 1); new_game_screen.update_sensitivity (true);
+ settings.set_string ("color", "light");
return;
+ case "two": settings.set_int ("num-players", 2); new_game_screen.update_sensitivity
(false); return;
+ default: assert_not_reached ();
+ }
+ }
+
private void back_cb ()
requires (game_is_set)
{
diff --git a/src/new-game-screen.vala b/src/new-game-screen.vala
index f39a3ab..32f6345 100644
--- a/src/new-game-screen.vala
+++ b/src/new-game-screen.vala
@@ -25,6 +25,11 @@ using Gtk;
[GtkTemplate (ui = "/org/gnome/Reversi/ui/iagno-screens.ui")]
private class NewGameScreen : Box, AdaptativeWidget
{
+ [GtkChild] private Box infos_section;
+ [GtkChild] private Box users_section;
+ [GtkChild] private Box color_section;
+
+ [GtkChild] private Box users_box;
[GtkChild] private Box level_box;
[GtkChild] private Box color_box;
@@ -34,7 +39,111 @@ private class NewGameScreen : Box, AdaptativeWidget
color_box.sensitive = new_sensitivity;
}
+ private bool quite_thin = false;
+ private bool extra_thin = true; // extra_thin && !quite_thin is impossible, so it will not return in
next method the first time
+ private bool extra_flat = false;
private void set_window_size (AdaptativeWidget.WindowSize new_size)
{
+ bool _quite_thin = WindowSize.is_quite_thin (new_size);
+ bool _extra_thin = WindowSize.is_extra_thin (new_size);
+ bool _extra_flat = WindowSize.is_extra_flat (new_size);
+
+ if ((_quite_thin == quite_thin)
+ && (_extra_thin == extra_thin)
+ && (_extra_flat == extra_flat))
+ return;
+ quite_thin = _quite_thin;
+ extra_thin = _extra_thin;
+ extra_flat = _extra_flat;
+
+ if (extra_thin)
+ {
+ set_orientation (Orientation.VERTICAL);
+ spacing = 18;
+ homogeneous = false;
+ height_request = 360;
+ width_request = 250;
+ margin_bottom = 22;
+
+ users_section.hide ();
+ color_section.hide ();
+ infos_section.show ();
+
+ level_box.set_orientation (Orientation.VERTICAL);
+
+ users_box.set_spacing (0);
+ level_box.set_spacing (0);
+ color_box.set_spacing (0);
+
+ users_box.get_style_context ().add_class ("linked");
+ level_box.get_style_context ().add_class ("linked");
+ color_box.get_style_context ().add_class ("linked");
+ }
+ else if (extra_flat)
+ {
+ set_orientation (Orientation.HORIZONTAL);
+ homogeneous = true;
+ height_request = 113;
+ margin_bottom = 6;
+ if (quite_thin)
+ {
+ spacing = 21;
+ width_request = 420;
+ }
+ else
+ {
+ spacing = 24;
+ width_request = 450;
+ }
+
+ users_section.hide ();
+ color_section.hide ();
+ infos_section.show ();
+
+ level_box.set_orientation (Orientation.VERTICAL);
+
+ users_box.set_spacing (0);
+ level_box.set_spacing (0);
+ color_box.set_spacing (0);
+
+ users_box.get_style_context ().add_class ("linked");
+ level_box.get_style_context ().add_class ("linked");
+ color_box.get_style_context ().add_class ("linked");
+ }
+ else
+ {
+ set_orientation (Orientation.VERTICAL);
+ spacing = 18;
+ height_request = 263;
+ int boxes_spacing;
+ if (quite_thin)
+ {
+ boxes_spacing = 10;
+ width_request = 380;
+ }
+ else
+ {
+ boxes_spacing = 12;
+ width_request = 400;
+ }
+ margin_bottom = 22;
+
+ infos_section.hide ();
+ users_section.show ();
+ color_section.show ();
+
+ level_box.set_orientation (Orientation.HORIZONTAL);
+
+ users_box.get_style_context ().remove_class ("linked");
+ level_box.get_style_context ().remove_class ("linked");
+ color_box.get_style_context ().remove_class ("linked");
+
+ users_box.set_spacing (boxes_spacing);
+ level_box.set_spacing (boxes_spacing);
+ color_box.set_spacing (boxes_spacing);
+
+ homogeneous = true;
+ }
+ queue_allocate ();
}
}
diff --git a/src/reversi-view.vala b/src/reversi-view.vala
index e4cc647..0028cef 100644
--- a/src/reversi-view.vala
+++ b/src/reversi-view.vala
@@ -160,8 +160,6 @@ private class ReversiView : Gtk.DrawingArea
| Gdk.EventMask.POINTER_MOTION_MASK
| Gdk.EventMask.ENTER_NOTIFY_MASK
| Gdk.EventMask.LEAVE_NOTIFY_MASK);
- set_size_request (350, 350);
-
init_mouse ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]