Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/CSConsole/ConsoleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public ConsoleController()
}

_panel.OnInputChanged += OnInputChanged;
_panel.InputScroller.OnScroll += OnInputScrolled;
if (_panel.InputScroller != null)
{
_panel.InputScroller.OnScroll += OnInputScrolled;
}
_panel.OnCompileClicked += Evaluate;
_panel.OnResetClicked += ResetConsole;
_panel.OnDropdownChanged += SelectedDropDown;
Expand Down Expand Up @@ -454,7 +457,7 @@ private void UpdateCaret(out bool caretMoved)
}

// If caret moved, ensure caret is visible in the viewport
if (caretMoved)
if (caretMoved && !_panel.UsesSafeInputFallback)
{
UICharInfo charInfo = Input.TextGenerator.characters[lastCaretPosition];
float charTop = charInfo.cursorPos.y;
Expand Down Expand Up @@ -573,6 +576,12 @@ private void HighlightVisibleInput(out bool inStringOrComment)
return;
}

if (_panel.UsesSafeInputFallback)
{
HighlightCompleteInput(out inStringOrComment);
return;
}

// Calculate the visible lines

int topLine = -1;
Expand Down Expand Up @@ -654,6 +663,32 @@ private void HighlightVisibleInput(out bool inStringOrComment)
_panel.LineNumberText.text = sb.ToString();
}

private void HighlightCompleteInput(out bool inStringOrComment)
{
_panel.HighlightText.text = _lexer.BuildHighlightedString(Input.Text, 0, Input.Text.Length - 1, 0, lastCaretPosition, out inStringOrComment);

StringBuilder sb = new();
int realLine = 1;
sb.Append(realLine).Append('\n');

for (int i = 0; i < Input.Text.Length; i++)
{
char c = Input.Text[i];
if (c == '\r' || c == '\n')
{
if (c == '\r' && i + 1 < Input.Text.Length && Input.Text[i + 1] == '\n')
{
i++;
}

realLine++;
sb.Append(realLine).Append('\n');
}
}

_panel.LineNumberText.text = sb.ToString();
}

#endregion


Expand Down
37 changes: 34 additions & 3 deletions src/Hooks/HookCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class HookCreator : ICellPoolDataSource<AddHookCell>
public static GameObject EditorRoot { get; private set; }
public static Text EditingHookLabel { get; private set; }
public static InputFieldScroller EditorInputScroller { get; private set; }
public static InputFieldRef EditorInput => EditorInputScroller.InputField;
public static InputFieldRef EditorInputFallback { get; private set; }
public static InputFieldRef EditorInput => EditorInputScroller != null ? EditorInputScroller.InputField : EditorInputFallback;
public static Text EditorInputText { get; private set; }
public static Text EditorHighlightText { get; private set; }

Expand Down Expand Up @@ -299,8 +300,15 @@ public void ConstructEditor(GameObject parent)
editorDoneButton.OnClick += EditorInputCancel;

int fontSize = 16;
GameObject inputObj = UIFactory.CreateScrollInputField(EditorRoot, "EditorInput", "", out InputFieldScroller inputScroller, fontSize);
EditorInputScroller = inputScroller;
if (ExplorerCore.IsUnity6000OrNewer)
{
ConstructSafeEditorInput(fontSize);
}
else
{
ConstructScrollEditorInput(fontSize);
}

EditorInput.OnValueChanged += OnEditorInputChanged;

EditorInputText = EditorInput.Component.textComponent;
Expand Down Expand Up @@ -329,5 +337,28 @@ public void ConstructEditor(GameObject parent)
EditorInput.PlaceholderText.font = UniversalUI.ConsoleFont;
EditorHighlightText.font = UniversalUI.ConsoleFont;
}

private static void ConstructScrollEditorInput(int fontSize)
{
UIFactory.CreateScrollInputField(EditorRoot, "EditorInput", "", out InputFieldScroller inputScroller, fontSize);
EditorInputScroller = inputScroller;
}

