public void Transfer(uint laneId) { ushort segmentId = laneId.ToLane().m_segment; var laneInfo = segmentId.ToSegment().GetLaneInfo(LaneIndex); SpeedLimitManager.Instance.SetLaneSpeedLimit( segmentId: segmentId, laneIndex: this.LaneIndex, laneInfo: laneInfo, laneId: laneId, action: SetSpeedLimitAction.FromNullableFloat(this.speedLimit_)); }
/// <summary> /// Creates a button with speed value on it, and label under it, showing opposite units. /// Also can be zero (reset to default) and 1000 km/h (unlimited speed button). /// </summary> /// <param name="builder">UI builder.</param> /// <param name="actionOnClick">What happens if clicked.</param> /// <param name="parentTool">Parent speedlimits tool.</param> /// <param name="buttonPanel">Panel where buttons are added to.</param> /// <param name="speedInteger">Integer value of the speed in the selected units.</param> /// <param name="speedValue">Speed value of the button we're creating.</param> /// <returns>The new button.</returns> private SpeedLimitPaletteButton CreatePaletteButton(UBuilder builder, SetSpeedLimitAction actionOnClick, SpeedLimitsTool parentTool, UPanel buttonPanel, int speedInteger, SpeedValue speedValue) { // Helper function to choose text for the button string GetSpeedButtonText() { if (speedInteger == 0) { return("✖"); // Unicode symbol U+2716 Heavy Multiplication X } if (speedValue.GameUnits >= SpeedValue.UNLIMITED) { return("⊘"); // Unicode symbol U+2298 Circled Division Slash } return(speedInteger.ToString()); } var button = builder.Button <SpeedLimitPaletteButton>(parent: buttonPanel); button.text = GetSpeedButtonText(); button.textScale = UIScaler.UIScale; button.textHorizontalAlignment = UIHorizontalAlignment.Center; button.normalBgSprite = button.hoveredBgSprite = "GenericPanel"; button.color = new Color32(128, 128, 128, 240); // button must know what to do with its speed value button.AssignedAction = actionOnClick; // The click events will be routed via the parent tool OnPaletteButtonClicked button.ParentTool = parentTool; button.SetStacking(UStackMode.NewRowBelow); // Width will be overwritten in SpeedLimitPaletteButton.UpdateSpeedLimitButton button.SetFixedSize( new Vector2( SpeedLimitPaletteButton.DEFAULT_WIDTH, SpeedLimitPaletteButton.DEFAULT_HEIGHT)); return(button); }
SetupControls_SpeedPalette_Button(UBuilder builder, UIComponent parent, bool showMph, SetSpeedLimitAction actionOnClick, SpeedLimitsTool parentTool) { SpeedValue speedValue = actionOnClick.Type == SetSpeedLimitAction.ActionType.ResetToDefault ? default : actionOnClick.GuardedValue.Override; int speedInteger = showMph ? speedValue.ToMphRounded(RoadSignThemes.MPH_STEP).Mph : speedValue.ToKmphRounded(RoadSignThemes.KMPH_STEP).Kmph; //-------------------------------- // Create vertical combo: // |[ 100 ]| // | "65 mph" | //-------------------------------- // Create a small panel which stacks together with other button panels horizontally var buttonPanel = builder.Panel_(parent: parent); buttonPanel.name = $"{GAMEOBJECT_NAME}_Button_{speedInteger}"; buttonPanel.ResizeFunction( resizeFn: (UResizer r) => { r.Stack(UStackMode.ToTheRight, spacing: 2f); r.FitToChildren(); }); SpeedLimitPaletteButton button = this.CreatePaletteButton( builder, actionOnClick, parentTool, buttonPanel, speedInteger, speedValue); this.CreatePaletteButtonHintLabel(builder, showMph, speedValue, button, buttonPanel); return(button); }
private static void FixSegmentRoundabout(ushort segmentId, ushort nextSegmentId) { if (OptionsMassEditTab.RoundAboutQuickFix_ParkingBanMainR) { ParkingRestrictionsManager.Instance.SetParkingAllowed(segmentId, false); } if (OptionsMassEditTab.RoundAboutQuickFix_RealisticSpeedLimits) { SpeedValue? targetSpeed = CalculatePreferedSpeed(segmentId); float defaultSpeed = SpeedLimitManager.Instance.CalculateCustomNetinfoSpeedLimit(segmentId.ToSegment().Info); if (targetSpeed != null && targetSpeed.Value.GetKmph() < defaultSpeed) { SpeedLimitManager.Instance.SetSegmentSpeedLimit( segmentId: segmentId, finalDir: NetInfo.Direction.Forward, action: SetSpeedLimitAction.SetOverride(targetSpeed.Value)); SpeedLimitManager.Instance.SetSegmentSpeedLimit( segmentId: segmentId, finalDir: NetInfo.Direction.Backward, action: SetSpeedLimitAction.SetOverride(targetSpeed.Value)); } } ushort nodeId = ExtSegmentManager.Instance.GetHeadNode(segmentId); if (OptionsMassEditTab.RoundAboutQuickFix_StayInLaneMainR && !HasJunctionFlag(nodeId)) { StayInLane(nodeId, StayInLaneMode.Both); } // allocation of dedicated exit lanes is supported only when the roundabout is round // in which case the next segment should be straigh ahead. bool isStraight = segEndMan.GetDirection(segmentId, nextSegmentId, nodeId) == ArrowDirection.Forward; if (OptionsMassEditTab.RoundAboutQuickFix_DedicatedExitLanes && HasJunctionFlag(nodeId) && SeparateTurningLanesUtil.CanChangeLanes( segmentId, nodeId) == SetLaneArrow_Result.Success && isStraight) { bool startNode = (bool)ExtSegmentManager.Instance.IsStartNode(segmentId, nodeId); ExtSegmentManager extSegmentManager = ExtSegmentManager.Instance; IList<LanePos> laneList = extSegmentManager.GetSortedLanes( segmentId, ref segmentId.ToSegment(), startNode, LaneArrowManager.LANE_TYPES, LaneArrowManager.VEHICLE_TYPES, true); int nSrc = laneList.Count; // check for exits. segEndMan.CalculateOutgoingLeftStraightRightSegments( ref GetSegEnd(segmentId, nodeId), ref nodeId.ToNode(), out bool bLeft, out bool bForward, out bool bRight); //Set one dedicated exit lane per exit - if there are enough lanes that is. switch (nSrc) { case 0: Debug.LogAssertion("The road is the wrong way around."); break; case 1: break; // not enough lanes Use default settings. case 2: if (bRight && bLeft) { // not enough lanes, use default settings } else if (bRight) { LaneArrowManager.Instance.SetLaneArrows(laneList[0].laneId, LaneArrows.Forward); LaneArrowManager.Instance.SetLaneArrows(laneList[1].laneId, LaneArrows.Right); } else if (bLeft) { LaneArrowManager.Instance.SetLaneArrows(laneList[0].laneId, LaneArrows.Left); LaneArrowManager.Instance.SetLaneArrows(laneList[1].laneId, LaneArrows.Forward); } else { LaneArrowManager.Instance.SetLaneArrows(laneList[0].laneId, LaneArrows.Forward); LaneArrowManager.Instance.SetLaneArrows(laneList[1].laneId, LaneArrows.Forward); } break; default: for (int i = 0; i < laneList.Count; ++i) { LaneArrowManager.Instance.SetLaneArrows(laneList[i].laneId, LaneArrows.Forward); } if (bRight) { LaneArrowManager.Instance.SetLaneArrows(laneList[nSrc - 1].laneId, LaneArrows.Right); } if (bLeft) { LaneArrowManager.Instance.SetLaneArrows(laneList[0].laneId, LaneArrows.Left); } break; } // end switch } // end if }