コード例 #1
0
    protected virtual bool CheckDependencies(ArgumentDescriptionAttribute InArugmentDescription, DependencyDescription[] InDependencies, string[] InArguments, out string OutMessage)
    {
        OutMessage = string.Empty;
        if (InArguments == null)
        {
            OutMessage = "缺少所有必要参数";
            return(false);
        }
        for (int i = 0; i < InDependencies.Length; i++)
        {
            DependencyDescription dependencyDescription = InDependencies[i];
            DebugHelper.Assert(dependencyDescription.dependsIndex >= 0 && dependencyDescription.dependsIndex < this.argumentsTypes.Length, "maybe internal error, can't find depend argument description.");
            if (dependencyDescription.dependsIndex < 0 || dependencyDescription.dependsIndex >= this.argumentsTypes.Length)
            {
                OutMessage = "maybe internal error, can't find depend argument description.";
                return(false);
            }
            DebugHelper.Assert(dependencyDescription.dependsIndex < InArguments.Length);
            string text         = InArguments[dependencyDescription.dependsIndex];
            Type   argumentType = this.argumentsTypes[dependencyDescription.dependsIndex].argumentType;
            IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(argumentType);

            DebugHelper.Assert(description != null);
            text = description.GetValue(argumentType, text);
            if (dependencyDescription.ShouldBackOff(text))
            {
                OutMessage = string.Format("您必须提供参数<{2}>, 因为参数<{0}>=\"{1}\"", this.argumentsTypes[dependencyDescription.dependsIndex].name, text, InArugmentDescription.name);
                return(false);
            }
        }
        return(true);
    }
コード例 #2
0
    private bool DrawArgument(ArgumentDescriptionAttribute InArgAttr, int InIndex, ArgumentDescriptionAttribute[] InArgTypes, ref string[] OutValues, ref string OutValue)
    {
        if (InArgAttr.isOptional && this.ShouldSkip(InArgAttr, ref OutValues))
        {
            return(false);
        }
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        base.DrawLabel(InArgAttr.name);
        string name = string.Format("Argument_{0}", GUIUtility.GetControlID(FocusType.Keyboard));

        GUI.SetNextControlName(name);
        GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(200f) };
        OutValue = GUILayout.TextField(OutValue, base.ParentView.CustomTextFieldStyle, options);
        if (GUI.GetNameOfFocusedControl() == name)
        {
            IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(InArgAttr.argumentType);

            DebugHelper.Assert(description != null);
            List <string> list = description.FilteredCandinates(InArgAttr.argumentType, OutValue);
            if ((list != null) && (list.Count > 0))
            {
                for (int i = 0; i < list.Count; i++)
                {
                    string inButtonText = list[i];
                    if (!inButtonText.Equals(OutValue, StringComparison.InvariantCultureIgnoreCase) && base.DrawButton(inButtonText, string.Empty))
                    {
                        OutValue = inButtonText;
                        break;
                    }
                }
            }
        }
        GUILayout.EndHorizontal();
        return(true);
    }
コード例 #3
0
 public virtual bool CheckArguments(string[] InArguments, out string OutMessage)
 {
     if (this.argumentsTypes != null && this.argumentsTypes.Length > 0)
     {
         for (int i = 0; i < this.argumentsTypes.Length; i++)
         {
             ArgumentDescriptionAttribute argumentDescriptionAttribute = this.argumentsTypes[i];
             if (InArguments == null || i >= InArguments.Length)
             {
                 if (!argumentDescriptionAttribute.isOptional)
                 {
                     OutMessage = string.Format("无法执行命令,因为缺少参数<{0}>, 类型为:<{1}>", argumentDescriptionAttribute.name, argumentDescriptionAttribute.argumentType.get_Name());
                     return(false);
                 }
                 DependencyDescription[] depends = argumentDescriptionAttribute.depends;
                 if (depends != null && !this.CheckDependencies(argumentDescriptionAttribute, depends, InArguments, out OutMessage))
                 {
                     return(false);
                 }
             }
             else if (!argumentDescriptionAttribute.isOptional)
             {
                 string text;
                 if (!CheatCommandBase.TypeCastCheck(InArguments[i], this.argumentsTypes[i], out text))
                 {
                     OutMessage = string.Format("无法执行命令,因为参数[{2}]=\"{0}\"无法转换到{1}, 错误信息:{3}", new object[]
                     {
                         InArguments[i],
                         this.argumentsTypes[i].argumentType.get_Name(),
                         this.GetArgumentNameAt(i),
                         text
                     });
                     return(false);
                 }
             }
             else
             {
                 DependencyDescription[] depends2 = argumentDescriptionAttribute.depends;
                 string text2;
                 if (depends2 != null && !this.CheckDependencies(argumentDescriptionAttribute, depends2, InArguments, out OutMessage) && !CheatCommandBase.TypeCastCheck(InArguments[i], this.argumentsTypes[i], out text2))
                 {
                     OutMessage = string.Format("无法执行命令,因为参数[{2}]=\"{0}\"无法转换到{1}, 错误信息:{3}", new object[]
                     {
                         InArguments[i],
                         this.argumentsTypes[i].argumentType.get_Name(),
                         this.GetArgumentNameAt(i),
                         text2
                     });
                     return(false);
                 }
             }
         }
     }
     OutMessage = string.Empty;
     return(true);
 }
コード例 #4
0
ファイル: CheatCommandBase.cs プロジェクト: isoundy000/wzry-1
 public virtual bool CheckArguments(string[] InArguments, out string OutMessage)
 {
     if ((this.argumentsTypes != null) && (this.argumentsTypes.Length > 0))
     {
         for (int i = 0; i < this.argumentsTypes.Length; i++)
         {
             ArgumentDescriptionAttribute inArugmentDescription = this.argumentsTypes[i];
             if ((InArguments == null) || (i >= InArguments.Length))
             {
                 if (!inArugmentDescription.isOptional)
                 {
                     OutMessage = string.Format("无法执行命令,因为缺少参数<{0}>, 类型为:<{1}>", inArugmentDescription.name, inArugmentDescription.argumentType.Name);
                     return(false);
                 }
                 DependencyDescription[] depends = inArugmentDescription.depends;
                 if ((depends != null) && !this.CheckDependencies(inArugmentDescription, depends, InArguments, out OutMessage))
                 {
                     return(false);
                 }
             }
             else if (!inArugmentDescription.isOptional)
             {
                 string str;
                 if (!TypeCastCheck(InArguments[i], this.argumentsTypes[i], out str))
                 {
                     object[] args = new object[] { InArguments[i], this.argumentsTypes[i].argumentType.Name, this.GetArgumentNameAt(i), str };
                     OutMessage = string.Format("无法执行命令,因为参数[{2}]=\"{0}\"无法转换到{1}, 错误信息:{3}", args);
                     return(false);
                 }
             }
             else
             {
                 string str2;
                 DependencyDescription[] inDependencies = inArugmentDescription.depends;
                 if (((inDependencies != null) && !this.CheckDependencies(inArugmentDescription, inDependencies, InArguments, out OutMessage)) && !TypeCastCheck(InArguments[i], this.argumentsTypes[i], out str2))
                 {
                     object[] objArray2 = new object[] { InArguments[i], this.argumentsTypes[i].argumentType.Name, this.GetArgumentNameAt(i), str2 };
                     OutMessage = string.Format("无法执行命令,因为参数[{2}]=\"{0}\"无法转换到{1}, 错误信息:{3}", objArray2);
                     return(false);
                 }
             }
         }
     }
     OutMessage = string.Empty;
     return(true);
 }
コード例 #5
0
    private bool ShouldSkip(ArgumentDescriptionAttribute InArgAttr, ref string[] ExistsValues)
    {
        DebugHelper.Assert(InArgAttr.isOptional);
        foreach (DependencyDescription description in InArgAttr.depends)
        {
            string               inArgument   = ExistsValues[description.dependsIndex];
            System.Type          argumentType = this.CheatCommand.argumentsTypes[description.dependsIndex].argumentType;
            IArgumentDescription description2 = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(argumentType);

            DebugHelper.Assert(description2 != null);
            inArgument = description2.GetValue(argumentType, inArgument);
            if (description.ShouldBackOff(inArgument))
            {
                return(false);
            }
        }
        return(true);
    }
