2007-06-12 12:33:20 +03:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "CMessage.h"
|
2008-08-02 18:08:03 +03:00
|
|
|
#include "SDL_ttf.h"
|
2008-07-01 11:01:02 +03:00
|
|
|
#include "hch/CDefHandler.h"
|
2007-07-11 15:08:42 +03:00
|
|
|
#include "CGameInfo.h"
|
2007-07-12 14:41:31 +03:00
|
|
|
#include "SDL_Extensions.h"
|
2008-07-01 11:01:02 +03:00
|
|
|
#include "hch/CLodHandler.h"
|
2007-10-13 23:31:50 +03:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "CPlayerInterface.h"
|
2008-07-01 11:01:02 +03:00
|
|
|
#include "hch/CDefHandler.h"
|
2007-10-13 23:31:50 +03:00
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "SDL_Extensions.h"
|
|
|
|
#include <sstream>
|
2007-12-27 02:11:46 +02:00
|
|
|
#include "hch/CGeneralTextHandler.h"
|
2008-06-30 03:06:41 +03:00
|
|
|
#include "client/Graphics.h"
|
2008-08-15 15:11:42 +03:00
|
|
|
#include "CAdvmapInterface.h"
|
2007-06-19 18:25:42 +03:00
|
|
|
SDL_Color tytulowy, tlo, zwykly ;
|
|
|
|
|
2008-04-25 12:25:59 +03:00
|
|
|
extern SDL_Surface * screen;
|
2007-06-19 18:25:42 +03:00
|
|
|
extern TTF_Font * TNRB16, *TNR, *GEOR13;
|
2007-07-28 12:44:10 +03:00
|
|
|
|
2007-07-29 02:01:25 +03:00
|
|
|
using namespace NMessage;
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
const int COMPONENT_TO_SUBTITLE = 5;
|
|
|
|
const int BETWEEN_COMPS_ROWS = 10;
|
|
|
|
const int BEFORE_COMPONENTS = 30;
|
|
|
|
|
2007-12-27 02:11:46 +02:00
|
|
|
template <typename T, typename U> std::pair<T,U> max(const std::pair<T,U> &x, const std::pair<T,U> &y)
|
|
|
|
{
|
|
|
|
std::pair<T,U> ret;
|
|
|
|
ret.first = std::max(x.first,y.first);
|
|
|
|
ret.second = std::max(x.second,y.second);
|
|
|
|
return ret;
|
|
|
|
}
|
2007-07-29 02:01:25 +03:00
|
|
|
|
|
|
|
namespace NMessage
|
|
|
|
{
|
2007-11-19 00:58:28 +02:00
|
|
|
CDefHandler * ok, *cancel;
|
2007-07-29 02:01:25 +03:00
|
|
|
std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
|
|
|
|
SDL_Surface * background = NULL;
|
|
|
|
}
|
2007-07-28 12:44:10 +03:00
|
|
|
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2007-07-29 02:01:25 +03:00
|
|
|
void CMessage::init()
|
2007-07-28 12:44:10 +03:00
|
|
|
{
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
|
|
|
for (int i=0;i<PLAYER_LIMIT;i++)
|
|
|
|
{
|
2008-06-12 09:45:51 +03:00
|
|
|
CDefHandler * bluePieces = CDefHandler::giveDef("DIALGBOX.DEF");
|
2007-07-29 02:01:25 +03:00
|
|
|
std::vector<SDL_Surface *> n;
|
|
|
|
piecesOfBox.push_back(n);
|
|
|
|
if (i==1)
|
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<bluePieces->ourImages.size();++j)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
|
|
|
piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
|
|
|
|
}
|
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<bluePieces->ourImages.size();++j)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
2008-06-30 03:06:41 +03:00
|
|
|
graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i);
|
2007-07-29 02:01:25 +03:00
|
|
|
piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
|
|
|
|
}
|
|
|
|
}
|
2008-06-12 09:45:51 +03:00
|
|
|
NMessage::background = BitmapHandler::loadBitmap("DIBOXBCK.BMP");
|
2007-07-29 02:01:25 +03:00
|
|
|
SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255));
|
|
|
|
}
|
2008-06-12 09:45:51 +03:00
|
|
|
ok = CDefHandler::giveDef("IOKAY.DEF");
|
|
|
|
cancel = CDefHandler::giveDef("ICANCEL.DEF");
|
2007-07-29 02:01:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMessage::dispose()
|
|
|
|
{
|
|
|
|
for (int i=0;i<PLAYER_LIMIT;i++)
|
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0; j<piecesOfBox[i].size(); ++j)
|
2007-07-29 02:01:25 +03:00
|
|
|
{
|
|
|
|
SDL_FreeSurface(piecesOfBox[i][j]);
|
|
|
|
}
|
|
|
|
}
|
2007-07-28 12:44:10 +03:00
|
|
|
SDL_FreeSurface(background);
|
2007-11-19 00:58:28 +02:00
|
|
|
delete ok;
|
|
|
|
delete cancel;
|
2007-07-28 12:44:10 +03:00
|
|
|
}
|
2008-08-15 15:11:42 +03:00
|
|
|
SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for window
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
|
|
|
//prepare surface
|
2008-04-25 12:25:59 +03:00
|
|
|
SDL_Surface * ret = SDL_CreateRGBSurface(screen->flags, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
|
2007-06-12 12:33:20 +03:00
|
|
|
for (int i=0; i<h; i+=background->h)//background
|
|
|
|
{
|
2008-12-23 15:59:03 +02:00
|
|
|
for (int j=0; j<w; j+=background->w-1)
|
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i)); //FIXME taking address of temporary
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
2007-07-12 14:41:31 +03:00
|
|
|
}
|
2008-12-08 00:38:04 +02:00
|
|
|
drawBorder(playerColor, ret, w, h);
|
2007-06-12 12:33:20 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:17:35 +02:00
|
|
|
std::vector<std::string> * CMessage::breakText(std::string text, size_t line, bool userBreak, bool ifor) //TODO userBreak -- use me
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
|
|
|
std::vector<std::string> * ret = new std::vector<std::string>();
|
2007-06-28 13:47:28 +03:00
|
|
|
while (text.length()>line)
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
2007-10-13 23:31:50 +03:00
|
|
|
int whereCut = -1, braces=0;
|
|
|
|
bool pom = true, opened=false;
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i<line+braces; i++)
|
2007-07-28 12:44:10 +03:00
|
|
|
{
|
|
|
|
if (text[i]==10) //end of line sign
|
|
|
|
{
|
|
|
|
whereCut=i+1;
|
|
|
|
pom=false;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
else if (ifor && ((text[i]=='{') || (text[i]=='}'))) // ignore braces
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
|
|
|
if (text[i]=='{')
|
|
|
|
opened=true;
|
2008-08-02 18:08:03 +03:00
|
|
|
else
|
2007-10-13 23:31:50 +03:00
|
|
|
opened=false;
|
|
|
|
braces++;
|
|
|
|
}
|
2007-07-28 12:44:10 +03:00
|
|
|
}
|
2007-10-13 23:31:50 +03:00
|
|
|
for (int i=line+braces; i>0&&pom; i--)
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
|
|
|
if (text[i]==' ')
|
|
|
|
{
|
|
|
|
whereCut = i;
|
|
|
|
break;
|
|
|
|
}
|
2007-10-13 23:31:50 +03:00
|
|
|
else if (opened && text[i]=='{')
|
|
|
|
opened = false;
|
|
|
|
else if (text[i]=='}')
|
|
|
|
opened = true;
|
2007-06-12 12:33:20 +03:00
|
|
|
}
|
|
|
|
ret->push_back(text.substr(0,whereCut));
|
|
|
|
text.erase(0,whereCut);
|
2007-10-13 23:31:50 +03:00
|
|
|
boost::algorithm::trim_left_if(text,boost::algorithm::is_any_of(" "));
|
|
|
|
if (opened)
|
|
|
|
{
|
|
|
|
(*(ret->end()-1))+='}';
|
|
|
|
text.insert(0,"{");
|
|
|
|
}
|
2007-06-12 12:33:20 +03:00
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0;i<text.length();i++)
|
2008-08-02 18:08:03 +03:00
|
|
|
{
|
2007-07-28 12:44:10 +03:00
|
|
|
if (text[i]==10) //end of line sign
|
|
|
|
{
|
|
|
|
ret->push_back(text.substr(0,i));
|
|
|
|
text.erase(0,i);
|
|
|
|
i=0;
|
|
|
|
}
|
|
|
|
}
|
2007-06-12 12:33:20 +03:00
|
|
|
if (text.length() > 0)
|
|
|
|
ret->push_back(text);
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i<ret->size(); i++)
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
|
|
|
boost::algorithm::trim((*ret)[i]);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2007-12-27 02:11:46 +02:00
|
|
|
|
2007-11-19 00:58:28 +02:00
|
|
|
std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg)
|
|
|
|
{
|
2008-08-02 18:08:03 +03:00
|
|
|
std::pair<int,int> ret;
|
2007-11-19 00:58:28 +02:00
|
|
|
ret.first = -1;
|
|
|
|
ret.second=0;
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i<txtg->size();i++) //szukamy najszerszej linii i lacznej wysokosci
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
|
|
|
int lw=0;
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<(*txtg)[i].size();j++)
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
|
|
|
lw+=(*txtg)[i][j]->w;
|
|
|
|
ret.second+=(*txtg)[i][j]->h;
|
|
|
|
}
|
2008-08-20 22:02:48 +03:00
|
|
|
if(!(*txtg)[i].size())
|
|
|
|
ret.second+=19;
|
2007-11-19 00:58:28 +02:00
|
|
|
if (ret.first<lw)
|
|
|
|
ret.first=lw;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2009-03-27 01:05:40 +02:00
|
|
|
SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret, int xCenterPos)
|
2007-12-01 14:50:33 +02:00
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i<txtg->size();i++)
|
2007-12-01 14:50:33 +02:00
|
|
|
{
|
2009-03-27 01:05:40 +02:00
|
|
|
int lw=0; //line width
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<(*txtg)[i].size();j++)
|
2009-03-27 01:05:40 +02:00
|
|
|
lw+=(*txtg)[i][j]->w;
|
|
|
|
|
|
|
|
int pw = (xCenterPos < 0) ? ret->w/2 : xCenterPos;
|
|
|
|
pw -= lw/2; //x coord for the start of the text
|
2007-10-13 23:31:50 +03:00
|
|
|
|
2007-12-01 14:50:33 +02:00
|
|
|
int tw = pw;
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0;j<(*txtg)[i].size();j++) //blit text
|
2008-08-02 18:08:03 +03:00
|
|
|
{
|
2007-12-01 14:50:33 +02:00
|
|
|
blitAt((*txtg)[i][j],tw,curh+i*19,ret);
|
|
|
|
tw+=(*txtg)[i][j]->w;
|
|
|
|
SDL_FreeSurface((*txtg)[i][j]);
|
2009-03-27 01:05:40 +02:00
|
|
|
(*txtg)[i][j] = NULL;
|
2007-12-01 14:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
2007-12-27 02:11:46 +02:00
|
|
|
curh+=txtg->size()*19;
|
2007-12-01 14:50:33 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2009-03-27 01:05:40 +02:00
|
|
|
std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext, TTF_Font *font)
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
2009-03-27 01:05:40 +02:00
|
|
|
if(!font) font = TNRB16;
|
2007-11-19 00:58:28 +02:00
|
|
|
std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
|
|
|
|
txtg->resize(brtext->size());
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i<brtext->size();i++) //foreach line
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
|
|
|
while((*brtext)[i].length()) //jesli zostalo cos
|
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
size_t z=0; bool br=true;
|
2007-10-13 23:31:50 +03:00
|
|
|
while( ((*brtext)[i][z]) != ('{') )
|
|
|
|
{
|
|
|
|
if (z >= (((*brtext)[i].length())-1))
|
|
|
|
{
|
|
|
|
br=false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
z++;
|
|
|
|
}
|
|
|
|
if (!br)
|
|
|
|
z++;
|
|
|
|
if (z)
|
2009-03-27 01:05:40 +02:00
|
|
|
(*txtg)[i].push_back(TTF_RenderText_Blended(font,(*brtext)[i].substr(0,z).c_str(),zwykly));
|
2007-10-13 23:31:50 +03:00
|
|
|
(*brtext)[i].erase(0,z);
|
|
|
|
z=0;
|
|
|
|
if ( ((*brtext)[i].length()==0) || ((*brtext)[i][z]!='{') )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while( ((*brtext)[i][++z]) != ('}') )
|
|
|
|
{}
|
|
|
|
//tyemp = (*brtext)[i].substr(1,z-1); //od 1 bo pomijamy otwierajaca klamre
|
2009-03-27 01:05:40 +02:00
|
|
|
(*txtg)[i].push_back(TTF_RenderText_Blended(font,(*brtext)[i].substr(1,z-1).c_str(),tytulowy));
|
2007-10-13 23:31:50 +03:00
|
|
|
(*brtext)[i].erase(0,z+1); //z+1 bo dajemy zamykajaca klamre
|
|
|
|
} //ends while((*brtext)[i].length())
|
2008-08-02 18:08:03 +03:00
|
|
|
} //ends for(int i=0; i<brtext->size();i++)
|
2007-11-19 00:58:28 +02:00
|
|
|
return txtg;
|
|
|
|
}
|
|
|
|
CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar)
|
|
|
|
{
|
|
|
|
CSimpleWindow * ret = new CSimpleWindow();
|
|
|
|
std::vector<std::string> * brtext = breakText(text,32,true,true);
|
|
|
|
std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
|
|
|
|
std::pair<int,int> txts = getMaxSizes(txtg);
|
2008-08-02 18:08:03 +03:00
|
|
|
ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,0);
|
2007-10-13 23:31:50 +03:00
|
|
|
ret->pos.h=ret->bitmap->h;
|
|
|
|
ret->pos.w=ret->bitmap->w;
|
2008-08-15 15:11:42 +03:00
|
|
|
int curh = ret->bitmap->h/2 - (19*txtg->size())/2;
|
2007-12-01 14:50:33 +02:00
|
|
|
blitTextOnSur(txtg,curh,ret->bitmap);
|
2008-08-15 15:11:42 +03:00
|
|
|
delete brtext;
|
|
|
|
delete txtg;
|
2007-12-27 02:11:46 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2008-08-20 22:02:48 +03:00
|
|
|
SDL_Surface * CMessage::drawBoxTextBitmapSub( int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline/*=30*/, int imgToBmp/*=55*/ )
|
2008-03-06 20:54:35 +02:00
|
|
|
{
|
|
|
|
int curh;
|
|
|
|
std::vector<std::string> * tekst = breakText(text,charperline);
|
|
|
|
std::vector<std::vector<SDL_Surface*> > * txtg = drawText(tekst);
|
|
|
|
std::pair<int,int> txts = getMaxSizes(txtg), boxs;
|
|
|
|
boxs.first = std::max(txts.first,bitmap->w) // text/bitmap max width
|
|
|
|
+ 50; //side margins
|
2008-08-02 18:08:03 +03:00
|
|
|
boxs.second =
|
2008-03-06 20:54:35 +02:00
|
|
|
(curh=45) //top margin
|
|
|
|
+ txts.second //text total height
|
2008-08-20 22:02:48 +03:00
|
|
|
+ imgToBmp //text <=> img
|
2008-03-06 20:54:35 +02:00
|
|
|
+ bitmap->h
|
|
|
|
+ 5 // to sibtitle
|
|
|
|
+ (*txtg)[0][0]->h
|
|
|
|
+ 30;
|
|
|
|
SDL_Surface *ret = drawBox1(boxs.first,boxs.second,player);
|
|
|
|
blitTextOnSur(txtg,curh,ret);
|
2008-08-20 22:02:48 +03:00
|
|
|
curh += imgToBmp;
|
2008-03-06 20:54:35 +02:00
|
|
|
blitAt(bitmap,(ret->w/2)-(bitmap->w/2),curh,ret);
|
|
|
|
curh += bitmap->h + 5;
|
|
|
|
CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+( ((*txtg)[0][0]->h) / 2 ),GEOR13,zwykly,ret);
|
2008-08-20 22:02:48 +03:00
|
|
|
delete tekst;
|
|
|
|
delete txtg;
|
2008-03-06 20:54:35 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline)
|
2007-12-27 02:11:46 +02:00
|
|
|
{
|
2009-03-27 01:05:40 +02:00
|
|
|
SDL_Surface * _or = NULL;
|
|
|
|
if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
|
|
|
|
_or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
|
|
|
|
|
|
|
|
std::vector<std::string> * brtext = breakText(text,charperline,true,true); //text
|
2008-08-15 15:11:42 +03:00
|
|
|
std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
|
2007-12-27 02:11:46 +02:00
|
|
|
std::pair<int,int> txts = getMaxSizes(txtg);
|
2009-03-27 01:05:40 +02:00
|
|
|
|
|
|
|
ComponentsToBlit comps(ret->components,500,_or);
|
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
if(ret->buttons.size())
|
|
|
|
txts.second += 20 + //before button
|
|
|
|
ok->ourImages[0].bitmap->h; //button
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
if (ret->components.size())
|
2009-03-27 01:05:40 +02:00
|
|
|
{
|
|
|
|
txts.second += 30 + comps.h; //space to first component
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
amax(txts.first,comps.w);
|
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
ret->bitmap = drawBox1(txts.first+70,txts.second+70,0);
|
|
|
|
ret->pos.h=ret->bitmap->h;
|
|
|
|
ret->pos.w=ret->bitmap->w;
|
2008-11-09 00:29:19 +02:00
|
|
|
ret->pos.x=screen->w/2-(ret->pos.w/2);
|
|
|
|
ret->pos.y=screen->h/2-(ret->pos.h/2);
|
2008-08-15 15:11:42 +03:00
|
|
|
int curh = 30; //gorny margines
|
2007-12-27 02:11:46 +02:00
|
|
|
blitTextOnSur(txtg,curh,ret->bitmap);
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2008-08-15 15:11:42 +03:00
|
|
|
if (ret->components.size())
|
|
|
|
{
|
2009-03-27 01:05:40 +02:00
|
|
|
curh += BEFORE_COMPONENTS;
|
|
|
|
comps.blitCompsOnSur(_or, 10, curh, ret->bitmap);
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
|
|
|
if(ret->buttons.size())
|
|
|
|
{
|
|
|
|
curh += 20; //to buttton
|
|
|
|
int bw = 20*(ret->buttons.size()-1); //total width of buttons - start with distance between them
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t i=0; i<ret->buttons.size(); i++) //and add buttons width
|
2008-08-15 15:11:42 +03:00
|
|
|
bw+=ret->buttons[i]->imgs[0][0]->w;
|
|
|
|
bw = (ret->bitmap->w/2) - (bw/2);
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t i=0; i<ret->buttons.size(); i++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
ret->buttons[i]->pos.x = bw + ret->pos.x;
|
|
|
|
ret->buttons[i]->pos.y = curh + ret->pos.y;
|
|
|
|
bw += ret->buttons[i]->imgs[0][0]->w + 20;
|
|
|
|
}
|
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t i=0; i<ret->components.size(); i++)
|
2008-08-15 15:11:42 +03:00
|
|
|
{
|
|
|
|
ret->components[i]->pos.x += ret->pos.x;
|
|
|
|
ret->components[i]->pos.y += ret->pos.y;
|
|
|
|
}
|
|
|
|
delete brtext;
|
|
|
|
delete txtg;
|
2009-03-27 01:05:40 +02:00
|
|
|
if(_or)
|
|
|
|
SDL_FreeSurface(_or);
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
2007-10-13 23:31:50 +03:00
|
|
|
|
2007-06-13 17:02:43 +03:00
|
|
|
SDL_Surface * CMessage::genMessage
|
2007-07-11 15:08:42 +03:00
|
|
|
(std::string title, std::string text, EWindowType type, std::vector<CDefHandler*> *addPics, void * cb)
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
|
|
|
//max x 320 okolo 30 znakow
|
|
|
|
std::vector<std::string> * tekst;
|
|
|
|
if (text.length() < 30) //nie trzeba polamac
|
|
|
|
{
|
|
|
|
tekst = new std::vector<std::string>();
|
|
|
|
tekst->push_back(text);
|
|
|
|
}
|
|
|
|
else tekst = breakText(text);
|
|
|
|
int ww, hh; //wymiary boksa
|
2007-06-13 17:02:43 +03:00
|
|
|
if (319>30+13*text.length())
|
|
|
|
ww = 30+13*text.length();
|
2007-06-12 12:33:20 +03:00
|
|
|
else ww = 319;
|
|
|
|
if (title.length())
|
2007-06-13 17:02:43 +03:00
|
|
|
hh=110+(21*tekst->size());
|
|
|
|
else hh=60+(21*tekst->size());
|
2008-04-11 20:41:02 +03:00
|
|
|
if (type==yesOrNO) //make place for buttons
|
2007-06-13 17:02:43 +03:00
|
|
|
{
|
2008-08-02 18:08:03 +03:00
|
|
|
if (ww<200) ww=200;
|
2007-06-13 17:02:43 +03:00
|
|
|
hh+=70;
|
|
|
|
}
|
2007-06-12 12:33:20 +03:00
|
|
|
|
2007-07-28 12:44:10 +03:00
|
|
|
SDL_Surface * ret = drawBox1(ww,hh,0);
|
2007-06-12 12:33:20 +03:00
|
|
|
//prepare title text
|
2008-08-02 18:08:03 +03:00
|
|
|
|
2007-06-14 16:13:04 +03:00
|
|
|
if (title.length())
|
|
|
|
{
|
2008-08-02 18:08:03 +03:00
|
|
|
SDL_Surface * titleText = TTF_RenderText_Blended(TNRB16,title.c_str(),tytulowy);
|
2007-06-19 18:25:42 +03:00
|
|
|
|
2007-06-14 16:13:04 +03:00
|
|
|
//draw title
|
|
|
|
SDL_Rect tytul = genRect(titleText->h,titleText->w,((ret->w/2)-(titleText->w/2)),37);
|
|
|
|
SDL_BlitSurface(titleText,NULL,ret,&tytul);
|
|
|
|
SDL_FreeSurface(titleText);
|
|
|
|
}
|
2007-06-12 12:33:20 +03:00
|
|
|
//draw text
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i<tekst->size(); i++)
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
2007-06-14 16:13:04 +03:00
|
|
|
int by = 37+i*21;
|
|
|
|
if (title.length()) by+=40;
|
2007-06-19 18:25:42 +03:00
|
|
|
SDL_Surface * tresc = TTF_RenderText_Blended(TNRB16,(*tekst)[i].c_str(),zwykly);
|
2007-06-14 16:13:04 +03:00
|
|
|
SDL_Rect trescRect = genRect(tresc->h,tresc->w,((ret->w/2)-(tresc->w/2)),by);
|
2007-06-12 12:33:20 +03:00
|
|
|
SDL_BlitSurface(tresc,NULL,ret,&trescRect);
|
|
|
|
SDL_FreeSurface(tresc);
|
|
|
|
}
|
2008-04-11 20:41:02 +03:00
|
|
|
if (type==yesOrNO) // add buttons
|
2007-06-13 17:02:43 +03:00
|
|
|
{
|
2007-06-14 16:13:04 +03:00
|
|
|
int by = 77+tekst->size()*21;
|
|
|
|
if (title.length()) by+=40;
|
2007-06-13 17:02:43 +03:00
|
|
|
int hwo = (*addPics)[0]->ourImages[0].bitmap->w, hwc=(*addPics)[0]->ourImages[0].bitmap->w;
|
|
|
|
//ok
|
|
|
|
SDL_Rect trescRect = genRect((*addPics)[0]->ourImages[0].bitmap->h,hwo,((ret->w/2)-hwo-10),by);
|
|
|
|
SDL_BlitSurface((*addPics)[0]->ourImages[0].bitmap,NULL,ret,&trescRect);
|
|
|
|
((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
|
|
|
|
//cancel
|
|
|
|
trescRect = genRect((*addPics)[1]->ourImages[0].bitmap->h,hwc,((ret->w/2)+10),by);
|
|
|
|
SDL_BlitSurface((*addPics)[1]->ourImages[0].bitmap,NULL,ret,&trescRect);
|
|
|
|
((std::vector<SDL_Rect>*)(cb))->push_back(trescRect);
|
|
|
|
}
|
2007-06-12 12:33:20 +03:00
|
|
|
delete tekst;
|
|
|
|
return ret;
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2008-12-08 00:38:04 +02:00
|
|
|
|
|
|
|
void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x, int y)
|
|
|
|
{
|
|
|
|
//obwodka I-szego rzedu pozioma
|
|
|
|
for (int i=0; i<w-piecesOfBox[playerColor][6]->w; i+=piecesOfBox[playerColor][6]->w)
|
|
|
|
{
|
|
|
|
SDL_BlitSurface
|
|
|
|
(piecesOfBox[playerColor][6],NULL,ret,&genRect(piecesOfBox[playerColor][6]->h,piecesOfBox[playerColor][6]->w,x+i,y+0));
|
|
|
|
SDL_BlitSurface
|
|
|
|
(piecesOfBox[playerColor][7],NULL,ret,&genRect(piecesOfBox[playerColor][7]->h,piecesOfBox[playerColor][7]->w,x+i,y+h-piecesOfBox[playerColor][7]->h));
|
|
|
|
}
|
|
|
|
//obwodka I-szego rzedu pionowa
|
|
|
|
for (int i=0; i<h-piecesOfBox[playerColor][4]->h; i+=piecesOfBox[playerColor][4]->h)
|
|
|
|
{
|
|
|
|
SDL_BlitSurface
|
|
|
|
(piecesOfBox[playerColor][4],NULL,ret,&genRect(piecesOfBox[playerColor][4]->h,piecesOfBox[playerColor][4]->w,x+0,y+i));
|
|
|
|
SDL_BlitSurface
|
|
|
|
(piecesOfBox[playerColor][5],NULL,ret,&genRect(piecesOfBox[playerColor][5]->h,piecesOfBox[playerColor][5]->w,x+w-piecesOfBox[playerColor][5]->w,y+i));
|
|
|
|
}
|
|
|
|
//corners
|
|
|
|
SDL_BlitSurface
|
|
|
|
(piecesOfBox[playerColor][0],NULL,ret,&genRect(piecesOfBox[playerColor][0]->h,piecesOfBox[playerColor][0]->w,x+0,y+0));
|
|
|
|
SDL_BlitSurface
|
|
|
|
(piecesOfBox[playerColor][1],NULL,ret,&genRect(piecesOfBox[playerColor][1]->h,piecesOfBox[playerColor][1]->w,x+w-piecesOfBox[playerColor][1]->w,y+0));
|
|
|
|
SDL_BlitSurface
|
|
|
|
(piecesOfBox[playerColor][2],NULL,ret,&genRect(piecesOfBox[playerColor][2]->h,piecesOfBox[playerColor][2]->w,x+0,y+h-piecesOfBox[playerColor][2]->h));
|
|
|
|
SDL_BlitSurface
|
|
|
|
(piecesOfBox[playerColor][3],NULL,ret,&genRect(piecesOfBox[playerColor][3]->h,piecesOfBox[playerColor][3]->w,x+w-piecesOfBox[playerColor][3]->w,y+h-piecesOfBox[playerColor][3]->h));
|
2009-03-27 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ComponentResolved::ComponentResolved()
|
|
|
|
{
|
|
|
|
comp = NULL;
|
|
|
|
img = NULL;
|
|
|
|
txt = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ComponentResolved::ComponentResolved( SComponent *Comp )
|
|
|
|
{
|
|
|
|
comp = Comp;
|
|
|
|
img = comp->getImg();
|
|
|
|
std::vector<std::string> * brtext = CMessage::breakText(comp->subtitle,11,true,true); //text
|
|
|
|
txt = CMessage::drawText(brtext,GEOR13);
|
|
|
|
delete brtext;
|
|
|
|
comp->pos.w = img->w;
|
|
|
|
comp->pos.h = img->h + COMPONENT_TO_SUBTITLE + CMessage::getMaxSizes(txt).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
ComponentResolved::~ComponentResolved()
|
|
|
|
{
|
|
|
|
for(size_t i = 0; i < txt->size(); i++)
|
|
|
|
for(size_t j = 0; j < (*txt)[i].size(); j++)
|
|
|
|
if((*txt)[i][j])
|
|
|
|
SDL_FreeSurface((*txt)[i][j]);
|
|
|
|
delete txt;
|
|
|
|
}
|
|
|
|
|
|
|
|
ComponentsToBlit::~ComponentsToBlit()
|
|
|
|
{
|
|
|
|
for(size_t i=0; i<comps.size(); i++)
|
|
|
|
for(size_t j = 0; j < comps[i].size(); j++)
|
|
|
|
delete comps[i][j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ComponentsToBlit::ComponentsToBlit(std::vector<SComponent*> & SComps, int maxw, SDL_Surface* _or)
|
|
|
|
{
|
|
|
|
w = h = 0;
|
|
|
|
if(!SComps.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
comps.resize(1);
|
|
|
|
int curw = 0;
|
|
|
|
int curr = 0;
|
|
|
|
|
|
|
|
for(size_t i=0;i<SComps.size();i++)
|
|
|
|
{
|
|
|
|
int toadd = (SComps[i]->getImg()->w + 12 + (_or ? _or->w : 0));
|
|
|
|
if (curw + toadd > maxw)
|
|
|
|
{
|
|
|
|
amax(w,curw);
|
|
|
|
curw = SComps[i]->getImg()->w;
|
|
|
|
comps.resize(curr+1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curw += toadd;
|
|
|
|
}
|
|
|
|
|
|
|
|
comps[curr].push_back(new ComponentResolved(SComps[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i=0;i<comps.size();i++)
|
|
|
|
{
|
|
|
|
int maxh = 0;
|
|
|
|
for(size_t j=0;j<comps.size();j++)
|
|
|
|
amax(maxh,comps[i][j]->comp->pos.h);
|
|
|
|
h += maxh + BETWEEN_COMPS_ROWS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret )
|
|
|
|
{
|
|
|
|
for (size_t i=0;i<comps.size();i++)
|
|
|
|
{
|
|
|
|
int totalw=0, maxh=0;
|
|
|
|
for(size_t j=0;j<(comps)[i].size();j++)
|
|
|
|
{
|
|
|
|
ComponentResolved *cur = (comps)[i][j];
|
|
|
|
totalw += cur->comp->pos.w;
|
|
|
|
amax(maxh,cur->comp->pos.h);
|
|
|
|
}
|
|
|
|
if(_or)
|
|
|
|
{
|
|
|
|
totalw += (inter*2+_or->w) * ((comps)[i].size() - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
totalw += (inter) * ((comps)[i].size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
curh+=maxh/2;
|
|
|
|
int curw = (ret->w/2)-(totalw/2);
|
|
|
|
for(size_t j=0;j<(comps)[i].size();j++)
|
|
|
|
{
|
|
|
|
ComponentResolved *cur = (comps)[i][j];
|
|
|
|
|
|
|
|
//blit img
|
|
|
|
int hlp = curh-(cur->comp->pos.h)/2;
|
|
|
|
blitAt(cur->img,curw,hlp,ret);
|
|
|
|
cur->comp->pos.x = curw;
|
|
|
|
cur->comp->pos.y = hlp;
|
|
|
|
|
|
|
|
//blit subtitle
|
|
|
|
hlp += cur->img->h + COMPONENT_TO_SUBTITLE;
|
|
|
|
CMessage::blitTextOnSur(cur->txt, hlp, ret, cur->comp->pos.x + cur->comp->pos.w/2 );
|
|
|
|
|
|
|
|
//if there is subsequent component blit "or"
|
|
|
|
curw += cur->img->w;
|
|
|
|
if(j<((comps)[i].size()-1))
|
|
|
|
{
|
|
|
|
if(_or)
|
|
|
|
{
|
|
|
|
curw+=inter;
|
|
|
|
blitAt(_or,curw,curh-(_or->h/2),ret);
|
|
|
|
curw+=_or->w;
|
|
|
|
}
|
|
|
|
curw+=inter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curh+=maxh/2;
|
|
|
|
}
|
2008-12-08 00:38:04 +02:00
|
|
|
}
|