public void SetMode(bool multiline) { var changed = MultiLineMode == multiline; MultiLineMode = multiline; if (MultiLineMode) { if (ConsoleSingleLine.Contains(ConsoleOutput)) { ConsoleSingleLine.Remove(ConsoleOutput); } UIUtils.SetElementDisplay(ConsoleSingleLine, !MultiLineMode); UIUtils.SetElementDisplay(ConsoleMultiLine, MultiLineMode); ConsoleMultiLine.Add(ConsoleOutput); RemoveFromClassList("singleline"); AddToClassList("multiline"); SetMultilineCode(State.Instance.ScriptCode, false); } else { // Make sure we store current script since we always restore it from state // when changing mode if (changed) { SaveMultiLineState(); } if (ConsoleMultiLine.Contains(ConsoleOutput)) { ConsoleMultiLine.Remove(ConsoleOutput); } UIUtils.SetElementDisplay(ConsoleSingleLine, !MultiLineMode); UIUtils.SetElementDisplay(ConsoleMultiLine, MultiLineMode); ConsoleSingleLine.Insert(0, ConsoleOutput); AddToClassList("singleline"); RemoveFromClassList("multiline"); } ConsoleOutput.ResetScrollView(true); }
/// <summary> /// Todo: separate in different class multiline/singleline /// </summary> public Console() { root = Resources.GetTemplate("Console.uxml"); Add(root); root.StretchToParentSize(); ConsoleOutput = new ConsoleOutput(); ConsoleOutput.name = "console-output"; ConsoleInput = new TextField(); ConsoleInput.multiline = false; ConsoleInput.name = "console-input"; ConsoleInput.RegisterCallback <KeyDownEvent>(evt => { if (!IsKeyEventUp(evt.keyCode) && evt.keyCode != KeyCode.None) { OnInputKeyPressed(evt.keyCode, evt.character); } }); // Currently a bug where KeyDown event is not sent for up/down arrow ConsoleInput.RegisterCallback <KeyUpEvent>(evt => { if (IsKeyEventUp(evt.keyCode)) { OnInputKeyPressed(evt.keyCode, evt.character); } }); ConsoleSingleLine.Add(ConsoleOutput); ConsoleSingleLine.Add(ConsoleInput); ConsoleInputMultiLine = new TextField(); ConsoleInputMultiLine.multiline = true; ConsoleInputMultiLine.name = "console-input-multiline"; ConsoleMultiLine.Add(ConsoleInputMultiLine); ConsoleInputMultiLine.RegisterCallback <KeyUpEvent>(OnMultiLineInputKeyPressed); ConsoleInputMultiLine.RegisterCallback <FocusOutEvent>(OnMultiLineFocusOut); ConsoleToolbar.Console = this; SetMode(MultiLineMode); }