From a2ee1e139d9ab2601ca85c7e2bebf90a871e1887 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Thu, 8 Dec 2022 23:00:33 -0800 Subject: [PATCH] Improved the standardization of UI --- src/dawn/display/RenderPipeline.cpp | 3 +- .../visualnovel/ui/VisualNovelTextbox.cpp | 6 ---- .../visualnovel/ui/VisualNovelTextbox.hpp | 13 ++------ src/dawnpokergame/scenes/TestScene.hpp | 2 +- src/dawnpokergame/ui/PokerGameBorder.hpp | 32 +++++++++++++++++++ src/dawnpokergame/ui/PokerGameTextbox.hpp | 30 ++++++++++------- src/dawnpokergame/ui/PokerPlayerDisplay.cpp | 23 +++++++++++-- src/dawnpokergame/ui/PokerPlayerDisplay.hpp | 12 +++++-- 8 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 src/dawnpokergame/ui/PokerGameBorder.hpp diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index 1226f148..6addf8cd 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -127,8 +127,7 @@ void RenderPipeline::renderUI( // Clear / Bind / Update the render target. renderTarget->bind(); this->renderManager->setRenderFlags( - RENDER_MANAGER_RENDER_FLAG_BLEND | - RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST + RENDER_MANAGER_RENDER_FLAG_BLEND ); // Prepare the UI Shader diff --git a/src/dawn/visualnovel/ui/VisualNovelTextbox.cpp b/src/dawn/visualnovel/ui/VisualNovelTextbox.cpp index a3d0a91a..0482a96d 100644 --- a/src/dawn/visualnovel/ui/VisualNovelTextbox.cpp +++ b/src/dawn/visualnovel/ui/VisualNovelTextbox.cpp @@ -142,12 +142,6 @@ void VisualNovelTextbox::drawSelf(UIShader *shader, glm::mat4 self) { } -void VisualNovelTextbox::setBorder(Texture *texture, glm::vec2 dimensions) { - this->border.texture = texture; - this->border.setBorderSize(dimensions); - this->updatePositions(); -} - void VisualNovelTextbox::setFont(Font *font) { this->label.setFont(font); this->label.updateMesh(); diff --git a/src/dawn/visualnovel/ui/VisualNovelTextbox.hpp b/src/dawn/visualnovel/ui/VisualNovelTextbox.hpp index 6ef73bb7..e1e7c719 100644 --- a/src/dawn/visualnovel/ui/VisualNovelTextbox.hpp +++ b/src/dawn/visualnovel/ui/VisualNovelTextbox.hpp @@ -19,8 +19,6 @@ namespace Dawn { int32_t lineCurrent = 0; glm::vec2 labelPadding = glm::vec2(0, 0); UIEmpty selfParent; - UIBorder border; - UILabel label; float_t timeCharacter = 0.0f; bool_t visible = false; @@ -41,6 +39,9 @@ namespace Dawn { int32_t getCountOfVisibleLines(); public: + UIBorder border; + UILabel label; + Event<> eventCharacterRevealed; Event<> eventCurrentCharactersRevealed; Event<> eventNewPage; @@ -66,14 +67,6 @@ namespace Dawn { */ void setFont(Font *font); - /** - * Sets the border information for this textbox. - * - * @param texture Texture to use for the border. - * @param dimensions Dimensions of the border. - */ - void setBorder(Texture *texture, glm::vec2 dimensions); - /** * Sets the string (label) for this textbox. * diff --git a/src/dawnpokergame/scenes/TestScene.hpp b/src/dawnpokergame/scenes/TestScene.hpp index b787a4d1..dfcbcce4 100644 --- a/src/dawnpokergame/scenes/TestScene.hpp +++ b/src/dawnpokergame/scenes/TestScene.hpp @@ -57,7 +57,7 @@ namespace Dawn { auto player = VNPenny::create(this); auto uiPlayer = canvas->addElement(); - uiPlayer->setTransform(UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, glm::vec4(i * 220, 0, 0, 0), 0); + uiPlayer->setTransform(UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START, glm::vec4(i * 220, 0, 220, 200), 0); uiPlayer->setPlayer(player->getComponent()); } diff --git a/src/dawnpokergame/ui/PokerGameBorder.hpp b/src/dawnpokergame/ui/PokerGameBorder.hpp new file mode 100644 index 00000000..b7d3a46b --- /dev/null +++ b/src/dawnpokergame/ui/PokerGameBorder.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "ui/UIBorder.hpp" +#include "asset/assets/TextureAsset.hpp" +#include "game/DawnGame.hpp" + +namespace Dawn { + class PokerGameBorder { + public: + static std::vector getAssets(AssetManager *man) { + return std::vector{ + man->get("texture_test") + }; + } + + static void apply(UIBorder *border) { + auto text = border->getGame()->assetManager.get("texture_test"); + border->texture = &text->texture; + border->setBorderSize(glm::vec2(16, 16)); + } + + static UIBorder * create(UICanvas *canvas) { + auto border = canvas->addElement(); + PokerGameBorder::apply(border); + return border; + } + }; +} \ No newline at end of file diff --git a/src/dawnpokergame/ui/PokerGameTextbox.hpp b/src/dawnpokergame/ui/PokerGameTextbox.hpp index 48de8546..8c7b749e 100644 --- a/src/dawnpokergame/ui/PokerGameTextbox.hpp +++ b/src/dawnpokergame/ui/PokerGameTextbox.hpp @@ -4,31 +4,37 @@ // https://opensource.org/licenses/MIT #pragma once +#include "ui/PokerGameBorder.hpp" #include "visualnovel/ui/VisualNovelTextbox.hpp" -#include "asset/assets/TextureAsset.hpp" #include "asset/assets/TrueTypeAsset.hpp" namespace Dawn { class PokerGameTextbox { public: static std::vector getAssets(AssetManager *man) { - return std::vector{ - man->get("truetype_ark"), - man->get("texture_test") - }; + assertNotNull(man); + + std::vector assets; + vectorAppend(&assets, &PokerGameBorder::getAssets(man)); + assets.push_back(man->get("truetype_ark")); + return assets; } - static VisualNovelTextbox * create(UICanvas *canvas) { - auto assMan = &canvas->getGame()->assetManager; + static void apply(VisualNovelTextbox *textbox) { + assertNotNull(textbox); - auto assetFont = assMan->get("truetype_ark"); - auto assetTexture = assMan->get("texture_test"); - - auto textbox = canvas->addElement(); - textbox->setBorder(&assetTexture->texture, glm::vec2(16, 16)); + auto assetFont = textbox->getGame()->assetManager.get("truetype_ark"); + PokerGameBorder::apply(&textbox->border); textbox->setFont(&assetFont->font); textbox->setFontSize(40); textbox->setLabelPadding(glm::vec2(10, 8)); + } + + static VisualNovelTextbox * create(UICanvas *canvas) { + assertNotNull(canvas); + + auto textbox = canvas->addElement(); + PokerGameTextbox::apply(textbox); textbox->setTransform( UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END, glm::vec4(0, 238, 0, 0), diff --git a/src/dawnpokergame/ui/PokerPlayerDisplay.cpp b/src/dawnpokergame/ui/PokerPlayerDisplay.cpp index 325bd5ce..a28897c0 100644 --- a/src/dawnpokergame/ui/PokerPlayerDisplay.cpp +++ b/src/dawnpokergame/ui/PokerPlayerDisplay.cpp @@ -12,12 +12,31 @@ PokerPlayerDisplay::PokerPlayerDisplay(UICanvas *canvas) : UIEmpty(canvas), labelName(canvas), labelChips(canvas), + borderInner(canvas), + border(canvas), animChips(&animChipsValue) { this->font = getGame()->assetManager.get("truetype_ark"); + // Border + this->addChild(&this->border); + PokerGameBorder::apply(&this->border); + this->border.setTransform( + UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, + glm::vec4(0, 0, 0, 0), + -0.0f + ); + + // Border Inner + this->addChild(&this->borderInner); + this->borderInner.setTransform( + UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, + glm::vec4(this->border.getBorderSize(), this->border.getBorderSize()), + 0.0f + ); + // Player Name - this->addChild(&this->labelName); + this->borderInner.addChild(&this->labelName); this->labelName.setText("Player Name"); this->labelName.setFont(&this->font->font); this->labelName.setFontSize(40); @@ -28,7 +47,7 @@ PokerPlayerDisplay::PokerPlayerDisplay(UICanvas *canvas) : ); // Chips label - this->addChild(&this->labelChips); + this->borderInner.addChild(&this->labelChips); this->labelChips.setFont(&this->font->font); this->labelChips.setFontSize(40); this->labelChips.setTransform( diff --git a/src/dawnpokergame/ui/PokerPlayerDisplay.hpp b/src/dawnpokergame/ui/PokerPlayerDisplay.hpp index 1f8054d9..e98829b5 100644 --- a/src/dawnpokergame/ui/PokerPlayerDisplay.hpp +++ b/src/dawnpokergame/ui/PokerPlayerDisplay.hpp @@ -6,10 +6,12 @@ #pragma once #include "ui/UILabel.hpp" #include "ui/UIEmpty.hpp" +#include "ui/UIBorder.hpp" #include "poker/PokerPlayer.hpp" #include "asset/AssetManager.hpp" #include "asset/assets/TrueTypeAsset.hpp" #include "display/animation/SimpleAnimation.hpp" +#include "ui/PokerGameBorder.hpp" namespace Dawn { class PokerPlayerDisplay : public UIEmpty { @@ -21,6 +23,9 @@ namespace Dawn { PokerPlayer *player = nullptr; UILabel labelName; UILabel labelChips; + UIEmpty borderInner; + UIBorder border; + TrueTypeAsset *font; void onPlayerChipsChanged(); @@ -28,9 +33,10 @@ namespace Dawn { public: static std::vector getAssets(AssetManager *assMan) { - return std::vector{ - assMan->get("truetype_ark") - }; + std::vector assets; + vectorAppend(&assets, &PokerGameBorder::getAssets(assMan)); + assets.push_back(assMan->get("truetype_ark")); + return assets; } PokerPlayerDisplay(UICanvas *canvas);