[iagno] Implement new design for new game screen
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Implement new design for new game screen
- Date: Mon, 9 Feb 2015 19:12:37 +0000 (UTC)
commit e2c4acc290006703d4678681e35ddeb1e99a9e0c
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Feb 8 14:54:06 2015 -0600
Implement new design for new game screen
https://bugzilla.gnome.org/show_bug.cgi?id=664976
data/iagno.ui | 159 ++++++++++++++++++++++++--------------
data/org.gnome.iagno.gschema.xml | 24 ++++---
src/iagno.vala | 86 +++++++++++++++------
3 files changed, 177 insertions(+), 92 deletions(-)
---
diff --git a/data/iagno.ui b/data/iagno.ui
index 44e6416..075c10f 100644
--- a/data/iagno.ui
+++ b/data/iagno.ui
@@ -70,47 +70,27 @@
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
- <object class="GtkLabel">
+ <object class="GtkLabel" id="players-label">
<property name="visible">True</property>
- <property name="label" translatable="yes">Game Mode</property>
<property name="valign">center</property>
<property name="halign">start</property>
</object>
</child>
<child>
- <object class="GtkBox" id="game-mode-box">
+ <object class="GtkBox" id="num-players-box">
<property name="visible">True</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkRadioButton" id="play_dark">
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="label" translatable="yes">Play _Dark</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="width-request">120</property>
- <property name="height-request">60</property>
- <property name="action-name">app.play-as</property>
- <property name="action-target">'first'</property>
- <property name="draw-indicator">False</property>
- <style>
- <class name="button"/>
- </style>
- </object>
- </child>
+ <property name="spacing">12</property>
<child>
- <object class="GtkRadioButton">
+ <object class="GtkRadioButton" id="one">
<property name="visible">True</property>
<property name="use_underline">True</property>
- <property name="label" translatable="yes">Play _Light</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="width-request">120</property>
- <property name="height-request">60</property>
- <property name="action-name">app.play-as</property>
- <property name="action-target">'second'</property>
- <property name="group">play_dark</property>
+ <property name="label" translatable="yes">_One</property>
+ <property name="halign">fill</property>
+ <property name="valign">fill</property>
+ <property name="action-name">app.num-players</property>
+ <property name="action-target">1</property>
<property name="draw-indicator">False</property>
+ <property name="expand">True</property>
<style>
<class name="button"/>
</style>
@@ -120,21 +100,23 @@
<object class="GtkRadioButton">
<property name="visible">True</property>
<property name="use_underline">True</property>
- <property name="label" translatable="yes">_Two Players</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="width-request">120</property>
- <property name="height-request">60</property>
- <property name="action-name">app.play-as</property>
- <property name="action-target">'two-players'</property>
- <property name="group">play_dark</property>
+ <property name="label" translatable="yes">_Two</property>
+ <property name="halign">fill</property>
+ <property name="valign">fill</property>
+ <property name="action-name">app.num-players</property>
+ <property name="action-target">2</property>
+ <property name="group">one</property>
<property name="draw-indicator">False</property>
+ <property name="expand">True</property>
<style>
<class name="button"/>
</style>
</object>
</child>
</object>
+ <packing>
+ <property name="expand">True</property>
+ </packing>
</child>
</object>
</child>
@@ -144,29 +126,27 @@
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
- <object class="GtkLabel">
+ <object class="GtkLabel" id="difficulty-label">
<property name="visible">True</property>
- <property name="label" translatable="yes">Computer Player</property>
<property name="valign">center</property>
<property name="halign">start</property>
</object>
</child>
<child>
- <object class="GtkBox" id="level-box">
+ <object class="GtkBox" id="difficulty-box">
<property name="visible">True</property>
- <property name="spacing">6</property>
+ <property name="spacing">12</property>
<child>
<object class="GtkRadioButton" id="easy">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="label" translatable="yes">_Easy</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="width-request">120</property>
- <property name="height-request">60</property>
+ <property name="halign">fill</property>
+ <property name="valign">fill</property>
<property name="action-name">app.computer-level</property>
<property name="action-target">1</property>
<property name="draw-indicator">False</property>
+ <property name="expand">True</property>
<style>
<class name="button"/>
</style>
@@ -177,14 +157,13 @@
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="label" translatable="yes">_Medium</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="width-request">120</property>
- <property name="height-request">60</property>
+ <property name="halign">fill</property>
+ <property name="valign">fill</property>
<property name="action-name">app.computer-level</property>
<property name="action-target">2</property>
<property name="group">easy</property>
<property name="draw-indicator">False</property>
+ <property name="expand">True</property>
<style>
<class name="button"/>
</style>
@@ -195,25 +174,80 @@
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="label" translatable="yes">_Hard</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="width-request">120</property>
- <property name="height-request">60</property>
+ <property name="halign">fill</property>
+ <property name="valign">fill</property>
<property name="action-name">app.computer-level</property>
<property name="action-target">3</property>
<property name="group">easy</property>
<property name="draw-indicator">False</property>
+ <property name="expand">True</property>
+ <style>
+ <class name="button"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="visible">True</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="color-label">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <property name="halign">start</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox" id="color-box">
+ <property name="visible">True</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkRadioButton" id="play_dark">
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <property name="label" translatable="yes">_Dark</property>
+ <property name="halign">fill</property>
+ <property name="valign">fill</property>
+ <property name="action-name">app.color</property>
+ <property name="action-target">'dark'</property>
+ <property name="draw-indicator">False</property>
+ <property name="expand">True</property>
+ <style>
+ <class name="button"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRadioButton">
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <property name="label" translatable="yes">_Light</property>
+ <property name="halign">fill</property>
+ <property name="valign">fill</property>
+ <property name="action-name">app.color</property>
+ <property name="action-target">'light'</property>
+ <property name="group">play_dark</property>
+ <property name="draw-indicator">False</property>
+ <property name="expand">True</property>
<style>
<class name="button"/>
</style>
</object>
</child>
</object>
+ <packing>
+ <property name="expand">True</property>
+ </packing>
</child>
</object>
</child>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="start-button">
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="label" translatable="yes">_Start Game</property>
@@ -221,8 +255,8 @@
<property name="valign">center</property>
<property name="action-name">app.start-game</property>
<property name="tooltip-text" translatable="yes">Start a game</property>
- <property name="width-request">222</property>
- <property name="height-request">60</property>
+ <property name="height-request">50</property>
+ <property name="width-request">450</property>
<style>
<class name="suggested-action"/>
</style>
@@ -346,7 +380,7 @@
<property name="action-name">app.new-game</property>
<property name="tooltip-text" translatable="yes">Start a new game</property>
<property name="width-request">120</property>
- <property name="height-request">60</property>
+ <property name="height-request">50</property>
</object>
<packing>
<property name="pack-type">end</property>
@@ -374,4 +408,13 @@
</object>
</child>
</object>
+ <object class="GtkSizeGroup">
+ <property name="mode">both</property>
+ <widgets>
+ <widget name="num-players-box"/>
+ <widget name="difficulty-box"/>
+ <widget name="color-box"/>
+ <widget name="start-button"/>
+ </widgets>
+ </object>
</interface>
diff --git a/data/org.gnome.iagno.gschema.xml b/data/org.gnome.iagno.gschema.xml
index db01192..35d67d1 100644
--- a/data/org.gnome.iagno.gschema.xml
+++ b/data/org.gnome.iagno.gschema.xml
@@ -1,8 +1,7 @@
<schemalist>
- <enum id="org.gnome.iagno.PlayAs">
- <value value="0" nick="two-players"/>
- <value value="1" nick="first"/>
- <value value="2" nick="second"/>
+ <enum id="org.gnome.iagno.Color">
+ <value value="0" nick="dark"/>
+ <value value="1" nick="light"/>
</enum>
<schema id="org.gnome.iagno" path="/org/gnome/iagno/" gettext-domain="iagno">
@@ -12,10 +11,15 @@
<summary>Computer's AI level</summary>
<description>From 1, the easiest, to 3, the hardest.</description>
</key>
- <key name="play-as" enum="org.gnome.iagno.PlayAs">
- <default>'first'</default>
- <summary>Type of game</summary>
- <description>Choose the type of the next game.</description>
+ <key name="num-players" type="i">
+ <default>1</default>
+ <range min="1" max="2" />
+ <summary>Whether to play against the computer or another human.</summary>
+ </key>
+ <key name="color" enum="org.gnome.iagno.Color">
+ <default>'dark'</default>
+ <summary>Color to play as</summary>
+ <description>Whether to play as Dark or Light. Ignored for two-player games.</description>
</key>
<key name="tileset" type="s">
<default>'black_and_white.svg'</default>
@@ -26,11 +30,11 @@
<description>Whether or not to play event sounds.</description>
</key>
<key name="window-width" type="i">
- <default>540</default>
+ <default>675</default>
<summary>Width of the window in pixels</summary>
</key>
<key name="window-height" type="i">
- <default>500</default>
+ <default>550</default>
<summary>Height of the window in pixels</summary>
</key>
<key name="window-is-maximized" type="b">
diff --git a/src/iagno.vala b/src/iagno.vala
index 3f8bcfb..1a86404 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -22,8 +22,9 @@ public class Iagno : Gtk.Application
private static int computer_level = 0;
private static int size = 8;
private static bool begin_with_new_game_screen = false;
- private static string play_as;
+ private static string color;
private static bool? sound = null;
+ private static bool? two_players = null;
/* Seconds */
private static const double QUICK_MOVE_DELAY = 0.4;
@@ -128,14 +129,17 @@ public class Iagno : Gtk.Application
if (computer_level < 0 || computer_level > 3)
stderr.printf ("%s\n", _("Level should be between 1 (easy) and 3 (hard). Settings unchanged."));
- if (options.contains ("two-players"))
- play_as = "two-players";
- else if (options.contains ("first"))
- play_as = "first";
- else if (options.contains ("second"))
- play_as = "second";
- else
+ if (options.contains ("two-players")) {
+ two_players = true;
+ } else if (options.contains ("first")) {
+ color = "dark";
+ two_players = false;
+ } else if (options.contains ("second")) {
+ color = "light";
+ two_players = false;
+ } else {
begin_with_new_game_screen = true;
+ }
/* Activate */
return -1;
@@ -144,19 +148,28 @@ public class Iagno : Gtk.Application
protected override void startup ()
{
base.startup ();
+
var builder = new Gtk.Builder.from_resource ("/org/gnome/iagno/ui/iagno.ui");
/* Settings */
settings = new Settings ("org.gnome.iagno");
+
if (sound != null)
settings.set_boolean ("sound", sound);
- if (!begin_with_new_game_screen)
- settings.set_string ("play-as", play_as);
- else /* hack, part 1 on 3 */
- play_as = settings.get_string ("play-as");
+
+ if (two_players != null)
+ settings.set_int ("num-players", two_players ? 2 : 1);
+ else /* hack, part 1 of 4 */
+ two_players = (settings.get_int ("num-players") == 2);
+
+ if (color != null)
+ settings.set_string ("color", color);
+ else /* hack, part 2 of 4 */
+ color = settings.get_string ("color");
+
if (computer_level > 0 && computer_level <= 3)
settings.set_int ("computer-level", computer_level);
- else /* hack, part 2 on 3 */
+ else /* hack, part 3 of 4 */
computer_level = settings.get_int ("computer-level");
/* Actions and preferences */
@@ -166,14 +179,21 @@ public class Iagno : Gtk.Application
add_action (settings.create_action ("sound"));
/* TODO bugs when changing manually the gsettings key (not for sound);
* solving this bug may remove the need of the hack in three parts */
- add_action (settings.create_action ("play-as"));
+ add_action (settings.create_action ("color"));
+ add_action (settings.create_action ("num-players"));
add_action (settings.create_action ("computer-level"));
- var level_box = builder.get_object ("level-box") as Gtk.Box;
- settings.changed["play-as"].connect (() => {
- level_box.sensitive = settings.get_string ("play-as") != "two-players";
+ var level_box = builder.get_object ("difficulty-box") as Gtk.Box;
+ settings.changed["num-players"].connect (() => {
+ level_box.sensitive = settings.get_int ("num-players") == 1;
});
- level_box.sensitive = play_as != "two-players";
+ level_box.sensitive = settings.get_int ("num-players") == 1;
+
+ var color_box = builder.get_object ("color-box") as Gtk.Box;
+ settings.changed["num-players"].connect (() => {
+ color_box.sensitive = settings.get_int ("num-players") == 1;
+ });
+ color_box.sensitive = settings.get_int ("num-players") == 1;
/* Window construction */
window = builder.get_object ("iagno-window") as Gtk.ApplicationWindow;
@@ -184,12 +204,28 @@ public class Iagno : Gtk.Application
window.maximize ();
add_window (window);
- /* Hack for restoring radiobuttons settings, part 3 on 3.
+ /* Hack for restoring radiobuttons settings, part 4 of 4.
* When you add_window(), settings are initialized with the value
* of the first radiobutton of the group found in the UI file. */
Settings.sync ();
- settings.set_string ("play-as", play_as);
+ settings.set_string ("color", color);
settings.set_int ("computer-level", computer_level);
+ settings.set_int ("num-players", two_players ? 2 : 1);
+
+ var label = builder.get_object ("players-label") as Gtk.Label;
+ label.use_markup = true;
+ /* Label on new game screen */
+ label.label = "<b>%s</b>".printf (_("Players"));
+
+ label = builder.get_object ("difficulty-label") as Gtk.Label;
+ label.use_markup = true;
+ /* Label on new game screen */
+ label.label = "<b>%s</b>".printf (_("Difficulty"));
+
+ label = builder.get_object ("color-label") as Gtk.Label;
+ label.use_markup = true;
+ /* Label on new game screen */
+ label.label = "<b>%s</b>".printf (_("Color"));
/* View construction */
view = new GameView ();
@@ -310,13 +346,15 @@ public class Iagno : Gtk.Application
game.turn_ended.connect (turn_ended_cb);
view.game = game;
- var mode = settings.get_string ("play-as");
- if (mode == "two-players")
+ if (settings.get_int ("num-players") == 2)
computer = null;
else
computer = new ComputerPlayer (game, settings.get_int ("computer-level"));
- player_one = (mode == "first") ? Player.DARK : Player.LIGHT;
+ if (settings.get_enum ("color") == 1)
+ player_one = Player.LIGHT;
+ else
+ player_one = Player.DARK;
update_ui ();
@@ -491,7 +529,7 @@ public class Iagno : Gtk.Application
"name", _("Iagno"),
"version", VERSION,
"copyright",
- "Copyright © 1998–2008 Ian Peters\nCopyright © 2013–2014 Michael Catanzaro",
+ "Copyright © 1998–2008 Ian Peters\nCopyright © 2013–2015 Michael Catanzaro",
"license-type", Gtk.License.GPL_2_0,
"comments", _("A disk flipping game derived from Reversi"),
"authors", authors,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]