mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 14:42:24 +01:00
fully implemented the sign with the new framework
This commit is contained in:
parent
fa08294d09
commit
fa736e138c
@ -1630,6 +1630,40 @@ void Client::sendSignText(v3s16 blockpos, s16 id, std::string text)
|
||||
Send(0, data, true);
|
||||
}
|
||||
|
||||
void Client::sendSignNodeText(v3s16 p, std::string text)
|
||||
{
|
||||
/*
|
||||
u16 command
|
||||
v3s16 p
|
||||
u16 textlen
|
||||
textdata
|
||||
*/
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
u8 buf[12];
|
||||
|
||||
// Write command
|
||||
writeU16(buf, TOSERVER_SIGNNODETEXT);
|
||||
os.write((char*)buf, 2);
|
||||
|
||||
// Write p
|
||||
writeV3S16(buf, p);
|
||||
os.write((char*)buf, 6);
|
||||
|
||||
u16 textlen = text.size();
|
||||
// Write text length
|
||||
writeS16(buf, textlen);
|
||||
os.write((char*)buf, 2);
|
||||
|
||||
// Write text
|
||||
os.write((char*)text.c_str(), textlen);
|
||||
|
||||
// Make data buffer
|
||||
std::string s = os.str();
|
||||
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
|
||||
// Send as reliable
|
||||
Send(0, data, true);
|
||||
}
|
||||
|
||||
void Client::sendInventoryAction(InventoryAction *a)
|
||||
{
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
|
@ -277,6 +277,7 @@ public:
|
||||
void clickObject(u8 button, v3s16 blockpos, s16 id, u16 item);
|
||||
|
||||
void sendSignText(v3s16 blockpos, s16 id, std::string text);
|
||||
void sendSignNodeText(v3s16 p, std::string text);
|
||||
void sendInventoryAction(InventoryAction *a);
|
||||
void sendChatMessage(const std::wstring &message);
|
||||
|
||||
|
@ -241,6 +241,14 @@ enum ToServerCommand
|
||||
wstring message
|
||||
*/
|
||||
|
||||
TOSERVER_SIGNNODETEXT = 0x33,
|
||||
/*
|
||||
u16 command
|
||||
v3s16 p
|
||||
u16 textlen
|
||||
textdata
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time)
|
||||
|
47
src/main.cpp
47
src/main.cpp
@ -578,6 +578,25 @@ struct TextDestChat : public TextDest
|
||||
Client *m_client;
|
||||
};
|
||||
|
||||
struct TextDestSignNode : public TextDest
|
||||
{
|
||||
TextDestSignNode(v3s16 p, Client *client)
|
||||
{
|
||||
m_p = p;
|
||||
m_client = client;
|
||||
}
|
||||
void gotText(std::wstring text)
|
||||
{
|
||||
std::string ntext = wide_to_narrow(text);
|
||||
dstream<<"Changing text of a sign node: "
|
||||
<<ntext<<std::endl;
|
||||
m_client->sendSignNodeText(m_p, ntext);
|
||||
}
|
||||
|
||||
v3s16 m_p;
|
||||
Client *m_client;
|
||||
};
|
||||
|
||||
class MyEventReceiver : public IEventReceiver
|
||||
{
|
||||
public:
|
||||
@ -2829,6 +2848,8 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
infotext = narrow_to_wide(meta->infoText());
|
||||
}
|
||||
|
||||
//MapNode node = client.getNode(nodepos);
|
||||
|
||||
/*
|
||||
Handle digging
|
||||
@ -2956,7 +2977,31 @@ int main(int argc, char *argv[])
|
||||
if(g_input->getRightClicked())
|
||||
{
|
||||
std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
|
||||
client.groundAction(1, nodepos, neighbourpos, g_selected_item);
|
||||
|
||||
if(meta && meta->typeId() == CONTENT_SIGN_WALL)
|
||||
{
|
||||
dstream<<"Sign node right-clicked"<<std::endl;
|
||||
|
||||
if(random_input == false)
|
||||
{
|
||||
// Get a new text for it
|
||||
|
||||
TextDest *dest = new TextDestSignNode(nodepos, &client);
|
||||
|
||||
SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
|
||||
|
||||
std::wstring wtext =
|
||||
narrow_to_wide(signmeta->getText());
|
||||
|
||||
(new GUITextInputMenu(guienv, guiroot, -1,
|
||||
&g_menumgr, dest,
|
||||
wtext))->drop();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
client.groundAction(1, nodepos, neighbourpos, g_selected_item);
|
||||
}
|
||||
}
|
||||
|
||||
nodepos_old = nodepos;
|
||||
|
@ -1878,8 +1878,6 @@ void MapBlock::serialize(std::ostream &os, u8 version)
|
||||
flags |= 0x02;
|
||||
if(m_lighting_expired)
|
||||
flags |= 0x04;
|
||||
/*if(m_not_fully_generated)
|
||||
flags |= 0x08;*/
|
||||
os.write((char*)&flags, 1);
|
||||
|
||||
u32 nodecount = MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE;
|
||||
@ -1913,6 +1911,14 @@ void MapBlock::serialize(std::ostream &os, u8 version)
|
||||
*/
|
||||
|
||||
compress(databuf, os, version);
|
||||
|
||||
/*
|
||||
NodeMetadata
|
||||
*/
|
||||
if(version >= 14)
|
||||
{
|
||||
m_node_metadata.serialize(os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2002,7 +2008,6 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
|
||||
is_underground = (flags & 0x01) ? true : false;
|
||||
m_day_night_differs = (flags & 0x02) ? true : false;
|
||||
m_lighting_expired = (flags & 0x04) ? true : false;
|
||||
//m_not_fully_generated = (flags & 0x08) ? true : false;
|
||||
|
||||
// Uncompress data
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
@ -2027,6 +2032,14 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
|
||||
{
|
||||
data[i].param2 = s[i+nodecount*2];
|
||||
}
|
||||
|
||||
/*
|
||||
NodeMetadata
|
||||
*/
|
||||
if(version >= 14)
|
||||
{
|
||||
m_node_metadata.deSerialize(is);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -307,7 +307,7 @@ void init_mapnode()
|
||||
f->wall_mounted = true;
|
||||
f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
|
||||
if(f->initial_metadata == NULL)
|
||||
f->initial_metadata = new SignNodeMetadata();
|
||||
f->initial_metadata = new SignNodeMetadata("Some sign");
|
||||
|
||||
}
|
||||
|
||||
|
@ -46,11 +46,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
11: (dev) zlib'd blocks, block flags
|
||||
12: (dev) UnlimitedHeightmap now uses interpolated areas
|
||||
13: (dev) Mapgen v2
|
||||
14: (dev) NodeMetadata
|
||||
*/
|
||||
// This represents an uninitialized or invalid format
|
||||
#define SER_FMT_VER_INVALID 255
|
||||
// Highest supported serialization version
|
||||
#define SER_FMT_VER_HIGHEST 13
|
||||
#define SER_FMT_VER_HIGHEST 14
|
||||
// Lowest supported serialization version
|
||||
#define SER_FMT_VER_LOWEST 2
|
||||
|
||||
|
@ -1221,6 +1221,8 @@ void Server::AsyncRunStep()
|
||||
{
|
||||
//u16 peer_id = i.getNode()->getKey();
|
||||
RemoteClient *client = i.getNode()->getValue();
|
||||
Player *player = m_env.getPlayer(client->peer_id);
|
||||
std::cout<<player->getName()<<" ";
|
||||
client->PrintInfo(std::cout);
|
||||
}
|
||||
}
|
||||
@ -2395,6 +2397,52 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
||||
|
||||
obj->getBlock()->setChangedFlag();
|
||||
}
|
||||
else if(command == TOSERVER_SIGNNODETEXT)
|
||||
{
|
||||
/*
|
||||
u16 command
|
||||
v3s16 p
|
||||
u16 textlen
|
||||
textdata
|
||||
*/
|
||||
std::string datastring((char*)&data[2], datasize-2);
|
||||
std::istringstream is(datastring, std::ios_base::binary);
|
||||
u8 buf[6];
|
||||
// Read stuff
|
||||
is.read((char*)buf, 6);
|
||||
v3s16 p = readV3S16(buf);
|
||||
is.read((char*)buf, 2);
|
||||
u16 textlen = readU16(buf);
|
||||
std::string text;
|
||||
for(u16 i=0; i<textlen; i++)
|
||||
{
|
||||
is.read((char*)buf, 1);
|
||||
text += (char)buf[0];
|
||||
}
|
||||
|
||||
NodeMetadata *meta = m_env.getMap().getNodeMetadata(p);
|
||||
if(!meta)
|
||||
return;
|
||||
if(meta->typeId() != CONTENT_SIGN_WALL)
|
||||
return;
|
||||
SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
|
||||
signmeta->setText(text);
|
||||
|
||||
v3s16 blockpos = getNodeBlockPos(p);
|
||||
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->SetBlockNotSent(blockpos);
|
||||
}
|
||||
}
|
||||
else if(command == TOSERVER_INVENTORY_ACTION)
|
||||
{
|
||||
/*// Ignore inventory changes if in creative mode
|
||||
@ -3376,12 +3424,12 @@ void setCreativeInventory(Player *player)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Sign
|
||||
/*// Sign
|
||||
{
|
||||
InventoryItem *item = new MapBlockObjectItem("Sign Example text");
|
||||
void* r = player->inventory.addItem("main", item);
|
||||
assert(r == NULL);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
Player *Server::emergePlayer(const char *name, const char *password,
|
||||
|
Loading…
Reference in New Issue
Block a user