mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 09:15:29 +01:00 
			
		
		
		
	Show infotext for unknown items placed on ground
This commit is contained in:
		@@ -183,12 +183,16 @@ public:
 | 
			
		||||
		{return &m_selection_box;}
 | 
			
		||||
	v3f getPosition()
 | 
			
		||||
		{return m_position;}
 | 
			
		||||
	
 | 
			
		||||
	std::string infoText()
 | 
			
		||||
		{return m_infotext;}
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	core::aabbox3d<f32> m_selection_box;
 | 
			
		||||
	scene::IMeshSceneNode *m_node;
 | 
			
		||||
	v3f m_position;
 | 
			
		||||
	std::string m_inventorystring;
 | 
			
		||||
	std::string m_infotext;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
@@ -530,7 +534,10 @@ ItemCAO::ItemCAO(IGameDef *gamedef, ClientEnvironment *env):
 | 
			
		||||
	m_node(NULL),
 | 
			
		||||
	m_position(v3f(0,10*BS,0))
 | 
			
		||||
{
 | 
			
		||||
	ClientActiveObject::registerType(getType(), create);
 | 
			
		||||
	if(!gamedef && !env)
 | 
			
		||||
	{
 | 
			
		||||
		ClientActiveObject::registerType(getType(), create);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ItemCAO::~ItemCAO()
 | 
			
		||||
@@ -694,6 +701,23 @@ void ItemCAO::initialize(const std::string &data)
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	updateNodePos();
 | 
			
		||||
	
 | 
			
		||||
	/*
 | 
			
		||||
		Set infotext to item name if item cannot be deserialized
 | 
			
		||||
	*/
 | 
			
		||||
	try{
 | 
			
		||||
		InventoryItem *item = NULL;
 | 
			
		||||
		item = InventoryItem::deSerialize(m_inventorystring, m_gamedef);
 | 
			
		||||
		if(item){
 | 
			
		||||
			if(!item->isKnown())
 | 
			
		||||
				m_infotext = "Unknown item: '" + m_inventorystring + "'";
 | 
			
		||||
		}
 | 
			
		||||
		delete item;
 | 
			
		||||
	}
 | 
			
		||||
	catch(SerializationError &e)
 | 
			
		||||
	{
 | 
			
		||||
		m_infotext = "Unknown item: '" + m_inventorystring + "'";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
@@ -343,6 +343,13 @@ video::ITexture * ToolItem::getImageRaw() const
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
bool ToolItem::isKnown() const
 | 
			
		||||
{
 | 
			
		||||
	IToolDefManager *tdef = m_gamedef->tdef();
 | 
			
		||||
	const ToolDefinition *def = tdef->getToolDefinition(m_toolname);
 | 
			
		||||
	return (def != NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
	CraftItem
 | 
			
		||||
*/
 | 
			
		||||
@@ -357,6 +364,13 @@ video::ITexture * CraftItem::getImage() const
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
bool CraftItem::isKnown() const
 | 
			
		||||
{
 | 
			
		||||
	ICraftItemDefManager *cidef = m_gamedef->cidef();
 | 
			
		||||
	const CraftItemDefinition *def = cidef->getCraftItemDefinition(m_subname);
 | 
			
		||||
	return (def != NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
u16 CraftItem::getStackMax() const
 | 
			
		||||
{
 | 
			
		||||
	ICraftItemDefManager *cidef = m_gamedef->cidef();
 | 
			
		||||
 
 | 
			
		||||
@@ -64,6 +64,9 @@ public:
 | 
			
		||||
	virtual std::string getText() { return ""; }
 | 
			
		||||
	// Returns the string used for inventory
 | 
			
		||||
	virtual std::string getItemString();
 | 
			
		||||
	
 | 
			
		||||
	// Shall return false if item is not known and cannot be used
 | 
			
		||||
	virtual bool isKnown() const { return true; }
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
		Quantity methods
 | 
			
		||||
@@ -269,6 +272,8 @@ public:
 | 
			
		||||
		return os.str();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	virtual bool isKnown() const;
 | 
			
		||||
 | 
			
		||||
	virtual bool addableTo(const InventoryItem *other) const
 | 
			
		||||
	{
 | 
			
		||||
		if(std::string(other->getName()) != "CraftItem")
 | 
			
		||||
@@ -366,6 +371,8 @@ public:
 | 
			
		||||
	{
 | 
			
		||||
		return "";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	virtual bool isKnown() const;
 | 
			
		||||
 | 
			
		||||
	virtual bool isSubsetOf(const InventoryItem *other) const
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user