Files @ 41381c24d35a
Branch filter:

Location: ATITD-Tools/Desert-Paint-Lab/ReactionStatusWindow.cs - annotation

Jason Maltzen
Now supports all the interface sizes with a setting to select the current interface size. The initial screen size check now displays the detected resolution as a hint. The screen size check / interface size settings can now be updated after launch through File->Preferences. Capturing a reaction now includes a progress bar, and runs in a separate thread instead of silently blocking. The reaction status window under 'Help' now has options to disable ingredients to remove them from the list. NOTE: this also disables/enables those ingredients in the recipe generator as well. The list also updates as new reactions are recorded instead of requiring that it be closed and re-opened to update.
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
41381c24d35a
41381c24d35a
41381c24d35a
f28757bb21cb
f28757bb21cb
f28757bb21cb
41381c24d35a
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
41381c24d35a
41381c24d35a
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
f28757bb21cb
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
41381c24d35a
f28757bb21cb
f28757bb21cb
f28757bb21cb
using System;

namespace DesertPaintLab
{
    public partial class ReactionStatusWindow : Gtk.Window
    {
        PlayerProfile _profile;

        Gtk.ListStore reagentListStore;

        public ReactionStatusWindow(PlayerProfile profile) : base(Gtk.WindowType.Toplevel)
        {
            _profile = profile;
            this.Build();

            //Gtk.CellRendererText reagentColumnCell = new Gtk.CellRendererText();

            SetupReagentList();

            int count = 0;
            foreach (string name1 in ReagentManager.Names)
            {
                Reagent reagent1 = ReagentManager.GetReagent(name1);
                foreach (string name2 in ReagentManager.Names)
                {
                    if (name1.Equals(name2))
                    {
                        continue;
                    }
                    Reagent reagent2 = ReagentManager.GetReagent(name2);
                    Reaction reaction = profile.FindReaction(reagent1, reagent2);
                    if (reaction == null)
                    {
                        if (count == 0)
                        {
                            Gtk.Label header = new Gtk.Label("Missing Reactions:");
                            resultbox.PackStart(header, false, false, 0);
                            Gtk.HSeparator sep = new Gtk.HSeparator();
                            resultbox.PackStart(sep, false, false, 0);
                        }
                        Gtk.Label label = new Gtk.Label(name1 + " + " + name2);
                        resultbox.PackStart(label, false, false, 0);

                        ++count;
                    }
                }
            }

            if (count == 0)
            {
                Gtk.Label header = new Gtk.Label("All reactions recorded!");
                resultbox.PackStart(header, false, false, 0);
            }
            ShowAll();
        }

        public void RefreshReactions()
        {
            while (resultbox.Children.Length > 0)
            {
                Gtk.Widget child = resultbox.Children[0];
                resultbox.Remove(child);
            }
            int count = 0;
            foreach (string name1 in ReagentManager.Names)
            {
                Reagent reagent1 = ReagentManager.GetReagent(name1);
                foreach (string name2 in ReagentManager.Names)
                {
                    if (name1.Equals(name2))
                    {
                        continue;
                    }
                    Reagent reagent2 = ReagentManager.GetReagent(name2);
                    if (!reagent1.Enabled || !reagent2.Enabled) continue;
                    Reaction reaction = _profile.FindReaction(reagent1, reagent2);
                    if (reaction == null)
                    {
                        if (count == 0)
                        {
                            Gtk.Label header = new Gtk.Label("Missing Reactions:");
                            resultbox.PackStart(header, false, false, 0);
                            Gtk.HSeparator sep = new Gtk.HSeparator();
                            resultbox.PackStart(sep, false, false, 0);
                        }
                        Gtk.Label label = new Gtk.Label(name1 + " + " + name2);
                        resultbox.PackStart(label, false, false, 0);

                        ++count;
                    }
                }
            }

            if (count == 0)
            {
                Gtk.Label header = new Gtk.Label("All reactions recorded!");
                resultbox.PackStart(header, false, false, 0);
            }
            ShowAll();
        }

        private void OnReagentToggled(object o, Gtk.ToggledArgs args)
        {
            Gtk.TreeIter iter;
            reagentListStore.GetIter(out iter, new Gtk.TreePath(args.Path));

            Reagent reagent = (Reagent)reagentListStore.GetValue(iter, 0);
            reagent.Enabled = !reagent.Enabled;
            // TODO: SaveReagentSettings();
            RefreshReactions();
        }

        // Reagent view handling
        private void RenderReagentToggle(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            Reagent reagent = (Reagent)model.GetValue(iter, 0);
            Gtk.CellRendererToggle toggle = (cell as Gtk.CellRendererToggle);
            toggle.Active = reagent.Enabled;
            toggle.Activatable = !reagent.IsCatalyst;
            toggle.Mode = reagent.IsCatalyst ? Gtk.CellRendererMode.Inert : Gtk.CellRendererMode.Activatable;
        }

        void SetupReagentList()
        {
            // initialize reagent list
            reagentListStore = new Gtk.ListStore(typeof(Reagent), typeof(string), typeof(Reagent), typeof(Reagent));
            foreach (string reagentName in ReagentManager.Names)
            {
                Reagent reagent = ReagentManager.GetReagent(reagentName);
                reagentListStore.AppendValues(reagent, reagentName); // , reagent, reagent);
            }

            // Add the columns to the TreeView
            Gtk.TreeViewColumn reagentEnabledColumn = new Gtk.TreeViewColumn();
            reagentEnabledColumn.Title = "Enabled";
            Gtk.CellRendererToggle reagentEnabledCell = new Gtk.CellRendererToggle();
            reagentEnabledCell.Activatable = true;
            reagentEnabledCell.Sensitive = true;
            reagentEnabledCell.Mode = Gtk.CellRendererMode.Activatable;
            reagentEnabledCell.Visible = true;
            reagentEnabledCell.Toggled += new Gtk.ToggledHandler(OnReagentToggled);
            reagentEnabledColumn.PackStart(reagentEnabledCell, true);
            //reagentEnabledColumn.AddAttribute(reagentEnabledCell, "active", 0);

            Gtk.TreeViewColumn reagentNameColumn = new Gtk.TreeViewColumn();
            reagentNameColumn.Title = "Ingredient";
            Gtk.CellRendererText reagentNameCell = new Gtk.CellRendererText();
            reagentNameCell.Mode = Gtk.CellRendererMode.Inert;
            reagentNameColumn.PackStart(reagentNameCell, true);
            reagentNameColumn.AddAttribute(reagentNameCell, "text", 1);
            reagentNameColumn.Expand = true;

            reagentListStore = new Gtk.ListStore(typeof(Reagent), typeof(string), typeof(Reagent), typeof(Reagent));
            foreach (string reagentName in ReagentManager.Names)
            {
                Reagent reagent = ReagentManager.GetReagent(reagentName);
                reagentListStore.AppendValues(reagent, reagentName); // , reagent, reagent);
            }

            reagentEnabledColumn.SetCellDataFunc(reagentEnabledCell, new Gtk.TreeCellDataFunc(RenderReagentToggle));

            // Assign the model to the TreeView
            reagentListView.Model = reagentListStore;
            reagentListView.Sensitive = true;

            reagentListView.AppendColumn(reagentEnabledColumn);
            reagentListView.AppendColumn(reagentNameColumn);
        }
    }
}