public override void OnPrimaryClickOverlay() { if ((HoveredNodeId == 0) || (HoveredSegmentId == 0)) { return; } NetNode.Flags netFlags = Singleton <NetManager> .instance.m_nodes.m_buffer[HoveredNodeId].m_flags; if ((netFlags & NetNode.Flags.Junction) == NetNode.Flags.None) { return; } NetSegment[] segmentsBuffer = Singleton <NetManager> .instance.m_segments.m_buffer; if ((segmentsBuffer[HoveredSegmentId].m_startNode != HoveredNodeId) && (segmentsBuffer[HoveredSegmentId].m_endNode != HoveredNodeId)) { return; } bool ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); bool altDown = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); SetLaneArrowError res = SetLaneArrowError.Success; if (altDown) { LaneArrowManager.SeparateTurningLanes.SeparateSegmentLanes(HoveredSegmentId, HoveredNodeId, out res); } else if (ctrlDown) { LaneArrowManager.SeparateTurningLanes.SeparateNode(HoveredNodeId, out res); } else if (HasHoverLaneArrows()) { SelectedSegmentId = HoveredSegmentId; SelectedNodeId = HoveredNodeId; } switch (res) { case SetLaneArrowError.HighwayArrows: { MainTool.ShowError( Translation.LaneRouting.Get("Dialog.Text:Disabled due to highway rules")); break; } case SetLaneArrowError.LaneConnection: { MainTool.ShowError( Translation.LaneRouting.Get("Dialog.Text:Disabled due to manual connection")); break; } } }
public bool ToggleLaneArrows(uint laneId, bool startNode, LaneArrows flags, out SetLaneArrowError res) { if (Flags.ToggleLaneArrowFlags(laneId, startNode, flags, out res)) { OnLaneChange(laneId); return(true); } return(false); }
public static bool ToggleLaneArrowFlags(uint laneId, bool startNode, LaneArrows flags, out SetLaneArrowError res) { if (!CanHaveLaneArrows(laneId)) { RemoveLaneArrowFlags(laneId); res = SetLaneArrowError.Invalid; return(false); } if (highwayLaneArrowFlags[laneId] != null) { res = SetLaneArrowError.HighwayArrows; return(false); // disallow custom lane arrows in highway rule mode } if (LaneConnectionManager.Instance.HasConnections(laneId, startNode)) { // TODO refactor res = SetLaneArrowError.LaneConnection; return(false); // custom lane connection present } LaneArrows?arrows = laneArrowFlags[laneId]; if (arrows == null) { // read currently defined arrows uint laneFlags = Singleton <NetManager> .instance.m_lanes.m_buffer[laneId].m_flags; laneFlags &= lfr; // filter arrows arrows = (LaneArrows)laneFlags; } arrows ^= flags; laneArrowFlags[laneId] = arrows; if (ApplyLaneArrowFlags(laneId, false)) { res = SetLaneArrowError.Success; return(true); } res = SetLaneArrowError.Invalid; return(false); }
public override void OnPrimaryClickOverlay() { if ((HoveredNodeId == 0) || (HoveredSegmentId == 0)) { return; } NetNode.Flags netFlags = Singleton <NetManager> .instance.m_nodes.m_buffer[HoveredNodeId].m_flags; if ((netFlags & NetNode.Flags.Junction) == NetNode.Flags.None) { return; } NetSegment[] segmentsBuffer = Singleton <NetManager> .instance.m_segments.m_buffer; if ((segmentsBuffer[HoveredSegmentId].m_startNode != HoveredNodeId) && (segmentsBuffer[HoveredSegmentId].m_endNode != HoveredNodeId)) { return; } bool ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); bool altDown = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); SetLaneArrowError res = SetLaneArrowError.Success; if (altDown) { LaneArrowManager.SeparateTurningLanes.SeparateSegmentLanes(HoveredSegmentId, HoveredNodeId, out res); HandleResult(res); } else if (ctrlDown) { LaneArrowManager.SeparateTurningLanes.SeparateNode(HoveredNodeId, out res); HandleResult(res); } else if (HasHoverLaneArrows()) { SelectedSegmentId = HoveredSegmentId; SelectedNodeId = HoveredNodeId; } }
private void HandleResult(SetLaneArrowError result) { switch (result) { case SetLaneArrowError.HighwayArrows: { MainTool.Guide.Activate("LaneArrowTool_Disabled due to highway rules"); break; } case SetLaneArrowError.LaneConnection: { MainTool.Guide.Activate("LaneArrowTool_Disabled due to lane connections"); break; } case SetLaneArrowError.Success: MainTool.Guide.Deactivate("LaneArrowTool_Disabled due to highway rules"); MainTool.Guide.Deactivate("LaneArrowTool_Disabled due to lane connections"); break; } }
private void GuiLaneChangeWindow(int num) { NetSegment[] segmentsBuffer = Singleton <NetManager> .instance.m_segments.m_buffer; IList <LanePos> laneList = Constants.ServiceFactory.NetService.GetSortedLanes( SelectedSegmentId, ref segmentsBuffer[SelectedSegmentId], segmentsBuffer[SelectedSegmentId].m_startNode == SelectedNodeId, LaneArrowManager.LANE_TYPES, LaneArrowManager.VEHICLE_TYPES, true); bool?startNode = Constants.ServiceFactory.NetService.IsStartNode(SelectedSegmentId, SelectedNodeId); if (startNode == null) { Log.Error( $"LaneArrowTool._guiLaneChangeWindow: Segment {SelectedSegmentId} " + $"is not connected to node {SelectedNodeId}"); return; } GUILayout.BeginHorizontal(); for (var i = 0; i < laneList.Count; i++) { var flags = (NetLane.Flags)Singleton <NetManager> .instance.m_lanes.m_buffer[laneList[i].laneId].m_flags; var style1 = new GUIStyle("button"); var style2 = new GUIStyle("button") { normal = { textColor = new Color32(255, 0, 0, 255) }, hover = { textColor = new Color32(255, 0, 0, 255) }, focused = { textColor = new Color32(255, 0, 0, 255) } }; var laneStyle = new GUIStyle { contentOffset = new Vector2(12f, 0f) }; var laneTitleStyle = new GUIStyle { contentOffset = new Vector2(36f, 2f), normal = { textColor = new Color(1f, 1f, 1f) } }; GUILayout.BeginVertical(laneStyle); GUILayout.Label(Translation.GetString("Lane") + " " + (i + 1), laneTitleStyle); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); if (!Flags.ApplyLaneArrowFlags(laneList[i].laneId)) { Flags.RemoveLaneArrowFlags(laneList[i].laneId); } SetLaneArrowError res = SetLaneArrowError.Invalid; bool buttonClicked = false; if (GUILayout.Button( "←", ((flags & NetLane.Flags.Left) == NetLane.Flags.Left ? style1 : style2), GUILayout.Width(35), GUILayout.Height(25))) { buttonClicked = true; LaneArrowManager.Instance.ToggleLaneArrows( laneList[i].laneId, (bool)startNode, LaneArrows.Left, out res); } if (GUILayout.Button( "↑", ((flags & NetLane.Flags.Forward) == NetLane.Flags.Forward ? style1 : style2), GUILayout.Width(25), GUILayout.Height(35))) { buttonClicked = true; LaneArrowManager.Instance.ToggleLaneArrows( laneList[i].laneId, (bool)startNode, LaneArrows.Forward, out res); } if (GUILayout.Button( "→", ((flags & NetLane.Flags.Right) == NetLane.Flags.Right ? style1 : style2), GUILayout.Width(35), GUILayout.Height(25))) { buttonClicked = true; LaneArrowManager.Instance.ToggleLaneArrows( laneList[i].laneId, (bool)startNode, LaneArrows.Right, out res); } if (buttonClicked) { switch (res) { case SetLaneArrowError.HighwayArrows: { MainTool.ShowTooltip( Translation.GetString("Lane_Arrow_Changer_Disabled_Highway")); break; } case SetLaneArrowError.LaneConnection: { MainTool.ShowTooltip( Translation.GetString("Lane_Arrow_Changer_Disabled_Connection")); break; } } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndVertical(); } GUILayout.EndHorizontal(); }