[gnome-taquin] Introduce NewGameScreen.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-taquin] Introduce NewGameScreen.
- Date: Mon, 21 Jan 2019 06:12:09 +0000 (UTC)
commit 26e9252e0edf96c1651fee099d07d30bd7d08f2d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Jan 17 15:39:41 2019 +0100
Introduce NewGameScreen.
Use a template instead of loading widget.
data/taquin-screens.ui | 8 ++++----
src/meson.build | 1 +
src/new-game-screen.vala | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
src/taquin-main.vala | 36 +++++++++---------------------------
4 files changed, 62 insertions(+), 31 deletions(-)
---
diff --git a/data/taquin-screens.ui b/data/taquin-screens.ui
index 935c015..097329b 100644
--- a/data/taquin-screens.ui
+++ b/data/taquin-screens.ui
@@ -55,7 +55,7 @@
</item>
</section>
</menu>
- <object class="GtkBox" id="new-game-screen">
+ <template class="NewGameScreen" parent="GtkBox">
<property name="orientation">vertical</property>
<property name="visible">True</property>
<property name="spacing">6</property>
@@ -107,7 +107,7 @@
<property name="homogeneous">True</property>
<property name="spacing">6</property>
<child>
- <object class="GtkMenuButton" id="size-button">
+ <object class="GtkMenuButton" id="size_button">
<property name="visible">True</property>
<property name="use-underline">True</property>
<property name="menu-model">size-menu</property>
@@ -120,7 +120,7 @@
</packing>
</child>
<child>
- <object class="GtkMenuButton" id="theme-button">
+ <object class="GtkMenuButton" id="theme_button">
<property name="visible">True</property>
<property name="use-underline">True</property>
<property name="menu-model">theme-menu</property>
@@ -137,5 +137,5 @@
<property name="fill">True</property>
</packing>
</child>
- </object>
+ </template>
</interface>
diff --git a/src/meson.build b/src/meson.build
index 247839e..2fdc711 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -11,6 +11,7 @@ executable(meson.project_name(),[
'game-headerbar.vala',
'game-view.vala',
'game-window.vala',
+ 'new-game-screen.vala',
'night-light-monitor.vala',
'notifications-revealer.vala',
'overlayed-list.vala',
diff --git a/src/new-game-screen.vala b/src/new-game-screen.vala
new file mode 100644
index 0000000..11b7697
--- /dev/null
+++ b/src/new-game-screen.vala
@@ -0,0 +1,48 @@
+/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * Copyright (C) 2015-2016 Arnaud Bonatti <arnaud bonatti gmail com>
+ *
+ * This file is part of a GNOME game.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Taquin/ui/taquin-screens.ui")]
+private class NewGameScreen : Box
+{
+ [GtkChild] private MenuButton size_button;
+ [GtkChild] private MenuButton theme_button;
+
+ public void update_size_button_label (int size)
+ {
+ /* Translators: when configuring a new game, button label for the size of the game ("3 × 3", or 4,
or 5) */
+ size_button.set_label (_("Size: %d × %d ▾").printf (size, size));
+ }
+
+ public void update_theme (string theme)
+ {
+ switch (theme)
+ {
+ /* Translators: when configuring a new game, button label for the theme, if the current theme is
Cats */
+ case "cats": theme_button.set_label (_("Theme: Cats ▾")); break;
+
+ /* Translators: when configuring a new game, button label for the theme, if the current theme is
Numbers */
+ case "numbers": theme_button.set_label (_("Theme: Numbers ▾")); break;
+
+ default: warn_if_reached (); break;
+ }
+ }
+}
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index 6a9558c..1006505 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -35,9 +35,8 @@ private class Taquin : Gtk.Application, BaseApplication
/* Widgets */
private GameWindow window;
- private MenuButton size_button;
- private MenuButton theme_button;
private TaquinView view;
+ private NewGameScreen new_game_screen;
/* The game being played */
private Game? game = null;
@@ -141,8 +140,7 @@ private class Taquin : Gtk.Application, BaseApplication
/* UI parts */
view = new TaquinView ();
-
- Builder builder = new Builder.from_resource ("/org/gnome/Taquin/ui/taquin-screens.ui");
+ new_game_screen = new NewGameScreen ();
/* Window */
init_night_mode ();
@@ -153,7 +151,7 @@ private class Taquin : Gtk.Application, BaseApplication
settings.get_boolean ("window-is-maximized"),
true, // TODO add an option to go to new-game screen?
GameWindowFlags.SHOW_UNDO | GameWindowFlags.SHOW_START_BUTTON,
- (Box) builder.get_object ("new-game-screen"),
+ (Box) new_game_screen,
view,
night_light_monitor);
window.play.connect (start_game);
@@ -175,16 +173,14 @@ private class Taquin : Gtk.Application, BaseApplication
set_accels_for_action ("app.help", { "F1" });
/* New-game screen signals */
- size_button = (MenuButton) builder.get_object ("size-button");
- settings.changed["size"].connect (() => {
+ settings.changed ["size"].connect (() => {
if (!size_changed)
- update_size_button_label (settings.get_int ("size"));
+ new_game_screen.update_size_button_label (settings.get_int ("size"));
size_changed = false;
});
- update_size_button_label (settings.get_int ("size"));
+ new_game_screen.update_size_button_label (settings.get_int ("size"));
- theme_button = (MenuButton) builder.get_object ("theme-button");
- settings.changed["theme"].connect (() => {
+ settings.changed ["theme"].connect (() => {
if (!theme_changed)
update_theme (settings.get_string ("theme"));
theme_changed = false;
@@ -323,14 +319,9 @@ private class Taquin : Gtk.Application, BaseApplication
{
size_changed = true;
int size = int.parse (((!) variant).get_string ());
- update_size_button_label (size);
+ new_game_screen.update_size_button_label (size);
settings.set_int ("size", size);
}
- private void update_size_button_label (int size)
- {
- /* Translators: when configuring a new game, button label for the size of the game ("3 × 3", or 4,
or 5) */
- size_button.set_label (_("Size: %d × %d ▾").printf (size, size));
- }
private void change_theme_cb (SimpleAction action, Variant? variant)
requires (variant != null)
@@ -342,16 +333,7 @@ private class Taquin : Gtk.Application, BaseApplication
}
private void update_theme (string theme)
{
- switch (theme)
- {
- /* Translators: when configuring a new game, button label for the theme, if the current theme is
Cats */
- case "cats": theme_button.set_label (_("Theme: Cats ▾")); break;
-
- /* Translators: when configuring a new game, button label for the theme, if the current theme is
Numbers */
- case "numbers": theme_button.set_label (_("Theme: Numbers ▾")); break;
-
- default: warn_if_reached (); break;
- }
+ new_game_screen.update_theme (theme);
Dir dir;
theme_dirlist = new List<string> ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]