GuiScreenResourcePacks .java

net.minecraft.client.gui.GuiScreenResourcePacks (class): members: availableResourcePacksList, getAvailableResourcePacks, selectedResourcePacksList, logger.

net.minecraft.client.guiclass244 linesclientextends GuiScreen9.7 KB

API Surface (11)

void initGui()
void handleMouseInput()
boolean hasResourcePackEntry(ResourcePackListEntry p_146961_1_)
List<ResourcePackListEntry> getListContaining(ResourcePackListEntry p_146962_1_)
List<ResourcePackListEntry> getAvailableResourcePacks()
List<ResourcePackListEntry> getSelectedResourcePacks()
void actionPerformed(GuiButton button)
void mouseClicked(int mouseX, int mouseY, int mouseButton)
void mouseReleased(int mouseX, int mouseY, int state)
void drawScreen(int mouseX, int mouseY, float partialTicks)
void markChanged()

Fields & Constants (7)

logger
parentScreen
availableResourcePacks
selectedResourcePacks
availableResourcePacksList
selectedResourcePacksList
changed

String literals (12)

"resourcePack.openFolder"
"gui.done"
"/usr/bin/open"
"Couldn\'t open file"
"java.awt.Desktop"
"getDesktop"
"browse"
"Couldn\'t open link"
"Opening via system class!"
"file://"
"resourcePack.title"
"resourcePack.folderInfo"

Full Source

GuiScreenResourcePacks.java244 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui;
2
3
import com.google.common.collect.Lists;
4
import java.io.File;
5
import java.io.IOException;
6
import java.net.URI;
7
import java.util.Collections;
8
import java.util.List;
9
import net.minecraft.client.resources.I18n;
10
import net.minecraft.client.resources.ResourcePackListEntry;
11
import net.minecraft.client.resources.ResourcePackListEntryDefault;
12
import net.minecraft.client.resources.ResourcePackListEntryFound;
13
import net.minecraft.client.resources.ResourcePackRepository;
14
import net.minecraft.util.Util;
15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17
import org.lwjgl.Sys;
18
19
public class GuiScreenResourcePacks extends GuiScreen
20
{
21
    private static final Logger logger = LogManager.getLogger();
22
    private final GuiScreen parentScreen;
23
    private List<ResourcePackListEntry> availableResourcePacks;
24
    private List<ResourcePackListEntry> selectedResourcePacks;
25
26
    /** List component that contains the available resource packs */
27
    private GuiResourcePackAvailable availableResourcePacksList;
28
29
    /** List component that contains the selected resource packs */
30
    private GuiResourcePackSelected selectedResourcePacksList;
31
    private boolean changed = false;
32
33
    public GuiScreenResourcePacks(GuiScreen parentScreenIn)
34
    {
35
        this.parentScreen = parentScreenIn;
36
    }
37
38
    /**
39
     * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
40
     * window resizes, the buttonList is cleared beforehand.
41
     */
42
    public void initGui()
43
    {
44
        this.buttonList.add(new GuiOptionButton(2, this.width / 2 - 154, this.height - 48, I18n.format("resourcePack.openFolder", new Object[0])));
45
        this.buttonList.add(new GuiOptionButton(1, this.width / 2 + 4, this.height - 48, I18n.format("gui.done", new Object[0])));
46
47
        if (!this.changed)
48
        {
49
            this.availableResourcePacks = Lists.<ResourcePackListEntry>newArrayList();
50
            this.selectedResourcePacks = Lists.<ResourcePackListEntry>newArrayList();
51
            ResourcePackRepository resourcepackrepository = this.mc.getResourcePackRepository();
52
            resourcepackrepository.updateRepositoryEntriesAll();
53
            List<ResourcePackRepository.Entry> list = Lists.newArrayList(resourcepackrepository.getRepositoryEntriesAll());
54
            list.removeAll(resourcepackrepository.getRepositoryEntries());
55
56
            for (ResourcePackRepository.Entry resourcepackrepository$entry : list)
57
            {
58
                this.availableResourcePacks.add(new ResourcePackListEntryFound(this, resourcepackrepository$entry));
59
            }
60
61
            for (ResourcePackRepository.Entry resourcepackrepository$entry1 : Lists.reverse(resourcepackrepository.getRepositoryEntries()))
62
            {
63
                this.selectedResourcePacks.add(new ResourcePackListEntryFound(this, resourcepackrepository$entry1));
64
            }
65
66
            this.selectedResourcePacks.add(new ResourcePackListEntryDefault(this));
67
        }
68
69
        this.availableResourcePacksList = new GuiResourcePackAvailable(this.mc, 200, this.height, this.availableResourcePacks);
70
        this.availableResourcePacksList.setSlotXBoundsFromLeft(this.width / 2 - 4 - 200);
71
        this.availableResourcePacksList.registerScrollButtons(7, 8);
72
        this.selectedResourcePacksList = new GuiResourcePackSelected(this.mc, 200, this.height, this.selectedResourcePacks);
73
        this.selectedResourcePacksList.setSlotXBoundsFromLeft(this.width / 2 + 4);
74
        this.selectedResourcePacksList.registerScrollButtons(7, 8);
75
    }
76
77
    /**
78
     * Handles mouse input.
79
     */
80
    public void handleMouseInput() throws IOException
81
    {
82
        super.handleMouseInput();
83
        this.selectedResourcePacksList.handleMouseInput();
84
        this.availableResourcePacksList.handleMouseInput();
85
    }
86
87
    public boolean hasResourcePackEntry(ResourcePackListEntry p_146961_1_)
88
    {
89
        return this.selectedResourcePacks.contains(p_146961_1_);
90
    }
91
92
    public List<ResourcePackListEntry> getListContaining(ResourcePackListEntry p_146962_1_)
93
    {
94
        return this.hasResourcePackEntry(p_146962_1_) ? this.selectedResourcePacks : this.availableResourcePacks;
95
    }
96
97
    public List<ResourcePackListEntry> getAvailableResourcePacks()
98
    {
99
        return this.availableResourcePacks;
100
    }
101
102
    public List<ResourcePackListEntry> getSelectedResourcePacks()
103
    {
104
        return this.selectedResourcePacks;
105
    }
106
107
    /**
108
     * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
109
     */
110
    protected void actionPerformed(GuiButton button) throws IOException
111
    {
112
        if (button.enabled)
113
        {
114
            if (button.id == 2)
115
            {
116
                File file1 = this.mc.getResourcePackRepository().getDirResourcepacks();
117
                String s = file1.getAbsolutePath();
118
119
                if (Util.getOSType() == Util.EnumOS.OSX)
120
                {
121
                    try
122
                    {
123
                        logger.info(s);
124
                        Runtime.getRuntime().exec(new String[] {"/usr/bin/open", s});
125
                        return;
126
                    }
127
                    catch (IOException ioexception1)
128
                    {
129
                        logger.error((String)"Couldn\'t open file", (Throwable)ioexception1);
130
                    }
131
                }
132
                else if (Util.getOSType() == Util.EnumOS.WINDOWS)
133
                {
134
                    String s1 = String.format("cmd.exe /C start \"Open file\" \"%s\"", new Object[] {s});
135
136
                    try
137
                    {
138
                        Runtime.getRuntime().exec(s1);
139
                        return;
140
                    }
141
                    catch (IOException ioexception)
142
                    {
143
                        logger.error((String)"Couldn\'t open file", (Throwable)ioexception);
144
                    }
145
                }
146
147
                boolean flag = false;
148
149
                try
150
                {
151
                    Class<?> oclass = Class.forName("java.awt.Desktop");
152
                    Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
153
                    oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {file1.toURI()});
154
                }
155
                catch (Throwable throwable)
156
                {
157
                    logger.error("Couldn\'t open link", throwable);
158
                    flag = true;
159
                }
160
161
                if (flag)
162
                {
163
                    logger.info("Opening via system class!");
164
                    Sys.openURL("file://" + s);
165
                }
166
            }
167
            else if (button.id == 1)
168
            {
169
                if (this.changed)
170
                {
171
                    List<ResourcePackRepository.Entry> list = Lists.<ResourcePackRepository.Entry>newArrayList();
172
173
                    for (ResourcePackListEntry resourcepacklistentry : this.selectedResourcePacks)
174
                    {
175
                        if (resourcepacklistentry instanceof ResourcePackListEntryFound)
176
                        {
177
                            list.add(((ResourcePackListEntryFound)resourcepacklistentry).func_148318_i());
178
                        }
179
                    }
180
181
                    Collections.reverse(list);
182
                    this.mc.getResourcePackRepository().setRepositories(list);
183
                    this.mc.gameSettings.resourcePacks.clear();
184
                    this.mc.gameSettings.incompatibleResourcePacks.clear();
185
186
                    for (ResourcePackRepository.Entry resourcepackrepository$entry : list)
187
                    {
188
                        this.mc.gameSettings.resourcePacks.add(resourcepackrepository$entry.getResourcePackName());
189
190
                        if (resourcepackrepository$entry.func_183027_f() != 1)
191
                        {
192
                            this.mc.gameSettings.incompatibleResourcePacks.add(resourcepackrepository$entry.getResourcePackName());
193
                        }
194
                    }
195
196
                    this.mc.gameSettings.saveOptions();
197
                    this.mc.refreshResources();
198
                }
199
200
                this.mc.displayGuiScreen(this.parentScreen);
201
            }
202
        }
203
    }
