Commit 7f8bd2ef authored by Michael Catanzaro's avatar Michael Catanzaro Committed by Iulian Radu

Use a gsettings enum for the color values

https://bugzilla.gnome.org/show_bug.cgi?id=762831
parent 58066ce1
<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>
......
......@@ -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");
......
......@@ -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");
......
......@@ -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];
......
......@@ -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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment