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