From 41cfd462787c09b0506692f9f212e27eb7decbc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Fri, 24 Apr 2026 18:59:34 +0200 Subject: [PATCH] ADD: Basic Progressbar --- CMakeLists.txt | 2 + assets/bar.png | Bin 0 -> 548 bytes assets/progress bar.svg | 586 ++++++++++++++++++ assets/progressbar.png | Bin 0 -> 3302 bytes src/engine/core/gui/uiComponent/UiComponent.h | 2 +- .../core/gui/uiComponent/UiProgressbar.cpp | 42 ++ .../core/gui/uiComponent/UiProgressbar.h | 26 + src/engine/core/scenes/SplashScreen.cpp | 4 +- src/engine/core/scenes/SplashScreenLayer.cpp | 12 + src/engine/core/scenes/SplashScreenLayer.h | 4 + 10 files changed, 676 insertions(+), 2 deletions(-) create mode 100644 assets/bar.png create mode 100644 assets/progress bar.svg create mode 100644 assets/progressbar.png create mode 100644 src/engine/core/gui/uiComponent/UiProgressbar.cpp create mode 100644 src/engine/core/gui/uiComponent/UiProgressbar.h 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 0000000000000000000000000000000000000000..337efe26332dd8c28856988866bbc889a6282050 GIT binary patch literal 548 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZzY=1HA;AcrO0(btiI zVPik{pF~z5Um@8e$d`ekN{xY`p@o6r7f`6-1p`B=0RzLU1O^7H84L{K1#@-<+5jck zlDyqr82*Fcg1yTp14TFsJR*x37=+h@Fk|wwzQaI4_7YEDSN2yd5&}A`e$nMifiB4K zba4!+xb^nNY0d@*9@YaKO}Wt%p5}1gZm!?bx|bs>?VKg+w~w0yfw~6-$Y0&c*LS?a z_jyY4hoV%Cv+sB1%dW}p-6VRuRX&ri;f8Y3MuQX544YdW&oSI!VR*vZaF~-piebVR zeh21;Ba90e8-y7Om>B#R9GDqQ2E+#-OB;^geIlm(rMGXzMG)81)z4*}Q$iB}wN7E7 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..ffd69bd09b15ea47cf6717834841e57454bb8570 GIT binary patch literal 3302 zcmdT{`8U+x8-HUE(pa))DOo=ELmdWW1EpB*(bhsB1}XLyH|3=-s$l_h+k1OUKUSv|P6>AycIq!~|bzlk&Dp~XDo$y zozJKpGG$(7TFjFy@qlfqFqs{^`0nV@!H5=2{9o95WdZ)D7XKB!%X8LJY^JY^@Gb>h zFrzbZ=X*A&E1lHAX-yyMV0=s6kG|c@>KnwtY0~FF;w?X?U~|x^p#OuwxztY{kV`7a zpTZ*1_|b>lb1{(Cx^WA)0Bi8Aq3vXiov@~N*({uLqt4$bP zS1-2Ea>m_@?z@z8uli`h;X>49gNw46Z=kIo>Gu0ulb-r0e=FkKTY>8nsGODsIQ*Qr zdR|WOPC9+fqHW^)te;Ee!f{=w#u-Ne7PpC3ZCJp|RaW<7_0K!H@l~?X^fmDk{to1j z1(z@10|aL>Z}X$cXjqAwYage|z;+M}teL;W8~(gmy(E&*ph9rN!K3w_cx9b5cg%Mz zaBB&;$i9q0c83O}Q8pZB zW#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 z3R(Neb@V5xg?q)njjGr7#&rq8~KMW1gE~f;Js@lE!G5lgQ1H`xuRp zTK_7BWnrd;Q}wHyyMfB9<2pQjSctFg+>@>cr3IzFv&7`#-{lz9 z53xa4CyKvDnNiZO&)C8fXxiPpitI)sG zC09bg9wh~#516>Qf2^T3z(XRM(gMTTZ)D;Jdr#l`3szP|RZ8a@BrkOi?oG$E?v&b% ziA}klxDTy&W87X*!JAL{oBOz{Mg*dE+hHSZ*6K5b(>NfwBLgrJ$!xra+Dw+Ea(-4_$ 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; };