forked from teamnwah/openmw-tes3coop
only show items in the trade window that the NPC actually trades (services enum)
This commit is contained in:
parent
adf0550292
commit
e2400ca7b2
4 changed files with 66 additions and 5 deletions
|
@ -309,11 +309,14 @@ void ContainerBase::drawItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<MWWorld::Ptr> ignoreItems = itemsToIgnore();
|
||||||
|
|
||||||
// now add the regular items
|
// now add the regular items
|
||||||
std::vector<MWWorld::Ptr> regularItems;
|
std::vector<MWWorld::Ptr> regularItems;
|
||||||
for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter)
|
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);
|
regularItems.push_back(*iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,13 +94,12 @@ namespace MWGui
|
||||||
|
|
||||||
std::string getCountString(const int count);
|
std::string getCountString(const int count);
|
||||||
|
|
||||||
// to be reimplemented by InventoryWindow
|
|
||||||
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) { ; }
|
||||||
|
|
||||||
// to be reimplemented by TradeWindow
|
|
||||||
virtual bool ignoreEquippedItems() { return false; }
|
virtual bool ignoreEquippedItems() { return false; }
|
||||||
|
virtual std::vector<MWWorld::Ptr> itemsToIgnore() { return std::vector<MWWorld::Ptr>(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class ContainerWindow : public ContainerBase, public WindowBase
|
class ContainerWindow : public ContainerBase, public WindowBase
|
||||||
|
|
|
@ -197,8 +197,6 @@ namespace MWGui
|
||||||
|
|
||||||
std::vector<MWWorld::Ptr> TradeWindow::getEquippedItems()
|
std::vector<MWWorld::Ptr> TradeWindow::getEquippedItems()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
std::vector<MWWorld::Ptr> items;
|
std::vector<MWWorld::Ptr> items;
|
||||||
|
|
||||||
if (mContainer.getTypeName() == typeid(ESM::Creature).name())
|
if (mContainer.getTypeName() == typeid(ESM::Creature).name())
|
||||||
|
@ -220,4 +218,61 @@ namespace MWGui
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TradeWindow::npcAcceptsItem(MWWorld::Ptr item)
|
||||||
|
{
|
||||||
|
int services = 0;
|
||||||
|
if (mContainer.getTypeName() == typeid(ESM::NPC).name())
|
||||||
|
{
|
||||||
|
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData>* ref = mContainer.get<ESM::NPC>();
|
||||||
|
if (ref->base->hasAI)
|
||||||
|
services = ref->base->AI.services;
|
||||||
|
}
|
||||||
|
else if (mContainer.getTypeName() == typeid(ESM::Creature).name())
|
||||||
|
{
|
||||||
|
ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData>* ref = mContainer.get<ESM::Creature>();
|
||||||
|
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<MWWorld::Ptr> TradeWindow::itemsToIgnore()
|
||||||
|
{
|
||||||
|
std::vector<MWWorld::Ptr> items;
|
||||||
|
MWWorld::InventoryStore& invStore = static_cast<MWWorld::InventoryStore&>(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ namespace MWGui
|
||||||
//virtual void Update();
|
//virtual void Update();
|
||||||
//virtual void notifyContentChanged();
|
//virtual void notifyContentChanged();
|
||||||
|
|
||||||
|
bool npcAcceptsItem(MWWorld::Ptr item);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MyGUI::Button* mFilterAll;
|
MyGUI::Button* mFilterAll;
|
||||||
MyGUI::Button* mFilterWeapon;
|
MyGUI::Button* mFilterWeapon;
|
||||||
|
@ -61,6 +63,8 @@ namespace MWGui
|
||||||
virtual bool ignoreEquippedItems() { return true; }
|
virtual bool ignoreEquippedItems() { return true; }
|
||||||
virtual std::vector<MWWorld::Ptr> getEquippedItems();
|
virtual std::vector<MWWorld::Ptr> getEquippedItems();
|
||||||
|
|
||||||
|
virtual std::vector<MWWorld::Ptr> itemsToIgnore();
|
||||||
|
|
||||||
void updateLabels();
|
void updateLabels();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue