public static void ToggleTrafficLight(ushort nodeId)
        {
            ToggleTrafficLightsTool toggleTool =
                ModUI.GetTrafficManagerTool()?.GetSubTool(ToolMode.ToggleTrafficLight) as ToggleTrafficLightsTool;

            toggleTool?.ToggleTrafficLight(nodeId, ref nodeId.ToNode(), false);
        }
        /// <summary>
        ///  Intersects mouse ray with marker bounds.
        /// </summary>
        /// <returns><c>true</c>if mouse ray intersects with marker <c>false</c> otherwise</returns>
        internal bool IntersectRay()
        {
            Camera currentCamera = Camera.main;
            Ray    mouseRay      = currentCamera.ScreenPointToRay(Input.mousePosition);
            float  hitH          = TrafficManagerTool.GetAccurateHitHeight();

            Vector3 pos    = Position;
            float   mouseH = ModUI.GetTrafficManagerTool(false).MousePosition.y;

            if (hitH < mouseH - TrafficManagerTool.MAX_HIT_ERROR)
            {
                // For metros use projection on the terrain.
                pos = TerrainPosition;
            }
            else if (hitH - pos.y > TrafficManagerTool.MAX_HIT_ERROR)
            {
                // if marker is projected on road plane above then modify its height
                pos.y = hitH;
            }
            Bounds bounds = new Bounds(Vector3.zero, Vector3.one * Radius)
            {
                center = pos,
            };

            return(bounds.IntersectRay(mouseRay));
        }
Пример #3
0
 public static void Postfix(Event e)
 {
     if (ToolsModifierControl.toolController.CurrentTool.GetType() != typeof(TrafficManagerTool))
     {
         if (UI.SubTools.PrioritySigns.MassEditOverlay.IsActive)
         {
             ModUI.GetTrafficManagerTool(true).OnToolGUIImpl(e);
         }
     }
 }
Пример #4
0
 public static void Postfix(Event e)
 {
     if (LoadingExtension.PlayMode && !TrafficManagerTool.IsCurrentTool)
     {
         if (UI.SubTools.PrioritySigns.MassEditOverlay.IsActive)
         {
             ModUI.GetTrafficManagerTool(true).OnToolGUIImpl(e);
         }
     }
 }
Пример #5
0
 public static void SetAllowLaneChangesWhileGoingStraight(bool value)
 {
     Options.allowLaneChangesWhileGoingStraight = value;
     if (_allowLaneChangesWhileGoingStraightToggle != null)
     {
         _allowLaneChangesWhileGoingStraightToggle.isChecked = value;
     }
     Constants.ManagerFactory.JunctionRestrictionsManager.UpdateAllDefaults();
     ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
 }
Пример #6
0
 public static void Postfix(RenderManager.CameraInfo cameraInfo)
 {
     if (ToolsModifierControl.toolController.CurrentTool.GetType() != typeof(TrafficManagerTool))
     {
         if (UI.SubTools.PrioritySigns.MassEditOverlay.IsActive)
         {
             ModUI.GetTrafficManagerTool(true).RenderOverlayImpl(cameraInfo);
         }
         RoadSelectionPanels.Root.RenderOverlay();
     }
 }
Пример #7
0
        public static void SetTimedLightsOverlay(bool newTimedLightsOverlay)
        {
            Options.timedLightsOverlay = newTimedLightsOverlay;

            if (_timedLightsOverlayToggle != null)
            {
                _timedLightsOverlayToggle.isChecked = newTimedLightsOverlay;
            }

            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
Пример #8
0
        public static void SetPrioritySignsOverlay(bool newPrioritySignsOverlay)
        {
            Options.prioritySignsOverlay = newPrioritySignsOverlay;

            if (_prioritySignsOverlayToggle != null)
            {
                _prioritySignsOverlayToggle.isChecked = newPrioritySignsOverlay;
            }

            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
 public static void Postfix(Event e)
 {
     if (TMPELifecycle.PlayMode && !TrafficManagerTool.IsCurrentTool)
     {
         if (UI.SubTools.PrioritySigns.MassEditOverlay.IsActive)
         {
             ModUI.
             GetTrafficManagerTool()?.OnToolGUIImpl(e);
         }
     }
 }
        /// <summary>
        /// When options which affect subtools or overlays are toggled,
        /// all subtools are reinitialised to ensure they reflect the change.
        /// </summary>
        internal static void ReinitialiseSubTools()
        {
            if (TMPELifecycle.Instance.Deserializing || ModUI.Instance == null)
            {
                Log._Debug("OptionsManager.ReinitialiseSubTools() - Ignoring; Deserialising or ModUI is null");
                return;
            }

            Log.Info("OptionsManager.ReinitialiseSubTools()");
            ModUI.GetTrafficManagerTool()?.InitializeSubTools();
        }
Пример #11
0
        public static void SetJunctionRestrictionsOverlay(bool newValue)
        {
            Options.junctionRestrictionsOverlay = newValue;

            if (_junctionRestrictionsOverlayToggle != null)
            {
                _junctionRestrictionsOverlayToggle.isChecked = newValue;
            }

            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
Пример #12
0
        public static void SetParkingRestrictionsOverlay(bool newParkingRestrictionsOverlay)
        {
            Options.parkingRestrictionsOverlay = newParkingRestrictionsOverlay;

            if (_parkingRestrictionsOverlayToggle != null)
            {
                _parkingRestrictionsOverlayToggle.isChecked = newParkingRestrictionsOverlay;
            }

            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
 public static void Postfix(RenderManager.CameraInfo cameraInfo)
 {
     if (TMPELifecycle.PlayMode && !TrafficManagerTool.IsCurrentTool)
     {
         if (UI.SubTools.PrioritySigns.MassEditOverlay.IsActive)
         {
             ModUI.GetTrafficManagerTool()?.RenderOverlayImpl(cameraInfo);
         }
         RoadSelectionPanels.Root.RenderOverlay();
     }
 }
Пример #14
0
        private static void OnSpeedLimitsOverlayChanged(bool newSpeedLimitsOverlay)
        {
            if (!Options.IsGameLoaded())
            {
                return;
            }

            Log._Debug($"speedLimitsOverlay changed to {newSpeedLimitsOverlay}");
            Options.speedLimitsOverlay = newSpeedLimitsOverlay;

            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
Пример #15
0
        private static void OnParkingRestrictionsOverlayChanged(bool newParkingRestrictionsOverlay)
        {
            if (!Options.IsGameLoaded())
            {
                return;
            }

            Log._Debug($"parkingRestrictionsOverlay changed to {newParkingRestrictionsOverlay}");
            Options.parkingRestrictionsOverlay = newParkingRestrictionsOverlay;

            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
Пример #16
0
        private static void OnConnectedLanesOverlayChanged(bool newValue)
        {
            if (!Options.IsGameLoaded())
            {
                return;
            }

            Log._Debug($"connectedLanesOverlay changed to {newValue}");
            Options.connectedLanesOverlay = newValue;

            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
Пример #17
0
 public static void DrawNodeCircle(RenderManager.CameraInfo cameraInfo,
                                   ushort nodeId,
                                   bool warning = false,
                                   bool alpha   = false)
 {
     DrawNodeCircle(
         cameraInfo: cameraInfo,
         nodeId: nodeId,
         color: ModUI.GetTrafficManagerTool().GetToolColor(warning, error: false),
         alpha: alpha);
     // TODO: Potentially we do not need to refer to a TrafficManagerTool object
 }
Пример #18
0
        private void OnToggleOsdButtonClicked(U.UButton button)
        {
            bool value = !GlobalConfig.Instance.Main.KeybindsPanelVisible;

            GlobalConfig.Instance.Main.KeybindsPanelVisible = value;
            GlobalConfig.WriteConfig();

            Log._Debug($"Toggle value of KeybindsPanelVisible to {value}");

            // Refer to the TrafficManager tool asking it to request help from the current tool
            ModUI.GetTrafficManagerTool().RequestOnscreenDisplayUpdate();
        }
Пример #19
0
        public static void SetBanRegularTrafficOnBusLanes(bool value)
        {
            Options.banRegularTrafficOnBusLanes = value;

            if (_banRegularTrafficOnBusLanesToggle != null)
            {
                _banRegularTrafficOnBusLanesToggle.isChecked = value;
            }

            VehicleRestrictionsManager.Instance.ClearCache();
            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
Пример #20
0
        public static void SetAllowFarTurnOnRed(bool newValue)
        {
            Options.allowFarTurnOnRed = newValue;

            if (_allowFarTurnOnRedToggle != null)
            {
                _allowFarTurnOnRedToggle.isChecked = newValue;
            }

            Constants.ManagerFactory.JunctionRestrictionsManager.UpdateAllDefaults();
            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
Пример #21
0
        private static void OnBanRegularTrafficOnBusLanesChanged(bool newValue)
        {
            if (!Options.IsGameLoaded())
            {
                return;
            }

            Log._Debug($"banRegularTrafficOnBusLanes changed to {newValue}");
            Options.banRegularTrafficOnBusLanes = newValue;
            VehicleRestrictionsManager.Instance.ClearCache();
            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
Пример #22
0
        public static void SetAllowEnterBlockedJunctions(bool value)
        {
            Options.allowEnterBlockedJunctions = value;

            if (_allowEnterBlockedJunctionsToggle != null)
            {
                _allowEnterBlockedJunctionsToggle.isChecked = value;
            }

            Constants.ManagerFactory.JunctionRestrictionsManager.UpdateAllDefaults();
            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
        }
Пример #23
0
        private void OnHelpButtonClicked(U.Button.UButton button)
        {
            bool value = !GlobalConfig.Instance.Main.KeybindsPanelVisible;

            GlobalConfig.Instance.Main.KeybindsPanelVisible = value;
            Log._Debug($"Toggle value of KeybindsPanelVisible to {value}");

            // Refer to the TrafficManager tool asking it to request help from the current tool
            ModUI.GetTrafficManagerTool().RequestOnscreenDisplayUpdate();

            // The task is delayed till next GUI update frame.
            // ModUI.GetTrafficManagerTool().InvalidateOnscreenDisplayFlag = true;
        }
        protected override void OnClick(UIMouseEventParameter p)
        {
            // Immediately unclick the tool button, but toggle the option
            ModUI.GetTrafficManagerTool(true).SetToolMode(ToolMode.None);

            // Toggle the despawning value
            OptionsGameplayTab.SetDisableDespawning(!Options.disableDespawning);

            // Update currently visible tooltip
            this.UpdateTooltip(refreshTooltip: true);
            this.UpdateButtonImage();
            // do not call base -- base.OnClick(p);
        }
Пример #25
0
        protected override void OnClick(UIMouseEventParameter p)
        {
            // Immediately unclick the tool button, but toggle the option
            ModUI.GetTrafficManagerTool()?.SetToolMode(ToolMode.None);

            // Toggle the despawning value
            GameplayTab_VehicleBehaviourGroup.DisableDespawning.Value = !Options.disableDespawning;

            // Update currently visible tooltip
            this.UpdateTooltip(refreshTooltip: true);
            this.ApplyButtonSkin();
            // do not call base -- base.OnClick(p);
        }
Пример #26
0
        public void CustomClickNodeButton(ushort nodeId, ref NetNode data, int index)
        {
            if ((data.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None ||
                Singleton <InfoManager> .instance.CurrentMode != InfoManager.InfoMode.TrafficRoutes ||
                Singleton <InfoManager> .instance.CurrentSubMode !=
                InfoManager.SubInfoMode.WaterPower)
            {
                return;
            }

            if (index == -1)
            {
                /*data.m_flags ^= NetNode.Flags.TrafficLights;
                 *  data.m_flags |= NetNode.Flags.CustomTrafficLights;*/

                // NON-STOCK CODE START
                ToggleTrafficLightsTool toggleTool = (ToggleTrafficLightsTool)ModUI
                                                     .GetTrafficManagerTool(true)
                                                     .GetSubTool(ToolMode.SwitchTrafficLight);
                toggleTool.ToggleTrafficLight(nodeId, ref data, false);

                // NON-STOCK CODE END
                UpdateNodeFlags(nodeId, ref data);
                Singleton <NetManager> .instance.m_yieldLights.Disable();
            }
            else if (index >= 1 &&
                     index <= 8 &&
                     (data.m_flags & (NetNode.Flags.TrafficLights
                                      | NetNode.Flags.OneWayIn)) == NetNode.Flags.None)
            {
                ushort segmentId = data.GetSegment(index - 1);
                if (segmentId == 0)
                {
                    return;
                }

                NetManager netManager = Singleton <NetManager> .instance;
                NetInfo    info       = netManager.m_segments.m_buffer[segmentId].Info;
                if ((info.m_vehicleTypes & (VehicleInfo.VehicleType.Car | VehicleInfo.VehicleType.Tram)) ==
                    VehicleInfo.VehicleType.None)
                {
                    return;
                }

                bool             flag  = netManager.m_segments.m_buffer[segmentId].m_startNode == nodeId;
                NetSegment.Flags flags = (!flag) ? NetSegment.Flags.YieldEnd : NetSegment.Flags.YieldStart;
                netManager.m_segments.m_buffer[segmentId].m_flags ^= flags;
                netManager.m_segments.m_buffer[segmentId].UpdateLanes(segmentId, true);
                Singleton <NetManager> .instance.m_yieldLights.Disable();
            }
        }
Пример #27
0
        public override void OnClickInternal(UIMouseEventParameter p)
        {
            ConfirmPanel.ShowModal(
                Translation.Menu.Get("Tooltip:Clear traffic"),
                Translation.Menu.Get("Dialog.Text:Clear traffic, confirmation"),
                (comp, ret) => {
                if (ret == 1)
                {
                    Constants.ServiceFactory.SimulationService.AddAction(
                        () => { UtilityManager.Instance.ClearTraffic(); });
                }

                ModUI.GetTrafficManagerTool(true).SetToolMode(ToolMode.None);
            });
        }
        protected override void OnClick(UIMouseEventParameter p)
        {
            ConfirmPanel.ShowModal(
                title: Translation.Menu.Get("Tooltip:Clear traffic"),
                message: Translation.Menu.Get("Dialog.Text:Clear traffic, confirmation"),
                callback: (comp, ret) => {
                if (ret == 1)
                {
                    Singleton <SimulationManager> .instance.AddAction(
                        () => UtilityManager.Instance.ClearTraffic());
                }

                ModUI.GetTrafficManagerTool()?.SetToolMode(ToolMode.None);
            });
            base.OnClick(p);
        }
Пример #29
0
        /// <summary>
        /// refreshes all subtools incflucned by mass edit.
        /// the mass edit overlay active while processing
        /// and remains active for one extra second so that
        /// </summary>
        private void RefreshMassEditOverlay()
        {
            // processing takes while.
            // Keep mass edit overlay active so that user has visual feedaback
            // that something is happening.
            // this is also to make sure overlay is refresshed
            // even when the user lets go of the mass edit overlay hotkey.
            MassEditOVerlay.SetTimer(float.MaxValue);

            ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
            RefreshCurrentPriorityNodeIds();

            // keep active for one more second so that the user
            // has a chance to see the new traffic rules.
            MassEditOVerlay.SetTimer(1);
        }
Пример #30
0
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            base.OnUpdate(realTimeDelta, simulationTimeDelta);

            using (var bm = Benchmark.MaybeCreateBenchmark()) {
                if (ToolsModifierControl.toolController == null || ModUI.Instance == null)
                {
                    return;
                }

                TrafficManagerTool tmTool = ModUI.GetTrafficManagerTool(false);
                if (tmTool != null && ToolsModifierControl.toolController.CurrentTool != tmTool &&
                    ModUI.Instance.IsVisible())
                {
                    ModUI.Instance.CloseMainMenu();
                }

                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    ModUI.Instance.CloseMainMenu();
                }
            } // end benchmark
        }