This commit is contained in:
2023-03-05 12:58:59 -08:00
parent 96b9cb75f0
commit 7d20397e83
24 changed files with 127 additions and 1522 deletions

View File

@ -4,9 +4,7 @@
// https://opensource.org/licenses/MIT
#include "UICanvas.hpp"
#include "ui/UIComponent.hpp"
#include "game/DawnGame.hpp"
#include "ui/UIMenu.hpp"
using namespace Dawn;
@ -15,71 +13,11 @@ UICanvas * UICanvas::create(Scene *scene) {
return item->addComponent<UICanvas>();
}
UICanvas::UICanvas(SceneItem *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) {
UICanvas::UICanvas(SceneItem *item) : SceneItemComponent(item) {
}
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() {
auto it = this->children.begin();
while(it != this->children.end()) {
delete *it;
++it;
}
}