Beispiel #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";
                }
            }
        }
Beispiel #2
0
        private void DoCommandSuggestions()
        {
            // TODO - null ptr checks for suggestion text box

            var suggestions = ParameterProcessorRegistry.FindSuggestionsFor(typeof(CommandDef), null, UserInputTerms[0], 20);

            for (int i = 0, num = suggestions.Count; i < num; i++)
            {
                var suggestion = suggestions[i];
                var commandDef = (CommandDef)ParameterProcessorRegistry.ConvertString(typeof(CommandDef), suggestion.Value);
                if (commandDef.IsValid())
                {
                    Suggestions.Add(commandDef.Name);
                    SuggestionText.text += commandDef.GetCommandFormat() + "\n";
                }
                else
                {
                    Suggestions.Add(suggestion.Value);
                    SuggestionText.text += suggestion.Display + "\n";
                }
            }
        }