Background test

This commit is contained in:
2022-12-13 23:30:19 -08:00
parent 41a85a0553
commit 850f4c227d
12 changed files with 138 additions and 27 deletions

View File

@ -7,6 +7,15 @@
using namespace Dawn;
SimpleVisualNovelBackground * SimpleVisualNovelBackground::create(Scene *s) {
auto item = s->createSceneItem();
item->addComponent<MeshRenderer>();
item->addComponent<MeshHost>();
item->addComponent<Material>();
auto background = item->addComponent<SimpleVisualNovelBackground>();
return background;
}
SimpleVisualNovelBackground::SimpleVisualNovelBackground(SceneItem *item) :
SceneItemComponent(item)
{
@ -15,11 +24,32 @@ SimpleVisualNovelBackground::SimpleVisualNovelBackground(SceneItem *item) :
std::vector<SceneItemComponent*> SimpleVisualNovelBackground::getDependencies(){
return std::vector<SceneItemComponent*>{
this->meshHost = this->item->getComponent<MeshHost>(),
this->material = this->item->getComponent<Material>()
this->material = this->item->getComponent<Material>(),
this->meshHost = this->item->getComponent<MeshHost>()
};
}
void SimpleVisualNovelBackground::onStart() {
void SimpleVisualNovelBackground::setTexture(Texture *texture) {
auto param = this->material->getShader()->getParameterByName("u_Text");
this->material->textureValues[param] = texture;
float_t aspect = (float_t)texture->getWidth() / (float_t)texture->getHeight();
float_t height = 0.5f;
QuadMesh::bufferQuadMeshWithZ(&this->meshHost->mesh,
glm::vec2(-aspect * height, -height), glm::vec2(0, 1),
glm::vec2( aspect * height, height), glm::vec2(1, 0),
0.0f, 0, 0
);
}
void SimpleVisualNovelBackground::onStart() {
assertNotNull(this->material);
assertNotNull(this->meshHost);
QuadMesh::initQuadMesh(&this->meshHost->mesh,
glm::vec2(-1, -1), glm::vec2(0, 1),
glm::vec2(1, 1), glm::vec2(1, 0),
0.0f
);
}

View File

@ -12,8 +12,11 @@ namespace Dawn {
Material *material;
MeshHost *meshHost;
static SimpleVisualNovelBackground * create(Scene *scene);
SimpleVisualNovelBackground(SceneItem *item);
std::vector<SceneItemComponent*> getDependencies() override;
void onStart() override;
void setTexture(Texture *texture);
};
}

View File

@ -10,4 +10,5 @@ target_sources(${DAWN_TARGET_NAME}
VisualNovelFadeEvent.cpp
VisualNovelPauseEvent.cpp
VisualNovelTextboxEvent.cpp
VisualNovelChangeSimpleBackgroundEvent.cpp
)

View File

@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT
#include "VisualNovelAnimationEvent.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;

View File

@ -0,0 +1,32 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VisualNovelChangeSimpleBackgroundEvent.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
VisualNovelChangeSimpleBackgroundEvent::VisualNovelChangeSimpleBackgroundEvent(
VisualNovelManager *manager, Texture *texture
) : IVisualNovelEvent(manager) {
this->texture = texture;
}
void VisualNovelChangeSimpleBackgroundEvent::onStart(IVisualNovelEvent *prev) {
auto back = this->manager->getScene()
->findComponent<SimpleVisualNovelBackground>()
;
assertNotNull(back);
back->setTexture(this->texture);
}
bool_t VisualNovelChangeSimpleBackgroundEvent::onUpdate() {
return false;
}
void VisualNovelChangeSimpleBackgroundEvent::onEnd() {
}

View File

@ -5,11 +5,16 @@
#pragma once
#include "visualnovel/VisualNovelManager.hpp"
#include "visualnovel/components/SimpleVisualNovelBackground.hpp"
namespace Dawn {
class VisualNovelChangeSimpleBackgroundEvent : public IVisualNovelEvent {
protected:
Texture *texture;
Texture *texture = nullptr;
void onStart(IVisualNovelEvent *previous) override;
bool_t onUpdate() override;
void onEnd() override;
public:
VisualNovelChangeSimpleBackgroundEvent(

View File

@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT
#include "VisualNovelPauseEvent.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;