This repository has been archived by the owner on Oct 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/moe/caa/fabric/quitconfirm/client/screen/confirm/style/BedrockStyle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package moe.caa.fabric.quitconfirm.client.screen.confirm.style; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.gui.DrawableHelper; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.screen.ScreenTexts; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.awt.*; | ||
|
||
public class BedrockStyle extends BaseStyle { | ||
private static final Identifier WINDOW_TEXTURE = new Identifier("quitconfirm", "textures/gui/bedrock/window.png"); | ||
private static final Identifier BACKGROUND = new Identifier("quitconfirm", "textures/gui/bedrock/background.png"); | ||
|
||
// 窗口宽度 | ||
private static final int windowWidth = 252; | ||
// 窗口长度 | ||
private static final int windowHeight = 140; | ||
// 按钮旁边距 | ||
private static final int buttonLRMargin = 20; | ||
// 按钮下边距 | ||
private static final int buttonBMargin = 20; | ||
// 按钮宽度 | ||
private static final int buttonWidth = 100; | ||
// 按钮长度 | ||
private static final int buttonHeight = 20; | ||
// 信息文本下边距 | ||
private static final int messageBMargin = 100; | ||
|
||
@Override | ||
public ButtonWidget generateConfirmButtons(Screen screen, ButtonWidget.PressAction onConfirm) { | ||
return ButtonWidget.builder(ScreenTexts.YES, onConfirm) | ||
.dimensions((screen.width - windowWidth) / 2 + windowWidth - buttonWidth - buttonLRMargin, | ||
(screen.height - windowHeight) / 2 + windowHeight - buttonBMargin - buttonHeight, | ||
buttonWidth, buttonHeight).build(); | ||
} | ||
|
||
@Override | ||
public ButtonWidget generateCancelButtons(Screen screen, ButtonWidget.PressAction onCancel) { | ||
return ButtonWidget.builder(ScreenTexts.NO, onCancel) | ||
.dimensions((screen.width - windowWidth) / 2 + buttonLRMargin, | ||
(screen.height - windowHeight) / 2 + windowHeight - buttonBMargin - buttonHeight, | ||
buttonWidth, buttonHeight).build(); | ||
} | ||
|
||
|
||
@Override | ||
public void render(MinecraftClient client, TextRenderer textRenderer, Screen screen, Text title, Text message, | ||
MatrixStack matrices, int mouseX, int mouseY, float delta) { | ||
drawBackground(client, screen, matrices); | ||
drawWindow(textRenderer, title, matrices, (screen.width - windowWidth) / 2, (screen.height - windowHeight) / 2); | ||
drawMessage(textRenderer, screen, message, matrices); | ||
} | ||
|
||
private void drawBackground(MinecraftClient client, Screen screen, MatrixStack matrices) { | ||
if (client.world != null) { | ||
fillGradient(matrices, 0, 0, screen.width, screen.height, -1072689136, -804253680); | ||
} else { | ||
screen.renderBackground(matrices); | ||
DrawableHelper.fill(matrices, 0, 0, screen.width, screen.height, new Color(16, 16, 16, 179).getRGB()); | ||
} | ||
} | ||
|
||
private void drawWindow(TextRenderer textRenderer, Text title, MatrixStack matrices, int x, int y) { | ||
renderBackground(x, y, x + windowWidth, y + windowHeight, BACKGROUND); | ||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
RenderSystem.enableBlend(); | ||
RenderSystem.setShaderTexture(0, WINDOW_TEXTURE); | ||
drawTexture(matrices, x, y, 0, 0, 252, 140); | ||
textRenderer.draw(matrices, title, (float) (x + 8), (float) (y + 6), 4210752); | ||
} | ||
|
||
|
||
private void drawMessage(TextRenderer textRenderer, Screen screen, Text message, MatrixStack matrices) { | ||
drawCenteredTextWithShadow(matrices, textRenderer, message, | ||
screen.width / 2, | ||
(screen.height - windowHeight) / 2 + windowHeight - messageBMargin, | ||
10526880); | ||
} | ||
} |
File renamed without changes
File renamed without changes