Skip to content

Commit

Permalink
TimedTrafficLights states moved inside TTL tool (#828)
Browse files Browse the repository at this point in the history
* TimedTrafficLights states moved inside TTL tool; Fixes #826
* Revert submodules accidentally modified to what Master branch has
* Delete extra sprite which should not be there
  • Loading branch information
kvakvs authored Apr 11, 2020
1 parent 9e5855b commit e03a672
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 141 deletions.
3 changes: 2 additions & 1 deletion TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@
<Compile Include="UI\SubTools\SpeedLimits\MphSignStyle.cs" />
<Compile Include="UI\SubTools\SpeedLimits\SpeedLimitsTool.cs" />
<Compile Include="UI\SubTools\SpeedLimits\SpeedUnit.cs" />
<Compile Include="UI\SubTools\TimedTrafficLights\TimedTrafficLightsTool.cs" />
<Compile Include="UI\SubTools\TimedTrafficLights\TTLToolMode.cs" />
<Compile Include="UI\Textures\JunctionRestrictions.cs" />
<Compile Include="UI\Textures\MainMenu.cs" />
<Compile Include="UI\Textures\RoadUI.cs" />
Expand All @@ -289,7 +291,6 @@
<Compile Include="UI\SubTools\JunctionRestrictionsTool.cs" />
<Compile Include="UI\SubTools\LaneConnectorTool.cs" />
<Compile Include="UI\SubTools\VehicleRestrictionsTool.cs" />
<Compile Include="UI\SubTools\TimedTrafficLightsTool.cs" />
<Compile Include="UI\SubTools\ManualTrafficLightsTool.cs" />
<Compile Include="UI\SubTools\PrioritySignsTool.cs" />
<Compile Include="UI\SubTools\ToggleTrafficLightsTool.cs" />
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/UI/MainMenu/MainMenuPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static readonly MenuButtonDef[] MENU_BUTTON_TYPES
},
new MenuButtonDef {
ButtonType = typeof(TimedTrafficLightsButton),
Mode = ToolMode.TimedLightsButton,
Mode = ToolMode.TimedTrafficLights,
},
new MenuButtonDef {
ButtonType = typeof(ManualTrafficLightsButton),
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 @@ -5,7 +5,7 @@ namespace TrafficManager.UI.MainMenu {
using TrafficManager.U.Button;

public class TimedTrafficLightsButton : BaseMenuToolModeButton {
protected override ToolMode ToolMode => ToolMode.TimedLightsSelectNode;
protected override ToolMode ToolMode => ToolMode.TimedTrafficLights;

public override void SetupButtonSkin(HashSet<string> atlasKeys) {
// Button backround (from BackgroundPrefix) is provided by MainMenuPanel.Start
Expand Down
18 changes: 18 additions & 0 deletions TLM/TLM/UI/SubTools/TimedTrafficLights/TTLToolMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace TrafficManager.UI.SubTools {
internal enum TTLToolMode {
/// <summary>Timed traffic light submode.</summary>
SelectNode,

/// <summary>Timed traffic light submode.</summary>
ShowLights,

/// <summary>Timed traffic light submode.</summary>
AddNode,

/// <summary>Timed traffic light submode.</summary>
RemoveNode,

/// <summary>Timed traffic light submode.</summary>
CopyLights,
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace TrafficManager.UI.SubTools {
using ColossalFramework;
using CSUtil.Commons;
namespace TrafficManager.UI.SubTools.TimedTrafficLights {
using System;
using System.Collections.Generic;
using System.Linq;
using System;
using ColossalFramework;
using CSUtil.Commons;
using TrafficManager.API.Manager;
using TrafficManager.API.Traffic.Data;
using TrafficManager.API.Traffic.Enums;
Expand All @@ -15,6 +15,8 @@ namespace TrafficManager.UI.SubTools {
using UnityEngine;

public class TimedTrafficLightsTool : LegacySubTool {
private TTLToolMode ttlToolMode_ = TTLToolMode.SelectNode;

private readonly GUIStyle _counterStyle = new GUIStyle();
private readonly int[] _hoveredButton = new int[2];
private bool nodeSelectionLocked;
Expand Down Expand Up @@ -95,10 +97,14 @@ public override void OnActivate() {
public override void OnSecondaryClickOverlay() {
if (!IsCursorInPanel()) {
Cleanup();
MainTool.SetToolMode(ToolMode.TimedLightsSelectNode);
this.SetToolMode(TTLToolMode.SelectNode);
}
}

private void SetToolMode(TTLToolMode t) {
ttlToolMode_ = t;
}

public override void OnPrimaryClickOverlay() {
if (HoveredNodeId <= 0 || nodeSelectionLocked || !Flags.MayHaveTrafficLight(HoveredNodeId)) {
return;
Expand Down Expand Up @@ -131,16 +137,16 @@ public override void OnPrimaryClickOverlay() {
return;
}
RefreshCurrentTimedNodeIds(HoveredNodeId);
MainTool.SetToolMode(ToolMode.TimedLightsShowLights);
this.SetToolMode(TTLToolMode.ShowLights);
}

TrafficLightSimulationManager tlsMan = TrafficLightSimulationManager.Instance;

switch (MainTool.GetToolMode()) {
case ToolMode.TimedLightsSelectNode:
case ToolMode.TimedLightsShowLights: {
if (MainTool.GetToolMode() == ToolMode.TimedLightsShowLights) {
MainTool.SetToolMode(ToolMode.TimedLightsSelectNode);
switch (ttlToolMode_) {
case TTLToolMode.SelectNode:
case TTLToolMode.ShowLights: {
if (ttlToolMode_ == TTLToolMode.ShowLights) {
this.SetToolMode(TTLToolMode.SelectNode);
ClearSelectedNodes();
}

Expand All @@ -158,7 +164,7 @@ public override void OnPrimaryClickOverlay() {

if (timedLight != null) {
selectedNodeIds = new List<ushort>(timedLight.NodeGroup);
MainTool.SetToolMode(ToolMode.TimedLightsShowLights);
this.SetToolMode(TTLToolMode.ShowLights);
}
} else {
MainTool.WarningPrompt(T("Dialog.Text:Node has timed TL script"));
Expand All @@ -168,9 +174,9 @@ public override void OnPrimaryClickOverlay() {
break;
}

case ToolMode.TimedLightsAddNode: {
case TTLToolMode.AddNode: {
if (selectedNodeIds.Count <= 0) {
MainTool.SetToolMode(ToolMode.TimedLightsSelectNode);
this.SetToolMode(TTLToolMode.SelectNode);
return;
}

Expand Down Expand Up @@ -208,29 +214,32 @@ public override void OnPrimaryClickOverlay() {
AddSelectedNode(nodeId);
}

MainTool.SetToolMode(ToolMode.TimedLightsShowLights);
this.SetToolMode(TTLToolMode.ShowLights);
break;
}

case ToolMode.TimedLightsRemoveNode: {
case TTLToolMode.RemoveNode: {
if (selectedNodeIds.Count <= 0) {
MainTool.SetToolMode(ToolMode.TimedLightsSelectNode);
this.SetToolMode(TTLToolMode.SelectNode);
return;
}

if (selectedNodeIds.Contains(HoveredNodeId)) {
tlsMan.RemoveNodeFromSimulation(HoveredNodeId, false, false);
tlsMan.RemoveNodeFromSimulation(
nodeId: HoveredNodeId,
destroyGroup: false,
removeTrafficLight: false);
RefreshCurrentTimedNodeIds(HoveredNodeId);
}

RemoveSelectedNode(HoveredNodeId);
MainTool.SetToolMode(ToolMode.TimedLightsShowLights);
this.SetToolMode(TTLToolMode.ShowLights);
break;
}

case ToolMode.TimedLightsCopyLights: {
case TTLToolMode.CopyLights: {
if (nodeIdToCopy == 0 || !tlsMan.HasTimedSimulation(nodeIdToCopy)) {
MainTool.SetToolMode(ToolMode.TimedLightsSelectNode);
this.SetToolMode(TTLToolMode.SelectNode);
return;
}

Expand Down Expand Up @@ -269,7 +278,7 @@ public override void OnPrimaryClickOverlay() {

Cleanup();
AddSelectedNode(HoveredNodeId);
MainTool.SetToolMode(ToolMode.TimedLightsShowLights);
this.SetToolMode(TTLToolMode.ShowLights);
break;
}
}
Expand All @@ -278,31 +287,31 @@ public override void OnPrimaryClickOverlay() {
public override void OnToolGUI(Event e) {
base.OnToolGUI(e);

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

case ToolMode.TimedLightsShowLights:
case ToolMode.TimedLightsAddNode:
case ToolMode.TimedLightsRemoveNode: {
case TTLToolMode.ShowLights:
case TTLToolMode.AddNode:
case TTLToolMode.RemoveNode: {
GuiTimedTrafficLights();
break;
}

case ToolMode.TimedLightsCopyLights: {
case TTLToolMode.CopyLights: {
GuiTimedTrafficLightsCopy();
break;
}
}
}

public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) {
bool onlySelected = MainTool.GetToolMode() == ToolMode.TimedLightsRemoveNode;
bool onlySelected = ttlToolMode_ == TTLToolMode.RemoveNode;

// Log._Debug($"nodeSelLocked={nodeSelectionLocked} HoveredNodeId={HoveredNodeId}
// IsNodeSelected={IsNodeSelected(HoveredNodeId)} onlySelected={onlySelected}
Expand Down Expand Up @@ -331,19 +340,19 @@ private void GuiTimedControlPanel(int num) {
try {
TrafficLightSimulationManager tlsMan = TrafficLightSimulationManager.Instance;

if (MainTool.GetToolMode() == ToolMode.TimedLightsAddNode ||
MainTool.GetToolMode() == ToolMode.TimedLightsRemoveNode) {
if (ttlToolMode_ == TTLToolMode.AddNode ||
ttlToolMode_ == TTLToolMode.RemoveNode) {
GUILayout.Label(T("TTL.Label:Select junction"));
if (GUILayout.Button(T("Button:Cancel"))) {
MainTool.SetToolMode(ToolMode.TimedLightsShowLights);
this.SetToolMode(TTLToolMode.ShowLights);
} else {
DragWindow(ref _windowRect);
return;
}
}

if (!tlsMan.HasTimedSimulation(selectedNodeIds[0])) {
MainTool.SetToolMode(ToolMode.TimedLightsSelectNode);
this.SetToolMode(TTLToolMode.SelectNode);
// Log._Debug("nodesim or timednodemain is null");
DragWindow(ref _windowRect);
return;
Expand Down Expand Up @@ -809,7 +818,7 @@ private void GuiTimedControlPanel(int num) {
if (GUILayout.Button(T("TTL.Button:Copy"))) {
TrafficManagerTool.ShowAdvisor(this.GetType().Name + "_Copy");
nodeIdToCopy = selectedNodeIds[0];
MainTool.SetToolMode(ToolMode.TimedLightsCopyLights);
this.SetToolMode(TTLToolMode.CopyLights);
}

if (GUILayout.Button(T("TTL.Button:Rotate right"))) {
Expand All @@ -827,15 +836,15 @@ private void GuiTimedControlPanel(int num) {
T("TTL.Button:Add junction to TTL")))
{
TrafficManagerTool.ShowAdvisor(this.GetType().Name + "_AddJunction");
MainTool.SetToolMode(ToolMode.TimedLightsAddNode);
this.SetToolMode(TTLToolMode.AddNode);
}

if (selectedNodeIds.Count > 1) {
if (GUILayout.Button(
T("TTL.Button:Remove junction from TTL")))
{
TrafficManagerTool.ShowAdvisor(this.GetType().Name + "_RemoveJunction");
MainTool.SetToolMode(ToolMode.TimedLightsRemoveNode);
this.SetToolMode(TTLToolMode.RemoveNode);
}
}

Expand All @@ -844,7 +853,7 @@ private void GuiTimedControlPanel(int num) {
if (GUILayout.Button(T("TTL.Button:Remove entire TTL"))) {
DisableTimed();
ClearSelectedNodes();
MainTool.SetToolMode(ToolMode.TimedLightsSelectNode);
this.SetToolMode(TTLToolMode.SelectNode);
}
}

Expand Down Expand Up @@ -1055,11 +1064,11 @@ private void GuiTimedTrafficLightsNode() {
_cursorInSecondaryPanel = false;

_windowRect2 = GUILayout.Window(
252,
_windowRect2,
GuiTimedTrafficLightsNodeWindow,
T("TTL.Window.Title:Select nodes"),
WindowStyle);
id: 252,
screenRect: _windowRect2,
func: GuiTimedTrafficLightsNodeWindow,
text: T("TTL.Window.Title:Select nodes"),
style: WindowStyle);

_cursorInSecondaryPanel = _windowRect2.Contains(Event.current.mousePosition);
}
Expand All @@ -1071,11 +1080,11 @@ private void GuiTimedTrafficLights() {
_cursorInSecondaryPanel = false;

_windowRect = GUILayout.Window(
253,
_windowRect,
GuiTimedControlPanel,
T("Dialog.Title:Timed traffic lights manager"),
WindowStyle);
id: 253,
screenRect: _windowRect,
func: GuiTimedControlPanel,
text: T("Dialog.Title:Timed traffic lights manager"),
style: WindowStyle);

_cursorInSecondaryPanel = _windowRect.Contains(Event.current.mousePosition);

Expand All @@ -1093,11 +1102,11 @@ private void GuiTimedTrafficLightsCopy() {
_cursorInSecondaryPanel = false;

_windowRect2 = GUILayout.Window(
255,
_windowRect2,
GuiTimedTrafficLightsPasteWindow,
T("TTL.Window.Title:Paste"),
WindowStyle);
id: 255,
screenRect: _windowRect2,
func: GuiTimedTrafficLightsPasteWindow,
text: T("TTL.Window.Title:Paste"),
style: WindowStyle);

_cursorInSecondaryPanel = _windowRect2.Contains(Event.current.mousePosition);
}
Expand Down Expand Up @@ -1131,18 +1140,18 @@ private void GuiTimedTrafficLightsNodeWindow(int num) {
ClearSelectedNodes();
}

if (!GUILayout.Button(T("TTL.Button:Setup timed traffic light"))) {
return;
}
if (GUILayout.Button(T("TTL.Button:Setup timed traffic light"))) {
_waitFlowBalance = GlobalConfig.Instance.TimedTrafficLights.FlowToWaitRatio;

_waitFlowBalance = GlobalConfig.Instance.TimedTrafficLights.FlowToWaitRatio;
foreach (ushort nodeId in selectedNodeIds) {
tlsMan.SetUpTimedTrafficLight(nodeId, selectedNodeIds);
RefreshCurrentTimedNodeIds(nodeId);
}

foreach (ushort nodeId in selectedNodeIds) {
tlsMan.SetUpTimedTrafficLight(nodeId, selectedNodeIds);
RefreshCurrentTimedNodeIds(nodeId);
this.SetToolMode(TTLToolMode.ShowLights);
} else {
return;
}

MainTool.SetToolMode(ToolMode.TimedLightsShowLights);
}

DragWindow(ref _windowRect2);
Expand Down Expand Up @@ -1356,12 +1365,7 @@ private void DrawMainLightTexture(RoadBaseAI.TrafficLightState state, Rect rect)
}

public override void ShowGUIOverlay(ToolMode toolMode, bool viewOnly) {
if (!ToolMode.TimedLightsShowLights.Equals(toolMode) &&
!ToolMode.TimedLightsSelectNode.Equals(toolMode) &&
!ToolMode.TimedLightsAddNode.Equals(toolMode) &&
!ToolMode.TimedLightsRemoveNode.Equals(toolMode) &&
!ToolMode.TimedLightsCopyLights.Equals(toolMode)) {
// TODO refactor timed light related tool modes to sub tool modes
if (!ToolMode.TimedTrafficLights.Equals(toolMode)) {
return;
}

Expand Down Expand Up @@ -1508,12 +1512,12 @@ private void ShowGUI() {
GUI.color = guiColor;

var myRect2 = new Rect(
screenPos.x - (manualPedestrianWidth / 2) -
(_timedPanelAdd || _timedEditStep >= 0 ? lightWidth : 0) +
(5f * zoom),
(screenPos.y - manualPedestrianHeight / 2) - (9f * zoom),
manualPedestrianWidth,
manualPedestrianHeight);
x: screenPos.x - (manualPedestrianWidth / 2) -
(_timedPanelAdd || _timedEditStep >= 0 ? lightWidth : 0) +
(5f * zoom),
y: screenPos.y - (manualPedestrianHeight / 2) - (9f * zoom),
width: manualPedestrianWidth,
height: manualPedestrianHeight);

GUI.DrawTexture(
myRect2,
Expand Down
Loading

0 comments on commit e03a672

Please sign in to comment.