SoundSSGood пре 1 година
родитељ
комит
b840cf3650

+ 1 - 1
client/widgets/CArtifactHolder.h

@@ -29,7 +29,7 @@ public:
 	virtual void artifactAssembled(const ArtifactLocation & artLoc)=0;
 };
 
-class CArtPlace : public LRClickableAreaWTextComp, public SelectableSlot
+class CArtPlace : public SelectableSlot
 {
 public:
 	using ClickFunctor = std::function<void(CArtPlace&, const Point&)>;

+ 2 - 2
client/widgets/CArtifactsOfHeroMarket.cpp

@@ -21,9 +21,9 @@ CArtifactsOfHeroMarket::CArtifactsOfHeroMarket(const Point & position)
 		std::bind(&CArtifactsOfHeroMarket::scrollBackpack, this, _1));
 
 	for(const auto & [slot, artPlace] : artWorn)
-		artPlace->selection->setBorderWidth(2);
+		artPlace->setSelectionWidth(2);
 	for(auto artPlace : backpack)
-		artPlace->selection->setBorderWidth(2);
+		artPlace->setSelectionWidth(2);
 };
 
 void CArtifactsOfHeroMarket::scrollBackpack(int offset)

+ 6 - 2
client/widgets/MiscWidgets.cpp

@@ -705,9 +705,8 @@ void SimpleLine::showAll(Canvas & to)
 }
 
 SelectableSlot::SelectableSlot(Rect area, Point oversize, const int width)
+	: LRClickableAreaWTextComp(area)
 {
-	pos += area.topLeft();
-	pos.w = area.w; pos.h = area.h;
 	selection = std::make_unique<TransparentFilledRectangle>(
 		Rect(area.topLeft() - oversize, area.dimensions() + oversize * 2), Colors::TRANSPARENCY, Colors::YELLOW, width);
 	selectSlot(false);
@@ -732,3 +731,8 @@ bool SelectableSlot::isSelected() const
 {
 	return selection->getDrawBorder();
 }
+
+void SelectableSlot::setSelectionWidth(int width)
+{
+	selection->setBorderWidth(width);
+}

+ 3 - 2
client/widgets/MiscWidgets.h

@@ -273,14 +273,15 @@ public:
     void showAll(Canvas & to) override;
 };
 
-class SelectableSlot : virtual public CIntObject
+class SelectableSlot : public LRClickableAreaWTextComp
 {
-public:
 	std::unique_ptr<TransparentFilledRectangle> selection;
 
+public:
 	SelectableSlot(Rect area, Point oversize, const int width);
 	SelectableSlot(Rect area, Point oversize);
 	SelectableSlot(Rect area, const int width = 1);
 	void selectSlot(bool on);
 	bool isSelected() const;
+	void setSelectionWidth(int width);
 };

+ 3 - 1
client/widgets/markets/CAltarArtifacts.cpp

