Merge branch 'dev' into canvases-and-atlases

This commit is contained in:
MihailRis
2025-11-05 02:40:31 +03:00
4 changed files with 49 additions and 5 deletions
+3 -1
View File
@@ -441,7 +441,9 @@ function __vc_on_hud_open()
end) end)
input.add_callback("key:escape", function() input.add_callback("key:escape", function()
if menu.page ~= "" then if menu.page ~= "" then
menu:reset() if not menu:back() then
menu:reset()
end
elseif hud.is_inventory_open() then elseif hud.is_inventory_open() then
hud.close_inventory() hud.close_inventory()
else else
+9
View File
@@ -26,6 +26,7 @@
#include "graphics/core/ImageData.hpp" #include "graphics/core/ImageData.hpp"
#include "graphics/core/Shader.hpp" #include "graphics/core/Shader.hpp"
#include "graphics/ui/GUI.hpp" #include "graphics/ui/GUI.hpp"
#include "graphics/ui/elements/Menu.hpp"
#include "objects/rigging.hpp" #include "objects/rigging.hpp"
#include "logic/EngineController.hpp" #include "logic/EngineController.hpp"
#include "logic/CommandsInterpreter.hpp" #include "logic/CommandsInterpreter.hpp"
@@ -154,6 +155,14 @@ void Engine::initializeClient() {
}, },
true true
)); ));
keepAlive(this->input->addKeyCallback(Keycode::ESCAPE, [this]() {
auto& menu = *gui->getMenu();
if (menu.hasOpenPage() && menu.back()) {
return true;
}
return false;
}));
} }
void Engine::initialize(CoreParameters coreParameters) { void Engine::initialize(CoreParameters coreParameters) {
+36 -3
View File
@@ -9,6 +9,7 @@
#include "graphics/ui/elements/TextBox.hpp" #include "graphics/ui/elements/TextBox.hpp"
#include "graphics/ui/elements/TrackBar.hpp" #include "graphics/ui/elements/TrackBar.hpp"
#include "graphics/ui/elements/InputBindBox.hpp" #include "graphics/ui/elements/InputBindBox.hpp"
#include "graphics/ui/GUI.hpp"
#include "graphics/render/WorldRenderer.hpp" #include "graphics/render/WorldRenderer.hpp"
#include "graphics/render/ParticlesRenderer.hpp" #include "graphics/render/ParticlesRenderer.hpp"
#include "graphics/render/ChunksRenderer.hpp" #include "graphics/render/ChunksRenderer.hpp"
@@ -43,10 +44,15 @@ static std::shared_ptr<Label> create_label(GUI& gui, wstringsupplier supplier) {
return label; return label;
} }
static bool should_keep_previous(GUI& gui) {
return !gui.getInput().isCursorLocked();
}
// TODO: move to xml // TODO: move to xml
// TODO: move to xml finally // TODO: move to xml finally
// TODO: move to xml finally // TODO: move to xml finally
// TODO: move to xml finally // TODO: move to xml finally
// TODO: move to xml finally
std::shared_ptr<UINode> create_debug_panel( std::shared_ptr<UINode> create_debug_panel(
Engine& engine, Engine& engine,
Level& level, Level& level,
@@ -81,7 +87,7 @@ std::shared_ptr<UINode> create_debug_panel(
fpsMax = fps; fpsMax = fps;
}); });
panel->listenInterval(1.0f, [&engine]() { panel->listenInterval(1.0f, [&engine, &gui]() {
const auto& network = engine.getNetwork(); const auto& network = engine.getNetwork();
size_t totalDownload = network.getTotalDownload(); size_t totalDownload = network.getTotalDownload();
size_t totalUpload = network.getTotalUpload(); size_t totalUpload = network.getTotalUpload();
@@ -135,7 +141,16 @@ std::shared_ptr<UINode> create_debug_panel(
std::to_wstring(player.getId()); std::to_wstring(player.getId());
})); }));
panel->add(create_label(gui, [&]() -> std::wstring { panel->add(create_label(gui, [&]() -> std::wstring {
const auto& vox = player.selection.vox; // TODO: move to xml finally
static voxel prevVox = {BLOCK_VOID, {}};
auto vox = player.selection.vox;
if (vox.id == BLOCK_VOID && should_keep_previous(gui)) {
vox = prevVox;
} else {
prevVox = vox;
}
std::wstringstream stream; std::wstringstream stream;
stream << "r:" << vox.state.rotation << " s:" stream << "r:" << vox.state.rotation << " s:"
<< std::bitset<3>(vox.state.segment) << " u:" << std::bitset<3>(vox.state.segment) << " u:"
@@ -148,8 +163,17 @@ std::shared_ptr<UINode> create_debug_panel(
} }
})); }));
panel->add(create_label(gui, [&]() -> std::wstring { panel->add(create_label(gui, [&]() -> std::wstring {
const auto& selection = player.selection; // TODO: move to xml finally
static CursorSelection prevSelection {};
auto selection = player.selection;
const auto& vox = selection.vox; const auto& vox = selection.vox;
if (vox.id == BLOCK_VOID && should_keep_previous(gui)) {
selection = prevSelection;
} else {
prevSelection = selection;
}
if (vox.id == BLOCK_VOID) { if (vox.id == BLOCK_VOID) {
return L"x: - y: - z: -"; return L"x: - y: - z: -";
} }
@@ -158,7 +182,16 @@ std::shared_ptr<UINode> create_debug_panel(
L" z: " + std::to_wstring(selection.actualPosition.z); L" z: " + std::to_wstring(selection.actualPosition.z);
})); }));
panel->add(create_label(gui, [&]() { panel->add(create_label(gui, [&]() {
// TODO: move to xml finally
static entityid_t prevEid = ENTITY_NONE;
auto eid = player.getSelectedEntity(); auto eid = player.getSelectedEntity();
if (eid == ENTITY_NONE && should_keep_previous(gui)) {
eid = prevEid;
} else {
prevEid = eid;
}
if (eid == ENTITY_NONE) { if (eid == ENTITY_NONE) {
return std::wstring {L"entity: -"}; return std::wstring {L"entity: -"};
} else if (auto entity = level.entities->get(eid)) { } else if (auto entity = level.entities->get(eid)) {
+1 -1
View File
@@ -57,7 +57,7 @@ DocumentNode get_document_node(lua::State* L, int idx) {
static int l_menu_back(lua::State* L) { static int l_menu_back(lua::State* L) {
auto node = get_document_node(L); auto node = get_document_node(L);
if (auto menu = dynamic_cast<Menu*>(node.node.get())) { if (auto menu = dynamic_cast<Menu*>(node.node.get())) {
menu->back(); return lua::pushboolean(L, menu->back());
} }
return 0; return 0;
} }