Skip to content

Commit

Permalink
New Speed Limits UI (#1168)
Browse files Browse the repository at this point in the history
New Speed Limits UI

* Config version bump
* Copied and adapted UIScaler logic from Kian's ModTools
* SpeedLimits manager uses intent structs for set speed limit action
* Speed Limits UI: New textures, new overlay and util classes
* Speed limits Translations: English, Russian, Ukrainian, Polish, German etc
* Events in ModUI grouped into a inner class; New event for UI Language changed
* Overlay drawing code moved
* Down arrow is rendered for speed limit icons of underground nodes
* Underground nodes don't show in overground mode. Added hint for that
* Increase max overlay distance for road signs. Render road without override as fullsize blue, not white circle.
* Reload atlases in debug but keep in release
* Green road signs; / and Delete keybinds
* Ctrl, select +- keys, slash, delete keys; Translations for new keybinds
* Overlay icons do not fade; UI intersection test now checks OSD panel.
* Unlimited button is now placed last, and behaves like a speed override
* Holding Alt shows defauls; Holding Alt in defaults shows override; Allows editing
* Translations; UI buttons 40px now to match main menu; Minor corrections

Co-authored-by: kianzzarrin <kian.zarrin@gmail.com>
  • Loading branch information
kvakvs and kianzarrin committed Dec 9, 2021
1 parent 2529372 commit 08cf09f
Show file tree
Hide file tree
Showing 119 changed files with 8,909 additions and 2,241 deletions.
18 changes: 17 additions & 1 deletion TLM/TLM/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace TrafficManager {
using TrafficManager.API.Manager;
using UnityEngine;
using TrafficManager.API.Notifier;
using TrafficManager.U;

public static class Constants {
/// <summary>
Expand All @@ -22,8 +23,23 @@ public static class Constants {
public const float SPEED_TO_MPH = 32.06f; // 50 km/h converted to mph

/// <summary>
/// The maximum amount of segments a node can hold.
/// Screen pixel size for overlay signs, such as one-per-segment speed limits.
/// </summary>
public static float OverlaySignVisibleSize => 100.0f * UIScaler.UIScale;

/// <summary>
/// World size for clickable signs used in overlays. Larger than readonly signs.
/// This is used as offset in grids of signs such as lane speed limit signs.
/// </summary>
public const float OVERLAY_INTERACTIVE_SIGN_SIZE = 6.0f;

/// <summary>
/// World size for readonly signs used in overlays.
/// This is used as offset in grids of signs such as lane speed limit signs.
/// </summary>
public const float OVERLAY_READONLY_SIGN_SIZE = 3.8f;

/// <summary>The maximum amount of segments a node can hold.</summary>
public const int MAX_SEGMENTS_OF_NODE = 8;

public static float ByteToFloat(byte b) {
Expand Down
2 changes: 2 additions & 0 deletions TLM/TLM/Manager/Impl/AdvancedParkingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,8 @@ bool citizenDebug
} // if find parking prop at building

buildingId = building.m_nextGridBuilding;
building = ref buildingId.ToBuilding();

if (++numIterations >= 49152) {
CODebugBase<LogChannel>.Error(
LogChannel.Core,
Expand Down
59 changes: 38 additions & 21 deletions TLM/TLM/Manager/Impl/SpeedLimitManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ or ItemClass.SubService.PublicTransportMetro
laneIndex++;
}

if (validLanes > 0) {
meanSpeedLimit = meanSpeedLimit.Scale(1.0f / validLanes);
switch (validLanes) {
case 0:
return null;
case > 0:
return meanSpeedLimit.Scale(1.0f / validLanes);
}

return meanSpeedLimit;
}

/// <summary>
Expand Down Expand Up @@ -434,12 +435,6 @@ or ItemClass.SubService.PublicTransportMetro
return;
}

// Resharper warning: condition always false
// if (info.name == null) {
// Log._DebugOnlyWarning($"SetCustomNetInfoSpeedLimitIndex: info.name is null!");
// return;
// }

string infoName = info.name;
customLaneSpeedLimitByNetInfoName_[infoName] = customSpeedLimit;
float gameSpeedLimit = ToGameSpeedLimit(customSpeedLimit);
Expand Down Expand Up @@ -497,6 +492,13 @@ or ItemClass.SubService.PublicTransportMetro
lane.m_speedLimit = gameSpeedLimit;
}
}

for(ushort segmentId = 1; segmentId < NetManager.MAX_SEGMENT_COUNT; ++segmentId) {
ref var segment = ref segmentId.ToSegment();
if (segment.IsValid() && segment.Info == info) {
Notifier.Instance.OnSegmentModified(segmentId, this);
}
}
}

/// <summary>Sets the speed limit of a given lane.</summary>
Expand All @@ -511,10 +513,14 @@ or ItemClass.SubService.PublicTransportMetro
return false;
}

