mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	scenario name for campaigns
This commit is contained in:
		| @@ -126,9 +126,11 @@ CBonusSelection::CBonusSelection() | ||||
| 	for(auto scenarioID : getCampaign()->allScenarios()) | ||||
| 	{ | ||||
| 		if(getCampaign()->isAvailable(scenarioID)) | ||||
| 			regions.push_back(std::make_shared<CRegion>(scenarioID, true, true, getCampaign()->getRegions())); | ||||
| 			regions.push_back(std::make_shared<CRegion>(scenarioID, true, true, false, getCampaign()->getRegions())); | ||||
| 		else if(getCampaign()->isConquered(scenarioID)) //display as striped | ||||
| 			regions.push_back(std::make_shared<CRegion>(scenarioID, false, false, getCampaign()->getRegions())); | ||||
| 			regions.push_back(std::make_shared<CRegion>(scenarioID, false, false, false, getCampaign()->getRegions())); | ||||
| 		else | ||||
| 			regions.push_back(std::make_shared<CRegion>(scenarioID, false, false, true, getCampaign()->getRegions())); | ||||
| 	} | ||||
|  | ||||
| 	if (!getCampaign()->getMusic().empty()) | ||||
| @@ -476,8 +478,8 @@ void CBonusSelection::decreaseDifficulty() | ||||
| 		CSH->setDifficulty(CSH->si->difficulty - 1); | ||||
| } | ||||
|  | ||||
| CBonusSelection::CRegion::CRegion(CampaignScenarioID id, bool accessible, bool selectable, const CampaignRegions & campDsc) | ||||
| 	: CIntObject(LCLICK | SHOW_POPUP), idOfMapAndRegion(id), accessible(accessible), selectable(selectable) | ||||
| CBonusSelection::CRegion::CRegion(CampaignScenarioID id, bool accessible, bool selectable, bool labelOnly, const CampaignRegions & campDsc) | ||||
| 	: CIntObject(LCLICK | SHOW_POPUP), idOfMapAndRegion(id), accessible(accessible), selectable(selectable), labelOnly(labelOnly) | ||||
| { | ||||
| 	OBJECT_CONSTRUCTION; | ||||
|  | ||||
| @@ -493,10 +495,17 @@ CBonusSelection::CRegion::CRegion(CampaignScenarioID id, bool accessible, bool s | ||||
| 	graphicsStriped->disable(); | ||||
| 	pos.w = graphicsNotSelected->pos.w; | ||||
| 	pos.h = graphicsNotSelected->pos.h; | ||||
|  | ||||
| 	auto labelPos = campDsc.getLabelPosition(id); | ||||
| 	if(labelPos) | ||||
| 		label = std::make_shared<CLabel>((*labelPos).x, (*labelPos).y, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CSH->si->campState->scenario(idOfMapAndRegion).scenarioName.toString()); | ||||
| } | ||||
|  | ||||
| void CBonusSelection::CRegion::updateState() | ||||
| { | ||||
| 	if(labelOnly) | ||||
| 		return; | ||||
|  | ||||
| 	if(!accessible) | ||||
| 	{ | ||||
| 		graphicsNotSelected->disable(); | ||||
| @@ -519,7 +528,7 @@ void CBonusSelection::CRegion::updateState() | ||||
|  | ||||
| void CBonusSelection::CRegion::clickReleased(const Point & cursorPosition) | ||||
| { | ||||
| 	if(selectable && !graphicsNotSelected->getSurface()->isTransparent(cursorPosition - pos.topLeft())) | ||||
| 	if(!labelOnly && selectable && !graphicsNotSelected->getSurface()->isTransparent(cursorPosition - pos.topLeft())) | ||||
| 	{ | ||||
| 		CSH->setCampaignMap(idOfMapAndRegion); | ||||
| 	} | ||||
| @@ -529,7 +538,7 @@ void CBonusSelection::CRegion::showPopupWindow(const Point & cursorPosition) | ||||
| { | ||||
| 	// FIXME: For some reason "down" is only ever contain indeterminate_value | ||||
| 	auto & text = CSH->si->campState->scenario(idOfMapAndRegion).regionText; | ||||
| 	if(!graphicsNotSelected->getSurface()->isTransparent(cursorPosition - pos.topLeft()) && !text.empty()) | ||||
| 	if(!labelOnly && !graphicsNotSelected->getSurface()->isTransparent(cursorPosition - pos.topLeft()) && !text.empty()) | ||||
| 	{ | ||||
| 		CRClickPopup::createAndPush(text.toString()); | ||||
| 	} | ||||
|   | ||||
| @@ -49,8 +49,10 @@ public: | ||||
| 		CampaignScenarioID idOfMapAndRegion; | ||||
| 		bool accessible; // false if region should be striped | ||||
| 		bool selectable; // true if region should be selectable | ||||
| 		bool labelOnly; | ||||
| 		std::shared_ptr<CLabel> label; | ||||
| 	public: | ||||
| 		CRegion(CampaignScenarioID id, bool accessible, bool selectable, const CampaignRegions & campDsc); | ||||
| 		CRegion(CampaignScenarioID id, bool accessible, bool selectable, bool labelOnly, const CampaignRegions & campDsc); | ||||
| 		void updateState(); | ||||
| 		void clickReleased(const Point & cursorPosition) override; | ||||
| 		void showPopupWindow(const Point & cursorPosition) override; | ||||
|   | ||||
| @@ -14,14 +14,14 @@ | ||||
| 			"suffix": ["1", "2", "3"], | ||||
| 			"color_suffix_length": 0, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "1", "x": 27, "y": 43 }, | ||||
| 				{ "infix": "2", "x": 231, "y": 43 }, | ||||
| 				{ "infix": "3", "x": 27, "y": 178 }, | ||||
| 				{ "infix": "4", "x": 231, "y": 178 }, | ||||
| 				{ "infix": "5", "x": 27, "y": 312 }, | ||||
| 				{ "infix": "6", "x": 231, "y": 312 }, | ||||
| 				{ "infix": "7", "x": 27, "y": 447 }, | ||||
| 				{ "infix": "8", "x": 231, "y": 447 } | ||||
| 				{ "infix": "1", "x": 27, "y": 43, "labelPos": { "x": 98, "y": 112 } }, | ||||
| 				{ "infix": "2", "x": 231, "y": 43, "labelPos": { "x": 98, "y": 112 } }, | ||||
| 				{ "infix": "3", "x": 27, "y": 178, "labelPos": { "x": 98, "y": 112 } }, | ||||
| 				{ "infix": "4", "x": 231, "y": 178, "labelPos": { "x": 98, "y": 112 } }, | ||||
| 				{ "infix": "5", "x": 27, "y": 312, "labelPos": { "x": 98, "y": 112 } }, | ||||
| 				{ "infix": "6", "x": 231, "y": 312, "labelPos": { "x": 98, "y": 112 } }, | ||||
| 				{ "infix": "7", "x": 27, "y": 447, "labelPos": { "x": 98, "y": 112 } }, | ||||
| 				{ "infix": "8", "x": 231, "y": 447, "labelPos": { "x": 98, "y": 112 } } | ||||
| 			] | ||||
| 		}, | ||||
| 		"scenarioCount": 8, | ||||
|   | ||||
| @@ -191,9 +191,9 @@ Predefined campaign regions are located in file `campaign_regions.json` | ||||
|     "prefix": "G3", | ||||
|     "colorSuffixLength": 1, | ||||
|     "desc": [ | ||||
|         { "infix": "A", "x": 289, "y": 376 }, | ||||
|         { "infix": "B", "x": 60, "y": 147 }, | ||||
|         { "infix": "C", "x": 131, "y": 202 } | ||||
|         { "infix": "A", "x": 289, "y": 376, "labelPos": { "x": 98, "y": 112 } }, | ||||
|         { "infix": "B", "x": 60, "y": 147, "labelPos": { "x": 98, "y": 112 } }, | ||||
|         { "infix": "C", "x": 131, "y": 202, "labelPos": { "x": 98, "y": 112 } } | ||||
|     ] | ||||
| }, | ||||
| ``` | ||||
| @@ -202,6 +202,7 @@ Predefined campaign regions are located in file `campaign_regions.json` | ||||
| - `"prefix"` used to identify all images related to campaign. In this example (if background parameter wouldn't exists), background picture will be `G3_BG` | ||||
| - `"suffix"` optional - use other suffixes than the default `En`, `Se` and `Co` for the three different images | ||||
| - `"infix"` used to identify all images related to region. In this example, it will be pictures whose files names begin with `G3A_..., G3B_..., G3C_..."`  | ||||
| - `"labelPos"` optional -  to add scenario name as label on map | ||||
| - `"colorSuffixLength"` identifies suffix length for region colourful frames. 0 is no color suffix (no colorisation), 1 is used for `R, B, N, G, O, V, T, P`, value 2 is used for `Re, Bl, Br, Gr, Or, Vi, Te, Pi` | ||||
|  | ||||
| ## Packing campaign | ||||
|   | ||||
| @@ -39,6 +39,16 @@ CampaignRegions::RegionDescription CampaignRegions::RegionDescription::fromJson( | ||||
| 	rd.infix = node["infix"].String(); | ||||
| 	rd.xpos = static_cast<int>(node["x"].Float()); | ||||
| 	rd.ypos = static_cast<int>(node["y"].Float()); | ||||
| 	if(!node["labelPos"].isNull()) | ||||
| 	{ | ||||
| 		rd.xLabelpos = static_cast<int>(node["labelPos"]["x"].Float()); | ||||
| 		rd.yLabelpos = static_cast<int>(node["labelPos"]["y"].Float()); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		rd.xLabelpos = std::nullopt; | ||||
| 		rd.yLabelpos = std::nullopt; | ||||
| 	} | ||||
| 	return rd; | ||||
| } | ||||
|  | ||||
| @@ -83,6 +93,15 @@ Point CampaignRegions::getPosition(CampaignScenarioID which) const | ||||
| 	return Point(region.xpos, region.ypos); | ||||
| } | ||||
|  | ||||
| std::optional<Point> CampaignRegions::getLabelPosition(CampaignScenarioID which) const | ||||
| { | ||||
| 	auto const & region = regions[which.getNum()]; | ||||
| 	if(region.xLabelpos && region.yLabelpos) | ||||
| 		return Point(*region.xLabelpos, *region.yLabelpos); | ||||
| 	else | ||||
| 		return std::nullopt; | ||||
| } | ||||
|  | ||||
| ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex, std::string type) const | ||||
| { | ||||
| 	auto const & region = regions[which.getNum()]; | ||||
|   | ||||
| @@ -42,12 +42,19 @@ class DLL_LINKAGE CampaignRegions | ||||
| 		std::string infix; | ||||
| 		int xpos; | ||||
| 		int ypos; | ||||
| 		std::optional<int> xLabelpos; | ||||
| 		std::optional<int> yLabelpos; | ||||
|  | ||||
| 		template <typename Handler> void serialize(Handler &h) | ||||
| 		{ | ||||
| 			h & infix; | ||||
| 			h & xpos; | ||||
| 			h & ypos; | ||||
| 			if (h.version >= Handler::Version::REGION_LABEL) | ||||
| 			{ | ||||
| 				h & xLabelpos; | ||||
| 				h & yLabelpos; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		static CampaignRegions::RegionDescription fromJson(const JsonNode & node); | ||||
| @@ -60,6 +67,7 @@ class DLL_LINKAGE CampaignRegions | ||||
| public: | ||||
| 	ImagePath getBackgroundName() const; | ||||
| 	Point getPosition(CampaignScenarioID which) const; | ||||
| 	std::optional<Point> getLabelPosition(CampaignScenarioID which) const; | ||||
| 	ImagePath getAvailableName(CampaignScenarioID which, int color) const; | ||||
| 	ImagePath getSelectedName(CampaignScenarioID which, int color) const; | ||||
| 	ImagePath getConqueredName(CampaignScenarioID which, int color) const; | ||||
|   | ||||
| @@ -60,6 +60,7 @@ enum class ESerializationVersion : int32_t | ||||
| 	PER_MAP_GAME_SETTINGS, // 861 - game settings are now stored per-map | ||||
| 	CAMPAIGN_OUTRO_SUPPORT, // 862 - support for campaign outro video | ||||
| 	REWARDABLE_BANKS, // 863 - team state contains list of scouted objects, coast visitable rewardable objects | ||||
| 	REGION_LABEL, // 864 - labels for campaign regions | ||||
|  | ||||
| 	CURRENT = REWARDABLE_BANKS | ||||
| 	CURRENT = REGION_LABEL | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user