#pragma once

#include "GameCore.h"
#include <stdlib.h>
#include <map>
#include <list>
#include "Text.h"
#include "TextImage.h"
#include "SpriteRenderer.h"

using namespace std;

typedef map<int,TextImage*> TextMap;

class TextManager{
public:
    TextManager(void);
    ~TextManager(void);

    // initialize
    void init(SpriteRenderer* spriteRenderer);

    // render all text
    void render();

    // Load the alphabet image into memory and figure out the dimensions to use.
    //    The alphabet is stored in a sprite.
    HRESULT loadAlphabet( int textureId, int alphabetWidth, int alphabetHeight, int lettersPerRow, int letterWidth, int letterHeight );
    
    // return dimensions of given string
    int getStringWidth(char* string, int textId);
    int getStringWidth(char* string, int textId, float scaleX);
    int getStringHeight(char* string, int textId);
    int getStringHeight(char* string, int textId, float scaleY);

    // add string to be printed to the screen
	Text* addString( int x, int y, char* string, int textureId, int lifeTime, Text::TEXT_COORDINATES textCoords );
    Text* addString( int x, int y, char* string, int textureId, int lifeTime, float scale, Text::TEXT_COORDINATES textCoords );
    Text* addString( int x, int y, char* string, int textureId, int lifeTime, float scaleX, float scaleY, Text::TEXT_COORDINATES textCoords );
    Text* addString( int x, int y, char* string, int textureId, int lifeTime, Text::TEXT_COORDINATES textCoords, Text::TEXT_EFFECT effect);
    // remove string from being printed to the screen
    void removeString(Text* string);
    // make a string fit in a specified width by inserting new lines
    void makeStringFitInWidth(Text* string, int width);

    void tick();

private:
    // Print a character to the screen
    // PARAMETERS:
    //      x            ->  Takes the X-coordinate for where you want the letter to end up
    //      y            ->  Takes the Y-coordinate for where you want the letter to end up
    //      Character    ->  The character you want to display
    //      image        ->  The text image you want to use
	void printChar( int x, int y, char character, int textureId, Text::TEXT_COORDINATES textCoords );

    SpriteRenderer*         spriteRenderer; // used to render sprites
    TextMap                 textMap; // map of TextImage - font information
    list<Text*>           strings; // vector of strings to be rendered
};

