Files
@ 41381c24d35a
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/ReagentWindow.cs - annotation
41381c24d35a
6.3 KiB
text/x-csharp
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | 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();
}
}
}
|