Browse Source

Merge pull request #72 from ArseniyShestakov/fixTradeWindow

Small fixes for CTradeWindow
DjWarmonger 10 years ago
parent
commit
9962623220
1 changed files with 27 additions and 18 deletions
  1. 27 18
      client/windows/CTradeWindow.cpp

+ 27 - 18
client/windows/CTradeWindow.cpp

@@ -125,6 +125,9 @@ int CTradeWindow::CTradeableItem::getIndex()
 
 void CTradeWindow::CTradeableItem::showAll(SDL_Surface * to)
 {
+	CTradeWindow *mw = dynamic_cast<CTradeWindow *>(parent);
+	assert(mw);
+
 	Point posToBitmap;
 	Point posToSubCenter;
 
@@ -137,7 +140,8 @@ void CTradeWindow::CTradeableItem::showAll(SDL_Surface * to)
 	case CREATURE_PLACEHOLDER:
 	case CREATURE:
 		posToSubCenter = Point(29, 76);
-		if(downSelection)
+		// Positing of unit count is different in Altar of Sacrifice and Freelancer's Guild
+		if(mw->mode == EMarketMode::CREATURE_EXP && downSelection)
 			posToSubCenter.y += 5;
 		break;
 	case PLAYER:
@@ -624,7 +628,7 @@ void CTradeWindow::artifactSelected(CArtPlace *slot)
 {
 	assert(mode == EMarketMode::ARTIFACT_RESOURCE);
 	items[1][0]->setArtInstance(slot->ourArt);
-	if(slot->ourArt)
+	if(slot->ourArt && !slot->locked)
 		hLeft = items[1][0];
 	else
 		hLeft = nullptr;
@@ -1155,10 +1159,18 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*=
 
 	deal = new CButton(Point(269, 520), "ALTSACR.DEF", CGI->generaltexth->zelp[585], std::bind(&CAltarWindow::makeDeal,this));
 
-	if(Hero->getAlignment() != ::EAlignment::EVIL && Mode == EMarketMode::CREATURE_EXP)
-		new CButton(Point(516, 421), "ALTART.DEF", CGI->generaltexth->zelp[580], std::bind(&CTradeWindow::setMode,this, EMarketMode::ARTIFACT_EXP));
-	if(Hero->getAlignment() != ::EAlignment::GOOD && Mode == EMarketMode::ARTIFACT_EXP)
-		new CButton(Point(516, 421), "ALTSACC.DEF", CGI->generaltexth->zelp[572], std::bind(&CTradeWindow::setMode,this, EMarketMode::CREATURE_EXP));
+	if(Mode == EMarketMode::CREATURE_EXP)
+	{
+		CButton *changeMode = new CButton(Point(516, 421), "ALTART.DEF", CGI->generaltexth->zelp[580], std::bind(&CTradeWindow::setMode,this, EMarketMode::ARTIFACT_EXP));
+		if (Hero->getAlignment() == ::EAlignment::EVIL)
+			changeMode->block(true);
+	}
+	if(Mode == EMarketMode::ARTIFACT_EXP)
+	{
+		CButton *changeMode = new CButton(Point(516, 421), "ALTSACC.DEF", CGI->generaltexth->zelp[572], std::bind(&CTradeWindow::setMode,this, EMarketMode::CREATURE_EXP));
+		if (Hero->getAlignment() == ::EAlignment::GOOD)
+			changeMode->block(true);
+	}
 
 	expPerUnit.resize(GameConstants::ARMY_SIZE, 0);
 	getExpValues();
@@ -1189,8 +1201,11 @@ void CAltarWindow::getBaseForPositions(EType type, int &dx, int &dy, int &x, int
 
 void CAltarWindow::sliderMoved(int to)
 {
-	sacrificedUnits[hLeft->serial] = to;
-	updateRight(hRight);
+	if(hLeft)
+		sacrificedUnits[hLeft->serial] = to;
+	if(hRight)
+		updateRight(hRight);
+
 	deal->block(!to);
 	calcTotalExp();
 	redraw();
@@ -1265,7 +1280,7 @@ void CAltarWindow::SacrificeAll()
 	{
 		for(auto i = hero->artifactsWorn.cbegin(); i != hero->artifactsWorn.cend(); i++)
 		{
-			if(i->second.artifact->artType->id != ArtifactID::ART_LOCK) //ignore locks from assembled artifacts
+			if(!i->second.locked) //ignore locks from assembled artifacts
 				moveFromSlotToAltar(i->first, nullptr, i->second.artifact);
 		}
 
@@ -1344,13 +1359,7 @@ void CAltarWindow::garrisonChanged()
 	std::set<CTradeableItem *> empty;
 	getEmptySlots(empty);
 
-	for(CTradeableItem *t : empty)
-	{
-		removeItem(*std::find_if(items[0].begin(), items[0].end(), [&](const CTradeableItem * item)
-		{
-			return item->serial == t->serial;
-		}));
-	}
+	removeItems(empty);
 
 	initSubs(true);
 	getExpValues();
@@ -1415,7 +1424,7 @@ int CAltarWindow::firstFreeSlot()
 {
 	int ret = -1;
 	while(items[0][++ret]->id >= 0  &&  ret + 1 < items[0].size());
-	return ret < items[0].size() ? ret : -1;
+	return items[0][ret]->id == -1 ? ret : -1;
 }
 
 void CAltarWindow::SacrificeBackpack()
@@ -1465,7 +1474,7 @@ bool CAltarWindow::putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance
 		return false;
 	}
 
-	if(!altarSlot)
+	if(!altarSlot || altarSlot->id != -1)
 	{
 		int slotIndex = firstFreeSlot();
 		if(slotIndex < 0)