Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions NodeController/GUI/TrafficRulesOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public bool DrawSignHandles(ushort nodeId,
baseZoom: TMPEUtils.GetBaseZoom());

JunctionRestrictionsManager jrMan = JunctionRestrictionsManager.Instance;
RoadSignTheme theme = RoadSignThemeManager.ActiveTheme;

#region UTURN
// draw "u-turns allowed" sign at (1; 0)
Expand All @@ -278,9 +279,7 @@ public bool DrawSignHandles(ushort nodeId,
handleClick: configurable && handleClick_,
camPos: ref camPos,
guiColor: guiColor,
signTexture: allowed
? JunctionRestrictions.Instance.UturnAllowed
: JunctionRestrictions.Instance.UturnForbidden);
signTexture: theme.GetOtherRestriction(RoadSignTheme.OtherRestriction.UTurn, allowed));

if (signHovered && handleClick_ && configurable) {
isAnyHovered = true;
Expand Down Expand Up @@ -317,9 +316,7 @@ public bool DrawSignHandles(ushort nodeId,
handleClick: configurable && handleClick_,
camPos: ref camPos,
guiColor: guiColor,
signTexture: allowed
? JunctionRestrictions.Instance.EnterBlockedJunctionAllowed
: JunctionRestrictions.Instance.EnterBlockedJunctionForbidden);
signTexture: theme.GetOtherRestriction(RoadSignTheme.OtherRestriction.EnterBlockedJunction, allowed));

if (signHovered && this.handleClick_ && configurable) {
isAnyHovered = true;
Expand Down Expand Up @@ -369,9 +366,7 @@ public bool DrawSignHandles(ushort nodeId,
handleClick: configurable && handleClick_,
camPos: ref camPos,
guiColor: guiColor,
signTexture: allowed
? JunctionRestrictions.Instance.PedestrianCrossingAllowed
: JunctionRestrictions.Instance.PedestrianCrossingForbidden);
signTexture: theme.GetOtherRestriction(RoadSignTheme.OtherRestriction.Crossing, allowed));

if (signHovered && this.handleClick_ && configurable) {
isAnyHovered = true;
Expand Down
5 changes: 5 additions & 0 deletions NodeController/LifeCycle/LifeCycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public static class LifeCycle {

public static bool Loaded;

/// <summary>
/// A reference to ensure initialization of the hook.
/// </summary>
private static Patches.TMPE.JunctionRestrictions junctionRestrictionsHook = Patches.TMPE.JunctionRestrictions.Instance;

public static void Enable() {
Log.Debug("Testing StackTrace:\n" + new StackTrace(true).ToString(), copyToGameLog: false);
KianCommons.UI.TextureUtil.EmbededResources = false;
Expand Down
105 changes: 53 additions & 52 deletions NodeController/Manager/NodeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,91 +764,92 @@ public void ShiftPilar() {
// undefined -> don't touch prev value
// true -> force true
// false -> force false.
public TernaryBool IsUturnAllowedConfigurable() {

public bool? IsUturnAllowedConfigurable() {
switch (NodeType) {
case NodeTypeT.Crossing:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.UTurn:
return TernaryBool.Undefined; // default on
return null; // default on
case NodeTypeT.Stretch:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.Nodeless:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.Bend:
return TernaryBool.False; // always default
return false; // always default
case NodeTypeT.Custom:
return TernaryBool.Undefined; // default
return null; // default
case NodeTypeT.End:
return TernaryBool.Undefined;
return null;
default:
throw new Exception("Unreachable code");
}
}

public TernaryBool GetDefaultUturnAllowed() {
public bool? GetDefaultUturnAllowed() {
switch (NodeType) {
case NodeTypeT.Crossing:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.UTurn:
return TernaryBool.True; // default on
return true; // default on
case NodeTypeT.Stretch:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.Nodeless:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.Bend:
return TernaryBool.Undefined; // don't care
return null; // don't care
case NodeTypeT.Custom:
return TernaryBool.Undefined; // default
return null; // default
case NodeTypeT.End:
return TernaryBool.Undefined;
return null;
default:
throw new Exception("Unreachable code");
}
}

public TernaryBool IsPedestrianCrossingAllowedConfigurable() {
public bool? IsPedestrianCrossingAllowedConfigurable() {
switch (NodeType) {
case NodeTypeT.Crossing:
return TernaryBool.False; // always on
return false; // always on
case NodeTypeT.UTurn:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.Stretch:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.Nodeless:
case NodeTypeT.Bend:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.Custom:
if (SegmentCount == 2 && !HasPedestrianLanes) {
return TernaryBool.False; // TODO move to TMPE.
return false; // TODO move to TMPE.
}
return TernaryBool.Undefined; // default off
return null; // default off
case NodeTypeT.End:
return TernaryBool.Undefined;
return null;
default:
throw new Exception("Unreachable code");
}
}

public TernaryBool GetDefaultPedestrianCrossingAllowed() {
public bool? GetDefaultPedestrianCrossingAllowed() {
switch (NodeType) {
case NodeTypeT.Crossing:
return TernaryBool.True; // always on
return true; // always on
case NodeTypeT.UTurn:
return TernaryBool.False; // default off
return false; // default off
case NodeTypeT.Stretch:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.Nodeless:
case NodeTypeT.Bend:
return TernaryBool.False; // always off
return false; // always off
case NodeTypeT.Custom:
var netAI1 = segmentID1.ToSegment().Info.m_netAI;
var netAI2 = segmentID2.ToSegment().Info.m_netAI;
bool sameAIType = netAI1.GetType() == netAI2.GetType();
bool sameAIType = netAI1.GetType() == netAI2.GetType();
if (SegmentCount == 2 && !sameAIType) // eg: at bridge/tunnel entrances.
return TernaryBool.False; // default off
return TernaryBool.Undefined; // don't care
return false; // default off
return null; // don't care
case NodeTypeT.End:
return TernaryBool.Undefined;
return null;
default:
throw new Exception("Unreachable code");
}
Expand Down Expand Up @@ -880,54 +881,54 @@ public TernaryBool CanHaveTrafficLights(out ToggleTrafficLightError reason) {
}
}

public TernaryBool IsEnteringBlockedJunctionAllowedConfigurable() {
public bool? IsEnteringBlockedJunctionAllowedConfigurable() {
switch (NodeType) {
case NodeTypeT.Crossing:
return TernaryBool.Undefined; // default off
return null; // default off
case NodeTypeT.UTurn:
return TernaryBool.Undefined; // default
return null; // default
case NodeTypeT.Stretch:
return TernaryBool.False; // always on
return false; // always on
case NodeTypeT.Nodeless:
case NodeTypeT.Bend:
return TernaryBool.False; // always default
return false; // always default
case NodeTypeT.Custom:
if (SegmentCount > 2)
return TernaryBool.Undefined;
return null;
bool oneway = DefaultFlags.IsFlagSet(NetNode.Flags.OneWayIn) & DefaultFlags.IsFlagSet(NetNode.Flags.OneWayOut);
if (oneway & !HasPedestrianLanes) {
return TernaryBool.False; // always on.
return false; // always on.
}
return TernaryBool.Undefined; // default on.
return null; // default on.
case NodeTypeT.End:
return TernaryBool.Undefined;
return null;
default:
throw new Exception("Unreachable code");
}
}

public TernaryBool GetDefaultEnteringBlockedJunctionAllowed() {
public bool? GetDefaultEnteringBlockedJunctionAllowed() {
switch (NodeType) {
case NodeTypeT.Crossing:
return TernaryBool.False; // default off
return false; // default off
case NodeTypeT.UTurn:
return TernaryBool.Undefined; // default
return null; // default
case NodeTypeT.Stretch:
return TernaryBool.True; // always on
return true; // always on
case NodeTypeT.Nodeless:
case NodeTypeT.Bend:
return TernaryBool.Undefined; // don't care
return null; // don't care
case NodeTypeT.Custom:
if (SegmentCount > 2)
return TernaryBool.Undefined;
return TernaryBool.True;
return null;
return true;
//bool oneway = DefaultFlags.IsFlagSet(NetNode.Flags.OneWayIn) & DefaultFlags.IsFlagSet(NetNode.Flags.OneWayOut);
//if (oneway & !HasPedestrianLanes) {
// return TernaryBool.True; // always on.
// return true; // always on.
//}
//return TernaryBool.Undefined;
//return null;
case NodeTypeT.End:
return TernaryBool.Undefined;
return null;
default:
throw new Exception("Unreachable code");
}
Expand Down
8 changes: 8 additions & 0 deletions NodeController/Manager/NodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public NodeData InsertNode(NetTool.ControlPoint controlPoint, NodeTypeT nodeType
return buffer[nodeID];
}

public bool TryGet(ushort segmentId, bool startNode, out NodeData nodeData)
=> TryGet(segmentId.ToSegment().GetNode(startNode), out nodeData);

public bool TryGet(ushort nodeId, out NodeData nodeData) {
nodeData = Instance.buffer[nodeId];
return nodeData != null;
}

public ref NodeData GetOrCreate(ushort nodeID) {
ref NodeData data = ref Instance.buffer[nodeID];
if (data == null) {
Expand Down

This file was deleted.

28 changes: 0 additions & 28 deletions NodeController/Patches/TMPE/GetDefaultPedestrianCrossingAllowed.cs

This file was deleted.

26 changes: 0 additions & 26 deletions NodeController/Patches/TMPE/GetDefaultUturnAllowed.cs

This file was deleted.

This file was deleted.

Loading