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 int maxLines = 20; 073 for (String s: missingIds) { 074 this.drawCenteredString(this.fontRenderer, s, this.width / 2, offset, 0xEEEEEE); 075 offset += 10; 076 maxLines --; 077 if (maxLines < 0) break; 078 if (offset >= this.height - 30) break; 079 } 080 if (maxLines > 0 && offset < this.height - 30) 081 { 082 for (String s: mismatchedIds) { 083 this.drawCenteredString(this.fontRenderer, s, this.width / 2, offset, 0xEEEEEE); 084 offset += 10; 085 maxLines --; 086 if (maxLines < 0) break; 087 if (offset >= this.height - 30) break; 088 } 089 } 090 if (allowContinue) 091 { 092 this.drawCenteredString(this.fontRenderer, "Do you wish to continue loading?", this.width / 2, this.height - 30, 0xFFFFFF); 093 } 094 else 095 { 096 this.drawCenteredString(this.fontRenderer, "You cannot connect to this server", this.width / 2, this.height - 30, 0xFFFFFF); 097 } 098 // super.super. Grrr 099 for (int var4 = 0; var4 < this.buttonList.size(); ++var4) 100 { 101 GuiButton var5 = (GuiButton)this.buttonList.get(var4); 102 var5.yPosition = this.height - 20; 103 if (!allowContinue) 104 { 105 var5.xPosition = this.width / 2 - 75; 106 var5.displayString = StringTranslate.getInstance().translateKey("gui.done"); 107 } 108 var5.drawButton(this.mc, par1, par2); 109 } 110 } 111}