110 lines
3.2 KiB
C#
110 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using FlaxEditor;
|
|
using FlaxEngine;
|
|
using FlaxEngine.GUI;
|
|
|
|
namespace Cabrito
|
|
{
|
|
public class ConsoleInputTextBox : ConsoleTextBoxBase
|
|
{
|
|
public override string TextPrefix { get => Console.LinePrefix; }
|
|
|
|
private ConsoleContentTextBox contentBox;
|
|
|
|
public ConsoleInputTextBox() : base()
|
|
{
|
|
|
|
}
|
|
|
|
public ConsoleInputTextBox(ConsoleContentTextBox contentBox, float x, float y, float width, float height) : base(x, y, width, height)
|
|
{
|
|
this.contentBox = contentBox;
|
|
IsMultiline = true; // Not really but behaves better than single-line box
|
|
}
|
|
|
|
public override bool OnCharInput(char c)
|
|
{
|
|
// Ignore any characters generated by the key which opens the console
|
|
var consoleKeyMappings = Input.ActionMappings.Where(x => x.Name == "Console" && x.Key != KeyboardKeys.None);
|
|
foreach (var mapping in consoleKeyMappings)
|
|
{
|
|
if (Input.GetKey(mapping.Key))
|
|
return true;
|
|
}
|
|
|
|
return base.OnCharInput(c);
|
|
}
|
|
|
|
public override bool OnKeyDown(KeyboardKeys key)
|
|
{
|
|
var consoleKeyMappings = Input.ActionMappings.Where(x => x.Name == "Console" && x.Key != KeyboardKeys.None);
|
|
bool shiftDown = Root.GetKey(KeyboardKeys.Shift);
|
|
bool ctrlDown = Root.GetKey(KeyboardKeys.Control);
|
|
|
|
if (consoleKeyMappings.Any(x => x.Key == key))
|
|
{
|
|
Clear();
|
|
return true;
|
|
}
|
|
else if (key == KeyboardKeys.Escape)
|
|
{
|
|
Console.Close();
|
|
Clear();
|
|
return true;
|
|
}
|
|
else if (key == KeyboardKeys.Return)
|
|
{
|
|
try
|
|
{
|
|
Console.Execute(Text);
|
|
}
|
|
finally
|
|
{
|
|
Clear();
|
|
}
|
|
return true;
|
|
}
|
|
else if (key == KeyboardKeys.ArrowUp || key == KeyboardKeys.ArrowDown)
|
|
{
|
|
// TODO: implement input history
|
|
return true;
|
|
}
|
|
else if (key == KeyboardKeys.PageUp || key == KeyboardKeys.PageDown)
|
|
{
|
|
return contentBox.OnKeyDown(key);
|
|
}
|
|
|
|
return base.OnKeyDown(key);
|
|
}
|
|
|
|
public override void OnLostFocus()
|
|
{
|
|
// Avoids reseting the caret location
|
|
var oldEditing = _isEditing;
|
|
_isEditing = false;
|
|
base.OnLostFocus();
|
|
_isEditing = oldEditing;
|
|
}
|
|
|
|
public override bool OnMouseDown(Vector2 location, MouseButton button)
|
|
{
|
|
base.OnMouseDown(location, button);
|
|
return true;
|
|
}
|
|
|
|
public override bool OnMouseWheel(Vector2 location, float delta)
|
|
{
|
|
return contentBox.OnMouseWheel(location, delta);
|
|
}
|
|
|
|
public override void Draw()
|
|
{
|
|
Profiler.BeginEvent("ConsoleInputTextBoxDraw");
|
|
base.Draw();
|
|
Profiler.EndEvent();
|
|
}
|
|
}
|
|
}
|