private static void ConstructSafeEditorInput(int fontSize)
{
ExplorerCore.Log("Unity 6000 detected, using safe Hook Editor input fallback.");

EditorInputFallback = UIFactory.CreateInputField(EditorRoot, "EditorInput", "");
UIFactory.SetLayoutElement(EditorInputFallback.Component.gameObject, minWidth: 100, minHeight: 30, flexibleWidth: 5000, flexibleHeight: 5000);

EditorInputFallback.Component.lineType = InputField.LineType.MultiLineNewline;
EditorInputFallback.Component.targetGraphic.color = new Color(0.12f, 0.12f, 0.12f);
EditorInputFallback.Component.textComponent.alignment = TextAnchor.UpperLeft;
EditorInputFallback.Component.textComponent.fontSize = fontSize;
EditorInputFallback.Component.textComponent.horizontalOverflow = HorizontalWrapMode.Wrap;
EditorInputFallback.PlaceholderText.alignment = TextAnchor.UpperLeft;
EditorInputFallback.PlaceholderText.fontSize = fontSize;
EditorInputFallback.PlaceholderText.horizontalOverflow = HorizontalWrapMode.Wrap;
}
}
}
53 changes: 48 additions & 5 deletions src/UI/Panels/CSConsolePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class CSConsolePanel : UEPanel
public override Vector2 DefaultAnchorMax => new(0.85f, 0.925f);

public InputFieldScroller InputScroller { get; private set; }
public InputFieldRef Input => InputScroller.InputField;
public InputFieldRef InputFallback { get; private set; }
public InputFieldRef Input => InputScroller != null ? InputScroller.InputField : InputFallback;
public bool UsesSafeInputFallback => InputScroller == null && InputFallback != null;
public Text InputText { get; private set; }
public Text HighlightText { get; private set; }
public Text LineNumberText { get; private set; }
Expand Down Expand Up @@ -130,6 +132,7 @@ protected override void ConstructPanelContent()
linesRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 50);
linesHolder.AddComponent<Image>().color = new Color(0.05f, 0.05f, 0.05f);
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(linesHolder, true, true, true, true);
UIFactory.SetLayoutElement(linesHolder, minWidth: 50, flexibleWidth: 0, flexibleHeight: 9999);

LineNumberText = UIFactory.CreateLabel(linesHolder, "LineNumbers", "1", TextAnchor.UpperCenter, Color.grey, fontSize: 16);
LineNumberText.font = UniversalUI.ConsoleFont;
Expand All @@ -138,11 +141,25 @@ protected override void ConstructPanelContent()

int fontSize = 16;

if (ExplorerCore.IsUnity6000OrNewer)
{
ConstructSafeInputField(inputArea, fontSize);
}
else
{
ConstructScrollInputField(inputArea, linesRect, fontSize);
}

ConfigureInputVisuals(fontSize);

RuntimeHelper.StartCoroutine(DelayedLayoutSetup());
}

private void ConstructScrollInputField(GameObject inputArea, RectTransform linesRect, int fontSize)
{
GameObject inputObj = UIFactory.CreateScrollInputField(inputArea, "ConsoleInput", ConsoleController.STARTUP_TEXT,
out InputFieldScroller inputScroller, fontSize);
InputScroller = inputScroller;
ConsoleController.DefaultInputFieldAlpha = Input.Component.selectionColor.a;
Input.OnValueChanged += InvokeOnValueChanged;

// move line number text with input field
linesRect.transform.SetParent(inputObj.transform.Find("Viewport"), false);
Expand All @@ -153,6 +170,29 @@ void SetLinesPosition()
linesRect.anchoredPosition = new Vector2(linesRect.anchoredPosition.x, inputScroller.ContentRect.anchoredPosition.y);
//SetInputLayout();
}
}

