Advertisement
TNT_Block

Untitled

Sep 1st, 2019
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. package net.minecraft.client.gui;
  2.  
  3. import java.io.IOException;
  4. import net.minecraft.client.Minecraft;
  5. import net.minecraft.client.audio.PositionedSoundRecord;
  6. import net.minecraft.client.audio.SoundCategory;
  7. import net.minecraft.client.audio.SoundHandler;
  8. import net.minecraft.client.renderer.GlStateManager;
  9. import net.minecraft.client.resources.I18n;
  10. import net.minecraft.client.settings.GameSettings;
  11. import net.minecraft.util.MathHelper;
  12. import net.minecraft.util.ResourceLocation;
  13.  
  14. public class GuiScreenOptionsSounds extends GuiScreen {
  15. private final GuiScreen field_146505_f;
  16.  
  17. /** Reference to the GameSettings object. */
  18. private final GameSettings game_settings_4;
  19. protected String field_146507_a = "Options";
  20. private String field_146508_h;
  21.  
  22. public GuiScreenOptionsSounds(GuiScreen p_i45025_1_, GameSettings p_i45025_2_) {
  23. this.field_146505_f = p_i45025_1_;
  24. this.game_settings_4 = p_i45025_2_;
  25. }
  26.  
  27. /**
  28. * Adds the buttons (and other controls) to the screen in question. Called
  29. * when the GUI is displayed and when the window resizes, the buttonList is
  30. * cleared beforehand.
  31. */
  32. public void initGui() {
  33. int i = 0;
  34. this.field_146507_a = I18n.format("options.sounds.title", new Object[0]);
  35. this.field_146508_h = I18n.format("options.off", new Object[0]);
  36. this.buttonList.add(new GuiScreenOptionsSounds.Button(SoundCategory.MASTER.getCategoryId(),
  37. this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 12 + 24 * (i >> 1), SoundCategory.MASTER, true));
  38. i = i + 2;
  39.  
  40. for (SoundCategory soundcategory : SoundCategory.values()) {
  41. if (soundcategory != SoundCategory.MASTER) {
  42. this.buttonList.add(new GuiScreenOptionsSounds.Button(soundcategory.getCategoryId(),
  43. this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 12 + 24 * (i >> 1), soundcategory,
  44. false));
  45. ++i;
  46. }
  47. }
  48.  
  49. this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168,
  50. I18n.format("gui.done", new Object[0])));
  51. }
  52.  
  53. /**
  54. * Called by the controls from the buttonList when activated. (Mouse pressed
  55. * for buttons)
  56. */
  57. protected void actionPerformed(GuiButton button) throws IOException {
  58. if (button.enabled) {
  59. if (button.id == 200) {
  60. this.mc.gameSettings.saveOptions();
  61. this.mc.displayGuiScreen(this.field_146505_f);
  62. }
  63. }
  64. }
  65.  
  66. /**
  67. * Draws the screen and all the components in it. Args : mouseX, mouseY,
  68. * renderPartialTicks
  69. */
  70. public void drawScreen(int mouseX, int mouseY, float partialTicks) {
  71. this.drawDefaultBackground();
  72. this.drawCenteredString(this.fontRendererObj, this.field_146507_a, this.width / 2, 15, 16777215);
  73. super.drawScreen(mouseX, mouseY, partialTicks);
  74. }
  75.  
  76. protected String getSoundVolume(SoundCategory p_146504_1_) {
  77. float f = this.game_settings_4.getSoundLevel(p_146504_1_);
  78. return f == 0.0F ? this.field_146508_h : (int) (f * 100.0F) + "%";
  79. }
  80.  
  81. class Button extends GuiButton {
  82. private final SoundCategory field_146153_r;
  83. private final String field_146152_s;
  84. public float value = 1.0F;
  85. public boolean dragged;
  86.  
  87. public Button(int p_i45024_2_, int p_i45024_3_, int p_i45024_4_, SoundCategory p_i45024_5_,
  88. boolean p_i45024_6_) {
  89. super(p_i45024_2_, p_i45024_3_, p_i45024_4_, p_i45024_6_ ? 310 : 150, 20, "");
  90. this.field_146153_r = p_i45024_5_;
  91. this.field_146152_s = I18n.format("soundCategory." + p_i45024_5_.getCategoryName(), new Object[0]);
  92. this.displayString = this.field_146152_s + ": " + GuiScreenOptionsSounds.this.getSoundVolume(p_i45024_5_);
  93. this.value = GuiScreenOptionsSounds.this.game_settings_4.getSoundLevel(p_i45024_5_);
  94. }
  95.  
  96. @Override
  97. public void drawButton(Minecraft mc, int mouseX, int mouseY) {
  98. super.drawButton(mc, mouseX, mouseY);
  99. // this.drawTexturedModalRect(this.xPosition + (int) (this.value *
  100. // (float) (this.width - 8)), this.yPosition,
  101. // 0, 66, 4, 20);
  102.  
  103. this.drawRect(this.xPosition + (int) (this.value * (float) (this.width - 8)) + 1, yPosition + 1,
  104. this.xPosition + (int) (this.value * (float) (this.width - 8)) + 7, yPosition + height - 1, Integer.MAX_VALUE);
  105.  
  106.  
  107. if (dragged) {
  108. this.value = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8);
  109. this.value = MathHelper.clamp_float(this.value, 0.0F, 1.0F);
  110. mc.gameSettings.setSoundLevel(this.field_146153_r, this.value);
  111. mc.gameSettings.saveOptions();
  112. this.displayString = this.field_146152_s + ": "
  113. + GuiScreenOptionsSounds.this.getSoundVolume(this.field_146153_r);
  114. }
  115.  
  116.  
  117. }
  118.  
  119. protected int getHoverState(boolean mouseOver) {
  120. return 0;
  121. }
  122.  
  123. protected void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
  124. if (this.visible) {
  125. if (this.dragged) {
  126. this.value = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8);
  127. this.value = MathHelper.clamp_float(this.value, 0.0F, 1.0F);
  128. mc.gameSettings.setSoundLevel(this.field_146153_r, this.value);
  129. mc.gameSettings.saveOptions();
  130. this.displayString = this.field_146152_s + ": "
  131. + GuiScreenOptionsSounds.this.getSoundVolume(this.field_146153_r);
  132. }
  133.  
  134. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  135. }
  136. }
  137.  
  138. public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
  139. if (super.mousePressed(mc, mouseX, mouseY)) {
  140. this.value = (float) (mouseX - (this.xPosition + 4)) / (float) (this.width - 8);
  141. this.value = MathHelper.clamp_float(this.value, 0.0F, 1.0F);
  142. mc.gameSettings.setSoundLevel(this.field_146153_r, this.value);
  143. mc.gameSettings.saveOptions();
  144. this.displayString = this.field_146152_s + ": "
  145. + GuiScreenOptionsSounds.this.getSoundVolume(this.field_146153_r);
  146. this.dragged = true;
  147. return true;
  148. } else {
  149. return false;
  150. }
  151. }
  152.  
  153. public void playPressSound(SoundHandler soundHandlerIn) {
  154. }
  155.  
  156. public void mouseReleased(int mouseX, int mouseY) {
  157. if (this.dragged) {
  158. if (this.field_146153_r == SoundCategory.MASTER) {
  159. float f = 1.0F;
  160. } else {
  161. GuiScreenOptionsSounds.this.game_settings_4.getSoundLevel(this.field_146153_r);
  162. }
  163.  
  164. GuiScreenOptionsSounds.this.mc.getSoundHandler()
  165. .playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F));
  166. }
  167.  
  168. this.dragged = false;
  169. }
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement