001    package cpw.mods.fml.client;
002    
003    import java.util.List;
004    import java.util.Map.Entry;
005    
006    import com.google.common.collect.Lists;
007    import com.google.common.collect.MapDifference;
008    import com.google.common.collect.MapDifference.ValueDifference;
009    
010    import cpw.mods.fml.common.registry.ItemData;
011    import cpw.mods.fml.common.versioning.ArtifactVersion;
012    import net.minecraft.src.GuiButton;
013    import net.minecraft.src.GuiYesNo;
014    import net.minecraft.src.StringTranslate;
015    
016    public class GuiIdMismatchScreen extends GuiYesNo {
017        private List<String> missingIds = Lists.newArrayList();
018        private List<String> mismatchedIds = Lists.newArrayList();
019        private boolean allowContinue;
020    
021        public GuiIdMismatchScreen(MapDifference<Integer, ItemData> idDifferences, boolean allowContinue)
022        {
023            super(null,"ID mismatch", "Should I continue?", 1);
024            parentScreen = this;
025            for (Entry<Integer, ItemData> entry : idDifferences.entriesOnlyOnLeft().entrySet())
026            {
027                missingIds.add(String.format("ID %d (ModID: %s, type %s) is missing", entry.getValue().itemId, entry.getValue().modId, entry.getValue().itemType));
028            }
029            for (Entry<Integer, ValueDifference<ItemData>> entry : idDifferences.entriesDiffering().entrySet())
030            {
031                ItemData world = entry.getValue().leftValue();
032                ItemData game = entry.getValue().rightValue();
033                mismatchedIds.add(String.format("ID %d is mismatched. World: (ModID: %s, type %s, ordinal %d) Game (ModID: %s, type %s, ordinal %d)", world.itemId, world.modId, world.itemType, world.ordinal, game.modId, game.itemType, game.ordinal));
034            }
035            this.allowContinue = allowContinue;
036        }
037    
038        @Override
039        public void confirmClicked(boolean choice, int par2)
040        {
041            FMLClientHandler.instance().callbackIdDifferenceResponse(choice);
042        }
043    
044        @Override
045    
046        /**
047         * Draws the screen and all the components in it.
048         */
049        public void drawScreen(int par1, int par2, float par3)
050        {
051            this.drawDefaultBackground();
052            if (!allowContinue && controlList.size() == 2)
053            {
054                controlList.remove(0);
055            }
056            int offset = Math.max(85 - missingIds.size() * 10 + mismatchedIds.size() * 30, 10);
057            this.drawCenteredString(this.fontRenderer, "Forge Mod Loader has found world ID mismatches", this.width / 2, offset, 0xFFFFFF);
058            offset += 10;
059            for (String s: missingIds) {
060                this.drawCenteredString(this.fontRenderer, s, this.width / 2, offset, 0xEEEEEE);
061                offset += 10;
062            }
063            for (String s: mismatchedIds) {
064                this.drawCenteredString(this.fontRenderer, s, this.width / 2, offset, 0xEEEEEE);
065                offset += 10;
066            }
067            offset += 10;
068            if (allowContinue)
069            {
070                this.drawCenteredString(this.fontRenderer, "Do you wish to continue loading?", this.width / 2, offset, 0xFFFFFF);
071                offset += 10;
072            }
073            else
074            {
075                this.drawCenteredString(this.fontRenderer, "You cannot connect to this server", this.width / 2, offset, 0xFFFFFF);
076                offset += 10;
077            }
078            // super.super. Grrr
079            for (int var4 = 0; var4 < this.controlList.size(); ++var4)
080            {
081                GuiButton var5 = (GuiButton)this.controlList.get(var4);
082                var5.yPosition = Math.min(offset + 10, this.height - 20);
083                if (!allowContinue)
084                {
085                    var5.xPosition = this.width / 2 - 75;
086                    var5.displayString = StringTranslate.getInstance().translateKey("gui.done");
087                }
088                var5.drawButton(this.mc, par1, par2);
089            }
090        }
091    }