private void ConstructSafeInputField(GameObject inputArea, int fontSize)
{
ExplorerCore.Log("Unity 6000 detected, using safe C# Console input fallback.");

InputFallback = UIFactory.CreateInputField(inputArea, "ConsoleInput", ConsoleController.STARTUP_TEXT);
UIFactory.SetLayoutElement(InputFallback.Component.gameObject, minWidth: 100, minHeight: 30, flexibleWidth: 5000, flexibleHeight: 5000);

InputFallback.Component.lineType = InputField.LineType.MultiLineNewline;
InputFallback.Component.targetGraphic.color = new Color(0.12f, 0.12f, 0.12f);
InputFallback.Component.textComponent.alignment = TextAnchor.UpperLeft;
InputFallback.Component.textComponent.fontSize = fontSize;
InputFallback.Component.textComponent.horizontalOverflow = HorizontalWrapMode.Wrap;
InputFallback.PlaceholderText.alignment = TextAnchor.UpperLeft;
InputFallback.PlaceholderText.fontSize = fontSize;
InputFallback.PlaceholderText.horizontalOverflow = HorizontalWrapMode.Wrap;
}

private void ConfigureInputVisuals(int fontSize)
{
ConsoleController.DefaultInputFieldAlpha = Input.Component.selectionColor.a;
Input.OnValueChanged += InvokeOnValueChanged;

InputText = Input.Component.textComponent;
InputText.supportRichText = false;
Expand All @@ -179,8 +219,6 @@ void SetLinesPosition()
InputText.font = UniversalUI.ConsoleFont;
Input.PlaceholderText.font = UniversalUI.ConsoleFont;
HighlightText.font = UniversalUI.ConsoleFont;

RuntimeHelper.StartCoroutine(DelayedLayoutSetup());
}

private IEnumerator DelayedLayoutSetup()
Expand All @@ -191,6 +229,11 @@ private IEnumerator DelayedLayoutSetup()

public void SetInputLayout()
{
if (UsesSafeInputFallback)
{
return;
}

Input.Transform.offsetMin = new Vector2(52, Input.Transform.offsetMin.y);
Input.Transform.offsetMax = new Vector2(2, Input.Transform.offsetMax.y);
}
Expand Down
26 changes: 24 additions & 2 deletions src/UI/Widgets/EvaluateWidget/GenericConstructorWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,30 @@ internal void ConstructUI(GameObject parent)
Title = UIFactory.CreateLabel(UIRoot, "Title", LocalizationManager.GetText("generic_arguments", "Generic Arguments"), TextAnchor.MiddleCenter);
UIFactory.SetLayoutElement(Title.gameObject, minHeight: 25, flexibleWidth: 9999);

GameObject scrollview = UIFactory.CreateScrollView(UIRoot, "GenericArgsScrollView", out ArgsHolder, out _, new(0.1f, 0.1f, 0.1f));
UIFactory.SetLayoutElement(scrollview, flexibleWidth: 9999, flexibleHeight: 9999);
if (ExplorerCore.IsUnity6000OrNewer)
{
ExplorerCore.Log("Unity 6000 detected, using safe Generic Arguments container fallback.");

ArgsHolder = UIFactory.CreateVerticalGroup(
UIRoot,
"GenericArgsContent",
true,
false,
true,
true,
0,
new Vector4(5, 5, 5, 5),
new(0.1f, 0.1f, 0.1f),
TextAnchor.UpperLeft);

UIFactory.SetLayoutElement(ArgsHolder, flexibleWidth: 9999, flexibleHeight: 9999);
}
else
{
GameObject scrollview = UIFactory.CreateScrollView(UIRoot, "GenericArgsScrollView", out ArgsHolder, out _, new(0.1f, 0.1f, 0.1f));
UIFactory.SetLayoutElement(scrollview, flexibleWidth: 9999, flexibleHeight: 9999);
}

UIFactory.SetLayoutGroup<VerticalLayoutGroup>(ArgsHolder, padTop: 5, padLeft: 5, padBottom: 5, padRight: 5);
}
}
Expand Down
Loading