Allows for easily creating complex UIs.

Supported Games
GameServerKingsGameServerKings

UiBuilderLibrary

A Library that allows for easily creating complex UIs in Rust.
By itself this plugin doesn't really do anything.

BSD 3 Clause licenseCommitizen friendly

Configuration

Default configuration:

{
  "DefaultScreenAspectRatio": 1.7777777777777777, // 16 : 9
  "DefaultRenderScale": 1.0
}

Example

var MyUi = new UI("Overlay", (rootPanel, player) =>
{
  rootPanel.CursorEnabled = true;
  rootPanel.Image.Color = "1 1 1 0.5";
  rootPanel.Bounds.MinX = 0.2;
  rootPanel.Bounds.MaxX = 0.8;
  rootPanel.Bounds.MinY = 0.2;
  rootPanel.Bounds.MaxY = 0.8;

  rootPanel.AddPanel((panel) => {
    // ...
  });
  rootPanel.AddLabel((label) => {
    // ...
  });
  rootPanel.AddButton((button) => {
    // ...
  });
  rootPanel.AddGameImage((gameImage) => {
    // ...
  });
  rootPanel.AddRawImage((rawImage) => {
    // ...
  });
  rootPanel.AddTabs((tabs) => {
    tabs.Vertical = true;
    tabs.AddTab((tab) => {
      // ...
    });
  });
  rootPanel.AddGrid((grid) => {
    grid.Rows = 3;
    grid.Columns = 4;
    for (var i = 0; i < grid.Rows * grid.Columns; i++) {
      grid.AddCell((cell) => {
        // ...
      });
    }
  });
}

MyUi.Open(player);
MyUi.Close(player);

The Render Function

When defining an element, you need to provided a render function for it.This function should perform all of the changes that you want to apply to the element.This includes setting the element's bounds, color and children.

The render function must return a boolean.This boolean indicates whether or not the element's content has changed since the last rendering of the element (it has no effect for the first render).

Dos and Don'ts

Each rendering of an element must add all the same children in the same order. You cannot dynamically add or remove them.

❌ Don't

if (comeCondition) {
  rootPanel.AddPanel((panel) => {});
}

✅ Do

rootPanel.AddPanel((panel) => {
  panel.Visible = comeCondition
});

Development

Bug Report or Feature Request

Open an issue on GitHub.

Want to contribute

Fork and clone the GitHub repository. Send me a PR :)

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.