From c775e05d7a5e2f4b723164cedcfbc2f0fa76f0d8 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 24 Aug 2014 19:15:02 +0200 Subject: [PATCH] Show encumbrance preview when trading (Fixes #1793) --- apps/openmw/mwgui/inventorywindow.cpp | 1 + apps/openmw/mwgui/tradeitemmodel.cpp | 15 +++++++++++++++ apps/openmw/mwgui/tradeitemmodel.hpp | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index a044d014f..441d8c28f 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -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); } diff --git a/apps/openmw/mwgui/tradeitemmodel.cpp b/apps/openmw/mwgui/tradeitemmodel.cpp index 5fdf604da..7ac14f7b5 100644 --- a/apps/openmw/mwgui/tradeitemmodel.cpp +++ b/apps/openmw/mwgui/tradeitemmodel.cpp @@ -93,6 +93,21 @@ namespace MWGui unborrowImpl(item, count, mBorrowedFromUs); } + void TradeItemModel::adjustEncumbrance(float &encumbrance) + { + for (std::vector::iterator it = mBorrowedToUs.begin(); it != mBorrowedToUs.end(); ++it) + { + MWWorld::Ptr item = it->mBase; + encumbrance += item.getClass().getWeight(item) * it->mCount; + } + for (std::vector::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(); diff --git a/apps/openmw/mwgui/tradeitemmodel.hpp b/apps/openmw/mwgui/tradeitemmodel.hpp index 5cfaaafc7..1bfee9b2a 100644 --- a/apps/openmw/mwgui/tradeitemmodel.hpp +++ b/apps/openmw/mwgui/tradeitemmodel.hpp @@ -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 getItemsBorrowedToUs(); private: