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); }
protected void DrawArugments() { ArgumentDescriptionAttribute[] ArgTypes = CheatCommand.argumentsTypes; string[] Arguments = CheatCommand.arguments; int DrawCount = 0; if (ArgTypes != null && ArgTypes.Length > 0) { DebugHelper.Assert(ArgTypes.Length == Arguments.Length); for (int i = 0; i < ArgTypes.Length; ++i) { ArgumentDescriptionAttribute ArgAttr = ArgTypes[i]; if (!DrawArgument(ArgAttr, i, ArgTypes, ref Arguments, ref Arguments[i])) { break; } ++DrawCount; } } if (DrawButton(CheatCommand.comment)) { logger.AddMessage(CheatCommand.StartProcess(Arguments)); } }
private void DrawCommand(string InGroupName, string InName, ICheatCommand InCommand) { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); ArgumentDescriptionAttribute[] ArgTypes = InCommand.argumentsTypes; string[] Arguments = InCommand.arguments; if (ArgTypes != null && ArgTypes.Length > 0) { DebugHelper.Assert(ArgTypes.Length == Arguments.Length); for (int i = 0; i < ArgTypes.Length; ++i) { ArgumentDescriptionAttribute ArgAttr = ArgTypes[i]; if (!DrawArgument(ArgAttr, ArgTypes, ref Arguments, ref Arguments[i])) { break; } } } if (GUILayout.Button(InCommand.comment, GUILayout.Width(InCommand.comment.Length * 12 + 10))) { Logger.AddMessage(InCommand.StartProcess(Arguments)); } GUILayout.EndHorizontal(); }
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); }
protected virtual bool CheckDependencies( ArgumentDescriptionAttribute InArugmentDescription, DependencyDescription[] InDependencies, string[] InArguments, out string OutMessage ) { OutMessage = ""; if (InArguments == null) { OutMessage = "Missing parameters"; return(false); } for (int i = 0; i < InDependencies.Length; ++i) { DependencyDescription CurDependency = InDependencies[i]; DebugHelper.Assert(CurDependency.dependsIndex >= 0 && CurDependency.dependsIndex < argumentsTypes.Length, "maybe internal error, can't find depend argument description."); if (CurDependency.dependsIndex < 0 || CurDependency.dependsIndex >= argumentsTypes.Length) { OutMessage = "maybe internal error, can't find depend argument description."; return(false); } DebugHelper.Assert(CurDependency.dependsIndex < InArguments.Length); // try convert to actual value string CurDependValue = InArguments[CurDependency.dependsIndex]; Type DependType = argumentsTypes[CurDependency.dependsIndex].argumentType; var ArgDescriptionInterface = ArgumentDescriptionRepository.instance.GetDescription(DependType); DebugHelper.Assert(ArgDescriptionInterface != null); CurDependValue = ArgDescriptionInterface.GetValue(DependType, CurDependValue); if (CurDependency.ShouldBackOff(CurDependValue)) { OutMessage = string.Format( "you must provide parameter <{2}>, because <{0}>=\"{1}\"", argumentsTypes[CurDependency.dependsIndex].name, CurDependValue, InArugmentDescription.name ); return(false); } } return(true); }
protected void CacheArgumentDescriptions() { ParameterInfo[] Parameters = Method.GetParameters(); if (Parameters != null && Parameters.Length > 0) { ArgumentDescs = new ArgumentDescriptionAttribute[Parameters.Length]; for (int i = 0; i < ArgumentDescs.Length; ++i) { ArgumentDescs[i] = new ArgumentDescriptionAttribute( ArgumentDescriptionAttribute.EDefaultValueTag.Tag, i, Parameters[i].ParameterType, Parameters[i].Name, Parameters[i].DefaultValue != null ? Parameters[i].DefaultValue.ToString() : "" ); } } }
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); }
internal void IndependentInitialize(object[] InReferencesArguments) { if (!bHasInitialized) { bHasInitialized = true; argumentsTypes = new ArgumentDescriptionAttribute[InReferencesArguments.Length]; for (int i = 0; i < argumentsTypes.Length; ++i) { argumentsTypes[i] = InReferencesArguments[i] as ArgumentDescriptionAttribute; DebugHelper.Assert(argumentsTypes[i] != null); } // order first Array.Sort(argumentsTypes, new ADAComparer()); // check dependencies for (int i = 0; i < argumentsTypes.Length; ++i) { argumentsTypes[i].ValidateDependencies(i - 1); } } }
public static bool TypeCastCheck(string InArgument, ArgumentDescriptionAttribute InArgDescription, out string OutErrorMessage) { DebugHelper.Assert(InArgDescription != null); return(TypeCastCheck(InArgument, InArgDescription.argumentType, out OutErrorMessage)); }
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); }