ADD: InventoryContainer
This commit is contained in:
parent
8c50f61d5f
commit
00e7826209
@ -151,6 +151,8 @@ add_executable(Dicewars_Siedler src/main.cpp
|
|||||||
src/game/ui/components/UiRessourceWidget.h
|
src/game/ui/components/UiRessourceWidget.h
|
||||||
src/game/ui/components/factorys/RessourceWidgetFactory.cpp
|
src/game/ui/components/factorys/RessourceWidgetFactory.cpp
|
||||||
src/game/ui/components/factorys/RessourceWidgetFactory.h
|
src/game/ui/components/factorys/RessourceWidgetFactory.h
|
||||||
|
src/game/ui/components/UiInventoryContainer.cpp
|
||||||
|
src/game/ui/components/UiInventoryContainer.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(Dicewars_Siedler PRIVATE
|
target_include_directories(Dicewars_Siedler PRIVATE
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include "../engine/core/gui/uiComponent/UiText.h"
|
#include "../engine/core/gui/uiComponent/UiText.h"
|
||||||
#include "../engine/renderer/loader/Loader.h"
|
#include "../engine/renderer/loader/Loader.h"
|
||||||
#include "../engine/renderer/model/GUITexture.h"
|
#include "../engine/renderer/model/GUITexture.h"
|
||||||
|
#include "ui/components/UiInventoryContainer.h"
|
||||||
#include "ui/components/UiRessourceWidget.h"
|
#include "ui/components/UiRessourceWidget.h"
|
||||||
#include "ui/components/factorys/RessourceWidgetFactory.h"
|
#include "ui/components/factorys/RessourceWidgetFactory.h"
|
||||||
|
|
||||||
@ -61,27 +62,18 @@ void UILayer::onAttach() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//rootContainer->addChild(std::move(button));
|
//rootContainer->addChild(std::move(button));
|
||||||
|
|
||||||
auto inventoryContainer = std::make_unique<UiContainer>();
|
|
||||||
inventoryContainer->getLayoutStyle().flexDirection = FlexDirection::Row;
|
|
||||||
inventoryContainer->getLayoutStyle().width = SizeValue(300.f, SizeUnit::Pixels); // Platz für mehrere Ressourcen
|
|
||||||
inventoryContainer->getLayoutStyle().height = SizeValue(60.f, SizeUnit::Pixels);
|
|
||||||
inventoryContainer->getLayoutStyle().margin.left = {100.f, SizeUnit::Pixels};
|
|
||||||
inventoryContainer->getLayoutStyle().alignItems = AlignItems::Center;
|
|
||||||
|
|
||||||
smallFont =std::make_unique<Font>("/usr/share/fonts/TTF/DejaVuSans.ttf", 18);
|
smallFont =std::make_unique<Font>("/usr/share/fonts/TTF/DejaVuSans.ttf", 18);
|
||||||
|
|
||||||
auto wood_widget = RessourceWidgetFactory::create("assets/ui/ressource-icons/wood-log.png", 10, *smallFont, 0.0f);
|
|
||||||
auto stone_widget = RessourceWidgetFactory::create("assets/ui/ressource-icons/granite.png", 1139, *smallFont, 20.0f);
|
|
||||||
auto bread_widget = RessourceWidgetFactory::create("assets/ui/ressource-icons/bread.png", 10, *smallFont, 20.0f);
|
|
||||||
auto human_widget = RessourceWidgetFactory::create("assets/ui/ressource-icons/humans.png", 10, *smallFont, 20.0f);
|
|
||||||
auto military_widget = RessourceWidgetFactory::create("assets/ui/ressource-icons/swords.png", 10, *smallFont, 20.0f);
|
|
||||||
|
|
||||||
rootContainer->addChild(std::move(wood_widget));
|
auto inventoryContainer = std::make_unique<UiInventoryContainer>(*smallFont);
|
||||||
rootContainer->addChild(std::move(stone_widget));
|
|
||||||
rootContainer->addChild(std::move(bread_widget));
|
inventoryContainer->addRessource("assets/ui/ressource-icons/wood-log.png", 10);
|
||||||
rootContainer->addChild(std::move(human_widget));
|
inventoryContainer->addRessource("assets/ui/ressource-icons/granite.png", 1139);
|
||||||
rootContainer->addChild(std::move(military_widget));
|
inventoryContainer->addRessource("assets/ui/ressource-icons/humans.png", 523);
|
||||||
|
inventoryContainer->addRessource("assets/ui/ressource-icons/bread.png", 89);
|
||||||
|
inventoryContainer->addRessource("assets/ui/ressource-icons/swords.png", 45);
|
||||||
|
|
||||||
|
rootContainer->addChild(std::move(inventoryContainer));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
src/game/ui/components/UiInventoryContainer.cpp
Normal file
5
src/game/ui/components/UiInventoryContainer.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 13.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "UiInventoryContainer.h"
|
||||||
44
src/game/ui/components/UiInventoryContainer.h
Normal file
44
src/game/ui/components/UiInventoryContainer.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 13.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DICEWARS_SIEDLER_UIINVENTORYCONTAINER_H
|
||||||
|
#define DICEWARS_SIEDLER_UIINVENTORYCONTAINER_H
|
||||||
|
#include "UiRessourceWidget.h"
|
||||||
|
#include "../../../engine/core/gui/uiComponent/UiComponent.h"
|
||||||
|
#include "../../../engine/renderer/loader/Loader.h"
|
||||||
|
#include "factorys/RessourceWidgetFactory.h"
|
||||||
|
|
||||||
|
// UiInventoryContainer.h
|
||||||
|
class UiInventoryContainer : public UiComponent {
|
||||||
|
public:
|
||||||
|
UiInventoryContainer(Font& font) : font(font) {
|
||||||
|
LayoutStyle containerStyle;
|
||||||
|
containerStyle.width = SizeValue(1.f, SizeUnit::Percent);
|
||||||
|
containerStyle.height = SizeValue(80.f, SizeUnit::Pixels);
|
||||||
|
containerStyle.flexDirection = FlexDirection::Row;
|
||||||
|
containerStyle.justifyContent = JustifyContent::Center;
|
||||||
|
containerStyle.alignItems = AlignItems::Center;
|
||||||
|
|
||||||
|
uiPositioner.setLayout(containerStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addRessource(const std::string& iconPath, int amount) {
|
||||||
|
float marginLeft = (widgets.empty()) ? 0.0f : 10.0f;
|
||||||
|
auto widget = RessourceWidgetFactory::create(iconPath, amount, font, marginLeft);
|
||||||
|
widgets.push_back(widget.get());
|
||||||
|
addChild(std::move(widget));
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateRessource(size_t index, int newAmount) {
|
||||||
|
if (index < widgets.size()) {
|
||||||
|
// widgets[index]->updateAmount(newAmount); // falls du so eine Methode implementierst
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Font& font;
|
||||||
|
std::vector<UiRessourceWidget*> widgets; // raw pointers für Zugriff
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DICEWARS_SIEDLER_UIINVENTORYCONTAINER_H
|
||||||
Loading…
Reference in New Issue
Block a user