Make supplying empty formspec strings close the formspec (#4737)
This will only happen if the formname matches or if formname is "".master
parent
dbeb322f62
commit
0d1c9598a0
|
@ -239,3 +239,7 @@ else
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function core.close_formspec(player_name, formname)
|
||||||
|
return minetest.show_formspec(player_name, formname, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
@ -2316,6 +2316,13 @@ and `minetest.auth_reload` call the authetification handler.
|
||||||
* `formname`: name passed to `on_player_receive_fields` callbacks.
|
* `formname`: name passed to `on_player_receive_fields` callbacks.
|
||||||
It should follow the `"modname:<whatever>"` naming convention
|
It should follow the `"modname:<whatever>"` naming convention
|
||||||
* `formspec`: formspec to display
|
* `formspec`: formspec to display
|
||||||
|
* `minetest.close_formspec(playername, formname)`
|
||||||
|
* `playername`: name of player to close formspec
|
||||||
|
* `formname`: has to exactly match the one given in show_formspec, or the formspec will
|
||||||
|
not close.
|
||||||
|
* calling show_formspec(playername, formname, "") is equal to this expression
|
||||||
|
* to close a formspec regardless of the formname, call
|
||||||
|
minetest.close_formspec(playername, ""). USE THIS ONLY WHEN ABSOLUTELY NECESSARY!
|
||||||
* `minetest.formspec_escape(string)`: returns a string
|
* `minetest.formspec_escape(string)`: returns a string
|
||||||
* escapes the characters "[", "]", "\", "," and ";", which can not be used in formspecs
|
* escapes the characters "[", "]", "\", "," and ";", which can not be used in formspecs
|
||||||
* `minetest.explode_table_event(string)`: returns a table
|
* `minetest.explode_table_event(string)`: returns a table
|
||||||
|
|
27
src/game.cpp
27
src/game.cpp
|
@ -1205,6 +1205,7 @@ static inline void create_formspec_menu(GUIFormSpecMenu **cur_formspec,
|
||||||
(*cur_formspec)->setFormSource(fs_src);
|
(*cur_formspec)->setFormSource(fs_src);
|
||||||
(*cur_formspec)->setTextDest(txt_dest);
|
(*cur_formspec)->setTextDest(txt_dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
|
@ -1753,6 +1754,8 @@ private:
|
||||||
ChatBackend *chat_backend;
|
ChatBackend *chat_backend;
|
||||||
|
|
||||||
GUIFormSpecMenu *current_formspec;
|
GUIFormSpecMenu *current_formspec;
|
||||||
|
//default: "". If other than "", empty show_formspec packets will only close the formspec when the formname matches
|
||||||
|
std::string cur_formname;
|
||||||
|
|
||||||
EventManager *eventmgr;
|
EventManager *eventmgr;
|
||||||
QuicktuneShortcutter *quicktune;
|
QuicktuneShortcutter *quicktune;
|
||||||
|
@ -1841,6 +1844,7 @@ Game::Game() :
|
||||||
soundmaker(NULL),
|
soundmaker(NULL),
|
||||||
chat_backend(NULL),
|
chat_backend(NULL),
|
||||||
current_formspec(NULL),
|
current_formspec(NULL),
|
||||||
|
cur_formname(""),
|
||||||
eventmgr(NULL),
|
eventmgr(NULL),
|
||||||
quicktune(NULL),
|
quicktune(NULL),
|
||||||
gui_chat_console(NULL),
|
gui_chat_console(NULL),
|
||||||
|
@ -3005,6 +3009,7 @@ void Game::openInventory()
|
||||||
|
|
||||||
create_formspec_menu(¤t_formspec, client, gamedef, texture_src,
|
create_formspec_menu(¤t_formspec, client, gamedef, texture_src,
|
||||||
device, &input->joystick, fs_src, txt_dst, client);
|
device, &input->joystick, fs_src, txt_dst, client);
|
||||||
|
cur_formname = "";
|
||||||
|
|
||||||
InventoryLocation inventoryloc;
|
InventoryLocation inventoryloc;
|
||||||
inventoryloc.setCurrentPlayer();
|
inventoryloc.setCurrentPlayer();
|
||||||
|
@ -3484,14 +3489,21 @@ void Game::processClientEvents(CameraOrientation *cam, float *damage_flash)
|
||||||
player->hurt_tilt_strength = 0;
|
player->hurt_tilt_strength = 0;
|
||||||
|
|
||||||
} else if (event.type == CE_SHOW_FORMSPEC) {
|
} else if (event.type == CE_SHOW_FORMSPEC) {
|
||||||
FormspecFormSource *fs_src =
|
if (*(event.show_formspec.formspec) == "") {
|
||||||
new FormspecFormSource(*(event.show_formspec.formspec));
|
if (current_formspec && ( *(event.show_formspec.formname) == "" || *(event.show_formspec.formname) == cur_formname) ){
|
||||||
TextDestPlayerInventory *txt_dst =
|
current_formspec->quitMenu();
|
||||||
new TextDestPlayerInventory(client, *(event.show_formspec.formname));
|
}
|
||||||
|
} else {
|
||||||
|
FormspecFormSource *fs_src =
|
||||||
|
new FormspecFormSource(*(event.show_formspec.formspec));
|
||||||
|
TextDestPlayerInventory *txt_dst =
|
||||||
|
new TextDestPlayerInventory(client, *(event.show_formspec.formname));
|
||||||
|
|
||||||
create_formspec_menu(¤t_formspec, client, gamedef,
|
create_formspec_menu(¤t_formspec, client, gamedef,
|
||||||
texture_src, device, &input->joystick,
|
texture_src, device, &input->joystick,
|
||||||
fs_src, txt_dst, client);
|
fs_src, txt_dst, client);
|
||||||
|
cur_formname = *(event.show_formspec.formname);
|
||||||
|
}
|
||||||
|
|
||||||
delete(event.show_formspec.formspec);
|
delete(event.show_formspec.formspec);
|
||||||
delete(event.show_formspec.formname);
|
delete(event.show_formspec.formname);
|
||||||
|
@ -3955,6 +3967,7 @@ void Game::handlePointingAtNode(GameRunData *runData,
|
||||||
|
|
||||||
create_formspec_menu(¤t_formspec, client, gamedef,
|
create_formspec_menu(¤t_formspec, client, gamedef,
|
||||||
texture_src, device, &input->joystick, fs_src, txt_dst, client);
|
texture_src, device, &input->joystick, fs_src, txt_dst, client);
|
||||||
|
cur_formname = "";
|
||||||
|
|
||||||
current_formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
|
current_formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1647,8 +1647,12 @@ void Server::SendShowFormspecMessage(u16 peer_id, const std::string &formspec,
|
||||||
DSTACK(FUNCTION_NAME);
|
DSTACK(FUNCTION_NAME);
|
||||||
|
|
||||||
NetworkPacket pkt(TOCLIENT_SHOW_FORMSPEC, 0 , peer_id);
|
NetworkPacket pkt(TOCLIENT_SHOW_FORMSPEC, 0 , peer_id);
|
||||||
|
if (formspec == "" ){
|
||||||
pkt.putLongString(FORMSPEC_VERSION_STRING + formspec);
|
//the client should close the formspec
|
||||||
|
pkt.putLongString("");
|
||||||
|
} else {
|
||||||
|
pkt.putLongString(FORMSPEC_VERSION_STRING + formspec);
|
||||||
|
}
|
||||||
pkt << formname;
|
pkt << formname;
|
||||||
|
|
||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
|
|
Loading…
Reference in New Issue