| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.client.Minecraft;
|
| 6 | import net.minecraft.client.multiplayer.ServerList;
|
| 7 | import net.minecraft.client.network.LanServerDetector;
|
| 8 |
|
| 9 | public class ServerSelectionList extends GuiListExtended
|
| 10 | {
|
| 11 | private final GuiMultiplayer owner;
|
| 12 | private final List<ServerListEntryNormal> serverListInternet = Lists.<ServerListEntryNormal>newArrayList();
|
| 13 | private final List<ServerListEntryLanDetected> serverListLan = Lists.<ServerListEntryLanDetected>newArrayList();
|
| 14 | private final GuiListExtended.IGuiListEntry lanScanEntry = new ServerListEntryLanScan();
|
| 15 | private int selectedSlotIndex = -1;
|
| 16 |
|
| 17 | public ServerSelectionList(GuiMultiplayer ownerIn, Minecraft mcIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn)
|
| 18 | {
|
| 19 | super(mcIn, widthIn, heightIn, topIn, bottomIn, slotHeightIn);
|
| 20 | this.owner = ownerIn;
|
| 21 | }
|
| 22 |
|
| 23 | /**
|
| 24 | * Gets the IGuiListEntry object for the given index
|
| 25 | */
|
| 26 | public GuiListExtended.IGuiListEntry getListEntry(int index)
|
| 27 | {
|
| 28 | if (index < this.serverListInternet.size())
|
| 29 | {
|
| 30 | return (GuiListExtended.IGuiListEntry)this.serverListInternet.get(index);
|
| 31 | }
|
| 32 | else
|
| 33 | {
|
| 34 | index = index - this.serverListInternet.size();
|
| 35 |
|
| 36 | if (index == 0)
|
| 37 | {
|
| 38 | return this.lanScanEntry;
|
| 39 | }
|
| 40 | else
|
| 41 | {
|
| 42 | --index;
|
| 43 | return (GuiListExtended.IGuiListEntry)this.serverListLan.get(index);
|
| 44 | }
|
| 45 | }
|
| 46 | }
|
| 47 |
|
| 48 | protected int getSize()
|
| 49 | {
|
| 50 | return this.serverListInternet.size() + 1 + this.serverListLan.size();
|
| 51 | }
|
| 52 |
|
| 53 | public void setSelectedSlotIndex(int selectedSlotIndexIn)
|
| 54 | {
|
| 55 | this.selectedSlotIndex = selectedSlotIndexIn;
|
| 56 | }
|
| 57 |
|
| 58 | /**
|
| 59 | * Returns true if the element passed in is currently selected
|
| 60 | */
|
| 61 | protected boolean isSelected(int slotIndex)
|
| 62 | {
|
| 63 | return slotIndex == this.selectedSlotIndex;
|
| 64 | }
|
| 65 |
|
| 66 | public int func_148193_k()
|
| 67 | {
|
| 68 | return this.selectedSlotIndex;
|
| 69 | }
|
| 70 |
|
| 71 | public void func_148195_a(ServerList p_148195_1_)
|
| 72 | {
|
| 73 | this.serverListInternet.clear();
|
| 74 |
|
| 75 | for (int i = 0; i < p_148195_1_.countServers(); ++i)
|
| 76 | {
|
| 77 | this.serverListInternet.add(new ServerListEntryNormal(this.owner, p_148195_1_.getServerData(i)));
|
| 78 | }
|
| 79 | }
|
| 80 |
|
| 81 | public void func_148194_a(List<LanServerDetector.LanServer> p_148194_1_)
|
| 82 | {
|
| 83 | this.serverListLan.clear();
|
| 84 |
|
| 85 | for (LanServerDetector.LanServer lanserverdetector$lanserver : p_148194_1_)
|
| 86 | {
|
| 87 | this.serverListLan.add(new ServerListEntryLanDetected(this.owner, lanserverdetector$lanserver));
|
| 88 | }
|
| 89 | }
|
| 90 |
|
| 91 | protected int getScrollBarX()
|
| 92 | {
|
| 93 | return super.getScrollBarX() + 30;
|
| 94 | }
|
| 95 |
|
| 96 | /**
|
| 97 | * Gets the width of the list
|
| 98 | */
|
| 99 | public int getListWidth()
|
| 100 | {
|
| 101 | return super.getListWidth() + 85;
|
| 102 | }
|
| 103 | }
|
| 104 |
|