001/*
002 * Forge Mod Loader
003 * Copyright (c) 2012-2013 cpw.
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser Public License v2.1
006 * which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
008 *
009 * Contributors:
010 *     cpw - implementation
011 */
012
013package cpw.mods.fml.client;
014
015import java.util.List;
016import java.util.Map.Entry;
017
018import net.minecraft.client.gui.GuiButton;
019import net.minecraft.client.gui.GuiYesNo;
020import net.minecraft.util.StringTranslate;
021
022import com.google.common.collect.Lists;
023import com.google.common.collect.MapDifference;
024import com.google.common.collect.MapDifference.ValueDifference;
025
026import cpw.mods.fml.common.registry.ItemData;
027import cpw.mods.fml.common.versioning.ArtifactVersion;
028
029public class GuiIdMismatchScreen extends GuiYesNo {
030    private List<String> missingIds = Lists.newArrayList();
031    private List<String> mismatchedIds = Lists.newArrayList();
032    private boolean allowContinue;
033
034    public GuiIdMismatchScreen(MapDifference<Integer, ItemData> idDifferences, boolean allowContinue)
035    {
036        super(null,"ID mismatch", "Should I continue?", 1);
037        parentScreen = this;
038        for (Entry<Integer, ItemData> entry : idDifferences.entriesOnlyOnLeft().entrySet())
039        {
040            missingIds.add(String.format("ID %d from Mod %s is missing", entry.getValue().getItemId(), entry.getValue().getModId(), entry.getValue().getItemType()));
041        }
042        for (Entry<Integer, ValueDifference<ItemData>> entry : idDifferences.entriesDiffering().entrySet())
043        {
044            ItemData world = entry.getValue().leftValue();
045            ItemData game = entry.getValue().rightValue();
046            mismatchedIds.add(String.format("ID %d is mismatched between world and game", world.getItemId()));
047        }
048        this.allowContinue = allowContinue;
049    }
050
051    @Override
052    public void confirmClicked(boolean choice, int par2)
053    {
054        FMLClientHandler.instance().callbackIdDifferenceResponse(choice);
055    }
056
057    @Override
058
059    /**
060     * Draws the screen and all the components in it.
061     */
062    public void drawScreen(int par1, int par2, float par3)
063    {
064        this.drawDefaultBackground();
065        if (!allowContinue && buttonList.size() == 2)
066        {
067            buttonList.remove(0);
068        }
069        int offset = Math.max(85 - (missingIds.size() + mismatchedIds.size()) * 10, 30);
070        this.drawCenteredString(this.fontRenderer, "Forge Mod Loader has found ID mismatches", this.width / 2, 10, 0xFFFFFF);
071        this.drawCenteredString(this.fontRenderer, "Complete details are in the log file", this.width / 2, 20, 0xFFFFFF);
072        for (String s: missingIds) {
073            this.drawCenteredString(this.fontRenderer, s, this.width / 2, offset, 0xEEEEEE);
074            offset += 10;
075            if (offset > this.height - 30) break;
076        }
077        for (String s: mismatchedIds) {
078            this.drawCenteredString(this.fontRenderer, s, this.width / 2, offset, 0xEEEEEE);
079            offset += 10;
080            if (offset > this.height - 30) break;
081        }
082        if (allowContinue)
083        {
084            this.drawCenteredString(this.fontRenderer, "Do you wish to continue loading?", this.width / 2, this.height - 30, 0xFFFFFF);
085        }
086        else
087        {
088            this.drawCenteredString(this.fontRenderer, "You cannot connect to this server", this.width / 2, this.height - 30, 0xFFFFFF);
089        }
090        // super.super. Grrr
091        for (int var4 = 0; var4 < this.buttonList.size(); ++var4)
092        {
093            GuiButton var5 = (GuiButton)this.buttonList.get(var4);
094            var5.yPosition = this.height - 20;
095            if (!allowContinue)
096            {
097                var5.xPosition = this.width / 2 - 75;
098                var5.displayString = StringTranslate.getInstance().translateKey("gui.done");
099            }
100            var5.drawButton(this.mc, par1, par2);
101        }
102    }
103}