Merge pull request #930 from Neveix/feat-inventory-enhancements

[WIP] Inventory enhancements
This commit is contained in:
MihailRis 2026-08-14 00:56:52 +03:00 • committed by GitHub
commit f8e4e2759b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 88 additions and 24 deletions

View file

@ -174,6 +174,15 @@ Hud::Hud(Engine& engine, LevelFrontend& frontend, Player& player)
gui,
"<container size='4000' color='#00000080' z-index='-1' visible='false'/>"
);
inventoryDropArea = guiutil::create(
gui,
R"(<container size='4000' color='#00000000' z-index='-1' visible='false'
onclick='events.emit(\"core:drop_outside_inventory\", 0)'
onrightclick='events.emit(\"core:drop_outside_inventory\", 1)'
onmiddleclick='events.emit(\"core:drop_outside_inventory\", 2)'
/>)"
);
uicamera = std::make_unique<Camera>(glm::vec3(), 1);
uicamera->perspective = false;
@ -188,6 +197,7 @@ Hud::Hud(Engine& engine, LevelFrontend& frontend, Player& player)
gui.add(debugPanel);
gui.add(darkOverlay);
gui.add(inventoryDropArea);
gui.add(hotbarView);
gui.add(contentAccessPanel);
@ -213,6 +223,7 @@ Hud::~Hud() {
}
gui.remove(hotbarView);
gui.remove(darkOverlay);
gui.remove(inventoryDropArea);
gui.remove(contentAccessPanel);
gui.remove(debugPanel);
}
@ -358,6 +369,7 @@ void Hud::update(bool visible) {
contentAccess->setMinSize(glm::vec2(1, windowSize.y));
hotbarView->setVisible(visible && !(secondUI && !inventoryView));
darkOverlay->setVisible(isMenuOpen);
inventoryDropArea->setVisible(inventoryOpen);
menu.setVisible(isMenuOpen);
if (visible) {
@ -739,6 +751,10 @@ std::shared_ptr<Inventory> Hud::getSecondInventory() {
return nullptr;
}
std::shared_ptr<Inventory> Hud::getExchangeInventory() {
return exchangeSlotInv;
}
bool Hud::isContentAccess() const {
return showContentPanel;
}

View file

@ -93,6 +93,8 @@ class Hud : public util::ObjectsKeeper {
std::shared_ptr<gui::UINode> debugPanel;
/// @brief Overlay used in pause mode
std::shared_ptr<gui::UINode> darkOverlay;
/// @brief Overlay used in inventory
std::shared_ptr<gui::UINode> inventoryDropArea;
/// @brief Inventories interaction agent (grabbed item)
std::shared_ptr<gui::SlotView> exchangeSlot;
/// @brief Exchange slot inventory (1 slot only)
@ -207,6 +209,8 @@ public:
std::shared_ptr<Inventory> getSecondInventory();
std::shared_ptr<Inventory> getExchangeInventory();
bool isContentAccess() const;
void setContentAccess(bool flag);

View file

@ -14,7 +14,6 @@
#include "frontend/UiDocument.hpp"
#include "frontend/locale.hpp"
#include "graphics/core/Batch2D.hpp"
#include "graphics/core/LineBatch.hpp"
#include "graphics/core/Shader.hpp"
#include "graphics/core/Font.hpp"
#include "graphics/core/DrawContext.hpp"

View file

@ -12,11 +12,8 @@
#include "graphics/core/Batch2D.hpp"
#include "graphics/core/DrawContext.hpp"
#include "graphics/core/Font.hpp"
#include "graphics/core/Shader.hpp"
#include "graphics/core/Texture.hpp"
#include "graphics/render/BlocksPreview.hpp"
#include "graphics/ui/GUI.hpp"
#include "items/Inventories.hpp"
#include "items/Inventory.hpp"
#include "items/ItemDef.hpp"
#include "logic/scripting/scripting.hpp"

View file

@ -149,6 +149,15 @@ static int l_get_second_inventory(lua::State* L) {
}
}
static int l_get_exchange_inventory(lua::State* L) {
auto inventory = hud->getExchangeInventory();
if (inventory == nullptr) {
return lua::pushinteger(L, 0);
} else {
return lua::pushinteger(L, inventory->getId());
}
}
static int l_get_player(lua::State* L) {
auto player = hud->getPlayer();
return lua::pushinteger(L, player->getId());
@ -216,6 +225,7 @@ const luaL_Reg hudlib[] = {
{"show_overlay", wrap_hud<l_show_overlay>},
{"get_block_inventory", wrap_hud<l_get_block_inventory>},
{"get_second_inventory", wrap_hud<l_get_second_inventory>},
{"get_exchange_inventory", wrap_hud<l_get_exchange_inventory>},
{"close", wrap_hud<l_close>},
{"pause", wrap_hud<l_pause>},
{"resume", wrap_hud<l_resume>},