From 9e84383a61b4a10fcbc24feb3eb256c69dfe791d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 13 Oct 2007 20:31:50 +0000 Subject: [PATCH] * added #13 and #15 (for buttons and minimap, rest will be added later) --- CAdvmapInterface.cpp | 41 ++++++++++++++- CAdvmapInterface.h | 3 +- CConsoleHandler.cpp | 1 + CGameInterface.cpp | 29 ++++++++++ CGameInterface.h | 12 ++++- CMT.cpp | 2 +- CMessage.cpp | 123 ++++++++++++++++++++++++++++++++++++++++--- CMessage.h | 11 ++-- SDL_Extensions.cpp | 1 + 9 files changed, 202 insertions(+), 21 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 65b06aabb..241000bba 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -10,6 +10,9 @@ #include "CCallback.h" #include #include "mapHandler.h" +#include "CMessage.h" +#include +#include extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts using namespace boost::logic; @@ -86,7 +89,7 @@ void AdventureMapButton::clickLeft (tribool down) } void AdventureMapButton::clickRight (tribool down) { - //TODO: show/hide infobox + LOCPLINT->adventureInt->handleRightClick(helpBox,down,this); } void AdventureMapButton::hover (bool on) { @@ -101,6 +104,7 @@ void AdventureMapButton::activate() if (active) return; active=true; ClickableL::activate(); + ClickableR::activate(); Hoverable::activate(); KeyInterested::activate(); } @@ -501,6 +505,7 @@ void CStatusBar::show() CMinimap::CMinimap(bool draw) { statusbarTxt = CGI->preth->advWorldMap.first; + rcText = CGI->preth->advWorldMap.second; pos.x=630; pos.y=26; pos.h=pos.w=144; @@ -565,7 +570,9 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels void CMinimap::updateRadar() {} void CMinimap::clickRight (tribool down) -{} +{ + LOCPLINT->adventureInt->handleRightClick(rcText,down,this); +} void CMinimap::clickLeft (tribool down) { if (down && (!pressedL)) @@ -682,6 +689,14 @@ void CTerrainRect::clickLeft(tribool down) int3 bufpos = currentHero->getPosition(false); //bufpos.x-=1; currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1); + + //if (LOCPLINT->objsToBlit.size()==0) + //{ + // CSimpleWindow * temp = CMessage::genWindow(" Tutaj dlugi dlugo test Tutaj dlugi dlugi dlugo test Tutaj dlugi dlugi dlugo test Tutaj dlugi dlugi dlugo test {Tutaj tytul} Tutaj dlugi dlugi dlugo test",0); + // temp->pos.x=temp->pos.y=0;temp->ID=3; + // LOCPLINT->objsToBlit.push_back(temp); + //} + //SDL_Delay(5000); } void CTerrainRect::clickRight(tribool down) { @@ -1165,6 +1180,28 @@ CAdvMapInt::CurrentSelection::CurrentSelection() type=-1; selected=NULL; } +void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client) +{ + if (down) + { + boost::algorithm::erase_all(text,"\""); + CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID); + temp->pos.x=300-(temp->pos.w/2); + temp->pos.y=300-(temp->pos.h/2); + temp->owner = client; + LOCPLINT->objsToBlit.push_back(temp); + } + else + { + for (int i=0;iobjsToBlit.size();i++) + { + if (LOCPLINT->objsToBlit[i]->owner==client) + { + LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i)); + } + } + } +} int3 CAdvMapInt::verifyPos(int3 ver) { if (ver.x<0) diff --git a/CAdvmapInterface.h b/CAdvmapInterface.h index 67a2cedc1..0de5ca35a 100644 --- a/CAdvmapInterface.h +++ b/CAdvmapInterface.h @@ -129,7 +129,7 @@ public: std::map colorsBlocked; std::vector map; //one bitmap for each level //TODO flagged buildings - std::string statusbarTxt; + std::string statusbarTxt, rcText; CMinimap(bool draw=true); void draw(); @@ -256,6 +256,7 @@ public: void centerOn(int3 on); int3 verifyPos(int3 ver); + void handleRightClick(std::string text, tribool down, CIntObject * client); }; diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index 8c684ccf2..d569448c3 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -72,6 +72,7 @@ int internalFunc(void * callback) } std::cout<update(); LOCPLINT->adventureInt->updateScreen=false; } + for(int i=0;ibitmap,objsToBlit[i]->pos.x,objsToBlit[i]->pos.y); SDL_Delay(5); //give time for other apps SDL_framerateDelay(mainFPSmng); } @@ -957,6 +964,28 @@ void CPlayerInterface::handleEvent(SDL_Event *sEvent) lclickable[i]->clickLeft(boost::logic::indeterminate); } } + else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT)) + { + for(int i=0; ipos,sEvent->motion.x,sEvent->motion.y)) + { + rclickable[i]->clickRight(true); + } + } + } + else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT)) + { + for(int i=0; ipos,sEvent->motion.x,sEvent->motion.y)) + { + rclickable[i]->clickRight(false); + } + else + rclickable[i]->clickRight(boost::logic::indeterminate); + } + } current = NULL; } //event end diff --git a/CGameInterface.h b/CGameInterface.h index 7a3c0dbdc..49ba52332 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -21,7 +21,15 @@ public: SDL_Rect pos; int ID; }; -class CButtonBase : public virtual CIntObject +class CSimpleWindow : public virtual CIntObject +{ +public: + SDL_Surface * bitmap; + CIntObject * owner; + CSimpleWindow():bitmap(NULL),owner(NULL){}; + virtual ~CSimpleWindow(); +}; +class CButtonBase : public virtual CIntObject //basic buttton class { public: int type; //advmapbutton=2 @@ -111,6 +119,7 @@ public: std::vector hoverable; std::vector keyinterested; std::vector motioninterested; + std::vector objsToBlit; SDL_Surface * hInfo; @@ -121,7 +130,6 @@ public: void heroCreated(const CHeroInstance * hero); SDL_Surface * infoWin(void * specific); //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void* - void handleEvent(SDL_Event * sEvent); void init(CCallback * CB); int3 repairScreenPos(int3 pos); diff --git a/CMT.cpp b/CMT.cpp index f99f2e151..87a52f0da 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -292,7 +292,7 @@ int _tmain(int argc, _TCHAR* argv[]) p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray cgi->neutralColor = p;//gray //colors initialized - + CMessage::init(); cgi->townh = new CTownHandler; cgi->townh->loadNames(); CAbilityHandler * abilh = new CAbilityHandler; diff --git a/CMessage.cpp b/CMessage.cpp index 898ed33ed..bda402746 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -6,7 +6,14 @@ #include "CGameInfo.h" #include "SDL_Extensions.h" #include "hch\CLodHandler.h" - +#include +#include +#include "CGameInterface.h" +#include "hch\CDefHandler.h" +#include "hch\CSemiDefHandler.h" +#include "CGameInfo.h" +#include "SDL_Extensions.h" +#include SDL_Color tytulowy, tlo, zwykly ; SDL_Rect genRect(int hh, int ww, int xx, int yy); @@ -27,8 +34,8 @@ namespace NMessage CMessage::CMessage() { - if (!NMessage::background) - init(); + //if (!NMessage::background) + // init(); } void CMessage::init() { @@ -107,14 +114,14 @@ SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) return ret; } -std::vector * CMessage::breakText(std::string text, int line, bool userBreak) +std::vector * CMessage::breakText(std::string text, int line, bool userBreak, bool ifor) { std::vector * ret = new std::vector(); while (text.length()>line) { - int whereCut = -1; - bool pom = true; - for (int i=0; i * CMessage::breakText(std::string text, int line, bool pom=false; break; } + else if (ifor && (text[i]=='{') || (text[i]=='}')) // ignore braces + { + if (text[i]=='{') + opened=true; + else + opened=false; + braces++; + } } - for (int i=line; i>0&&pom; i--) + for (int i=line+braces; i>0&&pom; i--) { if (text[i]==' ') { whereCut = i; break; } + else if (opened && text[i]=='{') + opened = false; + else if (text[i]=='}') + opened = true; } ret->push_back(text.substr(0,whereCut)); text.erase(0,whereCut); + boost::algorithm::trim_left_if(text,boost::algorithm::is_any_of(" ")); + if (opened) + { + (*(ret->end()-1))+='}'; + text.insert(0,"{"); + } } for (int i=0;i * CMessage::breakText(std::string text, int line, bool } if (text.length() > 0) ret->push_back(text); + for (int i=0; isize(); i++) + { + boost::algorithm::trim((*ret)[i]); + } return ret; } + +CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar) +{ + CSimpleWindow * ret = new CSimpleWindow(); + std::vector * brtext = breakText(text,32,true,true); + std::vector > txtg; + txtg.resize(brtext->size()); + for (int i=0; isize();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) + txtg[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(0,z).c_str(),zwykly)); + (*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 + txtg[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(1,z-1).c_str(),tytulowy)); + (*brtext)[i].erase(0,z+1); //z+1 bo dajemy zamykajaca klamre + } //ends while((*brtext)[i].length()) + } //ends for(int i=0; isize();i++) + int max = -1, lh=0; + for (int i=0; iw; + lh+=txtg[i][j]->h; + } + if (maxbitmap = drawBox1(max+Lmar+Rmar,lh+Tmar+Bmar,0); + ret->pos.h=ret->bitmap->h; + ret->pos.w=ret->bitmap->w; + for (int i=0; iw; + int pw = ret->bitmap->w/2, ph = ret->bitmap->h/2; + //int pw = Tmar, ph = Lmar; + pw -= lw/2; + ph -= (19*txtg.size())/2; + + int tw = pw; + for (int j=0;jbitmap); + //SDL_SaveBMP(ret->bitmap,n.str().c_str()); + tw+=txtg[i][j]->w; + SDL_FreeSurface(txtg[i][j]); + } + } + return ret; +} + + SDL_Surface * CMessage::genMessage (std::string title, std::string text, EWindowType type, std::vector *addPics, void * cb) { diff --git a/CMessage.h b/CMessage.h index 4c6a0f53b..11cad65d5 100644 --- a/CMessage.h +++ b/CMessage.h @@ -4,15 +4,11 @@ #include "global.h" #include "SDL_TTF.h" #include "SDL.h" -#include "hch\CSemiDefHandler.h" -#include "hch\CDefHandler.h" -#include "CGameInterface.h" -#include "CGameInfo.h" -#include "SDL_Extensions.h" enum EWindowType {infoOnly, infoOK, yesOrNO}; class CPreGame; class MapSel; - +class CSimpleWindow; +class CDefHandler; namespace NMessage { extern std::vector > piecesOfBox; //in colors of all players @@ -22,10 +18,11 @@ namespace NMessage class CMessage { public: + static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly, std::vector *addPics=NULL, void * cb=NULL); static SDL_Surface * drawBox1(int w, int h, int playerColor=1); - static std::vector * breakText(std::string text, int line=30, bool userBreak=true); //line - chars per line + static std::vector * breakText(std::string text, int line=30, bool userBreak=true, bool ifor=true); //line - chars per line CMessage(); static void init(); static void dispose(); diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 0e63fee9b..f2461bad5 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -7,6 +7,7 @@ #include #include "CMessage.h" #include +#include "hch\CDefHandler.h" SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given {