Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions TLM/TLM/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace TrafficManager {
using TrafficManager.API.Manager;
using TrafficManager.API.Notifier;
using TrafficManager.API.UI;
using TrafficManager.U;
using TrafficManager.UI.Textures;

public static class Constants {
/// <summary>
Expand Down Expand Up @@ -36,5 +38,7 @@ public static float ByteToFloat(byte b) {
public static IManagerFactory ManagerFactory => Manager.Impl.ManagerFactory.Instance;

public static INotifier Notifier => TrafficManager.Notifier.Instance;

public static IRoadSignTheme ActiveTheme => RoadSignThemeManager.ActiveTheme;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class LaneConnectionManager
| VehicleInfo.VehicleType.Trolleybus;

public LaneConnectionSubManager Sub = // TODO #354 divide into Road/Track
new LaneConnectionSubManager(LaneEndTransitionGroup.All);
new LaneConnectionSubManager(LaneEndTransitionGroup.Vehicle);

public NetInfo.LaneType LaneTypes => LANE_TYPES;

Expand Down
12 changes: 12 additions & 0 deletions TLM/TLM/Manager/Impl/TrafficLightManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ protected override void InternalPrintDebugInfo() {
Log.NotImpl("InternalPrintDebugInfo for TrafficLightManager");
}

public bool SetTrafficLight(ushort nodeId, bool enabled) => SetTrafficLight(nodeId, enabled, ref nodeId.ToNode());

// TODO: Consider replacing out error code with Result<> or VoidResult<>
public bool SetTrafficLight(ushort nodeId, bool flag, ref NetNode node) {
return SetTrafficLight(nodeId, flag, ref node, out ToggleTrafficLightError _);
Expand Down Expand Up @@ -127,6 +129,14 @@ public bool ToggleTrafficLight(ushort nodeId, ref NetNode node, out ToggleTraffi
return SetTrafficLight(nodeId, !HasTrafficLight(nodeId, ref node), ref node, out reason);
}

public bool CanSetTrafficLight(ushort nodeId, bool enabled) {
return CanToggleTrafficLight(
nodeId,
enabled,
ref nodeId.ToNode(),
out _);
}

public bool CanToggleTrafficLight(ushort nodeId,
bool flag, // override?
ref NetNode node,
Expand Down Expand Up @@ -242,6 +252,8 @@ public bool CanEnableTrafficLight(ushort nodeId,
return ret;
}

public bool HasTrafficLight(ushort nodeId) => HasTrafficLight(nodeId, ref nodeId.ToNode());

public bool HasTrafficLight(ushort nodeId, ref NetNode node) {
return node.IsValid()
&& node.m_flags.IsFlagSet(NetNode.Flags.TrafficLights);
Expand Down
16 changes: 14 additions & 2 deletions TLM/TLM/UI/Textures/RoadSignTheme.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
namespace TrafficManager.UI.Textures {
namespace TrafficManager.UI.Textures {
using System;
using System.Collections.Generic;
using CSUtil.Commons;
using JetBrains.Annotations;
using TrafficManager.API.Traffic.Data;
using TrafficManager.API.Traffic.Enums;
using TrafficManager.API.UI;
using TrafficManager.State;
using TrafficManager.UI.SubTools;
using TrafficManager.Util;
Expand All @@ -15,7 +16,7 @@
/// Defines one theme for road signs. All themes are accessible via, and stored in
/// <see cref="RoadSignThemeManager"/>.
/// </summary>
public class RoadSignTheme {
public class RoadSignTheme : IRoadSignTheme {
public enum OtherRestriction {
Crossing,
EnterBlockedJunction,
Expand Down Expand Up @@ -148,6 +149,17 @@ public Texture2D GetOtherRestriction(OtherRestriction type, bool allow) {
: this.ParentTheme.GetOtherRestriction(type, allow: false);
}

public Texture2D Crossing(bool allow) => GetOtherRestriction(OtherRestriction.Crossing, allow);
public Texture2D EnterBlockedJunction(bool allow) => GetOtherRestriction(OtherRestriction.EnterBlockedJunction, allow);
public Texture2D LaneChange(bool allow) => GetOtherRestriction(OtherRestriction.LaneChange, allow);
public Texture2D LeftOnRed(bool allow) => GetOtherRestriction(OtherRestriction.LeftOnRed, allow);
public Texture2D RightOnRed(bool allow) => GetOtherRestriction(OtherRestriction.RightOnRed, allow);
public Texture2D UTurn(bool allow) => GetOtherRestriction(OtherRestriction.UTurn, allow);
public Texture2D TrafficLights(bool enabled) =>
enabled ? TrafficLightTextures.Instance.TrafficLightEnabled : TrafficLightTextures.Instance.TrafficLightDisabled;
public Texture2D TimedTrafficLights(bool paused) =>
paused ? TrafficLightTextures.Instance.ClockPause : TrafficLightTextures.Instance.TrafficLightEnabledTimed;

public RoadSignTheme Load(bool whiteTexture = false) {
if (this.AttemptedToLoad) {
return this;
Expand Down
3 changes: 3 additions & 0 deletions TLM/TMPE.API/Implementations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ namespace TrafficManager.API {
using TrafficManager.API.Manager;
using TrafficManager.API.Notifier;
using System.Linq;
using TrafficManager.API.UI;

public static class Implementations {
private static Type constantsType_;
private static IManagerFactory managerFactory_;
private static INotifier notifier_;
private static IRoadSignTheme activeTheme_;

public static IManagerFactory ManagerFactory => managerFactory_ ??= GetImplementation<IManagerFactory>();
public static INotifier Notifier => notifier_ ??= GetImplementation<INotifier>();
public static IRoadSignTheme ActiveTheme => activeTheme_ ??= GetImplementation<IRoadSignTheme>();

private static T GetImplementation<T>()
where T : class {
Expand Down
5 changes: 5 additions & 0 deletions TLM/TMPE.API/Manager/ITrafficLightManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ namespace TrafficManager.API.Manager {
using TrafficManager.API.Traffic.Enums;

public interface ITrafficLightManager {
bool HasTrafficLight(ushort nodeId);

bool CanSetTrafficLight(ushort nodeId, bool enabled);

bool SetTrafficLight(ushort nodeId, bool enabled);
}
}
3 changes: 3 additions & 0 deletions TLM/TMPE.API/Manager/ITrafficLightSimulationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ namespace TrafficManager.API.Manager {
using System.Collections.Generic;

public interface ITrafficLightSimulationManager {
bool HasTimedSimulation(ushort nodeId);

bool HasActiveTimedSimulation(ushort nodeId);
}
}
1 change: 1 addition & 0 deletions TLM/TMPE.API/TMPE.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<Compile Include="Traffic\Enums\VehicleRestrictionsMode.cs" />
<Compile Include="Traffic\ISegmentEnd.cs" />
<Compile Include="Traffic\ISegmentEndId.cs" />
<Compile Include="UI\IRoadSignTheme.cs" />
<Compile Include="Util\IObservable.cs" />
<Compile Include="Util\IObserver.cs" />
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion TLM/TMPE.API/Traffic/Enums/LaneEndTransitionGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public enum LaneEndTransitionGroup {
None = 0,
Road = 1,
Track = 2,
All = Road | Track,
Vehicle = Road | Track,
Bicycle = 4,
Pedestrian = 8,
}
}
21 changes: 21 additions & 0 deletions TLM/TMPE.API/UI/IRoadSignTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace TrafficManager.API.UI {
using TrafficManager.API.Traffic.Enums;
using UnityEngine;

/// <summary>
/// gets the texture for overlay sprite for each traffic rule according to the current theme.
/// </summary>
public interface IRoadSignTheme {
Texture2D Crossing(bool allowewd);
Texture2D EnterBlockedJunction(bool allowewd);
Texture2D LaneChange(bool allowewd);
Texture2D LeftOnRed(bool allowewd);
Texture2D RightOnRed(bool allowewd);
Texture2D UTurn(bool allowewd);
Texture2D Priority(PriorityType p);
Texture2D Parking(bool p);
Texture2D VehicleRestriction(ExtVehicleType type, bool allow);
Texture2D TrafficLights(bool enabled);
Texture2D TimedTrafficLights(bool paused);
}
}