Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        public static void OnDPTMoreOptions(UICustomControl dpt)
        {
            Log.Debug("OnDPTMoreOptions() called");
            VerifySelectedDPTs(dpt);
            if (!SelectedDPTs.Contains(dpt))
            {
                DeselectAllDPTs();
            }

            var groupPanel = dpt.GetComponentInParent <RoadEditorCollapsiblePanel>();
            var sidePanel  = dpt.GetComponentInParent <RoadEditorPanel>();

            Log.Debug($"dpt={dpt} " +
                      $"groupPanel={groupPanel} " +
                      $"sidePanel={sidePanel}");

            object target  = GetDPTTargetObject(dpt);
            object element = GetDPTTargetElement(dpt);
            IEnumerable <object> elements;

            if (SelectedDPTs.Any())
            {
                elements = SelectedDPTs.Select(_dpt => GetDPTTargetElement(_dpt));
            }
            else
            {
                elements = new object[] { element }
            };

            if (target is NetLaneProps netLaneProps &&
                element is NetLaneProps.Prop)
            {
                var lane = sidePanel.GetTarget() as NetInfo.Lane;
                Assertion.AssertNotNull(lane, "sidePanel.target is lane");
                bool forward        = lane.IsGoingForward();
                bool backward       = lane.IsGoingBackward();
                bool unidirectional = forward || backward;

                var    panel          = MiniPanel.Display();
                var    f_props        = typeof(NetLaneProps).GetField(nameof(NetLaneProps.m_props));
                var    original_props = elements.Select(_p => _p as NetLaneProps.Prop);
                var    cloned_props   = original_props.Select(_p => _p.Clone());
                string strAll         = cloned_props.Count() > 1 ? " all" : "";

                panel.AddButton("Duplicate" + strAll, null, delegate() {
                    AddProps(groupPanel, cloned_props.ToArray());
                });

                if (cloned_props.Any(_p => _p.CanInvert()))
                {
                    string hint = HintExtension.GetHintSwichLHT_RHT(unidirectional);
                    panel.AddButton(
                        "LHT duplicate" + strAll,
                        hint,
                        delegate() {
                        try {
                            var arProsp = cloned_props.ToArray();
                            foreach (var item in arProsp)
                            {
                                item.ToggleRHT_LHT(unidirectional);
                            }
                            AddProps(groupPanel, arProsp);
                        } catch (Exception ex) {
                            Log.Exception(ex);
                        }
                    });
                }
                panel.AddButton("Copy" + strAll, null, delegate() {
                    ClipBoard.SetData(cloned_props);
                });
                panel.AddButton("Copy" + strAll + " to other elevations", null, delegate() {
                    foreach (var item in cloned_props)
                    {
                        PropHelpers.CopyPropsToOtherElevations(item);
                    }
                });
                panel.AddButton("Add" + strAll + " to Template", null, delegate() {
                    SaveTemplatePanel.Display(cloned_props);
                });
                if (cloned_props.Count() >= 2)
                {
                    panel.AddButton("Displace all", null, delegate() {
                        DisplaceAll(original_props);
                    });
                }
            }
Exemplo n.º 3
0
        /// <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);
            }
        }