Skip to content

UI

The UI is Dear ImGui, through sdk.ui. Keys and the mouse are on Keybinds and input.

A window is a struct with a window field and a draw method.

const MyWindow = struct {
window: sdk.ui.Window = .{ .title = "My Plugin" },
speed: f32 = 1,
pub fn draw(self: *MyWindow) void {
_ = sdk.ui.slider("Speed", &self.speed, 0.5, 5);
if (sdk.ui.button("Reset")) self.speed = 1;
}
};

Keep it in your plugin struct, since it mustn’t move, and add it in start.

try ctx.addWindow(&self.my_window);

To list it in the overlay, add a menu item that opens it.

self.menu = .{ .label = "My Plugin", .open = &self.my_window.window.open };
try sdk.overlay.addMenuItem(&self.menu);

A plugin can add tweaks to the overlay’s Tweaks menu, with fields players can change. Wraith keeps their keys and values, and you do the work.

const Speed = struct {
speed: f64 = 1,
fn handle(self: *Speed, event: sdk.tweaks.Event, problem: *sdk.tweaks.Problem) bool {
switch (event.kind) {
.changed => self.speed = event.value,
.on => if (self.speed > 10) {
problem.set("too fast");
return false;
},
.off => {},
}
return true;
}
};
// in start
try sdk.tweaks.add(.{
.id = "speed",
.title = "Speed",
.key = "F8",
.fields = &.{.{ .name = "speed", .type = .f32, .value = 2, .min = 1, .max = 5 }},
}, &self.speed, Speed.handle);

Each field’s value comes as a changed before on, and again whenever it changes. Return false from on with a problem set and it stays off, showing why.

sdk.overlay.toast pops up a short message in the corner.

_ = sdk.overlay.toast(.{ .kind = .success, .title = "My Plugin", .text = "Done!" });

sdk.ui.getDisplaySize() is the game window’s size in the overlay. Draw lists work in screen pixels that start at sdk.ui.getMainViewportPos(), which is 0,0 in the overlay but the main window’s corner in the Workbench, so add it when you place things yourself.

const size = sdk.ui.getDisplaySize();
const corner = sdk.ui.getMainViewportPos();
sdk.ui.getWindowDrawList().addLine(corner, .{ corner[0] + size[0], corner[1] + size[1] }, sdk.ui.rgba(255, 0, 0, 255), 2);

Made with ♥ by Asgard