Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up[RDY] Allow diagonal movement via keybinding modifiers in SDL builds #22690
Conversation
ZhilkinSerg
added some commits
Jan 2, 2018
codemime
reviewed
Jan 6, 2018
| if( keysym.mod & KMOD_SHIFT ){ | ||
| switch (keysym.sym) { | ||
| case SDLK_LEFT: | ||
| return '7'; //LEFTUP; |
This comment has been minimized.
This comment has been minimized.
codemime
Jan 6, 2018
Member
Numeric constants in src/input.h would be better than the magic numbers.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Jan 6, 2018
Author
Contributor
I agree. My final aim is to be able to load keys from keybindings.
This comment has been minimized.
This comment has been minimized.
codemime
reviewed
Jan 6, 2018
| } | ||
| //Ctrl + Arrow (diagonal counter-clockwise) | ||
| if( keysym.mod & KMOD_CTRL ){ | ||
| switch (keysym.sym) { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Any luck with |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Didn't look into @AMurkin, thanks for the picture. |
ZhilkinSerg
changed the title
Allow diagonal movement via keybinding modifiers
[WIPAllow diagonal movement via keybinding modifiers
Jan 6, 2018
ZhilkinSerg
changed the title
[WIPAllow diagonal movement via keybinding modifiers
[WIP] Allow diagonal movement via keybinding modifiers
Jan 6, 2018
This comment has been minimized.
This comment has been minimized.
In that case, you should probably change "input.cpp" and add support for modifier keys. At least for SDL builds, the modifiers can be set in "sdltiles.cpp" (maybe where |
ZhilkinSerg
added some commits
Jan 31, 2018
This comment has been minimized.
This comment has been minimized.
Thanks, but it happened to be too hard for me to implement this, so I decided not to save modifiers together with keybindings, but simply read action characters from |
ZhilkinSerg
added some commits
Jan 31, 2018
ZhilkinSerg
changed the title
[WIP] Allow diagonal movement via keybinding modifiers
[RDY] Allow diagonal movement via keybinding modifiers in SDL builds
Jan 31, 2018
This comment has been minimized.
This comment has been minimized.
|
Should be good to go for I've started research for |
BevapDin
reviewed
Feb 1, 2018
| { | ||
| const input_event first_input_event = get_input_for_action( action_descriptor, context )[0]; | ||
| long first_input = first_input_event.get_first_input(); | ||
| char first_input_char = ( char )first_input; |
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 1, 2018
Contributor
Why are you explicitly casting this using a C-style cast (there is already an implicit conversion for the assignment)?
Why the local variable, why not return it directly?
Why return a char, when the return value (first_input) is a long and the result of the function is promoted to a long again (see return statement in sdl_keysym_to_curse, which returns a long)?
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Feb 1, 2018
Author
Contributor
That is true. I've simplified new function to remove redundant type cast.
BevapDin
reviewed
Feb 1, 2018
| char input_manager::get_first_char_for_action( const std::string &action_descriptor, | ||
| const std::string context ) | ||
| { | ||
| const input_event first_input_event = get_input_for_action( action_descriptor, context )[0]; |
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 1, 2018
Contributor
How can you be sure that the vector returned by get_input_for_action always has at least one entry?
This comment has been minimized.
This comment has been minimized.
BevapDin
reviewed
Feb 1, 2018
| * Return first char associated with an action ID in a given context. | ||
| */ | ||
| char get_first_char_for_action( const std::string &action_descriptor, | ||
| const std::string context = "default" ); |
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 1, 2018
Contributor
Why is there a default value for the second parameter? All calls to this function supply a specific value anyway, the default is never used. And why is it a const value, but the first parameter is a reference to const?
This comment has been minimized.
This comment has been minimized.
BevapDin
reviewed
Feb 1, 2018
| if( keysym.mod & KMOD_SHIFT ) { | ||
| switch( keysym.sym ) { | ||
| case SDLK_LEFT: | ||
| return inp_mngr.get_first_char_for_action( "LEFTUP", "keyboard" ); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
BevapDin
reviewed
Feb 1, 2018
| @@ -1030,6 +1030,13 @@ void options_manager::init() | |||
|
|
|||
| mOptionsSort["interface"]++; | |||
|
|
|||
| add( "DIAG_MOVE_WITH_MODIFIERS", "interface", translate_marker( "Diagonal movement with cursor keys and modifiers" ), | |||
| translate_marker( "If true, allows diagonal movement with cursor keys using CTRL and SHIFT modifiers (<color_red>currently only in SDL builds</color>). Diagonal movement action keys are taken from keybindings, so you need these to be configured." ), | |||
This comment has been minimized.
This comment has been minimized.
BevapDin
Feb 1, 2018
Contributor
No other build specific option mentions that is only available in certain build types. (Note that COPT_CURSES_HIDE already hides it on curses builds.) For the sake of consistency, this should not be mentioned at all, or be mentioned by all options, preferably automated by checking cOpt::hide.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
added some commits
Feb 1, 2018
This comment has been minimized.
This comment has been minimized.
I have to admit |
codemime
self-assigned this
Feb 19, 2018
This comment has been minimized.
This comment has been minimized.
|
Works as expected (although, it took some time to get used to it). I'd only change two things:
|
ZhilkinSerg
added some commits
Feb 20, 2018
This comment has been minimized.
This comment has been minimized.
There is add( "DIAG_MOVE_WITH_MODIFIERS", "interface", translate_marker( "Diagonal movement with cursor keys and modifiers" ),
translate_marker( "If true, allows diagonal movement with cursor keys using CTRL and SHIFT modifiers. Diagonal movement action keys are taken from keybindings, so you need these to be configured." ),
true, COPT_CURSES_HIDE
);
I've changed default value of |
codemime
merged commit f78e2e4
into
CleverRaven:master
Feb 20, 2018
Night-Pryanik
referenced this pull request
Feb 23, 2018
Closed
Keybinding modifiers (ex. diagonal movements via SHIFT+arrow keys) #20447
ZhilkinSerg
deleted the
ZhilkinSerg:sdl-diag-move-mod
branch
Feb 25, 2018
This comment has been minimized.
This comment has been minimized.
Litppunk
commented
Apr 30, 2018
|
does this also affect menus? My game bugged last time I loaded so the diagonals were default. But on save/exit and reload worked fine, unless maybe caps lock got clicked or something, I'm not sure what might have caused it. Something to look out for. |
This comment has been minimized.
This comment has been minimized.
|
This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there: https://discourse.cataclysmdda.org/t/dropping-things-on-the-wrong-tile-constantly/18223/8 |

ZhilkinSerg commentedJan 2, 2018
•
edited
First approach for #20447.
What was changed:
DIAG_MOVE_WITH_MODIFIERSinterface option (currently enabled only in SDL builds and disabled in CURSES build);Default key bindings for diagonal movement:
1=Move Southwest;3=Move Southeast;7=Move Northwest;9=Move Northeast.New key bindings:
Shift+Cursor Left->7=Move Northwest;Shift+Cursor Right->3=Move Southeast;Shift+Cursor Up->9=Move Northeast;Shift+Cursor Down->1=Move Southwest.and
Ctrl+Cursor Left->1=Move Southwest;Ctrl+Cursor Right->9=Move Northeast;Ctrl+Cursor Up->7=Move Northwest;Ctrl+Cursor Down->3=Move Southeast.Illustration:
Screenshots: