Skip to content

Commit

Permalink
TextCinematicDefinition cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
afritz1 committed Jan 1, 2025
1 parent 70e1774 commit 3acd25e
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 101 deletions.
6 changes: 3 additions & 3 deletions OpenTESArena/src/Interface/CharacterCreationUiController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,9 @@ void ChooseAttributesUiController::onSavedDoneButtonSelected(Game &game)
const bool success = cinematicLibrary.findTextDefinitionIndexIf(
[&defPtr](const TextCinematicDefinition &def)
{
if (def.getType() == TextCinematicDefinition::Type::MainQuest)
if (def.type == TextCinematicDefinitionType::MainQuest)
{
const auto &mainQuestCinematicDef = def.getMainQuestDefinition();
const MainQuestTextCinematicDefinition &mainQuestCinematicDef = def.mainQuest;
const bool isMainQuestStartCinematic = mainQuestCinematicDef.progress == 0;
if (isMainQuestStartCinematic)
{
Expand All @@ -600,7 +600,7 @@ void ChooseAttributesUiController::onSavedDoneButtonSelected(Game &game)
game.setCharacterCreationState(nullptr);

TextureManager &textureManager = game.textureManager;
const std::string &cinematicFilename = defPtr->getAnimationFilename();
const std::string &cinematicFilename = defPtr->animFilename;
const std::optional<TextureFileMetadataID> metadataID = textureManager.tryGetMetadataID(cinematicFilename.c_str());
if (!metadataID.has_value())
{
Expand Down
8 changes: 3 additions & 5 deletions OpenTESArena/src/Interface/CinematicLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ void CinematicLibrary::init()

// Main quest intro.
TextCinematicDefinition textCinematicDef;
textCinematicDef.initMainQuest(1400, std::string(animFilenameDreamGood), ColorGood, 0);
textCinematicDef.initMainQuest(1400, animFilenameDreamGood, ColorGood, 0);
this->textDefs.emplace_back(std::move(textCinematicDef));

// Death (good).
textCinematicDef.initDeath(1402, std::string(animFilenameDreamGood), ColorGood,
TextCinematicDefinition::DeathDefinition::Type::Good);
textCinematicDef.initDeath(1402, animFilenameDreamGood, ColorGood, DeathTextCinematicType::Good);
this->textDefs.emplace_back(std::move(textCinematicDef));

// Death (bad).
textCinematicDef.initDeath(1403, std::string(animFilenameDreamBad), ColorBad,
TextCinematicDefinition::DeathDefinition::Type::Bad);
textCinematicDef.initDeath(1403, animFilenameDreamBad, ColorBad, DeathTextCinematicType::Bad);
this->textDefs.emplace_back(std::move(textCinematicDef));
}

Expand Down
57 changes: 10 additions & 47 deletions OpenTESArena/src/Interface/TextCinematicDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,30 @@

#include "components/debug/Debug.h"

void TextCinematicDefinition::DeathDefinition::init(DeathDefinition::Type type)
void DeathTextCinematicDefinition::init(DeathTextCinematicType type)
{
this->type = type;
}

void TextCinematicDefinition::MainQuestDefinition::init(int progress)
void MainQuestTextCinematicDefinition::init(int progress)
{
this->progress = progress;
}

void TextCinematicDefinition::init(Type type, int templateDatKey, std::string &&animFilename,
const Color &fontColor)
void TextCinematicDefinition::initDeath(int templateDatKey, const std::string &animFilename, const Color &fontColor, DeathTextCinematicType type)
{
this->type = type;
this->type = TextCinematicDefinitionType::Death;
this->templateDatKey = templateDatKey;
this->animFilename = std::move(animFilename);
this->animFilename = animFilename;
this->fontColor = fontColor;
}

void TextCinematicDefinition::initDeath(int templateDatKey, std::string &&animFilename,
const Color &fontColor, DeathDefinition::Type type)
{
this->init(Type::Death, templateDatKey, std::move(animFilename), fontColor);
this->death.init(type);
}

void TextCinematicDefinition::initMainQuest(int templateDatKey, std::string &&animFilename,
const Color &fontColor, int progress)
void TextCinematicDefinition::initMainQuest(int templateDatKey, const std::string &animFilename, const Color &fontColor, int progress)
{
this->init(Type::MainQuest, templateDatKey, std::move(animFilename), fontColor);
this->type = TextCinematicDefinitionType::MainQuest;
this->templateDatKey = templateDatKey;
this->animFilename = animFilename;
this->fontColor = fontColor;
this->mainQuest.init(progress);
}

TextCinematicDefinition::Type TextCinematicDefinition::getType() const
{
return this->type;
}

int TextCinematicDefinition::getTemplateDatKey() const
{
return this->templateDatKey;
}

const std::string &TextCinematicDefinition::getAnimationFilename() const
{
return this->animFilename;
}

const Color &TextCinematicDefinition::getFontColor() const
{
return this->fontColor;
}

const TextCinematicDefinition::DeathDefinition &TextCinematicDefinition::getDeathDefinition() const
{
DebugAssert(this->type == Type::Death);
return this->death;
}

const TextCinematicDefinition::MainQuestDefinition &TextCinematicDefinition::getMainQuestDefinition() const
{
DebugAssert(this->type == Type::MainQuest);
return this->mainQuest;
}
69 changes: 28 additions & 41 deletions OpenTESArena/src/Interface/TextCinematicDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,49 @@

#include "../Utilities/Color.h"

// Intended for text cinematics with speech.
class TextCinematicDefinition
enum class TextCinematicDefinitionType
{
public:
enum class Type
{
Death,
MainQuest
};
Death,
MainQuest
};

struct DeathDefinition
{
enum class Type
{
Good,
Bad
};
enum class DeathTextCinematicType
{
Good,
Bad
};

DeathDefinition::Type type;
struct DeathTextCinematicDefinition
{
DeathTextCinematicType type;

void init(DeathDefinition::Type type);
};
void init(DeathTextCinematicType type);
};

struct MainQuestDefinition
{
int progress; // Current point in main quest.
struct MainQuestTextCinematicDefinition
{
int progress; // Current point in main quest.

void init(int progress);
};
private:
Type type;
void init(int progress);
};

// Intended for text cinematics with speech.
struct TextCinematicDefinition
{
TextCinematicDefinitionType type;
int templateDatKey; // Maps to TEMPLATE.DAT text and used with .VOC filenames.
std::string animFilename;
Color fontColor;
// @todo: maybe some isFloppyVersion bool to support floppy/CD endings.

union
{
DeathDefinition death;
MainQuestDefinition mainQuest;
DeathTextCinematicDefinition death;
MainQuestTextCinematicDefinition mainQuest;
};

void init(Type type, int templateDatKey, std::string &&animFilename, const Color &fontColor);
public:
void initDeath(int templateDatKey, std::string &&animFilename, const Color &fontColor,
DeathDefinition::Type type);
void initMainQuest(int templateDatKey, std::string &&animFilename, const Color &fontColor,
int progress);

Type getType() const;
int getTemplateDatKey() const;
const std::string &getAnimationFilename() const;
const Color &getFontColor() const;

const DeathDefinition &getDeathDefinition() const;
const MainQuestDefinition &getMainQuestDefinition() const;
void initDeath(int templateDatKey, const std::string &animFilename, const Color &fontColor, DeathTextCinematicType type);
void initMainQuest(int templateDatKey, const std::string &animFilename, const Color &fontColor, int progress);
};

#endif
6 changes: 3 additions & 3 deletions OpenTESArena/src/Interface/TextCinematicPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool TextCinematicPanel::init(int textCinematicDefIndex, double secondsPerImage,
const auto &fontLibrary = FontLibrary::getInstance();

const TextCinematicDefinition &textCinematicDef = cinematicLibrary.getTextDefinition(textCinematicDefIndex);
const TextBox::InitInfo subtitlesTextBoxInitInfo = TextCinematicUiView::getSubtitlesTextBoxInitInfo(textCinematicDef.getFontColor(), fontLibrary);
const TextBox::InitInfo subtitlesTextBoxInitInfo = TextCinematicUiView::getSubtitlesTextBoxInitInfo(textCinematicDef.fontColor, fontLibrary);
if (!this->textBox.init(subtitlesTextBoxInitInfo, renderer))
{
DebugLogError("Couldn't init subtitles text box.");
Expand Down Expand Up @@ -89,7 +89,7 @@ bool TextCinematicPanel::init(int textCinematicDefIndex, double secondsPerImage,
this->textPages = TextCinematicUiModel::getSubtitleTextPages(subtitleText);

auto &textureManager = game.textureManager;
const std::string &animFilename = textCinematicDef.getAnimationFilename();
const std::string &animFilename = textCinematicDef.animFilename;
const Buffer<UiTextureID> animTextureIDs = TextCinematicUiView::allocAnimationTextures(animFilename, textureManager, renderer);
if (animTextureIDs.getCount() == 0)
{
Expand Down Expand Up @@ -128,7 +128,7 @@ bool TextCinematicPanel::init(int textCinematicDefIndex, double secondsPerImage,
// Optionally initialize speech state if speech is available.
if (TextCinematicUiModel::shouldPlaySpeech(game))
{
this->speechState.init(textCinematicDef.getTemplateDatKey());
this->speechState.init(textCinematicDef.templateDatKey);
}

this->onFinished = onFinished;
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/Interface/TextCinematicUiModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ std::string TextCinematicUiModel::getSubtitleText(Game &game, const TextCinemati
{
const auto &textAssetLibrary = TextAssetLibrary::getInstance();
const auto &templateDat = textAssetLibrary.getTemplateDat();
const auto &templateDatEntry = templateDat.getEntry(textCinematicDef.getTemplateDatKey());
const auto &templateDatEntry = templateDat.getEntry(textCinematicDef.templateDatKey);
std::string cinematicText = templateDatEntry.values.front();
cinematicText.push_back('\n');

Expand Down
3 changes: 2 additions & 1 deletion OpenTESArena/src/Interface/TextCinematicUiModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <vector>

class Game;
class TextCinematicDefinition;

struct TextCinematicDefinition;

namespace TextCinematicUiModel
{
Expand Down

0 comments on commit 3acd25e

Please sign in to comment.