From a09d86dd3cc3fd31404e6403cfc5d9c7020f944f Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 3 Jun 2012 18:30:34 +0300 Subject: Update inventory menu from formspec on-the-fly --- src/game.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 768bb5602..69b3c321a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -132,6 +132,28 @@ private: Client *m_client; }; +/* Form update callback */ + +class NodeMetadataFormSource: public IFormSource +{ +public: + NodeMetadataFormSource(ClientMap *map, v3s16 p): + m_map(map), + m_p(p) + { + } + std::string getForm() + { + NodeMetadata *meta = m_map->getNodeMetadata(m_p); + if(!meta) + return ""; + return meta->getString("formspec"); + } + + ClientMap *m_map; + v3s16 m_p; +}; + /* Hotbar draw routine */ @@ -2348,6 +2370,8 @@ void the_game( &client, gamedef); menu->setFormSpec(meta->getString("formspec"), inventoryloc); + menu->setFormSource(new NodeMetadataFormSource( + &client.getEnv().getClientMap(), nodepos)); menu->drop(); } // Otherwise report right click to server -- cgit v1.2.3