コード例 #6
0
    private bool ShouldSkip(ArgumentDescriptionAttribute InArgAttr, ref string[] ExistsValues)
    {
        DebugHelper.Assert(InArgAttr.isOptional);
        DependencyDescription[] depends = InArgAttr.depends;
        for (int i = 0; i < depends.Length; i++)
        {
            DependencyDescription dependencyDescription = depends[i];
            string text         = ExistsValues[dependencyDescription.dependsIndex];
            Type   argumentType = this.CheatCommand.argumentsTypes[dependencyDescription.dependsIndex].argumentType;
            IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(argumentType);

            DebugHelper.Assert(description != null);
            text = description.GetValue(argumentType, text);
            if (dependencyDescription.ShouldBackOff(text))
            {
                return(false);
            }
        }
        return(true);
    }
コード例 #7
0
    private bool DrawArgument(ArgumentDescriptionAttribute InArgAttr, int InIndex, ArgumentDescriptionAttribute[] InArgTypes, ref string[] OutValues, ref string OutValue)
    {
        if (InArgAttr.isOptional && this.ShouldSkip(InArgAttr, ref OutValues))
        {
            return(false);
        }
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        base.DrawLabel(InArgAttr.name);
        string text = string.Format("Argument_{0}", GUIUtility.GetControlID(FocusType.Keyboard));

        GUI.SetNextControlName(text);
        OutValue = GUILayout.TextField(OutValue, this.ParentView.CustomTextFieldStyle, new GUILayoutOption[]
        {
            GUILayout.Width(200f)
        });
        string nameOfFocusedControl = GUI.GetNameOfFocusedControl();

        if (nameOfFocusedControl == text)
        {
            IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(InArgAttr.argumentType);

            DebugHelper.Assert(description != null);
            List <string> list = description.FilteredCandinates(InArgAttr.argumentType, OutValue);
            if (list != null && list.get_Count() > 0)
            {
                for (int i = 0; i < list.get_Count(); i++)
                {
                    string text2 = list.get_Item(i);
                    if (!text2.Equals(OutValue, 3) && base.DrawButton(text2, string.Empty))
                    {
                        OutValue = text2;
                        break;
                    }
                }
            }
        }
        GUILayout.EndHorizontal();
        return(true);
    }
コード例 #8
0
    protected void DrawArugments()
    {
        ArgumentDescriptionAttribute[] argumentsTypes = this.CheatCommand.argumentsTypes;
        string[] arguments = this.CheatCommand.arguments;
        int      num       = 0;

        if (argumentsTypes != null && argumentsTypes.Length > 0)
        {
            DebugHelper.Assert(argumentsTypes.Length == arguments.Length);
            for (int i = 0; i < argumentsTypes.Length; i++)
            {
                ArgumentDescriptionAttribute inArgAttr = argumentsTypes[i];
                if (!this.DrawArgument(inArgAttr, i, argumentsTypes, ref arguments, ref arguments[i]))
                {
                    break;
                }
                num++;
            }
        }
        if (base.DrawButton(this.CheatCommand.comment, string.Empty))
        {
            base.logger.AddMessage(this.CheatCommand.StartProcess(arguments));
        }
    }
コード例 #9
0
        private bool ShouldSkip(ArgumentDescriptionAttribute InArgAttr, ref string[] ExistsValues)
        {
            DebugHelper.Assert(InArgAttr.isOptional);

            DependencyDescription[] Dependencies = InArgAttr.depends;

            for (int i = 0; i < Dependencies.Length; ++i)
            {
                DependencyDescription Depend = Dependencies[i];

                string ExistsValue = ExistsValues[Depend.dependsIndex];

                var DependType = CheatCommand.argumentsTypes[Depend.dependsIndex].argumentType;

                var ArgDescInterface = ArgumentDescriptionRepository.instance.GetDescription(DependType);

                DebugHelper.Assert(ArgDescInterface != null);

                ExistsValue = ArgDescInterface.GetValue(DependType, ExistsValue);

                if (Depend.ShouldBackOff(ExistsValue))
                {
                    return false;
                }
            }

            return true;
        }
