mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 01:45:33 +00:00
Reduce includes, move DragAndDrop to separate file
This commit is contained in:
parent
eb99ed697b
commit
4b704f665f
13 changed files with 187 additions and 140 deletions
|
@ -41,6 +41,7 @@ add_openmw_dir (mwgui
|
|||
itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview
|
||||
tradeitemmodel companionitemmodel pickpocketitemmodel controllers savegamedialog
|
||||
recharge mode videowidget backgroundimage itemwidget screenfader debugwindow spellmodel spellview
|
||||
draganddrop
|
||||
)
|
||||
|
||||
add_openmw_dir (mwdialogue
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "itemview.hpp"
|
||||
#include "sortfilteritemmodel.hpp"
|
||||
#include "companionitemmodel.hpp"
|
||||
#include "container.hpp"
|
||||
#include "draganddrop.hpp"
|
||||
#include "countdialog.hpp"
|
||||
|
||||
namespace MWGui
|
||||
|
|
|
@ -24,123 +24,11 @@
|
|||
#include "inventoryitemmodel.hpp"
|
||||
#include "sortfilteritemmodel.hpp"
|
||||
#include "pickpocketitemmodel.hpp"
|
||||
#include "draganddrop.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
DragAndDrop::DragAndDrop()
|
||||
: mDraggedWidget(NULL)
|
||||
, mDraggedCount(0)
|
||||
, mSourceModel(NULL)
|
||||
, mSourceView(NULL)
|
||||
, mSourceSortModel(NULL)
|
||||
, mIsOnDragAndDrop(false)
|
||||
{
|
||||
}
|
||||
|
||||
void DragAndDrop::startDrag (int index, SortFilterItemModel* sortModel, ItemModel* sourceModel, ItemView* sourceView, int count)
|
||||
{
|
||||
mItem = sourceModel->getItem(index);
|
||||
mDraggedCount = count;
|
||||
mSourceModel = sourceModel;
|
||||
mSourceView = sourceView;
|
||||
mSourceSortModel = sortModel;
|
||||
mIsOnDragAndDrop = true;
|
||||
|
||||
// If picking up an item that isn't from the player's inventory, the item gets added to player inventory backend
|
||||
// immediately, even though it's still floating beneath the mouse cursor. A bit counterintuitive,
|
||||
// but this is how it works in vanilla, and not doing so would break quests (BM_beasts for instance).
|
||||
ItemModel* playerModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getModel();
|
||||
if (mSourceModel != playerModel)
|
||||
{
|
||||
MWWorld::Ptr item = mSourceModel->moveItem(mItem, mDraggedCount, playerModel);
|
||||
|
||||
playerModel->update();
|
||||
|
||||
ItemModel::ModelIndex newIndex = -1;
|
||||
for (unsigned int i=0; i<playerModel->getItemCount(); ++i)
|
||||
{
|
||||
if (playerModel->getItem(i).mBase == item)
|
||||
{
|
||||
newIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mItem = playerModel->getItem(newIndex);
|
||||
mSourceModel = playerModel;
|
||||
|
||||
SortFilterItemModel* playerFilterModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getSortFilterModel();
|
||||
mSourceSortModel = playerFilterModel;
|
||||
}
|
||||
|
||||
std::string sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase);
|
||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||
|
||||
if (mSourceSortModel)
|
||||
{
|
||||
mSourceSortModel->clearDragItems();
|
||||
mSourceSortModel->addDragItem(mItem.mBase, count);
|
||||
}
|
||||
|
||||
ItemWidget* baseWidget = MyGUI::Gui::getInstance().createWidget<ItemWidget>("MW_ItemIcon", 0, 0, 42, 42, MyGUI::Align::Default, "DragAndDrop");
|
||||
|
||||
Controllers::ControllerFollowMouse* controller =
|
||||
MyGUI::ControllerManager::getInstance().createItem(Controllers::ControllerFollowMouse::getClassTypeName())
|
||||
->castType<Controllers::ControllerFollowMouse>();
|
||||
MyGUI::ControllerManager::getInstance().addItem(baseWidget, controller);
|
||||
|
||||
mDraggedWidget = baseWidget;
|
||||
baseWidget->setItem(mItem.mBase);
|
||||
baseWidget->setNeedMouseFocus(false);
|
||||
baseWidget->setCount(count);
|
||||
|
||||
sourceView->update();
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->setDragDrop(true);
|
||||
}
|
||||
|
||||
void DragAndDrop::drop(ItemModel *targetModel, ItemView *targetView)
|
||||
{
|
||||
std::string sound = mItem.mBase.getClass().getDownSoundId(mItem.mBase);
|
||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||
|
||||
// We can't drop a conjured item to the ground; the target container should always be the source container
|
||||
if (mItem.mFlags & ItemStack::Flag_Bound && targetModel != mSourceModel)
|
||||
{
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sBarterDialog12}");
|
||||
return;
|
||||
}
|
||||
|
||||
// If item is dropped where it was taken from, we don't need to do anything -
|
||||
// otherwise, do the transfer
|
||||
if (targetModel != mSourceModel)
|
||||
{
|
||||
mSourceModel->moveItem(mItem, mDraggedCount, targetModel);
|
||||
}
|
||||
|
||||
mSourceModel->update();
|
||||
|
||||
finish();
|
||||
if (targetView)
|
||||
targetView->update();
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->updateItemView();
|
||||
|
||||
// We need to update the view since an other item could be auto-equipped.
|
||||
mSourceView->update();
|
||||
}
|
||||
|
||||
void DragAndDrop::finish()
|
||||
{
|
||||
mIsOnDragAndDrop = false;
|
||||
mSourceSortModel->clearDragItems();
|
||||
|
||||
MyGUI::Gui::getInstance().destroyWidget(mDraggedWidget);
|
||||
mDraggedWidget = 0;
|
||||
MWBase::Environment::get().getWindowManager()->setDragDrop(false);
|
||||
}
|
||||
|
||||
|
||||
ContainerWindow::ContainerWindow(DragAndDrop* dragAndDrop)
|
||||
: WindowBase("openmw_container_window.layout")
|
||||
, mDragAndDrop(dragAndDrop)
|
||||
|
|
|
@ -28,25 +28,6 @@ namespace MWGui
|
|||
|
||||
namespace MWGui
|
||||
{
|
||||
class DragAndDrop
|
||||
{
|
||||
public:
|
||||
bool mIsOnDragAndDrop;
|
||||
MyGUI::Widget* mDraggedWidget;
|
||||
ItemModel* mSourceModel;
|
||||
ItemView* mSourceView;
|
||||
SortFilterItemModel* mSourceSortModel;
|
||||
ItemStack mItem;
|
||||
int mDraggedCount;
|
||||
|
||||
DragAndDrop();
|
||||
|
||||
void startDrag (int index, SortFilterItemModel* sortModel, ItemModel* sourceModel, ItemView* sourceView, int count);
|
||||
void drop (ItemModel* targetModel, ItemView* targetView);
|
||||
|
||||
void finish();
|
||||
};
|
||||
|
||||
class ContainerWindow : public WindowBase, public ReferenceInterface
|
||||
{
|
||||
public:
|
||||
|
|
130
apps/openmw/mwgui/draganddrop.cpp
Normal file
130
apps/openmw/mwgui/draganddrop.cpp
Normal file
|
@ -0,0 +1,130 @@
|
|||
#include "draganddrop.hpp"
|
||||
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include "sortfilteritemmodel.hpp"
|
||||
#include "inventorywindow.hpp"
|
||||
#include "itemwidget.hpp"
|
||||
#include "itemview.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
|
||||
DragAndDrop::DragAndDrop()
|
||||
: mDraggedWidget(NULL)
|
||||
, mDraggedCount(0)
|
||||
, mSourceModel(NULL)
|
||||
, mSourceView(NULL)
|
||||
, mSourceSortModel(NULL)
|
||||
, mIsOnDragAndDrop(false)
|
||||
{
|
||||
}
|
||||
|
||||
void DragAndDrop::startDrag (int index, SortFilterItemModel* sortModel, ItemModel* sourceModel, ItemView* sourceView, int count)
|
||||
{
|
||||
mItem = sourceModel->getItem(index);
|
||||
mDraggedCount = count;
|
||||
mSourceModel = sourceModel;
|
||||
mSourceView = sourceView;
|
||||
mSourceSortModel = sortModel;
|
||||
mIsOnDragAndDrop = true;
|
||||
|
||||
// If picking up an item that isn't from the player's inventory, the item gets added to player inventory backend
|
||||
// immediately, even though it's still floating beneath the mouse cursor. A bit counterintuitive,
|
||||
// but this is how it works in vanilla, and not doing so would break quests (BM_beasts for instance).
|
||||
ItemModel* playerModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getModel();
|
||||
if (mSourceModel != playerModel)
|
||||
{
|
||||
MWWorld::Ptr item = mSourceModel->moveItem(mItem, mDraggedCount, playerModel);
|
||||
|
||||
playerModel->update();
|
||||
|
||||
ItemModel::ModelIndex newIndex = -1;
|
||||
for (unsigned int i=0; i<playerModel->getItemCount(); ++i)
|
||||
{
|
||||
if (playerModel->getItem(i).mBase == item)
|
||||
{
|
||||
newIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mItem = playerModel->getItem(newIndex);
|
||||
mSourceModel = playerModel;
|
||||
|
||||
SortFilterItemModel* playerFilterModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getSortFilterModel();
|
||||
mSourceSortModel = playerFilterModel;
|
||||
}
|
||||
|
||||
std::string sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase);
|
||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||
|
||||
if (mSourceSortModel)
|
||||
{
|
||||
mSourceSortModel->clearDragItems();
|
||||
mSourceSortModel->addDragItem(mItem.mBase, count);
|
||||
}
|
||||
|
||||
ItemWidget* baseWidget = MyGUI::Gui::getInstance().createWidget<ItemWidget>("MW_ItemIcon", 0, 0, 42, 42, MyGUI::Align::Default, "DragAndDrop");
|
||||
|
||||
Controllers::ControllerFollowMouse* controller =
|
||||
MyGUI::ControllerManager::getInstance().createItem(Controllers::ControllerFollowMouse::getClassTypeName())
|
||||
->castType<Controllers::ControllerFollowMouse>();
|
||||
MyGUI::ControllerManager::getInstance().addItem(baseWidget, controller);
|
||||
|
||||
mDraggedWidget = baseWidget;
|
||||
baseWidget->setItem(mItem.mBase);
|
||||
baseWidget->setNeedMouseFocus(false);
|
||||
baseWidget->setCount(count);
|
||||
|
||||
sourceView->update();
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->setDragDrop(true);
|
||||
}
|
||||
|
||||
void DragAndDrop::drop(ItemModel *targetModel, ItemView *targetView)
|
||||
{
|
||||
std::string sound = mItem.mBase.getClass().getDownSoundId(mItem.mBase);
|
||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||
|
||||
// We can't drop a conjured item to the ground; the target container should always be the source container
|
||||
if (mItem.mFlags & ItemStack::Flag_Bound && targetModel != mSourceModel)
|
||||
{
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sBarterDialog12}");
|
||||
return;
|
||||
}
|
||||
|
||||
// If item is dropped where it was taken from, we don't need to do anything -
|
||||
// otherwise, do the transfer
|
||||
if (targetModel != mSourceModel)
|
||||
{
|
||||
mSourceModel->moveItem(mItem, mDraggedCount, targetModel);
|
||||
}
|
||||
|
||||
mSourceModel->update();
|
||||
|
||||
finish();
|
||||
if (targetView)
|
||||
targetView->update();
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->updateItemView();
|
||||
|
||||
// We need to update the view since an other item could be auto-equipped.
|
||||
mSourceView->update();
|
||||
}
|
||||
|
||||
void DragAndDrop::finish()
|
||||
{
|
||||
mIsOnDragAndDrop = false;
|
||||
mSourceSortModel->clearDragItems();
|
||||
|
||||
MyGUI::Gui::getInstance().destroyWidget(mDraggedWidget);
|
||||
mDraggedWidget = 0;
|
||||
MWBase::Environment::get().getWindowManager()->setDragDrop(false);
|
||||
}
|
||||
|
||||
}
|
38
apps/openmw/mwgui/draganddrop.hpp
Normal file
38
apps/openmw/mwgui/draganddrop.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef OPENMW_MWGUI_DRAGANDDROP_H
|
||||
#define OPENMW_MWGUI_DRAGANDDROP_H
|
||||
|
||||
#include "itemmodel.hpp"
|
||||
|
||||
namespace MyGUI
|
||||
{
|
||||
class Widget;
|
||||
}
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
class ItemView;
|
||||
class SortFilterItemModel;
|
||||
|
||||
class DragAndDrop
|
||||
{
|
||||
public:
|
||||
bool mIsOnDragAndDrop;
|
||||
MyGUI::Widget* mDraggedWidget;
|
||||
ItemModel* mSourceModel;
|
||||
ItemView* mSourceView;
|
||||
SortFilterItemModel* mSourceSortModel;
|
||||
ItemStack mItem;
|
||||
int mDraggedCount;
|
||||
|
||||
DragAndDrop();
|
||||
|
||||
void startDrag (int index, SortFilterItemModel* sortModel, ItemModel* sourceModel, ItemView* sourceView, int count);
|
||||
void drop (ItemModel* targetModel, ItemView* targetView);
|
||||
|
||||
void finish();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -15,7 +15,6 @@
|
|||
#include "../mwworld/esmstore.hpp"
|
||||
|
||||
#include "itemselection.hpp"
|
||||
#include "container.hpp"
|
||||
#include "itemwidget.hpp"
|
||||
|
||||
#include "sortfilteritemmodel.hpp"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "console.hpp"
|
||||
#include "spellicons.hpp"
|
||||
#include "itemmodel.hpp"
|
||||
#include "container.hpp"
|
||||
#include "draganddrop.hpp"
|
||||
|
||||
#include "itemmodel.hpp"
|
||||
#include "itemwidget.hpp"
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "tradeitemmodel.hpp"
|
||||
#include "countdialog.hpp"
|
||||
#include "tradewindow.hpp"
|
||||
#include "container.hpp"
|
||||
#include "draganddrop.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
#ifndef OPENMW_GAME_MWGUI_ITEMSELECTION_H
|
||||
#define OPENMW_GAME_MWGUI_ITEMSELECTION_H
|
||||
|
||||
#include "container.hpp"
|
||||
#include <MyGUI_Delegate.h>
|
||||
|
||||
#include "windowbase.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Ptr;
|
||||
}
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef MWGUI_TRADEWINDOW_H
|
||||
#define MWGUI_TRADEWINDOW_H
|
||||
|
||||
#include "container.hpp"
|
||||
#include "referenceinterface.hpp"
|
||||
#include "windowbase.hpp"
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "windowbase.hpp"
|
||||
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "container.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwgui/windowmanagerimp.hpp"
|
||||
|
||||
#include "draganddrop.hpp"
|
||||
|
||||
using namespace MWGui;
|
||||
|
||||
|
|
|
@ -74,6 +74,8 @@
|
|||
#include "screenfader.hpp"
|
||||
#include "debugwindow.hpp"
|
||||
#include "spellview.hpp"
|
||||
#include "draganddrop.hpp"
|
||||
#include "container.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue