Files @ 41381c24d35a
Branch filter:

Location: ATITD-Tools/Desert-Paint-Lab/ReagentWindow.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.
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
2040107278aa
using System;
using System.Collections.Generic;

namespace DesertPaintLab
{
    public partial class ReagentWindow : Gtk.Window
    {
        private class ReagentCheckButton : Gtk.CheckButton
        {
            private Reagent reagent;
            public Reagent Reagent
            {
                get {
                    return reagent;
                }
                set {
                    reagent = value;
                }
            }
        }
        private class ReagentEntry : Gtk.Entry
        {
            private Reagent reagent;
            public Reagent Reagent
            {
                get {
                    return reagent;
                }
                set {
                    reagent = value;
                }
            }

            // public ReagentEntry(int size) : base(size)
            //{
            //}

            override protected void OnTextInserted(string text, ref int position)
            {
                uint val;
                if (uint.TryParse(text, out val))
                {
                    base.OnTextInserted(text, ref position);
                }
            }
        }

        bool dirty = false;
        PlayerProfile profile;

        SortedDictionary<string, ReagentCheckButton> ingredientCheckButtons = new SortedDictionary<string, ReagentCheckButton>();
        SortedDictionary<string, ReagentEntry> ingredientCostEntries = new SortedDictionary<string, ReagentEntry>();
        SortedDictionary<string, ReagentEntry> ingredientQuantityEntries = new SortedDictionary<string, ReagentEntry>();
        int numReagents = 14;
        public ReagentWindow(PlayerProfile profile)
            : base(Gtk.WindowType.Toplevel)
        {
            this.profile = profile;
            this.Build();

            numReagents = ReagentManager.Names.Count;
            ingredientTable.NRows = (uint)numReagents;
            ingredientTable.NColumns = 4;
            uint row = 0;
            foreach (string reagentName in ReagentManager.Names)
            {
                Reagent reagent = ReagentManager.GetReagent(reagentName);
                ReagentCheckButton checkButton = new ReagentCheckButton();
                checkButton.Active = reagent.Enabled;
                checkButton.Reagent = reagent;
                checkButton.Toggled += OnEnableToggled;
                ingredientCheckButtons.Add(reagentName, checkButton);
                ingredientTable.Attach(checkButton, 0, 1, row, row+1); // checkbox for enabled
                ingredientTable.Attach(new Gtk.Label(reagentName), 1, 2, row, row+1); // name label
                ReagentEntry costEntry = new ReagentEntry();
                costEntry.MaxLength = 6;
                costEntry.WidthChars = 6;
                costEntry.Text = reagent.Cost.ToString();
                // TODO: set up validator
                // TODO: set up event handler for changed
                costEntry.Reagent = reagent;
                costEntry.TextDeleted += OnCostChanged;
                costEntry.TextInserted += OnCostChanged;
                ingredientCostEntries.Add(reagentName, costEntry);
                ingredientTable.Attach(costEntry, 2, 3, row, row+1); // cost input
                ReagentEntry maxQuantityEntry = new ReagentEntry();
                maxQuantityEntry.Text = reagent.RecipeMax.ToString();
                maxQuantityEntry.MaxLength = 4;
                maxQuantityEntry.WidthChars = 4;
                // TODO: set up validator
                // TODO: set up event handler for changed
                maxQuantityEntry.Reagent = reagent;
                if (reagent.IsCatalyst)
                {
                    maxQuantityEntry.Sensitive = false;
                }
                else
                {
                    maxQuantityEntry.TextDeleted += OnQuantityChanged;
                    maxQuantityEntry.TextInserted += OnQuantityChanged;
                }
                ingredientQuantityEntries.Add(reagentName, maxQuantityEntry);
                ingredientTable.Attach(maxQuantityEntry, 3, 4, row, row+1); // maximum quantity input
                ++row;
            }

            okButton.Clicked += OnOK;
            cancelButton.Clicked += OnCancel;
            ShowAll();
        }

        private void OnCostChanged(object o, EventArgs args)
        {
            ReagentEntry costEntry = (ReagentEntry)o;
            uint newCost;
            if (uint.TryParse(costEntry.Text, out newCost))
            {
                if (costEntry.Reagent.Cost != newCost)
                {
                    dirty = true;
                }
            }
        }

        private void OnQuantityChanged(object o, EventArgs args)
        {
            ReagentEntry qtyEntry = (ReagentEntry)o;
            uint newCost;
            if (uint.TryParse(qtyEntry.Text, out newCost))
            {
                if (qtyEntry.Reagent.Cost != newCost)
                {
                    dirty = true;
                }
            }
        }

        private void OnEnableToggled(object o, EventArgs args)
        {
            ReagentCheckButton btn = (ReagentCheckButton)o;
            if (btn.Active != btn.Reagent.Enabled)
            {
                dirty = true;
            }
        }

        private void OnOK(object obj, EventArgs args)
        {
            if (dirty)
            {
                // save out state
                foreach (string reagentName in ReagentManager.Names)
                {
                    ReagentCheckButton checkButton = ingredientCheckButtons[reagentName];
                    ReagentEntry costEntry = ingredientCostEntries[reagentName];
                    ReagentEntry qtyEntry = ingredientQuantityEntries[reagentName];
                    checkButton.Reagent.Enabled = checkButton.Active;
                    uint val;
                    if (uint.TryParse(costEntry.Text, out val))
                    {
                        costEntry.Reagent.Cost = val;
                    }
                    if (uint.TryParse(qtyEntry.Text, out val))
                    {
                        qtyEntry.Reagent.RecipeMax = val;
                    }
                }

                ReagentManager.SaveProfileReagents(profile.ReagentFile);
            }
            this.Destroy();
        }

        private void OnCancel(object obj, EventArgs args)
        {
            this.Destroy();
        }
    }
}