GuiScreenOptionsSounds .java

net.minecraft.client.gui.GuiScreenOptionsSounds (class): members: game_settings_4, field_146505_f, field_146507_a, field_146508_h, Button, getSoundVolume.

net.minecraft.client.guiclass166 linesclientextends GuiScreen6.5 KB

API Surface (9)

void initGui()
void actionPerformed(GuiButton button)
void drawScreen(int mouseX, int mouseY, float partialTicks)
String getSoundVolume(SoundCategory p_146504_1_)
int getHoverState(boolean mouseOver)
void mouseDragged(Minecraft mc, int mouseX, int mouseY)
boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
void playPressSound(SoundHandler soundHandlerIn)
void mouseReleased(int mouseX, int mouseY)

Fields & Constants (4)

field_146505_f
game_settings_4
field_146507_a
field_146508_h

String literals (6)

"Options"
"options.sounds.title"
"options.off"
"gui.done"
"soundCategory."
"gui.button.press"

Full Source

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

Deobfuscated MCP 1.8.9 source of GuiScreenOptionsSounds from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/gui/GuiScreenOptionsSounds.java), stored verbatim.