/// <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})\n" /* + Environment.StackTrace*/); ReplaceLabel(__instance, "Start Flags Required:", "Tail Flags Required:"); ReplaceLabel(__instance, "Start Flags Forbidden:", "Tail Flags Forbidden:"); ReplaceLabel(__instance, "End Flags Required:", "Head Flags Required:"); ReplaceLabel(__instance, "End Flags Forbidden:", "Head Flags Forbidden:"); if (field.Name == nameof(NetLaneProps.Prop.m_endFlagsForbidden)) { Assert(prop.LocateEditProp(out _, out var lane), "could not locate prop"); bool forward = lane.IsGoingForward(); bool backward = lane.IsGoingBackward(); bool unidirectional = forward || backward; if (ModSettings.ARMode) { var metadata = prop.GetOrCreateMetaData(); foreach (var field2 in metadata.GetFieldsWithAttribute <CustomizablePropertyAttribute>()) { CreateExtendedComponent(groupName, field2, metadata, __instance); } } 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(); }); } } else if (target is NetInfo.Node node) { Log.Debug($"{__instance.name}.CreateGenericField.Postfix({groupName},{field},{target})\n" /* + Environment.StackTrace*/); if (ModSettings.ARMode) { if (field.Name == nameof(NetInfo.Node.m_flagsForbidden)) { var fields = typeof(NetInfoExtionsion.Node).GetFields() .Where(_field => _field.HasAttribute <CustomizablePropertyAttribute>()); var node2 = node.GetOrCreateMetaData(); foreach (var field2 in fields) { CreateExtendedComponent(groupName, field2, node2, __instance); } } } } else if (target is NetInfo.Segment segment) { Log.Debug($"{__instance.name}.CreateGenericField.Postfix({groupName}, {field}, {target})\n" /* + Environment.StackTrace*/); if (ModSettings.ARMode) { var segment2 = segment.GetOrCreateMetaData(); AssertNotNull(segment2, $"{segment}"); var fieldForward = typeof(NetInfoExtionsion.Segment).GetField( nameof(NetInfoExtionsion.Segment.Forward)); if (field.Name == nameof(NetInfo.Segment.m_forwardForbidden)) { CreateExtendedComponent(groupName, fieldForward, segment2, __instance); } else if (field.Name == nameof(NetInfo.Segment.m_backwardForbidden)) { var fields = segment2 .GetFieldsWithAttribute <CustomizablePropertyAttribute>() .Where(_f => _f != fieldForward); int totalCount = typeof(NetInfoExtionsion.Segment) .GetFieldsWithAttribute <CustomizablePropertyAttribute>() .Count(); foreach (var field2 in fields) { CreateExtendedComponent(groupName, field2, segment2, __instance); } } } } else if (target is NetInfo netInfo) { if (ModSettings.ARMode) { // replace "Pavement Width" with Pavement Width Left ReplaceLabel(__instance, "Pavement Width", "Pavement Width Left"); // inject our own field if (field.Name == nameof(NetInfo.m_pavementWidth)) { Log.Debug($"{__instance.name}.CreateGenericField.Postfix({groupName},{field},{target})\n" /* + Environment.StackTrace*/); var net = netInfo.GetOrCreateMetaData(); AssertNotNull(net, $"{netInfo}"); var f = net.GetType().GetField(nameof(net.PavementWidthRight)); __instance.CreateGenericField(groupName, f, net); } } } } catch (Exception e) { Log.Exception(e); } }
/// <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); } }