Improved the standardization of UI

This commit is contained in:
2022-12-08 23:00:33 -08:00
parent eb6c4c8076
commit a2ee1e139d
8 changed files with 85 additions and 36 deletions

View File

@ -127,8 +127,7 @@ void RenderPipeline::renderUI(
// Clear / Bind / Update the render target. // Clear / Bind / Update the render target.
renderTarget->bind(); renderTarget->bind();
this->renderManager->setRenderFlags( this->renderManager->setRenderFlags(
RENDER_MANAGER_RENDER_FLAG_BLEND | RENDER_MANAGER_RENDER_FLAG_BLEND
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST
); );
// Prepare the UI Shader // Prepare the UI Shader

View File

@ -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) { void VisualNovelTextbox::setFont(Font *font) {
this->label.setFont(font); this->label.setFont(font);
this->label.updateMesh(); this->label.updateMesh();

View File

@ -19,8 +19,6 @@ namespace Dawn {
int32_t lineCurrent = 0; int32_t lineCurrent = 0;
glm::vec2 labelPadding = glm::vec2(0, 0); glm::vec2 labelPadding = glm::vec2(0, 0);
UIEmpty selfParent; UIEmpty selfParent;
UIBorder border;
UILabel label;
float_t timeCharacter = 0.0f; float_t timeCharacter = 0.0f;
bool_t visible = false; bool_t visible = false;
@ -41,6 +39,9 @@ namespace Dawn {
int32_t getCountOfVisibleLines(); int32_t getCountOfVisibleLines();
public: public:
UIBorder border;
UILabel label;
Event<> eventCharacterRevealed; Event<> eventCharacterRevealed;
Event<> eventCurrentCharactersRevealed; Event<> eventCurrentCharactersRevealed;
Event<> eventNewPage; Event<> eventNewPage;
@ -66,14 +67,6 @@ namespace Dawn {
*/ */
void setFont(Font *font); 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. * Sets the string (label) for this textbox.
* *

View File

@ -57,7 +57,7 @@ namespace Dawn {
auto player = VNPenny::create(this); auto player = VNPenny::create(this);
auto uiPlayer = canvas->addElement<PokerPlayerDisplay>(); auto uiPlayer = canvas->addElement<PokerPlayerDisplay>();
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<PokerPlayer>()); uiPlayer->setPlayer(player->getComponent<PokerPlayer>());
} }

View File

@ -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<Asset*> getAssets(AssetManager *man) {
return std::vector<Asset*>{
man->get<TextureAsset>("texture_test")
};
}
static void apply(UIBorder *border) {
auto text = border->getGame()->assetManager.get<TextureAsset>("texture_test");
border->texture = &text->texture;
border->setBorderSize(glm::vec2(16, 16));
}
static UIBorder * create(UICanvas *canvas) {
auto border = canvas->addElement<UIBorder>();
PokerGameBorder::apply(border);
return border;
}
};
}

View File

@ -4,31 +4,37 @@
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "ui/PokerGameBorder.hpp"
#include "visualnovel/ui/VisualNovelTextbox.hpp" #include "visualnovel/ui/VisualNovelTextbox.hpp"
#include "asset/assets/TextureAsset.hpp"
#include "asset/assets/TrueTypeAsset.hpp" #include "asset/assets/TrueTypeAsset.hpp"
namespace Dawn { namespace Dawn {
class PokerGameTextbox { class PokerGameTextbox {
public: public:
static std::vector<Asset*> getAssets(AssetManager *man) { static std::vector<Asset*> getAssets(AssetManager *man) {
return std::vector<Asset*>{ assertNotNull(man);
man->get<TrueTypeAsset>("truetype_ark"),
man->get<TextureAsset>("texture_test") std::vector<Asset*> assets;
}; vectorAppend(&assets, &PokerGameBorder::getAssets(man));
assets.push_back(man->get<TrueTypeAsset>("truetype_ark"));
return assets;
} }
static VisualNovelTextbox * create(UICanvas *canvas) { static void apply(VisualNovelTextbox *textbox) {
auto assMan = &canvas->getGame()->assetManager; assertNotNull(textbox);
auto assetFont = assMan->get<TrueTypeAsset>("truetype_ark"); auto assetFont = textbox->getGame()->assetManager.get<TrueTypeAsset>("truetype_ark");
auto assetTexture = assMan->get<TextureAsset>("texture_test"); PokerGameBorder::apply(&textbox->border);
auto textbox = canvas->addElement<VisualNovelTextbox>();
textbox->setBorder(&assetTexture->texture, glm::vec2(16, 16));
textbox->setFont(&assetFont->font); textbox->setFont(&assetFont->font);
textbox->setFontSize(40); textbox->setFontSize(40);
textbox->setLabelPadding(glm::vec2(10, 8)); textbox->setLabelPadding(glm::vec2(10, 8));
}
static VisualNovelTextbox * create(UICanvas *canvas) {
assertNotNull(canvas);
auto textbox = canvas->addElement<VisualNovelTextbox>();
PokerGameTextbox::apply(textbox);
textbox->setTransform( textbox->setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END, UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
glm::vec4(0, 238, 0, 0), glm::vec4(0, 238, 0, 0),

View File

@ -12,12 +12,31 @@ PokerPlayerDisplay::PokerPlayerDisplay(UICanvas *canvas) :
UIEmpty(canvas), UIEmpty(canvas),
labelName(canvas), labelName(canvas),
labelChips(canvas), labelChips(canvas),
borderInner(canvas),
border(canvas),
animChips(&animChipsValue) animChips(&animChipsValue)
{ {
this->font = getGame()->assetManager.get<TrueTypeAsset>("truetype_ark"); this->font = getGame()->assetManager.get<TrueTypeAsset>("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 // Player Name
this->addChild(&this->labelName); this->borderInner.addChild(&this->labelName);
this->labelName.setText("Player Name"); this->labelName.setText("Player Name");
this->labelName.setFont(&this->font->font); this->labelName.setFont(&this->font->font);
this->labelName.setFontSize(40); this->labelName.setFontSize(40);
@ -28,7 +47,7 @@ PokerPlayerDisplay::PokerPlayerDisplay(UICanvas *canvas) :
); );
// Chips label // Chips label
this->addChild(&this->labelChips); this->borderInner.addChild(&this->labelChips);
this->labelChips.setFont(&this->font->font); this->labelChips.setFont(&this->font->font);
this->labelChips.setFontSize(40); this->labelChips.setFontSize(40);
this->labelChips.setTransform( this->labelChips.setTransform(

View File

@ -6,10 +6,12 @@
#pragma once #pragma once
#include "ui/UILabel.hpp" #include "ui/UILabel.hpp"
#include "ui/UIEmpty.hpp" #include "ui/UIEmpty.hpp"
#include "ui/UIBorder.hpp"
#include "poker/PokerPlayer.hpp" #include "poker/PokerPlayer.hpp"
#include "asset/AssetManager.hpp" #include "asset/AssetManager.hpp"
#include "asset/assets/TrueTypeAsset.hpp" #include "asset/assets/TrueTypeAsset.hpp"
#include "display/animation/SimpleAnimation.hpp" #include "display/animation/SimpleAnimation.hpp"
#include "ui/PokerGameBorder.hpp"
namespace Dawn { namespace Dawn {
class PokerPlayerDisplay : public UIEmpty { class PokerPlayerDisplay : public UIEmpty {
@ -21,6 +23,9 @@ namespace Dawn {
PokerPlayer *player = nullptr; PokerPlayer *player = nullptr;
UILabel labelName; UILabel labelName;
UILabel labelChips; UILabel labelChips;
UIEmpty borderInner;
UIBorder border;
TrueTypeAsset *font; TrueTypeAsset *font;
void onPlayerChipsChanged(); void onPlayerChipsChanged();
@ -28,9 +33,10 @@ namespace Dawn {
public: public:
static std::vector<Asset*> getAssets(AssetManager *assMan) { static std::vector<Asset*> getAssets(AssetManager *assMan) {
return std::vector<Asset*>{ std::vector<Asset*> assets;
assMan->get<TrueTypeAsset>("truetype_ark") vectorAppend(&assets, &PokerGameBorder::getAssets(assMan));
}; assets.push_back(assMan->get<TrueTypeAsset>("truetype_ark"));
return assets;
} }
PokerPlayerDisplay(UICanvas *canvas); PokerPlayerDisplay(UICanvas *canvas);