This commit is contained in:
2023-03-05 12:58:59 -08:00
parent 855ac79095
commit f7ff21fa8d
24 changed files with 501 additions and 520 deletions

View File

@ -35,7 +35,6 @@ add_subdirectory(save)
add_subdirectory(scene) add_subdirectory(scene)
add_subdirectory(state) add_subdirectory(state)
add_subdirectory(time) add_subdirectory(time)
add_subdirectory(ui)
if(DAWN_VISUAL_NOVEL) if(DAWN_VISUAL_NOVEL)
add_subdirectory(visualnovel) add_subdirectory(visualnovel)

View File

@ -153,14 +153,16 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
assertUnreachable(); assertUnreachable();
} }
auto itChild = canvas->children.begin(); auto children = canvas->item.chil
while(itChild != canvas->children.end()) {
vectorAppend(&shaderPassItems, (*itChild)->getPassItems( // auto itChild = canvas->children.begin();
projection, view, model // while(itChild != canvas->children.end()) {
)); // vectorAppend(&shaderPassItems, (*itChild)->getPassItems(
++itChild; // projection, view, model
} // ));
++itCanvas; // ++itChild;
// }
// ++itCanvas;
} }
// Debug Lines // Debug Lines

View File

@ -9,8 +9,7 @@
#include "scene/components/display/MeshRenderer.hpp" #include "scene/components/display/MeshRenderer.hpp"
#include "scene/components/display/Camera.hpp" #include "scene/components/display/Camera.hpp"
#include "scene/components/scene/SubSceneController.hpp" #include "scene/components/scene/SubSceneController.hpp"
#include "ui/UIComponent.hpp" #include "scene/components/ui/UIComponent.hpp"
namespace Dawn { namespace Dawn {
class RenderManager; class RenderManager;

View File

@ -4,9 +4,7 @@
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "UICanvas.hpp" #include "UICanvas.hpp"
#include "ui/UIComponent.hpp"
#include "game/DawnGame.hpp" #include "game/DawnGame.hpp"
#include "ui/UIMenu.hpp"
using namespace Dawn; using namespace Dawn;
@ -15,71 +13,11 @@ UICanvas * UICanvas::create(Scene *scene) {
return item->addComponent<UICanvas>(); return item->addComponent<UICanvas>();
} }
UICanvas::UICanvas(SceneItem *item) : UICanvas::UICanvas(SceneItem *item) : SceneItemComponent(item) {
SceneItemComponent(item),
camera(nullptr),
currentMenu(nullptr)
{
}
float_t UICanvas::getWidth() {
if(this->camera == nullptr) {
return this->getGame()->renderManager.getBackBuffer()->getWidth();
}
return this->camera->getRenderTarget()->getWidth();
}
float_t UICanvas::getHeight() {
if(this->camera == nullptr) {
return this->getGame()->renderManager.getBackBuffer()->getHeight();
}
return this->camera->getRenderTarget()->getHeight();
}
void UICanvas::setCurrentMenu(struct UIMenu *menu) {
} }
void UICanvas::onStart() { void UICanvas::onStart() {
useEffectWithTeardown([&]{
if(this->camera == nullptr) return evtCamResize = [&]{};
auto it = this->children.begin();
while(it != this->children.end()) {
(*it)->updatePositions();
++it;
}
return evtCamResize = useEvent([&](float_t w, float_t h){
auto it = this->children.begin();
while(it != this->children.end()) {
(*it)->updatePositions();
++it;
}
}, camera->eventRenderTargetResized);
}, camera);
useEffectWithTeardown([&]{
if(currentMenu != nullptr) currentMenu->onActive();
return [&] {
if(currentMenu == nullptr) currentMenu->onInactive();
};
}, this->currentMenu);
// Scene Update
useEvent([&](float_t delta){
if(this->currentMenu == nullptr) return;
this->currentMenu->onTick();
}, getScene()->eventSceneUpdate);
// Find Camera if we need to.
if(camera == nullptr) camera = this->getScene()->findComponent<Camera>();
} }
void UICanvas::onDispose() { void UICanvas::onDispose() {
auto it = this->children.begin();
while(it != this->children.end()) {
delete *it;
++it;
}
} }

View File

@ -15,19 +15,8 @@ namespace Dawn {
UI_DRAW_TYPE_CAMERA_OVERLAY UI_DRAW_TYPE_CAMERA_OVERLAY
}; };
class UIComponent;
struct UIMenu;
class UICanvas : public SceneItemComponent { class UICanvas : public SceneItemComponent {
protected:
std::function<void()> evtCamResize;
void onRenderTargetResize(float_t w, float_t h);
public: public:
StateProperty<struct UIMenu*> currentMenu;
StateProperty<Camera*> camera;
/** /**
* Creates a UI Canvas Scene Item Element, and attaches it to the provided * Creates a UI Canvas Scene Item Element, and attaches it to the provided
* scene. * scene.
@ -38,8 +27,8 @@ namespace Dawn {
static UICanvas * create(Scene *scene); static UICanvas * create(Scene *scene);
//======================================================================// //======================================================================//
std::vector<UIComponent*> children;
UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE; enum UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE;
/** /**
* Constructs the UI Canvas Scene Item Component. * Constructs the UI Canvas Scene Item Component.
@ -48,65 +37,6 @@ namespace Dawn {
*/ */
UICanvas(SceneItem *item); UICanvas(SceneItem *item);
/**
* Construct and append a UI item to this UI Canvas.
*
* @tparam Type of the UI Item.
* @return Pointer to the created UI Item.
*/
template<class T>
T * addElement() {
auto item = new T(this);
this->children.push_back(item);
return item;
}
/**
* Find a UI Element attached to this canvas.
*
* @tparam Type of the UI item to find.
* @return Pointer to first matching element of type T.
*/
template<class T>
T * findElement() {
auto it = this->children.begin();
while(it != this->children.end()) {
auto castedAs = dynamic_cast<T*>(*it);
if(castedAs != nullptr) return castedAs;
++it;
}
return nullptr;
}
/**
* Returns the width of the root UI Canvas size. In future I may allow
* this to be dynamic, right now it uses the render canvas however.
*
* @return Width of the UI Canvas.
*/
float_t getWidth();
/**
* Returns the height of this UI Canvas element.
*
* @return Height of the UI Canvas.
*/
float_t getHeight();
/**
* Returns the currently active menu for this UI Canvas.
*
* @return The currently active menu, or nullptr if there is none.
*/
struct UIMenu * getCurrentMenu();
/**
* Sets the currently active menu, and ticks it appropriately.
*
* @param menu Menu to set as the current active menu.
*/
void setCurrentMenu(struct UIMenu *menu);
void onStart() override; void onStart() override;
void onDispose() override; void onDispose() override;
}; };

