mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 13:43:41 +00:00
created textmanager class
used to load fonts, will contain wrapper functions of sdl ttf functions
This commit is contained in:
parent
7c50c8d1fb
commit
d4374ef46d
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL3/SDL_render.h>
|
#include <SDL3/SDL_render.h>
|
||||||
#include <SDL3_mixer/SDL_mixer.h>
|
#include <SDL3_mixer/SDL_mixer.h>
|
||||||
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -33,15 +34,19 @@ public:
|
|||||||
|
|
||||||
// sound management
|
// sound management
|
||||||
void addSoundEffect(std::string id, const char* path);
|
void addSoundEffect(std::string id, const char* path);
|
||||||
|
|
||||||
void addMusic(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);
|
Mix_Music* getMusic(std::string id);
|
||||||
|
|
||||||
|
TTF_Font* getFont(std::string id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Manager* man;
|
Manager* man;
|
||||||
std::map<std::string, Mix_Chunk*> soundEffects;
|
std::map<std::string, Mix_Chunk*> soundEffects;
|
||||||
std::map<std::string, Mix_Music*> music;
|
std::map<std::string, Mix_Music*> music;
|
||||||
|
std::map<std::string, TTF_Font*> fonts;
|
||||||
};
|
};
|
||||||
|
|||||||
15
include/DialogHandler.h
Normal file
15
include/DialogHandler.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef CHICKENGAME_DIALOGHANDLER_H
|
||||||
|
#define CHICKENGAME_DIALOGHANDLER_H
|
||||||
|
|
||||||
|
class DialogHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void displayDialog();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //CHICKENGAME_DIALOGHANDLER_H
|
||||||
@ -18,6 +18,7 @@ class AssetManager;
|
|||||||
class CollisionHandler;
|
class CollisionHandler;
|
||||||
class TextureManager;
|
class TextureManager;
|
||||||
class SoundManager;
|
class SoundManager;
|
||||||
|
class TextManager;
|
||||||
class Map;
|
class Map;
|
||||||
class Game;
|
class Game;
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ public:
|
|||||||
/* static */ AssetManager* assets;
|
/* static */ AssetManager* assets;
|
||||||
/* static */ TextureManager* textureManager;
|
/* static */ TextureManager* textureManager;
|
||||||
/* static */ SoundManager* soundManager;
|
/* static */ SoundManager* soundManager;
|
||||||
|
/* static */ TextManager* textManager;
|
||||||
|
|
||||||
Manager manager;
|
Manager manager;
|
||||||
RenderManager renderManager;
|
RenderManager renderManager;
|
||||||
|
|||||||
26
include/TextManager.h
Normal file
26
include/TextManager.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef CHICKENGAME_TEXTMANAGER_H
|
||||||
|
#define CHICKENGAME_TEXTMANAGER_H
|
||||||
|
|
||||||
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
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<const char*, TTF_Font*> font_cache;
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //CHICKENGAME_TEXTMANAGER_H
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "SoundManager.h"
|
#include "SoundManager.h"
|
||||||
|
#include "TextManager.h"
|
||||||
#include "ProjectileComponent.h"
|
#include "ProjectileComponent.h"
|
||||||
#include "GameInternal.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));
|
music.emplace(id, this->man->getGame()->soundManager->loadMusic(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssetManager::addFont(std::string id, const char *path)
|
||||||
Mix_Chunk* AssetManager::getSound(std::string id) {
|
{
|
||||||
return soundEffects.at(id);
|
fonts.emplace(id, this->man->getGame()->textManager->loadFont(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
Mix_Music* AssetManager::getMusic(std::string id)
|
Mix_Music* AssetManager::getMusic(std::string id)
|
||||||
@ -41,6 +42,16 @@ Mix_Music* AssetManager::getMusic(std::string id)
|
|||||||
return music.at(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) {
|
void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, float speed, Textures textureEnum, Entity* owner) {
|
||||||
|
|
||||||
auto& projectile(man->addEntity());
|
auto& projectile(man->addEntity());
|
||||||
|
|||||||
5
src/DialogHandler.cpp
Normal file
5
src/DialogHandler.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by PC on 21.01.2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../include/DialogHandler.h"
|
||||||
23
src/TextManager.cpp
Normal file
23
src/TextManager.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "TextManager.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user