public static void Postfix(REPropertySet __instance, FieldInfo targetField, object target) { if (__instance is REEnumSet enumSet) { Type enumType = targetField.FieldType; var enumType2 = HintExtension.GetMappedEnumWithHints(enumType); if (HasHint(enumType2)) { var panel = enumSet.GetComponentInChildren <UIPanel>(); panel.objectUserData = new EnumSetHint(enumSet); } } }
public string GetHint() { Type enumType = enumSet_.GetTargetField().FieldType; int i = dd.GetHoverIndex(); if (i >= 0) { string itemName = dd.items[i]; return(HintExtension.GetEnumMappedHint(enumType, itemName)); } else if (dd.containsMouse) { Type enumType2 = HintExtension.GetMappedEnumWithHints(enumType); return(enumType2.GetHints().JoinLines()); } return(null); }
/// <summary> /// replace built-in fields /// </summary> public static bool Prefix(string groupName, FieldInfo field, object target, RoadEditorPanel __instance) { if (NetInfoExtionsion.EditedNetInfo == null) { return(true); // ignore this outside of asset editor. } if (RoadEditorPanelExtensions.RequiresUserFlag(field.FieldType)) { return(true); } if (field.HasAttribute <BitMaskAttribute>() && field.HasAttribute <CustomizablePropertyAttribute>()) { UIComponent container = __instance.m_Container; if (!string.IsNullOrEmpty(groupName)) { container = __instance.GetGroupPanel(groupName).Container; } var att = field.GetAttribute <CustomizablePropertyAttribute>(); var enumType = field.FieldType; enumType = HintExtension.GetMappedEnumWithHints(enumType); var hints = field.GetHints(); if (field.Name == "m_stopType") { hints.Add("set this for the pedestrian lane that contains the bus/tram stop."); } hints.AddRange(enumType.GetHints()); string hint = hints.JoinLines(); Log.Debug($"{field} -> hint is: " + hint); var bitMaskPanel = BitMaskPanel.Add( roadEditorPanel: __instance, container: container, label: att.name, enumType: enumType, setHandler: val => field.SetValue(target, val), getHandler: () => (int)field.GetValue(target), hint: hint); return(false); } return(true); }
/// <summary> /// /// </summary> /// <param name="groupName"></param> /// <param name="fieldInfo"></param> /// <param name="target"></param> /// <param name="instance"></param> /// <param name="prefix"></param> public static void CreateExtendedComponent( string groupName, FieldInfo fieldInfo, object target, RoadEditorPanel instance, string prefix = "") { //Assert(string.IsNullOrEmpty(groupName), "groupName is empty"); UIComponent container = instance.m_Container; //instance.component.GetComponentInChildren<UIScrollablePanel>(); if (!string.IsNullOrEmpty(groupName)) { container = instance.GetGroupPanel(groupName).Container; } AssertNotNull(container, "container"); Log.Debug("CreateExtendedComponent():container=" + container); Assert(fieldInfo.HasAttribute <CustomizablePropertyAttribute>(), "HasAttribute:CustomizablePropertyAttribute"); AssertNotNull(target, "target"); AssertNotNull(target, "fieldInfo"); AssertNotNull(target, "RoadEditorPanel instance"); Log.Debug( $"CreateExtendedComponent(groupName={groupName}, fieldInfo={fieldInfo}, target={target}, instance={instance.name}) called", false); var att = fieldInfo.GetAttribute <CustomizablePropertyAttribute>(); var optionals = fieldInfo.GetAttributes <OptionalAttribute>(); var optionals2 = target.GetType().GetAttributes <OptionalAttribute>(); foreach (var optional in optionals.Concat(optionals2)) { if (optional != null && !ModSettings.GetOption(optional.Option)) { Log.Debug($"Hiding {target.GetType().Name}::`{att.name}` because {optional.Option} is disabled"); return; } } var hints = fieldInfo.GetHints(); hints.AddRange(fieldInfo.FieldType.GetHints()); string hint = hints.JoinLines(); Log.Debug("hint is " + hint); if (fieldInfo.FieldType.HasAttribute <FlagPairAttribute>()) { int GetRequired() { object subTarget = fieldInfo.GetValue(target); return((int)GetFieldValue(subTarget, "Required")); } void SetRequired(int flags) { var subTarget = fieldInfo.GetValue(target); SetFieldValue(target: subTarget, fieldName: "Required", value: flags); fieldInfo.SetValue(target, subTarget); } int GetForbidden() { object subTarget = fieldInfo.GetValue(target); return((int)GetFieldValue(subTarget, "Forbidden")); } void SetForbidden(int flags) { var subTarget = fieldInfo.GetValue(target); SetFieldValue(target: subTarget, fieldName: "Forbidden", value: flags); fieldInfo.SetValue(target, subTarget); } Type enumType = fieldInfo.FieldType.GetField("Required").FieldType; enumType = HintExtension.GetMappedEnumWithHints(enumType); var panel0 = BitMaskPanel.Add( roadEditorPanel: instance, container: container, label: prefix + att.name + " Flags Required", enumType: enumType, setHandler: SetRequired, getHandler: GetRequired, hint: hint); panel0.EventPropertyChanged += instance.OnObjectModified; var panel1 = BitMaskPanel.Add( roadEditorPanel: instance, container: container, label: prefix + att.name + " Flags Forbidden", enumType: enumType, setHandler: SetForbidden, getHandler: GetForbidden, hint: hint); panel1.EventPropertyChanged += instance.OnObjectModified; } else if (fieldInfo.FieldType == typeof(NetInfoExtionsion.Range) && fieldInfo.Name.ToLower().Contains("speed")) { var panel = SpeedRangePanel.Add( roadEditorPanel: instance, container: container, label: prefix + att.name, target: target, fieldInfo: fieldInfo); panel.EventPropertyChanged += instance.OnObjectModified; } else { Log.Error($"CreateExtendedComponent: Unhandled field: {fieldInfo} att:{att.name} "); } }