add item 'uses-display' property
This commit is contained in:
parent
449b0ebca4
commit
df2cff3e4c
@ -438,6 +438,18 @@ void ContentLoader::loadItem(
|
|||||||
root.at("stack-size").get(def.stackSize);
|
root.at("stack-size").get(def.stackSize);
|
||||||
root.at("uses").get(def.uses);
|
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")) {
|
if (auto found = root.at("emission")) {
|
||||||
const auto& emissionarr = *found;
|
const auto& emissionarr = *found;
|
||||||
def.emission[0] = emissionarr[0].asNumber();
|
def.emission[0] = emissionarr[0].asNumber();
|
||||||
|
|||||||
@ -234,8 +234,13 @@ void SlotView::drawItemInfo(
|
|||||||
if (!ptr->isInteger()) {
|
if (!ptr->isInteger()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
int16_t uses = ptr->asInteger();
|
||||||
|
switch (item.usesDisplay) {
|
||||||
|
case ItemUsesDisplay::NONE:
|
||||||
|
break;
|
||||||
|
case ItemUsesDisplay::RELATION:
|
||||||
{
|
{
|
||||||
std::wstring text = std::to_wstring(ptr->asInteger());
|
std::wstring text = std::to_wstring(uses);
|
||||||
batch.setColor({0, 0, 0, 1.0f});
|
batch.setColor({0, 0, 0, 1.0f});
|
||||||
font.draw(batch, text, pos.x - 2, pos.y - 2, nullptr, 0);
|
font.draw(batch, text, pos.x - 2, pos.y - 2, nullptr, 0);
|
||||||
batch.resetColor();
|
batch.resetColor();
|
||||||
@ -248,6 +253,20 @@ void SlotView::drawItemInfo(
|
|||||||
batch.resetColor();
|
batch.resetColor();
|
||||||
font.draw(batch, text, pos.x - 3, pos.y - 3 + 12, nullptr, 0);
|
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<float>(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,4 +15,6 @@ void ItemDef::cloneTo(ItemDef& dst) {
|
|||||||
dst.placingBlock = placingBlock;
|
dst.placingBlock = placingBlock;
|
||||||
dst.scriptName = scriptName;
|
dst.scriptName = scriptName;
|
||||||
dst.modelName = modelName;
|
dst.modelName = modelName;
|
||||||
|
dst.uses = uses;
|
||||||
|
dst.usesDisplay = usesDisplay;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,13 @@ enum class ItemIconType {
|
|||||||
BLOCK, // block preview: icon is string block id
|
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 {
|
struct ItemDef {
|
||||||
/// @brief Item string id (with prefix included)
|
/// @brief Item string id (with prefix included)
|
||||||
std::string const name;
|
std::string const name;
|
||||||
@ -40,6 +47,9 @@ struct ItemDef {
|
|||||||
/// @brief Default item uses count
|
/// @brief Default item uses count
|
||||||
int16_t uses = -1;
|
int16_t uses = -1;
|
||||||
|
|
||||||
|
/// @brief Item uses count display mode
|
||||||
|
ItemUsesDisplay usesDisplay = ItemUsesDisplay::DEFAULT;
|
||||||
|
|
||||||
ItemIconType iconType = ItemIconType::SPRITE;
|
ItemIconType iconType = ItemIconType::SPRITE;
|
||||||
std::string icon = "blocks:notfound";
|
std::string icon = "blocks:notfound";
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user