@@ -31,6 +31,8 @@ CAltarArtifacts::CAltarArtifacts(const IMarket * market, const CGHeroInstance *
 {
 	OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
 
+	deal = std::make_shared<CButton>(dealButtonPos, AnimationPath::builtin("ALTSACR.DEF"),
+		CGI->generaltexth->zelp[585], [this]() {CAltarArtifacts::makeDeal(); });
 	labels.emplace_back(std::make_shared<CLabel>(450, 34, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[477]));
 	labels.emplace_back(std::make_shared<CLabel>(302, 423, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[478]));
 	selectedCost = std::make_shared<CLabel>(302, 500, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
@@ -50,7 +52,7 @@ CAltarArtifacts::CAltarArtifacts(const IMarket * market, const CGHeroInstance *
 	int slotNum = 0;
 	for(auto & altarSlotPos : posSlotsAltar)
 	{
-		auto altarSlot = std::make_shared<CTradeableItem>(altarSlotPos, EType::ARTIFACT_PLACEHOLDER, -1, false, slotNum);
+		auto altarSlot = std::make_shared<CTradeableItem>(Rect(altarSlotPos, Point(44, 44)), EType::ARTIFACT_PLACEHOLDER, -1, false, slotNum);
 		altarSlot->clickPressedCallback = std::bind(&CAltarArtifacts::onSlotClickPressed, this, _1, hRight);
 		altarSlot->subtitle.clear();
 		items.front().emplace_back(altarSlot);

+ 2 - 0
client/widgets/markets/CAltarCreatures.cpp

@@ -30,6 +30,8 @@ CAltarCreatures::CAltarCreatures(const IMarket * market, const CGHeroInstance *
 {
 	OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
 
+	deal = std::make_shared<CButton>(dealButtonPos, AnimationPath::builtin("ALTSACR.DEF"),
+		CGI->generaltexth->zelp[584], [this]() {CAltarCreatures::makeDeal();});
 	labels.emplace_back(std::make_shared<CLabel>(155, 30, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW,
 		boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->getNameTranslated())));
 	labels.emplace_back(std::make_shared<CLabel>(450, 30, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[479]));

+ 4 - 7
client/widgets/markets/CTradeBase.cpp

@@ -25,8 +25,6 @@ CTradeBase::CTradeBase(const IMarket * market, const CGHeroInstance * hero)
 	: market(market)
 	, hero(hero)
 {
-	deal = std::make_shared<CButton>(Point(), AnimationPath::builtin("ALTSACR.DEF"),
-		CGI->generaltexth->zelp[585], std::bind(&CTradeBase::makeDeal, this));
 }
 
 void CTradeBase::removeItems(const std::set<std::shared_ptr<CTradeableItem>> & toRemove)
@@ -53,9 +51,9 @@ void CTradeBase::getEmptySlots(std::set<std::shared_ptr<CTradeableItem>> & toRem
 void CTradeBase::deselect()
 {
 	if(hLeft)
-		hLeft->selection->selectSlot(false);
+		hLeft->selectSlot(false);
 	if(hRight)
-		hRight->selection->selectSlot(false);
+		hRight->selectSlot(false);
 	hLeft = hRight = nullptr;
 	deal->block(true);
 }
@@ -66,9 +64,9 @@ void CTradeBase::onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newS
 		return;
 
 	if(hCurSlot)
-		hCurSlot->selection->selectSlot(false);
+		hCurSlot->selectSlot(false);
 	hCurSlot = newSlot;
-	newSlot->selection->selectSlot(true);
+	newSlot->selectSlot(true);
 }
 
 CExperienceAltar::CExperienceAltar()
@@ -79,7 +77,6 @@ CExperienceAltar::CExperienceAltar()
 	texts.emplace_back(std::make_shared<CTextBox>(CGI->generaltexth->allTexts[475], Rect(15, 415, 125, 50), 0, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW));
 	// Total experience on the Altar
 	texts.emplace_back(std::make_shared<CTextBox>(CGI->generaltexth->allTexts[476], Rect(15, 495, 125, 40), 0, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW));
-	deal->moveBy(dealButtonPos);
 	expToLevel = std::make_shared<CLabel>(75, 477, FONT_SMALL, ETextAlignment::CENTER);
 	expForHero = std::make_shared<CLabel>(75, 545, FONT_SMALL, ETextAlignment::CENTER);
 }

+ 25 - 27
client/widgets/markets/TradePanels.cpp

@@ -10,8 +10,6 @@
 #include "StdInc.h"
 #include "TradePanels.h"
 
-#include "../MiscWidgets.h"
-
 #include "../../gui/CGuiHandler.h"
 #include "../../render/Canvas.h"
 #include "../../widgets/TextControls.h"
@@ -25,9 +23,9 @@
 #include "../../../lib/CGeneralTextHandler.h"
 #include "../../../lib/mapObjects/CGHeroInstance.h"
 
-CTradeableItem::CTradeableItem(Point pos, EType Type, int ID, bool Left, int Serial)
-	: CIntObject(LCLICK | HOVER | SHOW_POPUP, pos)
-	, hlp(nullptr)
+CTradeableItem::CTradeableItem(const Rect & area, EType Type, int ID, bool Left, int Serial)
+	: SelectableSlot(area, Point(1, 1))
+	, artInstance(nullptr)
 	, type(EType(-1)) // set to invalid, will be corrected in setType
 	, id(ID)
 	, serial(Serial)
@@ -35,13 +33,15 @@ CTradeableItem::CTradeableItem(Point pos, EType Type, int ID, bool Left, int Ser
 	, downSelection(false)
 {
 	OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
+
+	addUsedEvents(LCLICK);
+	addUsedEvents(HOVER);
+	addUsedEvents(SHOW_POPUP);
 	
 	setType(Type);
-	if(image)
-	{
-		this->pos.w = image->pos.w;
-		this->pos.h = image->pos.h;
-	}
+
+	this->pos.w = area.w;
+	this->pos.h = area.h;
 }
 
 void CTradeableItem::setType(EType newType)
@@ -248,7 +248,7 @@ const CArtifactInstance * CTradeableItem::getArtInstance() const
 	{
 	case EType::ARTIFACT_PLACEHOLDER:
 	case EType::ARTIFACT_INSTANCE:
-		return hlp;
+		return artInstance;
 	default:
 		return nullptr;
 	}
@@ -257,7 +257,7 @@ const CArtifactInstance * CTradeableItem::getArtInstance() const
 void CTradeableItem::setArtInstance(const CArtifactInstance * art)
 {
 	assert(type == EType::ARTIFACT_PLACEHOLDER || type == EType::ARTIFACT_INSTANCE);
-	hlp = art;
+	artInstance = art;
 	if(art)
 		setID(art->getTypeId());
 	else
@@ -273,7 +273,7 @@ void TradePanelBase::updateSlots()
 void TradePanelBase::deselect()
 {
 	for(const auto & slot : slots)
-		slot->selection->selectSlot(false);
+		slot->selectSlot(false);
 }
 
 void TradePanelBase::clearSubtitles()
@@ -305,10 +305,10 @@ ResourcesPanel::ResourcesPanel(CTradeableItem::ClickPressedFunctor clickPressedC
 
 	for(const auto & res : resourcesForTrade)
 	{
-		auto slot = slots.emplace_back(std::make_shared<CTradeableItem>(slotsPos[res.num], EType::RESOURCE, res.num, true, res.num));
+		auto slot = slots.emplace_back(std::make_shared<CTradeableItem>(Rect(slotsPos[res.num], slotDimension),
+			EType::RESOURCE, res.num, true, res.num));
 		slot->clickPressedCallback = clickPressedCallback;
-		slot->pos.w = 69; slots.back()->pos.h = 66;
-		slot->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[res.num], slots.back()->pos.dimensions()), Point(1, 1), selectionWidth);
+		slot->setSelectionWidth(selectionWidth);
 	}
 	updateSlotsCallback = updateSubtitles;
 }
@@ -325,10 +325,10 @@ ArtifactsPanel::ArtifactsPanel(CTradeableItem::ClickPressedFunctor clickPressedC
 		auto artType = arts[slotIdx].getNum();
 		if(artType != ArtifactID::NONE)
 		{
-			auto slot = slots.emplace_back(std::make_shared<CTradeableItem>(slotsPos[slotIdx], EType::ARTIFACT_TYPE, artType, false, slotIdx));
+			auto slot = slots.emplace_back(std::make_shared<CTradeableItem>(Rect(slotsPos[slotIdx], slotDimension),
+				EType::ARTIFACT_TYPE, artType, false, slotIdx));
 			slot->clickPressedCallback = clickPressedCallback;
-			slot->pos.w = 69; slot->pos.h = 66;
-			slot->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[slotIdx], slot->pos.dimensions()), Point(1, 1), selectionWidth);
+			slot->setSelectionWidth(selectionWidth);
 		}
 	}
 	updateSlotsCallback = updateSubtitles;
@@ -350,9 +350,9 @@ PlayersPanel::PlayersPanel(CTradeableItem::ClickPressedFunctor clickPressedCallb
 	int slotNum = 0;
 	for(auto & slot : slots)
 	{
-		slot = std::make_shared<CTradeableItem>(slotsPos[slotNum], EType::PLAYER, players[slotNum].num, false, slotNum);
+		slot = std::make_shared<CTradeableItem>(Rect(slotsPos[slotNum], slotDimension), EType::PLAYER, players[slotNum].num, false, slotNum);
 		slot->clickPressedCallback = clickPressedCallback;
-		slot->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[slotNum], slot->pos.dimensions()), Point(1, 1), selectionWidth);
+		slot->setSelectionWidth(selectionWidth);
 		slot->subtitle = CGI->generaltexth->capColors[players[slotNum].num];
 		slotNum++;
 	}
@@ -366,13 +366,12 @@ CreaturesPanel::CreaturesPanel(CTradeableItem::ClickPressedFunctor clickPressedC
 
 	for(const auto & [creatureId, slotId, creaturesNum] : initialSlots)
 	{
-		auto slot = slots.emplace_back(std::make_shared<CTradeableItem>(slotsPos[slotId.num],
+		auto slot = slots.emplace_back(std::make_shared<CTradeableItem>(Rect(slotsPos[slotId.num], slotDimension),
 			creaturesNum == 0 ? EType::CREATURE_PLACEHOLDER : EType::CREATURE, creatureId.num, true, slotId));
 		slot->clickPressedCallback = clickPressedCallback;
 		if(creaturesNum != 0)
 			slot->subtitle = std::to_string(creaturesNum);
-		slot->pos.w = 58; slot->pos.h = 64;
-		slot->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[slotId.num], slot->pos.dimensions()), Point(1, 1), selectionWidth);
+		slot->setSelectionWidth(selectionWidth);
 	}
 }
 
@@ -384,11 +383,10 @@ CreaturesPanel::CreaturesPanel(CTradeableItem::ClickPressedFunctor clickPressedC
 
 	for(const auto & srcSlot : srcSlots)
 	{
-		auto slot = slots.emplace_back(std::make_shared<CTradeableItem>(slotsPos[srcSlot->serial],
+		auto slot = slots.emplace_back(std::make_shared<CTradeableItem>(Rect(slotsPos[srcSlot->serial], srcSlot->pos.dimensions()),
 			emptySlots ? EType::CREATURE_PLACEHOLDER : EType::CREATURE, srcSlot->id, true, srcSlot->serial));
 		slot->clickPressedCallback = clickPressedCallback;
 		slot->subtitle = emptySlots ? "" : srcSlot->subtitle;
-		slot->pos.w = srcSlot->pos.w; slot->pos.h = srcSlot->pos.h;
-		slot->selection = std::make_unique<SelectableSlot>(Rect(slotsPos[slot->serial], slot->pos.dimensions()), Point(1, 1), selectionWidth);
+		slot->setSelectionWidth(selectionWidth);
 	}
 }

+ 8 - 7
client/widgets/markets/TradePanels.h

@@ -9,19 +9,17 @@
  */
 #pragma once
 
+#include "../MiscWidgets.h"
 #include "../Images.h"
 
 #include "../../../lib/networkPacks/TradeItem.h"
 
-class CTextBox;
-class SelectableSlot;
-
 enum class EType
 {
 	RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
 };
 
-class CTradeableItem : public CIntObject, public std::enable_shared_from_this<CTradeableItem>
+class CTradeableItem : public SelectableSlot, public std::enable_shared_from_this<CTradeableItem>
 {
 public:
 	std::shared_ptr<CAnimImage> image;
@@ -29,7 +27,7 @@ public:
 	int getIndex();
 	using ClickPressedFunctor = std::function<void(const std::shared_ptr<CTradeableItem>&)>;
 
-	const CArtifactInstance * hlp; //holds ptr to artifact instance id type artifact
+	const CArtifactInstance * artInstance; //holds ptr to artifact instance id type artifact
 	EType type;
 	int id;
 	const int serial;
@@ -43,7 +41,6 @@ public:
 	const CArtifactInstance * getArtInstance() const;
 	void setArtInstance(const CArtifactInstance * art);
 
-	std::unique_ptr<SelectableSlot> selection;
 	bool downSelection;
 
 	void showAllAt(const Point & dstPos, const std::string & customSub, Canvas & to);
@@ -53,7 +50,7 @@ public:
 	void showAll(Canvas & to) override;
 	void clickPressed(const Point & cursorPosition) override;
 	std::string getName(int number = -1) const;
-	CTradeableItem(Point pos, EType Type, int ID, bool Left, int Serial);
+	CTradeableItem(const Rect & area, EType Type, int ID, bool Left, int Serial);
 };
 
 class TradePanelBase : public CIntObject
@@ -89,6 +86,7 @@ class ResourcesPanel : public TradePanelBase
 		Point(0, 79), Point(83, 79), Point(166, 79),
 		Point(83, 158)
 	};
+	const Point slotDimension = Point(69, 66);
 
 public:
 	ResourcesPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback, UpdateSlotsFunctor updateSubtitles);
@@ -103,6 +101,7 @@ class ArtifactsPanel : public TradePanelBase
 		Point(83, 158)
 	};
 	const size_t slotsForTrade = 7;
+	const Point slotDimension = Point(69, 66);
 
 public:
 	ArtifactsPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback, UpdateSlotsFunctor updateSubtitles,
@@ -117,6 +116,7 @@ class PlayersPanel : public TradePanelBase
 		Point(0, 118), Point(83, 118), Point(166, 118),
 		Point(83, 236)
 	};
+	const Point slotDimension = Point(58, 64);
 
 public:
 	explicit PlayersPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback);
@@ -130,6 +130,7 @@ class CreaturesPanel : public TradePanelBase
 		Point(0, 98), Point(83, 98), Point(166, 98),
 		Point(83, 196)
 	};
+	const Point slotDimension = Point(58, 64);
 
 public:
 	using slotsData = std::vector<std::tuple<CreatureID, SlotID, int>>;

+ 1 - 1
client/windows/CTradeWindow.cpp

@@ -77,7 +77,7 @@ void CTradeWindow::initItems(bool Left)
 	{
 		if(mode == EMarketMode::ARTIFACT_RESOURCE)
 		{
-			auto item = std::make_shared<CTradeableItem>(Point(137, 469), itemsType[Left], -1, 1, 0);
+			auto item = std::make_shared<CTradeableItem>(Rect(Point(137, 469), Point()), itemsType[Left], -1, 1, 0);
 			item->recActions &= ~(UPDATE | SHOWALL);
 			items[Left].push_back(item);
 		}