hud.open_block 4th overlay mode argument
This commit is contained in:
+24
-15
@@ -380,7 +380,7 @@ void Hud::update(bool visible) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 invSize = contentAccessPanel->getSize();
|
glm::vec2 invSize = contentAccessPanel->getSize();
|
||||||
contentAccessPanel->setVisible(inventoryOpen);
|
contentAccessPanel->setVisible(inventoryView != nullptr);
|
||||||
contentAccessPanel->setSize(glm::vec2(invSize.x, Window::height));
|
contentAccessPanel->setSize(glm::vec2(invSize.x, Window::height));
|
||||||
contentAccess->setMinSize(glm::vec2(1, Window::height));
|
contentAccess->setMinSize(glm::vec2(1, Window::height));
|
||||||
hotbarView->setVisible(visible);
|
hotbarView->setVisible(visible);
|
||||||
@@ -436,7 +436,7 @@ void Hud::openInventory() {
|
|||||||
* @param blockinv block inventory.
|
* @param blockinv block inventory.
|
||||||
* In case of nullptr a new virtual inventory will be created
|
* In case of nullptr a new virtual inventory will be created
|
||||||
*/
|
*/
|
||||||
void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inventory> blockinv) {
|
void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inventory> blockinv, bool playerInventory) {
|
||||||
if (isInventoryOpen()) {
|
if (isInventoryOpen()) {
|
||||||
closeInventory();
|
closeInventory();
|
||||||
}
|
}
|
||||||
@@ -445,7 +445,11 @@ void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inven
|
|||||||
if (blockUI == nullptr) {
|
if (blockUI == nullptr) {
|
||||||
throw std::runtime_error("block UI root element must be 'inventory'");
|
throw std::runtime_error("block UI root element must be 'inventory'");
|
||||||
}
|
}
|
||||||
openInventory();
|
if (playerInventory) {
|
||||||
|
openInventory();
|
||||||
|
} else {
|
||||||
|
inventoryOpen = true;
|
||||||
|
}
|
||||||
if (blockinv == nullptr) {
|
if (blockinv == nullptr) {
|
||||||
blockinv = level->inventories->createVirtual(blockUI->getSlotsCount());
|
blockinv = level->inventories->createVirtual(blockUI->getSlotsCount());
|
||||||
}
|
}
|
||||||
@@ -594,25 +598,30 @@ void Hud::draw(const GfxContext& ctx){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inventoryOpen) {
|
if (inventoryOpen) {
|
||||||
float caWidth = contentAccess->getSize().x;
|
float caWidth = inventoryView ? contentAccess->getSize().x : 0.0f;
|
||||||
contentAccessPanel->setCoord(glm::vec2(width-caWidth, 0));
|
contentAccessPanel->setCoord(glm::vec2(width-caWidth, 0));
|
||||||
|
|
||||||
glm::vec2 invSize = inventoryView->getSize();
|
glm::vec2 invSize = inventoryView ? inventoryView->getSize() : glm::vec2();
|
||||||
if (blockUI == nullptr) {
|
if (blockUI == nullptr) {
|
||||||
inventoryView->setCoord(glm::vec2(
|
if (inventoryView) {
|
||||||
glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x),
|
inventoryView->setCoord(glm::vec2(
|
||||||
height/2-invSize.y/2
|
glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x),
|
||||||
));
|
height/2-invSize.y/2
|
||||||
|
));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
glm::vec2 blockInvSize = blockUI->getSize();
|
glm::vec2 blockInvSize = blockUI->getSize();
|
||||||
int interval = 5;
|
float invwidth = glm::max(invSize.x, blockInvSize.x);
|
||||||
|
int interval = invSize.y > 0.0 ? 5 : 0;
|
||||||
float totalHeight = invSize.y + blockInvSize.y + interval;
|
float totalHeight = invSize.y + blockInvSize.y + interval;
|
||||||
inventoryView->setCoord(glm::vec2(
|
if (inventoryView) {
|
||||||
glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x),
|
inventoryView->setCoord(glm::vec2(
|
||||||
height/2+totalHeight/2-invSize.y
|
glm::min(width/2-invwidth/2, width-caWidth-10-invwidth),
|
||||||
));
|
height/2+totalHeight/2-invSize.y
|
||||||
|
));
|
||||||
|
}
|
||||||
blockUI->setCoord(glm::vec2(
|
blockUI->setCoord(glm::vec2(
|
||||||
glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x),
|
glm::min(width/2-invwidth/2, width-caWidth-10-invwidth),
|
||||||
height/2-totalHeight/2
|
height/2-totalHeight/2
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -110,7 +110,7 @@ public:
|
|||||||
void setPause(bool pause);
|
void setPause(bool pause);
|
||||||
|
|
||||||
void openInventory();
|
void openInventory();
|
||||||
void openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inventory> blockInv);
|
void openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inventory> blockInv, bool playerInventory);
|
||||||
void closeInventory();
|
void closeInventory();
|
||||||
void openPermanent(UiDocument* doc);
|
void openPermanent(UiDocument* doc);
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ int l_hud_open_block(lua_State* L) {
|
|||||||
lua::luaint x = lua_tointeger(L, 1);
|
lua::luaint x = lua_tointeger(L, 1);
|
||||||
lua::luaint y = lua_tointeger(L, 2);
|
lua::luaint y = lua_tointeger(L, 2);
|
||||||
lua::luaint z = lua_tointeger(L, 3);
|
lua::luaint z = lua_tointeger(L, 3);
|
||||||
|
bool playerInventory = !lua_toboolean(L, 4);
|
||||||
|
|
||||||
voxel* vox = scripting::level->chunks->get(x, y, z);
|
voxel* vox = scripting::level->chunks->get(x, y, z);
|
||||||
if (vox == nullptr) {
|
if (vox == nullptr) {
|
||||||
@@ -55,7 +56,7 @@ int l_hud_open_block(lua_State* L) {
|
|||||||
auto id = scripting::blocks->createBlockInventory(x, y, z);
|
auto id = scripting::blocks->createBlockInventory(x, y, z);
|
||||||
|
|
||||||
scripting::hud->openInventory(
|
scripting::hud->openInventory(
|
||||||
glm::ivec3(x, y, z), layout, scripting::level->inventories->get(id)
|
glm::ivec3(x, y, z), layout, scripting::level->inventories->get(id), playerInventory
|
||||||
);
|
);
|
||||||
|
|
||||||
lua_pushinteger(L, id);
|
lua_pushinteger(L, id);
|
||||||
|
|||||||
Reference in New Issue
Block a user