public static void Postfix( string name, FieldInfo field, object target, RoadEditorPanel __instance, object ___m_Target) { target ??= ___m_Target; RoadEditorCollapsiblePanel groupPanel = __instance.GetGroupPanel(name); if (name == "Props") { Log.Debug("creating `Add from template` button"); var button = groupPanel.m_Panel.AddUIComponent <EditorButon>(); button.zOrder = int.MaxValue; button.text = "Add from template"; button.width = 200; button.eventClicked += OnLoadFromTempalteClicked; } }
/// <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} "); } }
/// <summary> /// Adds new custom fields after a built-in field. /// or modify the name of the built-in fields /// </summary> public static void Postfix(string groupName, FieldInfo field, object target, RoadEditorPanel __instance) { try { if (target is NetLaneProps.Prop prop) { Log.Debug($"{__instance.name}.CreateGenericField.Postfix({groupName},{field},{target})" /* + Environment.StackTrace*/); if (ModSettings.ARMode) { var metadata = prop.GetOrCreateMetaData(); foreach (var field2 in field.GetAfterFields(metadata)) { CreateGenericComponentExt( roadEditorPanel: __instance, groupName: groupName, target: target, metadata: metadata, extensionField: field2); } } if (typeof(NetInfoExtionsion.LaneProp).ComesAfter(field)) { Assert(prop.LocateEditProp(out _, out var lane), "could not locate prop"); bool forward = lane.IsGoingForward(); bool backward = lane.IsGoingBackward(); bool unidirectional = forward || backward; if (!unidirectional) { ButtonPanel.Add( roadEditorPanel: __instance, container: __instance.m_Container, label: "Switch Forward/Backward", null, action: () => { prop.ToggleForwardBackward(); __instance.OnObjectModified(); __instance.Reset(); }); } ButtonPanel.Add( roadEditorPanel: __instance, container: __instance.m_Container, label: "Switch RHT/LHT", HintExtension.GetHintSwichLHT_RHT(unidirectional), action: () => { prop.ToggleRHT_LHT(unidirectional); __instance.OnObjectModified(); __instance.Reset(); }); } ReplaceLabel(__instance, "Start Flags Required:", "Tail Node Flags Required:"); ReplaceLabel(__instance, "Start Flags Forbidden:", "Tail Node Flags Forbidden:"); ReplaceLabel(__instance, "End Flags Required:", "Head Node Flags Required:"); ReplaceLabel(__instance, "End Flags Forbidden:", "Head Node Flags Forbidden:"); } else if (target is NetInfo.Node node) { Log.Debug($"{__instance.name}.CreateGenericField.Postfix({groupName},{field},{target})" /* + Environment.StackTrace*/); if (ModSettings.ARMode) { var metadata = node.GetOrCreateMetaData(); foreach (var field2 in field.GetAfterFields(metadata)) { CreateGenericComponentExt( roadEditorPanel: __instance, groupName: groupName, target: target, metadata: metadata, extensionField: field2); } } } else if (target is NetInfo.Segment segment) { Log.Debug($"{__instance.name}.CreateGenericField.Postfix({groupName}, {field}, {target})" /* + Environment.StackTrace*/); if (ModSettings.ARMode) { var metadata = segment.GetOrCreateMetaData(); AssertNotNull(metadata, $"{segment}"); foreach (var field2 in field.GetAfterFields(metadata)) { CreateGenericComponentExt( roadEditorPanel: __instance, groupName: groupName, target: target, metadata: metadata, extensionField: field2); } } } else if (target is NetInfo netInfo) { if (ModSettings.ARMode) { ReplaceLabel(__instance, "Pavement Width", "Pavement Width Left"); var net = netInfo.GetOrCreateMetaData(); AssertNotNull(net, $"{netInfo}"); foreach (var field2 in net.GetFieldsWithAttribute <CustomizablePropertyAttribute>()) { if (field2.ComesAfter(field)) { Log.Debug($"calling {__instance.name}.CreateGenericField({groupName},{field2},{net}) ..."); __instance.CreateGenericField(groupName, field2, net); } } if (field.Name == nameof(NetInfo.m_surfaceLevel)) { Log.Debug("adding QuayRoads button"); var qrButtonPanel = ButtonPanel.Add( roadEditorPanel: __instance, container: __instance.GetGroupPanel("Properties").m_Panel, label: "Edit QuayRoads profile", hint: "", action: () => QuayRoadsPanel.GetOrOpen(netInfo, __instance)); qrButtonPanel.EventDestroy += (_, _) => { QuayRoadsPanel.CloseIfOpen(netInfo); }; } } } } catch (Exception e) { Log.Exception(e); } }