Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/net/vulkanmod/config/gui/VOptionScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.util.FormattedCharSequence;
import net.vulkanmod.Initializer;
import net.vulkanmod.config.UpdateChecker;
import net.vulkanmod.config.gui.render.GuiRenderer;
import net.vulkanmod.config.gui.util.SearchHelper;
Expand Down Expand Up @@ -44,6 +42,7 @@ public class VOptionScreen extends Screen {
private int tooltipX;
private int tooltipY;
private int tooltipWidth;
private long firstRenderTime = -1;

private VButtonWidget applyButton;
private VButtonWidget undoButton;
Expand Down Expand Up @@ -352,6 +351,10 @@ public void onClose() {

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
if (firstRenderTime == -1) {
firstRenderTime = System.currentTimeMillis();
}

GuiRenderer.guiGraphics = guiGraphics;
VRenderSystem.enableBlend();

Expand Down
97 changes: 87 additions & 10 deletions src/main/java/net/vulkanmod/config/gui/widget/ModIconWidget.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.vulkanmod.config.gui.widget;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.client.sounds.SoundManager;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.resources.Identifier;
Expand All @@ -22,19 +24,94 @@ public ModIconWidget(FormattedText name, Identifier icon, int x0, int y0, int wi
this.height = height;
}

@Override
public void playDownSound(SoundManager soundManager) {
}

public void render(double mX, double mY) {
int backgroundColor = ColorUtil.ARGB.multiplyAlpha(VGuiConstants.COLOR_BLACK, 0.6f);
int width = this.width;
int height = this.height;
GuiRenderer.fill(this.x, this.y, this.x + width, this.y + height, backgroundColor);
drawBackground();

int iconSize = height - 4;
int iconX = x + 4;
int iconY = y + (height - iconSize) / 2;

GuiRenderer.guiGraphics.blit(
RenderPipelines.GUI_TEXTURED,
icon,
iconX,
iconY,
0f,
0f,
iconSize,
iconSize,
iconSize,
iconSize
);

Font font = Minecraft.getInstance().font;
Component name = (Component) this.name;
int textX = iconX + iconSize + 2;
int textY = y + height / 2 - 4;

renderName(font, name, textX, textY);
}

private void drawBackground() {
int backgroundColor = ColorUtil.ARGB.multiplyAlpha(
VGuiConstants.COLOR_BLACK,
0.6f
);

GuiRenderer.fill(
x,
y,
x + width,
y + height,
backgroundColor
);
}

private void renderName(Font font, Component name, int textX, int textY) {
int textWidth = font.width(name);
int visibleWidth = (x + width - 4) - textX;
renderName(font, name, textX, textY, textWidth, visibleWidth);
}

private void renderName(
Font font,
Component name,
int textX,
int textY,
int textWidth,
int visibleWidth
) {
if (textWidth <= visibleWidth) {
drawText(font, name, textX, textY);
return;
}

GuiRenderer.enableScissor(
textX,
textY,
x + width - 4,
textY + font.lineHeight
);

int overflow = textWidth - visibleWidth;
long tick = System.currentTimeMillis() / 200;

int size = this.height - 4;
int iconX = this.x + 4;
int iconY = this.y + (height - size) / 2;
GuiRenderer.guiGraphics.blit(RenderPipelines.GUI_TEXTURED, icon, iconX, iconY, 0f, 0f, size, size, size, size);
int offset = (int) (tick % overflow);

int animatedX = ((tick / overflow) % 2 == 0)
? textX - offset
: textX - (overflow - offset);

drawText(font, name, animatedX, textY);

GuiRenderer.disableScissor();
}

size = this.height;
GuiRenderer.drawString(Minecraft.getInstance().font, (Component) this.name, this.x + 6 + size, this.y + this.height / 2 - 4, 0xffffffff);
private static void drawText(Font font, Component text, int x, int y) {
GuiRenderer.drawString(font, text, x, y, 0xFFFFFFFF);
}
}