diff --git a/res/layouts/console.xml.lua b/res/layouts/console.xml.lua index f251e120..2957c187 100644 --- a/res/layouts/console.xml.lua +++ b/res/layouts/console.xml.lua @@ -194,7 +194,7 @@ function set_mode(mode) console_mode = mode end -function on_open() +function on_open(mode) if modes == nil then modes = RadioGroup({ chat=document.s_chat, @@ -204,4 +204,7 @@ function on_open() set_mode(mode) end, "console") end + if mode then + modes:set(mode) + end end diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 4bade31d..7fc726f8 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -86,6 +86,9 @@ end local _RadioGroup = {} function _RadioGroup.set(self, key) + if type(self) ~= 'table' then + error("called as non-OOP via '.', use radiogroup:set") + end if self.current then self.elements[self.current].enabled = true end diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 89672c50..889b102f 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -230,7 +230,11 @@ void Hud::processInput(bool visible) { } } if (!pause && Events::jactive(BIND_DEVTOOLS_CONSOLE)) { - showOverlay(assets->get("core:console"), false); + showOverlay( + assets->get("core:console"), + false, + std::string("console") + ); } if (!Window::isFocused() && !pause && !isInventoryOpen()) { setPause(true); @@ -465,7 +469,9 @@ void Hud::showExchangeSlot() { } -void Hud::showOverlay(UiDocument* doc, bool playerInventory) { +void Hud::showOverlay( + UiDocument* doc, bool playerInventory, const dv::value& arg +) { if (isInventoryOpen()) { closeInventory(); } @@ -476,7 +482,8 @@ void Hud::showOverlay(UiDocument* doc, bool playerInventory) { showExchangeSlot(); inventoryOpen = true; } - add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false)); + add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false), + arg); } void Hud::openPermanent(UiDocument* doc) { @@ -508,13 +515,13 @@ void Hud::closeInventory() { cleanup(); } -void Hud::add(const HudElement& element) { +void Hud::add(const HudElement& element, const dv::value& arg) { gui->add(element.getNode()); auto document = element.getDocument(); if (document) { auto invview = std::dynamic_pointer_cast(element.getNode()); auto inventory = invview ? invview->getInventory() : nullptr; - std::vector args; + std::vector args {arg}; args.emplace_back(inventory ? inventory.get()->getId() : 0); for (int i = 0; i < 3; i++) { args.emplace_back(static_cast(blockPos[i])); diff --git a/src/frontend/hud.hpp b/src/frontend/hud.hpp index c5708527..4a2ecfd5 100644 --- a/src/frontend/hud.hpp +++ b/src/frontend/hud.hpp @@ -2,6 +2,7 @@ #include "typedefs.hpp" #include "util/ObjectsKeeper.hpp" +#include "data/dv.hpp" #include #include @@ -173,7 +174,10 @@ public: /// @brief Show element in inventory-mode /// @param doc element layout /// @param playerInventory show player inventory too - void showOverlay(UiDocument* doc, bool playerInventory); + /// @param arg first argument passing to on_open + void showOverlay( + UiDocument* doc, bool playerInventory, const dv::value& arg = nullptr + ); /// @brief Close all open inventories and overlay void closeInventory(); @@ -182,7 +186,7 @@ public: /// @param doc element layout void openPermanent(UiDocument* doc); - void add(const HudElement& element); + void add(const HudElement& element, const dv::value& arg=nullptr); void onRemove(const HudElement& element); void remove(const std::shared_ptr& node);