Files
@ 279cf14eb87c
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/ReactionStatusWindow.cs
279cf14eb87c
6.9 KiB
text/x-csharp
Update README to link to latest 9.0.5
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 | 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);
}
}
}
|