2012-04-15 15:52:39 +00:00
|
|
|
#include "container.hpp"
|
|
|
|
|
2015-01-10 01:50:43 +00:00
|
|
|
#include <MyGUI_InputManager.h>
|
|
|
|
#include <MyGUI_Button.h>
|
|
|
|
|
2012-05-11 09:52:07 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-09 12:33:21 +00:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2014-01-07 02:01:33 +00:00
|
|
|
#include "../mwbase/dialoguemanager.hpp"
|
2014-01-07 18:49:16 +00:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2015-08-21 09:12:39 +00:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
|
2014-01-07 02:01:33 +00:00
|
|
|
#include "../mwmechanics/pickpocket.hpp"
|
2014-04-27 03:40:07 +00:00
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
2014-01-07 02:01:33 +00:00
|
|
|
|
2012-05-15 10:51:51 +00:00
|
|
|
#include "countdialog.hpp"
|
2012-05-18 15:27:55 +00:00
|
|
|
#include "inventorywindow.hpp"
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
#include "itemview.hpp"
|
2014-06-05 20:13:18 +00:00
|
|
|
#include "itemwidget.hpp"
|
2013-05-11 16:38:27 +00:00
|
|
|
#include "inventoryitemmodel.hpp"
|
|
|
|
#include "sortfilteritemmodel.hpp"
|
|
|
|
#include "pickpocketitemmodel.hpp"
|
2015-01-10 00:21:17 +00:00
|
|
|
#include "draganddrop.hpp"
|
2013-05-11 16:38:27 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
namespace MWGui
|
2012-04-15 15:52:39 +00:00
|
|
|
{
|
2012-05-12 20:44:12 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
ContainerWindow::ContainerWindow(DragAndDrop* dragAndDrop)
|
|
|
|
: WindowBase("openmw_container_window.layout")
|
|
|
|
, mDragAndDrop(dragAndDrop)
|
2014-01-07 02:01:33 +00:00
|
|
|
, mPickpocketDetected(false)
|
2015-05-01 00:24:27 +00:00
|
|
|
, mSortModel(NULL)
|
|
|
|
, mModel(NULL)
|
|
|
|
, mSelectedItem(-1)
|
2012-05-15 18:33:34 +00:00
|
|
|
{
|
2013-05-11 16:38:27 +00:00
|
|
|
getWidget(mDisposeCorpseButton, "DisposeCorpseButton");
|
|
|
|
getWidget(mTakeButton, "TakeButton");
|
|
|
|
getWidget(mCloseButton, "CloseButton");
|
2012-05-15 19:44:57 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
getWidget(mItemView, "ItemView");
|
|
|
|
mItemView->eventBackgroundClicked += MyGUI::newDelegate(this, &ContainerWindow::onBackgroundSelected);
|
|
|
|
mItemView->eventItemClicked += MyGUI::newDelegate(this, &ContainerWindow::onItemSelected);
|
2013-03-16 18:00:14 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
mDisposeCorpseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onDisposeCorpseButtonClicked);
|
|
|
|
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked);
|
2014-01-10 23:24:21 +00:00
|
|
|
mCloseButton->eventKeyButtonPressed += MyGUI::newDelegate(this, &ContainerWindow::onKeyPressed);
|
2013-05-11 16:38:27 +00:00
|
|
|
mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked);
|
2013-03-16 18:00:14 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
setCoord(200,0,600,300);
|
|
|
|
}
|
2013-03-16 18:00:14 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
void ContainerWindow::onItemSelected(int index)
|
|
|
|
{
|
2014-09-11 05:00:39 +00:00
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop)
|
|
|
|
{
|
|
|
|
if (!dynamic_cast<PickpocketItemModel*>(mModel))
|
|
|
|
dropItem();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-11 03:38:38 +00:00
|
|
|
const ItemStack& item = mSortModel->getItem(index);
|
|
|
|
|
|
|
|
// We can't take a conjured item from a container (some NPC we're pickpocketing, a box, etc)
|
2014-09-13 22:48:41 +00:00
|
|
|
if (item.mFlags & ItemStack::Flag_Bound)
|
2014-09-11 03:38:38 +00:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sContentsMessage1}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
MWWorld::Ptr object = item.mBase;
|
|
|
|
int count = item.mCount;
|
|
|
|
bool shift = MyGUI::InputManager::getInstance().isShiftPressed();
|
|
|
|
if (MyGUI::InputManager::getInstance().isControlPressed())
|
|
|
|
count = 1;
|
2012-05-15 18:33:34 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
mSelectedItem = mSortModel->mapToSource(index);
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
if (count > 1 && !shift)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
2013-05-11 16:38:27 +00:00
|
|
|
CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog();
|
2015-06-04 18:31:28 +00:00
|
|
|
dialog->openCountDialog(object.getClass().getName(object), "#{sTake}", count);
|
2013-05-11 16:38:27 +00:00
|
|
|
dialog->eventOkClicked.clear();
|
|
|
|
dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::dragItem);
|
2012-05-06 09:04:07 +00:00
|
|
|
}
|
2013-04-17 22:56:48 +00:00
|
|
|
else
|
2013-05-11 16:38:27 +00:00
|
|
|
dragItem (NULL, count);
|
2012-05-18 18:53:24 +00:00
|
|
|
}
|
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
void ContainerWindow::dragItem(MyGUI::Widget* sender, int count)
|
2012-05-18 18:53:24 +00:00
|
|
|
{
|
2014-01-07 02:01:33 +00:00
|
|
|
if (!onTakeItem(mModel->getItem(mSelectedItem), count))
|
|
|
|
return;
|
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mModel, mItemView, count);
|
2012-05-18 15:27:55 +00:00
|
|
|
}
|
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
void ContainerWindow::dropItem()
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
2013-05-11 16:38:27 +00:00
|
|
|
if (mPtr.getTypeName() == typeid(ESM::Container).name())
|
2013-03-07 13:00:13 +00:00
|
|
|
{
|
2013-05-11 16:38:27 +00:00
|
|
|
// check container organic flag
|
|
|
|
MWWorld::LiveCellRef<ESM::Container>* ref = mPtr.get<ESM::Container>();
|
|
|
|
if (ref->mBase->mFlags & ESM::Container::Organic)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
2013-05-11 16:38:27 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->
|
|
|
|
messageBox("#{sContentsMessage2}");
|
|
|
|
return;
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2014-07-14 15:27:36 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2012-05-12 20:44:12 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
mDragAndDrop->drop(mModel, mItemView);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2012-05-12 20:44:12 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
void ContainerWindow::onBackgroundSelected()
|
2012-04-30 11:01:18 +00:00
|
|
|
{
|
2013-05-11 16:38:27 +00:00
|
|
|
if (mDragAndDrop->mIsOnDragAndDrop && !dynamic_cast<PickpocketItemModel*>(mModel))
|
|
|
|
dropItem();
|
2012-04-30 11:01:18 +00:00
|
|
|
}
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2015-06-04 18:31:28 +00:00
|
|
|
void ContainerWindow::openContainer(const MWWorld::Ptr& container, bool loot)
|
2012-05-11 14:58:07 +00:00
|
|
|
{
|
2014-01-07 02:01:33 +00:00
|
|
|
mPickpocketDetected = false;
|
2013-05-11 16:38:27 +00:00
|
|
|
mPtr = container;
|
2012-05-12 12:01:59 +00:00
|
|
|
|
2013-05-17 12:11:02 +00:00
|
|
|
if (mPtr.getTypeName() == typeid(ESM::NPC).name() && !loot)
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
|
|
|
// we are stealing stuff
|
2015-08-21 09:12:39 +00:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
2014-08-25 15:01:02 +00:00
|
|
|
mModel = new PickpocketItemModel(player, new InventoryItemModel(container),
|
|
|
|
!mPtr.getClass().getCreatureStats(mPtr).getKnockedDown());
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
2013-05-11 16:38:27 +00:00
|
|
|
else
|
|
|
|
mModel = new InventoryItemModel(container);
|
2013-03-17 21:28:28 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
mDisposeCorpseButton->setVisible(loot);
|
2012-05-12 12:01:59 +00:00
|
|
|
|
2013-05-11 16:38:27 +00:00
|
|
|
mSortModel = new SortFilterItemModel(mModel);
|
|
|
|
|
|
|
|
mItemView->setModel (mSortModel);
|
2015-06-04 20:09:40 +00:00
|
|
|
mItemView->resetScrollBars();
|
2013-11-16 21:29:40 +00:00
|
|
|
|
2014-01-29 16:26:18 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton);
|
2014-01-10 23:24:21 +00:00
|
|
|
|
2014-05-22 18:37:22 +00:00
|
|
|
setTitle(container.getClass().getName(container));
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 23:24:21 +00:00
|
|
|
void ContainerWindow::onKeyPressed(MyGUI::Widget *_sender, MyGUI::KeyCode _key, MyGUI::Char _char)
|
|
|
|
{
|
|
|
|
if (_key == MyGUI::KeyCode::Space)
|
|
|
|
onCloseButtonClicked(mCloseButton);
|
|
|
|
if (_key == MyGUI::KeyCode::Return || _key == MyGUI::KeyCode::NumpadEnter)
|
|
|
|
onTakeAllButtonClicked(mTakeButton);
|
|
|
|
}
|
|
|
|
|
2014-07-07 21:37:59 +00:00
|
|
|
void ContainerWindow::resetReference()
|
|
|
|
{
|
|
|
|
ReferenceInterface::resetReference();
|
|
|
|
mItemView->setModel(NULL);
|
2014-07-14 14:53:58 +00:00
|
|
|
mModel = NULL;
|
|
|
|
mSortModel = NULL;
|
2014-07-07 21:37:59 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 02:01:33 +00:00
|
|
|
void ContainerWindow::close()
|
|
|
|
{
|
|
|
|
WindowBase::close();
|
|
|
|
|
2014-01-07 17:11:19 +00:00
|
|
|
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
|
2014-01-07 02:01:33 +00:00
|
|
|
)
|
|
|
|
{
|
2015-08-21 09:12:39 +00:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
2014-01-07 18:49:16 +00:00
|
|
|
MWMechanics::Pickpocket pickpocket(player, mPtr);
|
2014-01-07 02:01:33 +00:00
|
|
|
if (pickpocket.finish())
|
|
|
|
{
|
2014-12-19 20:45:26 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->commitCrime(
|
|
|
|
player, mPtr, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
|
2014-01-07 02:01:33 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
|
|
|
|
mPickpocketDetected = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 03:13:37 +00:00
|
|
|
void ContainerWindow::exit()
|
2013-04-17 22:56:48 +00:00
|
|
|
{
|
|
|
|
if(mDragAndDrop == NULL || !mDragAndDrop->mIsOnDragAndDrop)
|
2012-05-12 12:01:59 +00:00
|
|
|
{
|
2013-04-17 22:56:48 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Container);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 03:13:37 +00:00
|
|
|
void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
{
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender)
|
|
|
|
{
|
|
|
|
if(mDragAndDrop == NULL || !mDragAndDrop->mIsOnDragAndDrop)
|
|
|
|
{
|
|
|
|
// transfer everything into the player's inventory
|
2013-05-11 16:38:27 +00:00
|
|
|
ItemModel* playerModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getModel();
|
2013-05-19 16:40:37 +00:00
|
|
|
mModel->update();
|
2013-05-11 16:38:27 +00:00
|
|
|
for (size_t i=0; i<mModel->getItemCount(); ++i)
|
2012-05-16 12:30:02 +00:00
|
|
|
{
|
2013-04-17 22:56:48 +00:00
|
|
|
if (i==0)
|
|
|
|
{
|
|
|
|
// play the sound of the first object
|
2013-05-11 16:38:27 +00:00
|
|
|
MWWorld::Ptr item = mModel->getItem(i).mBase;
|
2014-05-22 18:37:22 +00:00
|
|
|
std::string sound = item.getClass().getUpSoundId(item);
|
2013-04-17 22:56:48 +00:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
|
|
|
}
|
2012-05-12 12:01:59 +00:00
|
|
|
|
2014-01-07 02:01:33 +00:00
|
|
|
const ItemStack& item = mModel->getItem(i);
|
|
|
|
|
|
|
|
if (!onTakeItem(item, item.mCount))
|
|
|
|
break;
|
|
|
|
|
2014-04-27 03:40:07 +00:00
|
|
|
mModel->moveItem(item, item.mCount, playerModel);
|
2013-04-17 22:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Container);
|
|
|
|
}
|
2012-05-11 14:58:07 +00:00
|
|
|
}
|
2012-05-26 23:14:33 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
void ContainerWindow::onDisposeCorpseButtonClicked(MyGUI::Widget *sender)
|
2013-03-07 13:00:13 +00:00
|
|
|
{
|
2013-04-17 22:56:48 +00:00
|
|
|
if(mDragAndDrop == NULL || !mDragAndDrop->mIsOnDragAndDrop)
|
|
|
|
{
|
|
|
|
onTakeAllButtonClicked(mTakeButton);
|
2013-03-07 13:00:13 +00:00
|
|
|
|
2014-05-22 18:37:22 +00:00
|
|
|
if (mPtr.getClass().isPersistent(mPtr))
|
2013-05-16 16:50:26 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sDisposeCorpseFail}");
|
|
|
|
else
|
2013-04-17 22:56:48 +00:00
|
|
|
MWBase::Environment::get().getWorld()->deleteObject(mPtr);
|
2013-03-07 13:00:13 +00:00
|
|
|
|
2013-04-17 22:56:48 +00:00
|
|
|
mPtr = MWWorld::Ptr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainerWindow::onReferenceUnavailable()
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Container);
|
2013-03-07 13:00:13 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 02:01:33 +00:00
|
|
|
bool ContainerWindow::onTakeItem(const ItemStack &item, int count)
|
|
|
|
{
|
2015-08-21 09:12:39 +00:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
2014-08-25 15:01:02 +00:00
|
|
|
// TODO: move to ItemModels
|
|
|
|
if (dynamic_cast<PickpocketItemModel*>(mModel)
|
|
|
|
&& !mPtr.getClass().getCreatureStats(mPtr).getKnockedDown())
|
2014-01-07 02:01:33 +00:00
|
|
|
{
|
2014-01-07 18:49:16 +00:00
|
|
|
MWMechanics::Pickpocket pickpocket(player, mPtr);
|
2014-01-07 02:01:33 +00:00
|
|
|
if (pickpocket.pick(item.mBase, count))
|
|
|
|
{
|
2014-01-07 18:49:16 +00:00
|
|
|
int value = item.mBase.getClass().getValue(item.mBase) * count;
|
2014-12-19 20:45:26 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->commitCrime(
|
|
|
|
player, MWWorld::Ptr(), MWBase::MechanicsManager::OT_Theft, value, true);
|
2014-01-07 02:01:33 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
|
|
|
|
mPickpocketDetected = true;
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-13 06:27:08 +00:00
|
|
|
else
|
|
|
|
player.getClass().skillUsageSucceeded(player, ESM::Skill::Sneak, 1);
|
2014-01-07 02:01:33 +00:00
|
|
|
}
|
2014-01-07 18:49:16 +00:00
|
|
|
else
|
|
|
|
{
|
2014-04-27 03:40:07 +00:00
|
|
|
// Looting a dead corpse is considered OK
|
|
|
|
if (mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead())
|
|
|
|
return true;
|
|
|
|
else
|
2015-02-03 22:43:56 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item.mBase, mPtr, count);
|
2014-01-07 18:49:16 +00:00
|
|
|
}
|
2014-01-07 02:01:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-26 23:14:33 +00:00
|
|
|
}
|