View File

@ -0,0 +1,12 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIComponent.hpp"
using namespace Dawn;
UIComponent::UIComponent(SceneItem *item) : SceneItemComponent(item) {
}

View File

@ -0,0 +1,20 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "UICanvas.hpp"
namespace Dawn {
class UIComponent : public SceneItemComponent {
private:
UICanvas *canvas = nullptr;
public:
UIComponent(SceneItem *item);
friend class UICanvas;
};
}

View File

@ -0,0 +1,49 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UILabel.hpp"
using namespace Dawn;
UILabel::UILabel(SceneItem *item) :
UIComponent(item),
text(""),
fontSize(10.0f),
font(nullptr)
{
}
void UILabel::updateMesh() {
if(!this->needsRebuffering || !this->hasText) return;
if(((Font*)this->font) == nullptr || !this->font->isReady()) return;
// float_t width = this->width;
// if(width == 0) width = -1;
// std::string text = this->getGame()->localeManager.getString(key);
this->font->buffer(
this->text,
this->fontSize,
-1,
&this->mesh,
&this->measure
);
this->needsRebuffering = false;
}
void UILabel::onStart() {
useEffect([&]{
hasText = ((std::string)text).size() > 0;
needsRebuffering = true;
}, text);
useEffect([&]{
needsRebuffering = true;
}, fontSize);
useEffect([&]{
needsRebuffering = true;
}, font);
}

View File

@ -0,0 +1,32 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "UIComponent.hpp"
namespace Dawn {
class UILabel : public UIComponent {
private:
bool_t needsRebuffering = true;
bool_t hasText = false;
Mesh mesh;
void updateMesh();
public:
StateProperty<std::string> text;
StateProperty<float_t> fontSize;
StateProperty<Font*> font;
struct Color textColor = COLOR_MAGENTA;
struct FontMeasure measure;
int32_t startQuad = 0;
int32_t quadCount = -1;
UILabel(SceneItem *item);
void onStart() override;
};
}