Decompiled source of DSP Helmod v1.4.5

DSP_Helmod.dll

Decompiled 11 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using BepInEx;
using BepInEx.Configuration;
using DSP_Helmod.Classes;
using DSP_Helmod.Converter;
using DSP_Helmod.Helpers;
using DSP_Helmod.Math;
using DSP_Helmod.Model;
using DSP_Helmod.UI;
using DSP_Helmod.UI.Core;
using DSP_Helmod.UI.Editions;
using DSP_Helmod.UI.Gui;
using DSP_Helmod.UI.Selectors;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DSP")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DSP")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3a06bd16-899e-4722-9285-6c035d6d297a")]
[assembly: AssemblyFileVersion("1.4.5.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
public class ExampleClass : MonoBehaviour
{
	public Rect windowRect0 = new Rect(20f, 20f, 120f, 50f);

	public Rect windowRect1 = new Rect(20f, 100f, 120f, 50f);

	public void OnGUI()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Expected O, but got Unknown
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		GUI.color = Color.red;
		windowRect0 = GUI.Window(0, windowRect0, new WindowFunction(DoMyWindow), "Red Window");
		GUI.color = Color.green;
		windowRect1 = GUI.Window(1, windowRect1, new WindowFunction(DoMyWindow), "Green Window");
	}

	private void DoMyWindow(int windowID)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if (GUI.Button(new Rect(10f, 20f, 100f, 20f), "Hello World"))
		{
			Color color = GUI.color;
			MonoBehaviour.print((object)("Got a click in window with color " + ((object)(Color)(ref color)).ToString()));
		}
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 10000f));
	}
}
namespace DSP_Helmod
{
	[BepInPlugin("helmod.dsp.plugin", "DSP Helmod Plug-In", "1.4.3")]
	public class HelmodPlugin : BaseUnityPlugin
	{
		public static string PluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		private UIController uiController = new UIController();

		internal void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("helmod.dsp.plugin").PatchAll();
			Settings.Instance.Init();
			Language.Load();
		}

		private void Start()
		{
		}

		private void Update()
		{
			uiController.Update();
		}

		private void OnGUI()
		{
			uiController.OnGUI();
		}

		private void Save()
		{
		}
	}
}
namespace DSP_Helmod.UI
{
	internal class ChooseRecipe : HMForm
	{
		private Nodes nodes;

		private IItem item;

		public ChooseRecipe(UIController parent)
			: base(parent)
		{
			name = "Choose Recipe";
			Caption = "Choose Recipe";
		}

		public override void OnDoWindow()
		{
			DrawHeader();
			DrawContent();
		}

		public override void OnInit()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			windowRect0 = new Rect(300f, 200f, 900f, 400f);
		}

		public override void OnUpdate()
		{
		}

		private void DrawHeader()
		{
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxHeight(25f) });
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnRecipe);
			GUILayout.Label("Recipe", HMStyle.TextAlignMiddleCenter, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnMachine);
			GUILayout.Label("Machine", HMStyle.TextAlignMiddleCenter, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnProducts);
			GUILayout.Label("Product", HMStyle.TextAlignMiddleCenter, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnIngredients);
			GUILayout.Label("Ingredient", HMStyle.TextAlignMiddleCenter, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.EndHorizontal();
		}

		private void DrawContent()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, HMLayoutOptions.ScrollChoose);
			if (item != null)
			{
				foreach (IRecipe item in Database.SelectRecipeByProduct(item))
				{
					DrawRecipe(item);
				}
			}
			GUILayout.EndScrollView();
		}

		public void DrawRecipe(IRecipe recipe)
		{
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxHeight(70f) });
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnRecipe);
			HMCell.Node(recipe, null, delegate
			{
				HMEvent.SendEvent(this, new HMEvent(HMEventType.ChooseRecipe, recipe));
			});
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnMachine);
			HMCell.Product(recipe.Factory);
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnProducts);
			foreach (IItem product in recipe.Products)
			{
				HMCell.ItemProduct(product, product.Count);
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnIngredients);
			foreach (IItem ingredient in recipe.Ingredients)
			{
				HMCell.ItemIngredient(ingredient, ingredient.Count);
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.EndHorizontal();
		}

		public void OnEvent(object sender, HMEvent e)
		{
			if (e.Type == HMEventType.SwitchChooseRecipe)
			{
				nodes = (Nodes)sender;
				item = e.GetItem<IItem>();
				SwitchShow();
			}
		}

		public override void OnClose()
		{
		}
	}
	public class AboutPanel : HMForm
	{
		protected SectionAbout selection;

		protected Dictionary<string, string> abouts = new Dictionary<string, string>();

		public AboutPanel(UIController parent)
			: base(parent)
		{
			name = "About";
			Caption = "About";
		}

		public override void OnDoWindow()
		{
			DrawMenu();
			DrawContent();
		}

		public override void OnInit()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			windowRect0 = new Rect(200f, 20f, 600f, 700f);
			abouts.Add("Mode", PluginInfo.Instance.name);
			abouts.Add("Version", PluginInfo.Instance.version_number);
			abouts.Add("Description", PluginInfo.Instance.description);
			abouts.Add("Url", PluginInfo.Instance.website_url);
		}

		public override void OnUpdate()
		{
		}

		private void DrawMenu()
		{
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MaxHeight(20f),
				GUILayout.Width(80f)
			});
			foreach (SectionAbout value in Enum.GetValues(typeof(SectionAbout)))
			{
				if (GUILayout.Button(value.ToString(), Array.Empty<GUILayoutOption>()))
				{
					selection = value;
				}
			}
			GUILayout.EndHorizontal();
		}

		private void DrawContent()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUI.skin.box);
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			switch (selection)
			{
			case SectionAbout.About:
				DrawAbout();
				break;
			case SectionAbout.ChangeLog:
				DrawChangeLog();
				break;
			}
			GUILayout.EndVertical();
			GUILayout.EndScrollView();
		}

		private void DrawAbout()
		{
			foreach (KeyValuePair<string, string> about in abouts)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label($"{about.Key:30}:{about.Value}", Array.Empty<GUILayoutOption>());
				GUILayout.EndHorizontal();
			}
		}

		private void DrawChangeLog()
		{
			GUILayout.Label(LoadAssembly.ReadEmbeddedRessourceString("changelog"), Array.Empty<GUILayoutOption>());
		}

		public void OnEvent(object sender, HMEvent e)
		{
		}

		public override void OnClose()
		{
		}
	}
	public enum SectionAbout
	{
		About,
		ChangeLog
	}
	public class PropertiesPanel : HMForm
	{
		private List<object> elements = new List<object>();

		protected int toolbarInt = -1;

		protected List<HMForm> toolbarForms;

		protected List<PropertyData> attributeTypes = new List<PropertyData>();

		protected Dictionary<object, Dictionary<string, PropertyData>> datas = new Dictionary<object, Dictionary<string, PropertyData>>();

		protected bool displayNull;

		public PropertiesPanel(UIController parent)
			: base(parent)
		{
			name = "Properties Panel";
			Caption = "Properties Panel";
			IsTool = true;
		}

		public override void OnDoWindow()
		{
			DrawMenu();
			DrawContent();
		}

		public override void OnInit()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			windowRect0 = new Rect(500f, 200f, 1400f, 650f);
		}

		public override void OnUpdate()
		{
		}

		private void DrawMenu()
		{
			if (parent.Forms == null)
			{
				return;
			}
			toolbarForms = new List<HMForm>();
			List<string> list = new List<string>();
			foreach (HMForm form in parent.Forms)
			{
				if ((Object)(object)form != (Object)(object)this && form.IsTool)
				{
					toolbarForms.Add(form);
					list.Add(form.Name);
				}
			}
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxHeight(20f) });
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			toolbarInt = GUILayout.Toolbar(toolbarInt, list.ToArray(), Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			if (GUILayout.Button(displayNull ? "Null On" : "Null Off", Array.Empty<GUILayoutOption>()))
			{
				displayNull = !displayNull;
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			if (toolbarInt > -1)
			{
				toolbarForms[toolbarInt].SwitchShow(SelectorMode.Properties);
				toolbarInt = -1;
			}
		}

		private void DrawContent()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (elements.Count <= 0)
			{
				return;
			}
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			foreach (PropertyData item in attributeTypes.Where((PropertyData attr) => attr.Name == "name"))
			{
				List<PropertyData> list = new List<PropertyData>();
				bool flag = true;
				foreach (KeyValuePair<object, Dictionary<string, PropertyData>> data in datas)
				{
					Dictionary<string, PropertyData> value = data.Value;
					if (value.ContainsKey(item.Name))
					{
						PropertyData propertyData = value[item.Name];
						list.Add(propertyData);
						flag &= propertyData.IsNull;
					}
					else
					{
						list.Add(null);
						flag = flag;
					}
				}
				if (!flag || (displayNull && flag))
				{
					DrawRowButton(item, list);
				}
			}
			foreach (PropertyData item2 in attributeTypes.Where((PropertyData attr) => attr.Name != "name"))
			{
				List<PropertyData> list2 = new List<PropertyData>();
				bool flag2 = true;
				foreach (KeyValuePair<object, Dictionary<string, PropertyData>> data2 in datas)
				{
					Dictionary<string, PropertyData> value2 = data2.Value;
					if (value2.ContainsKey(item2.Name))
					{
						PropertyData propertyData2 = value2[item2.Name];
						list2.Add(propertyData2);
						flag2 &= propertyData2.IsNull;
					}
					else
					{
						list2.Add(null);
						flag2 = flag2;
					}
				}
				if (!flag2 || (displayNull && flag2))
				{
					DrawRow(item2, list2);
				}
			}
			GUILayout.EndVertical();
			GUILayout.EndScrollView();
		}

		private void DrawRow(PropertyData attributeType, List<PropertyData> rowData)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			foreach (PropertyData rowDatum in rowData)
			{
				string value = ((rowDatum != null && rowDatum.Value != null) ? rowDatum.Value.ToString() : "null");
				DrawColumns(attributeType.Name, value);
			}
			GUILayout.EndHorizontal();
		}

		private void DrawColumns(string name, string value)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			GUILayout.Label(name, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			GUILayout.Label(value, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.EndHorizontal();
		}

		private void DrawRowButton(PropertyData attributeType, List<PropertyData> rowData)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			foreach (PropertyData rowDatum in rowData)
			{
				DrawButton(rowDatum.Element, attributeType.Name, rowDatum.Value.ToString());
			}
			GUILayout.EndHorizontal();
		}

		private void DrawButton(object element, string name, string value)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			GUILayout.Label(name, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			if (GUILayout.Button(value, Array.Empty<GUILayoutOption>()))
			{
				HMEventQueue.EnQueue(this, new HMEvent(HMEventType.RemoveProperties, element));
			}
			GUILayout.EndHorizontal();
			GUILayout.EndHorizontal();
		}

		public void OnEvent(object sender, HMEvent e)
		{
			switch (e.Type)
			{
			case HMEventType.AddProperties:
				elements.Add(e.Item);
				PrepareData();
				break;
			case HMEventType.RemoveProperties:
				elements.Remove(e.Item);
				PrepareData();
				break;
			}
		}

		public override void OnClose()
		{
		}

		private void PrepareData()
		{
			datas.Clear();
			attributeTypes.Clear();
			foreach (object element in elements)
			{
				Dictionary<string, PropertyData> dictionary = PrepareData(element);
				if (datas.ContainsKey(element))
				{
					continue;
				}
				datas.Add(element, dictionary);
				foreach (KeyValuePair<string, PropertyData> item in dictionary)
				{
					attributeTypes.Add(new PropertyData
					{
						Name = item.Value.Name,
						Type = item.Value.Type
					});
				}
			}
			attributeTypes.Sort();
			attributeTypes = attributeTypes.Distinct().ToList();
		}

		private Dictionary<string, PropertyData> PrepareData(object element)
		{
			Dictionary<string, PropertyData> dictionary = new Dictionary<string, PropertyData>();
			MemberInfo[] members = element.GetType().GetMembers();
			for (int i = 0; i < members.Length; i++)
			{
				PropertyData propertyData = new PropertyData();
				MemberInfo memberInfo = members[i];
				propertyData.Element = element;
				propertyData.Name = memberInfo.Name;
				propertyData.Type = memberInfo.MemberType.ToString();
				object obj = null;
				try
				{
					obj = element.GetType().InvokeMember(propertyData.Name, BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty, null, element, null);
				}
				catch
				{
				}
				if (!(obj is Array array))
				{
					PrefabDesc val = (PrefabDesc)((obj is PrefabDesc) ? obj : null);
					if (val == null)
					{
						ItemProto val2 = (ItemProto)((obj is ItemProto) ? obj : null);
						if (val2 == null)
						{
							RecipeProto val3 = (RecipeProto)((obj is RecipeProto) ? obj : null);
							if (val3 == null)
							{
								TechProto val4 = (TechProto)((obj is TechProto) ? obj : null);
								if (val4 != null)
								{
									propertyData.Value = PrepareString(val4);
								}
								else
								{
									propertyData.Value = obj;
								}
							}
							else
							{
								propertyData.Value = PrepareString(val3);
							}
						}
						else
						{
							propertyData.Value = PrepareString(val2);
						}
					}
					else
					{
						propertyData.Value = PrepareString(val);
					}
				}
				else
				{
					propertyData.Value = "";
					for (int j = 0; j < array.Length; j++)
					{
						object value = array.GetValue(j);
						if (value != null)
						{
							propertyData.Value = propertyData.Value?.ToString() + value.ToString() + ",";
						}
					}
				}
				dictionary.Add(propertyData.Name, propertyData);
			}
			return dictionary;
		}

		private string PrepareString(object element)
		{
			StringBuilder stringBuilder = new StringBuilder();
			if (element != null)
			{
				SortedDictionary<string, string> sortedDictionary = new SortedDictionary<string, string>();
				MemberInfo[] members = element.GetType().GetMembers();
				foreach (MemberInfo memberInfo in members)
				{
					object obj = null;
					try
					{
						obj = element.GetType().InvokeMember(memberInfo.Name, BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty, null, element, null);
					}
					catch
					{
					}
					if (obj == null)
					{
						continue;
					}
					string text = "";
					if (obj is Array array)
					{
						for (int j = 0; j < array.Length; j++)
						{
							object value = array.GetValue(j);
							if (value != null)
							{
								text = text + value.ToString() + ",";
							}
						}
					}
					else
					{
						text = obj.ToString();
					}
					sortedDictionary.Add(memberInfo.Name, text);
				}
				foreach (KeyValuePair<string, string> item in sortedDictionary)
				{
					if (item.Value != "" && item.Value != "0")
					{
						stringBuilder.AppendLine(item.Key + ":" + item.Value);
					}
				}
			}
			return stringBuilder.ToString();
		}
	}
	public class PropertyData : IEquatable<PropertyData>, IComparable<PropertyData>
	{
		public object Element;

		public string Name;

		public object Value;

		public string Type;

		public bool IsNull => Value == null;

		public bool Equals(PropertyData other)
		{
			if (Name.Equals(other.Name))
			{
				return Type.Equals(other.Type);
			}
			return false;
		}

		public int CompareTo(PropertyData other)
		{
			if (other == null)
			{
				return 1;
			}
			return Name.CompareTo(other.Name);
		}

		public override int GetHashCode()
		{
			return Name.GetHashCode() ^ Type.GetHashCode();
		}

		public override string ToString()
		{
			return $"{Name}:{Type}:{Value}";
		}
	}
	public class MainTooltip : HMTooltip
	{
		private Regex RecipeRegex = new Regex("Recipe:([a-zA-Z]*)=([0-9]*)", RegexOptions.IgnoreCase);

		public MainTooltip(UIController parent)
			: base(parent)
		{
		}

		public override void OnInit()
		{
		}

		public override void OnDoWindow(string tooltip)
		{
			try
			{
				GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (tooltip.StartsWith("Action:"))
				{
					GUILayout.BeginVertical(HMStyle.BoxTooltip, Array.Empty<GUILayoutOption>());
					GUILayout.Label(tooltip.Substring(tooltip.IndexOf(':') + 1), Array.Empty<GUILayoutOption>());
					GUILayout.EndVertical();
				}
				else if (tooltip.StartsWith("Recipe:"))
				{
					GUILayout.BeginVertical(HMStyle.BoxTooltip, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Height(50f),
						GUILayout.Width(250f)
					});
					DrawRecipeRegex(tooltip);
					GUILayout.EndVertical();
				}
				else
				{
					GUILayout.BeginVertical(HMStyle.BoxTooltip, Array.Empty<GUILayoutOption>());
					GUILayout.Label(tooltip, Array.Empty<GUILayoutOption>());
					GUILayout.EndVertical();
				}
				GUILayout.EndHorizontal();
				GUILayout.EndVertical();
			}
			catch (Exception ex)
			{
				Debug.LogException(ex);
			}
		}

		private void DrawRecipeRegex(string tooltip)
		{
			try
			{
				Match match = RecipeRegex.Match(tooltip);
				if (match.Success)
				{
					string value = match.Groups[1].Captures[0].Value;
					int.TryParse(match.Groups[2].Captures[0].Value, out var result);
					IRecipe recipe = Database.SelectRecipe(value, result);
					if (recipe != null)
					{
						DrawRecipe(recipe);
					}
				}
			}
			catch
			{
			}
		}

		private void DrawRecipeSplit(string tooltip)
		{
			try
			{
				string[] array = tooltip.Split(new char[1] { ':' })[1].Split(new char[1] { '=' });
				string type = array[0];
				int.TryParse(array[1], out var result);
				IRecipe recipe = Database.SelectRecipe(type, result);
				if (recipe != null)
				{
					DrawRecipe(recipe);
				}
			}
			catch
			{
			}
		}

		private void DrawRecipe(IRecipe irecipe)
		{
			if (irecipe == null)
			{
				return;
			}
			DrawCell(irecipe.Icon, irecipe.Name);
			DrawCell(HMTexture.time, $"{irecipe.Energy}s");
			if (irecipe.Products.Count > 0)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label("Products:", Array.Empty<GUILayoutOption>());
				GUILayout.EndHorizontal();
				foreach (IItem product in irecipe.Products)
				{
					DrawCell(product.Icon, $"x{product.Count}: {product.Name}");
				}
			}
			if (irecipe.Ingredients.Count > 0)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label("Ingredients:", Array.Empty<GUILayoutOption>());
				GUILayout.EndHorizontal();
				foreach (IItem ingredient in irecipe.Ingredients)
				{
					DrawCell(ingredient.Icon, $"x{ingredient.Count}: {ingredient.Name}");
				}
			}
			if (irecipe.Factories.Count <= 0)
			{
				return;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Made in:", Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			foreach (Factory factory in irecipe.Factories)
			{
				GUILayout.Box((Texture)(object)((IItem)factory).Icon, HMLayoutOptions.Icon30);
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
		}

		private void DrawCell(Texture2D icon, string label)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			try
			{
				GUILayout.Box((Texture)(object)icon, HMLayoutOptions.Icon30);
				GUILayout.Label(label, Array.Empty<GUILayoutOption>());
			}
			catch
			{
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
		}
	}
	public class TopMenu : HMForm
	{
		private int length;

		public TopMenu(UIController parent)
			: base(parent)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Show = true;
			windowRect0 = new Rect(20f, 20f, 120f, (float)(50 + 25 * length));
			WindowButtons = false;
			BackgroundColor = Color.black;
		}

		public override void OnInit()
		{
			IsPersistant = true;
		}

		public override void OnUpdate()
		{
		}

		public override void OnDoWindow()
		{
			HMButton.Action("Open/Close", delegate
			{
				HMEvent.SendEvent(this, new HMEvent(HMEventType.OpenClose, typeof(MainPanel)));
			});
			if (length > 0)
			{
				HMButton.Action("Properties", delegate
				{
					HMEvent.SendEvent(this, new HMEvent(HMEventType.OpenClose, typeof(PropertiesPanel)));
				});
			}
		}

		public void OnEvent(object sender, HMEvent e)
		{
		}

		public override void OnClose()
		{
		}
	}
	public class MainPanel : HMForm
	{
		protected ERecipeType groupSelected;

		protected string recipeSelected;

		protected int selection;

		protected int toolbarInt = -1;

		protected List<HMForm> toolbarForms;

		protected List<RecipeProto> recipes = new List<RecipeProto>();

		protected Nodes currentSheet;

		protected Nodes currentNode;

		protected Vector2 ScrollOutputPosition;

		protected Vector2 ScrollInputPosition;

		protected Vector2 ScrollNavPosition;

		protected int timeSelected;

		protected string[] timesString = new string[3] { "1s", "1mn", "1h" };

		public MainPanel(UIController parent)
			: base(parent)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			name = "DSP Helmod V" + PluginInfo.Instance.version_number;
			windowRect0 = new Rect(500f, 200f, 1400f, 650f);
			AlphaButtons = true;
		}

		public override void OnInit()
		{
		}

		public override void OnUpdate()
		{
			if (currentSheet != null && currentSheet.TimeSelected != timeSelected)
			{
				currentSheet.TimeSelected = timeSelected;
				Compute();
			}
		}

		public override void OnDoWindow()
		{
			DrawContent();
		}

		private void DrawContent()
		{
			DrawMenuSheet();
			DrawMenu();
			DrawData();
		}

		private void DrawMenuSheet()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			new GUIStyle(GUI.skin.label).alignment = (TextAnchor)8;
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MaxHeight(50f),
				GUILayout.MinHeight(50f)
			});
			if (Database.DataModel != null)
			{
				int num = 0;
				foreach (Nodes sheet in Database.DataModel.Sheets)
				{
					if (num % 15 == 0)
					{
						GUILayout.EndHorizontal();
						GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.MaxHeight(50f),
							GUILayout.MinHeight(50f)
						});
					}
					GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.MaxWidth(50f),
						GUILayout.MaxWidth(50f)
					});
					if (currentSheet == sheet)
					{
						GUI.color = Color.yellow;
					}
					HMButton.Sheet(sheet, SetCurrentSheet);
					GUI.color = Color.white;
					GUILayout.EndHorizontal();
					num++;
				}
			}
			if (GUILayout.Button("New", HMStyle.ButtonIcon, HMLayoutOptions.Icon45))
			{
				CreateNewSheet();
			}
			GUILayout.EndHorizontal();
		}

		private void DrawMenu()
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			if (parent.Forms == null)
			{
				return;
			}
			toolbarForms = new List<HMForm>();
			List<string> list = new List<string>();
			foreach (HMForm form in parent.Forms)
			{
				if (form.InMain)
				{
					toolbarForms.Add(form);
					list.Add(form.Name);
				}
			}
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxHeight(20f) });
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			toolbarInt = GUILayout.Toolbar(toolbarInt, list.ToArray(), Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			HMButton.Action("Refresh", delegate
			{
				Compute();
			});
			HMButton.Action("Delete", delegate
			{
				DeleteSheet();
			});
			GUILayout.FlexibleSpace();
			if (Settings.Instance.DisplayTotal)
			{
				GUI.color = Color.yellow;
			}
			HMButton.Action("Total", delegate
			{
				Settings.Instance.DisplayTotal = !Settings.Instance.DisplayTotal;
			});
			GUI.color = Color.white;
			HMButton.Action("Logistic", delegate
			{
				Settings.Instance.DisplayLogistic = !Settings.Instance.DisplayLogistic;
			});
			if (Settings.Instance.DisplayLogistic)
			{
				foreach (Item logisticItem in Database.LogisticItems)
				{
					if (logisticItem.Id == Settings.Instance.ItemIdLogistic)
					{
						GUI.color = Color.yellow;
					}
					HMButton.IconLogistic(logisticItem, delegate(IItem element)
					{
						HMEventQueue.EnQueue(this, new HMEvent(HMEventType.ChangeLogisticItem, element));
					});
					GUI.color = Color.white;
				}
			}
			GUILayout.FlexibleSpace();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Base time:", Array.Empty<GUILayoutOption>());
			timeSelected = GUILayout.Toolbar(timeSelected, timesString.ToArray(), Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.EndHorizontal();
			if (toolbarForms != null && toolbarInt > -1)
			{
				toolbarForms[toolbarInt].SwitchShow();
				toolbarInt = -1;
			}
		}

		private void DrawData()
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			DrawNavigate();
			DrawTable();
			DrawDetail();
			GUILayout.EndHorizontal();
		}

		private void DrawNavigate()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			ScrollNavPosition = GUILayout.BeginScrollView(ScrollNavPosition, HMLayoutOptions.ScrollNav);
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			if (currentSheet != null)
			{
				if (currentNode == currentSheet)
				{
					GUI.color = Color.yellow;
				}
				HMCell.Node(currentSheet, Language.Get("open.sheet"), delegate(INode element)
				{
					SetCurrentNodes((Nodes)element);
				});
				GUI.color = Color.white;
				DrawNavigate(currentSheet);
			}
			else
			{
				GUILayout.Label("", Array.Empty<GUILayoutOption>());
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndVertical();
			GUILayout.EndScrollView();
		}

		private void DrawNavigate(Nodes nodes)
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (nodes == null || nodes.Children == null || nodes.Children.Count <= 0)
			{
				return;
			}
			int num = 1;
			List<INode> list = nodes.Children.Where((INode item) => item is Nodes).ToList();
			foreach (Node item in list)
			{
				if (item is Nodes)
				{
					if (num == list.Count)
					{
						GUILayout.BeginHorizontal(HMStyle.BoxNavigateTreeLeaf, Array.Empty<GUILayoutOption>());
					}
					else
					{
						GUILayout.BeginHorizontal(HMStyle.BoxNavigateTree, Array.Empty<GUILayoutOption>());
					}
					GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
					Nodes nodes2 = (Nodes)item;
					if (currentNode == nodes2)
					{
						GUI.color = Color.yellow;
					}
					HMCell.Node(item, Language.Get("open.node"), delegate(INode element)
					{
						SetCurrentNodes((Nodes)element);
					});
					GUI.color = Color.white;
					DrawNavigate(nodes2);
					GUILayout.EndVertical();
					GUILayout.EndHorizontal();
					num++;
				}
			}
		}

		private void DrawDetail()
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(HMLayoutOptions.ListDetail);
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxHeight(25f) });
			GUILayout.Label("Information", HMStyle.TextAlignMiddleCenter, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (currentNode != null)
			{
				_ = currentNode.Count;
				_ = 0.0;
				HMCell.NodePower(currentNode, currentNode.GetDeepCount(Settings.Instance.DisplayTotal) / currentNode.Count);
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxHeight(25f) });
			GUILayout.Label("Output", HMStyle.TextAlignMiddleCenter, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			ScrollOutputPosition = GUILayout.BeginScrollView(ScrollOutputPosition, HMStyle.ScrollListDetail, HMLayoutOptions.ScrollListDetail);
			if (currentNode != null && currentNode.Products != null)
			{
				HMCell.ItemProductList(currentNode, currentSheet.Time, withLogistic: true);
			}
			GUILayout.EndScrollView();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxHeight(25f) });
			GUILayout.Label("Input", HMStyle.TextAlignMiddleCenter, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			ScrollInputPosition = GUILayout.BeginScrollView(ScrollInputPosition, HMStyle.ScrollListDetail, HMLayoutOptions.ScrollListDetail);
			if (currentNode != null && currentNode.Ingredients != null)
			{
				HMCell.ItemIngredientList(currentNode, currentSheet.Time, withLogistic: true, delegate(IItem element)
				{
					HMEventQueue.EnQueue(this, new HMEvent(HMEventType.AddRecipeByIngredient, element));
				});
			}
			GUILayout.EndScrollView();
			GUILayout.EndVertical();
		}

		private void DrawTableHeader()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.alignment = (TextAnchor)4;
			GUILayout.BeginHorizontal(HMStyle.None, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxHeight(25f) });
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnAction);
			GUILayout.Label("Action", val, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnProduction);
			GUILayout.Label("%", val, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnRecipe);
			GUILayout.Label("Recipe", val, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnPower);
			GUILayout.Label("Power", val, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnMachine);
			GUILayout.Label("Machine", val, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnProducts);
			GUILayout.Label("Product", val, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.ColumnIngredients);
			GUILayout.Label("Ingredient", val, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.EndHorizontal();
		}

		private void DrawTable()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(HMStyle.None, Array.Empty<GUILayoutOption>());
			if (currentNode != null && currentNode.Children.Count > 0)
			{
				DrawTableHeader();
				bool displayLogistic = Settings.Instance.DisplayLogistic;
				new GUIStyle(GUI.skin.label).alignment = (TextAnchor)8;
				scrollPosition = GUILayout.BeginScrollView(scrollPosition, HMStyle.ScrollData, HMLayoutOptions.ScrollData);
				int count = currentNode.Children.Count;
				for (int i = 0; i < count; i++)
				{
					INode node = currentNode.Children[i];
					GUILayout.BeginHorizontal(HMStyle.None, Array.Empty<GUILayoutOption>());
					GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.GetDataCell(DataColumn.Actions, displayLogistic));
					HMCell.NodeActions(currentNode, node);
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.GetDataCell(DataColumn.Production, displayLogistic));
					node.ProductionString = GUILayout.TextField(node.ProductionString, Array.Empty<GUILayoutOption>());
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.GetDataCell(DataColumn.Recipe, displayLogistic));
					HMCell.Node(node, currentNode.GetDeepCount(Settings.Instance.DisplayTotal), Language.Get("edition.recipe"), delegate(INode element)
					{
						if (element is IRecipe)
						{
							HMEventQueue.EnQueue(currentNode, new HMEvent(HMEventType.EditionRecipe, element));
						}
					});
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.GetDataCell(DataColumn.Power, displayLogistic));
					HMCell.NodePower(node, currentNode.GetDeepCount(Settings.Instance.DisplayTotal), delegate
					{
						if (node is IRecipe)
						{
							HMEventQueue.EnQueue(currentNode, new HMEvent(HMEventType.EditionRecipe, node));
						}
					});
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.GetDataCell(DataColumn.Machine, displayLogistic));
					if (node is IRecipe)
					{
						HMCell.Product(((IRecipe)node).Factory, currentNode.GetDeepCount(Settings.Instance.DisplayTotal), delegate
						{
							HMEventQueue.EnQueue(currentNode, new HMEvent(HMEventType.EditionRecipe, node));
						});
					}
					else
					{
						GUILayout.Label("", Array.Empty<GUILayoutOption>());
					}
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.GetDataCell(DataColumn.Products, displayLogistic));
					GUILayout.BeginVertical(HMStyle.None, Array.Empty<GUILayoutOption>());
					GUILayout.BeginHorizontal(HMStyle.None, Array.Empty<GUILayoutOption>());
					int num = 0;
					foreach (IItem product in node.Products)
					{
						if (num != 0 && num % HMLayoutOptions.numProducts == 0)
						{
							GUILayout.FlexibleSpace();
							GUILayout.EndHorizontal();
							GUILayout.BeginHorizontal(HMStyle.None, Array.Empty<GUILayoutOption>());
						}
						if (product.State != ItemState.Main && !(product.Count > 0.01))
						{
							continue;
						}
						product.Flow = product.Count * node.Effects.Productivity / (double)currentSheet.Time;
						HMCell.ItemProduct(product, node.GetItemDeepCount(Settings.Instance.DisplayTotal) * node.Effects.Productivity, withLogistic: true, delegate(IItem element)
						{
							if (element.State == ItemState.Main)
							{
								HMEventQueue.EnQueue(currentNode, new HMEvent(HMEventType.EditionProduct, element));
							}
							else
							{
								HMEventQueue.EnQueue(this, new HMEvent(HMEventType.AddRecipeByProduct, element));
							}
						});
						num++;
					}
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.EndVertical();
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(HMStyle.BoxStyle, HMLayoutOptions.GetDataCell(DataColumn.Ingredients, displayLogistic));
					GUILayout.BeginVertical(HMStyle.None, Array.Empty<GUILayoutOption>());
					GUILayout.BeginHorizontal(HMStyle.None, Array.Empty<GUILayoutOption>());
					int num2 = 0;
					foreach (IItem ingredient in node.Ingredients)
					{
						if (num2 != 0 && num2 % HMLayoutOptions.numIngredients == 0)
						{
							GUILayout.FlexibleSpace();
							GUILayout.EndHorizontal();
							GUILayout.BeginHorizontal(HMStyle.None, Array.Empty<GUILayoutOption>());
						}
						if (ingredient.State == ItemState.Main || ingredient.Count > 0.01)
						{
							ingredient.Flow = ingredient.Count / (double)currentSheet.Time;
							HMCell.ItemIngredient(ingredient, node.GetItemDeepCount(Settings.Instance.DisplayTotal), withLogistic: true, delegate(IItem element)
							{
								HMEventQueue.EnQueue(this, new HMEvent(HMEventType.AddRecipeByIngredient, element));
							});
							num2++;
						}
					}
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.EndVertical();
					GUILayout.EndHorizontal();
					GUILayout.EndHorizontal();
				}
				GUILayout.EndScrollView();
			}
			GUILayout.EndVertical();
		}

		private void CreateNewSheet()
		{
			Nodes item = new Nodes();
			Database.DataModel.Sheets.Add(item);
			SetCurrentSheet(item);
		}

		private void SetCurrentNodes(Nodes nodes)
		{
			currentNode = nodes;
		}

		private void SetCurrentSheet(Nodes sheet)
		{
			currentSheet = sheet;
			currentNode = sheet;
			switch (sheet.Time)
			{
			case 60:
				timeSelected = 1;
				break;
			case 3600:
				timeSelected = 2;
				break;
			default:
				timeSelected = 0;
				break;
			}
		}

		public void OnEvent(object sender, HMEvent e)
		{
			switch (e.Type)
			{
			case HMEventType.LoadedModel:
				if (Database.DataModel.Sheets.Count > 0)
				{
					SetCurrentSheet(Database.DataModel.Sheets.First());
				}
				else
				{
					CreateNewSheet();
				}
				break;
			case HMEventType.AddRecipe:
			{
				if (currentNode == null)
				{
					CreateNewSheet();
				}
				IRecipe item2 = e.GetItem<IRecipe>();
				AddRecipe(item2);
				break;
			}
			case HMEventType.ChooseRecipe:
			{
				if (currentNode == null)
				{
					CreateNewSheet();
				}
				IRecipe item2 = e.GetItem<IRecipe>();
				AddRecipe(item2);
				break;
			}
			case HMEventType.AddRecipeByIngredient:
			{
				Item item3 = e.GetItem<Item>();
				AddRecipe(item3);
				break;
			}
			case HMEventType.RemoveNode:
			{
				Nodes obj3 = (Nodes)sender;
				Node item = e.GetItem<Node>();
				obj3.Remove(item);
				Compute();
				break;
			}
			case HMEventType.UpdateSheet:
				Compute();
				break;
			case HMEventType.UpNode:
			{
				Nodes obj2 = (Nodes)sender;
				ListExtensions.MoveStep(item: e.GetItem<Node>(), list: obj2.Children, step: -1);
				Compute();
				break;
			}
			case HMEventType.DownNode:
			{
				Nodes obj = (Nodes)sender;
				ListExtensions.MoveStep(item: e.GetItem<Node>(), list: obj.Children, step: 1);
				Compute();
				break;
			}
			case HMEventType.ChangeLogisticItem:
			{
				Item item3 = e.GetItem<Item>();
				Settings.Instance.ItemIdLogistic = item3.Id;
				break;
			}
			case HMEventType.UpLevelNode:
			{
				Node item = e.GetItem<Node>();
				if (item.Parent != null)
				{
					item.Parent.UpLevelNode(item);
					Compute();
				}
				break;
			}
			case HMEventType.DownLevelNode:
			{
				Node item = e.GetItem<Node>();
				if (item.Parent != null)
				{
					item.Parent.DownLevelNode(item);
					Compute();
				}
				break;
			}
			case HMEventType.OpenClose:
			case HMEventType.Update:
			case HMEventType.AddRecipeByProduct:
			case HMEventType.AddItem:
			case HMEventType.SwitchChooseRecipe:
			case HMEventType.EditionProduct:
			case HMEventType.EditionRecipe:
				break;
			}
		}

		private void AddRecipe(IRecipe recipe)
		{
			IRecipe recipe2 = recipe.Clone();
			UpdateRecipeFactory(recipe2);
			currentNode.Add(recipe2);
			Compute();
		}

		private void UpdateRecipeFactory(IRecipe recipe)
		{
			if (recipe.Factories.Count > 1)
			{
				if (Settings.Instance.FactorySelection == FactorySelection.Last)
				{
					recipe.Factory = recipe.Factories.Last();
				}
				else
				{
					recipe.Factory = recipe.Factories.First();
				}
			}
		}

		private void AddRecipe(Item item)
		{
			if (item == null || item.Proto == null)
			{
				return;
			}
			List<IRecipe> list = Database.SelectRecipeByProduct(item);
			if (list != null && list.Count > 0)
			{
				if (list.Count == 1)
				{
					IRecipe recipe = list.First().Clone();
					UpdateRecipeFactory(recipe);
					currentNode.Add(recipe);
					Compute();
				}
				else
				{
					HMEvent.SendEvent(currentNode, new HMEvent(HMEventType.SwitchChooseRecipe, item));
				}
			}
		}

		private void Compute()
		{
			new Compute().Update(currentSheet);
		}

		private void ComputeAll()
		{
			Compute compute = new Compute();
			foreach (Nodes sheet in Database.DataModel.Sheets)
			{
				compute.Update(sheet);
			}
		}

		private void DeleteSheet()
		{
			Database.DataModel.Sheets.Remove(currentSheet);
			if (Database.DataModel.Sheets.Count == 0)
			{
				CreateNewSheet();
			}
			else
			{
				SetCurrentSheet(Database.DataModel.Sheets.First());
			}
		}

		public override void OnClose()
		{
			Database.SaveModel();
		}
	}
	public class UIController : MonoBehaviour
	{
		private List<HMForm> forms = new List<HMForm>();

		private MainTooltip mainTooltip;

		private int formId = 6660000;

		public Vector2 TooltipPosition;

		public string Tooltip;

		public bool loaded;

		private bool IsUpdating;

		public List<HMForm> Forms => forms;

		public UIController()
		{
			TopMenu topMenu = new TopMenu(this);
			HMEvent.Handler += topMenu.OnEvent;
			AddForm(topMenu);
			mainTooltip = new MainTooltip(this);
			MainPanel mainPanel = new MainPanel(this);
			HMEvent.Handler += mainPanel.OnEvent;
			AddForm(mainPanel);
			AboutPanel aboutPanel = new AboutPanel(this);
			HMEvent.Handler += aboutPanel.OnEvent;
			AddForm(aboutPanel);
			SelectorRecipe form = new SelectorRecipe(this);
			AddForm(form);
			EditionPreference editionPreference = new EditionPreference(this);
			HMEvent.Handler += editionPreference.OnEvent;
			AddForm(editionPreference);
			EditionProduct editionProduct = new EditionProduct(this);
			HMEvent.Handler += editionProduct.OnEvent;
			AddForm(editionProduct);
			EditionRecipe editionRecipe = new EditionRecipe(this);
			HMEvent.Handler += editionRecipe.OnEvent;
			AddForm(editionRecipe);
			ChooseRecipe chooseRecipe = new ChooseRecipe(this);
			HMEvent.Handler += chooseRecipe.OnEvent;
			AddForm(chooseRecipe);
			HMEvent.Handler += OnEvent;
		}

		private void Load()
		{
			Database.Load();
			loaded = true;
		}

		private void AddForm(HMForm form)
		{
			formId++;
			form.id = formId;
			forms.Add(form);
		}

		public void OnGUI()
		{
			if (IsUpdating || (Object)(object)DSPGame.Game == (Object)null || !DSPGame.Game.running || !GameData.InGame || !GameData.HasUI)
			{
				return;
			}
			IsUpdating = true;
			HMEventQueue.DeQueue();
			foreach (HMForm form in forms)
			{
				if (form.Show)
				{
					form.OnGUI();
				}
			}
			if (mainTooltip.Show)
			{
				mainTooltip.OnGUI();
			}
			IsUpdating = false;
		}

		public void Update()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)DSPGame.Game == (Object)null || !DSPGame.Game.running || !GameData.InGame || !GameData.HasUI)
			{
				return;
			}
			if (!loaded)
			{
				Load();
			}
			if (Input.GetKeyDown((KeyCode)27))
			{
				CloseAll();
			}
			if (Input.GetKeyDown(Settings.Instance.OpenCloseKeyCode))
			{
				MainPanel mainPanel = (MainPanel)forms.Where((HMForm form) => form is MainPanel).First();
				if (mainPanel.Show)
				{
					CloseAll();
				}
				else
				{
					mainPanel.SwitchShow();
				}
			}
			foreach (HMForm form in forms)
			{
				if (form.Show)
				{
					form.OnUpdate();
				}
			}
			mainTooltip.OnUpdate();
		}

		public void CloseAll()
		{
			foreach (HMForm form in forms)
			{
				if (!form.IsPersistant)
				{
					form.Close();
				}
			}
		}

		public void OnEvent(object sender, HMEvent e)
		{
			if (e.Type != HMEventType.OpenClose)
			{
				return;
			}
			Type item = e.GetItem<Type>();
			foreach (HMForm form in forms)
			{
				if (((object)form).GetType().Equals(item))
				{
					form.SwitchShow();
				}
			}
		}
	}
}
namespace DSP_Helmod.UI.Selectors
{
	public class SelectorStar : HMForm
	{
		protected EStarType groupSelected;

