Fix buttons not working for Lua-triggered formspecs
parent
8b75736c6f
commit
0b1d09ff4f
|
@ -891,8 +891,10 @@ minetest.get_inventory(location) -> InvRef
|
||||||
minetest.create_detached_inventory(name, callbacks) -> InvRef
|
minetest.create_detached_inventory(name, callbacks) -> InvRef
|
||||||
^ callbacks: See "Detached inventory callbacks"
|
^ callbacks: See "Detached inventory callbacks"
|
||||||
^ Creates a detached inventory. If it already exists, it is cleared.
|
^ Creates a detached inventory. If it already exists, it is cleared.
|
||||||
minetest.show_formspec(playername, formspec)
|
minetest.show_formspec(playername, formname, formspec)
|
||||||
^ playername: name of player to show formspec
|
^ playername: name of player to show formspec
|
||||||
|
^ formname: name passed to on_player_receive_fields callbacks
|
||||||
|
^ should follow "modname:<whatever>" naming convention
|
||||||
^ formspec: formspec to display
|
^ formspec: formspec to display
|
||||||
|
|
||||||
Item handling:
|
Item handling:
|
||||||
|
|
|
@ -1906,12 +1906,14 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
||||||
std::istringstream is(datastring, std::ios_base::binary);
|
std::istringstream is(datastring, std::ios_base::binary);
|
||||||
|
|
||||||
std::string formspec = deSerializeLongString(is);
|
std::string formspec = deSerializeLongString(is);
|
||||||
|
std::string formname = deSerializeString(is);
|
||||||
|
|
||||||
ClientEvent event;
|
ClientEvent event;
|
||||||
event.type = CE_SHOW_FORMSPEC;
|
event.type = CE_SHOW_FORMSPEC;
|
||||||
// pointer is required as event is a struct only!
|
// pointer is required as event is a struct only!
|
||||||
// adding a std:string to a struct isn't possible
|
// adding a std:string to a struct isn't possible
|
||||||
event.show_formspec.formspec = new std::string(formspec);
|
event.show_formspec.formspec = new std::string(formspec);
|
||||||
|
event.show_formspec.formname = new std::string(formname);
|
||||||
m_client_event_queue.push_back(event);
|
m_client_event_queue.push_back(event);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -179,6 +179,7 @@ struct ClientEvent
|
||||||
} deathscreen;
|
} deathscreen;
|
||||||
struct{
|
struct{
|
||||||
std::string* formspec;
|
std::string* formspec;
|
||||||
|
std::string* formname;
|
||||||
} show_formspec;
|
} show_formspec;
|
||||||
struct{
|
struct{
|
||||||
} textures_updated;
|
} textures_updated;
|
||||||
|
|
|
@ -359,8 +359,10 @@ enum ToClientCommand
|
||||||
TOCLIENT_SHOW_FORMSPEC = 0x44,
|
TOCLIENT_SHOW_FORMSPEC = 0x44,
|
||||||
/*
|
/*
|
||||||
[0] u16 command
|
[0] u16 command
|
||||||
u16 len
|
u32 len
|
||||||
u8[len] formspec
|
u8[len] formspec
|
||||||
|
u16 len
|
||||||
|
u8[len] formname
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
11
src/game.cpp
11
src/game.cpp
|
@ -118,13 +118,20 @@ struct TextDestPlayerInventory : public TextDest
|
||||||
TextDestPlayerInventory(Client *client)
|
TextDestPlayerInventory(Client *client)
|
||||||
{
|
{
|
||||||
m_client = client;
|
m_client = client;
|
||||||
|
m_formname = "";
|
||||||
|
}
|
||||||
|
TextDestPlayerInventory(Client *client, std::string formname)
|
||||||
|
{
|
||||||
|
m_client = client;
|
||||||
|
m_formname = formname;
|
||||||
}
|
}
|
||||||
void gotText(std::map<std::string, std::string> fields)
|
void gotText(std::map<std::string, std::string> fields)
|
||||||
{
|
{
|
||||||
m_client->sendInventoryFields("", fields);
|
m_client->sendInventoryFields(m_formname, fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *m_client;
|
Client *m_client;
|
||||||
|
std::string m_formname;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Respawn menu callback */
|
/* Respawn menu callback */
|
||||||
|
@ -2154,6 +2161,7 @@ void the_game(
|
||||||
&g_menumgr,
|
&g_menumgr,
|
||||||
&client, gamedef);
|
&client, gamedef);
|
||||||
menu->setFormSource(current_formspec);
|
menu->setFormSource(current_formspec);
|
||||||
|
menu->setTextDest(new TextDestPlayerInventory(&client,*(event.show_formspec.formname)));
|
||||||
menu->drop();
|
menu->drop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2162,6 +2170,7 @@ void the_game(
|
||||||
current_formspec->setForm(*(event.show_formspec.formspec));
|
current_formspec->setForm(*(event.show_formspec.formspec));
|
||||||
}
|
}
|
||||||
delete(event.show_formspec.formspec);
|
delete(event.show_formspec.formspec);
|
||||||
|
delete(event.show_formspec.formname);
|
||||||
}
|
}
|
||||||
else if(event.type == CE_TEXTURES_UPDATED)
|
else if(event.type == CE_TEXTURES_UPDATED)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4921,13 +4921,14 @@ static int l_create_detached_inventory_raw(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create_detached_formspec_raw(name)
|
// show_formspec(playername,formname,formspec)
|
||||||
static int l_show_formspec(lua_State *L)
|
static int l_show_formspec(lua_State *L)
|
||||||
{
|
{
|
||||||
const char *playername = luaL_checkstring(L, 1);
|
const char *playername = luaL_checkstring(L, 1);
|
||||||
const char *formspec = luaL_checkstring(L, 2);
|
const char *formname = luaL_checkstring(L, 2);
|
||||||
|
const char *formspec = luaL_checkstring(L, 3);
|
||||||
|
|
||||||
if(get_server(L)->showFormspec(playername,formspec))
|
if(get_server(L)->showFormspec(playername,formspec,formname))
|
||||||
{
|
{
|
||||||
lua_pushboolean(L, true);
|
lua_pushboolean(L, true);
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -3638,7 +3638,7 @@ void Server::SendChatMessage(u16 peer_id, const std::wstring &message)
|
||||||
// Send as reliable
|
// Send as reliable
|
||||||
m_con.Send(peer_id, 0, data, true);
|
m_con.Send(peer_id, 0, data, true);
|
||||||
}
|
}
|
||||||
void Server::SendShowFormspecMessage(u16 peer_id, const std::string formspec)
|
void Server::SendShowFormspecMessage(u16 peer_id, const std::string formspec, const std::string formname)
|
||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
|
|
||||||
|
@ -3649,6 +3649,7 @@ void Server::SendShowFormspecMessage(u16 peer_id, const std::string formspec)
|
||||||
writeU16(buf, TOCLIENT_SHOW_FORMSPEC);
|
writeU16(buf, TOCLIENT_SHOW_FORMSPEC);
|
||||||
os.write((char*)buf, 2);
|
os.write((char*)buf, 2);
|
||||||
os<<serializeLongString(formspec);
|
os<<serializeLongString(formspec);
|
||||||
|
os<<serializeString(formname);
|
||||||
|
|
||||||
// Make data buffer
|
// Make data buffer
|
||||||
std::string s = os.str();
|
std::string s = os.str();
|
||||||
|
@ -4596,7 +4597,7 @@ void Server::notifyPlayer(const char *name, const std::wstring msg)
|
||||||
SendChatMessage(player->peer_id, std::wstring(L"Server: -!- ")+msg);
|
SendChatMessage(player->peer_id, std::wstring(L"Server: -!- ")+msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::showFormspec(const char *playername, const std::string &formspec)
|
bool Server::showFormspec(const char *playername, const std::string &formspec, const std::string &formname)
|
||||||
{
|
{
|
||||||
Player *player = m_env->getPlayer(playername);
|
Player *player = m_env->getPlayer(playername);
|
||||||
|
|
||||||
|
@ -4606,7 +4607,7 @@ bool Server::showFormspec(const char *playername, const std::string &formspec)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SendShowFormspecMessage(player->peer_id,formspec);
|
SendShowFormspecMessage(player->peer_id, formspec, formname);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -583,7 +583,7 @@ public:
|
||||||
m_async_fatal_error.set(error);
|
m_async_fatal_error.set(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool showFormspec(const char *name, const std::string &formspec);
|
bool showFormspec(const char *name, const std::string &formspec, const std::string &formname);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// con::PeerHandler implementation.
|
// con::PeerHandler implementation.
|
||||||
|
@ -621,7 +621,7 @@ private:
|
||||||
void SendMovePlayer(u16 peer_id);
|
void SendMovePlayer(u16 peer_id);
|
||||||
void SendPlayerPrivileges(u16 peer_id);
|
void SendPlayerPrivileges(u16 peer_id);
|
||||||
void SendPlayerInventoryFormspec(u16 peer_id);
|
void SendPlayerInventoryFormspec(u16 peer_id);
|
||||||
void SendShowFormspecMessage(u16 peer_id, const std::string formspec);
|
void SendShowFormspecMessage(u16 peer_id, const std::string formspec, const std::string formname);
|
||||||
/*
|
/*
|
||||||
Send a node removal/addition event to all clients except ignore_id.
|
Send a node removal/addition event to all clients except ignore_id.
|
||||||
Additionally, if far_players!=NULL, players further away than
|
Additionally, if far_players!=NULL, players further away than
|
||||||
|
|
Loading…
Reference in New Issue