From fb47681fbd61310037f29ca0095cda55615e451e Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 17:58:33 +0200 Subject: [PATCH] fix a bug, some cleanup --- apps/openmw/mwgui/container.cpp | 33 ++++++++++++--------------- apps/openmw/mwgui/container.hpp | 3 --- apps/openmw/mwgui/countdialog.cpp | 5 ++-- apps/openmw/mwgui/countdialog.hpp | 2 +- apps/openmw/mwgui/hud.cpp | 1 - apps/openmw/mwgui/inventorywindow.cpp | 8 +------ apps/openmw/mwgui/inventorywindow.hpp | 3 +-- apps/openmw/mwgui/tradewindow.hpp | 3 --- apps/openmw/mwgui/window_manager.cpp | 12 +++++++--- 9 files changed, 30 insertions(+), 40 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 7d9fd4363..d0fd06a70 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -109,8 +109,9 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) } else { + std::string message = MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTake")->str; CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->open(MWWorld::Class::get(object).getName(object), message, count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::startDragItem); } @@ -135,6 +136,10 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) } } + bool buying = isTradeWindow(); // buying or selling? + std::string message = buying ? MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sQuanityMenuMessage02")->str + : MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sQuanityMenuMessage01")->str; + if (std::find(mBoughtItems.begin(), mBoughtItems.end(), object) != mBoughtItems.end()) { if (MyGUI::InputManager::getInstance().isShiftPressed() || count == 1) @@ -148,7 +153,7 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) else { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->open(MWWorld::Class::get(object).getName(object), message, count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::sellAlreadyBoughtItem); } @@ -166,7 +171,7 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) else { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->open(MWWorld::Class::get(object).getName(object), message, count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::sellItem); } @@ -202,13 +207,15 @@ void ContainerBase::sellItem(MyGUI::Widget* _sender, int count) if (isInventory()) { newPtr = MWBase::Environment::get().getWindowManager()->getTradeWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); - mSoldItems.push_back(newPtr); + if (std::find(mSoldItems.begin(), mSoldItems.end(), newPtr) == mSoldItems.end()) + mSoldItems.push_back(newPtr); MWBase::Environment::get().getWindowManager()->getTradeWindow()->drawItems(); } else { newPtr = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); - mSoldItems.push_back(newPtr); + if (std::find(mSoldItems.begin(), mSoldItems.end(), newPtr) == mSoldItems.end()) + mSoldItems.push_back(newPtr); MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); } @@ -510,8 +517,6 @@ void ContainerBase::drawItems() MyGUI::IntSize size = MyGUI::IntSize(std::max(mItemView->getSize().width, x+42), mItemView->getSize().height); mItemView->setCanvasSize(size); mContainerWidget->setSize(size); - - notifyContentChanged(); } std::string ContainerBase::getCountString(const int count) @@ -524,16 +529,6 @@ std::string ContainerBase::getCountString(const int count) return boost::lexical_cast(count); } -void ContainerBase::Update() -{ - if(mDragAndDrop != NULL && mDragAndDrop->mIsOnDragAndDrop) - { - if(mDragAndDrop->mDraggedWidget) - mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); - else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug. - } -} - MWWorld::Ptr ContainerBase::readdBarteredItem(MWWorld::Ptr item, int count) { MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); @@ -558,7 +553,9 @@ MWWorld::Ptr ContainerBase::addBarteredItem(MWWorld::Ptr item, int count) MWWorld::ContainerStoreIterator it = containerStore.add(item); item.getRefData().setCount(origCount - count); - mBoughtItems.push_back(*it); + if (std::find(mBoughtItems.begin(), mBoughtItems.end(), *it) == mBoughtItems.end()) + mBoughtItems.push_back(*it); + return *it; } diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 43a04ae70..58d4548ee 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -73,11 +73,8 @@ namespace MWGui void openContainer(MWWorld::Ptr container); void setFilter(Filter filter); ///< set category filter - virtual void Update(); void drawItems(); - virtual void notifyContentChanged() { } - protected: MyGUI::ScrollView* mItemView; MyGUI::Widget* mContainerWidget; diff --git a/apps/openmw/mwgui/countdialog.cpp b/apps/openmw/mwgui/countdialog.cpp index dc7e75e0e..16e3f9aab 100644 --- a/apps/openmw/mwgui/countdialog.cpp +++ b/apps/openmw/mwgui/countdialog.cpp @@ -19,7 +19,6 @@ namespace MWGui mOkButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sOk")->str); mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); - mLabelText->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTake")->str); mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onCancelButtonClicked); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onOkButtonClicked); @@ -27,10 +26,12 @@ namespace MWGui mSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &CountDialog::onSliderMoved); } - void CountDialog::open(const std::string& item, const int maxCount) + void CountDialog::open(const std::string& item, const std::string& message, const int maxCount) { setVisible(true); + mLabelText->setCaption(message); + MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); mSlider->setScrollRange(maxCount); diff --git a/apps/openmw/mwgui/countdialog.hpp b/apps/openmw/mwgui/countdialog.hpp index b6c836c9d..aac17b846 100644 --- a/apps/openmw/mwgui/countdialog.hpp +++ b/apps/openmw/mwgui/countdialog.hpp @@ -9,7 +9,7 @@ namespace MWGui { public: CountDialog(WindowManager& parWindowManager); - void open(const std::string& item, const int maxCount); + void open(const std::string& item, const std::string& message, const int maxCount); typedef MyGUI::delegates::CMultiDelegate2 EventHandle_WidgetInt; diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 395ca79c5..34d5ece98 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -285,7 +285,6 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) // remove object from the container it was coming from object.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount); - mDragAndDrop->mDraggedFrom->notifyContentChanged(); mDragAndDrop->mIsOnDragAndDrop = false; MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index e08a2ba4f..ca629d51d 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -228,15 +228,9 @@ namespace MWGui mEncumbranceText->setCaption( boost::lexical_cast(int(encumbrance)) + "/" + boost::lexical_cast(int(capacity)) ); } - void InventoryWindow::notifyContentChanged() - { - } - - void InventoryWindow::Update() + void InventoryWindow::update() { updateEncumbranceBar(); - - ContainerBase::Update(); } int InventoryWindow::getPlayerGold() diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index e544b788a..59aaf7859 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -16,8 +16,7 @@ namespace MWGui /// start trading, disables item drag&drop void startTrade(); - virtual void Update(); - virtual void notifyContentChanged(); + void update(); int getPlayerGold(); diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 5ab2d0d79..b96abc7e2 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -27,9 +27,6 @@ namespace MWGui void startTrade(MWWorld::Ptr actor); - //virtual void Update(); - //virtual void notifyContentChanged(); - bool npcAcceptsItem(MWWorld::Ptr item); protected: diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index e12fb851e..abbdcbcc1 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -97,7 +97,7 @@ WindowManager::WindowManager( MyGUI::Widget* dragAndDropWidget = gui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget"); dragAndDropWidget->setVisible(false); - DragAndDrop* mDragAndDrop = new DragAndDrop(); + mDragAndDrop = new DragAndDrop(); mDragAndDrop->mIsOnDragAndDrop = false; mDragAndDrop->mDraggedWidget = 0; mDragAndDrop->mDragAndDropWidget = dragAndDropWidget; @@ -468,9 +468,15 @@ void WindowManager::onDialogueWindowBye() void WindowManager::onFrame (float frameDuration) { mMessageBoxManager->onFrame(frameDuration); - mInventoryWindow->Update(); - mContainerWindow->Update(); mToolTips->onFrame(frameDuration); + + if (mDragAndDrop->mIsOnDragAndDrop) + { + assert(mDragAndDrop->mDraggedWidget); + mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); + } + + mInventoryWindow->update(); } const ESMS::ESMStore& WindowManager::getStore() const