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