1/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 2 3 Gnome Nibbles: Gnome Worm Game 4 Copyright (C) 2020 Arnaud Bonatti <arnaud.bonatti@gmail.com> 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18*/ 19 20using Gtk; 21 22[GtkTemplate (ui = "/org/gnome/Nibbles/ui/speed.ui")] 23private class Speed : Box 24{ 25 private SimpleAction speed_action; 26 private SimpleAction fakes_action; 27 28 private const GLib.ActionEntry [] players_action_entries = 29 { 30 { "change-speed", null, "i", "4", change_speed }, 31 { "toggle-fakes", null, null, "true", toggle_fakes } 32 }; 33 34 construct 35 { 36 SimpleActionGroup action_group = new SimpleActionGroup (); 37 action_group.add_action_entries (players_action_entries, this); 38 insert_action_group ("speed", action_group); 39 40 speed_action = (SimpleAction) action_group.lookup_action ("change-speed"); 41 fakes_action = (SimpleAction) action_group.lookup_action ("toggle-fakes"); 42 } 43 44 internal inline void set_values (int speed, bool fakes) 45 { 46 speed_action.set_state (speed); 47 fakes_action.set_state (fakes); 48 } 49 50 internal inline void get_values (out int speed, out bool fakes) 51 { 52 speed = speed_action.get_state ().get_int32 (); 53 fakes = fakes_action.get_state ().get_boolean (); 54 } 55 56 private inline void change_speed (SimpleAction _speed_action, Variant variant) 57 { 58 int speed = variant.get_int32 (); 59 if (speed < 1 || speed > 4) 60 assert_not_reached (); 61 _speed_action.set_state (speed); 62 } 63 64 private void toggle_fakes (SimpleAction _fakes_action, Variant? variant) 65 { 66 _fakes_action.set_state (((!) variant).get_boolean ()); 67 } 68} 69