示例#1
0
 static void OnShowOptions(RoadEditorCollapsiblePanel groupPanel)
 {
     try {
         Array array  = groupPanel.GetArray();
         var   target = groupPanel.GetTarget();
         if (groupPanel.GetArray() is NetLaneProps.Prop[] m_props)
         {
             bool hasItems         = m_props.Length > 0;
             bool clipBoardHasData = ClipBoard.HasData <NetLaneProps.Prop>();
             if (hasItems || clipBoardHasData)
             {
                 var panel = MiniPanel.Display();
                 if (hasItems)
                 {
                     panel.AddButton("Copy all props", null,
                                     () => ClipBoard.SetData(m_props));
                     panel.AddButton("Clear all props", null,
                                     () => ClearAll(groupPanel));
                     panel.AddButton("Save Template", null, () => {
                         SaveTemplatePanel.Display(m_props);
                     });
                 }
                 if (clipBoardHasData)
                 {
                     panel.AddButton("Paste all props", null,
                                     () => PasteAll(groupPanel));
                 }
                 panel.AddButton(
                     "Displace all",
                     null,
                     () => DisplaceAll(m_props));
             }
         }
         else if (
             array is NetInfo.Lane[] m_lanes &&
             m_lanes.Any(_lane => _lane.HasProps()) &&
             target == NetInfoExtionsion.EditedNetInfo)
         {
             var panel = MiniPanel.Display();
             panel.AddButton(
                 "Copy props to other elevation",
                 "appends props to other elevations",
                 () => PropHelpers.CopyPropsToOtherElevations(clear: false));
             panel.AddButton(
                 "replace props to other elevation",
                 "clears props from other elevations before copying.",
                 () => PropHelpers.CopyPropsToOtherElevations(clear: true));
             panel.AddButton(
                 "Displace all",
                 null,
                 () => RoadEditorUtils.DisplaceAllProps(m_lanes));
         }
     } catch (Exception ex) {
         Log.Exception(ex);
     }
 }
        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);
                    });
                }
            }