GuiSelectWorld .java

net.minecraft.client.gui.GuiSelectWorld (class): members: addWorldSelectionButtons, makeDeleteWorldYesNo, confirmingDelete, availableWorlds, func_146614_d.

net.minecraft.client.guiclass343 linesclientextends GuiScreen12.9 KB

Implements

API Surface (16)

void initGui()
void handleMouseInput()
String func_146621_a(int p_146621_1_)
String func_146614_d(int p_146614_1_)
void addWorldSelectionButtons()
void actionPerformed(GuiButton button)
void func_146615_e(int p_146615_1_)
void confirmClicked(boolean result, int id)
void drawScreen(int mouseX, int mouseY, float partialTicks)
GuiYesNo makeDeleteWorldYesNo(GuiYesNoCallback selectWorld, String name, int id)
int getSize()
void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
boolean isSelected(int slotIndex)
int getContentHeight()
void drawBackground()
void drawSlot(int entryID, int p_180791_2_, int p_180791_3_, int p_180791_4_, int mouseXIn, int mouseYIn)

Fields & Constants (16)

logger
field_146633_h
parentScreen
screenTitle
field_146634_i
selectedIndex
field_146639_s
availableWorlds
field_146637_u
field_146636_v
field_146635_w
confirmingDelete
deleteButton
selectButton
renameButton
recreateButton

String literals (22)

"Select world"
"selectWorld.title"
"Couldn\'t load level list"
"Unable to load worlds"
"selectWorld.world"
"selectWorld.conversion"
"gameMode.survival"
"gameMode.creative"
"gameMode.adventure"
"gameMode.spectator"
"selectWorld.select"
"selectWorld.create"
"selectWorld.rename"
"selectWorld.delete"
"selectWorld.recreate"
"gui.cancel"
"World"
"selectWorld.deleteQuestion"
"selectWorld.deleteWarning"
"selectWorld.deleteButton"
"gameMode.hardcore"
"selectWorld.cheats"

Full Source