204
205
    /**
206
     * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
207
     */
208
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
209
    {
210
        super.mouseClicked(mouseX, mouseY, mouseButton);
211
        this.availableResourcePacksList.mouseClicked(mouseX, mouseY, mouseButton);
212
        this.selectedResourcePacksList.mouseClicked(mouseX, mouseY, mouseButton);
213
    }
214
215
    /**
216
     * Called when a mouse button is released.  Args : mouseX, mouseY, releaseButton
217
     */
218
    protected void mouseReleased(int mouseX, int mouseY, int state)
219
    {
220
        super.mouseReleased(mouseX, mouseY, state);
221
    }
222
223
    /**
224
     * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
225
     */
226
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
227
    {
228
        this.drawBackground(0);
229
        this.availableResourcePacksList.drawScreen(mouseX, mouseY, partialTicks);
230
        this.selectedResourcePacksList.drawScreen(mouseX, mouseY, partialTicks);
231
        this.drawCenteredString(this.fontRendererObj, I18n.format("resourcePack.title", new Object[0]), this.width / 2, 16, 16777215);
232
        this.drawCenteredString(this.fontRendererObj, I18n.format("resourcePack.folderInfo", new Object[0]), this.width / 2 - 77, this.height - 26, 8421504);
233
        super.drawScreen(mouseX, mouseY, partialTicks);
234
    }
235
236
    /**
237
     * Marks the selected resource packs list as changed to trigger a resource reload when the screen is closed
238
     */
239
    public void markChanged()
240
    {
241
        this.changed = true;
242
    }
243
}
244

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