Skip to content

Commit

Permalink
Merge pull request #631 from kianzarrin/542-edit-selected-roads
Browse files Browse the repository at this point in the history
added TMPE Road selection panel to Road World Info Panel.
- hovering over one of the Road selection panel the panel renders green path on the selected road.
- when changed the behavior when TMPE tool is set to none: clicking on roads opens the Road World Info Panel. 
- changed the behavior of default tool when TMPE tool is disabled. if mass edit overlay is active, TMPE `RenderoverlayImpl()` and `OnToolGUIImpl` are called.
- Mass edit overlay is enabled for as long as Road World Info Panel is open or Road Adjust Info View is active.
- the road selection panel disappears if Traffic routes info is active.
- Tutorial for road selection panel shows up when Road World Info Panel opens.
- clicking on any of the TMPE Road Selection Buttons (except Clear) activates them setting up 
appropriate traffic rules. Clicking them again deactivates them clearing the related traffic rules.

Changes to Vanilla interface:
- switching to Road Selection Info View shows  Road World Info Panel. this means clicking Adjust Road button does not hide Road World Info Panel.
- switching to Traffic Routes Info View or Junction Info View hides the Road World Info Panel.
- changed the icon of  Road World Info Panel to a road.

Furthur changes:
-Road selection util is an interface that exposes the list of selected segments. Also it provides an event that is invoked whenever selection changes.
- Modified Prioirty Road to add support for for when the main road is not straight.
- Modified Roundabout tool to add more support for semi-roundabout.
- Fixed a bug in linear button to show disabled textures for disabled buttons.
  • Loading branch information
