1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

code review

This commit is contained in:
Laserlicht 2023-10-01 17:35:56 +02:00 committed by GitHub
parent 7f4361eb10
commit cbd014ac88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 23 deletions

View File

@ -63,7 +63,7 @@ CMapOverview::CMapOverview(std::string mapName, std::string fileName, std::strin
fitToScreen(10);
}
Canvas CMapOverview::CMapOverviewWidget::createMinimapForLayer(std::unique_ptr<CMap> & map, int layer) const
Canvas CMapOverviewWidget::createMinimapForLayer(std::unique_ptr<CMap> & map, int layer) const
{
Canvas canvas = Canvas(Point(map->width, map->height));
@ -99,7 +99,7 @@ Canvas CMapOverview::CMapOverviewWidget::createMinimapForLayer(std::unique_ptr<C
return canvas;
}
std::vector<Canvas> CMapOverview::CMapOverviewWidget::createMinimaps(ResourcePath resource) const
std::vector<Canvas> CMapOverviewWidget::createMinimaps(ResourcePath resource) const
{
std::vector<Canvas> ret = std::vector<Canvas>();
@ -109,15 +109,16 @@ std::vector<Canvas> CMapOverview::CMapOverviewWidget::createMinimaps(ResourcePat
{
map = mapService.loadMap(resource);
}
catch (...)
catch (const std::exception & e)
{
logGlobal->warn("Failed to generate map preview! %s", e.what());
return ret;
}
return createMinimaps(map);
}
std::vector<Canvas> CMapOverview::CMapOverviewWidget::createMinimaps(std::unique_ptr<CMap> & map) const
std::vector<Canvas> CMapOverviewWidget::createMinimaps(std::unique_ptr<CMap> & map) const
{
std::vector<Canvas> ret = std::vector<Canvas>();
@ -127,7 +128,7 @@ std::vector<Canvas> CMapOverview::CMapOverviewWidget::createMinimaps(std::unique
return ret;
}
std::shared_ptr<CPicture> CMapOverview::CMapOverviewWidget::buildDrawMinimap(const JsonNode & config) const
std::shared_ptr<CPicture> CMapOverviewWidget::buildDrawMinimap(const JsonNode & config) const
{
logGlobal->debug("Building widget drawMinimap");
@ -144,7 +145,7 @@ std::shared_ptr<CPicture> CMapOverview::CMapOverviewWidget::buildDrawMinimap(con
return std::make_shared<CPicture>(img, Point(rect.x, rect.y));
}
CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent):
CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent):
InterfaceObjectConfigurable(), p(parent)
{
drawPlayerElements = p.tabType == ESelectionScreen::newGame;
@ -174,7 +175,7 @@ CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent):
minimaps = createMinimaps(campaignMap);
}
REGISTER_BUILDER("drawMinimap", &CMapOverview::CMapOverviewWidget::buildDrawMinimap);
REGISTER_BUILDER("drawMinimap", &CMapOverviewWidget::buildDrawMinimap);
build(config);

View File

@ -26,24 +26,26 @@ class Canvas;
class TransparentFilledRectangle;
enum ESelectionScreen : ui8;
class CMapOverview;
class CMapOverviewWidget : public InterfaceObjectConfigurable
{
CMapOverview& p;
bool drawPlayerElements;
std::vector<Canvas> minimaps;
Canvas createMinimapForLayer(std::unique_ptr<CMap> & map, int layer) const;
std::vector<Canvas> createMinimaps(ResourcePath resource) const;
std::vector<Canvas> createMinimaps(std::unique_ptr<CMap> & map) const;
std::shared_ptr<CPicture> buildDrawMinimap(const JsonNode & config) const;
public:
CMapOverviewWidget(CMapOverview& p);
};
class CMapOverview : public CWindowObject
{
class CMapOverviewWidget : public InterfaceObjectConfigurable
{
CMapOverview& p;
bool drawPlayerElements;
std::vector<Canvas> minimaps;
Canvas createMinimapForLayer(std::unique_ptr<CMap> & map, int layer) const;
std::vector<Canvas> createMinimaps(ResourcePath resource) const;
std::vector<Canvas> createMinimaps(std::unique_ptr<CMap> & map) const;
std::shared_ptr<CPicture> buildDrawMinimap(const JsonNode & config) const;
public:
CMapOverviewWidget(CMapOverview& p);
};
std::shared_ptr<CMapOverviewWidget> widget;
public: