mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	This commit is contained in:
		| @@ -10,6 +10,9 @@ | ||||
| #include "CCallback.h" | ||||
| #include <boost/assign/std/vector.hpp> | ||||
| #include "mapHandler.h" | ||||
| #include "CMessage.h" | ||||
| #include <boost/algorithm/string.hpp> | ||||
| #include <boost/algorithm/string/replace.hpp> | ||||
| 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;i<LOCPLINT->objsToBlit.size();i++) | ||||
| 		{ | ||||
| 			if (LOCPLINT->objsToBlit[i]->owner==client) | ||||
| 			{ | ||||
| 				LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i)); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| int3 CAdvMapInt::verifyPos(int3 ver) | ||||
| { | ||||
| 	if (ver.x<0) | ||||
|   | ||||
| @@ -129,7 +129,7 @@ public: | ||||
| 	std::map<int,SDL_Color> colorsBlocked; | ||||
| 	std::vector<SDL_Surface *> 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); | ||||
|  | ||||
|  | ||||
| }; | ||||
|   | ||||
| @@ -72,6 +72,7 @@ int internalFunc(void * callback) | ||||
| 				} | ||||
| 				std::cout<<std::endl; | ||||
| 			} | ||||
| 			break; | ||||
| 		} | ||||
| 		//SDL_Delay(100); | ||||
| 	} | ||||
|   | ||||
| @@ -21,6 +21,11 @@ public: | ||||
| 		return (*a.first)<(*b.first); | ||||
| 	} | ||||
| } ocmptwo_cgin ; | ||||
| CSimpleWindow::~CSimpleWindow() | ||||
| { | ||||
| 	SDL_FreeSurface(bitmap); | ||||
| 	bitmap=NULL; | ||||
| } | ||||
| CButtonBase::CButtonBase() | ||||
| { | ||||
| 	curimg=0; | ||||
| @@ -187,6 +192,8 @@ void CPlayerInterface::yourTurn() | ||||
| 			adventureInt->update(); | ||||
| 			LOCPLINT->adventureInt->updateScreen=false; | ||||
| 		} | ||||
| 		for(int i=0;i<objsToBlit.size();i++) | ||||
| 			blitAt(objsToBlit[i]->bitmap,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; i<rclickable.size();i++) | ||||
| 		{ | ||||
| 			if (isItIn(&rclickable[i]->pos,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; i<rclickable.size();i++) | ||||
| 		{ | ||||
| 			if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y)) | ||||
| 			{ | ||||
| 				rclickable[i]->clickRight(false); | ||||
| 			} | ||||
| 			else | ||||
| 				rclickable[i]->clickRight(boost::logic::indeterminate); | ||||
| 		} | ||||
| 	} | ||||
| 	current = NULL; | ||||
|  | ||||
| } //event end | ||||
|   | ||||
| @@ -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*> hoverable; | ||||
| 	std::vector<KeyInterested*> keyinterested; | ||||
| 	std::vector<MotionInterested*> motioninterested; | ||||
| 	std::vector<CSimpleWindow*> 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); | ||||
|   | ||||
							
								
								
									
										2
									
								
								CMT.cpp
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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; | ||||
|   | ||||
							
								
								
									
										123
									
								
								CMessage.cpp
									
									
									
									
									
								
							
							
						
						
									
										123
									
								
								CMessage.cpp
									
									
									
									
									
								
							| @@ -6,7 +6,14 @@ | ||||
| #include "CGameInfo.h" | ||||
| #include "SDL_Extensions.h" | ||||
| #include "hch\CLodHandler.h" | ||||
|  | ||||
| #include <boost/algorithm/string.hpp> | ||||
| #include <boost/algorithm/string/replace.hpp> | ||||
| #include "CGameInterface.h" | ||||
| #include "hch\CDefHandler.h" | ||||
| #include "hch\CSemiDefHandler.h" | ||||
| #include "CGameInfo.h" | ||||
| #include "SDL_Extensions.h" | ||||
| #include <sstream> | ||||
| 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<std::string> * CMessage::breakText(std::string text, int line, bool userBreak) | ||||
| std::vector<std::string> * CMessage::breakText(std::string text, int line, bool userBreak, bool ifor) | ||||
| { | ||||
| 	std::vector<std::string> * ret = new std::vector<std::string>(); | ||||
| 	while (text.length()>line) | ||||
| 	{ | ||||
| 		int whereCut = -1; | ||||
| 		bool pom = true; | ||||
| 		for (int i=0; i<line; i++) | ||||
| 		int whereCut = -1, braces=0; | ||||
| 		bool pom = true, opened=false; | ||||
| 		for (int i=0; i<line+braces; i++)  | ||||
| 		{ | ||||
| 			if (text[i]==10) //end of line sign | ||||
| 			{ | ||||
| @@ -122,17 +129,35 @@ std::vector<std::string> * 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<text.length();i++) | ||||
| 	{		 | ||||
| @@ -145,8 +170,90 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool | ||||
| 	} | ||||
| 	if (text.length() > 0) | ||||
| 		ret->push_back(text); | ||||
| 	for (int i=0; i<ret->size(); 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<std::string> * brtext = breakText(text,32,true,true); | ||||
| 	std::vector<std::vector<SDL_Surface*> > txtg; | ||||
| 	txtg.resize(brtext->size()); | ||||
| 	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) | ||||
| 				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; i<brtext->size();i++)  | ||||
| 	int max = -1, lh=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; | ||||
| 			lh+=txtg[i][j]->h; | ||||
| 		} | ||||
| 		if (max<lw) | ||||
| 			max=lw; | ||||
| 	} | ||||
| 	ret->bitmap = drawBox1(max+Lmar+Rmar,lh+Tmar+Bmar,0);  | ||||
| 	ret->pos.h=ret->bitmap->h; | ||||
| 	ret->pos.w=ret->bitmap->w; | ||||
| 	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; | ||||
| 		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;j<txtg[i].size();j++) | ||||
| 		{ | ||||
| 				//std::stringstream n; | ||||
| 				//n <<"temp_"<<i<<"__"<<j<<".bmp"; | ||||
| 			blitAt(txtg[i][j],tw,ph+i*19,ret->bitmap); | ||||
| 				//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<CDefHandler*> *addPics, void * cb) | ||||
| { | ||||
|   | ||||
							
								
								
									
										11
									
								
								CMessage.h
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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<std::vector<SDL_Surface*> > 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<CDefHandler*> *addPics=NULL, void * cb=NULL); | ||||
| 	static SDL_Surface * drawBox1(int w, int h, int playerColor=1); | ||||
| 	static std::vector<std::string> * breakText(std::string text, int line=30, bool userBreak=true); //line - chars per line | ||||
| 	static std::vector<std::string> * breakText(std::string text, int line=30, bool userBreak=true, bool ifor=true); //line - chars per line | ||||
| 	CMessage(); | ||||
| 	static void init(); | ||||
| 	static void dispose(); | ||||
|   | ||||
| @@ -7,6 +7,7 @@ | ||||
| #include <algorithm> | ||||
| #include "CMessage.h" | ||||
| #include <boost/algorithm/string.hpp> | ||||
| #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 | ||||
| { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user