		protected string recipeSelected;

		protected int selection;

		public SelectorStar(UIController parent)
			: base(parent)
		{
			name = "Star Selector";
			Caption = "Add Star";
			IsTool = true;
		}

		public override void OnInit()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			windowRect0 = new Rect(200f, 20f, 600f, 600f);
		}

		public override void OnUpdate()
		{
		}

		public override void OnDoWindow()
		{
			DrawContent();
		}

		private Dictionary<EStarType, List<StarData>> GetItems()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EStarType, List<StarData>> dictionary = new Dictionary<EStarType, List<StarData>>();
			foreach (StarData star in GameData.Stars)
			{
				EStarType type = star.type;
				if (!dictionary.ContainsKey(type))
				{
					dictionary.Add(type, new List<StarData>());
				}
				dictionary[type].Add(star);
			}
			return dictionary;
		}

		private void DrawContent()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EStarType, List<StarData>> items = GetItems();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MaxHeight(20f),
				GUILayout.Width(80f)
			});
			foreach (EStarType key in items.Keys)
			{
				EStarType current = key;
				if (GUILayout.Button(((object)(EStarType)(ref current)).ToString(), Array.Empty<GUILayoutOption>()))
				{
					groupSelected = current;
				}
				if ((int)groupSelected == 0)
				{
					groupSelected = current;
				}
			}
			GUILayout.EndHorizontal();
			List<StarData> items2 = items[groupSelected];
			DrawElements(items2);
		}

		private void DrawElements(List<StarData> items)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUI.skin.box);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			int num = 0;
			foreach (StarData item in items)
			{
				if (num != 0 && num % 5 == 0)
				{
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
				HMButton.Text(item.name, StarHelper.GetTootip(item), 100, 25, delegate
				{
					if (selectorMode == SelectorMode.Normal)
					{
						HMEvent.SendEvent(this, new HMEvent(HMEventType.AddRecipe, item));
					}
					else if (selectorMode == SelectorMode.Properties)
					{
						HMEvent.SendEvent(this, new HMEvent(HMEventType.AddProperties, item));
					}
				});
				num++;
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.EndScrollView();
		}

		public override void OnClose()
		{
		}
	}
	public class SelectorPlanet : HMForm
	{
		protected EPlanetType groupSelected;

		protected string recipeSelected;

		protected int selection;

		public SelectorPlanet(UIController parent)
			: base(parent)
		{
			name = "Planet Selector";
			Caption = "Add Planet";
			IsTool = true;
		}

		public override void OnInit()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			windowRect0 = new Rect(200f, 20f, 600f, 600f);
		}

		public override void OnUpdate()
		{
		}

		public override void OnDoWindow()
		{
			DrawContent();
		}

		private Dictionary<EPlanetType, List<PlanetData>> GetItems()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EPlanetType, List<PlanetData>> dictionary = new Dictionary<EPlanetType, List<PlanetData>>();
			foreach (PlanetData planet in GameData.Planets)
			{
				EPlanetType type = planet.type;
				if (!dictionary.ContainsKey(type))
				{
					dictionary.Add(type, new List<PlanetData>());
				}
				dictionary[type].Add(planet);
			}
			return dictionary;
		}

		private void DrawContent()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EPlanetType, List<PlanetData>> items = GetItems();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MaxHeight(20f),
				GUILayout.Width(80f)
			});
			foreach (EPlanetType key in items.Keys)
			{
				EPlanetType current = key;
				if (GUILayout.Button(((object)(EPlanetType)(ref current)).ToString(), Array.Empty<GUILayoutOption>()))
				{
					groupSelected = current;
				}
				if ((int)groupSelected == 0)
				{
					groupSelected = current;
				}
			}
			GUILayout.EndHorizontal();
			List<PlanetData> items2 = items[groupSelected];
			DrawElements(items2);
		}

		private void DrawElements(List<PlanetData> items)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUI.skin.box);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			int num = 0;
			foreach (PlanetData item in items)
			{
				if (num != 0 && num % 5 == 0)
				{
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
				HMButton.Text(item.name, PlanetProtoHelper.GetTootip(item), 100, 25, delegate
				{
					if (selectorMode == SelectorMode.Normal)
					{
						HMEvent.SendEvent(this, new HMEvent(HMEventType.AddRecipe, item));
					}
					else if (selectorMode == SelectorMode.Properties)
					{
						HMEvent.SendEvent(this, new HMEvent(HMEventType.AddProperties, item));
					}
				});
				num++;
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.EndScrollView();
		}

		public override void OnClose()
		{
		}
	}
	public class SelectorVege : HMForm
	{
		protected EMinerType groupSelected;

		protected string recipeSelected;

		protected int selection;

		public SelectorVege(UIController parent)
			: base(parent)
		{
			name = "Vege Selector";
			Caption = "Add Vege";
			IsTool = true;
		}

		public override void OnInit()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			windowRect0 = new Rect(200f, 20f, 600f, 600f);
		}

		public override void OnUpdate()
		{
		}

		public override void OnDoWindow()
		{
			DrawContent();
		}

		private Dictionary<EMinerType, List<VegeProto>> GetItems()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EMinerType, List<VegeProto>> dictionary = new Dictionary<EMinerType, List<VegeProto>>();
			VegeProto[] dataArray = ((ProtoSet<VegeProto>)(object)LDB.veges).dataArray;
			foreach (VegeProto val in dataArray)
			{
				EMinerType minerType = val.prefabDesc.minerType;
				if (!dictionary.ContainsKey(minerType))
				{
					dictionary.Add(minerType, new List<VegeProto>());
				}
				dictionary[minerType].Add(val);
			}
			return dictionary;
		}

		private void DrawContent()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EMinerType, List<VegeProto>> items = GetItems();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MaxHeight(20f),
				GUILayout.Width(80f)
			});
			foreach (EMinerType key in items.Keys)
			{
				EMinerType current = key;
				if (GUILayout.Button(((object)(EMinerType)(ref current)).ToString(), Array.Empty<GUILayoutOption>()))
				{
					groupSelected = current;
				}
				if ((int)groupSelected == 0)
				{
					groupSelected = current;
				}
			}
			GUILayout.EndHorizontal();
			List<VegeProto> items2 = items[groupSelected];
			DrawElements(items2);
		}

		private void DrawElements(List<VegeProto> items)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUI.skin.box);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			int num = 0;
			foreach (VegeProto item in items)
			{
				if (num != 0 && num % 5 == 0)
				{
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
				HMButton.Text(((Proto)item).name, VegeProtoHelper.GetTootip(item), 100, 25, delegate
				{
					if (selectorMode == SelectorMode.Normal)
					{
						HMEvent.SendEvent(this, new HMEvent(HMEventType.AddRecipe, item));
					}
					else if (selectorMode == SelectorMode.Properties)
					{
						HMEvent.SendEvent(this, new HMEvent(HMEventType.AddProperties, item));
					}
				});
				num++;
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.EndScrollView();
		}

		public override void OnClose()
		{
		}
	}
	public class SelectorVein : HMForm
	{
		protected EMinerType groupSelected;

		protected string recipeSelected;

		protected int selection;

		public SelectorVein(UIController parent)
			: base(parent)
		{
			name = "Vein Selector";
			Caption = "Add Vein";
			IsTool = true;
		}

		public override void OnInit()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			windowRect0 = new Rect(200f, 20f, 600f, 600f);
		}

		public override void OnUpdate()
		{
		}

		public override void OnDoWindow()
		{
			DrawContent();
		}

		private Dictionary<EMinerType, List<VeinProto>> GetItems()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EMinerType, List<VeinProto>> dictionary = new Dictionary<EMinerType, List<VeinProto>>();
			VeinProto[] dataArray = ((ProtoSet<VeinProto>)(object)LDB.veins).dataArray;
			foreach (VeinProto val in dataArray)
			{
				EMinerType minerType = val.prefabDesc.minerType;
				if (!dictionary.ContainsKey(minerType))
				{
					dictionary.Add(minerType, new List<VeinProto>());
				}
				dictionary[minerType].Add(val);
			}
			return dictionary;
		}

		private void DrawContent()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EMinerType, List<VeinProto>> items = GetItems();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MaxHeight(20f),
				GUILayout.Width(80f)
			});
			foreach (EMinerType key in items.Keys)
			{
				EMinerType current = key;
				if (GUILayout.Button(((object)(EMinerType)(ref current)).ToString(), Array.Empty<GUILayoutOption>()))
				{
					groupSelected = current;
				}
				if ((int)groupSelected == 0)
				{
					groupSelected = current;
				}
			}
			GUILayout.EndHorizontal();
			List<VeinProto> items2 = items[groupSelected];
			DrawElements(items2);
		}

		private void DrawElements(List<VeinProto> items)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUI.skin.box);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			int num = 0;
			foreach (VeinProto item in items)
			{
				if (num != 0 && num % 10 == 0)
				{
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
				HMButton.Texture(item.iconSprite.texture, delegate
				{
					if (selectorMode == SelectorMode.Properties)
					{
						HMEvent.SendEvent(this, new HMEvent(HMEventType.AddProperties, item));
					}
				});
				num++;
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.EndScrollView();
		}

		public override void OnClose()
		{
		}
	}
	public class SelectorRecipe : HMForm
	{
		protected string groupSelected = "";

		protected string recipeSelected;

		protected int selection;

		public SelectorRecipe(UIController parent)
			: base(parent)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			name = "Recipe Selector";
			Caption = "Add Recipe";
			InMain = true;
			IsTool = true;
			windowRect0 = new Rect(400f, 200f, 700f, 400f);
		}

		public override void OnInit()
		{
		}

		public override void OnUpdate()
		{
		}

		public override void OnDoWindow()
		{
			DrawContent();
		}

		private void DrawContent()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			SortedDictionary<string, List<IRecipe>> recipesByGroup = Database.RecipesByGroup;
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MaxHeight(20f),
				GUILayout.Width(80f)
			});
			foreach (string key in recipesByGroup.Keys)
			{
				if (groupSelected == key)
				{
					GUI.color = Color.yellow;
				}
				if (GUILayout.Button(key.ToString(), Array.Empty<GUILayoutOption>()))
				{
					groupSelected = key;
				}
				GUI.color = Color.white;
				if (groupSelected == "")
				{
					groupSelected = key;
				}
			}
			GUILayout.EndHorizontal();
			List<IRecipe> recipes = recipesByGroup[groupSelected];
			DrawElements(recipes);
		}

		private void DrawElements(List<IRecipe> recipes)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUI.skin.box);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			int num = 0;
			foreach (IRecipe recipe in recipes)
			{
				if (num != 0 && num % 14 == 0)
				{
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
				HMButton.Node(recipe, $"Recipe:{recipe.GetType().Name}={recipe.Id}", delegate
				{
					if (selectorMode == SelectorMode.Normal)
					{
						HMEvent.SendEvent(this, new HMEvent(HMEventType.AddRecipe, recipe));
					}
					else if (selectorMode == SelectorMode.Properties)
					{
						object obj = null;
						if (recipe is Recipe)
						{
							obj = ((Recipe)recipe).Proto;
						}
						if (recipe is RecipeVein)
						{
							obj = ((RecipeVein)recipe).Proto;
						}
						if (recipe is RecipeOrbit)
						{
							obj = ((RecipeOrbit)recipe).Proto;
						}
						if (recipe is RecipeOcean)
						{
							obj = ((RecipeOcean)recipe).Proto;
						}
						if (recipe is RecipeCustom)
						{
							obj = ((RecipeCustom)recipe).Proto;
						}
						if (obj != null)
						{
							HMEvent.SendEvent(this, new HMEvent(HMEventType.AddProperties, obj));
						}
					}
				});
				num++;
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.EndScrollView();
		}

		public override void OnClose()
		{
		}
	}
	public class SelectorItem : HMForm
	{
		protected EItemType groupSelected;

		protected string recipeSelected;

		protected int selection;

		public SelectorItem(UIController parent)
			: base(parent)
		{
			name = "Item Selector";
			Caption = "Add Item";
			IsTool = true;
		}

		public override void OnInit()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			windowRect0 = new Rect(200f, 20f, 600f, 600f);
		}

		public override void OnUpdate()
		{
		}

		public override void OnDoWindow()
		{
			DrawContent();
		}

		private Dictionary<EItemType, List<ItemProto>> GetItems()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EItemType, List<ItemProto>> dictionary = new Dictionary<EItemType, List<ItemProto>>();
			ItemProto[] dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
			foreach (ItemProto val in dataArray)
			{
				EItemType type = val.Type;
				if (!dictionary.ContainsKey(type))
				{
					dictionary.Add(type, new List<ItemProto>());
				}
				dictionary[type].Add(val);
			}
			return dictionary;
		}

		private void DrawContent()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Invalid comparison between Unknown and I4
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<EItemType, List<ItemProto>> items = GetItems();
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MaxHeight(20f),
				GUILayout.Width(80f)
			});
			foreach (EItemType key in items.Keys)
			{
				EItemType current = key;
				if (GUILayout.Button(((object)(EItemType)(ref current)).ToString(), Array.Empty<GUILayoutOption>()))
				{
					groupSelected = current;
				}
				if ((int)groupSelected == 0)
				{
					groupSelected = current;
				}
			}
			GUILayout.EndHorizontal();
			List<ItemProto> items2 = items[groupSelected];
			DrawElements(items2);
			if ((int)Event.current.type == 7)
			{
				if (lastTooltip != "")
				{
					GUI.Label(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y + 20f, 200f, 200f), GUI.tooltip);
				}
				lastTooltip = GUI.tooltip;
			}
		}

		private void DrawElements(List<ItemProto> items)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUI.skin.box);
			GUIContent[] array = (GUIContent[])(object)new GUIContent[items.Count];
			Texture2D[] array2 = (Texture2D[])(object)new Texture2D[items.Count];
			int num = 0;
			foreach (ItemProto item2 in items)
			{
				Texture2D texture = item2.iconSprite.texture;
				_ = ((Proto)item2).name;
				array2[num] = texture;
				GUIContent val = new GUIContent((Texture)(object)texture, ItemProtoHelper.GetTootip(item2));
				array[num] = val;
				num++;
			}
			GUILayoutOption[] array3 = (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxWidth(450f) };
			selection = GUILayout.SelectionGrid(-1, array, 10, array3);
			if (selection != -1)
			{
				ItemProto item = items[selection];
				if (selectorMode == SelectorMode.Normal)
				{
					HMEvent.SendEvent(this, new HMEvent(HMEventType.AddItem, item));
				}
				else if (selectorMode == SelectorMode.Properties)
				{
					HMEvent.SendEvent(this, new HMEvent(HMEventType.AddProperties, item));
				}
				selection = -1;
			}
			GUILayout.EndScrollView();
		}

		public override void OnClose()
		{
		}
	}
}
namespace DSP_Helmod.UI.Gui
{
	public class HMLayoutOptions
	{
		public static int numProducts = 4;

		public static int numIngredients = 8;

		private static GUILayoutOption ColumnWidthAction = GUILayout.Width(100f);

		private static GUILayoutOption ColumnWidthProduction = GUILayout.Width(40f);

		private static GUILayoutOption ColumnWidthRecipe = GUILayout.Width(80f);

		private static GUILayoutOption ColumnWidthPower = GUILayout.Width(80f);

		private static GUILayoutOption ColumnWidthMachine = GUILayout.Width(80f);

		private static GUILayoutOption ColumnWidthProducts = GUILayout.Width((float)(5 + 47 * numProducts));

		private static GUILayoutOption ColumnWidthIngredients = GUILayout.Width((float)(5 + 47 * numIngredients));

		public static GUILayoutOption[] BoxIcon = (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(70f) };

		public static GUILayoutOption[] Icon50 = (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(50f),
			GUILayout.Width(50f)
		};

		public static GUILayoutOption[] Icon45 = (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(45f),
			GUILayout.Width(45f)
		};

		public static GUILayoutOption[] Icon30 = (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(30f),
			GUILayout.Width(30f)
		};

		public static GUILayoutOption[] Icon20 = (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(20f),
			GUILayout.Width(20f)
		};

		public static GUILayoutOption[] Icon15 = (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(15f),
			GUILayout.Width(15f)
		};

