Guest User

Gui class

a guest
Dec 31st, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. package com.theundertaker11.GeneticsReborn.blocks.cellanalyser;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.client.gui.inventory.GuiContainer;
  5. import net.minecraft.client.renderer.GlStateManager;
  6. import net.minecraft.entity.player.InventoryPlayer;
  7. import net.minecraft.util.ResourceLocation;
  8. import net.minecraftforge.fml.relauncher.Side;
  9. import net.minecraftforge.fml.relauncher.SideOnly;
  10.  
  11. import java.awt.*;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14.  
  15. import com.theundertaker11.GeneticsReborn.Reference;
  16.  
  17.  
  18. @SideOnly(Side.CLIENT)
  19. public class GuiCellAnalyser extends GuiContainer {
  20.  
  21. // This is the resource location for the background image
  22. private static final ResourceLocation texture = new ResourceLocation(Reference.MODID, "textures/gui/GuiCellAnalyser_bg.png");
  23. private GRTileEntityCellAnalyser tileEntity;
  24.  
  25. public GuiCellAnalyser(InventoryPlayer invPlayer, GRTileEntityCellAnalyser tileInventory){
  26. super(new ContainerCellAnalyser(invPlayer, tileInventory));
  27.  
  28. // Set the width and height of the gui
  29. xSize = 176;
  30. ySize = 207;
  31.  
  32. this.tileEntity = tileInventory;
  33. }
  34.  
  35. // some [x,y] coordinates of graphical elements
  36. final int COOK_BAR_XPOS = 49;
  37. final int COOK_BAR_YPOS = 60;
  38. final int COOK_BAR_ICON_U = 0; // texture position of white arrow icon
  39. final int COOK_BAR_ICON_V = 207;
  40. final int COOK_BAR_WIDTH = 80;
  41. final int COOK_BAR_HEIGHT = 17;
  42.  
  43. final int FLAME_XPOS = 54;
  44. final int FLAME_YPOS = 80;
  45. final int FLAME_ICON_U = 176; // texture position of flame icon
  46. final int FLAME_ICON_V = 0;
  47. final int FLAME_WIDTH = 14;
  48. final int FLAME_HEIGHT = 14;
  49. final int FLAME_X_SPACING = 18;
  50.  
  51. @Override
  52. protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
  53. // Bind the image texture
  54. Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
  55. // Draw the image
  56. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  57. drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
  58.  
  59. // get cook progress as a double between 0 and 1
  60. double cookProgress = tileEntity.percComplete();
  61. // draw the cook progress bar
  62. drawTexturedModalRect(guiLeft + COOK_BAR_XPOS, guiTop + COOK_BAR_YPOS, COOK_BAR_ICON_U, COOK_BAR_ICON_V,
  63. (int)(cookProgress * COOK_BAR_WIDTH), COOK_BAR_HEIGHT);
  64.  
  65. // draw the fuel remaining bar for each fuel slot flame
  66. double energyRemaining = tileEntity.fractionOfEnergyRemaining();
  67. int yOffset = (int)((1.0 - energyRemaining) * FLAME_HEIGHT);
  68. drawTexturedModalRect(guiLeft + FLAME_XPOS + FLAME_X_SPACING * 0, guiTop + FLAME_YPOS + yOffset,
  69. FLAME_ICON_U, FLAME_ICON_V + yOffset, FLAME_WIDTH, FLAME_HEIGHT - yOffset);
  70. }
  71.  
  72. @Override
  73. protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
  74. super.drawGuiContainerForegroundLayer(mouseX, mouseY);
  75.  
  76. final int LABEL_XPOS = 5;
  77. final int LABEL_YPOS = 5;
  78. fontRendererObj.drawString("Cell Analyser", LABEL_XPOS, LABEL_YPOS, Color.darkGray.getRGB());
  79.  
  80. List<String> hoveringText = new ArrayList<String>();
  81.  
  82. // If the mouse is over the progress bar add the progress bar hovering text
  83. if (isInRect(guiLeft + COOK_BAR_XPOS, guiTop + COOK_BAR_YPOS, COOK_BAR_WIDTH, COOK_BAR_HEIGHT, mouseX, mouseY))
  84. {
  85. hoveringText.add("Progress:");
  86. int cookPercentage =(int)(tileEntity.percComplete() * 100);
  87. hoveringText.add(cookPercentage + "%");
  88. }
  89.  
  90. // If the mouse is over one of the burn time indicator add the burn time indicator hovering text
  91.  
  92. if (isInRect(guiLeft + FLAME_XPOS + FLAME_X_SPACING * 0, guiTop + FLAME_YPOS, FLAME_WIDTH, FLAME_HEIGHT, mouseX, mouseY))
  93. {
  94. hoveringText.add("Energy:");
  95. hoveringText.add(tileEntity.getEnergyStored(null) + " RF");
  96. }
  97.  
  98. // If hoveringText is not empty draw the hovering text
  99. if (!hoveringText.isEmpty()){
  100. drawHoveringText(hoveringText, mouseX - guiLeft, mouseY - guiTop, fontRendererObj);
  101. }
  102. // // You must re bind the texture and reset the colour if you still need to use it after drawing a string
  103. // Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
  104. // GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  105.  
  106. }
  107.  
  108. // Returns true if the given x,y coordinates are within the given rectangle
  109. public static boolean isInRect(int x, int y, int xSize, int ySize, int mouseX, int mouseY){
  110. return ((mouseX >= x && mouseX <= x+xSize) && (mouseY >= y && mouseY <= y+ySize));
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment