From edc11fd4510e463cfaac0497d6865525760ebe14 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Thu, 17 Aug 2023 09:56:50 +0200 Subject: [PATCH 1/9] Map preview initial draft --- client/lobby/SelectionTab.cpp | 68 ++++++++++++++++++++++++++++++++++- client/lobby/SelectionTab.h | 12 ++++++- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 592f70048..35c0667d6 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -18,6 +18,7 @@ #include "../CServerHandler.h" #include "../gui/CGuiHandler.h" #include "../gui/Shortcut.h" +#include "../gui/WindowHandler.h" #include "../widgets/CComponent.h" #include "../widgets/Buttons.h" #include "../widgets/MiscWidgets.h" @@ -27,6 +28,7 @@ #include "../windows/GUIClasses.h" #include "../windows/InfoWindows.h" #include "../render/CAnimation.h" +#include "../render/Canvas.h" #include "../render/IImage.h" #include "../../CCallback.h" @@ -37,9 +39,12 @@ #include "../../lib/GameSettings.h" #include "../../lib/filesystem/Filesystem.h" #include "../../lib/campaign/CampaignState.h" +#include "../../lib/mapping/CMap.h" +#include "../../lib/mapping/CMapService.h" #include "../../lib/mapping/CMapInfo.h" #include "../../lib/mapping/CMapHeader.h" #include "../../lib/mapping/MapFormat.h" +#include "../../lib/TerrainHandler.h" #include "../../lib/serializer/Connection.h" bool mapSorter::operator()(const std::shared_ptr aaa, const std::shared_ptr bbb) @@ -353,7 +358,7 @@ void SelectionTab::showPopupWindow(const Point & cursorPosition) if(curItems[py]->date != "") text += boost::str(boost::format("\r\n\r\n%1%:\r\n%2%") % CGI->generaltexth->translate("vcmi.lobby.creationDate") % curItems[py]->date); - CRClickPopup::createAndPush(text); + GH.windows().createAndPushWindow(text, ResourceID(curItems[py]->fileURI), tabType == ESelectionScreen::newGame); } } @@ -797,6 +802,67 @@ std::unordered_set SelectionTab::getFiles(std::string dirURI, int re return ret; } +SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceID resource, bool renderImage) + : CWindowObject(BORDERED | RCLICK_POPUP) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; + + pos = Rect(0, 0, 250, 2000); + + label = std::make_shared(text, Rect(20, 20, 250-40, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); + if(!label->slider) + label->resize(label->label->textSize); + + pos.h = 20 + label->label->textSize.y + 20; + if(renderImage) + pos.h += 200 + 20; + backgroundTexture = std::make_shared("DIBOXBCK", pos); + updateShadow(); + + // TODO: hacky redraw + label = std::make_shared(text, Rect(20, 20, 250-40, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); + if(!label->slider) + label->resize(label->label->textSize); + + if(renderImage) + { + std::shared_ptr img = redrawMinimap(ResourceID(resource.getName(), EResType::MAP)); + image = std::make_shared(img, Point(25, label->label->textSize.y + 40)); + } + + center(GH.getCursorPosition()); //center on mouse +#ifdef VCMI_MOBILE + moveBy({0, -pos.h / 2}); +#endif + fitToScreen(10); +} + +std::shared_ptr SelectionTab::CMapInfoTooltipBox::redrawMinimap(ResourceID resource) +{ + CMapService mapService; + std::unique_ptr map = mapService.loadMap(resource); + Canvas canvas = Canvas(Point(map->width, map->height)); + + for (int y = 0; y < map->height; ++y) + for (int x = 0; x < map->width; ++x) + { + TerrainTile & tile = map->getTile(int3(x, y, 0)); + + ColorRGBA color = tile.terType->minimapUnblocked; + if (tile.blocked && (!tile.visitable)) + color = tile.terType->minimapBlocked; + + canvas.drawPoint(Point(x, y), color); + } + + Canvas canvasScaled = Canvas(Point(200, 200)); + canvasScaled.drawScaled(canvas, Point(0, 0), Point(200, 200)); + + std::shared_ptr img = IImage::createFromSurface(canvasScaled.getInternalSurface()); + + return img; +} + SelectionTab::ListItem::ListItem(Point position, std::shared_ptr iconsFormats, std::shared_ptr iconsVictory, std::shared_ptr iconsLoss) : CIntObject(LCLICK, position) { diff --git a/client/lobby/SelectionTab.h b/client/lobby/SelectionTab.h index 5e8e35e92..da44cfe2f 100644 --- a/client/lobby/SelectionTab.h +++ b/client/lobby/SelectionTab.h @@ -11,6 +11,7 @@ #include "CSelectionBase.h" #include "../../lib/mapping/CMapInfo.h" +#include "../widgets/Images.h" class CSlider; class CLabel; @@ -62,6 +63,16 @@ class SelectionTab : public CIntObject std::shared_ptr iconsVictoryCondition; std::shared_ptr iconsLossCondition; + class CMapInfoTooltipBox : public CWindowObject + { + std::shared_ptr backgroundTexture; + std::shared_ptr label; + std::shared_ptr image; + + std::shared_ptr redrawMinimap(ResourceID resource); + public: + CMapInfoTooltipBox(std::string text, ResourceID resource, bool renderImage); + }; public: std::vector> allItems; std::vector> curItems; @@ -100,7 +111,6 @@ public: void restoreLastSelection(); private: - std::shared_ptr background; std::shared_ptr slider; std::vector> buttonsSortBy; From e44f713f01bb6481e65c9dfc9bedce97ec9b4e65 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Thu, 17 Aug 2023 23:09:20 +0200 Subject: [PATCH 2/9] side by side map; player colors --- client/lobby/SelectionTab.cpp | 79 ++++++++++++++++++++++++++--------- client/lobby/SelectionTab.h | 18 ++++++-- 2 files changed, 74 insertions(+), 23 deletions(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 35c0667d6..aec42454e 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -30,6 +30,7 @@ #include "../render/CAnimation.h" #include "../render/Canvas.h" #include "../render/IImage.h" +#include "../render/Graphics.h" #include "../../CCallback.h" @@ -358,7 +359,7 @@ void SelectionTab::showPopupWindow(const Point & cursorPosition) if(curItems[py]->date != "") text += boost::str(boost::format("\r\n\r\n%1%:\r\n%2%") % CGI->generaltexth->translate("vcmi.lobby.creationDate") % curItems[py]->date); - GH.windows().createAndPushWindow(text, ResourceID(curItems[py]->fileURI), tabType == ESelectionScreen::newGame); + GH.windows().createAndPushWindow(text, ResourceID(curItems[py]->fileURI), tabType); } } @@ -802,32 +803,42 @@ std::unordered_set SelectionTab::getFiles(std::string dirURI, int re return ret; } -SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceID resource, bool renderImage) +SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceID resource, ESelectionScreen tabType) : CWindowObject(BORDERED | RCLICK_POPUP) { + drawPlayerElements = tabType == ESelectionScreen::newGame; + renderImage = tabType == ESelectionScreen::newGame; + OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; - pos = Rect(0, 0, 250, 2000); + std::vector> images; + if(renderImage) + images = redrawMinimap(ResourceID(resource.getName(), EResType::MAP), IMAGE_SIZE); - label = std::make_shared(text, Rect(20, 20, 250-40, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); + pos = Rect(0, 0, 2*BORDER + IMAGE_SIZE, 2000); + if(renderImage && images.size() > 1) + pos.w += IMAGE_SIZE + BORDER; + + label = std::make_shared(text, Rect(BORDER, BORDER, pos.w-2*BORDER, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); if(!label->slider) label->resize(label->label->textSize); - pos.h = 20 + label->label->textSize.y + 20; + pos.h = BORDER + label->label->textSize.y + BORDER; if(renderImage) - pos.h += 200 + 20; + pos.h += IMAGE_SIZE + BORDER; backgroundTexture = std::make_shared("DIBOXBCK", pos); updateShadow(); // TODO: hacky redraw - label = std::make_shared(text, Rect(20, 20, 250-40, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); + label = std::make_shared(text, Rect(BORDER, BORDER, pos.w-2*BORDER, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); if(!label->slider) label->resize(label->label->textSize); if(renderImage) { - std::shared_ptr img = redrawMinimap(ResourceID(resource.getName(), EResType::MAP)); - image = std::make_shared(img, Point(25, label->label->textSize.y + 40)); + image1 = std::make_shared(images[0], Point(BORDER, label->label->textSize.y + 2*BORDER)); + if(images.size()>1) + image2 = std::make_shared(images[1], Point(BORDER + IMAGE_SIZE + BORDER, label->label->textSize.y + 2*BORDER)); } center(GH.getCursorPosition()); //center on mouse @@ -837,30 +848,60 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI fitToScreen(10); } -std::shared_ptr SelectionTab::CMapInfoTooltipBox::redrawMinimap(ResourceID resource) +Canvas SelectionTab::CMapInfoTooltipBox::createMinimap(std::unique_ptr & map, int layer) { - CMapService mapService; - std::unique_ptr map = mapService.loadMap(resource); Canvas canvas = Canvas(Point(map->width, map->height)); for (int y = 0; y < map->height; ++y) for (int x = 0; x < map->width; ++x) { - TerrainTile & tile = map->getTile(int3(x, y, 0)); + TerrainTile & tile = map->getTile(int3(x, y, layer)); ColorRGBA color = tile.terType->minimapUnblocked; if (tile.blocked && (!tile.visitable)) color = tile.terType->minimapBlocked; + if(drawPlayerElements) + // if object at tile is owned - it will be colored as its owner + for (const CGObjectInstance *obj : tile.blockingObjects) + { + PlayerColor player = obj->getOwner(); + if(player == PlayerColor::NEUTRAL) + { + color = graphics->neutralColor; + break; + } + if (player < PlayerColor::PLAYER_LIMIT) + { + color = graphics->playerColors[player.getNum()]; + break; + } + } + canvas.drawPoint(Point(x, y), color); } - - Canvas canvasScaled = Canvas(Point(200, 200)); - canvasScaled.drawScaled(canvas, Point(0, 0), Point(200, 200)); - - std::shared_ptr img = IImage::createFromSurface(canvasScaled.getInternalSurface()); - return img; + return canvas; +} + +std::vector> SelectionTab::CMapInfoTooltipBox::redrawMinimap(ResourceID resource, int size) +{ + std::vector> ret = std::vector>(); + + CMapService mapService; + std::unique_ptr map = mapService.loadMap(resource); + + for(int i = 0; i < (map->twoLevel ? 2 : 1); i++) + { + Canvas canvas = createMinimap(map, i); + Canvas canvasScaled = Canvas(Point(size, size)); + canvasScaled.drawScaled(canvas, Point(0, 0), Point(size, size)); + std::shared_ptr img = IImage::createFromSurface(canvasScaled.getInternalSurface()); + + ret.push_back(img); + } + + return ret; } SelectionTab::ListItem::ListItem(Point position, std::shared_ptr iconsFormats, std::shared_ptr iconsVictory, std::shared_ptr iconsLoss) diff --git a/client/lobby/SelectionTab.h b/client/lobby/SelectionTab.h index da44cfe2f..ec1aa4b30 100644 --- a/client/lobby/SelectionTab.h +++ b/client/lobby/SelectionTab.h @@ -11,10 +11,12 @@ #include "CSelectionBase.h" #include "../../lib/mapping/CMapInfo.h" -#include "../widgets/Images.h" class CSlider; class CLabel; +class CMap; +class CPicture; +class IImage; enum ESortBy { @@ -65,13 +67,21 @@ class SelectionTab : public CIntObject class CMapInfoTooltipBox : public CWindowObject { + const int IMAGE_SIZE = 169; + const int BORDER = 30; + + bool drawPlayerElements; + bool renderImage; + std::shared_ptr backgroundTexture; std::shared_ptr label; - std::shared_ptr image; + std::shared_ptr image1; + std::shared_ptr image2; - std::shared_ptr redrawMinimap(ResourceID resource); + Canvas createMinimap(std::unique_ptr & map, int layer); + std::vector> redrawMinimap(ResourceID resource, int size=144); public: - CMapInfoTooltipBox(std::string text, ResourceID resource, bool renderImage); + CMapInfoTooltipBox(std::string text, ResourceID resource, ESelectionScreen tabType); }; public: std::vector> allItems; From f9fa27b1800c5ef498ddaace7918e8ad095eaf11 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Thu, 17 Aug 2023 23:40:19 +0200 Subject: [PATCH 3/9] fix --- client/lobby/SelectionTab.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lobby/SelectionTab.h b/client/lobby/SelectionTab.h index ec1aa4b30..2894a7ad3 100644 --- a/client/lobby/SelectionTab.h +++ b/client/lobby/SelectionTab.h @@ -10,11 +10,11 @@ #pragma once #include "CSelectionBase.h" +#include "../../lib/mapping/CMap.h" #include "../../lib/mapping/CMapInfo.h" class CSlider; class CLabel; -class CMap; class CPicture; class IImage; From 1d94536299fc3f050227b138cff71854a399e6d1 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 20 Aug 2023 13:16:39 +0200 Subject: [PATCH 4/9] code review --- client/lobby/SelectionTab.cpp | 18 +++++++++--------- client/lobby/SelectionTab.h | 8 +++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index aec42454e..e0cc108a0 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -811,12 +811,12 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; - std::vector> images; + std::vector> mapLayerImages; if(renderImage) - images = redrawMinimap(ResourceID(resource.getName(), EResType::MAP), IMAGE_SIZE); + mapLayerImages = createMinimaps(ResourceID(resource.getName(), EResType::MAP), IMAGE_SIZE); pos = Rect(0, 0, 2*BORDER + IMAGE_SIZE, 2000); - if(renderImage && images.size() > 1) + if(renderImage && mapLayerImages.size() > 1) pos.w += IMAGE_SIZE + BORDER; label = std::make_shared(text, Rect(BORDER, BORDER, pos.w-2*BORDER, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); @@ -836,9 +836,9 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI if(renderImage) { - image1 = std::make_shared(images[0], Point(BORDER, label->label->textSize.y + 2*BORDER)); - if(images.size()>1) - image2 = std::make_shared(images[1], Point(BORDER + IMAGE_SIZE + BORDER, label->label->textSize.y + 2*BORDER)); + image1 = std::make_shared(mapLayerImages[0], Point(BORDER, label->label->textSize.y + 2*BORDER)); + if(mapLayerImages.size()>1) + image2 = std::make_shared(mapLayerImages[1], Point(BORDER + IMAGE_SIZE + BORDER, label->label->textSize.y + 2*BORDER)); } center(GH.getCursorPosition()); //center on mouse @@ -848,7 +848,7 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI fitToScreen(10); } -Canvas SelectionTab::CMapInfoTooltipBox::createMinimap(std::unique_ptr & map, int layer) +Canvas SelectionTab::CMapInfoTooltipBox::createMinimapForLayer(std::unique_ptr & map, int layer) { Canvas canvas = Canvas(Point(map->width, map->height)); @@ -884,7 +884,7 @@ Canvas SelectionTab::CMapInfoTooltipBox::createMinimap(std::unique_ptr & m return canvas; } -std::vector> SelectionTab::CMapInfoTooltipBox::redrawMinimap(ResourceID resource, int size) +std::vector> SelectionTab::CMapInfoTooltipBox::createMinimaps(ResourceID resource, int size) { std::vector> ret = std::vector>(); @@ -893,7 +893,7 @@ std::vector> SelectionTab::CMapInfoTooltipBox::redrawMin for(int i = 0; i < (map->twoLevel ? 2 : 1); i++) { - Canvas canvas = createMinimap(map, i); + Canvas canvas = createMinimapForLayer(map, i); Canvas canvasScaled = Canvas(Point(size, size)); canvasScaled.drawScaled(canvas, Point(0, 0), Point(size, size)); std::shared_ptr img = IImage::createFromSurface(canvasScaled.getInternalSurface()); diff --git a/client/lobby/SelectionTab.h b/client/lobby/SelectionTab.h index 2894a7ad3..50426b78d 100644 --- a/client/lobby/SelectionTab.h +++ b/client/lobby/SelectionTab.h @@ -10,7 +10,9 @@ #pragma once #include "CSelectionBase.h" -#include "../../lib/mapping/CMap.h" +VCMI_LIB_NAMESPACE_BEGIN +class CMap; +VCMI_LIB_NAMESPACE_END #include "../../lib/mapping/CMapInfo.h" class CSlider; @@ -78,8 +80,8 @@ class SelectionTab : public CIntObject std::shared_ptr image1; std::shared_ptr image2; - Canvas createMinimap(std::unique_ptr & map, int layer); - std::vector> redrawMinimap(ResourceID resource, int size=144); + Canvas createMinimapForLayer(std::unique_ptr & map, int layer); + std::vector> createMinimaps(ResourceID resource, int size); public: CMapInfoTooltipBox(std::string text, ResourceID resource, ESelectionScreen tabType); }; From e3a4c65100c6e64f9f62220d84016a29a972bacd Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 20 Aug 2023 14:14:47 +0200 Subject: [PATCH 5/9] code review --- client/lobby/SelectionTab.cpp | 22 +++++++++++----------- config/schemas/settings.json | 14 +++++++++++++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index e0cc108a0..f2522258e 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -807,7 +807,7 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI : CWindowObject(BORDERED | RCLICK_POPUP) { drawPlayerElements = tabType == ESelectionScreen::newGame; - renderImage = tabType == ESelectionScreen::newGame; + renderImage = tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool(); OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; @@ -815,13 +815,16 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI if(renderImage) mapLayerImages = createMinimaps(ResourceID(resource.getName(), EResType::MAP), IMAGE_SIZE); - pos = Rect(0, 0, 2*BORDER + IMAGE_SIZE, 2000); + pos = Rect(0, 0, 2 * BORDER + IMAGE_SIZE, 2000); if(renderImage && mapLayerImages.size() > 1) pos.w += IMAGE_SIZE + BORDER; - label = std::make_shared(text, Rect(BORDER, BORDER, pos.w-2*BORDER, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); - if(!label->slider) - label->resize(label->label->textSize); + auto drawLabel = [&]() { + label = std::make_shared(text, Rect(BORDER, BORDER, pos.w - 2 * BORDER, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); + if(!label->slider) + label->resize(label->label->textSize); + }; + drawLabel(); pos.h = BORDER + label->label->textSize.y + BORDER; if(renderImage) @@ -829,16 +832,13 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI backgroundTexture = std::make_shared("DIBOXBCK", pos); updateShadow(); - // TODO: hacky redraw - label = std::make_shared(text, Rect(BORDER, BORDER, pos.w-2*BORDER, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); - if(!label->slider) - label->resize(label->label->textSize); + drawLabel(); if(renderImage) { - image1 = std::make_shared(mapLayerImages[0], Point(BORDER, label->label->textSize.y + 2*BORDER)); + image1 = std::make_shared(mapLayerImages[0], Point(BORDER, label->label->textSize.y + 2 * BORDER)); if(mapLayerImages.size()>1) - image2 = std::make_shared(mapLayerImages[1], Point(BORDER + IMAGE_SIZE + BORDER, label->label->textSize.y + 2*BORDER)); + image2 = std::make_shared(mapLayerImages[1], Point(BORDER + IMAGE_SIZE + BORDER, label->label->textSize.y + 2 * BORDER)); } center(GH.getCursorPosition()); //center on mouse diff --git a/config/schemas/settings.json b/config/schemas/settings.json index 20699af25..eb2ca4d0d 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -3,7 +3,7 @@ { "type" : "object", "$schema" : "http://json-schema.org/draft-04/schema", - "required" : [ "general", "video", "adventure", "battle", "input", "server", "logging", "launcher", "gameTweaks" ], + "required" : [ "general", "video", "adventure", "battle", "input", "server", "logging", "launcher", "lobby", "gameTweaks" ], "definitions" : { "logLevelEnum" : { "type" : "string", @@ -526,6 +526,18 @@ } } }, + "lobby" : { + "type" : "object", + "additionalProperties" : false, + "default" : {}, + "required" : [ "mapPreview" ], + "properties" : { + "mapPreview" : { + "type" : "boolean", + "default" : true + } + } + }, "gameTweaks" : { "type" : "object", "default" : {}, From 952ce3061ba40b6ad8d6695ba96140db162a7ab7 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 20 Aug 2023 14:28:10 +0200 Subject: [PATCH 6/9] avoid crash if any error in map --- client/lobby/SelectionTab.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index f2522258e..195fbdf3b 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -815,6 +815,9 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI if(renderImage) mapLayerImages = createMinimaps(ResourceID(resource.getName(), EResType::MAP), IMAGE_SIZE); + if(mapLayerImages.size() == 0) + renderImage = false; + pos = Rect(0, 0, 2 * BORDER + IMAGE_SIZE, 2000); if(renderImage && mapLayerImages.size() > 1) pos.w += IMAGE_SIZE + BORDER; @@ -889,7 +892,15 @@ std::vector> SelectionTab::CMapInfoTooltipBox::createMin std::vector> ret = std::vector>(); CMapService mapService; - std::unique_ptr map = mapService.loadMap(resource); + std::unique_ptr map; + try + { + map = mapService.loadMap(resource); + } + catch (...) + { + return ret; + } for(int i = 0; i < (map->twoLevel ? 2 : 1); i++) { From 5c5576313b9ed8e3d812c2d50268a8d700aabaa8 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 20 Aug 2023 16:58:13 +0200 Subject: [PATCH 7/9] handle long texts better; big window also for only one layer --- client/lobby/SelectionTab.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 195fbdf3b..874b56aac 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -818,9 +818,7 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI if(mapLayerImages.size() == 0) renderImage = false; - pos = Rect(0, 0, 2 * BORDER + IMAGE_SIZE, 2000); - if(renderImage && mapLayerImages.size() > 1) - pos.w += IMAGE_SIZE + BORDER; + pos = Rect(0, 0, 3 * BORDER + 2 * IMAGE_SIZE, 2000); auto drawLabel = [&]() { label = std::make_shared(text, Rect(BORDER, BORDER, pos.w - 2 * BORDER, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); @@ -829,7 +827,8 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI }; drawLabel(); - pos.h = BORDER + label->label->textSize.y + BORDER; + int textHeight = std::min(350, label->label->textSize.y); + pos.h = BORDER + textHeight + BORDER; if(renderImage) pos.h += IMAGE_SIZE + BORDER; backgroundTexture = std::make_shared("DIBOXBCK", pos); @@ -839,9 +838,13 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI if(renderImage) { - image1 = std::make_shared(mapLayerImages[0], Point(BORDER, label->label->textSize.y + 2 * BORDER)); - if(mapLayerImages.size()>1) - image2 = std::make_shared(mapLayerImages[1], Point(BORDER + IMAGE_SIZE + BORDER, label->label->textSize.y + 2 * BORDER)); + if(mapLayerImages.size() == 1) + image1 = std::make_shared(mapLayerImages[0], Point(BORDER + (BORDER + IMAGE_SIZE) / 2, textHeight + 2 * BORDER)); + else + { + image1 = std::make_shared(mapLayerImages[0], Point(BORDER, textHeight + 2 * BORDER)); + image2 = std::make_shared(mapLayerImages[1], Point(BORDER + IMAGE_SIZE + BORDER, textHeight + 2 * BORDER)); + } } center(GH.getCursorPosition()); //center on mouse From 080630b39fa31f25a5ea391648440037bcc61c71 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 20 Aug 2023 22:22:46 +0200 Subject: [PATCH 8/9] try to fix --- client/lobby/SelectionTab.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 874b56aac..6ee831eb7 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -821,7 +821,7 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI pos = Rect(0, 0, 3 * BORDER + 2 * IMAGE_SIZE, 2000); auto drawLabel = [&]() { - label = std::make_shared(text, Rect(BORDER, BORDER, pos.w - 2 * BORDER, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); + label = std::make_shared(text, Rect(BORDER, BORDER, BORDER + 2 * IMAGE_SIZE, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); if(!label->slider) label->resize(label->label->textSize); }; From 05a88bd8acc5e7c48319bf499a767b2047ef1f88 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 20 Aug 2023 23:34:09 +0200 Subject: [PATCH 9/9] another try... --- client/lobby/SelectionTab.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 6ee831eb7..fe5e8c0bc 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -823,7 +823,7 @@ SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourceI auto drawLabel = [&]() { label = std::make_shared(text, Rect(BORDER, BORDER, BORDER + 2 * IMAGE_SIZE, 350), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE); if(!label->slider) - label->resize(label->label->textSize); + label->resize(Point(BORDER + 2 * IMAGE_SIZE, label->label->textSize.y)); }; drawLabel();