Guest User

Gui class

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