From 43f94a889016a508273bcc43a8c71ef210f8a2b5 Mon Sep 17 00:00:00 2001 From: lukago Date: Thu, 19 Oct 2017 16:50:04 +0200 Subject: [PATCH 1/3] simplify drag and drop on avatar for potions and ingredients --- apps/openmw/mwgui/inventorywindow.cpp | 19 +++++++++++++++---- apps/openmw/mwgui/inventorywindow.hpp | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 735bf3682..2f3099c09 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -213,11 +213,13 @@ namespace MWGui void InventoryWindow::onItemSelected (int index) { - onItemSelectedFromSourceModel (mSortModel->mapToSource(index)); + onItemSelectedFromSourceModel (mSortModel->mapToSource(index), false); } - void InventoryWindow::onItemSelectedFromSourceModel (int index) + void InventoryWindow::onItemSelectedFromSourceModel (int index, bool takeMaxItemCount) { + mLastItemIndex = index; + if (mDragAndDrop->mIsOnDragAndDrop) { mDragAndDrop->drop(mTradeModel, mItemView); @@ -230,7 +232,8 @@ namespace MWGui MWWorld::Ptr object = item.mBase; int count = item.mCount; - bool shift = MyGUI::InputManager::getInstance().isShiftPressed(); + bool shift = takeMaxItemCount ? true : MyGUI::InputManager::getInstance().isShiftPressed(); + if (MyGUI::InputManager::getInstance().isControlPressed()) count = 1; @@ -528,6 +531,8 @@ namespace MWGui if (mDragAndDrop->mIsOnDragAndDrop) { MWWorld::Ptr ptr = mDragAndDrop->mItem.mBase; + int itemType = ptr.getContainerStore()->getType(ptr); + mDragAndDrop->finish(); if (mDragAndDrop->mSourceModel != mTradeModel) @@ -536,6 +541,12 @@ namespace MWGui ptr = mDragAndDrop->mSourceModel->moveItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount, mTradeModel); } useItem(ptr); + + if ((itemType == MWWorld::ContainerStore::Type_Ingredient || itemType == MWWorld::ContainerStore::Type_Potion) && mDragAndDrop->mDraggedCount > 1) + { + onItemSelectedFromSourceModel(mLastItemIndex, true); + } + } else { @@ -550,7 +561,7 @@ namespace MWGui { if (mTradeModel->getItem(i).mBase == itemSelected) { - onItemSelectedFromSourceModel(i); + onItemSelectedFromSourceModel(i, false); return; } } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 5576b52ed..dde46558f 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -69,6 +69,7 @@ namespace MWGui DragAndDrop* mDragAndDrop; int mSelectedItem; + int mLastItemIndex; MWWorld::Ptr mPtr; @@ -103,7 +104,7 @@ namespace MWGui bool mTrading; void onItemSelected(int index); - void onItemSelectedFromSourceModel(int index); + void onItemSelectedFromSourceModel(int index, bool takeMaxCount); void onBackgroundSelected(); From a3225364ff2e689ff43c3f93b3961c91b0b505c0 Mon Sep 17 00:00:00 2001 From: lukago Date: Thu, 19 Oct 2017 17:17:14 +0200 Subject: [PATCH 2/3] refactor, use dragItem method --- apps/openmw/mwgui/inventorywindow.cpp | 22 ++++++++++------------ apps/openmw/mwgui/inventorywindow.hpp | 3 +-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 2f3099c09..d0af00e5f 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -1,7 +1,5 @@ #include "inventorywindow.hpp" -#include - #include #include #include @@ -26,7 +24,6 @@ #include "../mwworld/class.hpp" #include "../mwworld/action.hpp" #include "../mwscript/interpretercontext.hpp" -#include "../mwrender/characterpreview.hpp" #include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/creaturestats.hpp" @@ -213,13 +210,11 @@ namespace MWGui void InventoryWindow::onItemSelected (int index) { - onItemSelectedFromSourceModel (mSortModel->mapToSource(index), false); + onItemSelectedFromSourceModel (mSortModel->mapToSource(index)); } - void InventoryWindow::onItemSelectedFromSourceModel (int index, bool takeMaxItemCount) + void InventoryWindow::onItemSelectedFromSourceModel (int index) { - mLastItemIndex = index; - if (mDragAndDrop->mIsOnDragAndDrop) { mDragAndDrop->drop(mTradeModel, mItemView); @@ -230,10 +225,9 @@ namespace MWGui std::string sound = item.mBase.getClass().getDownSoundId(item.mBase); MWWorld::Ptr object = item.mBase; + bool shift = MyGUI::InputManager::getInstance().isShiftPressed(); int count = item.mCount; - bool shift = takeMaxItemCount ? true : MyGUI::InputManager::getInstance().isShiftPressed(); - if (MyGUI::InputManager::getInstance().isControlPressed()) count = 1; @@ -540,11 +534,15 @@ namespace MWGui // Move item to the player's inventory ptr = mDragAndDrop->mSourceModel->moveItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount, mTradeModel); } + useItem(ptr); - if ((itemType == MWWorld::ContainerStore::Type_Ingredient || itemType == MWWorld::ContainerStore::Type_Potion) && mDragAndDrop->mDraggedCount > 1) + // If item is ingredient or potion don't stop drag and drop to simplify action of taking more than one 1 item + if ((itemType == MWWorld::ContainerStore::Type_Ingredient + || itemType == MWWorld::ContainerStore::Type_Potion) + && mDragAndDrop->mDraggedCount > 1) { - onItemSelectedFromSourceModel(mLastItemIndex, true); + dragItem (nullptr, mDragAndDrop->mDraggedCount - 1); } } @@ -561,7 +559,7 @@ namespace MWGui { if (mTradeModel->getItem(i).mBase == itemSelected) { - onItemSelectedFromSourceModel(i, false); + onItemSelectedFromSourceModel(i); return; } } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index dde46558f..5576b52ed 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -69,7 +69,6 @@ namespace MWGui DragAndDrop* mDragAndDrop; int mSelectedItem; - int mLastItemIndex; MWWorld::Ptr mPtr; @@ -104,7 +103,7 @@ namespace MWGui bool mTrading; void onItemSelected(int index); - void onItemSelectedFromSourceModel(int index, bool takeMaxCount); + void onItemSelectedFromSourceModel(int index); void onBackgroundSelected(); From b6cb3b445cb5406b3c06d48c54fc1427d426d1bf Mon Sep 17 00:00:00 2001 From: lukago Date: Fri, 20 Oct 2017 01:10:17 +0200 Subject: [PATCH 3/3] use getIndex to handle other windows, nullsafe fixes --- apps/openmw/mwgui/inventorywindow.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index d0af00e5f..b3697008c 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -1,5 +1,7 @@ #include "inventorywindow.hpp" +#include + #include #include #include @@ -225,8 +227,8 @@ namespace MWGui std::string sound = item.mBase.getClass().getDownSoundId(item.mBase); MWWorld::Ptr object = item.mBase; - bool shift = MyGUI::InputManager::getInstance().isShiftPressed(); int count = item.mCount; + bool shift = MyGUI::InputManager::getInstance().isShiftPressed(); if (MyGUI::InputManager::getInstance().isControlPressed()) count = 1; @@ -525,7 +527,6 @@ namespace MWGui if (mDragAndDrop->mIsOnDragAndDrop) { MWWorld::Ptr ptr = mDragAndDrop->mItem.mBase; - int itemType = ptr.getContainerStore()->getType(ptr); mDragAndDrop->finish(); @@ -538,13 +539,15 @@ namespace MWGui useItem(ptr); // If item is ingredient or potion don't stop drag and drop to simplify action of taking more than one 1 item - if ((itemType == MWWorld::ContainerStore::Type_Ingredient - || itemType == MWWorld::ContainerStore::Type_Potion) + if ((ptr.getTypeName() == typeid(ESM::Potion).name() || + ptr.getTypeName() == typeid(ESM::Ingredient).name()) && mDragAndDrop->mDraggedCount > 1) { - dragItem (nullptr, mDragAndDrop->mDraggedCount - 1); + // Item can be provided from other window for example container. + // But after DragAndDrop::startDrag item automaticly always gets to player inventory. + mSelectedItem = getModel()->getIndex(mDragAndDrop->mItem); + dragItem(nullptr, mDragAndDrop->mDraggedCount - 1); } - } else {