dextercd / Noita-Dear-ImGui

MIT License
12 stars 1 forks source link
imgui lua noita

Noita Dear ImGui bindings

Users

If you want to install this mod, head over to the Releases and download the latest build (NoitaDearImGui-X.Y.Z.zip NOT the source code).

How to use this in your own mod?

You are not expected to bundle this mod with your own mod, you should instead instruct people to install this themselves alongside your mod.

Any mod below this mod in the load order can use the ImGui bindings. This mod requires 'unsafe' mode, but mods that use the ImGui bindings don't need unsafe mode themselves.

Make sure to occassionally switch the build type to 'Debug (for devs)' during development or if the game starts crashing. This often helps identify mistakes in use of the bindings.

Also check out the ImGui FAQ: https://github.com/ocornut/imgui/blob/master/docs/FAQ.md a lot of stuff there also applies to these bindings.

Documentation

There's generated documentation containing all the function signatures.

You can just refer to this file manually, but it's also possible to load into VS Code or any other editor that supports the LuaLS/Lua Language Server.

VS Code is pretty easy to setup:

  1. Get the Lua language server extension. https://marketplace.visualstudio.com/items?itemName=sumneko.lua
  2. Go into the extension's settings and add the imguidoc directory. This is included in the mod release zip.
  3. It should now be working. Press ctrl+space to trigger autocomplete.

Bindings

The bindings are a relatively close 1:1 mapping of the normal ImGui functions except:

This standard ImGui code:

ImGui::ColorEdit3("Color", (float*)&color,
    ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoAlpha);

turns into this with these Noita/Lua bindings:

_, r, g, b = imgui.ColorEdit3("Colour", r, g, b,
    bit.bor(imgui.ColorEditFlags.PickerHueWheel, imgui.ColorEditFlags.NoSidePreview, imgui.ColorEditFlags.NoAlpha))

Example mod

There's an example mod that shows the basics: https://github.com/dextercd/Noita-Dear-ImGui/blob/main/ExampleMod/init.lua

Credit

Many thanks to 🌸Rain🌸 (vexx32) on the Noita Discord for the Noita pixel and glyph ttf files she created: Discord message (Download).

Thanks to Kaedenn for creating the initial documentation using this script he made.