		public static GUILayoutOption[] Text45x15 = (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(15f),
			GUILayout.Width(45f)
		};

		public static GUILayoutOption[] Text30x15 = (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(15f),
			GUILayout.Width(30f)
		};

		public static GUILayoutOption[] ActionButton = (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(25f),
			GUILayout.Width(25f)
		};

		public static GUILayoutOption[] ListDetail = (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(250f) };

		public static GUILayoutOption[] ScrollListDetail = (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(170f) };

		public static GUILayoutOption[] ScrollNav = (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.ExpandHeight(true),
			GUILayout.Width(140f)
		};

		public static GUILayoutOption[] ScrollData = (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) };

		public static GUILayoutOption[] ScrollChoose = (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(300f) };

		public static GUILayoutOption[] ColumnAction = (GUILayoutOption[])(object)new GUILayoutOption[1] { ColumnWidthAction };

		public static GUILayoutOption[] ColumnProduction = (GUILayoutOption[])(object)new GUILayoutOption[1] { ColumnWidthProduction };

		public static GUILayoutOption[] ColumnRecipe = (GUILayoutOption[])(object)new GUILayoutOption[1] { ColumnWidthRecipe };

		public static GUILayoutOption[] ColumnPower = (GUILayoutOption[])(object)new GUILayoutOption[1] { ColumnWidthPower };

		public static GUILayoutOption[] ColumnMachine = (GUILayoutOption[])(object)new GUILayoutOption[1] { ColumnWidthMachine };

		public static GUILayoutOption[] ColumnProducts = (GUILayoutOption[])(object)new GUILayoutOption[1] { ColumnWidthProducts };

		public static GUILayoutOption[] ColumnIngredients = (GUILayoutOption[])(object)new GUILayoutOption[1] { ColumnWidthIngredients };

		public static GUILayoutOption[] GetDataCell(DataColumn column, bool logistic)
		{
			GUILayoutOption val = GUILayout.Height(73f);
			if (logistic)
			{
				val = GUILayout.Height(91f);
			}
			return column switch
			{
				DataColumn.Actions => (GUILayoutOption[])(object)new GUILayoutOption[2] { ColumnWidthAction, val }, 
				DataColumn.Production => (GUILayoutOption[])(object)new GUILayoutOption[2] { ColumnWidthProduction, val }, 
				DataColumn.Recipe => (GUILayoutOption[])(object)new GUILayoutOption[2] { ColumnWidthRecipe, val }, 
				DataColumn.Power => (GUILayoutOption[])(object)new GUILayoutOption[2] { ColumnWidthPower, val }, 
				DataColumn.Machine => (GUILayoutOption[])(object)new GUILayoutOption[2] { ColumnWidthMachine, val }, 
				DataColumn.Products => (GUILayoutOption[])(object)new GUILayoutOption[2] { ColumnWidthProducts, val }, 
				DataColumn.Ingredients => (GUILayoutOption[])(object)new GUILayoutOption[2] { ColumnWidthIngredients, val }, 
				_ => null, 
			};
		}
	}
	public class Callback
	{
		public delegate void ForSheet(Nodes sheet);

		public delegate void ForNode(INode node);

		public delegate void ForItem(IItem item);

		public delegate void ForVoid();
	}
	public class HMButton
	{
		private static Texture2D infoTexture = LoadAssembly.LoadTexture2D("info");

		public static void Texture(Texture2D texture, Callback.ForVoid callback)
		{
			if ((Object)(object)texture != (Object)null && GUILayout.Button((Texture)(object)texture, HMStyle.ButtonIcon, HMLayoutOptions.Icon45))
			{
				callback?.Invoke();
			}
		}

		public static void Sheet(Nodes sheet, Callback.ForSheet callback)
		{
			if ((Object)(object)sheet.Icon == (Object)null)
			{
				if (GUILayout.Button((Texture)(object)infoTexture, HMStyle.ButtonIcon, HMLayoutOptions.Icon45))
				{
					callback?.Invoke(sheet);
				}
			}
			else if (GUILayout.Button((Texture)(object)sheet.Icon, HMStyle.ButtonIcon, HMLayoutOptions.Icon45))
			{
				callback?.Invoke(sheet);
			}
		}

		public static void Node(INode node, Callback.ForNode callback)
		{
			if ((Object)(object)node.Icon == (Object)null)
			{
				if (GUILayout.Button("?", HMStyle.ButtonIcon, HMLayoutOptions.Icon45))
				{
					callback?.Invoke(node);
				}
			}
			else if (GUILayout.Button((Texture)(object)node.Icon, HMStyle.ButtonIcon, HMLayoutOptions.Icon45))
			{
				callback?.Invoke(node);
			}
		}

		public static void Node(INode node, string tooltip, Callback.ForNode callback)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			if ((Object)(object)node.Icon == (Object)null)
			{
				if (GUILayout.Button(new GUIContent("?", tooltip), HMStyle.ButtonIcon, HMLayoutOptions.Icon45))
				{
					callback?.Invoke(node);
				}
			}
			else if (GUILayout.Button(new GUIContent((Texture)(object)node.Icon, tooltip), HMStyle.ButtonIcon, HMLayoutOptions.Icon45))
			{
				callback?.Invoke(node);
			}
		}

		public static void ActionNode(INode node, GUIContent action, Callback.ForNode callback)
		{
			if (action != null && GUILayout.Button(action, HMLayoutOptions.ActionButton))
			{
				callback?.Invoke(node);
			}
		}

		public static void Action(string action, Callback.ForVoid callback)
		{
			if (action != null && GUILayout.Button(action, Array.Empty<GUILayoutOption>()))
			{
				callback?.Invoke();
			}
		}

		public static void Text(string text, int width = 100, int height = 25, Callback.ForVoid callback = null)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			if (text != null && GUILayout.Button(new GUIContent(text), (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height((float)height),
				GUILayout.Width((float)width)
			}))
			{
				callback?.Invoke();
			}
		}

		public static void Text(string text, string tooltip, int width = 100, int height = 25, Callback.ForVoid callback = null)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if (text != null && GUILayout.Button(new GUIContent(text, tooltip), (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Height((float)height),
				GUILayout.Width((float)width)
			}))
			{
				callback?.Invoke();
			}
		}

		public static void Item(IItem item, double factor = 1.0, Callback.ForItem callback = null)
		{
			ItemColored(item, ItemColor.Normal, factor, callback);
		}

		public static void ItemColored(IItem item, ItemColor color, double factor = 1.0, Callback.ForItem callback = null)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			GUIStyle val = HMStyle.ButtonIcon;
			switch (color)
			{
			case ItemColor.Blue:
				val = HMStyle.ButtonIconBlue;
				break;
			case ItemColor.Green:
				val = HMStyle.ButtonIconGreen;
				break;
			case ItemColor.Orange:
				val = HMStyle.ButtonIconOrange;
				break;
			case ItemColor.Red:
				val = HMStyle.ButtonIconRed;
				break;
			case ItemColor.Yellow:
				val = HMStyle.ButtonIconYellow;
				break;
			}
			if ((Object)(object)item.Icon == (Object)null)
			{
				if (GUILayout.Button("?", val, HMLayoutOptions.Icon45))
				{
					callback?.Invoke(item);
				}
			}
			else if (GUILayout.Button(new GUIContent((Texture)(object)item.Icon, $"{item.Name}\nFlow: {item.Flow * factor * 60.0:N2}/mn"), val, HMLayoutOptions.Icon45))
			{
				callback?.Invoke(item);
			}
		}

		public static void Icon(IItem item, Callback.ForItem callback = null)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.button);
			val.normal.background = item.Icon;
			val.onHover.background = item.Icon;
			val.fontStyle = (FontStyle)1;
			val.alignment = (TextAnchor)8;
			if (GUILayout.Button(item.Count.ToString(), val, HMLayoutOptions.Icon45))
			{
				callback?.Invoke(item);
			}
		}

		public static void IconLogistic(IItem item, Callback.ForItem callback = null)
		{
			if (GUILayout.Button((Texture)(object)item.Icon, HMLayoutOptions.Icon30))
			{
				callback?.Invoke(item);
			}
		}
	}
	public class HMCell
	{
		private static double limit = 10.0;

		public static void Node(INode node, string tooltip = null, Callback.ForNode callback = null)
		{
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			HMButton.Node(node, tooltip, callback);
			GUILayout.BeginHorizontal(HMStyle.TextBoxStyle, HMLayoutOptions.Text45x15);
			if (node.Count < limit)
			{
				GUILayout.Label($"{node.Count:N2}", HMStyle.TextButtonIcon, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label($"{node.Count:N1}", HMStyle.TextButtonIcon, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		public static void Node(INode node, double factor, string tooltip = null, Callback.ForNode callback = null)
		{
			double num = node.Count * factor;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			HMButton.Node(node, tooltip, callback);
			GUILayout.BeginHorizontal(HMStyle.TextBoxStyle, HMLayoutOptions.Text45x15);
			if (num < limit)
			{
				GUILayout.Label($"{num:N2}", HMStyle.TextButtonIcon, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label($"{num:N1}", HMStyle.TextButtonIcon, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		public static void NodePower(INode node, double factor, Callback.ForVoid callback = null)
		{
			double num = node.Power * factor;
			if (!(node is IRecipe))
			{
				num *= node.Count;
			}
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			HMButton.Texture(HMTexture.eclaireTexture, callback);
			GUILayout.BeginHorizontal(HMStyle.TextBoxStyle, HMLayoutOptions.Text45x15);
			GUILayout.Label(NumberFormater.Format(num, "W"), HMStyle.TextButtonIcon, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		public static void NodeActions(Nodes parent, INode node)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			GUILayout.BeginVertical(HMStyle.None, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUIContent action = new GUIContent("U", "Action:Up");
			HMButton.ActionNode(node, action, delegate(INode element)
			{
				HMEventQueue.EnQueue(parent, new HMEvent(HMEventType.UpNode, element));
			});
			GUILayout.FlexibleSpace();
			GUIContent action2 = new GUIContent("X", "Action:Delete");
			HMButton.ActionNode(node, action2, delegate(INode element)
			{
				HMEventQueue.EnQueue(parent, new HMEvent(HMEventType.RemoveNode, element));
			});
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUIContent action3 = new GUIContent("D", "Action:Down");
			HMButton.ActionNode(node, action3, delegate(INode element)
			{
				HMEventQueue.EnQueue(parent, new HMEvent(HMEventType.DownNode, element));
			});
			GUIContent action4 = new GUIContent("<", "Action:DownLevel");
			HMButton.ActionNode(node, action4, delegate(INode element)
			{
				HMEventQueue.EnQueue(parent, new HMEvent(HMEventType.DownLevelNode, element));
			});
			GUIContent action5 = new GUIContent(">", "Action:UpLevel");
			HMButton.ActionNode(node, action5, delegate(INode element)
			{
				HMEventQueue.EnQueue(parent, new HMEvent(HMEventType.UpLevelNode, element));
			});
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		public static void RecipeTime(IRecipe recipe, Callback.ForVoid callback = null)
		{
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			HMButton.Texture(HMTexture.time, callback);
			GUILayout.BeginHorizontal(HMStyle.TextBoxStyle, HMLayoutOptions.Text45x15);
			if (recipe.Energy < limit)
			{
				GUILayout.Label($"{recipe.Energy:N2}", HMStyle.TextButtonIcon, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label($"{recipe.Energy:N1}", HMStyle.TextButtonIcon, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		public static void Product(IItem item, double factor = 1.0, Callback.ForItem callback = null)
		{
			ItemColored(item, ItemColor.Normal, factor, withLogistic: false, callback);
		}

		private static void ItemColored(IItem item, ItemColor color, double factor = 1.0, bool withLogistic = false, Callback.ForItem callback = null)
		{
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			HMButton.ItemColored(item, color, factor, callback);
			GUILayout.BeginHorizontal(HMStyle.TextBoxStyle, HMLayoutOptions.Text45x15);
			if (item.Count * factor < limit)
			{
				GUILayout.Label($"{item.Count * factor:N2}", HMStyle.TextButtonIcon, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label($"{item.Count * factor:N1}", HMStyle.TextButtonIcon, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndHorizontal();
			if (withLogistic && Settings.Instance.DisplayLogistic)
			{
				GUILayout.BeginHorizontal(HMStyle.TextBoxStyle, HMLayoutOptions.Text45x15);
				IItem logisticItem = Compute.GetLogisticItem(item);
				GUILayout.Box((Texture)(object)logisticItem.Icon, HMStyle.BoxIcon, HMLayoutOptions.Icon15);
				GUILayout.Label($"{logisticItem.Count * factor:N1}", HMStyle.TextButtonIcon, Array.Empty<GUILayoutOption>());
				GUILayout.EndHorizontal();
			}
			GUILayout.EndVertical();
		}

		public static void ItemProduct(IItem item, double factor = 1.0, bool withLogistic = false, Callback.ForItem callback = null)
		{
			ItemColor color = ItemColor.Normal;
			switch (item.State)
			{
			case ItemState.Main:
				color = ItemColor.Green;
				break;
			case ItemState.Overflow:
				color = ItemColor.Red;
				break;
			case ItemState.Residual:
				color = ItemColor.Blue;
				break;
			}
			ItemColored(item, color, factor, withLogistic, callback);
		}

		public static void ItemIngredient(IItem item, double factor = 1.0, bool withLogistic = false, Callback.ForItem callback = null)
		{
			ItemColor color = ItemColor.Yellow;
			ItemColored(item, color, factor, withLogistic, callback);
		}

		public static void ItemList(List<IItem> items, Callback.ForItem callback = null)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			int num = 0;
			foreach (IItem item in items)
			{
				if (num % 5 == 0)
				{
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
				if (item.State == ItemState.Main || item.Count > 0.01)
				{
					Product(item, 1.0, callback);
					num++;
				}
			}
			if (num == 0)
			{
				GUILayout.Label("", Array.Empty<GUILayoutOption>());
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
		}

		public static void ItemProductList(INode node, double time, bool withLogistic = false, Callback.ForItem callback = null)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			int num = 0;
			foreach (IItem product in node.Products)
			{
				if (num % 5 == 0)
				{
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
				if (product.State == ItemState.Main || product.Count > 0.01)
				{
					product.Flow = product.Count / time;
					ItemProduct(product, node.GetDeepCount(Settings.Instance.DisplayTotal), withLogistic, callback);
					num++;
				}
			}
			if (num == 0)
			{
				GUILayout.Label("", Array.Empty<GUILayoutOption>());
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
		}

		public static void ItemIngredientList(INode node, double time, bool withLogistic = false, Callback.ForItem callback = null)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			int num = 0;
			foreach (IItem ingredient in node.Ingredients)
			{
				if (num % 5 == 0)
				{
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
				if (ingredient.State == ItemState.Main || ingredient.Count > 0.01)
				{
					ingredient.Flow = ingredient.Count / time;
					ItemIngredient(ingredient, node.GetDeepCount(Settings.Instance.DisplayTotal), withLogistic, callback);
					num++;
				}
			}
			if (num == 0)
			{
				GUILayout.Label("", Array.Empty<GUILayoutOption>());
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
		}
	}
	public class HMStyle
	{
		public static GUIStyle Form = ChangeTexture(new GUIStyle(GUI.skin.window), HMTexture.form_gray, HMTexture.form_gray_active);

		public static GUIStyle FormTooltip = ChangeTexture(new GUIStyle(GUI.skin.window), Texture2D.blackTexture, Texture2D.blackTexture);

		public static GUIStyle ButtonIcon = new GUIStyle(GUI.skin.button)
		{
			padding = new RectOffset(5, 5, 5, 5),
			margin = new RectOffset(1, 1, 1, 1)
		};

		public static GUIStyle ButtonIconBlue = ChangeTexture(ButtonIcon, HMTexture.icon_blue);

		public static GUIStyle ButtonIconGreen = ChangeTexture(ButtonIcon, HMTexture.icon_green);

		public static GUIStyle ButtonIconOrange = ChangeTexture(ButtonIcon, HMTexture.icon_orange);

		public static GUIStyle ButtonIconRed = ChangeTexture(ButtonIcon, HMTexture.icon_red);

		public static GUIStyle ButtonIconYellow = ChangeTexture(ButtonIcon, HMTexture.icon_yellow);

		public static GUIStyle BoxNavigate = new GUIStyle
		{
			padding = new RectOffset(10, 0, 0, 0),
			margin = new RectOffset(0, 0, 0, 0)
		};

		public static GUIStyle TreeBarNavigateStretch = ChangeTexture(new GUIStyle
		{
			padding = new RectOffset(0, 0, 0, 0),
			margin = new RectOffset(0, 0, 0, 0),
			stretchHeight = true
		}, HMTexture.icon_orange);

		public static GUIStyle TreeBarNavigate = new GUIStyle(GUI.skin.box)
		{
			padding = new RectOffset(0, 0, 0, 0),
			margin = new RectOffset(0, 0, 0, 0)
		};

		public static GUIStyle TextAlignLowerRight = new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)8
		};

		public static GUIStyle TextAlignMiddleCenter = new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4
		};

		public static GUIStyle TextTooltip = ChangeTooltip(GUI.skin.label);

		public static GUIStyle TextButtonIcon = new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4,
			margin = new RectOffset(0, 0, 0, 0),
			padding = new RectOffset(1, 1, 1, 1)
		};

		public static GUIStyle BoxStyle = new GUIStyle(GUI.skin.box)
		{
			margin = new RectOffset(2, 2, 2, 2)
		};

		public static GUIStyle BoxIcon = new GUIStyle
		{
			margin = new RectOffset(0, 0, 0, 0),
			padding = new RectOffset(0, 0, 0, 0)
		};

		public static GUIStyle BoxTooltip = ChangeTexture(new GUIStyle
		{
			margin = new RectOffset(0, 0, 0, 0),
			padding = new RectOffset(3, 3, 3, 3),
			border = new RectOffset(5, 5, 5, 5)
		}, HMTexture.tooltip_gray);

		public static GUIStyle TextBoxStyle = new GUIStyle(GUI.skin.box)
		{
			padding = new RectOffset(0, 0, 0, 0),
			margin = new RectOffset(1, 1, 1, 1)
		};

		public static GUIStyle ScrollListDetail = new GUIStyle();

		public static GUIStyle None = new GUIStyle
		{
			margin = new RectOffset(0, 0, 0, 0),
			padding = new RectOffset(0, 0, 0, 0)
		};

		public static GUIStyle ScrollData = new GUIStyle
		{
			margin = new RectOffset(0, 3, 0, 0),
			padding = new RectOffset(0, 0, 0, 0)
		};

		public static GUIStyle BoxNavigateTree = ChangeTexture(new GUIStyle
		{
			margin = new RectOffset(0, 0, 0, 0),
			padding = new RectOffset(10, 0, 0, 0),
			border = new RectOffset(25, 25, 25, 25)
		}, HMTexture.tree);

		public static GUIStyle BoxNavigateTreeLeaf = ChangeTexture(new GUIStyle
		{
			margin = new RectOffset(0, 0, 0, 0),
			padding = new RectOffset(10, 0, 0, 0),
			border = new RectOffset(25, 25, 25, 25)
		}, HMTexture.tree_leaf);

		internal static GUIStyle ChangeTexture(GUIStyle style, Texture2D image)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(style);
			val.normal.background = image;
			return val;
		}

		internal static GUIStyle ChangeTexture(GUIStyle style, Texture2D background, Texture2D active)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(style);
			val.normal.background = background;
			val.onNormal.background = active;
			val.active.background = background;
			val.onActive.background = active;
			return val;
		}

		internal static GUIStyle ChangeTooltip(GUIStyle style)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(style);
			val.normal.background = HMTexture.black;
			val.stretchWidth = true;
			val.stretchHeight = true;
			val.alignment = (TextAnchor)0;
			return val;
		}
	}
	public class HMTexture
	{
		public static Texture2D infoTexture = LoadAssembly.LoadTexture2D("info");

		public static Texture2D eclaireTexture = LoadAssembly.LoadTexture2D("eclair_x64");

		public static Texture2D black = LoadAssembly.LoadTexture2D("black_x64");

		public static Texture2D icon_blue = LoadAssembly.LoadTexture2D("icon_blue_x64");

		public static Texture2D icon_green = LoadAssembly.LoadTexture2D("icon_green_x64");

		public static Texture2D icon_orange = LoadAssembly.LoadTexture2D("icon_orange_x64");

		public static Texture2D icon_red = LoadAssembly.LoadTexture2D("icon_red_x64");

		public static Texture2D icon_yellow = LoadAssembly.LoadTexture2D("icon_yellow_x64");

		public static Texture2D form_gray = LoadAssembly.LoadTexture2D("form_gray_x64");

		public static Texture2D form_gray_active = LoadAssembly.LoadTexture2D("form_gray_active_x64");

		public static Texture2D tooltip_gray = LoadAssembly.LoadTexture2D("tooltip_gray_x64");

		public static Texture2D time = LoadAssembly.LoadTexture2D("time_x64");

		public static Texture2D tree = LoadAssembly.LoadTexture2D("tree_x64");

		public static Texture2D tree_leaf = LoadAssembly.LoadTexture2D("tree_leaf_x64");
	}
}
namespace DSP_Helmod.UI.Editions
{
	public class EditionPreference : HMForm
	{
		protected SectionPreference selection;

		protected Dictionary<string, string> controls = new Dictionary<string, string>();

		public EditionPreference(UIController parent)
			: base(parent)
		{
			name = "Edition Preferences";
			Caption = "Edition Preferences";
		}

		public override void OnDoWindow()
		{
			DrawMenu();
			DrawContent();
		}

		public override void OnInit()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			windowRect0 = new Rect(200f, 20f, 600f, 700f);
			Dictionary<string, string> dictionary = controls;
			KeyCode openCloseKeyCode = Settings.Instance.OpenCloseKeyCode;
			dictionary.Add("Open/Close", ((object)(KeyCode)(ref openCloseKeyCode)).ToString());
		}

		public override void OnUpdate()
		{
		}

		private void DrawMenu()
		{
			GUILayout.BeginHorizontal(HMStyle.BoxStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MaxHeight(20f),
				GUILayout.Width(80f)
			});
			foreach (SectionPreference value in Enum.GetValues(typeof(SectionPreference)))
			{
				if (GUILayout.Button(value.ToString(), Array.Empty<GUILayoutOption>()))
				{
					selection = value;
				}
			}
			GUILayout.EndHorizontal();
		}

		private void DrawContent()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUI.skin.box);
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			switch (selection)
			{
			case SectionPreference.General:
				DrawGeneral();
				break;
			case SectionPreference.Controls:
				DrawControls();
				break;
			}
			GUILayout.EndVertical();
			GUILayout.EndScrollView();
		}

		private void DrawGeneral()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00