浏览代码

Implement giving commander artifacts back to hero

dydzio 9 年之前
父节点
当前提交
96fa0fb6d4
共有 3 个文件被更改,包括 26 次插入5 次删除
  1. 20 3
      client/widgets/CArtifactHolder.cpp
  2. 5 1
      client/widgets/CArtifactHolder.h
  3. 1 1
      client/windows/CCreatureWindow.cpp

+ 20 - 3
client/widgets/CArtifactHolder.cpp

@@ -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

+ 5 - 1
client/widgets/CArtifactHolder.h

@@ -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;
 

+ 1 - 1
client/windows/CCreatureWindow.cpp

@@ -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.)
 	}