deSerializeLongString(is); // m_text
deSerializeString(is); // m_owner
- meta->setInfoText(deSerializeString(is));
- meta->setInventoryDrawSpec(deSerializeString(is));
+ meta->setString("infotext",deSerializeString(is));
+ meta->setString("formspec",deSerializeString(is));
readU8(is); // m_allow_text_input
- meta->setAllowRemoval(readU8(is) == 0);
+ readU8(is); // m_allow_removal
readU8(is); // m_enforce_owner
int num_vars = readU32(is);
else if(id == NODEMETA_SIGN) // SignNodeMetadata
{
meta->setString("text", deSerializeLongString(is));
- meta->setInfoText("\"${text}\"");
- meta->setFormSpec("field[text;;${text}]");
+ meta->setString("infotext","\"${text}\"");
+ meta->setString("formspec","field[text;;${text}]");
return false;
}
else if(id == NODEMETA_CHEST) // ChestNodeMetadata
{
meta->getInventory()->deSerialize(is);
- meta->setInventoryDrawSpec("invsize[8,9;]"
+ meta->setString("formspec","invsize[8,9;]"
"list[current_name;0;0,0;8,4;]"
"list[current_player;main;0,5;8,4;]");
return false;
{
meta->setString("owner", deSerializeString(is));
meta->getInventory()->deSerialize(is);
- meta->setInventoryDrawSpec("invsize[8,9;]"
+ meta->setString("formspec","invsize[8,9;]"
"list[current_name;0;0,0;8,4;]"
"list[current_player;main;0,5;8,4;]");
return false;
is>>temp;
meta->setString("src_time", ftos((float)temp/10));
- meta->setInventoryDrawSpec("invsize[8,9;]"
+ meta->setString("formspec","invsize[8,9;]"
"list[current_name;fuel;2,3;1,1;]"
"list[current_name;src;2,1;1,1;]"
"list[current_name;dst;5,1;2,2;]"
ClientMap &map = client.getEnv().getClientMap();
NodeMetadata *meta = map.getNodeMetadata(nodepos);
if(meta){
- infotext = narrow_to_wide(meta->getInfoText());
+ infotext = narrow_to_wide(meta->getString("infotext"));
} else {
MapNode n = map.getNode(nodepos);
if(nodedef->get(n).tname_tiles[0] == "unknown_block.png"){
{
infostream<<"Ground right-clicked"<<std::endl;
+ // sign special case, at least until formspec is properly implemented
+ if(meta && meta->getString("formspec") == "hack:sign_text_input" && !random_input)
+ {
+ infostream<<"Launching metadata text input"<<std::endl;
+
+ // Get a new text for it
+
+ TextDest *dest = new TextDestNodeMetadata(nodepos, &client);
+
+ std::wstring wtext = narrow_to_wide(meta->getString("text"));
+
+ (new GUITextInputMenu(guienv, guiroot, -1,
+ &g_menumgr, dest,
+ wtext))->drop();
+ }
// If metadata provides an inventory view, activate it
- errorstream<<"Need to implement metadata formspecs"<<std::endl;
- #if 0
- if(meta && meta->getInventoryDrawSpecString() != "" && !random_input)
+ else if(meta && meta->getString("formspec") != "" && !random_input)
{
infostream<<"Launching custom inventory view"<<std::endl;
v2s16 invsize =
GUIInventoryMenu::makeDrawSpecArrayFromString(
draw_spec,
- meta->getInventoryDrawSpecString(),
+ meta->getString("formspec"),
inventoryloc);
GUIInventoryMenu *menu =
menu->setDrawSpec(draw_spec);
menu->drop();
}
- // If metadata provides text input, activate text input
- else if(meta && meta->allowsTextInput() && !random_input)
- {
- infostream<<"Launching metadata text input"<<std::endl;
-
- // Get a new text for it
-
- TextDest *dest = new TextDestNodeMetadata(nodepos, &client);
-
- std::wstring wtext = narrow_to_wide(meta->getText());
-
- (new GUITextInputMenu(guienv, guiroot, -1,
- &g_menumgr, dest,
- wtext))->drop();
- }
- #else
- if(0) /* do nothing */;
- #endif
// Otherwise report right click to server
else
{
NodeMetadata::NodeMetadata(IGameDef *gamedef):
m_stringvars(),
- m_inventory(new Inventory(gamedef->idef())),
- m_inventorydrawspec(""),
- m_formspec(""),
- m_infotext(""),
- m_allow_removal(true)
+ m_inventory(new Inventory(gamedef->idef()))
{
}
}
m_inventory->serialize(os);
- os<<serializeString(m_inventorydrawspec);
- os<<serializeString(m_formspec);
- os<<serializeString(m_infotext);
- writeU8(os, m_allow_removal);
}
void NodeMetadata::deSerialize(std::istream &is)
}
m_inventory->deSerialize(is);
- m_inventorydrawspec = deSerializeString(is);
- m_formspec = deSerializeString(is);
- m_infotext = deSerializeString(is);
- m_allow_removal = readU8(is);
}
void NodeMetadata::clear()
{
m_stringvars.clear();
m_inventory->clear();
- m_inventorydrawspec = "";
- m_formspec = "";
- m_infotext = "";
- m_allow_removal = true;
}
/*
{
return m_inventory;
}
-
- // If non-empty, player can interact by using an inventory view
- // See format in guiInventoryMenu.cpp.
- std::string getInventoryDrawSpec() const
- {
- return m_inventorydrawspec;
- }
- void setInventoryDrawSpec(const std::string &text)
- {
- m_inventorydrawspec = text;
- }
-
- // If non-empty, player can interact by using an form view
- // See format in guiFormMenu.cpp.
- std::string getFormSpec() const
- {
- return m_formspec;
- }
- void setFormSpec(const std::string &text)
- {
- m_formspec = text;
- }
-
- // Called on client-side; shown on screen when pointed at
- std::string getInfoText() const
- {
- return m_infotext;
- }
- void setInfoText(const std::string &text)
- {
- m_infotext = text;
- }
-
- // Whether the related node and this metadata can be removed
- bool getAllowRemoval() const
- {
- return m_allow_removal;
- }
- void setAllowRemoval(bool b)
- {
- m_allow_removal = b;
- }
private:
std::map<std::string, std::string> m_stringvars;
Inventory *m_inventory;
- std::string m_inventorydrawspec;
- std::string m_formspec;
- std::string m_infotext;
- bool m_allow_removal;
};
lua_pushlstring(L, "", 0);
return 1;
}
- std::string str = meta->getInventoryDrawSpec();
+ std::string str = meta->getString("formspec");
lua_pushlstring(L, str.c_str(), str.size());
return 1;
}
std::string str(s, len);
NodeMetadata *meta = getmeta(ref, !str.empty());
- if(meta == NULL || str == meta->getInventoryDrawSpec())
+ if(meta == NULL || str == meta->getString("formspec"))
return 0;
- meta->setInventoryDrawSpec(str);
+ meta->setString("formspec",str);
reportMetadataChange(ref);
return 0;
}
lua_pushlstring(L, "", 0);
return 1;
}
- std::string str = meta->getFormSpec();
+ std::string str = meta->getString("formspec");
lua_pushlstring(L, str.c_str(), str.size());
return 1;
}
std::string str(s, len);
NodeMetadata *meta = getmeta(ref, !str.empty());
- if(meta == NULL || str == meta->getFormSpec())
+ if(meta == NULL || str == meta->getString("formspec"))
return 0;
- meta->setFormSpec(str);
+ meta->setString("formspec",str);
reportMetadataChange(ref);
return 0;
}
lua_pushlstring(L, "", 0);
return 1;
}
- std::string str = meta->getInfoText();
+ std::string str = meta->getString("infotext");
lua_pushlstring(L, str.c_str(), str.size());
return 1;
}
std::string str(s, len);
NodeMetadata *meta = getmeta(ref, !str.empty());
- if(meta == NULL || str == meta->getInfoText())
+ if(meta == NULL || str == meta->getString("infotext"))
return 0;
- meta->setInfoText(str);
- reportMetadataChange(ref);
- return 0;
- }
-
- // get_allow_removal(self)
- static int l_get_allow_removal(lua_State *L)
- {
- NodeMetaRef *ref = checkobject(L, 1);
-
- NodeMetadata *meta = getmeta(ref, false);
- if(meta == NULL){
- lua_pushboolean(L, true);
- return 1;
- }
- lua_pushboolean(L, meta->getAllowRemoval());
- return 1;
- }
-
- // set_allow_removal(self, flag)
- static int l_set_allow_removal(lua_State *L)
- {
- NodeMetaRef *ref = checkobject(L, 1);
- bool flag = lua_toboolean(L, 2);
-
- NodeMetadata *meta = getmeta(ref, flag != true);
- if(meta == NULL || flag == meta->getAllowRemoval())
- return 0;
- meta->setAllowRemoval(flag);
+ meta->setString("infotext",str);
reportMetadataChange(ref);
return 0;
}
method(NodeMetaRef, set_form_spec),
method(NodeMetaRef, get_infotext),
method(NodeMetaRef, set_infotext),
- method(NodeMetaRef, get_allow_removal),
- method(NodeMetaRef, set_allow_removal),
{0,0}
};