UPD: Make Building Buttons dependent on BuildingConfigurations
This commit is contained in:
parent
911d07e882
commit
d2f9d3541c
@ -8,14 +8,17 @@
|
|||||||
#include "../../../../engine/core/gui/uiComponent/ClickableUiComponent.h"
|
#include "../../../../engine/core/gui/uiComponent/ClickableUiComponent.h"
|
||||||
#include "../../../../engine/core/gui/uiComponent/UiImage.h"
|
#include "../../../../engine/core/gui/uiComponent/UiImage.h"
|
||||||
#include "../../../../engine/renderer/loader/AssetManager.h"
|
#include "../../../../engine/renderer/loader/AssetManager.h"
|
||||||
|
#include "../../../hexWorld/building/BuildingConfig.h"
|
||||||
|
#include "../../../hexWorld/building/BuildingDefinition.h"
|
||||||
|
#include "../../../hexWorld/ecs/components/BuildingComponent.h"
|
||||||
|
|
||||||
|
|
||||||
class UiBuildingMenuButton :public ClickableUiComponent {
|
class UiBuildingMenuButton :public ClickableUiComponent {
|
||||||
public:
|
public:
|
||||||
UiBuildingMenuButton(const std::string& iconName, LayoutStyle& style, Font& font) : ClickableUiComponent(style) {
|
UiBuildingMenuButton(const std::string& iconName, LayoutStyle& style, Font& font, BuildingType buildingType) : ClickableUiComponent(style) {
|
||||||
LayoutStyle iconStyle;
|
LayoutStyle iconStyle;
|
||||||
iconStyle.width = SizeValue(0.75, SizeUnit::Percent);
|
iconStyle.width = SizeValue(0.6, SizeUnit::Percent);
|
||||||
iconStyle.height = SizeValue(0.75f, SizeUnit::Percent);
|
iconStyle.height = SizeValue(0.6f, SizeUnit::Percent);
|
||||||
|
|
||||||
getLayoutStyle().width = SizeValue(143, SizeUnit::Pixels);
|
getLayoutStyle().width = SizeValue(143, SizeUnit::Pixels);
|
||||||
getLayoutStyle().height = SizeValue(200.f, SizeUnit::Pixels);
|
getLayoutStyle().height = SizeValue(200.f, SizeUnit::Pixels);
|
||||||
@ -27,11 +30,25 @@ public:
|
|||||||
|
|
||||||
LayoutStyle costContainerStyle;
|
LayoutStyle costContainerStyle;
|
||||||
costContainerStyle.width = SizeValue(1.f, SizeUnit::Percent);
|
costContainerStyle.width = SizeValue(1.f, SizeUnit::Percent);
|
||||||
costContainerStyle.height = SizeValue(35, SizeUnit::Pixels);
|
costContainerStyle.height = SizeValue(30, SizeUnit::Pixels);
|
||||||
costContainerStyle.margin.top = {10.f, SizeUnit::Pixels};
|
costContainerStyle.margin.top = {10.f, SizeUnit::Pixels};
|
||||||
|
|
||||||
auto costContainer = std::make_unique<UiBuildingMenuCostContainer>("wood_icon", costContainerStyle, font);
|
if (buildingType == BuildingType::FOREST_HUT) {
|
||||||
|
BuildingDefinition def = BuildingConfig::get(BuildingType::FOREST_HUT);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& [resourceTye, costs] : BuildingConfig::get(buildingType).resourceCosts) {
|
||||||
|
std::string iconCostName = "background";
|
||||||
|
if (resourceTye == RessourceType::WOOD) iconCostName = "wood_icon";
|
||||||
|
else if (resourceTye == RessourceType::STONE) iconCostName = "stone_icon";
|
||||||
|
|
||||||
|
auto costContainer = std::make_unique<UiBuildingMenuCostContainer>(iconCostName, costs, costContainerStyle, font);
|
||||||
addChild(std::move(costContainer));
|
addChild(std::move(costContainer));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
visualStyles[UiEventType::NONE] = {1.0f, glm::vec3(0.0f), 0.0f};
|
visualStyles[UiEventType::NONE] = {1.0f, glm::vec3(0.0f), 0.0f};
|
||||||
visualStyles[UiEventType::MOUSE_OVER] = {1.15f, glm::vec3(0.0f), 0.0f};
|
visualStyles[UiEventType::MOUSE_OVER] = {1.15f, glm::vec3(0.0f), 0.0f};
|
||||||
|
|||||||
@ -20,7 +20,7 @@ UiBuildingMenuContainer::UiBuildingMenuContainer(Font& font) {
|
|||||||
|
|
||||||
LayoutStyle buttonStyle;
|
LayoutStyle buttonStyle;
|
||||||
|
|
||||||
auto forest_icon = std::make_unique<UiBuildingMenuButton>("forest_hut_icon", buttonStyle, font);
|
auto forest_icon = std::make_unique<UiBuildingMenuButton>("forest_hut_icon", buttonStyle, font, BuildingType::FOREST_HUT);
|
||||||
forest_icon->addMouseListener([](const MouseEventData& e) {
|
forest_icon->addMouseListener([](const MouseEventData& e) {
|
||||||
if (e.isClick(MouseButton::LEFT)) {
|
if (e.isClick(MouseButton::LEFT)) {
|
||||||
std::cout << "Forest hut clicked!" << std::endl;
|
std::cout << "Forest hut clicked!" << std::endl;
|
||||||
@ -30,7 +30,7 @@ UiBuildingMenuContainer::UiBuildingMenuContainer(Font& font) {
|
|||||||
|
|
||||||
LayoutStyle buttonStyle2;
|
LayoutStyle buttonStyle2;
|
||||||
|
|
||||||
auto stone_icon = std::make_unique<UiBuildingMenuButton>("stone_mason_icon", buttonStyle2, font);
|
auto stone_icon = std::make_unique<UiBuildingMenuButton>("stone_mason_icon", buttonStyle2, font, BuildingType::STONE_MASON);
|
||||||
stone_icon->addMouseListener([](const MouseEventData& e) {
|
stone_icon->addMouseListener([](const MouseEventData& e) {
|
||||||
if (e.isClick(MouseButton::LEFT)) {
|
if (e.isClick(MouseButton::LEFT)) {
|
||||||
std::cout << "Stone hut clicked!" << std::endl;
|
std::cout << "Stone hut clicked!" << std::endl;
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
class UiBuildingMenuCostContainer: public UiComponent {
|
class UiBuildingMenuCostContainer: public UiComponent {
|
||||||
public:
|
public:
|
||||||
UiBuildingMenuCostContainer(const std::string& resourceIconName, LayoutStyle& style, Font& font) : UiComponent(style) {
|
UiBuildingMenuCostContainer(const std::string& resourceIconName, int buildingCost, LayoutStyle& style, Font& font) : UiComponent(style) {
|
||||||
LayoutStyle iconStyle;
|
LayoutStyle iconStyle;
|
||||||
iconStyle.width = SizeValue(30, SizeUnit::Pixels);
|
iconStyle.width = SizeValue(30, SizeUnit::Pixels);
|
||||||
iconStyle.height = SizeValue(30, SizeUnit::Pixels);
|
iconStyle.height = SizeValue(30, SizeUnit::Pixels);
|
||||||
@ -27,7 +27,7 @@ class UiBuildingMenuCostContainer: public UiComponent {
|
|||||||
textStyle.width = SizeValue(123, SizeUnit::Pixels);
|
textStyle.width = SizeValue(123, SizeUnit::Pixels);
|
||||||
textStyle.height = SizeValue(30, SizeUnit::Pixels);
|
textStyle.height = SizeValue(30, SizeUnit::Pixels);
|
||||||
|
|
||||||
auto costText = std::make_unique<UiText>(font, "13", textStyle, glm::vec3(0.f));
|
auto costText = std::make_unique<UiText>(font, std::to_string(buildingCost), textStyle, glm::vec3(0.f));
|
||||||
addChild(std::move(costText));
|
addChild(std::move(costText));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user