Log._Assert(action.Override != null, "action.Override != null");
if (action.Type == SetSpeedLimitAction.ActionType.ResetToDefault) {
Flags.RemoveLaneSpeedLimit(laneId);
Notifier.Instance.OnSegmentModified(segmentId, this);
return true;
}

if (action.Type != SetSpeedLimitAction.ActionType.ResetToDefault
&& !IsValidRange(action.Override.Value.GameUnits)) {
&& !IsValidRange(action.GuardedValue.Override.GameUnits)) {
return false;
}

Expand All @@ -523,15 +529,18 @@ or ItemClass.SubService.PublicTransportMetro
return false;
}

if (action.Type != SetSpeedLimitAction.ActionType.ResetToDefault) {
Flags.SetLaneSpeedLimit(segmentId, laneIndex, laneId, action);
} else {
Flags.RemoveLaneSpeedLimit(laneId);
}
Flags.SetLaneSpeedLimit(segmentId, laneIndex, laneId, action);

Notifier.Instance.OnSegmentModified(segmentId, this);
return true;
}

public void ResetCustomDefaultSpeedlimit([NotNull] string netinfoName) {
if (this.customLaneSpeedLimitByNetInfoName_.ContainsKey(netinfoName)) {
this.customLaneSpeedLimitByNetInfoName_.Remove(netinfoName);
}
}

/// <summary>Sets speed limit for all configurable lanes.</summary>
/// <param name="action">Speed limit in game units, or null to restore defaults.</param>
/// <returns>
Expand Down Expand Up @@ -562,10 +571,8 @@ or ItemClass.SubService.PublicTransportMetro
return false;
}

Log._Assert(action.Override != null, "action.Override != null");

if (action.Type == SetSpeedLimitAction.ActionType.SetOverride
&& !IsValidRange(action.Override.Value.GameUnits)) {
&& !IsValidRange(action.GuardedValue.Override.GameUnits)) {
return false;
}

Expand Down Expand Up @@ -601,7 +608,7 @@ or ItemClass.SubService.PublicTransportMetro
Flags.RemoveLaneSpeedLimit(curLaneId);
} else {
bool showMph = GlobalConfig.Instance.Main.DisplaySpeedLimitsMph;
string overrideStr = action.Override.Value.FormatStr(showMph);
string overrideStr = action.GuardedValue.Override.FormatStr(showMph);

Log._Debug(
$"SpeedLimitManager: Setting lane {curLaneId} to {overrideStr}");
Expand All @@ -613,6 +620,7 @@ or ItemClass.SubService.PublicTransportMetro
laneIndex++;
}

Notifier.Instance.OnSegmentModified(segmentId, this);
return true;
}

Expand Down Expand Up @@ -1029,5 +1037,14 @@ or ItemClass.SubService.PublicTransportMetro
public static bool IsValidRange(float speed) {
return FloatUtil.IsZero(speed) || (speed >= MIN_SPEED && speed <= SpeedValue.UNLIMITED);
}

/// <summary>
/// Used to check roads if they're a known and valid asset.
/// This will filter out helper roads which are created during public transport route setup.
/// </summary>
// ReSharper restore Unity.ExpensiveCode
public bool IsKnownNetinfoName(string infoName) {
return this.vanillaLaneSpeedLimitsByNetInfoName_.ContainsKey(infoName);
}
} // end class
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 08cf09f

Please sign in to comment.