mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-06 17:41:04 +00:00
Formspec: Show a player inventory using core.show_formspec (#15963)
'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
d41de3da79
commit
fdc149f316
10 changed files with 59 additions and 23 deletions
|
@ -178,6 +178,10 @@ public:
|
|||
const std::string &getForm() const
|
||||
{
|
||||
LocalPlayer *player = m_client->getEnv().getLocalPlayer();
|
||||
|
||||
if (!player->inventory_formspec_override.empty())
|
||||
return player->inventory_formspec_override;
|
||||
|
||||
return player->inventory_formspec;
|
||||
}
|
||||
|
||||
|
@ -304,7 +308,7 @@ void GameFormSpec::showNodeFormspec(const std::string &formspec, const v3s16 &no
|
|||
m_formspec->setFormSpec(formspec, inventoryloc);
|
||||
}
|
||||
|
||||
void GameFormSpec::showPlayerInventory()
|
||||
void GameFormSpec::showPlayerInventory(const std::string *fs_override)
|
||||
{
|
||||
/*
|
||||
* Don't permit to open inventory is CAO or player doesn't exists.
|
||||
|
@ -317,28 +321,35 @@ void GameFormSpec::showPlayerInventory()
|
|||
|
||||
infostream << "Game: Launching inventory" << std::endl;
|
||||
|
||||
PlayerInventoryFormSource *fs_src = new PlayerInventoryFormSource(m_client);
|
||||
auto fs_src = std::make_unique<PlayerInventoryFormSource>(m_client);
|
||||
|
||||
InventoryLocation inventoryloc;
|
||||
inventoryloc.setCurrentPlayer();
|
||||
|
||||
if (m_client->modsLoaded() && m_client->getScript()->on_inventory_open(m_client->getInventory(inventoryloc))) {
|
||||
delete fs_src;
|
||||
return;
|
||||
if (fs_override) {
|
||||
// Temporary overwrite for this specific formspec.
|
||||
player->inventory_formspec_override = *fs_override;
|
||||
} else {
|
||||
// Show the regular inventory formspec
|
||||
player->inventory_formspec_override.clear();
|
||||
}
|
||||
|
||||
if (fs_src->getForm().empty()) {
|
||||
delete fs_src;
|
||||
// If prevented by Client-Side Mods
|
||||
if (m_client->modsLoaded() && m_client->getScript()->on_inventory_open(m_client->getInventory(inventoryloc)))
|
||||
return;
|
||||
|
||||
// Empty formspec -> do not show.
|
||||
if (fs_src->getForm().empty())
|
||||
return;
|
||||
}
|
||||
|
||||
TextDest *txt_dst = new TextDestPlayerInventory(m_client);
|
||||
|
||||
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
|
||||
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
|
||||
&m_input->joystick, fs_src.get(), txt_dst, m_client->getFormspecPrepend(),
|
||||
m_client->getSoundManager());
|
||||
|
||||
m_formspec->setFormSpec(fs_src->getForm(), inventoryloc);
|
||||
fs_src.release(); // owned by GUIFormSpecMenu
|
||||
}
|
||||
|
||||
#define SIZE_TAG "size[11,5.5,true]" // Fixed size (ignored in touchscreen mode)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue