mohsenph69 / Godot-MTerrain-plugin

A GDExtension plugin which give godot the ability to produce highly optimized Terrain for Open world games
MIT License
418 stars 22 forks source link

request for ability to remap keyboard shortcuts (with draft code) #43

Open rossunger opened 1 month ago

rossunger commented 1 month ago

I would like an easy system for remapping keyboard shortcuts for mterrain.

I propose using project settings to store keymap.

Below is an example of how this can work. It only requires a few small changes to the gdscript: 1) for m_terrain.gd: on enter_tree you call add_keymap() which loads the keymap from project settings and on exit_tree you remove the keymap 2) in each file with hardcoded keyboard shortcuts, you replace with corresponding action e.g. if Input.is_action_just_pressed("toggle_mpath_mode"):

Here is the new code to make it work, added to m_terrain.gd:

const keyboard_actions = [
        {"name": "toggle_mpath_mode", "keycode": KEY_QUOTELEFT, "pressed": true}
]
const setting_path = 'addons/mterrain/keymap/'

func add_keymap():
    for action in keyboard_actions:
        var path = setting_path + action.name
        if not ProjectSettings.has_setting(path):
            var a = InputEventKey.new()
            a.keycode = action.keycode
            a.pressed = action.pressed
            ProjectSettings.set_setting(path, [a])
        var events = ProjectSettings.get_setting(path)
        if not InputMap.has_action(action.name):
            InputMap.add_action(action.name)
        for e in events:
            InputMap.action_add_event(action.name, e)

func remove_keymap():
    for action in keyboard_actions:
        InputMap.erase_action(action.name)
mohsenph69 commented 1 month ago

Hi there! this is a good Idea!

This code you which you have wrote will create and input action in project setting! I believe it would be better if we keep project setting clean! because this plugin functionality is only for editor not final game!

I think we can use Godot config class for this! This class is just a text file (with .ini or .cfg class) which you can read and you can change some stuff in that! easily! And we can put the entire setting for MTerrain editor in that! that can be anything from keycode to any other setting which can change the behaviour of the MTerrain in editor!

Also we need to create a setting class which read and analyze MTerrain setting!

I will work on this in near future! Also if you want to contribute you can help me about this!

rossunger commented 1 month ago

Actually it does add the actions to project setting, it adds to editor inputmap. Unfortunately there no clean way to do this in code via add-on, but at runtime these actions won't exist.

On Sun, Jul 28, 2024, 4:48 a.m. mohsenph69 @.***> wrote:

Hi there! this is a good Idea!

This code you which you have wrote will create and input action in project setting! I believe it would be better if we keep project setting clean! because this plugin functionality is only for editor not final game!

I think we can use Godot config class https://docs.godotengine.org/en/stable/classes/class_configfile.html for this! This class is just a text file (with .ini or .cfg class) which you can read and you can change some stuff in that! easily! And we can put the entire setting for MTerrain editor in that! that can be anything from keycode to any other setting which can change the behaviour of the MTerrain in editor!

Also we need to create a setting class which read and analyze MTerrain setting!

I will work on this in near future! Also if you want to contribute you can help me about this!

— Reply to this email directly, view it on GitHub https://github.com/mohsenph69/Godot-MTerrain-plugin/issues/43#issuecomment-2254454366, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACGZ2R6FOG4SHBU5A43JZJDZOS45DAVCNFSM6AAAAABLPFURFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJUGQ2TIMZWGY . You are receiving this because you authored the thread.Message ID: @.***>

rossunger commented 1 month ago

I would love to help you with mterrain project setting. Please let me know what I can do. Do you have a list of seeing you'd like to have in project settings?

I was thinking about whether inputmap settings should be a editor setting or project setting, and I decided that because add-ons are enable on a per-project basis, the add-on settings should be part of project setting not editor setting, although personally I think they would fit better in editor setting.

On Sun, Jul 28, 2024, 4:48 a.m. mohsenph69 @.***> wrote:

Hi there! this is a good Idea!

This code you which you have wrote will create and input action in project setting! I believe it would be better if we keep project setting clean! because this plugin functionality is only for editor not final game!

I think we can use Godot config class https://docs.godotengine.org/en/stable/classes/class_configfile.html for this! This class is just a text file (with .ini or .cfg class) which you can read and you can change some stuff in that! easily! And we can put the entire setting for MTerrain editor in that! that can be anything from keycode to any other setting which can change the behaviour of the MTerrain in editor!

Also we need to create a setting class which read and analyze MTerrain setting!

I will work on this in near future! Also if you want to contribute you can help me about this!

— Reply to this email directly, view it on GitHub https://github.com/mohsenph69/Godot-MTerrain-plugin/issues/43#issuecomment-2254454366, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACGZ2R6FOG4SHBU5A43JZJDZOS45DAVCNFSM6AAAAABLPFURFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJUGQ2TIMZWGY . You are receiving this because you authored the thread.Message ID: @.***>

rossunger commented 1 month ago

to get editor camera in addon:

var _editor_cameras : Array = find_cameras(get_editor_interface().get_base_control())   
editor_camera = _editor_cameras[0]  

apparently now you can also do EditorInterface.get_editor_viewport_3d(idx).get_camera_3d()

mohsenph69 commented 1 month ago

Hi there rossunger! that is really nice of you!

Let me make clear about the way you want to add hot-key modifier! in the way that you want to add hot key, the key name will appear in this section by your method!

image

If yes! I prefer to keep this section clean, and only for the final game!

If you want to contribute to this project I really appreciate that! Up to this point in MTerrain plugin project I made most of the things by myself, but if more people help, definitely the speed of progress will be increase!

So if you know about c++ I can introduce to you some section which you can help! otherwise all functionality of MTerrain plugin in godot editor is written in gdscript! you can help me with those!

I believe I can create a page an write down the goal that we want to achieve and everyone can help with some section!

rossunger commented 1 month ago

No, the keymap will appear here: image

When you call InputMap.add_action at runtime, it adds it to the game. When you call it from the editor, it adds it to the Editors keymap, not the games. Unfortunately godot doesn't have any interface yet for editing editor keymap for addon. Ideally it would appear under editor setting/keyboard shortcuts, but that is not how it works.

I love the idea of contributing to this project. I think what you've done is amazing and I hope more people find out about it and use it.

I'm getting to the stage where I can understand C++ ok, but I definitely am not ready to be contributing to the C++ code base. I also don't like working with compilers and visual studio and all that. But I think at some point I might have to dive into that

For now I would LOVE to help with the gdscript side of things. Is there anything gscript that I can work on right now?

Quality of life improvements I'd like to make that would be gdscript based:

image

Also, I made a resizable minimap that I use with mterrain so I dont get lost in the editor. It uses editor camera position to show you where you are in your terrain: image This has saved me SO many times. would highly recommend. I can publish it as a separate plugin, but you might want something like this as part of mterrain.

I would also like to make a floating panel for editing multiple MGrass at once... one problem I have is that I use MGrass for trees, and rocks, and grass, and its very uncomfortable using the inspector to make changes. I want to make a floating panel that has all the settings side-by-side with the ability to edit. image