Example #1
0
		/// <summary>
		/// Toggles if the settings menu is open or not.
		/// </summary>
		public static void Toggle()
		{
			menuOpen = !menuOpen;
			menuState = 0;
			selectedMod = null;
			scrollPos = Vector2.zero;
		}
Example #2
0
		// Manage windows
		private void windowManager(int id)
		{
			if (id == 0)
			{
				if (menuState == 0)
				{
					// Main menu

					scrollPos = GUILayout.BeginScrollView(scrollPos);

					GUILayout.Label("Loaded mods");

					GUILayout.Space(20);

					foreach (Mod mod in ModLoader.LoadedMods)
					{
						if (GUILayout.Button(mod.Name, GUILayout.Height(30)))
						{
							menuState = 1;
							selectedMod = mod;
						}
					}

					GUILayout.EndScrollView();

					GUILayout.Space(20);

					if (GUILayout.Button("Close", GUILayout.Height(30)))
					{
						menuOpen = false;
					}
				}
				else if (menuState == 1)
				{
					// Mod info

					scrollPos = GUILayout.BeginScrollView(scrollPos);

					GUILayout.Space(20);

					if (selectedMod != null)
					{
						GUILayout.Label("ID: " + selectedMod.ID);
						GUILayout.Label("Name: " + selectedMod.Name);
						GUILayout.Label("Version: " + selectedMod.Version);
						GUILayout.Label("Author: " + selectedMod.Author);

						GUILayout.Space(20);

						if (GUILayout.Button("Keybinds", GUILayout.Height(30)))
						{
							menuState = 2;
							scrollPos = Vector2.zero;
						}
					}
					else
					{
						GUILayout.Label("Invalid mod");
					}

					GUILayout.EndScrollView();

					GUILayout.Space(20);

					if (GUILayout.Button("Back", GUILayout.Height(30)))
					{
						menuState = 0;
						selectedMod = null;
						scrollPos = Vector2.zero;
					}
				}
				else if (menuState == 2)
				{
					// Edit keybinds

					GUILayout.Label("Keybinds");
					GUILayout.Space(20);

					scrollPos = GUILayout.BeginScrollView(scrollPos);

					if (selectedMod != null)
					{
						bool none = true;

						foreach (Keybind key in Keybind.Keybinds)
						{
							if (key.Mod == selectedMod)
							{
								GUILayout.Label(key.Name);

								string modStr = key.Modifier.ToString();
								string keyStr = key.Key.ToString();

								if (awaitingInput)
								{
									if (awaitingKeyID == 0)
									{
										modStr = "Press any key";
									}
									else if (awaitingKeyID == 1)
									{
										keyStr = "Press any key";
									}
								}

								if (GUILayout.Button("Modifier - " + modStr, GUILayout.Height(30)))
								{
									if (!awaitingInput)
									{
										awaitingInput = true;
										awaitingKeyID = 0;
										awaitingKey = key;
									}
								}

								if (GUILayout.Button("Key - " + keyStr, GUILayout.Height(30)))
								{
									if (!awaitingInput)
									{
										awaitingInput = true;
										awaitingKeyID = 1;
										awaitingKey = key;
									}
								}

								GUILayout.Space(10);

								none = false;
							}
						}

						if (none)
						{
							GUILayout.Label("This mod has no keybinds");
						}
					}
					else
					{
						GUILayout.Label("Invalid mod");
					}

					GUILayout.EndScrollView();

					GUILayout.Space(20);

					if (GUILayout.Button("Reset", GUILayout.Height(30)))
					{
						resetBinds();
					}

					if (GUILayout.Button("Back", GUILayout.Height(30)))
					{
						menuState = 1;
						scrollPos = Vector2.zero;
					}
				}
			}
		}
Example #3
0
		/// <summary>
		/// Return all default keybinds for mod.
		/// </summary>
		/// <param name="mod">The mod to get the keybinds for.</param>
		/// <returns>List of default Keybinds for the mod.</returns>
		public static List<Keybind> GetDefault(Mod mod)
		{
			return DefaultKeybinds.FindAll(x => x.Mod == mod);
		}
Example #4
0
		/// <summary>
		/// Save keybind for a single mod to config file.
		/// </summary>
		/// <param name="mod">The mod to save the config for.</param>
		public static void SaveModBinds(Mod mod)
		{
			string path = ModLoader.ConfigFolder + mod.ID + "\\keybinds.xml";

			// Clear file
			File.WriteAllText(path, "");

			// Write XML
			XmlDocument doc = new XmlDocument();
			XmlElement keybinds = doc.CreateElement(string.Empty, "Keybinds", string.Empty);

			foreach (Keybind bind in Keybind.Get(mod))
			{
				XmlElement keybind = doc.CreateElement(string.Empty, "Keybind", string.Empty);

				XmlElement name = doc.CreateElement(string.Empty, "ID", string.Empty);
				name.AppendChild(doc.CreateTextNode(bind.ID));
				keybind.AppendChild(name);

				XmlElement key = doc.CreateElement(string.Empty, "Key", string.Empty);
				key.AppendChild(doc.CreateTextNode(bind.Key.ToString()));
				keybind.AppendChild(key);

				XmlElement modifier = doc.CreateElement(string.Empty, "Modifier", string.Empty);
				modifier.AppendChild(doc.CreateTextNode(bind.Modifier.ToString()));
				keybind.AppendChild(modifier);

				keybinds.AppendChild(keybind);
			}

			doc.AppendChild(keybinds);
			doc.Save(path);
		}
Example #5
0
		/// <summary>
		/// Add a keybind.
		/// </summary>
		/// <param name="mod">The instance of your mod.</param>
		/// <param name="key">The Keybind to add.</param>
		public static void Add(Mod mod, Keybind key)
		{
			key.Mod = mod;
			Keybinds.Add(key);
			DefaultKeybinds.Add(new Keybind(key.ID, key.Name, key.Key, key.Modifier) { Mod = mod });
		}