diff --git a/src/content/ContentLoader.cpp b/src/content/ContentLoader.cpp index 0c25b6da..75b7b035 100644 --- a/src/content/ContentLoader.cpp +++ b/src/content/ContentLoader.cpp @@ -438,6 +438,18 @@ void ContentLoader::loadItem( root.at("stack-size").get(def.stackSize); root.at("uses").get(def.uses); + std::string usesDisplayStr = ""; + root.at("uses-display").get(usesDisplayStr); + if (usesDisplayStr == "none") { + def.usesDisplay = ItemUsesDisplay::NONE; + } else if (usesDisplayStr == "relation") { + def.usesDisplay = ItemUsesDisplay::RELATION; + } else if (usesDisplayStr == "vbar") { + def.usesDisplay = ItemUsesDisplay::VBAR; + } else if (usesDisplayStr.length()) { + logger.error() << name << ": unknown uses display mode " << usesDisplayStr; + } + if (auto found = root.at("emission")) { const auto& emissionarr = *found; def.emission[0] = emissionarr[0].asNumber(); diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index 7abc2ab6..d40614fe 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -234,19 +234,38 @@ void SlotView::drawItemInfo( if (!ptr->isInteger()) { return; } - { - std::wstring text = std::to_wstring(ptr->asInteger()); - batch.setColor({0, 0, 0, 1.0f}); - font.draw(batch, text, pos.x - 2, pos.y - 2, nullptr, 0); - batch.resetColor(); - font.draw(batch, text, pos.x - 3, pos.y - 3, nullptr, 0); - } - { - std::wstring text = std::to_wstring(item.uses); - batch.setColor({0, 0, 0, 1.0f}); - font.draw(batch, text, pos.x - 2, pos.y - 2 + 12, nullptr, 0); - batch.resetColor(); - font.draw(batch, text, pos.x - 3, pos.y - 3 + 12, nullptr, 0); + int16_t uses = ptr->asInteger(); + switch (item.usesDisplay) { + case ItemUsesDisplay::NONE: + break; + case ItemUsesDisplay::RELATION: + { + std::wstring text = std::to_wstring(uses); + batch.setColor({0, 0, 0, 1.0f}); + font.draw(batch, text, pos.x - 2, pos.y - 2, nullptr, 0); + batch.resetColor(); + font.draw(batch, text, pos.x - 3, pos.y - 3, nullptr, 0); + } + { + std::wstring text = std::to_wstring(item.uses); + batch.setColor({0, 0, 0, 1.0f}); + font.draw(batch, text, pos.x - 2, pos.y - 2 + 12, nullptr, 0); + batch.resetColor(); + font.draw(batch, text, pos.x - 3, pos.y - 3 + 12, nullptr, 0); + } + break; + case ItemUsesDisplay::VBAR: { + batch.untexture(); + batch.setColor({0, 0, 0, 0.75f}); + batch.rect(pos.x - 2, pos.y - 2, 6, SLOT_SIZE + 4); + float t = static_cast(uses) / item.uses; + + batch.setColor({(1.0f - t * 0.8f), 0.4f, t * 0.8f + 0.2f, 1.0f}); + + int height = SLOT_SIZE * t; + batch.rect(pos.x, pos.y + SLOT_SIZE - height, 2, height); + break; + } } } } diff --git a/src/items/ItemDef.cpp b/src/items/ItemDef.cpp index 8d0cdd66..e2b54b81 100644 --- a/src/items/ItemDef.cpp +++ b/src/items/ItemDef.cpp @@ -15,4 +15,6 @@ void ItemDef::cloneTo(ItemDef& dst) { dst.placingBlock = placingBlock; dst.scriptName = scriptName; dst.modelName = modelName; + dst.uses = uses; + dst.usesDisplay = usesDisplay; } diff --git a/src/items/ItemDef.hpp b/src/items/ItemDef.hpp index 36b9fe2d..59cf8256 100644 --- a/src/items/ItemDef.hpp +++ b/src/items/ItemDef.hpp @@ -19,6 +19,13 @@ enum class ItemIconType { BLOCK, // block preview: icon is string block id }; +enum class ItemUsesDisplay { + NONE, // uses count is not displayed + RELATION, // uses count is displayed as `remain/default` relation + VBAR, // uses count is displayed as vertical bar without counter + DEFAULT = VBAR, +}; + struct ItemDef { /// @brief Item string id (with prefix included) std::string const name; @@ -40,6 +47,9 @@ struct ItemDef { /// @brief Default item uses count int16_t uses = -1; + /// @brief Item uses count display mode + ItemUsesDisplay usesDisplay = ItemUsesDisplay::DEFAULT; + ItemIconType iconType = ItemIconType::SPRITE; std::string icon = "blocks:notfound";