Advertisement
Creepinson

Untitled

Jun 24th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. package me.creepinson.gui;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.client.gui.FontRenderer;
  5. import net.minecraft.client.gui.GuiButton;
  6. import net.minecraft.client.renderer.GlStateManager;
  7. import net.minecraft.client.resources.I18n;
  8.  
  9. import org.lwjgl.opengl.GL11;
  10.  
  11. public class GuiSliderFixed extends GuiButton {
  12.  
  13. public float sliderPosition = 1.0F;
  14. public float sliderMaxValue = 1.0F;
  15. public float sliderMinValue = 1.0F;
  16. public boolean dragging = false;
  17. public String label;
  18.  
  19. public GuiSliderFixed(int id, int x, int y, String label, float defaultValue, float maxValue, float minValue) {
  20. super(id, x, y, 150, 20, label);
  21. this.label = label;
  22. this.sliderMaxValue = maxValue;
  23. this.sliderMinValue = minValue;
  24. this.sliderPosition = (defaultValue - minValue) / (maxValue - minValue);
  25. this.displayString = label;
  26. }
  27.  
  28. protected int getHoverState(boolean par1) {
  29. return 0;
  30. }
  31. public void setSliderValue(float value)
  32. {
  33. this.sliderPosition = (value - this.sliderMinValue) / (this.sliderMaxValue - this.sliderMinValue);
  34. this.displayString = this.label;
  35.  
  36.  
  37. }
  38. public float getSliderValue()
  39. {
  40. return this.sliderMinValue + (this.sliderMaxValue - this.sliderMinValue) * this.sliderPosition;
  41. }
  42. /**
  43. * Gets the slider's position.
  44. * @return The position of the slider, which will under normal circumstances be between 0 and 1, unless it was
  45. * manually set out of that range.
  46. */
  47. public float getSliderPosition()
  48. {
  49. return this.sliderPosition;
  50. }
  51.  
  52.  
  53. @Override
  54. public void drawButton(Minecraft mc, int mouseX, int mouseY)
  55. {
  56. if (this.visible)
  57. {
  58. FontRenderer fontrenderer = mc.fontRendererObj;
  59. mc.getTextureManager().bindTexture(BUTTON_TEXTURES);
  60. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  61. this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
  62. int k = this.getHoverState(this.hovered);
  63. GlStateManager.enableBlend();
  64. GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
  65. GlStateManager.blendFunc(770, 771);
  66. this.mouseDragged(mc, mouseX, mouseY);
  67. int l = 14737632;
  68.  
  69. if (packedFGColour != 0)
  70. {
  71. l = packedFGColour;
  72. }
  73. else if (!this.enabled)
  74. {
  75. l = 10526880;
  76. }
  77. else if (this.hovered)
  78. {
  79. l = 16777120;
  80. }
  81.  
  82. this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
  83. }
  84. }
  85.  
  86. protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3) {
  87. if (this.enabled && this.visible && this.packedFGColour == 0) {
  88. if (this.dragging) {
  89. this.sliderPosition = (float) (par2 - (this.xPosition + 4)) / (float) (this.width - 8);
  90.  
  91. if (this.sliderPosition < 0.0F) {
  92. this.sliderPosition = 0.0F;
  93. }
  94.  
  95. if (this.sliderPosition > 1.0F) {
  96. this.sliderPosition = 1.0F;
  97. }
  98.  
  99. }
  100.  
  101. this.displayString = label + ": " + (int) (sliderPosition * sliderMaxValue);
  102. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  103. this.drawTexturedModalRect(this.xPosition + (int) (this.sliderPosition * (float) (this.width - 8)), this.yPosition, 0, 66, 4, 20);
  104. this.drawTexturedModalRect(this.xPosition + (int) (this.sliderPosition * (float) (this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
  105. }
  106. }
  107.  
  108. public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
  109. if (super.mousePressed(par1Minecraft, par2, par3)) {
  110. this.sliderPosition = (float) (par2 - (this.xPosition + 4)) / (float) (this.width - 8);
  111.  
  112. if (this.sliderPosition < 0.0F) {
  113. this.sliderPosition = 0.0F;
  114. }
  115.  
  116. if (this.sliderPosition > 1.0F) {
  117. this.sliderPosition = 1.0F;
  118. }
  119.  
  120. this.dragging = true;
  121. return true;
  122. } else {
  123. return false;
  124. }
  125. }
  126.  
  127. public void mouseReleased(int par1, int par2) {
  128. this.dragging = false;
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement