예제 #1
0
        void generarUI()
        {
            W8KeyboardManager.clearLayout();
            posPanelCentral             = new SGUIComponent();
            posPanelCentral.Position    = new Rect((Screen.width - anchoPanelCentral) / 2, (Screen.height - altoPanelCentral) / 4, anchoPanelCentral, altoPanelCentral);
            posGrupoPuntaje             = new SGUIComponent();
            posGrupoPuntaje.Parent      = posPanelCentral;
            posGrupoPuntaje.Position    = new Rect(10, 10, posPanelCentral.Position.width - 20, 80);
            labelCentralizado           = estilo.label;
            labelCentralizado.alignment = TextAnchor.MiddleCenter;
            estiloLabelPuntaje          = estilo.GetStyle("label_score");
            estiloValorPuntaje          = estilo.GetStyle("score");
            estiloBoton         = estilo.GetStyle("boton_principal");
            estiloBotonCancelar = estilo.GetStyle("boton_cancelar");

            posGrupoNombre          = new SGUIComponent();
            posGrupoNombre.Parent   = posPanelCentral;
            posGrupoNombre.Position = new Rect(10, posGrupoPuntaje.Position.yMax + 10, posPanelCentral.Position.width - 20, 100);
            posFondo = new Rect(0, 0, Screen.width, Screen.height);
            Color colorDeFondo = new Color(1f, 1f, 1f, 0.5f);

            texturaFondo = new Texture2D(1, 1);
            texturaFondo.SetPixel(0, 0, colorDeFondo);
            texturaFondo.Apply();

            CampoNombre        = new STextField();
            CampoNombre.Parent = posGrupoNombre;
            W8KeyboardManager.fields.Add(CampoNombre);
        }
예제 #2
0
    public void ShowAutocomplete()
    {
        if (GUI.Children.Count >= 3)
        {
            return;
        }
        STextField field = (STextField)GUI[1];

        // AUTO COMPLETIONATOR 3000
        // (by Zatherz)
        //
        // TODO: Make Tab autocomplete to the shared part of completions
        // TODO: AutocompletionRule interface and class per rule?
        // Create an input array by splitting it on spaces
        string inputtext = field.Text.Substring(0, field.CursorIndex);

        string[] input      = SplitArgs(inputtext);
        string   otherinput = string.Empty;

        if (field.CursorIndex < field.Text.Length)
        {
            otherinput = field.Text.Substring(field.CursorIndex + 1);
        }
        // Get where the command appears in the path so that we know where the arguments start
        int           commandindex = Commands.GetFirstNonUnitIndexInPath(input);
        List <string> pathlist     = new List <string>();

        for (int i = 0; i < input.Length - (input.Length - commandindex); i++)
        {
            pathlist.Add(input[i]);
        }

        string[] path = pathlist.ToArray();

        ConsoleCommandUnit unit = Commands.GetUnit(path);
        // Get an array of available completions
        int matchindex = input.Length - path.Length;

        /*
         *      HACK! blame Zatherz
         *      matchindex will be off by +1 if the current keyword your cursor is on isn't empty
         *      this will check if there are no spaces on the left on the cursor
         *      and if so, decrease matchindex
         *      if there *are* spaces on the left of the cursor, that means the current
         *      "token" the cursor is on is an empty string, so that doesn't have any problems
         *      Hopefully this is a good enough explanation, if not, ping @Zatherz on Discord
         */

        string matchkeyword = string.Empty;

        if (!inputtext.EndsWithInvariant(" "))
        {
            matchindex--;
            matchkeyword = input[input.Length - 1];
        }

        string[] completions = unit.Autocompletion.Match(Math.Max(matchindex, 0), matchkeyword);

        if (completions == null || completions.Length == 0)
        {
            Debug.Log("ETGModConsole: no completions available (match returned null)");
        }
        else if (completions.Length == 1)
        {
            if (path.Length > 0)
            {
                field.Text = string.Join(" ", path) + " " + completions[0] + " " + otherinput;
            }
            else
            {
                field.Text = completions[0] + " " + otherinput;
            }

            field.MoveCursor(field.Text.Length);
        }
        else if (completions.Length > 1)
        {
            SGroup hints = new SGroup {
                Parent          = GUI,
                AutoLayout      = (SGroup g) => g.AutoLayoutVertical,
                ScrollDirection = SGroup.EDirection.Vertical,
                OnUpdateStyle   = delegate(SElement elem) {
                    elem.Size     = new Vector2(elem.Parent.InnerSize.x, Mathf.Min(((SGroup)elem).ContentSize.y, 160f));
                    elem.Position = GUI[1].Position - new Vector2(0f, elem.Size.y + 4f);
                }
            };

            for (int i = 0; i < completions.Length; i++)
            {
                hints.Children.Add(new SLabel(completions[i]));
            }
        }
    }