2008-09-17 13:18:22 +03:00
|
|
|
#define VCMI_DLL
|
2007-08-15 18:13:11 +03:00
|
|
|
#include "stdafx.h"
|
2007-08-17 20:42:21 +03:00
|
|
|
#include "CConsoleHandler.h"
|
|
|
|
#include "CAdvmapInterface.h"
|
2008-08-22 15:21:09 +03:00
|
|
|
#include "CCastleInterface.h"
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "CPlayerInterface.h"
|
2007-08-17 20:42:21 +03:00
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "global.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CGameState.h"
|
|
|
|
#include "CCallback.h"
|
2007-09-18 16:30:26 +03:00
|
|
|
#include "CPathfinder.h"
|
|
|
|
#include "mapHandler.h"
|
2007-08-17 20:42:21 +03:00
|
|
|
#include <sstream>
|
2007-10-17 01:39:11 +03:00
|
|
|
#include "SDL_Extensions.h"
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "hch/CHeroHandler.h"
|
2008-02-26 01:26:50 +02:00
|
|
|
#include "hch/CLodHandler.h"
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2008-09-17 13:18:22 +03:00
|
|
|
#include "boost/function.hpp"
|
|
|
|
#include <boost/thread.hpp>
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <windows.h>
|
|
|
|
HANDLE handleIn;
|
|
|
|
HANDLE handleOut;
|
|
|
|
WORD defColor;
|
2008-06-21 16:27:52 +03:00
|
|
|
#endif
|
|
|
|
|
2008-09-17 13:18:22 +03:00
|
|
|
void CConsoleHandler::setColor(int level)
|
|
|
|
{
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
WORD color;
|
|
|
|
switch(level)
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
color = defColor;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
color = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
color = FOREGROUND_RED | FOREGROUND_INTENSITY;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
color = defColor;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SetConsoleTextAttribute(handleOut,color);
|
|
|
|
#endif
|
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
|
2008-09-17 13:18:22 +03:00
|
|
|
int CConsoleHandler::run()
|
2007-08-15 18:13:11 +03:00
|
|
|
{
|
2008-09-17 13:18:22 +03:00
|
|
|
char buffer[500];
|
2007-08-15 18:13:11 +03:00
|
|
|
std::string readed;
|
|
|
|
while(true)
|
|
|
|
{
|
2008-09-17 13:18:22 +03:00
|
|
|
std::cin.getline(buffer, 500);
|
|
|
|
if(cb && *cb)
|
|
|
|
(*cb)(buffer);
|
2007-08-15 18:13:11 +03:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2008-09-17 13:18:22 +03:00
|
|
|
CConsoleHandler::CConsoleHandler()
|
2007-08-15 18:13:11 +03:00
|
|
|
{
|
2008-09-17 13:18:22 +03:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
handleIn = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
handleOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
GetConsoleScreenBufferInfo(handleOut,&csbi);
|
|
|
|
defColor = csbi.wAttributes;
|
|
|
|
#endif
|
|
|
|
cb = new boost::function<void(const std::string &)>;
|
2007-08-15 18:13:11 +03:00
|
|
|
}
|
2008-09-17 13:18:22 +03:00
|
|
|
CConsoleHandler::~CConsoleHandler()
|
|
|
|
{
|
|
|
|
delete cb;
|
|
|
|
}
|
|
|
|
void CConsoleHandler::killConsole(void *hThread)
|
|
|
|
{
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
log3 << "Killing console... ";
|
|
|
|
TerminateThread(hThread,0);
|
|
|
|
log3 << "done!\n";
|
|
|
|
#endif
|
|
|
|
}
|