public Console(BMFont font) : base(new Point(0, 0), new Point(500, 300), "Console" + UserInterface.GetUniqueElementID()) { textBox = new TextBox(font, null); textBox.RelativeTo = Corner.TopLeft; textBox.BackgroundColor = new Vector4(0, 0, 0, 0.5f); textBox.AllowScrollBar = true; this.AddElement(textBox); textEntry = new TextInput(font); textEntry.RelativeTo = Corner.BottomLeft; textEntry.BackgroundColor = new Vector4(0, 0, 0, 0.7f); this.AddElement(textEntry); textEntry.OnCarriageReturn = new TextInput.OnTextEvent(ExecuteCommand); }
private void ExecuteCommand(TextInput entry, string command) { if (command.Length == 0) { return; } entry.Clear(); textBox.Write(new Vector3(1, 1, 1), "> "); textBox.WriteLine(new Vector3(0, 0.6f, 0.9f), command); try { if (command.Contains(" ")) { int i = command.IndexOf(" "); string opcode = command.Substring(0, i); if (commands.ContainsKey(opcode)) { commands[opcode](command.Substring(i + 1)); } else { textBox.WriteLine(new Vector3(1f, 0, 0), "Unknown command"); } } else { if (commands.ContainsKey(command)) { commands[command](""); } else { textBox.WriteLine(new Vector3(1f, 0, 0), "Unknown command"); } } } catch (Exception e) { textBox.WriteLine(new Vector3(1f, 0, 0), "Exception while running command. " + e.Message); } }
private void ExecuteCommand(TextInput entry, string command) { if (command.Length == 0) { return; } entry.Clear(); this.textBox.Write(new Vector3(1f, 1f, 1f), "> "); this.textBox.WriteLine(new Vector3(0.0f, 0.6f, 0.9f), command); try { if (command.Contains(" ")) { int length = command.IndexOf(" "); string key = command.Substring(0, length); if (this.commands.ContainsKey(key)) { this.commands[key](command.Substring(length + 1)); } else { this.textBox.WriteLine(new Vector3(1f, 0.0f, 0.0f), "Unknown command"); } } else if (this.commands.ContainsKey(command)) { this.commands[command](""); } else { this.textBox.WriteLine(new Vector3(1f, 0.0f, 0.0f), "Unknown command"); } } catch (Exception ex) { this.textBox.WriteLine(new Vector3(1f, 0.0f, 0.0f), "Exception while running command. " + ex.Message); } }