2007-06-12 12:33:20 +03:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "CMessage.h"
|
|
|
|
#include "SDL_TTF.h"
|
2007-08-30 13:11:53 +03:00
|
|
|
#include "hch\CSemiDefHandler.h"
|
|
|
|
#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"
|
2007-08-30 13:11:53 +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"
|
2007-10-13 23:31:50 +03:00
|
|
|
#include "hch\CDefHandler.h"
|
|
|
|
#include "hch\CSemiDefHandler.h"
|
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "SDL_Extensions.h"
|
|
|
|
#include <sstream>
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "CLua.h"
|
2007-12-27 02:11:46 +02:00
|
|
|
#include "hch/CGeneralTextHandler.h"
|
2007-06-19 18:25:42 +03:00
|
|
|
SDL_Color tytulowy, tlo, zwykly ;
|
2007-06-12 12:33:20 +03:00
|
|
|
SDL_Rect genRect(int hh, int ww, int xx, int yy);
|
2007-06-19 18:25:42 +03:00
|
|
|
|
|
|
|
extern SDL_Surface * ekran;
|
|
|
|
extern TTF_Font * TNRB16, *TNR, *GEOR13;
|
|
|
|
SDL_Color genRGB(int r, int g, int b, int a=0);
|
2007-07-07 19:04:15 +03:00
|
|
|
//void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2);
|
2007-06-19 18:25:42 +03:00
|
|
|
bool isItIn(const SDL_Rect * rect, int x, int y);
|
2007-07-28 12:44:10 +03:00
|
|
|
|
2007-07-29 02:01:25 +03:00
|
|
|
using namespace NMessage;
|
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
|
|
|
|
2007-06-12 12:33:20 +03:00
|
|
|
CMessage::CMessage()
|
|
|
|
{
|
2007-10-13 23:31:50 +03:00
|
|
|
//if (!NMessage::background)
|
|
|
|
// init();
|
2007-06-12 12:33:20 +03: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++)
|
|
|
|
{
|
|
|
|
CDefHandler * bluePieces = CGI->spriteh->giveDef("DIALGBOX.DEF");
|
|
|
|
std::vector<SDL_Surface *> n;
|
|
|
|
piecesOfBox.push_back(n);
|
|
|
|
if (i==1)
|
|
|
|
{
|
|
|
|
for (int j=0;j<bluePieces->ourImages.size();j++)
|
|
|
|
{
|
|
|
|
piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int j=0;j<bluePieces->ourImages.size();j++)
|
|
|
|
{
|
|
|
|
CSDL_Ext::blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i);
|
|
|
|
piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NMessage::background = CGI->bitmaph->loadBitmap("DIBOXBCK.BMP");
|
|
|
|
SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255));
|
|
|
|
}
|
2007-11-19 00:58:28 +02:00
|
|
|
ok = CGI->spriteh->giveDef("IOKAY.DEF");
|
|
|
|
cancel = CGI->spriteh->giveDef("ICANCEL.DEF");
|
2007-07-29 02:01:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMessage::dispose()
|
|
|
|
{
|
|
|
|
for (int i=0;i<PLAYER_LIMIT;i++)
|
|
|
|
{
|
|
|
|
for (int j=0;j<piecesOfBox[i].size();j++)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor)
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
|
|
|
//prepare surface
|
|
|
|
SDL_Surface * ret = SDL_CreateRGBSurface(ekran->flags, w, h, ekran->format->BitsPerPixel, ekran->format->Rmask, ekran->format->Gmask, ekran->format->Bmask, ekran->format->Amask);
|
|
|
|
for (int i=0; i<h; i+=background->h)//background
|
|
|
|
{
|
|
|
|
for (int j=0; j<w; j+=background->w-1)
|
|
|
|
SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i));
|
2007-07-12 14:41:31 +03:00
|
|
|
}
|
2007-07-29 02:01:25 +03:00
|
|
|
|
2007-06-12 12:33:20 +03:00
|
|
|
//obwodka I-szego rzedu pozioma
|
2007-07-29 02:01:25 +03:00
|
|
|
for (int i=0; i<w; i+=piecesOfBox[playerColor][6]->w)
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
|
|
|
SDL_BlitSurface
|
2007-07-29 02:01:25 +03:00
|
|
|
(piecesOfBox[playerColor][6],NULL,ret,&genRect(piecesOfBox[playerColor][6]->h,piecesOfBox[playerColor][6]->w,i,0));
|
2007-06-12 12:33:20 +03:00
|
|
|
SDL_BlitSurface
|
2007-07-29 02:01:25 +03:00
|
|
|
(piecesOfBox[playerColor][7],NULL,ret,&genRect(piecesOfBox[playerColor][7]->h,piecesOfBox[playerColor][7]->w,i,h-piecesOfBox[playerColor][7]->h));
|
2007-06-12 12:33:20 +03:00
|
|
|
}
|
|
|
|
//obwodka I-szego rzedu pionowa
|
2007-07-29 02:01:25 +03:00
|
|
|
for (int i=0; i<h; i+=piecesOfBox[playerColor][4]->h)
|
2007-06-12 12:33:20 +03:00
|
|
|
{
|
|
|
|
SDL_BlitSurface
|
2007-07-29 02:01:25 +03:00
|
|
|
(piecesOfBox[playerColor][4],NULL,ret,&genRect(piecesOfBox[playerColor][4]->h,piecesOfBox[playerColor][4]->w,0,i));
|
2007-06-12 12:33:20 +03:00
|
|
|
SDL_BlitSurface
|
2007-07-29 02:01:25 +03:00
|
|
|
(piecesOfBox[playerColor][5],NULL,ret,&genRect(piecesOfBox[playerColor][5]->h,piecesOfBox[playerColor][5]->w,w-piecesOfBox[playerColor][5]->w,i));
|
2007-06-12 12:33:20 +03:00
|
|
|
}
|
|
|
|
//corners
|
|
|
|
SDL_BlitSurface
|
2007-07-29 02:01:25 +03:00
|
|
|
(piecesOfBox[playerColor][0],NULL,ret,&genRect(piecesOfBox[playerColor][0]->h,piecesOfBox[playerColor][0]->w,0,0));
|
2007-06-12 12:33:20 +03:00
|
|
|
SDL_BlitSurface
|
2007-07-29 02:01:25 +03:00
|
|
|
(piecesOfBox[playerColor][1],NULL,ret,&genRect(piecesOfBox[playerColor][1]->h,piecesOfBox[playerColor][1]->w,w-piecesOfBox[playerColor][1]->w,0));
|
2007-06-12 12:33:20 +03:00
|
|
|
SDL_BlitSurface
|
2007-07-29 02:01:25 +03:00
|
|
|
(piecesOfBox[playerColor][2],NULL,ret,&genRect(piecesOfBox[playerColor][2]->h,piecesOfBox[playerColor][2]->w,0,h-piecesOfBox[playerColor][2]->h));
|
2007-06-12 12:33:20 +03:00
|
|
|
SDL_BlitSurface
|
2007-07-29 02:01:25 +03:00
|
|
|
(piecesOfBox[playerColor][3],NULL,ret,&genRect(piecesOfBox[playerColor][3]->h,piecesOfBox[playerColor][3]->w,w-piecesOfBox[playerColor][3]->w,h-piecesOfBox[playerColor][3]->h));
|
2007-06-12 12:33:20 +03:00
|
|
|
//box gotowy!
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-10-13 23:31:50 +03:00
|
|
|
std::vector<std::string> * CMessage::breakText(std::string text, int line, bool userBreak, bool ifor)
|
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;
|
|
|
|
for (int 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;
|
|
|
|
}
|
2007-10-13 23:31:50 +03:00
|
|
|
else if (ifor && (text[i]=='{') || (text[i]=='}')) // ignore braces
|
|
|
|
{
|
|
|
|
if (text[i]=='{')
|
|
|
|
opened=true;
|
|
|
|
else
|
|
|
|
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
|
|
|
}
|
2007-07-28 12:44:10 +03:00
|
|
|
for (int i=0;i<text.length();i++)
|
|
|
|
{
|
|
|
|
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);
|
2007-10-13 23:31:50 +03:00
|
|
|
for (int i=0; i<ret->size(); i++)
|
|
|
|
{
|
|
|
|
boost::algorithm::trim((*ret)[i]);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2007-12-27 02:11:46 +02:00
|
|
|
std::pair<int, int> CMessage::getMaxSizes(std::vector< std::vector<CSelectableComponent*> > * komp)
|
|
|
|
{
|
|
|
|
std::pair<int,int> ret;
|
|
|
|
for (int i=0;i<komp->size();i++)
|
|
|
|
{
|
|
|
|
int sumaw=0;
|
|
|
|
int maxh=0;
|
|
|
|
for(int j=0;j<(*komp)[i].size();j++)
|
|
|
|
{
|
|
|
|
sumaw += (*komp)[i][j]->getImg()->w;
|
|
|
|
if (maxh < (*komp)[i][j]->getImg()->h)
|
|
|
|
maxh = (*komp)[i][j]->getImg()->h;
|
|
|
|
}
|
|
|
|
if(sumaw>ret.first)
|
|
|
|
ret.first = sumaw;
|
|
|
|
ret.second+=maxh;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-11-19 00:58:28 +02:00
|
|
|
std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg)
|
|
|
|
{
|
|
|
|
std::pair<int,int> ret;
|
|
|
|
ret.first = -1;
|
|
|
|
ret.second=0;
|
|
|
|
for (int i=0; i<txtg->size();i++) //szukamy najszerszej linii i lacznej wysokosci
|
|
|
|
{
|
|
|
|
int lw=0;
|
|
|
|
for (int j=0;j<(*txtg)[i].size();j++)
|
|
|
|
{
|
|
|
|
lw+=(*txtg)[i][j]->w;
|
|
|
|
ret.second+=(*txtg)[i][j]->h;
|
|
|
|
}
|
|
|
|
if (ret.first<lw)
|
|
|
|
ret.first=lw;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2007-12-01 14:50:33 +02:00
|
|
|
SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret)
|
|
|
|
{
|
|
|
|
for (int i=0; i<txtg->size();i++)
|
|
|
|
{
|
|
|
|
int lw=0;
|
|
|
|
for (int j=0;j<(*txtg)[i].size();j++)
|
|
|
|
lw+=(*txtg)[i][j]->w; //lw - laczna szerokosc linii
|
|
|
|
int pw = ret->w/2;
|
|
|
|
pw -= lw/2; //poczatek tekstu (x)
|
2007-10-13 23:31:50 +03:00
|
|
|
|
2007-12-01 14:50:33 +02:00
|
|
|
int tw = pw;
|
|
|
|
for (int j=0;j<(*txtg)[i].size();j++) //blit text
|
|
|
|
{
|
|
|
|
blitAt((*txtg)[i][j],tw,curh+i*19,ret);
|
|
|
|
tw+=(*txtg)[i][j]->w;
|
|
|
|
SDL_FreeSurface((*txtg)[i][j]);
|
|
|
|
}
|
|
|
|
}
|
2007-12-27 02:11:46 +02:00
|
|
|
curh+=txtg->size()*19;
|
2007-12-01 14:50:33 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
SDL_Surface * CMessage::blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret)
|
|
|
|
{
|
|
|
|
std::vector<std::string> * brdtext;
|
|
|
|
if (comps.size())
|
|
|
|
brdtext = breakText(comps[0]->subtitle,12,true,true);
|
|
|
|
else
|
|
|
|
brdtext = NULL;
|
|
|
|
curh += 30;
|
|
|
|
comps[0]->pos.x = (ret->w/2) - ((comps[0]->getImg()->w)/2);
|
|
|
|
comps[0]->pos.y = curh;
|
|
|
|
blitAt(comps[0]->getImg(),comps[0]->pos.x,comps[0]->pos.y,ret);
|
|
|
|
curh += comps[0]->getImg()->h + 5; //obrazek + przerwa
|
|
|
|
for (int i=0; i<brdtext->size();i++) //descr.
|
|
|
|
{
|
|
|
|
SDL_Surface * tesu = TTF_RenderText_Blended(GEOR13,(*brdtext)[i].c_str(),zwykly);
|
|
|
|
blitAt(tesu,((comps[0]->getImg()->w - tesu->w)/2)+comps[0]->pos.x,curh,ret);
|
|
|
|
curh+=tesu->h;
|
|
|
|
SDL_FreeSurface(tesu);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2007-12-27 02:11:46 +02:00
|
|
|
SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * or, std::vector< std::vector<CSelectableComponent*> > * komp, int inter, int &curh, SDL_Surface *ret)
|
|
|
|
{
|
|
|
|
for (int i=0;i<komp->size();i++)
|
|
|
|
{
|
|
|
|
int totalw=0, maxh=0;
|
|
|
|
for(int j=0;j<(*komp)[i].size();j++)
|
|
|
|
{
|
|
|
|
totalw+=(*komp)[i][j]->getImg()->w;
|
|
|
|
if(maxh<(*komp)[i][j]->getImg()->h)
|
|
|
|
maxh=(*komp)[i][j]->getImg()->h;
|
|
|
|
}
|
|
|
|
totalw += (inter*2+or->w) * ((*komp)[i].size() - 1);
|
|
|
|
curh+=maxh/2;
|
|
|
|
int curw = (ret->w/2)-(totalw/2);
|
|
|
|
for(int j=0;j<(*komp)[i].size();j++)
|
|
|
|
{
|
|
|
|
blitAt((*komp)[i][j]->getImg(),curw,curh-((*komp)[i][j]->getImg()->h/2),ret);
|
|
|
|
(*komp)[i][j]->pos.x = curw;
|
|
|
|
(*komp)[i][j]->pos.y = curh-((*komp)[i][j]->getImg()->h/2);
|
|
|
|
CSDL_Ext::printAtMiddle((*komp)[i][j]->subtitle,curw+(*komp)[i][j]->getImg()->w/2,curh+((*komp)[i][j]->getImg()->h/2)+10,GEOR13,zwykly,ret);
|
|
|
|
curw += (*komp)[i][j]->getImg()->w;
|
|
|
|
if(j<((*komp)[i].size()-1))
|
|
|
|
{
|
|
|
|
curw+=inter;
|
|
|
|
blitAt(or,curw,curh-(or->h/2),ret);
|
|
|
|
curw+=or->w;
|
|
|
|
curw+=inter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curh+=maxh/2;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2007-11-19 00:58:28 +02:00
|
|
|
std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext)
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
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());
|
2007-10-13 23:31:50 +03:00
|
|
|
for (int i=0; i<brtext->size();i++) //foreach line
|
|
|
|
{
|
|
|
|
while((*brtext)[i].length()) //jesli zostalo cos
|
|
|
|
{
|
|
|
|
int z=0; bool br=true;
|
|
|
|
while( ((*brtext)[i][z]) != ('{') )
|
|
|
|
{
|
|
|
|
if (z >= (((*brtext)[i].length())-1))
|
|
|
|
{
|
|
|
|
br=false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
z++;
|
|
|
|
}
|
|
|
|
if (!br)
|
|
|
|
z++;
|
|
|
|
if (z)
|
2007-11-19 00:58:28 +02:00
|
|
|
(*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*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
|
2007-11-19 00:58:28 +02:00
|
|
|
(*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*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())
|
|
|
|
} //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);
|
|
|
|
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;
|
2007-11-19 00:58:28 +02:00
|
|
|
for (int i=0; i<txtg->size();i++)
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
|
|
|
int lw=0;
|
2007-11-19 00:58:28 +02:00
|
|
|
for (int j=0;j<(*txtg)[i].size();j++)
|
|
|
|
lw+=(*txtg)[i][j]->w;
|
2007-10-13 23:31:50 +03:00
|
|
|
int pw = ret->bitmap->w/2, ph = ret->bitmap->h/2;
|
|
|
|
//int pw = Tmar, ph = Lmar;
|
|
|
|
pw -= lw/2;
|
2007-11-19 00:58:28 +02:00
|
|
|
ph -= (19*txtg->size())/2;
|
2007-10-13 23:31:50 +03:00
|
|
|
|
|
|
|
int tw = pw;
|
2007-11-19 00:58:28 +02:00
|
|
|
for (int j=0;j<(*txtg)[i].size();j++)
|
2007-10-13 23:31:50 +03:00
|
|
|
{
|
|
|
|
//std::stringstream n;
|
|
|
|
//n <<"temp_"<<i<<"__"<<j<<".bmp";
|
2007-11-19 00:58:28 +02:00
|
|
|
blitAt((*txtg)[i][j],tw,ph+i*19,ret->bitmap);
|
2007-10-13 23:31:50 +03:00
|
|
|
//SDL_SaveBMP(ret->bitmap,n.str().c_str());
|
2007-11-19 00:58:28 +02:00
|
|
|
tw+=(*txtg)[i][j]->w;
|
|
|
|
SDL_FreeSurface((*txtg)[i][j]);
|
2007-10-13 23:31:50 +03:00
|
|
|
}
|
|
|
|
}
|
2007-06-12 12:33:20 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2007-10-13 23:31:50 +03:00
|
|
|
|
2007-11-19 00:58:28 +02:00
|
|
|
CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline, std::vector<SComponent*> & comps)
|
|
|
|
{
|
|
|
|
//TODO: support for more than one component
|
|
|
|
CInfoWindow * ret = new CInfoWindow();
|
2007-11-24 00:33:55 +02:00
|
|
|
ret->components = comps;
|
|
|
|
std::vector<std::string> * brtext = breakText(text,charperline,true,true);
|
2007-11-19 00:58:28 +02:00
|
|
|
std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
|
|
|
|
std::pair<int,int> txts = getMaxSizes(txtg);
|
|
|
|
txts.second = txts.second
|
|
|
|
+ ok->ourImages[0].bitmap->h //button
|
2007-11-24 00:33:55 +02:00
|
|
|
+ 15 //after button
|
|
|
|
+ 20; // space between subtitle and button
|
|
|
|
if (comps.size())
|
|
|
|
txts.second = txts.second
|
|
|
|
+ 30 //space to first component
|
|
|
|
+ comps[0]->getImg()->h
|
|
|
|
+ 5 //img <-> subtitle
|
2007-12-01 14:50:33 +02:00
|
|
|
+ 20; //subtitle //!!!!!!!!!!!!!!!!!!!!
|
2007-11-19 00:58:28 +02:00
|
|
|
ret->bitmap = drawBox1(txts.first+70,txts.second+70,0);
|
|
|
|
ret->pos.h=ret->bitmap->h;
|
|
|
|
ret->pos.w=ret->bitmap->w;
|
2007-11-24 00:33:55 +02:00
|
|
|
int curh = 30; //gorny margines
|
2007-12-01 14:50:33 +02:00
|
|
|
blitTextOnSur(txtg,curh,ret->bitmap);
|
2007-11-24 00:33:55 +02:00
|
|
|
if (comps.size())
|
|
|
|
{
|
2007-12-01 14:50:33 +02:00
|
|
|
blitCompsOnSur(comps,200,0,curh,ret->bitmap);
|
2007-11-24 00:33:55 +02:00
|
|
|
}
|
|
|
|
curh += 20; //to buttton
|
|
|
|
ret->okb.posr.x = (ret->bitmap->w/2) - (ret->okb.imgs[0][0]->w/2);
|
|
|
|
ret->okb.posr.y = curh;
|
|
|
|
ret->okb.show();
|
|
|
|
curh+=ret->okb.imgs[0][0]->h;
|
2007-12-27 02:11:46 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
std::vector< std::vector<CSelectableComponent*> > * CMessage::breakComps(std::vector<CSelectableComponent*> & comps,int maxw, SDL_Surface* or)
|
|
|
|
{
|
|
|
|
std::vector< std::vector<CSelectableComponent*> > * ret = new std::vector< std::vector<CSelectableComponent*> >();
|
|
|
|
ret->resize(1);
|
|
|
|
bool wywalicOr=false;
|
|
|
|
if (!or)
|
|
|
|
{
|
|
|
|
or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
|
|
|
|
wywalicOr=true;
|
|
|
|
}
|
|
|
|
int rvi = 0;
|
|
|
|
int curw = 0;
|
|
|
|
for(int i=0;i<comps.size();i++)
|
|
|
|
{
|
|
|
|
curw += (comps[i]->getImg()->w + 12 + or->w);
|
|
|
|
if (curw > maxw)
|
|
|
|
{
|
|
|
|
curw = 0;
|
|
|
|
rvi++;
|
|
|
|
ret->resize(rvi+1);
|
|
|
|
}
|
|
|
|
(*ret)[rvi].push_back(comps[i]);
|
|
|
|
}
|
|
|
|
if (wywalicOr)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(or);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
CSelWindow * CMessage::genSelWindow(std::string text, int player, int charperline, std::vector<CSelectableComponent*> & comps, int owner)
|
|
|
|
{
|
|
|
|
CSelWindow * ret = new CSelWindow();
|
|
|
|
for(int i=0;i<comps.size();i++)
|
|
|
|
{
|
|
|
|
ret->components.push_back(comps[i]);
|
|
|
|
comps[i]->owner = ret;
|
|
|
|
}
|
|
|
|
std::vector<std::string> * tekst = breakText(text,charperline);
|
|
|
|
std::vector<std::vector<SDL_Surface*> > * txtg = drawText(tekst);
|
|
|
|
std::pair<int,int> txts = getMaxSizes(txtg);
|
|
|
|
txts.first+=45; //side margins
|
|
|
|
int curh = 50; //top margin
|
|
|
|
SDL_Surface * or = TTF_RenderText_Blended(GEOR13,CGI->generaltexth->allTexts[4].c_str(),zwykly);
|
|
|
|
std::vector< std::vector<CSelectableComponent*> > * komp = breakComps(comps,500,or);
|
|
|
|
std::pair<int,int> txts2 = getMaxSizes(komp);
|
|
|
|
ret->pos.h = txts.second //wys. tekstu
|
|
|
|
+ txts2.second //wys komponentow
|
|
|
|
+ 20 //podpis pod komponentami
|
|
|
|
+ 55 //gorny margines
|
|
|
|
+ 60 //text <=> comps
|
|
|
|
+ 20 //comps <=> button
|
|
|
|
+ ok->ourImages[0].bitmap->h //button
|
|
|
|
+ 30; //bottom margin
|
|
|
|
ret->pos.w = std::max(txts.first,txts.second);
|
|
|
|
ret->bitmap = drawBox1(ret->pos.w,ret->pos.h,player);
|
|
|
|
blitTextOnSur(txtg,curh,ret->bitmap);
|
|
|
|
curh += 50;
|
|
|
|
blitCompsOnSur(or,komp,10,curh,ret->bitmap);
|
|
|
|
curh += 30; //to buttton
|
|
|
|
ret->okb.posr.x = (ret->bitmap->w/2) - (ret->okb.imgs[0][0]->w/2);
|
|
|
|
ret->okb.posr.y = curh;
|
|
|
|
ret->okb.show();
|
|
|
|
curh+=ret->okb.imgs[0][0]->h;
|
|
|
|
SDL_FreeSurface(or);
|
|
|
|
delete komp;
|
|
|
|
delete tekst;
|
2007-11-19 00:58:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
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());
|
|
|
|
if (type==EWindowType::yesOrNO) //make place for buttons
|
|
|
|
{
|
|
|
|
if (ww<200) ww=200;
|
|
|
|
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
|
2007-06-14 16:13:04 +03:00
|
|
|
|
|
|
|
if (title.length())
|
|
|
|
{
|
2007-06-19 18:25:42 +03:00
|
|
|
//SDL_Surface * titleText = TTF_RenderText_Shaded(TNRB16,title.c_str(),tytulowy,tlo);
|
|
|
|
SDL_Surface * titleText = TTF_RenderText_Blended(TNRB16,title.c_str(),tytulowy);
|
|
|
|
|
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
|
2007-06-13 17:02:43 +03:00
|
|
|
for (int 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_Shaded(TNRB16,(*tekst)[i].c_str(),zwykly,tlo);
|
|
|
|
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);
|
|
|
|
}
|
2007-06-13 17:02:43 +03:00
|
|
|
if (type==EWindowType::yesOrNO) // add buttons
|
|
|
|
{
|
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;
|
|
|
|
}
|