From f8c20ef77f934939a9489fbd7c89f632cf36a9c6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 00:20:24 +0200 Subject: [PATCH] don't allow putting items into a container if the weight is exceeded. --- apps/openmw/mwgui/container.cpp | 41 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 5ae943ea4..b7e0bf8b5 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -107,26 +107,45 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here { MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData(); + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); if (mDragAndDrop->mDraggedFrom != this) { assert(object.getContainerStore() && "Item is not in a container!"); - MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - int origCount = object.getRefData().getCount(); - object.getRefData().setCount (mDragAndDrop->mDraggedCount); - containerStore.add(object); - object.getRefData().setCount (origCount - mDragAndDrop->mDraggedCount); - } - else - { + // check that we don't exceed the allowed weight (only for containers, not for inventory) - if (isInventory()) + if (!isInventory()) { - float curWeight = MWWorld::Class::get(mContainer).getEncumbrance(mContainer); float capacity = MWWorld::Class::get(mContainer).getCapacity(mContainer); - + // try adding the item, and if weight is exceeded, just remove it again. + int origCount = object.getRefData().getCount(); + object.getRefData().setCount(mDragAndDrop->mDraggedCount); + MWWorld::ContainerStoreIterator it = containerStore.add(object); + + float curWeight = MWWorld::Class::get(mContainer).getEncumbrance(mContainer); + if (curWeight > capacity) + { + it->getRefData().setCount(0); + object.getRefData().setCount(origCount); + // user notification + MWBase::Environment::get().getWindowManager()-> + messageBox(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sContentsMessage3")->str, std::vector()); + return; + } + else + { + object.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount); + } + std::cout << "container weight " << curWeight << "/" << capacity << std::endl; + } + else + { + int origCount = object.getRefData().getCount(); + object.getRefData().setCount (mDragAndDrop->mDraggedCount); + containerStore.add(object); + object.getRefData().setCount (origCount - mDragAndDrop->mDraggedCount); } }