ThexXTURBOXx

Code

Apr 27th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. package de.thexxturboxx.craftoflegends.gui;
  2.  
  3. import java.io.IOException;
  4. import java.util.List;
  5.  
  6. import org.lwjgl.input.Keyboard;
  7. import org.lwjgl.input.Mouse;
  8. import org.lwjgl.opengl.GL11;
  9.  
  10. import de.thexxturboxx.craftoflegends.COLMod;
  11. import de.thexxturboxx.craftoflegends.COLRegistry;
  12. import de.thexxturboxx.craftoflegends.api.DataManager;
  13. import de.thexxturboxx.craftoflegends.api.PLAYER_PROPERTY;
  14. import de.thexxturboxx.craftoflegends.items.InvItem;
  15. import de.thexxturboxx.craftoflegends.util.Helpers;
  16. import net.minecraft.client.gui.GuiScreen;
  17. import net.minecraft.util.ResourceLocation;
  18. import scala.actors.threadpool.Arrays;
  19.  
  20. public class GuiShop extends GuiScreen {
  21.  
  22. int guiWidth = 256;
  23. int guiHeight = 137;
  24.  
  25. int realGuiWidth = 512;
  26. int realGuiHeight = 274;
  27.  
  28. int goldWidth = 32;
  29. int goldHeight = 16;
  30.  
  31. int scaleFactor = 2;
  32.  
  33. int scroll = 0;
  34. int itemsPerLine = 7;
  35. int linesPerGui = 7;
  36.  
  37. //GuiButton button;
  38.  
  39. @Override
  40. public void drawScreen(int x, int y, float ticks) {
  41. int guiX = ((width - realGuiWidth) / 2 / scaleFactor);
  42. int guiY = ((height - realGuiHeight) / 2 / scaleFactor);
  43. GL11.glColor4f(1, 1, 1, 1);
  44. drawDefaultBackground();
  45. mc.renderEngine.bindTexture(new ResourceLocation(COLMod.ID, "textures/gui/datageneral.png"));
  46. GL11.glScaled(scaleFactor, scaleFactor, scaleFactor);
  47. drawTexturedModalRect(guiX, guiY, 0, 0, guiWidth, guiHeight);
  48. String s = Integer.toString(DataManager.getProperty(mc.thePlayer.getUniqueID().toString(), PLAYER_PROPERTY.GOLD));
  49. int xx = (16 + fontRendererObj.getStringWidth(s)) / 2;
  50. drawTexturedModalRect(guiX + (guiWidth / 2) - xx, guiY + 2, 0, guiHeight, goldWidth, goldHeight);
  51. fontRendererObj.drawString(s, guiX + (guiWidth / 2) + xx, guiY + 4, 0xffffff, false);
  52. GL11.glScaled((1 / (double) scaleFactor), (1 / (double) scaleFactor), (1 / (double) scaleFactor));
  53. int c = 0;
  54. for(InvItem is : COLRegistry.itemList) {
  55. InvItem i = COLRegistry.itemList.get(scroll * itemsPerLine + c);
  56. if(c < itemsPerLine * 10) {
  57. ResourceLocation r = new ResourceLocation(COLMod.ID, "textures/items/" + i.getName() + ".png");
  58. drawNextItem(i, r, c++, itemsPerLine);
  59. }
  60. }
  61. super.drawScreen(x, y, ticks);
  62. }
  63.  
  64. protected void drawNextItem(InvItem i, ResourceLocation r, int number, int itemsPerLine) {
  65. int guiX = (width - realGuiWidth) / scaleFactor;
  66. int guiY = (height - realGuiHeight) / scaleFactor;
  67. GL11.glColor4f(1, 1, 1, 1);
  68. mc.renderEngine.bindTexture(r);
  69. int lineX = (number % itemsPerLine) + 1;
  70. int lineY = (number - lineX + 1) / itemsPerLine;
  71. int itemX = guiX + ((lineX - 1) * 32) + 3;
  72. int itemY = guiY + (lineY * 32) + 33;
  73. GL11.glScaled(0.0625, 0.0625, 0.0625);
  74. drawTexturedModalRect(16 * (itemX + 5), 16 * itemY, 0, 0, 256, 256);
  75. String cost = Integer.toString(i.getCost());
  76. int stringX = (itemX + 13) - ((fontRendererObj.getStringWidth(cost) + 1) / 2);
  77. int stringY = itemY + 17;
  78. GL11.glScaled(16, 16, 16);
  79. GL11.glColor4d(0.5, 0.5, 0.5, 1);
  80. fontRendererObj.drawString(cost, stringX, stringY, 0x557661);
  81. }
  82.  
  83. @Override
  84. protected void keyTyped(char typedChar, int keyCode) throws IOException {
  85. if(keyCode == Keyboard.KEY_DOWN) {
  86. if(scroll + 1 <= Math.ceil(((double) COLRegistry.itemList.size() / (double) itemsPerLine)) - linesPerGui) {
  87. scroll++;
  88. }
  89. }
  90. if(keyCode == Keyboard.KEY_UP) {
  91. if(scroll - 1 >= 0) {
  92. scroll--;
  93. }
  94. }
  95. super.keyTyped(typedChar, keyCode);
  96. }
  97.  
  98. @Override
  99. public void handleMouseInput() throws IOException {
  100. for(int number = 0; number < COLRegistry.itemList.size(); number++) {
  101. int guiX = (width - realGuiWidth) / scaleFactor;
  102. int guiY = (height - realGuiHeight) / scaleFactor;
  103. int lineX = (number % itemsPerLine) + 1;
  104. int lineY = (number - lineX + 1) / itemsPerLine;
  105. int itemX = guiX + ((lineX - 1) * 32) + 3;
  106. int itemY = guiY + (lineY * 32) + 33;
  107. int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
  108. int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 4;
  109. if(i >= itemX && j >= itemY && i <= itemX + 16 && j <= itemY + 16) {
  110. String[] sa = new String[] {Helpers.translate("item." + COLRegistry.itemList.get(number).getName() + ".name")};
  111. List<String> s = Arrays.asList(sa);
  112. drawHoveringText(s, i, j);
  113. }
  114. }
  115. super.handleMouseInput();
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment