Use owned tooltips for items in containers correctly

new-script-api
Andrei Kortunov 7 years ago
parent b24fd77ea2
commit 1cb7ed5db1

@ -22,6 +22,7 @@
#include "itemview.hpp"
#include "itemwidget.hpp"
#include "inventoryitemmodel.hpp"
#include "containeritemmodel.hpp"
#include "sortfilteritemmodel.hpp"
#include "pickpocketitemmodel.hpp"
#include "draganddrop.hpp"
@ -136,15 +137,22 @@ namespace MWGui
bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead();
if (mPtr.getClass().isNpc() && !loot)
if (mPtr.getClass().hasInventoryStore(mPtr))
{
// we are stealing stuff
MWWorld::Ptr player = MWMechanics::getPlayer();
mModel = new PickpocketItemModel(player, new InventoryItemModel(container),
!mPtr.getClass().getCreatureStats(mPtr).getKnockedDown());
if (mPtr.getClass().isNpc() && !loot)
{
// we are stealing stuff
MWWorld::Ptr player = MWMechanics::getPlayer();
mModel = new PickpocketItemModel(player, new InventoryItemModel(container),
!mPtr.getClass().getCreatureStats(mPtr).getKnockedDown());
}
else
mModel = new InventoryItemModel(container);
}
else
mModel = new InventoryItemModel(container);
{
mModel = new ContainerItemModel(container);
}
mDisposeCorpseButton->setVisible(loot);

@ -6,8 +6,11 @@
#include "../mwworld/class.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/environment.hpp"
#include "../mwmechanics/actorutil.hpp"
namespace
{
@ -47,6 +50,19 @@ ContainerItemModel::ContainerItemModel (const MWWorld::Ptr& source)
mItemSources.push_back(source);
}
bool ContainerItemModel::allowedToUseItems() const
{
if (mItemSources.size() == 0)
return true;
MWWorld::Ptr ptr = MWMechanics::getPlayer();
MWWorld::Ptr victim;
// Check if the player is allowed to use items from opened container
MWBase::MechanicsManager* mm = MWBase::Environment::get().getMechanicsManager();
return mm->isAllowedToUse(ptr, mItemSources[0], victim);
}
ItemStack ContainerItemModel::getItem (ModelIndex index)
{
if (index < 0)

@ -17,6 +17,7 @@ namespace MWGui
ContainerItemModel (const MWWorld::Ptr& source);
virtual bool allowedToUseItems() const;
virtual ItemStack getItem (ModelIndex index);
virtual ModelIndex getIndex (ItemStack item);
virtual size_t getItemCount();

@ -119,6 +119,11 @@ namespace MWGui
return ret;
}
bool ItemModel::allowedToUseItems() const
{
return true;
}
bool ItemModel::allowedToInsertItems() const
{
return true;
@ -135,6 +140,11 @@ namespace MWGui
delete mSourceModel;
}
bool ProxyItemModel::allowedToUseItems() const
{
return mSourceModel->allowedToUseItems();
}
MWWorld::Ptr ProxyItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
{
return mSourceModel->copyItem (item, count, setNewOwner);

@ -70,6 +70,9 @@ namespace MWGui
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false) = 0;
virtual void removeItem (const ItemStack& item, size_t count) = 0;
/// Is the player allowed to use items from this item model? (default true)
virtual bool allowedToUseItems() const;
/// Is the player allowed to insert items into this model? (default true)
virtual bool allowedToInsertItems() const;
@ -85,6 +88,9 @@ namespace MWGui
public:
ProxyItemModel();
virtual ~ProxyItemModel();
bool allowedToUseItems() const;
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
virtual void removeItem (const ItemStack& item, size_t count);
virtual ModelIndex getIndex (ItemStack item);

@ -26,6 +26,11 @@ namespace MWGui
}
}
bool PickpocketItemModel::allowedToUseItems() const
{
return false;
}
ItemStack PickpocketItemModel::getItem (ModelIndex index)
{
if (index < 0)

@ -11,6 +11,8 @@ namespace MWGui
{
public:
PickpocketItemModel (const MWWorld::Ptr& thief, ItemModel* sourceModel, bool hideItems=true);
virtual bool allowedToUseItems() const;
virtual ItemStack getItem (ModelIndex index);
virtual size_t getItemCount();
virtual void update();

@ -159,6 +159,11 @@ namespace MWGui
mSourceModel = sourceModel;
}
bool SortFilterItemModel::allowedToUseItems() const
{
return mSourceModel->allowedToUseItems();
}
void SortFilterItemModel::addDragItem (const MWWorld::Ptr& dragItem, size_t count)
{
mDragItems.push_back(std::make_pair(dragItem, count));

@ -15,6 +15,7 @@ namespace MWGui
bool filterAccepts (const ItemStack& item);
bool allowedToUseItems() const;
virtual ItemStack getItem (ModelIndex index);
virtual size_t getItemCount();

@ -120,7 +120,7 @@ namespace MWGui
if (info.caption.empty())
info.caption=mFocusObject.getCellRef().getRefId();
info.icon="";
tooltipSize = createToolTip(info, true);
tooltipSize = createToolTip(info, checkOwned());
}
else
tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), true);
@ -186,22 +186,24 @@ namespace MWGui
ToolTipInfo info;
info.text = data.caption;
info.notes = data.notes;
tooltipSize = createToolTip(info, false);
tooltipSize = createToolTip(info);
}
else if (type == "ItemPtr")
{
mFocusObject = *focus->getUserData<MWWorld::Ptr>();
tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), false);
bool isAllowedToUse = checkOwned();
tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), false, !isAllowedToUse);
}
else if (type == "ItemModelIndex")
{
std::pair<ItemModel::ModelIndex, ItemModel*> pair = *focus->getUserData<std::pair<ItemModel::ModelIndex, ItemModel*> >();
mFocusObject = pair.second->getItem(pair.first).mBase;
tooltipSize = getToolTipViaPtr(pair.second->getItem(pair.first).mCount, false);
bool isAllowedToUse = pair.second->allowedToUseItems();
tooltipSize = getToolTipViaPtr(pair.second->getItem(pair.first).mCount, false, !isAllowedToUse);
}
else if (type == "ToolTipInfo")
{
tooltipSize = createToolTip(*focus->getUserData<MWGui::ToolTipInfo>(), false);
tooltipSize = createToolTip(*focus->getUserData<MWGui::ToolTipInfo>());
}
else if (type == "AvatarItemSelection")
{
@ -244,7 +246,7 @@ namespace MWGui
info.text = "#{sSchool}: " + sSchoolNames[school];
}
info.effects = effects;
tooltipSize = createToolTip(info, false);
tooltipSize = createToolTip(info);
}
else if (type == "Layout")
{
@ -298,7 +300,7 @@ namespace MWGui
{
if (!mFocusObject.isEmpty())
{
MyGUI::IntSize tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount());
MyGUI::IntSize tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), true, checkOwned());
setCoord(viewSize.width/2 - tooltipSize.width/2,
std::max(0, int(mFocusToolTipY*viewSize.height - tooltipSize.height)),
@ -332,7 +334,7 @@ namespace MWGui
update(mFrameDuration);
}
MyGUI::IntSize ToolTips::getToolTipViaPtr (int count, bool image)
MyGUI::IntSize ToolTips::getToolTipViaPtr (int count, bool image, bool isOwned)
{
// this the maximum width of the tooltip before it starts word-wrapping
setCoord(0, 0, 300, 300);
@ -351,7 +353,7 @@ namespace MWGui
ToolTipInfo info = object.getToolTipInfo(mFocusObject, count);
if (!image)
info.icon = "";
tooltipSize = createToolTip(info, true);
tooltipSize = createToolTip(info, isOwned);
}
return tooltipSize;
@ -359,27 +361,21 @@ namespace MWGui
bool ToolTips::checkOwned()
{
if(!mFocusObject.isEmpty())
{
MWWorld::Ptr ptr = MWMechanics::getPlayer();
MWWorld::Ptr victim;
MWBase::MechanicsManager* mm = MWBase::Environment::get().getMechanicsManager();
bool allowed = mm->isAllowedToUse(ptr, mFocusObject, victim);
return !allowed;
}
else
{
if(mFocusObject.isEmpty())
return false;
}
MWWorld::Ptr ptr = MWMechanics::getPlayer();
MWWorld::Ptr victim;
MWBase::MechanicsManager* mm = MWBase::Environment::get().getMechanicsManager();
return !mm->isAllowedToUse(ptr, mFocusObject, victim);
}
MyGUI::IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info, bool isFocusObject)
MyGUI::IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info, bool isOwned)
{
mDynamicToolTipBox->setVisible(true);
if((mShowOwned == 1 || mShowOwned == 3) && isFocusObject && checkOwned())
if((mShowOwned == 1 || mShowOwned == 3) && isOwned)
mDynamicToolTipBox->changeWidgetSkin(MWBase::Environment::get().getWindowManager()->isGuiMode() ? "HUD_Box_NoTransp_Owned" : "HUD_Box_Owned");
else
mDynamicToolTipBox->changeWidgetSkin(MWBase::Environment::get().getWindowManager()->isGuiMode() ? "HUD_Box_NoTransp" : "HUD_Box");

@ -98,10 +98,10 @@ namespace MWGui
MWWorld::Ptr mFocusObject;
MyGUI::IntSize getToolTipViaPtr (int count, bool image=true);
MyGUI::IntSize getToolTipViaPtr (int count, bool image = true, bool isOwned = false);
///< @return requested tooltip size
MyGUI::IntSize createToolTip(const ToolTipInfo& info, bool isFocusObject);
MyGUI::IntSize createToolTip(const ToolTipInfo& info, bool isOwned = false);
///< @return requested tooltip size
/// @param isFocusObject Is the object this tooltips originates from mFocusObject?

@ -15,6 +15,11 @@ namespace MWGui
mSourceModel = sourceModel;
}
bool TradeItemModel::allowedToUseItems() const
{
return true;
}
ItemStack TradeItemModel::getItem (ModelIndex index)
{
if (index < 0)

@ -15,6 +15,8 @@ namespace MWGui
public:
TradeItemModel (ItemModel* sourceModel, const MWWorld::Ptr& merchant);
bool allowedToUseItems() const;
virtual ItemStack getItem (ModelIndex index);
virtual size_t getItemCount();

@ -842,6 +842,9 @@ namespace MWMechanics
bool MechanicsManager::isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim)
{
if (target.isEmpty())
return true;
const MWWorld::CellRef& cellref = target.getCellRef();
// there is no harm to use unlocked doors
if (target.getClass().isDoor() && cellref.getLockLevel() <= 0 && ptr.getCellRef().getTrap().empty())

Loading…
Cancel
Save