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

primitive config with custom shortcuts #159

Merged
merged 5 commits into from
Jul 4, 2022
Merged

Conversation

HuntClauss
Copy link

@HuntClauss HuntClauss commented Jun 17, 2022

This is just a simple/primitive implementation of custom shortcuts. For now, editing shortcuts can be made only via settings.cfg file.

There is problem with some combination of shortucts (like Control+[key] and Control+Shift+[key]), because godot don't check other shortcuts if overlap. I found this about possible solution.

(I know almost nothing about godot so I am really sorry if I did something wrong.)

@mbrlabs
Copy link
Owner

mbrlabs commented Jun 18, 2022

Thank you for your contribution, but custom keyboard shortcuts are already beeing worked on by @MrApplejuice. See: #144.
I'll leave this open for now though.

Copy link
Contributor

@MrApplejuice MrApplejuice left a comment

Choose a reason for hiding this comment

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

Hey there! Wow, handy to have this actually. I did not tackle persisting of keyboard shortcuts yet, at all. And this comes in just handy. Seems pretty compatible with what I am doing as well, except for the "multiple bindings" per action thing that I commented on.

If that is not fixed now, I will need to do this later, and that would probably be a bit annoying because the config-file syntax needs to be changed again and might require backwards incompatible changes.

I would suggest, taking the current implementation and wrapping the serialization of scancodes in an Array and set that value - that should work right? ConfigFile seems to support "Variants", I would assume that would include Arrays of serializable values. Then we would be done with this for good. (If arrays cannot be written directly, just JSONify the array and save/load that one).

That would be my 2-cents to this. Looks good otherwise :-) I leave the final decision to @mbrlabs .

lorien/Misc/Settings.gd Outdated Show resolved Hide resolved
@HuntClauss
Copy link
Author

HuntClauss commented Jun 18, 2022

Hey @MrApplejuice, you were right, ConfigFile supports Arrays so I fixed that, and now multiple bindings per action work. I had to add a prefix to every shortcut: KB: representing keyboard and JOY: representing joypad, but I think this shouldn't be a problem.

Edit:
I created config in a way that allows manual modification by the user directly in the file, for this reason, each button is turned into an easy to read string. Currently, I think this approach doesn't make sense because the user will modify the shortcuts through the GUI anyway, but I would like to hear other people's opinion on this

Copy link
Contributor

@MrApplejuice MrApplejuice left a comment

Choose a reason for hiding this comment

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

Hey, looks good to me! Have tow nit-picky suggestions, but in no way necessary :-)

I am also only contributing ;-) @mbrlabs what do you think?

lorien/Misc/Settings.gd Outdated Show resolved Hide resolved
lorien/Misc/Settings.gd Outdated Show resolved Hide resolved
'_setup_shortcuts' function now creates binding if it is not present in
settings
new function 'set_default_shortcut' allows you to restore default values
for a shortcut
@HuntClauss
Copy link
Author

I think this is everything for now. I hope you find this useful.

Thank you for your suggestions, godot is totally new for me so I appreciate every help :-)

@mbrlabs
Copy link
Owner

mbrlabs commented Jun 18, 2022

Persistence-wise i probably would have done it the same: Shortcuts section in settings.cfg, and then a list of actions. Basically like this (simplified):

[shortcuts]
save_project = [InputEvent("CTRL+S")]
undo = [InputEvent("CTRL+Z"), "..."]

As for how to serialize the key combinantions: just let Godot do it (InputEvent is a Resource, so that should be no problem). It's less readable then a custom format, but it's still possible if you want to debug/check something by reading or changing the file directly. For example a single-event action would look like this:

shortcut_undo=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,
"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":90,
"physical_scancode":0,"unicode":0,"echo":false,"script":null) ]

In order to save it like this you can just pass in the array of InputEvents into the set_value method of the ConfigFile. Serialization & deserialization is automatic.

This was referenced Jun 27, 2022
@mbrlabs mbrlabs merged commit b8392e1 into mbrlabs:main Jul 4, 2022
@mbrlabs
Copy link
Owner

mbrlabs commented Jul 4, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants