public static void AddSpawnCommand() { ModAPI.Console.Command command = new ModAPI.Console.Command { CommandName = "spawn", HelpText = "Spawns an item/object", OnSubmit = delegate(object[] objs) { string str = (string)objs[0]; lastObject = str; lastObjectType = "spawn"; UnityEngine.Object.Instantiate(Objects[str], LocalPlayer.MainCam.transform.position + ((Vector3)(LocalPlayer.MainCam.transform.forward * 2f)), Quaternion.identity); } }; List <ModAPI.Console.IConsoleParameter> list = new List <ModAPI.Console.IConsoleParameter>(); ModAPI.Console.BaseConsoleParameter item = new ModAPI.Console.BaseConsoleParameter { IsOptional = false, UseAutoComplete = true, Name = "Object", ListValueRequired = true, TooltipText = "", Values = ObjectNames }; list.Add(item); command.Parameters = list; ModAPI.Console.RegisterCommand(command); ModAPI.Console.Command command2 = new ModAPI.Console.Command { CommandName = "add", HelpText = "Add items to inventory", OnSubmit = delegate(object[] objs) { string str = (string)objs[0]; int amount = 1; for (int j = 0; j < ItemDatabase.Items.Length; j++) { try { if ((ItemDatabase.Items[j]._name == str) || (str == "All")) { if (str == "All") { amount = 50; } if ((ItemDatabase.Items[j]._name != "BombTimed") || (str != "All")) { lastObject = ItemDatabase.Items[j]._id.ToString(); lastObjectType = "add"; LocalPlayer.Inventory.AddItem(ItemDatabase.Items[j]._id, amount, false, false, ~WeaponStatUpgrade.Types.smashDamage); } } } catch (Exception) { ModAPI.Console.Lines.Add("[Item]: Error while adding " + ItemDatabase.Items[j]._name); } } } }; List <ModAPI.Console.IConsoleParameter> list2 = new List <ModAPI.Console.IConsoleParameter>(); ModAPI.Console.BaseConsoleParameter parameter2 = new ModAPI.Console.BaseConsoleParameter { IsOptional = false, UseAutoComplete = true, Name = "Object", ListValueRequired = true, TooltipText = "", Values = ItemNames }; list2.Add(parameter2); command2.Parameters = list2; ModAPI.Console.RegisterCommand(command2); }
void OnGUI() { if (opened) { if (autoCompletionMax > -1) { if (currentAutocompletion == -1) { currentAutocompletion = 0; } if (Event.current.keyCode == KeyCode.DownArrow && Event.current.type == EventType.KeyDown) { currentAutocompletion += 1; if (currentAutocompletion > autoCompletionMax) { currentAutocompletion = 0; } Event.current.Use(); } if (Event.current.keyCode == KeyCode.UpArrow && Event.current.type == EventType.KeyDown) { currentAutocompletion -= 1; if (currentAutocompletion < 0) { currentAutocompletion = autoCompletionMax; } Event.current.Use(); } if (currentAutocompletion > -1) { if ((Event.current.keyCode == KeyCode.RightArrow || Event.current.keyCode == KeyCode.Space || Event.current.keyCode == KeyCode.Return) && Event.current.type == EventType.KeyDown) { if (Event.current.keyCode == KeyCode.Return) { submit = true; } addParam = true; Event.current.Use(); return; } } } else { if (Event.current.keyCode == KeyCode.DownArrow && Event.current.type == EventType.KeyDown) { if (LastPosition > 0) { LastPosition--; if (LastPosition <= 0) { input = ""; LastPosition = 0; } else { input = Last[LastPosition]; } Event.current.Use(); } } if (Event.current.keyCode == KeyCode.UpArrow && Event.current.type == EventType.KeyDown) { if (LastPosition < Last.Count - 1) { LastPosition++; input = Last[LastPosition]; Event.current.Use(); } } if ((Event.current.keyCode == KeyCode.BackQuote || Event.current.keyCode == KeyCode.Escape || Event.current.keyCode == KeyCode.Backslash) && Event.current.type == EventType.KeyDown) { ModAPI.Console.Switch(); } if (Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyDown) { submit = true; } } UnityEngine.GUI.skin = ModAPI.GUI.Skin; UnityEngine.GUI.color = new Color(1f, 1f, 1f, 1f); UnityEngine.GUI.backgroundColor = new Color(1f, 1f, 1f, 1f); UnityEngine.GUI.contentColor = new Color(1f, 1f, 1f, 1f); UnityEngine.GUI.depth = -100; float width = Screen.width / 2f; float height = 400f; float x = Screen.width - width - 10f; float y = Screen.height - height - 10f; UnityEngine.GUI.Box(new Rect(x, y, width, height), "Console", UnityEngine.GUI.skin.window); List <string> n = ModAPI.Console.Lines.ToList(); n.Reverse(); UnityEngine.GUI.enabled = false; UnityEngine.GUI.color = new Color(1f, 1f, 1f, 1f); UnityEngine.GUI.TextArea(new Rect(x + 10f, y + 40f, width - 20f, height - 85f), string.Join("\r\n", n.ToArray())); UnityEngine.GUI.enabled = true; UnityEngine.GUI.SetNextControlName("Input"); input = UnityEngine.GUI.TextField(new Rect(x + 10f, y + height - 40f, width - 20f, 25f), input); input = input.Replace("â", "a"); input = input.Replace("Â", "A"); input = input.Replace("ô", "o"); input = input.Replace("Ô", "O"); input = input.Replace("î", "i"); input = input.Replace("Î", "I"); input = input.Replace("û", "u"); input = input.Replace("Û", "U"); input = input.Replace("ê", "e"); input = input.Replace("Ê", "E"); input = input.Replace("á", "a"); input = input.Replace("Á", "A"); input = input.Replace("ó", "o"); input = input.Replace("Ó", "O"); input = input.Replace("í", "i"); input = input.Replace("Í", "I"); input = input.Replace("ú", "u"); input = input.Replace("Ú", "U"); input = input.Replace("é", "e"); input = input.Replace("É", "E"); if (input.StartsWith("^")) { input = input.Substring(1); } int spaceIndex = input.IndexOf(" "); TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl); if (spaceIndex > 0 && editor.pos == input.Length && editor.pos == editor.selectPos) { string command = input.Substring(0, spaceIndex); ModAPI.Console.Command c = ModAPI.Console.GetCommand(command); List <string> possible = ModAPI.Console.GetPossibleValues(input); int lastIndex = input.LastIndexOf(" "); try { if (possible.Count > 1) { float _left = UnityEngine.GUI.skin.textField.CalcSize(new GUIContent(input.Substring(0, lastIndex))).x - 10f; float _right = UnityEngine.GUI.skin.textField.CalcSize(new GUIContent(input + ".")).x - 5f; float labelWidth = 0f; foreach (string poss in possible) { float w = UnityEngine.GUI.skin.label.CalcSize(new GUIContent(poss)).x; if (w > labelWidth) { labelWidth = w; } } float entryHeight = 20f; float maxHeight = 300f; float contentHeight = possible.Count * entryHeight; if (contentHeight > maxHeight) { contentHeight = maxHeight; } UnityEngine.GUI.Box(new Rect(x + 10f + _left, y + height - 35f - contentHeight, labelWidth + 10f, contentHeight), ""); int maxNum = possible.Count; int perPage = (int)(contentHeight / entryHeight); int istartIndex = 0; if (currentAutocompletion > perPage / 2) { istartIndex = currentAutocompletion - perPage / 2; } if (istartIndex > possible.Count - perPage) { istartIndex = possible.Count - perPage; } if (maxNum > perPage) { maxNum = perPage; } autoCompletionMax = possible.Count - 1; for (int i = 0; i < maxNum; i++) { if (istartIndex + i == currentAutocompletion) { UnityEngine.GUI.Box(new Rect(x + 10f + _left, y + height - 40f - contentHeight + i * entryHeight, labelWidth + 10f, entryHeight), "", GUI.Skin.button); } UnityEngine.GUI.Label(new Rect(x + 10f + _left + 5f, y + height - 40f - contentHeight + i * entryHeight, labelWidth, entryHeight), possible.ElementAt(istartIndex + i)); } if (currentAutocompletion > -1) { string _n = possible[currentAutocompletion].Substring(input.Substring(lastIndex + 1).Length); UnityEngine.GUI.Label(new Rect(x + 10f + _right, y + height - 43f + 3f, 200f, 20f), _n); if (addParam) { string newInput = input.Substring(0, lastIndex) + " "; if (possible[currentAutocompletion].Contains(" ")) { newInput += "\"" + possible[currentAutocompletion] + "\" "; } else { newInput += possible[currentAutocompletion] + " "; } input = newInput; addParam = false; editor.pos = input.Length; editor.selectPos = input.Length; } } } } catch (Exception e) { Console.Write(e.ToString(), "Core"); } } if (UnityEngine.GUI.GetNameOfFocusedControl() == "Input" && ((submit && !addParam)) && input.Trim() != "") { ModAPI.Console.ParseInput(input); Last.Insert(0, input); input = ""; LastPosition = -1; submit = false; } Event.current.mousePosition = new Vector2(0f, 0f); if (justOpened) { UnityEngine.GUI.FocusControl("Input"); justOpened = false; } } if (lastInput != input) { currentAutocompletion = -1; autoCompletionMax = -1; } lastInput = input; }