This commit is contained in:
MihailRis
2024-04-28 22:33:34 +03:00
parent 167388aefb
commit ef28a368cb
12 changed files with 54 additions and 51 deletions
+8 -12
View File
@@ -136,7 +136,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
batch->setColor(glm::vec4(1.0f));
auto previews = frontend->getBlocksAtlas();
auto previews = assets->getAtlas("block-previews");
auto indices = content->getIndices();
ItemDef* item = indices->getItemDef(stack.getItemId());
@@ -181,7 +181,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
int x = pos.x+slotSize-text.length()*8;
int y = pos.y+slotSize-16;
batch->setColor(glm::vec4(0, 0, 0, 1.0f));
batch->setColor({0, 0, 0, 1.0f});
font->draw(batch, text, x+1, y+1);
batch->setColor(glm::vec4(1.0f));
font->draw(batch, text, x, y);
@@ -266,13 +266,12 @@ void SlotView::onFocus(gui::GUI* gui) {
void SlotView::bind(
int64_t inventoryid,
ItemStack& stack,
LevelFrontend* frontend,
const Content* content,
InventoryInteraction* interaction
) {
this->inventoryid = inventoryid;
bound = &stack;
content = frontend->getLevel()->content;
this->frontend = frontend;
this->content = content;
this->interaction = interaction;
}
@@ -332,21 +331,18 @@ void InventoryView::bind(
slot->bind(
inventory->getId(),
inventory->getSlot(slot->getLayout().index),
frontend, interaction
content, interaction
);
}
}
void InventoryView::unbind() {
if (inventory && inventory->isVirtual()) {
frontend->getLevel()->inventories->remove(inventory->getId());
}
inventory = nullptr;
}
void InventoryView::setSelected(int index) {
for (int i = 0; i < int(slots.size()); i++) {
auto slot = slots[i];
slot->setHighlighted(i == index);
for (size_t i = 0; i < slots.size(); i++) {
slots[i]->setHighlighted(static_cast<int>(i) == index);
}
}
+1 -2
View File
@@ -59,7 +59,6 @@ struct SlotLayout {
};
class SlotView : public gui::UINode {
LevelFrontend* frontend = nullptr;
InventoryInteraction* interaction = nullptr;
const Content* content;
SlotLayout layout;
@@ -81,7 +80,7 @@ public:
void bind(
int64_t inventoryid,
ItemStack& stack,
LevelFrontend* frontend,
const Content* content,
InventoryInteraction* interaction
);
+5 -6
View File
@@ -15,9 +15,12 @@ LevelFrontend::LevelFrontend(LevelController* controller, Assets* assets)
: level(controller->getLevel()),
controller(controller),
assets(assets),
contentCache(std::make_unique<ContentGfxCache>(level->content, assets)),
blocksAtlas(BlocksPreview::build(contentCache.get(), assets, level->content))
contentCache(std::make_unique<ContentGfxCache>(level->content, assets))
{
assets->store(
BlocksPreview::build(contentCache.get(), assets, level->content).release(),
"block-previews"
);
controller->getPlayerController()->listenBlockInteraction(
[=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) {
auto material = level->content->findBlockMaterial(def->material);
@@ -79,10 +82,6 @@ ContentGfxCache* LevelFrontend::getContentGfxCache() const {
return contentCache.get();
}
Atlas* LevelFrontend::getBlocksAtlas() const {
return blocksAtlas.get();
}
LevelController* LevelFrontend::getController() const {
return controller;
}
-5
View File
@@ -3,10 +3,8 @@
#include <memory>
class Atlas;
class Level;
class Assets;
class BlocksPreview;
class ContentGfxCache;
class LevelController;
@@ -15,7 +13,6 @@ class LevelFrontend {
LevelController* controller;
Assets* assets;
std::unique_ptr<ContentGfxCache> contentCache;
std::unique_ptr<Atlas> blocksAtlas;
public:
LevelFrontend(LevelController* controller, Assets* assets);
~LevelFrontend();
@@ -23,8 +20,6 @@ public:
Level* getLevel() const;
Assets* getAssets() const;
ContentGfxCache* getContentGfxCache() const;
Atlas* getBlocksAtlas() const;
LevelController* getController() const;
};
+1 -1
View File
@@ -153,7 +153,7 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
grabbedItemView->bind(
0,
interaction->getGrabbedItem(),
frontend,
frontend->getLevel()->content,
interaction.get()
);
grabbedItemView->setColor(glm::vec4());