add 'args' parameter to hud.show_overlay
This commit is contained in:
parent
02578a6276
commit
e842b217da
@ -24,7 +24,9 @@ hud.open_block(x: int, y: int, z: int) -> int, str
|
|||||||
```lua
|
```lua
|
||||||
-- Show overlay with layout specified.
|
-- Show overlay with layout specified.
|
||||||
-- Shows player inventory also if playerinv is true.
|
-- Shows player inventory also if playerinv is true.
|
||||||
hud.show_overlay(layoutid: str, playerinv: bool)
|
-- Using `args` you can specify an array of parameter values that will be passed
|
||||||
|
-- to on_open of the overlay being shown.
|
||||||
|
hud.show_overlay(layoutid: str, playerinv: bool, [optional] args: table)
|
||||||
|
|
||||||
-- Add element to the screen.
|
-- Add element to the screen.
|
||||||
-- The element will be removed on world close only.
|
-- The element will be removed on world close only.
|
||||||
|
|||||||
@ -25,7 +25,9 @@ hud.open_block(x: int, y: int, z: int) -> int, str
|
|||||||
```lua
|
```lua
|
||||||
-- Показывает элемент в режиме оверлея.
|
-- Показывает элемент в режиме оверлея.
|
||||||
-- Также показывает инвентарь игрока, если playerinv - **true**.
|
-- Также показывает инвентарь игрока, если playerinv - **true**.
|
||||||
hud.show_overlay(layoutid: str, playerinv: bool)
|
-- Через args можно указать массив значений параметров, что будут переданы
|
||||||
|
-- в on_open показываемого оверлея.
|
||||||
|
hud.show_overlay(layoutid: str, playerinv: bool, [опционально] args: table)
|
||||||
|
|
||||||
-- Добавляет постоянный элемент на экран. Элемент не удаляется при
|
-- Добавляет постоянный элемент на экран. Элемент не удаляется при
|
||||||
-- закрытии инвентаря. Чтобы не перекрывать затенение в режиме
|
-- закрытии инвентаря. Чтобы не перекрывать затенение в режиме
|
||||||
|
|||||||
@ -233,7 +233,7 @@ void Hud::processInput(bool visible) {
|
|||||||
showOverlay(
|
showOverlay(
|
||||||
assets->get<UiDocument>("core:console"),
|
assets->get<UiDocument>("core:console"),
|
||||||
false,
|
false,
|
||||||
std::string("console")
|
dv::list({std::string("console")})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!Window::isFocused() && !pause && !isInventoryOpen()) {
|
if (!Window::isFocused() && !pause && !isInventoryOpen()) {
|
||||||
@ -470,7 +470,7 @@ void Hud::showExchangeSlot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Hud::showOverlay(
|
void Hud::showOverlay(
|
||||||
UiDocument* doc, bool playerInventory, const dv::value& arg
|
UiDocument* doc, bool playerInventory, const dv::value& args
|
||||||
) {
|
) {
|
||||||
if (isInventoryOpen()) {
|
if (isInventoryOpen()) {
|
||||||
closeInventory();
|
closeInventory();
|
||||||
@ -483,7 +483,7 @@ void Hud::showOverlay(
|
|||||||
inventoryOpen = true;
|
inventoryOpen = true;
|
||||||
}
|
}
|
||||||
add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false),
|
add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false),
|
||||||
arg);
|
args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hud::openPermanent(UiDocument* doc) {
|
void Hud::openPermanent(UiDocument* doc) {
|
||||||
@ -515,13 +515,18 @@ void Hud::closeInventory() {
|
|||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hud::add(const HudElement& element, const dv::value& arg) {
|
void Hud::add(const HudElement& element, const dv::value& argsArray) {
|
||||||
gui->add(element.getNode());
|
gui->add(element.getNode());
|
||||||
auto document = element.getDocument();
|
auto document = element.getDocument();
|
||||||
if (document) {
|
if (document) {
|
||||||
auto invview = std::dynamic_pointer_cast<InventoryView>(element.getNode());
|
auto invview = std::dynamic_pointer_cast<InventoryView>(element.getNode());
|
||||||
auto inventory = invview ? invview->getInventory() : nullptr;
|
auto inventory = invview ? invview->getInventory() : nullptr;
|
||||||
std::vector<dv::value> args {arg};
|
std::vector<dv::value> args;
|
||||||
|
if (argsArray != nullptr) {
|
||||||
|
for (const auto& arg : argsArray) {
|
||||||
|
args.push_back(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
args.emplace_back(inventory ? inventory.get()->getId() : 0);
|
args.emplace_back(inventory ? inventory.get()->getId() : 0);
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
args.emplace_back(static_cast<integer_t>(blockPos[i]));
|
args.emplace_back(static_cast<integer_t>(blockPos[i]));
|
||||||
|
|||||||
@ -98,7 +98,8 @@ static int l_show_overlay(lua::State* L) {
|
|||||||
if (layout == nullptr) {
|
if (layout == nullptr) {
|
||||||
throw std::runtime_error("there is no ui layout " + util::quote(name));
|
throw std::runtime_error("there is no ui layout " + util::quote(name));
|
||||||
}
|
}
|
||||||
hud->showOverlay(layout, playerInventory);
|
auto args = lua::tovalue(L, 3);
|
||||||
|
hud->showOverlay(layout, playerInventory, std::move(args));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,4 +189,5 @@ const luaL_Reg hudlib[] = {
|
|||||||
{"_is_content_access", lua::wrap<l_is_content_access>},
|
{"_is_content_access", lua::wrap<l_is_content_access>},
|
||||||
{"_set_content_access", lua::wrap<l_set_content_access>},
|
{"_set_content_access", lua::wrap<l_set_content_access>},
|
||||||
{"_set_debug_cheats", lua::wrap<l_set_debug_cheats>},
|
{"_set_debug_cheats", lua::wrap<l_set_debug_cheats>},
|
||||||
{NULL, NULL}};
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user