forked from oerkki/voxelands
book nodemetadata pt1
This commit is contained in:
parent
62a539b96f
commit
22fad3f5bb
|
@ -4147,6 +4147,8 @@ void content_mapnode_init()
|
|||
crafting::setCol1Recipe(CONTENT_CRAFTITEM_PAPER,i);
|
||||
lists::add("craftguide",i);
|
||||
lists::add("creative",i);
|
||||
if (f->initial_metadata == NULL)
|
||||
f->initial_metadata = new ClosedBookNodeMetadata();
|
||||
|
||||
i = CONTENT_COOK_BOOK;
|
||||
f = &content_features(i);
|
||||
|
@ -4262,6 +4264,8 @@ void content_mapnode_init()
|
|||
};
|
||||
crafting::setRecipe(r,CONTENT_CRAFT_BOOK,1);
|
||||
}
|
||||
if (f->initial_metadata == NULL)
|
||||
f->initial_metadata = new ClosedBookNodeMetadata();
|
||||
lists::add("craftguide",i);
|
||||
lists::add("creative",i);
|
||||
|
||||
|
@ -4287,6 +4291,8 @@ void content_mapnode_init()
|
|||
f->setInventoryTextureNodeBox(i, "guide_top.png", "guide_end.png", "guide_side.png");
|
||||
f->type = CMT_DIRT;
|
||||
f->hardness = 1.0;
|
||||
if (f->initial_metadata == NULL)
|
||||
f->initial_metadata = new BookNodeMetadata();
|
||||
|
||||
i = CONTENT_COOK_BOOK_OPEN;
|
||||
f = &content_features(i);
|
||||
|
|
|
@ -1048,12 +1048,17 @@ NodeMetadata* CraftGuideNodeMetadata::clone()
|
|||
{
|
||||
CraftGuideNodeMetadata *d = new CraftGuideNodeMetadata();
|
||||
*d->m_inventory = *m_inventory;
|
||||
d->m_page = m_page;
|
||||
InventoryList *l = d->m_inventory->getList("list");
|
||||
InventoryItem *t;
|
||||
content_t *r;
|
||||
l->clearItems();
|
||||
std::vector<content_t> &list = lists::get("craftguide");
|
||||
for (u16 i=0; i<list.size() && i < 40; i++) {
|
||||
u16 start = m_page*40;
|
||||
u16 end = start+40;
|
||||
if (end > list.size())
|
||||
end = list.size();
|
||||
for (int i=start; i<end; i++) {
|
||||
if ((list[i]&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
|
||||
t = new CraftItem(list[i],1);
|
||||
}else if ((list[i]&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
|
||||
|
@ -1120,6 +1125,41 @@ bool CraftGuideNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env
|
|||
|
||||
return true;
|
||||
}
|
||||
bool CraftGuideNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() == CONTENT_BOOK)
|
||||
m_page = ((ClosedBookNodeMetadata*)meta)->getPage();
|
||||
|
||||
if (m_page < 0)
|
||||
m_page = 0;
|
||||
std::vector<content_t> &list = lists::get("craftguide");
|
||||
if (m_page > (list.size()/40))
|
||||
m_page = list.size()/40;
|
||||
InventoryList *l = m_inventory->getList("list");
|
||||
InventoryItem *t;
|
||||
content_t *r;
|
||||
l->clearItems();
|
||||
u16 start = m_page*40;
|
||||
u16 end = start+40;
|
||||
if (end > list.size())
|
||||
end = list.size();
|
||||
for (int i=start; i<end; i++) {
|
||||
if ((list[i]&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
|
||||
t = new CraftItem(list[i],1);
|
||||
}else if ((list[i]&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
|
||||
t = new ToolItem(list[i],1);
|
||||
}else{
|
||||
t = new MaterialItem(list[i],1);
|
||||
}
|
||||
r = crafting::getRecipe(t);
|
||||
if (!r) {
|
||||
delete t;
|
||||
continue;
|
||||
}
|
||||
l->addItem(t);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool CraftGuideNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||
{
|
||||
if (fields["prev"] == "" && fields["next"] == "")
|
||||
|
@ -1189,3 +1229,149 @@ std::string CraftGuideNodeMetadata::getDrawSpecString()
|
|||
spec += "list[current_name;list;0,4;8,5;]";
|
||||
return spec;
|
||||
}
|
||||
|
||||
/*
|
||||
BookNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
BookNodeMetadata proto_BookNodeMetadata;
|
||||
|
||||
BookNodeMetadata::BookNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_title = "Book";
|
||||
m_content = "";
|
||||
}
|
||||
|
||||
u16 BookNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_BOOK_OPEN;
|
||||
}
|
||||
NodeMetadata* BookNodeMetadata::clone()
|
||||
{
|
||||
BookNodeMetadata *d = new BookNodeMetadata();
|
||||
d->m_title = m_title;
|
||||
d->m_content = m_content;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* BookNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
BookNodeMetadata *d = new BookNodeMetadata();
|
||||
d->m_title = deSerializeString(is);
|
||||
d->m_content = deSerializeString(is);
|
||||
return d;
|
||||
}
|
||||
void BookNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_title);
|
||||
os<<serializeString(m_content);
|
||||
}
|
||||
bool BookNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
if (m_content != "")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool BookNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
if (meta->typeId() != CONTENT_BOOK)
|
||||
return false;
|
||||
|
||||
ClosedBookNodeMetadata *m = (ClosedBookNodeMetadata*)meta;
|
||||
m_title = m->infoText();
|
||||
m_content = m->getContent();
|
||||
return true;
|
||||
}
|
||||
bool BookNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||
{
|
||||
m_title = fields["title"];
|
||||
m_content = fields["content"];
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string BookNodeMetadata::getDrawSpecString()
|
||||
{
|
||||
std::string spec("size[4,6]");
|
||||
spec += "field[1,1;3,1;title;Title;";
|
||||
spec += m_title;
|
||||
spec += "]";
|
||||
spec += "field[1,2;3,2;content;Content;";
|
||||
spec += m_content;
|
||||
spec += "]";
|
||||
spec += "button_exit[1,5;3,1;submit;Save]";
|
||||
return spec;
|
||||
}
|
||||
|
||||
/*
|
||||
ClosedBookNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
ClosedBookNodeMetadata proto_ClosedBookNodeMetadata;
|
||||
|
||||
ClosedBookNodeMetadata::ClosedBookNodeMetadata()
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
|
||||
m_page = 0;
|
||||
m_owner = "";
|
||||
m_title = "";
|
||||
m_content = "";
|
||||
}
|
||||
u16 ClosedBookNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_BOOK;
|
||||
}
|
||||
NodeMetadata* ClosedBookNodeMetadata::clone()
|
||||
{
|
||||
ClosedBookNodeMetadata *d = new ClosedBookNodeMetadata();
|
||||
d->m_page = m_page;
|
||||
d->m_owner = m_owner;
|
||||
d->m_title = m_title;
|
||||
d->m_content = m_content;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* ClosedBookNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
ClosedBookNodeMetadata *d = new ClosedBookNodeMetadata();
|
||||
|
||||
d->m_owner = deSerializeString(is);
|
||||
d->m_title = deSerializeString(is);
|
||||
d->m_content = deSerializeString(is);
|
||||
is>>d->m_page;
|
||||
|
||||
return d;
|
||||
}
|
||||
void ClosedBookNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<serializeString(m_owner);
|
||||
os<<serializeString(m_title);
|
||||
os<<serializeString(m_content);
|
||||
os<<itos(m_page) << " ";
|
||||
}
|
||||
bool ClosedBookNodeMetadata::nodeRemovalDisabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool ClosedBookNodeMetadata::import(NodeMetadata *meta)
|
||||
{
|
||||
switch (meta->typeId()) {
|
||||
case CONTENT_CRAFT_BOOK_OPEN:
|
||||
{
|
||||
CraftGuideNodeMetadata *cm = (CraftGuideNodeMetadata*)meta;
|
||||
m_page = cm->getPage();
|
||||
m_title = cm->infoText();
|
||||
break;
|
||||
}
|
||||
case CONTENT_BOOK_OPEN:
|
||||
{
|
||||
BookNodeMetadata *bm = (BookNodeMetadata*)meta;
|
||||
m_title = bm->infoText();
|
||||
m_content = bm->getContent();
|
||||
}
|
||||
default:;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -306,17 +306,67 @@ public:
|
|||
NodeMetadata* clone();
|
||||
static NodeMetadata* create(std::istream &is);
|
||||
virtual void serializeBody(std::ostream &os);
|
||||
virtual std::string infoText() {return std::string("Craft Guide");}
|
||||
virtual Inventory* getInventory() {return m_inventory;}
|
||||
virtual bool nodeRemovalDisabled();
|
||||
virtual void inventoryModified();
|
||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||
virtual bool import(NodeMetadata *meta);
|
||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||
virtual std::string getDrawSpecString();
|
||||
|
||||
u16 getPage() {return m_page;}
|
||||
|
||||
private:
|
||||
Inventory *m_inventory;
|
||||
u16 m_page;
|
||||
};
|
||||
|
||||
class BookNodeMetadata : public NodeMetadata
|
||||
{
|
||||
public:
|
||||
BookNodeMetadata();
|
||||
|
||||
virtual u16 typeId() const;
|
||||
NodeMetadata* clone();
|
||||
static NodeMetadata* create(std::istream &is);
|
||||
virtual void serializeBody(std::ostream &os);
|
||||
virtual std::string infoText() {return m_title;}
|
||||
virtual bool nodeRemovalDisabled();
|
||||
virtual bool import(NodeMetadata *meta);
|
||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||
virtual std::string getDrawSpecString();
|
||||
|
||||
std::string getContent() { return m_content; }
|
||||
|
||||
private:
|
||||
std::string m_title;
|
||||
std::string m_content;
|
||||
};
|
||||
|
||||
class ClosedBookNodeMetadata : public NodeMetadata
|
||||
{
|
||||
public:
|
||||
ClosedBookNodeMetadata();
|
||||
|
||||
virtual u16 typeId() const;
|
||||
NodeMetadata* clone();
|
||||
static NodeMetadata* create(std::istream &is);
|
||||
virtual void serializeBody(std::ostream &os);
|
||||
virtual std::string infoText() {return m_title;}
|
||||
virtual bool nodeRemovalDisabled();
|
||||
virtual bool import(NodeMetadata *meta);
|
||||
|
||||
virtual std::string getOwner(){ return m_owner; }
|
||||
std::string getContent() { return m_content; }
|
||||
u16 getPage() {return m_page;}
|
||||
|
||||
private:
|
||||
std::string m_owner;
|
||||
std::string m_title;
|
||||
std::string m_content;
|
||||
u16 m_page;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -248,6 +248,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
{
|
||||
std::string fname = f.next(";");
|
||||
std::string flabel = f.next(";");
|
||||
bool multi = false;
|
||||
|
||||
if(fname.find(",") == std::string::npos && flabel.find(",") == std::string::npos)
|
||||
{
|
||||
|
@ -280,9 +281,15 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
pos.Y = stof(fname.substr(fname.find(",")+1)) * (float)spacing.Y;
|
||||
v2s32 geom;
|
||||
geom.X = (stof(flabel.substr(0,flabel.find(","))) * (float)spacing.X)-(spacing.X-imgsize.X);
|
||||
pos.Y += (stof(flabel.substr(flabel.find(",")+1)) * (float)imgsize.Y)/2;
|
||||
if (stof(flabel.substr(flabel.find(",")+1)) > 1.0) {
|
||||
geom.Y = (stof(flabel.substr(flabel.find(",")+1)) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
|
||||
multi = true;
|
||||
}else{
|
||||
geom.Y = 30;
|
||||
}
|
||||
pos.Y += ((stof(flabel.substr(flabel.find(",")+1)) * (float)imgsize.Y)/2)-15;
|
||||
|
||||
rect = core::rect<s32>(pos.X, pos.Y-15, pos.X+geom.X, pos.Y+15);
|
||||
rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
||||
|
||||
fname = f.next(";");
|
||||
flabel = f.next(";");
|
||||
|
@ -312,14 +319,18 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
if (flabel == "")
|
||||
{
|
||||
spec.send = true;
|
||||
gui::IGUIElement *e = Environment->addEditBox(spec.fdefault.c_str(), rect, false, this, spec.fid);
|
||||
Environment->setFocus(e);
|
||||
|
||||
irr::SEvent evt;
|
||||
evt.EventType = EET_KEY_INPUT_EVENT;
|
||||
evt.KeyInput.Key = KEY_END;
|
||||
evt.KeyInput.PressedDown = true;
|
||||
e->OnEvent(evt);
|
||||
gui::IGUIEditBox *e = Environment->addEditBox(spec.fdefault.c_str(), rect, false, this, spec.fid);
|
||||
if (multi) {
|
||||
e->setMultiLine(true);
|
||||
e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
|
||||
}else{
|
||||
irr::SEvent evt;
|
||||
evt.EventType = EET_KEY_INPUT_EVENT;
|
||||
evt.KeyInput.Key = KEY_END;
|
||||
evt.KeyInput.PressedDown = true;
|
||||
e->OnEvent(evt);
|
||||
Environment->setFocus(e);
|
||||
}
|
||||
}
|
||||
else if (fname == "")
|
||||
{
|
||||
|
@ -329,17 +340,21 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||
else
|
||||
{
|
||||
spec.send = true;
|
||||
gui::IGUIElement *e = Environment->addEditBox(spec.fdefault.c_str(), rect, false, this, spec.fid);
|
||||
Environment->setFocus(e);
|
||||
gui::IGUIEditBox *e = Environment->addEditBox(spec.fdefault.c_str(), rect, false, this, spec.fid);
|
||||
if (multi) {
|
||||
e->setMultiLine(true);
|
||||
e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
|
||||
}else{
|
||||
irr::SEvent evt;
|
||||
evt.EventType = EET_KEY_INPUT_EVENT;
|
||||
evt.KeyInput.Key = KEY_END;
|
||||
evt.KeyInput.PressedDown = true;
|
||||
e->OnEvent(evt);
|
||||
Environment->setFocus(e);
|
||||
}
|
||||
rect.UpperLeftCorner.Y -= 15;
|
||||
rect.LowerRightCorner.Y -= 15;
|
||||
Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0);
|
||||
|
||||
irr::SEvent evt;
|
||||
evt.EventType = EET_KEY_INPUT_EVENT;
|
||||
evt.KeyInput.Key = KEY_END;
|
||||
evt.KeyInput.PressedDown = true;
|
||||
e->OnEvent(evt);
|
||||
}
|
||||
|
||||
m_fields.push_back(spec);
|
||||
|
|
|
@ -79,6 +79,8 @@ public:
|
|||
virtual void setInventoryOwner(std::string t){ }
|
||||
// receive data from the client. Returns true if metadata changed.
|
||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player) {return false;}
|
||||
// import data from another nodemetadata. Returns true if metadata changed.
|
||||
virtual bool import(NodeMetadata *meta) {return false;}
|
||||
// used by tnt to arm it, but also for future circuitry
|
||||
// level is the amount of power
|
||||
// powersrc is the generator or such that created the power
|
||||
|
|
|
@ -2491,7 +2491,16 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
}else if (content_features(n).onpunch_replace_node != CONTENT_IGNORE) {
|
||||
core::list<u16> far_players;
|
||||
core::map<v3s16, MapBlock*> modified_blocks;
|
||||
|
||||
NodeMetadata *meta = m_env.getMap().getNodeMetadata(p_under);
|
||||
NodeMetadata *ometa = NULL;
|
||||
std::string owner;
|
||||
if (meta) {
|
||||
ometa = meta->clone();
|
||||
owner = meta->getOwner();
|
||||
}
|
||||
m_env.getMap().removeNodeMetadata(p_under);
|
||||
|
||||
n.setContent(content_features(n).onpunch_replace_node);
|
||||
sendAddNode(p_under, n, 0, &far_players, 30);
|
||||
{
|
||||
|
@ -2500,12 +2509,29 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
std::string p_name = std::string(player->getName());
|
||||
m_env.getMap().addNodeAndUpdate(p_under, n, modified_blocks, p_name);
|
||||
}
|
||||
for(core::list<u16>::Iterator i = far_players.begin(); i != far_players.end(); i++) {
|
||||
u16 peer_id = *i;
|
||||
RemoteClient *client = getClient(peer_id);
|
||||
if (client == NULL)
|
||||
continue;
|
||||
|
||||
if (ometa) {
|
||||
meta = m_env.getMap().getNodeMetadata(p_under);
|
||||
if (meta) {
|
||||
meta->import(ometa);
|
||||
meta->setOwner(owner);
|
||||
}
|
||||
|
||||
delete ometa;
|
||||
}
|
||||
|
||||
v3s16 blockpos = getNodeBlockPos(p_under);
|
||||
MapBlock *block = m_env.getMap().getBlockNoCreateNoEx(blockpos);
|
||||
if (block)
|
||||
block->setChangedFlag();
|
||||
|
||||
for(core::map<u16, RemoteClient*>::Iterator
|
||||
i = m_clients.getIterator();
|
||||
i.atEnd()==false; i++)
|
||||
{
|
||||
RemoteClient *client = i.getNode()->getValue();
|
||||
client->SetBlocksNotSent(modified_blocks);
|
||||
client->SetBlockNotSent(blockpos);
|
||||
}
|
||||
}else if (content_features(n).flammable > 1) {
|
||||
InventoryItem *wield = (InventoryItem*)player->getWieldItem();
|
||||
|
|
Loading…
Reference in New Issue