1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/lib/logging/VisualLogger.cpp

116 lines
2.3 KiB
C++
Raw Normal View History

2024-02-03 12:19:48 +02:00
/*
* CLogger.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "VisualLogger.h"
VCMI_LIB_NAMESPACE_BEGIN
DLL_LINKAGE VisualLogger * logVisual = new VisualLogger();
void VisualLogger::updateWithLock(const std::string & channel, const std::function<void(IVisualLogBuilder & logBuilder)> & func)
2024-02-03 12:19:48 +02:00
{
std::lock_guard lock(mutex);
2024-02-03 12:19:48 +02:00
mapLines[channel].clear();
2024-08-06 21:29:04 +02:00
mapTexts[channel].clear();
2024-08-06 17:32:02 +02:00
battleTexts[channel].clear();
2024-02-03 12:19:48 +02:00
2024-08-06 21:29:04 +02:00
VisualLogBuilder builder(mapLines[channel], mapTexts[channel], battleTexts[channel]);
2024-02-03 12:20:59 +02:00
func(builder);
2024-02-03 12:19:48 +02:00
}
2024-08-06 17:32:02 +02:00
void VisualLogger::visualize(IMapOverlayLogVisualizer & visulizer)
2024-02-03 12:19:48 +02:00
{
std::lock_guard lock(mutex);
2024-02-03 12:19:48 +02:00
for(const auto & line : mapLines[keyToShow])
2024-02-03 12:19:48 +02:00
{
visulizer.drawLine(line.start, line.end);
}
2024-08-06 21:29:04 +02:00
2024-08-10 18:13:09 +02:00
std::map<int3, std::vector<Text<int3>>> textMap;
2024-08-06 21:29:04 +02:00
for(const auto & line : mapTexts[keyToShow])
2024-08-06 21:29:04 +02:00
{
2024-08-10 18:13:09 +02:00
textMap[line.tile].push_back(line);
2024-08-06 21:29:04 +02:00
}
for(const auto & pair : textMap)
2024-08-06 21:29:04 +02:00
{
2024-08-10 18:13:09 +02:00
for(int i = 0; i < pair.second.size(); i++)
{
visulizer.drawText(pair.first, i, pair.second[i].text, pair.second[i].background);
}
2024-08-06 21:29:04 +02:00
}
2024-02-03 12:19:48 +02:00
}
2024-08-06 17:32:02 +02:00
void VisualLogger::visualize(IBattleOverlayLogVisualizer & visulizer)
{
std::lock_guard lock(mutex);
2024-08-06 17:32:02 +02:00
std::map<BattleHex, std::vector<std::string>> textMap;
for(auto line : battleTexts[keyToShow])
{
textMap[line.tile].push_back(line.text);
}
for(auto & pair : textMap)
{
2024-08-10 18:13:09 +02:00
for(int i = 0; i < pair.second.size(); i++)
{
visulizer.drawText(pair.first, i, pair.second[i]);
}
2024-08-06 17:32:02 +02:00
}
}
void VisualLogger::setKey(const std::string & key)
2024-02-03 12:19:48 +02:00
{
keyToShow = key;
}
void IVisualLogBuilder::addText(int3 tile, const std::string & text, PlayerColor background)
2024-08-10 18:13:09 +02:00
{
std::optional<ColorRGBA> rgbColor;
switch(background)
{
case 0:
rgbColor = ColorRGBA(255, 0, 0);
break;
case 1:
rgbColor = ColorRGBA(0, 0, 255);
break;
case 2:
rgbColor = ColorRGBA(128, 128, 128);
break;
case 3:
rgbColor = ColorRGBA(0, 255, 0);
break;
case 4:
rgbColor = ColorRGBA(255, 128, 0);
break;
case 5:
rgbColor = ColorRGBA(128, 0, 128);
break;
case 6:
rgbColor = ColorRGBA(0, 255, 255);
break;
case 7:
rgbColor = ColorRGBA(255, 128, 255);
break;
}
addText(tile, text, rgbColor);
}
2024-02-03 12:19:48 +02:00
VCMI_LIB_NAMESPACE_END