Exemple #1
0
        private void DoParameterSuggestions(int termIdx)
        {
            // TODO - null ptr checks for suggestion text box

            CommandDef commandDef = CommandRegistry.GetCommand(UserInputTerms[0]);

            if (!commandDef.IsValid())
            {
                SuggestionText.text = "No Matching Commands!";
                return;
            }
            Assert.IsTrue(commandDef.IsValid());

            if (termIdx < 0 || termIdx >= commandDef.Command.GetNumExpectedTerms())
            {
                return;
            }

            string[] terms = commandDef.GetCommandFormatAsTerms();
            if (termIdx < terms.Length)
            {
                terms[termIdx] = "<b><color=#ffffffff>" + terms[termIdx] + "</color></b>";
            }

            SuggestionText.text += Utils.GetCommand(terms) + "\n";

            string searchTerm       = termIdx < UserInputTerms.Length ? UserInputTerms[termIdx] : "";
            int    paramIdx         = termIdx - 1;
            var    cmd              = commandDef.Command;
            var    paramSuggestions = ParameterProcessorRegistry.FindSuggestionsFor(cmd.GetParamType(paramIdx), cmd.GetParameterAttributes(paramIdx), searchTerm, 20);

            if (paramSuggestions != null)
            {
                string suggestionDisplayPrefix = "";
                for (int i = 0; i < Mathf.Min(terms.Length, termIdx); i++)
                {
                    suggestionDisplayPrefix += terms[i] + " ";
                }

                suggestionDisplayPrefix = "<color=#ffffff00>" + suggestionDisplayPrefix + "</color>";

                for (int i = 0, num = paramSuggestions.Count; i < num; i++)
                {
                    var paramSuggestion = paramSuggestions[i];
                    Suggestions.Add(paramSuggestion);
                    SuggestionText.text += suggestionDisplayPrefix + paramSuggestion.Display + "\n";
                }
            }
        }