Exemple #1
0
        public CustomGameDialog(ITranslations translations, GameSession session)
            : base(translations, "CustomGameDialog.ui", "customgame")
        {
            Game game;

            selection_done = false;
            this.session = session;
            games = session.GameManager.AvailableGames;

            drawing_area = new GameDrawingArea ();
            drawing_area.UseSolutionArea = false;
                        drawing_area.SetSizeRequest (preview_vbox.WidthRequest, preview_vbox.HeightRequest);
            preview_vbox.Add (drawing_area);
            drawing_area.Visible = true;
            treeview.HeadersClickable = true;

            CreateColumnName ();
            CreateColumnType ();
            CreateColumnSelected ();
            LoadGames ();

            treeview.Model = games_store;
            game = (Game) Activator.CreateInstance (games [0].TypeOf, true);
            game.Translations = Translations;
            game.Variant = 0;
            game.Begin ();
            drawing_area.Drawable = game;
            drawing_area.Question = game.Question;
            treeview.ColumnsAutosize ();
        }
Exemple #2
0
 void UpdateSolution(string solution, GameDrawingArea.SolutionType solution_type)
 {
     drawing_area.Solution = solution;
     drawing_area.SolutionIcon = solution_type;
     QueueDraw ();
 }
Exemple #3
0
        void BuildUI()
        {
            bool show_toolbar;

            GtkBeans.Builder builder = new GtkBeans.Builder ("gbrainy.ui");
            builder.Autoconnect (this);

            show_toolbar = Preferences.Get <bool> (Preferences.ToolbarShowKey) == true && low_res == false;

            // Toolbar creation
            toolbar = new Widgets.Toolbar (main_hbox, framework_vbox);
            toolbar.Attach ((Gtk.Orientation) Preferences.Get <int> (Preferences.ToolbarOrientationKey));
            toolbar.AllButton.Clicked += OnAllGames;
            toolbar.LogicButton.Clicked += OnLogicOnly;
            toolbar.CalculationButton.Clicked += OnMathOnly;
            toolbar.MemoryButton.Clicked += OnMemoryOnly;
            toolbar.VerbalButton.Clicked += OnVerbalOnly;
            toolbar.PauseButton.Clicked += OnPauseGame;
            toolbar.FinishButton.Clicked += OnEndGame;

            drawing_area = new GameDrawingArea ();
            drawing_area.Drawable = session;
            GameSensitiveUI ();

            // For low resolutions, hide the toolbar and made the drawing area smaller
            if (drawing_area.Screen.Width> 0 && drawing_area.Screen.Height > 0) {
                if (drawing_area.Screen.Height < 700) {
                    drawing_vbox.HeightRequest = 350;
                    low_res = true;
                }
            }

            EventBox eb = new EventBox (); // Provides a window for drawing area windowless widget

            eb.Events = Gdk.EventMask.PointerMotionMask;
            drawing_vbox.Add (eb);

            eb.Add (drawing_area);

            eb.MotionNotifyEvent += OnMouseMotionEvent;
            eb.ButtonPressEvent += OnHandleButtonPress;

            show_toolbar = Preferences.Get <bool> (Preferences.ToolbarShowKey) == true && low_res == false;

            // We only disable the Arrow if we are going to show the toolbar.
            // It has an impact on the total window width size even if we do not show it
            if (show_toolbar)
                toolbar.ShowArrow = false;

            app_window.IconName = "gbrainy";

            app_window.ShowAll ();

            toolbar_orientation_menuitem.Sensitive = toolbar.Visible;

            // Check default radio button
            switch (toolbar.Orientation) {
            case Gtk.Orientation.Vertical:
                vertical_radiomenuitem.Active = true;
                break;
            case Gtk.Orientation.Horizontal:
                horizontal_radiomenuitem.Active = true;
                break;
            default:
                throw new InvalidOperationException ();
            }

            // The toolbar by default is enabled. By setting this menu entry to false
            // triggers the OnActivateToolbar event that hides the toolbar
            if (show_toolbar == false)
                showtoolbar_menuitem.Active = false;

            #if MONO_ADDINS
            extensions_menuitem.Activated += delegate (object sender, EventArgs ar)
            {
                Mono.Addins.Gui.AddinManagerWindow.Run (app_window);
                GameManagerPreload (session.GameManager);
                CustomGameDialog.Clear ();
            };
            #else
            extensions_menuitem.Visible = false;
            #endif
            ActiveInputControls (false);
        }
        public CustomGameDialog(GameManager manager)
            : base("CustomGameDialog.ui", "customgame")
        {
            Game game;

            selection_done = false;
            this.manager = manager;
            games = manager.AvailableGames;

            drawing_area = new GameDrawingArea ();
            drawing_area.UseSolutionArea = false;
            preview_vbox.Add (drawing_area);
            drawing_area.Visible = true;
            treeview.HeadersClickable = true;

            // Column: Game Name
            TreeViewColumn name_column = new TreeViewColumn (Catalog.GetString("Game Name"),
                new CellRendererText(), "text", 0);

            name_column.Expand = true;
            name_column.Clickable = true;
            name_column.Clicked += delegate (object sender, EventArgs args)
            {
                Gtk.SortType order;
                Gtk.TreeViewColumn column = (Gtk.TreeViewColumn) sender;

                if (column.SortOrder == Gtk.SortType.Ascending)
                    order = Gtk.SortType.Descending;
                else
                    order = Gtk.SortType.Ascending;

                column.SortOrder = order;
                games_store.SetSortColumnId (COL_NAME, order);
            };

            treeview.AppendColumn (name_column);

            // Column: Type
            TreeViewColumn type_column = new TreeViewColumn (Catalog.GetString("Type"),
                new CellRendererText(), "text", 1);

            type_column.Expand = true;
            treeview.AppendColumn (type_column);
            type_column.Clickable = true;
            type_column.Clicked += delegate (object sender, EventArgs args)
            {
                Gtk.SortType order;
                Gtk.TreeViewColumn column = (Gtk.TreeViewColumn) sender;

                if (column.SortOrder == Gtk.SortType.Ascending)
                    order = Gtk.SortType.Descending;
                else
                    order = Gtk.SortType.Ascending;

                column.SortOrder = order;
                games_store.SetSortColumnId (COL_TYPE, order);
            };

            // Column: Selected
            CellRendererToggle toggle_cell = new CellRendererToggle();
            TreeViewColumn toggle_column = new TreeViewColumn(Catalog.GetString("Selected"),
                toggle_cell, "active", COL_ENABLED);
            toggle_cell.Activatable = true;
            toggle_cell.Toggled += OnActiveToggled;
            toggle_column.Expand = false;
            treeview.CursorChanged += OnCursorChanged;
            treeview.AppendColumn (toggle_column);

            if (games_store == null) {
                games_store = new ListStore (typeof(string), typeof (string), typeof(bool), typeof (Game), typeof (int));

                games_store.SetSortFunc (0, new Gtk.TreeIterCompareFunc (GameSort));
                games_store.SetSortColumnId (COL_TYPE, SortType.Ascending);

                // Data
                string type;
                for (int i = 0; i < games.Length; i++)
                {
                    if (games [i].IsGame == false)
                        continue;

                    game = (Game) Activator.CreateInstance (games [i].TypeOf, true);
                    game.Variant = games [i].Variant;
                    type = GameTypesDescription.GetLocalized (game.Type);
                    games_store.AppendValues (game.Name, type, true, game, i);
                }
            }

            treeview.Model = games_store;
            game = (Game) Activator.CreateInstance (games [0].TypeOf, true);
            game.Variant = 0;
            game.Begin ();
            drawing_area.Drawable = game;
            drawing_area.Question = game.Question;
            treeview.ColumnsAutosize ();
        }