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
|
||||||
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 ---------------------
|
------------------- Events ---------------------
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|||||||
@ -124,15 +124,23 @@ void SlotView::refreshTooltip(const ItemStack& stack, const ItemDef& item) {
|
|||||||
}
|
}
|
||||||
if (itemid) {
|
if (itemid) {
|
||||||
dv::value* caption = stack.getField("caption");
|
dv::value* caption = stack.getField("caption");
|
||||||
if (caption != nullptr) {
|
dv::value* description = stack.getField("description");
|
||||||
tooltip = util::pascal_case(
|
std::wstring captionText;
|
||||||
langs::get(util::str2wstr_utf8(caption->asString()))
|
std::wstring descriptionText;
|
||||||
);
|
|
||||||
|
if (description != nullptr) {
|
||||||
|
descriptionText = util::pascal_case( langs::get( util::str2wstr_utf8( description->asString() ) ) );
|
||||||
} else {
|
} else {
|
||||||
tooltip = util::pascal_case(
|
descriptionText = util::pascal_case( langs::get( util::str2wstr_utf8( item.description ) ) );
|
||||||
langs::get(util::str2wstr_utf8(item.caption))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
tooltip.clear();
|
tooltip.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
ItemDef::ItemDef(const std::string& name) : name(name) {
|
ItemDef::ItemDef(const std::string& name) : name(name) {
|
||||||
caption = util::id_to_caption(name);
|
caption = util::id_to_caption(name);
|
||||||
|
description = "";
|
||||||
}
|
}
|
||||||
void ItemDef::cloneTo(ItemDef& dst) {
|
void ItemDef::cloneTo(ItemDef& dst) {
|
||||||
dst.caption = caption;
|
dst.caption = caption;
|
||||||
|
|||||||
@ -34,6 +34,9 @@ struct ItemDef {
|
|||||||
/// @brief Item name will shown in inventory
|
/// @brief Item name will shown in inventory
|
||||||
std::string caption;
|
std::string caption;
|
||||||
|
|
||||||
|
/// @brief Item description will shown in inventory
|
||||||
|
std::string description;
|
||||||
|
|
||||||
dv::value properties = nullptr;
|
dv::value properties = nullptr;
|
||||||
|
|
||||||
/// @brief Item max stack size
|
/// @brief Item max stack size
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user