mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Merge pull request #6209 from Laserlicht/kingdomoverview_res
Kingdomoverview additional mines
This commit is contained in:
		| @@ -38,10 +38,13 @@ | ||||
| #include "../../lib/StartInfo.h" | ||||
| #include "../../lib/callback/CCallback.h" | ||||
| #include "../../lib/entities/hero/CHeroHandler.h" | ||||
| #include "../../lib/entities/ResourceTypeHandler.h" | ||||
| #include "../../lib/texts/TextOperations.h" | ||||
| #include "../../lib/mapObjects/CGHeroInstance.h" | ||||
| #include "../../lib/mapObjects/CGTownInstance.h" | ||||
| #include "../../lib/mapObjects/MiscObjects.h" | ||||
| #include "../../lib/mapObjectConstructors/CommonConstructors.h" | ||||
| #include "../../lib/mapObjectConstructors/CObjectClassesHandler.h" | ||||
| #include "texts/CGeneralTextHandler.h" | ||||
| #include "../../lib/GameSettings.h" | ||||
|  | ||||
| @@ -476,7 +479,7 @@ CKingdomInterface::CKingdomInterface() | ||||
|  | ||||
| 	std::vector<const CGObjectInstance * > ownedObjects = GAME->interface()->cb->getMyObjects(); | ||||
| 	generateObjectsList(ownedObjects); | ||||
| 	generateMinesList(ownedObjects); | ||||
| 	generateMinesList(ownedObjects, 0); | ||||
| 	generateButtons(); | ||||
|  | ||||
| 	statusbar = CGStatusBar::create(std::make_shared<CPicture>(ImagePath::builtin("KSTATBAR"), 10,pos.h - 45)); | ||||
| @@ -594,12 +597,36 @@ std::shared_ptr<CIntObject> CKingdomInterface::createMainTab(size_t index) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstance *> & ownedObjects) | ||||
| std::shared_ptr<MineInstanceConstructor> CKingdomInterface::getMineHandler(const GameResID & res) | ||||
| { | ||||
| 	std::shared_ptr<MineInstanceConstructor> mineHandler; | ||||
| 	for(auto & subObjID : LIBRARY->objtypeh->knownSubObjects(Obj::MINE)) | ||||
| 	{ | ||||
| 		auto handler = std::dynamic_pointer_cast<MineInstanceConstructor>(LIBRARY->objtypeh->getHandlerFor(Obj::MINE, subObjID)); | ||||
| 		if(handler->getResourceType() == res) | ||||
| 			mineHandler = handler; | ||||
| 	} | ||||
|  | ||||
| 	if(!mineHandler) | ||||
| 	{ | ||||
| 		logGlobal->error("No mine for resource %s found!", res.toResource()->getJsonKey()); | ||||
| 		return nullptr; | ||||
| 	} | ||||
|  | ||||
| 	return mineHandler; | ||||
| } | ||||
|  | ||||
| void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstance *> & ownedObjects, int line) | ||||
| { | ||||
| 	OBJECT_CONSTRUCTION; | ||||
|  | ||||
| 	ui32 footerPos = OVERVIEW_SIZE * 116; | ||||
| 	ResourceSet minesCount = ResourceSet(); | ||||
| 	int totalIncome=0; | ||||
|  | ||||
| 	for(auto & ptr : minesBox) | ||||
|     	ptr.reset(); | ||||
|  | ||||
| 	for(const CGObjectInstance * object : ownedObjects) | ||||
| 	{ | ||||
| 		//Mines | ||||
| @@ -619,13 +646,40 @@ void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstan | ||||
| 	totalIncome += GAME->interface()->cb->getPlayerState(GAME->interface()->playerID)->valOfBonuses(BonusType::RESOURCES_CONSTANT_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * playerSettings->handicap.percentIncome / 100; | ||||
| 	totalIncome += GAME->interface()->cb->getPlayerState(GAME->interface()->playerID)->valOfBonuses(BonusType::RESOURCES_TOWN_MULTIPLYING_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * towns.size() * playerSettings->handicap.percentIncome / 100; | ||||
|  | ||||
| 	for(int i=0; i<GameConstants::RESOURCE_QUANTITY; i++) // TODO: configurable resources - show up more mines | ||||
| 	for(int i=0; i<GameConstants::RESOURCE_QUANTITY; i++) | ||||
| 	{ | ||||
| 		std::string value = std::to_string(minesCount[i]); | ||||
| 		auto data = std::make_shared<InfoBoxCustom>(value, "", AnimationPath::builtin("OVMINES"), i, LIBRARY->generaltexth->translate("core.minename", i)); | ||||
| 		int resID = line * GameConstants::RESOURCE_QUANTITY + i; | ||||
| 		if(resID >= LIBRARY->resourceTypeHandler->getAllObjects().size()) | ||||
| 			break; | ||||
|  | ||||
| 		std::string value = std::to_string(minesCount[resID]); | ||||
| 		std::shared_ptr<InfoBoxCustom> data; | ||||
| 		if(line == 0) | ||||
| 			data = std::make_shared<InfoBoxCustom>(value, "", AnimationPath::builtin("OVMINES"), i, LIBRARY->generaltexth->translate("core.minename", i)); | ||||
| 		else | ||||
| 		{ | ||||
| 			auto mine = getMineHandler(GameResID(resID)); | ||||
| 			if(!mine || mine->getKingdomOverviewImage().empty()) | ||||
| 				continue; | ||||
| 			data = std::make_shared<InfoBoxCustom>(value, "", mine->getKingdomOverviewImage(), 0, mine->getNameTranslated()); | ||||
| 		} | ||||
| 		minesBox[i] = std::make_shared<InfoBox>(Point(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data); | ||||
| 		minesBox[i]->removeUsedEvents(LCLICK|SHOW_POPUP); //fixes #890 - mines boxes ignore clicks | ||||
| 	} | ||||
|  | ||||
| 	if(LIBRARY->resourceTypeHandler->getAllObjects().size() > GameConstants::RESOURCE_QUANTITY) | ||||
| 	{ | ||||
| 		int lines = vstd::divideAndCeil(LIBRARY->resourceTypeHandler->getAllObjects().size(), GameConstants::RESOURCE_QUANTITY); | ||||
| 		minesSlider = std::make_shared<CSlider>(Point(723, 495), 57, [this, ownedObjects](int to){ | ||||
| 			generateMinesList(ownedObjects, to); | ||||
| 			statusbar->clear(); | ||||
| 			setRedrawParent(true); | ||||
| 			redraw(); | ||||
| 		}, 1, lines, line, Orientation::VERTICAL, CSlider::BROWN); | ||||
| 		minesSlider->setPanningStep(57); | ||||
| 		minesSlider->setScrollBounds(Rect(-735, 0, 735, 57)); | ||||
| 	} | ||||
|  | ||||
| 	incomeArea = std::make_shared<CHoverableArea>(); | ||||
| 	incomeArea->pos = Rect(pos.x+580, pos.y+31+footerPos, 136, 68); | ||||
| 	incomeArea->hoverText = LIBRARY->generaltexth->allTexts[255]; | ||||
| @@ -722,6 +776,7 @@ CKingdHeroList::CKingdHeroList(size_t maxSize, const CreateHeroItemFunctor & onC | ||||
| 				return std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), (idx - 2) % GameConstants::KINGDOM_WINDOW_HEROES_SLOTS); | ||||
| 			} | ||||
| 		}, Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size)); | ||||
| 	heroes->getSlider()->setScrollBounds(Rect(0, 0, 725, 483)); | ||||
| } | ||||
|  | ||||
| void CKingdHeroList::updateGarrisons() | ||||
| @@ -755,6 +810,7 @@ CKingdTownList::CKingdTownList(size_t maxSize) | ||||
| 	ui32 size = OVERVIEW_SIZE*116 + 19; | ||||
| 	towns = std::make_shared<CListBox>(std::bind(&CKingdTownList::createTownItem, this, _1), | ||||
| 		Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size)); | ||||
| 	towns->getSlider()->setScrollBounds(Rect(0, 0, 725, 483)); | ||||
| } | ||||
|  | ||||
| void CKingdTownList::townChanged(const CGTownInstance * town) | ||||
|   | ||||
| @@ -11,6 +11,8 @@ | ||||
|  | ||||
| #include "CWindowWithArtifacts.h" | ||||
|  | ||||
| #include "../../lib/mapObjectConstructors/CommonConstructors.h" | ||||
|  | ||||
| VCMI_LIB_NAMESPACE_BEGIN | ||||
| class CGObjectInstance; | ||||
| VCMI_LIB_NAMESPACE_END | ||||
| @@ -232,6 +234,7 @@ private: | ||||
| 	std::shared_ptr<CButton> dwellBottom; | ||||
|  | ||||
| 	std::array<std::shared_ptr<InfoBox>, 7> minesBox; | ||||
| 	std::shared_ptr<CSlider> minesSlider; | ||||
|  | ||||
| 	std::shared_ptr<CHoverableArea> incomeArea; | ||||
| 	std::shared_ptr<CLabel> incomeAmount; | ||||
| @@ -241,10 +244,12 @@ private: | ||||
|  | ||||
| 	void activateTab(size_t which); | ||||
|  | ||||
| 	std::shared_ptr<MineInstanceConstructor> getMineHandler(const GameResID & res); | ||||
|  | ||||
| 	//Internal functions used during construction | ||||
| 	void generateButtons(); | ||||
| 	void generateObjectsList(const std::vector<const CGObjectInstance * > &ownedObjects); | ||||
| 	void generateMinesList(const std::vector<const CGObjectInstance * > &ownedObjects); | ||||
| 	void generateMinesList(const std::vector<const CGObjectInstance * > &ownedObjects, int line); | ||||
|  | ||||
| 	std::shared_ptr<CIntObject> createOwnedObject(size_t index); | ||||
| 	std::shared_ptr<CIntObject> createMainTab(size_t index); | ||||
|   | ||||
| @@ -47,7 +47,7 @@ VCMI allows overriding HoMM3 .def files with .json replacement. Compared to .def | ||||
|             // Group of this image. Optional, default = 0 | ||||
|             "group" : 0, | ||||
|  | ||||
|             // Imdex of the image in group | ||||
|             // Index of the image in group | ||||
|             "frame" : 0, | ||||
|  | ||||
|             // Filename for this frame | ||||
|   | ||||
| @@ -49,6 +49,7 @@ These are object types that are available for modding and have configurable prop | ||||
| - `bank` - see [Creature Bank](Map_Objects/Creature_Bank.md). Object that grants award on defeating guardians. Deprectated in favor of [Rewardable](Map_Objects/Rewardable.md) | ||||
| - `dwelling` - see [Dwelling](Map_Objects/Dwelling.md). Object that allows recruitments of units outside of towns | ||||
| - `market` - see [Market](Map_Objects/Market.md). Trading resources, artifacts, creatures and such | ||||
| - `mine` - see [Mine](Map_Objects/Mine.md). for Mines | ||||
| - `boat` - see [Boat](Map_Objects/Boat.md). Object to move across different terrains, such as water | ||||
| - `flaggable` - see [Flaggable](Map_Objects/Flaggable.md). Object that can be flagged by a player to provide [Bonus](Bonus_Format.md) or resources | ||||
| - `hillFort` - TODO: documentation. See config files in vcmi installation for reference | ||||
| @@ -64,7 +65,6 @@ These are types that don't have configurable properties, however it is possible | ||||
| - `borderGate` | ||||
| - `borderGuard` | ||||
| - `magi` | ||||
| - `mine` | ||||
| - `obelisk` | ||||
| - `subterraneanGate` | ||||
| - `whirlpool` | ||||
|   | ||||
							
								
								
									
										24
									
								
								docs/modders/Map_Objects/Mine.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								docs/modders/Map_Objects/Mine.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| # Mine | ||||
|  | ||||
| Currently only one mine per resource allowed. | ||||
|  | ||||
| Beside the common parameters from [Map Object Format](../Map_Object_Format.md) there are some additional parameters: | ||||
|  | ||||
| ```json | ||||
| { | ||||
| 	/// produced resource | ||||
| 	"resource" : "mithril", | ||||
|  | ||||
| 	/// amount of resources produced each day | ||||
| 	"defaultQuantity" : 1, | ||||
|  | ||||
| 	/// displayed name of mine | ||||
| 	"name" : "name text", | ||||
|  | ||||
| 	/// displayed description of mine (for popup) | ||||
| 	"description" : "description text", | ||||
|  | ||||
| 	/// Image showed on kingdom overview (animation; only frame 0 displayed) | ||||
| 	"kingdomOverviewImage" : "image.def" | ||||
| } | ||||
| ``` | ||||
| @@ -107,6 +107,8 @@ void MineInstanceConstructor::initTypeData(const JsonNode & input) | ||||
|  | ||||
| 	if (!config["description"].isNull()) | ||||
| 		LIBRARY->generaltexth->registerString(config.getModScope(), getDescriptionTextID(), config["description"]); | ||||
|  | ||||
| 	kingdomOverviewImage = AnimationPath::fromJson(config["kingdomOverviewImage"]); | ||||
| } | ||||
|  | ||||
| GameResID MineInstanceConstructor::getResourceType() const | ||||
| @@ -129,6 +131,11 @@ std::string MineInstanceConstructor::getDescriptionTranslated() const | ||||
| 	return LIBRARY->generaltexth->translate(getDescriptionTextID()); | ||||
| } | ||||
|  | ||||
| AnimationPath MineInstanceConstructor::getKingdomOverviewImage() const | ||||
| { | ||||
| 	return kingdomOverviewImage; | ||||
| } | ||||
|  | ||||
| void CTownInstanceConstructor::initTypeData(const JsonNode & input) | ||||
| { | ||||
| 	LIBRARY->identifiers()->requestIdentifier("faction", input["faction"], [&](si32 index) | ||||
|   | ||||
| @@ -67,6 +67,7 @@ class DLL_LINKAGE MineInstanceConstructor : public CDefaultObjectTypeHandler<CGM | ||||
| 	JsonNode config; | ||||
| 	GameResID resourceType; | ||||
| 	ui32 defaultQuantity; | ||||
| 	AnimationPath kingdomOverviewImage; | ||||
| public: | ||||
| 	void initTypeData(const JsonNode & input) override; | ||||
|  | ||||
| @@ -74,6 +75,7 @@ public: | ||||
| 	ui32 getDefaultQuantity() const; | ||||
| 	std::string getDescriptionTextID() const; | ||||
| 	std::string getDescriptionTranslated() const; | ||||
| 	AnimationPath getKingdomOverviewImage() const; | ||||
| }; | ||||
|  | ||||
| class CTownInstanceConstructor : public CDefaultObjectTypeHandler<CGTownInstance> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user