Client: add form interception
register_on_receiving_inventory_form(function(formname, formspec)) intercepts forms sent from the server register_on_open_nodemeta_form(function(pos, formname, formspec)) intercepts forms that are to be shown locally nodemeta intecept probably doesn't intercept all ways it can be opened
This commit is contained in:
parent
14b9c0b98f
commit
eeff0d4be0
@ -94,3 +94,5 @@ core.registered_on_item_use, core.register_on_item_use = make_registration()
|
||||
core.registered_on_modchannel_message, core.register_on_modchannel_message = make_registration()
|
||||
core.registered_on_modchannel_signal, core.register_on_modchannel_signal = make_registration()
|
||||
core.registered_on_inventory_open, core.register_on_inventory_open = make_registration()
|
||||
core.registered_on_receiving_inventory_form, core.register_on_receiving_inventory_form = make_registration()
|
||||
core.registered_on_open_nodemeta_form, core.register_on_open_nodemeta_form = make_registration()
|
||||
|
@ -2624,6 +2624,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
|
||||
if (nodedef_manager->get(map.getNode(nodepos)).rightclickable)
|
||||
client->interact(INTERACT_PLACE, pointed);
|
||||
|
||||
std::string formspec_str = meta->getString("formspec");
|
||||
if (!client->getScript()->on_nodemeta_form_open(nodepos, "", formspec_str)) {
|
||||
infostream << "Launching custom inventory view" << std::endl;
|
||||
|
||||
InventoryLocation inventoryloc;
|
||||
@ -2637,7 +2639,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
|
||||
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
|
||||
txt_dst, client->getFormspecPrepend());
|
||||
|
||||
formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
|
||||
formspec->setFormSpec(formspec_str, inventoryloc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -979,6 +979,7 @@ void Client::handleCommand_ShowFormSpec(NetworkPacket* pkt)
|
||||
|
||||
*pkt >> formname;
|
||||
|
||||
if (!m_script->on_receiving_inventory_form(formname, formspec)) {
|
||||
ClientEvent *event = new ClientEvent();
|
||||
event->type = CE_SHOW_FORMSPEC;
|
||||
// pointer is required as event is a struct only!
|
||||
@ -986,6 +987,7 @@ void Client::handleCommand_ShowFormSpec(NetworkPacket* pkt)
|
||||
event->show_formspec.formspec = new std::string(formspec);
|
||||
event->show_formspec.formname = new std::string(formname);
|
||||
m_client_event_queue.push(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
|
||||
|
@ -248,6 +248,35 @@ void ScriptApiClient::open_special_inventory()
|
||||
lua_pcall(L, 0, 0, error_handler);
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_receiving_inventory_form(std::string formname, std::string formspec)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_receiving_inventory_form");
|
||||
|
||||
lua_pushstring(L, formname.c_str());
|
||||
lua_pushstring(L, formspec.c_str());
|
||||
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_nodemeta_form_open(v3s16 position, std::string formname, std::string formspec)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_nodemeta_form_open");
|
||||
|
||||
push_v3s16(L, position);
|
||||
lua_pushstring(L, formname.c_str());
|
||||
lua_pushstring(L, formspec.c_str());
|
||||
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
void ScriptApiClient::setEnv(ClientEnvironment *env)
|
||||
{
|
||||
ScriptApiBase::setEnv(env);
|
||||
|
@ -61,5 +61,8 @@ public:
|
||||
bool on_inventory_open(Inventory *inventory);
|
||||
void open_special_inventory();
|
||||
|
||||
bool on_receiving_inventory_form(std::string formname, std::string formspec);
|
||||
bool on_nodemeta_form_open(v3s16 position, std::string formname, std::string formspec);
|
||||
|
||||
void setEnv(ClientEnvironment *env);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user