OpenTTD icon indicating copy to clipboard operation
OpenTTD copied to clipboard

[WIP] Change: add support for next/previous railtype global hotkeys

Open grossws opened this issue 5 years ago • 13 comments

This patch adds support for next/prev railtype global hotkeys which are basically autorail + special modifier which selects previous or next available railtype.

Such behaviour is useful for players who use PURR, Useless Tracks and similar NewGRFs for quick selection.

I use PURR with semantic tracks coloring (e.g. white purr for waiting bays, red purr for prio zones etc).

Current patch binds this feature to GLOBAL+[ and GLOBAL+].

UPD If user explicitly selected some widget in railway build toolbar it won't switch to autorail.

Signed-off-by: Konstantin Gribov [email protected]

grossws avatar Dec 01 '19 22:12 grossws

This needs to be tested with keyboard layouts where the [ ] characters are on AltGr combinations with the number row. (Several continental European layouts.)

nielsmh avatar Dec 02 '19 12:12 nielsmh

@nielsmh, I tested it on Linux w/ SDL2 and default German layout where [/] are on AltGr+8/9. Hotkeys work as expected when PR #7850 is applied, on same keys where [/] are on US layout.

grossws avatar Dec 02 '19 21:12 grossws

Some additional thoughts about this feature. Currently it switches to autorail but better in UX terms would be to stay with same chosen widget if one is selected.

Then you can just switch railtype on the fly with say converse or depot instead of switching railtype and choosing converse/depot/whatever after that. Behavior when rail building tools are inactive should stay the same: choose railtype and activate autorail.

grossws avatar Dec 07 '19 18:12 grossws

@LordAro, ok, I'll fix things mentioned above. In case of code style I just did by example and got smacked by CI once)

Anyway, I will mark this as work-in-progress since I wish to change some logic (see https://github.com/OpenTTD/OpenTTD/pull/7851#issuecomment-562877015)

grossws avatar Dec 24 '19 12:12 grossws

hi @grossws : exactly a year later, as if I planned this! (I did not :D). I was wondering if you are still interested in seeing this PR through? It seems you have a few comments open that needs resolving .. would be cool if you could! Tnx!

TrueBrain avatar Dec 24 '20 20:12 TrueBrain

Is it extensible to roadtypes also? :D No problem if not, just curious.

andythenorth avatar Dec 24 '20 20:12 andythenorth

@TrueBrain, I can possibly look into this and update PR but after Jan, 7th when I return from vacation. Quite eventful year it was ,)

@andythenorth, didn't look into that, but it may be possible if it has similar implementation. I don't recall different road types at all, could you point what additional GRFs should I have to check that?

grossws avatar Dec 28 '20 14:12 grossws

Possible modification: instead of adding RailToolbarWidgetModifiers enum just add prev/next_railtype to RailToolbarWidgets with explicit constants like 0xfd/0xfe.

Initially I put them into separate enum because I thought that it would be confusing to have WID_RAT_* enum values not represented in toolbar as a button. But caption already exists, so maybe it's not the case.

Also, GHK_MOD_RAT_* became simple special hotkeys and not actually modifiers for WID_RAT_AUTORAIL, another point to putting them into RailToolbarWidgets enum.

grossws avatar Jan 14 '21 00:01 grossws

@TrueBrain, did you have some time to review this PR?

grossws avatar Feb 09 '21 16:02 grossws

@ldpl, I'll comment on most of the review comment here.

I [snip] think this implementation is quite messy and can cause some problems in the future.

Quite possible. I mark PR as [WIP] again.

Also, I'd expect these hotkeys to loop around tbh, not just stop at first/last railtype.

It was deliberate. First time I tried with wrapping around it was no as good ux as with current behavior. When it saturates at simple rail/last available rail it's easy to press [/] several times and return back to required from there without looking at widget at all.

Thanks for your review and looking forward for your reply ,)

grossws avatar Mar 06 '21 14:03 grossws

@grossws Are you still interested in working on this? I'm going through the PR backlog to find low-hanging fruit and this is on my list.

2TallTyler avatar Nov 09 '22 19:11 2TallTyler

@2TallTyler, yeah. I'd like some answers for @ldpl's review above about constant naming and in which file implementation should live.

Likely I'll have a bit of time to update the PR and fix issues mentioned above this or next weekend

grossws avatar Nov 09 '22 20:11 grossws

I'd look at other widget enums for naming conventions, and I've seen other hotkey implementations (#10110) stay in the corresponding *_gui.cpp file so I'd imagine that would be fine.

2TallTyler avatar Nov 09 '22 21:11 2TallTyler