use of net.minecraft.text.StringVisitable in project MiniMap by pl3xgaming.
the class Tab method render.
@Override
public void render(MatrixStack matrixStack, float mouseX, float mouseY, float delta) {
super.render(matrixStack, mouseX, mouseY, delta);
icon().tint(matrixStack, iconX(), iconY(), iconSize(), color());
if (width() > Sidebar.DEFAULT_WIDTH) {
if (width() < Sidebar.HOVER_WIDTH) {
// only trim text if sidebar is between open and
// closed states since this is sort of expensive
StringVisitable str = Font.RALEWAY.trimToWidth(text(), (int) (width() - textX()));
for (OrderedText orderedText : Font.RALEWAY.wrapLines(str, Integer.MAX_VALUE)) {
Font.RALEWAY.draw(matrixStack, orderedText, textX(), textY(), color());
}
} else {
Font.RALEWAY.draw(matrixStack, text(), textX(), textY(), color());
}
}
if (hovered()) {
Mouse.INSTANCE.cursor(Cursor.HAND_POINTER);
}
}
use of net.minecraft.text.StringVisitable in project BleachHack by BleachDrinker420.
the class UpdateScreen method init.
public void init() {
super.init();
int wd = Math.min(width / 2 - 30, 175);
addWindow(new Window(width / 2 - wd, height / 16, width / 2 + wd, height - height / 16, String.format("BleachHack Update [%s -> %s]", BleachHack.VERSION, updateJson.get("name").getAsString()), new ItemStack(Items.MAGENTA_GLAZED_TERRACOTTA)));
int w = getWindow(0).x2 - getWindow(0).x1;
int h = getWindow(0).y2 - getWindow(0).y1;
getWindow(0).addWidget(new WindowTextWidget("A new BleachHack update is available.", true, WindowTextWidget.TextAlign.MIDDLE, 1.5f, w / 2, 18, 0xe0e0e0));
getWindow(0).addWidget(new WindowBoxWidget(3, 50, w - 3, h - 23));
ImmutablePairList<String, Boolean> changelog = new ImmutablePairList<>();
if (updateJson.has("changelog") && updateJson.get("changelog").isJsonArray()) {
for (JsonElement je : updateJson.get("changelog").getAsJsonArray()) {
if (je.isJsonPrimitive()) {
String string = je.getAsString();
if (string.charAt(0) == '-')
string = "\u00a77-\u00a7r" + string.substring(1);
List<StringVisitable> wrapped = client.textRenderer.getTextHandler().wrapLines(string, w - 32, Style.EMPTY);
for (int i = 0; i < wrapped.size(); i++) changelog.add(wrapped.get(i).getString(), i == 0);
}
}
} else {
changelog.add("Could not find changelog.", false);
}
changelogWidgets.clear();
changelogWidgets.add(getWindow(0).addWidget(new WindowTextWidget(updateJson.get("name").getAsString(), true, WindowTextWidget.TextAlign.MIDDLE, 2.5f, w / 2, 58, 0xe0e0e0)));
for (int i = 0; i < changelog.size(); i++) {
if (changelog.get(i).getValue()) {
changelogWidgets.add(getWindow(0).addWidget(new WindowTextWidget("*", true, 10, 87 + i * 10, 0xa0a0a0)));
}
changelogWidgets.add(getWindow(0).addWidget(new WindowTextWidget(changelog.get(i).getKey(), true, 19, 85 + i * 10, 0xe0e0e0)));
}
scrollbar = getWindow(0).addWidget(new WindowScrollbarWidget(w - 14, 51, 37 + changelog.size() * 10, h - 75, 0));
getWindow(0).addWidget(new WindowButtonWidget(3, h - 21, w / 2 - 2, h - 3, "Website", () -> Util.getOperatingSystem().open(URI.create("https://bleachhack.org/"))));
getWindow(0).addWidget(new WindowButtonWidget(w / 2 + 2, h - 21, w - 3, h - 3, "Update", () -> {
try {
JsonObject installerJson = updateJson.get("installer").getAsJsonObject();
if (installerJson.has("os") && installerJson.get("os").isJsonPrimitive() && !System.getProperty("os.name").startsWith(installerJson.get("os").getAsString())) {
updateResult = "Updater doesn't support your OS!";
selectWindow(1);
return;
}
File modpath = new File(FabricLoader.getInstance().getModContainer("bleachhack").get().getOrigin().getPaths().get(0).toUri());
if (!modpath.isFile()) {
updateResult = "Invalid mod path!";
selectWindow(1);
return;
}
String link = installerJson.get("link").getAsString();
String name = link.replaceFirst("^.*\\/", "");
File installerFile = new File(System.getProperty("java.io.tmpdir"), name);
BleachLogger.logger.info("\n> Installer path: " + installerFile + "\n> Installer URL: " + link + "\n> Installer file name: " + name + "\n> Regular File: " + Files.isRegularFile(installerFile.toPath()) + "\n> File Length: " + installerFile.length());
if (!Files.isRegularFile(installerFile.toPath()) || installerFile.length() <= 1024L) {
FileUtils.copyURLToFile(new URL(link), installerFile);
}
String execCommand = link.endsWith(".jar") ? "java -jar " : "cmd /c start ";
Runtime.getRuntime().exec(execCommand + installerFile.getAbsolutePath() + " " + modpath + " " + installerJson.get("url").getAsString());
client.scheduleStop();
} catch (Exception e) {
updateResult = "Unknown error!";
selectWindow(1);
e.printStackTrace();
}
}));
wd = Math.min(width / 2 - 20, 90);
addWindow(new Window(width / 2 - wd, height / 2 - 15, width / 2 + wd, height / 2 + 15, "Error updating!", new ItemStack(Items.RED_BANNER), true));
getWindow(1).addWidget(new WindowTextWidget("", true, WindowTextWidget.TextAlign.MIDDLE, wd, 16, 0xc05050).withRenderEvent((wg, ms, wx, wy) -> ((WindowTextWidget) wg).setText(new LiteralText(updateResult))));
}
use of net.minecraft.text.StringVisitable in project Polymorph by TheIllusiveC4.
the class SelectionWidget method drawHoveringText.
public static void drawHoveringText(MatrixStack mStack, List<? extends StringVisitable> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, int backgroundColor, int borderColorStart, int borderColorEnd, TextRenderer font) {
if (!textLines.isEmpty()) {
RenderSystem.disableDepthTest();
int tooltipTextWidth = 0;
for (StringVisitable textLine : textLines) {
int textLineWidth = font.getWidth(textLine);
if (textLineWidth > tooltipTextWidth) {
tooltipTextWidth = textLineWidth;
}
}
boolean needsWrap = false;
int titleLinesCount = 1;
int tooltipX = mouseX + 12;
if (tooltipX + tooltipTextWidth + 4 > screenWidth) {
tooltipX = mouseX - 16 - tooltipTextWidth;
if (tooltipX < 4) {
if (mouseX > screenWidth / 2) {
tooltipTextWidth = mouseX - 12 - 8;
} else {
tooltipTextWidth = screenWidth - 16 - mouseX;
}
needsWrap = true;
}
}
if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) {
tooltipTextWidth = maxTextWidth;
needsWrap = true;
}
if (needsWrap) {
int wrappedTooltipWidth = 0;
List<StringVisitable> wrappedTextLines = new ArrayList<>();
for (int i = 0; i < textLines.size(); i++) {
StringVisitable textLine = textLines.get(i);
List<StringVisitable> wrappedLine = font.getTextHandler().wrapLines(textLine, tooltipTextWidth, Style.EMPTY);
if (i == 0) {
titleLinesCount = wrappedLine.size();
}
for (StringVisitable line : wrappedLine) {
int lineWidth = font.getWidth(line);
if (lineWidth > wrappedTooltipWidth) {
wrappedTooltipWidth = lineWidth;
}
wrappedTextLines.add(line);
}
}
tooltipTextWidth = wrappedTooltipWidth;
textLines = wrappedTextLines;
if (mouseX > screenWidth / 2) {
tooltipX = mouseX - 16 - tooltipTextWidth;
} else {
tooltipX = mouseX + 12;
}
}
int tooltipY = mouseY - 12;
int tooltipHeight = 8;
if (textLines.size() > 1) {
tooltipHeight += (textLines.size() - 1) * 10;
if (textLines.size() > titleLinesCount) {
tooltipHeight += 2;
}
}
if (tooltipY < 4) {
tooltipY = 4;
} else if (tooltipY + tooltipHeight + 4 > screenHeight) {
tooltipY = screenHeight - tooltipHeight - 4;
}
final int zLevel = 900;
mStack.push();
Matrix4f mat = mStack.peek().getPositionMatrix();
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
drawGradientRect(mat, zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);
VertexConsumerProvider.Immediate renderType = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
mStack.translate(0.0D, 0.0D, zLevel);
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) {
StringVisitable line = textLines.get(lineNumber);
if (line != null) {
font.draw(Language.getInstance().reorder(line), (float) tooltipX, (float) tooltipY, -1, true, mat, renderType, false, 0, 15728880);
}
if (lineNumber + 1 == titleLinesCount) {
tooltipY += 2;
}
tooltipY += 10;
}
renderType.draw();
mStack.pop();
RenderSystem.enableDepthTest();
}
}
Aggregations