kianzarrin authored Apr 18, 2020
2 parents 07332b0 + d052e02 commit 4fa6a94
Show file tree
Hide file tree
Showing 33 changed files with 1,309 additions and 215 deletions.
17 changes: 8 additions & 9 deletions TLM/TLM/LoadingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace TrafficManager {
using Harmony;
using ICities;
using JetBrains.Annotations;
using UnityEngine;
using Object = UnityEngine.Object;
using System.Collections.Generic;
using System.Reflection;
Expand All @@ -14,7 +15,6 @@ namespace TrafficManager {
using TrafficManager.Manager.Impl;
using TrafficManager.RedirectionFramework;
using TrafficManager.State;
using TrafficManager.UI.Localization;
using TrafficManager.UI;
using static TrafficManager.Util.Shortcuts;
using UnityEngine;
Expand Down Expand Up @@ -339,14 +339,16 @@ public override void OnLevelUnloading() {
GlobalConfig.OnLevelUnloading();

var gameObject = UIView.GetAView().gameObject;
void Destroy<T>() where T : MonoBehaviour {

void Destroy<T>() where T : MonoBehaviour
{
Object obj = (Object)gameObject.GetComponent<T>();
if (obj != null) {
Object.Destroy(obj);
}
}

// remove vehicle button
Destroy<RoadSelectionPanels>();
Destroy<RemoveVehicleButtonExtender>();
Destroy<RemoveCitizenInstanceButtonExtender>();

Expand Down Expand Up @@ -538,12 +540,7 @@ public override void OnLevelLoaded(LoadMode mode) {
}
}

Log.Info("Adding Controls to UI.");
if (ModUI.Instance == null) {
Log._Debug("Adding UIBase instance.");
ModUI.SetSingletonInstance(
ToolsModifierControl.toolController.gameObject.AddComponent<ModUI>());
}
ModUI.OnLevelLoaded();

// Init transport demand UI
if (TransportDemandUI == null) {
Expand All @@ -557,6 +554,8 @@ public override void OnLevelLoaded(LoadMode mode) {
// add "remove citizen instance" button
UIView.GetAView().gameObject.AddComponent<RemoveCitizenInstanceButtonExtender>();

UIView.GetAView().gameObject.AddComponent<RoadSelectionPanels>();

InitDetours();

// Log.Info("Fixing non-created nodes with problems...");
Expand Down
24 changes: 24 additions & 0 deletions TLM/TLM/Patch/_DefaultTool/OnToolGUIPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace TrafficManager.Patch._DefaultTool {
using Harmony;
using JetBrains.Annotations;
using TrafficManager.UI;
using UnityEngine;
using static TrafficManager.UI.SubTools.PrioritySignsTool;

[HarmonyPatch(typeof(DefaultTool), "OnToolGUI")]
[UsedImplicitly]
public static class OnToolGUIPatch {
/// <summary>
/// Renders mass edit overlay even when traffic manager is not current tool.
/// </summary>
[HarmonyPostfix]
[UsedImplicitly]
public static void Postfix(Event e) {
if(ToolsModifierControl.toolController.CurrentTool.GetType() != typeof(TrafficManagerTool)) {
if (MassEditOVerlay.IsActive) {
ModUI.GetTrafficManagerTool(true).OnToolGUIImpl(e);
}
}
}
}
}
25 changes: 25 additions & 0 deletions TLM/TLM/Patch/_DefaultTool/RenderOverlayPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace TrafficManager.Patch._DefaultTool {
using Harmony;
using JetBrains.Annotations;
using TrafficManager.UI;
using static TrafficManager.UI.SubTools.PrioritySignsTool;

[HarmonyPatch(typeof(DefaultTool), "RenderOverlay")]
[UsedImplicitly]
public static class RenderOverlayPatch {
/// <summary>
/// Renders mass edit overlay even when traffic manager is not current tool.
/// </summary>
[HarmonyPostfix]
[UsedImplicitly]
public static void Postfix(RenderManager.CameraInfo cameraInfo) {
if (ToolsModifierControl.toolController.CurrentTool.GetType() != typeof(TrafficManagerTool)) {
if (MassEditOVerlay.IsActive) {
ModUI.GetTrafficManagerTool(true).RenderOverlayImpl(cameraInfo);
}
RoadSelectionPanels.Root.RenderOverlay();
}

}
}
}
41 changes: 41 additions & 0 deletions TLM/TLM/Patch/_InfoManager/SetModePatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace TrafficManager.Patch._InfoManager
{
using ColossalFramework;
using Harmony;
using JetBrains.Annotations;
using TrafficManager.Util;
using TrafficManager.UI;
using UnityEngine;
using static InfoManager;

[HarmonyPatch(typeof(InfoManager), "SetMode")]
[UsedImplicitly]
public static class SetModePatch
{
[UsedImplicitly]
public static void Prefix(InfoMode mode, SubInfoMode subMode)
{
if (RoadSelectionPanels.Root?.RoadWorldInfoPanelExt != null) {
RoadSelectionPanels.Root.RoadWorldInfoPanelExt.isVisible =
mode == InfoMode.None ||
RoadSelectionUtil.IsNetAdjustMode(mode, (int)subMode);
}
if (RoadSelectionUtil.IsNetAdjustMode(mode,(int)subMode))
{
// UI to be handled by Default tool
ModUI.instance_.Close();

SimulationManager.instance.m_ThreadingWrapper.QueueMainThread(delegate () {
DefaultTool.OpenWorldInfoPanel(
Singleton<InstanceManager>.instance.GetSelectedInstance(),
Input.mousePosition);
});
}
else
{
SimulationManager.instance.m_ThreadingWrapper.QueueMainThread(RoadSelectionPanels.RoadWorldInfoPanel.Hide);
}

}
}
}
24 changes: 24 additions & 0 deletions TLM/TLM/Patch/_RoadWorldInfoPanel/OnAdjustRoadButtonPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace TrafficManager.Patch._RoadWorldInfoPanel
{
using ColossalFramework;
using Harmony;
using JetBrains.Annotations;

[HarmonyPatch(typeof(RoadWorldInfoPanel), "OnAdjustRoadButton")]
[UsedImplicitly]
public static class OnAdjustRoadButtonPatch
{
/// <summary>
/// Prefixed to prevent call to Hide.
/// </summary>
/// <param name="mode"></param>
/// <param name="subMode"></param>
/// <returns></returns>
[UsedImplicitly]
public static bool Prefix()
{
Singleton<InfoManager>.instance.SetCurrentMode(InfoManager.InfoMode.TrafficRoutes, InfoManager.SubInfoMode.WindPower);
return false;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
<Compile Include="Manager\Impl\ExtNodeManager.cs" />
<Compile Include="Manager\Impl\ExtSegmentEndManager.cs" />
<Compile Include="Manager\Impl\ExtSegmentManager.cs" />
<Compile Include="Patch\_CitizenManager\ReleaseCitizenPatch.cs" />
<Compile Include="Patch\_DefaultTool\OnToolGUIPatch.cs" />
<Compile Include="Patch\_InfoManager\SetModePatch.cs" />
<Compile Include="Patch\_RoadWorldInfoPanel\OnAdjustRoadButtonPatch.cs" />
<Compile Include="UI\Helpers\NodeLaneMarker.cs" />
<Compile Include="UI\Helpers\Prompt.cs" />
<Compile Include="UI\Helpers\SegmentLaneMarker.cs" />
Expand Down Expand Up @@ -196,7 +200,7 @@
<Compile Include="Manager\Impl\JunctionRestrictionsManager.cs" />
<Compile Include="Manager\Impl\UtilityManager.cs" />
<Compile Include="Manager\Impl\ExtCitizenInstanceManager.cs" />
<Compile Include="Patch\_CitizenManager\ReleaseCitizenPatch.cs" />
<Compile Include="Patch\_DefaultTool\RenderOverlayPatch.cs" />
<Compile Include="Patch\_CitizenManager\ReleaseCitizenInstancePatch.cs" />
<Compile Include="Patch\_NetManager\UpdateSegmentPatch.cs" />
<Compile Include="Patch\_NetManager\FinalizeSegmentPatch.cs" />
Expand Down Expand Up @@ -241,6 +245,7 @@
<Compile Include="LoadingExtension.cs" />
<Compile Include="Traffic\ExtVehicleType.cs" />
<Compile Include="Traffic\Impl\SegmentEnd.cs" />
<Compile Include="UI\RoadSelectionPanels.cs" />
<Compile Include="UI\CustomKeyHandler.cs" />
<Compile Include="UI\Helpers\GuideHandler.cs" />
<Compile Include="UI\Helpers\GuideWrapper.cs" />
Expand Down Expand Up @@ -315,6 +320,7 @@
<Compile Include="Util\MathUtil.cs" />
<Compile Include="Util\LoopUtil.cs" />
<Compile Include="Util\ModsCompatibilityChecker.cs" />
<Compile Include="Util\RoadSelectionUtil.cs" />
<Compile Include="Util\RoundaboutMassEdit.cs" />
<Compile Include="Util\SegmentLaneTraverser.cs" />
<Compile Include="Util\TinyDictionary.cs" />
Expand Down Expand Up @@ -625,6 +631,22 @@
<EmbeddedResource Include="Resources\Translations\Tutorials.csv" />
<EmbeddedResource Include="Resources\Translations\VehicleRestrictions.csv" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\RoadSelectionPanel\Clear-fg-disabled.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\Clear-fg-normal.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\HighPriority-fg-disabled.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\HighPriority-fg-normal.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\Roundabout-fg-disabled.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\Roundabout-fg-normal.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\RoundButton-bg-active.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\RoundButton-bg-disabled.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\RoundButton-bg-hovered.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\RoundButton-bg-normal.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\Stop-fg-disabled.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\Stop-fg-normal.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\Yield-fg-disabled.png" />
<EmbeddedResource Include="Resources\RoadSelectionPanel\Yield-fg-normal.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="PostBuildMacros">
<!-- Code from https://superuser.com/questions/82231/how-do-i-do-comments-at-a-windows-command-prompt -->
Expand Down
4 changes: 2 additions & 2 deletions TLM/TLM/U/Button/BaseUButton.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TrafficManager.U.Button {
namespace TrafficManager.U.Button {
using System;
using ColossalFramework.UI;
using TrafficManager.State.Keybinds;
Expand Down Expand Up @@ -97,7 +97,7 @@ internal void UpdateButtonImage() {
? ControlActiveState.Active
: ControlActiveState.Normal;
ControlEnabledState enabledState =
this.enabled ? ControlEnabledState.Enabled : ControlEnabledState.Disabled;
this.isEnabled ? ControlEnabledState.Enabled : ControlEnabledState.Disabled;

m_BackgroundSprites.m_Normal
= m_BackgroundSprites.m_Disabled =
Expand Down
11 changes: 10 additions & 1 deletion TLM/TLM/U/TextureUtil.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace TrafficManager.U {
namespace TrafficManager.U {
using System;
using System.Collections.Generic;
using ColossalFramework.UI;
using CSUtil.Commons;
using TrafficManager.UI.Textures;
using UnityEngine;
using CSUtil.Commons;
using TrafficManager.State.ConfigData;

public static class TextureUtil {
/// <summary>
Expand Down Expand Up @@ -96,6 +98,13 @@ public static UITextureAtlas Generate2DAtlas(string name,
$"(expected {numX} x {numY}, was {spriteNames.Length})");
}

#if DEBUG
Log._DebugIf(
DebugSwitch.ResourceLoading.Get(),
() => $"Loading atlas for {name} count:{numX}x{numY} " +
$"texture:{texture.name} size:{texture.width}x{texture.height}");
#endif

UITextureAtlas atlas = ScriptableObject.CreateInstance<UITextureAtlas>();
atlas.padding = 0;
atlas.name = name;
Expand Down
11 changes: 11 additions & 0 deletions TLM/TLM/UI/ModUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ public static void EnableTool() {
ToolsModifierControl.SetTool<TrafficManagerTool>();
}

public static void OnLevelLoaded() {
Log._Debug("ModUI.OnLevelLoaded: called");
if (ModUI.Instance == null) {
Log._Debug("Adding UIBase instance.");
ModUI.SetSingletonInstance(
ToolsModifierControl.toolController.gameObject.AddComponent<ModUI>());
}
LoadingExtension.TranslationDatabase.ReloadTutorialTranslations();
LoadingExtension.TranslationDatabase.ReloadGuideTranslations();
}

public static void DisableTool() {
Log._Debug("ModUI.DisableTool: called");
if (ToolsModifierControl.toolController == null) {
Expand Down
Loading

0 comments on commit 4fa6a94

Please sign in to comment.