Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Speed Limits UI #1168

Merged
merged 61 commits into from
Dec 9, 2021
Merged

Conversation

kvakvs
Copy link
Collaborator

@kvakvs kvakvs commented Oct 18, 2021

This introduces:

  • New speed limits UI
  • New overlay for speed limits showing both current override, and defaults, or both (holding Alt). Textures rendered transparent when they overlap with TM:PE UI which reduces the overlay/UI overlapping problem since Harbor DLC.
  • New textures for default speed limits (blue signs), SVG source file with the graphics
  • New texture for no override (circle)
  • MIP mapped textures instead of old aliased textures

bild

TO DO and Bugs:

  • BUG: Changing display MPH option sends event handled by speed limits tool which rebuilds the UI
  • Cosmetic: Move X button to the left because it has a long label
  • Cosmetic: Make cursor tooltip have 2px padding
  • BUG: When TM:PE main panel must close, the Speed limits window must hide and then properly reappear too
  • BUG: Dragging window only works on the title label, make label width to fit window.
  • BUG: Tooltip label on mouse cursor contributes to window size
  • BUG: Changing language does not rebuild window labels in new language
  • BUG: When MoveIt changes road segment, lane signs remain misplaced
  • BUG: Holding Shift in lane mode works on click, but does not highlight with blue sausages
  • BUG: Transparency of signs when colliding with UI windows does not work. The collision boxes seem to be wrong/off. Is something to do with UI scale?
  • BUG: Holding shift to set speed limits for a street not working
  • TODO: How to show that there is no override, or override is same value as the segment default? Old solution was to show white ⭕ and small blue default speed limit (like this but reverse https://user-images.githubusercontent.com/288724/118206586-1a3e8900-b463-11eb-8f10-e4914ddbf4d9.png )
  • Speed limit value buttons sometimes don't accept clicks in their bottom half?
  • Get rid of the tooltip and use existing tooltip helper class, problem when UI scale is different than 100%.
  • Cursor tooltip position is wrong when UI scale is different than 100%
  • Tooltip position blinks for a frame (I think it's worth setting correct position before first render),
  • Add the translation strings
  • opening panel takes way too long IMO (~2sec), lag is consistent, no matter how many times I try, which suggest that panel is build from scratch each time or some really slow operation is running before showing the panel.
  • speed limits overlay (outside tool) does not work, probably because of that:
Error 210.3279831: GUI Error: System.NullReferenceException: Object reference not set to an instance of an object
  at TrafficManager.U.HelperExtensions.GetScreenRectInGuiSpace (ColossalFramework.UI.UIComponent ctrl) [0x00000] in <filename unknown>:0 
  at TrafficManager.UI.SubTools.SpeedLimits.SpeedLimitsTool.CreateOverlayDrawArgs (Boolean interactive) [0x00000] in <filename unknown>:0 
  at TrafficManager.UI.SubTools.SpeedLimits.SpeedLimitsTool.RenderGenericInfoOverlay_GUI () [0x00000] in <filename unknown>:0 
  at TrafficManager.UI.TrafficManagerTool.OnToolGUIImpl (UnityEngine.Event e) [0x00000] in <filename unknown>:0 
   at CSUtil.Commons.Log.LogToFile(System.String log, LogLevel level)
   at CSUtil.Commons.Log.Error(System.String s)
   at TrafficManager.UI.TrafficManagerTool.OnToolGUIImpl(UnityEngine.Event e)
   at TrafficManager.UI.TrafficManagerTool.OnToolGUI(UnityEngine.Event e)
   at ToolBase.OnGUI()
  • Make default overlay view to show signs per whole road, not per direction - just like IRL.
  • (Minor) add some kind of feedback to the user that shown speed limit is averaged value when one or more lanes have different speed.
  • (Minor) since we can't(won't) change default limits per lane, maybe we should hide that from view, so we can reuse the key modifier to switch between handles per-road and per-lane
  • Overlay seems to be cached, so after moving segment it shows sign handles at the same place https://user-images.githubusercontent.com/19638970/141699445-26c3c738-ad0a-4e01-a3ac-cd407ade1fda.png
  • BUG: MoveIt integration trying to copy roads would crash with assertion error trying to apply "no override" to copied lanes
  • BUG: in loading speed limits conversion https://user-images.githubusercontent.com/19638970/141701722-91135805-d4cb-47f4-8f29-0a156c837421.png
  • BUG: in default speed limits view, no matter what the lane/segment toggle is, must only show per segment speed limits, and click must work also regardless that toggle
  • Redesign the tool states: 1st button becomes tri-state: Show segments, show lanes, show defaults. 2nd button is removed. Alt always shows either default speed for this road type or segment speed if defaults is on, and hides whatever other was being rendered.
  • BUG: no overlays when cursor is intersecting with sign, nor when holding shift
  • BUG: when holding alt - shows default speed but you can still click and change overrides
  • BUG: Keybind tooltip is correct but opens junction restrictions tool

@kvakvs kvakvs marked this pull request as draft October 18, 2021 03:34
-#if DEBUG guards for release
Config version bump
Reverted DebugIf to accept a lambda instead of string
Copied and adapted UIScaler logic from Kian's ModTools
SpeedLimits manager uses intent structs for set speed limit action
@krzychu124
Copy link
Member

It's draft, should we wait for the remaining todo's or you think it's ok to review?

@kvakvs
Copy link
Collaborator Author

kvakvs commented Oct 20, 2021

The TODOs changes should be small.
Can review new commits separately.

@DaEgi01
Copy link
Contributor

DaEgi01 commented Oct 21, 2021

The TODOs changes should be small. Can review new commits separately.

I never care for draft PR and would rather review the final one. or is it really a draft in the sense that you want some feedback first before you want to proceed?

@kvakvs
Copy link
Collaborator Author

kvakvs commented Oct 21, 2021

You're welcome to not care for another few days, or can start reviewing right away.
This is a lot of changed lines, half of it are SVG file sources, but the other half is real code.

Copy link
Member

@krzychu124 krzychu124 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, UI nicely separated from the tool 👍
Will test in-game...

@krzychu124
Copy link
Member

Couple findings:

  • cursor tooltip position is wrong when UI scale is different than 100%
  • tooltip position blinks for a frame (I think it's worth setting correct position before first render),
  • opening panel takes way too long IMO (~2sec), lag is consistent, no matter how many times I try, which suggest that panel is build from scratch each time or some really slow operation is running before showing the panel.
  • speed limits overlay (outside tool) does not work, probably because of that:
Error 210.3279831: GUI Error: System.NullReferenceException: Object reference not set to an instance of an object
  at TrafficManager.U.HelperExtensions.GetScreenRectInGuiSpace (ColossalFramework.UI.UIComponent ctrl) [0x00000] in <filename unknown>:0 
  at TrafficManager.UI.SubTools.SpeedLimits.SpeedLimitsTool.CreateOverlayDrawArgs (Boolean interactive) [0x00000] in <filename unknown>:0 
  at TrafficManager.UI.SubTools.SpeedLimits.SpeedLimitsTool.RenderGenericInfoOverlay_GUI () [0x00000] in <filename unknown>:0 
  at TrafficManager.UI.TrafficManagerTool.OnToolGUIImpl (UnityEngine.Event e) [0x00000] in <filename unknown>:0 
   at CSUtil.Commons.Log.LogToFile(System.String log, LogLevel level)
   at CSUtil.Commons.Log.Error(System.String s)
   at TrafficManager.UI.TrafficManagerTool.OnToolGUIImpl(UnityEngine.Event e)
   at TrafficManager.UI.TrafficManagerTool.OnToolGUI(UnityEngine.Event e)
   at ToolBase.OnGUI()
  • apparently bugs reported about issues with loading and storing settings are gone. Cannot reproduce them once I merged this PR into latest master

One thing which once I realized about some time ago, now can't be unseen and would be nice to address it:

  • make default overlay view to show signs per whole road, not per direction - just like IRL.

Other minor things to consider:

  • add some kind of feedback to the user that shown speed limit is averaged value when one or more lanes have different speed.
  • since we can't(won't) change default limits per lane, maybe we should hide that from view, so we can reuse the key modifier to switch between handles per-road and per-lane

@krzychu124
Copy link
Member

I found one more issue:
image

Overlay seems to be cached, so after moving segment it shows sign handles at the same place

@kvakvs
Copy link
Collaborator Author

kvakvs commented Nov 14, 2021

Added the notes to the TODO list, will begin fixing one by one now.

@krzychu124
Copy link
Member

apparently bugs reported about issues with loading and storing settings are gone. Cannot reproduce them once I merged this PR into latest master

Nope, after loading older savegame everything is ok, but once saved and reloaded any lane/segment I touched with speed limits tool is gone. Investigating...

@krzychu124
Copy link
Member

Yup, there is a bug in conversion when loading settings

image

@krzychu124
Copy link
Member

@kvakvs

laneSpeedLimit[laneId] = action.Override.Value.GetKmph();

limit per lane dictionary is filled with Kmph, but then while saving they are treated as GameUnits

foreach (KeyValuePair<uint, float> e in Flags.GetAllLaneSpeedLimits()) {
try {
var laneSpeedLimit = new Configuration.LaneSpeedLimit(
e.Key,
new SpeedValue(e.Value));

TMPE/TLM/TLM/State/Flags.cs

Lines 893 to 899 in b703cc4

internal static IDictionary<uint, float> GetAllLaneSpeedLimits() {
IDictionary<uint, float> ret;
lock(laneSpeedLimitLock) {
ret = new Dictionary<uint, float>(laneSpeedLimit);
}
return ret;

here converting again to Kmph

public LaneSpeedLimit(uint laneId, SpeedValue speed) {
this.laneId = laneId;
this.speedLimit = speed.ToKmphPrecise().Kmph;

Am I missing something here?

@kvakvs
Copy link
Collaborator Author

kvakvs commented Nov 14, 2021

Thanks for investigating
That is the conversion point and i made it safe to that point but i always forget how speeds are stored in the savefile 😀

@krzychu124
Copy link
Member

laneSpeedLimit[laneId] = action.Override.Value.GetKmph();

That lane was changed in previous PR, probably by accident, since the code for loading and saving data is pretty much the same. I did 20? quick saves that's why values were so big.

I haven't found any new issues other than those from previous comments😃 👍

@krzychu124 krzychu124 added this to the 11.6.0 milestone Nov 19, 2021
@krzychu124 krzychu124 added enhancement Improve existing feature SPEED LIMITS Feature: Speed limits labels Nov 19, 2021
@kvakvs
Copy link
Collaborator Author

kvakvs commented Dec 7, 2021

Added cheaper simple changes back. Layout changes are not cheap, the UI allows some of those tricks you desire, and doesn't allow some others, so it quickly becomes messy.

@originalfoo
Copy link
Member

❤️ the new layout!

image

@kvakvs
Copy link
Collaborator Author

kvakvs commented Dec 7, 2021

❤️ the new layout!

The change size was growing, and i yet have to do some other work tonight. We can return to it later, probably, or redo it a bit cleaner.

Copy link
Member

@originalfoo originalfoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested:

✔️ Loading/conversion of speed customisations from v11.5.2 and v11.6.1 saves
✔️ Vanilla + Workshop roads (including some weird roads I had subscribed)
✔️ Lane vs. segment
✔️ Inside/outside central 25 tile area
✔️ km/h vs. mph speeds
✔️ Setting default speeds
✔️ OSD collision transparency
✔️ Camera angles/zooms
✔️ Road vs. tracks
✔️ Short segments
✔️ Asymmetric roads
✔️ 1-way and 2-way roads/tracks
✔️ Esc exits tool

I've not tested save/load yet as another mod is currently breaking my saves. I've not tested monorail/tram-only networks or trolleybus. Those can be tested in future PR.

@kvakvs
Copy link
Collaborator Author

kvakvs commented Dec 7, 2021

If Hold Alt to show defaults is not in this branch i can add it, the change set is short for that.

@originalfoo
Copy link
Member

If Hold Alt to show defaults is not in

It's in (tested via latest appveyor build)

@kvakvs
Copy link
Collaborator Author

kvakvs commented Dec 7, 2021

If Hold Alt to show defaults is not in

It's in (tested via latest appveyor build)

I mean holding Alt and editing defaults, and holding Alt in defaults and editing overrides.
It is in now, just pushed.

@originalfoo
Copy link
Member

Regarding minor task in OP:

(Minor) add some kind of feedback to the user that shown speed limit is averaged value when one or more lanes have different speed.

Maybe:

  • Use basic circle icon (similar to default speeds, but different colour/shape)?
  • Or, rotate the icon by 45 degrees? Or make bigger than normal?
  • Or, force per-lane speed display on segments that have lanes with different speeds? (might clutter overlay tho)

If leaving to later PR, add to #1221 to track.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve existing feature Overlays Overlays, data vis, etc. SPEED LIMITS Feature: Speed limits UI User interface updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants