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

Speed Limit tool - Lane highlighting #709

Merged

Conversation

kianzarrin
Copy link
Collaborator

@kianzarrin kianzarrin commented Feb 17, 2020

fixes #682

highlight the affected lanes when user hovers speed limit sprite.

  • highlight color is blue. when mouse button is pressed the highlight is emboldened and becomes orange.
  • If in per lane mode one lane is highlighted. holding shift highlights that lane on the entirety of the road.
  • if in directional mode EDIT:all lanes in that direction are highlighted. they highlights are much thicker so that they would merge together as one. holding shift will highlight all affected lanes on that road. appropriate side of the segment is highlighted.

Screenshot (527)
Cities_9dZikiSpXP

EDIT: I made major changes:

  • TrafficManagerTool has a new method to render only one side of a segment see screenshots
  • restored priority sings tool dust bin sprite from old TMPE. I renamed it to clear.png and put it in a central place to be accessed from multiple places. (Priority Signs: Interaction model is whack #77)
  • added new button to restore speed limits to default value. it uses clear.png sprite.
  • created back-end to reset speed limit to default state.
  • the UI panel has a new toggle to apply changes to entire road. This was handled with shift modifier (which still works)
  • pressing shift will toggle "entire road" mode. Pressing the toggle has the same effect. if the toggle is active, shift will deactivate multi-lane mode. When user pressed/releases shift, the toggle gets checked/unchecked to give visual feedback.
  • ShowPerLane toggle works in the same way as "entire road" toggle but with CTRL key.
  • The text of the toggles show the modifier key.

EDIT: I forgot to mention I introduced a couple methods/properties to Lane/Sagement traverse data structures and put some commonly used code in there.

Test:

  • I tested both with LHT and RHT
  • I tried swaping start and end node of segments
  • I tired inverting the segments.

Screenshot (571)

@originalfoo
Copy link
Member

It went a bit bonkers on LHT map (mouse was over the icon at top of pic, but lanes at bottom of pic were highlighted):

image

@originalfoo
Copy link
Member

originalfoo commented Feb 17, 2020

Interestingly, when I hold down Ctrl key for lane-mode, it was highlighting correct lanes.

Seems the inversion issue is only affecting direction-mode.

@originalfoo
Copy link
Member

originalfoo commented Feb 17, 2020

In cases where two icons are hovered at same time in lane-mode, only one lane gets highligted:

image

I use the little trick of hovering the overlap in icons to set both at same time quite often.

EDIT: Same in direciton mode:

image

@originalfoo
Copy link
Member

I suspect this is due to direction inversion issue on LHT maps - it's one way roundabout, in direction mode:

image

@originalfoo originalfoo added Overlays Overlays, data vis, etc. SPEED LIMITS Feature: Speed limits UI User interface updates Usability Make mod easier to use labels Feb 17, 2020
@originalfoo originalfoo self-requested a review February 17, 2020 12:36
@originalfoo originalfoo added this to the 11.1.1 milestone Feb 17, 2020
@kianzarrin
Copy link
Collaborator Author

I replaced m_direction with m_finalDirection. This is fixed now.

I need to develop a test check list because I keep forgetting to test in all possible circumstances.

Copy link
Collaborator

@kvakvs kvakvs left a comment

Choose a reason for hiding this comment

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

The amount of if (something) conditions is getting out of hand.
Is not a blocker for this PR but there should be a way to reduce nesting and reduce the cyclomatic complexity (amount of code branching to keep in head while reading) for the future code.

@@ -9,6 +9,7 @@ internal class SegmentLaneMarker {
}

internal Bezier3 Bezier;
internal float size = 1.1f;
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this a const? Can it change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it does change.

@@ -200,12 +312,15 @@ public SpeedLimitsTool(TrafficManagerTool mainTool)
}

// no speed limit overlay on selected segment when in vehicle restrictions mode
DrawSpeedLimitHandles(
hover|= DrawSpeedLimitHandles(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing a space.

@kianzarrin
Copy link
Collaborator Author

@kvakvs The amount of if (something) conditions is getting out of hand.

"cyclomatic complexity" ... interesting concept.

how should I do this though? move branches into sub methods?

Note that when the user holds shift, FPS drops because the code goes though a big ass slow for loop. as an optimization effort I created a separate code path for when shift is not pressed so that in most cases FPS is high. I haven't performed any benchmark though. I could do some caching too but the FPS seems fine on my slow computer so I didn't bother.

@kvakvs
Copy link
Collaborator

kvakvs commented Feb 18, 2020

If you later revisit this code, yes, please split logic into functions and reduce the nesting.
You will notice that a lot of values are carried between calls and those represent state of this logic flow and maybe deserve their own storage class or struct. The resulting code will be simpler and that is good.

@originalfoo
Copy link
Member

There's another performance hit with speed limits -- and maybe other tools, haven't checked -- in that to facilitate user being able to 'drag a speed' along a series of segments... this: #388 (not relevant to this PR but something to consider for future performance tuning)

@originalfoo originalfoo changed the title speedlimit lane highlight Speed Limit tool - Lane highlighting Feb 18, 2020
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 in-game, LGTM from end-user perspective 👍

@originalfoo originalfoo added the DO NOT MERGE YET Don't merge this PR, even if approved, until further notice label Feb 18, 2020
@originalfoo
Copy link
Member

Need to do some more testing on this; found some issues with parking lane higlight in other PR and need to see if issues also apply to speed limits.

@originalfoo
Copy link
Member

Retested, only one minor issue found - if two signs hovered at same time, only one lane is highlighting (yet both lanes would be updated if I clicked):

image

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.

If two icons hovered at same time, please highlight all affected lanes not just lanes for one icon.

@originalfoo originalfoo removed the DO NOT MERGE YET Don't merge this PR, even if approved, until further notice label Feb 18, 2020
@kianzarrin
Copy link
Collaborator Author

improved highlighting of segment side:

Screenshot (528)

Cities_UGnW8PubnV

@kianzarrin
Copy link
Collaborator Author

@aubergine10 If two icons hovered at same time, please highlight all affected lanes not just lanes for one icon.

this is more like a bug (you view it as a trick). In any case I increased the distance of the sprites so they do not overlap any more.

@originalfoo
Copy link
Member

I'd suggest Reset instead of Clear ("Clear" is a bit ambiguous; might give impression the speed limit is being removed rather than reset to whatever its default is).

@kvakvs
Copy link
Collaborator

kvakvs commented Feb 20, 2020

Do not bake keys into translation strings on Crowdin, just do + "[Del]" for now and i can deal with it later.

@kianzarrin
Copy link
Collaborator Author

@aubergine10 ! I renamed clear to to default. The screenshot are a commit too old.

@kvakvs Do not bake keys into translation

Of course . if you look at the code you will notice its not part of the translation.

@originalfoo
Copy link
Member

originalfoo commented Feb 20, 2020

Is there a way to constrain the highlight to where the lanes are - currently it goes over pavement and sometimes cuts in to other side of road too:

image

image

Road in screenshots is asymmetric road from UK Roads - Small Roads

@originalfoo
Copy link
Member

Sometimes it looks a bit weird, eg. when apply to whole road and there's a corner in the road:

image

@originalfoo
Copy link
Member

2-lane 1-way road, only half road highligted (direction mode):

image

@originalfoo
Copy link
Member

@kianzarrin Did you get chance to update the direction-mode lane highlights? Everything else in this PR is good to go.

@kianzarrin
Copy link
Collaborator Author

I restored the old lane highlighting method.

On bend nodes I am either going to get this (currently this is what we get):
Cities_ldBlcTMrYh

or this:

Unless if I do some super clever stuff which is a can of worms I do not want to open right now.

@kianzarrin
Copy link
Collaborator Author

I tested this on LHT with invert flag on and off and both directions of start/end nodes.

@originalfoo
Copy link
Member

originalfoo commented Feb 24, 2020

For the corners, I prefer the gap rather than the weird overlap.

Will test latest commits now...

@originalfoo
Copy link
Member

Wrong translation key on the reset button in speed palette?

image

Other than that, looks good.

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Feb 24, 2020

Crowdin translations are in and i changed Checkbox:Default to Button:Default
@aubergine10 are you happy?
Screenshot (581)

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.

LGTM 👍

@kianzarrin kianzarrin merged commit 3d5a286 into CitiesSkylinesMods:master Feb 24, 2020
@kianzarrin kianzarrin deleted the 682-speedlimit-overlay branch February 24, 2020 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Overlays Overlays, data vis, etc. SPEED LIMITS Feature: Speed limits UI User interface updates Usability Make mod easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add lane highlight to Speed Limits tool
3 participants