mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Implement giving commander artifacts back to hero
This commit is contained in:
		| @@ -960,7 +960,7 @@ void CArtPlace::clickRight(tribool down, bool previousState) | ||||
| 	LRClickableAreaWTextComp::clickRight(down, previousState); | ||||
| } | ||||
|  | ||||
| CCommanderArtPlace::CCommanderArtPlace(Point position, const CArtifactInstance * Art) : CArtPlace(position, Art) | ||||
| CCommanderArtPlace::CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, const CArtifactInstance * Art) : CArtPlace(position, Art), commanderOwner(commanderOwner), commanderSlotID(artSlot.num) | ||||
| { | ||||
| 	createImage(); | ||||
| 	setArtifact(Art); | ||||
| @@ -968,8 +968,9 @@ CCommanderArtPlace::CCommanderArtPlace(Point position, const CArtifactInstance * | ||||
|  | ||||
| void CCommanderArtPlace::clickLeft(tribool down, bool previousState) | ||||
| { | ||||
| 	if(ourArt && text.size()) | ||||
| 		CArtPlace::clickLeft(down, previousState);	 | ||||
| 	if (down && ourArt && text.size()) | ||||
| 		LOCPLINT->showYesNoDialog("Do you want to give this artifact back to hero?", [this] { returnArtToHeroCallback(); }, [] {}); | ||||
| 		//CArtPlace::clickLeft(down, previousState);	 | ||||
| } | ||||
|  | ||||
| void CCommanderArtPlace::clickRight(tribool down, bool previousState) | ||||
| @@ -991,6 +992,22 @@ void CCommanderArtPlace::createImage() | ||||
| 		image->disable(); | ||||
| } | ||||
|  | ||||
| void CCommanderArtPlace::returnArtToHeroCallback() | ||||
| { | ||||
| 	ArtifactPosition artifactPos = commanderSlotID;; | ||||
| 	ArtifactPosition freeSlot = ourArt->firstBackpackSlot(commanderOwner); | ||||
|  | ||||
| 	ArtifactLocation src(commanderOwner->commander.get(), artifactPos); | ||||
| 	ArtifactLocation dst(commanderOwner, freeSlot); | ||||
|  | ||||
| 	if (ourArt->canBePutAt(dst, true)) | ||||
| 	{ | ||||
| 		LOCPLINT->cb->swapArtifacts(src, dst); | ||||
| 		setArtifact(nullptr); | ||||
| 		parent->redraw(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CCommanderArtPlace::setArtifact(const CArtifactInstance * art) | ||||
| { | ||||
| 	baseType = -1; //by default we don't store any component | ||||
|   | ||||
| @@ -59,9 +59,13 @@ public: | ||||
| class CCommanderArtPlace : public CArtPlace | ||||
| { | ||||
| protected: | ||||
| 	const CGHeroInstance * commanderOwner; | ||||
| 	ArtifactPosition commanderSlotID; | ||||
|  | ||||
| 	void createImage() override; | ||||
| 	void returnArtToHeroCallback(); | ||||
| public: | ||||
| 	CCommanderArtPlace(Point position, const CArtifactInstance * Art = nullptr); //c-tor | ||||
| 	CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, const CArtifactInstance * Art = nullptr); //c-tor | ||||
| 	void clickLeft(tribool down, bool previousState) override; | ||||
| 	void clickRight(tribool down, bool previousState) override; | ||||
|  | ||||
|   | ||||
| @@ -461,7 +461,7 @@ void CStackWindow::CWindowSection::createCommander() | ||||
| 	{ | ||||
| 		Point artPos = getArtifactPos(equippedArtifact.first); | ||||
| 		//auto icon = new CClickableObject(new CAnimImage("artifact", equippedArtifact.second.artifact.get()->artType.get()->iconIndex, 0, artPos.x, artPos.y), [=] {}); | ||||
| 		auto icon = new CCommanderArtPlace(artPos, equippedArtifact.second.artifact); | ||||
| 		auto icon = new CCommanderArtPlace(artPos, parent->info->owner, equippedArtifact.first, equippedArtifact.second.artifact); | ||||
|  | ||||
| 		//TODO: Use CArtPlace or equivalent instead of CClickableObject and handle commander artifact actions to match WOG (return artifact to hero etc.) | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user