set(minetest_SRCS
${common_SRCS}
clientobject.cpp
+ guiFurnaceMenu.cpp
guiMainMenu.cpp
guiMessageMenu.cpp
guiTextInputMenu.cpp
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr,
v2s16 menu_size,
- core::array<DrawSpec> &init_draw_spec,
InventoryContext *c,
InventoryManager *invmgr
):
GUIModalMenu(env, parent, id, menumgr),
m_menu_size(menu_size),
m_c(c),
- m_invmgr(invmgr),
- m_init_draw_spec(init_draw_spec)
+ m_invmgr(invmgr)
{
m_selected_item = NULL;
}
void GUIInventoryMenu::removeChildren()
{
- /*const core::list<gui::IGUIElement*> &children = getChildren();
+ const core::list<gui::IGUIElement*> &children = getChildren();
core::list<gui::IGUIElement*> children_copy;
for(core::list<gui::IGUIElement*>::ConstIterator
i = children.begin(); i != children.end(); i++)
i != children_copy.end(); i++)
{
(*i)->remove();
- }*/
- {
+ }
+ /*{
gui::IGUIElement *e = getElementFromId(256);
if(e != NULL)
e->remove();
- }
+ }*/
}
void GUIInventoryMenu::regenerateGui(v2u32 screensize)
inv_from->getList(m_selected_item->listname);
InventoryList *list_to =
inv_to->getList(s.listname);
+ if(list_from == NULL)
+ dstream<<"from list doesn't exist"<<std::endl;
+ if(list_to == NULL)
+ dstream<<"to list doesn't exist"<<std::endl;
// Indicates whether source slot completely empties
bool source_empties = false;
if(list_from && list_to
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr,
v2s16 menu_size,
- core::array<DrawSpec> &init_draw_spec,
InventoryContext *c,
InventoryManager *invmgr
);
~GUIInventoryMenu();
+ void setDrawSpec(core::array<DrawSpec> &init_draw_spec)
+ {
+ m_init_draw_spec = init_draw_spec;
+ }
+
void removeChildren();
/*
Remove and re-add (or reposition) stuff
bool OnEvent(const SEvent& event);
-private:
+protected:
v2s32 getBasePos() const
{
return padding + AbsoluteRect.UpperLeftCorner;
\r
TODO: Remove IrrlichtWrapper\r
\r
+SUGG: Add a "description" field to InventoryList and show it in\r
+ GUIInventoryMenu\r
+ - If separate menus are made for everything, this is not needed\r
+\r
Server:\r
-------\r
\r
#include "mineral.h"\r
#include "noise.h"\r
#include "tile.h"\r
+#include "guiFurnaceMenu.h"\r
\r
// TODO: Remove this\r
IrrlichtWrapper *g_irrlicht = NULL;\r
dstream<<DTIME<<"MyEventReceiver: "\r
<<"Launching inventory"<<std::endl;\r
\r
+ GUIInventoryMenu *menu =\r
+ new GUIInventoryMenu(guienv, guiroot, -1,\r
+ &g_menumgr, v2s16(8,7),\r
+ g_client->getInventoryContext(),\r
+ g_client);\r
+\r
core::array<GUIInventoryMenu::DrawSpec> draw_spec;\r
draw_spec.push_back(GUIInventoryMenu::DrawSpec(\r
"list", "current_player", "main",\r
"list", "current_player", "craftresult",\r
v2s32(7, 1), v2s32(1, 1)));\r
\r
- GUIInventoryMenu *menu =\r
- new GUIInventoryMenu(guienv, guiroot, -1,\r
- &g_menumgr, v2s16(8,7), draw_spec,\r
- g_client->getInventoryContext(),\r
- g_client);\r
+ menu->setDrawSpec(draw_spec);\r
\r
menu->drop();\r
\r
\r
//ChestNodeMetadata *chestmeta = (ChestNodeMetadata*)meta;\r
\r
- core::array<GUIInventoryMenu::DrawSpec> draw_spec;\r
- \r
std::string chest_inv_id;\r
chest_inv_id += "nodemeta:";\r
chest_inv_id += itos(nodepos.X);\r
chest_inv_id += ",";\r
chest_inv_id += itos(nodepos.Z);\r
\r
+ GUIInventoryMenu *menu =\r
+ new GUIInventoryMenu(guienv, guiroot, -1,\r
+ &g_menumgr, v2s16(8,9),\r
+ g_client->getInventoryContext(),\r
+ g_client);\r
+\r
+ core::array<GUIInventoryMenu::DrawSpec> draw_spec;\r
+ \r
draw_spec.push_back(GUIInventoryMenu::DrawSpec(\r
"list", chest_inv_id, "0",\r
v2s32(0, 0), v2s32(8, 4)));\r
"list", "current_player", "main",\r
v2s32(0, 5), v2s32(8, 4)));\r
\r
- GUIInventoryMenu *menu =\r
- new GUIInventoryMenu(guienv, guiroot, -1,\r
- &g_menumgr, v2s16(8,9), draw_spec,\r
- g_client->getInventoryContext(),\r
- g_client);\r
+ menu->setDrawSpec(draw_spec);\r
+\r
+ menu->drop();\r
+\r
+ }\r
+ else if(meta && meta->typeId() == CONTENT_FURNACE && !random_input)\r
+ {\r
+ dstream<<"Furnace node right-clicked"<<std::endl;\r
+ \r
+ GUIFurnaceMenu *menu =\r
+ new GUIFurnaceMenu(guienv, guiroot, -1,\r
+ &g_menumgr, nodepos, g_client);\r
\r
menu->drop();\r
\r
{
DSTACK(__FUNCTION_NAME);
+ // Block file is map/sectors/xxxxxxxx/xxxx
+ std::string fullpath = m_savedir+"/sectors/"+sectordir+"/"+blockfile;
try{
- // Block file is map/sectors/xxxxxxxx/xxxx
- std::string fullpath = m_savedir+"/sectors/"+sectordir+"/"+blockfile;
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
if(is.good() == false)
throw FileNotGoodException("Cannot open block file");
-
+
v3s16 p3d = getBlockPos(sectordir, blockfile);
v2s16 p2d(p3d.X, p3d.Z);
"(SerializationError). Ignoring. "
"A new one will be generated."
<<std::endl;
+
+ // TODO: Backup file; name is in fullpath.
}
}
*/
if(version >= 14)
{
- m_node_metadata.serialize(os);
+ std::ostringstream oss(std::ios_base::binary);
+ m_node_metadata.serialize(oss);
+ os<<serializeString(oss.str());
}
}
}
*/
if(version >= 14)
{
- m_node_metadata.deSerialize(is);
+ // Ignore errors
+ try{
+ std::string data = deSerializeString(is);
+ std::istringstream iss(data, std::ios_base::binary);
+ m_node_metadata.deSerialize(iss);
+ }
+ catch(SerializationError &e)
+ {
+ dstream<<"WARNING: MapBlock::deSerialize(): Ignoring an error"
+ <<" while deserializing node metadata"<<std::endl;
+ }
}
}
f->setTexture(5, "furnace_front.png"); // Z-
f->setInventoryTexture("furnace_front.png");
f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
+ if(f->initial_metadata == NULL)
+ f->initial_metadata = new FurnaceNodeMetadata();
}
#define CONTENT_SIGN_WALL 14
#define CONTENT_CHEST 15
#define CONTENT_FURNACE 16
+//#define CONTENT_WORKBENCH 17
/*
Content feature list
IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
core::rect<s32>(0,0,100,100))
{
+ //m_force_regenerate_gui = false;
+
m_menumgr = menumgr;
m_allow_focus_removal = false;
m_screensize_old = v2u32(0,0);
video::IVideoDriver* driver = Environment->getVideoDriver();
v2u32 screensize = driver->getScreenSize();
- if(screensize != m_screensize_old)
+ if(screensize != m_screensize_old /*|| m_force_regenerate_gui*/)
{
m_screensize_old = screensize;
regenerateGui(screensize);
+ //m_force_regenerate_gui = false;
}
drawMenu();
virtual void regenerateGui(v2u32 screensize) = 0;
virtual void drawMenu() = 0;
virtual bool OnEvent(const SEvent& event) { return false; };
-
+
+protected:
+ //bool m_force_regenerate_gui;
private:
IMenuManager *m_menumgr;
// This might be necessary to expose to the implementation if it
#include "mapnode.h"
#include "exceptions.h"
#include "inventory.h"
+#include <sstream>
/*
NodeMetadata
NodeMetadata* NodeMetadata::deSerialize(std::istream &is)
{
+ // Read id
u8 buf[2];
is.read((char*)buf, 2);
s16 id = readS16(buf);
-
+
+ // Read data
+ std::string data = deSerializeString(is);
+
+ // Find factory function
core::map<u16, Factory>::Node *n;
n = m_types.find(id);
if(n == NULL)
{
- dstream<<"NodeMetadata(): No factory for typeId="<<id<<std::endl;
- throw SerializationError("Unknown metadata id");
+ // If factory is not found, just return.
+ dstream<<"WARNING: NodeMetadata: No factory for typeId="
+ <<id<<std::endl;
+ return NULL;
}
- Factory f = n->getValue();
- NodeMetadata *meta = (*f)(is);
- return meta;
+ // Try to load the metadata. If it fails, just return.
+ try
+ {
+ std::istringstream iss(data, std::ios_base::binary);
+
+ Factory f = n->getValue();
+ NodeMetadata *meta = (*f)(iss);
+ return meta;
+ }
+ catch(SerializationError &e)
+ {
+ dstream<<"WARNING: NodeMetadata: ignoring SerializationError"<<std::endl;
+ return NULL;
+ }
}
void NodeMetadata::serialize(std::ostream &os)
u8 buf[2];
writeU16(buf, typeId());
os.write((char*)buf, 2);
-
- serializeBody(os);
+
+ std::ostringstream oss(std::ios_base::binary);
+ serializeBody(oss);
+ os<<serializeString(oss.str());
}
void NodeMetadata::registerType(u16 id, Factory f)
{
return "Chest";
}
-/*Inventory* ChestNodeMetadata::getInventory()
+
+/*
+ FurnaceNodeMetadata
+*/
+
+FurnaceNodeMetadata::FurnaceNodeMetadata()
{
- return m_inventory;
-}*/
+ NodeMetadata::registerType(typeId(), create);
+
+ m_inventory = new Inventory();
+ m_inventory->addList("fuel", 1);
+ m_inventory->addList("src", 1);
+ m_inventory->addList("dst", 1);
+}
+FurnaceNodeMetadata::~FurnaceNodeMetadata()
+{
+ delete m_inventory;
+}
+u16 FurnaceNodeMetadata::typeId() const
+{
+ return CONTENT_FURNACE;
+}
+NodeMetadata* FurnaceNodeMetadata::clone()
+{
+ FurnaceNodeMetadata *d = new FurnaceNodeMetadata();
+ *d->m_inventory = *m_inventory;
+ return d;
+}
+NodeMetadata* FurnaceNodeMetadata::create(std::istream &is)
+{
+ FurnaceNodeMetadata *d = new FurnaceNodeMetadata();
+ d->m_inventory->deSerialize(is);
+ /*std::string params;
+ std::getline(is, params, '\n');*/
+ return d;
+}
+void FurnaceNodeMetadata::serializeBody(std::ostream &os)
+{
+ m_inventory->serialize(os);
+ // This line will contain the other parameters
+ //os<<"\n";
+}
+std::string FurnaceNodeMetadata::infoText()
+{
+ return "Furnace";
+}
+void FurnaceNodeMetadata::inventoryModified()
+{
+ dstream<<"Furnace inventory modification callback"<<std::endl;
+}
/*
NodeMetadatalist
p16 -= p.Y * MAP_BLOCKSIZE;
p.X += p16;
+ NodeMetadata *data = NodeMetadata::deSerialize(is);
+
+ if(data == NULL)
+ continue;
+
if(m_data.find(p))
{
- dstream<<"ERROR: NodeMetadataList::deSerialize(): "
+ dstream<<"WARNING: NodeMetadataList::deSerialize(): "
<<"already set data at position"
- <<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
+ <<"("<<p.X<<","<<p.Y<<","<<p.Z<<"): Ignoring."
<<std::endl;
- throw SerializationError("NodeMetadataList::deSerialize()");
+ delete data;
+ continue;
}
- NodeMetadata *data = NodeMetadata::deSerialize(is);
-
m_data.insert(p, data);
}
}
virtual void serializeBody(std::ostream &os) = 0;
virtual std::string infoText() {return "<todo: remove this text>";}
virtual Inventory* getInventory() {return NULL;}
+ // This is called always after the inventory is modified, before
+ // the changes are copied elsewhere
+ virtual void inventoryModified(){}
protected:
static void registerType(u16 id, Factory f);
Inventory *m_inventory;
};
+class FurnaceNodeMetadata : public NodeMetadata
+{
+public:
+ FurnaceNodeMetadata();
+ ~FurnaceNodeMetadata();
+
+ virtual u16 typeId() const;
+ virtual NodeMetadata* clone();
+ static NodeMetadata* create(std::istream &is);
+ virtual void serializeBody(std::ostream &os);
+ virtual std::string infoText();
+ virtual Inventory* getInventory() {return m_inventory;}
+ virtual void inventoryModified();
+
+private:
+ Inventory *m_inventory;
+};
+
+/*
+ List of metadata of all the nodes of a block
+*/
+
class NodeMetadataList
{
public:
assert(c->current_player);
v3s16 blockpos = getNodeBlockPos(p);
- /*RemoteClient *client = getClient(c->current_player->peer_id);
- client->SetBlockNotSent(blockpos);*/
+ NodeMetadata *meta = m_env.getMap().getNodeMetadata(p);
+ if(meta)
+ meta->inventoryModified();
for(core::map<u16, RemoteClient*>::Iterator
i = m_clients.getIterator();