AGMPenguin

PhoneScreen

Sep 25th, 2023
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.88 KB | Source Code | 0 0
  1. package net.agmpenguin.mcphone.client.screen;
  2.  
  3. import net.agmpenguin.mcphone.MCPhone;
  4. import net.minecraft.client.Minecraft;
  5. import net.minecraft.client.gui.GuiGraphics;
  6. import net.minecraft.client.gui.components.*;
  7. import net.minecraft.client.gui.screens.Screen;
  8. import net.minecraft.network.chat.Component;
  9. import net.minecraft.resources.ResourceLocation;
  10. import net.minecraft.world.level.Level;
  11. import org.jetbrains.annotations.NotNull;
  12.  
  13. import java.util.function.Supplier;
  14.  
  15. // import static net.minecraft.client.Minecraft.getInstance;
  16.  
  17. public class PhoneScreen extends Screen {
  18.     private static final Component TITLE =
  19.             Component.translatable("gui." + MCPhone.MOD_ID + ".phone_screen");
  20.     private static final Component EXAMPLE_BUTTON =
  21.             Component.translatable("gui." + MCPhone.MOD_ID + ".phone_screen.button.example_button");
  22.     private static final Component EXAMPLE_IMAGE_BUTTON =
  23.             Component.translatable("gui." + MCPhone.MOD_ID + ".phone_screen.image_button.example_button_2");
  24.     private static final Component SETTINGS_BUTTON =
  25.             Component.translatable("gui." + MCPhone.MOD_ID + ".phone_screen.image_button.settings_button");
  26.  
  27.     private static final ResourceLocation TEXTURE = new ResourceLocation(MCPhone.MOD_ID, "textures/gui/phone_home_screen_1.png");
  28.     private static final ResourceLocation TEXTURE2 = new ResourceLocation(MCPhone.MOD_ID, "textures/gui/example_button_4.png");
  29.     private static final ResourceLocation SETTINGSTEXTURE = new ResourceLocation(MCPhone.MOD_ID, "textures/gui/settings_button_temp.png");
  30.  
  31.     private final int imageWidth, imageHeight;
  32.  
  33.     private int leftPos, topPos;
  34.  
  35.     private Button button;
  36.  
  37.     private ImageButton imageButton, settingsBtn;
  38.  
  39.     public PhoneScreen() {
  40.         super(TITLE);
  41.  
  42.         this.imageWidth = 142;
  43.         this.imageHeight = 256;
  44.     }
  45.  
  46.     @Override
  47.     protected void init() {
  48.         super.init();
  49.  
  50.         this.leftPos = (this.width - this.imageWidth) / 2;
  51.         this.topPos = (this.height - this.imageHeight) / 2;
  52.  
  53.         assert this.minecraft != null;
  54.         Level level = this.minecraft.level;
  55.         assert level != null;
  56.  
  57.         this.button = addRenderableWidget(
  58.                 Button.builder(
  59.                         EXAMPLE_BUTTON, this::handleExampleButton)
  60.                         .bounds(this.leftPos + 50, this.topPos + 100, 80, 20)
  61.                         .tooltip(Tooltip.create(EXAMPLE_BUTTON))
  62.                         .build());
  63.  
  64.  
  65.         this.imageButton = addRenderableWidget(new ImageButton(this.leftPos + 50, this.topPos + 120, 80, 80, 0, 0, 80, TEXTURE2, 80, 160, this::handleExampleImageButton, EXAMPLE_IMAGE_BUTTON));
  66.         this.settingsBtn = addRenderableWidget(new ImageButton(this.leftPos + 10, this.topPos + 40, 30, 30, 0, 0, 30, SETTINGSTEXTURE, 30, 60, this::handleSettingsBtn));
  67.         this.settingsBtn.setTooltip(Tooltip.create(SETTINGS_BUTTON));
  68.         print("imageButton: " + this.imageButton.getTabOrderGroup() + ", settingsBtn: " + this.settingsBtn.getTabOrderGroup() + ", imageButton: " + this.imageButton.isHovered() + ", settingsBtn: " + this.settingsBtn.isHovered());
  69.         assert this.minecraft.player != null;
  70.         this.minecraft.player.sendSystemMessage(Component.literal("TEST"));
  71.     }
  72.  
  73.     @Override
  74.     public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
  75.         assert this.minecraft != null;
  76.         renderBackground(graphics);
  77.         graphics.blit(TEXTURE, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight);
  78.         super.render(graphics, mouseX, mouseY, partialTicks);
  79.  
  80.         graphics.drawString(this.font,
  81.                 TITLE,
  82.                 this.leftPos + 8,
  83.                 this.topPos + 8,
  84.                 0xff00ff,
  85.                 false);
  86.     }
  87.  
  88.     private void handleExampleButton(Button button) {
  89.         print("Unladen Swallow: 3");
  90.     }
  91.  
  92.     private void handleExampleImageButton(Button button) {
  93.         print("Unladen Swallow: 4");
  94.         print("imageButton: " + this.imageButton.getTabOrderGroup() + ", settingsBtn: " + this.settingsBtn.getTabOrderGroup() + ", imageButton: " + this.imageButton.isHovered() + ", settingsBtn: " + this.settingsBtn.isHovered());
  95.     }
  96.  
  97.     private void handleSettingsBtn(Button button) {
  98.         print("Unladen Swallow: 5");
  99.         print("imageButton: " + this.imageButton.getTabOrderGroup() + ", settingsBtn: " + this.settingsBtn.getTabOrderGroup() + ", imageButton: " + this.imageButton.isHovered() + ", settingsBtn: " + this.settingsBtn.isHovered());
  100.         assert this.minecraft != null;
  101.         this.minecraft.setScreen(new SettingsScreen());
  102.         // this.minecraft.setScreen((Screen)null);
  103.     }
  104.  
  105.     @Override
  106.     public boolean isPauseScreen() {
  107.         return false;
  108.     }
  109.    
  110.     public static void print(String text) {
  111.         System.out.println(text);
  112.     }
  113. }
Add Comment
Please, Sign In to add comment