diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 6f8ca4730..9ff4b8d4a 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -309,11 +309,14 @@ void ContainerBase::drawItems() } } + std::vector ignoreItems = itemsToIgnore(); + // now add the regular items std::vector regularItems; for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) { - if (std::find(equippedItems.begin(), equippedItems.end(), *iter) == equippedItems.end()) + if (std::find(equippedItems.begin(), equippedItems.end(), *iter) == equippedItems.end() + && std::find(ignoreItems.begin(), ignoreItems.end(), *iter) == ignoreItems.end()) regularItems.push_back(*iter); } diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 956382f23..563b22bc3 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -94,13 +94,12 @@ namespace MWGui std::string getCountString(const int count); - // to be reimplemented by InventoryWindow 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; } + virtual std::vector itemsToIgnore() { return std::vector(); } }; class ContainerWindow : public ContainerBase, public WindowBase diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 97c66b9dc..e5fc47764 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -197,8 +197,6 @@ namespace MWGui std::vector TradeWindow::getEquippedItems() { - - std::vector items; if (mContainer.getTypeName() == typeid(ESM::Creature).name()) @@ -220,4 +218,61 @@ namespace MWGui return items; } + + bool TradeWindow::npcAcceptsItem(MWWorld::Ptr item) + { + int services = 0; + if (mContainer.getTypeName() == typeid(ESM::NPC).name()) + { + ESMS::LiveCellRef* ref = mContainer.get(); + if (ref->base->hasAI) + services = ref->base->AI.services; + } + else if (mContainer.getTypeName() == typeid(ESM::Creature).name()) + { + ESMS::LiveCellRef* ref = mContainer.get(); + if (ref->base->hasAI) + services = ref->base->AI.services; + } + + if (item.getTypeName() == typeid(ESM::Weapon).name()) + return services & ESM::NPC::Weapon; + else if (item.getTypeName() == typeid(ESM::Armor).name()) + return services & ESM::NPC::Armor; + else if (item.getTypeName() == typeid(ESM::Clothing).name()) + return services & ESM::NPC::Clothing; + else if (item.getTypeName() == typeid(ESM::Book).name()) + return services & ESM::NPC::Books; + else if (item.getTypeName() == typeid(ESM::Ingredient).name()) + return services & ESM::NPC::Ingredients; + else if (item.getTypeName() == typeid(ESM::Tool).name()) + return services & ESM::NPC::Picks; + else if (item.getTypeName() == typeid(ESM::Probe).name()) + return services & ESM::NPC::Probes; + else if (item.getTypeName() == typeid(ESM::Light).name()) + return services & ESM::NPC::Lights; + else if (item.getTypeName() == typeid(ESM::Apparatus).name()) + return services & ESM::NPC::Apparatus; + else if (item.getTypeName() == typeid(ESM::Repair).name()) + return services & ESM::NPC::RepairItem; + else if (item.getTypeName() == typeid(ESM::Miscellaneous).name()) + return services & ESM::NPC::Misc; + + return false; + } + + std::vector TradeWindow::itemsToIgnore() + { + std::vector items; + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + + for (MWWorld::ContainerStoreIterator it = invStore.begin(); + it != invStore.end(); ++it) + { + if (!npcAcceptsItem(*it)) + items.push_back(*it); + } + + return items; + } } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index dd28fcb8b..5e762cbe5 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -30,6 +30,8 @@ namespace MWGui //virtual void Update(); //virtual void notifyContentChanged(); + bool npcAcceptsItem(MWWorld::Ptr item); + protected: MyGUI::Button* mFilterAll; MyGUI::Button* mFilterWeapon; @@ -61,6 +63,8 @@ namespace MWGui virtual bool ignoreEquippedItems() { return true; } virtual std::vector getEquippedItems(); + virtual std::vector itemsToIgnore(); + void updateLabels(); }; }