Browse Source

Improvement quick recruitment window

-Position is now relative to castle interface
-The highest level of creature is now presented.
-Improve positioning of creature card, now it's look like in hd mod.
FeniksFire 8 years ago
parent
commit
3c3aaa7bb5

+ 2 - 2
client/windows/CCastleInterface.cpp

@@ -797,7 +797,7 @@ void CCastleBuildings::enterDwelling(int level)
 
 void CCastleBuildings::enterToTheQuickRecruitmentWindow()
 {
-	GH.pushInt(new QuickRecruitmentWindow(town));
+	GH.pushInt(new QuickRecruitmentWindow(town, pos));
 }
 
 void CCastleBuildings::enterFountain(BuildingID building)
@@ -996,7 +996,7 @@ void CCastleInterface::recreateIcons()
 
 	hall = new CTownInfo( 80, 413, town, true);
 	fort = new CTownInfo(122, 413, town, false);
-	fastArmyPurhase = new CButton(Point(122, 413), "itmcl.def", CButton::tooltip("quick army purhase"), [&](){builds->enterToTheQuickRecruitmentWindow();});
+	fastArmyPurhase = new CButton(Point(122, 413), "itmcl.def", CButton::tooltip(), [&](){builds->enterToTheQuickRecruitmentWindow();});
 	fastArmyPurhase->setImageOrder(town->fortLevel()-1,town->fortLevel()-1,town->fortLevel()-1,town->fortLevel()-1);
 	for (auto & elem : creainfo)
 		delete elem;

+ 7 - 7
client/windows/CreaturePurhaseCard.cpp

@@ -41,38 +41,38 @@ void CreaturePurhaseCard::initAmountInfo()
 
 void CreaturePurhaseCard::updateAmountInfo(int value)
 {
-	availableAmount->setText(boost::lexical_cast<std::string>(maxamount-value));
+	availableAmount->setText(boost::lexical_cast<std::string>(maxAmount-value));
 	purhaseAmount->setText(boost::lexical_cast<std::string>(value));
 }
 
 void CreaturePurhaseCard::initSlider()
 {
-	slider = std::make_shared<CSlider>(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurhaseCard::sliderMoved, this , _1), 0, maxamount, 0);
+	slider = std::make_shared<CSlider>(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurhaseCard::sliderMoved, this , _1), 0, maxAmount, 0);
 }
 
 void CreaturePurhaseCard::initCostBox()
 {
 	cost = std::make_shared<CreatureCostBox>(Rect(pos.x, pos.y + 194, 97, 74), "");
-	cost->createItems(creature->cost);
+	cost->createItems(creatureOnTheCard->cost);
 }
 
 
 void CreaturePurhaseCard::sliderMoved(int to)
 {
 	updateAmountInfo(to);
-	cost->set(creature->cost * to);
+	cost->set(creatureOnTheCard->cost * to);
 	parent->updateAllSliders();
 }
 
