mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
fix build & suggested changed
This commit is contained in:
parent
539b2e596d
commit
41ee52d9d4
@ -73,29 +73,7 @@ CAltarArtifacts::CAltarArtifacts(const IMarket * market, const CGHeroInstance *
|
||||
for(auto & altarSlotPos : posSlotsAltar)
|
||||
{
|
||||
auto altarSlot = std::make_shared<CTradeableItem>(altarSlotPos, EType::ARTIFACT_PLACEHOLDER, -1, false, slotNum++);
|
||||
altarSlot->clickPressedCallback = [this](std::shared_ptr<CTradeableItem> altarSlot) -> void
|
||||
{
|
||||
const auto pickedArtInst = arts->getPickedArtifact();
|
||||
if(pickedArtInst)
|
||||
{
|
||||
arts->pickedArtMoveToAltar(ArtifactPosition::TRANSITION_POS);
|
||||
moveArtToAltar(altarSlot, pickedArtInst);
|
||||
}
|
||||
else if(const CArtifactInstance * art = altarSlot->getArtInstance())
|
||||
{
|
||||
const auto hero = arts->getHero();
|
||||
const auto slot = hero->getSlotByInstance(art);
|
||||
assert(slot != ArtifactPosition::PRE_FIRST);
|
||||
LOCPLINT->cb->swapArtifacts(ArtifactLocation(hero->id, slot),
|
||||
ArtifactLocation(hero->id, ArtifactPosition::TRANSITION_POS));
|
||||
arts->pickedArtFromSlot = slot;
|
||||
arts->artifactsOnAltar.erase(art);
|
||||
altarSlot->setID(-1);
|
||||
altarSlot->subtitle.clear();
|
||||
deal->block(!arts->artifactsOnAltar.size());
|
||||
}
|
||||
calcExpAltarForHero();
|
||||
};
|
||||
altarSlot->clickPressedCallback = std::bind(&CAltarArtifacts::onSlotClickPressed, this, _1);
|
||||
altarSlot->subtitle = "";
|
||||
items.front().emplace_back(altarSlot);
|
||||
}
|
||||
@ -227,6 +205,30 @@ bool CAltarArtifacts::putArtOnAltar(std::shared_ptr<CTradeableItem> altarSlot, c
|
||||
return true;
|
||||
};
|
||||
|
||||
void CAltarArtifacts::onSlotClickPressed(std::shared_ptr<CTradeableItem> altarSlot)
|
||||
{
|
||||
const auto pickedArtInst = arts->getPickedArtifact();
|
||||
if(pickedArtInst)
|
||||
{
|
||||
arts->pickedArtMoveToAltar(ArtifactPosition::TRANSITION_POS);
|
||||
moveArtToAltar(altarSlot, pickedArtInst);
|
||||
}
|
||||
else if(const CArtifactInstance * art = altarSlot->getArtInstance())
|
||||
{
|
||||
const auto hero = arts->getHero();
|
||||
const auto slot = hero->getSlotByInstance(art);
|
||||
assert(slot != ArtifactPosition::PRE_FIRST);
|
||||
LOCPLINT->cb->swapArtifacts(ArtifactLocation(hero->id, slot),
|
||||
ArtifactLocation(hero->id, ArtifactPosition::TRANSITION_POS));
|
||||
arts->pickedArtFromSlot = slot;
|
||||
arts->artifactsOnAltar.erase(art);
|
||||
altarSlot->setID(-1);
|
||||
altarSlot->subtitle.clear();
|
||||
deal->block(!arts->artifactsOnAltar.size());
|
||||
}
|
||||
calcExpAltarForHero();
|
||||
}
|
||||
|
||||
CAltarCreatures::CAltarCreatures(const IMarket * market, const CGHeroInstance * hero)
|
||||
: CAltar(market, hero)
|
||||
{
|
||||
@ -239,16 +241,7 @@ CAltarCreatures::CAltarCreatures(const IMarket * market, const CGHeroInstance *
|
||||
lSubtitle = std::make_shared<CLabel>(180, 503, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
||||
rSubtitle = std::make_shared<CLabel>(426, 503, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
||||
|
||||
unitsSlider = std::make_shared<CSlider>(Point(231, 481), 137, [this](int newVal) -> void
|
||||
{
|
||||
if(hLeft)
|
||||
unitsOnAltar[hLeft->serial] = newVal;
|
||||
if(hRight)
|
||||
updateAltarSlot(hRight);
|
||||
deal->block(calcExpAltarForHero() == 0);
|
||||
updateControls();
|
||||
updateSubtitlesForSelected();
|
||||
}, 0, 0, 0, Orientation::HORIZONTAL);
|
||||
unitsSlider = std::make_shared<CSlider>(Point(231, 481), 137, std::bind(&CAltarCreatures::onUnitsSliderMoved, this, _1), 0, 0, 0, Orientation::HORIZONTAL);
|
||||
maxUnits = std::make_shared<CButton>(Point(147, 520), AnimationPath::builtin("IRCBTNS.DEF"), CGI->generaltexth->zelp[578], std::bind(&CSlider::scrollToMax, unitsSlider));
|
||||
|
||||
unitsOnAltar.resize(GameConstants::ARMY_SIZE, 0);
|
||||
@ -256,27 +249,7 @@ CAltarCreatures::CAltarCreatures(const IMarket * market, const CGHeroInstance *
|
||||
sacrificeAllButton = std::make_shared<CButton>(
|
||||
Point(393, 520), AnimationPath::builtin("ALTARMY.DEF"), CGI->generaltexth->zelp[579], std::bind(&CAltar::sacrificeAll, this));
|
||||
|
||||
auto clickPressed = [this](std::shared_ptr<CTradeableItem> altarSlot, std::vector<std::shared_ptr<CTradeableItem>> & oppositeSlots,
|
||||
std::shared_ptr<CTradeableItem> & hCurSide, std::shared_ptr<CTradeableItem> & hOppSide) -> void
|
||||
{
|
||||
std::shared_ptr<CTradeableItem> oppositeSlot;
|
||||
for(const auto & slot : oppositeSlots)
|
||||
if(slot->serial == altarSlot->serial)
|
||||
{
|
||||
oppositeSlot = slot;
|
||||
break;
|
||||
}
|
||||
|
||||
if(hCurSide != altarSlot && oppositeSlot)
|
||||
{
|
||||
hCurSide = altarSlot;
|
||||
hOppSide = oppositeSlot;
|
||||
updateControls();
|
||||
updateSubtitlesForSelected();
|
||||
redraw();
|
||||
}
|
||||
};
|
||||
|
||||
// Creating slots for hero creatures
|
||||
for(int slotIdx = 0; slotIdx < GameConstants::ARMY_SIZE; slotIdx++)
|
||||
{
|
||||
CreatureID creatureId = CreatureID::NONE;
|
||||
@ -286,21 +259,23 @@ CAltarCreatures::CAltarCreatures(const IMarket * market, const CGHeroInstance *
|
||||
continue;
|
||||
|
||||
auto heroSlot = std::make_shared<CTradeableItem>(posSlotsHero[slotIdx], EType::CREATURE, creatureId.num, true, slotIdx);
|
||||
heroSlot->clickPressedCallback = [this, clickPressed](std::shared_ptr<CTradeableItem> altarSlot) -> void
|
||||
heroSlot->clickPressedCallback = [this](std::shared_ptr<CTradeableItem> altarSlot) -> void
|
||||
{
|
||||
clickPressed(altarSlot, items[0], hLeft, hRight);
|
||||
onSlotClickPressed(altarSlot, items[0], hLeft, hRight);
|
||||
};
|
||||
heroSlot->subtitle = std::to_string(hero->getStackCount(SlotID(slotIdx)));
|
||||
items[1].emplace_back(heroSlot);
|
||||
}
|
||||
|
||||
// Creating slots for creatures on altar
|
||||
assert(items[1].size() <= posSlotsAltar.size());
|
||||
for(const auto & heroSlot : items[1])
|
||||
{
|
||||
auto altarSlot = std::make_shared<CTradeableItem>(posSlotsAltar[heroSlot->serial], EType::CREATURE_PLACEHOLDER, heroSlot->id, false, heroSlot->serial);
|
||||
altarSlot->pos.w = heroSlot->pos.w; altarSlot->pos.h = heroSlot->pos.h;
|
||||
altarSlot->clickPressedCallback = [this, clickPressed](std::shared_ptr<CTradeableItem> altarSlot) -> void
|
||||
altarSlot->clickPressedCallback = [this](std::shared_ptr<CTradeableItem> altarSlot) -> void
|
||||
{
|
||||
clickPressed(altarSlot, items[1], hRight, hLeft);
|
||||
onSlotClickPressed(altarSlot, items[1], hRight, hLeft);
|
||||
};
|
||||
items[0].emplace_back(altarSlot);
|
||||
}
|
||||
@ -454,4 +429,37 @@ void CAltarCreatures::updateAltarSlot(std::shared_ptr<CTradeableItem> slot)
|
||||
slot->setType(units > 0 ? CREATURE : CREATURE_PLACEHOLDER);
|
||||
slot->subtitle = units > 0 ?
|
||||
boost::str(boost::format(CGI->generaltexth->allTexts[122]) % std::to_string(hero->calculateXp(units * expPerUnit[slot->serial]))) : "";
|
||||
}
|
||||
}
|
||||
|
||||
void CAltarCreatures::onUnitsSliderMoved(int newVal)
|
||||
{
|
||||
if(hLeft)
|
||||
unitsOnAltar[hLeft->serial] = newVal;
|
||||
if(hRight)
|
||||
updateAltarSlot(hRight);
|
||||
deal->block(calcExpAltarForHero() == 0);
|
||||
updateControls();
|
||||
updateSubtitlesForSelected();
|
||||
}
|
||||
|
||||
void CAltarCreatures::onSlotClickPressed(std::shared_ptr<CTradeableItem> altarSlot,
|
||||
std::vector<std::shared_ptr<CTradeableItem>> & oppositeSlots,
|
||||
std::shared_ptr<CTradeableItem> & hCurSide, std::shared_ptr<CTradeableItem> & hOppSide)
|
||||
{
|
||||
std::shared_ptr<CTradeableItem> oppositeSlot;
|
||||
for(const auto & slot : oppositeSlots)
|
||||
if(slot->serial == altarSlot->serial)
|
||||
{
|
||||
oppositeSlot = slot;
|
||||
break;
|
||||
}
|
||||
|
||||
if(hCurSide != altarSlot && oppositeSlot)
|
||||
{
|
||||
hCurSide = altarSlot;
|
||||
hOppSide = oppositeSlot;
|
||||
updateControls();
|
||||
updateSubtitlesForSelected();
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ private:
|
||||
};
|
||||
|
||||
bool putArtOnAltar(std::shared_ptr<CTradeableItem> altarSlot, const CArtifactInstance * art);
|
||||
void onSlotClickPressed(std::shared_ptr<CTradeableItem> altarSlot);
|
||||
};
|
||||
|
||||
class CAltarCreatures : public CAltar
|
||||
@ -95,4 +96,8 @@ private:
|
||||
void readExpValues();
|
||||
void updateControls();
|
||||
void updateSubtitlesForSelected();
|
||||
void onUnitsSliderMoved(int newVal);
|
||||
void onSlotClickPressed(std::shared_ptr<CTradeableItem> altarSlot,
|
||||
std::vector<std::shared_ptr<CTradeableItem>> & oppositeSlots,
|
||||
std::shared_ptr<CTradeableItem> & hCurSide, std::shared_ptr<CTradeableItem> & hOppSide);
|
||||
};
|
||||
|
@ -30,12 +30,12 @@ CAltarWindow::CAltarWindow(const IMarket * market, const CGHeroInstance * hero,
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255 - DISPOSE);
|
||||
|
||||
assert(mode == EMarketMode::ARTIFACT_EXP || mode == EMarketMode::CREATURE_EXP);
|
||||
if(mode == EMarketMode::ARTIFACT_EXP)
|
||||
createAltarArtifacts(market, hero);
|
||||
else if (mode == EMarketMode::CREATURE_EXP)
|
||||
else if(mode == EMarketMode::CREATURE_EXP)
|
||||
createAltarCreatures(market, hero);
|
||||
else
|
||||
close();
|
||||
|
||||
updateExpToLevel();
|
||||
statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
|
||||
}
|
||||
|
@ -163,9 +163,46 @@ void CTradeWindow::getPositionsFor(std::vector<Rect> &poss, bool Left, EType typ
|
||||
// X X X
|
||||
// X X X
|
||||
// X
|
||||
int h, w, x, y, dx, dy;
|
||||
int leftToRightOffset;
|
||||
getBaseForPositions(type, dx, dy, x, y, h, w, !Left, leftToRightOffset);
|
||||
int h = 0, w = 0, x = 0, y = 0, dx = 0, dy = 0;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case RESOURCE:
|
||||
dx = 82;
|
||||
dy = 79;
|
||||
x = 39;
|
||||
y = 180;
|
||||
h = 68;
|
||||
w = 70;
|
||||
break;
|
||||
case PLAYER:
|
||||
dx = 83;
|
||||
dy = 118;
|
||||
h = 64;
|
||||
w = 58;
|
||||
x = 44;
|
||||
y = 83;
|
||||
assert(!Left);
|
||||
break;
|
||||
case CREATURE://45,123
|
||||
x = 45;
|
||||
y = 123;
|
||||
w = 58;
|
||||
h = 64;
|
||||
dx = 83;
|
||||
dy = 98;
|
||||
assert(Left);
|
||||
break;
|
||||
case ARTIFACT_TYPE://45,123
|
||||
x = 340 - 289;
|
||||
y = 180;
|
||||
w = 44;
|
||||
h = 44;
|
||||
dx = 83;
|
||||
dy = 79;
|
||||
break;
|
||||
}
|
||||
int leftToRightOffset = 289;
|
||||
|
||||
const std::vector<Rect> tmp =
|
||||
{
|
||||
@ -672,49 +709,6 @@ void CMarketplaceWindow::resourceChanged()
|
||||
initSubs(true);
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case RESOURCE:
|
||||
dx = 82;
|
||||
dy = 79;
|
||||
x = 39;
|
||||
y = 180;
|
||||
h = 68;
|
||||
w = 70;
|
||||
break;
|
||||
case PLAYER:
|
||||
dx = 83;
|
||||
dy = 118;
|
||||
h = 64;
|
||||
w = 58;
|
||||
x = 44;
|
||||
y = 83;
|
||||
assert(Right);
|
||||
break;
|
||||
case CREATURE://45,123
|
||||
x = 45;
|
||||
y = 123;
|
||||
w = 58;
|
||||
h = 64;
|
||||
dx = 83;
|
||||
dy = 98;
|
||||
assert(!Right);
|
||||
break;
|
||||
case ARTIFACT_TYPE://45,123
|
||||
x = 340-289;
|
||||
y = 180;
|
||||
w = 44;
|
||||
h = 44;
|
||||
dx = 83;
|
||||
dy = 79;
|
||||
break;
|
||||
}
|
||||
|
||||
leftToRightOffset = 289;
|
||||
}
|
||||
|
||||
void CMarketplaceWindow::updateTraderText()
|
||||
{
|
||||
if(readyToTrade)
|
||||
|
@ -41,8 +41,6 @@ public:
|
||||
void setMode(EMarketMode Mode); //mode setter
|
||||
|
||||
void artifactSelected(CHeroArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot
|
||||
|
||||
virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0;
|
||||
virtual void selectionChanged(bool side) = 0; //true == left
|
||||
virtual Point selectionOffset(bool Left) const = 0;
|
||||
virtual std::string updateSlotSubtitle(bool Left) const = 0;
|
||||
@ -80,7 +78,5 @@ public:
|
||||
void updateGarrison() override; //removes creatures with count 0 from the list (apparently whole stack has been sold)
|
||||
void artifactsChanged(bool left) override;
|
||||
void resourceChanged();
|
||||
|
||||
void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const override;
|
||||
void updateTraderText();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user