From 7f5aa1007f32a0325bab4f4149010046e862274d Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Sat, 24 Oct 2009 11:17:10 +0000 Subject: [PATCH] Better handling of huge and empty message boxes (Bugs #55 and #183) --- client/CMessage.cpp | 29 +++++++++++++++++------------ client/CPlayerInterface.cpp | 5 ++++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/client/CMessage.cpp b/client/CMessage.cpp index 10f948a47..c6b442240 100644 --- a/client/CMessage.cpp +++ b/client/CMessage.cpp @@ -380,18 +380,20 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int // Try to compute a reasonable number of characters per line if (!charperline) { - if (text.size() < 30) + if (text.size() < 30 && ret->buttons.size() < 2) charperline = 30; else if (text.size() < 200) charperline = 40; - else + else if (text.size() < 750) charperline = 50; + else + charperline = 75; //TODO: add scrollbar for very long texts } if(dynamic_cast(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 * brtext = breakText(text,charperline,true,true); //text + std::vector * brtext = breakText(text, charperline, true, true); //text std::vector > * txtg = drawText(brtext, fontHeight); std::pair txts = getMaxSizes(txtg, fontHeight); @@ -400,19 +402,27 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int if (ret->components.size()) txts.second += 30 + comps.h; //space to first component + int bw = 0; if (ret->buttons.size()) + { + // Compute total width of buttons + bw = 20*(ret->buttons.size()-1); // space between all buttons + for(size_t i=0; ibuttons.size(); i++) //and add buttons width + bw+=ret->buttons[i]->imgs[0][0]->w; txts.second += 20 + //before button - ok->ourImages[0].bitmap->h; //button + ok->ourImages[0].bitmap->h; //button + } // Clip window size amax(txts.first, 80); amax(txts.second, 50); - amax(txts.first,comps.w); + amax(txts.first, comps.w); + amax(txts.first, bw); 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,player); + ret->bitmap = drawBox1(txts.first+2*SIDE_MARGIN, txts.second+2*SIDE_MARGIN, player); ret->pos.h=ret->bitmap->h; ret->pos.w=ret->bitmap->w; ret->pos.x=screen->w/2-(ret->pos.w/2); @@ -429,13 +439,8 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int if(ret->buttons.size()) { // 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; ibuttons.size(); i++) //and add buttons width - bw+=ret->buttons[i]->imgs[0][0]->w; bw = (ret->bitmap->w/2) - (bw/2); + curh = ret->bitmap->h - SIDE_MARGIN - ret->buttons[0]->imgs[0][0]->h; for(size_t i=0; ibuttons.size(); i++) { diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 6898be6dc..1a752952c 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1232,7 +1232,10 @@ void CPlayerInterface::showBlockingDialog( const std::string &text, const std::v pom.push_back(std::pair >("ICANCEL.DEF",0)); } - CSelWindow * temp = new CSelWindow(text,playerID,35,intComps,pom,askID); + int charperline = 35; + if (pom.size() > 1) + charperline = 50; + CSelWindow * temp = new CSelWindow(text, playerID, charperline, intComps, pom, askID); GH.pushInt(temp); intComps[0]->clickLeft(true, false); }