From ea5a76d6718797d684b1b2e41f3c8ed782c0c4c6 Mon Sep 17 00:00:00 2001 From: seiggy Date: Wed, 22 Jul 2015 22:44:21 -0400 Subject: [PATCH] Fixed the Traffic++ detection code. No longer disables the Lane Changer and Traffic Remover features errantly. --- TLM/TLM.sln.DotSettings | 3 +- TLM/TLM/SegmentRestrictions.cs | 4 +- TLM/TLM/SerializableDataExtension.cs | 2 +- TLM/TLM/ThreadingExtension.cs | 2 +- TLM/TLM/TrafficLight/TrafficLightTool.cs | 1689 ++++++++++++---------- TLM/TLM/UI/UITrafficManager.cs | 12 +- 6 files changed, 911 insertions(+), 801 deletions(-) diff --git a/TLM/TLM.sln.DotSettings b/TLM/TLM.sln.DotSettings index 550cf7cb..cc265b00 100644 --- a/TLM/TLM.sln.DotSettings +++ b/TLM/TLM.sln.DotSettings @@ -1,2 +1,3 @@  - AI \ No newline at end of file + AI + GUI \ No newline at end of file diff --git a/TLM/TLM/SegmentRestrictions.cs b/TLM/TLM/SegmentRestrictions.cs index 3c113752..d2e7a878 100644 --- a/TLM/TLM/SegmentRestrictions.cs +++ b/TLM/TLM/SegmentRestrictions.cs @@ -15,8 +15,8 @@ class SegmentRestrictions public SegmentRestrictions(int segmentid, List segmentGroup ) { - this._segmentId = segmentid; - this.SegmentGroup = new List(segmentGroup); + _segmentId = segmentid; + SegmentGroup = new List(segmentGroup); } public void AddLane(uint lane, int lanenum, NetInfo.Direction dir) diff --git a/TLM/TLM/SerializableDataExtension.cs b/TLM/TLM/SerializableDataExtension.cs index 94485e65..948ddf3c 100644 --- a/TLM/TLM/SerializableDataExtension.cs +++ b/TLM/TLM/SerializableDataExtension.cs @@ -60,7 +60,7 @@ public void OnLoadData() } } - private static void OnLoadDataTimed(Object source, ElapsedEventArgs e) + private static void OnLoadDataTimed(object source, ElapsedEventArgs e) { byte[] data = SerializableData.LoadData(DataId); diff --git a/TLM/TLM/ThreadingExtension.cs b/TLM/TLM/ThreadingExtension.cs index 4efc7383..cc57d09d 100644 --- a/TLM/TLM/ThreadingExtension.cs +++ b/TLM/TLM/ThreadingExtension.cs @@ -67,7 +67,7 @@ public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) null), typeof (CustomHumanAI).GetMethod("CustomCheckTrafficLights")); - if (!LoadingExtension.IsPathManagerCompatibile) + if (LoadingExtension.IsPathManagerCompatibile) { Debug.Log("Traffic++ Not detected. Loading Pathfinder."); Debug.Log("Redirecting CarAI Simulation Step Calls"); diff --git a/TLM/TLM/TrafficLight/TrafficLightTool.cs b/TLM/TLM/TrafficLight/TrafficLightTool.cs index f9d93549..c93ce100 100644 --- a/TLM/TLM/TrafficLight/TrafficLightTool.cs +++ b/TLM/TLM/TrafficLight/TrafficLightTool.cs @@ -6,6 +6,7 @@ using ColossalFramework; using ColossalFramework.Math; using ColossalFramework.UI; +using JetBrains.Annotations; using TrafficManager.CustomAI; using TrafficManager.Traffic; using UnityEngine; @@ -79,9 +80,9 @@ public class TrafficLightTool : DefaultTool private Rect _windowRect; private Rect _windowRect2; - public float StepValue = 1f; + private float _stepValue = 1f; - public float[] SliderValues = new float[16] {1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f}; + private readonly float[] _sliderValues = {1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f,1f}; private Texture2D _secondPanelTexture; @@ -147,13 +148,13 @@ protected override void Awake() base.Awake(); } - public static Texture2D LoadDllResource(string resourceName, int width, int height) + private static Texture2D LoadDllResource(string resourceName, int width, int height) { var myAssembly = Assembly.GetExecutingAssembly(); var myStream = myAssembly.GetManifestResourceStream("TrafficManager.Resources." + resourceName); var texture = new Texture2D(width, height, TextureFormat.ARGB32, false); - + texture.LoadImage(ReadToEnd(myStream)); return texture; @@ -161,41 +162,40 @@ public static Texture2D LoadDllResource(string resourceName, int width, int heig static byte[] ReadToEnd(Stream stream) { - long originalPosition = stream.Position; + var originalPosition = stream.Position; stream.Position = 0; try { - byte[] readBuffer = new byte[4096]; + var readBuffer = new byte[4096]; - int totalBytesRead = 0; + var totalBytesRead = 0; int bytesRead; while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0) { totalBytesRead += bytesRead; - if (totalBytesRead == readBuffer.Length) - { - int nextByte = stream.ReadByte(); - if (nextByte != -1) - { - byte[] temp = new byte[readBuffer.Length*2]; - Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length); - Buffer.SetByte(temp, totalBytesRead, (byte) nextByte); - readBuffer = temp; - totalBytesRead++; + if (totalBytesRead != readBuffer.Length) + continue; - } - } - } + var nextByte = stream.ReadByte(); + if (nextByte == -1) + continue; - byte[] buffer = readBuffer; - if (readBuffer.Length != totalBytesRead) - { - buffer = new byte[totalBytesRead]; - Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead); + var temp = new byte[readBuffer.Length*2]; + Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length); + Buffer.SetByte(temp, totalBytesRead, (byte) nextByte); + readBuffer = temp; + totalBytesRead++; } + + var buffer = readBuffer; + if (readBuffer.Length == totalBytesRead) + return buffer; + + buffer = new byte[totalBytesRead]; + Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead); return buffer; } finally @@ -205,6 +205,7 @@ static byte[] ReadToEnd(Stream stream) } // Expose protected property + // ReSharper disable once MemberCanBePrivate.Global public new CursorInfo ToolCursor { get { return base.ToolCursor; } @@ -259,161 +260,136 @@ public override void RenderGeometry(RenderManager.CameraInfo cameraInfo) public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) { - if (ToolMode == ToolMode.SwitchTrafficLight) - { - if (m_toolController.IsInsideUI || !Cursor.visible) - { - return; - } - - _renderOverlaySwitch(cameraInfo); - } - else if (ToolMode == ToolMode.AddPrioritySigns) - { - _renderOverlayPriority(cameraInfo); - } - else if (ToolMode == ToolMode.ManualSwitch) - { - _renderOverlayManual(cameraInfo); - } - else if (ToolMode == ToolMode.TimedLightsSelectNode) - { - _renderOverlayTimedSelectNodes(cameraInfo); - } - else if (ToolMode == ToolMode.TimedLightsShowLights) + switch (ToolMode) { + case ToolMode.SwitchTrafficLight: + if (m_toolController.IsInsideUI || !Cursor.visible) + { + return; + } - } - else if (ToolMode == ToolMode.LaneChange) - { - _renderOverlayLaneChange(cameraInfo); - } - else if (ToolMode == ToolMode.LaneRestrictions) - { - _renderOverlayLaneRestrictions(cameraInfo); - } - else if (ToolMode == ToolMode.Crosswalk) - { - _renderOverlayCrosswalk(cameraInfo); - } - else - { - base.RenderOverlay(cameraInfo); + _renderOverlaySwitch(cameraInfo, _mouseDown); + break; + case ToolMode.AddPrioritySigns: + _renderOverlaySwitch(cameraInfo, false); + break; + case ToolMode.ManualSwitch: + _renderOverlayManual(cameraInfo); + break; + case ToolMode.TimedLightsSelectNode: + _renderOverlayTimedSelectNodes(cameraInfo); + break; + case ToolMode.TimedLightsShowLights: + + break; + case ToolMode.LaneChange: + _renderOverlayLaneChange(cameraInfo); + break; + case ToolMode.LaneRestrictions: + _renderOverlayLaneRestrictions(cameraInfo); + break; + case ToolMode.Crosswalk: + _renderOverlayCrosswalk(cameraInfo); + break; + default: + base.RenderOverlay(cameraInfo); + break; } } - public void _renderOverlaySwitch(RenderManager.CameraInfo cameraInfo) + public void _renderOverlaySwitch(RenderManager.CameraInfo cameraInfo, bool warning = false) { - if (_hoveredNetNodeIdx != 0) - { - var node = GetNetNode(_hoveredNetNodeIdx); - - if ((node.m_flags & NetNode.Flags.Junction) != NetNode.Flags.None) - { - Bezier3 bezier; + if (_hoveredNetNodeIdx == 0) return; - var segment = Singleton.instance.m_segments.m_buffer[node.m_segment0]; - - bezier.a = node.m_position; - bezier.d = node.m_position; + var node = GetNetNode(_hoveredNetNodeIdx); - var color = GetToolColor(_mouseDown, false); + if ((node.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) return; - NetSegment.CalculateMiddlePoints(bezier.a, segment.m_startDirection, bezier.d, - segment.m_endDirection, - false, false, out bezier.b, out bezier.c); - _renderOverlayDraw(cameraInfo, bezier, color); - } - } - } + var segment = Singleton.instance.m_segments.m_buffer[node.m_segment0]; - public void _renderOverlayPriority(RenderManager.CameraInfo cameraInfo) - { - if (_hoveredNetNodeIdx != 0 && _hoveredNetNodeIdx != SelectedNode) - { - var node = GetNetNode(_hoveredNetNodeIdx); - var segment = Singleton.instance.m_segments.m_buffer[node.m_segment0]; + Bezier3 bezier; + bezier.a = node.m_position; + bezier.d = node.m_position; - if ((node.m_flags & NetNode.Flags.TrafficLights) == NetNode.Flags.None) - { - Bezier3 bezier; - bezier.a = node.m_position; - bezier.d = node.m_position; + var color = GetToolColor(warning, false); - var color = GetToolColor(false, false); + NetSegment.CalculateMiddlePoints(bezier.a, segment.m_startDirection, bezier.d, + segment.m_endDirection, + false, false, out bezier.b, out bezier.c); - NetSegment.CalculateMiddlePoints(bezier.a, segment.m_startDirection, bezier.d, - segment.m_endDirection, false, false, out bezier.b, out bezier.c); - _renderOverlayDraw(cameraInfo, bezier, color); - } - } + _renderOverlayDraw(cameraInfo, bezier, color); } public void _renderOverlayManual(RenderManager.CameraInfo cameraInfo) { if (SelectedNode != 0) { - var node = GetNetNode(SelectedNode); + RenderNodeOverlays(cameraInfo); + } + else + { + RenderSelectionOverlay(cameraInfo); + } + } - var colorGray = new Color(0.25f, 0.25f, 0.25f, 0.25f); + private void RenderSelectionOverlay(RenderManager.CameraInfo cameraInfo) + { + if (_hoveredNetNodeIdx == 0) return; + var node = GetNetNode(_hoveredNetNodeIdx); + var segment = Singleton.instance.m_segments.m_buffer[node.m_segment0]; - var color2 = colorGray; + if ((node.m_flags & NetNode.Flags.TrafficLights) == NetNode.Flags.None) return; + Bezier3 bezier; + bezier.a = node.m_position; + bezier.d = node.m_position; - var nodeSimulation = CustomRoadAI.GetNodeSimulation(SelectedNode); + var color = GetToolColor(false, false); - for (var i = 0; i < 8; i++) - { - int segmentId = node.GetSegment(i); + NetSegment.CalculateMiddlePoints(bezier.a, segment.m_startDirection, bezier.d, + segment.m_endDirection, false, false, out bezier.b, out bezier.c); + _renderOverlayDraw(cameraInfo, bezier, color); + } - if (segmentId != 0) - { - var segment = Singleton.instance.m_segments.m_buffer[segmentId]; + private void RenderNodeOverlays(RenderManager.CameraInfo cameraInfo) + { + var node = GetNetNode(SelectedNode); + + var nodeSimulation = CustomRoadAI.GetNodeSimulation(SelectedNode); - var position = node.m_position; + for (var i = 0; i < 8; i++) + { + var colorGray = new Color(0.25f, 0.25f, 0.25f, 0.25f); + int segmentId = node.GetSegment(i); - if (segment.m_startNode == SelectedNode) - { - position.x += segment.m_startDirection.x*10f; - position.y += segment.m_startDirection.y*10f; - position.z += segment.m_startDirection.z*10f; - } - else - { - position.x += segment.m_endDirection.x*10f; - position.y += segment.m_endDirection.y*10f; - position.z += segment.m_endDirection.z*10f; - } + if (segmentId == 0 || + (nodeSimulation != null && TrafficLightsManual.IsSegmentLight(SelectedNode, segmentId))) + continue; + + var position = CalculateNodePositionForSegment(node, segmentId); - if (nodeSimulation == null || !TrafficLightsManual.IsSegmentLight(SelectedNode, segmentId)) - { - var width = _hoveredButton[0] == segmentId ? 11.25f : 10f; + var width = _hoveredButton[0] == segmentId ? 11.25f : 10f; + _renderOverlayDraw(cameraInfo, colorGray, position, width, segmentId != _hoveredButton[0]); + } + } - _renderOverlayDraw(cameraInfo, color2, position, width, segmentId != _hoveredButton[0]); - } - } - } + private static Vector3 CalculateNodePositionForSegment(NetNode node, int segmentId) + { + var position = node.m_position; + + var segment = Singleton.instance.m_segments.m_buffer[segmentId]; + if (segment.m_startNode == SelectedNode) + { + position.x += segment.m_startDirection.x*10f; + position.y += segment.m_startDirection.y*10f; + position.z += segment.m_startDirection.z*10f; } else { - if (_hoveredNetNodeIdx != 0) - { - var node = GetNetNode(_hoveredNetNodeIdx); - var segment = Singleton.instance.m_segments.m_buffer[node.m_segment0]; - - if ((node.m_flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None) - { - Bezier3 bezier; - bezier.a = node.m_position; - bezier.d = node.m_position; - - var color = GetToolColor(false, false); - - NetSegment.CalculateMiddlePoints(bezier.a, segment.m_startDirection, bezier.d, - segment.m_endDirection, false, false, out bezier.b, out bezier.c); - _renderOverlayDraw(cameraInfo, bezier, color); - } - } + position.x += segment.m_endDirection.x*10f; + position.y += segment.m_endDirection.y*10f; + position.z += segment.m_endDirection.z*10f; } + return position; } public void _renderOverlayTimedSelectNodes(RenderManager.CameraInfo cameraInfo) @@ -437,24 +413,23 @@ public void _renderOverlayTimedSelectNodes(RenderManager.CameraInfo cameraInfo) } } - if (SelectedNodeIndexes.Count > 0) + if (SelectedNodeIndexes.Count <= 0) return; + + foreach (var index in SelectedNodeIndexes) { - foreach (var index in SelectedNodeIndexes) - { - var node = GetNetNode(index); - var segment = Singleton.instance.m_segments.m_buffer[node.m_segment0]; + var node = GetNetNode(index); + var segment = Singleton.instance.m_segments.m_buffer[node.m_segment0]; - Bezier3 bezier; + Bezier3 bezier; - bezier.a = node.m_position; - bezier.d = node.m_position; + bezier.a = node.m_position; + bezier.d = node.m_position; - var color = GetToolColor(true, false); + var color = GetToolColor(true, false); - NetSegment.CalculateMiddlePoints(bezier.a, segment.m_startDirection, bezier.d, - segment.m_endDirection, false, false, out bezier.b, out bezier.c); - _renderOverlayDraw(cameraInfo, bezier, color); - } + NetSegment.CalculateMiddlePoints(bezier.a, segment.m_startDirection, bezier.d, + segment.m_endDirection, false, false, out bezier.b, out bezier.c); + _renderOverlayDraw(cameraInfo, bezier, color); } } @@ -468,19 +443,18 @@ public void _renderOverlayLaneChange(RenderManager.CameraInfo cameraInfo) if ((netFlags & NetNode.Flags.Junction) != NetNode.Flags.None) { - var segment = Singleton.instance.m_segments.m_buffer[_hoveredSegmentIdx]; + var hoveredSegment = Singleton.instance.m_segments.m_buffer[_hoveredSegmentIdx]; - NetTool.RenderOverlay(cameraInfo, ref segment, GetToolColor(false, false), + NetTool.RenderOverlay(cameraInfo, ref hoveredSegment, GetToolColor(false, false), GetToolColor(false, false)); } } - if (SelectedSegment != 0) - { - var segment = Singleton.instance.m_segments.m_buffer[SelectedSegment]; + if (SelectedSegment == 0) return; - NetTool.RenderOverlay(cameraInfo, ref segment, GetToolColor(true, false), GetToolColor(true, false)); - } + var selectedSegment = Singleton.instance.m_segments.m_buffer[SelectedSegment]; + + NetTool.RenderOverlay(cameraInfo, ref selectedSegment, GetToolColor(true, false), GetToolColor(true, false)); } public void _renderOverlayLaneRestrictions(RenderManager.CameraInfo cameraInfo) @@ -497,13 +471,12 @@ public void _renderOverlayLaneRestrictions(RenderManager.CameraInfo cameraInfo) } } - if (_hoveredSegmentIdx != 0) - { - var segment = Singleton.instance.m_segments.m_buffer[_hoveredSegmentIdx]; + if (_hoveredSegmentIdx == 0) return; - NetTool.RenderOverlay(cameraInfo, ref segment, GetToolColor(false, false), - GetToolColor(false, false)); - } + var hoveredSegment = Singleton.instance.m_segments.m_buffer[_hoveredSegmentIdx]; + + NetTool.RenderOverlay(cameraInfo, ref hoveredSegment, GetToolColor(false, false), + GetToolColor(false, false)); } public void _renderOverlayCrosswalk(RenderManager.CameraInfo cameraInfo) @@ -596,255 +569,281 @@ protected override void OnToolUpdate() if (_mouseDown) { - if (!_mouseClicked) + if (_mouseClicked) return; + + _mouseClicked = true; + + if (m_toolController.IsInsideUI || !Cursor.visible || _cursorInSecondaryPanel) { - _mouseClicked = true; + return; + } + if (_hoveredSegmentIdx == 0) return; + + var node = GetNetNode(_hoveredNetNodeIdx); + + switch (ToolMode) + { + case ToolMode.SwitchTrafficLight: + SwitchTrafficLightToolMode(node); + break; + case ToolMode.AddPrioritySigns: + AddPrioritySignsToolMode(node); + break; + case ToolMode.ManualSwitch: + ManualSwitchToolMode(node); + break; + case ToolMode.TimedLightsSelectNode: + TimedLightSelectNodeToolMode(node); + break; + case ToolMode.LaneChange: + LaneChangeToolMode(); + break; + case ToolMode.Crosswalk: + CrosswalkToolMode(); + break; + case ToolMode.LaneRestrictions: + LaneRestrictionsToolMode(); + break; + } + } + else + { + ShowToolInfo(false, null, Vector3.zero); + _mouseClicked = false; + } + } + + private void LaneChangeToolMode() + { + if (_hoveredNetNodeIdx == 0 || _hoveredSegmentIdx == 0) return; + + var netFlags = Singleton.instance.m_nodes.m_buffer[_hoveredNetNodeIdx].m_flags; + + if ((netFlags & NetNode.Flags.Junction) == NetNode.Flags.None) return; + + SelectedSegment = _hoveredSegmentIdx; + SelectedNode = _hoveredNetNodeIdx; + } - if (m_toolController.IsInsideUI || !Cursor.visible || _cursorInSecondaryPanel) + private void TimedLightSelectNodeToolMode(NetNode node) + { + if (!TrafficLightsTimed.IsTimedLight(_hoveredNetNodeIdx)) + { + if ((node.m_flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None) + { + if (ContainsListNode(_hoveredNetNodeIdx)) { - return; + RemoveListNode(_hoveredNetNodeIdx); } - - if (_hoveredNetNodeIdx != 0) + else { - var node = GetNetNode(_hoveredNetNodeIdx); + AddListNode(_hoveredNetNodeIdx); + } + } + else + { + ShowToolInfo(true, "Node is not a traffic light", node.m_position); + } + } + else + { + if (SelectedNodeIndexes.Count == 0) + { + var timedLight = TrafficLightsTimed.GetTimedLight(_hoveredNetNodeIdx); - if (ToolMode == ToolMode.SwitchTrafficLight) - { - if ((node.m_flags & NetNode.Flags.Junction) != NetNode.Flags.None) - { - _switchTrafficLights(); - } - } - else if (ToolMode == ToolMode.AddPrioritySigns) - { - if ((node.m_flags & NetNode.Flags.TrafficLights) == NetNode.Flags.None) - { - _uiClickedSegment = true; - SelectedNode = _hoveredNetNodeIdx; - } - else - { - ShowToolInfo(true, "Node should not be a traffic light", node.m_position); - } - } - else if (ToolMode == ToolMode.ManualSwitch) - { - if (SelectedNode == 0) - { - if (!TrafficLightsTimed.IsTimedLight(_hoveredNetNodeIdx)) - { - if ((node.m_flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None) - { - SelectedNode = _hoveredNetNodeIdx; + SelectedNodeIndexes = new List(timedLight.NodeGroup); + SetToolMode(ToolMode.TimedLightsShowLights); + } + else + { + ShowToolInfo(true, "Node is part of timed script", node.m_position); + } + } + } - var node2 = GetNetNode(SelectedNode); + private void ManualSwitchToolMode(NetNode node) + { + if (SelectedNode != 0) return; - CustomRoadAI.AddNodeToSimulation(SelectedNode); - var nodeSimulation = CustomRoadAI.GetNodeSimulation(SelectedNode); - nodeSimulation.FlagManualTrafficLights = true; + if (!TrafficLightsTimed.IsTimedLight(_hoveredNetNodeIdx)) + { + if ((node.m_flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None) + { + SelectedNode = _hoveredNetNodeIdx; - for (var s = 0; s < 8; s++) - { - var segment = node2.GetSegment(s); + var node2 = GetNetNode(SelectedNode); - if (segment != 0 && !TrafficPriority.IsPrioritySegment(SelectedNode, segment)) - { - TrafficPriority.AddPrioritySegment(SelectedNode, segment, PrioritySegment.PriorityType.None); - } - } - } - else - { - ShowToolInfo(true, "Node is not a traffic light", node.m_position); - } - } - else - { - if (SelectedNodeIndexes.Count == 0) - { + CustomRoadAI.AddNodeToSimulation(SelectedNode); + var nodeSimulation = CustomRoadAI.GetNodeSimulation(SelectedNode); + nodeSimulation.FlagManualTrafficLights = true; - } - ShowToolInfo(true, "Node is part of timed script", node.m_position); - } - } - } - else if (ToolMode == ToolMode.TimedLightsSelectNode) - { - if (!TrafficLightsTimed.IsTimedLight(_hoveredNetNodeIdx)) - { - if ((node.m_flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None) - { - if (ContainsListNode(_hoveredNetNodeIdx)) - { - RemoveListNode(_hoveredNetNodeIdx); - } - else - { - AddListNode(_hoveredNetNodeIdx); - } - } - else - { - ShowToolInfo(true, "Node is not a traffic light", node.m_position); - } - } - else - { - if (SelectedNodeIndexes.Count == 0) - { - var timedLight = TrafficLightsTimed.GetTimedLight(_hoveredNetNodeIdx); + for (var s = 0; s < 8; s++) + { + var segment = node2.GetSegment(s); - SelectedNodeIndexes = new List(timedLight.NodeGroup); - SetToolMode(ToolMode.TimedLightsShowLights); - } - else - { - ShowToolInfo(true, "Node is part of timed script", node.m_position); - } - } - } - else if (ToolMode == ToolMode.LaneChange) + if (segment != 0 && !TrafficPriority.IsPrioritySegment(SelectedNode, segment)) { - if (_hoveredNetNodeIdx != 0 && _hoveredSegmentIdx != 0) - { - var netFlags = Singleton.instance.m_nodes.m_buffer[_hoveredNetNodeIdx].m_flags; - - if ((netFlags & NetNode.Flags.Junction) != NetNode.Flags.None) - { - SelectedSegment = _hoveredSegmentIdx; - SelectedNode = _hoveredNetNodeIdx; - } - } + TrafficPriority.AddPrioritySegment(SelectedNode, segment, PrioritySegment.PriorityType.None); } } - if (_hoveredSegmentIdx != 0) - { - if (ToolMode == ToolMode.Crosswalk) - { - var segment = Singleton.instance.m_segments.m_buffer[_hoveredSegmentIdx]; - - var startNode = GetNetNode(segment.m_startNode); - var endNode = GetNetNode(segment.m_endNode); - - var result = false; - - if (!result && ValidCrosswalkNode(segment.m_startNode, startNode)) - { - if ((startNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) - { - startNode.m_flags |= NetNode.Flags.Junction; - result = true; - } - } - if (!result && (ValidCrosswalkNode(segment.m_startNode, startNode) || ValidCrosswalkNode(segment.m_endNode, endNode)) && (endNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) - { - if (ValidCrosswalkNode(segment.m_startNode, startNode) && (startNode.m_flags & NetNode.Flags.Junction) != NetNode.Flags.None) - { - startNode.m_flags &= ~NetNode.Flags.Junction; - result = true; - } - if (ValidCrosswalkNode(segment.m_endNode, endNode) && - (endNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) - { - endNode.m_flags |= NetNode.Flags.Junction; - result = true; - } - } - if (!result && - (ValidCrosswalkNode(segment.m_startNode, startNode) || - ValidCrosswalkNode(segment.m_endNode, endNode))) - { - if (ValidCrosswalkNode(segment.m_startNode, startNode) && (startNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) - { - startNode.m_flags |= NetNode.Flags.Junction; - result = true; - } - if (ValidCrosswalkNode(segment.m_endNode, endNode) && - (endNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) - { - endNode.m_flags |= NetNode.Flags.Junction; - result = true; - } - } - if (!result && - (ValidCrosswalkNode(segment.m_startNode, startNode) || - ValidCrosswalkNode(segment.m_endNode, endNode))) - { - if (ValidCrosswalkNode(segment.m_startNode, startNode) && (startNode.m_flags & NetNode.Flags.Junction) != NetNode.Flags.None) - { - startNode.m_flags &= ~NetNode.Flags.Junction; - } - if (ValidCrosswalkNode(segment.m_endNode, endNode) && - (endNode.m_flags & NetNode.Flags.Junction) != NetNode.Flags.None) - { - endNode.m_flags &= ~NetNode.Flags.Junction; - } - } + } + else + { + ShowToolInfo(true, "Node is not a traffic light", node.m_position); + } + } + else + { + if (SelectedNodeIndexes.Count == 0) + { + } + ShowToolInfo(true, "Node is part of timed script", node.m_position); + } + } - SetNetNode(segment.m_startNode, startNode); - SetNetNode(segment.m_endNode, endNode); - } - else if (ToolMode == ToolMode.LaneRestrictions) - { - var segment = Singleton.instance.m_segments.m_buffer[_hoveredSegmentIdx]; - var info = segment.Info; + private void AddPrioritySignsToolMode(NetNode node) + { + if ((node.m_flags & NetNode.Flags.TrafficLights) == NetNode.Flags.None) + { + _uiClickedSegment = true; + SelectedNode = _hoveredNetNodeIdx; + } + else + { + ShowToolInfo(true, "Node should not be a traffic light", node.m_position); + } + } - if (TrafficRoadRestrictions.IsSegment(_hoveredSegmentIdx)) - { - if (SelectedSegmentIndexes.Count > 0) - { - ShowToolInfo(true, "Road is already in a group!", - Singleton.instance.m_nodes.m_buffer[segment.m_startNode] - .m_position); - } - else - { - var restSegment = TrafficRoadRestrictions.GetSegment(_hoveredSegmentIdx); + private void SwitchTrafficLightToolMode(NetNode node) + { + if ((node.m_flags & NetNode.Flags.Junction) != NetNode.Flags.None) + { + _switchTrafficLights(); + } + } - SelectedSegmentIndexes = new List(restSegment.SegmentGroup); - } - } - else - { - if (ContainsListSegment(_hoveredSegmentIdx)) - { - RemoveListSegment(_hoveredSegmentIdx); - } - else - { - if (SelectedSegmentIndexes.Count > 0) - { - var segment2 = - Singleton.instance.m_segments.m_buffer[SelectedSegmentIndexes[0] - ]; - var info2 = segment2.Info; + private void CrosswalkToolMode() + { + var segment = Singleton.instance.m_segments.m_buffer[_hoveredSegmentIdx]; - if (info.m_lanes.Length != info2.m_lanes.Length) - { - ShowToolInfo(true, "All selected roads must be of the same type!", - Singleton.instance.m_nodes.m_buffer[segment.m_startNode] - .m_position); - } - else - { - AddListSegment(_hoveredSegmentIdx); - } - } - else - { - AddListSegment(_hoveredSegmentIdx); - } - } - } - } - } + var startNode = GetNetNode(segment.m_startNode); + var endNode = GetNetNode(segment.m_endNode); + + var result = false; + + if (!result && ValidCrosswalkNode(segment.m_startNode, startNode)) + { + if ((startNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) + { + startNode.m_flags |= NetNode.Flags.Junction; + result = true; + } + } + if (!result && + (ValidCrosswalkNode(segment.m_startNode, startNode) || ValidCrosswalkNode(segment.m_endNode, endNode)) && + (endNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) + { + if (ValidCrosswalkNode(segment.m_startNode, startNode) && + (startNode.m_flags & NetNode.Flags.Junction) != NetNode.Flags.None) + { + startNode.m_flags &= ~NetNode.Flags.Junction; + result = true; + } + if (ValidCrosswalkNode(segment.m_endNode, endNode) && + (endNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) + { + endNode.m_flags |= NetNode.Flags.Junction; + result = true; + } + } + if (!result && + (ValidCrosswalkNode(segment.m_startNode, startNode) || + ValidCrosswalkNode(segment.m_endNode, endNode))) + { + if (ValidCrosswalkNode(segment.m_startNode, startNode) && + (startNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) + { + startNode.m_flags |= NetNode.Flags.Junction; + result = true; + } + if (ValidCrosswalkNode(segment.m_endNode, endNode) && + (endNode.m_flags & NetNode.Flags.Junction) == NetNode.Flags.None) + { + endNode.m_flags |= NetNode.Flags.Junction; + result = true; + } + } + if (!result && + (ValidCrosswalkNode(segment.m_startNode, startNode) || + ValidCrosswalkNode(segment.m_endNode, endNode))) + { + if (ValidCrosswalkNode(segment.m_startNode, startNode) && + (startNode.m_flags & NetNode.Flags.Junction) != NetNode.Flags.None) + { + startNode.m_flags &= ~NetNode.Flags.Junction; + } + if (ValidCrosswalkNode(segment.m_endNode, endNode) && + (endNode.m_flags & NetNode.Flags.Junction) != NetNode.Flags.None) + { + endNode.m_flags &= ~NetNode.Flags.Junction; + } + } + + SetNetNode(segment.m_startNode, startNode); + SetNetNode(segment.m_endNode, endNode); + } + + private void LaneRestrictionsToolMode() + { + var segment = Singleton.instance.m_segments.m_buffer[_hoveredSegmentIdx]; + var info = segment.Info; + + if (TrafficRoadRestrictions.IsSegment(_hoveredSegmentIdx)) + { + if (SelectedSegmentIndexes.Count > 0) + { + ShowToolInfo(true, "Road is already in a group!", + Singleton.instance.m_nodes.m_buffer[segment.m_startNode] + .m_position); + } + else + { + var restSegment = TrafficRoadRestrictions.GetSegment(_hoveredSegmentIdx); + + SelectedSegmentIndexes = new List(restSegment.SegmentGroup); } } else { - ShowToolInfo(false, null, Vector3.zero); - _mouseClicked = false; + if (ContainsListSegment(_hoveredSegmentIdx)) + { + RemoveListSegment(_hoveredSegmentIdx); + } + else + { + if (SelectedSegmentIndexes.Count > 0) + { + var segment2 = + Singleton.instance.m_segments.m_buffer[SelectedSegmentIndexes[0] + ]; + var info2 = segment2.Info; + + if (info.m_lanes.Length != info2.m_lanes.Length) + { + ShowToolInfo(true, "All selected roads must be of the same type!", + Singleton.instance.m_nodes.m_buffer[segment.m_startNode] + .m_position); + } + else + { + AddListSegment(_hoveredSegmentIdx); + } + } + else + { + AddListSegment(_hoveredSegmentIdx); + } + } } } @@ -906,474 +905,579 @@ protected void _guiManualTrafficLights() { int segmentId = node.GetSegment(i); - if (segmentId != 0 && nodeSimulation != null && TrafficLightsManual.IsSegmentLight(SelectedNode, segmentId)) - { - var segmentDict = TrafficLightsManual.GetSegmentLight(SelectedNode, segmentId); + if (segmentId == 0 || nodeSimulation == null || + !TrafficLightsManual.IsSegmentLight(SelectedNode, segmentId)) continue; - var segment = Singleton.instance.m_segments.m_buffer[segmentId]; + var segmentDict = TrafficLightsManual.GetSegmentLight(SelectedNode, segmentId); - var position = node.m_position; + var segment = Singleton.instance.m_segments.m_buffer[segmentId]; - var offset = 25f; + var position = CalculateNodePositionForSegment(node, segment); + + var screenPos = Camera.main.WorldToScreenPoint(position); + screenPos.y = Screen.height - screenPos.y; - if (segment.m_startNode == SelectedNode) - { - position.x += segment.m_startDirection.x * offset; - position.y += segment.m_startDirection.y * offset; - position.z += segment.m_startDirection.z * offset; - } - else - { - position.x += segment.m_endDirection.x * offset; - position.y += segment.m_endDirection.y * offset; - position.z += segment.m_endDirection.z * offset; - } + var diff = position - Camera.main.transform.position; + var zoom = 1.0f/diff.magnitude*100f; - var guiColor = GUI.color; + // original / 2.5 + var lightWidth = 41f*zoom; + var lightHeight = 97f*zoom; - var screenPos = Camera.main.WorldToScreenPoint(position); - screenPos.y = Screen.height - screenPos.y; + // SWITCH MODE BUTTON + var modeWidth = 41f*zoom; + var modeHeight = 38f*zoom; - Vector3 diff = position - Camera.main.transform.position; - float zoom = 1.0f/diff.magnitude*100f; + SetAlpha(segmentId, -1); - // original / 2.5 - var lightWidth = 41f*zoom; - var lightHeight = 97f*zoom; + var myRect1 = new Rect(screenPos.x - modeWidth / 2, screenPos.y - modeHeight / 2 + modeHeight - 7f*zoom, modeWidth, modeHeight); - // SWITCH MODE BUTTON - var modeWidth = 41f*zoom; - var modeHeight = 38f*zoom; + GUI.DrawTexture(myRect1, _lightMode); + hoveredSegment = GetHoveredSegment(myRect1, segmentId, hoveredSegment, segmentDict); - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == -1 ? 0.92f : 0.45f; + // COUNTER + hoveredSegment = RenderCounter(segmentId, screenPos, modeWidth, modeHeight, zoom, segmentDict, hoveredSegment); - GUI.color = guiColor; + // SWITCH MANUAL PEDESTRIAN LIGHT BUTTON + hoveredSegment = RenderManualPedestrianLightSwitch(zoom, segmentId, screenPos, lightWidth, segmentDict, hoveredSegment); - Rect myRect1 = new Rect(screenPos.x - modeWidth / 2, screenPos.y - modeHeight / 2 + modeHeight - 7f*zoom, modeWidth, modeHeight); + // SWITCH PEDESTRIAN LIGHT + var pedestrianWidth = 36f * zoom; + var pedestrianHeight = 61f * zoom; - GUI.DrawTexture(myRect1, _lightMode); + var guiColor = GUI.color; + guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 2 && segmentDict.PedestrianEnabled ? 0.92f : 0.45f; + GUI.color = guiColor; - if (myRect1.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = -1; - hoveredSegment = true; + var myRect3 = new Rect(screenPos.x - pedestrianWidth / 2 - lightWidth + 5f*zoom, screenPos.y - pedestrianHeight / 2 + 22f*zoom, pedestrianWidth, pedestrianHeight); - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ChangeMode(); - } - } + switch (segmentDict.LightPedestrian) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect3, _pedestrianLight2); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect3, _pedestrianLight1); + break; + } - // COUNTER - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 0 ? 0.92f : 0.45f; + hoveredSegment = IsPedestrianLightHovered(myRect3, segmentId, hoveredSegment, segmentDict); - Rect myRectCounter = new Rect(screenPos.x - modeWidth / 2, screenPos.y - modeHeight / 2 - 6f*zoom, modeWidth, modeHeight); + if (TrafficLightsManual.SegmentIsIncomingOneWay(segmentId, SelectedNode)) continue; - GUI.DrawTexture(myRectCounter, _lightCounter); + var hasLeftSegment = TrafficPriority.HasLeftSegment(segmentId, SelectedNode) && TrafficPriority.HasLeftLane(SelectedNode, segmentId); + var hasForwardSegment = TrafficPriority.HasForwardSegment(segmentId, SelectedNode) && TrafficPriority.HasForwardLane(SelectedNode, segmentId); + var hasRightSegment = TrafficPriority.HasRightSegment(segmentId, SelectedNode) && TrafficPriority.HasRightLane(SelectedNode, segmentId); - float counterSize = 20f * zoom; + switch (segmentDict.CurrentMode) + { + case ManualSegmentLight.Mode.Simple: + hoveredSegment = SimpleManualSegmentLightMode(segmentId, screenPos, lightWidth, pedestrianWidth, zoom, lightHeight, segmentDict, hoveredSegment); + break; + case ManualSegmentLight.Mode.LeftForwardR: + hoveredSegment = LeftForwardRManualSegmentLightMode(hasLeftSegment, segmentId, screenPos, lightWidth, pedestrianWidth, zoom, lightHeight, segmentDict, hoveredSegment, hasForwardSegment, hasRightSegment); + break; + case ManualSegmentLight.Mode.RightForwardL: + hoveredSegment = RightForwardLSegmentLightMode(segmentId, screenPos, lightWidth, pedestrianWidth, zoom, lightHeight, hasForwardSegment, hasLeftSegment, segmentDict, hasRightSegment, hoveredSegment); + break; + default: + // left arrow light + if (hasLeftSegment) + hoveredSegment = LeftArrowLightMode(segmentId, lightWidth, hasRightSegment, hasForwardSegment, screenPos, pedestrianWidth, zoom, lightHeight, segmentDict, hoveredSegment); + + // forward arrow light + if (hasForwardSegment) + hoveredSegment = ForwardArrowLightMode(segmentId, lightWidth, hasRightSegment, screenPos, pedestrianWidth, zoom, lightHeight, segmentDict, hoveredSegment); + + // right arrow light + if (hasRightSegment) + hoveredSegment = RightArrowLightMode(segmentId, screenPos, lightWidth, pedestrianWidth, zoom, lightHeight, segmentDict, hoveredSegment); + break; + } + } + } - var counter = segmentDict.LastChange; + if (hoveredSegment) return; + _hoveredButton[0] = 0; + _hoveredButton[1] = 0; + } - Rect myRectCounterNum = new Rect(screenPos.x - counterSize + 15f * zoom + (counter >= 10 ? -5*zoom : 0f), screenPos.y - counterSize + 11f * zoom, counterSize, counterSize); + private bool RightArrowLightMode(int segmentId, Vector3 screenPos, float lightWidth, + float pedestrianWidth, float zoom, float lightHeight, ManualSegmentLight segmentDict, bool hoveredSegment) + { + SetAlpha(segmentId, 5); - _counterStyle.fontSize = (int)(18f*zoom); - _counterStyle.normal.textColor = new Color(1f, 1f, 1f); + var myRect5 = + new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); - GUI.Label(myRectCounterNum, counter.ToString(), _counterStyle); + switch (segmentDict.LightRight) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect5, _lightRight3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect5, _lightRight1); + break; + } - if (myRectCounter.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 0; - hoveredSegment = true; - } + if (!myRect5.Contains(Event.current.mousePosition)) + return hoveredSegment; - // SWITCH MANUAL PEDESTRIAN LIGHT BUTTON - var manualPedestrianWidth = 36f*zoom; - var manualPedestrianHeight = 35f*zoom; + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 5; - guiColor.a = _hoveredButton[0] == segmentId && (_hoveredButton[1] == 1 || _hoveredButton[1] == 2) ? 0.92f : 0.45f; + if (!Input.GetMouseButtonDown(0) || _uiClickedSegment) + return true; - GUI.color = guiColor; + _uiClickedSegment = true; + segmentDict.ChangeLightRight(); + return true; + } - var myRect2 = new Rect(screenPos.x - manualPedestrianWidth / 2 - lightWidth + 5f*zoom, screenPos.y - manualPedestrianHeight / 2 - 9f*zoom, manualPedestrianWidth, manualPedestrianHeight); + private void SetAlpha(int segmentId, int buttonId) + { + var guiColor = GUI.color; - if (segmentDict.PedestrianEnabled) - GUI.DrawTexture(myRect2, _pedestrianMode2); - else - GUI.DrawTexture(myRect2, _pedestrianMode1); + guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == buttonId ? 0.92f : 0.45f; - if (myRect2.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 1; - hoveredSegment = true; + GUI.color = guiColor; + } - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ManualPedestrian(); - } - } + private bool ForwardArrowLightMode(int segmentId, float lightWidth, bool hasRightSegment, + Vector3 screenPos, float pedestrianWidth, float zoom, float lightHeight, ManualSegmentLight segmentDict, + bool hoveredSegment) + { + SetAlpha(segmentId, 4); - // SWITCH PEDESTRIAN LIGHT - var pedestrianWidth = 36f * zoom; - var pedestrianHeight = 61f * zoom; + var offsetLight = lightWidth; - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 2 && segmentDict.PedestrianEnabled ? 0.92f : 0.45f; + if (hasRightSegment) + offsetLight += lightWidth; - GUI.color = guiColor; + var myRect6 = + new Rect(screenPos.x - lightWidth/2 - offsetLight - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); - var myRect3 = new Rect(screenPos.x - pedestrianWidth / 2 - lightWidth + 5f*zoom, screenPos.y - pedestrianHeight / 2 + 22f*zoom, pedestrianWidth, pedestrianHeight); + switch (segmentDict.LightMain) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect6, _lightForward3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect6, _lightForward1); + break; + } - if (segmentDict.LightPedestrian == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect3, _pedestrianLight2); - else if (segmentDict.LightPedestrian == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect3, _pedestrianLight1); + if (!myRect6.Contains(Event.current.mousePosition)) + return hoveredSegment; - if (myRect3.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 2; - hoveredSegment = true; + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 4; - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; + if (!Input.GetMouseButtonDown(0) || _uiClickedSegment) + return true; - if (!segmentDict.PedestrianEnabled) - { - segmentDict.ManualPedestrian(); - } - else - { - segmentDict.ChangeLightPedestrian(); - } - } - } + _uiClickedSegment = true; + segmentDict.ChangeLightMain(); + return true; + } - if (!TrafficLightsManual.SegmentIsIncomingOneWay(segmentId, SelectedNode)) - { - var hasLeftSegment = TrafficPriority.HasLeftSegment(segmentId, SelectedNode) && TrafficPriority.HasLeftLane(SelectedNode, segmentId); - var hasForwardSegment = TrafficPriority.HasForwardSegment(segmentId, SelectedNode) && TrafficPriority.HasForwardLane(SelectedNode, segmentId); - var hasRightSegment = TrafficPriority.HasRightSegment(segmentId, SelectedNode) && TrafficPriority.HasRightLane(SelectedNode, segmentId); + private bool LeftArrowLightMode(int segmentId, float lightWidth, bool hasRightSegment, + bool hasForwardSegment, Vector3 screenPos, float pedestrianWidth, float zoom, float lightHeight, + ManualSegmentLight segmentDict, bool hoveredSegment) + { + SetAlpha(segmentId, 3); - if (segmentDict.CurrentMode == ManualSegmentLight.Mode.Simple) - { - // no arrow light - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 3 ? 0.92f : 0.45f; + var offsetLight = lightWidth; - GUI.color = guiColor; + if (hasRightSegment) + offsetLight += lightWidth; - var myRect4 = - new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, - screenPos.y - lightHeight/2, lightWidth, lightHeight); + if (hasForwardSegment) + offsetLight += lightWidth; - if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect4, _lightSimple3); - else if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect4, _lightSimple1); + var myRect4 = + new Rect(screenPos.x - lightWidth/2 - offsetLight - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); - if (myRect4.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 3; - hoveredSegment = true; + switch (segmentDict.LightLeft) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect4, _lightLeft3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect4, _lightLeft1); + break; + } - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ChangeLightMain(); - } - } - } - else if (segmentDict.CurrentMode == ManualSegmentLight.Mode.LeftForwardR) - { - if (hasLeftSegment) - { - // left arrow light - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 3 ? 0.92f : 0.45f; + if (!myRect4.Contains(Event.current.mousePosition)) + return hoveredSegment; + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 3; - GUI.color = guiColor; + if (!Input.GetMouseButtonDown(0) || _uiClickedSegment) + return true; - Rect myRect4 = - new Rect(screenPos.x - lightWidth/2 - lightWidth*2 - pedestrianWidth + 5f*zoom, - screenPos.y - lightHeight/2, lightWidth, lightHeight); + _uiClickedSegment = true; + segmentDict.ChangeLightLeft(); + + if (!hasForwardSegment) + { + segmentDict.ChangeLightMain(); + } + return true; + } + + private bool RightForwardLSegmentLightMode(int segmentId, Vector3 screenPos, float lightWidth, float pedestrianWidth, + float zoom, float lightHeight, bool hasForwardSegment, bool hasLeftSegment, ManualSegmentLight segmentDict, + bool hasRightSegment, bool hoveredSegment) + { + SetAlpha(segmentId, 3); + + var myRect4 = new Rect(screenPos.x - lightWidth/2 - lightWidth*2 - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); + + if (hasForwardSegment && hasLeftSegment) + { + switch (segmentDict.LightLeft) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect4, _lightForwardLeft3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect4, _lightForwardLeft1); + break; + } + } + else if (!hasLeftSegment) + { + if (!hasRightSegment) + { + myRect4 = new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); + } + + switch (segmentDict.LightMain) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect4, _lightForward3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect4, _lightForward1); + break; + } + } + else + { + if (!hasRightSegment) + { + myRect4 = new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); + } + + switch (segmentDict.LightMain) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect4, _lightLeft3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect4, _lightLeft1); + break; + } + } + + + if (myRect4.Contains(Event.current.mousePosition)) + { + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 3; + hoveredSegment = true; + + if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) + { + _uiClickedSegment = true; + segmentDict.ChangeLightMain(); + } + } + + var guiColor = GUI.color; + // right arrow light + if (hasRightSegment) + guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 4 ? 0.92f : 0.45f; + + GUI.color = guiColor; + + var myRect5 = + new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); - if (segmentDict.LightLeft == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect4, _lightLeft3); - else if (segmentDict.LightLeft == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect4, _lightLeft1); + switch (segmentDict.LightRight) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect5, _lightRight3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect5, _lightRight1); + break; + } - if (myRect4.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 3; - hoveredSegment = true; - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ChangeLightLeft(); - } - } - } + if (!myRect5.Contains(Event.current.mousePosition)) + return hoveredSegment; - // forward-right arrow light - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 4 ? 0.92f : 0.45f; + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 4; - GUI.color = guiColor; + if (!Input.GetMouseButtonDown(0) || _uiClickedSegment) + return true; + _uiClickedSegment = true; + segmentDict.ChangeLightRight(); + return true; + } - Rect myRect5 = - new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, - screenPos.y - lightHeight/2, lightWidth, lightHeight); + private bool LeftForwardRManualSegmentLightMode(bool hasLeftSegment, int segmentId, Vector3 screenPos, float lightWidth, + float pedestrianWidth, float zoom, float lightHeight, ManualSegmentLight segmentDict, bool hoveredSegment, + bool hasForwardSegment, bool hasRightSegment) + { + if (hasLeftSegment) + { + // left arrow light + SetAlpha(segmentId, 3); - if (hasForwardSegment && hasRightSegment) - { - if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect5, _lightForwardRight3); - else if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect5, _lightForwardRight1); - } - else if (!hasRightSegment) - { - if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect5, _lightForward3); - else if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect5, _lightForward1); - } - else - { - if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect5, _lightRight3); - else if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect5, _lightRight1); - } + var myRect4 = + new Rect(screenPos.x - lightWidth/2 - lightWidth*2 - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); - if (myRect5.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 4; - hoveredSegment = true; + switch (segmentDict.LightLeft) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect4, _lightLeft3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect4, _lightLeft1); + break; + } - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ChangeLightMain(); - } - } - } - else if (segmentDict.CurrentMode == ManualSegmentLight.Mode.RightForwardL) - { - // forward-left light - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 3 ? 0.92f : 0.45f; + if (myRect4.Contains(Event.current.mousePosition)) + { + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 3; + hoveredSegment = true; - GUI.color = guiColor; + if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) + { + _uiClickedSegment = true; + segmentDict.ChangeLightLeft(); + } + } + } - Rect myRect4 = new Rect(screenPos.x - lightWidth/2 - lightWidth*2 - pedestrianWidth + 5f*zoom, - screenPos.y - lightHeight/2, lightWidth, lightHeight); + // forward-right arrow light + SetAlpha(segmentId, 4); - if (hasForwardSegment && hasLeftSegment) - { - if (segmentDict.LightLeft == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect4, _lightForwardLeft3); - else if (segmentDict.LightLeft == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect4, _lightForwardLeft1); - } - else if (!hasLeftSegment) - { - if (!hasRightSegment) - { - myRect4 = new Rect(screenPos.x - lightWidth / 2 - lightWidth - pedestrianWidth + 5f * zoom, - screenPos.y - lightHeight / 2, lightWidth, lightHeight); - } + var myRect5 = + new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); - if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect4, _lightForward3); - else if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect4, _lightForward1); - } - else - { - if (!hasRightSegment) - { - myRect4 = new Rect(screenPos.x - lightWidth / 2 - lightWidth - pedestrianWidth + 5f * zoom, - screenPos.y - lightHeight / 2, lightWidth, lightHeight); - } + if (hasForwardSegment && hasRightSegment) + { + switch (segmentDict.LightMain) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect5, _lightForwardRight3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect5, _lightForwardRight1); + break; + } + } + else if (!hasRightSegment) + { + switch (segmentDict.LightMain) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect5, _lightForward3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect5, _lightForward1); + break; + } + } + else + { + switch (segmentDict.LightMain) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect5, _lightRight3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect5, _lightRight1); + break; + } + } - if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect4, _lightLeft3); - else if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect4, _lightLeft1); - } + if (!myRect5.Contains(Event.current.mousePosition)) + return hoveredSegment; + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 4; + if (!Input.GetMouseButtonDown(0) || _uiClickedSegment) + return true; + _uiClickedSegment = true; + segmentDict.ChangeLightMain(); + return true; + } - if (myRect4.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 3; - hoveredSegment = true; + private bool SimpleManualSegmentLightMode(int segmentId, Vector3 screenPos, float lightWidth, float pedestrianWidth, + float zoom, float lightHeight, ManualSegmentLight segmentDict, bool hoveredSegment) + { + SetAlpha(segmentId, 3); - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ChangeLightMain(); - } - } + var myRect4 = + new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, + screenPos.y - lightHeight/2, lightWidth, lightHeight); - // right arrow light - if (hasRightSegment) - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 4 ? 0.92f : 0.45f; + switch (segmentDict.LightMain) + { + case RoadBaseAI.TrafficLightState.Green: + GUI.DrawTexture(myRect4, _lightSimple3); + break; + case RoadBaseAI.TrafficLightState.Red: + GUI.DrawTexture(myRect4, _lightSimple1); + break; + } - GUI.color = guiColor; + if (!myRect4.Contains(Event.current.mousePosition)) + return hoveredSegment; + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 3; - Rect myRect5 = - new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, - screenPos.y - lightHeight/2, lightWidth, lightHeight); + if (!Input.GetMouseButtonDown(0) || _uiClickedSegment) + return true; - if (segmentDict.LightRight == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect5, _lightRight3); - else if (segmentDict.LightRight == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect5, _lightRight1); + _uiClickedSegment = true; + segmentDict.ChangeLightMain(); + return true; + } + private bool IsPedestrianLightHovered(Rect myRect3, int segmentId, bool hoveredSegment, ManualSegmentLight segmentDict) + { + if (!myRect3.Contains(Event.current.mousePosition)) + return hoveredSegment; - if (myRect5.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 4; - hoveredSegment = true; + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 2; - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ChangeLightRight(); - } - } - } - else // all - { - // left arrow light - if (hasLeftSegment) - { - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 3 ? 0.92f : 0.45f; + if (!Input.GetMouseButtonDown(0) || _uiClickedSegment) + return true; + _uiClickedSegment = true; - GUI.color = guiColor; + if (!segmentDict.PedestrianEnabled) + { + segmentDict.ManualPedestrian(); + } + else + { + segmentDict.ChangeLightPedestrian(); + } + return true; + } - var offsetLight = lightWidth; + private bool RenderManualPedestrianLightSwitch(float zoom, int segmentId, Vector3 screenPos, float lightWidth, + ManualSegmentLight segmentDict, bool hoveredSegment) + { + var guiColor = GUI.color; + var manualPedestrianWidth = 36f*zoom; + var manualPedestrianHeight = 35f*zoom; - if (hasRightSegment) - offsetLight += lightWidth; + guiColor.a = _hoveredButton[0] == segmentId && (_hoveredButton[1] == 1 || _hoveredButton[1] == 2) ? 0.92f : 0.45f; - if (hasForwardSegment) - offsetLight += lightWidth; + GUI.color = guiColor; - Rect myRect4 = - new Rect(screenPos.x - lightWidth / 2 - offsetLight - pedestrianWidth + 5f * zoom, - screenPos.y - lightHeight/2, lightWidth, lightHeight); + var myRect2 = new Rect(screenPos.x - manualPedestrianWidth/2 - lightWidth + 5f*zoom, + screenPos.y - manualPedestrianHeight/2 - 9f*zoom, manualPedestrianWidth, manualPedestrianHeight); - if (segmentDict.LightLeft == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect4, _lightLeft3); - else if (segmentDict.LightLeft == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect4, _lightLeft1); + GUI.DrawTexture(myRect2, segmentDict.PedestrianEnabled ? _pedestrianMode2 : _pedestrianMode1); - if (myRect4.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 3; - hoveredSegment = true; + if (!myRect2.Contains(Event.current.mousePosition)) + return hoveredSegment; - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ChangeLightLeft(); + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 1; - if (!hasForwardSegment) - { - segmentDict.ChangeLightMain(); - } - } - } - } + if (!Input.GetMouseButtonDown(0) || _uiClickedSegment) + return true; - // forward arrow light - if (hasForwardSegment) - { - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 4 ? 0.92f : 0.45f; + _uiClickedSegment = true; + segmentDict.ManualPedestrian(); + return true; + } - GUI.color = guiColor; + private bool RenderCounter(int segmentId, Vector3 screenPos, float modeWidth, float modeHeight, float zoom, + ManualSegmentLight segmentDict, bool hoveredSegment) + { + SetAlpha(segmentId, 0); - var offsetLight = lightWidth; + var myRectCounter = new Rect(screenPos.x - modeWidth/2, screenPos.y - modeHeight/2 - 6f*zoom, modeWidth, modeHeight); - if (hasRightSegment) - offsetLight += lightWidth; + GUI.DrawTexture(myRectCounter, _lightCounter); - Rect myRect6 = - new Rect(screenPos.x - lightWidth/2 - offsetLight - pedestrianWidth + 5f*zoom, - screenPos.y - lightHeight/2, lightWidth, lightHeight); + var counterSize = 20f*zoom; - if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect6, _lightForward3); - else if (segmentDict.LightMain == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect6, _lightForward1); + var counter = segmentDict.LastChange; - if (myRect6.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 4; - hoveredSegment = true; + var myRectCounterNum = new Rect(screenPos.x - counterSize + 15f*zoom + (counter >= 10 ? -5*zoom : 0f), + screenPos.y - counterSize + 11f*zoom, counterSize, counterSize); - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ChangeLightMain(); - } - } - } + _counterStyle.fontSize = (int) (18f*zoom); + _counterStyle.normal.textColor = new Color(1f, 1f, 1f); - // right arrow light - if (hasRightSegment) - { - guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 5 ? 0.92f : 0.45f; + GUI.Label(myRectCounterNum, counter.ToString(), _counterStyle); - GUI.color = guiColor; + if (!myRectCounter.Contains(Event.current.mousePosition)) + return hoveredSegment; + _hoveredButton[0] = segmentId; + _hoveredButton[1] = 0; + return true; + } - Rect myRect5 = - new Rect(screenPos.x - lightWidth/2 - lightWidth - pedestrianWidth + 5f*zoom, - screenPos.y - lightHeight/2, lightWidth, lightHeight); + private bool GetHoveredSegment(Rect myRect1, int segmentId, bool hoveredSegment, ManualSegmentLight segmentDict) + { + if (!myRect1.Contains(Event.current.mousePosition)) + return hoveredSegment; + + Debug.Log("mouse in myRect1"); + _hoveredButton[0] = segmentId; + _hoveredButton[1] = -1; + + if (!Input.GetMouseButtonDown(0) || _uiClickedSegment) + return true; + _uiClickedSegment = true; + segmentDict.ChangeMode(); + return true; + } - if (segmentDict.LightRight == RoadBaseAI.TrafficLightState.Green) - GUI.DrawTexture(myRect5, _lightRight3); - else if (segmentDict.LightRight == RoadBaseAI.TrafficLightState.Red) - GUI.DrawTexture(myRect5, _lightRight1); + private static Vector3 CalculateNodePositionForSegment(NetNode node, NetSegment segment) + { + var position = node.m_position; - if (myRect5.Contains(Event.current.mousePosition)) - { - _hoveredButton[0] = segmentId; - _hoveredButton[1] = 5; - hoveredSegment = true; + const float offset = 25f; - if (Input.GetMouseButtonDown(0) && !_uiClickedSegment) - { - _uiClickedSegment = true; - segmentDict.ChangeLightRight(); - } - } - } - } - } - } - } + if (segment.m_startNode == SelectedNode) + { + position.x += segment.m_startDirection.x*offset; + position.y += segment.m_startDirection.y*offset; + position.z += segment.m_startDirection.z*offset; } - - if (!hoveredSegment) + else { - _hoveredButton[0] = 0; - _hoveredButton[1] = 0; + position.x += segment.m_endDirection.x*offset; + position.y += segment.m_endDirection.y*offset; + position.z += segment.m_endDirection.z*offset; } + return position; } protected void _guiManualTrafficLightsCrosswalk(NetNode node) @@ -1500,14 +1604,7 @@ protected void _guiTimedTrafficLights() { GUILayout.Window(253, _windowRect, _guiTimedControlPanel, "Timed traffic lights manager"); - if (_windowRect.Contains(Event.current.mousePosition)) - { - _cursorInSecondaryPanel = true; - } - else - { - _cursorInSecondaryPanel = false; - } + IsCursorInSecondaryPanel(); var hoveredSegment = false; @@ -2359,6 +2456,18 @@ protected void _guiTimedTrafficLights() } } + private void IsCursorInSecondaryPanel() + { + if (_windowRect.Contains(Event.current.mousePosition)) + { + _cursorInSecondaryPanel = true; + } + else + { + _cursorInSecondaryPanel = false; + } + } + protected void _guiLaneChange() { if (SelectedNode != 0 && SelectedSegment != 0) @@ -2799,16 +2908,16 @@ protected void _guiLaneRestrictionsOneWayWindow(int num) if (_setSpeed == (int)laneList[i][2]) { - SliderValues[(int) laneList[i][2]] = - GUILayout.HorizontalSlider(SliderValues[(int) laneList[i][2]], + _sliderValues[(int) laneList[i][2]] = + GUILayout.HorizontalSlider(_sliderValues[(int) laneList[i][2]], 20f, 150f, GUILayout.Height(20)); - if (GUILayout.Button("Set Speed " + (int)SliderValues[(int) laneList[i][2]])) + if (GUILayout.Button("Set Speed " + (int)_sliderValues[(int) laneList[i][2]])) { foreach (var restrictionSegment in SelectedSegmentIndexes.Select(TrafficRoadRestrictions.GetSegment)) { restrictionSegment.SpeedLimits[(int) laneList[i][2]] = - SliderValues[(int) laneList[i][2]]/ + _sliderValues[(int) laneList[i][2]]/ 50f; } @@ -2819,7 +2928,7 @@ protected void _guiLaneRestrictionsOneWayWindow(int num) { if (GUILayout.Button("Max speed " + (int)(resSpeed > 0.1f ? resSpeed*50f : info2.m_lanes[(int) laneList[i][2]].m_speedLimit*50f))) { - SliderValues[(int) laneList[i][2]] = info2.m_lanes[(int) laneList[i][2]].m_speedLimit*50f; + _sliderValues[(int) laneList[i][2]] = info2.m_lanes[(int) laneList[i][2]].m_speedLimit*50f; _setSpeed = (int) laneList[i][2]; } } @@ -3199,7 +3308,7 @@ protected void _guiTimedControlPanel(int num) { _timedPanelAdd = false; _timedEditStep = i; - StepValue = timedNodeMain.GetStep(i).NumSteps; + _stepValue = timedNodeMain.GetStep(i).NumSteps; foreach (var timedNode2 in SelectedNodeIndexes.Select(TrafficLightsTimed.GetTimedLight)) { @@ -3223,13 +3332,13 @@ protected void _guiTimedControlPanel(int num) } else { - GUILayout.Label("Time: " + (int)StepValue, GUILayout.Width(60)); - StepValue = GUILayout.HorizontalSlider(StepValue, 1f, 120f, GUILayout.Height(20)); + GUILayout.Label("Time: " + (int)_stepValue, GUILayout.Width(60)); + _stepValue = GUILayout.HorizontalSlider(_stepValue, 1f, 120f, GUILayout.Height(20)); if (GUILayout.Button("Save", GUILayout.Width(45))) { foreach (var timeNode in SelectedNodeIndexes.Select(TrafficLightsTimed.GetTimedLight)) { - timeNode.GetStep(_timedEditStep).NumSteps = (int)StepValue; + timeNode.GetStep(_timedEditStep).NumSteps = (int)_stepValue; timeNode.GetStep(_timedEditStep).UpdateLights(); } @@ -3246,13 +3355,13 @@ protected void _guiTimedControlPanel(int num) { if (_timedPanelAdd) { - GUILayout.Label("Time: " + (int) StepValue, GUILayout.Width(60)); - StepValue = GUILayout.HorizontalSlider(StepValue, 1f, 120f, GUILayout.Height(20)); + GUILayout.Label("Time: " + (int) _stepValue, GUILayout.Width(60)); + _stepValue = GUILayout.HorizontalSlider(_stepValue, 1f, 120f, GUILayout.Height(20)); if (GUILayout.Button("Add", GUILayout.Width(45))) { foreach (var timedNode in SelectedNodeIndexes.Select(TrafficLightsTimed.GetTimedLight)) { - timedNode.AddStep((int) StepValue); + timedNode.AddStep((int) _stepValue); } _timedPanelAdd = false; } @@ -3519,7 +3628,7 @@ protected void _guiPrioritySigns() } } - protected void _switchTrafficLights() + private void _switchTrafficLights() { var node = GetNetNode(_hoveredNetNodeIdx); diff --git a/TLM/TLM/UI/UITrafficManager.cs b/TLM/TLM/UI/UITrafficManager.cs index 9f0609c6..62c4b3bb 100644 --- a/TLM/TLM/UI/UITrafficManager.cs +++ b/TLM/TLM/UI/UITrafficManager.cs @@ -29,7 +29,7 @@ public static UIState UIState //buttonLaneRestrictions.focusedBgSprite = "ButtonMenu"; _buttonCrosswalk.focusedBgSprite = "ButtonMenu"; _buttonClearTraffic.focusedBgSprite = "ButtonMenu"; - if (!LoadingExtension.IsPathManagerCompatibile) + if (LoadingExtension.IsPathManagerCompatibile) { _buttonLaneChange.focusedBgSprite = "ButtonMenu"; _buttonToggleDespawn.focusedBgSprite = "ButtonMenu"; @@ -62,14 +62,14 @@ public override void Start() backgroundSprite = "GenericPanel"; color = new Color32(75, 75, 135, 255); width = 250; - height = !LoadingExtension.IsPathManagerCompatibile ? 350 : 270; + height = LoadingExtension.IsPathManagerCompatibile ? 350 : 270; relativePosition = new Vector3(10.48f, 80f); UILabel title = AddUIComponent(); title.text = "Traffic Manager"; title.relativePosition = new Vector3(65.0f, 5.0f); - if (!LoadingExtension.IsPathManagerCompatibile) + if (LoadingExtension.IsPathManagerCompatibile) { _buttonSwitchTraffic = _createButton("Switch traffic lights", new Vector3(35f, 30f), clickSwitchTraffic); _buttonPrioritySigns = _createButton("Add priority signs", new Vector3(35f, 70f), clickAddPrioritySigns); @@ -213,7 +213,7 @@ private static void ClickToggleDespawn(UIComponent component, UIMouseEventParame { LoadingExtension.Instance.DespawnEnabled = !LoadingExtension.Instance.DespawnEnabled; - if (!LoadingExtension.IsPathManagerCompatibile) + if (LoadingExtension.IsPathManagerCompatibile) { _buttonToggleDespawn.text = LoadingExtension.Instance.DespawnEnabled ? "Disable despawning" @@ -227,7 +227,7 @@ private void clickChangeLanes(UIComponent component, UIMouseEventParameter event { _uiState = UIState.LaneChange; - if (!LoadingExtension.IsPathManagerCompatibile) + if (LoadingExtension.IsPathManagerCompatibile) { _buttonLaneChange.focusedBgSprite = "ButtonMenuFocused"; } @@ -238,7 +238,7 @@ private void clickChangeLanes(UIComponent component, UIMouseEventParameter event { _uiState = UIState.None; - if (!LoadingExtension.IsPathManagerCompatibile) + if (LoadingExtension.IsPathManagerCompatibile) { _buttonLaneChange.focusedBgSprite = "ButtonMenu"; }