[four-in-a-row/KaKnife/four-in-a-row-vala: 42/65] made prefbox it's own class
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row/KaKnife/four-in-a-row-vala: 42/65] made prefbox it's own class
- Date: Sun, 16 Dec 2018 03:20:10 +0000 (UTC)
commit ed3f863ab21e516f23c8bbd24ac6258395408a2e
Author: Jacob Humphrey <jacob ryan humphrey gmail com>
Date: Fri Dec 14 23:18:34 2018 -0600
made prefbox it's own class
src/prefs.vala | 197 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 107 insertions(+), 90 deletions(-)
---
diff --git a/src/prefs.vala b/src/prefs.vala
index 02b957c..5945cc2 100644
--- a/src/prefs.vala
+++ b/src/prefs.vala
@@ -92,7 +92,7 @@ class Prefs {
}
Settings settings;
-Gtk.Dialog? prefsbox = null;
+PrefsBox? prefsbox = null;
Gtk.ComboBox combobox;
Gtk.ComboBoxText combobox_theme;
Gtk.CheckButton checkbutton_sound;
@@ -137,8 +137,107 @@ public void on_select_opponent(Gtk.ComboBox w) {
application.game_reset();
}
+class PrefsBox : Gtk.Dialog {
+ public Gtk.Notebook notebook;
+ public PrefsBox(Gtk.Window parent) {
+ Gtk.Grid grid;
+ GamesControlsList controls_list;
+ Gtk.Label label;
+ Gtk.CellRendererText renderer;
+ Gtk.ListStore model;
+ Gtk.TreeIter iter;
+
+ Object(
+ title: _("Preferences"),
+ destroy_with_parent: true);
+ set_transient_for(parent);
+ border_width = 5;
+ get_content_area().spacing = 2;
+ notebook = new Gtk.Notebook();
+ notebook.set_border_width(5);
+ get_content_area().pack_start(notebook, true, true, 0);
+
+ /* game tab */
+ grid = new Gtk.Grid();
+ grid.set_row_spacing(6);
+ grid.set_column_spacing(12);
+ grid.set_border_width(12);
+
+ label = new Gtk.Label(_("Game"));
+ notebook.append_page(grid, label);
+
+ label = new Gtk.Label(_("Opponent:"));
+ label.set_hexpand(true);
+ grid.attach(label,0,0 ,1, 1);
+
+ combobox = new Gtk.ComboBox();
+ renderer = new Gtk.CellRendererText();
+ combobox.pack_start(renderer, true);
+ combobox.add_attribute(renderer, "text", 0);
+ model = new Gtk.ListStore(2, typeof(string), typeof(int));
+ combobox.set_model(model);
+ model.append(out iter);
+ model.set(iter, 0, _("Human"), 1, Level.HUMAN);
+ if (p.level[PlayerID.PLAYER2] == Level.HUMAN)
+ combobox.set_active_iter(iter);
+ model.append(out iter);
+ model.set(iter, 0, _("Level one"), 1, Level.WEAK);
+ if (p.level[PlayerID.PLAYER2] == Level.WEAK)
+ combobox.set_active_iter(iter);
+ model.append(out iter);
+ model.set(iter, 0, _("Level two"), 1, Level.MEDIUM);
+ if (p.level[PlayerID.PLAYER2] == Level.MEDIUM)
+ combobox.set_active_iter(iter);
+ model.append(out iter);
+ model.set(iter, 0, _("Level thre"), 1, Level.STRONG);
+ if (p.level[PlayerID.PLAYER2] == Level.STRONG)
+ combobox.set_active_iter(iter);
+
+ combobox.changed.connect(on_select_opponent);
+ grid.attach(combobox, 1, 0, 1, 1);
+
+ label = new Gtk.Label.with_mnemonic(_("_Theme:"));
+ label.set_xalign((float)0.0);
+ label.set_yalign((float)0.5);
+ grid.attach(label, 0, 1, 1, 1);
+
+ combobox_theme = new Gtk.ComboBoxText();
+ for (int i = 0; i < theme.length; i++) {
+ combobox_theme.append_text(_(theme_get_title(i)));
+ }
+ label.set_mnemonic_widget(combobox_theme);
+ grid.attach(combobox_theme, 1, 1, 1, 1);
+
+ checkbutton_sound = new Gtk.CheckButton.with_mnemonic(_("E_nable sounds"));
+ grid.attach(checkbutton_sound, 0, 2, 2, 1);
+
+ /* keyboard tab */
+ label = new Gtk.Label.with_mnemonic(_("Keyboard Controls"));
+
+ controls_list = new GamesControlsList(settings);
+ controls_list.add_controls("key-left", _("Move left"), DEFAULT_KEY_LEFT,
+ "key-right", _("Move right"), DEFAULT_KEY_RIGHT,
+ "key-drop", _("Drop marble"), DEFAULT_KEY_DROP);
+ controls_list.border_width = 12;
+ notebook.append_page(controls_list, label);
+
+ /* fill in initial values */
+ combobox_theme.set_active(p.theme_id);
+ checkbutton_sound.set_active(p.do_sound);
+
+ /* connect signals */
+ combobox_theme.changed.connect(on_select_theme);
+ checkbutton_sound.toggled.connect(p.on_toggle_sound);
+ //response.connect(() => {prefsbox.hide();});
+ }
+
+ protected override bool delete_event(Gdk.EventAny event) {
+ hide();
+ return true;
+ }
+}
+
public void prefsbox_open() {
- Gtk.Notebook notebook;
Gtk.Grid grid;
GamesControlsList controls_list;
Gtk.Label label;
@@ -151,97 +250,15 @@ public void prefsbox_open() {
return;
}
- prefsbox = new Gtk.Dialog.with_buttons(_("Preferences"),
- window,
- Gtk.DialogFlags.DESTROY_WITH_PARENT);
-
- prefsbox.set_border_width(5);
- prefsbox.get_content_area().set_spacing(2);
-
- notebook = new Gtk.Notebook();
- notebook.set_border_width(5);
- prefsbox.get_content_area().pack_start(notebook, true, true, 0);
-
- /* game tab */
-
- grid = new Gtk.Grid();
- grid.set_row_spacing(6);
- grid.set_column_spacing(12);
- grid.set_border_width(12);
-
- label = new Gtk.Label(_("Game"));
- notebook.append_page(grid, label);
-
- label = new Gtk.Label(_("Opponent:"));
- label.set_hexpand(true);
- grid.attach(label,0,0 ,1, 1);
-
- combobox = new Gtk.ComboBox();
- renderer = new Gtk.CellRendererText();
- combobox.pack_start(renderer, true);
- combobox.add_attribute(renderer, "text", 0);
- model = new Gtk.ListStore(2, typeof(string), typeof(int));
- combobox.set_model(model);
- model.append(out iter);
- model.set(iter, 0, _("Human"), 1, Level.HUMAN);
- if (p.level[PlayerID.PLAYER2] == Level.HUMAN)
- combobox.set_active_iter(iter);
- model.append(out iter);
- model.set(iter, 0, _("Level one"), 1, Level.WEAK);
- if (p.level[PlayerID.PLAYER2] == Level.WEAK)
- combobox.set_active_iter(iter);
- model.append(out iter);
- model.set(iter, 0, _("Level two"), 1, Level.MEDIUM);
- if (p.level[PlayerID.PLAYER2] == Level.MEDIUM)
- combobox.set_active_iter(iter);
- model.append(out iter);
- model.set(iter, 0, _("Level thre"), 1, Level.STRONG);
- if (p.level[PlayerID.PLAYER2] == Level.STRONG)
- combobox.set_active_iter(iter);
-
- combobox.changed.connect(on_select_opponent);
- grid.attach(combobox, 1, 0, 1, 1);
-
- label = new Gtk.Label.with_mnemonic(_("_Theme:"));
- label.set_xalign((float)0.0);
- label.set_yalign((float)0.5);
- grid.attach(label, 0, 1, 1, 1);
-
- combobox_theme = new Gtk.ComboBoxText();
- for (int i = 0; i < theme.length; i++) {
- combobox_theme.append_text(_(theme_get_title(i)));
- }
- label.set_mnemonic_widget(combobox_theme);
- grid.attach(combobox_theme, 1, 1, 1, 1);
-
- checkbutton_sound = new Gtk.CheckButton.with_mnemonic(_("E_nable sounds"));
- grid.attach(checkbutton_sound, 0, 2, 2, 1);
-
- /* keyboard tab */
-
- label = new Gtk.Label.with_mnemonic(_("Keyboard Controls"));
-
- controls_list = new GamesControlsList(settings);
- controls_list.add_controls("key-left", _("Move left"), DEFAULT_KEY_LEFT,
- "key-right", _("Move right"), DEFAULT_KEY_RIGHT,
- "key-drop", _("Drop marble"), DEFAULT_KEY_DROP);
- controls_list.border_width = 12;
- notebook.append_page(controls_list, label);
-
- /* fill in initial values */
-
- combobox_theme.set_active(p.theme_id);
- checkbutton_sound.set_active(p.do_sound);
+ prefsbox = new PrefsBox(window);
/* connect signals */
- prefsbox.response.connect(() => {prefsbox.hide();});
- prefsbox.delete_event.connect((event) => {
- prefsbox.hide();
- return true;
- });
- combobox_theme.changed.connect(on_select_theme);
+ // prefsbox.response.connect(() => {prefsbox.hide();});
+ // prefsbox.delete_event.connect((event) => {
+ // prefsbox.hide();
+ // return true;
+ // });
- checkbutton_sound.toggled.connect(p.on_toggle_sound);
prefsbox.show_all();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]