1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

make independent

This commit is contained in:
SmallJoker 2025-06-10 19:02:30 +02:00
parent bf6ca40b27
commit 0fe91a7a23
10 changed files with 30 additions and 21 deletions

View file

@ -6873,9 +6873,9 @@ Formspec
* `playername`: name of player to show formspec * `playername`: name of player to show formspec
* `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.
* If empty: Reshows the inventory formspec. Servers and * If empty: Shows an inventory formspec. Use
clients >= 5.13.0 will update the inventory formspec `ObjectRef:set_inventory_formspec` to change it for future opens.
(`ObjectRef:set_inventory_formspec`) for future opens. Supported if server AND client are both of version >= 5.13.0.
* `formspec`: formspec to display * `formspec`: formspec to display
* `core.close_formspec(playername, formname)` * `core.close_formspec(playername, formname)`
* `playername`: name of player to close formspec * `playername`: name of player to close formspec
@ -8654,7 +8654,7 @@ child will follow movement and rotation of that bone.
* Returns `nil` if no attribute found. * Returns `nil` if no attribute found.
* `get_meta()`: Returns metadata associated with the player (a PlayerMetaRef). * `get_meta()`: Returns metadata associated with the player (a PlayerMetaRef).
* `set_inventory_formspec(formspec)` * `set_inventory_formspec(formspec)`
* Redefine player's inventory form * Redefine player's inventory form. This sends an update to the player.
* Should usually be called in `on_joinplayer` * Should usually be called in `on_joinplayer`
* If `formspec` is `""`, the player's inventory is disabled. * If `formspec` is `""`, the player's inventory is disabled.
* `get_inventory_formspec()`: returns a formspec string * `get_inventory_formspec()`: returns a formspec string

View file

@ -1925,7 +1925,7 @@ void Game::processKeyInput()
if (g_settings->getBool("continuous_forward")) if (g_settings->getBool("continuous_forward"))
toggleAutoforward(); toggleAutoforward();
} else if (wasKeyDown(KeyType::INVENTORY)) { } else if (wasKeyDown(KeyType::INVENTORY)) {
m_game_formspec.showPlayerInventory(); m_game_formspec.showPlayerInventory(nullptr);
} else if (input->cancelPressed()) { } else if (input->cancelPressed()) {
#ifdef __ANDROID__ #ifdef __ANDROID__
m_android_chat_open = false; m_android_chat_open = false;
@ -2717,11 +2717,7 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation
auto &fs = event->show_formspec; auto &fs = event->show_formspec;
if (fs.formname->empty() && !fs.formspec->empty()) { if (fs.formname->empty() && !fs.formspec->empty()) {
// Overwrite the inventory formspec m_game_formspec.showPlayerInventory(fs.formspec);
LocalPlayer *player = client->getEnv().getLocalPlayer();
player->inventory_formspec = *fs.formspec;
m_game_formspec.showPlayerInventory();
} else { } else {
m_game_formspec.showFormSpec(*fs.formspec, m_game_formspec.showFormSpec(*fs.formspec,
*fs.formname); *fs.formname);

View file

@ -178,6 +178,10 @@ public:
const std::string &getForm() const const std::string &getForm() const
{ {
LocalPlayer *player = m_client->getEnv().getLocalPlayer(); LocalPlayer *player = m_client->getEnv().getLocalPlayer();
if (!player->inventory_formspec_override.empty())
return player->inventory_formspec_override;
return player->inventory_formspec; return player->inventory_formspec;
} }
@ -304,7 +308,7 @@ void GameFormSpec::showNodeFormspec(const std::string &formspec, const v3s16 &no
m_formspec->setFormSpec(formspec, inventoryloc); 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. * Don't permit to open inventory is CAO or player doesn't exists.
@ -327,10 +331,13 @@ void GameFormSpec::showPlayerInventory()
return; return;
} }
if (fs_src->getForm().empty()) { const std::string &formspec = fs_override ? *fs_override : fs_src->getForm();
if (formspec.empty()) {
delete fs_src; delete fs_src;
return; return;
} }
if (fs_override)
player->inventory_formspec_override = *fs_override;
TextDest *txt_dst = new TextDestPlayerInventory(m_client); TextDest *txt_dst = new TextDestPlayerInventory(m_client);
@ -338,7 +345,7 @@ void GameFormSpec::showPlayerInventory()
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(), &m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
m_client->getSoundManager()); m_client->getSoundManager());
m_formspec->setFormSpec(fs_src->getForm(), inventoryloc); m_formspec->setFormSpec(formspec, inventoryloc);
} }
#define SIZE_TAG "size[11,5.5,true]" // Fixed size (ignored in touchscreen mode) #define SIZE_TAG "size[11,5.5,true]" // Fixed size (ignored in touchscreen mode)

View file

@ -34,7 +34,9 @@ struct GameFormSpec
// Currently only used for the in-game settings menu. // Currently only used for the in-game settings menu.
void showPauseMenuFormSpec(const std::string &formspec, const std::string &formname); void showPauseMenuFormSpec(const std::string &formspec, const std::string &formname);
void showNodeFormspec(const std::string &formspec, const v3s16 &nodepos); 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(); void showDeathFormspecLegacy();
// Shows the hardcoded "main" pause menu. // Shows the hardcoded "main" pause menu.
void showPauseMenu(); void showPauseMenu();

View file

@ -99,6 +99,7 @@ public:
std::string hotbar_image = ""; std::string hotbar_image = "";
std::string hotbar_selected_image = ""; std::string hotbar_selected_image = "";
std::string inventory_formspec_override;
video::SColor light_color = video::SColor(255, 255, 255, 255); video::SColor light_color = video::SColor(255, 255, 255, 255);

View file

@ -902,6 +902,7 @@ void Client::handleCommand_InventoryFormSpec(NetworkPacket* pkt)
// Store formspec in LocalPlayer // Store formspec in LocalPlayer
player->inventory_formspec = pkt->readLongString(); player->inventory_formspec = pkt->readLongString();
player->inventory_formspec_override.clear();
} }
void Client::handleCommand_DetachedInventory(NetworkPacket* pkt) void Client::handleCommand_DetachedInventory(NetworkPacket* pkt)

View file

@ -178,6 +178,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_STOP_SOUND", 0, true }, // 0x40 { "TOCLIENT_STOP_SOUND", 0, true }, // 0x40
{ "TOCLIENT_PRIVILEGES", 0, true }, // 0x41 { "TOCLIENT_PRIVILEGES", 0, true }, // 0x41
{ "TOCLIENT_INVENTORY_FORMSPEC", 0, true }, // 0x42 { "TOCLIENT_INVENTORY_FORMSPEC", 0, true }, // 0x42
// ^ `channel` MUST be the same as TOCLIENT_SHOW_FORMSPEC
{ "TOCLIENT_DETACHED_INVENTORY", 0, true }, // 0x43 { "TOCLIENT_DETACHED_INVENTORY", 0, true }, // 0x43
{ "TOCLIENT_SHOW_FORMSPEC", 0, true }, // 0x44 { "TOCLIENT_SHOW_FORMSPEC", 0, true }, // 0x44
{ "TOCLIENT_MOVEMENT", 0, true }, // 0x45 { "TOCLIENT_MOVEMENT", 0, true }, // 0x45

View file

@ -121,6 +121,8 @@ public:
u16 protocol_version = 0; u16 protocol_version = 0;
u16 formspec_version = 0; u16 formspec_version = 0;
bool inventory_formspec_overridden = false;
/// returns PEER_ID_INEXISTENT when PlayerSAO is not ready /// returns PEER_ID_INEXISTENT when PlayerSAO is not ready
session_t getPeerId() const { return m_peer_id; } session_t getPeerId() const { return m_peer_id; }

View file

@ -1574,7 +1574,9 @@ int ObjectRef::l_set_inventory_formspec(lua_State *L)
auto formspec = readParam<std::string_view>(L, 2); auto formspec = readParam<std::string_view>(L, 2);
if (formspec != player->inventory_formspec) { if (player->inventory_formspec_overridden
|| formspec != player->inventory_formspec) {
player->inventory_formspec_overridden = false;
player->inventory_formspec = formspec; player->inventory_formspec = formspec;
getServer(L)->reportInventoryFormspecModified(player->getName()); getServer(L)->reportInventoryFormspecModified(player->getName());
} }

View file

@ -1595,11 +1595,10 @@ void Server::SendShowFormspecMessage(session_t peer_id, const std::string &forms
(it->second == formname || formname.empty())) { (it->second == formname || formname.empty())) {
m_formspec_state_data.erase(peer_id); m_formspec_state_data.erase(peer_id);
} }
pkt.putLongString("");
} else { } else {
m_formspec_state_data[peer_id] = formname; m_formspec_state_data[peer_id] = formname;
pkt.putLongString(formspec);
} }
pkt.putLongString(formspec);
pkt << formname; pkt << formname;
Send(&pkt); Send(&pkt);
@ -3397,10 +3396,8 @@ bool Server::showFormspec(const char *playername, const std::string &formspec,
if (!player) if (!player)
return false; return false;
if (formname.empty() && !formspec.empty()) { // To allow re-sending the same inventory formspec.
// Overwrite the inventory formspec player->inventory_formspec_overridden = formname.empty() && !formspec.empty();
player->inventory_formspec = formspec;
}
SendShowFormspecMessage(player->getPeerId(), formspec, formname); SendShowFormspecMessage(player->getPeerId(), formspec, formname);
return true; return true;