Laserlicht 2 年之前
父節點
當前提交
79e66c38df
共有 4 個文件被更改,包括 197 次插入65 次删除
  1. 1 7
      client/lobby/SelectionTab.cpp
  2. 55 47
      client/windows/CMapOverview.cpp
  3. 11 11
      client/windows/CMapOverview.h
  4. 130 0
      config/widgets/mapOverview.json

+ 1 - 7
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<CMapOverview>(text, ResourcePath(curItems[py]->fileURI), tabType);
-	}
+		GH.windows().createAndPushWindow<CMapOverview>(curItems[py]->getName(), curItems[py]->fullFileURI, curItems[py]->date, ResourcePath(curItems[py]->fileURI), tabType);
 	else
 		CRClickPopup::createAndPush(curItems[py]->folderName);
 }

+ 55 - 47
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);
-
-	widget = std::make_shared<CMapOverviewWidget>(text, resource, tabType);
-
-	updateShadow();
-
-	/*
-	std::vector<std::shared_ptr<IImage>> 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);
+	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());
 
-	auto drawLabel = [&]() {
-		label = std::make_shared<CTextBox>(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();
+	widget = std::make_shared<CMapOverviewWidget>(*this);
 
-	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<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), pos);
 	updateShadow();
 
-	drawLabel();
-
-	if(renderImage)
-	{
-		if(mapLayerImages.size() == 1)
-			image1 = std::make_shared<CPicture>(mapLayerImages[0], Point(BORDER + (BORDER + IMAGE_SIZE) / 2, textHeight + 2 * BORDER));
-		else
-		{
-			image1 = std::make_shared<CPicture>(mapLayerImages[0], Point(BORDER, textHeight + 2 * BORDER));
-			image2 = std::make_shared<CPicture>(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<CPicture> CMapOverview::CMapOverviewWidget::buildDrawMinimap(con
 
 	auto rect = readRect(config["rect"]);
 	auto id = config["id"].Integer();
-	const std::vector<std::shared_ptr<IImage>> images = createMinimaps(ResourcePath(resource.getName(), EResType::MAP), Point(rect.w, rect.h));
+
+	if(!renderImage)
+		return nullptr;
+
+	const std::vector<std::shared_ptr<IImage>> images = createMinimaps(ResourcePath(parent.resource.getName(), EResType::MAP), Point(rect.w, rect.h));
+
+	if(id >= images.size())
+		return nullptr;
 
 	return std::make_shared<CPicture>(images[id], Point(rect.x, rect.y));
 }
 
-CMapOverview::CMapOverviewWidget::CMapOverviewWidget(std::string text, ResourcePath resource, ESelectionScreen tabType):
-	InterfaceObjectConfigurable(), resource(resource)
+std::shared_ptr<CTextBox> 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<CTextBox>(parent.fileName, rect, 0, font, alignment, color);
+}
+
+std::shared_ptr<CLabel> 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<CLabel>(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);
 }

+ 11 - 11
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<CFilledTexture> backgroundTexture;
-	std::shared_ptr<CTextBox> label;
-	std::shared_ptr<CPicture> image1;
-	std::shared_ptr<CPicture> image2;
-
 	class CMapOverviewWidget : public InterfaceObjectConfigurable
 	{
-		ResourcePath resource;
+		CMapOverview& parent;
 
 		bool drawPlayerElements;
 		bool renderImage;
@@ -47,12 +39,20 @@ class CMapOverview : public CWindowObject
 
 		std::shared_ptr<TransparentFilledRectangle> buildDrawTransparentRect(const JsonNode & config) const;
 		std::shared_ptr<CPicture> buildDrawMinimap(const JsonNode & config) const;
+		std::shared_ptr<CTextBox> buildDrawPath(const JsonNode & config) const;
+		std::shared_ptr<CLabel> buildDrawString(const JsonNode & config) const;
 	public:
-		CMapOverviewWidget(std::string text, ResourcePath resource, ESelectionScreen tabType);
+		CMapOverviewWidget(CMapOverview& parent);
 	};
 
 	std::shared_ptr<CMapOverviewWidget> 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);
 };

+ 130 - 0
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}
+		}
+	]
+}