diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp index 050b075e..a09d64c1 100644 --- a/src/frontend/InventoryView.cpp +++ b/src/frontend/InventoryView.cpp @@ -28,6 +28,10 @@ void InventoryLayout::add(SlotLayout slot) { slots.push_back(slot); } +void InventoryLayout::add(InventoryPanel panel) { + panels.push_back(panel); +} + void InventoryLayout::setSize(glm::vec2 size) { this->size = size; } @@ -48,6 +52,10 @@ std::vector& InventoryLayout::getSlots() { return slots; } +std::vector& InventoryLayout::getPanels() { + return panels; +} + SlotLayout::SlotLayout( glm::vec2 position, bool background, @@ -74,7 +82,8 @@ InventoryBuilder::InventoryBuilder() void InventoryBuilder::addGrid( int cols, int count, glm::vec2 coord, - int padding, + int padding, + bool addpanel, SlotLayout slotLayout) { const int slotSize = InventoryView::SLOT_SIZE; @@ -97,7 +106,7 @@ void InventoryBuilder::addGrid( for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { if (row * cols + col >= count) - return; + break; glm::vec2 position ( col * (slotSize + interval) + padding, row * (slotSize + interval) + padding @@ -107,6 +116,32 @@ void InventoryBuilder::addGrid( layout->add(builtSlot); } } + + if (addpanel) { + add(InventoryPanel( + coord, + glm::vec2(width, height), + glm::vec4(0, 0, 0, 0.5f))); + } +} + +void InventoryBuilder::add(SlotLayout slotLayout) { + uint width = InventoryView::SLOT_SIZE; + uint height = InventoryView::SLOT_SIZE; + + auto coord = slotLayout.position; + auto lsize = layout->getSize(); + if (coord.x + width > lsize.x) { + lsize.x = coord.x + width; + } + if (coord.y + height > lsize.y) { + lsize.y = coord.y + height; + } + layout->add(slotLayout); +} + +void InventoryBuilder::add(InventoryPanel panel) { + layout->add(panel); } std::unique_ptr InventoryBuilder::build() { @@ -275,7 +310,7 @@ InventoryView::InventoryView( frontend(frontend), interaction(interaction) { size(this->layout->getSize()); - color(glm::vec4(0, 0, 0, 0.5f)); + color(glm::vec4(0, 0, 0, 0.0f)); } InventoryView::~InventoryView() {} @@ -321,7 +356,13 @@ InventoryLayout* InventoryView::getLayout() const { void InventoryView::drawBackground(Batch2D* batch, Assets* assets) { glm::vec2 coord = calcCoord(); + batch->texture(nullptr); - batch->color = color_; - batch->rect(coord.x-1, coord.y-1, size_.x+2, size_.y+2); + + for (auto& panel : layout->getPanels()) { + glm::vec2 size = panel.size; + glm::vec2 pos = coord + panel.position; + batch->color = panel.color; + batch->rect(pos.x-1, pos.y-1, size.x+2, size.y+2); + } } diff --git a/src/frontend/InventoryView.h b/src/frontend/InventoryView.h index c8c4801d..cb31da01 100644 --- a/src/frontend/InventoryView.h +++ b/src/frontend/InventoryView.h @@ -53,10 +53,12 @@ class InventoryLayout { glm::vec2 size; glm::vec2 origin; std::vector slots; + std::vector panels; public: InventoryLayout(glm::vec2 size); void add(SlotLayout slot); + void add(InventoryPanel panel); void setSize(glm::vec2 size); void setOrigin(glm::vec2 origin); @@ -64,6 +66,7 @@ public: glm::vec2 getOrigin() const; std::vector& getSlots(); + std::vector& getPanels(); }; class InventoryBuilder { @@ -74,8 +77,13 @@ public: void addGrid( int cols, int count, glm::vec2 coord, - int padding, + int padding, + bool addpanel, SlotLayout slotLayout); + + void add(SlotLayout slotLayout); + void add(InventoryPanel panel); + std::unique_ptr build(); }; diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 4d0a5493..b8e2db63 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -187,7 +187,7 @@ std::shared_ptr HudRenderer::createContentAccess() { }); InventoryBuilder builder; - builder.addGrid(8, itemsCount-1, glm::vec2(), 8, slotLayout); + builder.addGrid(8, itemsCount-1, glm::vec2(), 8, true, slotLayout); auto layout = builder.build(); auto contentAccess = std::make_shared( @@ -209,7 +209,7 @@ std::shared_ptr HudRenderer::createHotbar() { SlotLayout slotLayout(glm::vec2(), false, false, nullptr, nullptr); InventoryBuilder builder; - builder.addGrid(10, 10, glm::vec2(), 4, slotLayout); + builder.addGrid(10, 10, glm::vec2(), 4, true, slotLayout); auto layout = builder.build(); layout->setOrigin(glm::vec2(layout->getSize().x/2, 0)); @@ -236,7 +236,7 @@ std::shared_ptr HudRenderer::createInventory() { }, nullptr); InventoryBuilder builder; - builder.addGrid(10, inventory->size(), glm::vec2(), 4, slotLayout); + builder.addGrid(10, inventory->size(), glm::vec2(), 4, true, slotLayout); auto layout = builder.build(); auto view = std::make_shared(