add console on_open 'mode' argument

This commit is contained in:
MihailRis 2024-11-19 08:30:50 +03:00
parent e80b10dbda
commit 78ea12aa26
4 changed files with 25 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -230,7 +230,11 @@ void Hud::processInput(bool visible) {
}
}
if (!pause && Events::jactive(BIND_DEVTOOLS_CONSOLE)) {
showOverlay(assets->get<UiDocument>("core:console"), false);
showOverlay(
assets->get<UiDocument>("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<InventoryView>(element.getNode());
auto inventory = invview ? invview->getInventory() : nullptr;
std::vector<dv::value> args;
std::vector<dv::value> args {arg};
args.emplace_back(inventory ? inventory.get()->getId() : 0);
for (int i = 0; i < 3; i++) {
args.emplace_back(static_cast<integer_t>(blockPos[i]));

View File

@ -2,6 +2,7 @@
#include "typedefs.hpp"
#include "util/ObjectsKeeper.hpp"
#include "data/dv.hpp"
#include <string>
#include <memory>
@ -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<gui::UINode>& node);