Started work on prefabs.
This commit is contained in:
38
src/dawnbarrygame/prefabs/UIBorderPrefab.hpp
Normal file
38
src/dawnbarrygame/prefabs/UIBorderPrefab.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/Prefab.hpp"
|
||||
#include "ui/UIBorder.hpp"
|
||||
#include "asset/assets/TextureAsset.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
#define UI_BORDER_TEXTURE_ASSET "texture_test"
|
||||
|
||||
namespace Dawn {
|
||||
class UIBorderPrefab : public UIPrefab<UIBorder> {
|
||||
protected:
|
||||
static std::vector<Asset*> getAssets(AssetManager *man) override {
|
||||
return std::vector<Asset*>{
|
||||
man->get<TextureAsset>(UI_BORDER_TEXTURE_ASSET)
|
||||
};
|
||||
}
|
||||
|
||||
static SceneItem * uiCreate(UICanvas *canvas) override {
|
||||
auto border = canvas->addElement<UIBorder>();
|
||||
UIPrefab::uiApply(border);
|
||||
return border;
|
||||
}
|
||||
|
||||
public:
|
||||
void uiApply(UIBorder *border) {
|
||||
border->texture = &border
|
||||
->getGame()
|
||||
->assetManager.get<TextureAsset>(UI_BORDER_TEXTURE_ASSET)->texture
|
||||
;
|
||||
border->setBorderSize(glm::vec2(16, 16));
|
||||
}
|
||||
}
|
||||
}
|
36
src/dawnbarrygame/prefabs/VisualNovelTextboxPrefab.hpp
Normal file
36
src/dawnbarrygame/prefabs/VisualNovelTextboxPrefab.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "prefabs/UIBorderPrefab.hpp"
|
||||
#include "visualnovel/ui/VisualNovelTextbox.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelTextboxPrefab : public UIPrefab<VisualNovelTextbox> {
|
||||
public:
|
||||
static std::vector<Asset*> getAssets(AssetManager *man) {
|
||||
std::vector<Asset*> assets{
|
||||
man->get<TrueTypeAsset>("truetype_ark")
|
||||
};
|
||||
vectorAppend(&assets, &UIBorderPrefab::getAssets(man));
|
||||
return assets;
|
||||
}
|
||||
|
||||
static void uiApply(VisualNovelTextbox *textbox) override {
|
||||
assertNotNull(textbox);
|
||||
|
||||
auto assetFont = textbox->getGame()->assetManager.get<TrueTypeAsset>("truetype_ark");
|
||||
UIBorderPrefab::uiApply(&textbox->border);
|
||||
textbox->setFont(&assetFont->font);
|
||||
textbox->setFontSize(40);
|
||||
textbox->setLabelPadding(glm::vec2(10, 8));
|
||||
textbox->setTransform(
|
||||
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
|
||||
glm::vec4(0, 238, 0, 0),
|
||||
0.0f
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user