From 718bafc8aff1ec01ee7e518e61ebf510174384ee Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 15:05:12 +0200 Subject: [PATCH 01/15] map overview rework --- client/CMakeLists.txt | 2 + client/lobby/SelectionTab.cpp | 122 +------------------- client/lobby/SelectionTab.h | 19 --- client/windows/CMapOverview.cpp | 197 ++++++++++++++++++++++++++++++++ client/windows/CMapOverview.h | 58 ++++++++++ 5 files changed, 259 insertions(+), 139 deletions(-) create mode 100644 client/windows/CMapOverview.cpp create mode 100644 client/windows/CMapOverview.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index ed53ca99a..2912d02cf 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -119,6 +119,7 @@ set(client_SRCS windows/CHeroOverview.cpp windows/CHeroWindow.cpp windows/CKingdomInterface.cpp + windows/CMapOverview.cpp windows/CMessage.cpp windows/CPuzzleWindow.cpp windows/CQuestLog.cpp @@ -285,6 +286,7 @@ set(client_HEADERS windows/CHeroWindow.h windows/CKingdomInterface.h windows/CMessage.h + windows/CMapOverview.h windows/CPuzzleWindow.h windows/CQuestLog.h windows/CSpellWindow.h diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 34375db26..8a3b4b494 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -27,11 +27,10 @@ #include "../widgets/TextControls.h" #include "../windows/GUIClasses.h" #include "../windows/InfoWindows.h" +#include "../windows/CMapOverview.h" #include "../render/CAnimation.h" -#include "../render/Canvas.h" #include "../render/IImage.h" #include "../render/IRenderHandler.h" -#include "../render/Graphics.h" #include "../../CCallback.h" @@ -41,8 +40,6 @@ #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" @@ -371,7 +368,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, ResourcePath(curItems[py]->fileURI), tabType); + GH.windows().createAndPushWindow(text, ResourcePath(curItems[py]->fileURI), tabType); } else CRClickPopup::createAndPush(curItems[py]->folderName); @@ -822,121 +819,6 @@ std::unordered_set SelectionTab::getFiles(std::string dirURI, ERes return ret; } -SelectionTab::CMapInfoTooltipBox::CMapInfoTooltipBox(std::string text, ResourcePath resource, ESelectionScreen tabType) - : CWindowObject(BORDERED | RCLICK_POPUP) -{ - drawPlayerElements = tabType == ESelectionScreen::newGame; - renderImage = tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool(); - - OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; - - std::vector> mapLayerImages; - if(renderImage) - mapLayerImages = createMinimaps(ResourcePath(resource.getName(), EResType::MAP), IMAGE_SIZE); - - if(mapLayerImages.size() == 0) - renderImage = false; - - pos = Rect(0, 0, 3 * BORDER + 2 * IMAGE_SIZE, 2000); - - 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(Point(BORDER + 2 * IMAGE_SIZE, label->label->textSize.y)); - }; - drawLabel(); - - 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(ImagePath::builtin("DIBOXBCK"), pos); - updateShadow(); - - drawLabel(); - - if(renderImage) - { - 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 -#ifdef VCMI_MOBILE - moveBy({0, -pos.h / 2}); -#endif - fitToScreen(10); -} - -Canvas SelectionTab::CMapInfoTooltipBox::createMinimapForLayer(std::unique_ptr & map, int layer) -{ - 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, 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.isValidPlayer()) - { - color = graphics->playerColors[player.getNum()]; - break; - } - } - - canvas.drawPoint(Point(x, y), color); - } - - return canvas; -} - -std::vector> SelectionTab::CMapInfoTooltipBox::createMinimaps(ResourcePath resource, int size) -{ - std::vector> ret = std::vector>(); - - CMapService mapService; - std::unique_ptr map; - try - { - map = mapService.loadMap(resource); - } - catch (...) - { - return ret; - } - - for(int i = 0; i < (map->twoLevel ? 2 : 1); 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 = GH.renderHandler().createImage(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) : CIntObject(LCLICK, position) { diff --git a/client/lobby/SelectionTab.h b/client/lobby/SelectionTab.h index e4d67ef83..50f501769 100644 --- a/client/lobby/SelectionTab.h +++ b/client/lobby/SelectionTab.h @@ -67,25 +67,6 @@ class SelectionTab : public CIntObject // FIXME: CSelectionBase use them too! std::shared_ptr iconsVictoryCondition; std::shared_ptr iconsLossCondition; - - 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 image1; - std::shared_ptr image2; - - Canvas createMinimapForLayer(std::unique_ptr & map, int layer); - std::vector> createMinimaps(ResourcePath resource, int size); - public: - CMapInfoTooltipBox(std::string text, ResourcePath resource, ESelectionScreen tabType); - }; public: std::vector> allItems; std::vector> curItems; diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp new file mode 100644 index 000000000..7f05e68b1 --- /dev/null +++ b/client/windows/CMapOverview.cpp @@ -0,0 +1,197 @@ +/* + * CMapOverview.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 "CMapOverview.h" + +#include "../lobby/SelectionTab.h" + +#include "../gui/CGuiHandler.h" +#include "../gui/WindowHandler.h" +#include "../widgets/CComponent.h" +#include "../widgets/MiscWidgets.h" +#include "../widgets/TextControls.h" +#include "../windows/GUIClasses.h" +#include "../windows/InfoWindows.h" +#include "../render/CAnimation.h" +#include "../render/Canvas.h" +#include "../render/IImage.h" +#include "../render/IRenderHandler.h" +#include "../render/Graphics.h" + +#include "../../lib/CGeneralTextHandler.h" +#include "../../lib/CConfigHandler.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" + +CMapOverview::CMapOverview(std::string text, ResourcePath resource, ESelectionScreen tabType) + : CWindowObject(BORDERED | RCLICK_POPUP) +{ + + OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; + + pos = Rect(0, 0, 400, 300); + + widget = std::make_shared(text, resource, tabType); + + updateShadow(); + + /* + std::vector> mapLayerImages; + if(renderImage) + mapLayerImages = createMinimaps(ResourcePath(resource.getName(), EResType::MAP), IMAGE_SIZE); + + if(mapLayerImages.size() == 0) + renderImage = false; + + pos = Rect(0, 0, 3 * BORDER + 2 * IMAGE_SIZE, 2000); + + 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(Point(BORDER + 2 * IMAGE_SIZE, label->label->textSize.y)); + }; + drawLabel(); + + 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(ImagePath::builtin("DIBOXBCK"), pos); + updateShadow(); + + drawLabel(); + + if(renderImage) + { + 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 +#ifdef VCMI_MOBILE + moveBy({0, -pos.h / 2}); +#endif + fitToScreen(10); +} + +Canvas CMapOverview::CMapOverviewWidget::createMinimapForLayer(std::unique_ptr & map, int layer) const +{ + 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, 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.isValidPlayer()) + { + color = graphics->playerColors[player.getNum()]; + break; + } + } + + canvas.drawPoint(Point(x, y), color); + } + + return canvas; +} + +std::vector> CMapOverview::CMapOverviewWidget::createMinimaps(ResourcePath resource, Point size) const +{ + std::vector> ret = std::vector>(); + + CMapService mapService; + std::unique_ptr map; + try + { + map = mapService.loadMap(resource); + } + catch (...) + { + return ret; + } + + for(int i = 0; i < (map->twoLevel ? 2 : 1); i++) + { + Canvas canvas = createMinimapForLayer(map, i); + Canvas canvasScaled = Canvas(size); + canvasScaled.drawScaled(canvas, Point(0, 0), size); + std::shared_ptr img = GH.renderHandler().createImage(canvasScaled.getInternalSurface()); + + ret.push_back(img); + } + + return ret; +} + +std::shared_ptr CMapOverview::CMapOverviewWidget::CMapOverviewWidget::buildDrawTransparentRect(const JsonNode & config) const +{ + logGlobal->debug("Building widget drawTransparentRect"); + + auto rect = readRect(config["rect"]); + auto color = readColor(config["color"]); + if(!config["colorLine"].isNull()) + { + auto colorLine = readColor(config["colorLine"]); + return std::make_shared(rect, color, colorLine); + } + return std::make_shared(rect, color); +} + +std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(const JsonNode & config) const +{ + logGlobal->debug("Building widget drawMinimap"); + + auto rect = readRect(config["rect"]); + auto id = config["id"].Integer(); + const std::vector> images = createMinimaps(ResourcePath(resource.getName(), EResType::MAP), Point(rect.w, rect.h)); + + return std::make_shared(images[id], Point(rect.x, rect.y)); +} + +CMapOverview::CMapOverviewWidget::CMapOverviewWidget(std::string text, ResourcePath resource, ESelectionScreen tabType): + InterfaceObjectConfigurable(), resource(resource) +{ + drawPlayerElements = tabType == ESelectionScreen::newGame; + renderImage = tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool(); + + const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json")); + + REGISTER_BUILDER("drawTransparentRect", &CMapOverview::CMapOverviewWidget::buildDrawTransparentRect); + REGISTER_BUILDER("drawMinimap", &CMapOverview::CMapOverviewWidget::buildDrawMinimap); + + build(config); +} \ No newline at end of file diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h new file mode 100644 index 000000000..cd211a87d --- /dev/null +++ b/client/windows/CMapOverview.h @@ -0,0 +1,58 @@ +/* + * CMapOverview.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 + +VCMI_LIB_NAMESPACE_BEGIN +class CMap; +VCMI_LIB_NAMESPACE_END +#include "CWindowObject.h" +#include "../../lib/filesystem/ResourcePath.h" +#include "../gui/InterfaceObjectConfigurable.h" + +class CSlider; +class CLabel; +class CPicture; +class CFilledTexture; +class CTextBox; +class IImage; +class Canvas; +class TransparentFilledRectangle; +enum ESelectionScreen : ui8; + +class CMapOverview : public CWindowObject +{ + //const int IMAGE_SIZE = 169; + //const int BORDER = 30; + + std::shared_ptr backgroundTexture; + std::shared_ptr label; + std::shared_ptr image1; + std::shared_ptr image2; + + class CMapOverviewWidget : public InterfaceObjectConfigurable + { + ResourcePath resource; + + bool drawPlayerElements; + bool renderImage; + Canvas createMinimapForLayer(std::unique_ptr & map, int layer) const; + std::vector> createMinimaps(ResourcePath resource, Point size) const; + + std::shared_ptr buildDrawTransparentRect(const JsonNode & config) const; + std::shared_ptr buildDrawMinimap(const JsonNode & config) const; + public: + CMapOverviewWidget(std::string text, ResourcePath resource, ESelectionScreen tabType); + }; + + std::shared_ptr widget; + +public: + CMapOverview(std::string text, ResourcePath resource, ESelectionScreen tabType); +}; \ No newline at end of file From 79e66c38df63d80bd92940e08eb1f56d4bdcb664 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 17:14:22 +0200 Subject: [PATCH 02/15] layout --- client/lobby/SelectionTab.cpp | 8 +- client/windows/CMapOverview.cpp | 102 +++++++++++++------------ client/windows/CMapOverview.h | 22 +++--- config/widgets/mapOverview.json | 130 ++++++++++++++++++++++++++++++++ 4 files changed, 197 insertions(+), 65 deletions(-) create mode 100644 config/widgets/mapOverview.json diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index 8a3b4b494..c66deb246 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -363,13 +363,7 @@ void SelectionTab::showPopupWindow(const Point & cursorPosition) return; if(!curItems[py]->isFolder) - { - std::string text = boost::str(boost::format("{%1%}\r\n\r\n%2%:\r\n%3%") % curItems[py]->getName() % CGI->generaltexth->translate("vcmi.lobby.filename") % curItems[py]->fullFileURI); - 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, ResourcePath(curItems[py]->fileURI), tabType); - } + GH.windows().createAndPushWindow(curItems[py]->getName(), curItems[py]->fullFileURI, curItems[py]->date, ResourcePath(curItems[py]->fileURI), tabType); else CRClickPopup::createAndPush(curItems[py]->folderName); } diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index 7f05e68b1..3ac103963 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -36,56 +36,19 @@ #include "../../lib/mapping/MapFormat.h" #include "../../lib/TerrainHandler.h" -CMapOverview::CMapOverview(std::string text, ResourcePath resource, ESelectionScreen tabType) - : CWindowObject(BORDERED | RCLICK_POPUP) +CMapOverview::CMapOverview(std::string mapName, std::string fileName, std::string date, ResourcePath resource, ESelectionScreen tabType) + : CWindowObject(BORDERED | RCLICK_POPUP), resource(resource), mapName(mapName), fileName(fileName), date(date), tabType(tabType) { OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; - pos = Rect(0, 0, 400, 300); + const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json")); + pos = Rect(0, 0, config["items"][0]["rect"]["w"].Integer(), config["items"][0]["rect"]["h"].Integer()); - widget = std::make_shared(text, resource, tabType); + widget = std::make_shared(*this); updateShadow(); - /* - std::vector> mapLayerImages; - if(renderImage) - mapLayerImages = createMinimaps(ResourcePath(resource.getName(), EResType::MAP), IMAGE_SIZE); - - if(mapLayerImages.size() == 0) - renderImage = false; - - pos = Rect(0, 0, 3 * BORDER + 2 * IMAGE_SIZE, 2000); - - 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(Point(BORDER + 2 * IMAGE_SIZE, label->label->textSize.y)); - }; - drawLabel(); - - 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(ImagePath::builtin("DIBOXBCK"), pos); - updateShadow(); - - drawLabel(); - - if(renderImage) - { - 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 #ifdef VCMI_MOBILE moveBy({0, -pos.h / 2}); @@ -177,21 +140,66 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(con auto rect = readRect(config["rect"]); auto id = config["id"].Integer(); - const std::vector> images = createMinimaps(ResourcePath(resource.getName(), EResType::MAP), Point(rect.w, rect.h)); + + if(!renderImage) + return nullptr; + + const std::vector> images = createMinimaps(ResourcePath(parent.resource.getName(), EResType::MAP), Point(rect.w, rect.h)); + + if(id >= images.size()) + return nullptr; return std::make_shared(images[id], Point(rect.x, rect.y)); } -CMapOverview::CMapOverviewWidget::CMapOverviewWidget(std::string text, ResourcePath resource, ESelectionScreen tabType): - InterfaceObjectConfigurable(), resource(resource) +std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawPath(const JsonNode & config) const { - drawPlayerElements = tabType == ESelectionScreen::newGame; - renderImage = tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool(); + logGlobal->debug("Building widget drawPath"); + + auto rect = readRect(config["rect"]); + auto font = readFont(config["font"]); + auto alignment = readTextAlignment(config["alignment"]); + auto color = readColor(config["color"]); + + return std::make_shared(parent.fileName, rect, 0, font, alignment, color); +} + +std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawString(const JsonNode & config) const +{ + logGlobal->debug("Building widget drawString"); + + auto font = readFont(config["font"]); + auto alignment = readTextAlignment(config["alignment"]); + auto color = readColor(config["color"]); + std::string text = ""; + if("mapname" == config["text"].String()) + text = parent.mapName; + if("date" == config["text"].String()) + if(parent.date.empty()) + { + //std::time_t time = + } + else + text = parent.date; + auto position = readPosition(config["position"]); + return std::make_shared(position.x, position.y, font, alignment, color, text); +} + +CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): + InterfaceObjectConfigurable(), parent(parent) +{ + drawPlayerElements = parent.tabType == ESelectionScreen::newGame; + renderImage = parent.tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool(); const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json")); REGISTER_BUILDER("drawTransparentRect", &CMapOverview::CMapOverviewWidget::buildDrawTransparentRect); REGISTER_BUILDER("drawMinimap", &CMapOverview::CMapOverviewWidget::buildDrawMinimap); + REGISTER_BUILDER("drawPath", &CMapOverview::CMapOverviewWidget::buildDrawPath); + REGISTER_BUILDER("drawString", &CMapOverview::CMapOverviewWidget::buildDrawString); + + drawPlayerElements = parent.tabType == ESelectionScreen::newGame; + renderImage = parent.tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool(); build(config); } \ No newline at end of file diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h index cd211a87d..782b8b2b6 100644 --- a/client/windows/CMapOverview.h +++ b/client/windows/CMapOverview.h @@ -28,17 +28,9 @@ enum ESelectionScreen : ui8; class CMapOverview : public CWindowObject { - //const int IMAGE_SIZE = 169; - //const int BORDER = 30; - - std::shared_ptr backgroundTexture; - std::shared_ptr label; - std::shared_ptr image1; - std::shared_ptr image2; - class CMapOverviewWidget : public InterfaceObjectConfigurable { - ResourcePath resource; + CMapOverview& parent; bool drawPlayerElements; bool renderImage; @@ -47,12 +39,20 @@ class CMapOverview : public CWindowObject std::shared_ptr buildDrawTransparentRect(const JsonNode & config) const; std::shared_ptr buildDrawMinimap(const JsonNode & config) const; + std::shared_ptr buildDrawPath(const JsonNode & config) const; + std::shared_ptr buildDrawString(const JsonNode & config) const; public: - CMapOverviewWidget(std::string text, ResourcePath resource, ESelectionScreen tabType); + CMapOverviewWidget(CMapOverview& parent); }; std::shared_ptr widget; public: - CMapOverview(std::string text, ResourcePath resource, ESelectionScreen tabType); + ResourcePath resource; + std::string mapName; + std::string fileName; + std::string date; + ESelectionScreen tabType; + + CMapOverview(std::string mapName, std::string fileName, std::string date, ResourcePath resource, ESelectionScreen tabType); }; \ No newline at end of file diff --git a/config/widgets/mapOverview.json b/config/widgets/mapOverview.json new file mode 100644 index 000000000..b626cf878 --- /dev/null +++ b/config/widgets/mapOverview.json @@ -0,0 +1,130 @@ +{ + "items": + [ + { + "name": "background", + "type": "texture", + "image": "DIBOXBCK", + "rect": {"w": 428, "h": 500} + }, + { + "type": "drawTransparentRect", + "rect": {"x": 5, "y": 5, "w": 418, "h": 20}, + "color": [0, 0, 0, 75], + "colorLine": [128, 100, 75, 255] + }, + { + "type": "label", + "font": "medium", + "alignment": "center", + "color": "yellow", + "text": "vcmi.lobby.filename", + "position": {"x": 214, "y": 15} + }, + { + "type": "drawTransparentRect", + "rect": {"x": 5, "y": 30, "w": 418, "h": 20}, + "color": [0, 0, 0, 75], + "colorLine": [128, 100, 75, 255] + }, + { + "type": "drawString", + "font": "small", + "alignment": "center", + "color": "white", + "text": "mapname", + "position": {"x": 214, "y": 40} + }, + { + "type": "drawTransparentRect", + "rect": {"x": 5, "y": 55, "w": 418, "h": 20}, + "color": [0, 0, 0, 75], + "colorLine": [128, 100, 75, 255] + }, + { + "type": "label", + "font": "medium", + "alignment": "center", + "color": "yellow", + "text": "vcmi.lobby.filename", + "position": {"x": 214, "y": 65} + }, + { + "type": "drawTransparentRect", + "rect": {"x": 29, "y": 79, "w": 171, "h": 171}, + "color": [0, 0, 0, 255], + "colorLine": [128, 100, 75, 255] + }, + { + "type": "drawMinimap", + "id": 0, + "rect": {"x": 30, "y": 80, "w": 169, "h": 169} + }, + { + "type": "drawTransparentRect", + "rect": {"x": 228, "y": 79, "w": 171, "h": 171}, + "color": [0, 0, 0, 255], + "colorLine": [128, 100, 75, 255] + }, + { + "type": "drawMinimap", + "id": 1, + "rect": {"x": 229, "y": 80, "w": 169, "h": 169} + }, + { + "type": "drawTransparentRect", + "rect": {"x": 5, "y": 254, "w": 418, "h": 20}, + "color": [0, 0, 0, 75], + "colorLine": [128, 100, 75, 255] + }, + { + "type": "label", + "font": "medium", + "alignment": "center", + "color": "yellow", + "text": "vcmi.lobby.creationDate", + "position": {"x": 214, "y": 264} + }, + { + "type": "drawTransparentRect", + "rect": {"x": 5, "y": 279, "w": 418, "h": 20}, + "color": [0, 0, 0, 75], + "colorLine": [128, 100, 75, 255] + }, + { + "type": "drawString", + "font": "small", + "alignment": "center", + "color": "white", + "text": "date", + "position": {"x": 214, "y": 289} + }, + { + "type": "drawTransparentRect", + "rect": {"x": 5, "y": 309, "w": 418, "h": 20}, + "color": [0, 0, 0, 75], + "colorLine": [128, 100, 75, 255] + }, + { + "type": "label", + "font": "medium", + "alignment": "center", + "color": "yellow", + "text": "vcmi.lobby.filename", + "position": {"x": 214, "y": 319} + }, + { + "type": "drawTransparentRect", + "rect": {"x": 5, "y": 334, "w": 418, "h": 45}, + "color": [0, 0, 0, 75], + "colorLine": [128, 100, 75, 255] + }, + { + "type": "drawPath", + "font": "small", + "alignment": "center", + "color": "white", + "rect": {"x": 10, "y": 339, "w": 408, "h": 35} + } + ] +} From c6adcc40f5bed57b95c8dabbca89961da8dfd173 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 17:56:51 +0200 Subject: [PATCH 03/15] add date; cleanup --- Mods/vcmi/config/vcmi/english.json | 2 ++ Mods/vcmi/config/vcmi/german.json | 4 +++- client/windows/CMapOverview.cpp | 8 +++++++- client/windows/CMapOverview.h | 10 +++++----- config/widgets/mapOverview.json | 6 +++--- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index a14081798..e5a8b3975 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -51,6 +51,8 @@ "vcmi.lobby.filename" : "Filename", "vcmi.lobby.creationDate" : "Creation date", + "vcmi.lobby.scenarioName" : "Scenario name", + "vcmi.lobby.mapPreview" : "Map preview", "vcmi.server.errors.existingProcess" : "Another VCMI server process is running. Please terminate it before starting a new game.", "vcmi.server.errors.modsToEnable" : "{Following mods are required}", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index abe112ebd..3548c4ea6 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -50,6 +50,8 @@ "vcmi.lobby.filename" : "Dateiname", "vcmi.lobby.creationDate" : "Erstellungsdatum", + "vcmi.lobby.scenarioName" : "Szenario-Name", + "vcmi.lobby.mapPreview" : "Kartenvorschau", "vcmi.server.errors.existingProcess" : "Es läuft ein weiterer vcmiserver-Prozess, bitte beendet diesen zuerst", "vcmi.server.errors.modsToEnable" : "{Erforderliche Mods um das Spiel zu laden}", @@ -361,4 +363,4 @@ "core.bonus.WATER_IMMUNITY.description": "Immun gegen alle Zauber der Wasserschule", "core.bonus.WIDE_BREATH.name": "Breiter Atem", "core.bonus.WIDE_BREATH.description": "Breiter Atem-Angriff (mehrere Felder)" -} +} \ No newline at end of file diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index 3ac103963..66b555b22 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -13,6 +13,8 @@ #include "../lobby/SelectionTab.h" +#include + #include "../gui/CGuiHandler.h" #include "../gui/WindowHandler.h" #include "../widgets/CComponent.h" @@ -35,6 +37,7 @@ #include "../../lib/mapping/CMapHeader.h" #include "../../lib/mapping/MapFormat.h" #include "../../lib/TerrainHandler.h" +#include "../../lib/filesystem/Filesystem.h" CMapOverview::CMapOverview(std::string mapName, std::string fileName, std::string date, ResourcePath resource, ESelectionScreen tabType) : CWindowObject(BORDERED | RCLICK_POPUP), resource(resource), mapName(mapName), fileName(fileName), date(date), tabType(tabType) @@ -175,12 +178,15 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawString(const if("mapname" == config["text"].String()) text = parent.mapName; if("date" == config["text"].String()) + { if(parent.date.empty()) { - //std::time_t time = + std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(ResourcePath(parent.resource.getName(), EResType::MAP))); + text = vstd::getFormattedDateTime(time); } else text = parent.date; + } auto position = readPosition(config["position"]); return std::make_shared(position.x, position.y, font, alignment, color, text); } diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h index 782b8b2b6..545ea4bcb 100644 --- a/client/windows/CMapOverview.h +++ b/client/windows/CMapOverview.h @@ -48,11 +48,11 @@ class CMapOverview : public CWindowObject std::shared_ptr widget; public: - ResourcePath resource; - std::string mapName; - std::string fileName; - std::string date; - ESelectionScreen tabType; + const ResourcePath resource; + const std::string mapName; + const std::string fileName; + const std::string date; + const ESelectionScreen tabType; CMapOverview(std::string mapName, std::string fileName, std::string date, ResourcePath resource, ESelectionScreen tabType); }; \ No newline at end of file diff --git a/config/widgets/mapOverview.json b/config/widgets/mapOverview.json index b626cf878..e397d8909 100644 --- a/config/widgets/mapOverview.json +++ b/config/widgets/mapOverview.json @@ -5,7 +5,7 @@ "name": "background", "type": "texture", "image": "DIBOXBCK", - "rect": {"w": 428, "h": 500} + "rect": {"w": 428, "h": 384} }, { "type": "drawTransparentRect", @@ -18,7 +18,7 @@ "font": "medium", "alignment": "center", "color": "yellow", - "text": "vcmi.lobby.filename", + "text": "vcmi.lobby.scenarioName", "position": {"x": 214, "y": 15} }, { @@ -46,7 +46,7 @@ "font": "medium", "alignment": "center", "color": "yellow", - "text": "vcmi.lobby.filename", + "text": "vcmi.lobby.mapPreview", "position": {"x": 214, "y": 65} }, { From 8b835c92538de65b046d2b2f6ddc945d5cf1d0f7 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 20:03:33 +0200 Subject: [PATCH 04/15] load game support --- client/windows/CMapOverview.cpp | 39 ++++++++++++++++++++++++++++----- client/windows/CMapOverview.h | 1 + lib/StartInfo.h | 4 +++- server/CVCMIServer.cpp | 2 ++ 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index 66b555b22..0f2afef00 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -39,6 +39,10 @@ #include "../../lib/TerrainHandler.h" #include "../../lib/filesystem/Filesystem.h" +#include "../../lib/serializer/BinaryDeserializer.h" +#include "../../lib/StartInfo.h" +#include "../../lib/rmg/CMapGenOptions.h" + CMapOverview::CMapOverview(std::string mapName, std::string fileName, std::string date, ResourcePath resource, ESelectionScreen tabType) : CWindowObject(BORDERED | RCLICK_POPUP), resource(resource), mapName(mapName), fileName(fileName), date(date), tabType(tabType) { @@ -110,6 +114,13 @@ std::vector> CMapOverview::CMapOverviewWidget::createMin return ret; } + return createMinimaps(map, size); +} + +std::vector> CMapOverview::CMapOverviewWidget::createMinimaps(std::unique_ptr & map, Point size) const +{ + std::vector> ret = std::vector>(); + for(int i = 0; i < (map->twoLevel ? 2 : 1); i++) { Canvas canvas = createMinimapForLayer(map, i); @@ -147,7 +158,28 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(con if(!renderImage) return nullptr; - const std::vector> images = createMinimaps(ResourcePath(parent.resource.getName(), EResType::MAP), Point(rect.w, rect.h)); + ResourcePath res = ResourcePath(parent.resource.getName(), EResType::MAP); + std::unique_ptr campaignMap = nullptr; + if(parent.tabType != ESelectionScreen::newGame) + { + CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(parent.resource.getName(), EResType::SAVEGAME)), MINIMAL_SERIALIZATION_VERSION); + lf.checkMagicBytes(SAVEGAME_MAGIC); + + std::unique_ptr mapHeader = std::make_unique(); + StartInfo * startInfo; + lf >> *(mapHeader) >> startInfo; + + if(startInfo->campState) + campaignMap = startInfo->campState->getMap(*startInfo->campState->currentScenario()); + res = ResourcePath(startInfo->fileURI, EResType::MAP); + } + + std::vector> images; + if(!campaignMap) + images = createMinimaps(res, Point(rect.w, rect.h)); + else + images = createMinimaps(campaignMap, Point(rect.w, rect.h)); + if(id >= images.size()) return nullptr; @@ -195,7 +227,7 @@ CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): InterfaceObjectConfigurable(), parent(parent) { drawPlayerElements = parent.tabType == ESelectionScreen::newGame; - renderImage = parent.tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool(); + renderImage = settings["lobby"]["mapPreview"].Bool(); const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json")); @@ -204,8 +236,5 @@ CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): REGISTER_BUILDER("drawPath", &CMapOverview::CMapOverviewWidget::buildDrawPath); REGISTER_BUILDER("drawString", &CMapOverview::CMapOverviewWidget::buildDrawString); - drawPlayerElements = parent.tabType == ESelectionScreen::newGame; - renderImage = parent.tabType == ESelectionScreen::newGame && settings["lobby"]["mapPreview"].Bool(); - build(config); } \ No newline at end of file diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h index 545ea4bcb..7c70210d8 100644 --- a/client/windows/CMapOverview.h +++ b/client/windows/CMapOverview.h @@ -36,6 +36,7 @@ class CMapOverview : public CWindowObject bool renderImage; Canvas createMinimapForLayer(std::unique_ptr & map, int layer) const; std::vector> createMinimaps(ResourcePath resource, Point size) const; + std::vector> createMinimaps(std::unique_ptr & map, Point size) const; std::shared_ptr buildDrawTransparentRect(const JsonNode & config) const; std::shared_ptr buildDrawMinimap(const JsonNode & config) const; diff --git a/lib/StartInfo.h b/lib/StartInfo.h index a558c4d32..b4031fa42 100644 --- a/lib/StartInfo.h +++ b/lib/StartInfo.h @@ -102,6 +102,7 @@ struct DLL_LINKAGE StartInfo ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet ui32 mapfileChecksum; //0 if not relevant std::string startTimeIso8601; + std::string fileURI; SimturnsInfo simturnsInfo; TurnTimerInfo turnTimerInfo; std::string mapname; // empty for random map, otherwise name of the map or savegame @@ -127,6 +128,7 @@ struct DLL_LINKAGE StartInfo h & seedPostInit; h & mapfileChecksum; h & startTimeIso8601; + h & fileURI; h & simturnsInfo; h & turnTimerInfo; h & mapname; @@ -135,7 +137,7 @@ struct DLL_LINKAGE StartInfo } StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0), - mapfileChecksum(0), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(0))) + mapfileChecksum(0), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(0))), fileURI("") { } diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 5b3eecdef..3d99c1fbd 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -318,6 +318,7 @@ bool CVCMIServer::prepareToStartGame() case StartInfo::CAMPAIGN: logNetwork->info("Preparing to start new campaign"); si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(0)); + si->fileURI = mi->fileURI; si->campState->setCurrentMap(campaignMap); si->campState->setCurrentMapBonus(campaignBonus); gh->init(si.get(), progressTracking); @@ -326,6 +327,7 @@ bool CVCMIServer::prepareToStartGame() case StartInfo::NEW_GAME: logNetwork->info("Preparing to start new game"); si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(0)); + si->fileURI = mi->fileURI; gh->init(si.get(), progressTracking); break; From 73a05d82e136ed5d3177fe62c2205bbf7890d339 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 20:18:12 +0200 Subject: [PATCH 05/15] fix --- client/VCMI_client.cbp | 2 ++ client/VCMI_client.vcxproj | 2 ++ client/VCMI_client.vcxproj.filters | 6 ++++++ config/widgets/mapOverview.json | 8 ++++---- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/VCMI_client.cbp b/client/VCMI_client.cbp index 57fc618b5..081be52ae 100644 --- a/client/VCMI_client.cbp +++ b/client/VCMI_client.cbp @@ -229,6 +229,8 @@ + + diff --git a/client/VCMI_client.vcxproj b/client/VCMI_client.vcxproj index 3fe7331f9..997bdba6a 100644 --- a/client/VCMI_client.vcxproj +++ b/client/VCMI_client.vcxproj @@ -238,6 +238,7 @@ + @@ -305,6 +306,7 @@ + diff --git a/client/VCMI_client.vcxproj.filters b/client/VCMI_client.vcxproj.filters index 8831d0480..9b717e834 100644 --- a/client/VCMI_client.vcxproj.filters +++ b/client/VCMI_client.vcxproj.filters @@ -25,6 +25,9 @@ windows + + windows + windows @@ -179,6 +182,9 @@ windows + + windows + windows diff --git a/config/widgets/mapOverview.json b/config/widgets/mapOverview.json index e397d8909..0c98d57a5 100644 --- a/config/widgets/mapOverview.json +++ b/config/widgets/mapOverview.json @@ -101,7 +101,7 @@ }, { "type": "drawTransparentRect", - "rect": {"x": 5, "y": 309, "w": 418, "h": 20}, + "rect": {"x": 5, "y": 304, "w": 418, "h": 20}, "color": [0, 0, 0, 75], "colorLine": [128, 100, 75, 255] }, @@ -111,11 +111,11 @@ "alignment": "center", "color": "yellow", "text": "vcmi.lobby.filename", - "position": {"x": 214, "y": 319} + "position": {"x": 214, "y": 314} }, { "type": "drawTransparentRect", - "rect": {"x": 5, "y": 334, "w": 418, "h": 45}, + "rect": {"x": 5, "y": 329, "w": 418, "h": 45}, "color": [0, 0, 0, 75], "colorLine": [128, 100, 75, 255] }, @@ -124,7 +124,7 @@ "font": "small", "alignment": "center", "color": "white", - "rect": {"x": 10, "y": 339, "w": 408, "h": 35} + "rect": {"x": 10, "y": 334, "w": 408, "h": 35} } ] } From 2eb4413978e65f1f70d5ad15a525363fa08b6fb2 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 20:44:46 +0200 Subject: [PATCH 06/15] fix height --- config/widgets/mapOverview.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/widgets/mapOverview.json b/config/widgets/mapOverview.json index 0c98d57a5..8ce7a2b97 100644 --- a/config/widgets/mapOverview.json +++ b/config/widgets/mapOverview.json @@ -5,7 +5,7 @@ "name": "background", "type": "texture", "image": "DIBOXBCK", - "rect": {"w": 428, "h": 384} + "rect": {"w": 428, "h": 379} }, { "type": "drawTransparentRect", From 61aae7bccc0c892b4a25d644ca74cea2ec37e0ab Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 22:49:22 +0200 Subject: [PATCH 07/15] code review --- client/gui/InterfaceObjectConfigurable.cpp | 29 ++++++++ client/gui/InterfaceObjectConfigurable.h | 4 ++ client/windows/CMapOverview.cpp | 82 +++++++--------------- client/windows/CMapOverview.h | 7 +- config/widgets/mapOverview.json | 32 +++++---- 5 files changed, 77 insertions(+), 77 deletions(-) diff --git a/client/gui/InterfaceObjectConfigurable.cpp b/client/gui/InterfaceObjectConfigurable.cpp index 3a1fd45cb..24d20d3fc 100644 --- a/client/gui/InterfaceObjectConfigurable.cpp +++ b/client/gui/InterfaceObjectConfigurable.cpp @@ -56,6 +56,8 @@ InterfaceObjectConfigurable::InterfaceObjectConfigurable(int used, Point offset) REGISTER_BUILDER("layout", &InterfaceObjectConfigurable::buildLayout); REGISTER_BUILDER("comboBox", &InterfaceObjectConfigurable::buildComboBox); REGISTER_BUILDER("textInput", &InterfaceObjectConfigurable::buildTextInput); + REGISTER_BUILDER("transparentFilledRectangle", &InterfaceObjectConfigurable::buildTransparentFilledRectangle); + REGISTER_BUILDER("textBox", &InterfaceObjectConfigurable::buildTextBox); } void InterfaceObjectConfigurable::registerBuilder(const std::string & type, BuilderFunction f) @@ -684,6 +686,33 @@ std::shared_ptr InterfaceObjectConfigurable::buildAnimation(const return anim; } +std::shared_ptr InterfaceObjectConfigurable::buildTransparentFilledRectangle(const JsonNode & config) const +{ + logGlobal->debug("Building widget TransparentFilledRectangle"); + + auto rect = readRect(config["rect"]); + auto color = readColor(config["color"]); + if(!config["colorLine"].isNull()) + { + auto colorLine = readColor(config["colorLine"]); + return std::make_shared(rect, color, colorLine); + } + return std::make_shared(rect, color); +} + +std::shared_ptr InterfaceObjectConfigurable::buildTextBox(const JsonNode & config) const +{ + logGlobal->debug("Building widget CTextBox"); + + auto rect = readRect(config["rect"]); + auto font = readFont(config["font"]); + auto alignment = readTextAlignment(config["alignment"]); + auto color = readColor(config["color"]); + auto text = readText(config["text"]); + + return std::make_shared(text, rect, 0, font, alignment, color); +} + std::shared_ptr InterfaceObjectConfigurable::buildWidget(JsonNode config) const { assert(!config.isNull()); diff --git a/client/gui/InterfaceObjectConfigurable.h b/client/gui/InterfaceObjectConfigurable.h index 30b96bfb4..cc812299e 100644 --- a/client/gui/InterfaceObjectConfigurable.h +++ b/client/gui/InterfaceObjectConfigurable.h @@ -29,6 +29,8 @@ class CShowableAnim; class CFilledTexture; class ComboBox; class CTextInput; +class TransparentFilledRectangle; +class CTextBox; #define REGISTER_BUILDER(type, method) registerBuilder(type, std::bind(method, this, std::placeholders::_1)) @@ -105,6 +107,8 @@ protected: std::shared_ptr buildLayout(const JsonNode &); std::shared_ptr buildComboBox(const JsonNode &); std::shared_ptr buildTextInput(const JsonNode &) const; + std::shared_ptr buildTransparentFilledRectangle(const JsonNode & config) const; + std::shared_ptr buildTextBox(const JsonNode & config) const; //composite widgets std::shared_ptr buildWidget(JsonNode config) const; diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index 0f2afef00..bf4d893de 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -134,20 +134,6 @@ std::vector> CMapOverview::CMapOverviewWidget::createMin return ret; } -std::shared_ptr CMapOverview::CMapOverviewWidget::CMapOverviewWidget::buildDrawTransparentRect(const JsonNode & config) const -{ - logGlobal->debug("Building widget drawTransparentRect"); - - auto rect = readRect(config["rect"]); - auto color = readColor(config["color"]); - if(!config["colorLine"].isNull()) - { - auto colorLine = readColor(config["colorLine"]); - return std::make_shared(rect, color, colorLine); - } - return std::make_shared(rect, color); -} - std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(const JsonNode & config) const { logGlobal->debug("Building widget drawMinimap"); @@ -158,11 +144,11 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(con if(!renderImage) return nullptr; - ResourcePath res = ResourcePath(parent.resource.getName(), EResType::MAP); + ResourcePath res = ResourcePath(p.resource.getName(), EResType::MAP); std::unique_ptr campaignMap = nullptr; - if(parent.tabType != ESelectionScreen::newGame) + if(p.tabType != ESelectionScreen::newGame) { - CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(parent.resource.getName(), EResType::SAVEGAME)), MINIMAL_SERIALIZATION_VERSION); + CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getName(), EResType::SAVEGAME)), MINIMAL_SERIALIZATION_VERSION); lf.checkMagicBytes(SAVEGAME_MAGIC); std::unique_ptr mapHeader = std::make_unique(); @@ -187,54 +173,34 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(con return std::make_shared(images[id], Point(rect.x, rect.y)); } -std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawPath(const JsonNode & config) const -{ - logGlobal->debug("Building widget drawPath"); - - auto rect = readRect(config["rect"]); - auto font = readFont(config["font"]); - auto alignment = readTextAlignment(config["alignment"]); - auto color = readColor(config["color"]); - - return std::make_shared(parent.fileName, rect, 0, font, alignment, color); -} - -std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawString(const JsonNode & config) const -{ - logGlobal->debug("Building widget drawString"); - - auto font = readFont(config["font"]); - auto alignment = readTextAlignment(config["alignment"]); - auto color = readColor(config["color"]); - std::string text = ""; - if("mapname" == config["text"].String()) - text = parent.mapName; - if("date" == config["text"].String()) - { - if(parent.date.empty()) - { - std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(ResourcePath(parent.resource.getName(), EResType::MAP))); - text = vstd::getFormattedDateTime(time); - } - else - text = parent.date; - } - auto position = readPosition(config["position"]); - return std::make_shared(position.x, position.y, font, alignment, color, text); -} - CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): - InterfaceObjectConfigurable(), parent(parent) + InterfaceObjectConfigurable(), p(parent) { - drawPlayerElements = parent.tabType == ESelectionScreen::newGame; + drawPlayerElements = p.tabType == ESelectionScreen::newGame; renderImage = settings["lobby"]["mapPreview"].Bool(); const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json")); - REGISTER_BUILDER("drawTransparentRect", &CMapOverview::CMapOverviewWidget::buildDrawTransparentRect); REGISTER_BUILDER("drawMinimap", &CMapOverview::CMapOverviewWidget::buildDrawMinimap); - REGISTER_BUILDER("drawPath", &CMapOverview::CMapOverviewWidget::buildDrawPath); - REGISTER_BUILDER("drawString", &CMapOverview::CMapOverviewWidget::buildDrawString); build(config); + + if(auto w = widget("fileName")) + { + w->setText(p.fileName); + } + if(auto w = widget("mapName")) + { + w->setText(p.mapName); + } + if(auto w = widget("date")) + { + if(p.date.empty()) + { + std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getName(), EResType::MAP))); + w->setText(vstd::getFormattedDateTime(time)); + } + else + w->setText(p.date); + } } \ No newline at end of file diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h index 7c70210d8..0628852d7 100644 --- a/client/windows/CMapOverview.h +++ b/client/windows/CMapOverview.h @@ -30,7 +30,7 @@ class CMapOverview : public CWindowObject { class CMapOverviewWidget : public InterfaceObjectConfigurable { - CMapOverview& parent; + CMapOverview& p; bool drawPlayerElements; bool renderImage; @@ -38,12 +38,9 @@ class CMapOverview : public CWindowObject std::vector> createMinimaps(ResourcePath resource, Point size) const; std::vector> createMinimaps(std::unique_ptr & map, Point size) const; - std::shared_ptr buildDrawTransparentRect(const JsonNode & config) const; std::shared_ptr buildDrawMinimap(const JsonNode & config) const; - std::shared_ptr buildDrawPath(const JsonNode & config) const; - std::shared_ptr buildDrawString(const JsonNode & config) const; public: - CMapOverviewWidget(CMapOverview& parent); + CMapOverviewWidget(CMapOverview& p); }; std::shared_ptr widget; diff --git a/config/widgets/mapOverview.json b/config/widgets/mapOverview.json index 8ce7a2b97..bed9130f5 100644 --- a/config/widgets/mapOverview.json +++ b/config/widgets/mapOverview.json @@ -8,7 +8,7 @@ "rect": {"w": 428, "h": 379} }, { - "type": "drawTransparentRect", + "type": "transparentFilledRectangle", "rect": {"x": 5, "y": 5, "w": 418, "h": 20}, "color": [0, 0, 0, 75], "colorLine": [128, 100, 75, 255] @@ -22,21 +22,22 @@ "position": {"x": 214, "y": 15} }, { - "type": "drawTransparentRect", + "type": "transparentFilledRectangle", "rect": {"x": 5, "y": 30, "w": 418, "h": 20}, "color": [0, 0, 0, 75], "colorLine": [128, 100, 75, 255] }, { - "type": "drawString", + "type": "label", + "name": "mapName", "font": "small", "alignment": "center", "color": "white", - "text": "mapname", + "text": "", "position": {"x": 214, "y": 40} }, { - "type": "drawTransparentRect", + "type": "transparentFilledRectangle", "rect": {"x": 5, "y": 55, "w": 418, "h": 20}, "color": [0, 0, 0, 75], "colorLine": [128, 100, 75, 255] @@ -50,7 +51,7 @@ "position": {"x": 214, "y": 65} }, { - "type": "drawTransparentRect", + "type": "transparentFilledRectangle", "rect": {"x": 29, "y": 79, "w": 171, "h": 171}, "color": [0, 0, 0, 255], "colorLine": [128, 100, 75, 255] @@ -61,7 +62,7 @@ "rect": {"x": 30, "y": 80, "w": 169, "h": 169} }, { - "type": "drawTransparentRect", + "type": "transparentFilledRectangle", "rect": {"x": 228, "y": 79, "w": 171, "h": 171}, "color": [0, 0, 0, 255], "colorLine": [128, 100, 75, 255] @@ -72,7 +73,7 @@ "rect": {"x": 229, "y": 80, "w": 169, "h": 169} }, { - "type": "drawTransparentRect", + "type": "transparentFilledRectangle", "rect": {"x": 5, "y": 254, "w": 418, "h": 20}, "color": [0, 0, 0, 75], "colorLine": [128, 100, 75, 255] @@ -86,21 +87,22 @@ "position": {"x": 214, "y": 264} }, { - "type": "drawTransparentRect", + "type": "transparentFilledRectangle", "rect": {"x": 5, "y": 279, "w": 418, "h": 20}, "color": [0, 0, 0, 75], "colorLine": [128, 100, 75, 255] }, { - "type": "drawString", + "type": "label", + "name": "date", "font": "small", "alignment": "center", "color": "white", - "text": "date", + "text": "", "position": {"x": 214, "y": 289} }, { - "type": "drawTransparentRect", + "type": "transparentFilledRectangle", "rect": {"x": 5, "y": 304, "w": 418, "h": 20}, "color": [0, 0, 0, 75], "colorLine": [128, 100, 75, 255] @@ -114,16 +116,18 @@ "position": {"x": 214, "y": 314} }, { - "type": "drawTransparentRect", + "type": "transparentFilledRectangle", "rect": {"x": 5, "y": 329, "w": 418, "h": 45}, "color": [0, 0, 0, 75], "colorLine": [128, 100, 75, 255] }, { - "type": "drawPath", + "type": "textBox", + "name": "fileName", "font": "small", "alignment": "center", "color": "white", + "text": "", "rect": {"x": 10, "y": 334, "w": 408, "h": 35} } ] From 58dfc55ca3314cfbbc5b017a427233b7b20d9256 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 23:50:27 +0200 Subject: [PATCH 08/15] only calc minimaps once --- client/windows/CMapOverview.cpp | 55 ++++++++++++++------------------- client/windows/CMapOverview.h | 6 ++-- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index bf4d893de..7fdad167e 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -99,9 +99,9 @@ Canvas CMapOverview::CMapOverviewWidget::createMinimapForLayer(std::unique_ptr> CMapOverview::CMapOverviewWidget::createMinimaps(ResourcePath resource, Point size) const +std::vector CMapOverview::CMapOverviewWidget::createMinimaps(ResourcePath resource) const { - std::vector> ret = std::vector>(); + std::vector ret = std::vector(); CMapService mapService; std::unique_ptr map; @@ -114,22 +114,15 @@ std::vector> CMapOverview::CMapOverviewWidget::createMin return ret; } - return createMinimaps(map, size); + return createMinimaps(map); } -std::vector> CMapOverview::CMapOverviewWidget::createMinimaps(std::unique_ptr & map, Point size) const +std::vector CMapOverview::CMapOverviewWidget::createMinimaps(std::unique_ptr & map) const { - std::vector> ret = std::vector>(); + std::vector ret = std::vector(); for(int i = 0; i < (map->twoLevel ? 2 : 1); i++) - { - Canvas canvas = createMinimapForLayer(map, i); - Canvas canvasScaled = Canvas(size); - canvasScaled.drawScaled(canvas, Point(0, 0), size); - std::shared_ptr img = GH.renderHandler().createImage(canvasScaled.getInternalSurface()); - - ret.push_back(img); - } + ret.push_back(createMinimapForLayer(map, i)); return ret; } @@ -141,9 +134,23 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(con auto rect = readRect(config["rect"]); auto id = config["id"].Integer(); - if(!renderImage) + if(id >= minimaps.size()) return nullptr; + Canvas canvasScaled = Canvas(Point(rect.w, rect.h)); + canvasScaled.drawScaled(minimaps[id], Point(0, 0), Point(rect.w, rect.h)); + std::shared_ptr img = GH.renderHandler().createImage(canvasScaled.getInternalSurface()); + + return std::make_shared(img, Point(rect.x, rect.y)); +} + +CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): + InterfaceObjectConfigurable(), p(parent) +{ + drawPlayerElements = p.tabType == ESelectionScreen::newGame; + renderImage = settings["lobby"]["mapPreview"].Bool(); + + // create minimaps ResourcePath res = ResourcePath(p.resource.getName(), EResType::MAP); std::unique_ptr campaignMap = nullptr; if(p.tabType != ESelectionScreen::newGame) @@ -159,26 +166,12 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(con campaignMap = startInfo->campState->getMap(*startInfo->campState->currentScenario()); res = ResourcePath(startInfo->fileURI, EResType::MAP); } - - std::vector> images; if(!campaignMap) - images = createMinimaps(res, Point(rect.w, rect.h)); + minimaps = createMinimaps(res); else - images = createMinimaps(campaignMap, Point(rect.w, rect.h)); - - - if(id >= images.size()) - return nullptr; - - return std::make_shared(images[id], Point(rect.x, rect.y)); -} - -CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): - InterfaceObjectConfigurable(), p(parent) -{ - drawPlayerElements = p.tabType == ESelectionScreen::newGame; - renderImage = settings["lobby"]["mapPreview"].Bool(); + minimaps = createMinimaps(campaignMap); + // config const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json")); REGISTER_BUILDER("drawMinimap", &CMapOverview::CMapOverviewWidget::buildDrawMinimap); diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h index 0628852d7..c9d4197f9 100644 --- a/client/windows/CMapOverview.h +++ b/client/windows/CMapOverview.h @@ -34,9 +34,11 @@ class CMapOverview : public CWindowObject bool drawPlayerElements; bool renderImage; + std::vector minimaps; + Canvas createMinimapForLayer(std::unique_ptr & map, int layer) const; - std::vector> createMinimaps(ResourcePath resource, Point size) const; - std::vector> createMinimaps(std::unique_ptr & map, Point size) const; + std::vector createMinimaps(ResourcePath resource) const; + std::vector createMinimaps(std::unique_ptr & map) const; std::shared_ptr buildDrawMinimap(const JsonNode & config) const; public: From 182d762135a0eea463e9406d77c59dc84f8dee56 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Sep 2023 23:58:49 +0200 Subject: [PATCH 09/15] docs --- docs/modders/Configurable_Widgets.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/modders/Configurable_Widgets.md b/docs/modders/Configurable_Widgets.md index d13af3a64..9d3234e10 100644 --- a/docs/modders/Configurable_Widgets.md +++ b/docs/modders/Configurable_Widgets.md @@ -517,6 +517,22 @@ Configurable object has following structure: `"text"`: [text](#text), +### TextBox + +`"type": "textBox"` + +`"name": "string"` optional, object name + +`"font"`: [font](#font) + +`"alignment"`: [alignment](#text-alignment), + +`"color"`: [color](#color), + +`"text"`: [text](#text), + +`"rect"`: [rect](#rect) + ### Picture `"type": "picture"` @@ -559,6 +575,18 @@ Filling area with texture `"rect"`: [rect](#rect) +### TransparentFilledRectangle + +`"type": "transparentFilledRectangle"` + +`"name": "string"` optional, object name + +`"color"`: [color](#color) fill color of rectangle (supports transparency) + +`"colorLine"`: [color](#color) optional, 1px border color + +`"rect"`: [rect](#rect) + ### Animation `"type": "animation"` From 65c21064b5620fe72caa8e1c7c7c2e19e8209c9c Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 1 Oct 2023 00:18:25 +0200 Subject: [PATCH 10/15] added var --- client/windows/CMapOverview.cpp | 46 ++++++++++++++++----------------- client/windows/CMapOverview.h | 1 - config/widgets/mapOverview.json | 7 ++++- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index 7fdad167e..1a154ac2b 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -148,32 +148,32 @@ CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): InterfaceObjectConfigurable(), p(parent) { drawPlayerElements = p.tabType == ESelectionScreen::newGame; - renderImage = settings["lobby"]["mapPreview"].Bool(); - // create minimaps - ResourcePath res = ResourcePath(p.resource.getName(), EResType::MAP); - std::unique_ptr campaignMap = nullptr; - if(p.tabType != ESelectionScreen::newGame) - { - CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getName(), EResType::SAVEGAME)), MINIMAL_SERIALIZATION_VERSION); - lf.checkMagicBytes(SAVEGAME_MAGIC); - - std::unique_ptr mapHeader = std::make_unique(); - StartInfo * startInfo; - lf >> *(mapHeader) >> startInfo; - - if(startInfo->campState) - campaignMap = startInfo->campState->getMap(*startInfo->campState->currentScenario()); - res = ResourcePath(startInfo->fileURI, EResType::MAP); - } - if(!campaignMap) - minimaps = createMinimaps(res); - else - minimaps = createMinimaps(campaignMap); - - // config const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json")); + if(settings["lobby"]["mapPreview"].Bool()) + { + ResourcePath res = ResourcePath(p.resource.getName(), EResType::MAP); + std::unique_ptr campaignMap = nullptr; + if(p.tabType != ESelectionScreen::newGame && config["variables"]["mapPreviewForSaves"].Bool()) + { + CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getName(), EResType::SAVEGAME)), MINIMAL_SERIALIZATION_VERSION); + lf.checkMagicBytes(SAVEGAME_MAGIC); + + std::unique_ptr mapHeader = std::make_unique(); + StartInfo * startInfo; + lf >> *(mapHeader) >> startInfo; + + if(startInfo->campState) + campaignMap = startInfo->campState->getMap(*startInfo->campState->currentScenario()); + res = ResourcePath(startInfo->fileURI, EResType::MAP); + } + if(!campaignMap) + minimaps = createMinimaps(res); + else + minimaps = createMinimaps(campaignMap); + } + REGISTER_BUILDER("drawMinimap", &CMapOverview::CMapOverviewWidget::buildDrawMinimap); build(config); diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h index c9d4197f9..872e35292 100644 --- a/client/windows/CMapOverview.h +++ b/client/windows/CMapOverview.h @@ -33,7 +33,6 @@ class CMapOverview : public CWindowObject CMapOverview& p; bool drawPlayerElements; - bool renderImage; std::vector minimaps; Canvas createMinimapForLayer(std::unique_ptr & map, int layer) const; diff --git a/config/widgets/mapOverview.json b/config/widgets/mapOverview.json index bed9130f5..d28c2cfc2 100644 --- a/config/widgets/mapOverview.json +++ b/config/widgets/mapOverview.json @@ -130,5 +130,10 @@ "text": "", "rect": {"x": 10, "y": 334, "w": 408, "h": 35} } - ] + ], + + "variables": + { + "mapPreviewForSaves": true + } } From 648a37310fc3e50e6f4470d0da9964f2a1d9ab3a Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 1 Oct 2023 00:35:11 +0200 Subject: [PATCH 11/15] description --- Mods/vcmi/config/vcmi/english.json | 2 ++ Mods/vcmi/config/vcmi/german.json | 2 ++ client/windows/CMapOverview.cpp | 5 +++++ config/widgets/mapOverview.json | 17 +++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index e5a8b3975..a49161520 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -53,6 +53,8 @@ "vcmi.lobby.creationDate" : "Creation date", "vcmi.lobby.scenarioName" : "Scenario name", "vcmi.lobby.mapPreview" : "Map preview", + "vcmi.lobby.noPreview" : "no preview", + "vcmi.lobby.noUnderground" : "no underground", "vcmi.server.errors.existingProcess" : "Another VCMI server process is running. Please terminate it before starting a new game.", "vcmi.server.errors.modsToEnable" : "{Following mods are required}", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index 3548c4ea6..cc35abdb9 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -52,6 +52,8 @@ "vcmi.lobby.creationDate" : "Erstellungsdatum", "vcmi.lobby.scenarioName" : "Szenario-Name", "vcmi.lobby.mapPreview" : "Kartenvorschau", + "vcmi.lobby.noPreview" : "Keine Vorschau", + "vcmi.lobby.noUnderground" : "Kein Untergrund", "vcmi.server.errors.existingProcess" : "Es läuft ein weiterer vcmiserver-Prozess, bitte beendet diesen zuerst", "vcmi.server.errors.modsToEnable" : "{Erforderliche Mods um das Spiel zu laden}", diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index 1a154ac2b..3e1aa5847 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -196,4 +196,9 @@ CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): else w->setText(p.date); } + if(auto w = widget("noUnderground")) + { + if(minimaps.size() == 0) + w->setText(""); + } } \ No newline at end of file diff --git a/config/widgets/mapOverview.json b/config/widgets/mapOverview.json index d28c2cfc2..c4e246c8a 100644 --- a/config/widgets/mapOverview.json +++ b/config/widgets/mapOverview.json @@ -56,6 +56,14 @@ "color": [0, 0, 0, 255], "colorLine": [128, 100, 75, 255] }, + { + "type": "label", + "font": "small", + "alignment": "center", + "color": "white", + "text": "vcmi.lobby.noPreview", + "position": {"x": 114, "y": 164} + }, { "type": "drawMinimap", "id": 0, @@ -67,6 +75,15 @@ "color": [0, 0, 0, 255], "colorLine": [128, 100, 75, 255] }, + { + "type": "label", + "name": "noUnderground", + "font": "small", + "alignment": "center", + "color": "white", + "text": "vcmi.lobby.noUnderground", + "position": {"x": 313, "y": 164} + }, { "type": "drawMinimap", "id": 1, From 23b8a321f6a8732ee552d4ef4970af3caa8ac7d4 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 1 Oct 2023 00:46:29 +0200 Subject: [PATCH 12/15] file ending --- Mods/vcmi/config/vcmi/german.json | 2 +- client/windows/CMapOverview.cpp | 2 +- client/windows/CMapOverview.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index cc35abdb9..0afd45188 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -365,4 +365,4 @@ "core.bonus.WATER_IMMUNITY.description": "Immun gegen alle Zauber der Wasserschule", "core.bonus.WIDE_BREATH.name": "Breiter Atem", "core.bonus.WIDE_BREATH.description": "Breiter Atem-Angriff (mehrere Felder)" -} \ No newline at end of file +} diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index 3e1aa5847..e0f7fb58c 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -201,4 +201,4 @@ CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): if(minimaps.size() == 0) w->setText(""); } -} \ No newline at end of file +} diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h index 872e35292..5c9364508 100644 --- a/client/windows/CMapOverview.h +++ b/client/windows/CMapOverview.h @@ -54,4 +54,4 @@ public: const ESelectionScreen tabType; CMapOverview(std::string mapName, std::string fileName, std::string date, ResourcePath resource, ESelectionScreen tabType); -}; \ No newline at end of file +}; From 7f4361eb10f2057a58683108e47f5203bbb72ca4 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 1 Oct 2023 01:11:11 +0200 Subject: [PATCH 13/15] name -> path --- Mods/vcmi/config/vcmi/czech.json | 2 +- Mods/vcmi/config/vcmi/english.json | 2 +- Mods/vcmi/config/vcmi/german.json | 2 +- Mods/vcmi/config/vcmi/polish.json | 2 +- Mods/vcmi/config/vcmi/ukrainian.json | 2 +- Mods/vcmi/config/vcmi/vietnamese.json | 2 +- config/widgets/mapOverview.json | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Mods/vcmi/config/vcmi/czech.json b/Mods/vcmi/config/vcmi/czech.json index 1e9f8b2e8..f1c561b97 100644 --- a/Mods/vcmi/config/vcmi/czech.json +++ b/Mods/vcmi/config/vcmi/czech.json @@ -44,7 +44,7 @@ "vcmi.mainMenu.joinTCP" : "Připojit se do hry TCP/IP", "vcmi.mainMenu.playerName" : "Hráč", - "vcmi.lobby.filename" : "Název souboru", + "vcmi.lobby.filepath" : "Název souboru", "vcmi.lobby.creationDate" : "Datum vytvoření", "vcmi.server.errors.existingProcess" : "Již běží jiný server VCMI. Prosím, ukončete ho před startem nové hry.", diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index a49161520..c5cba2fa1 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -49,7 +49,7 @@ "vcmi.mainMenu.joinTCP" : "Join TCP/IP game", "vcmi.mainMenu.playerName" : "Player", - "vcmi.lobby.filename" : "Filename", + "vcmi.lobby.filepath" : "File path", "vcmi.lobby.creationDate" : "Creation date", "vcmi.lobby.scenarioName" : "Scenario name", "vcmi.lobby.mapPreview" : "Map preview", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index 0afd45188..121deacb2 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -48,7 +48,7 @@ "vcmi.mainMenu.joinTCP" : "Trete TCP/IP Spiel bei", "vcmi.mainMenu.playerName" : "Spieler", - "vcmi.lobby.filename" : "Dateiname", + "vcmi.lobby.filepath" : "Dateipfad", "vcmi.lobby.creationDate" : "Erstellungsdatum", "vcmi.lobby.scenarioName" : "Szenario-Name", "vcmi.lobby.mapPreview" : "Kartenvorschau", diff --git a/Mods/vcmi/config/vcmi/polish.json b/Mods/vcmi/config/vcmi/polish.json index 51c96dac4..1526e83e3 100644 --- a/Mods/vcmi/config/vcmi/polish.json +++ b/Mods/vcmi/config/vcmi/polish.json @@ -43,7 +43,7 @@ "vcmi.mainMenu.joinTCP" : "Dołącz do gry TCP/IP", "vcmi.mainMenu.playerName" : "Gracz", - "vcmi.lobby.filename" : "Nazwa pliku", + "vcmi.lobby.filepath" : "Nazwa pliku", "vcmi.lobby.creationDate" : "Data utworzenia", "vcmi.server.errors.existingProcess" : "Inny proces 'vcmiserver' został już uruchomiony, zakończ go nim przejdziesz dalej", diff --git a/Mods/vcmi/config/vcmi/ukrainian.json b/Mods/vcmi/config/vcmi/ukrainian.json index 4f5228821..9773fc7af 100644 --- a/Mods/vcmi/config/vcmi/ukrainian.json +++ b/Mods/vcmi/config/vcmi/ukrainian.json @@ -44,7 +44,7 @@ "vcmi.mainMenu.joinTCP" : "Приєднатися до TCP/IP гри", "vcmi.mainMenu.playerName" : "Гравець", - "vcmi.lobby.filename" : "Назва файлу", + "vcmi.lobby.filepath" : "Назва файлу", "vcmi.lobby.creationDate" : "Дата створення", "vcmi.server.errors.existingProcess" : "Працює інший процес vcmiserver, будь ласка, спочатку завершіть його", diff --git a/Mods/vcmi/config/vcmi/vietnamese.json b/Mods/vcmi/config/vcmi/vietnamese.json index 9926fce10..890e699d1 100644 --- a/Mods/vcmi/config/vcmi/vietnamese.json +++ b/Mods/vcmi/config/vcmi/vietnamese.json @@ -50,7 +50,7 @@ "vcmi.mainMenu.joinTCP": "Tham gia TCP/IP", "vcmi.mainMenu.playerName": "Người chơi", - "vcmi.lobby.filename": "Tên tập tin", + "vcmi.lobby.filepath": "Tên tập tin", "vcmi.lobby.creationDate": "Ngày tạo", "vcmi.server.errors.existingProcess": "1 chương trình VCMI khác đang chạy. Tắt nó trước khi mở cái mới", diff --git a/config/widgets/mapOverview.json b/config/widgets/mapOverview.json index c4e246c8a..d451afda4 100644 --- a/config/widgets/mapOverview.json +++ b/config/widgets/mapOverview.json @@ -129,7 +129,7 @@ "font": "medium", "alignment": "center", "color": "yellow", - "text": "vcmi.lobby.filename", + "text": "vcmi.lobby.filepath", "position": {"x": 214, "y": 314} }, { From cbd014ac88031ae6d5ab6b310001910462fa0174 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 1 Oct 2023 17:35:56 +0200 Subject: [PATCH 14/15] code review --- client/windows/CMapOverview.cpp | 15 ++++++++------- client/windows/CMapOverview.h | 34 +++++++++++++++++---------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index e0f7fb58c..4db99c772 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -63,7 +63,7 @@ CMapOverview::CMapOverview(std::string mapName, std::string fileName, std::strin fitToScreen(10); } -Canvas CMapOverview::CMapOverviewWidget::createMinimapForLayer(std::unique_ptr & map, int layer) const +Canvas CMapOverviewWidget::createMinimapForLayer(std::unique_ptr & map, int layer) const { Canvas canvas = Canvas(Point(map->width, map->height)); @@ -99,7 +99,7 @@ Canvas CMapOverview::CMapOverviewWidget::createMinimapForLayer(std::unique_ptr CMapOverview::CMapOverviewWidget::createMinimaps(ResourcePath resource) const +std::vector CMapOverviewWidget::createMinimaps(ResourcePath resource) const { std::vector ret = std::vector(); @@ -109,15 +109,16 @@ std::vector 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 CMapOverview::CMapOverviewWidget::createMinimaps(std::unique_ptr & map) const +std::vector CMapOverviewWidget::createMinimaps(std::unique_ptr & map) const { std::vector ret = std::vector(); @@ -127,7 +128,7 @@ std::vector CMapOverview::CMapOverviewWidget::createMinimaps(std::unique return ret; } -std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(const JsonNode & config) const +std::shared_ptr CMapOverviewWidget::buildDrawMinimap(const JsonNode & config) const { logGlobal->debug("Building widget drawMinimap"); @@ -144,7 +145,7 @@ std::shared_ptr CMapOverview::CMapOverviewWidget::buildDrawMinimap(con return std::make_shared(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); diff --git a/client/windows/CMapOverview.h b/client/windows/CMapOverview.h index 5c9364508..1602e80c3 100644 --- a/client/windows/CMapOverview.h +++ b/client/windows/CMapOverview.h @@ -26,24 +26,26 @@ class Canvas; class TransparentFilledRectangle; enum ESelectionScreen : ui8; +class CMapOverview; + +class CMapOverviewWidget : public InterfaceObjectConfigurable +{ + CMapOverview& p; + + bool drawPlayerElements; + std::vector minimaps; + + Canvas createMinimapForLayer(std::unique_ptr & map, int layer) const; + std::vector createMinimaps(ResourcePath resource) const; + std::vector createMinimaps(std::unique_ptr & map) const; + + std::shared_ptr buildDrawMinimap(const JsonNode & config) const; +public: + CMapOverviewWidget(CMapOverview& p); +}; + class CMapOverview : public CWindowObject { - class CMapOverviewWidget : public InterfaceObjectConfigurable - { - CMapOverview& p; - - bool drawPlayerElements; - std::vector minimaps; - - Canvas createMinimapForLayer(std::unique_ptr & map, int layer) const; - std::vector createMinimaps(ResourcePath resource) const; - std::vector createMinimaps(std::unique_ptr & map) const; - - std::shared_ptr buildDrawMinimap(const JsonNode & config) const; - public: - CMapOverviewWidget(CMapOverview& p); - }; - std::shared_ptr widget; public: From 12ca3ea0ec3373e172d1dd44a7553ffe007a63f7 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 1 Oct 2023 19:44:04 +0200 Subject: [PATCH 15/15] pos from texture --- client/windows/CMapOverview.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/windows/CMapOverview.cpp b/client/windows/CMapOverview.cpp index 4db99c772..ffa7aeb03 100644 --- a/client/windows/CMapOverview.cpp +++ b/client/windows/CMapOverview.cpp @@ -49,9 +49,6 @@ CMapOverview::CMapOverview(std::string mapName, std::string fileName, std::strin OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; - const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json")); - pos = Rect(0, 0, config["items"][0]["rect"]["w"].Integer(), config["items"][0]["rect"]["h"].Integer()); - widget = std::make_shared(*this); updateShadow(); @@ -179,6 +176,10 @@ CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent): build(config); + if(auto w = widget("background")) + { + p.pos = w->pos; + } if(auto w = widget("fileName")) { w->setText(p.fileName);