Generic NodeMetadata text input

This commit is contained in:
Perttu Ahola 2011-11-13 12:48:05 +02:00
parent 79c9f14aec
commit 64fa59e24f
3 changed files with 20 additions and 28 deletions

@ -36,8 +36,9 @@ public:
virtual void serializeBody(std::ostream &os); virtual void serializeBody(std::ostream &os);
virtual std::string infoText(); virtual std::string infoText();
std::string getText(){ return m_text; } virtual bool allowsTextInput(){ return true; }
void setText(std::string t){ m_text = t; } virtual std::string getText(){ return m_text; }
virtual void setText(const std::string &t){ m_text = t; }
private: private:
std::string m_text; std::string m_text;

@ -43,12 +43,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gettext.h" #include "gettext.h"
#include "log.h" #include "log.h"
#include "filesys.h" #include "filesys.h"
// Needed for writing to signs (CONTENT_SIGN_WALL)
// TODO: A generic way for handling such should be created
#include "content_mapnode.h"
// Needed for sign text input
// TODO: A generic way for handling such should be created
#include "content_nodemeta.h"
// Needed for determining pointing to nodes // Needed for determining pointing to nodes
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
@ -115,9 +109,9 @@ struct TextDestChat : public TextDest
Client *m_client; Client *m_client;
}; };
struct TextDestSignNode : public TextDest struct TextDestNodeMetadata : public TextDest
{ {
TextDestSignNode(v3s16 p, Client *client) TextDestNodeMetadata(v3s16 p, Client *client)
{ {
m_p = p; m_p = p;
m_client = client; m_client = client;
@ -1784,23 +1778,22 @@ void the_game(
menu->setDrawSpec(draw_spec); menu->setDrawSpec(draw_spec);
menu->drop(); menu->drop();
} }
else if(meta && meta->typeId() == CONTENT_SIGN_WALL && !random_input) // If metadata provides text input, activate text input
else if(meta && meta->allowsTextInput() && !random_input)
{ {
infostream<<"Sign node right-clicked"<<std::endl; infostream<<"Launching metadata text input"<<std::endl;
SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
// Get a new text for it // Get a new text for it
TextDest *dest = new TextDestSignNode(nodepos, &client); TextDest *dest = new TextDestNodeMetadata(nodepos, &client);
std::wstring wtext = std::wstring wtext = narrow_to_wide(meta->getText());
narrow_to_wide(signmeta->getText());
(new GUITextInputMenu(guienv, guiroot, -1, (new GUITextInputMenu(guienv, guiroot, -1,
&g_menumgr, dest, &g_menumgr, dest,
wtext))->drop(); wtext))->drop();
} }
// Otherwise report right click to server
else else
{ {
client.groundAction(1, nodepos, neighbourpos, g_selected_item); client.groundAction(1, nodepos, neighbourpos, g_selected_item);

@ -25,16 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream> #include <iostream>
/* /*
Used for storing: NodeMetadata stores arbitary amounts of data for special blocks.
Used for furnaces, chests and signs.
Oven: There are two interaction methods: inventory menu and text input.
- Item that is being burned Only one can be used for a single metadata, thus only inventory OR
- Burning time text input should exist in a metadata.
- Item stack that is being heated
- Result item stack
Sign:
- Text
*/ */
class Inventory; class Inventory;
@ -67,8 +63,10 @@ public:
virtual std::string getInventoryDrawSpecString(){return "";} virtual std::string getInventoryDrawSpecString(){return "";}
// primarily used for locking chests, but others can play too // primarily used for locking chests, but others can play too
virtual std::string getOwner(){ return std::string(""); } virtual std::string getOwner(){ return std::string(""); }
virtual void setOwner(std::string t){ } virtual void setOwner(std::string t){}
virtual bool allowsTextInput(){ return false; }
virtual std::string getText(){ return ""; }
virtual void setText(const std::string &t){}
protected: protected:
static void registerType(u16 id, Factory f); static void registerType(u16 id, Factory f);
private: private: