Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default Timed traffic light #554

Merged
merged 20 commits into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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: 2 additions & 2 deletions TLM/CSUtil.Commons/ArrowDirection.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace CSUtil.Commons {
namespace CSUtil.Commons {
public enum ArrowDirection {
None = 0,
Left = 1,
Forward = 2,
Right = 3,
Turn = 4
Turn = 4,
}
}
1 change: 1 addition & 0 deletions TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<Compile Include="State\Flags.cs" />
<Compile Include="UI\TransportDemandViewMode.cs" />
<Compile Include="UI\UITransportDemand.cs" />
<Compile Include="Util\AutoTimedTrafficLights.cs" />
<Compile Include="Util\Caching\CameraTransformValue.cs" />
<Compile Include="Util\Caching\GenericArrayCache.cs" />
<Compile Include="Util\FloatUtil.cs" />
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/UI/MainMenu/TimedTrafficLightsButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class TimedTrafficLightsButton : MenuToolModeButton {

protected override ButtonFunction Function => ButtonFunction.TimedTrafficLights;

public override string Tooltip => Translation.Menu.Get("Tooltip:Timed traffic lights");
public override string Tooltip => Translation.Menu.Get("Tooltip:Timed traffic lights") + "\n" + Translation.Menu.Get("Tooltip.Keybinds:Auto TL");

public override bool Visible => Options.timedLightsEnabled;
}
Expand Down
37 changes: 34 additions & 3 deletions TLM/TLM/UI/SubTools/TimedTrafficLightsTool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace TrafficManager.UI.SubTools {
namespace TrafficManager.UI.SubTools {
using TrafficManager.Util;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -99,9 +100,36 @@ public override void OnSecondaryClickOverlay() {
}

public override void OnPrimaryClickOverlay() {
if (HoveredNodeId <= 0 || nodeSelectionLocked) {
if (HoveredNodeId <= 0 || nodeSelectionLocked || !Flags.MayHaveTrafficLight(HoveredNodeId)) {
return;
}
bool ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
if(ctrlDown) {
AutoTimedTrafficLights.ErrorResult res = AutoTimedTrafficLights.Setup(HoveredNodeId);
if (res != AutoTimedTrafficLights.ErrorResult.Success) {
string message;
switch (res) {
case AutoTimedTrafficLights.ErrorResult.NotSupported:
message = "Dialog.Text:Auto TL no need";
break;
case AutoTimedTrafficLights.ErrorResult.TTLExists:
message = "Dialog.Text:Node has timed TL script";
break;
default: //Unreachable code
message = $"error = {res}";
break;
}
message =
Translation.TrafficLights.Get("Dialog.Text:Auto TL create failed because") +
"\n" +
Translation.TrafficLights.Get(message);
MainTool.ShowError(message);
return;
}
RefreshCurrentTimedNodeIds(HoveredNodeId);
MainTool.SetToolMode(ToolMode.TimedLightsShowLights);
}


TrafficLightSimulationManager tlsMan = TrafficLightSimulationManager.Instance;

Expand Down Expand Up @@ -249,7 +277,10 @@ public override void OnToolGUI(Event e) {

switch (MainTool.GetToolMode()) {
case ToolMode.TimedLightsSelectNode: {
GuiTimedTrafficLightsNode();
bool ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
if (!ctrlDown) {
GuiTimedTrafficLightsNode();
}
break;
}

Expand Down
Loading