mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	backpack window initial
This commit is contained in:
		| @@ -32,10 +32,6 @@ CArtifactsOfHeroBase::CArtifactsOfHeroBase() | ||||
|  | ||||
| CArtifactsOfHeroBase::~CArtifactsOfHeroBase() | ||||
| { | ||||
| 	// TODO: cursor handling is CWindowWithArtifacts level. Should be moved when trading, kingdom and hero window are reworked | ||||
| 	// This will interfere with the implementation of a separate backpack window | ||||
| 	CCS->curh->dragAndDropCursor(nullptr); | ||||
|  | ||||
| 	// Artifact located in artifactsTransitionPos should be returned | ||||
| 	if(getPickedArtifact()) | ||||
| 	{ | ||||
|   | ||||
| @@ -21,7 +21,6 @@ public: | ||||
| 	using ArtPlaceMap = std::map<ArtifactPosition, ArtPlacePtr>; | ||||
| 	using ClickHandler = std::function<void(CArtifactsOfHeroBase&, CHeroArtPlace&)>; | ||||
|  | ||||
| 	const CGHeroInstance * curHero; | ||||
| 	ClickHandler leftClickCallback; | ||||
| 	ClickHandler rightClickCallback; | ||||
| 	 | ||||
| @@ -42,6 +41,7 @@ public: | ||||
| 	virtual const CArtifactInstance * getPickedArtifact(); | ||||
|  | ||||
| protected: | ||||
| 	const CGHeroInstance * curHero; | ||||
| 	ArtPlaceMap artWorn; | ||||
| 	std::vector<ArtPlacePtr> backpack; | ||||
| 	std::shared_ptr<CButton> leftBackpackRoll; | ||||
|   | ||||
| @@ -26,6 +26,11 @@ | ||||
| #include "../../lib/CGeneralTextHandler.h" | ||||
| #include "../../lib/mapObjects/CGHeroInstance.h" | ||||
|  | ||||
| CWindowWithArtifacts::~CWindowWithArtifacts() | ||||
| { | ||||
| 	CCS->curh->dragAndDropCursor(nullptr); | ||||
| } | ||||
|  | ||||
| void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet) | ||||
| { | ||||
| 	artSets.emplace_back(artSet); | ||||
|   | ||||
| @@ -24,6 +24,7 @@ public: | ||||
| 		std::weak_ptr<CArtifactsOfHeroKingdom>, | ||||
| 		std::weak_ptr<CArtifactsOfHeroMain>>; | ||||
|  | ||||
| 	virtual ~CWindowWithArtifacts(); | ||||
| 	void addSet(CArtifactsOfHeroPtr artSet); | ||||
| 	const CGHeroInstance * getHeroPickedArtifact(); | ||||
| 	const CArtifactInstance * getPickedArtifact(); | ||||
|   | ||||
| @@ -180,24 +180,23 @@ void CTradeWindow::CTradeableItem::clickPressed(const Point & cursorPosition) | ||||
| 			CAltarWindow *aw = static_cast<CAltarWindow *>(mw); | ||||
| 			const auto pickedArtInst = aw->getPickedArtifact(); | ||||
|  | ||||
| 			auto artifactsOfHero = std::dynamic_pointer_cast<CArtifactsOfHeroAltar>(aw->arts); | ||||
| 			if(pickedArtInst) | ||||
| 			{ | ||||
| 				artifactsOfHero->pickedArtMoveToAltar(ArtifactPosition::TRANSITION_POS); | ||||
| 				aw->arts->pickedArtMoveToAltar(ArtifactPosition::TRANSITION_POS); | ||||
| 				aw->moveArtToAltar(this->shared_from_this(), pickedArtInst); | ||||
| 			} | ||||
| 			else if(const CArtifactInstance *art = getArtInstance()) | ||||
| 			{ | ||||
| 				const auto hero = artifactsOfHero->getHero(); | ||||
| 				const auto hero = aw->arts->getHero(); | ||||
| 				const auto slot = hero->getSlotByInstance(art); | ||||
| 				assert(slot != ArtifactPosition::PRE_FIRST); | ||||
| 				LOCPLINT->cb->swapArtifacts(ArtifactLocation(hero, slot), | ||||
| 					ArtifactLocation(hero, ArtifactPosition::TRANSITION_POS)); | ||||
| 				artifactsOfHero->pickedArtFromSlot = slot; | ||||
| 				artifactsOfHero->artifactsOnAltar.erase(art); | ||||
| 				aw->arts->pickedArtFromSlot = slot; | ||||
| 				aw->arts->artifactsOnAltar.erase(art); | ||||
| 				setID(-1); | ||||
| 				subtitle.clear(); | ||||
| 				aw->deal->block(!artifactsOfHero->artifactsOnAltar.size()); | ||||
| 				aw->deal->block(!aw->arts->artifactsOnAltar.size()); | ||||
| 			} | ||||
|  | ||||
| 			aw->calcTotalExp(); | ||||
| @@ -374,34 +373,10 @@ void CTradeWindow::initItems(bool Left) | ||||
| 		int xOffset = 0, yOffset = 0; | ||||
| 		if(mode == EMarketMode::ARTIFACT_RESOURCE) | ||||
| 		{ | ||||
| 			xOffset = -361; | ||||
| 			yOffset = +46; | ||||
|  | ||||
| 			auto item = std::make_shared<CTradeableItem>(Point(137, 469), itemsType[Left], -1, 1, 0); | ||||
| 			item->recActions &= ~(UPDATE | SHOWALL); | ||||
| 			items[Left].push_back(item); | ||||
| 		} | ||||
| 		else //ARTIFACT_EXP | ||||
| 		{ | ||||
| 			xOffset = -365; | ||||
| 			yOffset = -12; | ||||
| 		} | ||||
|  | ||||
| 		if(mode == EMarketMode::ARTIFACT_RESOURCE) | ||||
| 		{ | ||||
| 			auto artifactsOfHero = std::make_shared<CArtifactsOfHeroMarket>(Point(xOffset, yOffset)); | ||||
| 			artifactsOfHero->selectArtCallback = std::bind(&CTradeWindow::artifactSelected, this, _1); | ||||
| 			artifactsOfHero->setHero(hero); | ||||
| 			addSet(artifactsOfHero); | ||||
| 			arts = artifactsOfHero; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			auto artifactsOfHero = std::make_shared<CArtifactsOfHeroAltar>(Point(xOffset, yOffset)); | ||||
| 			artifactsOfHero->setHero(hero); | ||||
| 			addSet(artifactsOfHero); | ||||
| 			arts = artifactsOfHero; | ||||
| 		} | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| @@ -701,7 +676,13 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket * Market, const CGHeroInsta | ||||
| 	} | ||||
|  | ||||
| 	titleLabel = std::make_shared<CLabel>(300, 27, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, title); | ||||
|  | ||||
| 	if(mode == EMarketMode::ARTIFACT_RESOURCE) | ||||
| 	{ | ||||
| 		arts = std::make_shared<CArtifactsOfHeroMarket>(Point(-361, 46)); | ||||
| 		arts->selectArtCallback = std::bind(&CTradeWindow::artifactSelected, this, _1); | ||||
| 		arts->setHero(hero); | ||||
| 		addSet(arts); | ||||
| 	} | ||||
| 	initItems(false); | ||||
| 	initItems(true); | ||||
|  | ||||
| @@ -1133,6 +1114,10 @@ CAltarWindow::CAltarWindow(const IMarket * Market, const CGHeroInstance * Hero, | ||||
| 		sacrificeBackpack = std::make_shared<CButton>(Point(147, 520), "ALTEMBK.DEF", CGI->generaltexth->zelp[570], std::bind(&CAltarWindow::SacrificeBackpack,this)); | ||||
| 		sacrificeBackpack->block(hero->artifactsInBackpack.empty()); | ||||
|  | ||||
| 		arts = std::make_shared<CArtifactsOfHeroAltar>(Point(-365, -12)); | ||||
| 		arts->setHero(hero); | ||||
| 		addSet(arts); | ||||
|  | ||||
| 		initItems(true); | ||||
| 		initItems(false); | ||||
| 		artIcon = std::make_shared<CAnimImage>("ARTIFACT", 0, 0, 281, 442); | ||||
| @@ -1234,15 +1219,14 @@ void CAltarWindow::makeDeal() | ||||
| 	else | ||||
| 	{ | ||||
| 		std::vector<ui32> positions; | ||||
| 		auto artifactsOfHero = std::dynamic_pointer_cast<CArtifactsOfHeroAltar>(arts); | ||||
| 		for(const CArtifactInstance * art : artifactsOfHero->artifactsOnAltar) | ||||
| 		for(const CArtifactInstance * art : arts->artifactsOnAltar) | ||||
| 		{ | ||||
| 			positions.push_back(hero->getSlotByInstance(art)); | ||||
| 		} | ||||
| 		std::sort(positions.begin(), positions.end(), std::greater<>()); | ||||
|  | ||||
| 		LOCPLINT->cb->trade(market, mode, positions, {}, {}, hero); | ||||
| 		artifactsOfHero->artifactsOnAltar.clear(); | ||||
| 		arts->artifactsOnAltar.clear(); | ||||
|  | ||||
| 		for(auto item : items[0]) | ||||
| 		{ | ||||
| @@ -1279,13 +1263,12 @@ void CAltarWindow::SacrificeAll() | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		auto artifactsOfHero = std::dynamic_pointer_cast<CArtifactsOfHeroAltar>(arts); | ||||
| 		for(const auto & aw : artifactsOfHero->visibleArtSet.artifactsWorn) | ||||
| 		for(const auto & aw : arts->visibleArtSet.artifactsWorn) | ||||
| 		{ | ||||
| 			if(!aw.second.locked) | ||||
| 				moveArtToAltar(nullptr, aw.second.artifact); | ||||
| 		} | ||||
| 		artifactsOfHero->updateWornSlots(); | ||||
| 		arts->updateWornSlots(); | ||||
| 		SacrificeBackpack(); | ||||
| 	} | ||||
| 	redraw(); | ||||
| @@ -1501,9 +1484,8 @@ bool CAltarWindow::putOnAltar(std::shared_ptr<CTradeableItem> altarSlot, const C | ||||
| 	market->getOffer(art->artType->getId(), 0, dmp, val, EMarketMode::ARTIFACT_EXP); | ||||
| 	val = static_cast<int>(hero->calculateXp(val)); | ||||
|  | ||||
| 	auto artsAltar = std::dynamic_pointer_cast<CArtifactsOfHeroAltar>(arts); | ||||
| 	artsAltar->artifactsOnAltar.insert(art); | ||||
| 	artsAltar->deleteFromVisible(art); | ||||
| 	arts->artifactsOnAltar.insert(art); | ||||
| 	arts->deleteFromVisible(art); | ||||
| 	altarSlot->setArtInstance(art); | ||||
| 	altarSlot->subtitle = std::to_string(val); | ||||
|  | ||||
|   | ||||
| @@ -67,7 +67,6 @@ public: | ||||
| 	const IMarket * market; | ||||
| 	const CGHeroInstance * hero; | ||||
|  | ||||
| 	std::shared_ptr<CArtifactsOfHeroBase> arts; | ||||
| 	//all indexes: 1 = left, 0 = right | ||||
| 	std::array<std::vector<std::shared_ptr<CTradeableItem>>, 2> items; | ||||
|  | ||||
| @@ -117,6 +116,7 @@ protected: | ||||
| class CMarketplaceWindow : public CTradeWindow | ||||
| { | ||||
| 	std::shared_ptr<CLabel> titleLabel; | ||||
| 	std::shared_ptr<CArtifactsOfHeroMarket> arts; | ||||
|  | ||||
| 	bool printButtonFor(EMarketMode::EMarketMode M) const; | ||||
|  | ||||
| @@ -155,6 +155,7 @@ public: | ||||
| 	std::shared_ptr<CButton> sacrificeBackpack; | ||||
| 	std::shared_ptr<CLabel> expToLevel; | ||||
| 	std::shared_ptr<CLabel> expOnAltar; | ||||
| 	std::shared_ptr<CArtifactsOfHeroAltar> arts; | ||||
|  | ||||
| 	CAltarWindow(const IMarket * Market, const CGHeroInstance * Hero, EMarketMode::EMarketMode Mode); | ||||
| 	~CAltarWindow(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user