pkdawson / imgui-godot

Dear ImGui plugin for Godot 4
MIT License
322 stars 19 forks source link

Extract Keymaps to public static class for use in Godot projects #12

Closed arran-nz closed 1 year ago

arran-nz commented 1 year ago

Hey there, awesome project - This is a game changer for me!

The PR allows for Godot developers to check against Godot keycodes in an ImGUI window.

For example:

if (ImGui.IsKeyPressed(ImGuiInput.KeyMap[Godot.Key.A]))
{
    log.Information("Keyboard button A was pressed");
}                

Otherwise using the ImGuiKey enumeration in our projects increases coupling.

pkdawson commented 1 year ago

Hi, thanks for the PR. I'm working on the next version in the develop branch, so the Dictionary has been changed to a switch statement, and stuff has been reorganized.

I think this would actually be a great place to use an extension method, so usage would look like:

if (ImGui.IsKeyPressed(Godot.Key.A.ToImGuiKey()))

If you want to get a PR merged, it's probably simplest to just open a new one on the develop branch. In ImGuiGD.cs, add:

public static ImGuiKey ToImGuiKey(this Key key)

and the same for JoyButton, using the Convert* methods in ImGuiGDInternal.

Otherwise, I'll take care of that myself in the next few days.

arran-nz commented 1 year ago

Thanks for the reply, I've implemented it as you suggusted - Great idea.

Succesor: https://github.com/pkdawson/imgui-godot/pull/13