ADD: BackgroundTextures for GuiTextures
This commit is contained in:
parent
c8531c5ea6
commit
4146ea5ea1
@ -211,6 +211,8 @@ add_executable(Dicewars_Siedler src/main.cpp
|
||||
src/engine/renderer/shaders/MinimapShader.h
|
||||
src/engine/renderer/model/RenderTargets.cpp
|
||||
src/engine/renderer/model/RenderTargets.h
|
||||
src/engine/renderer/model/GuiTextureBuilder.cpp
|
||||
src/engine/renderer/model/GuiTextureBuilder.h
|
||||
)
|
||||
|
||||
target_compile_options(Dicewars_Siedler PRIVATE
|
||||
|
||||
@ -5,14 +5,22 @@ in vec2 textureCoords;
|
||||
out vec4 color;
|
||||
|
||||
uniform sampler2D guiTexture;
|
||||
uniform sampler2D backgroundTexture;
|
||||
|
||||
uniform float brightness; // 1.0 = normal
|
||||
uniform vec3 tintColor; // (0,0,0) = kein Tint
|
||||
uniform float tintStrength; // 0.0 = aus
|
||||
|
||||
uniform bool hasForeground;
|
||||
uniform bool hasBackground;
|
||||
|
||||
|
||||
void main(void) {
|
||||
vec4 textureColor = texture(guiTexture, textureCoords);
|
||||
vec4 fg = hasForeground ? texture(guiTexture, textureCoords) : vec4(0.0);
|
||||
vec4 bg = hasBackground ? texture(backgroundTexture, textureCoords) : vec4(0.0);
|
||||
|
||||
|
||||
vec4 textureColor = mix(bg, fg, fg.a);
|
||||
|
||||
textureColor.rgb *= brightness;
|
||||
|
||||
|
||||
@ -22,16 +22,16 @@ void UiButton::onCollectRenderData(UiRenderBundle &uiRenderBundle) {
|
||||
glm::vec2 size = glm::vec2(uiPositioner.screenSpace.width, uiPositioner.screenSpace.height);
|
||||
|
||||
VisualStyle visualStyle = getVisualStyle();
|
||||
uiRenderBundle.addGUITexture(
|
||||
std::make_shared<GUITexture>(
|
||||
textureID,
|
||||
position,
|
||||
size,
|
||||
visualStyle.brightness,
|
||||
visualStyle.tintColor,
|
||||
visualStyle.tintStrength
|
||||
)
|
||||
);
|
||||
|
||||
GUITextureBuilder textureBuilder;
|
||||
textureBuilder = textureBuilder.Foreground(textureID);
|
||||
textureBuilder = textureBuilder.Position(position);
|
||||
textureBuilder = textureBuilder.Scale(size);
|
||||
textureBuilder = textureBuilder.Tint(visualStyle.tintColor, visualStyle.tintStrength);
|
||||
textureBuilder = textureBuilder.Brightness(visualStyle.brightness);
|
||||
|
||||
GUITexture texture = textureBuilder.Build();
|
||||
uiRenderBundle.addGUITexture(std::make_shared<GUITexture>(texture));
|
||||
|
||||
uiRenderBundle.addGUIText(std::make_shared<GUIText>(font, text, uiPositioner.screenSpace));
|
||||
}
|
||||
|
||||
@ -5,10 +5,21 @@
|
||||
#include "UiImage.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "../../../renderer/model/GuiTextureBuilder.h"
|
||||
|
||||
void UiImage::onCollectRenderData(UiRenderBundle& renderBundle) {
|
||||
if (!visible) return;
|
||||
Dimensions dims = uiPositioner.screenSpace;
|
||||
GUITexture texture(textureID, glm::vec2(dims.x, dims.y), glm::vec2(dims.width, dims.height));
|
||||
|
||||
GUITextureBuilder texureBuilder;
|
||||
texureBuilder = texureBuilder.Foreground(textureID);
|
||||
texureBuilder = texureBuilder.Position(glm::vec2(dims.x, dims.y));
|
||||
texureBuilder = texureBuilder.Scale(glm::vec2(dims.width, dims.height));
|
||||
|
||||
if (hasBackground) {
|
||||
texureBuilder = texureBuilder.Background(backgroundID);
|
||||
}
|
||||
|
||||
GUITexture texture = texureBuilder.Build();
|
||||
renderBundle.addGUITexture(std::make_shared<GUITexture>(texture));;
|
||||
}
|
||||
|
||||
@ -9,15 +9,16 @@
|
||||
|
||||
class UiImage : public UiComponent {
|
||||
public:
|
||||
UiImage(GLuint textureID, const LayoutStyle& style) : textureID(textureID), UiComponent(style) {
|
||||
|
||||
};
|
||||
UiImage(GLuint textureID, const LayoutStyle& style) : UiComponent(style), textureID(textureID), backgroundID(0), hasBackground(false) {};
|
||||
UiImage(GLuint textureID, GLuint backgroundID, const LayoutStyle& style) : UiComponent(style), textureID(textureID), backgroundID(backgroundID), hasBackground(true) {};
|
||||
|
||||
protected:
|
||||
void onCollectRenderData(UiRenderBundle& renderBundle) override;
|
||||
|
||||
private:
|
||||
GLuint textureID;
|
||||
GLuint backgroundID;
|
||||
bool hasBackground;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -27,14 +27,27 @@ void GUIRenderer::render(std::vector<std::shared_ptr<GUITexture>>& gui_textures)
|
||||
for (auto texture : gui_textures) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->getTextureID());
|
||||
guiShader.loadForegroundTexture(0, true);
|
||||
glm::mat4 transformationMatrix = MathUtils::createTransformationMatrix(texture->getPosition(), texture->getScale());
|
||||
guiShader.loadTransformationMatrix(transformationMatrix);
|
||||
guiShader.loadShaderEffect(texture->getBrightness(), texture->getTintColor(), texture->getTintStrength());
|
||||
|
||||
if (texture->hasBackground()) {
|
||||
guiShader.loadBackgroundTexture(1, true);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->getBackgroundTextureID());
|
||||
} else {
|
||||
guiShader.loadBackgroundTexture(1, false);
|
||||
}
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, rawModel->vertexCount);
|
||||
}
|
||||
//render
|
||||
glDisableVertexAttribArray(0);
|
||||
glBindVertexArray(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_BLEND);
|
||||
guiShader.stop();
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
void MinimapRenderer::render(const std::vector<MinimapRenderData> &renderData, std::unordered_map<PlayerID, glm::vec3> colorMapping) {
|
||||
minimapFBO->bind();
|
||||
glViewport(0,0, width, height);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
@ -59,6 +59,7 @@ void TextRenderer::renderText(const UiText &textToRender) {
|
||||
glBindVertexArray(textModel.vaoID);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, ch.textureID);
|
||||
|
||||
|
||||
|
||||
@ -4,9 +4,4 @@
|
||||
|
||||
#include "GUITexture.h"
|
||||
|
||||
GUITexture::GUITexture(GLuint textureID, glm::vec2 position, glm::vec2 scale) : textureID(textureID), position(position), scale(scale){
|
||||
}
|
||||
|
||||
GUITexture::GUITexture(GLuint textureID, glm::vec2 position, glm::vec2 scale, float brightness, glm::vec3 tintColor,
|
||||
float tintStrength) : textureID(textureID), position(position), scale(scale), brightness(brightness), tintColor(tintColor), tintStrength(tintStrength){
|
||||
}
|
||||
|
||||
@ -9,9 +9,12 @@
|
||||
#include "glm/vec3.hpp"
|
||||
|
||||
|
||||
#include "GuiTextureBuilder.h"
|
||||
|
||||
class GUITexture {
|
||||
private:
|
||||
const GLuint textureID;
|
||||
const GLuint backgroundTextureID;
|
||||
const glm::vec2 position;
|
||||
const glm::vec2 scale;
|
||||
|
||||
@ -19,16 +22,28 @@ private:
|
||||
float tintStrength = 0.0f;
|
||||
glm::vec3 tintColor = glm::vec3(0.3, 0.6, 1.0);
|
||||
|
||||
bool useBackground;
|
||||
|
||||
public:
|
||||
GUITexture(GLuint textureID, glm::vec2 position, glm::vec2 scale);
|
||||
GUITexture(GLuint textureID, glm::vec2 position, glm::vec2 scale, float brightness, glm::vec3 tintColor, float tintStrength);
|
||||
explicit GUITexture(const GUITextureDesc& desc)
|
||||
: textureID(desc.foreground)
|
||||
, backgroundTextureID(desc.background)
|
||||
, position(desc.position)
|
||||
, scale(desc.scale)
|
||||
, brightness(desc.brightness)
|
||||
, tintStrength(desc.tintStrength)
|
||||
, tintColor(desc.tintColor)
|
||||
, useBackground(desc.hasBackground)
|
||||
{}
|
||||
|
||||
[[nodiscard]] GLuint getTextureID() const {return textureID;}
|
||||
[[nodiscard]] GLuint getBackgroundTextureID() const {return backgroundTextureID;}
|
||||
[[nodiscard]] glm::vec2 getPosition() const {return position;}
|
||||
[[nodiscard]] glm::vec2 getScale() const {return scale;}
|
||||
[[nodiscard]] float getBrightness() const {return brightness;}
|
||||
[[nodiscard]] glm::vec3 getTintColor() const {return tintColor;}
|
||||
[[nodiscard]] float getTintStrength() const {return tintStrength;}
|
||||
[[nodiscard]] bool hasBackground() const {return useBackground;}
|
||||
|
||||
};
|
||||
|
||||
|
||||
10
src/engine/renderer/model/GuiTextureBuilder.cpp
Normal file
10
src/engine/renderer/model/GuiTextureBuilder.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by sebastian on 15.02.26.
|
||||
//
|
||||
|
||||
#include "GuiTextureBuilder.h"
|
||||
#include "GUITexture.h"
|
||||
|
||||
GUITexture GUITextureBuilder::Build() {
|
||||
return GUITexture(desc);
|
||||
}
|
||||
47
src/engine/renderer/model/GuiTextureBuilder.h
Normal file
47
src/engine/renderer/model/GuiTextureBuilder.h
Normal file
@ -0,0 +1,47 @@
|
||||
//
|
||||
// Created by sebastian on 15.02.26.
|
||||
//
|
||||
|
||||
#ifndef DICEWARS_SIEDLER_GUITEXTUREBUILDER_H
|
||||
#define DICEWARS_SIEDLER_GUITEXTUREBUILDER_H
|
||||
#include "glad/glad.h"
|
||||
#include "glm/vec2.hpp"
|
||||
#include "glm/vec3.hpp"
|
||||
|
||||
class GUITexture;
|
||||
|
||||
|
||||
struct GUITextureDesc {
|
||||
GLuint foreground = 0;
|
||||
GLuint background = 0;
|
||||
|
||||
glm::vec2 position {0.0f, 0.0f};
|
||||
glm::vec2 scale {1.0f, 1.0f};
|
||||
|
||||
float brightness = 1.0f;
|
||||
glm::vec3 tintColor = {1.0f, 1.0f, 1.0f};
|
||||
float tintStrength = 0.0f;
|
||||
|
||||
bool hasBackground = false;
|
||||
};
|
||||
|
||||
class GUITextureBuilder {
|
||||
public:
|
||||
GUITextureBuilder& Foreground(GLuint id) { desc.foreground = id; return *this; }
|
||||
GUITextureBuilder& Background(GLuint id) { desc.background = id; desc.hasBackground = true; return *this; }
|
||||
GUITextureBuilder& Position(glm::vec2 p) { desc.position = p; return *this; }
|
||||
GUITextureBuilder& Scale(glm::vec2 s) { desc.scale = s; return *this; }
|
||||
GUITextureBuilder& Tint(glm::vec3 c, float strength) {
|
||||
desc.tintColor = c; desc.tintStrength = strength; return *this;
|
||||
}
|
||||
GUITextureBuilder& Brightness(float b) { desc.brightness = b; return *this; }
|
||||
|
||||
[[nodiscard]] GUITexture Build();
|
||||
|
||||
private:
|
||||
GUITextureDesc desc;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //DICEWARS_SIEDLER_GUITEXTUREBUILDER_H
|
||||
@ -14,12 +14,27 @@ void GUIShader::loadShaderEffect(float brightness, glm::vec3 tintColor, float ti
|
||||
ShaderProgram::loadFloat(location_tintStrength, tintStrength);
|
||||
}
|
||||
|
||||
void GUIShader::loadForegroundTexture(int textureBankIndex, bool useTexture) {
|
||||
ShaderProgram::loadBoolean(location_usesForgroundTexture, useTexture);
|
||||
ShaderProgram::loadInt(location_foregroundTextureSampler, textureBankIndex);
|
||||
}
|
||||
|
||||
void GUIShader::loadBackgroundTexture(int textureBankIndex, bool useTexture) {
|
||||
ShaderProgram::loadBoolean(location_usesBackgroundTexture, useTexture);
|
||||
ShaderProgram::loadInt(location_backgroundTextureSampler, textureBankIndex);
|
||||
}
|
||||
|
||||
void GUIShader::getAllUniformLocations() {
|
||||
location_transformationMatrix = ShaderProgram::getUniformLocation("transformationMatrix");
|
||||
|
||||
location_brightness = ShaderProgram::getUniformLocation("brightness");
|
||||
location_tintColor = ShaderProgram::getUniformLocation("tintColor");
|
||||
location_tintStrength = ShaderProgram::getUniformLocation("tintStrength");
|
||||
|
||||
location_foregroundTextureSampler = ShaderProgram::getUniformLocation("guiTexture");
|
||||
location_backgroundTextureSampler = ShaderProgram::getUniformLocation("backgroundTexture");
|
||||
location_usesForgroundTexture = ShaderProgram::getUniformLocation("hasForeground");
|
||||
location_usesBackgroundTexture = ShaderProgram::getUniformLocation("hasBackground");
|
||||
}
|
||||
|
||||
void GUIShader::bindAttributes() const {
|
||||
|
||||
@ -16,6 +16,9 @@ public:
|
||||
void loadTransformationMatrix(glm::mat4 matrix);
|
||||
void loadShaderEffect(float brightness, glm::vec3 tintColor, float tintStrength);
|
||||
|
||||
void loadForegroundTexture(int textureBankIndex, bool useTexture);
|
||||
void loadBackgroundTexture(int textureBankIndex, bool useTexture);
|
||||
|
||||
private:
|
||||
inline static const std::string VERTEX_FILE = "assets/shaders/guiVertexShader.glsl";
|
||||
inline static const std::string FRAGMENT_FILE = "assets/shaders/guiFragmentShader.glsl";
|
||||
@ -25,6 +28,11 @@ private:
|
||||
int location_tintColor;
|
||||
int location_tintStrength;
|
||||
|
||||
int location_usesForgroundTexture;
|
||||
int location_foregroundTextureSampler;
|
||||
int location_usesBackgroundTexture;
|
||||
int location_backgroundTextureSampler;
|
||||
|
||||
protected:
|
||||
void getAllUniformLocations() override;
|
||||
void bindAttributes() const override;
|
||||
|
||||
@ -64,6 +64,10 @@ void ShaderProgram::loadMatrix(int location, glm::mat4 matrix) {
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
}
|
||||
|
||||
void ShaderProgram::loadInt(int location, int value) {
|
||||
glUniform1i(location, value);
|
||||
}
|
||||
|
||||
|
||||
int ShaderProgram::loadShader(const std::string& file, int type) {
|
||||
std::ifstream shaderFile(file);
|
||||
|
||||
@ -33,6 +33,7 @@ protected:
|
||||
void loadVector(int location, glm::vec3 vector);
|
||||
void loadBoolean(int location, bool value);
|
||||
void loadMatrix(int location, glm::mat4 matrix);
|
||||
void loadInt(int location, int value);
|
||||
private:
|
||||
static int loadShader(const std::string& file, int type);
|
||||
};
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../engine/core/gui/uiComponent/UiButton.h"
|
||||
#include "../engine/core/gui/uiComponent/UiImage.h"
|
||||
#include "../engine/core/gui/uiComponent/UiText.h"
|
||||
#include "../engine/renderer/loader/AssetManager.h"
|
||||
#include "../engine/renderer/loader/Loader.h"
|
||||
#include "../engine/renderer/model/GUITexture.h"
|
||||
#include "../engine/renderer/model/RenderTargets.h"
|
||||
@ -29,40 +30,15 @@ UILayer::UILayer() {
|
||||
void UILayer::onAttach() {
|
||||
Layer::onAttach();
|
||||
|
||||
AssetManager::loadTexture("background", "assets/textures/texture.png", Loader::instance());
|
||||
|
||||
|
||||
rootContainer = std::make_unique<UiContainer>();
|
||||
rootContainer->getLayoutStyle().flexDirection = FlexDirection::Column;
|
||||
|
||||
auto imageStyle = LayoutStyle();
|
||||
imageStyle.width = SizeValue(0.25f, SizeUnit::Percent);
|
||||
imageStyle.height = SizeValue(0.25f, SizeUnit::Percent);
|
||||
imageStyle.margin.left = {50.f, SizeUnit::Pixels}; // 50px
|
||||
imageStyle.margin.top = {0.f, SizeUnit::Percent};
|
||||
|
||||
auto image = std::make_unique<UiImage>(
|
||||
Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(),
|
||||
imageStyle
|
||||
);
|
||||
|
||||
auto image2 = std::make_unique<UiImage>(
|
||||
Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(),
|
||||
imageStyle
|
||||
);
|
||||
|
||||
auto image3 = std::make_unique<UiImage>(
|
||||
Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(),
|
||||
imageStyle
|
||||
);
|
||||
|
||||
Font myFont("/usr/share/fonts/TTF/DejaVuSans.ttf", 48);
|
||||
font = std::make_unique<Font>(myFont);
|
||||
//auto text = std::make_unique<UiText>(*font, "Hello World!", glm::vec2(0.5f, 0.5f), glm::vec3(1,1,1));
|
||||
|
||||
auto button = std::make_unique<UiButton>(Loader::instance().loadTextureFromFile("assets/textures/texture.png").getTextureID(), "Button", *font, imageStyle);
|
||||
|
||||
button->setOnClick([]() {
|
||||
std::cout << "Button Clicked!" << std::endl;
|
||||
});
|
||||
|
||||
//rootContainer->addChild(std::move(button));
|
||||
smallFont =std::make_unique<Font>("/usr/share/fonts/TTF/DejaVuSans.ttf", 18);
|
||||
@ -70,11 +46,11 @@ void UILayer::onAttach() {
|
||||
|
||||
auto inventoryContainer = std::make_unique<UiInventoryContainer>(*smallFont);
|
||||
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/wood-log.png", 10, RessourceType::WOOD);
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/granite.png", 1139, RessourceType::STONE);
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/humans.png", 523, RessourceType::PEOPLE);
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/bread.png", 89, RessourceType::FOOD);
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/swords.png", 45, RessourceType::SOLDIERS);
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/wood-log.png", "background", 10, RessourceType::WOOD);
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/granite.png","background", 1139, RessourceType::STONE);
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/humans.png","background", 523, RessourceType::PEOPLE);
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/bread.png","background", 89, RessourceType::FOOD);
|
||||
inventoryContainer->addRessource("assets/ui/ressource-icons/swords.png", "background",45, RessourceType::SOLDIERS);
|
||||
|
||||
inventoryContainerID = rootContainer->addChild(std::move(inventoryContainer));
|
||||
|
||||
@ -100,7 +76,8 @@ void UILayer::onAttach() {
|
||||
minimapStyle.margin.top = {10.f, SizeUnit::Pixels};
|
||||
|
||||
GLuint minimapTextureID = RenderTargets::instance().getMinimapTexture();
|
||||
auto minimap = std::make_unique<UiImage>(minimapTextureID, minimapStyle);
|
||||
GLuint backgroundTextureID = AssetManager::getTexture("background")->getTextureID();
|
||||
auto minimap = std::make_unique<UiImage>(minimapTextureID, backgroundTextureID, minimapStyle);
|
||||
rootContainer->addChild(std::move(minimap));
|
||||
}
|
||||
|
||||
|
||||
@ -24,9 +24,9 @@ public:
|
||||
uiPositioner.setLayout(containerStyle);
|
||||
}
|
||||
|
||||
void addRessource(const std::string& iconPath, int amount, RessourceType widgetID) {
|
||||
void addRessource(const std::string& iconPath, const std::string& textureName, int amount, RessourceType widgetID) {
|
||||
float marginLeft = (widgets.empty()) ? 0.0f : 10.0f;
|
||||
auto widget = RessourceWidgetFactory::create(iconPath, amount, font, marginLeft);
|
||||
auto widget = RessourceWidgetFactory::create(iconPath, textureName, amount, font, marginLeft);
|
||||
widgets.emplace(widgetID, widget.get());
|
||||
addChild(std::move(widget));
|
||||
}
|
||||
|
||||
@ -6,10 +6,10 @@
|
||||
|
||||
#include "../../../engine/core/gui/uiComponent/UiText.h"
|
||||
|
||||
UiRessourceWidget::UiRessourceWidget(GLuint iconTextureID, int amount, Font &font, const LayoutStyle &containerStyle,
|
||||
UiRessourceWidget::UiRessourceWidget(GLuint iconTextureID, GLuint backgroundID, int amount, Font &font, const LayoutStyle &containerStyle,
|
||||
LayoutStyle &iconStyle, LayoutStyle &textStyle) : UiComponent(containerStyle) {
|
||||
|
||||
auto icon = std::make_unique<UiImage>(iconTextureID, iconStyle);
|
||||
auto icon = std::make_unique<UiImage>(iconTextureID, backgroundID, iconStyle);
|
||||
auto text = std::make_unique<UiText>(font, std::to_string(amount), textStyle);
|
||||
|
||||
iconIndex = addChild(std::move(icon));
|
||||
|
||||
@ -12,7 +12,11 @@
|
||||
|
||||
class UiRessourceWidget : public UiComponent {
|
||||
public:
|
||||
UiRessourceWidget(GLuint iconTextureID, int amount, Font& font, const LayoutStyle& containerStyle, LayoutStyle& iconStyle, LayoutStyle& textStyle);
|
||||
|
||||
UiRessourceWidget(GLuint iconTextureID, GLuint backgroundID, int amount, Font &font,
|
||||
const LayoutStyle &containerStyle,
|
||||
LayoutStyle &iconStyle, LayoutStyle &textStyle);
|
||||
|
||||
void setAmount(int newAmount);
|
||||
private:
|
||||
size_t iconIndex;
|
||||
|
||||
@ -4,9 +4,10 @@
|
||||
|
||||
#include "RessourceWidgetFactory.h"
|
||||
#include "../UiRessourceWidget.h"
|
||||
#include "../../../../engine/renderer/loader/AssetManager.h"
|
||||
#include "../../../../engine/renderer/loader/Loader.h"
|
||||
|
||||
std::unique_ptr<UiRessourceWidget> RessourceWidgetFactory::create(const std::string &iconPath, int amount, Font &font, float marginLeft) {
|
||||
std::unique_ptr<UiRessourceWidget> RessourceWidgetFactory::create(const std::string &iconPath, const std::string& textureName, int amount, Font &font, float marginLeft) {
|
||||
LayoutStyle iconStyle;
|
||||
iconStyle.width = SizeValue(40.f, SizeUnit::Pixels);
|
||||
iconStyle.height = SizeValue(40.f,SizeUnit::Pixels);
|
||||
@ -27,8 +28,8 @@ std::unique_ptr<UiRessourceWidget> RessourceWidgetFactory::create(const std::str
|
||||
}
|
||||
|
||||
GLuint textureID = Loader::instance().loadTextureFromFile(iconPath).getTextureID();
|
||||
return std::make_unique<UiRessourceWidget>(
|
||||
Loader::instance().loadTextureFromFile(iconPath).getTextureID(),
|
||||
GLuint backgroundTextureID = AssetManager::getTexture(textureName)->getTextureID();
|
||||
return std::make_unique<UiRessourceWidget>(textureID, backgroundTextureID,
|
||||
amount, font, containerStyle, iconStyle, textStyle
|
||||
);
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ class Font;
|
||||
|
||||
class RessourceWidgetFactory {
|
||||
public:
|
||||
static std::unique_ptr<UiRessourceWidget> create(const std::string& iconPath, int amount, Font& font, float marginLeft = 0.0);
|
||||
static std::unique_ptr<UiRessourceWidget> create(const std::string &iconPath, const std::string &textureName, int amount, Font &font, float marginLeft = 0.0);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user