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

@ -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
#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<Asset*> getAssets(AssetManager *man) {
return std::vector<Asset*>{
man->get<TrueTypeAsset>("truetype_ark"),
man->get<TextureAsset>("texture_test")
};
assertNotNull(man);
std::vector<Asset*> assets;
vectorAppend(&assets, &PokerGameBorder::getAssets(man));
assets.push_back(man->get<TrueTypeAsset>("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<TrueTypeAsset>("truetype_ark");
auto assetTexture = assMan->get<TextureAsset>("texture_test");
auto textbox = canvas->addElement<VisualNovelTextbox>();
textbox->setBorder(&assetTexture->texture, glm::vec2(16, 16));
auto assetFont = textbox->getGame()->assetManager.get<TrueTypeAsset>("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<VisualNovelTextbox>();
PokerGameTextbox::apply(textbox);
textbox->setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
glm::vec4(0, 238, 0, 0),

View File

@ -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<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
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(

View File

@ -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<Asset*> getAssets(AssetManager *assMan) {
return std::vector<Asset*>{
assMan->get<TrueTypeAsset>("truetype_ark")
};
std::vector<Asset*> assets;
vectorAppend(&assets, &PokerGameBorder::getAssets(assMan));
assets.push_back(assMan->get<TrueTypeAsset>("truetype_ark"));
return assets;
}
PokerPlayerDisplay(UICanvas *canvas);