forked from teamnwah/openmw-tes3coop
Merge remote-tracking branch 'scrawl/master'
commit
595c08817f
@ -0,0 +1,134 @@
|
|||||||
|
#include "draganddrop.hpp"
|
||||||
|
|
||||||
|
#include <MyGUI_Gui.h>
|
||||||
|
#include <MyGUI_ControllerManager.h>
|
||||||
|
|
||||||
|
#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"
|
||||||
|
#include "controllers.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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
|
@ -0,0 +1,103 @@
|
|||||||
|
#include "layout.hpp"
|
||||||
|
|
||||||
|
#include <MyGUI_LayoutManager.h>
|
||||||
|
#include <MyGUI_Widget.h>
|
||||||
|
#include <MyGUI_Gui.h>
|
||||||
|
#include <MyGUI_TextBox.h>
|
||||||
|
#include <MyGUI_Window.h>
|
||||||
|
|
||||||
|
namespace OEngine
|
||||||
|
{
|
||||||
|
namespace GUI
|
||||||
|
{
|
||||||
|
void Layout::initialise(const std::string& _layout, MyGUI::Widget* _parent)
|
||||||
|
{
|
||||||
|
const std::string MAIN_WINDOW = "_Main";
|
||||||
|
mLayoutName = _layout;
|
||||||
|
|
||||||
|
if (mLayoutName.empty())
|
||||||
|
mMainWidget = _parent;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mPrefix = MyGUI::utility::toString(this, "_");
|
||||||
|
mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix, _parent);
|
||||||
|
|
||||||
|
const std::string main_name = mPrefix + MAIN_WINDOW;
|
||||||
|
for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin(); iter!=mListWindowRoot.end(); ++iter)
|
||||||
|
{
|
||||||
|
if ((*iter)->getName() == main_name)
|
||||||
|
{
|
||||||
|
mMainWidget = (*iter);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MYGUI_ASSERT(mMainWidget, "root widget name '" << MAIN_WINDOW << "' in layout '" << mLayoutName << "' not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layout::shutdown()
|
||||||
|
{
|
||||||
|
MyGUI::Gui::getInstance().destroyWidget(mMainWidget);
|
||||||
|
mListWindowRoot.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layout::setCoord(int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
mMainWidget->setCoord(x,y,w,h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layout::adjustWindowCaption()
|
||||||
|
{
|
||||||
|
MyGUI::TextBox* box = mMainWidget->castType<MyGUI::Window>(mMainWidget)->getCaptionWidget();
|
||||||
|
box->setSize(box->getTextSize().width + 24, box->getSize().height);
|
||||||
|
|
||||||
|
// in order to trigger alignment updates, we need to update the parent
|
||||||
|
// mygui doesn't provide a proper way of doing this, so we are just changing size
|
||||||
|
box->getParent()->setCoord(MyGUI::IntCoord(
|
||||||
|
box->getParent()->getCoord().left,
|
||||||
|
box->getParent()->getCoord().top,
|
||||||
|
box->getParent()->getCoord().width,
|
||||||
|
box->getParent()->getCoord().height+1
|
||||||
|
));
|
||||||
|
box->getParent()->setCoord(MyGUI::IntCoord(
|
||||||
|
box->getParent()->getCoord().left,
|
||||||
|
box->getParent()->getCoord().top,
|
||||||
|
box->getParent()->getCoord().width,
|
||||||
|
box->getParent()->getCoord().height-1
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layout::setVisible(bool b)
|
||||||
|
{
|
||||||
|
mMainWidget->setVisible(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layout::setText(const std::string &name, const std::string &caption)
|
||||||
|
{
|
||||||
|
MyGUI::Widget* pt;
|
||||||
|
getWidget(pt, name);
|
||||||
|
static_cast<MyGUI::TextBox*>(pt)->setCaption(caption);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layout::setTitle(const std::string& title)
|
||||||
|
{
|
||||||
|
static_cast<MyGUI::Window*>(mMainWidget)->setCaptionWithReplacing(title);
|
||||||
|
adjustWindowCaption();
|
||||||
|
}
|
||||||
|
|
||||||
|
MyGUI::Widget* Layout::getWidget(const std::string &_name)
|
||||||
|
{
|
||||||
|
for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin();
|
||||||
|
iter!=mListWindowRoot.end(); ++iter)
|
||||||
|
{
|
||||||
|
MyGUI::Widget* find = (*iter)->findWidget(mPrefix + _name);
|
||||||
|
if (nullptr != find)
|
||||||
|
{
|
||||||
|
return find;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MYGUI_EXCEPT("widget name '" << _name << "' in layout '" << mLayoutName << "' not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue