This commit is contained in:
2024-09-29 00:47:12 -05:00
parent 2cb1d745b2
commit c770953b2e
12 changed files with 178 additions and 19 deletions

View File

@ -28,7 +28,7 @@ namespace Dawn {
}
);
if(existing == finishedAssetLoaders.end()) {
if(existing == pendingAssetLoaders.end()) {
existing = std::find_if(
finishedAssetLoaders.begin(), finishedAssetLoaders.end(),
[&](auto &loader) {

View File

@ -11,3 +11,4 @@ target_sources(${DAWN_TARGET_NAME}
# Subdirs
add_subdirectory(display)
add_subdirectory(ui)
add_subdirectory(vn)

View File

@ -142,3 +142,8 @@ void UICanvas::flushPass() {
void UICanvas::addElement(std::shared_ptr<UIElement> element) {
elements.push_back(element);
}
void UICanvas::removeElement(std::shared_ptr<UIElement> element) {
auto it = std::find(elements.begin(), elements.end(), element);
if(it != elements.end()) elements.erase(it);
}

View File

@ -69,5 +69,12 @@ namespace Dawn {
* @param component The component to add.
*/
void addElement(std::shared_ptr<UIElement> component);
/**
* Removes a component from the canvas.
*
* @param component The component to remove.
*/
void removeElement(std::shared_ptr<UIElement> component);
};
}

View File

@ -0,0 +1,9 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DAWN_TARGET_NAME}
PRIVATE
VNManager.cpp
)

View File

@ -0,0 +1,62 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNManager.hpp"
using namespace Dawn;
void VNManager::onInit() {
assertNotNull(canvas, "Canvas must be set.");
assertNotNull(texture, "Texture must be set.");
container = std::make_shared<UIContainer>();
container->align = { 0, 128, 0, 0 };
container->alignX = UIAlignmentType::STRETCH;
container->alignY = UIAlignmentType::END;
borders = std::make_shared<UIRectangle>();
borders->align = { 0, 0, 0, 0 };
borders->alignX = UIAlignmentType::STRETCH;
borders->alignY = UIAlignmentType::STRETCH;
borders->color = COLOR_BLUE;
container->appendChild(borders);
background = std::make_shared<UIRectangle>();
background->align = { 16, 16, 16, 16 };
background->alignX = UIAlignmentType::STRETCH;
background->alignY = UIAlignmentType::STRETCH;
background->color = COLOR_RED;
container->appendChild(background);
label = std::make_shared<UILabel>();
label->align = { 16, 16, 16, 16 };
label->alignX = UIAlignmentType::STRETCH;
label->alignY = UIAlignmentType::STRETCH;
label->setFont(texture);
label->setText(text);
container->appendChild(label);
canvas->addElement(container);
listeners.push_back(getScene()->onUnpausedUpdate.listen([&](const float_t d) {
}));
}
void VNManager::onDispose() {
canvas->removeElement(container);
container = nullptr;
label = nullptr;
background = nullptr;
borders = nullptr;
texture = nullptr;
canvas = nullptr;
}
void VNManager::setText(const std::wstring &text) {
this->text = text;
if(label) label->setText(text);
}

View File

@ -0,0 +1,36 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItem.hpp"
#include "ui/container/UIContainer.hpp"
#include "ui/elements/UILabel.hpp"
#include "ui/elements/UIRectangle.hpp"
namespace Dawn {
class VNManager : public SceneComponent {
protected:
std::shared_ptr<UIContainer> container;
std::shared_ptr<UILabel> label;
std::shared_ptr<UIRectangle> borders;
std::shared_ptr<UIRectangle> background;
std::wstring text;
public:
std::shared_ptr<UICanvas> canvas;
std::shared_ptr<TrueTypeTexture> texture;
void onInit() override;
void onDispose() override;
/**
* Sets the text to display.
*
* @param text The text to display.
*/
void setText(const std::wstring &text);
};
}

View File

@ -200,25 +200,20 @@ void UIAlignableElement::updateSelfAlignment(
}
bool_t UIAlignableElement::hasExplicitWidth() {
if(size.x == 0.0f) return false;
if(
(alignX == UIAlignmentType::STRETCH) ||
(alignX == UIAlignmentType::END)
) {
return align[0] != UI_ALIGN_SIZE_AUTO;
}
return align[2] != UI_ALIGN_SIZE_AUTO;
}
bool_t UIAlignableElement::hasExplicitHeight() {
if(size.y == 0.0f) return false;
if(
(alignY == UIAlignmentType::STRETCH) ||
(alignY == UIAlignmentType::END)
) {
if(alignX == UIAlignmentType::STRETCH) return true;
if(alignX == UIAlignmentType::END) {
return align[1] != UI_ALIGN_SIZE_AUTO;
}
return align[3] != UI_ALIGN_SIZE_AUTO;
}
bool_t UIAlignableElement::hasExplicitHeight() {
if(alignY == UIAlignmentType::STRETCH) return true;
if(alignY == UIAlignmentType::END) {
return align[0] != UI_ALIGN_SIZE_AUTO;
}
return align[2] != UI_ALIGN_SIZE_AUTO;
}
float_t UIAlignableElement::getWidth() {

View File

@ -8,5 +8,5 @@
using namespace Dawn;
const std::function<void(Scene&)> Scene::getInitialScene() {
return Dawn::worldScene;
return Dawn::vnScene;
}

View File

@ -7,4 +7,5 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE
TestScene.cpp
WorldScene.cpp
VNScene.cpp
)

View File

@ -9,4 +9,5 @@
namespace Dawn {
void testScene(Scene &scene);
void worldScene(Scene &scene);
void vnScene(Scene &scene);
}

View File

@ -0,0 +1,42 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "scenes/SceneList.hpp"
#include "component/display/Camera.hpp"
#include "component/ui/UICanvas.hpp"
#include "ui/elements/UIRectangle.hpp"
#include "ui/elements/UILabel.hpp"
#include "ui/UIMenu.hpp"
#include "ui/container/UIRowContainer.hpp"
#include "ui/container/UIPaddingContainer.hpp"
#include "component/vn/VNManager.hpp"
using namespace Dawn;
void Dawn::vnScene(Scene &s) {
// Load assets
// auto testj = s.getGame()->assetManager.get<json>("test");
auto texture = s.getGame()->assetManager.get<TrueTypeTexture>("font_silver", 32);
while(!s.getGame()->assetManager.isEverythingLoaded()) {
s.getGame()->assetManager.update();
}
// Setup camera
auto cameraItem = s.createSceneItem();
auto camera = cameraItem->addComponent<Camera>();
cameraItem->lookAt({ 3, 3, 3 }, { 0, 0, 0 }, { 0, 1, 0 });
camera->clipFar = 99999.99f;
// Create canvas
auto canvasItem = s.createSceneItem();
auto canvas = canvasItem->addComponent<UICanvas>();
auto vnManager = canvasItem->addComponent<VNManager>();
vnManager->canvas = canvas;
vnManager->texture = texture;
vnManager->setText(L"broivvoib");
}