Exemplo n.º 1
0
		/// <summary>
		/// Open menu if the key is pressed.
		/// </summary>
		public override void Update()
		{
			// Open menu
			if (menuKey.IsDown())
			{
				Toggle();
			}

			// Rebinds
			if (awaitingInput)
			{
				// Cancel rebind
				if (Input.GetKeyDown(KeyCode.Escape))
				{
					if (awaitingKeyID == 0)
					{
						awaitingKey.Modifier = KeyCode.None;
					}
					else if (awaitingKeyID == 1)
					{
						awaitingKey.Key = KeyCode.None;
					}

					awaitingInput = false;
					awaitingKeyID = -1;
					awaitingKey = null;
				}

				if (Input.anyKeyDown)
				{
					if (awaitingKeyID == 0)
					{
						if (Event.current.keyCode != KeyCode.None)
						{
							awaitingKey.Modifier = Event.current.keyCode;
						}
						else
						{
							if (Event.current.shift)
							{
								awaitingKey.Modifier = KeyCode.LeftShift;
							}
						}
					}
					else if (awaitingKeyID == 1)
					{
						string input = Input.inputString.ToUpper();
						KeyCode code = KeyCode.None;

						try
						{
							code = (KeyCode)Enum.Parse(typeof(KeyCode), input);
						}
						catch (Exception e)
						{
							if (input == "`")
							{
								code = KeyCode.BackQuote;
							}
							else
							{
								ModConsole.Error("Invalid key");
							}
						}

						awaitingKey.Key = code;
					}

					awaitingInput = false;
					awaitingKey = null;
					awaitingKeyID = -1;
				}
			}
		}
Exemplo n.º 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;
					}
				}
			}
		}
Exemplo n.º 3
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 });
		}