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

107 lines
2.1 KiB
C++
Raw Normal View History

2024-02-03 12:19:48 +02:00
/*
* VisualLogger.h, 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
*
*/
#pragma once
#include "../int3.h"
#include "../constants/EntityIdentifiers.h"
2024-08-06 17:32:02 +02:00
#include "../battle/BattleHex.h"
2024-02-03 12:19:48 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2024-08-06 17:32:02 +02:00
class IMapOverlayLogVisualizer
2024-02-03 12:19:48 +02:00
{
public:
virtual void drawLine(int3 start, int3 end) = 0;
};
2024-08-06 17:32:02 +02:00
class IBattleOverlayLogVisualizer
{
public:
virtual void drawText(BattleHex tile, std::vector<std::string> texts) = 0;
};
2024-02-03 12:19:48 +02:00
class IVisualLogBuilder
{
public:
virtual void addLine(int3 start, int3 end) = 0;
2024-08-06 17:32:02 +02:00
virtual void addText(BattleHex tile, std::string text) = 0;
2024-02-03 12:19:48 +02:00
};
/// The logger is used to show screen overlay
class DLL_LINKAGE VisualLogger
{
private:
2024-08-06 17:32:02 +02:00
template<typename T>
struct Line
2024-02-03 12:19:48 +02:00
{
2024-08-06 17:32:02 +02:00
T start;
T end;
2024-02-03 12:19:48 +02:00
2024-08-06 17:32:02 +02:00
Line(T start, T end)
2024-02-03 12:19:48 +02:00
:start(start), end(end)
{
}
};
2024-08-06 17:32:02 +02:00
template<typename T>
struct Text
{
T tile;
std::string text;
Text(T tile, std::string text)
:tile(tile), text(text)
{
}
};
2024-02-03 12:19:48 +02:00
class VisualLogBuilder : public IVisualLogBuilder
{
private:
2024-08-06 17:32:02 +02:00
std::vector<Line<int3>> & mapLines;
std::vector<Text<BattleHex>> & battleTexts;
2024-02-03 12:19:48 +02:00
public:
2024-08-06 17:32:02 +02:00
VisualLogBuilder(
std::vector<Line<int3>> & mapLines,
std::vector<Text<BattleHex>> & battleTexts)
:mapLines(mapLines), battleTexts(battleTexts)
{
}
void addLine(int3 start, int3 end) override
2024-02-03 12:19:48 +02:00
{
2024-08-06 17:32:02 +02:00
mapLines.emplace_back(start, end);
2024-02-03 12:19:48 +02:00
}
2024-08-06 17:32:02 +02:00
void addText(BattleHex tile, std::string text) override
2024-02-03 12:19:48 +02:00
{
2024-08-06 17:32:02 +02:00
battleTexts.emplace_back(tile, text);
2024-02-03 12:19:48 +02:00
}
};
private:
2024-08-06 17:32:02 +02:00
std::map<std::string, std::vector<Line<int3>>> mapLines;
std::map<std::string, std::vector<Text<BattleHex>>> battleTexts;
2024-02-03 12:19:48 +02:00
std::mutex mutex;
std::string keyToShow;
public:
void updateWithLock(std::string channel, std::function<void(IVisualLogBuilder & logBuilder)> func);
2024-08-06 17:32:02 +02:00
void visualize(IMapOverlayLogVisualizer & visulizer);
void visualize(IBattleOverlayLogVisualizer & visulizer);
2024-02-03 12:19:48 +02:00
void setKey(std::string key);
};
extern DLL_LINKAGE VisualLogger * logVisual;
VCMI_LIB_NAMESPACE_END