Bladeren bron

Cleanup of stack artifacts code

Ivan Savenko 11 jaren geleden
bovenliggende
commit
1ae7a77246
2 gewijzigde bestanden met toevoegingen van 37 en 24 verwijderingen
  1. 33 24
      client/CCreatureWindow.cpp
  2. 4 0
      client/CCreatureWindow.h

+ 33 - 24
client/CCreatureWindow.cpp

@@ -171,6 +171,36 @@ std::string CStackWindow::generateStackExpDescription()
 	return expText;
 }
 
+void CStackWindow::removeStackArtifact(ArtifactPosition pos)
+{
+	auto art = info->stackNode->getArt(ArtifactPosition::CREATURE_SLOT);
+	LOCPLINT->cb->swapArtifacts(ArtifactLocation(info->stackNode, pos),
+								ArtifactLocation(info->owner, art->firstBackpackSlot(info->owner)));
+	delete stackArtifactButton;
+	delete stackArtifactHelp;
+	delete stackArtifactIcon;
+}
+
+void CStackWindow::setStackArtifact(const CArtifactInstance * art, Point artPos)
+{
+	if (art)
+	{
+		stackArtifactIcon = new CAnimImage("ARTIFACT", art->artType->iconIndex, 0, pos.x, pos.y);
+		stackArtifactHelp = new LRClickableAreaWTextComp(Rect(artPos, Point(44, 44)), CComponent::artifact);
+		stackArtifactHelp->type = art->artType->id;
+
+		const JsonNode & text = VLC->generaltexth->localizedTexts["creatureWindow"]["returnArtifact"];
+
+		if (info->owner)
+		{
+			stackArtifactButton = new CAdventureMapButton(text["label"].String(), text["help"].String(),[=]{
+				removeStackArtifact(ArtifactPosition::CREATURE_SLOT);
+			}, artPos.x - 2 , artPos.y + 46, "stackWindow/cancelButton");
+		}
+	}
+
+}
+
 void CStackWindow::CWindowSection::createStackInfo(bool showExp, bool showArt)
 {
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
@@ -226,31 +256,10 @@ void CStackWindow::CWindowSection::createStackInfo(bool showExp, bool showArt)
 	auto luck = new MoraleLuckBox(false, genRect(42, 42, 375, 110));
 	luck->set(parent->info->stackNode);
 
-	//TODO: TEST
-	//TODO: delete "pass artifact" button on removal
-	//TODO: refactor into give art / take art methods
 	if (showArt)
 	{
-		const CStackInstance * stack = parent->info->stackNode;
-		if (stack->getArt(ArtifactPosition::CREATURE_SLOT))
-		{
-			auto art = stack->getArt(ArtifactPosition::CREATURE_SLOT);
-
-			Point pos = showExp ? Point(375, 32) : Point(347, 32);
-			parent->stackArtifactIcon = new CAnimImage("ARTIFACT", art->artType->iconIndex, 0, pos.x, pos.y);
-			parent->stackArtifactHelp = new LRClickableAreaWTextComp(Rect(pos, Point(44, 44)), CComponent::artifact);
-			parent->stackArtifactHelp->type = art->artType->id;
-
-			const JsonNode & text = VLC->generaltexth->localizedTexts["creatureWindow"]["returnArtifact"];
-
-			if (parent->info->owner)
-			{
-				new CAdventureMapButton(text["label"].String(), text["help"].String(),[=]{
-					LOCPLINT->cb->swapArtifacts(ArtifactLocation(stack, ArtifactPosition::CREATURE_SLOT),
-												ArtifactLocation(parent->info->owner, art->firstBackpackSlot(parent->info->owner)));
-				}, pos.x - 2 , pos.y + 46, "stackWindow/cancelButton");
-			}
-		}
+		Point pos = showExp ? Point(375, 32) : Point(347, 32);
+		parent->setStackArtifact(parent->info->stackNode->getArt(ArtifactPosition::CREATURE_SLOT), pos);
 	}
 
 	if (showExp)
@@ -404,7 +413,6 @@ void CStackWindow::CWindowSection::createCommander()
 			};
 		}
 	}
-
 	//TODO: commander artifacts
 }
 
@@ -758,6 +766,7 @@ void CStackWindow::init()
 {
 	stackArtifactHelp = nullptr;
 	stackArtifactIcon = nullptr;
+	stackArtifactButton = nullptr;
 
 	selectedIcon = nullptr;
 	selectedSkill = 0;

+ 4 - 0
client/CCreatureWindow.h

@@ -71,6 +71,7 @@ class CStackWindow : public CWindowObject
 
 	CAnimImage * stackArtifactIcon;
 	LRClickableAreaWTextComp * stackArtifactHelp;
+	CAdventureMapButton * stackArtifactButton;
 
 	std::unique_ptr<StackWindowInfo> info;
 	std::vector<BonusInfo> activeBonuses;
@@ -86,6 +87,9 @@ class CStackWindow : public CWindowObject
 	CIntObject * createBonusEntry(size_t index);
 	CIntObject * switchTab(size_t index);
 
+	void removeStackArtifact(ArtifactPosition pos);
+	void setStackArtifact(const CArtifactInstance * art, Point artPos);
+
 	void initSections();
 	void initBonusesList();