Пример #1
0
        public void UseAutocomplete(string suggestion)
        {
            string input = InputField.text;

            input           = input.Insert(m_lastCaretPos, suggestion);
            InputField.text = input;

            m_fixCaretPos = m_lastCaretPos += suggestion.Length;

            var color = InputField.selectionColor;

            m_lastSelectAlpha         = color.a;
            color.a                   = 0f;
            InputField.selectionColor = color;

            AutoCompleter.ClearAutocompletes();
        }
Пример #2
0
        // ========== UI CONSTRUCTION =========== //

        public void ConstructUI()
        {
            CSConsolePage.Instance.Content = UIFactory.CreateUIObject("C# Console", MainMenu.Instance.PageViewport);

            var mainLayout = CSConsolePage.Instance.Content.AddComponent <LayoutElement>();

            mainLayout.preferredHeight = 500;
            mainLayout.flexibleHeight  = 9000;

            var mainGroup = CSConsolePage.Instance.Content.AddComponent <VerticalLayoutGroup>();

            mainGroup.childControlHeight     = true;
            mainGroup.childControlWidth      = true;
            mainGroup.childForceExpandHeight = true;
            mainGroup.childForceExpandWidth  = true;

            #region TOP BAR

            // Main group object

            var           topBarObj    = UIFactory.CreateHorizontalGroup(CSConsolePage.Instance.Content);
            LayoutElement topBarLayout = topBarObj.AddComponent <LayoutElement>();
            topBarLayout.minHeight      = 50;
            topBarLayout.flexibleHeight = 0;

            var topBarGroup = topBarObj.GetComponent <HorizontalLayoutGroup>();
            topBarGroup.padding.left           = 30;
            topBarGroup.padding.right          = 30;
            topBarGroup.padding.top            = 8;
            topBarGroup.padding.bottom         = 8;
            topBarGroup.spacing                = 10;
            topBarGroup.childForceExpandHeight = true;
            topBarGroup.childForceExpandWidth  = true;
            topBarGroup.childControlWidth      = true;
            topBarGroup.childControlHeight     = true;
            topBarGroup.childAlignment         = TextAnchor.LowerCenter;

            var topBarLabel       = UIFactory.CreateLabel(topBarObj, TextAnchor.MiddleLeft);
            var topBarLabelLayout = topBarLabel.AddComponent <LayoutElement>();
            topBarLabelLayout.preferredWidth = 150;
            topBarLabelLayout.flexibleWidth  = 5000;
            var topBarText = topBarLabel.GetComponent <Text>();
            topBarText.text     = "C# Console";
            topBarText.fontSize = 20;

            // Enable Ctrl+R toggle

            var ctrlRToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle ctrlRToggle, out Text ctrlRToggleText);
            ctrlRToggle.onValueChanged.AddListener(CtrlRToggleCallback);
            void CtrlRToggleCallback(bool val)
            {
                EnableCtrlRShortcut = val;
            }

            ctrlRToggleText.text      = "Run on Ctrl+R";
            ctrlRToggleText.alignment = TextAnchor.UpperLeft;
            var ctrlRLayout = ctrlRToggleObj.AddComponent <LayoutElement>();
            ctrlRLayout.minWidth      = 140;
            ctrlRLayout.flexibleWidth = 0;
            ctrlRLayout.minHeight     = 25;

            // Enable Suggestions toggle

            var suggestToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle suggestToggle, out Text suggestToggleText);
            suggestToggle.onValueChanged.AddListener(SuggestToggleCallback);
            void SuggestToggleCallback(bool val)
            {
                EnableAutocompletes = val;
                AutoCompleter.Update();
            }

            suggestToggleText.text      = "Suggestions";
            suggestToggleText.alignment = TextAnchor.UpperLeft;
            var suggestLayout = suggestToggleObj.AddComponent <LayoutElement>();
            suggestLayout.minWidth      = 120;
            suggestLayout.flexibleWidth = 0;
            suggestLayout.minHeight     = 25;

            // Enable Auto-indent toggle

            var autoIndentToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle autoIndentToggle, out Text autoIndentToggleText);
            autoIndentToggle.onValueChanged.AddListener(OnIndentChanged);
            void OnIndentChanged(bool val) => EnableAutoIndent = val;

            autoIndentToggleText.text      = "Auto-indent on Enter";
            autoIndentToggleText.alignment = TextAnchor.UpperLeft;

            var autoIndentLayout = autoIndentToggleObj.AddComponent <LayoutElement>();
            autoIndentLayout.minWidth      = 180;
            autoIndentLayout.flexibleWidth = 0;
            autoIndentLayout.minHeight     = 25;

            #endregion

            #region CONSOLE INPUT

            int fontSize = 16;

            var inputObj = UIFactory.CreateSrollInputField(CSConsolePage.Instance.Content, out InputFieldScroller consoleScroll, fontSize);

            var inputField = consoleScroll.inputField;

            var mainTextObj   = inputField.textComponent.gameObject;
            var mainTextInput = inputField.textComponent;
            mainTextInput.supportRichText = false;
            mainTextInput.color           = new Color(1, 1, 1, 0.5f);

            var placeHolderText = inputField.placeholder.GetComponent <Text>();
            placeHolderText.text     = STARTUP_TEXT;
            placeHolderText.fontSize = fontSize;

            var highlightTextObj  = UIFactory.CreateUIObject("HighlightText", mainTextObj.gameObject);
            var highlightTextRect = highlightTextObj.GetComponent <RectTransform>();
            highlightTextRect.pivot     = new Vector2(0, 1);
            highlightTextRect.anchorMin = Vector2.zero;
            highlightTextRect.anchorMax = Vector2.one;
            highlightTextRect.offsetMin = new Vector2(20, 0);
            highlightTextRect.offsetMax = new Vector2(14, 0);

            var highlightTextInput = highlightTextObj.AddComponent <Text>();
            highlightTextInput.supportRichText = true;
            highlightTextInput.fontSize        = fontSize;

            #endregion

            #region COMPILE BUTTON

            var compileBtnObj    = UIFactory.CreateButton(CSConsolePage.Instance.Content);
            var compileBtnLayout = compileBtnObj.AddComponent <LayoutElement>();
            compileBtnLayout.preferredWidth = 80;
            compileBtnLayout.flexibleWidth  = 0;
            compileBtnLayout.minHeight      = 45;
            compileBtnLayout.flexibleHeight = 0;
            var compileButton    = compileBtnObj.GetComponent <Button>();
            var compileBtnColors = compileButton.colors;
            compileBtnColors.normalColor = new Color(14f / 255f, 80f / 255f, 14f / 255f);
            compileButton.colors         = compileBtnColors;
            var btnText = compileBtnObj.GetComponentInChildren <Text>();
            btnText.text     = "Run";
            btnText.fontSize = 18;
            btnText.color    = Color.white;

            // Set compile button callback now that we have the Input Field reference
            compileButton.onClick.AddListener(CompileCallback);
            void CompileCallback()
            {
                if (!string.IsNullOrEmpty(inputField.text))
                {
                    CSConsolePage.Instance.Evaluate(inputField.text.Trim());
                }
            }

            #endregion

            //mainTextInput.supportRichText = false;

            mainTextInput.font      = UIManager.ConsoleFont;
            placeHolderText.font    = UIManager.ConsoleFont;
            highlightTextInput.font = UIManager.ConsoleFont;

            // reset this after formatting finalized
            highlightTextRect.anchorMin = Vector2.zero;
            highlightTextRect.anchorMax = Vector2.one;
            highlightTextRect.offsetMin = Vector2.zero;
            highlightTextRect.offsetMax = Vector2.zero;

            // assign references

            this.InputField = inputField;

            this.InputText          = mainTextInput;
            this.inputHighlightText = highlightTextInput;
        }
Пример #3
0
 internal void UpdateAutocompletes()
 {
     AutoCompleter.CheckAutocomplete();
     AutoCompleter.SetSuggestions(AutoCompletes.ToArray());
 }