added description to item
This commit is contained in:
parent
b4b49ccd83
commit
21364af7a3
@ -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 ---------------------
|
||||
------------------------------------------------
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user