public void ButtonDown() { if (input == null) { input = GetComponentInChildren <InputField>(); } if (CommandProcessing.input != this) { CommandProcessing.input = this; } try { if (CommandProcessing.Process(input.text)) { input.text = ""; index = CommandProcessing.lastCommands.Count; } } catch (Exception e) { CommandProcessing.Log(RichText.InColour("Exception : " + e.Message, Color.red)); } EventSystem.current.SetSelectedGameObject(input.gameObject, null); input.ActivateInputField(); }
public void Input() { if (input == null) { input = GetComponentInChildren <InputField>(); } if (CommandProcessing.input != this) { CommandProcessing.input = this; } string text = input.text; if (!UnityEngine.Input.GetKeyDown(KeyCode.Return)) { return; } try { if (CommandProcessing.Process(text)) { input.text = ""; index = CommandProcessing.lastCommands.Count; } }catch (Exception e) { CommandProcessing.Log(RichText.InColour("Exception : " + e.Message, Color.red)); } EventSystem.current.SetSelectedGameObject(input.gameObject, null); input.ActivateInputField(); }
public void Update() { // This is an item, on the floor, that has a collider. Yep. if (MouseOver) { if (AllowPickup && !Item.IsEquipped()) { // Show the user that they can pick this item up. if (InputManager.Active) { string key = InputManager.GetInput("Pick up").ToString(); string itemName = RichText.InBold(RichText.InColour(Item.Name, ItemRarityUtils.GetColour(Item.Rarity))); ActionHUD.DisplayAction("PickupPrompt".Translate(key, itemName)); } if (InputManager.InputDown("Pick up")) { // Check client-server situation... if (isServer) { // Pick up manually. Item.RequestDataUpdate(); PickupAccepted(Item.Data); Destroy(this.gameObject); } else { // Pick up using the command. Player.Local.NetUtils.CmdRequestPickup(Player.Local.gameObject, this.gameObject); } } } } }
public static void Log(string text, Color colour) { if (!_Instance.Active) { return; } _Instance.str += RichText.InColour(text, colour) + '\n'; }
private string BuildDescription(Item item) { string description = "\n"; description += RichText.InColour(RichText.InItalics(item.ShortDescription), Color.black) + "\n\n"; description += RichText.InColour(item.LongDescription, Color.black) + "\n\n"; return(description); }
public static void LogError(string output) { string o = RichText.InColour(output.Trim(), Color.red); if (UI_CommandInput.Instance != null) { UI_CommandInput.Instance.Output.Log(o); } Debug.Log("[CMD][ERROR] {0}".Form(o)); }
public void LateUpdate() { if (!Active) { return; } str = (RichText.InBold(RichText.InColour("FPS: " + FPS, FPS > 55 ? Color.green : FPS > 30 ? Color.yellow : Color.red)) + "\n") + str; Text.text = str; str = ""; }
public void Update() { bool focoused = Input.isFocused; string typed = Input.text.Trim(); bool isCmd = typed.StartsWith("/"); if (InputManager.IsDown("Complete Command", true)) { if (isCmd && Suggestions.Matches.Count > 0) { string complete = this.Suggestions.Matches[autoIndex++].Name; if (typed.Length - 1 < complete.Length) { Input.text = '/' + complete; Input.caretPosition = Input.text.Length; } } } if (InputManager.IsDown("Enter Command", true)) { if (isCmd) { // Execute here... string error; bool clear = Commands.TryExecute(Input.text.Trim(), out error); if (clear) { // Assume this means it executed successfuly. Commands.AddCommandAsExectued(Input.text); Input.text = ""; Suggestions.Text.text = ""; autoIndex = 0; } if (!string.IsNullOrWhiteSpace(error)) { Output.Log(RichText.InColour(error.Trim(), Color.red)); } } // Give focous back to the input field. Slightly hackish, very effective. EventSystem.current.SetSelectedGameObject(Input.gameObject, null); Input.ActivateInputField(); } }
private void SetText() { if (holding == null) { AmmoText.text = "-/-"; FireMode.text = "---"; Title.text = "---"; Icon.sprite = null; return; } // Title - Name string name = holding.Item.Name; // Ammo counter. float percent = holding.Shooting.Capacity.MagazineCapacity <= 3 ? 0f : ((float)holding.Shooting.bulletsInMagazine / (float)holding.Shooting.Capacity.MagazineCapacity); bool isLow = percent <= BulletWarningPercentage || holding.Shooting.bulletsInMagazine <= BulletWarningCount; Color colour = AmmoText.color; if (isLow) { bool isBlink = ((int)timer2) % 2 == 0; colour = isBlink ? BlinkRed : Red; } string maxMagString = holding.Shooting.Capacity.MagazineCapacity.ToString(); string ammoString = string.Empty + (holding.Shooting.bulletsInMagazine + (holding.Shooting.BulletInChamber ? 1 : 0)); while (ammoString.Length < maxMagString.Length) { ammoString = '0' + ammoString; } string ammo = RichText.InColour(ammoString, colour) + '/' + maxMagString; // Firing mode. string fireMode = holding.Shooting.FiringMode.ToString(); //Apply all AmmoText.text = ammo; FireMode.text = fireMode; Title.text = name; Icon.sprite = holding.Item.ItemIcon; }
public void Refresh() { if (Item == null) { Text.text = "ERROR"; Image.enabled = false; } else { Text.text = RichText.InColour(Item.Name, ItemRarityUtils.GetColour(Item.Rarity)); if (Atlas == null) { Atlas = Resources.Load <SpriteAtlas>("Atlas/Game Point"); } Sprite spr = Atlas.GetSprite(Item.ItemIcon.name); Image.sprite = spr == null ? Item.ItemIcon : spr; } }
public void Enter(Item item) { if (item == null) { return; } Debug.Log("Opening details for : " + item.Name); gameObject.SetActive(true); string desc = BuildDescription(item); Text.text = desc; Title.text = RichText.InColour(item.Name, ItemRarityUtils.GetColour(item.Rarity)); SetStats(BuildStats(item)); Sprite spr = Atlas.GetSprite(item.ItemIcon.name); Image.sprite = spr == null ? item.ItemIcon : spr; }
public void SetText() { string quantity = ItemData.Count > 1 ? " x" + ItemData.Count : ""; string quickSlot = ""; if (ItemData.Data != null && ItemData.Data.Get <int>("Quick Slot") != 0) { quickSlot = RichText.InColour(" (Slot #" + ItemData.Data.Get <int>("Quick Slot") + ")", Color.black); } Text.text = ItemData.Item.Name + quantity + quickSlot; Text.color = Color.Lerp(ItemRarityUtils.GetColour(ItemData.Item.Rarity), Color.black, 0.2f); if (Details != null) { Details.text = (ItemData.Item.InventoryInfo.Weight * ItemData.Count) + "Kg"; } if (Atlas == null) { Atlas = Resources.Load <SpriteAtlas>("Atlas/Game Point"); } Sprite spr = Atlas.GetSprite(ItemData.Item.ItemIcon.name); Image.sprite = spr == null ? ItemData.Item.ItemIcon : spr; }
public void Update() { if (!Active) { All.SetActive(false); } else { str.Append("Select a "); if (AllowUnits) { str.Append("unit"); } if (AllowPositions && AllowUnits) { str.Append(" or a "); } if (AllowPositions) { str.Append("position"); } Title.text = str.ToString(); str.Clear(); All.SetActive(true); // Get unit under mouse, if any... overUnit = false; Unit u = null; if (AllowUnits) { u = Unit.GetUnder(InputManager.MousePos); overUnit = u != null; } UnitSelector.gameObject.SetActive(overUnit && AllowUnits); PosSelector.gameObject.SetActive(!overUnit && AllowPositions); PosSelector.Colour = PosSelectorColour; UnitSelector.Colour = UnitSelectorColour; if (overUnit) { UnitSelector.WorldPos = u.transform.position; } if (InputManager.IsDown("Select")) { bool isUnit = overUnit; if ((isUnit && AllowUnits) || (!isUnit && AllowPositions)) { // Something has been selected! Unit unit = null; if (isUnit) { unit = u; } Vector2 position = Vector2.zero; if (!isUnit) { position = InputManager.MousePos; } Finish(isUnit, unit, position); } } if (u != null && AllowUnits) { var player = Player.Local; bool same = false; if (player != null) { same = player.Faction == u.Faction; if (same) { str.Append(RichText.InColour("Friendly ", Color.green)); } else { str.Append("Enemy "); } } str.Append("Unit: "); str.Append(u.Name); if (!same) { str.Append(" ("); str.Append(u.Faction.ToString()); str.Append(')'); } } else if (AllowPositions) { str.Append("Position: "); str.Append(InputManager.MousePos.ToString("F1")); } SubTitle.text = str.ToString(); str.Clear(); } }
// Returns true to clear the console. public static bool Process(string command) { Error(""); // Is null or empty if (string.IsNullOrEmpty(command.Trim())) { Error("Input is empty!"); return(false); } string[] parts = SplitCommand(command); if (parts == null)// There was an error! { return(false); } // Make objects! object[] objects = new object[parts.Length]; // TODO int x = 0; foreach (string s in parts) { float f; int i2; bool b; if (float.TryParse(s, out f)) { // Is float, or int. // Give float priority. objects[x] = f; } else if (int.TryParse(s, out i2)) { // Is int, but not float. objects[x] = i2; } else if (bool.TryParse(s, out b)) { // Is bool objects[x] = b; } else { // Is string objects[x] = s; } x++; } // Find command... tempCommands.Clear(); foreach (Command comm in commands) { if (comm.Name == parts[0]) { tempCommands.Add(comm); } } object[] args = new object[parts.Length - 1]; for (int i3 = 1; i3 < objects.Length; i3++) { args[i3 - 1] = objects[i3]; } if (tempCommands.Count == 0) { Error("No commands found: '" + parts[0] + "'. Try typing help."); return(false); } if (lastCommands.Count == 0 || lastCommands[lastCommands.Count - 1] != command) { lastCommands.Add(command); } int i = 0; foreach (Command c in tempCommands) { bool isGood = args.Length == c.parameters.Count && c.IsValid(args); bool isLast = i == tempCommands.Count - 1; if (isGood) { for (int z = 0; z < args.Length; z++) { Type t = c.parameters[z]; if (t == typeof(int)) { // Cast to int args[z] = int.Parse(((Single)(args[z])).ToString()); // That is a float - EDIT: Is a wrapper class of course. } } Log("Running: " + command); // Execute string value = c.Execute(args); if (value != null) { Error("Error in execution. See log."); Log(parts[0] + " error: " + RichText.InColour(value, Color.red)); return(false); } tempCommands.Clear(); return(true); } if (!isGood && isLast) { if (tempCommands.Count > 1) { Error("Args did not match any of the " + tempCommands.Count + " '" + parts[0] + "' commands! See log."); Log(RichText.InColour("Error: No match for args (" + GetArgsAsString(builder, args) + ")", Color.red)); Log(RichText.InColour("Try the help command.", Color.red)); tempCommands.Clear(); return(false); } else { // Only one command Error("Wrong arguments for '" + parts[0] + "'. See log."); Log(RichText.InColour("Error: No match for args (" + GetArgsAsString(builder, args) + ")", Color.red)); Log(RichText.InColour("Try the help command.", Color.red)); tempCommands.Clear(); return(false); } } i++; } tempCommands.Clear(); // Done, successful execution. Log("Run: '" + command + "'"); return(false); }
public string[] GetEffects() { List <string> eff = new List <string>(); bool pos; // Damage if (DamageMultiplier != 1f) { pos = DamageMultiplier > 1f; eff.Add("Base Damage " + RichText.InColour((pos ? "+" : "-") + Mathf.RoundToInt(Mathf.Abs(DamageMultiplier - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } // Damage Falloff if (DamageFalloffMultiplier != 1f) { pos = DamageFalloffMultiplier > 1f; eff.Add("Damage Falloff " + RichText.InColour((pos ? "-" : "+") + Mathf.RoundToInt(Mathf.Abs(DamageFalloffMultiplier - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } // Penetration if (PenetrationChange != 0) { pos = PenetrationChange >= 1; eff.Add("Penetration " + RichText.InColour((pos ? "+" : "-") + Mathf.Abs(PenetrationChange), pos ? Color.green : Color.red)); } // Penetration Falloff if (PenetrationFalloffMultiplier != 1f) { pos = PenetrationFalloffMultiplier > 1f; eff.Add("Penetration Falloff " + RichText.InColour((pos ? "-" : "+") + Mathf.RoundToInt(Mathf.Abs(PenetrationFalloffMultiplier - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } // Magazine Capacity if (MagazineCapacityMultiplier != 1f) { pos = MagazineCapacityMultiplier > 1f; eff.Add("Magazine Capacity " + RichText.InColour((pos ? "+" : "-") + Mathf.RoundToInt(Mathf.Abs(MagazineCapacityMultiplier - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } // Inaccuracy if (InaccuracyMultiplier.x == InaccuracyMultiplier.y) { if (InaccuracyMultiplier.x != 1f) { pos = InaccuracyMultiplier.x < 1f; eff.Add("Accuracy " + RichText.InColour((pos ? "+" : "-") + Mathf.RoundToInt(Mathf.Abs(InaccuracyMultiplier.x - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } } else { if (InaccuracyMultiplier.x != 1f) { pos = InaccuracyMultiplier.x < 1f; eff.Add("Initial Accuracy " + RichText.InColour((pos ? "+" : "-") + Mathf.RoundToInt(Mathf.Abs(InaccuracyMultiplier.x - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } if (InaccuracyMultiplier.y != 1f) { pos = InaccuracyMultiplier.y < 1f; eff.Add("Final Accuracy " + RichText.InColour((pos ? "+" : "-") + Mathf.RoundToInt(Mathf.Abs(InaccuracyMultiplier.y - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } } // Shot Speed if (ShotSpeedMultiplier != 1f) { pos = ShotSpeedMultiplier > 1f; eff.Add("Fire Rate " + RichText.InColour((pos ? "+" : "-") + Mathf.RoundToInt(Mathf.Abs(ShotSpeedMultiplier - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } // Reload Speed if (ReloadSpeedMultiplier != 1f) { pos = ReloadSpeedMultiplier > 1f; eff.Add("Reload Speed " + RichText.InColour((pos ? "+" : "-") + Mathf.RoundToInt(Mathf.Abs(ReloadSpeedMultiplier - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } // Range if (RangeMultiplier != 1f) { pos = RangeMultiplier > 1f; eff.Add("Range " + RichText.InColour((pos ? "+" : "-") + Mathf.RoundToInt(Mathf.Abs(RangeMultiplier - 1f) * 100f) + "%", pos ? Color.green : Color.red)); } return(eff.ToArray()); }
public void RefreshAmount() { Text.text = RichText.InBold(RichText.InColour(Item == null ? "---" : Item.Name, Item == null ? Color.black : ItemRarityUtils.GetColour(Item.Rarity))) + " x" + Amount; }
private void Awake() { UI.AddDrawer(DrawUI); LoadCommands(); Input = new IMGUIWindow(int.MaxValue, new Rect(100, 100, Width, Height), "Console", () => { var e = Event.current; if (e.type == EventType.KeyDown && e.keyCode == KeyCode.Return && !string.IsNullOrWhiteSpace(CurrentCommand)) { SubmitCommand(CurrentCommand); CurrentCommand = string.Empty; } if (e.type == EventType.KeyDown && e.keyCode == KeyCode.UpArrow) { BrowseHistory(1); } else if (e.type == EventType.KeyDown && e.keyCode == KeyCode.DownArrow) { BrowseHistory(-1); } var items = GetSuggestions(CurrentCommand); string suggestions = GetSuggestionString(items); bool tabbed = false; if (e.type == EventType.KeyDown && e.keyCode == KeyCode.Tab) { if (items.Count > 0) { tabbed = true; } } float SafeZone = 15f; var previous = GUI.skin; GUI.skin = CustomSkin; GUILayout.Label(RichText.InColour(suggestions, Color.white * 0.8f)); GUILayout.BeginHorizontal(); if (tabbed) { CurrentCommand = items[0]; } GUI.SetNextControlName("CMDInput"); CurrentCommand = GUILayout.TextField(CurrentCommand, GUILayout.MaxWidth(Width - 50)); if (firstFrame) { GUI.FocusWindow(int.MaxValue); GUI.FocusControl("CMDInput"); firstFrame = false; } if (tabbed) { var txtF = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl); txtF.cursorIndex = CurrentCommand.Length; txtF.selectIndex = CurrentCommand.Length; } bool pin = GUILayout.Button(Pin, GUILayout.ExpandWidth(false)); if (pin) { PinCmd(CurrentCommand); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); // Log view area. scroll = GUILayout.BeginScrollView(scroll, false, true, GUILayout.Width((Width - SafeZone) * LOG_AREA)); for (int i = Log.Count - 1; i >= 0; i--) { var item = Log[i]; item.Draw(); } GUILayout.EndScrollView(); // Pinned commands area. scroll2 = GUILayout.BeginScrollView(scroll2, false, true, GUILayout.Width((Width - SafeZone) * (1f - LOG_AREA))); // Single pinned command. for (int i = 0; i < PinnedCommands.Count; i++) { var cmd = PinnedCommands[i]; GUILayout.BeginHorizontal(); bool run = GUILayout.Button(cmd, GUILayout.MaxWidth(100)); if (run) { ExecuteCommand(cmd); } bool delete = GUILayout.Button(Bin, GUILayout.ExpandWidth(false)); if (delete) { PinnedCommands.RemoveAt(i); i--; } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndHorizontal(); GUI.skin = previous; }); }
private void ExecuteCommand(string cmd) { (string command, string[] args) = SplitCommand(cmd); Debug.Log($"CMD: '{command}' with {args.Length} args"); if (command.StartsWith("-")) { // It's a variable get or set. string name = command.Remove(0, 1); if (GameVars.ContainsKey(name)) { var gv = GameVars[name]; if (!gv.FInfo.IsStatic) { LogText(RichText.InColour($"Game var '{name}' is not static, which is currently not fully supported: cannot read or write.", Color.yellow)); } else { try { // TODO add support for non-static variables and commands. if (args.Length == 0) { if (gv.FInfo.CanRead) { // Read varaible... LogBoxText(gv.Converter.MakeString(null, gv.FInfo)); } else { LogText(RichText.InColour($"That variable is a C# property, which is set to be write only.", Color.yellow)); } } else { if (gv.FInfo.CanWrite) { // Write variable. string old = null; if (GVWriteCompare) { old = gv.Converter.MakeString(null, gv.FInfo); } string error = gv.Converter.Write(null, gv.FInfo, args); bool worked = error == null; if (!worked) { LogText(RichText.InColour($"Failed to write to variable:\n{error}", Color.yellow)); } else if (GVWriteCompare) { string updated = gv.Converter.MakeString(null, gv.FInfo); LogBoxText($"{old} -> {updated}"); } } else { LogText(RichText.InColour($"That variable is a C# property, which is set to be read only.", Color.yellow)); } } } catch (Exception e) { LogText(RichText.InColour($"Exception when reading or writing value '{name}': {e}!", Color.yellow)); } } } else { LogText(RichText.InColour("Could not find that variable!", Color.yellow)); } } else { // Normal command. if (Commands.ContainsKey(command)) { var c = Commands[command]; if (c.HasStringReturn) { try { object[] realArgs = MakeArgs(c.ArgTypes, args, out string error); if (error != null) { LogText(RichText.InColour(error, Color.yellow)); } else { var r = c.Method.Invoke(null, realArgs); if (c.HasStringReturn && !string.IsNullOrWhiteSpace(r as string)) { LogBoxText(r as string); } else { LogText(RichText.InColour("Run successfully", Color.green)); } } } catch (Exception e) { LogText(RichText.InColour($"Exception when running command '{command}':\n{e}", Color.yellow)); } } } else { LogText(RichText.InColour("Could not find that command!", Color.yellow)); } } }