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

Formspec: allow lists to change size and existence while the formspec is open (#9700)

Fixes #9640.
This commit is contained in:
DS 2020-04-18 17:21:10 +02:00 committed by GitHub
parent 241bf44260
commit 4fb6b6afa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 41 deletions

View file

@ -489,38 +489,10 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element)
start_i = stoi(startindex);
if (geom.X < 0 || geom.Y < 0 || start_i < 0) {
errorstream<< "Invalid list element: '" << element << "'" << std::endl;
errorstream << "Invalid list element: '" << element << "'" << std::endl;
return;
}
// check for the existence of inventory and list
Inventory *inv = m_invmgr->getInventory(loc);
if (!inv) {
warningstream << "GUIFormSpecMenu::parseList(): "
<< "The inventory location "
<< "\"" << loc.dump() << "\" doesn't exist"
<< std::endl;
return;
}
InventoryList *ilist = inv->getList(listname);
if (!ilist) {
warningstream << "GUIFormSpecMenu::parseList(): "
<< "The inventory list \"" << listname << "\" "
<< "@ \"" << loc.dump() << "\" doesn't exist"
<< std::endl;
return;
}
// trim geom if it is larger than the actual inventory size
s32 list_size = (s32)ilist->getSize();
if (list_size < geom.X * geom.Y + start_i) {
list_size -= MYMAX(start_i, 0);
geom.Y = list_size / geom.X;
geom.Y += list_size % geom.X > 0 ? 1 : 0;
if (geom.Y <= 1)
geom.X = list_size;
}
if (!data->explicit_size)
warningstream << "invalid use of list without a size[] element" << std::endl;