|
|
|
@ -8,12 +8,10 @@
|
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
|
#include "../mwbase/dialoguemanager.hpp"
|
|
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
|
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
#include "../mwworld/inventorystore.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwmechanics/pickpocket.hpp"
|
|
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
|
|
|
|
|
|
|
|
|
#include "countdialog.hpp"
|
|
|
|
@ -33,7 +31,6 @@ namespace MWGui
|
|
|
|
|
ContainerWindow::ContainerWindow(DragAndDrop* dragAndDrop)
|
|
|
|
|
: WindowBase("openmw_container_window.layout")
|
|
|
|
|
, mDragAndDrop(dragAndDrop)
|
|
|
|
|
, mPickpocketDetected(false)
|
|
|
|
|
, mSortModel(NULL)
|
|
|
|
|
, mModel(NULL)
|
|
|
|
|
, mSelectedItem(-1)
|
|
|
|
@ -55,10 +52,9 @@ namespace MWGui
|
|
|
|
|
|
|
|
|
|
void ContainerWindow::onItemSelected(int index)
|
|
|
|
|
{
|
|
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop)
|
|
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop && mModel)
|
|
|
|
|
{
|
|
|
|
|
if (mModel && mModel->allowedToInsertItems())
|
|
|
|
|
dropItem();
|
|
|
|
|
dropItem();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -100,39 +96,20 @@ namespace MWGui
|
|
|
|
|
|
|
|
|
|
void ContainerWindow::dropItem()
|
|
|
|
|
{
|
|
|
|
|
if (mPtr.getTypeName() == typeid(ESM::Container).name())
|
|
|
|
|
{
|
|
|
|
|
// check container organic flag
|
|
|
|
|
MWWorld::LiveCellRef<ESM::Container>* ref = mPtr.get<ESM::Container>();
|
|
|
|
|
if (ref->mBase->mFlags & ESM::Container::Organic)
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->
|
|
|
|
|
messageBox("#{sContentsMessage2}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bool success = mModel->onDropItem(mDragAndDrop->mItem.mBase, mDragAndDrop->mDraggedCount);
|
|
|
|
|
|
|
|
|
|
// check that we don't exceed container capacity
|
|
|
|
|
MWWorld::Ptr item = mDragAndDrop->mItem.mBase;
|
|
|
|
|
float weight = item.getClass().getWeight(item) * mDragAndDrop->mDraggedCount;
|
|
|
|
|
if (mPtr.getClass().getCapacity(mPtr) < mPtr.getClass().getEncumbrance(mPtr) + weight)
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sContentsMessage3}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mDragAndDrop->drop(mModel, mItemView);
|
|
|
|
|
if (success)
|
|
|
|
|
mDragAndDrop->drop(mModel, mItemView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerWindow::onBackgroundSelected()
|
|
|
|
|
{
|
|
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop && mModel && mModel->allowedToInsertItems())
|
|
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop && mModel)
|
|
|
|
|
dropItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerWindow::setPtr(const MWWorld::Ptr& container)
|
|
|
|
|
{
|
|
|
|
|
mPickpocketDetected = false;
|
|
|
|
|
mPtr = container;
|
|
|
|
|
|
|
|
|
|
bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead();
|
|
|
|
@ -142,8 +119,7 @@ namespace MWGui
|
|
|
|
|
if (mPtr.getClass().isNpc() && !loot)
|
|
|
|
|
{
|
|
|
|
|
// we are stealing stuff
|
|
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
|
mModel = new PickpocketItemModel(player, new InventoryItemModel(container),
|
|
|
|
|
mModel = new PickpocketItemModel(mPtr, new InventoryItemModel(container),
|
|
|
|
|
!mPtr.getClass().getCreatureStats(mPtr).getKnockedDown());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -178,24 +154,7 @@ namespace MWGui
|
|
|
|
|
{
|
|
|
|
|
WindowBase::onClose();
|
|
|
|
|
|
|
|
|
|
if (dynamic_cast<PickpocketItemModel*>(mModel)
|
|
|
|
|
// Make sure we were actually closed, rather than just temporarily hidden (e.g. console or main menu opened)
|
|
|
|
|
&& !MWBase::Environment::get().getWindowManager()->containsMode(GM_Container)
|
|
|
|
|
// If it was already detected while taking an item, no need to check now
|
|
|
|
|
&& !mPickpocketDetected
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
|
MWMechanics::Pickpocket pickpocket(player, mPtr);
|
|
|
|
|
if (pickpocket.finish())
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->commitCrime(
|
|
|
|
|
player, mPtr, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
|
|
|
|
|
mPickpocketDetected = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mModel->onClose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
@ -271,32 +230,7 @@ namespace MWGui
|
|
|
|
|
|
|
|
|
|
bool ContainerWindow::onTakeItem(const ItemStack &item, int count)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
|
// TODO: move to ItemModels
|
|
|
|
|
if (dynamic_cast<PickpocketItemModel*>(mModel)
|
|
|
|
|
&& !mPtr.getClass().getCreatureStats(mPtr).getKnockedDown())
|
|
|
|
|
{
|
|
|
|
|
MWMechanics::Pickpocket pickpocket(player, mPtr);
|
|
|
|
|
if (pickpocket.pick(item.mBase, count))
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->commitCrime(
|
|
|
|
|
player, mPtr, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
|
|
|
|
|
mPickpocketDetected = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
player.getClass().skillUsageSucceeded(player, ESM::Skill::Sneak, 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Looting a dead corpse is considered OK
|
|
|
|
|
if (mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead())
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item.mBase, mPtr, count);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
return mModel->onTakeItem(item.mBase, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|