diff --git a/include/AssetManager.h b/include/AssetManager.h index a5f635f..17ea8d2 100644 --- a/include/AssetManager.h +++ b/include/AssetManager.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #include #include @@ -33,15 +34,19 @@ public: // sound management void addSoundEffect(std::string id, const char* path); - void addMusic(std::string id, const char* path); - Mix_Chunk* getSound(std::string id); + void addFont(std::string id, const char* path); + + Mix_Chunk* getSound(std::string id); // ??? do we not have a getsound implemented????? too busy to look now, where do we get the soundeffects??? Mix_Music* getMusic(std::string id); + TTF_Font* getFont(std::string id); + private: Manager* man; std::map soundEffects; std::map music; + std::map fonts; }; diff --git a/include/DialogHandler.h b/include/DialogHandler.h new file mode 100644 index 0000000..55c6cd0 --- /dev/null +++ b/include/DialogHandler.h @@ -0,0 +1,15 @@ +#ifndef CHICKENGAME_DIALOGHANDLER_H +#define CHICKENGAME_DIALOGHANDLER_H + +class DialogHandler +{ +public: + void displayDialog(); + + +private: + +}; + + +#endif //CHICKENGAME_DIALOGHANDLER_H diff --git a/include/GameInternal.h b/include/GameInternal.h index 7cb3b1f..573b9c9 100644 --- a/include/GameInternal.h +++ b/include/GameInternal.h @@ -18,6 +18,7 @@ class AssetManager; class CollisionHandler; class TextureManager; class SoundManager; +class TextManager; class Map; class Game; @@ -43,6 +44,7 @@ public: /* static */ AssetManager* assets; /* static */ TextureManager* textureManager; /* static */ SoundManager* soundManager; + /* static */ TextManager* textManager; Manager manager; RenderManager renderManager; diff --git a/include/TextManager.h b/include/TextManager.h new file mode 100644 index 0000000..a2b607f --- /dev/null +++ b/include/TextManager.h @@ -0,0 +1,26 @@ +#ifndef CHICKENGAME_TEXTMANAGER_H +#define CHICKENGAME_TEXTMANAGER_H + +#include +#include + +class TextManager +{ +public: + TextManager() {} + ~TextManager() { + for (auto& it : this->font_cache) { + TTF_CloseFont(it.second); + } + } + + TextManager(TextManager const&) = delete; + void operator=(TextManager const&) = delete; + + TTF_Font* loadFont(const char* filepath); + + std::map font_cache; +private: +}; + +#endif //CHICKENGAME_TEXTMANAGER_H diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index ae8242a..926a3dd 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -2,6 +2,7 @@ #include "TextureManager.h" #include "SoundManager.h" +#include "TextManager.h" #include "ProjectileComponent.h" #include "GameInternal.h" @@ -31,9 +32,9 @@ void AssetManager::addMusic(std::string id, const char* path) music.emplace(id, this->man->getGame()->soundManager->loadMusic(path)); } - -Mix_Chunk* AssetManager::getSound(std::string id) { - return soundEffects.at(id); +void AssetManager::addFont(std::string id, const char *path) +{ + fonts.emplace(id, this->man->getGame()->textManager->loadFont(path)); } Mix_Music* AssetManager::getMusic(std::string id) @@ -41,6 +42,16 @@ Mix_Music* AssetManager::getMusic(std::string id) return music.at(id); } +Mix_Chunk* AssetManager::getSound(std::string id) +{ + return soundEffects.at(id); +} + +TTF_Font* AssetManager::getFont(std::string id) +{ + return fonts.at(id); +} + void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, float speed, Textures textureEnum, Entity* owner) { auto& projectile(man->addEntity()); diff --git a/src/DialogHandler.cpp b/src/DialogHandler.cpp new file mode 100644 index 0000000..20eed21 --- /dev/null +++ b/src/DialogHandler.cpp @@ -0,0 +1,5 @@ +// +// Created by PC on 21.01.2025. +// + +#include "../include/DialogHandler.h" diff --git a/src/TextManager.cpp b/src/TextManager.cpp new file mode 100644 index 0000000..cbb1c47 --- /dev/null +++ b/src/TextManager.cpp @@ -0,0 +1,23 @@ +#include "TextManager.h" + +#include + +TTF_Font* TextManager::loadFont(const char *filepath) +{ + auto it = this->font_cache.find(filepath); + + if (it != this->font_cache.end()) { + return it->second; + } + + auto font = TTF_OpenFont(filepath, 12); // setting fontsize to 12 for now + + if (font == NULL) + std::cerr << "Couldn't load font '" << filepath << "'" << std::endl; + + this->font_cache.emplace(filepath, font); + + std::cout << "Loaded font at " << filepath << std::endl; + + return font; +} \ No newline at end of file