Update editor scripts

This commit is contained in:
Insality
2025-04-19 18:03:50 +03:00
parent 8d2b8c25a0
commit 50e59d9469
19 changed files with 1118 additions and 280 deletions

View File

@@ -79,7 +79,7 @@ Widgets are reusable UI components that encapsulate multiple **Druid** component
### Creating a Widget
Create a new Lua file for your widget class. This file better to be placed near the corresponding GUI file with the same name.
Create a new Lua file for your widget class. This file better to be placed near the corresponding GUI file with the same name. You can use the Druid's editor script to create a widget by right-clicking on the GUI file in the editor or in "Edit" menu panel, while GUI file is opened.
Define `init` function to initialize the widget.

View File

@@ -5,6 +5,8 @@ Custom compomnents from 1.1 release are deprecated. Now we have a new way to cre
Custom components are will exists for more system things like basic components. You don't have to migrate to widgets.
The editor script for creating custom components is removed. Now you can create widgets with the new editor script.
Read more about widgets in [widgets.md](widgets.md)
## Overview
@@ -17,7 +19,7 @@ Every component is a child of the Basic Druid component. You can call methods of
### Basic Component Template
A basic custom component template looks like this (you can copy it from `/druid/templates/component.template.lua`):
A basic custom component template looks like this (you can copy it from `/druid/templates/component.lua.template`):
```lua
local component = require("druid.component")
@@ -58,7 +60,7 @@ end
### Full Component Template
A full custom component template looks like this (you can copy it from `/druid/templates/component_full.template.lua`):
A full custom component template looks like this (you can copy it from `/druid/templates/component_full.lua.template`):
```lua
local component = require("druid.component")
@@ -138,29 +140,6 @@ function init(self)
end
```
## Create Druid Component Editor Script
Druid provides an editor script to assist you in creating Lua files for your GUI scenes. You can find the commands under the menu `Edit -> Create Druid Component` when working with *.gui scenes.
The script analyzes the current GUI scene and generates a Lua file with stubs for all Druid components found. The output file is named after the current GUI scene and placed in the same directory. Note that the script does not override any existing *.lua files. If you want to regenerate a file, delete the previous version first.
The script requires `python` with `deftree` installed. If `deftree` is not installed, the instructions will be displayed in the console.
### Auto-Layout Components
The generator script also checks the current GUI scene for Druid components and creates stubs for them. If a node name starts with a specific keyword, the script generates component stubs in the Lua file. For example, nodes named `button` and `button_exit` will result in the generation of two Druid Button components with callback stubs.
Available keywords:
- `button`: Adds a [Druid Button](01-components.md#button) component and generates the callback stub.
- `text`: Adds a [Druid Text](01-components.md#text) component.
- `lang_text`: Adds a [Druid Lang Text](01-components.md#lang-text) component.
- `grid` or `static_grid`: Adds a [Druid Static Grid](01-components.md#static-grid) component. You should set up the Grid prefab for this component after generating the file.
- `scroll_view`: Adds a [Druid Scroll](01-components.md#scroll) component. It also adds a `scroll_content` node with the same postfix. Ensure that it's the correct node.
- `blocker`: Adds a [Druid Blocker](01-components.md#blocker) component.
- `slider`: Adds a [Druid Slider](01-components.md#slider) component. You should adjust the end position of the Slider after generating the file.
- `progress`: Adds a [Druid Progress](01-components.md#progress) component.
- `timer`: Adds a [Druid Timer](01-components.md#timer) component.
## The Power of Using Templates
With Druid, you can use a single component but create and customize templates for it. Templates only need to match the component scheme. For example, you can have a component named `player_panel` and two GUI templates named `player_panel` and `enemy_panel` with different layouts. The same component script can be used for both templates.

View File

@@ -168,3 +168,16 @@ function init(self)
end
```
## Create Druid Widget Editor Script
Druid provides an editor script to assist you in creating Lua files for your GUI scenes. You can find the commands under the menu `Edit -> Create Druid Widget` when working with *.gui scenes.
This script will create a new widget lua file with the same name and basic template for the widget.
The Druid provides two templates:
- `/druid/templates/widget.lua.template` - Basic template for the widget.
- `/druid/templates/widget_full.lua.template` - Full template for the widget.
You can change the path to the template in the `[Druid] Settings` option in the `Edit` menu.