mirror of
https://github.com/Shiewk/BedrockDeathScreen.git
synced 2026-04-27 22:44:17 +02:00
Change cursor to hand when hovering buttons, fix text and buttons flickering
This commit is contained in:
@@ -12,11 +12,14 @@ import net.minecraft.util.Formatting;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class BedrockDeathScreen extends DeathScreen {
|
public class BedrockDeathScreen extends DeathScreen {
|
||||||
|
|
||||||
|
public static final long CURSOR_HAND = GLFW.glfwCreateStandardCursor(GLFW.GLFW_POINTING_HAND_CURSOR);
|
||||||
|
|
||||||
private final long screenCreationTime;
|
private final long screenCreationTime;
|
||||||
private final Text message;
|
private final Text message;
|
||||||
private Text scoreText = Text.empty();
|
private Text scoreText = Text.empty();
|
||||||
@@ -27,6 +30,7 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
private final Identifier SOUND = Identifier.of("minecraft", "ui.button.click");
|
private final Identifier SOUND = Identifier.of("minecraft", "ui.button.click");
|
||||||
private final int deg = (int) (Math.random() * 360);
|
private final int deg = (int) (Math.random() * 360);
|
||||||
private boolean confirmingExit = false;
|
private boolean confirmingExit = false;
|
||||||
|
private boolean wasHoveringButtons = false;
|
||||||
|
|
||||||
public BedrockDeathScreen(@Nullable Text message, boolean isHardcore) {
|
public BedrockDeathScreen(@Nullable Text message, boolean isHardcore) {
|
||||||
super(message, isHardcore);
|
super(message, isHardcore);
|
||||||
@@ -157,32 +161,44 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||||
final float totalDelta = getTotalScreenTime();
|
boolean hoveringButton = hoversMenuButton(mouseX, mouseY) || hoversRespawn(mouseX, mouseY);
|
||||||
context.fill(0, 0, width, height, new Color(0, 0, 0, (int) Math.min(80, totalDelta/4f)).getRGB());
|
if (hoveringButton != wasHoveringButtons){
|
||||||
if (totalDelta > 750.0f){
|
wasHoveringButtons = hoveringButton;
|
||||||
final int backOpacity = (int) Math.min(255, (totalDelta - 750f) / 10f);
|
assert client != null;
|
||||||
|
long window = client.getWindow().getHandle();
|
||||||
|
if (hoveringButton){
|
||||||
|
GLFW.glfwSetCursor(window, CURSOR_HAND);
|
||||||
|
} else {
|
||||||
|
GLFW.glfwSetCursor(window, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final float totalScreenTime = getTotalScreenTime();
|
||||||
|
context.fill(0, 0, width, height, new Color(0, 0, 0, (int) Math.min(80, totalScreenTime/4f)).getRGB());
|
||||||
|
if (totalScreenTime > 750.0f){
|
||||||
|
final int backOpacity = (int) Math.min(255, (totalScreenTime - 750f) / 10f);
|
||||||
context.fill(0, 0, width, height, new Color(155, 0, 0, (int) (backOpacity/2.5)).getRGB());
|
context.fill(0, 0, width, height, new Color(155, 0, 0, (int) (backOpacity/2.5)).getRGB());
|
||||||
|
|
||||||
final int textOpacity = (int) Math.min(255, (totalDelta - 750f) / 3f);
|
final int textOpacity = (int) Math.min(255, (totalScreenTime - 750f) / 3f);
|
||||||
if (textOpacity > 0){
|
if (textOpacity > 3){
|
||||||
context.getMatrices().push();
|
context.getMatrices().push();
|
||||||
context.getMatrices().scale(2F, 2F, 2F);
|
context.getMatrices().scale(2F, 2F, 2F);
|
||||||
context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2 / 2, (int) (this.height / 3.5 / 2 - 10), new Color(255, 255, 255, textOpacity).getRGB());
|
context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2 / 2, (int) (this.height / 3.5 / 2 - 10), new Color(255, 255, 255, textOpacity).getRGB());
|
||||||
context.getMatrices().pop();
|
context.getMatrices().pop();
|
||||||
context.drawCenteredTextWithShadow(this.textRenderer, this.message, this.width / 2, (int) (this.height / 3.5), new Color(255, 255, 255, textOpacity).getRGB());
|
context.drawCenteredTextWithShadow(this.textRenderer, this.message, this.width / 2, (int) (this.height / 3.5), new Color(255, 255, 255, textOpacity).getRGB());
|
||||||
}
|
}
|
||||||
final int scoreTextOpacity = (int) Math.min(255, (totalDelta - 1250f) / 3f);
|
final int scoreTextOpacity = (int) Math.min(255, (totalScreenTime - 1250f) / 3f);
|
||||||
if (scoreTextOpacity > 0){
|
if (scoreTextOpacity > 3){
|
||||||
context.drawCenteredTextWithShadow(this.textRenderer, this.scoreText, this.width / 2, (int) (this.height / 3.5) + 12, new Color(255, 255, 255, scoreTextOpacity).getRGB());
|
context.drawCenteredTextWithShadow(this.textRenderer, this.scoreText, this.width / 2, (int) (this.height / 3.5) + 12, new Color(255, 255, 255, scoreTextOpacity).getRGB());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!confirmingExit){
|
if (!confirmingExit){
|
||||||
if (totalDelta > 1250f){
|
if (totalScreenTime > 1259f){
|
||||||
float respawnOpacity = (int) Math.min(255, (totalDelta - 1250f) / 3f);
|
float respawnOpacity = (int) Math.min(255, (totalScreenTime - 1250f) / 3f);
|
||||||
renderRespawnButton(context, mouseX, mouseY, respawnOpacity);
|
renderRespawnButton(context, mouseX, mouseY, respawnOpacity);
|
||||||
}
|
}
|
||||||
if (totalDelta > 1750f){
|
if (totalScreenTime > 1759f){
|
||||||
float menuOpacity = (int) Math.min(255, (totalDelta - 1750f) / 3f);
|
float menuOpacity = (int) Math.min(255, (totalScreenTime - 1750f) / 3f);
|
||||||
renderMenuButton(context, mouseX, mouseY, menuOpacity);
|
renderMenuButton(context, mouseX, mouseY, menuOpacity);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -262,4 +278,20 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
final double ep = Math.pow(e, del);
|
final double ep = Math.pow(e, del);
|
||||||
return (float) (ep / (1d + ep) * 7d + 2d);
|
return (float) (ep / (1d + ep) * 7d + 2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
assert client != null;
|
||||||
|
long window = client.getWindow().getHandle();
|
||||||
|
GLFW.glfwSetCursor(window, 0);
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removed() {
|
||||||
|
assert client != null;
|
||||||
|
long window = client.getWindow().getHandle();
|
||||||
|
GLFW.glfwSetCursor(window, 0);
|
||||||
|
super.removed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user