GuiSelectWorld.java343 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui;
2
3
import java.io.IOException;
4
import java.text.DateFormat;
5
import java.text.SimpleDateFormat;
6
import java.util.Collections;
7
import java.util.Date;
8
import net.minecraft.client.AnvilConverterException;
9
import net.minecraft.client.Minecraft;
10
import net.minecraft.client.resources.I18n;
11
import net.minecraft.util.EnumChatFormatting;
12
import net.minecraft.world.WorldSettings;
13
import net.minecraft.world.storage.ISaveFormat;
14
import net.minecraft.world.storage.ISaveHandler;
15
import net.minecraft.world.storage.SaveFormatComparator;
16
import net.minecraft.world.storage.WorldInfo;
17
import org.apache.commons.lang3.StringUtils;
18
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.Logger;
20
21
public class GuiSelectWorld extends GuiScreen implements GuiYesNoCallback
22
{
23
    private static final Logger logger = LogManager.getLogger();
24
    private final DateFormat field_146633_h = new SimpleDateFormat();
25
    protected GuiScreen parentScreen;
26
    protected String screenTitle = "Select world";
27
    private boolean field_146634_i;
28
29
    /** The list index of the currently-selected world */
30
    private int selectedIndex;
31
    private java.util.List<SaveFormatComparator> field_146639_s;
32
    private GuiSelectWorld.List availableWorlds;
33
    private String field_146637_u;
34
    private String field_146636_v;
35
    private String[] field_146635_w = new String[4];
36
    private boolean confirmingDelete;
37
    private GuiButton deleteButton;
38
    private GuiButton selectButton;
39
    private GuiButton renameButton;
40
    private GuiButton recreateButton;
41
42
    public GuiSelectWorld(GuiScreen parentScreenIn)
43
    {
44
        this.parentScreen = parentScreenIn;
45
    }
46
47
    /**
48
     * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
49
     * window resizes, the buttonList is cleared beforehand.
50
     */
51
    public void initGui()
52
    {
53
        this.screenTitle = I18n.format("selectWorld.title", new Object[0]);
54
55
        try
56
        {
57
            this.loadLevelList();
58
        }
59
        catch (AnvilConverterException anvilconverterexception)
60
        {
61
            logger.error((String)"Couldn\'t load level list", (Throwable)anvilconverterexception);
62
            this.mc.displayGuiScreen(new GuiErrorScreen("Unable to load worlds", anvilconverterexception.getMessage()));
63
            return;
64
        }
65
66
        this.field_146637_u = I18n.format("selectWorld.world", new Object[0]);
67
        this.field_146636_v = I18n.format("selectWorld.conversion", new Object[0]);
68
        this.field_146635_w[WorldSettings.GameType.SURVIVAL.getID()] = I18n.format("gameMode.survival", new Object[0]);
69
        this.field_146635_w[WorldSettings.GameType.CREATIVE.getID()] = I18n.format("gameMode.creative", new Object[0]);
70
        this.field_146635_w[WorldSettings.GameType.ADVENTURE.getID()] = I18n.format("gameMode.adventure", new Object[0]);
71
        this.field_146635_w[WorldSettings.GameType.SPECTATOR.getID()] = I18n.format("gameMode.spectator", new Object[0]);
72
        this.availableWorlds = new GuiSelectWorld.List(this.mc);
73
        this.availableWorlds.registerScrollButtons(4, 5);
74
        this.addWorldSelectionButtons();
75
    }
76
77
    /**
78
     * Handles mouse input.
79
     */
80
    public void handleMouseInput() throws IOException
81
    {
82
        super.handleMouseInput();
83
        this.availableWorlds.handleMouseInput();
84
    }
85
86
    /**
87
     * Load the existing world saves for display
88
     */
89
    private void loadLevelList() throws AnvilConverterException
90
    {
91
        ISaveFormat isaveformat = this.mc.getSaveLoader();
92
        this.field_146639_s = isaveformat.getSaveList();
93
        Collections.sort(this.field_146639_s);
94
        this.selectedIndex = -1;
95
    }
96
97
    protected String func_146621_a(int p_146621_1_)
98
    {
99
        return ((SaveFormatComparator)this.field_146639_s.get(p_146621_1_)).getFileName();
100
    }
101
102
    protected String func_146614_d(int p_146614_1_)
103
    {
104
        String s = ((SaveFormatComparator)this.field_146639_s.get(p_146614_1_)).getDisplayName();
105
106
        if (StringUtils.isEmpty(s))
107
        {
108
            s = I18n.format("selectWorld.world", new Object[0]) + " " + (p_146614_1_ + 1);
109
        }
110
111
        return s;
112
    }
113
114
    public void addWorldSelectionButtons()
115
    {
116
        this.buttonList.add(this.selectButton = new GuiButton(1, this.width / 2 - 154, this.height - 52, 150, 20, I18n.format("selectWorld.select", new Object[0])));
117
        this.buttonList.add(new GuiButton(3, this.width / 2 + 4, this.height - 52, 150, 20, I18n.format("selectWorld.create", new Object[0])));
118
        this.buttonList.add(this.renameButton = new GuiButton(6, this.width / 2 - 154, this.height - 28, 72, 20, I18n.format("selectWorld.rename", new Object[0])));
119
        this.buttonList.add(this.deleteButton = new GuiButton(2, this.width / 2 - 76, this.height - 28, 72, 20, I18n.format("selectWorld.delete", new Object[0])));
120
        this.buttonList.add(this.recreateButton = new GuiButton(7, this.width / 2 + 4, this.height - 28, 72, 20, I18n.format("selectWorld.recreate", new Object[0])));
121
        this.buttonList.add(new GuiButton(0, this.width / 2 + 82, this.height - 28, 72, 20, I18n.format("gui.cancel", new Object[0])));
122
        this.selectButton.enabled = false;
123
        this.deleteButton.enabled = false;
124
        this.renameButton.enabled = false;
125
        this.recreateButton.enabled = false;
126
    }
127
128
    /**
129
     * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
130
     */
131
    protected void actionPerformed(GuiButton button) throws IOException
132
    {
133
        if (button.enabled)
134
        {
135
            if (button.id == 2)
136
            {
137
                String s = this.func_146614_d(this.selectedIndex);
138
139
                if (s != null)
140
                {
141
                    this.confirmingDelete = true;
142
                    GuiYesNo guiyesno = makeDeleteWorldYesNo(this, s, this.selectedIndex);
143
                    this.mc.displayGuiScreen(guiyesno);
144
                }
145
            }
146
            else if (button.id == 1)
147
            {
148
                this.func_146615_e(this.selectedIndex);
149
            }
150
            else if (button.id == 3)
151
            {
152
                this.mc.displayGuiScreen(new GuiCreateWorld(this));
153
            }
154
            else if (button.id == 6)
155
            {
156
                this.mc.displayGuiScreen(new GuiRenameWorld(this, this.func_146621_a(this.selectedIndex)));
157
            }
158
            else if (button.id == 0)
159
            {
160
                this.mc.displayGuiScreen(this.parentScreen);
161
            }
162
            else if (button.id == 7)
163
            {
164
                GuiCreateWorld guicreateworld = new GuiCreateWorld(this);
165
                ISaveHandler isavehandler = this.mc.getSaveLoader().getSaveLoader(this.func_146621_a(this.selectedIndex), false);
166
                WorldInfo worldinfo = isavehandler.loadWorldInfo();
167
                isavehandler.flush();
168
                guicreateworld.recreateFromExistingWorld(worldinfo);
169
                this.mc.displayGuiScreen(guicreateworld);
170
            }
171
            else
172
            {
173
                this.availableWorlds.actionPerformed(button);
174
            }
175
        }
176
    }
177
178
    public void func_146615_e(int p_146615_1_)
179
    {
180
        this.mc.displayGuiScreen((GuiScreen)null);
181
182
        if (!this.field_146634_i)
183
        {
184
            this.field_146634_i = true;
185
            String s = this.func_146621_a(p_146615_1_);
186
187
            if (s == null)
188
            {
189
                s = "World" + p_146615_1_;
190
            }
191
192
            String s1 = this.func_146614_d(p_146615_1_);
193
194
            if (s1 == null)
195
            {
196
                s1 = "World" + p_146615_1_;
197
            }
198
199
            if (this.mc.getSaveLoader().canLoadWorld(s))
200
            {
201
                this.mc.launchIntegratedServer(s, s1, (WorldSettings)null);
202
            }
203
        }
204
    }
205
206
    public void confirmClicked(boolean result, int id)
207
    {
208
        if (this.confirmingDelete)
209
        {
210
            this.confirmingDelete = false;
211
212
            if (result)
213
            {
214
                ISaveFormat isaveformat = this.mc.getSaveLoader();
215
                isaveformat.flushCache();
216
                isaveformat.deleteWorldDirectory(this.func_146621_a(id));
217
218
                try
219
                {
220
                    this.loadLevelList();
221
                }
222
                catch (AnvilConverterException anvilconverterexception)
223
                {
224
                    logger.error((String)"Couldn\'t load level list", (Throwable)anvilconverterexception);
225
                }
226
            }
227
228
            this.mc.displayGuiScreen(this);
229
        }
230
    }
231
232
    /**
233
     * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
234
     */
235
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
236
    {
237
        this.availableWorlds.drawScreen(mouseX, mouseY, partialTicks);
238
        this.drawCenteredString(this.fontRendererObj, this.screenTitle, this.width / 2, 20, 16777215);
239
        super.drawScreen(mouseX, mouseY, partialTicks);
240
    }
241
242
    /**
243
     * Generate a GuiYesNo asking for confirmation to delete a world
244
     *  
245
     * Called when user selects the "Delete" button.
246
     *  
247
     * @param selectWorld A reference back to the GuiSelectWorld spawning the GuiYesNo
248
     * @param name The name of the world selected for deletion
249
     * @param id An arbitrary integer passed back to selectWorld's confirmClicked method
250
     */
251
    public static GuiYesNo makeDeleteWorldYesNo(GuiYesNoCallback selectWorld, String name, int id)
252
    {
253
        String s = I18n.format("selectWorld.deleteQuestion", new Object[0]);
254
        String s1 = "\'" + name + "\' " + I18n.format("selectWorld.deleteWarning", new Object[0]);
255
        String s2 = I18n.format("selectWorld.deleteButton", new Object[0]);
256
        String s3 = I18n.format("gui.cancel", new Object[0]);
257
        GuiYesNo guiyesno = new GuiYesNo(selectWorld, s, s1, s2, s3, id);
258
        return guiyesno;
259
    }
260
261
    class List extends GuiSlot
262
    {
263
        public List(Minecraft mcIn)
264
        {
265
            super(mcIn, GuiSelectWorld.this.width, GuiSelectWorld.this.height, 32, GuiSelectWorld.this.height - 64, 36);
266
        }
267
268
        protected int getSize()
269
        {
270
            return GuiSelectWorld.this.field_146639_s.size();
271
        }
272
273
        protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
274
        {
275
            GuiSelectWorld.this.selectedIndex = slotIndex;
276
            boolean flag = GuiSelectWorld.this.selectedIndex >= 0 && GuiSelectWorld.this.selectedIndex < this.getSize();
277
            GuiSelectWorld.this.selectButton.enabled = flag;
278
            GuiSelectWorld.this.deleteButton.enabled = flag;
279
            GuiSelectWorld.this.renameButton.enabled = flag;
280
            GuiSelectWorld.this.recreateButton.enabled = flag;
281
282
            if (isDoubleClick && flag)
283
            {
284
                GuiSelectWorld.this.func_146615_e(slotIndex);
285
            }
286
        }
287
288
        protected boolean isSelected(int slotIndex)
289
        {
290
            return slotIndex == GuiSelectWorld.this.selectedIndex;
291
        }
292
293
        protected int getContentHeight()
294
        {
295
            return GuiSelectWorld.this.field_146639_s.size() * 36;
296
        }
297
298
        protected void drawBackground()
299
        {
300
            GuiSelectWorld.this.drawDefaultBackground();
301
        }
302
303
        protected void drawSlot(int entryID, int p_180791_2_, int p_180791_3_, int p_180791_4_, int mouseXIn, int mouseYIn)
304
        {
305
            SaveFormatComparator saveformatcomparator = (SaveFormatComparator)GuiSelectWorld.this.field_146639_s.get(entryID);
306
            String s = saveformatcomparator.getDisplayName();
307
308
            if (StringUtils.isEmpty(s))
309
            {
310
                s = GuiSelectWorld.this.field_146637_u + " " + (entryID + 1);
311
            }
312
313
            String s1 = saveformatcomparator.getFileName();
314
            s1 = s1 + " (" + GuiSelectWorld.this.field_146633_h.format(new Date(saveformatcomparator.getLastTimePlayed()));
315
            s1 = s1 + ")";
316
            String s2 = "";
317
318
            if (saveformatcomparator.requiresConversion())
319
            {
320
                s2 = GuiSelectWorld.this.field_146636_v + " " + s2;
321
            }
322
            else
323
            {
324
                s2 = GuiSelectWorld.this.field_146635_w[saveformatcomparator.getEnumGameType().getID()];
325
326
                if (saveformatcomparator.isHardcoreModeEnabled())
327
                {
328
                    s2 = EnumChatFormatting.DARK_RED + I18n.format("gameMode.hardcore", new Object[0]) + EnumChatFormatting.RESET;
329
                }
330
331
                if (saveformatcomparator.getCheatsEnabled())
332
                {
333
                    s2 = s2 + ", " + I18n.format("selectWorld.cheats", new Object[0]);
334
                }
335
            }
336
337
            GuiSelectWorld.this.drawString(GuiSelectWorld.this.fontRendererObj, s, p_180791_2_ + 2, p_180791_3_ + 1, 16777215);
338
            GuiSelectWorld.this.drawString(GuiSelectWorld.this.fontRendererObj, s1, p_180791_2_ + 2, p_180791_3_ + 12, 8421504);
339
            GuiSelectWorld.this.drawString(GuiSelectWorld.this.fontRendererObj, s2, p_180791_2_ + 2, p_180791_3_ + 12 + 10, 8421504);
340
        }
341
    }
342
}
343

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