ソースを参照

CArtPlace preparation

SoundSSGood 2 年 前
コミット
fbe3e0fe12

+ 32 - 70
client/widgets/CArtifactHolder.cpp

@@ -75,12 +75,26 @@ void CArtPlace::setInternals(const CArtifactInstance * artInst)
 	text = artInst->getDescription();
 }
 
-CArtPlace::CArtPlace(Point position, const CArtifactInstance * Art) 
-	: ourArt(Art)
+CArtPlace::CArtPlace(Point position, const CArtifactInstance * art) 
+	: ourArt(art)
+	, locked(false)
 {
-	image = nullptr;
 	pos += position;
 	pos.w = pos.h = 44;
+
+	OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
+
+	imageIndex = 0;
+	if(locked)
+		imageIndex = ArtifactID::ART_LOCK;
+	else if(ourArt)
+		imageIndex = ourArt->artType->getIconIndex();
+
+	image = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), imageIndex);
+	image->disable();
+
+	selection = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), ArtifactID::ART_SELECTION);
+	selection->visible = false;
 }
 
 const CArtifactInstance * CArtPlace::getArt()
@@ -88,26 +102,12 @@ const CArtifactInstance * CArtPlace::getArt()
 	return ourArt;
 }
 
-CCommanderArtPlace::CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, 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);
-}
-
-void CCommanderArtPlace::createImage()
-{
-	OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
-
-	imageIndex = 0;
-	if(ourArt)
-		imageIndex = ourArt->artType->getIconIndex();
-
-	image = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), imageIndex);
-	if(!ourArt)
-		image->disable();
+	setArtifact(art);
 }
 
 void CCommanderArtPlace::returnArtToHeroCallback()
@@ -145,20 +145,12 @@ void CCommanderArtPlace::showPopupWindow(const Point & cursorPosition)
 		CArtPlace::showPopupWindow(cursorPosition);
 }
 
-void CCommanderArtPlace::setArtifact(const CArtifactInstance * art)
-{
-	setInternals(art);
-}
-
-CHeroArtPlace::CHeroArtPlace(Point position, const CArtifactInstance * Art)
-	: CArtPlace(position, Art),
-	locked(false),
-	marked(false)
+CHeroArtPlace::CHeroArtPlace(Point position, const CArtifactInstance * art)
+	: CArtPlace(position, art)
 {
-	createImage();
 }
 
-void CHeroArtPlace::lockSlot(bool on)
+void CArtPlace::lockSlot(bool on)
 {
 	if(locked == on)
 		return;
@@ -173,26 +165,19 @@ void CHeroArtPlace::lockSlot(bool on)
 		image->setFrame(0);
 }
 
-bool CHeroArtPlace::isLocked()
+bool CArtPlace::isLocked() const
 {
 	return locked;
 }
 
-void CHeroArtPlace::selectSlot(bool on)
+void CArtPlace::selectSlot(bool on)
 {
-	if(marked == on)
-		return;
-
-	marked = on;
-	if(on)
-		selection->enable();
-	else
-		selection->disable();
+	selection->visible = on;
 }
 
-bool CHeroArtPlace::isMarked() const
+bool CArtPlace::isSelected() const
 {
-	return marked;
+	return selection->visible;
 }
 
 void CHeroArtPlace::clickPressed(const Point & cursorPosition)
@@ -207,18 +192,13 @@ void CHeroArtPlace::showPopupWindow(const Point & cursorPosition)
 		showPopupCallback(*this);
 }
 
-void CHeroArtPlace::showAll(Canvas & to)
+void CArtPlace::showAll(Canvas & to)
 {
-	if(ourArt)
-	{
-		CIntObject::showAll(to);
-	}
-
-	if(marked && isActive())
-		to.drawBorder(pos, Colors::BRIGHT_YELLOW);
+	CIntObject::showAll(to);
+	selection->showAll(to);
 }
 
-void CHeroArtPlace::setArtifact(const CArtifactInstance * art)
+void CArtPlace::setArtifact(const CArtifactInstance * art)
 {
 	setInternals(art);
 	if(art)
@@ -253,24 +233,6 @@ void CHeroArtPlace::addCombinedArtInfo(std::map<const CArtifact*, int> & arts)
 	}
 }
 
-void CHeroArtPlace::createImage()
-{
-	OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
-
-	si32 imageIndex = 0;
-
-	if(locked)
-		imageIndex = ArtifactID::ART_LOCK;
-	else if(ourArt)
-		imageIndex = ourArt->artType->getIconIndex();
-
-	image = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), imageIndex);
-	image->disable();
-
-	selection = std::make_shared<CAnimImage>(AnimationPath::builtin("artifact"), ArtifactID::ART_SELECTION);
-	selection->disable();
-}
-
 bool ArtifactUtilsClient::askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot)
 {
 	assert(hero);

+ 14 - 25
client/widgets/CArtifactHolder.h

@@ -19,7 +19,6 @@ class CArtifactSet;
 VCMI_LIB_NAMESPACE_END
 
 class CAnimImage;
-class CButton;
 
 class CArtifactHolder
 {
@@ -32,19 +31,24 @@ public:
 
 class CArtPlace : public LRClickableAreaWTextComp
 {
+public:
+	CArtPlace(Point position, const CArtifactInstance * art = nullptr);
+	const CArtifactInstance* getArt();
+	void lockSlot(bool on);
+	bool isLocked() const;
+	void selectSlot(bool on);
+	bool isSelected() const;
+	void showAll(Canvas & to) override;
+	void setArtifact(const CArtifactInstance * art);
+
 protected:
 	std::shared_ptr<CAnimImage> image;
 	const CArtifactInstance * ourArt;
 	int imageIndex;
+	std::shared_ptr<CAnimImage> selection;
+	bool locked;
 
 	void setInternals(const CArtifactInstance * artInst);
-	virtual void createImage()=0;
-
-public:
-	CArtPlace(Point position, const CArtifactInstance * Art = nullptr);
-	const CArtifactInstance * getArt();
-
-	virtual void setArtifact(const CArtifactInstance * art)=0;
 };
 
 class CCommanderArtPlace : public CArtPlace
@@ -53,14 +57,12 @@ protected:
 	const CGHeroInstance * commanderOwner;
 	ArtifactPosition commanderSlotID;
 
-	void createImage() override;
 	void returnArtToHeroCallback();
 
 public:
-	CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, const CArtifactInstance * Art = nullptr);
+	CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, const CArtifactInstance * art = nullptr);
 	void clickPressed(const Point & cursorPosition) override;
 	void showPopupWindow(const Point & cursorPosition) override;
-	void setArtifact(const CArtifactInstance * art) override;
 };
 
 class CHeroArtPlace: public CArtPlace
@@ -72,23 +74,10 @@ public:
 	ClickFunctor leftClickCallback;
 	ClickFunctor showPopupCallback;
 
-	CHeroArtPlace(Point position, const CArtifactInstance * Art = nullptr);
-	void lockSlot(bool on);
-	bool isLocked();
-	void selectSlot(bool on);
-	bool isMarked() const;
+	CHeroArtPlace(Point position, const CArtifactInstance * art = nullptr);
 	void clickPressed(const Point & cursorPosition) override;
 	void showPopupWindow(const Point & cursorPosition) override;
-	void showAll(Canvas & to) override;
-	void setArtifact(const CArtifactInstance * art) override;
 	void addCombinedArtInfo(std::map<const CArtifact*, int> & arts);
-
-protected:
-	std::shared_ptr<CAnimImage> selection;
-	bool locked;
-	bool marked;
-
-	void createImage() override;
 };
 
 namespace ArtifactUtilsClient

+ 2 - 0
client/widgets/CArtifactsOfHeroBase.h

@@ -11,6 +11,8 @@
 
 #include "CArtifactHolder.h"
 
+class CButton;
+
 class CArtifactsOfHeroBase : public CIntObject
 {
 protected:

+ 1 - 1
client/widgets/CArtifactsOfHeroMarket.cpp

@@ -30,7 +30,7 @@ void CArtifactsOfHeroMarket::scrollBackpack(int offset)
 	{
 		for(auto & artPlace : backpack)
 		{
-			if(artPlace->isMarked())
+			if(artPlace->isSelected())
 			{
 				selectArtCallback(artPlace.get());
 				break;