diff --git a/Minecraft.Client/UI/Screens/AbstractContainerScreen.cpp b/Minecraft.Client/UI/Screens/AbstractContainerScreen.cpp index 53a81d19d..80e1ff815 100644 --- a/Minecraft.Client/UI/Screens/AbstractContainerScreen.cpp +++ b/Minecraft.Client/UI/Screens/AbstractContainerScreen.cpp @@ -112,8 +112,70 @@ void AbstractContainerScreen::render(int xm, int ym, float a) { // 4jcraft: extracted from render() into a standalone method so this can be used // in other derived classes +// update: also added 1.6.x era overloads (for the creative inventory and other +// places) +void AbstractContainerScreen::renderTooltipInternal( + const std::vector& cleanedLines, + const std::vector& lineColors, int mouseX, int mouseY) { + if (cleanedLines.empty()) return; + + int tooltipWidth = 0; + for (const auto& line : cleanedLines) { + int lineWidth = font->width(line); + if (lineWidth > tooltipWidth) tooltipWidth = lineWidth; + } + + int tooltipX = mouseX + 12; + int tooltipY = mouseY - 12; + int tooltipHeight = 8; + + if (cleanedLines.size() > 1) { + tooltipHeight += 2 + (cleanedLines.size() - 1) * 10; + } + + int bgColor = 0xf0100010; + fillGradient(tooltipX - 3, tooltipY - 4, tooltipX + tooltipWidth + 3, + tooltipY - 3, bgColor, bgColor); + fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 3, + tooltipX + tooltipWidth + 3, tooltipY + tooltipHeight + 4, + bgColor, bgColor); + fillGradient(tooltipX - 3, tooltipY - 3, tooltipX + tooltipWidth + 3, + tooltipY + tooltipHeight + 3, bgColor, bgColor); + fillGradient(tooltipX - 4, tooltipY - 3, tooltipX - 3, + tooltipY + tooltipHeight + 3, bgColor, bgColor); + fillGradient(tooltipX + tooltipWidth + 3, tooltipY - 3, + tooltipX + tooltipWidth + 4, tooltipY + tooltipHeight + 3, + bgColor, bgColor); + + int borderStart = 0x505000ff; + int borderFinish = (borderStart & 0xfefefe) >> 1 | borderStart & 0xff000000; + fillGradient(tooltipX - 3, (tooltipY - 3) + 1, (tooltipX - 3) + 1, + (tooltipY + tooltipHeight + 3) - 1, borderStart, borderFinish); + fillGradient(tooltipX + tooltipWidth + 2, (tooltipY - 3) + 1, + tooltipX + tooltipWidth + 3, + (tooltipY + tooltipHeight + 3) - 1, borderStart, borderFinish); + fillGradient(tooltipX - 3, tooltipY - 3, tooltipX + tooltipWidth + 3, + (tooltipY - 3) + 1, borderStart, borderStart); + fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 2, + tooltipX + tooltipWidth + 3, tooltipY + tooltipHeight + 3, + borderFinish, borderFinish); + + int currentY = tooltipY; + for (size_t lineIndex = 0; lineIndex < cleanedLines.size(); ++lineIndex) { + const std::wstring& currentLine = cleanedLines[lineIndex]; + int textColor = lineColors[lineIndex]; + + font->drawShadow(currentLine, tooltipX, currentY, textColor); + + if (lineIndex == 0) { + currentY += 2; + } + currentY += 10; + } +} + void AbstractContainerScreen::renderTooltip(std::shared_ptr item, - int x, int y) { + int mouseX, int mouseY) { if (item == nullptr) return; std::vector elementName; @@ -121,7 +183,6 @@ void AbstractContainerScreen::renderTooltip(std::shared_ptr item, item->getHoverText(minecraft->player, false, elementName); if (tooltipLines != NULL && tooltipLines->size() > 0) { - int tooltipWidth = 0; std::vector cleanedLines; std::vector lineColors; @@ -173,74 +234,38 @@ void AbstractContainerScreen::renderTooltip(std::shared_ptr item, cleanedLines.push_back(clean); lineColors.push_back(lineColor); - - int lineWidth = font->width(clean); - if (lineWidth > tooltipWidth) { - tooltipWidth = lineWidth; - } } - int tooltipX = x + 12; - int tooltipY = y - 12; - int tooltipHeight = 8; - - if (tooltipLines->size() > 1) { - tooltipHeight += 2 + (tooltipLines->size() - 1) * 10; + if (!cleanedLines.empty()) { + lineColors[0] = app.GetHTMLColour(item->getRarity()->color); } - int bgColor = 0xf0100010; - fillGradient(tooltipX - 3, tooltipY - 4, tooltipX + tooltipWidth + 3, - tooltipY - 3, bgColor, bgColor); - fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 3, - tooltipX + tooltipWidth + 3, tooltipY + tooltipHeight + 4, - bgColor, bgColor); - fillGradient(tooltipX - 3, tooltipY - 3, tooltipX + tooltipWidth + 3, - tooltipY + tooltipHeight + 3, bgColor, bgColor); - fillGradient(tooltipX - 4, tooltipY - 3, tooltipX - 3, - tooltipY + tooltipHeight + 3, bgColor, bgColor); - fillGradient(tooltipX + tooltipWidth + 3, tooltipY - 3, - tooltipX + tooltipWidth + 4, tooltipY + tooltipHeight + 3, - bgColor, bgColor); + renderTooltipInternal(cleanedLines, lineColors, mouseX, mouseY); + } +} - int borderStart = 0x505000ff; - int borderFinish = - (borderStart & 0xfefefe) >> 1 | borderStart & 0xff000000; - fillGradient(tooltipX - 3, (tooltipY - 3) + 1, (tooltipX - 3) + 1, - (tooltipY + tooltipHeight + 3) - 1, borderStart, - borderFinish); - fillGradient(tooltipX + tooltipWidth + 2, (tooltipY - 3) + 1, - tooltipX + tooltipWidth + 3, - (tooltipY + tooltipHeight + 3) - 1, borderStart, - borderFinish); - fillGradient(tooltipX - 3, tooltipY - 3, tooltipX + tooltipWidth + 3, - (tooltipY - 3) + 1, borderStart, borderStart); - fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 2, - tooltipX + tooltipWidth + 3, tooltipY + tooltipHeight + 3, - borderFinish, borderFinish); +void AbstractContainerScreen::renderTooltip( + const std::vector& lines, int mouseX, int mouseY) { + if (lines.empty()) return; - int currentY = tooltipY; - for (int lineIndex = 0; lineIndex < (int)tooltipLines->size(); - ++lineIndex) { - std::wstring& currentLine = cleanedLines[lineIndex]; - int textColor; + std::vector cleanedLines = lines; + std::vector lineColors; + lineColors.reserve(lines.size()); - if (lineIndex == 0) { - textColor = app.GetHTMLColour(item->getRarity()->color); - } else { - textColor = (lineColors[lineIndex] != 0xffffffff) - ? lineColors[lineIndex] - : 0xffaaaaaa; - } - - font->drawShadow(currentLine, tooltipX, currentY, textColor); - - if (lineIndex == 0) { - currentY += 2; - } - - currentY += 10; + for (size_t i = 0; i < lines.size(); ++i) { + if (i == 0) { + lineColors.push_back(0xffffffff); + } else { + lineColors.push_back(0xffaaaaaa); } } + + renderTooltipInternal(cleanedLines, lineColors, mouseX, mouseY); +} + +void AbstractContainerScreen::renderTooltip(const std::wstring& line, + int mouseX, int mouseY) { + renderTooltip(std::vector{line}, mouseX, mouseY); } void AbstractContainerScreen::renderLabels() {} diff --git a/Minecraft.Client/UI/Screens/AbstractContainerScreen.h b/Minecraft.Client/UI/Screens/AbstractContainerScreen.h index dcd2f4214..72f774ef6 100644 --- a/Minecraft.Client/UI/Screens/AbstractContainerScreen.h +++ b/Minecraft.Client/UI/Screens/AbstractContainerScreen.h @@ -33,7 +33,10 @@ protected: virtual bool isHoveringOver(int x, int y, int w, int h, int xm, int ym); virtual bool isHovering(Slot* slot, int xm, int ym); // 4jcraft: extracted from render() into a standalone method so this can be - // used in other classes + // used in other places + virtual void renderTooltipInternal( + const std::vector& cleanedLines, + const std::vector& lineColors, int mouseX, int mouseY); virtual void renderTooltip(std::shared_ptr item, int x, int y); @@ -50,4 +53,9 @@ public: virtual void slotsChanged(std::shared_ptr container); virtual bool isPauseScreen() override; virtual void tick() override; -}; \ No newline at end of file + + // 4jcraft: 1.6.x era overloads + virtual void renderTooltip(const std::vector& lines, int x, + int y); + virtual void renderTooltip(const std::wstring& line, int x, int y); +};