Explorar el Código

Try to better dimension the info windows.

Frank Zago hace 16 años
padre
commit
b2014c79d4
Se han modificado 2 ficheros con 33 adiciones y 12 borrados
  1. 31 10
      client/CMessage.cpp
  2. 2 2
      client/CPlayerInterface.cpp

+ 31 - 10
client/CMessage.cpp

@@ -15,6 +15,7 @@
 #include "Graphics.h"
 #include "GUIClasses.h"
 #include "AdventureMapButton.h"
+#include "CConfigHandler.h"
 
 /*
  * CMessage.cpp, part of VCMI engine
@@ -36,6 +37,7 @@ using namespace NMessage;
 const int COMPONENT_TO_SUBTITLE = 5;
 const int BETWEEN_COMPS_ROWS = 10;
 const int BEFORE_COMPONENTS = 30;
+const int SIDE_MARGIN = 30;
 
 template <typename T, typename U> std::pair<T,U> max(const std::pair<T,U> &x, const std::pair<T,U> &y)
 {
@@ -352,6 +354,17 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int
 {
 	SDL_Surface * _or = NULL;
 	int fontHeight;
+
+	// Try to compute a resonable number of characters per line
+	if (!charperline) {
+		if (text.size() < 30)
+			charperline = 30;
+		else if (text.size() < 200)
+			charperline = 40;
+		else
+			charperline = 50;
+	}
+
 	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);
 
@@ -361,24 +374,28 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int
 
 	ComponentsToBlit comps(ret->components,500,_or);
 
-	if(ret->buttons.size())
-		txts.second += 20 + //before button
-		ok->ourImages[0].bitmap->h; //button
-
 	if (ret->components.size())
-	{
 		txts.second += 30 + comps.h; //space to first component
 
-	}
+	if (ret->buttons.size())
+		txts.second += 20 + //before button
+		ok->ourImages[0].bitmap->h; //button
 
+	// Clip window size
+	amax(txts.first, 80);
+	amax(txts.second, 50);
 	amax(txts.first,comps.w);
 
-	ret->bitmap = drawBox1(txts.first+70,txts.second+70,0);
+	amin(txts.first, conf.cc.resx - 150);
+	amin(txts.second, conf.cc.resy - 150);
+
+	ret->bitmap = drawBox1(txts.first+2*SIDE_MARGIN,txts.second+2*SIDE_MARGIN,0);
 	ret->pos.h=ret->bitmap->h;
 	ret->pos.w=ret->bitmap->w;
 	ret->pos.x=screen->w/2-(ret->pos.w/2);
 	ret->pos.y=screen->h/2-(ret->pos.h/2);
-	int curh = 30; //gorny margines
+
+	int curh = SIDE_MARGIN;
 	blitTextOnSur(txtg, fontHeight, curh,ret->bitmap);
 
 	if (ret->components.size())
@@ -388,11 +405,15 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int
 	}
 	if(ret->buttons.size())
 	{
-		curh += 20; //to buttton
-		int bw = 20*(ret->buttons.size()-1); //total width of buttons - start with distance between them
+		// Position the buttons at the bottom of the window
+		curh = ret->bitmap->h - SIDE_MARGIN - ret->buttons[0]->imgs[0][0]->h;
+
+		// Compute total width of buttons
+		int bw = 20*(ret->buttons.size()-1); // space between all buttons
 		for(size_t i=0; i<ret->buttons.size(); i++) //and add buttons width
 			bw+=ret->buttons[i]->imgs[0][0]->w; 
 		bw = (ret->bitmap->w/2) - (bw/2);
+
 		for(size_t i=0; i<ret->buttons.size(); i++)
 		{
 			ret->buttons[i]->pos.x = bw + ret->pos.x;

+ 2 - 2
client/CPlayerInterface.cpp

@@ -1418,7 +1418,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector
 
 	std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
-	CInfoWindow * temp = new CInfoWindow(text,playerID,36,components,pom,false);
+	CInfoWindow * temp = new CInfoWindow(text,playerID,0,components,pom,false);
 
 	if(makingTurn && listInt.size())
 	{
@@ -1439,7 +1439,7 @@ void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vecto
 	std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
 	pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
-	CInfoWindow * temp = new CInfoWindow(text,playerID,36,components,pom,DelComps);
+	CInfoWindow * temp = new CInfoWindow(text,playerID,0,components,pom,DelComps);
 	temp->delComps = DelComps;
 	for(int i=0;i<onYes.funcs.size();i++)
 		temp->buttons[0]->callback += onYes.funcs[i];