/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(MemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); Tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; if (Display?.Name != null) { // Use name provided by the attribute DisplayName = Display.Name; } else { // Use filtered member name DisplayName = CustomEditorsUtil.GetPropertyNameUI(info.Name); } }
private void DrawUIOptions <T>(SerializedProperty headerProperty) { HeaderAttribute header = EditorGUIHelper.Attributes.GetSerializedPropertyFirstAttribute <T, HeaderAttribute>(headerProperty); if (null != header) { m_GUIOptionsFolded = EditorGUILayout.Foldout( m_GUIOptionsFolded, header.header, m_GUIOptionsFolded ? EditorGUIHelper.Styles.boldFoldout : EditorStyles.foldout ); if (!m_GUIOptionsFolded) { return; } } EditorGUIHelper.Drawing.DrawMultiValueObjectField <T>(m_DynamicInfoText); EditorGUIHelper.Drawing.DrawMultiValueObjectField <T>(m_StaticInfoText); if (null != header) { EditorGUILayout.Separator(); } }
/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(MemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); Tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; if (!IsReadOnly && info is FieldInfo fieldInfo && fieldInfo.IsInitOnly) { // Field declared with `readonly` keyword IsReadOnly = true; } if (!IsReadOnly && info is PropertyInfo propertyInfo && !propertyInfo.CanWrite) { // Property without a setter IsReadOnly = true; } if (Display?.Name != null) { // Use name provided by the attribute DisplayName = Display.Name; } else { // Use filtered member name DisplayName = CustomEditorsUtil.GetPropertyNameUI(info.Name); } }
private static string GetFieldHeaderInfo(FieldInfo fieldInfo) { HeaderAttribute header = Attribute.GetCustomAttribute (fieldInfo, typeof(HeaderAttribute)) as HeaderAttribute; return(header?.header); }
public override void OnGUI(SerializedProperty property, GUIContent label) { EditorGUILayout.Space(); HeaderAttribute attribute = fieldInfo.GetAttribute <HeaderAttribute> (); GUILayout.Label(attribute.header, EditorStyles.boldLabel); base.OnGUI(property, label); }
public static void AddHeader <T>(string fieldName, string displayOverride = null) { string displayName = (displayOverride != null ? displayOverride : ObjectNames.NicifyVariableName(fieldName)); FieldInfo fieldInfo = typeof(T).GetField(fieldName); HeaderAttribute headerAttribute = (HeaderAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(HeaderAttribute)); AddHeader(headerAttribute == null ? displayName : headerAttribute.header); }
private bool ParameterBehavior(IHttpBehavior behavior, string paramName, HeaderAttribute attr, int argIndex, Encoding encoding, Formatters.IFormatter formatter) { if (attr == null) { return(false); } behavior.HeaderKeys.Add(new HttpParameterBehavior(paramName, argIndex, encoding, formatter)); return(true); }
private CodeExpression CreateHeaderStatement(FieldInfo field, HeaderAttribute header) { var propertyFieldParameters = new CodeExpression[] { new CodePrimitiveExpression(header.header), new CodeVariableReferenceExpression($"EditorStyles.boldLabel") }; return(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(EditorGUILayout)), "LabelField", propertyFieldParameters)); }
public static bool DrawHeader(SerializedProperty property) { HeaderAttribute headerAttr = PropertyUtility.GetAttribute<HeaderAttribute>(property); if (headerAttr != null) { DrawHeader(headerAttr.header); return true; } return false; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { headerAttribute = attribute as HeaderAttribute; GUIStyle style = new GUIStyle(); style.normal.textColor = Color.white; EditorGUILayout.LabelField(headerAttribute.header, style); base.OnGUI(position, property, label); }
public async Task OnRequestAsync() { var apiAction = new ApiActionDescriptor(typeof(ITestApi).GetMethod("PostAsync")); var context = new TestRequestContext(apiAction, string.Empty); var attr = new HeaderAttribute("MyHeader", "laojiu"); await attr.OnRequestAsync(context); context.HttpContext.RequestMessage.Headers.TryGetValues("MyHeader", out IEnumerable <string> values); Assert.Equal("laojiu", values.First()); }
/// <summary> /// 绘制头部(HeaderAttribute是内置特性) /// </summary> /// <param name="headerLable"></param> static public bool DrawHeader(SerializedProperty property) { HeaderAttribute attribute = PropertyUtility.GetAttribute <HeaderAttribute>(property); if (attribute != null) { DrawHeader(attribute.header); return(true); } return(false); }
public static bool DrawHeader(AttributeWrapper wrapper) { HeaderAttribute headerAttr = wrapper.GetCustomAttributes <HeaderAttribute>().FirstOrDefault(); if (headerAttr != null) { DrawHeader(headerAttr.header); return(true); } return(false); }
private bool HandleHeaderAttribute(FieldInfo properyfield, object obj) { HeaderAttribute headerAtt = properyfield.GetCustomAttribute <HeaderAttribute>(); if (headerAtt != null) { GUILayout.BeginHorizontal(setting.testGUIskin.box); GUILayout.Label(headerAtt.header, setting.testGUIskin.customStyles[3]); GUILayout.EndHorizontal(); } return(true); }
public async Task IApiActionAttributeTest() { var context = new TestActionContext( httpApi: null, httpApiConfig: new HttpApiConfig(), apiActionDescriptor: new ApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync"))); var attr = new HeaderAttribute("MyHeader", "laojiu"); await attr.BeforeRequestAsync(context); context.RequestMessage.Headers.TryGetValues("MyHeader", out IEnumerable <string> values); Assert.Equal("laojiu", values.First()); }
private void AddMethodHeader(ILGenerator methodIlGenerator, HeaderAttribute header) { // Equivalent C#: // requestInfo.AddMethodHeader("name", "value"); // Stack: [..., requestInfo, requestInfo] methodIlGenerator.Emit(OpCodes.Dup); // Stack: [..., requestInfo, requestInfo, "name"] methodIlGenerator.Emit(OpCodes.Ldstr, header.Name); // Stack: [..., requestInfo, requestInfo, "name", "value"] methodIlGenerator.Emit(OpCodes.Ldstr, header.Value); // Stack: [..., requestInfo] methodIlGenerator.Emit(OpCodes.Callvirt, addMethodHeaderMethod); }
internal LabelElement Header(HeaderAttribute header) { var element = Header(header.Text); if (header.FontSize != -1) { element.Label.Font = new FontReference(element.Label.Font.Font, header.FontSize); } if (header.Color != 0) { element.Label.TextColor = Color.FromRGBA(header.Color); } return(element); }
public GraphParameterData(GraphParameter parameter, string name, bool isPublic, Type type, Attribute[] attributes, object tag) { Parameter = parameter; IsPublic = isPublic; Type = type; Tag = tag; Attributes = attributes; Order = (EditorOrderAttribute)Attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)Attributes.FirstOrDefault(x => x is EditorDisplayAttribute); Tooltip = (TooltipAttribute)Attributes.FirstOrDefault(x => x is TooltipAttribute); Space = (SpaceAttribute)Attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)Attributes.FirstOrDefault(x => x is HeaderAttribute); DisplayName = Display?.Name ?? name ?? parameter.Name; }
public object FromMessage(IMessage message) { if (message == null) { return(null); } if (message.Payload == null) { throw new ArgumentException("Message payload must not be null."); } object[] args = new object[_parameterMetadata.Length]; for (int i = 0; i < _parameterMetadata.Length; i++) { MethodParameterMetadata metadata = this._parameterMetadata[i]; Type expectedType = metadata.ParameterType; HeaderAttribute headerAttr = metadata.HeaderAttr; if (headerAttr != null) { string headerName = metadata.HeaderName; object value = message.Headers.Get(headerName); if (value == null && headerAttr.Required) { throw new MessageHandlingException(message, "required header '" + headerName + "' not available"); } args[i] = value; } else if (metadata.HasHeadersAnnotation) { if (typeof(Properties).IsAssignableFrom(expectedType)) { args[i] = GetStringTypedHeaders(message); } else { args[i] = message.Headers; } } else if (expectedType.IsAssignableFrom(typeof(IMessage)) && typeof(IMessage).IsAssignableFrom(expectedType)) { args[i] = message; } else { args[i] = message.Payload; } } return(args); }
/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(ScriptMemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); Tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; IsReadOnly |= !info.HasSet; DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name); }
public async Task IApiActionAttributeTest() { var context = new ApiActionContext { RequestMessage = new HttpApiRequestMessage { RequestUri = new Uri("http://www.mywebapi.com"), Method = HttpMethod.Post }, ApiActionDescriptor = ApiDescriptorCache.GetApiActionDescriptor(typeof(IMyApi).GetMethod("PostAsync")) }; var attr = new HeaderAttribute("MyHeader", "laojiu"); await attr.BeforeRequestAsync(context); context.RequestMessage.Headers.TryGetValues("MyHeader", out IEnumerable <string> values); Assert.Equal("laojiu", values.First()); }
private void SetupList() { dataList.Clear(); object data = _GetValue(); if (data != null) { if (separatePage && !ignoreSeparatePage) { separatePagePanel = UIModConfig.MakeSeparateListPanel(item, data, memberInfo, array, index, AbridgedTextDisplayFunction); } else { int order = 0; foreach (PropertyFieldWrapper variable in ConfigManager.GetFieldsAndProperties(data)) { if (Attribute.IsDefined(variable.MemberInfo, typeof(JsonIgnoreAttribute))) { continue; } int top = 0; HeaderAttribute header = ConfigManager.GetCustomAttribute <HeaderAttribute>(variable, null, null); if (header != null) { var wrapper = new PropertyFieldWrapper(typeof(HeaderAttribute).GetProperty(nameof(HeaderAttribute.Header))); UIModConfig.WrapIt(dataList, ref top, wrapper, header, order++); } var wrapped = UIModConfig.WrapIt(dataList, ref top, variable, data, order++); if (array != null) { //wrapped.Item1.Left.Pixels -= 20; wrapped.Item1.Width.Pixels += 20; } else { //wrapped.Item1.Left.Pixels += 20; //wrapped.Item1.Width.Pixels -= 20; } } } } }
public void DrawReorderableArray(SerializedProperty property) { HeaderAttribute propertyAttribute = ReorderableArrayEditor.GetPropertyAttribute <HeaderAttribute>(property); if (propertyAttribute != null) { EditorGUILayout.Space(); EditorGUILayout.LabelField(propertyAttribute.header, EditorStyles.boldLabel, new GUILayoutOption[0]); } ReorderableArrayEditor.ReorderableListWrapper reorderableListWrapper = this.GetReorderableListWrapper(property); if (reorderableListWrapper.isExpanded) { reorderableListWrapper.list.DoLayoutList(); } else { property.isExpanded = (EditorGUILayout.Foldout(property.isExpanded, new GUIContent(string.Format("{0} [{1}]", property.displayName, property.arraySize), property.tooltip))); } }
public void BeforeRequestTest() { var method = typeof(IAubTestApi).GetMethod("PostAsync"); var context = new TestActionContext( httpApiConfig: new HttpApiConfig(), apiActionDescriptor: new ApiActionDescriptor("http://api.dev/", method, HttpMethod.Post) { Url = new Uri("http://api.dev/api/test/order"), Method = HttpMethod.Post }, null); var attr = new HeaderAttribute(); var parameter = new ApiParameterDescriptor(name: "logkey", value: "1234567", attributes: null); attr.BeforeRequest(context, parameter); context.RequestMessage.Headers.TryGetValues("logkey", out IEnumerable <string> values); Assert.Equal("1234567", values.FirstOrDefault()); }
/// <summary> /// Initializes a new instance of the <see cref="ItemInfo"/> class. /// </summary> /// <param name="info">The reflection information.</param> /// <param name="attributes">The attributes.</param> public ItemInfo(ScriptMemberInfo info, object[] attributes) { Info = info; Order = (EditorOrderAttribute)attributes.FirstOrDefault(x => x is EditorOrderAttribute); Display = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); CustomEditor = (CustomEditorAttribute)attributes.FirstOrDefault(x => x is CustomEditorAttribute); CustomEditorAlias = (CustomEditorAliasAttribute)attributes.FirstOrDefault(x => x is CustomEditorAliasAttribute); Space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute); Header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute); VisibleIf = (VisibleIfAttribute)attributes.FirstOrDefault(x => x is VisibleIfAttribute); IsReadOnly = attributes.FirstOrDefault(x => x is ReadOnlyAttribute) != null; ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null; IsReadOnly |= !info.HasSet; DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name); var editor = Editor.Instance; TooltipText = editor.CodeDocs.GetTooltip(info, attributes); _membersOrder = editor.Options.Options.General.ScriptMembersOrder; }
/// <summary> /// Draws buttons for turning custom editors on/off, as well as DocType, Tutorial and UseWith attributes /// </summary> private void DrawInspectorHeader() { EditorGUILayout.Space(); GUILayout.BeginHorizontal(); if (GUILayout.Button(ShowCustomEditors ? "Toggle Custom Editors (ON)" : "Toggle Custom Editors (OFF)", ShowCustomEditors ? toggleButtonOnStyle : toggleButtonOffStyle)) { ShowCustomEditors = !ShowCustomEditors; } if (ShowCustomEditors) { if (GUILayout.Button(showHelp ? "Toggle Help (ON)" : "Toggle Help (OFF)", showHelp ? toggleButtonOnStyle : toggleButtonOffStyle)) { showHelp = !showHelp; } if (GUILayout.Button("Expand Sections", toggleButtonOffStyle)) { Type targetType = target.GetType(); foreach (MemberInfo member in targetType.GetMembers(defaultBindingFlags)) { if (member.IsDefined(typeof(HeaderAttribute), true)) { HeaderAttribute h = member.GetCustomAttributes(typeof(HeaderAttribute), true)[0] as HeaderAttribute; string lookupName = targetType.Name + h.header; if (!displayedSections.ContainsKey(lookupName)) { displayedSections.Add(lookupName, true); } else { displayedSections[lookupName] = true; } } } } if (GUILayout.Button("Collapse Sections", toggleButtonOffStyle)) { Type targetType = target.GetType(); foreach (MemberInfo member in targetType.GetMembers(defaultBindingFlags)) { if (member.IsDefined(typeof(HeaderAttribute), true)) { HeaderAttribute h = member.GetCustomAttributes(typeof(HeaderAttribute), true)[0] as HeaderAttribute; string lookupName = targetType.Name + h.header; if (!displayedSections.ContainsKey(lookupName)) { displayedSections.Add(lookupName, false); } else { displayedSections[lookupName] = false; } } } } } GUILayout.EndHorizontal(); if (ShowCustomEditors) { GUI.color = defaultColor; GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); Type targetType = target.GetType(); foreach (DocLinkAttribute attribute in targetType.GetCustomAttributes(typeof(DocLinkAttribute), true)) { string description = attribute.Description; if (string.IsNullOrEmpty(description)) { description = "Click for documentation about " + targetType.Name; } if (GUILayout.Button(description, EditorStyles.toolbarButton)) { Application.OpenURL(attribute.DocURL); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); foreach (TutorialAttribute attribute in targetType.GetCustomAttributes(typeof(TutorialAttribute), true)) { string description = attribute.Description; if (string.IsNullOrEmpty(description)) { description = "Click for a tutorial on " + targetType.Name; } if (GUILayout.Button(description, EditorStyles.toolbarButton)) { Application.OpenURL(attribute.TutorialURL); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); List <Type> missingTypes = new List <Type>(); foreach (UseWithAttribute attribute in targetType.GetCustomAttributes(typeof(UseWithAttribute), true)) { Component targetGo = (Component)target; if (targetGo == null) { break; } foreach (Type type in attribute.UseWithTypes) { Component c = targetGo.GetComponent(type); if (c == null) { missingTypes.Add(type); } } } if (missingTypes.Count > 0) { string warningMessage = "This class is designed to be accompanied by scripts of (or inheriting from) types: \n"; for (int i = 0; i < missingTypes.Count; i++) { warningMessage += " - " + missingTypes[i].FullName; if (i < missingTypes.Count - 1) { warningMessage += "\n"; } } warningMessage += "\nIt may not function correctly without them."; DrawWarning(warningMessage); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); } EditorGUILayout.Space(); }
/// <summary> /// Draws main editor /// </summary> protected void DrawCustomEditor() { EditorGUILayout.BeginVertical(); Type targetType = target.GetType(); // Get all the members of this type, public and private List <MemberInfo> members = new List <MemberInfo>(targetType.GetMembers(defaultBindingFlags)); members.Sort( delegate(MemberInfo m1, MemberInfo m2) { if (m1.IsDefined(typeof(DrawLastAttribute), true)) { return(1); } return(0); } ); // Start drawing the editor int currentIndentLevel = 0; bool insideSectionBlock = false; bool drawCurrentSection = true; foreach (MemberInfo member in members) { try { // First get header and indent settings if (member.IsDefined(typeof(HeaderAttribute), true)) { HeaderAttribute header = member.GetCustomAttributes(typeof(HeaderAttribute), true)[0] as HeaderAttribute; if (insideSectionBlock) { DrawSectionEnd(); } insideSectionBlock = true; drawCurrentSection = DrawSectionStart(target.GetType().Name, header.header); } // Then do basic show / hide based on ShowIfAttribute if ((insideSectionBlock && !drawCurrentSection) || !ShouldDrawMember(member, targetType, target)) { continue; } // Handle drawing stuff (indent, help) if (showHelp) { DrawToolTip(member); } if (member.IsDefined(typeof(SetIndentAttribute), true)) { SetIndentAttribute indent = member.GetCustomAttributes(typeof(SetIndentAttribute), true)[0] as SetIndentAttribute; currentIndentLevel += indent.Indent; EditorGUI.indentLevel = currentIndentLevel; } // Now get down to drawing the thing // Get an array ready for our override attributes object[] drawOverrideAttributes = null; switch (member.MemberType) { case MemberTypes.Field: FieldInfo field = targetType.GetField(member.Name, defaultBindingFlags); if (!field.IsPrivate || field.IsDefined(typeof(SerializeField), true)) { // If it's a profile field, take care of that first if (IsSubclassOf(field.FieldType, typeof(ProfileBase))) { UnityEngine.Object profile = (UnityEngine.Object)field.GetValue(target); profile = DrawProfileField(target, profile, field.FieldType); field.SetValue(target, profile); } else { drawOverrideAttributes = field.GetCustomAttributes(typeof(DrawOverrideAttribute), true); // If we fine overrides, draw using those if (drawOverrideAttributes.Length > 0) { if (drawOverrideAttributes.Length > 1) { DrawWarning("You should only use one DrawOverride attribute per member. Drawing " + drawOverrideAttributes[0].GetType().Name + " only."); } (drawOverrideAttributes[0] as DrawOverrideAttribute).DrawEditor(target, field, serializedObject.FindProperty(field.Name)); } else { // Otherwise just draw the default editor DrawSerializedField(serializedObject, field.Name); } } } break; case MemberTypes.Property: // We have to draw properties manually PropertyInfo prop = targetType.GetProperty(member.Name, defaultBindingFlags); drawOverrideAttributes = prop.GetCustomAttributes(typeof(DrawOverrideAttribute), true); // If it's a profile field, take care of that first if (IsSubclassOf(prop.PropertyType, typeof(ProfileBase))) { UnityEngine.Object profile = (UnityEngine.Object)prop.GetValue(target, null); profile = DrawProfileField(target, profile, prop.PropertyType); prop.SetValue(target, profile, null); } // If we find overrides, draw using those else if (drawOverrideAttributes.Length > 0) { if (drawOverrideAttributes.Length > 1) { DrawWarning("You should only use one DrawOverride attribute per member. Drawing " + drawOverrideAttributes[0].GetType().Name + " only."); } (drawOverrideAttributes[0] as DrawOverrideAttribute).DrawEditor(target, prop); } break; default: // Don't do anything, it's not something we can use break; } } catch (Exception e) { DrawWarning("There was a problem drawing the member " + member.Name + ":"); DrawError(System.Environment.NewLine + e.ToString()); } } if (insideSectionBlock) { DrawSectionEnd(); } EditorGUILayout.EndVertical(); }
internal static UIPanel MakeSeparateListPanel(object item, object subitem, PropertyFieldWrapper memberInfo, IList array, int index, Func <string> AbridgedTextDisplayFunction) { UIPanel uIPanel = new UIPanel(); uIPanel.CopyStyle(Interface.modConfig.uIPanel); uIPanel.BackgroundColor = UICommon.MainPanelBackground; BackgroundColorAttribute bca = ConfigManager.GetCustomAttribute <BackgroundColorAttribute>(memberInfo, subitem, null); if (bca != null) { uIPanel.BackgroundColor = bca.color; } //uIElement.Append(uIPanel); UIList separateList = new UIList(); separateList.CopyStyle(Interface.modConfig.mainConfigList); separateList.Height.Set(-40f, 1f); separateList.Top.Set(40f, 0f); uIPanel.Append(separateList); int i = 0; int top = 0; UIScrollbar uIScrollbar = new UIScrollbar(); uIScrollbar.SetView(100f, 1000f); uIScrollbar.Height.Set(-40f, 1f); uIScrollbar.Top.Set(40f, 0f); uIScrollbar.HAlign = 1f; uIPanel.Append(uIScrollbar); separateList.SetScrollbar(uIScrollbar); string name = ConfigManager.GetCustomAttribute <LabelAttribute>(memberInfo, subitem, null)?.Label ?? memberInfo.Name; if (index != -1) { name = name + " #" + (index + 1); } Interface.modConfig.subPageStack.Push(name); //UIPanel heading = new UIPanel(); //UIText headingText = new UIText(name); name = string.Join(" > ", Interface.modConfig.subPageStack.Reverse()); //.Aggregate((current, next) => current + "/" + next); UITextPanel <string> heading = new UITextPanel <string>(name); // TODO: ToString as well. Separate label? heading.HAlign = 0f; //heading.Width.Set(-10, 0.5f); //heading.Left.Set(60, 0f); heading.Top.Set(-6, 0); heading.Height.Set(40, 0); //var headingContainer = GetContainer(heading, i++); //headingContainer.Height.Pixels = 40; uIPanel.Append(heading); //headingText.Top.Set(6, 0); //headingText.Left.Set(0, .5f); //headingText.HAlign = .5f; //uIPanel.Append(headingText); //top += 40; UITextPanel <string> back = new UITextPanel <string>("Back"); back.HAlign = 1f; back.Width.Set(50, 0f); back.Top.Set(-6, 0); //top += 40; //var capturedCurrent = Interface.modConfig.currentConfigList; back.OnClick += (a, c) => { Interface.modConfig.uIElement.RemoveChild(uIPanel); Interface.modConfig.configPanelStack.Pop(); Interface.modConfig.uIElement.Append(Interface.modConfig.configPanelStack.Peek()); //Interface.modConfig.configPanelStack.Peek().SetScrollbar(Interface.modConfig.uIScrollbar); //Interface.modConfig.currentConfigList = capturedCurrent; }; back.WithFadedMouseOver(); //var backContainer = GetContainer(back, i++); //backContainer.Height.Pixels = 40; uIPanel.Append(back); //var b = new UIText("Test"); //separateList.Add(b); // Make rest of list // load all mod config options into UIList // TODO: Inheritance with ModConfig? DeclaredOnly? if (true) { int order = 0; bool hasToString = false; if (array != null) { var listType = memberInfo.Type.GetGenericArguments()[0]; hasToString = listType.GetMethod("ToString", new Type[0]).DeclaringType != typeof(object); } else { hasToString = memberInfo.Type.GetMethod("ToString", new Type[0]).DeclaringType != typeof(object); } if (AbridgedTextDisplayFunction != null) { var display = new UITextPanel <FuncStringWrapper>(new FuncStringWrapper() { func = AbridgedTextDisplayFunction, }) { DrawPanel = true }; display.Recalculate(); var container = GetContainer(display, order++); container.Height.Pixels = (int)display.GetOuterDimensions().Height; separateList.Add(container); } //if (hasToString) // _TextDisplayFunction = () => index + 1 + ": " + (array[index]?.ToString() ?? "null"); foreach (PropertyFieldWrapper variable in ConfigManager.GetFieldsAndProperties(subitem)) { if (Attribute.IsDefined(variable.MemberInfo, typeof(JsonIgnoreAttribute)) && !Attribute.IsDefined(variable.MemberInfo, typeof(LabelAttribute))) // TODO, appropriately named attribute { continue; } HeaderAttribute header = ConfigManager.GetCustomAttribute <HeaderAttribute>(variable, null, null); if (header != null) { var wrapper = new PropertyFieldWrapper(typeof(HeaderAttribute).GetProperty(nameof(HeaderAttribute.Header))); WrapIt(separateList, ref top, wrapper, header, order++); } WrapIt(separateList, ref top, variable, subitem, order++); } } else { //ignoreSeparatePage just to simplify ToString label--> had some issues. //WrapIt(separateList, ref top, memberInfo, item, 1, ignoreSeparatePage: true); } Interface.modConfig.subPageStack.Pop(); return(uIPanel); }
public override void OnActivate() { filterTextField.SetText(""); updateNeeded = false; SetMessage("", Color.White); string configDisplayName = ((LabelAttribute)Attribute.GetCustomAttribute(modConfig.GetType(), typeof(LabelAttribute)))?.Label ?? modConfig.Name; headerTextPanel.SetText(string.IsNullOrEmpty(configDisplayName) ? modConfig.mod.DisplayName : modConfig.mod.DisplayName + ": " + configDisplayName); pendingConfig = ConfigManager.GeneratePopulatedClone(modConfig); pendingChanges = pendingRevertDefaults; if (pendingRevertDefaults) { pendingRevertDefaults = false; ConfigManager.Reset(pendingConfig); pendingChangesUIUpdate = true; } int index = modConfigs.IndexOf(modConfig); int count = modConfigs.Count; //pendingChanges = false; backButton.BackgroundColor = UICommon.DefaultUIBlueMouseOver; uIElement.RemoveChild(saveConfigButton); uIElement.RemoveChild(revertConfigButton); uIElement.RemoveChild(previousConfigButton); uIElement.RemoveChild(nextConfigButton); if (index + 1 < count) { uIElement.Append(nextConfigButton); } if (index - 1 >= 0) { uIElement.Append(previousConfigButton); } uIElement.RemoveChild(configPanelStack.Peek()); uIElement.Append(uIPanel); mainConfigItems.Clear(); mainConfigList.Clear(); configPanelStack.Clear(); configPanelStack.Push(uIPanel); subPageStack.Clear(); //currentConfigList = mainConfigList; int top = 0; // load all mod config options into UIList // TODO: Inheritance with ModConfig? DeclaredOnly? uIPanel.BackgroundColor = UICommon.MainPanelBackground; var backgroundColorAttribute = (BackgroundColorAttribute)Attribute.GetCustomAttribute(pendingConfig.GetType(), typeof(BackgroundColorAttribute)); if (backgroundColorAttribute != null) { uIPanel.BackgroundColor = backgroundColorAttribute.color; } int order = 0; foreach (PropertyFieldWrapper variable in ConfigManager.GetFieldsAndProperties(pendingConfig)) { if (variable.isProperty && variable.Name == "Mode") { continue; } if (Attribute.IsDefined(variable.MemberInfo, typeof(JsonIgnoreAttribute)) && !Attribute.IsDefined(variable.MemberInfo, typeof(LabelAttribute))) // TODO, appropriately named attribute { continue; } HeaderAttribute header = ConfigManager.GetCustomAttribute <HeaderAttribute>(variable, null, null); if (header != null) { var wrapper = new PropertyFieldWrapper(typeof(HeaderAttribute).GetProperty(nameof(HeaderAttribute.Header))); WrapIt(mainConfigList, ref top, wrapper, header, order++); } WrapIt(mainConfigList, ref top, variable, pendingConfig, order++); } }
public void SetUp() { _attribute = new HeaderAttribute("field", "value"); _route = new Route.Routing.Route("name", Guid.NewGuid(), "relative"); _container = MockRepository.GenerateMock <IContainer>(); }