Skip to content

Commit

Permalink
Heinous Junction Restrictions overlay (#845)
Browse files Browse the repository at this point in the history
* Moved Overlay rendering parts to a separate class in PrioritySigns tool
* PrioritySigns Overlay is not a stateful struct
* More cleanup for PrioritySigns overlay
* Overlay for view and edit of junction restrictions now looks consistent
* Remove 2 trash documentation comments
* -use CalculateCorner for more precise calculations.
-define constants to make sure sign sizes have harmony in both normal mode and view mode.
- simplified the code.
* Style changes and renaming
* cached corner calculations
* calculate corners In NetSegment.CalcualteSegment.Postfix()
* corner cache is initialzed on startup.

Co-authored-by: kian.zarrin <kian.zarrin@gmail.com>
  • Loading branch information
kvakvs and kianzarrin authored Apr 28, 2020
1 parent 0725f9a commit 78cd4a7
Show file tree
Hide file tree
Showing 17 changed files with 694 additions and 571 deletions.
39 changes: 39 additions & 0 deletions TLM/TLM/Manager/Impl/ExtSegmentEndManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace TrafficManager.Manager.Impl {
using TrafficManager.API.Manager;
using TrafficManager.API.Traffic.Data;
using TrafficManager.State.ConfigData;
using TrafficManager.Util;
using UnityEngine;

public class ExtSegmentEndManager
Expand Down Expand Up @@ -288,6 +289,32 @@ private void Recalculate(ref ExtSegmentEnd segEnd) {
}
}

/// <summary>
/// This recalcualtion must requires to be called after CalcualteSegment(). therefore it is not being called together
/// with other calculations.
/// </summary>
/// <param name="segmentId"></param>
/// <param name="startNode"></param>
public void CalculateCorners(ushort segmentId, bool startNode) {
ref ExtSegmentEnd segEnd = ref ExtSegmentEnds[GetIndex(segmentId, startNode)];
segmentId.ToSegment().CalculateCorner(
segmentID: segmentId,
heightOffset: true,
start: startNode,
leftSide: false,
cornerPos: out segEnd.RightCorner,
cornerDirection: out segEnd.RightCornerDir,
smooth: out _);
segmentId.ToSegment().CalculateCorner(
segmentID: segmentId,
heightOffset: true,
start: startNode,
leftSide: true,
cornerPos: out segEnd.LeftCorner,
cornerDirection: out segEnd.LeftCornerDir,
smooth: out _);
}

private void CalculateIncomingOutgoing(ushort segmentId,
ushort nodeId,
out bool incoming,
Expand Down Expand Up @@ -464,6 +491,18 @@ protected override void InternalPrintDebugInfo() {
}
}

public override void OnLevelLoading() {
base.OnLevelLoading();
Log._Debug($"ExtSegmentEndManager.OnLevelLoading: Calculating {ExtSegmentEnds.Length} " +
"extended segment ends...");

for (int i = 0; i < ExtSegmentEnds.Length; ++i) {
// TODO [issue #872]: move CalculateCorners to Recalculate().
CalculateCorners(ExtSegmentEnds[i].segmentId, ExtSegmentEnds[i].startNode);
}
Log._Debug($"ExtSegmentEndManager.OnLevelLoading: Calculation finished.");
}

public override void OnLevelUnloading() {
base.OnLevelUnloading();

Expand Down
3 changes: 1 addition & 2 deletions TLM/TLM/Patch/_DefaultTool/OnToolGUIPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace TrafficManager.Patch._DefaultTool {
using JetBrains.Annotations;
using TrafficManager.UI;
using UnityEngine;
using static TrafficManager.UI.SubTools.PrioritySignsTool;

[HarmonyPatch(typeof(DefaultTool), "OnToolGUI")]
[UsedImplicitly]
Expand All @@ -15,7 +14,7 @@ public static class OnToolGUIPatch {
[UsedImplicitly]
public static void Postfix(Event e) {
if(ToolsModifierControl.toolController.CurrentTool.GetType() != typeof(TrafficManagerTool)) {
if (MassEditOVerlay.IsActive) {
if (UI.SubTools.PrioritySigns.MassEditOverlay.IsActive) {
ModUI.GetTrafficManagerTool(true).OnToolGUIImpl(e);
}
}
Expand Down
3 changes: 1 addition & 2 deletions TLM/TLM/Patch/_DefaultTool/RenderOverlayPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace TrafficManager.Patch._DefaultTool {
using Harmony;
using JetBrains.Annotations;
using TrafficManager.UI;
using static TrafficManager.UI.SubTools.PrioritySignsTool;

[HarmonyPatch(typeof(DefaultTool), "RenderOverlay")]
[UsedImplicitly]
Expand All @@ -14,7 +13,7 @@ public static class RenderOverlayPatch {
[UsedImplicitly]
public static void Postfix(RenderManager.CameraInfo cameraInfo) {
if (ToolsModifierControl.toolController.CurrentTool.GetType() != typeof(TrafficManagerTool)) {
if (MassEditOVerlay.IsActive) {
if (UI.SubTools.PrioritySigns.MassEditOverlay.IsActive) {
ModUI.GetTrafficManagerTool(true).RenderOverlayImpl(cameraInfo);
}
RoadSelectionPanels.Root.RenderOverlay();
Expand Down
16 changes: 16 additions & 0 deletions TLM/TLM/Patch/_NetSegment/CalculateSegmentPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TrafficManager.Patch._NetSegment {
using Harmony;
using JetBrains;
using JetBrains.Annotations;
using TrafficManager.Manager.Impl;

[HarmonyPatch(typeof(NetSegment), nameof(NetSegment.CalculateSegment))]
[UsedImplicitly]
public class CalculateSegmentPatch {
[UsedImplicitly]
public static void Postfix(ushort segmentID) {
ExtSegmentEndManager.Instance.CalculateCorners(segmentID, false);
ExtSegmentEndManager.Instance.CalculateCorners(segmentID, true);
}
}
}
10 changes: 5 additions & 5 deletions TLM/TLM/State/OptionsTabs/OptionsOverlaysTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ internal static void MakeSettings_Overlays(ExtUITabstrip tabStrip) {
onVehicleOverlayChanged) as UICheckBox;
_citizenOverlayToggle = panelHelper.AddCheckbox(
Translation.Options.Get("Overlay.Checkbox:Citizens"),
Options.citizenOverlay,
onCitizenOverlayChanged) as UICheckBox;
Options.citizenOverlay,
onCitizenOverlayChanged) as UICheckBox;
_buildingOverlayToggle = panelHelper.AddCheckbox(
Translation.Options.Get("Overlay.Checkbox:Buildings"),
Options.buildingOverlay,
onBuildingOverlayChanged) as UICheckBox;
Options.buildingOverlay,
onBuildingOverlayChanged) as UICheckBox;
#endif
}

Expand All @@ -93,7 +93,7 @@ public static void SetPrioritySignsOverlay(bool newPrioritySignsOverlay) {
ModUI.GetTrafficManagerTool(false)?.InitializeSubTools();
}

public static void SetTimedLightsOverlay(bool newTimedLightsOverlay) {
public static void SetTimedLightsOverlay(bool newTimedLightsOverlay) {
Options.timedLightsOverlay = newTimedLightsOverlay;

if (_timedLightsOverlayToggle != null) {
Expand Down
5 changes: 4 additions & 1 deletion TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<Compile Include="Patch\_CitizenManager\ReleaseCitizenPatch.cs" />
<Compile Include="Patch\_DefaultTool\OnToolGUIPatch.cs" />
<Compile Include="Patch\_InfoManager\SetModePatch.cs" />
<Compile Include="Patch\_NetSegment\CalculateSegmentPatch.cs" />
<Compile Include="Patch\_RoadWorldInfoPanel\OnAdjustRoadButtonPatch.cs" />
<Compile Include="UI\Helpers\NodeLaneMarker.cs" />
<Compile Include="UI\Helpers\Prompt.cs" />
Expand Down Expand Up @@ -284,6 +285,9 @@
<Compile Include="UI\SubTools\LaneArrows\LaneArrowTool.cs" />
<Compile Include="UI\SubTools\LaneArrows\LaneArrowToolWindow.cs" />
<Compile Include="UI\SubTools\ParkingRestrictionsTool.cs" />
<Compile Include="UI\SubTools\PrioritySigns\MassEditOverlay.cs" />
<Compile Include="UI\Helpers\TrafficRulesOverlay.cs" />
<Compile Include="UI\SubTools\PrioritySigns\PrioritySignsTool.cs" />
<Compile Include="UI\SubTools\SpeedLimits\MphSignStyle.cs" />
<Compile Include="UI\SubTools\SpeedLimits\SpeedLimitsTool.cs" />
<Compile Include="UI\SubTools\SpeedLimits\SpeedUnit.cs" />
Expand All @@ -303,7 +307,6 @@
<Compile Include="UI\SubTools\LaneConnectorTool.cs" />
<Compile Include="UI\SubTools\VehicleRestrictionsTool.cs" />
<Compile Include="UI\SubTools\ManualTrafficLightsTool.cs" />
<Compile Include="UI\SubTools\PrioritySignsTool.cs" />
<Compile Include="UI\SubTools\ToggleTrafficLightsTool.cs" />
<Compile Include="State\Options.cs" />
<Compile Include="Manager\Impl\SpeedLimitManager.cs" />
Expand Down
Loading

0 comments on commit 78cd4a7

Please sign in to comment.