mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-05 19:31: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
|
@ -1925,7 +1925,7 @@ void Game::processKeyInput()
|
|||
if (g_settings->getBool("continuous_forward"))
|
||||
toggleAutoforward();
|
||||
} else if (wasKeyDown(KeyType::INVENTORY)) {
|
||||
m_game_formspec.showPlayerInventory();
|
||||
m_game_formspec.showPlayerInventory(nullptr);
|
||||
} else if (input->cancelPressed()) {
|
||||
#ifdef __ANDROID__
|
||||
m_android_chat_open = false;
|
||||
|
@ -2714,11 +2714,16 @@ 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()) {
|
||||
m_game_formspec.showPlayerInventory(fs.formspec);
|
||||
} else {
|
||||
m_game_formspec.showFormSpec(*fs.formspec, *fs.formname);
|
||||
}
|
||||
|
||||
delete fs.formspec;
|
||||
delete fs.formname;
|
||||
}
|
||||
|
||||
void Game::handleClientEvent_ShowCSMFormSpec(ClientEvent *event, CameraOrientation *cam)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -34,7 +34,9 @@ struct GameFormSpec
|
|||
// Currently only used for the in-game settings menu.
|
||||
void showPauseMenuFormSpec(const std::string &formspec, const std::string &formname);
|
||||
void showNodeFormspec(const std::string &formspec, const v3s16 &nodepos);
|
||||
void showPlayerInventory();
|
||||
/// If `!fs_override`: Uses `player->inventory_formspec`.
|
||||
/// If ` fs_override`: Uses a temporary formspec until an update is received.
|
||||
void showPlayerInventory(const std::string *fs_override);
|
||||
void showDeathFormspecLegacy();
|
||||
// Shows the hardcoded "main" pause menu.
|
||||
void showPauseMenu();
|
||||
|
|
|
@ -99,6 +99,8 @@ public:
|
|||
|
||||
std::string hotbar_image = "";
|
||||
std::string hotbar_selected_image = "";
|
||||
/// Temporary player inventory formspec. Empty value = feature inactive.
|
||||
std::string inventory_formspec_override;
|
||||
|
||||
video::SColor light_color = video::SColor(255, 255, 255, 255);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue