1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Added autoselection of in-game console log width

This commit is contained in:
Ivan Savenko
2023-05-07 20:15:43 +03:00
parent ecff5f3d12
commit ca15bf5698

View File

@@ -19,6 +19,8 @@
#include "../gui/CGuiHandler.h" #include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h" #include "../gui/Shortcut.h"
#include "../render/Colors.h" #include "../render/Colors.h"
#include "../adventureMap/CAdventureMapInterface.h"
#include "../windows/CMessage.h"
#include "../../CCallback.h" #include "../../CCallback.h"
#include "../../lib/CConfigHandler.h" #include "../../lib/CConfigHandler.h"
@@ -83,24 +85,17 @@ void CInGameConsole::print(const std::string & txt)
// boost::unique_lock scope // boost::unique_lock scope
{ {
boost::unique_lock<boost::mutex> lock(texts_mx); boost::unique_lock<boost::mutex> lock(texts_mx);
int lineLen = 60; //FIXME: CONFIGURABLE ADVMAP
if(txt.size() < lineLen) // Maximum width for a text line is limited by:
{ // 1) width of adventure map terrain area, for when in-game console is on top of advmap
texts.push_back({txt, 0}); // 2) width of castle/battle window (fixed to 800) when this window is open
} // 3) arbitrary selected left and right margins
else int maxWidth = std::min( 800, adventureInt->terrainAreaPixels().w) - 100;
{
assert(lineLen);
for(int g = 0; g < txt.size() / lineLen + 1; ++g)
{
std::string part = txt.substr(g * lineLen, lineLen);
if(part.empty())
break;
texts.push_back({part, 0}); auto splitText = CMessage::breakText(txt, maxWidth, FONT_MEDIUM);
}
} for (auto const & entry : splitText)
texts.push_back({entry, 0});
while(texts.size() > maxDisplayedTexts) while(texts.size() > maxDisplayedTexts)
texts.erase(texts.begin()); texts.erase(texts.begin());