rednode API - v0.80.1
    Preparing search index...

    Variable uiConst

    ui: {
        button(
            label: string,
            onClick?: () => void,
            options?: Omit<ButtonProps, "label">,
        ): UiNode<ButtonProps>;
        column(
            ...children: UiNode<Record<string, unknown>>[],
        ): UiNode<Record<string, never>>;
        copy(text: string): Promise<void>;
        heading(text: string, options?: Omit<TextProps, "text">): UiNode<TextProps>;
        image(
            src: string | Uint8Array<ArrayBufferLike>,
            options?: Omit<ImageProps, "src"> & { onClick?: () => void },
        ): UiImage;
        input(
            options?: InputProps & {
                onChange?: (value: string) => void;
                onSubmit?: (value: string) => void;
            },
        ): UiNode<InputProps>;
        list(options?: Partial<ListProps>): UiList;
        onAppKey(handler: (shown: boolean, panels: boolean) => void): () => void;
        onSolo(handler: (on: boolean) => void): () => void;
        progress(
            value: number,
            options?: Omit<ProgressProps, "value">,
        ): UiNode<ProgressProps>;
        row(
            ...children: UiNode<Record<string, unknown>>[],
        ): UiNode<Record<string, never>>;
        select(
            label: string,
            options: SelectOption[],
            props?: Omit<SelectProps, "label" | "options"> & {
                onChange?: (value: string) => void;
            },
        ): UiNode<SelectProps>;
        slider(
            label: string,
            onChange?: (value: number) => void,
            options?: Omit<SliderProps, "label">,
        ): UiNode<SliderProps>;
        solo(on: boolean): Promise<void>;
        text(text: string, options?: Omit<TextProps, "text">): UiNode<TextProps>;
        toggle(
            label: string,
            onChange?: (checked: boolean) => void,
            options?: Omit<ToggleProps, "label">,
        ): UiNode<ToggleProps>;
        window(options: WindowOptions): UiWindow;
    } = ...

    Builds overlay windows from a Node mod.

    Type Declaration

    • button: function
      • A button. onClick runs in the mod when the player presses it. tip is a tooltip, shown on a disabled button too, to say why it cannot be pressed.

        Parameters

        • label: string
        • OptionalonClick: () => void
        • options: Omit<ButtonProps, "label"> = {}

        Returns UiNode<ButtonProps>

        const make = ui.button("Generate", async () => {
        make.set({ disabled: true, tip: "Generating..." });
        await generate();
        make.set({ disabled: false, tip: "Make a clip from the prompt" });
        }, { tip: "Make a clip from the prompt" });
    • column: function
      • Puts nodes under each other. A window's content is already a column.

        Parameters

        • ...children: UiNode<Record<string, unknown>>[]

        Returns UiNode<Record<string, never>>

    • copy: function
      • Puts text on the Windows clipboard, for the player to paste anywhere. Works in Node mods and in overlay apps; use it instead of navigator.clipboard, which an overlay window cannot always reach. It only writes: no package can read the clipboard.

        Parameters

        • text: string

        Returns Promise<void>

        import { ui } from "rednode";

        await ui.copy("746693166");
    • heading: function
    • image: function
      • A picture from a file or from bytes, for a mod that makes or fetches pictures: a render, a preview, a before and after. src is a PNG, JPEG, WebP or GIF file (a relative path in the package's folder, or a full path in pkg.dataDir), a data:image/ URL, or the file's bytes (a Buffer or Uint8Array). Give a width in pixels; the height follows the picture. set({ src }) shows another picture, or the same file again after the mod wrote over it. A picture that cannot be shown says why in the window and in the Mod log. Needs REDnode 0.55.0 or later.

        Parameters

        • src: string | Uint8Array<ArrayBufferLike>
        • options: Omit<ImageProps, "src"> & { onClick?: () => void } = {}

        Returns UiImage

        import path from "node:path";
        import { pkg, ui } from "rednode";

        const file = path.join(pkg.dataDir, "before.png"); // written by the mod
        const before = ui.image(file, { width: 220, alt: "The hat before" });
        const after = ui.image("waiting.png", { width: 220, onClick: () => console.log("larger") });
        ui.window({ title: "Reshape", width: 480, height: 320, children: [ui.row(before, after)] });
        after.set({ src: path.join(pkg.dataDir, "after.png") });
    • input: function
      • A text field. onSubmit runs on Enter; onChange when the field loses focus.

        Parameters

        • options: InputProps & {
              onChange?: (value: string) => void;
              onSubmit?: (value: string) => void;
          } = {}

        Returns UiNode<InputProps>

    • list: function
      • A list of lines that scrolls on its own, for a log or a live feed. It keeps the newest lines only (keep, 500 by default), follows the newest line unless the player has scrolled up, and without a height fills the window's free height. It keeps at least 160 px: when the other nodes leave less, the window scrolls.

        Parameters

        Returns UiList

        import { game, ui } from "rednode";

        const log = ui.list({ keep: 1000 });
        ui.window({ title: "Events", width: 420, height: 360, children: [log, ui.button("Clear", () => log.clear())] });
        game.on("PlayerPuppet.OnGameAttached", (e) => log.push(`${new Date().toLocaleTimeString()} ${e.name}`));
    • onAppKey: function
      • Hears the app's key: the key the player gave this app in its title bar (Key binding) or the Mod Manager. A press shows only this app's windows with the cursor (shown true), and the next press hides them and gives the game its input back (shown false). Pressing F10 or Esc, or clicking empty screen, ends that and shows the app again (shown true if the key had hidden it).

        An app whose page fills the screen ("fill": "screen", such as an editor's viewport) is not hidden: its page stays, with the cursor, so its own view keeps the mouse, and the key hides only the page's rn-windows, its panels (the UI kit does it). panels is then true. A page drawing panels of its own, not in rn-windows, hides them here.

        The key never changes the app's own state: an editor stays in its edit mode while hidden. Use this to pause what only makes sense on screen, such as a drag in progress. Works in Node mods and in overlay apps. Returns a function that stops listening.

        Parameters

        • handler: (shown: boolean, panels: boolean) => void

        Returns () => void

        import { ui } from "rednode";

        ui.onAppKey((shown, panels) => {
        if (panels) toolbar.hidden = !shown; // a full-screen page's own toolbar
        else if (!shown) endDrag(); // the player hid the window to look at the world
        });
    • onSolo: function
      • Calls the handler when this package's solo mode starts or ends, also when the player ends it from the launcher. Returns a function that stops listening.

        Parameters

        • handler: (on: boolean) => void

        Returns () => void

    • progress: function
    • row: function
    • select: function
      • A dropdown: a box showing the chosen option, with the list opening below it (or above it near the bottom of the window). The player picks with the mouse, or with the arrows and Enter. onChange gets the value the player picks. Change the options or the choice later with set({ options, value }). Needs REDnode 0.68.0 or later.

        Parameters

        • label: string
        • options: SelectOption[]
        • props: Omit<SelectProps, "label" | "options"> & { onChange?: (value: string) => void } = {}

        Returns UiNode<SelectProps>

        const zoom = ui.select("Zoom", [
        { value: "near", label: "Near" },
        { value: "body", label: "Whole body" },
        { value: "far", label: "Far" },
        ], { value: "body", onChange: (v) => setZoom(v) });

        zoom.set({ value: "far" }); // from code, no onChange
    • slider: function
      • A slider. onChange gets the value when the player lets go, or while they drag with live: true.

        Parameters

        • label: string
        • OptionalonChange: (value: number) => void
        • options: Omit<SliderProps, "label"> = {}

        Returns UiNode<SliderProps>

        ui.slider("Level", (v) => panel.set({ level: v }), { min: 0, max: 100, value: 50, unit: "%", live: true });
        
    • solo: function
      • Solo mode: while on, REDnode hides every other package's windows and HUD widgets, so this package has the screen to itself (an editing viewport, a full-screen tool). REDnode's own tool windows stay: the launcher tab, which shows the solo and an End solo button, the Mod log, the Mod Manager and the Test timer. Solo ends when the package turns it off, stops or crashes, or the player ends it; ui.onSolo hears that.

        The package must list "solo" in its rednode-app.json permissions and the player must allow it in the Mod Manager; until then this rejects and says so. Works in Node mods and in overlay apps.

        Parameters

        • on: boolean

        Returns Promise<void>

        import { ui } from "rednode";

        await ui.solo(true); // edit mode on: other windows go
        // ...
        await ui.solo(false); // they come back
    • text: function
    • toggle: function
    • window: function
    import { game, ui } from "rednode";

    const where = ui.text("Waiting for the game");
    ui.window({
    title: "Where am I",
    children: [
    where,
    ui.button("Update", async () => {
    const p = await game.player.position();
    where.set({ text: `${p.x.toFixed(1)}, ${p.y.toFixed(1)}, ${p.z.toFixed(1)}` });
    }),
    ],
    });