Adding VN Character interface

This commit is contained in:
2022-12-18 13:48:43 -08:00
parent 1dbfd9f42e
commit 53ebbf0699
12 changed files with 93 additions and 26 deletions

@ -7,4 +7,5 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
SimpleVisualNovelBackground.cpp
VisualNovelCharacter.cpp
)

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

@ -0,0 +1,22 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
namespace Dawn {
class VisualNovelCharacter : public SceneItemComponent {
public:
std::string nameKey = "character.unknown";
/**
* Visual Novel Character Component. Mostly logic-less but provides nice
* interfaces for sibling components.
*
* @param item Item that this component belongs to.
*/
VisualNovelCharacter(SceneItem *item);
};
}

@ -8,16 +8,19 @@
using namespace Dawn;
VisualNovelTextboxEvent::VisualNovelTextboxEvent(
VisualNovelManager *manager,
std::string key
VisualNovelManager *manager,
VisualNovelCharacter *character,
std::string languageKey
) : IVisualNovelEvent(manager) {
this->key = key;
this->character = character;
this->languageKey = languageKey;
}
void VisualNovelTextboxEvent::onStart(IVisualNovelEvent *previous) {
if(this->manager->textBox == nullptr) return;
this->manager->textBox->setText(this->key);
this->manager->textBox->setText(this->languageKey);
this->manager->textBox->setCharacter(this->character);
this->manager->textBox->show();
this->hasSetText = true;
}
@ -26,7 +29,8 @@ bool_t VisualNovelTextboxEvent::onUpdate() {
if(this->manager->textBox == nullptr) return true;
if(!this->hasSetText) {
this->manager->textBox->setText(this->key);
this->manager->textBox->setText(this->languageKey);
this->manager->textBox->setCharacter(this->character);
this->manager->textBox->show();
this->hasSetText = true;
}

@ -5,11 +5,13 @@
#pragma once
#include "visualnovel/VisualNovelManager.hpp"
#include "visualnovel/components/VisualNovelCharacter.hpp"
namespace Dawn {
class VisualNovelTextboxEvent : public IVisualNovelEvent {
protected:
std::string key;
std::string languageKey;
VisualNovelCharacter *character;
bool_t hasSetText = false;
void onStart(IVisualNovelEvent *previous) override;
@ -17,9 +19,18 @@ namespace Dawn {
void onEnd() override;
public:
/**
* Create a new Textbox Event. This will queue a conversation item for the
* textbox to display.
*
* @param manager Visual Novel Manager instance for this event.
* @param character Character that is intended to be speaking.
* @param languageKey Language Key to talk.
*/
VisualNovelTextboxEvent(
VisualNovelManager *manager,
std::string text
VisualNovelCharacter *character,
std::string languageKey
);
};
}

@ -153,6 +153,10 @@ void VisualNovelTextbox::setText(std::string key, float_t fontSize) {
this->label.updateMesh();
}
void VisualNovelTextbox::setCharacter(VisualNovelCharacter *character) {
this->character = character;
}
void VisualNovelTextbox::setText(std::string key) {
this->label.setText(key);
this->label.updateMesh();

@ -9,6 +9,7 @@
#include "ui/UILabel.hpp"
#include "ui/UIEmpty.hpp"
#include "util/mathutils.hpp"
#include "visualnovel/components/VisualNovelCharacter.hpp"
#define VISUAL_NOVEL_TEXTBOX_SPEED 25.0f
#define VISUAL_NOVEL_TEXTBOX_SPEED_FASTER 40.0f
@ -21,6 +22,7 @@ namespace Dawn {
UIEmpty selfParent;
float_t timeCharacter = 0.0f;
bool_t visible = false;
VisualNovelCharacter *character = nullptr;
void updatePositions() override;
void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
@ -82,6 +84,13 @@ namespace Dawn {
*/
void setText(std::string key);
/**
* Sets the VN Character for this text.
*
* @param character Character to set.
*/
void setCharacter(VisualNovelCharacter *character);
/**
* Sets the font size to use.
*

@ -25,7 +25,6 @@ add_subdirectory(scenes)
# Assets
tool_language(language_en locale/en.csv)
tool_language(language_fr locale/fr.csv)
tool_texture(texture_test texture_test.png)
tool_texture(texture_city_day borrowed/city_day.png)
tool_texture(texture_city_night borrowed/city_night.png)
@ -44,7 +43,6 @@ tool_truetype(truetype_ark
add_dependencies(${DAWN_TARGET_NAME}
language_en
language_fr
texture_test
tileset_penny
truetype_ark

@ -7,6 +7,7 @@
#include "asset/AssetManager.hpp"
#include "poker/PokerPlayer.hpp"
#include "scene/components/Components.hpp"
#include "visualnovel/components/VisualNovelCharacter.hpp"
#include "display/animation/TiledSpriteAnimation.hpp"
namespace Dawn {
@ -31,6 +32,9 @@ namespace Dawn {
auto tiledSprite = item->addComponent<TiledSprite>();
auto animation = item->addComponent<AnimationController>();
auto pokerPlayer = item->addComponent<PokerPlayer>();
auto vnCharacter = item->addComponent<VisualNovelCharacter>();
vnCharacter->nameKey = "character.penny.name";
auto param = material->getShader()->getParameterByName("u_Text");
material->textureValues[param] = &textureAsset->texture;

@ -41,10 +41,10 @@ namespace Dawn {
);
start
->then(new VisualNovelTextboxEvent(vnManager, "test"))
->then(new PokerNewGameEvent(vnManager))
->then(new VisualNovelTextboxEvent(vnManager, "test"))
->then(new PokerInitialEvent(vnManager))
->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent<VisualNovelCharacter>(), "undefined"))
// ->then(new PokerNewGameEvent(vnManager))
->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent<VisualNovelCharacter>(), "undefined"))
// ->then(new PokerInitialEvent(vnManager))
;
return start;

@ -16,49 +16,49 @@ void PokerBetLoopEvent::onStart(IVisualNovelEvent *prev) {
auto betting = this->then(evt2);
betting
->whenEveryoneFolded(new VisualNovelTextboxEvent(this->manager, "Everyone Folded"))
// ->whenEveryoneFolded(new VisualNovelTextboxEvent(this->manager, "Everyone Folded"))
->then(new PokerWinnerEvent(this->manager))
->then(new PokerInitialEvent(this->manager))
;
betting
->whenBettingFinished(new VisualNovelTextboxEvent(this->manager, "Betting Finished"))
// ->whenBettingFinished(new VisualNovelTextboxEvent(this->manager, "Betting Finished"))
->then(new PokerWinnerEvent(this->manager))
->then(new PokerInitialEvent(this->manager))
;
betting
->whenTurn(new PokerTurnEvent(this->manager))
->then(new VisualNovelTextboxEvent(this->manager, "Turn Time"))
// ->then(new VisualNovelTextboxEvent(this->manager, "Turn Time"))
->then(new PokerNewBettingRoundEvent(this->manager))
->then(new PokerBetLoopEvent(this->manager))
;
betting
->whenHumanBet(new VisualNovelTextboxEvent(this->manager, "Human Bet"))
// ->whenHumanBet(new VisualNovelTextboxEvent(this->manager, "Human Bet"))
->then(new PokerBetLoopEvent(this->manager))
;
// AI Betting
auto aiBet = betting
->whenAiBet(new VisualNovelTextboxEvent(this->manager, "AI Bet"))
// ->whenAiBet(new VisualNovelTextboxEvent(this->manager, "AI Bet"))
->then(new PokerAIBetEvent(this->manager))
;
aiBet
->whenFolded(new VisualNovelTextboxEvent(this->manager, "Folded"))
// ->whenFolded(new VisualNovelTextboxEvent(this->manager, "Folded"))
->then(new PokerBetLoopEvent(this->manager))
;
aiBet
->whenAllIn(new VisualNovelTextboxEvent(this->manager, "All In"))
// ->whenAllIn(new VisualNovelTextboxEvent(this->manager, "All In"))
->then(new PokerBetLoopEvent(this->manager))
;
aiBet
->whenBetting(new VisualNovelTextboxEvent(this->manager, "Betting"))
// ->whenBetting(new VisualNovelTextboxEvent(this->manager, "Betting"))
->then(new PokerBetLoopEvent(this->manager))
;
aiBet
->whenCalling(new VisualNovelTextboxEvent(this->manager, "Calling"))
// ->whenCalling(new VisualNovelTextboxEvent(this->manager, "Calling"))
->then(new PokerBetLoopEvent(this->manager))
;
aiBet
->whenChecking(new VisualNovelTextboxEvent(this->manager, "Checking"))
// ->whenChecking(new VisualNovelTextboxEvent(this->manager, "Checking"))
->then(new PokerBetLoopEvent(this->manager))
;
}

@ -20,11 +20,11 @@ namespace Dawn {
this
->then(new PokerNewRoundEvent(this->manager))
->then(new VisualNovelTextboxEvent(this->manager, "Round Started"))
// ->then(new VisualNovelTextboxEvent(this->manager, "Round Started"))
->then(new PokerTakeBlindsEvent(this->manager))
->then(new VisualNovelTextboxEvent(this->manager, "Blinds Taken"))
// ->then(new VisualNovelTextboxEvent(this->manager, "Blinds Taken"))
->then(new PokerDealEvent(this->manager))
->then(new VisualNovelTextboxEvent(this->manager, "Cards Dealt"))
// ->then(new VisualNovelTextboxEvent(this->manager, "Cards Dealt"))
->then(new PokerBetLoopEvent(this->manager))
;
}