forked from teamnwah/openmw-tes3coop
change the drag&drop to not use a seperate containerstore
This commit is contained in:
parent
ca4fa21d64
commit
175623bf22
4 changed files with 45 additions and 42 deletions
|
@ -83,10 +83,9 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count)
|
||||||
MWWorld::Ptr object = *mSelectedItem->getUserData<MWWorld::Ptr>();
|
MWWorld::Ptr object = *mSelectedItem->getUserData<MWWorld::Ptr>();
|
||||||
_unequipItem(object);
|
_unequipItem(object);
|
||||||
|
|
||||||
int originalCount = object.getRefData().getCount();
|
mDragAndDrop->mDraggedCount = count;
|
||||||
object.getRefData().setCount(count);
|
|
||||||
mDragAndDrop->mStore.add(object);
|
mDragAndDrop->mDraggedFrom = this;
|
||||||
object.getRefData().setCount(originalCount - count);
|
|
||||||
|
|
||||||
std::string sound = MWWorld::Class::get(object).getUpSoundId(object);
|
std::string sound = MWWorld::Class::get(object).getUpSoundId(object);
|
||||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||||
|
@ -94,7 +93,7 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count)
|
||||||
mDragAndDrop->mDraggedWidget = mSelectedItem;
|
mDragAndDrop->mDraggedWidget = mSelectedItem;
|
||||||
static_cast<MyGUI::ImageBox*>(mSelectedItem)->setImageTexture(""); // remove the background texture (not visible during drag)
|
static_cast<MyGUI::ImageBox*>(mSelectedItem)->setImageTexture(""); // remove the background texture (not visible during drag)
|
||||||
static_cast<MyGUI::TextBox*>(mSelectedItem->getChildAt(0)->getChildAt(0))->setCaption(
|
static_cast<MyGUI::TextBox*>(mSelectedItem->getChildAt(0)->getChildAt(0))->setCaption(
|
||||||
getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount()));
|
getCountString(mDragAndDrop->mDraggedCount));
|
||||||
|
|
||||||
mDragAndDrop->mWasInInventory = isInventory();
|
mDragAndDrop->mWasInInventory = isInventory();
|
||||||
|
|
||||||
|
@ -108,19 +107,27 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender)
|
||||||
if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here
|
if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here
|
||||||
{
|
{
|
||||||
MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData<MWWorld::Ptr>();
|
MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData<MWWorld::Ptr>();
|
||||||
|
|
||||||
|
if (mDragAndDrop->mDraggedFrom != this)
|
||||||
|
{
|
||||||
assert(object.getContainerStore() && "Item is not in a container!");
|
assert(object.getContainerStore() && "Item is not in a container!");
|
||||||
|
|
||||||
std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
|
|
||||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
|
||||||
|
|
||||||
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
|
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
|
||||||
containerStore.add(*mDragAndDrop->mStore.begin());
|
int origCount = object.getRefData().getCount();
|
||||||
mDragAndDrop->mStore.clear();
|
object.getRefData().setCount (mDragAndDrop->mDraggedCount);
|
||||||
|
containerStore.add(object);
|
||||||
|
object.getRefData().setCount (origCount - mDragAndDrop->mDraggedCount);
|
||||||
|
}
|
||||||
|
|
||||||
mDragAndDrop->mIsOnDragAndDrop = false;
|
mDragAndDrop->mIsOnDragAndDrop = false;
|
||||||
MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget);
|
MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget);
|
||||||
drawItems();
|
drawItems();
|
||||||
|
mDragAndDrop->mDraggedFrom->drawItems();
|
||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->setDragDrop(false);
|
MWBase::Environment::get().getWindowManager()->setDragDrop(false);
|
||||||
|
|
||||||
|
std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
|
||||||
|
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +231,14 @@ void ContainerBase::drawItems()
|
||||||
{
|
{
|
||||||
index++;
|
index++;
|
||||||
const MWWorld::Ptr* iter = &((*it).first);
|
const MWWorld::Ptr* iter = &((*it).first);
|
||||||
if(iter->getRefData().getCount() > 0 && !(onlyMagic && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name()))
|
|
||||||
|
int displayCount = iter->getRefData().getCount();
|
||||||
|
if (mDragAndDrop->mIsOnDragAndDrop && *iter == *mDragAndDrop->mDraggedWidget->getUserData<MWWorld::Ptr>())
|
||||||
|
{
|
||||||
|
std::cout << "beep" << std::endl;
|
||||||
|
displayCount -= mDragAndDrop->mDraggedCount;
|
||||||
|
}
|
||||||
|
if(displayCount > 0 && !(onlyMagic && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name()))
|
||||||
{
|
{
|
||||||
std::string path = std::string("icons\\");
|
std::string path = std::string("icons\\");
|
||||||
path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter);
|
path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter);
|
||||||
|
@ -276,7 +290,7 @@ void ContainerBase::drawItems()
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
text->setCaption(getCountString(iter->getRefData().getCount()));
|
text->setCaption(getCountString(displayCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@ namespace MWGui
|
||||||
bool mIsOnDragAndDrop;
|
bool mIsOnDragAndDrop;
|
||||||
MyGUI::Widget* mDraggedWidget;
|
MyGUI::Widget* mDraggedWidget;
|
||||||
MyGUI::Widget* mDragAndDropWidget;
|
MyGUI::Widget* mDragAndDropWidget;
|
||||||
MWWorld::ContainerStore mStore;
|
ContainerBase* mDraggedFrom;
|
||||||
|
int mDraggedCount;
|
||||||
bool mWasInInventory; // was the item in inventory before it was dragged
|
bool mWasInInventory; // was the item in inventory before it was dragged
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,6 +78,8 @@ namespace MWGui
|
||||||
void openContainer(MWWorld::Ptr container);
|
void openContainer(MWWorld::Ptr container);
|
||||||
void setFilter(Filter filter); ///< set category filter
|
void setFilter(Filter filter); ///< set category filter
|
||||||
void Update();
|
void Update();
|
||||||
|
void drawItems();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MyGUI::ScrollView* mItemView;
|
MyGUI::ScrollView* mItemView;
|
||||||
|
@ -100,8 +103,6 @@ namespace MWGui
|
||||||
virtual bool isInventory() { return false; }
|
virtual bool isInventory() { return false; }
|
||||||
virtual std::vector<MWWorld::Ptr> getEquippedItems() { return std::vector<MWWorld::Ptr>(); }
|
virtual std::vector<MWWorld::Ptr> getEquippedItems() { return std::vector<MWWorld::Ptr>(); }
|
||||||
virtual void _unequipItem(MWWorld::Ptr item) { ; }
|
virtual void _unequipItem(MWWorld::Ptr item) { ; }
|
||||||
|
|
||||||
void drawItems();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ContainerWindow : public ContainerBase, public WindowBase
|
class ContainerWindow : public ContainerBase, public WindowBase
|
||||||
|
|
|
@ -260,7 +260,7 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender)
|
||||||
if (mDragAndDrop->mIsOnDragAndDrop)
|
if (mDragAndDrop->mIsOnDragAndDrop)
|
||||||
{
|
{
|
||||||
// drop item into the gameworld
|
// drop item into the gameworld
|
||||||
MWWorld::Ptr object = *mDragAndDrop->mStore.begin();
|
MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData<MWWorld::Ptr>();
|
||||||
|
|
||||||
MWWorld::World* world = MWBase::Environment::get().getWorld();
|
MWWorld::World* world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
|
@ -279,7 +279,9 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender)
|
||||||
std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
|
std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
|
||||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||||
|
|
||||||
mDragAndDrop->mStore.clear();
|
// remove object from the container it was coming from
|
||||||
|
object.getRefData().setCount(0);
|
||||||
|
|
||||||
mDragAndDrop->mIsOnDragAndDrop = false;
|
mDragAndDrop->mIsOnDragAndDrop = false;
|
||||||
MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget);
|
MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget);
|
||||||
mDragAndDrop->mDraggedWidget = 0;
|
mDragAndDrop->mDraggedWidget = 0;
|
||||||
|
|
|
@ -142,7 +142,7 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
if (mDragAndDrop->mIsOnDragAndDrop)
|
if (mDragAndDrop->mIsOnDragAndDrop)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ptr = *mDragAndDrop->mStore.begin();
|
MWWorld::Ptr ptr = *mDragAndDrop->mDraggedWidget->getUserData<MWWorld::Ptr>();
|
||||||
|
|
||||||
// can the object be equipped?
|
// can the object be equipped?
|
||||||
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(ptr).getEquipmentSlots(ptr);
|
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(ptr).getEquipmentSlots(ptr);
|
||||||
|
@ -166,35 +166,22 @@ namespace MWGui
|
||||||
mWindowManager.getBookWindow()->setTakeButtonShow(false);
|
mWindowManager.getBookWindow()->setTakeButtonShow(false);
|
||||||
mWindowManager.getScrollWindow()->setTakeButtonShow(false);
|
mWindowManager.getScrollWindow()->setTakeButtonShow(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// put back in inventory
|
|
||||||
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
|
|
||||||
containerStore.add(ptr);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// put back in inventory
|
|
||||||
MWWorld::InventoryStore& invStore = static_cast<MWWorld::InventoryStore&>(MWWorld::Class::get(mContainer).getContainerStore(mContainer));
|
MWWorld::InventoryStore& invStore = static_cast<MWWorld::InventoryStore&>(MWWorld::Class::get(mContainer).getContainerStore(mContainer));
|
||||||
|
|
||||||
MWWorld::ContainerStoreIterator it = invStore.add(ptr);
|
// retrieve iterator to the item
|
||||||
|
MWWorld::ContainerStoreIterator it = invStore.begin();
|
||||||
|
for (; it != invStore.end(); ++it)
|
||||||
|
{
|
||||||
|
if (*it == ptr)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// retrieve iterator to the item we just re-added (if stacking didn't happen).
|
assert(it != invStore.end());
|
||||||
// if stacking happened, the iterator was already returned by the add() call
|
|
||||||
/// \todo this does not work!
|
|
||||||
if (it == invStore.end())
|
|
||||||
{
|
|
||||||
std::cout << "stacking didn't happen" << std::endl;
|
|
||||||
for (MWWorld::ContainerStoreIterator it2 = invStore.begin();
|
|
||||||
it2 != invStore.end(); ++it2)
|
|
||||||
{
|
|
||||||
if (*it2 == ptr)
|
|
||||||
{
|
|
||||||
std::cout << "found iterator" << std::endl;
|
|
||||||
it = it2;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// equip the item in the first available slot
|
// equip the item in the first available slot
|
||||||
invStore.equip(slots.first.front(), it);
|
invStore.equip(slots.first.front(), it);
|
||||||
|
@ -202,13 +189,12 @@ namespace MWGui
|
||||||
std::cout << "Equipped item in slot " << slots.first.front() << std::endl;
|
std::cout << "Equipped item in slot " << slots.first.front() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawItems();
|
|
||||||
|
|
||||||
mDragAndDrop->mStore.clear();
|
|
||||||
mDragAndDrop->mIsOnDragAndDrop = false;
|
mDragAndDrop->mIsOnDragAndDrop = false;
|
||||||
MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget);
|
MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget);
|
||||||
|
|
||||||
mWindowManager.setDragDrop(false);
|
mWindowManager.setDragDrop(false);
|
||||||
|
|
||||||
|
drawItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue