mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-19 03:39:58 +00:00
Use owned tooltips for items in containers correctly
This commit is contained in:
parent
b24fd77ea2
commit
1cb7ed5db1
@ -22,6 +22,7 @@
|
|||||||
#include "itemview.hpp"
|
#include "itemview.hpp"
|
||||||
#include "itemwidget.hpp"
|
#include "itemwidget.hpp"
|
||||||
#include "inventoryitemmodel.hpp"
|
#include "inventoryitemmodel.hpp"
|
||||||
|
#include "containeritemmodel.hpp"
|
||||||
#include "sortfilteritemmodel.hpp"
|
#include "sortfilteritemmodel.hpp"
|
||||||
#include "pickpocketitemmodel.hpp"
|
#include "pickpocketitemmodel.hpp"
|
||||||
#include "draganddrop.hpp"
|
#include "draganddrop.hpp"
|
||||||
@ -136,6 +137,8 @@ namespace MWGui
|
|||||||
|
|
||||||
bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead();
|
bool loot = mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead();
|
||||||
|
|
||||||
|
if (mPtr.getClass().hasInventoryStore(mPtr))
|
||||||
|
{
|
||||||
if (mPtr.getClass().isNpc() && !loot)
|
if (mPtr.getClass().isNpc() && !loot)
|
||||||
{
|
{
|
||||||
// we are stealing stuff
|
// we are stealing stuff
|
||||||
@ -145,6 +148,11 @@ namespace MWGui
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
mModel = new InventoryItemModel(container);
|
mModel = new InventoryItemModel(container);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mModel = new ContainerItemModel(container);
|
||||||
|
}
|
||||||
|
|
||||||
mDisposeCorpseButton->setVisible(loot);
|
mDisposeCorpseButton->setVisible(loot);
|
||||||
|
|
||||||
|
@ -6,8 +6,11 @@
|
|||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwbase/mechanicsmanager.hpp"
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
|
||||||
|
#include "../mwmechanics/actorutil.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -47,6 +50,19 @@ ContainerItemModel::ContainerItemModel (const MWWorld::Ptr& source)
|
|||||||
mItemSources.push_back(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)
|
ItemStack ContainerItemModel::getItem (ModelIndex index)
|
||||||
{
|
{
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
|
@ -17,6 +17,7 @@ namespace MWGui
|
|||||||
|
|
||||||
ContainerItemModel (const MWWorld::Ptr& source);
|
ContainerItemModel (const MWWorld::Ptr& source);
|
||||||
|
|
||||||
|
virtual bool allowedToUseItems() const;
|
||||||
virtual ItemStack getItem (ModelIndex index);
|
virtual ItemStack getItem (ModelIndex index);
|
||||||
virtual ModelIndex getIndex (ItemStack item);
|
virtual ModelIndex getIndex (ItemStack item);
|
||||||
virtual size_t getItemCount();
|
virtual size_t getItemCount();
|
||||||
|
@ -119,6 +119,11 @@ namespace MWGui
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ItemModel::allowedToUseItems() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ItemModel::allowedToInsertItems() const
|
bool ItemModel::allowedToInsertItems() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@ -135,6 +140,11 @@ namespace MWGui
|
|||||||
delete mSourceModel;
|
delete mSourceModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProxyItemModel::allowedToUseItems() const
|
||||||
|
{
|
||||||
|
return mSourceModel->allowedToUseItems();
|
||||||
|
}
|
||||||
|
|
||||||
MWWorld::Ptr ProxyItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
|
MWWorld::Ptr ProxyItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
|
||||||
{
|
{
|
||||||
return mSourceModel->copyItem (item, count, 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 MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false) = 0;
|
||||||
virtual void removeItem (const ItemStack& item, size_t count) = 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)
|
/// Is the player allowed to insert items into this model? (default true)
|
||||||
virtual bool allowedToInsertItems() const;
|
virtual bool allowedToInsertItems() const;
|
||||||
|
|
||||||
@ -85,6 +88,9 @@ namespace MWGui
|
|||||||
public:
|
public:
|
||||||
ProxyItemModel();
|
ProxyItemModel();
|
||||||
virtual ~ProxyItemModel();
|
virtual ~ProxyItemModel();
|
||||||
|
|
||||||
|
bool allowedToUseItems() const;
|
||||||
|
|
||||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
|
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
|
||||||
virtual void removeItem (const ItemStack& item, size_t count);
|
virtual void removeItem (const ItemStack& item, size_t count);
|
||||||
virtual ModelIndex getIndex (ItemStack item);
|
virtual ModelIndex getIndex (ItemStack item);
|
||||||
|
@ -26,6 +26,11 @@ namespace MWGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PickpocketItemModel::allowedToUseItems() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ItemStack PickpocketItemModel::getItem (ModelIndex index)
|
ItemStack PickpocketItemModel::getItem (ModelIndex index)
|
||||||
{
|
{
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
|
@ -11,6 +11,8 @@ namespace MWGui
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PickpocketItemModel (const MWWorld::Ptr& thief, ItemModel* sourceModel, bool hideItems=true);
|
PickpocketItemModel (const MWWorld::Ptr& thief, ItemModel* sourceModel, bool hideItems=true);
|
||||||
|
|
||||||
|
virtual bool allowedToUseItems() const;
|
||||||
virtual ItemStack getItem (ModelIndex index);
|
virtual ItemStack getItem (ModelIndex index);
|
||||||
virtual size_t getItemCount();
|
virtual size_t getItemCount();
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
@ -159,6 +159,11 @@ namespace MWGui
|
|||||||
mSourceModel = sourceModel;
|
mSourceModel = sourceModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SortFilterItemModel::allowedToUseItems() const
|
||||||
|
{
|
||||||
|
return mSourceModel->allowedToUseItems();
|
||||||
|
}
|
||||||
|
|
||||||
void SortFilterItemModel::addDragItem (const MWWorld::Ptr& dragItem, size_t count)
|
void SortFilterItemModel::addDragItem (const MWWorld::Ptr& dragItem, size_t count)
|
||||||
{
|
{
|
||||||
mDragItems.push_back(std::make_pair(dragItem, count));
|
mDragItems.push_back(std::make_pair(dragItem, count));
|
||||||
|
@ -15,6 +15,7 @@ namespace MWGui
|
|||||||
|
|
||||||
bool filterAccepts (const ItemStack& item);
|
bool filterAccepts (const ItemStack& item);
|
||||||
|
|
||||||
|
bool allowedToUseItems() const;
|
||||||
virtual ItemStack getItem (ModelIndex index);
|
virtual ItemStack getItem (ModelIndex index);
|
||||||
virtual size_t getItemCount();
|
virtual size_t getItemCount();
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ namespace MWGui
|
|||||||
if (info.caption.empty())
|
if (info.caption.empty())
|
||||||
info.caption=mFocusObject.getCellRef().getRefId();
|
info.caption=mFocusObject.getCellRef().getRefId();
|
||||||
info.icon="";
|
info.icon="";
|
||||||
tooltipSize = createToolTip(info, true);
|
tooltipSize = createToolTip(info, checkOwned());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), true);
|
tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), true);
|
||||||
@ -186,22 +186,24 @@ namespace MWGui
|
|||||||
ToolTipInfo info;
|
ToolTipInfo info;
|
||||||
info.text = data.caption;
|
info.text = data.caption;
|
||||||
info.notes = data.notes;
|
info.notes = data.notes;
|
||||||
tooltipSize = createToolTip(info, false);
|
tooltipSize = createToolTip(info);
|
||||||
}
|
}
|
||||||
else if (type == "ItemPtr")
|
else if (type == "ItemPtr")
|
||||||
{
|
{
|
||||||
mFocusObject = *focus->getUserData<MWWorld::Ptr>();
|
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")
|
else if (type == "ItemModelIndex")
|
||||||
{
|
{
|
||||||
std::pair<ItemModel::ModelIndex, ItemModel*> pair = *focus->getUserData<std::pair<ItemModel::ModelIndex, ItemModel*> >();
|
std::pair<ItemModel::ModelIndex, ItemModel*> pair = *focus->getUserData<std::pair<ItemModel::ModelIndex, ItemModel*> >();
|
||||||
mFocusObject = pair.second->getItem(pair.first).mBase;
|
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")
|
else if (type == "ToolTipInfo")
|
||||||
{
|
{
|
||||||
tooltipSize = createToolTip(*focus->getUserData<MWGui::ToolTipInfo>(), false);
|
tooltipSize = createToolTip(*focus->getUserData<MWGui::ToolTipInfo>());
|
||||||
}
|
}
|
||||||
else if (type == "AvatarItemSelection")
|
else if (type == "AvatarItemSelection")
|
||||||
{
|
{
|
||||||
@ -244,7 +246,7 @@ namespace MWGui
|
|||||||
info.text = "#{sSchool}: " + sSchoolNames[school];
|
info.text = "#{sSchool}: " + sSchoolNames[school];
|
||||||
}
|
}
|
||||||
info.effects = effects;
|
info.effects = effects;
|
||||||
tooltipSize = createToolTip(info, false);
|
tooltipSize = createToolTip(info);
|
||||||
}
|
}
|
||||||
else if (type == "Layout")
|
else if (type == "Layout")
|
||||||
{
|
{
|
||||||
@ -298,7 +300,7 @@ namespace MWGui
|
|||||||
{
|
{
|
||||||
if (!mFocusObject.isEmpty())
|
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,
|
setCoord(viewSize.width/2 - tooltipSize.width/2,
|
||||||
std::max(0, int(mFocusToolTipY*viewSize.height - tooltipSize.height)),
|
std::max(0, int(mFocusToolTipY*viewSize.height - tooltipSize.height)),
|
||||||
@ -332,7 +334,7 @@ namespace MWGui
|
|||||||
update(mFrameDuration);
|
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
|
// this the maximum width of the tooltip before it starts word-wrapping
|
||||||
setCoord(0, 0, 300, 300);
|
setCoord(0, 0, 300, 300);
|
||||||
@ -351,7 +353,7 @@ namespace MWGui
|
|||||||
ToolTipInfo info = object.getToolTipInfo(mFocusObject, count);
|
ToolTipInfo info = object.getToolTipInfo(mFocusObject, count);
|
||||||
if (!image)
|
if (!image)
|
||||||
info.icon = "";
|
info.icon = "";
|
||||||
tooltipSize = createToolTip(info, true);
|
tooltipSize = createToolTip(info, isOwned);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tooltipSize;
|
return tooltipSize;
|
||||||
@ -359,27 +361,21 @@ namespace MWGui
|
|||||||
|
|
||||||
bool ToolTips::checkOwned()
|
bool ToolTips::checkOwned()
|
||||||
{
|
{
|
||||||
if(!mFocusObject.isEmpty())
|
if(mFocusObject.isEmpty())
|
||||||
{
|
return false;
|
||||||
|
|
||||||
MWWorld::Ptr ptr = MWMechanics::getPlayer();
|
MWWorld::Ptr ptr = MWMechanics::getPlayer();
|
||||||
MWWorld::Ptr victim;
|
MWWorld::Ptr victim;
|
||||||
|
|
||||||
MWBase::MechanicsManager* mm = MWBase::Environment::get().getMechanicsManager();
|
MWBase::MechanicsManager* mm = MWBase::Environment::get().getMechanicsManager();
|
||||||
bool allowed = mm->isAllowedToUse(ptr, mFocusObject, victim);
|
return !mm->isAllowedToUse(ptr, mFocusObject, victim);
|
||||||
|
|
||||||
return !allowed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MyGUI::IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info, bool isFocusObject)
|
MyGUI::IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info, bool isOwned)
|
||||||
{
|
{
|
||||||
mDynamicToolTipBox->setVisible(true);
|
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");
|
mDynamicToolTipBox->changeWidgetSkin(MWBase::Environment::get().getWindowManager()->isGuiMode() ? "HUD_Box_NoTransp_Owned" : "HUD_Box_Owned");
|
||||||
else
|
else
|
||||||
mDynamicToolTipBox->changeWidgetSkin(MWBase::Environment::get().getWindowManager()->isGuiMode() ? "HUD_Box_NoTransp" : "HUD_Box");
|
mDynamicToolTipBox->changeWidgetSkin(MWBase::Environment::get().getWindowManager()->isGuiMode() ? "HUD_Box_NoTransp" : "HUD_Box");
|
||||||
|
@ -98,10 +98,10 @@ namespace MWGui
|
|||||||
|
|
||||||
MWWorld::Ptr mFocusObject;
|
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
|
///< @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
|
///< @return requested tooltip size
|
||||||
/// @param isFocusObject Is the object this tooltips originates from mFocusObject?
|
/// @param isFocusObject Is the object this tooltips originates from mFocusObject?
|
||||||
|
|
||||||
|
@ -15,6 +15,11 @@ namespace MWGui
|
|||||||
mSourceModel = sourceModel;
|
mSourceModel = sourceModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TradeItemModel::allowedToUseItems() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
ItemStack TradeItemModel::getItem (ModelIndex index)
|
ItemStack TradeItemModel::getItem (ModelIndex index)
|
||||||
{
|
{
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
|
@ -15,6 +15,8 @@ namespace MWGui
|
|||||||
public:
|
public:
|
||||||
TradeItemModel (ItemModel* sourceModel, const MWWorld::Ptr& merchant);
|
TradeItemModel (ItemModel* sourceModel, const MWWorld::Ptr& merchant);
|
||||||
|
|
||||||
|
bool allowedToUseItems() const;
|
||||||
|
|
||||||
virtual ItemStack getItem (ModelIndex index);
|
virtual ItemStack getItem (ModelIndex index);
|
||||||
virtual size_t getItemCount();
|
virtual size_t getItemCount();
|
||||||
|
|
||||||
|
@ -842,6 +842,9 @@ namespace MWMechanics
|
|||||||
|
|
||||||
bool MechanicsManager::isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim)
|
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();
|
const MWWorld::CellRef& cellref = target.getCellRef();
|
||||||
// there is no harm to use unlocked doors
|
// there is no harm to use unlocked doors
|
||||||
if (target.getClass().isDoor() && cellref.getLockLevel() <= 0 && ptr.getCellRef().getTrap().empty())
|
if (target.getClass().isDoor() && cellref.getLockLevel() <= 0 && ptr.getCellRef().getTrap().empty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user