| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #include "StdInc.h"
- #include "CBattleConsole.h"
- #include "../SDL_Extensions.h"
- CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt(""), whoSetAlter(0)
- {
- }
- CBattleConsole::~CBattleConsole()
- {
- texts.clear();
- }
- void CBattleConsole::show(SDL_Surface * to)
- {
- if(ingcAlter.size())
- {
- CSDL_Ext::printAtMiddleWB(ingcAlter, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to);
- }
- else if(alterTxt.size())
- {
- CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to);
- }
- else if(texts.size())
- {
- if(texts.size()==1)
- {
- CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to);
- }
- else
- {
- CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, zwykly, to);
- CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 27, FONT_SMALL, 80, zwykly, to);
- }
- }
- }
- bool CBattleConsole::addText(const std::string & text)
- {
- if(text.size()>70)
- return false; //text too long!
- int firstInToken = 0;
- for(size_t i = 0; i < text.size(); ++i) //tokenize
- {
- if(text[i] == 10)
- {
- texts.push_back( text.substr(firstInToken, i-firstInToken) );
- firstInToken = i+1;
- }
- }
- texts.push_back( text.substr(firstInToken, text.size()) );
- lastShown = texts.size()-1;
- return true;
- }
- void CBattleConsole::eraseText(ui32 pos)
- {
- if(pos < texts.size())
- {
- texts.erase(texts.begin() + pos);
- if(lastShown == texts.size())
- --lastShown;
- }
- }
- void CBattleConsole::changeTextAt(const std::string & text, ui32 pos)
- {
- if(pos >= texts.size()) //no such pos
- return;
- texts[pos] = text;
- }
- void CBattleConsole::scrollUp(ui32 by)
- {
- if(lastShown > static_cast<int>(by))
- lastShown -= by;
- }
- void CBattleConsole::scrollDown(ui32 by)
- {
- if(lastShown + by < texts.size())
- lastShown += by;
- }
|