InventoryBuilder add(InventoryPanel), add(SlotLayout)
This commit is contained in:
parent
0d62067e5a
commit
e4ef813705
@ -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<SlotLayout>& InventoryLayout::getSlots() {
|
||||
return slots;
|
||||
}
|
||||
|
||||
std::vector<InventoryPanel>& 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<InventoryLayout> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,10 +53,12 @@ class InventoryLayout {
|
||||
glm::vec2 size;
|
||||
glm::vec2 origin;
|
||||
std::vector<SlotLayout> slots;
|
||||
std::vector<InventoryPanel> 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<SlotLayout>& getSlots();
|
||||
std::vector<InventoryPanel>& 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<InventoryLayout> build();
|
||||
};
|
||||
|
||||
|
||||
@ -187,7 +187,7 @@ std::shared_ptr<InventoryView> 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<InventoryView>(
|
||||
@ -209,7 +209,7 @@ std::shared_ptr<InventoryView> 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<InventoryView> 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<InventoryView>(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user