1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 22:49:55 +00:00
openmw-tes3mp/apps/openmw/mwgui/itemmodel.hpp

116 lines
3.6 KiB
C++
Raw Normal View History

2013-05-11 16:38:27 +00:00
#ifndef MWGUI_ITEM_MODEL_H
#define MWGUI_ITEM_MODEL_H
#include "../mwworld/ptr.hpp"
namespace MWGui
{
class ItemModel;
/// @brief A single item stack managed by an item model
struct ItemStack
{
ItemStack (const MWWorld::Ptr& base, ItemModel* creator, size_t count);
ItemStack();
bool stacks (const ItemStack& other);
///< like operator==, only without checking mType
enum Type
{
Type_Barter,
Type_Equipped,
Type_Normal
};
Type mType;
enum Flags
{
Flag_Enchanted = (1<<0),
Flag_Bound = (1<<1)
2013-05-11 16:38:27 +00:00
};
int mFlags;
ItemModel* mCreator;
size_t mCount;
MWWorld::Ptr mBase;
};
bool operator == (const ItemStack& left, const ItemStack& right);
/// @brief The base class that all item models should derive from.
class ItemModel
{
public:
ItemModel();
virtual ~ItemModel() {}
typedef int ModelIndex; // -1 means invalid index
2013-05-11 16:38:27 +00:00
/// Throws for invalid index or out of range index
2013-05-11 16:38:27 +00:00
virtual ItemStack getItem (ModelIndex index) = 0;
/// The number of items in the model, this specifies the range of indices you can pass to
/// the getItem function (but this range is only valid until the next call to update())
2013-05-11 16:38:27 +00:00
virtual size_t getItemCount() = 0;
/// Returns an invalid index if the item was not found
2013-05-11 16:38:27 +00:00
virtual ModelIndex getIndex (ItemStack item) = 0;
/// Rebuild the item model, this will invalidate existing model indices
2013-05-11 16:38:27 +00:00
virtual void update() = 0;
/// Move items from this model to \a otherModel.
/// @note Derived implementations may return an empty Ptr if the move was unsuccessful.
virtual MWWorld::Ptr moveItem (const ItemStack& item, size_t count, ItemModel* otherModel);
/// @param setNewOwner If true, set the copied item's owner to the actor we are copying to,
/// otherwise reset owner to ""
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count) = 0;
2013-05-11 16:38:27 +00:00
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;
2017-10-04 19:26:06 +00:00
virtual void onClose()
{
}
virtual bool onDropItem(const MWWorld::Ptr &item, int count);
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
2016-03-05 18:53:24 +00:00
2013-05-11 16:38:27 +00:00
private:
ItemModel(const ItemModel&);
ItemModel& operator=(const ItemModel&);
};
/// @brief A proxy item model can be used to filter or rearrange items from a source model (or even add new items to it).
/// The neat thing is that this does not actually alter the source model.
class ProxyItemModel : public ItemModel
{
public:
ProxyItemModel();
2013-05-11 16:38:27 +00:00
virtual ~ProxyItemModel();
bool allowedToUseItems() const;
2017-10-04 19:26:06 +00:00
virtual void onClose();
virtual bool onDropItem(const MWWorld::Ptr &item, int count);
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
2017-10-04 18:37:08 +00:00
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count);
2013-05-11 16:38:27 +00:00
virtual void removeItem (const ItemStack& item, size_t count);
virtual ModelIndex getIndex (ItemStack item);
/// @note Takes ownership of the passed pointer.
void setSourceModel(ItemModel* sourceModel);
2013-05-11 16:38:27 +00:00
ModelIndex mapToSource (ModelIndex index);
ModelIndex mapFromSource (ModelIndex index);
protected:
ItemModel* mSourceModel;
};
}
#endif