コード例 #10
0
        private bool DrawArgument(
            ArgumentDescriptionAttribute InArgAttr,
            int InIndex,
            ArgumentDescriptionAttribute[] InArgTypes,
            ref string[] OutValues,
            ref string OutValue
            )
        {
            if (InArgAttr.isOptional && ShouldSkip(InArgAttr, ref OutValues))
            {
                return false;
            }

            GUILayout.BeginHorizontal();

            DrawLabel(InArgAttr.name);

            // string InputName = string.Format("{0}_{1}", CheatCommand.command.baseName, InArgAttr.index);
            string InputName = string.Format("Argument_{0}", GUIUtility.GetControlID(FocusType.Keyboard));

            GUI.SetNextControlName(InputName);

            OutValue = GUILayout.TextField(OutValue, ParentView.CustomTextFieldStyle, GUILayout.Width(200));

            string FocusedName = GUI.GetNameOfFocusedControl();

            if (FocusedName == InputName)
            {
                // let try get some helper for this argument
                IArgumentDescription ArgDescInterface = ArgumentDescriptionRepository.instance.GetDescription(InArgAttr.argumentType);

                DebugHelper.Assert(ArgDescInterface != null);

                List<String> Results = ArgDescInterface.FilteredCandinates(InArgAttr.argumentType, OutValue);

                if (Results != null && Results.Count > 0)
                {
                    for (int i = 0; i < Results.Count; ++i)
                    {
                        string CandinateName = Results[i];

                        if (!CandinateName.Equals(OutValue, StringComparison.InvariantCultureIgnoreCase)
                            && DrawButton(CandinateName)
                            )
                        {
                            OutValue = CandinateName;
                            break;
                        }
                    }
                }
            }

            GUILayout.EndHorizontal();

            return true;
        }
コード例 #11
0
 public static bool TypeCastCheck(string InArgument, ArgumentDescriptionAttribute InArgDescription, out string OutErrorMessage)
 {
     DebugHelper.Assert(InArgDescription != null);
     return(CheatCommandBase.TypeCastCheck(InArgument, InArgDescription.argumentType, out OutErrorMessage));
 }
コード例 #12
0
        private bool DrawArgument(
            ArgumentDescriptionAttribute InArgAttr,
            ArgumentDescriptionAttribute[] InArgTypes,
            ref string[] OutValues,
            ref string OutValue
        )
        {
            string DummyString = "";

            if (InArgAttr.isOptional && ShouldSkip(InArgAttr, ref OutValues))
            {
                return false;
            }

            EditorGUILayout.LabelField(InArgAttr.name, GUILayout.Width(InArgAttr.name.Length * 12 + 5));

            if (InArgAttr.isEnum)
            {
                Enum TagEnum = null;

                if (string.IsNullOrEmpty(OutValue))
                {
                    Array Values = Enum.GetValues(InArgAttr.argumentType);

                    DebugHelper.Assert(Values.Length > 0);

                    TagEnum = (Enum)Values.GetValue(0);
                }
                else
                {
                    TagEnum = (Enum)Enum.Parse(InArgAttr.argumentType, OutValue);
                }

                Enum Result = EditorGUILayout.EnumPopup(TagEnum, GUILayout.Width(60));

                OutValue = Result.ToString();
            }
            else if (InArgAttr.argumentType == typeof(int))
            {
                int Value = 1;

                if (CheatCommandCommon.TypeCastCheck(OutValue, typeof(int), out DummyString))
                {
                    Value = CheatCommandCommon.SmartConvert<int>(OutValue);
                }

                Value = EditorGUILayout.IntField(Value, GUILayout.Width(60));

                OutValue = Value.ToString();
            }
            else if (InArgAttr.argumentType == typeof(float))
            {
                float Value = 1;

                if (CheatCommandCommon.TypeCastCheck(OutValue, typeof(float), out DummyString))
                {
                    Value = CheatCommandCommon.SmartConvert<float>(OutValue);
                }

                Value = EditorGUILayout.FloatField(Value, GUILayout.Width(60));

                OutValue = Value.ToString();
            }
            else
            {
                // string
                OutValue = EditorGUILayout.TextField(OutValue, GUILayout.Width(80));
            }

            return true;
        }
コード例 #13
0
        private bool ShouldSkip(ArgumentDescriptionAttribute InArgAttr, ref string[] ExistsValues)
        {
            DebugHelper.Assert(InArgAttr.isOptional);

            DependencyDescription[] Dependencies = InArgAttr.depends;

            for (int i = 0; i < Dependencies.Length; ++i)
            {
                DependencyDescription Depend = Dependencies[i];

                string ExistsValue = ExistsValues[Depend.dependsIndex];

                if (Depend.ShouldBackOff(ExistsValue))
                {
                    return false;
                }
            }

            return true;
        }