diff --git a/timber-api/uibuilder/basic-usage.md b/timber-api/uibuilder/basic-usage.md index e69de29..2c66971 100644 --- a/timber-api/uibuilder/basic-usage.md +++ b/timber-api/uibuilder/basic-usage.md @@ -0,0 +1,42 @@ +# Basic UIBuilder usage +TimberApi provides many base game [presets](https://github.com/Timberborn-Modding-Central/TimberAPI/tree/main/TimberApi.UIPresets) in the UIBuilder. These presets can be used to create UI quickly and simple. + +## Prerequisites +To make use of the UIBuilder you need to get the `UIBuilder` instance with Timberborn Dependency Injection. +In the following guides the field `uiBuilder` will be used as, which is the `UIBuilder` instance. + +## Basic usage +#### `Build` +With `Build` you can quickly instantiate fully configured presets. +This are presets you made yourself or presets where no additional information needs to be given. +```C# +// Generic Typed +uiBuilder.Build() + +// Type parameter, can be used for dynamic building +uiBuilder.Build(typeof(ArrowDownButton)) +``` + +#### `Create` +Some presets can contain extra configurations, for example adding a localization text or making a button larger. +With the `create` method you can change these configurations before instantiating the preset. +```C# +// Creates a default game button with a loc key +_uiBuilder.Create().SetLocKey("hello.world.key").Build() + +// Creates a destructive game button, red, with a loc key +_uiBuilder.Create().Destructive().SetLocKey("hello.world.key").Build() +``` + + +#### `Initialize` +Timberborn has a visual element initialization process, this process will for example make sure that a click sound is added to a button. + + +> [!CAUTION] +> **Initialization** should only be done on the highest parent element! Calling initialization on every preset will make creation of the whole visual element slow. + +Initialization can be by the following methods: +- `UIBuilder.Initialize`, initializes the given element. +- `UIBuilder.BuildAndInitialize`, returns the given visual element back after being initialized. +- `UIBuilder.Create().BuildAndInitialize()`, returns the given visual element back after being initialized. \ No newline at end of file diff --git a/timber-api/uibuilder/creating-presets.md b/timber-api/uibuilder/creating-presets.md index e69de29..4a84bcd 100644 --- a/timber-api/uibuilder/creating-presets.md +++ b/timber-api/uibuilder/creating-presets.md @@ -0,0 +1,97 @@ +# Creating Simple Preset +Creating presets is the core functionality of the UIBuilder, presets can be a one time use or re-used many times. + +## Creating a new button preset +Let's re-create the `ArrowLeftButton` of the TimberApi presets for this guide. + +### Step 1, Create a preset class +First you need to create a class that extends the `BaseBuilder`, where `T` is the visual element you want to create. In this case it will be the `Button`. + +```C# +public class TopButton : BaseBuilder