diff --git a/CMakeLists.txt b/CMakeLists.txt index aeeb4d4..84095b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -319,6 +319,8 @@ if(BUILD_GAME) src/engine/core/scenes/SplashScreen.h src/engine/core/scenes/SplashScreenLayer.cpp src/engine/core/scenes/SplashScreenLayer.h + src/engine/core/gui/uiComponent/UiProgressbar.cpp + src/engine/core/gui/uiComponent/UiProgressbar.h ) target_compile_options(Dicewars_Siedler PRIVATE -Wall diff --git a/assets/bar.png b/assets/bar.png new file mode 100644 index 0000000..337efe2 Binary files /dev/null and b/assets/bar.png differ diff --git a/assets/progress bar.svg b/assets/progress bar.svg new file mode 100644 index 0000000..3999494 --- /dev/null +++ b/assets/progress bar.svg @@ -0,0 +1,586 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/progressbar.png b/assets/progressbar.png new file mode 100644 index 0000000..ffd69bd Binary files /dev/null and b/assets/progressbar.png differ diff --git a/src/engine/core/gui/uiComponent/UiComponent.h b/src/engine/core/gui/uiComponent/UiComponent.h index d64b883..fc3b35b 100644 --- a/src/engine/core/gui/uiComponent/UiComponent.h +++ b/src/engine/core/gui/uiComponent/UiComponent.h @@ -24,7 +24,7 @@ struct UiEvent { class UiComponent { public: UiComponent() :uiPositioner(*this) {}; - UiComponent(const LayoutStyle& layout) : uiPositioner(*this, layout) {}; + explicit UiComponent(const LayoutStyle& layout) : uiPositioner(*this, layout) {}; virtual ~UiComponent() = default; template T* addChild(std::unique_ptr child) { diff --git a/src/engine/core/gui/uiComponent/UiProgressbar.cpp b/src/engine/core/gui/uiComponent/UiProgressbar.cpp new file mode 100644 index 0000000..5d461a4 --- /dev/null +++ b/src/engine/core/gui/uiComponent/UiProgressbar.cpp @@ -0,0 +1,42 @@ +// +// Created by sebastian on 24.04.26. +// + +#include "UiProgressbar.h" + +#include + +#include "../../Application.h" +#include "spdlog/fmt/bundled/format.h" + +UiProgressbar::UiProgressbar(const GLuint backgroundTextureID, const GLuint barTextureID, const LayoutStyle &style) + : UiComponent(style), backgroundTextureID(backgroundTextureID), barTextureID(barTextureID){ +} + +void UiProgressbar::setProgress(const float progress) { + this->progress = std::clamp(progress, 0.0f, 1.0f); +} + +void UiProgressbar::onCollectRenderData(UiRenderBundle &uiRenderBundle) { + if (!visible) return; + + Dimensions dims = uiPositioner.screenSpace; + + GUITextureBuilder builder; + builder = builder.Foreground(backgroundTextureID); + builder = builder.Position(glm::vec2(dims.x, dims.y)); + builder = builder.Scale(glm::vec2(dims.width, dims.height)); + GUITexture background = builder.Build(); + uiRenderBundle.addGUITexture(std::make_shared(background)); + + GUITextureBuilder barBuilder; + barBuilder = barBuilder.Foreground(barTextureID); + barBuilder = barBuilder.Position(glm::vec2(dims.x, dims.y)); + barBuilder = barBuilder.Scale(glm::vec2(dims.width * progress, dims.height)); + GUITexture bar = barBuilder.Build(); + uiRenderBundle.addGUITexture(std::make_shared(bar)); +} + +float UiProgressbar::getProgress() const { + return progress; +} diff --git a/src/engine/core/gui/uiComponent/UiProgressbar.h b/src/engine/core/gui/uiComponent/UiProgressbar.h new file mode 100644 index 0000000..03cd761 --- /dev/null +++ b/src/engine/core/gui/uiComponent/UiProgressbar.h @@ -0,0 +1,26 @@ +// +// Created by sebastian on 24.04.26. +// + +#ifndef UIPROGRESSBAR_H +#define UIPROGRESSBAR_H +#include "UiComponent.h" + + +class UiProgressbar: public UiComponent { +public: + UiProgressbar(GLuint backgroundTextureID, GLuint barTextureID, const LayoutStyle& style); + void setProgress(float progress); + void onCollectRenderData(UiRenderBundle &uiRenderBundle) override; + float getProgress() const; +private: + GLuint backgroundTextureID; + GLuint barTextureID; + float progress = 0.0f; + + +}; + + + +#endif //UIPROGRESSBAR_H diff --git a/src/engine/core/scenes/SplashScreen.cpp b/src/engine/core/scenes/SplashScreen.cpp index 837e89c..0af88ea 100644 --- a/src/engine/core/scenes/SplashScreen.cpp +++ b/src/engine/core/scenes/SplashScreen.cpp @@ -8,7 +8,9 @@ std::vector SplashScreen::getRequiredAssets() { std::vector requests; - requests.push_back(TextureRequest("logo", "assets/logo.png")); + requests.emplace_back(TextureRequest("logo", "assets/logo.png")); + requests.emplace_back(TextureRequest("progressbar_background", "assets/progressbar.png")); + requests.emplace_back(TextureRequest("progressbar_bar", "assets/bar.png")); return requests; } diff --git a/src/engine/core/scenes/SplashScreenLayer.cpp b/src/engine/core/scenes/SplashScreenLayer.cpp index 03c8b31..5248f9c 100644 --- a/src/engine/core/scenes/SplashScreenLayer.cpp +++ b/src/engine/core/scenes/SplashScreenLayer.cpp @@ -7,6 +7,7 @@ #include "../../renderer/loader/AssetManager.h" #include "../../renderer/GUIRenderer.h" #include "../gui/uiComponent/UiImage.h" +#include "../gui/uiComponent/UiProgressbar.h" #include "../gui/uiMain/UiContainer.h" #include "spdlog/spdlog.h" @@ -27,6 +28,8 @@ void SplashScreenLayer::onRender() { void SplashScreenLayer::onUpdate() { Dimensions rootParent {0.0, 0.0, 1.0, 1.0f}; rootContainer->uiPositioner.compute(rootParent); + + progressbar->setProgress(progressbar->getProgress() + 0.01f); } void SplashScreenLayer::onAttach() { @@ -40,6 +43,15 @@ void SplashScreenLayer::onAttach() { rootContainer->getLayoutStyle().alignItems = AlignItems::Center; rootContainer->addChild(std::make_unique(AssetManager::getTexture("logo")->getTextureID(), logoLayoutStyle)); + + LayoutStyle progressbarLayoutStyle; + progressbarLayoutStyle.width = SizeValue(0.5f, SizeUnit::Vmin); + progressbarLayoutStyle.height = SizeValue(0.5f, SizeUnit::Vmin); + + progressbar = rootContainer->addChild(std::make_unique( + AssetManager::getTexture("progressbar_background")->getTextureID(), + AssetManager::getTexture("progressbar_bar")->getTextureID(), progressbarLayoutStyle + )); } void SplashScreenLayer::onDetach() { diff --git a/src/engine/core/scenes/SplashScreenLayer.h b/src/engine/core/scenes/SplashScreenLayer.h index 23bf4a9..eaffe54 100644 --- a/src/engine/core/scenes/SplashScreenLayer.h +++ b/src/engine/core/scenes/SplashScreenLayer.h @@ -8,6 +8,8 @@ #include "../../renderer/GUIRenderer.h" #include "../../core/gui/uiMain/UiContainer.h" +#include "../gui/uiComponent/UiProgressbar.h" + class SplashScreenLayer: public Layer { public: SplashScreenLayer(); @@ -19,6 +21,8 @@ public: private: std::unique_ptr rootContainer; std::unique_ptr guiRenderer; + + UiProgressbar* progressbar; };