Skip to content

Commit 559b624

Browse files
committed
New enhancment: Now you can use Escape key to close Traffic Manager without returning to Pause Menu
1 parent c1fc56f commit 559b624

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ A modification for **Cities: Skylines** to add additional traffic control.
44
User manual: http://www.viathinksoft.de/tmpe/wiki
55

66
# Changelog
7+
1.10.15,
8+
- Enhancement: Now you can use Escape key to close Traffic Manager without returning to Pause Menu
9+
- Updated pathfinding with missing vanilla logic
10+
711
1.10.14, 27/01/2019
812
- Bugfix: Added missing Car AI type (postVanAI) - now post vans and post trucks are assigned to service vehicles group
913
- Bugfix: Vehicles doesn't stop when driving through toll booth - fixes toll booth income too

TLM/TLM/TLM.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -205,6 +205,7 @@
205205
<Compile Include="Custom\PathFinding\CustomPathManager.cs" />
206206
<Compile Include="Geometry\Impl\SegmentGeometry.cs" />
207207
<Compile Include="LoadingExtension.cs" />
208+
<Compile Include="UI\CustomKeyHandler.cs" />
208209
<Compile Include="UI\RemoveCitizenInstanceButtonExtender.cs" />
209210
<Compile Include="UI\RemoveVehicleButtonExtender.cs" />
210211
<Compile Include="UI\MainMenu\LaneConnectorButton.cs" />

TLM/TLM/UI/CustomKeyHandler.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using ColossalFramework.UI;
2+
using CSUtil.Commons;
3+
using UnityEngine;
4+
5+
namespace TrafficManager.UI {
6+
public class CustomKeyHandler : UICustomControl {
7+
//TODO add more key bindings or refactor to mod key shortcut manager
8+
9+
public void OnKeyDown(UIComponent comp, UIKeyEventParameter p)
10+
{
11+
if (p.used || p.keycode != KeyCode.Escape)
12+
return;
13+
Log._Debug("CustomKeyHandler::OnKeyDown(KeyCode.Escape) call");
14+
p.Use();
15+
}
16+
}
17+
}

TLM/TLM/UI/UIBase.cs

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public UIBase() {
4343

4444
// add the menu
4545
MainMenu = (MainMenuPanel)uiView.AddUIComponent(typeof(MainMenuPanel));
46+
MainMenu.gameObject.AddComponent<CustomKeyHandler>();
4647
#if DEBUG
4748
DebugMenu = (DebugMenuPanel)uiView.AddUIComponent(typeof(DebugMenuPanel));
4849
#endif
@@ -52,6 +53,9 @@ public UIBase() {
5253

5354
~UIBase() {
5455
UnityEngine.Object.Destroy(MainMenuButton);
56+
CustomKeyHandler keyHandler = MainMenu.GetComponent<CustomKeyHandler>();
57+
if(keyHandler != null)
58+
UnityEngine.Object.Destroy(keyHandler);
5559
}
5660

5761
public bool IsVisible() {
@@ -68,13 +72,18 @@ public void ToggleMainMenu() {
6872
internal void RebuildMenu() {
6973
Close();
7074
if (MainMenu != null) {
75+
CustomKeyHandler keyHandler = MainMenu.GetComponent<CustomKeyHandler>();
76+
if(keyHandler != null)
77+
UnityEngine.Object.Destroy(keyHandler);
78+
7179
UnityEngine.Object.Destroy(MainMenu);
7280
#if DEBUG
7381
UnityEngine.Object.Destroy(DebugMenu);
7482
#endif
7583
}
7684
var uiView = UIView.GetAView();
7785
MainMenu = (MainMenuPanel)uiView.AddUIComponent(typeof(MainMenuPanel));
86+
MainMenu.gameObject.AddComponent<CustomKeyHandler>();
7887
#if DEBUG
7988
DebugMenu = (DebugMenuPanel)uiView.AddUIComponent(typeof(DebugMenuPanel));
8089
#endif
@@ -99,6 +108,7 @@ public void Show() {
99108
SetToolMode(TrafficManagerMode.Activated);
100109
_uiShown = true;
101110
MainMenuButton.UpdateSprites();
111+
UIView.SetFocus(MainMenu);
102112
}
103113

104114
public void Close() {

0 commit comments

Comments
 (0)