diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index b44926eaf..587f610af 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -12,6 +12,9 @@ namespace TrafficManager.Manager.Impl { using TrafficManager.State.ConfigData; using TrafficManager.State; using TrafficManager.Traffic; + using static TrafficManager.Util.Shortcuts; + using static CSUtil.Commons.TernaryBoolUtil; + using TrafficManager.Util; public class JunctionRestrictionsManager : AbstractGeometryObservingManager, @@ -743,6 +746,54 @@ public bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) { !IsPedestrianCrossingAllowed(segmentId, startNode)); } + public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) { + return SetUturnAllowed(segmentId, startNode, ToTernaryBool(value)); + } + + public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) { + return SetNearTurnOnRedAllowed(segmentId, startNode, ToTernaryBool(value)); + } + + public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) { + return SetFarTurnOnRedAllowed(segmentId, startNode, ToTernaryBool(value)); + } + + public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) { + return SetTurnOnRedAllowed(near, segmentId, startNode, ToTernaryBool(value)); + } + + public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) { + return SetLaneChangingAllowedWhenGoingStraight( + segmentId, + startNode, + ToTernaryBool(value)); + } + + public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) { + return SetEnteringBlockedJunctionAllowed( + segmentId, + startNode, + ToTernaryBool(value)); + } + + public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) { + return SetPedestrianCrossingAllowed( + segmentId, + startNode, + ToTernaryBool(value)); + } + + public bool ClearSegmentEnd(ushort segmentId, bool startNode) { + bool ret = true; + ret |= SetPedestrianCrossingAllowed(segmentId, startNode, TernaryBool.Undefined); + ret |= SetEnteringBlockedJunctionAllowed(segmentId, startNode, TernaryBool.Undefined); + ret |= SetLaneChangingAllowedWhenGoingStraight(segmentId, startNode, TernaryBool.Undefined); + ret |= SetFarTurnOnRedAllowed(segmentId, startNode, TernaryBool.Undefined); + ret |= SetNearTurnOnRedAllowed(segmentId, startNode, TernaryBool.Undefined); + ret |= SetUturnAllowed(segmentId, startNode, TernaryBool.Undefined); + return ret; + } + private void SetSegmentEndFlags(ushort segmentId, bool startNode, SegmentEndFlags flags) { if (flags.uturnAllowed != TernaryBool.Undefined) { SetUturnAllowed(segmentId, startNode, flags.IsUturnAllowed()); @@ -753,7 +804,7 @@ private void SetSegmentEndFlags(ushort segmentId, bool startNode, SegmentEndFlag } if (flags.nearTurnOnRedAllowed != TernaryBool.Undefined) { - SetFarTurnOnRedAllowed(segmentId, startNode, flags.IsFarTurnOnRedAllowed()); + SetFarTurnOnRedAllowed(segmentId, startNode, flags.IsNearTurnOnRedAllowed()); } if (flags.straightLaneChangingAllowed != TernaryBool.Undefined) { @@ -778,12 +829,27 @@ private void SetSegmentEndFlags(ushort segmentId, bool startNode, SegmentEndFlag } } - public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) { + + private static ref NetNode GetNode(ushort segmentId, bool startNode) { + ref NetSegment segment = ref GetSeg(segmentId); + ushort nodeId = startNode ? segment.m_startNode : segment.m_endNode; + return ref Shortcuts.GetNode(nodeId); + } + + #region SetAllowed: TernaryBool + + public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) { if (!Services.NetService.IsSegmentValid(segmentId)) { return false; } + if(GetUturnAllowed(segmentId,startNode) == value) { + return true; + } + if(!IsUturnAllowedConfigurable(segmentId,startNode, ref GetNode(segmentId, startNode))) { + return false; + } - if (!value && Constants.ManagerFactory.LaneConnectionManager.HasUturnConnections( + if (value == TernaryBool.False && Constants.ManagerFactory.LaneConnectionManager.HasUturnConnections( segmentId, startNode)) { return false; @@ -798,18 +864,30 @@ public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) { return true; } - public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) { + public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) { return SetTurnOnRedAllowed(true, segmentId, startNode, value); } - public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) { + public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) { return SetTurnOnRedAllowed(false, segmentId, startNode, value); } - public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) { + public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) { if (!Services.NetService.IsSegmentValid(segmentId)) { return false; } + if (GetTurnOnRedAllowed(near, segmentId, startNode) == value) { + return true; + } + if (!IsTurnOnRedAllowedConfigurable(near, segmentId, startNode, ref GetNode(segmentId, startNode))) { + return false; + } + + if (value == TernaryBool.False && Constants.ManagerFactory.LaneConnectionManager.HasUturnConnections( + segmentId, + startNode)) { + return false; + } if (near) { segmentFlags_[segmentId].SetNearTurnOnRedAllowed(startNode, value); @@ -823,10 +901,16 @@ public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, boo public bool SetLaneChangingAllowedWhenGoingStraight( ushort segmentId, bool startNode, - bool value) { + TernaryBool value) { if (!Services.NetService.IsSegmentValid(segmentId)) { return false; } + if (GetLaneChangingAllowedWhenGoingStraight(segmentId, startNode) == value) { + return true; + } + if (!IsLaneChangingAllowedWhenGoingStraightConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { + return false; + } segmentFlags_[segmentId].SetLaneChangingAllowedWhenGoingStraight(startNode, value); OnSegmentChange( @@ -837,11 +921,16 @@ public bool SetLaneChangingAllowedWhenGoingStraight( return true; } - public bool - SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) { + public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) { if (!Services.NetService.IsSegmentValid(segmentId)) { return false; } + if (GetEnteringBlockedJunctionAllowed(segmentId, startNode) == value) { + return true; + } + if (!IsEnteringBlockedJunctionAllowedConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { + return false; + } segmentFlags_[segmentId].SetEnteringBlockedJunctionAllowed(startNode, value); @@ -854,10 +943,17 @@ public bool return true; } - public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) { + public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) { if (!Services.NetService.IsSegmentValid(segmentId)) { return false; } + if(GetPedestrianCrossingAllowed(segmentId, startNode) == value) { + return true; + } + if(!IsPedestrianCrossingAllowedConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { + return false; + } + segmentFlags_[segmentId].SetPedestrianCrossingAllowed(startNode, value); OnSegmentChange( @@ -868,6 +964,8 @@ public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool return true; } +#endregion + private void OnSegmentChange(ushort segmentId, bool startNode, ref ExtSegment seg, diff --git a/TLM/TLM/State/Keybinds/KeybindSetting.cs b/TLM/TLM/State/Keybinds/KeybindSetting.cs index e25bbae84..170939955 100644 --- a/TLM/TLM/State/Keybinds/KeybindSetting.cs +++ b/TLM/TLM/State/Keybinds/KeybindSetting.cs @@ -95,11 +95,30 @@ public string ToLocalizedString(string prefix = "") { return result + Keybind.ToLocalizedString(AlternateKey); } + /// + /// true for as long as user holds the key public bool IsPressed(Event e) { return Key.IsPressed(e) || (AlternateKey != null && AlternateKey.IsPressed(e)); } + private bool prev_value = false; + + /// + /// Determines when user first presses the key. the event is consumed first time + /// this function is called. + /// + /// + /// true once when user presses the key. + public bool KeyDown(Event e) { + bool value = Key.IsPressed(e); + bool ret = value && !prev_value; + if (ret || !value) { + prev_value = value; + } + return ret; + } + /// /// Check whether main or alt key are the same as k /// diff --git a/TLM/TLM/UI/SubTools/JunctionRestrictionsTool.cs b/TLM/TLM/UI/SubTools/JunctionRestrictionsTool.cs index f74b4f928..cc1bfe9e1 100644 --- a/TLM/TLM/UI/SubTools/JunctionRestrictionsTool.cs +++ b/TLM/TLM/UI/SubTools/JunctionRestrictionsTool.cs @@ -8,6 +8,8 @@ namespace TrafficManager.UI.SubTools { using TrafficManager.State; using TrafficManager.UI.Textures; using UnityEngine; + using TrafficManager.State.Keybinds; + using static TrafficManager.Util.Shortcuts; public class JunctionRestrictionsTool : SubTool { private readonly HashSet currentRestrictedNodeIds; @@ -24,6 +26,18 @@ public override void OnToolGUI(Event e) { // overlayHandleHovered = false; // } // ShowSigns(false); + + // handle delete + if (KeybindSettingsBase.LaneConnectorDelete.KeyDown(e)) { + netService.IterateNodeSegments( + SelectedNodeId, + (ushort segmmentId, ref NetSegment segment) => { + // TODO: #568 provide unified delete key for all managers. + bool startNode = (bool)netService.IsStartNode(segmmentId, SelectedNodeId); + JunctionRestrictionsManager.Instance.ClearSegmentEnd(segmmentId, startNode); + return true; + }); + } } public override void RenderInfoOverlay(RenderManager.CameraInfo cameraInfo) { } diff --git a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs index bf6ec1a20..611557787 100644 --- a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs +++ b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs @@ -2,6 +2,7 @@ namespace TrafficManager.API.Manager { using CSUtil.Commons; public interface IJunctionRestrictionsManager { + #region IsConfigurable /// /// Determines if u-turn behavior may be controlled at the given segment end. /// @@ -82,7 +83,9 @@ bool IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); + #endregion + #region GetDefault /// /// Determines the default setting for u-turns at the given segment end. /// @@ -159,17 +162,21 @@ bool GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, /// at start node? /// node data /// true if crossing the road is allowed by default, - /// false otherwise + /// false otherwise + /// returns the default value if flag is not set. bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node); + #endregion + #region IsAllowed /// /// Determines whether u-turns are allowed at the given segment end. /// /// segment id /// at start node? - /// true if u-turns are allowed, false otherwise + /// true if u-turns are allowed, false otherwise + /// returns the default value if flag is not set. bool IsUturnAllowed(ushort segmentId, bool startNode); /// @@ -177,8 +184,8 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true if turn-on-red is allowed for near turns, false - /// otherwise + /// true if turn-on-red is allowed for near turns, false otherwise + /// returns the default value if flag is not set. bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// @@ -186,8 +193,8 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true if turn-on-red is allowed for far turns, false - /// otherwise + /// true if turn-on-red is allowed for far turns, false otherwise + /// returns the default behaviour if flag is not set. bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// @@ -196,7 +203,8 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// for near turns? /// segment id /// at start node? - /// true if turn-on-red is allowed, false otherwise + /// true if turn-on-red is allowed, false otherwise + /// returns the default behaviour if flag is not set. bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// @@ -204,8 +212,9 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true if lane changing when going straight is allowed, - /// false otherwise + /// true if lane changing when going straight is allowed, false otherwise + /// returns the default behaviour if flag is not set. + bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// @@ -213,7 +222,8 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true if entering a blocked junction is allowed, false otherwise + /// true if entering a blocked junction is allowed, false otherwise + /// returns the default behaviour if flag is not set. bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// @@ -221,16 +231,19 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true if crossing the road is allowed, false - /// otherwise + /// true if crossing the road is allowed, false otherwise. + /// returns the default value if flag is not set. bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode); + #endregion + #region Get /// /// Retrieves the u-turn setting for the given segment end. /// /// segment id /// at start node? - /// ternary u-turn flag + /// ternary u-turn flag. + /// returns TernaryBool.Undefined if the flag is not set. TernaryBool GetUturnAllowed(ushort segmentId, bool startNode); /// @@ -238,7 +251,8 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// ternary turn-on-red flag for near turns + /// ternary turn-on-red flag for near turns. + /// returns TernaryBool.Undefined if the flag is not set. TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// @@ -246,7 +260,8 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// ternary turn-on-red flag for far turns + /// ternary turn-on-red flag for far turns. + /// returns TernaryBool.Undefined if the flag is not set. TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// @@ -255,7 +270,8 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// for near turns? /// segment id /// at start node? - /// ternary turn-on-red flag + /// ternary turn-on-red flag. + /// returns TernaryBool.Undefined if the flag is not set. TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// @@ -263,7 +279,8 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// ternary lane changing flag + /// ternary lane changing flag. + /// returns TernaryBool.Undefined if the flag is not set. TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// @@ -271,7 +288,8 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// ternary "enter blocked junction" flag + /// ternary "enter blocked junction" flag. + /// returns TernaryBool.Undefined if the flag is not set. TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// @@ -279,15 +297,21 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// ternary pedestrian crossing flag + /// ternary pedestrian crossing flag. + /// returns TernaryBool.Undefined if the flag is not set. TernaryBool GetPedestrianCrossingAllowed(ushort segmentId, bool startNode); - + #endregion + + #region Toggle /// /// Switches the u-turn flag for the given segment end. /// /// segment id /// at start node? - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool ToggleUturnAllowed(ushort segmentId, bool startNode); /// @@ -295,7 +319,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// @@ -303,7 +330,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// @@ -312,7 +342,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// for near turns? /// segment id /// at start node? - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// @@ -320,7 +353,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// @@ -328,7 +364,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// @@ -336,16 +375,24 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// /// segment id /// at start node? - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode); + #endregion + #region Set : bool /// /// Sets the u-turn flag for the given segment end to the given value. /// /// segment id /// at start node? /// new value - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool SetUturnAllowed(ushort segmentId, bool startNode, bool value); /// @@ -354,7 +401,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// segment id /// at start node? /// new value - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value); /// @@ -363,7 +413,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// segment id /// at start node? /// new value - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value); /// @@ -373,7 +426,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// segment id /// at start node? /// new value - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value); /// @@ -382,7 +438,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// segment id /// at start node? /// new value - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value); /// @@ -391,7 +450,10 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// segment id /// at start node? /// new value - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value); /// @@ -400,8 +462,109 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// segment id /// at start node? /// new value - /// true on success, false otherwise + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value); + #endregion + + #region Set : TernaryBool + + + /// + /// Sets the u-turn flag for the given segment end to the given value. + /// + /// segment id + /// at start node? + /// new value. Passing in TernaryBool.Undefined removes the traffic bool. + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// + bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value); + + /// + /// Sets the turn-on-red flag for near turns at the given segment end to the given value. + /// + /// segment id + /// at start node? + /// new value. Passing in TernaryBool.Undefined removes the traffic bool. + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// + bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value); + + /// + /// Sets the turn-on-red flag for far turns at the given segment end to the given value. + /// + /// segment id + /// at start node? + /// new value. Passing in TernaryBool.Undefined removes the traffic bool. + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// + bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value); + + /// + /// Sets the turn-on-red flag for the given turn type and segment end to the given value. + /// + /// for near turns? + /// segment id + /// at start node? + /// new value. Passing in TernaryBool.Undefined removes the traffic bool. + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// + bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value); + + /// + /// Sets the lane changing flag for the given segment end to the given value. + /// + /// segment id + /// at start node? + /// new value. Passing in TernaryBool.Undefined removes the traffic bool. + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// + bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value); + + /// + /// Sets the "enter blocked junction" flag for the given segment end to the given value. + /// + /// segment id + /// at start node? + /// new value. Passing in TernaryBool.Undefined removes the traffic bool. + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// + bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value); + + /// + /// Sets the pedestrian crossing flag for the given segment end to the given value. + /// + /// segment id + /// at start node? + /// new value. Passing in TernaryBool.Undefined removes the traffic bool. + /// true on success. + /// Silently returns true if the given equals to the flag. + /// On failure (including when traffic rule is not configurable) returns false + /// + bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value); + #endregion + + /// + /// Removes all traffic rules for the input segment end. + /// + /// + /// + /// true on success, false otherwise + bool ClearSegmentEnd(ushort segmentId, bool startNode); /// /// Updates the default values for all junction restrictions and segments. diff --git a/TLM/TMPE.API/Traffic/Data/SegmentEndFlags.cs b/TLM/TMPE.API/Traffic/Data/SegmentEndFlags.cs index dad16605a..b7133df63 100644 --- a/TLM/TMPE.API/Traffic/Data/SegmentEndFlags.cs +++ b/TLM/TMPE.API/Traffic/Data/SegmentEndFlags.cs @@ -1,4 +1,4 @@ -namespace TrafficManager.API.Traffic.Data { +namespace TrafficManager.API.Traffic.Data { using System; using CSUtil.Commons; @@ -56,28 +56,28 @@ public bool IsPedestrianCrossingAllowed() { : TernaryBoolUtil.ToBool(pedestrianCrossingAllowed); } - public void SetUturnAllowed(bool value) { - uturnAllowed = TernaryBoolUtil.ToTernaryBool(value); + public void SetUturnAllowed(TernaryBool value) { + uturnAllowed = value; } - public void SetNearTurnOnRedAllowed(bool value) { - nearTurnOnRedAllowed = TernaryBoolUtil.ToTernaryBool(value); + public void SetNearTurnOnRedAllowed(TernaryBool value) { + nearTurnOnRedAllowed = value; } - public void SetFarTurnOnRedAllowed(bool value) { - farTurnOnRedAllowed = TernaryBoolUtil.ToTernaryBool(value); + public void SetFarTurnOnRedAllowed(TernaryBool value) { + farTurnOnRedAllowed = value; } - public void SetLaneChangingAllowedWhenGoingStraight(bool value) { - straightLaneChangingAllowed = TernaryBoolUtil.ToTernaryBool(value); + public void SetLaneChangingAllowedWhenGoingStraight(TernaryBool value) { + straightLaneChangingAllowed = value; } - public void SetEnteringBlockedJunctionAllowed(bool value) { - enterWhenBlockedAllowed = TernaryBoolUtil.ToTernaryBool(value); + public void SetEnteringBlockedJunctionAllowed(TernaryBool value) { + enterWhenBlockedAllowed = value; } - public void SetPedestrianCrossingAllowed(bool value) { - pedestrianCrossingAllowed = TernaryBoolUtil.ToTernaryBool(value); + public void SetPedestrianCrossingAllowed(TernaryBool value) { + pedestrianCrossingAllowed = value; } public bool IsDefault() { diff --git a/TLM/TMPE.API/Traffic/Data/SegmentFlags.cs b/TLM/TMPE.API/Traffic/Data/SegmentFlags.cs index b96d83d87..6327665a6 100644 --- a/TLM/TMPE.API/Traffic/Data/SegmentFlags.cs +++ b/TLM/TMPE.API/Traffic/Data/SegmentFlags.cs @@ -1,4 +1,4 @@ -namespace TrafficManager.API.Traffic.Data { +namespace TrafficManager.API.Traffic.Data { using System; using CSUtil.Commons; @@ -79,7 +79,7 @@ public TernaryBool GetPedestrianCrossingAllowed(bool startNode) { : endNodeFlags.pedestrianCrossingAllowed; } - public void SetUturnAllowed(bool startNode, bool value) { + public void SetUturnAllowed(bool startNode, TernaryBool value) { if (startNode) { startNodeFlags.SetUturnAllowed(value); } else { @@ -87,7 +87,7 @@ public void SetUturnAllowed(bool startNode, bool value) { } } - public void SetNearTurnOnRedAllowed(bool startNode, bool value) { + public void SetNearTurnOnRedAllowed(bool startNode, TernaryBool value) { if (startNode) { startNodeFlags.SetNearTurnOnRedAllowed(value); } else { @@ -95,7 +95,7 @@ public void SetNearTurnOnRedAllowed(bool startNode, bool value) { } } - public void SetFarTurnOnRedAllowed(bool startNode, bool value) { + public void SetFarTurnOnRedAllowed(bool startNode, TernaryBool value) { if (startNode) { startNodeFlags.SetFarTurnOnRedAllowed(value); } else { @@ -103,7 +103,7 @@ public void SetFarTurnOnRedAllowed(bool startNode, bool value) { } } - public void SetLaneChangingAllowedWhenGoingStraight(bool startNode, bool value) { + public void SetLaneChangingAllowedWhenGoingStraight(bool startNode, TernaryBool value) { if (startNode) { startNodeFlags.SetLaneChangingAllowedWhenGoingStraight(value); } else { @@ -111,7 +111,7 @@ public void SetLaneChangingAllowedWhenGoingStraight(bool startNode, bool value) } } - public void SetEnteringBlockedJunctionAllowed(bool startNode, bool value) { + public void SetEnteringBlockedJunctionAllowed(bool startNode, TernaryBool value) { if (startNode) { startNodeFlags.SetEnteringBlockedJunctionAllowed(value); } else { @@ -119,7 +119,7 @@ public void SetEnteringBlockedJunctionAllowed(bool startNode, bool value) { } } - public void SetPedestrianCrossingAllowed(bool startNode, bool value) { + public void SetPedestrianCrossingAllowed(bool startNode, TernaryBool value) { if (startNode) { startNodeFlags.SetPedestrianCrossingAllowed(value); } else {