#ifndef OUTPUTMANAGER
#define OUTPUTMANAGER

#include <windows.h>
#include <stdarg.h>
#include <time.h>
#include <string>
#include <d3dx9.h>
#include <iostream>
#include <vector>
#include "resource.h"

// Enum to define different output types.
typedef enum _OUTPUT_TYPE {

		OUTPUT_INVALID				= -1, // Invalid output.
		OUTPUT_NORMAL				= 0, // Normal output.
		OUTPUT_ERROR				= 1, // Error message.
		OUTPUT_GOOD					= 2, // Success message.
		OUTPUT_INFO					= 3 // Information.

} OUTPUT_TYPE;

// Structure to define HUD message output.
typedef struct {

		BOOL						IsStatic; // If the message should not be removed.
		std::string					Message; // The message text.
		D3DXCOLOR					Color; // The text color.
		INT							Spawned; // When the message spawned.
		INT							FadeIn; // The fade in speed.
		INT							FadeOut; // The fade out speed.

} HUDMessage;

// Reference required for internal font loading.
extern "C" IMAGE_DOS_HEADER __ImageBase;

class OutputManager
{
	public:
		OutputManager();
		~OutputManager();

		VOID						Init(IDirect3DDevice9 *device); // Initialise the output component.
		VOID						Release(); // Release all objects.

		VOID						Write(OUTPUT_TYPE type, char* outputContent, ...); // Write a line of output.
		VOID						NewLine(); // Write a new line.
		VOID						WriteError(DWORD, TCHAR*); // Write an error message.
		VOID						Clear(); // Clear the output.

		VOID						DrawConsole(); // Draw the console.
		VOID						DrawHUD(); // Draw the HUD.

		VOID						ToHUD(std::string hudText); // Write a message to the HUD.
		VOID						ToHUD(std::string hudText, bool isStatic); // Write a static message to the HUD.

		VOID						SetHUDColor(D3DXCOLOR color); // Sets the HUD color.

		BOOL						Show; // If the output is visible.
	private:

		ID3DXFont*					ConsoleFont; // The console font.
		ID3DXFont*					HUDFont; // The HUD font.
		HANDLE						ConsoleFontHandle; // Handle to the console font.
		HANDLE						HUDFontHandle; // Handle to the HUD font.

		D3DVIEWPORT9				Viewport; // The device viewport.

		std::string					GetTimestamp(); // Get the timestamp prefix.

		std::vector<std::string>	ConsoleLines; // The list of console lines.
		std::vector<HUDMessage>		HUDLines; // The list of HUD lines.
		RECT						DrawRectangle; // The text draw rectangle.

		HANDLE						CreateFont(int id); // Creates a font from a resource ID.

		BOOL						ShowTimestamp; // If the console should show a timestamp prefix.
		int							MaxLines; // Tha maximum lines to render.
		int							ConsoleFontSize; // The size of the console font.

		OUTPUT_TYPE					Type(std::string str); // Determines the output type from a console message.

		D3DXCOLOR					HUDColor; // The HUD text color.
};
#endif 
