diff --git a/doc/en/scripting/ui.md b/doc/en/scripting/ui.md index e209c267..0a6ad4c3 100644 --- a/doc/en/scripting/ui.md +++ b/doc/en/scripting/ui.md @@ -74,6 +74,7 @@ Properties: | ----------- | ------ | ---- | ----- | ------------------------------------------------------------------------------------ | | text | string | yes | yes | entered text or placeholder | | placeholder | string | yes | yes | placeholder (used if nothing has been entered) | +| hint | string | yes | yes | text to display when nothing is entered | | caret | int | yes | yes | carriage position. `textbox.caret = -1` will set the position to the end of the text | | editable | bool | yes | yes | text mutability | | multiline | bool | yes | yes | multiline support | diff --git a/doc/en/world-generator.md b/doc/en/world-generator.md index 47f46b80..2112bce2 100644 --- a/doc/en/world-generator.md +++ b/doc/en/world-generator.md @@ -72,17 +72,20 @@ Fragments used by the generator must present in the directory: ## Structures -A structure is a set of rules for inserting a fragment into the world by the generator. It currently has no properties, being created as empty objects in the `generators/generator_name.files/structures.toml` file. Example: +A structure is a set of rules for inserting a fragment into the world by the generator. Structures are declared as objects in the file `generators/generator_name.files/structures.toml`. Example: ```toml tree0 = {} tree1 = {} tree2 = {} -tower = {} +tower = {lowering=2} coal_ore0 = {} ``` Currently, the name of the structure must match the name of the fragment used. +Available properties: +- lowering - depth of structure lowering. + ## Biomes A biome defines what blocks and layers the terrain is generated from, as well as a set of plants and structures. diff --git a/doc/ru/scripting/ui.md b/doc/ru/scripting/ui.md index 6d39c6c7..0a955947 100644 --- a/doc/ru/scripting/ui.md +++ b/doc/ru/scripting/ui.md @@ -74,6 +74,7 @@ document["worlds-panel"]:clear() | ----------- | ------ | ------ | ------ | ---------------------------------------------------------------------- | | text | string | да | да | введенный текст или заполнитель | | placeholder | string | да | да | заполнитель (используется если ничего не было введено) | +| hint | string | да | да | текст, отображаемый, когда ничего не введено | | caret | int | да | да | позиция каретки. `textbox.caret = -1` установит позицию в конец текста | | editable | bool | да | да | изменяемость текста | | multiline | bool | да | да | поддержка многострочности | diff --git a/doc/ru/world-generator.md b/doc/ru/world-generator.md index 284ea067..1523f94a 100644 --- a/doc/ru/world-generator.md +++ b/doc/ru/world-generator.md @@ -72,17 +72,20 @@ ## Структуры -Структура - набор правил по вставке фрагмента в мир генератором. На данный момент не имеет свойств, создаваясь в виде пустых объектов в файле `generators/имя_генератора.files/structures.toml`. Пример: +Структура - набор правил по вставке фрагмента в мир генератором. Структуры объявляются в виде объектов в файле `generators/имя_генератора.files/structures.toml`. Пример: ```toml tree0 = {} tree1 = {} tree2 = {} -tower = {} +tower = {lowering=-2} coal_ore0 = {} ``` На данный момент, имя структуры должно совпадать с именем использованного фрагмента. +Доступные свойства: +- lowering - глубина погружения структуры под поверхность. + ## Биомы Биом определяет то, из каких блоков и какими слоями генерируется ландшафт, а так же набор растений, структур. diff --git a/res/content/base/generators/demo.files/structures.toml b/res/content/base/generators/demo.files/structures.toml index 3dcf3cda..12edb165 100644 --- a/res/content/base/generators/demo.files/structures.toml +++ b/res/content/base/generators/demo.files/structures.toml @@ -1,5 +1,5 @@ tree0 = {} tree1 = {} tree2 = {} -tower = {} +tower = {lowering=2} coal_ore0 = {} diff --git a/src/content/loading/GeneratorLoader.cpp b/src/content/loading/GeneratorLoader.cpp index ebae9118..8aef7f7b 100644 --- a/src/content/loading/GeneratorLoader.cpp +++ b/src/content/loading/GeneratorLoader.cpp @@ -127,7 +127,7 @@ static VoxelStructureMeta load_structure_meta( ) { VoxelStructureMeta meta; meta.name = name; - + config.at("lowering").get(meta.lowering); return meta; } diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index 7477d2f3..9fe44327 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -127,7 +127,7 @@ void TextBox::drawBackground(const DrawContext* pctx, Assets*) { void TextBox::refreshLabel() { label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f)); - label->setText(getText()); + label->setText(input.empty() && !hint.empty() ? hint : getText()); if (autoresize && font) { auto size = getSize(); @@ -505,7 +505,7 @@ void TextBox::performEditingKeyboardEvents(keycode key) { } else { defocus(); if (validate() && consumer) { - consumer(label->getText()); + consumer(getText()); } } } else if (key == keycode::TAB) { @@ -627,7 +627,7 @@ glm::vec4 TextBox::getErrorColor() const { return invalidColor; } -std::wstring TextBox::getText() const { +const std::wstring& TextBox::getText() const { if (input.empty()) return placeholder; return input; @@ -638,7 +638,7 @@ void TextBox::setText(const std::wstring& value) { input.erase(std::remove(input.begin(), input.end(), '\r'), input.end()); } -std::wstring TextBox::getPlaceholder() const { +const std::wstring& TextBox::getPlaceholder() const { return placeholder; } @@ -646,6 +646,15 @@ void TextBox::setPlaceholder(const std::wstring& placeholder) { this->placeholder = placeholder; } + +const std::wstring& TextBox::getHint() const { + return hint; +} + +void TextBox::setHint(const std::wstring& text) { + this->hint = text; +} + std::wstring TextBox::getSelection() const { return input.substr(selectionStart, selectionEnd-selectionStart); } diff --git a/src/graphics/ui/elements/TextBox.hpp b/src/graphics/ui/elements/TextBox.hpp index c7898307..834f7a64 100644 --- a/src/graphics/ui/elements/TextBox.hpp +++ b/src/graphics/ui/elements/TextBox.hpp @@ -13,23 +13,35 @@ namespace gui { glm::vec4 focusedColor {0.0f, 0.0f, 0.0f, 1.0f}; glm::vec4 invalidColor {0.1f, 0.05f, 0.03f, 1.0f}; std::shared_ptr