mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Formspec: Show/update the player inv using core.show_formspec
'core.show_formspec' now shows and updates the inventory formspec as if it was opened using the hotkey on client-side.
This commit is contained in:
parent
aba2b6638e
commit
bf6ca40b27
3 changed files with 23 additions and 7 deletions
|
@ -6872,9 +6872,10 @@ Formspec
|
|||
* `core.show_formspec(playername, formname, formspec)`
|
||||
* `playername`: name of player to show formspec
|
||||
* `formname`: name passed to `on_player_receive_fields` callbacks.
|
||||
It should follow the `"modname:<whatever>"` naming convention.
|
||||
* `formname` must not be empty, unless you want to reshow
|
||||
the inventory formspec without updating it for future opens.
|
||||
* It should follow the `"modname:<whatever>"` naming convention.
|
||||
* If empty: Reshows the inventory formspec. Servers and
|
||||
clients >= 5.13.0 will update the inventory formspec
|
||||
(`ObjectRef:set_inventory_formspec`) for future opens.
|
||||
* `formspec`: formspec to display
|
||||
* `core.close_formspec(playername, formname)`
|
||||
* `playername`: name of player to close formspec
|
||||
|
|
|
@ -2714,11 +2714,21 @@ void Game::handleClientEvent_DeathscreenLegacy(ClientEvent *event, CameraOrienta
|
|||
|
||||
void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation *cam)
|
||||
{
|
||||
m_game_formspec.showFormSpec(*event->show_formspec.formspec,
|
||||
*event->show_formspec.formname);
|
||||
auto &fs = event->show_formspec;
|
||||
|
||||
delete event->show_formspec.formspec;
|
||||
delete event->show_formspec.formname;
|
||||
if (fs.formname->empty() && !fs.formspec->empty()) {
|
||||
// Overwrite the inventory formspec
|
||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||
player->inventory_formspec = *fs.formspec;
|
||||
|
||||
m_game_formspec.showPlayerInventory();
|
||||
} else {
|
||||
m_game_formspec.showFormSpec(*fs.formspec,
|
||||
*fs.formname);
|
||||
}
|
||||
|
||||
delete fs.formspec;
|
||||
delete fs.formname;
|
||||
}
|
||||
|
||||
void Game::handleClientEvent_ShowCSMFormSpec(ClientEvent *event, CameraOrientation *cam)
|
||||
|
|
|
@ -3397,6 +3397,11 @@ bool Server::showFormspec(const char *playername, const std::string &formspec,
|
|||
if (!player)
|
||||
return false;
|
||||
|
||||
if (formname.empty() && !formspec.empty()) {
|
||||
// Overwrite the inventory formspec
|
||||
player->inventory_formspec = formspec;
|
||||
}
|
||||
|
||||
SendShowFormspecMessage(player->getPeerId(), formspec, formname);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue