Show encumbrance preview when trading (Fixes #1793)

This commit is contained in:
scrawl 2014-08-24 19:15:02 +02:00
parent f1f38fc786
commit c775e05d7a
3 changed files with 20 additions and 0 deletions

View file

@ -493,6 +493,7 @@ namespace MWGui
float capacity = player.getClass().getCapacity(player);
float encumbrance = player.getClass().getEncumbrance(player);
mTradeModel->adjustEncumbrance(encumbrance);
mEncumbranceBar->setValue(encumbrance, capacity);
}

View file

@ -93,6 +93,21 @@ namespace MWGui
unborrowImpl(item, count, mBorrowedFromUs);
}
void TradeItemModel::adjustEncumbrance(float &encumbrance)
{
for (std::vector<ItemStack>::iterator it = mBorrowedToUs.begin(); it != mBorrowedToUs.end(); ++it)
{
MWWorld::Ptr item = it->mBase;
encumbrance += item.getClass().getWeight(item) * it->mCount;
}
for (std::vector<ItemStack>::iterator it = mBorrowedFromUs.begin(); it != mBorrowedFromUs.end(); ++it)
{
MWWorld::Ptr item = it->mBase;
encumbrance -= item.getClass().getWeight(item) * it->mCount;
}
encumbrance = std::max(0.f, encumbrance);
}
void TradeItemModel::abort()
{
mBorrowedFromUs.clear();

View file

@ -34,6 +34,10 @@ namespace MWGui
/// Aborts trade
void abort();
/// Adjusts the given encumbrance by adding weight for items that have been lent to us,
/// and removing weight for items we've lent to someone else.
void adjustEncumbrance (float& encumbrance);
std::vector<ItemStack> getItemsBorrowedToUs();
private: