Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.agmpenguin.mcphone.client.screen;
- import net.agmpenguin.mcphone.MCPhone;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.GuiGraphics;
- import net.minecraft.client.gui.components.*;
- import net.minecraft.client.gui.screens.Screen;
- import net.minecraft.network.chat.Component;
- import net.minecraft.resources.ResourceLocation;
- import net.minecraft.world.level.Level;
- import org.jetbrains.annotations.NotNull;
- import java.util.function.Supplier;
- // import static net.minecraft.client.Minecraft.getInstance;
- public class PhoneScreen extends Screen {
- private static final Component TITLE =
- Component.translatable("gui." + MCPhone.MOD_ID + ".phone_screen");
- private static final Component EXAMPLE_BUTTON =
- Component.translatable("gui." + MCPhone.MOD_ID + ".phone_screen.button.example_button");
- private static final Component EXAMPLE_IMAGE_BUTTON =
- Component.translatable("gui." + MCPhone.MOD_ID + ".phone_screen.image_button.example_button_2");
- private static final Component SETTINGS_BUTTON =
- Component.translatable("gui." + MCPhone.MOD_ID + ".phone_screen.image_button.settings_button");
- private static final ResourceLocation TEXTURE = new ResourceLocation(MCPhone.MOD_ID, "textures/gui/phone_home_screen_1.png");
- private static final ResourceLocation TEXTURE2 = new ResourceLocation(MCPhone.MOD_ID, "textures/gui/example_button_4.png");
- private static final ResourceLocation SETTINGSTEXTURE = new ResourceLocation(MCPhone.MOD_ID, "textures/gui/settings_button_temp.png");
- private final int imageWidth, imageHeight;
- private int leftPos, topPos;
- private Button button;
- private ImageButton imageButton, settingsBtn;
- public PhoneScreen() {
- super(TITLE);
- this.imageWidth = 142;
- this.imageHeight = 256;
- }
- @Override
- protected void init() {
- super.init();
- this.leftPos = (this.width - this.imageWidth) / 2;
- this.topPos = (this.height - this.imageHeight) / 2;
- assert this.minecraft != null;
- Level level = this.minecraft.level;
- assert level != null;
- this.button = addRenderableWidget(
- Button.builder(
- EXAMPLE_BUTTON, this::handleExampleButton)
- .bounds(this.leftPos + 50, this.topPos + 100, 80, 20)
- .tooltip(Tooltip.create(EXAMPLE_BUTTON))
- .build());
- this.imageButton = addRenderableWidget(new ImageButton(this.leftPos + 50, this.topPos + 120, 80, 80, 0, 0, 80, TEXTURE2, 80, 160, this::handleExampleImageButton, EXAMPLE_IMAGE_BUTTON));
- this.settingsBtn = addRenderableWidget(new ImageButton(this.leftPos + 10, this.topPos + 40, 30, 30, 0, 0, 30, SETTINGSTEXTURE, 30, 60, this::handleSettingsBtn));
- this.settingsBtn.setTooltip(Tooltip.create(SETTINGS_BUTTON));
- print("imageButton: " + this.imageButton.getTabOrderGroup() + ", settingsBtn: " + this.settingsBtn.getTabOrderGroup() + ", imageButton: " + this.imageButton.isHovered() + ", settingsBtn: " + this.settingsBtn.isHovered());
- assert this.minecraft.player != null;
- this.minecraft.player.sendSystemMessage(Component.literal("TEST"));
- }
- @Override
- public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
- assert this.minecraft != null;
- renderBackground(graphics);
- graphics.blit(TEXTURE, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight);
- super.render(graphics, mouseX, mouseY, partialTicks);
- graphics.drawString(this.font,
- TITLE,
- this.leftPos + 8,
- this.topPos + 8,
- 0xff00ff,
- false);
- }
- private void handleExampleButton(Button button) {
- print("Unladen Swallow: 3");
- }
- private void handleExampleImageButton(Button button) {
- print("Unladen Swallow: 4");
- print("imageButton: " + this.imageButton.getTabOrderGroup() + ", settingsBtn: " + this.settingsBtn.getTabOrderGroup() + ", imageButton: " + this.imageButton.isHovered() + ", settingsBtn: " + this.settingsBtn.isHovered());
- }
- private void handleSettingsBtn(Button button) {
- print("Unladen Swallow: 5");
- print("imageButton: " + this.imageButton.getTabOrderGroup() + ", settingsBtn: " + this.settingsBtn.getTabOrderGroup() + ", imageButton: " + this.imageButton.isHovered() + ", settingsBtn: " + this.settingsBtn.isHovered());
- assert this.minecraft != null;
- this.minecraft.setScreen(new SettingsScreen());
- // this.minecraft.setScreen((Screen)null);
- }
- @Override
- public boolean isPauseScreen() {
- return false;
- }
- public static void print(String text) {
- System.out.println(text);
- }
- }
Add Comment
Please, Sign In to add comment