Merge branch 'main' into volume-renderer

This commit is contained in:
MihailRis 2025-12-28 20:05:13 +03:00
commit b8bf249d1b
9 changed files with 59 additions and 51 deletions

View file

@ -57,7 +57,7 @@ std::unique_ptr<Content> ContentBuilder::build() {
}
}
} else {
def.rt.hitboxes->emplace_back(AABB(glm::vec3(1.0f)));
def.rt.hitboxes[0] = def.hitboxes;
}
blockDefsIndices.push_back(&def);

View file

@ -383,17 +383,18 @@ void Hud::update(bool visible) {
}
/// @brief Show inventory on the screen and turn on inventory mode blocking movement
void Hud::openInventory() {
auto& content = frontend.getLevel().content;
void Hud::openInventory(bool playerInventory) {
showExchangeSlot();
inventoryOpen = true;
auto inventory = player.getInventory();
auto inventoryDocument = assets.get<UiDocument>("core:inventory");
inventoryView = std::dynamic_pointer_cast<InventoryView>(inventoryDocument->getRoot());
inventoryView->bind(inventory, &content);
add(HudElement(HudElementMode::INVENTORY, inventoryDocument, inventoryView, false));
add(HudElement(HudElementMode::INVENTORY, nullptr, exchangeSlot, false));
if (playerInventory) {
auto& content = frontend.getLevel().content;
auto inventory = player.getInventory();
auto inventoryDocument = assets.get<UiDocument>("core:inventory");
inventoryView = std::dynamic_pointer_cast<InventoryView>(inventoryDocument->getRoot());
inventoryView->bind(inventory, &content);
add(HudElement(HudElementMode::INVENTORY, inventoryDocument, inventoryView, false));
}
}
std::shared_ptr<Inventory> Hud::openInventory(
@ -412,11 +413,8 @@ std::shared_ptr<Inventory> Hud::openInventory(
}
secondUI = secondInvView;
if (playerInventory) {
openInventory();
} else {
inventoryOpen = true;
}
openInventory(playerInventory);
if (inv == nullptr) {
inv = level.inventories->createVirtual(secondInvView->getSlotsCount());
}
@ -444,11 +442,9 @@ void Hud::openInventory(
throw std::runtime_error("block UI root element must be 'inventory'");
}
secondUI = blockUI;
if (playerInventory) {
openInventory();
} else {
inventoryOpen = true;
}
openInventory(playerInventory);
if (blockinv == nullptr) {
blockinv = level.inventories->createVirtual(blockUI->getSlotsCount());
}
@ -477,6 +473,7 @@ void Hud::showExchangeSlot() {
exchangeSlot->setInteractive(false);
exchangeSlot->setZIndex(1);
gui.store(SlotView::EXCHANGE_SLOT_NAME, exchangeSlot);
add(HudElement(HudElementMode::INVENTORY, nullptr, exchangeSlot, false));
}
void Hud::showOverlay(
@ -486,12 +483,9 @@ void Hud::showOverlay(
closeInventory();
}
secondUI = doc->getRoot();
if (playerInventory) {
openInventory();
} else {
showExchangeSlot();
inventoryOpen = true;
}
openInventory(playerInventory);
add(HudElement(HudElementMode::INVENTORY, doc, secondUI, false), args);
}

View file

@ -156,7 +156,7 @@ public:
void setPause(bool pause);
/// @brief Show player inventory in inventory-mode
void openInventory();
void openInventory(bool playerInventory = true);
/// @brief Show inventory in inventory-mode
/// @param doc ui layout

View file

@ -25,7 +25,8 @@ void CheckBox::draw(const DrawContext& pctx, const Assets&) {
batch->rect(pos.x, pos.y, size.x, size.y);
}
void CheckBox::mouseRelease(int, int) {
void CheckBox::mouseRelease(int x, int y) {
UINode::mouseRelease(x, y);
checked = !checked;
if (consumer) {
consumer(checked);

View file

@ -349,11 +349,23 @@ static int l_caption(lua::State* L) {
return 0;
}
static lua::Integer get_variant_index(lua::State* L, const Block* const block, int argumentIndex) {
const auto variantIndex = lua::gettop(L) >= argumentIndex ? lua::tointeger(L, argumentIndex) : 0;
const size_t variantsSize = block->variants->variants.size();
if (variantIndex < 0 || variantIndex >= variantsSize) {
throw std::out_of_range(
"variant index out of bounds [0, " + std::to_string(variantsSize - 1) + "]");
}
return variantIndex;
}
static int l_get_textures(lua::State* L) {
if (auto def = get_block_def(L)) {
const auto& textureFaces = (def->variants ? def->variants->variants[get_variant_index(L, def, 2)].textureFaces :
def->defaults.textureFaces);
lua::createtable(L, 6, 0);
for (size_t i = 0; i < 6; i++) {
lua::pushstring(L, def->defaults.textureFaces[i]); // TODO: variant argument
lua::pushstring(L, textureFaces[i]);
lua::rawseti(L, i + 1);
}
return 1;
@ -364,8 +376,8 @@ static int l_get_textures(lua::State* L) {
static int l_model_name(lua::State* L) {
if (auto def = get_block_def(L)) {
// TODO: variant argument
const auto& modelName = def->defaults.model.name;
const auto& modelName = (def->variants ? def->variants->variants[get_variant_index(L, def, 2)].model.name :
def->defaults.model.name);
if (modelName.empty()) {
return lua::pushlstring(L, def->name + ".model");
}
@ -376,8 +388,9 @@ static int l_model_name(lua::State* L) {
static int l_get_model(lua::State* L) {
if (auto def = get_block_def(L)) {
// TODO: variant argument
return lua::pushlstring(L, BlockModelTypeMeta.getName(def->defaults.model.type));
const BlockModelType modelType = (def->variants ? def->variants->variants[get_variant_index(L, def, 2)].model.type :
def->defaults.model.type);
return lua::pushlstring(L, BlockModelTypeMeta.getName(modelType));
}
return 0;
}
@ -385,12 +398,13 @@ static int l_get_model(lua::State* L) {
static int l_get_hitbox(lua::State* L) {
if (auto def = get_block_def(L)) {
size_t rotation = lua::tointeger(L, 2);
const size_t hitboxIndex = static_cast<size_t>(lua::gettop(L) >= 3 ? lua::tointeger(L, 3) : 0);
if (def->rotatable) {
rotation %= def->rotations.MAX_COUNT;
} else {
rotation = 0;
}
auto& hitbox = def->rt.hitboxes[rotation].at(0);
auto& hitbox = def->rt.hitboxes[rotation].at(hitboxIndex);
lua::createtable(L, 2, 0);
lua::pushvec3(L, hitbox.min());