fix various issues with console controls

This commit is contained in:
2023-05-19 00:30:31 +03:00
parent b5ec0b86b2
commit 3a59bad850
4 changed files with 41 additions and 17 deletions

View File

@@ -40,6 +40,8 @@ namespace Game
private int selectionStartLine;
public Color TextColor = Color.White;
public bool CopyOnSelect = true;
public TextWrapping Wrapping;
public ConsoleContentTextBox()
@@ -67,6 +69,12 @@ namespace Game
AutoFocus = false;
}
public override void OnDestroy()
{
base.OnDestroy();
EndMouseCapture();
}
public int FontHeight => Font.GetFont().Height;
public float HeightMultiplier
@@ -438,11 +446,15 @@ namespace Game
bool shiftDown = Root.GetKey(KeyboardKeys.Shift);
bool ctrlDown = Root.GetKey(KeyboardKeys.Control);
if ((shiftDown && key == KeyboardKeys.Delete) || (ctrlDown && key == KeyboardKeys.Insert) ||
(ctrlDown && key == KeyboardKeys.C) || (ctrlDown && key == KeyboardKeys.X))
if (!CopyOnSelect)
{
Copy();
return true;
// This is not working for some reason, the event is never called while selecting text
if ((shiftDown && key == KeyboardKeys.Delete) || (ctrlDown && key == KeyboardKeys.Insert) ||
(ctrlDown && key == KeyboardKeys.C) || (ctrlDown && key == KeyboardKeys.X))
{
Copy();
return true;
}
}
if (key == KeyboardKeys.PageUp)
@@ -463,7 +475,12 @@ namespace Game
//else if (ctrlDown && key == KeyboardKeys.A)
// SelectAll();
return base.OnKeyDown(key);
if (!base.OnKeyDown(key))
{
inputBox.Focus();
return inputBox.OnKeyDown(key);
}
return true;
}
public override bool OnMouseWheel(Float2 location, float delta)
@@ -493,17 +510,23 @@ namespace Game
if (!SelectionAllowed)
return false;
bool ret = false;
if (button == MouseButton.Left && !IsFocused)
if (!Bounds.Contains(location))
{
Focus();
ret = true;
OnSelectingEnd();
return false;
}
bool ret = false;
if (/*button == MouseButton.Left &&*/ !IsFocused)
{
//inputBox.Focus();
//ret = true;
}
if (button == MouseButton.Left && Console.Lines.Length > 0)
{
bool selectionStarted = !selectionActive;
Focus();
//Focus();
OnSelectingBegin();
//FlaxEngine.Debug.Log("mousedown, started: " + selectionStarted.ToString());
@@ -547,6 +570,8 @@ namespace Game
{
selectionEndLine = hitLine;
selectionEndChar = hitChar;
if (CopyOnSelect)
Copy();
//FlaxEngine.Debug.Log(string.Format("end line {0} char {1}", hitLine, hitChar));
}
}
@@ -558,13 +583,10 @@ namespace Game
return false;
if (button == MouseButton.Left)
{
OnSelectingEnd();
if (Bounds.Contains(location))
Focus(inputBox);
return true;
}
return false;
return true;
}
public override void OnMouseLeave()

View File

@@ -144,7 +144,7 @@ namespace Game
public override void OnLostFocus()
{
// Avoids reseting the caret location
// Prevent caret location getting reset back to beginning
bool oldEditing = _isEditing;
_isEditing = false;
base.OnLostFocus();

View File

@@ -17,13 +17,14 @@ namespace Game
#endif
}
private readonly InputEvent onExit = new InputEvent("Exit");
private InputEvent onExit;
public override void Initialize()
{
//FlaxEngine.Debug.Log("ConsolePlugin initialized");
Console.Init();
onExit = new InputEvent("Exit");
onExit.Triggered += () =>
{
if (Console.IsSafeToQuit)

View File

@@ -39,6 +39,7 @@ namespace Game
IsReadOnly = false;
CaretColor = new Color(1f, 1f, 1f, 1f);
AutoFocus = true;
EndEditOnClick = false;
_layout = TextLayoutOptions.Default;
_layout.VerticalAlignment = IsMultiline ? TextAlignment.Near : TextAlignment.Center;