[gnome-nibbles] Use a gsettings enum for the color values
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles] Use a gsettings enum for the color values
- Date: Fri, 4 Mar 2016 18:37:29 +0000 (UTC)
commit 7f8bd2ef9f73c1df94578699d9da7a3198047623
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Feb 28 14:29:17 2016 -0600
Use a gsettings enum for the color values
https://bugzilla.gnome.org/show_bug.cgi?id=762831
data/org.gnome.nibbles.gschema.xml | 20 ++++++++++++++------
src/gnome-nibbles.vala | 2 +-
src/nibbles-game.vala | 2 +-
src/nibbles-view.vala | 15 ---------------
src/preferences-dialog.vala | 16 ++++++++--------
5 files changed, 24 insertions(+), 31 deletions(-)
---
diff --git a/data/org.gnome.nibbles.gschema.xml b/data/org.gnome.nibbles.gschema.xml
index 817164c..d5f9193 100644
--- a/data/org.gnome.nibbles.gschema.xml
+++ b/data/org.gnome.nibbles.gschema.xml
@@ -1,4 +1,12 @@
<schemalist>
+ <enum id="org.gnome.nibbles.Color">
+ <value value="0" nick="red"/>
+ <value value="1" nick="green"/>
+ <value value="2" nick="blue"/>
+ <value value="3" nick="yellow"/>
+ <value value="4" nick="cyan"/>
+ <value value="5" nick="purple"/>
+ </enum>
<schema id="org.gnome.nibbles" path="/org/gnome/nibbles/" gettext-domain="gnome-nibbles">
<key name="window-width" type="i">
<default>730</default>
@@ -62,7 +70,7 @@
</key>
</schema>
<schema id="org.gnome.nibbles.worm0" path="/org/gnome/nibbles/worm0/">
- <key name="color" type="s">
+ <key name="color" enum="org.gnome.nibbles.Color">
<default>'red'</default>
<summary>Color to use for worm</summary>
<description>Color to use for worm.</description>
@@ -94,7 +102,7 @@
</key>
</schema>
<schema id="org.gnome.nibbles.worm1" path="/org/gnome/nibbles/worm1/">
- <key name="color" type="s">
+ <key name="color" enum="org.gnome.nibbles.Color">
<default>'green'</default>
<summary>Color to use for worm</summary>
<description>Color to use for worm.</description>
@@ -126,7 +134,7 @@
</key>
</schema>
<schema id="org.gnome.nibbles.worm2" path="/org/gnome/nibbles/worm2/">
- <key name="color" type="s">
+ <key name="color" enum="org.gnome.nibbles.Color">
<default>'blue'</default>
<summary>Color to use for worm</summary>
<description>Color to use for worm.</description>
@@ -158,7 +166,7 @@
</key>
</schema>
<schema id="org.gnome.nibbles.worm3" path="/org/gnome/nibbles/worm3/">
- <key name="color" type="s">
+ <key name="color" enum="org.gnome.nibbles.Color">
<default>'yellow'</default>
<summary>Color to use for worm</summary>
<description>Color to use for worm.</description>
@@ -190,7 +198,7 @@
</key>
</schema>
<schema id="org.gnome.nibbles.worm4" path="/org/gnome/nibbles/worm4/">
- <key name="color" type="s">
+ <key name="color" enum="org.gnome.nibbles.Color">
<default>'cyan'</default>
<summary>Color to use for worm</summary>
<description>Color to use for worm.</description>
@@ -222,7 +230,7 @@
</key>
</schema>
<schema id="org.gnome.nibbles.worm5" path="/org/gnome/nibbles/worm5/">
- <key name="color" type="s">
+ <key name="color" enum="org.gnome.nibbles.Color">
<default>'purple'</default>
<summary>Color to use for worm</summary>
<description>Color to use for worm.</description>
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index e8fb992..8e7a870 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -496,7 +496,7 @@ public class Nibbles : Gtk.Application
switch (key)
{
case "color":
- properties.color = NibblesView.colorval_from_name (changed_worm_settings.get_string
("color"));
+ properties.color = changed_worm_settings.get_enum ("color");
break;
case "key-up":
properties.up = changed_worm_settings.get_int ("key-up");
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 08a9f27..7ded550 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -560,7 +560,7 @@ public class NibblesGame : Object
foreach (var worm in worms)
{
var properties = WormProperties ();
- properties.color = NibblesView.colorval_from_name (worm_settings[worm.id].get_string ("color"));
+ properties.color = worm_settings[worm.id].get_enum ("color");
properties.up = worm_settings[worm.id].get_int ("key-up");
properties.down = worm_settings[worm.id].get_int ("key-down");
properties.left = worm_settings[worm.id].get_int ("key-left");
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index f1acc6f..f071f21 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -909,21 +909,6 @@ public class NibblesView : GtkClutter.Embed
Canberra.PROP_MEDIA_FILENAME, path);
}
- /*\
- * * Color conversion (name <-> value)
- \*/
-
- public static int colorval_from_name (string name)
- {
- for (int i = 0; i < NUM_COLORS; i++)
- {
- if (color_lookup[i] == name)
- return i;
- }
-
- return 0;
- }
-
public static string colorval_name (int colorval)
{
return color_lookup[colorval];
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index b257586..49d4f99 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -162,8 +162,8 @@ private class PreferencesDialog : Gtk.Dialog
var id = combo_boxes.index_of (combo_box);
- var color = worm_settings[id].get_string ("color");
- combo_box.set_active (NibblesView.colorval_from_name (color));
+ var color = worm_settings[id].get_enum ("color");
+ combo_box.set_active (color);
combo_box.changed.connect (combo_box_changed_cb);
}
}
@@ -267,8 +267,8 @@ private class PreferencesDialog : Gtk.Dialog
private void combo_box_changed_cb (Gtk.ComboBox combo_box)
{
var id = combo_boxes.index_of ((Gtk.ComboBoxText) combo_box);
- var color_new = NibblesView.colorval_name (combo_box.get_active ());
- var color_old = worm_settings[id].get_string ("color");
+ var color_new = combo_box.get_active ();
+ var color_old = worm_settings[id].get_enum ("color");
if (color_new == color_old)
return;
@@ -276,9 +276,9 @@ private class PreferencesDialog : Gtk.Dialog
/* Swap the colors if the new color is already set for another worm */
for (int i = 0; i < NibblesGame.MAX_WORMS; i++)
{
- if (i != id && worm_settings[i].get_string ("color") == color_new)
+ if (i != id && worm_settings[i].get_enum ("color") == color_new)
{
- worm_settings[i].set_string ("color", color_old);
+ worm_settings[i].set_enum ("color", color_old);
/* Update swapped colors in UI */
if (i < NibblesGame.MAX_HUMANS)
@@ -288,7 +288,7 @@ private class PreferencesDialog : Gtk.Dialog
var index = combo_boxes.index_of (cbox);
if (index == i)
{
- cbox.set_active (NibblesView.colorval_from_name (color_old));
+ cbox.set_active (color_old);
break;
}
}
@@ -298,6 +298,6 @@ private class PreferencesDialog : Gtk.Dialog
}
}
- worm_settings[id].set_string ("color", color_new);
+ worm_settings[id].set_enum ("color", color_new);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]