From 506203345ba2795aa0af68a434f4b77cf50e664a Mon Sep 17 00:00:00 2001 From: darkrose Date: Mon, 16 Jul 2012 02:19:38 +1000 Subject: Implement formspec --- src/game.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 347dbf44b..3ba90789a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include "guiPauseMenu.h" #include "guiPasswordChange.h" -#include "guiInventoryMenu.h" +#include "guiFormSpecMenu.h" #include "guiTextInputMenu.h" #include "guiDeathScreen.h" #include "tool.h" @@ -77,6 +77,10 @@ struct TextDestChat : public TextDest { m_client->typeChatMessage(text); } + void gotText(std::map fields) + { + m_client->typeChatMessage(narrow_to_wide(fields["text"])); + } Client *m_client; }; @@ -88,15 +92,20 @@ struct TextDestNodeMetadata : public TextDest m_p = p; m_client = client; } + // This is deprecated I guess? -celeron55 void gotText(std::wstring text) { std::string ntext = wide_to_narrow(text); - infostream<<"Changing text of a sign node: " - < fields; fields["text"] = ntext; m_client->sendNodemetaFields(m_p, "", fields); } + void gotText(std::map fields) + { + m_client->sendNodemetaFields(m_p, "", fields); + } v3s16 m_p; Client *m_client; @@ -139,6 +148,13 @@ public: return ""; return meta->getString("formspec"); } + std::string resolveText(std::string str) + { + NodeMetadata *meta = m_map->getNodeMetadata(m_p); + if(!meta) + return str; + return meta->resolveString(str); + } ClientMap *m_map; v3s16 m_p; @@ -1479,8 +1495,8 @@ void the_game( infostream<<"the_game: " <<"Launching inventory"<setFormSpec(src->getForm(), inventoryloc); - menu->setFormSource(new PlayerInventoryFormSource(&client)); + menu->setFormSource(src); menu->drop(); } else if(input->wasKeyDown(EscapeKey)) @@ -2219,7 +2235,8 @@ void the_game( { infostream<<"Ground right-clicked"<getString("formspec") == "hack:sign_text_input" && !random_input) { infostream<<"Launching metadata text input"<setFormSpec(meta->getString("formspec"), inventoryloc); menu->setFormSource(new NodeMetadataFormSource( &client.getEnv().getClientMap(), nodepos)); + menu->setTextDest(new TextDestNodeMetadata(nodepos, &client)); menu->drop(); } // Otherwise report right click to server -- cgit v1.2.3