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 (ModID: %s, type %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. 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())); 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() * 10 + mismatchedIds.size() * 30, 10); 070 this.drawCenteredString(this.fontRenderer, "Forge Mod Loader has found world ID mismatches", this.width / 2, offset, 0xFFFFFF); 071 offset += 10; 072 for (String s: missingIds) { 073 this.drawCenteredString(this.fontRenderer, s, this.width / 2, offset, 0xEEEEEE); 074 offset += 10; 075 } 076 for (String s: mismatchedIds) { 077 this.drawCenteredString(this.fontRenderer, s, this.width / 2, offset, 0xEEEEEE); 078 offset += 10; 079 } 080 offset += 10; 081 if (allowContinue) 082 { 083 this.drawCenteredString(this.fontRenderer, "Do you wish to continue loading?", this.width / 2, offset, 0xFFFFFF); 084 offset += 10; 085 } 086 else 087 { 088 this.drawCenteredString(this.fontRenderer, "You cannot connect to this server", this.width / 2, offset, 0xFFFFFF); 089 offset += 10; 090 } 091 // super.super. Grrr 092 for (int var4 = 0; var4 < this.buttonList.size(); ++var4) 093 { 094 GuiButton var5 = (GuiButton)this.buttonList.get(var4); 095 var5.yPosition = Math.min(offset + 10, this.height - 20); 096 if (!allowContinue) 097 { 098 var5.xPosition = this.width / 2 - 75; 099 var5.displayString = StringTranslate.getInstance().translateKey("gui.done"); 100 } 101 var5.drawButton(this.mc, par1, par2); 102 } 103 } 104}