| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import net.minecraft.client.Minecraft;
|
| 4 | import net.minecraft.client.renderer.GlStateManager;
|
| 5 | import net.minecraft.client.settings.GameSettings;
|
| 6 | import net.minecraft.util.MathHelper;
|
| 7 |
|
| 8 | public class GuiOptionSlider extends GuiButton
|
| 9 | {
|
| 10 | private float sliderValue;
|
| 11 | public boolean dragging;
|
| 12 | private GameSettings.Options options;
|
| 13 | private final float field_146132_r;
|
| 14 | private final float field_146131_s;
|
| 15 |
|
| 16 | public GuiOptionSlider(int p_i45016_1_, int p_i45016_2_, int p_i45016_3_, GameSettings.Options p_i45016_4_)
|
| 17 | {
|
| 18 | this(p_i45016_1_, p_i45016_2_, p_i45016_3_, p_i45016_4_, 0.0F, 1.0F);
|
| 19 | }
|
| 20 |
|
| 21 | public GuiOptionSlider(int p_i45017_1_, int p_i45017_2_, int p_i45017_3_, GameSettings.Options p_i45017_4_, float p_i45017_5_, float p_i45017_6_)
|
| 22 | {
|
| 23 | super(p_i45017_1_, p_i45017_2_, p_i45017_3_, 150, 20, "");
|
| 24 | this.sliderValue = 1.0F;
|
| 25 | this.options = p_i45017_4_;
|
| 26 | this.field_146132_r = p_i45017_5_;
|
| 27 | this.field_146131_s = p_i45017_6_;
|
| 28 | Minecraft minecraft = Minecraft.getMinecraft();
|
| 29 | this.sliderValue = p_i45017_4_.normalizeValue(minecraft.gameSettings.getOptionFloatValue(p_i45017_4_));
|
| 30 | this.displayString = minecraft.gameSettings.getKeyBinding(p_i45017_4_);
|
| 31 | }
|
| 32 |
|
| 33 | /**
|
| 34 | * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
|
| 35 | * this button.
|
| 36 | */
|
| 37 | protected int getHoverState(boolean mouseOver)
|
| 38 | {
|
| 39 | return 0;
|
| 40 | }
|
| 41 |
|
| 42 | /**
|
| 43 | * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
|
| 44 | */
|
| 45 | protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)
|
| 46 | {
|
| 47 | if (this.visible)
|
| 48 | {
|
| 49 | if (this.dragging)
|
| 50 | {
|
| 51 | this.sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
|
| 52 | this.sliderValue = MathHelper.clamp_float(this.sliderValue, 0.0F, 1.0F);
|
| 53 | float f = this.options.denormalizeValue(this.sliderValue);
|
| 54 | mc.gameSettings.setOptionFloatValue(this.options, f);
|
| 55 | this.sliderValue = this.options.normalizeValue(f);
|
| 56 | this.displayString = mc.gameSettings.getKeyBinding(this.options);
|
| 57 | }
|
| 58 |
|
| 59 | mc.getTextureManager().bindTexture(buttonTextures);
|
| 60 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 61 | this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
|
| 62 | this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
|
| 63 | }
|
| 64 | }
|
| 65 |
|
| 66 | /**
|
| 67 | * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
|
| 68 | * e).
|
| 69 | */
|
| 70 | public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
|
| 71 | {
|
| 72 | if (super.mousePressed(mc, mouseX, mouseY))
|
| 73 | {
|
| 74 | this.sliderValue = (float)(mouseX - (this.xPosition + 4)) / (float)(this.width - 8);
|
| 75 | this.sliderValue = MathHelper.clamp_float(this.sliderValue, 0.0F, 1.0F);
|
| 76 | mc.gameSettings.setOptionFloatValue(this.options, this.options.denormalizeValue(this.sliderValue));
|
| 77 | this.displayString = mc.gameSettings.getKeyBinding(this.options);
|
| 78 | this.dragging = true;
|
| 79 | return true;
|
| 80 | }
|
| 81 | else
|
| 82 | {
|
| 83 | return false;
|
| 84 | }
|
| 85 | }
|
| 86 |
|
| 87 | /**
|
| 88 | * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
|
| 89 | */
|
| 90 | public void mouseReleased(int mouseX, int mouseY)
|
| 91 | {
|
| 92 | this.dragging = false;
|
| 93 | }
|
| 94 | }
|
| 95 |
|