diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 0765199e..ebde9d12 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -128,6 +128,28 @@ function inventory.decrement(invid, slot, count) end end +function inventory.set_caption(invid, slot, caption) + local itemid, itemcount = inventory.get(invid, slot) + if itemid == 0 then + return + end + if caption == nil or type(caption) ~= "string" then + caption = "" + end + inventory.set_data(invid, slot, "caption", caption) +end + +function inventory.set_description(invid, slot, description) + local itemid, itemcount = inventory.get(invid, slot) + if itemid == 0 then + return + end + if description == nil or type(description) ~= "string" then + description = "" + end + inventory.set_data(invid, slot, "description", description) +end + ------------------------------------------------ ------------------- Events --------------------- ------------------------------------------------ diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index cbb1dde6..a02a49da 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -124,15 +124,23 @@ void SlotView::refreshTooltip(const ItemStack& stack, const ItemDef& item) { } if (itemid) { dv::value* caption = stack.getField("caption"); - if (caption != nullptr) { - tooltip = util::pascal_case( - langs::get(util::str2wstr_utf8(caption->asString())) - ); + dv::value* description = stack.getField("description"); + std::wstring captionText; + std::wstring descriptionText; + + if (description != nullptr) { + descriptionText = util::pascal_case( langs::get( util::str2wstr_utf8( description->asString() ) ) ); } else { - tooltip = util::pascal_case( - langs::get(util::str2wstr_utf8(item.caption)) - ); + descriptionText = util::pascal_case( langs::get( util::str2wstr_utf8( item.description ) ) ); } + + if (caption != nullptr) { + captionText = util::pascal_case( langs::get( util::str2wstr_utf8( caption->asString() ) ) ); + } else { + captionText = util::pascal_case( langs::get( util::str2wstr_utf8( item.caption ) ) ); + } + + tooltip = captionText + L"\n" + descriptionText; } else { tooltip.clear(); } diff --git a/src/items/ItemDef.cpp b/src/items/ItemDef.cpp index e2b54b81..8162323b 100644 --- a/src/items/ItemDef.cpp +++ b/src/items/ItemDef.cpp @@ -4,6 +4,7 @@ ItemDef::ItemDef(const std::string& name) : name(name) { caption = util::id_to_caption(name); + description = ""; } void ItemDef::cloneTo(ItemDef& dst) { dst.caption = caption; diff --git a/src/items/ItemDef.hpp b/src/items/ItemDef.hpp index 00870cc3..4e7e120c 100644 --- a/src/items/ItemDef.hpp +++ b/src/items/ItemDef.hpp @@ -34,6 +34,9 @@ struct ItemDef { /// @brief Item name will shown in inventory std::string caption; + /// @brief Item description will shown in inventory + std::string description; + dv::value properties = nullptr; /// @brief Item max stack size