From 41efea4c1d637b61e3f6be6757d2ae5478f5fcf1 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 21:56:16 +0200 Subject: [PATCH] in the trade window, don't show items that the merchant has equipped. --- apps/openmw/mwgui/container.cpp | 9 ++-- apps/openmw/mwgui/container.hpp | 3 ++ apps/openmw/mwgui/inventorywindow.cpp | 19 ++++++-- apps/openmw/mwgui/inventorywindow.hpp | 2 + apps/openmw/mwgui/tradewindow.cpp | 52 +++++++++++++++++++--- apps/openmw/mwgui/tradewindow.hpp | 8 ++++ apps/openmw/mwgui/window_manager.cpp | 2 +- files/mygui/openmw_trade_window_layout.xml | 4 +- 8 files changed, 85 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 078a5e370..6f8ca4730 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -300,10 +300,13 @@ void ContainerBase::drawItems() equippedItems.erase(found); } // and add the items that are left (= have the correct category) - for (std::vector::const_iterator it=equippedItems.begin(); - it != equippedItems.end(); ++it) + if (!ignoreEquippedItems()) { - items.push_back( std::make_pair(*it, ItemState_Equipped) ); + for (std::vector::const_iterator it=equippedItems.begin(); + it != equippedItems.end(); ++it) + { + items.push_back( std::make_pair(*it, ItemState_Equipped) ); + } } // now add the regular items diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index fe4ffc285..956382f23 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -98,6 +98,9 @@ namespace MWGui virtual bool isInventory() { return false; } virtual std::vector getEquippedItems() { return std::vector(); } virtual void _unequipItem(MWWorld::Ptr item) { ; } + + // to be reimplemented by TradeWindow + virtual bool ignoreEquippedItems() { return false; } }; class ContainerWindow : public ContainerBase, public WindowBase diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 92c0553f6..ebba395ff 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -84,13 +84,13 @@ namespace MWGui mFilterAll->setStateSelected(true); setCoord(0, 342, 600, 258); - } - void InventoryWindow::openInventory() - { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); openContainer(player); + } + void InventoryWindow::openInventory() + { onWindowResize(static_cast(mMainWidget)); updateEncumbranceBar(); @@ -232,4 +232,17 @@ namespace MWGui ContainerBase::Update(); } + + int InventoryWindow::getPlayerGold() + { + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + + for (MWWorld::ContainerStoreIterator it = invStore.begin(); + it != invStore.end(); ++it) + { + if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + return it->getRefData().getCount(); + } + return 0; + } } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 07aeeeafd..e53402bbd 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -16,6 +16,8 @@ namespace MWGui virtual void Update(); virtual void notifyContentChanged(); + int getPlayerGold(); + protected: MyGUI::Widget* mAvatar; MyGUI::TextBox* mArmorRating; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 31e0722aa..8348b6066 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -1,15 +1,20 @@ #include "tradewindow.hpp" +#include + #include "../mwbase/environment.hpp" #include "../mwworld/world.hpp" +#include "../mwworld/inventorystore.hpp" #include "window_manager.hpp" +#include "inventorywindow.hpp" namespace MWGui { TradeWindow::TradeWindow(WindowManager& parWindowManager) : - WindowBase("openmw_trade_window_layout.xml", parWindowManager), - ContainerBase(NULL) // no drag&drop + WindowBase("openmw_trade_window_layout.xml", parWindowManager) + , ContainerBase(NULL) // no drag&drop + , mCurrentBalance(0) { MyGUI::ScrollView* itemView; MyGUI::Widget* containerWidget; @@ -40,9 +45,6 @@ namespace MWGui mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sOffer")->str); /* - mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalCost")->str); - mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalSold")->str); - mPlayerGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sYourGold")->str); mMerchantGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sSellerGold")->str); */ @@ -108,6 +110,10 @@ namespace MWGui setTitle(MWWorld::Class::get(actor).getName(actor)); adjustWindowCaption(); + + mCurrentBalance = 0; + + updateLabels(); } void TradeWindow::onFilterChanged(MyGUI::Widget* _sender) @@ -145,4 +151,40 @@ namespace MWGui { mWindowManager.setGuiMode(GM_Game); } + + void TradeWindow::updateLabels() + { + mPlayerGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sYourGold")->str + + " " + boost::lexical_cast(mWindowManager.getInventoryWindow()->getPlayerGold())); + + if (mCurrentBalance > 0) + { + mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalSold")->str); + mTotalBalance->setCaption(boost::lexical_cast(mCurrentBalance)); + } + else + { + mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalCost")->str); + mTotalBalance->setCaption(boost::lexical_cast(-mCurrentBalance)); + } + } + + + std::vector TradeWindow::getEquippedItems() + { + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + + std::vector items; + + for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) + { + MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); + if (it != invStore.end()) + { + items.push_back(*it); + } + } + + return items; + } } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 1f937d06e..dd28fcb8b 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -50,10 +50,18 @@ namespace MWGui MyGUI::TextBox* mPlayerGold; MyGUI::TextBox* mMerchantGold; + int mCurrentBalance; + void onWindowResize(MyGUI::Window* _sender); void onFilterChanged(MyGUI::Widget* _sender); void onOfferButtonClicked(MyGUI::Widget* _sender); void onCancelButtonClicked(MyGUI::Widget* _sender); + + // don't show items that the NPC has equipped in his trade-window. + virtual bool ignoreEquippedItems() { return true; } + virtual std::vector getEquippedItems(); + + void updateLabels(); }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index e970de2e6..e12fb851e 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -108,10 +108,10 @@ WindowManager::WindowManager( console = new Console(w,h, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); + mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); mTradeWindow = new TradeWindow(*this); mDialogueWindow = new DialogueWindow(*this); mContainerWindow = new ContainerWindow(*this,mDragAndDrop); - mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); hud = new HUD(w,h, showFPSLevel, mDragAndDrop); mToolTips = new ToolTips(this); mScrollWindow = new ScrollWindow(*this); diff --git a/files/mygui/openmw_trade_window_layout.xml b/files/mygui/openmw_trade_window_layout.xml index 076924322..b6a93e697 100644 --- a/files/mygui/openmw_trade_window_layout.xml +++ b/files/mygui/openmw_trade_window_layout.xml @@ -22,10 +22,10 @@ - + - +