-CreaturePurhaseCard::CreaturePurhaseCard(const CCreature * monster, Point p, int amount, QuickRecruitmentWindow * par) : creature(monster), parent(par), maxamount(amount)
+CreaturePurhaseCard::CreaturePurhaseCard(const CCreature * creature, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents) : creatureOnTheCard(creature), parent(parents), maxAmount(creaturesMaxAmount)
 {
-	moveTo(Point(p.x, p.y));
+	moveTo(Point(position.x, position.y));
 	initView();
 }
 
 void CreaturePurhaseCard::initView()
 {
-	picture = std::make_shared<CCreaturePic>(pos.x, pos.y, creature);
+	picture = std::make_shared<CCreaturePic>(pos.x, pos.y, creatureOnTheCard);
 	initAmountInfo();
 	initSlider();
 	initButtons();

+ 3 - 3
client/windows/CreaturePurhaseCard.h

@@ -20,12 +20,12 @@ class QuickRecruitmentWindow;
 class CreaturePurhaseCard : public CIntObject
 {
 public:
-	const CCreature * creature;
+	const CCreature * creatureOnTheCard;
 	std::shared_ptr<CSlider> slider;
 	QuickRecruitmentWindow * parent;
-	int maxamount;
+	int maxAmount;
 	void sliderMoved(int to);
-	CreaturePurhaseCard(const CCreature * monster, Point p, int amount, QuickRecruitmentWindow * par);
+	CreaturePurhaseCard(const CCreature * creature, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents);
 
 private:
 	void initView();

+ 23 - 24
client/windows/QuickRecruitmentWindow.cpp

@@ -47,26 +47,24 @@ void QuickRecruitmentWindow::setMaxButton()
 
 void QuickRecruitmentWindow::setCreaturePurhaseCards()
 {
-	Point pos = Point(8,64);
-	for (int i=0; i < GameConstants::CREATURES_PER_TOWN; i++)
+	int availableAmount = getAvailableCreatures();
+	Point position = Point((pos.w - 100*availableAmount - 8*(availableAmount-1))/2,64);
+	for (int i = 0; i < GameConstants::CREATURES_PER_TOWN; i++)
 	{
 		if(!town->town->creatures.at(i).empty() && !town->creatures.at(i).second.empty() && town->creatures[i].first)
 		{
-			CreatureID crid = town->creatures[i].second[0];
-			if(town->creatures[i].second.size() > 1)
-				crid = town->creatures[i].second[1];
-
-			cards.push_back(std::make_shared<CreaturePurhaseCard>(VLC->creh->creatures[crid], pos, town->creatures[i].first, this));
-			pos.x += 108;
+			CreatureID crid = town->creatures[i].second[town->creatures[i].second.size() - 1];
+			cards.push_back(std::make_shared<CreaturePurhaseCard>(VLC->creh->creatures[crid], position, town->creatures[i].first, this));
+			position.x += 108;
 		}
 	}
-	totalCost = std::make_shared<CreatureCostBox>(Rect((this->pos.w/2)-45, pos.y + 260, 97, 74), "");
+	totalCost = std::make_shared<CreatureCostBox>(Rect((this->pos.w/2)-45, position.y+260, 97, 74), "");
 }
 
-void QuickRecruitmentWindow::initWindow()
+void QuickRecruitmentWindow::initWindow(Rect startupPosition)
 {
-	pos.x = 238;
-	pos.y = 45;
+	pos.x = startupPosition.x + 238;
+	pos.y = startupPosition.y + 45;
 	pos.w = 332;
 	pos.h = 461;
 	int creaturesAmount = getAvailableCreatures();
@@ -83,8 +81,8 @@ void QuickRecruitmentWindow::maxAllCards(std::vector<std::shared_ptr<CreaturePur
 	auto allAvailableResources = LOCPLINT->cb->getResourceAmount();
 	for(auto i : boost::adaptors::reverse(cards))
 	{
-		si32 maxAmount = i->creature->maxAmount(allAvailableResources);
-		vstd::amin(maxAmount, i->maxamount);
+		si32 maxAmount = i->creatureOnTheCard->maxAmount(allAvailableResources);
+		vstd::amin(maxAmount, i->maxAmount);
 
 		i->slider->setAmount(maxAmount);
 
@@ -94,7 +92,7 @@ void QuickRecruitmentWindow::maxAllCards(std::vector<std::shared_ptr<CreaturePur
 			i->sliderMoved(maxAmount);
 
 		i->slider->moveToMax();
-		allAvailableResources -= (i->creature->cost * maxAmount);
+		allAvailableResources -= (i->creatureOnTheCard->cost * maxAmount);
 	}
 	maxButton->block(allAvailableResources == LOCPLINT->cb->getResourceAmount());
 }
@@ -106,8 +104,8 @@ void QuickRecruitmentWindow::purhaseUnits()
 	{
 		if(selected->slider->getValue())
 		{
-			auto onRecruit = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, selected->creature->level-1); };
-			CreatureID crid =  selected->creature->idNumber;
+			auto onRecruit = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, selected->creatureOnTheCard->level-1); };
+			CreatureID crid =  selected->creatureOnTheCard->idNumber;
 			SlotID dstslot = town -> getSlotFor(crid);
 			if(!dstslot.validSlot())
 				continue;
@@ -130,28 +128,29 @@ void QuickRecruitmentWindow::updateAllSliders()
 {
 	auto allAvailableResources = LOCPLINT->cb->getResourceAmount();
 	for(auto i : boost::adaptors::reverse(cards))
-		allAvailableResources -= (i->creature->cost * i->slider->getValue());
+		allAvailableResources -= (i->creatureOnTheCard->cost * i->slider->getValue());
 	for(auto i : cards)
 	{
-		si32 maxAmount = i->creature->maxAmount(allAvailableResources);
-		vstd::amin(maxAmount, i->maxamount);
+		si32 maxAmount = i->creatureOnTheCard->maxAmount(allAvailableResources);
+		vstd::amin(maxAmount, i->maxAmount);
 		if(maxAmount < 0)
 			continue;
-		if(i->slider->getValue() + maxAmount < i->maxamount)
+		if(i->slider->getValue() + maxAmount < i->maxAmount)
 			i->slider->setAmount(i->slider->getValue() + maxAmount);
 		else
-			i->slider->setAmount(i->maxamount);
+			i->slider->setAmount(i->maxAmount);
 		i->slider->moveTo(i->slider->getValue());
 	}
 	totalCost->createItems(LOCPLINT->cb->getResourceAmount() - allAvailableResources);
 	totalCost->set(LOCPLINT->cb->getResourceAmount() - allAvailableResources);
 }
 
-QuickRecruitmentWindow::QuickRecruitmentWindow(const CGTownInstance * townd) : CWindowObject(PLAYER_COLORED | BORDERED), town(townd)
+QuickRecruitmentWindow::QuickRecruitmentWindow(const CGTownInstance * townd, Rect startupPosition)
+	: CWindowObject(PLAYER_COLORED | BORDERED), town(townd)
 {
 	OBJECT_CONSTRUCTION_CAPTURING(ACTIVATE + DEACTIVATE + UPDATE + SHOWALL);
 
-	initWindow();
+	initWindow(startupPosition);
 	setButtons();
 	setCreaturePurhaseCards();
 	maxAllCards(cards);

+ 2 - 2
client/windows/QuickRecruitmentWindow.h

@@ -21,10 +21,10 @@ class QuickRecruitmentWindow : public CWindowObject
 public:
 	int getAvailableCreatures();
 	void updateAllSliders();
-	QuickRecruitmentWindow(const CGTownInstance * townd);
+	QuickRecruitmentWindow(const CGTownInstance * townd, Rect startupPosition);
 
 private:
-	void initWindow();
+	void initWindow(Rect startupPosition);
 
 	void setButtons();
 	void setCancelButton();