refactor: streamline tooltip handling by separating caption and description retrieval
This commit is contained in:
parent
7893338b67
commit
d489dab013
@ -116,46 +116,43 @@ SlotView::SlotView(GUI& gui, SlotLayout layout)
|
|||||||
setColor(glm::vec4(0, 0, 0, 0.2f));
|
setColor(glm::vec4(0, 0, 0, 0.2f));
|
||||||
setTooltipDelay(0.0f);
|
setTooltipDelay(0.0f);
|
||||||
}
|
}
|
||||||
|
// TODO: Refactor
|
||||||
|
std::wstring get_caption_string(const ItemStack& stack, const ItemDef& item) {
|
||||||
|
dv::value* caption = stack.getField("caption");
|
||||||
|
if (caption != nullptr) {
|
||||||
|
return util::pascal_case(
|
||||||
|
langs::get(util::str2wstr_utf8(caption->asString()))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return util::pascal_case(langs::get(util::str2wstr_utf8(item.caption)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: Refactor
|
||||||
|
std::wstring get_description_string(const ItemStack& stack, const ItemDef& item) {
|
||||||
|
dv::value* description = stack.getField("description");
|
||||||
|
|
||||||
|
if (description != nullptr) {
|
||||||
|
return langs::get(util::str2wstr_utf8(description->asString()));
|
||||||
|
} else {
|
||||||
|
return langs::get(util::str2wstr_utf8(item.description));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SlotView::refreshTooltip(const ItemStack& stack, const ItemDef& item) {
|
void SlotView::refreshTooltip(const ItemStack& stack, const ItemDef& item) {
|
||||||
itemid_t itemid = stack.getItemId();
|
itemid_t itemid = stack.getItemId();
|
||||||
dv::value* caption = stack.getField("caption");
|
std::wstring caption = get_caption_string(stack, item);
|
||||||
dv::value* description = stack.getField("description");
|
std::wstring cached_caption = get_caption_string(cache.stack, item);
|
||||||
if (
|
std::wstring description = get_description_string(stack, item);
|
||||||
itemid == cache.stack.getItemId() &&
|
std::wstring cached_description = get_description_string(cache.stack, item);
|
||||||
caption == cache.stack.getField("caption") &&
|
|
||||||
description == cache.stack.getField("description")
|
if (itemid == cache.stack.getItemId() && cached_caption == caption && cached_description == description) {
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (itemid) {
|
if (itemid) {
|
||||||
std::wstring captionText;
|
if (description.length() > 0) {
|
||||||
std::wstring descriptionText;
|
tooltip = caption + L"\n" + description;
|
||||||
|
|
||||||
if (description != nullptr) {
|
|
||||||
descriptionText = util::pascal_case(
|
|
||||||
langs::get(util::str2wstr_utf8(description->asString()))
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
descriptionText = util::pascal_case(
|
tooltip = caption;
|
||||||
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))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptionText.length() > 0) {
|
|
||||||
tooltip = captionText + L"\n" + descriptionText;
|
|
||||||
} else {
|
|
||||||
tooltip = captionText;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tooltip.clear();
|
tooltip.clear();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user