mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
FML is no more. FML has ceased to be. FML's expired and gone to meet its maker. FML's a stiff! Bereft of life, FML rests in peace.
This commit is contained in:
1 parent
9a859f8d5c
commit
614bbcb0da
356 files changed
+2676
-235
No files matched your search
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraftforge.fml.common.EnhancedRuntimeException;
|
||||
import net.minecraftforge.fml.common.IFMLHandledException;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* If a mod throws this exception during loading, it will be called back to render
|
||||
* the error screen through the methods below. This error will not be cleared, and will
|
||||
* not allow the game to carry on, but might be useful if your mod wishes to report
|
||||
* a fatal configuration error in a pretty way.
|
||||
*
|
||||
* Throw this through a proxy. It won't work on the dedicated server environment.
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class CustomModLoadingErrorDisplayException extends EnhancedRuntimeException implements IFMLHandledException
|
||||
{
|
||||
public CustomModLoadingErrorDisplayException() {
|
||||
}
|
||||
|
||||
public CustomModLoadingErrorDisplayException(String message, Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Called after the GUI is inited by the parent code. You can do extra stuff here, maybe?
|
||||
*
|
||||
* @param errorScreen The error screen we're painting
|
||||
* @param fontRenderer A font renderer for you
|
||||
*/
|
||||
public abstract void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer);
|
||||
|
||||
/**
|
||||
* Draw your error to the screen.
|
||||
*
|
||||
* <br/><em>Warning: Minecraft is in a deep error state.</em> <strong>All</strong> it can do is stop.
|
||||
* Do not try and do anything involving complex user interaction here.
|
||||
*
|
||||
* @param errorScreen The error screen to draw to
|
||||
* @param fontRenderer A font renderer for you
|
||||
* @param mouseRelX Mouse X
|
||||
* @param mouseRelY Mouse Y
|
||||
* @param tickTime tick time
|
||||
*/
|
||||
public abstract void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime);
|
||||
|
||||
@Override public void printStackTrace(EnhancedRuntimeException.WrappedPrintStream s){}; // Do Nothing unless the modder wants to.
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ExtendedServerListData {
|
||||
public final String type;
|
||||
public final boolean isCompatible;
|
||||
public final Map<String,String> modData;
|
||||
public final boolean isBlocked;
|
||||
|
||||
public ExtendedServerListData(String type, boolean isCompatible, Map<String,String> modData, boolean isBlocked)
|
||||
{
|
||||
this.type = type;
|
||||
this.isCompatible = isCompatible;
|
||||
this.modData = modData;
|
||||
this.isBlocked = isBlocked;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,139 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.client.config.ConfigGuiType;
|
||||
import net.minecraftforge.fml.client.config.DummyConfigElement;
|
||||
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||
import net.minecraftforge.fml.client.config.IConfigElement;
|
||||
import net.minecraftforge.fml.client.config.DummyConfigElement.DummyCategoryElement;
|
||||
import net.minecraftforge.fml.client.config.DummyConfigElement.DummyListElement;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.NumberSliderEntry;
|
||||
|
||||
public class FMLConfigGuiFactory implements IModGuiFactory
|
||||
{
|
||||
public static class FMLConfigGuiScreen extends GuiConfig
|
||||
{
|
||||
|
||||
public FMLConfigGuiScreen(GuiScreen parent)
|
||||
{
|
||||
super(parent, getConfigElements(), "FML", false, false, I18n.format("fml.config.sample.title"));
|
||||
}
|
||||
|
||||
private static List<IConfigElement> getConfigElements()
|
||||
{
|
||||
List<IConfigElement> list = new ArrayList<IConfigElement>();
|
||||
List<IConfigElement> listsList = new ArrayList<IConfigElement>();
|
||||
List<IConfigElement> stringsList = new ArrayList<IConfigElement>();
|
||||
List<IConfigElement> numbersList = new ArrayList<IConfigElement>();
|
||||
Pattern commaDelimitedPattern = Pattern.compile("([A-Za-z]+((,){1}( )*|$))+?");
|
||||
|
||||
// Top Level Settings
|
||||
list.add(new DummyConfigElement("imABoolean", true, ConfigGuiType.BOOLEAN, "fml.config.sample.imABoolean").setRequiresMcRestart(true));
|
||||
list.add(new DummyConfigElement("imAnInteger", 42, ConfigGuiType.INTEGER, "fml.config.sample.imAnInteger", -1, 256).setRequiresMcRestart(true));
|
||||
list.add(new DummyConfigElement("imADouble", 42.4242D, ConfigGuiType.DOUBLE, "fml.config.sample.imADouble", -1.0D, 256.256D).setRequiresMcRestart(true));
|
||||
list.add(new DummyConfigElement("imAString", "http://www.montypython.net/scripts/string.php", ConfigGuiType.STRING, "fml.config.sample.imAString").setRequiresMcRestart(true));
|
||||
|
||||
// Lists category
|
||||
listsList.add(new DummyListElement("booleanList", new Boolean[] {true, false, true, false, true, false, true, false}, ConfigGuiType.BOOLEAN, "fml.config.sample.booleanList"));
|
||||
listsList.add(new DummyListElement("booleanListFixed", new Boolean[] {true, false, true, false, true, false, true, false}, ConfigGuiType.BOOLEAN, "fml.config.sample.booleanListFixed", true));
|
||||
listsList.add(new DummyListElement("booleanListMax", new Boolean[] {true, false, true, false, true, false, true, false}, ConfigGuiType.BOOLEAN, "fml.config.sample.booleanListMax", 10));
|
||||
listsList.add(new DummyListElement("doubleList", new Double[] {0.0D, 1.1D, 2.2D, 3.3D, 4.4D, 5.5D, 6.6D, 7.7D, 8.8D, 9.9D}, ConfigGuiType.DOUBLE, "fml.config.sample.doubleList"));
|
||||
listsList.add(new DummyListElement("doubleListFixed", new Double[] {0.0D, 1.1D, 2.2D, 3.3D, 4.4D, 5.5D, 6.6D, 7.7D, 8.8D, 9.9D}, ConfigGuiType.DOUBLE, "fml.config.sample.doubleListFixed", true));
|
||||
listsList.add(new DummyListElement("doubleListMax", new Double[] {0.0D, 1.1D, 2.2D, 3.3D, 4.4D, 5.5D, 6.6D, 7.7D, 8.8D, 9.9D}, ConfigGuiType.DOUBLE, "fml.config.sample.doubleListMax", 15));
|
||||
listsList.add(new DummyListElement("doubleListBounded", new Double[] {0.0D, 1.1D, 2.2D, 3.3D, 4.4D, 5.5D, 6.6D, 7.7D, 8.8D, 9.9D}, ConfigGuiType.DOUBLE, "fml.config.sample.doubleListBounded", -1.0D, 10.0D));
|
||||
listsList.add(new DummyListElement("integerList", new Integer[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, ConfigGuiType.INTEGER, "fml.config.sample.integerList"));
|
||||
listsList.add(new DummyListElement("integerListFixed", new Integer[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, ConfigGuiType.INTEGER, "fml.config.sample.integerListFixed", true));
|
||||
listsList.add(new DummyListElement("integerListMax", new Integer[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, ConfigGuiType.INTEGER, "fml.config.sample.integerListMax", 15));
|
||||
listsList.add(new DummyListElement("integerListBounded", new Integer[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, ConfigGuiType.INTEGER, "fml.config.sample.integerListBounded", -1, 10));
|
||||
listsList.add(new DummyListElement("stringList", new String[] {"An", "array", "of", "string", "values"}, ConfigGuiType.STRING, "fml.config.sample.stringList"));
|
||||
listsList.add(new DummyListElement("stringListFixed", new String[] {"A", "fixed", "length", "array", "of", "string", "values"}, ConfigGuiType.STRING, "fml.config.sample.stringListFixed", true));
|
||||
listsList.add(new DummyListElement("stringListMax", new String[] {"An", "array", "of", "string", "values", "with", "a", "max", "length", "of", "15"}, ConfigGuiType.STRING, "fml.config.sample.stringListMax", 15));
|
||||
listsList.add(new DummyListElement("stringListPattern", new String[] {"Valid", "Not Valid", "Is, Valid", "Comma, Separated, Value"}, ConfigGuiType.STRING, "fml.config.sample.stringListPattern", commaDelimitedPattern));
|
||||
|
||||
list.add(new DummyCategoryElement("lists", "fml.config.sample.ctgy.lists", listsList));
|
||||
|
||||
// Strings category
|
||||
stringsList.add(new DummyConfigElement("basicString", "Just a regular String value, anything goes.", ConfigGuiType.STRING, "fml.config.sample.basicString"));
|
||||
stringsList.add(new DummyConfigElement("cycleString", "this", ConfigGuiType.STRING, "fml.config.sample.cycleString", new String[] {"this", "property", "cycles", "through", "a", "list", "of", "valid", "choices"}));
|
||||
stringsList.add(new DummyConfigElement("patternString", "only, comma, separated, words, can, be, entered, in, this, box", ConfigGuiType.STRING, "fml.config.sample.patternString", commaDelimitedPattern));
|
||||
stringsList.add(new DummyConfigElement("chatColorPicker", "c", ConfigGuiType.COLOR, "fml.config.sample.chatColorPicker", new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}));
|
||||
stringsList.add(new DummyConfigElement("modIDSelector", "FML", ConfigGuiType.MOD_ID, "fml.config.sample.modIDSelector"));
|
||||
|
||||
list.add(new DummyCategoryElement("strings", "fml.config.sample.ctgy.strings", stringsList));
|
||||
|
||||
// Numbers category
|
||||
numbersList.add((new DummyConfigElement("basicInteger", 42, ConfigGuiType.INTEGER, "fml.config.sample.basicInteger")));
|
||||
numbersList.add((new DummyConfigElement("boundedInteger", 42, ConfigGuiType.INTEGER, "fml.config.sample.boundedInteger", -1, 256)));
|
||||
numbersList.add((new DummyConfigElement("sliderInteger", 2000, ConfigGuiType.INTEGER, "fml.config.sample.sliderInteger", 100, 10000)).setCustomListEntryClass(NumberSliderEntry.class));
|
||||
numbersList.add(new DummyConfigElement("basicDouble", 42.4242D, ConfigGuiType.DOUBLE, "fml.config.sample.basicDouble"));
|
||||
numbersList.add(new DummyConfigElement("boundedDouble", 42.4242D, ConfigGuiType.DOUBLE, "fml.config.sample.boundedDouble", -1.0D, 256.256D));
|
||||
numbersList.add(new DummyConfigElement("sliderDouble", 42.4242D, ConfigGuiType.DOUBLE, "fml.config.sample.sliderDouble", -1.0D, 256.256D).setCustomListEntryClass(NumberSliderEntry.class));
|
||||
|
||||
list.add(new DummyCategoryElement("numbers", "fml.config.sample.ctgy.numbers", numbersList));
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass()
|
||||
{
|
||||
return FMLConfigGuiScreen.class;
|
||||
}
|
||||
|
||||
private static final Set<RuntimeOptionCategoryElement> fmlCategories = ImmutableSet.of(new RuntimeOptionCategoryElement("HELP", "FML"));
|
||||
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
|
||||
{
|
||||
return fmlCategories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element)
|
||||
{
|
||||
return new RuntimeOptionGuiHandler() {
|
||||
@Override
|
||||
public void paint(int x, int y, int w, int h)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWidgets(List<Gui> widgets, int x, int y, int w, int h)
|
||||
{
|
||||
widgets.add(new GuiButton(100, x+10, y+10, "HELLO"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionCallback(int actionId)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import net.minecraft.client.resources.FileResourcePack;
|
||||
import net.minecraftforge.fml.common.FMLContainerHolder;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
public class FMLFileResourcePack extends FileResourcePack implements FMLContainerHolder {
|
||||
|
||||
private ModContainer container;
|
||||
|
||||
public FMLFileResourcePack(ModContainer container)
|
||||
{
|
||||
super(container.getSource());
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackName()
|
||||
{
|
||||
return "FMLFileResourcePack:"+container.getName();
|
||||
}
|
||||
@Override
|
||||
protected InputStream getInputStreamByName(String resourceName) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
return super.getInputStreamByName(resourceName);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
if ("pack.mcmeta".equals(resourceName))
|
||||
{
|
||||
FMLLog.log(container.getName(), Level.DEBUG, "Mod %s is missing a pack.mcmeta file, substituting a dummy one", container.getName());
|
||||
return new ByteArrayInputStream(("{\n" +
|
||||
" \"pack\": {\n"+
|
||||
" \"description\": \"dummy FML pack for "+container.getName()+"\",\n"+
|
||||
" \"pack_format\": 1\n"+
|
||||
"}\n" +
|
||||
"}").getBytes(Charsets.UTF_8));
|
||||
}
|
||||
else throw ioe;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getPackImage() throws IOException
|
||||
{
|
||||
return ImageIO.read(getInputStreamByName(container.getMetadata().logoFile));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModContainer getFMLContainer()
|
||||
{
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import net.minecraft.client.resources.FolderResourcePack;
|
||||
import net.minecraftforge.fml.common.FMLContainerHolder;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
public class FMLFolderResourcePack extends FolderResourcePack implements FMLContainerHolder {
|
||||
|
||||
private ModContainer container;
|
||||
|
||||
public FMLFolderResourcePack(ModContainer container)
|
||||
{
|
||||
super(container.getSource());
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasResourceName(String p_110593_1_)
|
||||
{
|
||||
return super.hasResourceName(p_110593_1_);
|
||||
}
|
||||
@Override
|
||||
public String getPackName()
|
||||
{
|
||||
return "FMLFileResourcePack:"+container.getName();
|
||||
}
|
||||
@Override
|
||||
protected InputStream getInputStreamByName(String resourceName) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
return super.getInputStreamByName(resourceName);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
if ("pack.mcmeta".equals(resourceName))
|
||||
{
|
||||
FMLLog.log(container.getName(), Level.DEBUG, "Mod %s is missing a pack.mcmeta file, substituting a dummy one", container.getName());
|
||||
return new ByteArrayInputStream(("{\n" +
|
||||
" \"pack\": {\n"+
|
||||
" \"description\": \"dummy FML pack for "+container.getName()+"\",\n"+
|
||||
" \"pack_format\": 1\n"+
|
||||
"}\n" +
|
||||
"}").getBytes(Charsets.UTF_8));
|
||||
}
|
||||
else throw ioe;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getPackImage() throws IOException
|
||||
{
|
||||
return ImageIO.read(getInputStreamByName(container.getMetadata().logoFile));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModContainer getFMLContainer()
|
||||
{
|
||||
return container;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
public class GuiAccessDenied extends GuiScreen
|
||||
{
|
||||
private GuiScreen parent;
|
||||
private ServerData data;
|
||||
public GuiAccessDenied(GuiScreen parent, ServerData data)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.buttonList.add(new GuiButton(1, this.width / 2 - 75, this.height - 38, I18n.format("gui.done")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton p_73875_1_)
|
||||
{
|
||||
if (p_73875_1_.enabled && p_73875_1_.id == 1)
|
||||
{
|
||||
FMLClientHandler.instance().showGuiScreen(parent);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
int offset = Math.max(85 - 2 * 10, 10);
|
||||
this.drawCenteredString(this.fontRendererObj, "Forge Mod Loader could not connect to this server", this.width / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("The server %s has forbidden modded access", data.serverName), this.width / 2, offset, 0xFFFFFF);
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.io.File;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
public class GuiBackupFailed extends GuiScreen
|
||||
{
|
||||
private GuiScreen parent;
|
||||
private File zipName;
|
||||
public GuiBackupFailed(GuiScreen parent, File zipName)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.zipName = zipName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.buttonList.add(new GuiButton(1, this.width / 2 - 75, this.height - 38, I18n.format("gui.done")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton p_73875_1_)
|
||||
{
|
||||
if (p_73875_1_.enabled && p_73875_1_.id == 1)
|
||||
{
|
||||
FMLClientHandler.instance().showGuiScreen(parent);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
int offset = Math.max(85 - 2 * 10, 10);
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("There was an error saving the archive %s", zipName.getName()), this.width / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("Please fix the problem and try again"), this.width / 2, offset, 0xFFFFFF);
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiOptionButton;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.common.StartupQuery;
|
||||
|
||||
public class GuiConfirmation extends GuiNotification
|
||||
{
|
||||
public GuiConfirmation(StartupQuery query)
|
||||
{
|
||||
super(query);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.buttonList.add(new GuiOptionButton(0, this.width / 2 - 155, this.height - 38, I18n.format("gui.yes")));
|
||||
this.buttonList.add(new GuiOptionButton(1, this.width / 2 - 155 + 160, this.height - 38, I18n.format("gui.no")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.enabled && (button.id == 0 || button.id == 1))
|
||||
{
|
||||
FMLClientHandler.instance().showGuiScreen(null);
|
||||
query.setResult(button.id == 0);
|
||||
query.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
|
||||
public class GuiCustomModLoadingErrorScreen extends GuiErrorScreen
|
||||
{
|
||||
private CustomModLoadingErrorDisplayException customException;
|
||||
public GuiCustomModLoadingErrorScreen(CustomModLoadingErrorDisplayException customException)
|
||||
{
|
||||
super(null,null);
|
||||
this.customException = customException;
|
||||
}
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
this.buttonList.clear();
|
||||
this.customException.initGui(this, fontRendererObj);
|
||||
}
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
this.customException.drawScreen(this, fontRendererObj, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraftforge.fml.common.DuplicateModsFoundException;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
|
||||
public class GuiDupesFound extends GuiErrorScreen
|
||||
{
|
||||
|
||||
private DuplicateModsFoundException dupes;
|
||||
|
||||
public GuiDupesFound(DuplicateModsFoundException dupes)
|
||||
{
|
||||
super(null,null);
|
||||
this.dupes = dupes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
this.buttonList.clear();
|
||||
}
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
int offset = Math.max(85 - dupes.dupes.size() * 10, 10);
|
||||
this.drawCenteredString(this.fontRendererObj, "Forge Mod Loader has found a problem with your minecraft installation", this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, "You have mod sources that are duplicate within your system", this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, "Mod Id : File name", this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=5;
|
||||
for (Entry<ModContainer, File> mc : dupes.dupes.entries())
|
||||
{
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("%s : %s", mc.getKey().getModId(), mc.getValue().getName()), this.width / 2, offset, 0xEEEEEE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
public class GuiIngameModOptions extends GuiScreen
|
||||
{
|
||||
private final GuiScreen parentScreen;
|
||||
protected String title = "Mod Options";
|
||||
private GuiModOptionList optionList;
|
||||
|
||||
public GuiIngameModOptions(GuiScreen parentScreen)
|
||||
{
|
||||
this.parentScreen = parentScreen;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.optionList=new GuiModOptionList(this);
|
||||
this.optionList.registerScrollButtons(this.buttonList, 7, 8);
|
||||
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, I18n.format("gui.done", new Object[0])));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.enabled)
|
||||
{
|
||||
if (button.id == 200)
|
||||
{
|
||||
this.mc.gameSettings.saveOptions();
|
||||
this.mc.displayGuiScreen(this.parentScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
// force a non-transparent background
|
||||
this.drawDefaultBackground();
|
||||
this.optionList.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.drawCenteredString(this.fontRendererObj, this.title, this.width / 2, 15, 0xFFFFFF);
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
FontRenderer getFontRenderer() {
|
||||
return fontRendererObj;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
/*
|
||||
* The FML Forge Mod Loader suite.
|
||||
* Copyright (C) 2012 cpw
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StringUtils;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.ModContainer.Disableable;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public class GuiModList extends GuiScreen
|
||||
{
|
||||
private enum SortType implements Comparator<ModContainer>
|
||||
{
|
||||
NORMAL(24),
|
||||
A_TO_Z(25){ @Override protected int compare(String name1, String name2){ return name1.compareTo(name2); }},
|
||||
Z_TO_A(26){ @Override protected int compare(String name1, String name2){ return name2.compareTo(name1); }};
|
||||
|
||||
private int buttonID;
|
||||
|
||||
private SortType(int buttonID)
|
||||
{
|
||||
this.buttonID = buttonID;
|
||||
}
|
||||
|
||||
public static SortType getTypeForButton(GuiButton button)
|
||||
{
|
||||
for (SortType t : values())
|
||||
{
|
||||
if (t.buttonID == button.id)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int compare(String name1, String name2){ return 0; }
|
||||
|
||||
@Override
|
||||
public int compare(ModContainer o1, ModContainer o2)
|
||||
{
|
||||
String name1 = StringUtils.stripControlCodes(o1.getName()).toLowerCase();
|
||||
String name2 = StringUtils.stripControlCodes(o2.getName()).toLowerCase();
|
||||
return compare(name1, name2);
|
||||
}
|
||||
}
|
||||
|
||||
private GuiScreen mainMenu;
|
||||
private GuiSlotModList modList;
|
||||
private int selected = -1;
|
||||
private ModContainer selectedMod;
|
||||
private int listWidth;
|
||||
private ArrayList<ModContainer> mods;
|
||||
private GuiButton configModButton;
|
||||
private GuiButton disableModButton;
|
||||
private ResourceLocation cachedLogo;
|
||||
private Dimension cachedLogoDimensions;
|
||||
|
||||
private int buttonMargin = 1;
|
||||
private int numButtons = SortType.values().length;
|
||||
|
||||
private String lastFilterText = "";
|
||||
|
||||
private GuiTextField search;
|
||||
private boolean sorted = false;
|
||||
private SortType sortType = SortType.NORMAL;
|
||||
|
||||
/**
|
||||
* @param mainMenu
|
||||
*/
|
||||
public GuiModList(GuiScreen mainMenu)
|
||||
{
|
||||
this.mainMenu = mainMenu;
|
||||
this.mods = new ArrayList<ModContainer>();
|
||||
FMLClientHandler.instance().addSpecialModEntries(mods);
|
||||
// Add child mods to their parent's list
|
||||
for (ModContainer mod : Loader.instance().getModList())
|
||||
{
|
||||
if (mod.getMetadata() != null && mod.getMetadata().parentMod == null && !Strings.isNullOrEmpty(mod.getMetadata().parent))
|
||||
{
|
||||
String parentMod = mod.getMetadata().parent;
|
||||
ModContainer parentContainer = Loader.instance().getIndexedModList().get(parentMod);
|
||||
if (parentContainer != null)
|
||||
{
|
||||
mod.getMetadata().parentMod = parentContainer;
|
||||
parentContainer.getMetadata().childMods.add(mod);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (mod.getMetadata() != null && mod.getMetadata().parentMod != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
mods.add(mod);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
for (ModContainer mod : mods)
|
||||
{
|
||||
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getName()) + 10);
|
||||
listWidth = Math.max(listWidth,getFontRenderer().getStringWidth(mod.getVersion()) + 10);
|
||||
}
|
||||
listWidth = Math.min(listWidth, 150);
|
||||
this.modList = new GuiSlotModList(this, mods, listWidth);
|
||||
this.modList.registerScrollButtons(this.buttonList, 7, 8);
|
||||
|
||||
this.buttonList.add(new GuiButton(6, ((modList.right + this.width) / 2) - 100, this.height - 38, I18n.format("gui.done")));
|
||||
configModButton = new GuiButton(20, 10, this.height - 49, this.listWidth, 20, "Config");
|
||||
disableModButton = new GuiButton(21, 10, this.height - 27, this.listWidth, 20, "Disable");
|
||||
this.buttonList.add(configModButton);
|
||||
this.buttonList.add(disableModButton);
|
||||
|
||||
search = new GuiTextField(0, getFontRenderer(), 12, modList.bottom + 17, modList.listWidth - 4, 14);
|
||||
search.setFocused(true);
|
||||
search.setCanLoseFocus(true);
|
||||
|
||||
int width = (modList.listWidth / numButtons);
|
||||
int x = 10, y = 10;
|
||||
GuiButton normalSort = new GuiButton(SortType.NORMAL.buttonID, x, y, width - buttonMargin, 20, I18n.format("fml.menu.mods.normal"));
|
||||
normalSort.enabled = false;
|
||||
buttonList.add(normalSort);
|
||||
x += width + buttonMargin;
|
||||
buttonList.add(new GuiButton(SortType.A_TO_Z.buttonID, x, y, width - buttonMargin, 20, "A-Z"));
|
||||
x += width + buttonMargin;
|
||||
buttonList.add(new GuiButton(SortType.Z_TO_A.buttonID, x, y, width - buttonMargin, 20, "Z-A"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button) throws IOException
|
||||
{
|
||||
super.mouseClicked(x, y, button);
|
||||
search.mouseClicked(x, y, button);
|
||||
if (button == 1 && x >= search.xPosition && x < search.xPosition + search.width && y >= search.yPosition && y < search.yPosition + search.height) {
|
||||
search.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char c, int keyCode) throws IOException
|
||||
{
|
||||
super.keyTyped(c, keyCode);
|
||||
search.textboxKeyTyped(c, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
search.updateCursorCounter();
|
||||
|
||||
if (!search.getText().equals(lastFilterText))
|
||||
{
|
||||
reloadMods();
|
||||
sorted = false;
|
||||
}
|
||||
|
||||
if (!sorted)
|
||||
{
|
||||
reloadMods();
|
||||
Collections.sort(mods, sortType);
|
||||
selected = modList.selectedIndex = mods.indexOf(selectedMod);
|
||||
sorted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadMods()
|
||||
{
|
||||
ArrayList<ModContainer> mods = modList.getMods();
|
||||
mods.clear();
|
||||
for (ModContainer m : Loader.instance().getActiveModList())
|
||||
{
|
||||
// If it passes the filter, and is not a child mod
|
||||
if (m.getName().toLowerCase().contains(search.getText().toLowerCase()) && m.getMetadata().parentMod == null)
|
||||
{
|
||||
mods.add(m);
|
||||
}
|
||||
}
|
||||
this.mods = mods;
|
||||
lastFilterText = search.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if (button.enabled)
|
||||
{
|
||||
SortType type = SortType.getTypeForButton(button);
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
for (GuiButton b : (List<GuiButton>) buttonList)
|
||||
{
|
||||
if (SortType.getTypeForButton(b) != null)
|
||||
{
|
||||
b.enabled = true;
|
||||
}
|
||||
}
|
||||
button.enabled = false;
|
||||
sorted = false;
|
||||
sortType = type;
|
||||
this.mods = modList.getMods();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (button.id)
|
||||
{
|
||||
case 6:
|
||||
this.mc.displayGuiScreen(this.mainMenu);
|
||||
return;
|
||||
case 20:
|
||||
try
|
||||
{
|
||||
IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(selectedMod);
|
||||
GuiScreen newScreen = guiFactory.mainConfigGuiClass().getConstructor(GuiScreen.class).newInstance(this);
|
||||
this.mc.displayGuiScreen(newScreen);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "There was a critical issue trying to build the config GUI for %s", selectedMod.getModId());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
super.actionPerformed(button);
|
||||
}
|
||||
|
||||
public int drawLine(String line, int offset, int shifty)
|
||||
{
|
||||
this.fontRendererObj.drawString(line, offset, shifty, 0xd7edea);
|
||||
return shifty + 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int p_571_1_, int p_571_2_, float p_571_3_)
|
||||
{
|
||||
this.modList.drawScreen(p_571_1_, p_571_2_, p_571_3_);
|
||||
this.drawCenteredString(this.fontRendererObj, "Mod List", this.width / 2, 16, 0xFFFFFF);
|
||||
int offset = this.listWidth + 20;
|
||||
if (selectedMod != null)
|
||||
{
|
||||
GlStateManager.enableBlend();
|
||||
if (!selectedMod.getMetadata().autogenerated)
|
||||
{
|
||||
configModButton.visible = true;
|
||||
disableModButton.visible = true;
|
||||
disableModButton.packedFGColour = 0xFF3377;
|
||||
configModButton.enabled = false;
|
||||
int shifty = 35;
|
||||
String logoFile = selectedMod.getMetadata().logoFile;
|
||||
if (!logoFile.isEmpty())
|
||||
{
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
TextureManager tm = mc.getTextureManager();
|
||||
IResourcePack pack = FMLClientHandler.instance().getResourcePackFor(selectedMod.getModId());
|
||||
try
|
||||
{
|
||||
if (cachedLogo == null)
|
||||
{
|
||||
BufferedImage logo = null;
|
||||
if (pack!=null)
|
||||
{
|
||||
logo = pack.getPackImage();
|
||||
}
|
||||
else
|
||||
{
|
||||
InputStream logoResource = getClass().getResourceAsStream(logoFile);
|
||||
if (logoResource != null)
|
||||
{
|
||||
logo = ImageIO.read(logoResource);
|
||||
}
|
||||
}
|
||||
if (logo != null)
|
||||
{
|
||||
cachedLogo = tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo));
|
||||
cachedLogoDimensions = new Dimension(logo.getWidth(), logo.getHeight());
|
||||
}
|
||||
}
|
||||
if (cachedLogo != null)
|
||||
{
|
||||
this.mc.renderEngine.bindTexture(cachedLogo);
|
||||
double scaleX = cachedLogoDimensions.width / 200.0;
|
||||
double scaleY = cachedLogoDimensions.height / 65.0;
|
||||
double scale = 1.0;
|
||||
if (scaleX > 1 || scaleY > 1)
|
||||
{
|
||||
scale = 1.0 / Math.max(scaleX, scaleY);
|
||||
}
|
||||
cachedLogoDimensions.width *= scale;
|
||||
cachedLogoDimensions.height *= scale;
|
||||
int top = 32;
|
||||
Tessellator tess = Tessellator.getInstance();
|
||||
WorldRenderer world = tess.getWorldRenderer();
|
||||
world.startDrawingQuads();
|
||||
world.addVertexWithUV(offset, top + cachedLogoDimensions.height, zLevel, 0, 1);
|
||||
world.addVertexWithUV(offset + cachedLogoDimensions.width, top + cachedLogoDimensions.height, zLevel, 1, 1);
|
||||
world.addVertexWithUV(offset + cachedLogoDimensions.width, top, zLevel, 1, 0);
|
||||
world.addVertexWithUV(offset, top, zLevel, 0, 0);
|
||||
tess.draw();
|
||||
|
||||
shifty += 65;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
this.fontRendererObj.drawStringWithShadow(selectedMod.getMetadata().name, offset, shifty, 0xFFFFFF);
|
||||
shifty += 12;
|
||||
|
||||
shifty = drawLine(String.format("Version: %s (%s)", selectedMod.getDisplayVersion(), selectedMod.getVersion()), offset, shifty);
|
||||
shifty = drawLine(String.format("Mod ID: '%s' Mod State: %s", selectedMod.getModId(), Loader.instance().getModState(selectedMod)), offset, shifty);
|
||||
if (!selectedMod.getMetadata().credits.isEmpty())
|
||||
{
|
||||
shifty = drawLine(String.format("Credits: %s", selectedMod.getMetadata().credits), offset, shifty);
|
||||
}
|
||||
shifty = drawLine(String.format("Authors: %s", selectedMod.getMetadata().getAuthorList()), offset, shifty);
|
||||
shifty = drawLine(String.format("URL: %s", selectedMod.getMetadata().url), offset, shifty);
|
||||
shifty = drawLine(selectedMod.getMetadata().childMods.isEmpty() ? "No child mods for this mod" : String.format("Child mods: %s", selectedMod.getMetadata().getChildModList()), offset, shifty);
|
||||
int rightSide = this.width - offset - 20;
|
||||
if (rightSide > 20)
|
||||
{
|
||||
this.getFontRenderer().drawSplitString(selectedMod.getMetadata().description, offset, shifty + 10, rightSide, 0xDDDDDD);
|
||||
}
|
||||
Disableable disableable = selectedMod.canBeDisabled();
|
||||
if (disableable == Disableable.RESTART)
|
||||
{
|
||||
disableModButton.enabled = true;
|
||||
disableModButton.visible = true;
|
||||
disableModButton.packedFGColour = 0xFF3377;
|
||||
}
|
||||
else if (disableable == Disableable.YES)
|
||||
{
|
||||
disableModButton.enabled = true;
|
||||
disableModButton.visible = true;
|
||||
disableModButton.packedFGColour = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
disableModButton.packedFGColour = 0;
|
||||
disableModButton.visible = true;
|
||||
disableModButton.enabled = false;
|
||||
}
|
||||
IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(selectedMod);
|
||||
if (guiFactory == null || guiFactory.mainConfigGuiClass() == null)
|
||||
{
|
||||
configModButton.visible = true;
|
||||
configModButton.enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
configModButton.visible = true;
|
||||
configModButton.enabled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = ( this.listWidth + this.width ) / 2;
|
||||
this.drawCenteredString(this.fontRendererObj, selectedMod.getName(), offset, 35, 0xFFFFFF);
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("Version: %s",selectedMod.getVersion()), offset, 45, 0xFFFFFF);
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("Mod State: %s",Loader.instance().getModState(selectedMod)), offset, 55, 0xFFFFFF);
|
||||
this.drawCenteredString(this.fontRendererObj, "No mod information found", offset, 65, 0xDDDDDD);
|
||||
this.drawCenteredString(this.fontRendererObj, "Ask your mod author to provide a mod mcmod.info file", offset, 75, 0xDDDDDD);
|
||||
configModButton.visible = false;
|
||||
disableModButton.visible = false;
|
||||
}
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
else
|
||||
{
|
||||
configModButton.visible = false;
|
||||
disableModButton.visible = false;
|
||||
}
|
||||
super.drawScreen(p_571_1_, p_571_2_, p_571_3_);
|
||||
|
||||
String text = I18n.format("fml.menu.mods.search");
|
||||
int x = ((10 + modList.right) / 2) - (getFontRenderer().getStringWidth(text) / 2);
|
||||
getFontRenderer().drawString(text, x, modList.bottom + 5, 0xFFFFFF);
|
||||
search.drawTextBox();
|
||||
}
|
||||
|
||||
Minecraft getMinecraftInstance()
|
||||
{
|
||||
return mc;
|
||||
}
|
||||
|
||||
FontRenderer getFontRenderer()
|
||||
{
|
||||
return fontRendererObj;
|
||||
}
|
||||
|
||||
public void selectModIndex(int index)
|
||||
{
|
||||
this.selected = index;
|
||||
this.selectedMod = (index >= 0 && index <= mods.size()) ? mods.get(selected) : null;
|
||||
cachedLogo = null;
|
||||
}
|
||||
|
||||
public boolean modIndexSelected(int index)
|
||||
{
|
||||
return index == selected;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
||||
public class GuiModOptionList extends GuiScrollingList {
|
||||
|
||||
private GuiIngameModOptions parent;
|
||||
|
||||
public GuiModOptionList(GuiIngameModOptions parent)
|
||||
{
|
||||
super(parent.mc, 150, parent.height, 32, parent.height - 65 + 4, 10, 35);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void elementClicked(int index, boolean doubleClick)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSelected(int index)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawSlot(int var1, int var2, int var3, int var4, Tessellator var5)
|
||||
{
|
||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth("Test 1", listWidth - 10), this.left + 3 , var3 + 2, 0xFF2222);
|
||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth("TEST 2", listWidth - 10), this.left + 3 , var3 + 12, 0xFF2222);
|
||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth("DISABLED", listWidth - 10), this.left + 3 , var3 + 22, 0xFF2222);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraftforge.fml.common.MissingModsException;
|
||||
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
|
||||
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
|
||||
|
||||
public class GuiModsMissing extends GuiErrorScreen
|
||||
{
|
||||
|
||||
private MissingModsException modsMissing;
|
||||
|
||||
public GuiModsMissing(MissingModsException modsMissing)
|
||||
{
|
||||
super(null,null);
|
||||
this.modsMissing = modsMissing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
this.buttonList.clear();
|
||||
}
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
int offset = Math.max(85 - modsMissing.missingMods.size() * 10, 10);
|
||||
this.drawCenteredString(this.fontRendererObj, "Forge Mod Loader has found a problem with your minecraft installation", this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, "The mods and versions listed below could not be found", this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=5;
|
||||
for (ArtifactVersion v : modsMissing.missingMods)
|
||||
{
|
||||
offset+=10;
|
||||
if (v instanceof DefaultArtifactVersion)
|
||||
{
|
||||
DefaultArtifactVersion dav = (DefaultArtifactVersion)v;
|
||||
if (dav.getRange() != null && dav.getRange().isUnboundedAbove())
|
||||
{
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("%s : minimum version required is %s", v.getLabel(), dav.getRange().getLowerBoundString()), this.width / 2, offset, 0xEEEEEE);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("%s : %s", v.getLabel(), v.getRangeString()), this.width / 2, offset, 0xEEEEEE);
|
||||
}
|
||||
offset+=20;
|
||||
this.drawCenteredString(this.fontRendererObj, "The file 'logs/fml-client-latest.log' contains more information", this.width / 2, offset, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.common.MissingModsException;
|
||||
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
|
||||
|
||||
public class GuiModsMissingForServer extends GuiScreen
|
||||
{
|
||||
private MissingModsException modsMissing;
|
||||
|
||||
public GuiModsMissingForServer(MissingModsException modsMissing)
|
||||
{
|
||||
this.modsMissing = modsMissing;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.buttonList.add(new GuiButton(1, this.width / 2 - 75, this.height - 38, I18n.format("gui.done")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton p_73875_1_)
|
||||
{
|
||||
if (p_73875_1_.enabled && p_73875_1_.id == 1)
|
||||
{
|
||||
FMLClientHandler.instance().showGuiScreen(null);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
int offset = Math.max(85 - modsMissing.missingMods.size() * 10, 10);
|
||||
this.drawCenteredString(this.fontRendererObj, "Forge Mod Loader could not connect to this server", this.width / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
this.drawCenteredString(this.fontRendererObj, "The mods and versions listed below could not be found", this.width / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
this.drawCenteredString(this.fontRendererObj, "They are required to play on this server", this.width / 2, offset, 0xFFFFFF);
|
||||
offset += 5;
|
||||
for (ArtifactVersion v : modsMissing.missingMods)
|
||||
{
|
||||
offset += 10;
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("%s : %s", v.getLabel(), v.getRangeString()), this.width / 2, offset, 0xEEEEEE);
|
||||
}
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.common.StartupQuery;
|
||||
|
||||
public class GuiNotification extends GuiScreen
|
||||
{
|
||||
public GuiNotification(StartupQuery query)
|
||||
{
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height - 38, I18n.format("gui.done")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.enabled && button.id == 0)
|
||||
{
|
||||
FMLClientHandler.instance().showGuiScreen(null);
|
||||
query.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
|
||||
String[] lines = query.getText().split("\n");
|
||||
|
||||
int spaceAvailable = this.height - 38 - 20;
|
||||
int spaceRequired = Math.min(spaceAvailable, 10 + 10 * lines.length);
|
||||
|
||||
int offset = 10 + (spaceAvailable - spaceRequired) / 2; // vertically centered
|
||||
|
||||
for (String line : lines)
|
||||
{
|
||||
if (offset >= spaceAvailable)
|
||||
{
|
||||
this.drawCenteredString(this.fontRendererObj, "...", this.width / 2, offset, 0xFFFFFF);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!line.isEmpty()) this.drawCenteredString(this.fontRendererObj, line, this.width / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
}
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
protected final StartupQuery query;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiLabel;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiSelectWorld;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import net.minecraftforge.fml.common.StartupQuery;
|
||||
import net.minecraftforge.fml.common.ZipperUtil;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
public class GuiOldSaveLoadConfirm extends GuiYesNo implements GuiYesNoCallback {
|
||||
|
||||
private String dirName;
|
||||
private String saveName;
|
||||
private File zip;
|
||||
private GuiScreen parent;
|
||||
public GuiOldSaveLoadConfirm(String dirName, String saveName, GuiScreen parent)
|
||||
{
|
||||
super(null, "", "", 0);
|
||||
this.parent = parent;
|
||||
this.dirName = dirName;
|
||||
this.saveName = saveName;
|
||||
this.zip = new File(FMLClientHandler.instance().getClient().mcDataDir,String.format("%s-%2$td%2$tm%2$ty%2$tH%2$tM%2$tS.zip", dirName, System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("The world %s contains pre-update modding data", saveName), this.width / 2, 50, 16777215);
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("There may be problems updating it to this version"), this.width / 2, 70, 16777215);
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("FML will save a zip to %s", zip.getName()), this.width / 2, 90, 16777215);
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("Do you wish to continue loading?"), this.width / 2, 110, 16777215);
|
||||
int k;
|
||||
|
||||
for (k = 0; k < this.buttonList.size(); ++k)
|
||||
{
|
||||
((GuiButton)this.buttonList.get(k)).drawButton(this.mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
for (k = 0; k < this.labelList.size(); ++k)
|
||||
{
|
||||
((GuiLabel)this.labelList.get(k)).drawLabel(this.mc, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.id == 1)
|
||||
{
|
||||
ObfuscationReflectionHelper.setPrivateValue(GuiSelectWorld.class, (GuiSelectWorld)parentScreen, false, "field_"+"146634_i");
|
||||
FMLClientHandler.instance().showGuiScreen(parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.info("Capturing current state of world %s into file %s", saveName, zip.getAbsolutePath());
|
||||
try
|
||||
{
|
||||
String skip = System.getProperty("fml.doNotBackup");
|
||||
if (skip == null || !"true".equals(skip))
|
||||
{
|
||||
ZipperUtil.zip(new File(FMLClientHandler.instance().getSavesDir(), dirName), zip);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int x = 0; x < 10; x++)
|
||||
FMLLog.severe("!!!!!!!!!! UPDATING WORLD WITHOUT DOING BACKUP !!!!!!!!!!!!!!!!");
|
||||
}
|
||||
} catch (IOException e)
|
||||
{
|
||||
FMLLog.log(Level.WARN, e, "There was a problem saving the backup %s. Please fix and try again", zip.getName());
|
||||
FMLClientHandler.instance().showGuiScreen(new GuiBackupFailed(parent, zip));
|
||||
return;
|
||||
}
|
||||
FMLClientHandler.instance().showGuiScreen(null);
|
||||
|
||||
try
|
||||
{
|
||||
mc.launchIntegratedServer(dirName, saveName, (WorldSettings)null);
|
||||
}
|
||||
catch (StartupQuery.AbortedException e)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,459 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public abstract class GuiScrollingList
|
||||
{
|
||||
private final Minecraft client;
|
||||
protected final int listWidth;
|
||||
protected final int listHeight;
|
||||
protected final int top;
|
||||
protected final int bottom;
|
||||
protected final int right;
|
||||
protected final int left;
|
||||
protected final int slotHeight;
|
||||
private int scrollUpActionId;
|
||||
private int scrollDownActionId;
|
||||
protected int mouseX;
|
||||
protected int mouseY;
|
||||
private float initialMouseClickY = -2.0F;
|
||||
private float scrollFactor;
|
||||
private float scrollDistance;
|
||||
protected int selectedIndex = -1;
|
||||
private long lastClickTime = 0L;
|
||||
private boolean field_25123_p = true;
|
||||
private boolean field_27262_q;
|
||||
private int field_27261_r;
|
||||
|
||||
public GuiScrollingList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight)
|
||||
{
|
||||
this.client = client;
|
||||
this.listWidth = width;
|
||||
this.listHeight = height;
|
||||
this.top = top;
|
||||
this.bottom = bottom;
|
||||
this.slotHeight = entryHeight;
|
||||
this.left = left;
|
||||
this.right = width + this.left;
|
||||
}
|
||||
|
||||
public void func_27258_a(boolean p_27258_1_)
|
||||
{
|
||||
this.field_25123_p = p_27258_1_;
|
||||
}
|
||||
|
||||
protected void func_27259_a(boolean p_27259_1_, int p_27259_2_)
|
||||
{
|
||||
this.field_27262_q = p_27259_1_;
|
||||
this.field_27261_r = p_27259_2_;
|
||||
|
||||
if (!p_27259_1_)
|
||||
{
|
||||
this.field_27261_r = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int getSize();
|
||||
|
||||
protected abstract void elementClicked(int index, boolean doubleClick);
|
||||
|
||||
protected abstract boolean isSelected(int index);
|
||||
|
||||
protected int getContentHeight()
|
||||
{
|
||||
return this.getSize() * this.slotHeight + this.field_27261_r;
|
||||
}
|
||||
|
||||
protected abstract void drawBackground();
|
||||
|
||||
protected abstract void drawSlot(int var1, int var2, int var3, int var4, Tessellator var5);
|
||||
|
||||
protected void func_27260_a(int p_27260_1_, int p_27260_2_, Tessellator p_27260_3_) {}
|
||||
|
||||
protected void func_27255_a(int p_27255_1_, int p_27255_2_) {}
|
||||
|
||||
protected void func_27257_b(int p_27257_1_, int p_27257_2_) {}
|
||||
|
||||
public int func_27256_c(int p_27256_1_, int p_27256_2_)
|
||||
|
||||
{
|
||||
int var3 = this.left + 1;
|
||||
int var4 = this.left + this.listWidth - 7;
|
||||
int var5 = p_27256_2_ - this.top - this.field_27261_r + (int)this.scrollDistance - 4;
|
||||
int var6 = var5 / this.slotHeight;
|
||||
return p_27256_1_ >= var3 && p_27256_1_ <= var4 && var6 >= 0 && var5 >= 0 && var6 < this.getSize() ? var6 : -1;
|
||||
}
|
||||
|
||||
public void registerScrollButtons(@SuppressWarnings("rawtypes") List p_22240_1_, int p_22240_2_, int p_22240_3_)
|
||||
{
|
||||
this.scrollUpActionId = p_22240_2_;
|
||||
this.scrollDownActionId = p_22240_3_;
|
||||
}
|
||||
|
||||
private void applyScrollLimits()
|
||||
{
|
||||
int var1 = this.getContentHeight() - (this.bottom - this.top - 4);
|
||||
|
||||
if (var1 < 0)
|
||||
{
|
||||
var1 /= 2;
|
||||
}
|
||||
|
||||
if (this.scrollDistance < 0.0F)
|
||||
{
|
||||
this.scrollDistance = 0.0F;
|
||||
}
|
||||
|
||||
if (this.scrollDistance > (float)var1)
|
||||
{
|
||||
this.scrollDistance = (float)var1;
|
||||
}
|
||||
}
|
||||
|
||||
public void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.enabled)
|
||||
{
|
||||
if (button.id == this.scrollUpActionId)
|
||||
{
|
||||
this.scrollDistance -= (float)(this.slotHeight * 2 / 3);
|
||||
this.initialMouseClickY = -2.0F;
|
||||
this.applyScrollLimits();
|
||||
}
|
||||
else if (button.id == this.scrollDownActionId)
|
||||
{
|
||||
this.scrollDistance += (float)(this.slotHeight * 2 / 3);
|
||||
this.initialMouseClickY = -2.0F;
|
||||
this.applyScrollLimits();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawScreen(int mouseX, int mouseY, float p_22243_3_)
|
||||
{
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
this.drawBackground();
|
||||
int listLength = this.getSize();
|
||||
int scrollBarXStart = this.left + this.listWidth - 6;
|
||||
int scrollBarXEnd = scrollBarXStart + 6;
|
||||
int boxLeft = this.left;
|
||||
int boxRight = scrollBarXStart-1;
|
||||
int var10;
|
||||
int var11;
|
||||
int var13;
|
||||
int var19;
|
||||
|
||||
if (Mouse.isButtonDown(0))
|
||||
{
|
||||
if (this.initialMouseClickY == -1.0F)
|
||||
{
|
||||
boolean var7 = true;
|
||||
|
||||
if (mouseY >= this.top && mouseY <= this.bottom)
|
||||
{
|
||||
var10 = mouseY - this.top - this.field_27261_r + (int)this.scrollDistance - 4;
|
||||
var11 = var10 / this.slotHeight;
|
||||
|
||||
if (mouseX >= boxLeft && mouseX <= boxRight && var11 >= 0 && var10 >= 0 && var11 < listLength)
|
||||
{
|
||||
boolean var12 = var11 == this.selectedIndex && System.currentTimeMillis() - this.lastClickTime < 250L;
|
||||
this.elementClicked(var11, var12);
|
||||
this.selectedIndex = var11;
|
||||
this.lastClickTime = System.currentTimeMillis();
|
||||
}
|
||||
else if (mouseX >= boxLeft && mouseX <= boxRight && var10 < 0)
|
||||
{
|
||||
this.func_27255_a(mouseX - boxLeft, mouseY - this.top + (int)this.scrollDistance - 4);
|
||||
var7 = false;
|
||||
}
|
||||
|
||||
if (mouseX >= scrollBarXStart && mouseX <= scrollBarXEnd)
|
||||
{
|
||||
this.scrollFactor = -1.0F;
|
||||
var19 = this.getContentHeight() - (this.bottom - this.top - 4);
|
||||
|
||||
if (var19 < 1)
|
||||
{
|
||||
var19 = 1;
|
||||
}
|
||||
|
||||
var13 = (int)((float)((this.bottom - this.top) * (this.bottom - this.top)) / (float)this.getContentHeight());
|
||||
|
||||
if (var13 < 32)
|
||||
{
|
||||
var13 = 32;
|
||||
}
|
||||
|
||||
if (var13 > this.bottom - this.top - 8)
|
||||
{
|
||||
var13 = this.bottom - this.top - 8;
|
||||
}
|
||||
|
||||
this.scrollFactor /= (float)(this.bottom - this.top - var13) / (float)var19;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scrollFactor = 1.0F;
|
||||
}
|
||||
|
||||
if (var7)
|
||||
{
|
||||
this.initialMouseClickY = (float)mouseY;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.initialMouseClickY = -2.0F;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.initialMouseClickY = -2.0F;
|
||||
}
|
||||
}
|
||||
else if (this.initialMouseClickY >= 0.0F)
|
||||
{
|
||||
this.scrollDistance -= ((float)mouseY - this.initialMouseClickY) * this.scrollFactor;
|
||||
this.initialMouseClickY = (float)mouseY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (Mouse.next())
|
||||
{
|
||||
int var16 = Mouse.getEventDWheel();
|
||||
|
||||
if (var16 != 0)
|
||||
{
|
||||
if (var16 > 0)
|
||||
{
|
||||
var16 = -1;
|
||||
}
|
||||
else if (var16 < 0)
|
||||
{
|
||||
var16 = 1;
|
||||
}
|
||||
|
||||
this.scrollDistance += (float)(var16 * this.slotHeight / 2);
|
||||
}
|
||||
}
|
||||
|
||||
this.initialMouseClickY = -1.0F;
|
||||
}
|
||||
|
||||
this.applyScrollLimits();
|
||||
Tessellator tess = Tessellator.getInstance();
|
||||
WorldRenderer worldr = tess.getWorldRenderer();
|
||||
if (this.client.theWorld != null)
|
||||
{
|
||||
this.drawGradientRect(this.left, this.top, this.right, this.bottom, -1072689136, -804253680);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableFog();
|
||||
this.client.renderEngine.bindTexture(Gui.optionsBackground);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
float var17 = 32.0F;
|
||||
worldr.startDrawingQuads();
|
||||
worldr.setColorOpaque_I(2105376);
|
||||
worldr.addVertexWithUV((double)this.left, (double)this.bottom, 0.0D, (double)((float)this.left / var17), (double)((float)(this.bottom + (int)this.scrollDistance) / var17));
|
||||
worldr.addVertexWithUV((double)this.right, (double)this.bottom, 0.0D, (double)((float)this.right / var17), (double)((float)(this.bottom + (int)this.scrollDistance) / var17));
|
||||
worldr.addVertexWithUV((double)this.right, (double)this.top, 0.0D, (double)((float)this.right / var17), (double)((float)(this.top + (int)this.scrollDistance) / var17));
|
||||
worldr.addVertexWithUV((double)this.left, (double)this.top, 0.0D, (double)((float)this.left / var17), (double)((float)(this.top + (int)this.scrollDistance) / var17));
|
||||
tess.draw();
|
||||
}
|
||||
// boxRight = this.listWidth / 2 - 92 - 16;
|
||||
var10 = this.top + 4 - (int)this.scrollDistance;
|
||||
|
||||
if (this.field_27262_q)
|
||||
{
|
||||
this.func_27260_a(boxRight, var10, tess);
|
||||
}
|
||||
|
||||
int var14;
|
||||
|
||||
for (var11 = 0; var11 < listLength; ++var11)
|
||||
{
|
||||
var19 = var10 + var11 * this.slotHeight + this.field_27261_r;
|
||||
var13 = this.slotHeight - 4;
|
||||
|
||||
if (var19 <= this.bottom && var19 + var13 >= this.top)
|
||||
{
|
||||
if (this.field_25123_p && this.isSelected(var11))
|
||||
{
|
||||
var14 = boxLeft;
|
||||
int var15 = boxRight;
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.disableTexture2D();
|
||||
worldr.startDrawingQuads();
|
||||
worldr.setColorOpaque_I(8421504);
|
||||
worldr.addVertexWithUV((double)var14, (double)(var19 + var13 + 2), 0.0D, 0.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)var15, (double)(var19 + var13 + 2), 0.0D, 1.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)var15, (double)(var19 - 2), 0.0D, 1.0D, 0.0D);
|
||||
worldr.addVertexWithUV((double)var14, (double)(var19 - 2), 0.0D, 0.0D, 0.0D);
|
||||
worldr.setColorOpaque_I(0);
|
||||
worldr.addVertexWithUV((double)(var14 + 1), (double)(var19 + var13 + 1), 0.0D, 0.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)(var15 - 1), (double)(var19 + var13 + 1), 0.0D, 1.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)(var15 - 1), (double)(var19 - 1), 0.0D, 1.0D, 0.0D);
|
||||
worldr.addVertexWithUV((double)(var14 + 1), (double)(var19 - 1), 0.0D, 0.0D, 0.0D);
|
||||
tess.draw();
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
|
||||
this.drawSlot(var11, boxRight, var19, var13, tess);
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager.disableDepth();
|
||||
byte border = 4;
|
||||
if (this.client.theWorld == null)
|
||||
{
|
||||
this.overlayBackground(0, this.top, 255, 255);
|
||||
this.overlayBackground(this.bottom, this.listHeight, 255, 255);
|
||||
}
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.shadeModel(GL11.GL_SMOOTH);
|
||||
GlStateManager.disableTexture2D();
|
||||
worldr.startDrawingQuads();
|
||||
worldr.setColorRGBA_I(0, 0);
|
||||
worldr.addVertexWithUV((double)this.left, (double)(this.top + border), 0.0D, 0.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)this.right, (double)(this.top + border), 0.0D, 1.0D, 1.0D);
|
||||
worldr.setColorRGBA_I(0, 255);
|
||||
worldr.addVertexWithUV((double)this.right, (double)this.top, 0.0D, 1.0D, 0.0D);
|
||||
worldr.addVertexWithUV((double)this.left, (double)this.top, 0.0D, 0.0D, 0.0D);
|
||||
tess.draw();
|
||||
worldr.startDrawingQuads();
|
||||
worldr.setColorRGBA_I(0, 255);
|
||||
worldr.addVertexWithUV((double)this.left, (double)this.bottom, 0.0D, 0.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)this.right, (double)this.bottom, 0.0D, 1.0D, 1.0D);
|
||||
worldr.setColorRGBA_I(0, 0);
|
||||
worldr.addVertexWithUV((double)this.right, (double)(this.bottom - border), 0.0D, 1.0D, 0.0D);
|
||||
worldr.addVertexWithUV((double)this.left, (double)(this.bottom - border), 0.0D, 0.0D, 0.0D);
|
||||
tess.draw();
|
||||
var19 = this.getContentHeight() - (this.bottom - this.top - 4);
|
||||
|
||||
if (var19 > 0)
|
||||
{
|
||||
var13 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
|
||||
|
||||
if (var13 < 32)
|
||||
{
|
||||
var13 = 32;
|
||||
}
|
||||
|
||||
if (var13 > this.bottom - this.top - 8)
|
||||
{
|
||||
var13 = this.bottom - this.top - 8;
|
||||
}
|
||||
|
||||
var14 = (int)this.scrollDistance * (this.bottom - this.top - var13) / var19 + this.top;
|
||||
|
||||
if (var14 < this.top)
|
||||
{
|
||||
var14 = this.top;
|
||||
}
|
||||
|
||||
worldr.startDrawingQuads();
|
||||
worldr.setColorRGBA_I(0, 255);
|
||||
worldr.addVertexWithUV((double)scrollBarXStart, (double)this.bottom, 0.0D, 0.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)scrollBarXEnd, (double)this.bottom, 0.0D, 1.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)scrollBarXEnd, (double)this.top, 0.0D, 1.0D, 0.0D);
|
||||
worldr.addVertexWithUV((double)scrollBarXStart, (double)this.top, 0.0D, 0.0D, 0.0D);
|
||||
tess.draw();
|
||||
worldr.startDrawingQuads();
|
||||
worldr.setColorRGBA_I(8421504, 255);
|
||||
worldr.addVertexWithUV((double)scrollBarXStart, (double)(var14 + var13), 0.0D, 0.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)scrollBarXEnd, (double)(var14 + var13), 0.0D, 1.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)scrollBarXEnd, (double)var14, 0.0D, 1.0D, 0.0D);
|
||||
worldr.addVertexWithUV((double)scrollBarXStart, (double)var14, 0.0D, 0.0D, 0.0D);
|
||||
tess.draw();
|
||||
worldr.startDrawingQuads();
|
||||
worldr.setColorRGBA_I(12632256, 255);
|
||||
worldr.addVertexWithUV((double)scrollBarXStart, (double)(var14 + var13 - 1), 0.0D, 0.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)(scrollBarXEnd - 1), (double)(var14 + var13 - 1), 0.0D, 1.0D, 1.0D);
|
||||
worldr.addVertexWithUV((double)(scrollBarXEnd - 1), (double)var14, 0.0D, 1.0D, 0.0D);
|
||||
worldr.addVertexWithUV((double)scrollBarXStart, (double)var14, 0.0D, 0.0D, 0.0D);
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
this.func_27257_b(mouseX, mouseY);
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.shadeModel(GL11.GL_FLAT);
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
|
||||
private void overlayBackground(int p_22239_1_, int p_22239_2_, int p_22239_3_, int p_22239_4_)
|
||||
{
|
||||
Tessellator var5 = Tessellator.getInstance();
|
||||
WorldRenderer worldr = var5.getWorldRenderer();
|
||||
this.client.renderEngine.bindTexture(Gui.optionsBackground);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
float var6 = 32.0F;
|
||||
worldr.startDrawingQuads();
|
||||
worldr.setColorRGBA_I(4210752, p_22239_4_);
|
||||
worldr.addVertexWithUV(0.0D, (double)p_22239_2_, 0.0D, 0.0D, (double)((float)p_22239_2_ / var6));
|
||||
worldr.addVertexWithUV((double)this.listWidth + 30, (double)p_22239_2_, 0.0D, (double)((float)(this.listWidth + 30) / var6), (double)((float)p_22239_2_ / var6));
|
||||
worldr.setColorRGBA_I(4210752, p_22239_3_);
|
||||
worldr.addVertexWithUV((double)this.listWidth + 30, (double)p_22239_1_, 0.0D, (double)((float)(this.listWidth + 30) / var6), (double)((float)p_22239_1_ / var6));
|
||||
worldr.addVertexWithUV(0.0D, (double)p_22239_1_, 0.0D, 0.0D, (double)((float)p_22239_1_ / var6));
|
||||
var5.draw();
|
||||
}
|
||||
|
||||
protected void drawGradientRect(int par1, int par2, int par3, int par4, int par5, int par6)
|
||||
{
|
||||
float f = (float)(par5 >> 24 & 255) / 255.0F;
|
||||
float f1 = (float)(par5 >> 16 & 255) / 255.0F;
|
||||
float f2 = (float)(par5 >> 8 & 255) / 255.0F;
|
||||
float f3 = (float)(par5 & 255) / 255.0F;
|
||||
float f4 = (float)(par6 >> 24 & 255) / 255.0F;
|
||||
float f5 = (float)(par6 >> 16 & 255) / 255.0F;
|
||||
float f6 = (float)(par6 >> 8 & 255) / 255.0F;
|
||||
float f7 = (float)(par6 & 255) / 255.0F;
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
GlStateManager.shadeModel(GL11.GL_SMOOTH);
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
||||
worldrenderer.startDrawingQuads();
|
||||
worldrenderer.setColorRGBA_F(f1, f2, f3, f);
|
||||
worldrenderer.addVertex((double)par3, (double)par2, 0.0D);
|
||||
worldrenderer.addVertex((double)par1, (double)par2, 0.0D);
|
||||
worldrenderer.setColorRGBA_F(f5, f6, f7, f4);
|
||||
worldrenderer.addVertex((double)par1, (double)par4, 0.0D);
|
||||
worldrenderer.addVertex((double)par3, (double)par4, 0.0D);
|
||||
tessellator.draw();
|
||||
GlStateManager.shadeModel(GL11.GL_FLAT);
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.StringUtils;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
|
||||
/**
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public class GuiSlotModList extends GuiScrollingList
|
||||
{
|
||||
private GuiModList parent;
|
||||
private ArrayList<ModContainer> mods;
|
||||
|
||||
public GuiSlotModList(GuiModList parent, ArrayList<ModContainer> mods, int listWidth)
|
||||
{
|
||||
super(parent.getMinecraftInstance(), listWidth, parent.height, 32, parent.height - 88 + 4, 10, 35);
|
||||
this.parent=parent;
|
||||
this.mods=mods;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize()
|
||||
{
|
||||
return mods.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void elementClicked(int var1, boolean var2)
|
||||
{
|
||||
this.parent.selectModIndex(var1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSelected(int var1)
|
||||
{
|
||||
return this.parent.modIndexSelected(var1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground()
|
||||
{
|
||||
this.parent.drawDefaultBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentHeight()
|
||||
{
|
||||
return (this.getSize()) * 35 + 1;
|
||||
}
|
||||
|
||||
ArrayList<ModContainer> getMods()
|
||||
{
|
||||
return mods;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawSlot(int listIndex, int var2, int var3, int var4, Tessellator var5)
|
||||
{
|
||||
ModContainer mc=mods.get(listIndex);
|
||||
String name = StringUtils.stripControlCodes(mc.getName());
|
||||
String version = StringUtils.stripControlCodes(mc.getDisplayVersion());
|
||||
if (Loader.instance().getModState(mc)==ModState.DISABLED)
|
||||
{
|
||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(name, listWidth - 10), this.left + 3 , var3 + 2, 0xFF2222);
|
||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(version, listWidth - 10), this.left + 3 , var3 + 12, 0xFF2222);
|
||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth("DISABLED", listWidth - 10), this.left + 3 , var3 + 22, 0xFF2222);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(name, listWidth - 10), this.left + 3 , var3 + 2, 0xFFFFFF);
|
||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(version, listWidth - 10), this.left + 3 , var3 + 12, 0xCCCCCC);
|
||||
this.parent.getFontRenderer().drawString(this.parent.getFontRenderer().trimStringToWidth(mc.getMetadata() !=null ? mc.getMetadata().getChildModCountString() : "Metadata not found", listWidth - 10), this.left + 3 , var3 + 22, 0xCCCCCC);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.toposort.ModSortingException;
|
||||
import net.minecraftforge.fml.common.toposort.ModSortingException.SortingExceptionData;
|
||||
|
||||
public class GuiSortingProblem extends GuiScreen {
|
||||
private SortingExceptionData<ModContainer> failedList;
|
||||
|
||||
public GuiSortingProblem(ModSortingException modSorting)
|
||||
{
|
||||
this.failedList = modSorting.getExceptionData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
int offset = Math.max(85 - (failedList.getVisitedNodes().size() + 3) * 10, 10);
|
||||
this.drawCenteredString(this.fontRendererObj, "Forge Mod Loader has found a problem with your minecraft installation", this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, "A mod sorting cycle was detected and loading cannot continue", this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("The first mod in the cycle is %s", failedList.getFirstBadNode()), this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, "The remainder of the cycle involves these mods", this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=5;
|
||||
for (ModContainer mc : failedList.getVisitedNodes())
|
||||
{
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("%s : before: %s, after: %s", mc.toString(), mc.getDependants(), mc.getDependencies()), this.width / 2, offset, 0xEEEEEE);
|
||||
}
|
||||
offset+=20;
|
||||
this.drawCenteredString(this.fontRendererObj, "The file 'ForgeModLoader-client-0.log' contains more information", this.width / 2, offset, 0xFFFFFF);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.WrongMinecraftVersionException;
|
||||
|
||||
public class GuiWrongMinecraft extends GuiErrorScreen
|
||||
{
|
||||
private WrongMinecraftVersionException wrongMC;
|
||||
public GuiWrongMinecraft(WrongMinecraftVersionException wrongMC)
|
||||
{
|
||||
super(null,null);
|
||||
this.wrongMC = wrongMC;
|
||||
}
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
this.buttonList.clear();
|
||||
}
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
int offset = 75;
|
||||
this.drawCenteredString(this.fontRendererObj, "Forge Mod Loader has found a problem with your minecraft installation", this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("The mod listed below does not want to run in Minecraft version %s", Loader.instance().getMinecraftModContainer().getVersion()), this.width / 2, offset, 0xFFFFFF);
|
||||
offset+=5;
|
||||
offset+=10;
|
||||
this.drawCenteredString(this.fontRendererObj, String.format("%s (%s) wants Minecraft %s", wrongMC.mod.getName(), wrongMC.mod.getModId(), wrongMC.mod.acceptableMinecraftVersionRange()), this.width / 2, offset, 0xEEEEEE);
|
||||
offset+=20;
|
||||
this.drawCenteredString(this.fontRendererObj, "The file 'ForgeModLoader-client-0.log' contains more information", this.width / 2, offset, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
public interface IModGuiFactory {
|
||||
/**
|
||||
* Called when instantiated to initialize with the active minecraft instance.
|
||||
*
|
||||
* @param minecraftInstance the instance
|
||||
*/
|
||||
public void initialize(Minecraft minecraftInstance);
|
||||
/**
|
||||
* Return the name of a class extending {@link GuiScreen}. This class will
|
||||
* be instantiated when the "config" button is pressed in the mod list. It will
|
||||
* have a single argument constructor - the "parent" screen, the same as all
|
||||
* Minecraft GUIs. The expected behaviour is that this screen will replace the
|
||||
* "mod list" screen completely, and will return to the mod list screen through
|
||||
* the parent link, once the appropriate action is taken from the config screen.
|
||||
*
|
||||
* A null from this method indicates that the mod does not provide a "config"
|
||||
* button GUI screen, and the config button will be hidden/disabled.
|
||||
*
|
||||
* This config GUI is anticipated to provide configuration to the mod in a friendly
|
||||
* visual way. It should not be abused to set internals such as IDs (they're gonna
|
||||
* keep disappearing anyway), but rather, interesting behaviours. This config GUI
|
||||
* is never run when a server game is running, and should be used to configure
|
||||
* desired behaviours that affect server state. Costs, mod game modes, stuff like that
|
||||
* can be changed here.
|
||||
*
|
||||
* @return A class that will be instantiated on clicks on the config button
|
||||
* or null if no GUI is desired.
|
||||
*/
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass();
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of the "runtime" categories this mod wishes to populate with
|
||||
* GUI elements.
|
||||
*
|
||||
* Runtime categories are created on demand and organized in a 'lite' tree format.
|
||||
* The parent represents the parent node in the tree. There is one special parent
|
||||
* 'Help' that will always list first, and is generally meant to provide Help type
|
||||
* content for mods. The remaining parents will sort alphabetically, though
|
||||
* this may change if there is a lot of alphabetic abuse. "AAA" is probably never a valid
|
||||
* category parent.
|
||||
*
|
||||
* Runtime configuration itself falls into two flavours: in-game help, which is
|
||||
* generally non interactive except for the text it wishes to show, and client-only
|
||||
* affecting behaviours. This would include things like toggling minimaps, or cheat modes
|
||||
* or anything NOT affecting the behaviour of the server. Please don't abuse this to
|
||||
* change the state of the server in any way, this is intended to behave identically
|
||||
* when the server is local or remote.
|
||||
*
|
||||
* @return the set of options this mod wishes to have available, or empty if none
|
||||
*/
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories();
|
||||
|
||||
/**
|
||||
* Return an instance of a {@link RuntimeOptionGuiHandler} that handles painting the
|
||||
* right hand side option screen for the specified {@link RuntimeOptionCategoryElement}.
|
||||
*
|
||||
* @param element The element we wish to paint for
|
||||
* @return The Handler for painting it
|
||||
*/
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element);
|
||||
|
||||
/**
|
||||
* Represents an option category and entry in the runtime gui options list.
|
||||
*
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public static class RuntimeOptionCategoryElement {
|
||||
public final String parent;
|
||||
public final String child;
|
||||
|
||||
public RuntimeOptionCategoryElement(String parent, String child)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.child = child;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Responsible for painting the mod specific section of runtime options GUI for a particular category
|
||||
*
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public interface RuntimeOptionGuiHandler {
|
||||
/**
|
||||
* Called to add widgets to the screen, such as buttons.
|
||||
* GUI identifier numbers should start at 100 and increase.
|
||||
* The callback will be through {@link #actionCallback(int)}
|
||||
*
|
||||
* @param x X
|
||||
* @param y Y
|
||||
* @param w width
|
||||
* @param h height
|
||||
*/
|
||||
public void addWidgets(List<Gui> widgetList, int x, int y, int w, int h);
|
||||
|
||||
/**
|
||||
* Called to paint the rectangle specified.
|
||||
* @param x X
|
||||
* @param y Y
|
||||
* @param w width
|
||||
* @param h height
|
||||
*/
|
||||
public void paint(int x, int y, int w, int h);
|
||||
|
||||
/**
|
||||
* Called if a widget with id >= 100 is fired.
|
||||
*
|
||||
* @param actionId the actionId of the firing widget
|
||||
*/
|
||||
public void actionCallback(int actionId);
|
||||
|
||||
/**
|
||||
* Called when this handler is about to go away (probably replaced by another one, or closing the
|
||||
* option screen)
|
||||
*/
|
||||
public void close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,816 @@
|
||||
package net.minecraftforge.fml.client;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_ALPHA_TEST;
|
||||
import static org.lwjgl.opengl.GL11.GL_BLEND;
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
|
||||
import static org.lwjgl.opengl.GL11.GL_GREATER;
|
||||
import static org.lwjgl.opengl.GL11.GL_LEQUAL;
|
||||
import static org.lwjgl.opengl.GL11.GL_LIGHTING;
|
||||
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
|
||||
import static org.lwjgl.opengl.GL11.GL_NEAREST;
|
||||
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
|
||||
import static org.lwjgl.opengl.GL11.GL_QUADS;
|
||||
import static org.lwjgl.opengl.GL11.GL_RENDERER;
|
||||
import static org.lwjgl.opengl.GL11.GL_RGBA;
|
||||
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
|
||||
import static org.lwjgl.opengl.GL11.GL_VENDOR;
|
||||
import static org.lwjgl.opengl.GL11.GL_VERSION;
|
||||
import static org.lwjgl.opengl.GL11.glAlphaFunc;
|
||||
import static org.lwjgl.opengl.GL11.glBegin;
|
||||
import static org.lwjgl.opengl.GL11.glBindTexture;
|
||||
import static org.lwjgl.opengl.GL11.glBlendFunc;
|
||||
import static org.lwjgl.opengl.GL11.glClear;
|
||||
import static org.lwjgl.opengl.GL11.glClearColor;
|
||||
import static org.lwjgl.opengl.GL11.glColor3ub;
|
||||
import static org.lwjgl.opengl.GL11.glDeleteTextures;
|
||||
import static org.lwjgl.opengl.GL11.glDepthFunc;
|
||||
import static org.lwjgl.opengl.GL11.glDisable;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glEnd;
|
||||
import static org.lwjgl.opengl.GL11.glGenTextures;
|
||||
import static org.lwjgl.opengl.GL11.glGetString;
|
||||
import static org.lwjgl.opengl.GL11.glLoadIdentity;
|
||||
import static org.lwjgl.opengl.GL11.glMatrixMode;
|
||||
import static org.lwjgl.opengl.GL11.glOrtho;
|
||||
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glRotatef;
|
||||
import static org.lwjgl.opengl.GL11.glScalef;
|
||||
import static org.lwjgl.opengl.GL11.glTexCoord2f;
|
||||
import static org.lwjgl.opengl.GL11.glTexImage2D;
|
||||
import static org.lwjgl.opengl.GL11.glTexParameteri;
|
||||
import static org.lwjgl.opengl.GL11.glTexSubImage2D;
|
||||
import static org.lwjgl.opengl.GL11.glTranslatef;
|
||||
import static org.lwjgl.opengl.GL11.glVertex2f;
|
||||
import static org.lwjgl.opengl.GL11.glViewport;
|
||||
import static org.lwjgl.opengl.GL12.GL_BGRA;
|
||||
import static org.lwjgl.opengl.GL12.GL_UNSIGNED_INT_8_8_8_8_REV;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.FileResourcePack;
|
||||
import net.minecraft.client.resources.FolderResourcePack;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.EnhancedRuntimeException;
|
||||
import net.minecraftforge.fml.common.EnhancedRuntimeException.WrappedPrintStream;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.ICrashCallable;
|
||||
import net.minecraftforge.fml.common.ProgressManager;
|
||||
import net.minecraftforge.fml.common.ProgressManager.ProgressBar;
|
||||
import net.minecraftforge.fml.common.asm.FMLSanityChecker;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.Drawable;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.SharedDrawable;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
|
||||
/**
|
||||
* @deprecated not a stable API, will break, don't use this yet
|
||||
*/
|
||||
@Deprecated
|
||||
public class SplashProgress
|
||||
{
|
||||
private static Drawable d;
|
||||
private static volatile boolean pause = false;
|
||||
private static volatile boolean done = false;
|
||||
private static Thread thread;
|
||||
private static volatile Throwable threadError;
|
||||
private static int angle = 0;
|
||||
private static final Lock lock = new ReentrantLock(true);
|
||||
private static SplashFontRenderer fontRenderer;
|
||||
|
||||
private static final IResourcePack mcPack = Minecraft.getMinecraft().mcDefaultResourcePack;
|
||||
private static final IResourcePack fmlPack = createResourcePack(FMLSanityChecker.fmlLocation);
|
||||
private static IResourcePack miscPack;
|
||||
|
||||
private static Texture fontTexture;
|
||||
private static Texture logoTexture;
|
||||
private static Texture forgeTexture;
|
||||
|
||||
private static Properties config;
|
||||
|
||||
private static boolean enabled;
|
||||
private static boolean rotate;
|
||||
private static int logoOffset;
|
||||
private static int backgroundColor;
|
||||
private static int fontColor;
|
||||
private static int barBorderColor;
|
||||
private static int barColor;
|
||||
private static int barBackgroundColor;
|
||||
static final Semaphore mutex = new Semaphore(1);
|
||||
|
||||
private static String getString(String name, String def)
|
||||
{
|
||||
String value = config.getProperty(name, def);
|
||||
config.setProperty(name, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private static boolean getBool(String name, boolean def)
|
||||
{
|
||||
return Boolean.parseBoolean(getString(name, Boolean.toString(def)));
|
||||
}
|
||||
|
||||
private static int getInt(String name, int def)
|
||||
{
|
||||
return Integer.decode(getString(name, Integer.toString(def)));
|
||||
}
|
||||
|
||||
private static int getHex(String name, int def)
|
||||
{
|
||||
return Integer.decode(getString(name, "0x" + Integer.toString(def, 16).toUpperCase()));
|
||||
}
|
||||
|
||||
public static void start()
|
||||
{
|
||||
File configFile = new File(Minecraft.getMinecraft().mcDataDir, "config/splash.properties");
|
||||
FileReader r = null;
|
||||
config = new Properties();
|
||||
try
|
||||
{
|
||||
r = new FileReader(configFile);
|
||||
config.load(r);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
FMLLog.info("Could not load splash.properties, will create a default one");
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(r);
|
||||
}
|
||||
|
||||
// Enable if we have the flag, and there's either no optifine, or optifine has added a key to the blackboard ("optifine.ForgeSplashCompatible")
|
||||
// Optifine authors - add this key to the blackboard if you feel your modifications are now compatible with this code.
|
||||
enabled = getBool("enabled", true) && ( (!FMLClientHandler.instance().hasOptifine()) || Launch.blackboard.containsKey("optifine.ForgeSplashCompatible"));
|
||||
rotate = getBool("rotate", false);
|
||||
logoOffset = getInt("logoOffset", 0);
|
||||
backgroundColor = getHex("background", 0xFFFFFF);
|
||||
fontColor = getHex("font", 0x000000);
|
||||
barBorderColor = getHex("barBorder", 0xC0C0C0);
|
||||
barColor = getHex("bar", 0xCB3D35);
|
||||
barBackgroundColor = getHex("barBackground", 0xFFFFFF);
|
||||
|
||||
final ResourceLocation fontLoc = new ResourceLocation(getString("fontTexture", "textures/font/ascii.png"));
|
||||
final ResourceLocation logoLoc = new ResourceLocation(getString("logoTexture", "textures/gui/title/mojang.png"));
|
||||
final ResourceLocation forgeLoc = new ResourceLocation(getString("forgeTexture", "fml:textures/gui/forge.gif"));
|
||||
|
||||
File miscPackFile = new File(Minecraft.getMinecraft().mcDataDir, getString("resourcePackPath", "resources"));
|
||||
|
||||
FileWriter w = null;
|
||||
try
|
||||
{
|
||||
w = new FileWriter(configFile);
|
||||
config.store(w, "Splash screen properties");
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Could not save the splash.properties file");
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(w);
|
||||
}
|
||||
|
||||
miscPack = createResourcePack(miscPackFile);
|
||||
|
||||
if(!enabled) return;
|
||||
// getting debug info out of the way, while we still can
|
||||
FMLCommonHandler.instance().registerCrashCallable(new ICrashCallable()
|
||||
{
|
||||
public String call() throws Exception
|
||||
{
|
||||
return "' Vendor: '" + glGetString(GL_VENDOR) +
|
||||
"' Version: '" + glGetString(GL_VERSION) +
|
||||
"' Renderer: '" + glGetString(GL_RENDERER) +
|
||||
"'";
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
return "GL info";
|
||||
}
|
||||
});
|
||||
CrashReport report = CrashReport.makeCrashReport(new Throwable()
|
||||
{
|
||||
@Override public String getMessage(){ return "This is just a prompt for computer specs to be printed. THIS IS NOT A ERROR"; }
|
||||
@Override public void printStackTrace(final PrintWriter s){ s.println(getMessage()); }
|
||||
@Override public void printStackTrace(final PrintStream s) { s.println(getMessage()); }
|
||||
}, "Loading screen debug info");
|
||||
System.out.println(report.getCompleteReport());
|
||||
|
||||
try
|
||||
{
|
||||
d = new SharedDrawable(Display.getDrawable());
|
||||
Display.getDrawable().releaseContext();
|
||||
d.makeCurrent();
|
||||
}
|
||||
catch (LWJGLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Thread mainThread = Thread.currentThread();
|
||||
thread = new Thread(new Runnable()
|
||||
{
|
||||
private final int barWidth = 400;
|
||||
private final int barHeight = 20;
|
||||
private final int textHeight2 = 20;
|
||||
private final int barOffset = 55;
|
||||
|
||||
public void run()
|
||||
{
|
||||
setGL();
|
||||
fontTexture = new Texture(fontLoc);
|
||||
logoTexture = new Texture(logoLoc);
|
||||
forgeTexture = new Texture(forgeLoc);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
fontRenderer = new SplashFontRenderer();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
while(!done)
|
||||
{
|
||||
ProgressBar first = null, penult = null, last = null;
|
||||
Iterator<ProgressBar> i = ProgressManager.barIterator();
|
||||
while(i.hasNext())
|
||||
{
|
||||
if(first == null) first = i.next();
|
||||
else
|
||||
{
|
||||
penult = last;
|
||||
last = i.next();
|
||||
}
|
||||
}
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// matrix setup
|
||||
int w = Display.getWidth();
|
||||
int h = Display.getHeight();
|
||||
glViewport(0, 0, w, h);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(320 - w/2, 320 + w/2, 240 + h/2, 240 - h/2, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
// mojang logo
|
||||
setColor(backgroundColor);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
logoTexture.bind();
|
||||
glBegin(GL_QUADS);
|
||||
logoTexture.texCoord(0, 0, 0);
|
||||
glVertex2f(320 - 256, 240 - 256);
|
||||
logoTexture.texCoord(0, 0, 1);
|
||||
glVertex2f(320 - 256, 240 + 256);
|
||||
logoTexture.texCoord(0, 1, 1);
|
||||
glVertex2f(320 + 256, 240 + 256);
|
||||
logoTexture.texCoord(0, 1, 0);
|
||||
glVertex2f(320 + 256, 240 - 256);
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
// bars
|
||||
if(first != null)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(320 - (float)barWidth / 2, 310, 0);
|
||||
drawBar(first);
|
||||
if(penult != null)
|
||||
{
|
||||
glTranslatef(0, barOffset, 0);
|
||||
drawBar(penult);
|
||||
}
|
||||
if(last != null)
|
||||
{
|
||||
glTranslatef(0, barOffset, 0);
|
||||
drawBar(last);
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
angle += 1;
|
||||
|
||||
// forge logo
|
||||
setColor(backgroundColor);
|
||||
float fw = (float)forgeTexture.getWidth() / 2 / 2;
|
||||
float fh = (float)forgeTexture.getHeight() / 2 / 2;
|
||||
if(rotate)
|
||||
{
|
||||
float sh = Math.max(fw, fh);
|
||||
glTranslatef(320 + w/2 - sh - logoOffset, 240 + h/2 - sh - logoOffset, 0);
|
||||
glRotatef(angle, 0, 0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTranslatef(320 + w/2 - fw - logoOffset, 240 + h/2 - fh - logoOffset, 0);
|
||||
}
|
||||
int f = (angle / 10) % forgeTexture.getFrames();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
forgeTexture.bind();
|
||||
glBegin(GL_QUADS);
|
||||
forgeTexture.texCoord(f, 0, 0);
|
||||
glVertex2f(-fw, -fh);
|
||||
forgeTexture.texCoord(f, 0, 1);
|
||||
glVertex2f(-fw, fh);
|
||||
forgeTexture.texCoord(f, 1, 1);
|
||||
glVertex2f(fw, fh);
|
||||
forgeTexture.texCoord(f, 1, 0);
|
||||
glVertex2f(fw, -fh);
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
// We use mutex to indicate safely to the main thread that we're taking the display global lock
|
||||
// So the main thread can skip processing messages while we're updating.
|
||||
// There are system setups where this call can pause for a while, because the GL implementation
|
||||
// is trying to impose a framerate or other thing is occurring. Without the mutex, the main
|
||||
// thread would delay waiting for the same global display lock
|
||||
mutex.acquireUninterruptibly();
|
||||
Display.update();
|
||||
// As soon as we're done, we release the mutex. The other thread can now ping the processmessages
|
||||
// call as often as it wants until we get get back here again
|
||||
mutex.release();
|
||||
if(pause)
|
||||
{
|
||||
clearGL();
|
||||
setGL();
|
||||
}
|
||||
Display.sync(100);
|
||||
}
|
||||
clearGL();
|
||||
}
|
||||
|
||||
private void setColor(int color)
|
||||
{
|
||||
glColor3ub((byte)((color >> 16) & 0xFF), (byte)((color >> 8) & 0xFF), (byte)(color & 0xFF));
|
||||
}
|
||||
|
||||
private void drawBox(int w, int h)
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(0, 0);
|
||||
glVertex2f(0, h);
|
||||
glVertex2f(w, h);
|
||||
glVertex2f(w, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
private void drawBar(ProgressBar b)
|
||||
{
|
||||
glPushMatrix();
|
||||
// title - message
|
||||
setColor(fontColor);
|
||||
glScalef(2, 2, 1);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
fontRenderer.drawString(b.getTitle() + " - " + b.getMessage(), 0, 0, 0x000000);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glPopMatrix();
|
||||
// border
|
||||
glPushMatrix();
|
||||
glTranslatef(0, textHeight2, 0);
|
||||
setColor(barBorderColor);
|
||||
drawBox(barWidth, barHeight);
|
||||
// interior
|
||||
setColor(barBackgroundColor);
|
||||
glTranslatef(1, 1, 0);
|
||||
drawBox(barWidth - 2, barHeight - 2);
|
||||
// slidy part
|
||||
setColor(barColor);
|
||||
drawBox((barWidth - 2) * (b.getStep() + 1) / (b.getSteps() + 1), barHeight - 2); // Step can sometimes be 0.
|
||||
// progress text
|
||||
String progress = "" + b.getStep() + "/" + b.getSteps();
|
||||
glTranslatef(((float)barWidth - 2) / 2 - fontRenderer.getStringWidth(progress), 2, 0);
|
||||
setColor(fontColor);
|
||||
glScalef(2, 2, 1);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
fontRenderer.drawString(progress, 0, 0, 0x000000);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
private void setGL()
|
||||
{
|
||||
lock.lock();
|
||||
try
|
||||
{
|
||||
Display.getDrawable().makeCurrent();
|
||||
}
|
||||
catch (LWJGLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
glClearColor((float)((backgroundColor >> 16) & 0xFF) / 0xFF, (float)((backgroundColor >> 8) & 0xFF) / 0xFF, (float)(backgroundColor & 0xFF) / 0xFF, 1);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
private void clearGL()
|
||||
{
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.displayWidth = Display.getWidth();
|
||||
mc.displayHeight = Display.getHeight();
|
||||
mc.resize(mc.displayWidth, mc.displayHeight);
|
||||
glClearColor(1, 1, 1, 1);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_GREATER, .1f);
|
||||
try
|
||||
{
|
||||
Display.getDrawable().releaseContext();
|
||||
}
|
||||
catch (LWJGLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler()
|
||||
{
|
||||
public void uncaughtException(Thread t, Throwable e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Splash thread Exception");
|
||||
threadError = e;
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
checkThreadState();
|
||||
}
|
||||
|
||||
private static void checkThreadState()
|
||||
{
|
||||
if(thread.getState() == Thread.State.TERMINATED || threadError != null)
|
||||
{
|
||||
throw new IllegalStateException("Splash thread", threadError);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Call before you need to explicitly modify GL context state during loading.
|
||||
* Resource loading doesn't usually require this call.
|
||||
* Call {@link #resume()} when you're done.
|
||||
* @deprecated not a stable API, will break, don't use this yet
|
||||
*/
|
||||
@Deprecated
|
||||
public static void pause()
|
||||
{
|
||||
if(!enabled) return;
|
||||
checkThreadState();
|
||||
pause = true;
|
||||
lock.lock();
|
||||
try
|
||||
{
|
||||
d.releaseContext();
|
||||
Display.getDrawable().makeCurrent();
|
||||
}
|
||||
catch (LWJGLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not a stable API, will break, don't use this yet
|
||||
*/
|
||||
@Deprecated
|
||||
public static void resume()
|
||||
{
|
||||
if(!enabled) return;
|
||||
checkThreadState();
|
||||
pause = false;
|
||||
try
|
||||
{
|
||||
Display.getDrawable().releaseContext();
|
||||
d.makeCurrent();
|
||||
}
|
||||
catch (LWJGLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
public static void finish()
|
||||
{
|
||||
if(!enabled) return;
|
||||
try
|
||||
{
|
||||
checkThreadState();
|
||||
done = true;
|
||||
thread.join();
|
||||
d.releaseContext();
|
||||
Display.getDrawable().makeCurrent();
|
||||
fontTexture.delete();
|
||||
logoTexture.delete();
|
||||
forgeTexture.delete();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
if (disableSplash())
|
||||
{
|
||||
throw new EnhancedRuntimeException(e)
|
||||
{
|
||||
@Override
|
||||
protected void printStackTrace(WrappedPrintStream stream)
|
||||
{
|
||||
stream.println("SplashProgress has detected a error loading Minecraft.");
|
||||
stream.println("This can sometimes be caused by bad video drivers.");
|
||||
stream.println("We have automatically disabeled the new Splash Screen in config/splash.properties.");
|
||||
stream.println("Try reloading minecraft before reporting any errors.");
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new EnhancedRuntimeException(e)
|
||||
{
|
||||
@Override
|
||||
protected void printStackTrace(WrappedPrintStream stream)
|
||||
{
|
||||
stream.println("SplashProgress has detected a error loading Minecraft.");
|
||||
stream.println("This can sometimes be caused by bad video drivers.");
|
||||
stream.println("Please try disabeling the new Splash Screen in config/splash.properties.");
|
||||
stream.println("After doing so, try reloading minecraft before reporting any errors.");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean disableSplash()
|
||||
{
|
||||
File configFile = new File(Minecraft.getMinecraft().mcDataDir, "config/splash.properties");
|
||||
File parent = configFile.getParentFile();
|
||||
if (!parent.exists())
|
||||
parent.mkdirs();
|
||||
|
||||
FileReader r = null;
|
||||
enabled = false;
|
||||
config.setProperty("enabled", "false");
|
||||
|
||||
FileWriter w = null;
|
||||
try
|
||||
{
|
||||
w = new FileWriter(configFile);
|
||||
config.store(w, "Splash screen properties");
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "Could not save the splash.properties file");
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(w);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IResourcePack createResourcePack(File file)
|
||||
{
|
||||
if(file.isDirectory())
|
||||
{
|
||||
return new FolderResourcePack(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FileResourcePack(file);
|
||||
}
|
||||
}
|
||||
|
||||
private static final IntBuffer buf = BufferUtils.createIntBuffer(4 * 1024 * 1024);
|
||||
|
||||
private static class Texture
|
||||
{
|
||||
private final ResourceLocation location;
|
||||
private final int name;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int frames;
|
||||
private final int size;
|
||||
|
||||
public Texture(ResourceLocation location)
|
||||
{
|
||||
InputStream s = null;
|
||||
try
|
||||
{
|
||||
this.location = location;
|
||||
s = open(location);
|
||||
ImageInputStream stream = ImageIO.createImageInputStream(s);
|
||||
Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
|
||||
if(!readers.hasNext()) throw new IOException("No suitable reader found for image" + location);
|
||||
ImageReader reader = readers.next();
|
||||
reader.setInput(stream);
|
||||
frames = reader.getNumImages(true);
|
||||
BufferedImage[] images = new BufferedImage[frames];
|
||||
for(int i = 0; i < frames; i++)
|
||||
{
|
||||
images[i] = reader.read(i);
|
||||
}
|
||||
reader.dispose();
|
||||
int size = 1;
|
||||
width = images[0].getWidth();
|
||||
height = images[0].getHeight();
|
||||
while((size / width) * (size / height) < frames) size *= 2;
|
||||
this.size = size;
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
synchronized(SplashProgress.class)
|
||||
{
|
||||
name = glGenTextures();
|
||||
glBindTexture(GL_TEXTURE_2D, name);
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, size, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (IntBuffer)null);
|
||||
checkGLError("Texture creation");
|
||||
for(int i = 0; i * (size / width) < frames; i++)
|
||||
{
|
||||
for(int j = 0; i * (size / width) + j < frames && j < size / width; j++)
|
||||
{
|
||||
buf.clear();
|
||||
BufferedImage image = images[i * (size / width) + j];
|
||||
for(int k = 0; k < height; k++)
|
||||
{
|
||||
for(int l = 0; l < width; l++)
|
||||
{
|
||||
buf.put(image.getRGB(l, k));
|
||||
}
|
||||
}
|
||||
buf.position(0).limit(width * height);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, j * width, i * height, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buf);
|
||||
checkGLError("Texture uploading");
|
||||
}
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(s);
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceLocation getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
public int getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getFrames()
|
||||
{
|
||||
return frames;
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
public void bind()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, name);
|
||||
}
|
||||
|
||||
public void delete()
|
||||
{
|
||||
glDeleteTextures(name);
|
||||
}
|
||||
|
||||
public float getU(int frame, float u)
|
||||
{
|
||||
return width * (frame % (size / width) + u) / size;
|
||||
}
|
||||
|
||||
public float getV(int frame, float v)
|
||||
{
|
||||
return height * (frame / (size / width) + v) / size;
|
||||
}
|
||||
|
||||
public void texCoord(int frame, float u, float v)
|
||||
{
|
||||
glTexCoord2f(getU(frame, u), getV(frame, v));
|
||||
}
|
||||
}
|
||||
|
||||
private static class SplashFontRenderer extends FontRenderer
|
||||
{
|
||||
public SplashFontRenderer()
|
||||
{
|
||||
super(Minecraft.getMinecraft().gameSettings, fontTexture.getLocation(), null, false);
|
||||
super.onResourceManagerReload(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindTexture(ResourceLocation location)
|
||||
{
|
||||
if(location != locationFontTexture) throw new IllegalArgumentException();
|
||||
fontTexture.bind();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream getResourceInputStream(ResourceLocation location) throws IOException
|
||||
{
|
||||
return Minecraft.getMinecraft().mcDefaultResourcePack.getInputStream(location);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawVanillaScreen(TextureManager renderEngine) throws LWJGLException
|
||||
{
|
||||
if(!enabled)
|
||||
{
|
||||
Minecraft.getMinecraft().drawSplashScreen(renderEngine);
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearVanillaResources(TextureManager renderEngine, ResourceLocation mojangLogo)
|
||||
{
|
||||
if(!enabled)
|
||||
{
|
||||
renderEngine.deleteTexture(mojangLogo);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkGLError(String where)
|
||||
{
|
||||
int err = GL11.glGetError();
|
||||
if (err != 0)
|
||||
{
|
||||
throw new IllegalStateException(where + ": " + GLU.gluErrorString(err));
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream open(ResourceLocation loc) throws IOException
|
||||
{
|
||||
if(miscPack.resourceExists(loc))
|
||||
{
|
||||
return miscPack.getInputStream(loc);
|
||||
}
|
||||
else if(fmlPack.resourceExists(loc))
|
||||
{
|
||||
return fmlPack.getInputStream(loc);
|
||||
}
|
||||
return mcPack.getInputStream(loc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
public enum ConfigGuiType
|
||||
{
|
||||
STRING,
|
||||
INTEGER,
|
||||
BOOLEAN,
|
||||
DOUBLE,
|
||||
COLOR,
|
||||
MOD_ID,
|
||||
CONFIG_CATEGORY;
|
||||
}
|
||||
@@ -0,0 +1,417 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry;
|
||||
import net.minecraftforge.fml.client.config.GuiEditArrayEntries.IArrayEntry;
|
||||
|
||||
|
||||
/**
|
||||
* This class's main purpose is to provide the necessary objects for a sample Config GUI for FML, although
|
||||
* there may be practical uses for the objects defined here such as using the DummyCategoryElement object as a
|
||||
* wrapper for a custom IGuiConfigListEntry object that opens a special screen.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class DummyConfigElement implements IConfigElement
|
||||
{
|
||||
protected boolean isProperty = true;
|
||||
protected boolean isList = false;
|
||||
protected ConfigGuiType type;
|
||||
protected String name;
|
||||
protected String langKey;
|
||||
protected Object value;
|
||||
protected Object defaultValue;
|
||||
protected Object[] values;
|
||||
protected Object[] defaultValues;
|
||||
protected String[] validValues;
|
||||
protected Pattern validStringPattern;
|
||||
protected Object minValue;
|
||||
protected Object maxValue;
|
||||
protected boolean requiresWorldRestart = false;
|
||||
protected boolean requiresMcRestart = false;
|
||||
protected boolean isListFixedLength = false;
|
||||
protected int maxListLength = -1;
|
||||
protected List<IConfigElement> childElements;
|
||||
protected Class<? extends IConfigEntry> configEntryClass;
|
||||
protected Class<? extends IArrayEntry> arrayEntryClass;
|
||||
|
||||
/**
|
||||
* This class provides a Dummy Category IConfigElement. It can be used to define a custom list of GUI entries that will
|
||||
* appear on the child screen or to specify a custom IGuiConfigListEntryfor a special category.
|
||||
*/
|
||||
public static class DummyCategoryElement extends DummyConfigElement
|
||||
{
|
||||
public DummyCategoryElement(String name, String langKey, List<IConfigElement> childElements)
|
||||
{
|
||||
this(name, langKey, childElements, (Class<? extends IConfigEntry>) null);
|
||||
}
|
||||
|
||||
public DummyCategoryElement(String name, String langKey, Class<? extends IConfigEntry> customListEntryClass)
|
||||
{
|
||||
this(name, langKey, new ArrayList<IConfigElement>(), customListEntryClass);
|
||||
}
|
||||
|
||||
public DummyCategoryElement(String name, String langKey, List<IConfigElement> childElements, Class<? extends IConfigEntry> customListEntryClass)
|
||||
{
|
||||
super(name, (Object) null, ConfigGuiType.CONFIG_CATEGORY, langKey);
|
||||
this.childElements = childElements;
|
||||
this.configEntryClass = customListEntryClass;
|
||||
isProperty = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides a dummy array-type IConfigElement.
|
||||
*/
|
||||
public static class DummyListElement extends DummyConfigElement
|
||||
{
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, boolean isListFixedLength, int maxListLength, Pattern validStringPattern, Object minValue, Object maxValue)
|
||||
{
|
||||
super(name, (Object) null, type, langKey, minValue, maxValue);
|
||||
this.defaultValues = defaultValues;
|
||||
this.values = defaultValues;
|
||||
this.isListFixedLength = isListFixedLength;
|
||||
this.maxListLength = maxListLength;
|
||||
this.validStringPattern = validStringPattern;
|
||||
isList = true;
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, false, -1, (Pattern) null, (Object) null, (Object) null);
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, boolean isListFixedLength)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, isListFixedLength, -1, (Pattern) null, (Object) null, (Object) null);
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, int maxListLength)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, false, maxListLength, (Pattern) null, (Object) null, (Object) null);
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, Object minValue, Object maxValue)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, false, -1, (Pattern) null, minValue, maxValue);
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, boolean isListFixedLength, Object minValue, Object maxValue)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, isListFixedLength, -1, (Pattern) null, minValue, maxValue);
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, int maxListLength, Object minValue, Object maxValue)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, false, maxListLength, (Pattern) null, minValue, maxValue);
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, boolean isListFixedLength, int maxListLength, Object minValue, Object maxValue)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, isListFixedLength, maxListLength, (Pattern) null, minValue, maxValue);
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, Pattern validStringPattern)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, false, -1, validStringPattern, (Object) null, (Object) null);
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, boolean isListFixedLength, Pattern validStringPattern)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, isListFixedLength, -1, validStringPattern, (Object) null, (Object) null);
|
||||
}
|
||||
|
||||
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, int maxListLength, Pattern validStringPattern)
|
||||
{
|
||||
this(name, defaultValues, type, langKey, false, maxListLength, validStringPattern, (Object) null, (Object) null);
|
||||
}
|
||||
|
||||
public DummyListElement setCustomEditListEntryClass(Class<? extends IArrayEntry> clazz)
|
||||
{
|
||||
this.arrayEntryClass = clazz;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefault()
|
||||
{
|
||||
return Arrays.toString(this.defaultValues);
|
||||
}
|
||||
}
|
||||
|
||||
public DummyConfigElement(String name, Object defaultValue, ConfigGuiType type, String langKey, String[] validValues, Pattern validStringPattern, Object minValue, Object maxValue)
|
||||
{
|
||||
this.name = name;
|
||||
this.defaultValue = defaultValue;
|
||||
this.value = defaultValue;
|
||||
this.type = type;
|
||||
this.langKey = langKey;
|
||||
this.validValues = validValues;
|
||||
this.validStringPattern = validStringPattern;
|
||||
if (minValue == null)
|
||||
{
|
||||
if (type == ConfigGuiType.INTEGER)
|
||||
this.minValue = (Integer) Integer.MIN_VALUE;
|
||||
else if (type == ConfigGuiType.DOUBLE)
|
||||
this.minValue = (Double) (-Double.MAX_VALUE);
|
||||
}
|
||||
else
|
||||
this.minValue = minValue;
|
||||
if (maxValue == null)
|
||||
{
|
||||
if (type == ConfigGuiType.INTEGER)
|
||||
this.maxValue = (Integer) Integer.MAX_VALUE;
|
||||
else if (type == ConfigGuiType.DOUBLE)
|
||||
this.maxValue = (Double) Double.MAX_VALUE;
|
||||
}
|
||||
else
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public DummyConfigElement(String name, Object defaultValue, ConfigGuiType type, String langKey, Pattern validStringPattern)
|
||||
{
|
||||
this(name, defaultValue, type, langKey, (String[]) null, validStringPattern, (Object) null, (Object) null);
|
||||
}
|
||||
|
||||
public DummyConfigElement(String name, Object defaultValue, ConfigGuiType type, String langKey, String[] validValues)
|
||||
{
|
||||
this(name, defaultValue, type, langKey, validValues, (Pattern) null, (Object) null, (Object) null);
|
||||
}
|
||||
|
||||
public DummyConfigElement(String name, Object defaultValue, ConfigGuiType type, String langKey)
|
||||
{
|
||||
this(name, defaultValue, type, langKey, (String[]) null, (Pattern) null, (Object) null, (Object) null);
|
||||
}
|
||||
|
||||
public DummyConfigElement(String name, Object defaultValue, ConfigGuiType type, String langKey, Object minValue, Object maxValue)
|
||||
{
|
||||
this(name, defaultValue, type, langKey, (String[]) null, (Pattern) null, minValue, maxValue);
|
||||
}
|
||||
|
||||
public DummyConfigElement setCustomListEntryClass(Class<? extends IConfigEntry> clazz)
|
||||
{
|
||||
this.configEntryClass = clazz;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProperty()
|
||||
{
|
||||
return isProperty;
|
||||
}
|
||||
|
||||
public IConfigElement setConfigEntryClass(Class<? extends IConfigEntry> clazz)
|
||||
{
|
||||
this.configEntryClass = clazz;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IConfigEntry> getConfigEntryClass()
|
||||
{
|
||||
return configEntryClass;
|
||||
}
|
||||
|
||||
public IConfigElement setArrayEntryClass(Class<? extends IArrayEntry> clazz)
|
||||
{
|
||||
this.arrayEntryClass = clazz;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IArrayEntry> getArrayEntryClass()
|
||||
{
|
||||
return arrayEntryClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQualifiedName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguageKey()
|
||||
{
|
||||
return langKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComment()
|
||||
{
|
||||
return I18n.format(langKey + ".tooltip");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IConfigElement> getChildElements()
|
||||
{
|
||||
return childElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigGuiType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isList()
|
||||
{
|
||||
return isList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListLengthFixed()
|
||||
{
|
||||
return this.isListFixedLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxListLength()
|
||||
{
|
||||
return this.maxListLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault()
|
||||
{
|
||||
if (isProperty)
|
||||
{
|
||||
if (!isList)
|
||||
{
|
||||
if (value != null)
|
||||
return value.equals(defaultValue);
|
||||
else
|
||||
return defaultValue == null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Arrays.deepEquals(values, defaultValues);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefault()
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getDefaults()
|
||||
{
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToDefault()
|
||||
{
|
||||
if (isList)
|
||||
this.values = Arrays.copyOf(this.defaultValues, this.defaultValues.length);
|
||||
else
|
||||
this.value = defaultValue;
|
||||
}
|
||||
|
||||
public IConfigElement setRequiresWorldRestart(boolean requiresWorldRestart)
|
||||
{
|
||||
this.requiresWorldRestart = requiresWorldRestart;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresWorldRestart()
|
||||
{
|
||||
return requiresWorldRestart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showInGui()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public IConfigElement setRequiresMcRestart(boolean requiresMcRestart)
|
||||
{
|
||||
this.requiresMcRestart = this.requiresWorldRestart = requiresMcRestart;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresMcRestart()
|
||||
{
|
||||
return requiresMcRestart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValidValues()
|
||||
{
|
||||
return validValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern getValidationPattern()
|
||||
{
|
||||
return validStringPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getList()
|
||||
{
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Object value)
|
||||
{
|
||||
defaultValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Object[] aVal)
|
||||
{
|
||||
defaultValues = aVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getMinValue()
|
||||
{
|
||||
return minValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getMaxValue()
|
||||
{
|
||||
return maxValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
/**
|
||||
* This class provides a button that fixes several bugs present in the vanilla GuiButton drawing code.
|
||||
* The gist of it is that it allows buttons of any size without gaps in the graphics and with the
|
||||
* borders drawn properly. It also prevents button text from extending out of the sides of the button by
|
||||
* trimming the end of the string and adding an ellipsis.<br/><br/>
|
||||
*
|
||||
* The code that handles drawing the button is in GuiUtils.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiButtonExt extends GuiButton
|
||||
{
|
||||
public GuiButtonExt(int id, int xPos, int yPos, String displayString)
|
||||
{
|
||||
super(id, xPos, yPos, displayString);
|
||||
}
|
||||
|
||||
public GuiButtonExt(int id, int xPos, int yPos, int width, int height, String displayString)
|
||||
{
|
||||
super(id, xPos, yPos, width, height, displayString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY)
|
||||
{
|
||||
if (this.visible)
|
||||
{
|
||||
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
||||
int k = this.getHoverState(this.hovered);
|
||||
GuiUtils.drawContinuousTexturedBox(buttonTextures, this.xPosition, this.yPosition, 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, this.zLevel);
|
||||
this.mouseDragged(mc, mouseX, mouseY);
|
||||
int color = 14737632;
|
||||
|
||||
if (packedFGColour != 0)
|
||||
{
|
||||
color = packedFGColour;
|
||||
}
|
||||
else if (!this.enabled)
|
||||
{
|
||||
color = 10526880;
|
||||
}
|
||||
else if (this.hovered)
|
||||
{
|
||||
color = 16777120;
|
||||
}
|
||||
|
||||
String buttonText = this.displayString;
|
||||
int strWidth = mc.fontRendererObj.getStringWidth(buttonText);
|
||||
int ellipsisWidth = mc.fontRendererObj.getStringWidth("...");
|
||||
|
||||
if (strWidth > width - 6 && strWidth > ellipsisWidth)
|
||||
buttonText = mc.fontRendererObj.trimStringToWidth(buttonText, width - 6 - ellipsisWidth).trim() + "...";
|
||||
|
||||
this.drawCenteredString(mc.fontRendererObj, buttonText, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
/**
|
||||
* This class provides a checkbox style control.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiCheckBox extends GuiButton
|
||||
{
|
||||
private boolean isChecked;
|
||||
private int boxWidth;
|
||||
|
||||
public GuiCheckBox(int id, int xPos, int yPos, String displayString, boolean isChecked)
|
||||
{
|
||||
super(id, xPos, yPos, displayString);
|
||||
this.isChecked = isChecked;
|
||||
this.boxWidth = 11;
|
||||
this.height = 11;
|
||||
this.width = this.boxWidth + 2 + Minecraft.getMinecraft().fontRendererObj.getStringWidth(displayString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY)
|
||||
{
|
||||
if (this.visible)
|
||||
{
|
||||
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.boxWidth && mouseY < this.yPosition + this.height;
|
||||
GuiUtils.drawContinuousTexturedBox(buttonTextures, this.xPosition, this.yPosition, 0, 46, this.boxWidth, this.height, 200, 20, 2, 3, 2, 2, this.zLevel);
|
||||
this.mouseDragged(mc, mouseX, mouseY);
|
||||
int color = 14737632;
|
||||
|
||||
if (packedFGColour != 0)
|
||||
{
|
||||
color = packedFGColour;
|
||||
}
|
||||
else if (!this.enabled)
|
||||
{
|
||||
color = 10526880;
|
||||
}
|
||||
|
||||
if (this.isChecked)
|
||||
this.drawCenteredString(mc.fontRendererObj, "x", this.xPosition + this.boxWidth / 2 + 1, this.yPosition + 1, 14737632);
|
||||
|
||||
this.drawString(mc.fontRendererObj, displayString, xPosition + this.boxWidth + 2, yPosition + 2, color);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
|
||||
{
|
||||
if (this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height)
|
||||
{
|
||||
this.isChecked = !this.isChecked;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isChecked()
|
||||
{
|
||||
return this.isChecked;
|
||||
}
|
||||
|
||||
public void setIsChecked(boolean isChecked)
|
||||
{
|
||||
this.isChecked = isChecked;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.RESET_CHAR;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.UNDO_CHAR;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent.PostConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
/**
|
||||
* This class is the base GuiScreen for all config GUI screens. It can be extended by mods to provide the top-level config screen
|
||||
* that will be called when the Config button is clicked from the Main Menu Mods list.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiConfig extends GuiScreen
|
||||
{
|
||||
/**
|
||||
* A reference to the screen object that created this. Used for navigating between screens.
|
||||
*/
|
||||
public final GuiScreen parentScreen;
|
||||
public String title = "Config GUI";
|
||||
public String titleLine2;
|
||||
public final List<IConfigElement> configElements;
|
||||
public final List<IConfigEntry> initEntries;
|
||||
public GuiConfigEntries entryList;
|
||||
protected GuiButtonExt btnDefaultAll;
|
||||
protected GuiButtonExt btnUndoAll;
|
||||
protected GuiCheckBox chkApplyGlobally;
|
||||
public final String modID;
|
||||
/**
|
||||
* When set to a non-null value the OnConfigChanged and PostConfigChanged events will be posted when the Done button is pressed
|
||||
* if any configElements were changed (includes child screens). If not defined, the events will be posted if the parent gui is null
|
||||
* or if the parent gui is not an instance of GuiConfig.
|
||||
*/
|
||||
public final String configID;
|
||||
public final boolean isWorldRunning;
|
||||
public final boolean allRequireWorldRestart;
|
||||
public final boolean allRequireMcRestart;
|
||||
public boolean needsRefresh = true;
|
||||
protected HoverChecker undoHoverChecker;
|
||||
protected HoverChecker resetHoverChecker;
|
||||
protected HoverChecker checkBoxHoverChecker;
|
||||
|
||||
/**
|
||||
* GuiConfig constructor that will use ConfigChangedEvent when editing is concluded. If a non-null value is passed for configID,
|
||||
* the OnConfigChanged and PostConfigChanged events will be posted when the Done button is pressed if any configElements were changed
|
||||
* (includes child screens). If configID is not defined, the events will be posted if the parent gui is null or if the parent gui
|
||||
* is not an instance of GuiConfig.
|
||||
*
|
||||
* @param parentScreen the parent GuiScreen object
|
||||
* @param configElements a List of IConfigElement objects
|
||||
* @param modID the mod ID for the mod whose config settings will be edited
|
||||
* @param configID an identifier that will be passed to the OnConfigChanged and PostConfigChanged events. Setting this value will force
|
||||
* the save action to be called when the Done button is pressed on this screen if any configElements were changed.
|
||||
* @param allRequireWorldRestart send true if all configElements on this screen require a world restart
|
||||
* @param allRequireMcRestart send true if all configElements on this screen require MC to be restarted
|
||||
* @param title the desired title for this screen. For consistency it is recommended that you pass the path of the config file being
|
||||
* edited.
|
||||
*/
|
||||
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID, String configID,
|
||||
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title)
|
||||
{
|
||||
this(parentScreen, configElements, modID, configID, allRequireWorldRestart, allRequireMcRestart, title, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* GuiConfig constructor that will use ConfigChangedEvent when editing is concluded. This constructor passes null for configID.
|
||||
* If configID is not defined, the events will be posted if the parent gui is null or if the parent gui is not an instance of GuiConfig.
|
||||
*
|
||||
* @param parentScreen the parent GuiScreen object
|
||||
* @param configElements a List of IConfigElement objects
|
||||
* @param modID the mod ID for the mod whose config settings will be edited
|
||||
* @param allRequireWorldRestart send true if all configElements on this screen require a world restart
|
||||
* @param allRequireMcRestart send true if all configElements on this screen require MC to be restarted
|
||||
* @param title the desired title for this screen. For consistency it is recommended that you pass the path of the config file being
|
||||
* edited.
|
||||
*/
|
||||
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID,
|
||||
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title)
|
||||
{
|
||||
this(parentScreen, configElements, modID, null, allRequireWorldRestart, allRequireMcRestart, title, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* GuiConfig constructor that will use ConfigChangedEvent when editing is concluded. This constructor passes null for configID.
|
||||
* If configID is not defined, the events will be posted if the parent gui is null or if the parent gui is not an instance of GuiConfig.
|
||||
*
|
||||
* @param parentScreen the parent GuiScreen object
|
||||
* @param configElements a List of IConfigElement objects
|
||||
* @param modID the mod ID for the mod whose config settings will be edited
|
||||
* @param allRequireWorldRestart send true if all configElements on this screen require a world restart
|
||||
* @param allRequireMcRestart send true if all configElements on this screen require MC to be restarted
|
||||
* @param title the desired title for this screen. For consistency it is recommended that you pass the path of the config file being
|
||||
* edited.
|
||||
* @param titleLine2 the desired title second line for this screen. Typically this is used to send the category name of the category
|
||||
* currently being edited.
|
||||
*/
|
||||
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID,
|
||||
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title, String titleLine2)
|
||||
{
|
||||
this(parentScreen, configElements, modID, null, allRequireWorldRestart, allRequireMcRestart, title, titleLine2);
|
||||
}
|
||||
|
||||
/**
|
||||
* GuiConfig constructor that will use ConfigChangedEvent when editing is concluded. titleLine2 is specified in this constructor.
|
||||
* If a non-null value is passed for configID, the OnConfigChanged and PostConfigChanged events will be posted when the Done button is
|
||||
* pressed if any configElements were changed (includes child screens). If configID is not defined, the events will be posted if the parent
|
||||
* gui is null or if the parent gui is not an instance of GuiConfig.
|
||||
*
|
||||
* @param parentScreen the parent GuiScreen object
|
||||
* @param configElements a List of IConfigElement objects
|
||||
* @param modID the mod ID for the mod whose config settings will be edited
|
||||
* @param configID an identifier that will be passed to the OnConfigChanged and PostConfigChanged events
|
||||
* @param allRequireWorldRestart send true if all configElements on this screen require a world restart
|
||||
* @param allRequireMcRestart send true if all configElements on this screen require MC to be restarted
|
||||
* @param title the desired title for this screen. For consistency it is recommended that you pass the path of the config file being
|
||||
* edited.
|
||||
* @param titleLine2 the desired title second line for this screen. Typically this is used to send the category name of the category
|
||||
* currently being edited.
|
||||
*/
|
||||
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID, String configID,
|
||||
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title, String titleLine2)
|
||||
{
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
this.parentScreen = parentScreen;
|
||||
this.configElements = configElements;
|
||||
this.entryList = new GuiConfigEntries(this, mc);
|
||||
this.initEntries = new ArrayList<IConfigEntry>(entryList.listEntries);
|
||||
this.allRequireWorldRestart = allRequireWorldRestart;
|
||||
this.allRequireMcRestart = allRequireMcRestart;
|
||||
this.modID = modID;
|
||||
this.configID = configID;
|
||||
this.isWorldRunning = mc.theWorld != null;
|
||||
if (title != null)
|
||||
this.title = title;
|
||||
this.titleLine2 = titleLine2;
|
||||
if (this.titleLine2 != null && this.titleLine2.startsWith(" > "))
|
||||
this.titleLine2 = this.titleLine2.replaceFirst(" > ", "");
|
||||
}
|
||||
|
||||
public static String getAbridgedConfigPath(String path)
|
||||
{
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.mcDataDir.getAbsolutePath().endsWith("."))
|
||||
return path.replace("\\", "/").replace(mc.mcDataDir.getAbsolutePath().replace("\\", "/").substring(0, mc.mcDataDir.getAbsolutePath().length() - 1), "/.minecraft/");
|
||||
else
|
||||
return path.replace("\\", "/").replace(mc.mcDataDir.getAbsolutePath().replace("\\", "/"), "/.minecraft");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
|
||||
if (this.entryList == null || this.needsRefresh)
|
||||
{
|
||||
this.entryList = new GuiConfigEntries(this, mc);
|
||||
this.needsRefresh = false;
|
||||
}
|
||||
|
||||
int undoGlyphWidth = mc.fontRendererObj.getStringWidth(UNDO_CHAR) * 2;
|
||||
int resetGlyphWidth = mc.fontRendererObj.getStringWidth(RESET_CHAR) * 2;
|
||||
int doneWidth = Math.max(mc.fontRendererObj.getStringWidth(I18n.format("gui.done")) + 20, 100);
|
||||
int undoWidth = mc.fontRendererObj.getStringWidth(" " + I18n.format("fml.configgui.tooltip.undoChanges")) + undoGlyphWidth + 20;
|
||||
int resetWidth = mc.fontRendererObj.getStringWidth(" " + I18n.format("fml.configgui.tooltip.resetToDefault")) + resetGlyphWidth + 20;
|
||||
int checkWidth = mc.fontRendererObj.getStringWidth(I18n.format("fml.configgui.applyGlobally")) + 13;
|
||||
int buttonWidthHalf = (doneWidth + 5 + undoWidth + 5 + resetWidth + 5 + checkWidth) / 2;
|
||||
this.buttonList.add(new GuiButtonExt(2000, this.width / 2 - buttonWidthHalf, this.height - 29, doneWidth, 20, I18n.format("gui.done")));
|
||||
this.buttonList.add(this.btnDefaultAll = new GuiUnicodeGlyphButton(2001, this.width / 2 - buttonWidthHalf + doneWidth + 5 + undoWidth + 5,
|
||||
this.height - 29, resetWidth, 20, " " + I18n.format("fml.configgui.tooltip.resetToDefault"), RESET_CHAR, 2.0F));
|
||||
this.buttonList.add(btnUndoAll = new GuiUnicodeGlyphButton(2002, this.width / 2 - buttonWidthHalf + doneWidth + 5,
|
||||
this.height - 29, undoWidth, 20, " " + I18n.format("fml.configgui.tooltip.undoChanges"), UNDO_CHAR, 2.0F));
|
||||
this.buttonList.add(chkApplyGlobally = new GuiCheckBox(2003, this.width / 2 - buttonWidthHalf + doneWidth + 5 + undoWidth + 5 + resetWidth + 5,
|
||||
this.height - 24, I18n.format("fml.configgui.applyGlobally"), false));
|
||||
|
||||
this.undoHoverChecker = new HoverChecker(this.btnUndoAll, 800);
|
||||
this.resetHoverChecker = new HoverChecker(this.btnDefaultAll, 800);
|
||||
this.checkBoxHoverChecker = new HoverChecker(chkApplyGlobally, 800);
|
||||
this.entryList.initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed()
|
||||
{
|
||||
this.entryList.onGuiClosed();
|
||||
|
||||
if (this.configID != null && this.parentScreen instanceof GuiConfig)
|
||||
{
|
||||
GuiConfig parentGuiConfig = (GuiConfig) this.parentScreen;
|
||||
parentGuiConfig.needsRefresh = true;
|
||||
parentGuiConfig.initGui();
|
||||
}
|
||||
|
||||
if (!(this.parentScreen instanceof GuiConfig))
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.id == 2000)
|
||||
{
|
||||
boolean flag = true;
|
||||
try
|
||||
{
|
||||
if ((configID != null || this.parentScreen == null || !(this.parentScreen instanceof GuiConfig))
|
||||
&& (this.entryList.hasChangedEntry(true)))
|
||||
{
|
||||
boolean requiresMcRestart = this.entryList.saveConfigElements();
|
||||
|
||||
if (Loader.isModLoaded(modID))
|
||||
{
|
||||
ConfigChangedEvent event = new OnConfigChangedEvent(modID, configID, isWorldRunning, requiresMcRestart);
|
||||
FMLCommonHandler.instance().bus().post(event);
|
||||
if (!event.getResult().equals(Result.DENY))
|
||||
FMLCommonHandler.instance().bus().post(new PostConfigChangedEvent(modID, configID, isWorldRunning, requiresMcRestart));
|
||||
|
||||
if (requiresMcRestart)
|
||||
{
|
||||
flag = false;
|
||||
mc.displayGuiScreen(new GuiMessageDialog(parentScreen, "fml.configgui.gameRestartTitle",
|
||||
new ChatComponentText(I18n.format("fml.configgui.gameRestartRequired")), "fml.configgui.confirmRestartMessage"));
|
||||
}
|
||||
|
||||
if (this.parentScreen instanceof GuiConfig)
|
||||
((GuiConfig) this.parentScreen).needsRefresh = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (flag)
|
||||
this.mc.displayGuiScreen(this.parentScreen);
|
||||
}
|
||||
else if (button.id == 2001)
|
||||
{
|
||||
this.entryList.setAllToDefault(this.chkApplyGlobally.isChecked());
|
||||
}
|
||||
else if (button.id == 2002)
|
||||
{
|
||||
this.entryList.undoAllChanges(this.chkApplyGlobally.isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
public void handleMouseInput() throws IOException
|
||||
{
|
||||
super.handleMouseInput();
|
||||
this.entryList.handleMouseInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int mouseEvent) throws IOException
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseClicked(x, y, mouseEvent))
|
||||
{
|
||||
this.entryList.mouseClickedPassThru(x, y, mouseEvent);
|
||||
super.mouseClicked(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int x, int y, int mouseEvent)
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseReleased(x, y, mouseEvent))
|
||||
{
|
||||
super.mouseReleased(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard.KEY_ESCAPE)
|
||||
this.mc.displayGuiScreen(parentScreen);
|
||||
else
|
||||
this.entryList.keyTyped(eventChar, eventKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
this.entryList.updateScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
this.entryList.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.drawCenteredString(this.fontRendererObj, this.title, this.width / 2, 8, 16777215);
|
||||
String title2 = this.titleLine2;
|
||||
|
||||
if (title2 != null)
|
||||
{
|
||||
int strWidth = mc.fontRendererObj.getStringWidth(title2);
|
||||
int elipsisWidth = mc.fontRendererObj.getStringWidth("...");
|
||||
if (strWidth > width - 6 && strWidth > elipsisWidth)
|
||||
title2 = mc.fontRendererObj.trimStringToWidth(title2, width - 6 - elipsisWidth).trim() + "...";
|
||||
this.drawCenteredString(this.fontRendererObj, title2, this.width / 2, 18, 16777215);
|
||||
}
|
||||
|
||||
this.btnUndoAll.enabled = this.entryList.areAnyEntriesEnabled(this.chkApplyGlobally.isChecked()) && this.entryList.hasChangedEntry(this.chkApplyGlobally.isChecked());
|
||||
this.btnDefaultAll.enabled = this.entryList.areAnyEntriesEnabled(this.chkApplyGlobally.isChecked()) && !this.entryList.areAllEntriesDefault(this.chkApplyGlobally.isChecked());
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.entryList.drawScreenPost(mouseX, mouseY, partialTicks);
|
||||
if (this.undoHoverChecker.checkHover(mouseX, mouseY))
|
||||
this.drawToolTip(this.mc.fontRendererObj.listFormattedStringToWidth(I18n.format("fml.configgui.tooltip.undoAll"), 300), mouseX, mouseY);
|
||||
if (this.resetHoverChecker.checkHover(mouseX, mouseY))
|
||||
this.drawToolTip(this.mc.fontRendererObj.listFormattedStringToWidth(I18n.format("fml.configgui.tooltip.resetAll"), 300), mouseX, mouseY);
|
||||
if (this.checkBoxHoverChecker.checkHover(mouseX, mouseY))
|
||||
this.drawToolTip(this.mc.fontRendererObj.listFormattedStringToWidth(I18n.format("fml.configgui.tooltip.applyGlobally"), 300), mouseX, mouseY);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void drawToolTip(List stringList, int x, int y)
|
||||
{
|
||||
this.drawHoveringText(stringList, x, y);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.RESET_CHAR;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.UNDO_CHAR;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
/**
|
||||
* This class is the base screen used for editing an array-type property. It provides a list of array entries for the user to edit.
|
||||
* This screen is invoked from a GuiConfig screen by controls that use the EditListPropEntry IGuiConfigListEntry object.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiEditArray extends GuiScreen
|
||||
{
|
||||
protected GuiScreen parentScreen;
|
||||
protected IConfigElement configElement;
|
||||
protected GuiEditArrayEntries entryList;
|
||||
protected GuiButtonExt btnUndoChanges, btnDefault, btnDone;
|
||||
protected String title;
|
||||
protected String titleLine2;
|
||||
protected String titleLine3;
|
||||
protected int slotIndex;
|
||||
protected final Object[] beforeValues;
|
||||
protected Object[] currentValues;
|
||||
protected HoverChecker tooltipHoverChecker;
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected List toolTip;
|
||||
protected boolean enabled;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public GuiEditArray(GuiScreen parentScreen, IConfigElement configElement, int slotIndex, Object[] currentValues, boolean enabled)
|
||||
{
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
this.parentScreen = parentScreen;
|
||||
this.configElement = configElement;
|
||||
this.slotIndex = slotIndex;
|
||||
this.beforeValues = currentValues;
|
||||
this.currentValues = currentValues;
|
||||
this.toolTip = new ArrayList();
|
||||
this.enabled = enabled;
|
||||
String propName = I18n.format(configElement.getLanguageKey());
|
||||
String comment;
|
||||
|
||||
comment = I18n.format(configElement.getLanguageKey() + ".tooltip",
|
||||
"\n" + EnumChatFormatting.AQUA, configElement.getDefault(), configElement.getMinValue(), configElement.getMaxValue());
|
||||
|
||||
if (!comment.equals(configElement.getLanguageKey() + ".tooltip"))
|
||||
toolTip = mc.fontRendererObj.listFormattedStringToWidth(
|
||||
EnumChatFormatting.GREEN + propName + "\n" + EnumChatFormatting.YELLOW + comment, 300);
|
||||
else if (configElement.getComment() != null && !configElement.getComment().trim().isEmpty())
|
||||
toolTip = mc.fontRendererObj.listFormattedStringToWidth(
|
||||
EnumChatFormatting.GREEN + propName + "\n" + EnumChatFormatting.YELLOW + configElement.getComment(), 300);
|
||||
else
|
||||
toolTip = mc.fontRendererObj.listFormattedStringToWidth(
|
||||
EnumChatFormatting.GREEN + propName + "\n" + EnumChatFormatting.RED + "No tooltip defined.", 300);
|
||||
|
||||
if (parentScreen instanceof GuiConfig)
|
||||
{
|
||||
this.title = ((GuiConfig) parentScreen).title;
|
||||
if (((GuiConfig) parentScreen).titleLine2 != null)
|
||||
{
|
||||
this.titleLine2 = ((GuiConfig) parentScreen).titleLine2;
|
||||
this.titleLine3 = I18n.format(configElement.getLanguageKey());
|
||||
}
|
||||
else
|
||||
this.titleLine2 = I18n.format(configElement.getLanguageKey());
|
||||
this.tooltipHoverChecker = new HoverChecker(28, 37, 0, parentScreen.width, 800);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.title = I18n.format(configElement.getLanguageKey());
|
||||
this.tooltipHoverChecker = new HoverChecker(8, 17, 0, parentScreen.width, 800);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.entryList = new GuiEditArrayEntries(this, this.mc, this.configElement, this.beforeValues, this.currentValues);
|
||||
|
||||
int undoGlyphWidth = mc.fontRendererObj.getStringWidth(UNDO_CHAR) * 2;
|
||||
int resetGlyphWidth = mc.fontRendererObj.getStringWidth(RESET_CHAR) * 2;
|
||||
int doneWidth = Math.max(mc.fontRendererObj.getStringWidth(I18n.format("gui.done")) + 20, 100);
|
||||
int undoWidth = mc.fontRendererObj.getStringWidth(" " + I18n.format("fml.configgui.tooltip.undoChanges")) + undoGlyphWidth + 20;
|
||||
int resetWidth = mc.fontRendererObj.getStringWidth(" " + I18n.format("fml.configgui.tooltip.resetToDefault")) + resetGlyphWidth + 20;
|
||||
int buttonWidthHalf = (doneWidth + 5 + undoWidth + 5 + resetWidth) / 2;
|
||||
this.buttonList.add(btnDone = new GuiButtonExt(2000, this.width / 2 - buttonWidthHalf, this.height - 29, doneWidth, 20, I18n.format("gui.done")));
|
||||
this.buttonList.add(btnDefault = new GuiUnicodeGlyphButton(2001, this.width / 2 - buttonWidthHalf + doneWidth + 5 + undoWidth + 5,
|
||||
this.height - 29, resetWidth, 20, " " + I18n.format("fml.configgui.tooltip.resetToDefault"), RESET_CHAR, 2.0F));
|
||||
this.buttonList.add(btnUndoChanges = new GuiUnicodeGlyphButton(2002, this.width / 2 - buttonWidthHalf + doneWidth + 5,
|
||||
this.height - 29, undoWidth, 20, " " + I18n.format("fml.configgui.tooltip.undoChanges"), UNDO_CHAR, 2.0F));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.id == 2000)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.entryList.saveListChanges();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.mc.displayGuiScreen(this.parentScreen);
|
||||
}
|
||||
else if (button.id == 2001)
|
||||
{
|
||||
this.currentValues = configElement.getDefaults();
|
||||
this.entryList = new GuiEditArrayEntries(this, this.mc, this.configElement, this.beforeValues, this.currentValues);
|
||||
}
|
||||
else if (button.id == 2002)
|
||||
{
|
||||
this.currentValues = Arrays.copyOf(beforeValues, beforeValues.length);
|
||||
this.entryList = new GuiEditArrayEntries(this, this.mc, this.configElement, this.beforeValues, this.currentValues);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleMouseInput() throws IOException
|
||||
{
|
||||
super.handleMouseInput();
|
||||
this.entryList.handleMouseInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int mouseEvent) throws IOException
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseClicked(x, y, mouseEvent))
|
||||
{
|
||||
this.entryList.mouseClickedPassThru(x, y, mouseEvent);
|
||||
super.mouseClicked(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int x, int y, int mouseEvent)
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseReleased(x, y, mouseEvent))
|
||||
{
|
||||
super.mouseReleased(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard.KEY_ESCAPE)
|
||||
this.mc.displayGuiScreen(parentScreen);
|
||||
else
|
||||
this.entryList.keyTyped(eventChar, eventKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
this.entryList.updateScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
this.entryList.drawScreen(par1, par2, par3);
|
||||
this.drawCenteredString(this.fontRendererObj, this.title, this.width / 2, 8, 16777215);
|
||||
|
||||
if (this.titleLine2 != null)
|
||||
this.drawCenteredString(this.fontRendererObj, this.titleLine2, this.width / 2, 18, 16777215);
|
||||
|
||||
if (this.titleLine3 != null)
|
||||
this.drawCenteredString(this.fontRendererObj, this.titleLine3, this.width / 2, 28, 16777215);
|
||||
|
||||
this.btnDone.enabled = this.entryList.isListSavable();
|
||||
this.btnDefault.enabled = enabled && !this.entryList.isDefault();
|
||||
this.btnUndoChanges.enabled = enabled && this.entryList.isChanged();
|
||||
super.drawScreen(par1, par2, par3);
|
||||
this.entryList.drawScreenPost(par1, par2, par3);
|
||||
|
||||
if (this.tooltipHoverChecker != null && this.tooltipHoverChecker.checkHover(par1, par2))
|
||||
drawToolTip(this.toolTip, par1, par2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void drawToolTip(List stringList, int x, int y)
|
||||
{
|
||||
this.drawHoveringText(stringList, x, y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,674 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.ArrayEntry;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.INVALID;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.VALID;
|
||||
|
||||
/**
|
||||
* This class implements the scrolling list functionality of the GuiEditList screen. It also provides all the default controls
|
||||
* for editing array-type properties.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class GuiEditArrayEntries extends GuiListExtended
|
||||
{
|
||||
protected GuiEditArray owningGui;
|
||||
public Minecraft mc;
|
||||
public IConfigElement configElement;
|
||||
public List<IArrayEntry> listEntries;
|
||||
public boolean isDefault;
|
||||
public boolean isChanged;
|
||||
public boolean canAddMoreEntries;
|
||||
public final int controlWidth;
|
||||
public final Object[] beforeValues;
|
||||
public Object[] currentValues;
|
||||
|
||||
public GuiEditArrayEntries(GuiEditArray parent, Minecraft mc, IConfigElement configElement, Object[] beforeValues, Object[] currentValues)
|
||||
{
|
||||
super(mc, parent.width, parent.height, parent.titleLine2 != null ? (parent.titleLine3 != null ? 43 : 33) : 23, parent.height - 32, 20);
|
||||
this.owningGui = parent;
|
||||
this.mc = mc;
|
||||
this.configElement = configElement;
|
||||
this.beforeValues = beforeValues;
|
||||
this.currentValues = currentValues;
|
||||
this.setShowSelectionBox(false);
|
||||
this.isChanged = !Arrays.deepEquals(beforeValues, currentValues);
|
||||
this.isDefault = Arrays.deepEquals(currentValues, configElement.getDefaults());
|
||||
this.canAddMoreEntries = !configElement.isListLengthFixed() && (configElement.getMaxListLength() == -1 || currentValues.length < configElement.getMaxListLength());
|
||||
|
||||
listEntries = new ArrayList<IArrayEntry>();
|
||||
|
||||
controlWidth = (parent.width / 2) - (configElement.isListLengthFixed() ? 0 : 48);
|
||||
|
||||
if (configElement.isList() && configElement.getArrayEntryClass() != null)
|
||||
{
|
||||
Class<? extends IArrayEntry> clazz = configElement.getArrayEntryClass();
|
||||
for (Object value : currentValues)
|
||||
{
|
||||
try
|
||||
{
|
||||
listEntries.add(clazz.getConstructor(GuiEditArray.class, GuiEditArrayEntries.class, IConfigElement.class, Object.class)
|
||||
.newInstance(this.owningGui, this, configElement, value.toString()));
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
FMLLog.severe("There was a critical error instantiating the custom IGuiEditListEntry for property %s.", configElement.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (configElement.isList() && configElement.getType().equals(ConfigGuiType.BOOLEAN))
|
||||
for (Object value : currentValues)
|
||||
listEntries.add(new BooleanEntry(this.owningGui, this, configElement, Boolean.valueOf(value.toString())));
|
||||
else if (configElement.isList() && configElement.getType().equals(ConfigGuiType.INTEGER))
|
||||
for (Object value : currentValues)
|
||||
listEntries.add(new IntegerEntry(this.owningGui, this, configElement, Integer.parseInt(value.toString())));
|
||||
else if (configElement.isList() && configElement.getType().equals(ConfigGuiType.DOUBLE))
|
||||
for (Object value : currentValues)
|
||||
listEntries.add(new DoubleEntry(this.owningGui, this, configElement, Double.parseDouble(value.toString())));
|
||||
else if (configElement.isList())
|
||||
for (Object value : currentValues)
|
||||
listEntries.add(new StringEntry(this.owningGui, this, configElement, value.toString()));
|
||||
|
||||
if (!configElement.isListLengthFixed())
|
||||
listEntries.add(new BaseEntry(this.owningGui, this, configElement));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrollBarX()
|
||||
{
|
||||
return width - (width / 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the list
|
||||
*/
|
||||
@Override
|
||||
public int getListWidth()
|
||||
{
|
||||
return owningGui.width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArrayEntry getListEntry(int index)
|
||||
{
|
||||
return listEntries.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize()
|
||||
{
|
||||
return listEntries.size();
|
||||
}
|
||||
|
||||
public void addNewEntry(int index)
|
||||
{
|
||||
if (configElement.isList() && configElement.getType() == ConfigGuiType.BOOLEAN)
|
||||
listEntries.add(index, new BooleanEntry(this.owningGui, this, this.configElement, Boolean.valueOf(true)));
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.INTEGER)
|
||||
listEntries.add(index, new IntegerEntry(this.owningGui, this, this.configElement, 0));
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.DOUBLE)
|
||||
listEntries.add(index, new DoubleEntry(this.owningGui, this, this.configElement, 0.0D));
|
||||
else if (configElement.isList())
|
||||
listEntries.add(index, new StringEntry(this.owningGui, this, this.configElement, ""));
|
||||
this.canAddMoreEntries = !configElement.isListLengthFixed()
|
||||
&& (configElement.getMaxListLength() == -1 || this.listEntries.size() - 1 < configElement.getMaxListLength());
|
||||
keyTyped((char) Keyboard.CHAR_NONE, Keyboard.KEY_END);
|
||||
}
|
||||
|
||||
public void removeEntry(int index)
|
||||
{
|
||||
this.listEntries.remove(index);
|
||||
this.canAddMoreEntries = !configElement.isListLengthFixed()
|
||||
&& (configElement.getMaxListLength() == -1 || this.listEntries.size() - 1 < configElement.getMaxListLength());
|
||||
keyTyped((char) Keyboard.CHAR_NONE, Keyboard.KEY_END);
|
||||
}
|
||||
|
||||
public boolean isChanged()
|
||||
{
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
public boolean isDefault()
|
||||
{
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
public void recalculateState()
|
||||
{
|
||||
isDefault = true;
|
||||
isChanged = false;
|
||||
|
||||
int listLength = configElement.isListLengthFixed() ? listEntries.size() : listEntries.size() - 1;
|
||||
|
||||
if (listLength != configElement.getDefaults().length)
|
||||
{
|
||||
isDefault = false;
|
||||
}
|
||||
|
||||
if (listLength != beforeValues.length)
|
||||
{
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (isDefault)
|
||||
for (int i = 0; i < listLength; i++)
|
||||
if (!configElement.getDefaults()[i].equals(listEntries.get(i).getValue()))
|
||||
isDefault = false;
|
||||
|
||||
if (!isChanged)
|
||||
for (int i = 0; i < listLength; i++)
|
||||
if (!beforeValues[i].equals(listEntries.get(i).getValue()))
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
protected void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
entry.keyTyped(eventChar, eventKey);
|
||||
|
||||
recalculateState();
|
||||
}
|
||||
|
||||
protected void updateScreen()
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
entry.updateCursorCounter();
|
||||
}
|
||||
|
||||
protected void mouseClickedPassThru(int x, int y, int mouseEvent)
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
entry.mouseClicked(x, y, mouseEvent);
|
||||
}
|
||||
|
||||
protected boolean isListSavable()
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
if (!entry.isValueSavable())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void saveListChanges()
|
||||
{
|
||||
int listLength = configElement.isListLengthFixed() ? listEntries.size() : listEntries.size() - 1;
|
||||
|
||||
if (owningGui.slotIndex != -1 && owningGui.parentScreen != null
|
||||
&& owningGui.parentScreen instanceof GuiConfig
|
||||
&& ((GuiConfig) owningGui.parentScreen).entryList.getListEntry(owningGui.slotIndex) instanceof ArrayEntry)
|
||||
{
|
||||
ArrayEntry entry = (ArrayEntry) ((GuiConfig) owningGui.parentScreen).entryList.getListEntry(owningGui.slotIndex);
|
||||
|
||||
Object[] ao = new Object[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
ao[i] = listEntries.get(i).getValue();
|
||||
|
||||
entry.setListFromChildScreen(ao);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (configElement.isList() && configElement.getType() == ConfigGuiType.BOOLEAN)
|
||||
{
|
||||
Boolean[] abol = new Boolean[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
abol[i] = Boolean.valueOf(listEntries.get(i).getValue().toString());
|
||||
|
||||
configElement.set(abol);
|
||||
}
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.INTEGER)
|
||||
{
|
||||
Integer[] ai = new Integer[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
ai[i] = Integer.valueOf(listEntries.get(i).getValue().toString());
|
||||
|
||||
configElement.set(ai);
|
||||
}
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.DOUBLE)
|
||||
{
|
||||
Double[] ad = new Double[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
ad[i] = Double.valueOf(listEntries.get(i).getValue().toString());
|
||||
|
||||
configElement.set(ad);
|
||||
}
|
||||
else if (configElement.isList())
|
||||
{
|
||||
String[] as = new String[listLength];
|
||||
for (int i = 0; i < listLength; i++)
|
||||
as[i] = listEntries.get(i).getValue().toString();
|
||||
|
||||
configElement.set(as);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawScreenPost(int mouseX, int mouseY, float f)
|
||||
{
|
||||
for (IArrayEntry entry : this.listEntries)
|
||||
entry.drawToolTip(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/**
|
||||
* IGuiListEntry Inner Classes
|
||||
*/
|
||||
|
||||
public static class DoubleEntry extends StringEntry
|
||||
{
|
||||
public DoubleEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement, Double value)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement, value);
|
||||
this.isValidated = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (owningScreen.enabled || eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT
|
||||
|| eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
{
|
||||
String validChars = "0123456789";
|
||||
String before = this.textFieldValue.getText();
|
||||
if (validChars.contains(String.valueOf(eventChar)) ||
|
||||
(!before.startsWith("-") && this.textFieldValue.getCursorPosition() == 0 && eventChar == '-')
|
||||
|| (!before.contains(".") && eventChar == '.')
|
||||
|| eventKey == Keyboard.KEY_BACK || eventKey == Keyboard.KEY_DELETE || eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT
|
||||
|| eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
this.textFieldValue.textboxKeyTyped((owningScreen.enabled ? eventChar : Keyboard.CHAR_NONE), eventKey);
|
||||
|
||||
if (!textFieldValue.getText().trim().isEmpty() && !textFieldValue.getText().trim().equals("-"))
|
||||
{
|
||||
try
|
||||
{
|
||||
double value = Double.parseDouble(textFieldValue.getText().trim());
|
||||
if (value < Double.valueOf(configElement.getMinValue().toString()) || value > Double.valueOf(configElement.getMaxValue().toString()))
|
||||
this.isValidValue = false;
|
||||
else
|
||||
this.isValidValue = true;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
this.isValidValue = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
this.isValidValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getValue()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Double.valueOf(this.textFieldValue.getText().trim());
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class IntegerEntry extends StringEntry
|
||||
{
|
||||
public IntegerEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement, Integer value)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement, value);
|
||||
this.isValidated = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (owningScreen.enabled || eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT
|
||||
|| eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
{
|
||||
String validChars = "0123456789";
|
||||
String before = this.textFieldValue.getText();
|
||||
if (validChars.contains(String.valueOf(eventChar))
|
||||
|| (!before.startsWith("-") && this.textFieldValue.getCursorPosition() == 0 && eventChar == '-')
|
||||
|| eventKey == Keyboard.KEY_BACK || eventKey == Keyboard.KEY_DELETE
|
||||
|| eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT || eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
this.textFieldValue.textboxKeyTyped((owningScreen.enabled ? eventChar : Keyboard.CHAR_NONE), eventKey);
|
||||
|
||||
if (!textFieldValue.getText().trim().isEmpty() && !textFieldValue.getText().trim().equals("-"))
|
||||
{
|
||||
try
|
||||
{
|
||||
long value = Long.parseLong(textFieldValue.getText().trim());
|
||||
if (value < Integer.valueOf(configElement.getMinValue().toString()) || value > Integer.valueOf(configElement.getMaxValue().toString()))
|
||||
this.isValidValue = false;
|
||||
else
|
||||
this.isValidValue = true;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
this.isValidValue = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
this.isValidValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Integer.valueOf(this.textFieldValue.getText().trim());
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringEntry extends BaseEntry
|
||||
{
|
||||
protected final GuiTextField textFieldValue;
|
||||
|
||||
public StringEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement, Object value)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
this.textFieldValue = new GuiTextField(0, owningEntryList.mc.fontRendererObj, owningEntryList.width / 4 + 1, 0, owningEntryList.controlWidth - 3, 16);
|
||||
this.textFieldValue.setMaxStringLength(10000);
|
||||
this.textFieldValue.setText(value.toString());
|
||||
this.isValidated = configElement.getValidationPattern() != null;
|
||||
|
||||
if (configElement.getValidationPattern() != null)
|
||||
{
|
||||
if (configElement.getValidationPattern().matcher(this.textFieldValue.getText().trim()).matches())
|
||||
isValidValue = true;
|
||||
else
|
||||
isValidValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected)
|
||||
{
|
||||
super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected);
|
||||
if (configElement.isListLengthFixed() || slotIndex != owningEntryList.listEntries.size() - 1)
|
||||
{
|
||||
this.textFieldValue.setVisible(true);
|
||||
this.textFieldValue.yPosition = y + 1;
|
||||
this.textFieldValue.drawTextBox();
|
||||
}
|
||||
else
|
||||
this.textFieldValue.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char eventChar, int eventKey)
|
||||
{
|
||||
if (owningScreen.enabled || eventKey == Keyboard.KEY_LEFT || eventKey == Keyboard.KEY_RIGHT
|
||||
|| eventKey == Keyboard.KEY_HOME || eventKey == Keyboard.KEY_END)
|
||||
{
|
||||
this.textFieldValue.textboxKeyTyped((owningScreen.enabled ? eventChar : Keyboard.CHAR_NONE), eventKey);
|
||||
|
||||
if (configElement.getValidationPattern() != null)
|
||||
{
|
||||
if (configElement.getValidationPattern().matcher(this.textFieldValue.getText().trim()).matches())
|
||||
isValidValue = true;
|
||||
else
|
||||
isValidValue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCursorCounter()
|
||||
{
|
||||
this.textFieldValue.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int mouseEvent)
|
||||
{
|
||||
this.textFieldValue.mouseClicked(x, y, mouseEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return this.textFieldValue.getText().trim();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class BooleanEntry extends BaseEntry
|
||||
{
|
||||
protected final GuiButtonExt btnValue;
|
||||
private boolean value;
|
||||
|
||||
public BooleanEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement, boolean value)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement);
|
||||
this.value = value;
|
||||
this.btnValue = new GuiButtonExt(0, 0, 0, owningEntryList.controlWidth, 18, I18n.format(String.valueOf(value)));
|
||||
this.btnValue.enabled = owningScreen.enabled;
|
||||
this.isValidated = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected)
|
||||
{
|
||||
super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected);
|
||||
this.btnValue.xPosition = listWidth / 4;
|
||||
this.btnValue.yPosition = y;
|
||||
|
||||
String trans = I18n.format(String.valueOf(value));
|
||||
if (!trans.equals(String.valueOf(value)))
|
||||
this.btnValue.displayString = trans;
|
||||
else
|
||||
this.btnValue.displayString = String.valueOf(value);
|
||||
btnValue.packedFGColour = value ? GuiUtils.getColorCode('2', true) : GuiUtils.getColorCode('4', true);
|
||||
|
||||
this.btnValue.drawButton(owningEntryList.mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
if (this.btnValue.mousePressed(owningEntryList.mc, x, y))
|
||||
{
|
||||
btnValue.playPressSound(owningEntryList.mc.getSoundHandler());
|
||||
value = !value;
|
||||
owningEntryList.recalculateState();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.mousePressed(index, x, y, mouseEvent, relativeX, relativeY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
this.btnValue.mouseReleased(x, y);
|
||||
super.mouseReleased(index, x, y, mouseEvent, relativeX, relativeY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return Boolean.valueOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BaseEntry implements IArrayEntry
|
||||
{
|
||||
protected final GuiEditArray owningScreen;
|
||||
protected final GuiEditArrayEntries owningEntryList;
|
||||
protected final IConfigElement configElement;
|
||||
protected final GuiButtonExt btnAddNewEntryAbove;
|
||||
private final HoverChecker addNewEntryAboveHoverChecker;
|
||||
protected final GuiButtonExt btnRemoveEntry;
|
||||
private final HoverChecker removeEntryHoverChecker;
|
||||
private List addNewToolTip, removeToolTip;
|
||||
protected boolean isValidValue = true;
|
||||
protected boolean isValidated = false;
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public BaseEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement)
|
||||
{
|
||||
this.owningScreen = owningScreen;
|
||||
this.owningEntryList = owningEntryList;
|
||||
this.configElement = configElement;
|
||||
this.btnAddNewEntryAbove = new GuiButtonExt(0, 0, 0, 18, 18, "+");
|
||||
this.btnAddNewEntryAbove.packedFGColour = GuiUtils.getColorCode('2', true);
|
||||
this.btnAddNewEntryAbove.enabled = owningScreen.enabled;
|
||||
this.btnRemoveEntry = new GuiButtonExt(0, 0, 0, 18, 18, "x");
|
||||
this.btnRemoveEntry.packedFGColour = GuiUtils.getColorCode('c', true);
|
||||
this.btnRemoveEntry.enabled = owningScreen.enabled;
|
||||
this.addNewEntryAboveHoverChecker = new HoverChecker(this.btnAddNewEntryAbove, 800);
|
||||
this.removeEntryHoverChecker = new HoverChecker(this.btnRemoveEntry, 800);
|
||||
this.addNewToolTip = new ArrayList();
|
||||
this.removeToolTip = new ArrayList();
|
||||
addNewToolTip.add(I18n.format("fml.configgui.tooltip.addNewEntryAbove"));
|
||||
removeToolTip.add(I18n.format("fml.configgui.tooltip.removeEntry"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected)
|
||||
{
|
||||
if (this.getValue() != null && this.isValidated)
|
||||
owningEntryList.mc.fontRendererObj.drawString(
|
||||
isValidValue ? EnumChatFormatting.GREEN + VALID : EnumChatFormatting.RED + INVALID,
|
||||
listWidth / 4 - owningEntryList.mc.fontRendererObj.getStringWidth(VALID) - 2,
|
||||
y + slotHeight / 2 - owningEntryList.mc.fontRendererObj.FONT_HEIGHT / 2,
|
||||
16777215);
|
||||
|
||||
int half = listWidth / 2;
|
||||
if (owningEntryList.canAddMoreEntries)
|
||||
{
|
||||
this.btnAddNewEntryAbove.visible = true;
|
||||
this.btnAddNewEntryAbove.xPosition = half + ((half / 2) - 44);
|
||||
this.btnAddNewEntryAbove.yPosition = y;
|
||||
this.btnAddNewEntryAbove.drawButton(owningEntryList.mc, mouseX, mouseY);
|
||||
}
|
||||
else
|
||||
this.btnAddNewEntryAbove.visible = false;
|
||||
|
||||
if (!configElement.isListLengthFixed() && slotIndex != owningEntryList.listEntries.size() - 1)
|
||||
{
|
||||
this.btnRemoveEntry.visible = true;
|
||||
this.btnRemoveEntry.xPosition = half + ((half / 2) - 22);
|
||||
this.btnRemoveEntry.yPosition = y;
|
||||
this.btnRemoveEntry.drawButton(owningEntryList.mc, mouseX, mouseY);
|
||||
}
|
||||
else
|
||||
this.btnRemoveEntry.visible = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawToolTip(int mouseX, int mouseY)
|
||||
{
|
||||
boolean canHover = mouseY < owningEntryList.bottom && mouseY > owningEntryList.top;
|
||||
if (this.btnAddNewEntryAbove.visible && this.addNewEntryAboveHoverChecker.checkHover(mouseX, mouseY, canHover))
|
||||
owningScreen.drawToolTip(this.addNewToolTip, mouseX, mouseY);
|
||||
if (this.btnRemoveEntry.visible && this.removeEntryHoverChecker.checkHover(mouseX, mouseY, canHover))
|
||||
owningScreen.drawToolTip(this.removeToolTip, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
if (this.btnAddNewEntryAbove.mousePressed(owningEntryList.mc, x, y))
|
||||
{
|
||||
btnAddNewEntryAbove.playPressSound(owningEntryList.mc.getSoundHandler());
|
||||
owningEntryList.addNewEntry(index);
|
||||
owningEntryList.recalculateState();
|
||||
return true;
|
||||
}
|
||||
else if (this.btnRemoveEntry.mousePressed(owningEntryList.mc, x, y))
|
||||
{
|
||||
btnRemoveEntry.playPressSound(owningEntryList.mc.getSoundHandler());
|
||||
owningEntryList.removeEntry(index);
|
||||
owningEntryList.recalculateState();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
this.btnAddNewEntryAbove.mouseReleased(x, y);
|
||||
this.btnRemoveEntry.mouseReleased(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char eventChar, int eventKey)
|
||||
{}
|
||||
|
||||
@Override
|
||||
public void updateCursorCounter()
|
||||
{}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int mouseEvent)
|
||||
{}
|
||||
|
||||
@Override
|
||||
public boolean isValueSavable()
|
||||
{
|
||||
return isValidValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_){}
|
||||
}
|
||||
|
||||
public static interface IArrayEntry extends GuiListExtended.IGuiListEntry
|
||||
{
|
||||
public void keyTyped(char eventChar, int eventKey);
|
||||
|
||||
public void updateCursorCounter();
|
||||
|
||||
public void mouseClicked(int x, int y, int mouseEvent);
|
||||
|
||||
public void drawToolTip(int mouseX, int mouseY);
|
||||
|
||||
public boolean isValueSavable();
|
||||
|
||||
public Object getValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import net.minecraft.client.gui.GuiDisconnected;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
public class GuiMessageDialog extends GuiDisconnected
|
||||
{
|
||||
protected String buttonText;
|
||||
|
||||
public GuiMessageDialog(GuiScreen nextScreen, String title, IChatComponent message, String buttonText)
|
||||
{
|
||||
super(nextScreen, title, message);
|
||||
this.buttonText = buttonText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
((GuiButton) buttonList.get(0)).displayString = I18n.format(buttonText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.RESET_CHAR;
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.UNDO_CHAR;
|
||||
|
||||
/**
|
||||
* This class provides a screen that allows the user to select a value from a list.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiSelectString extends GuiScreen
|
||||
{
|
||||
protected GuiScreen parentScreen;
|
||||
protected IConfigElement configElement;
|
||||
protected GuiSelectStringEntries entryList;
|
||||
protected GuiButtonExt btnUndoChanges, btnDefault, btnDone;
|
||||
protected String title;
|
||||
protected String titleLine2;
|
||||
protected String titleLine3;
|
||||
protected int slotIndex;
|
||||
protected final Map<Object, String> selectableValues;
|
||||
public final Object beforeValue;
|
||||
public Object currentValue;
|
||||
protected HoverChecker tooltipHoverChecker;
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected List toolTip;
|
||||
protected boolean enabled;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public GuiSelectString(GuiScreen parentScreen, IConfigElement configElement, int slotIndex, Map<Object, String> selectableValues, Object currentValue, boolean enabled)
|
||||
{
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
this.parentScreen = parentScreen;
|
||||
this.configElement = configElement;
|
||||
this.slotIndex = slotIndex;
|
||||
this.selectableValues = selectableValues;
|
||||
this.beforeValue = currentValue;
|
||||
this.currentValue = currentValue;
|
||||
this.toolTip = new ArrayList();
|
||||
this.enabled = enabled;
|
||||
String propName = I18n.format(configElement.getLanguageKey());
|
||||
String comment;
|
||||
|
||||
comment = I18n.format(configElement.getLanguageKey() + ".tooltip",
|
||||
"\n" + EnumChatFormatting.AQUA, configElement.getDefault(), configElement.getMinValue(), configElement.getMaxValue());
|
||||
|
||||
if (!comment.equals(configElement.getLanguageKey() + ".tooltip"))
|
||||
toolTip = mc.fontRendererObj.listFormattedStringToWidth(
|
||||
EnumChatFormatting.GREEN + propName + "\n" + EnumChatFormatting.YELLOW + comment, 300);
|
||||
else if (configElement.getComment() != null && !configElement.getComment().trim().isEmpty())
|
||||
toolTip = mc.fontRendererObj.listFormattedStringToWidth(
|
||||
EnumChatFormatting.GREEN + propName + "\n" + EnumChatFormatting.YELLOW + configElement.getComment(), 300);
|
||||
else
|
||||
toolTip = mc.fontRendererObj.listFormattedStringToWidth(
|
||||
EnumChatFormatting.GREEN + propName + "\n" + EnumChatFormatting.RED + "No tooltip defined.", 300);
|
||||
|
||||
if (parentScreen instanceof GuiConfig)
|
||||
{
|
||||
this.title = ((GuiConfig) parentScreen).title;
|
||||
this.titleLine2 = ((GuiConfig) parentScreen).titleLine2;
|
||||
this.titleLine3 = I18n.format(configElement.getLanguageKey());
|
||||
this.tooltipHoverChecker = new HoverChecker(28, 37, 0, parentScreen.width, 800);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
this.title = I18n.format(configElement.getLanguageKey());
|
||||
this.tooltipHoverChecker = new HoverChecker(8, 17, 0, parentScreen.width, 800);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
this.entryList = new GuiSelectStringEntries(this, this.mc, this.configElement, this.selectableValues);
|
||||
|
||||
int undoGlyphWidth = mc.fontRendererObj.getStringWidth(UNDO_CHAR) * 2;
|
||||
int resetGlyphWidth = mc.fontRendererObj.getStringWidth(RESET_CHAR) * 2;
|
||||
int doneWidth = Math.max(mc.fontRendererObj.getStringWidth(I18n.format("gui.done")) + 20, 100);
|
||||
int undoWidth = mc.fontRendererObj.getStringWidth(" " + I18n.format("fml.configgui.tooltip.undoChanges")) + undoGlyphWidth + 20;
|
||||
int resetWidth = mc.fontRendererObj.getStringWidth(" " + I18n.format("fml.configgui.tooltip.resetToDefault")) + resetGlyphWidth + 20;
|
||||
int buttonWidthHalf = (doneWidth + 5 + undoWidth + 5 + resetWidth) / 2;
|
||||
this.buttonList.add(btnDone = new GuiButtonExt(2000, this.width / 2 - buttonWidthHalf, this.height - 29, doneWidth, 20, I18n.format("gui.done")));
|
||||
this.buttonList.add(btnDefault = new GuiUnicodeGlyphButton(2001, this.width / 2 - buttonWidthHalf + doneWidth + 5 + undoWidth + 5,
|
||||
this.height - 29, resetWidth, 20, " " + I18n.format("fml.configgui.tooltip.resetToDefault"), RESET_CHAR, 2.0F));
|
||||
this.buttonList.add(btnUndoChanges = new GuiUnicodeGlyphButton(2002, this.width / 2 - buttonWidthHalf + doneWidth + 5,
|
||||
this.height - 29, undoWidth, 20, " " + I18n.format("fml.configgui.tooltip.undoChanges"), UNDO_CHAR, 2.0F));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
if (button.id == 2000)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.entryList.saveChanges();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.mc.displayGuiScreen(this.parentScreen);
|
||||
}
|
||||
else if (button.id == 2001)
|
||||
{
|
||||
this.currentValue = configElement.getDefault();
|
||||
this.entryList = new GuiSelectStringEntries(this, this.mc, this.configElement, this.selectableValues);
|
||||
}
|
||||
else if (button.id == 2002)
|
||||
{
|
||||
this.currentValue = beforeValue;
|
||||
this.entryList = new GuiSelectStringEntries(this, this.mc, this.configElement, this.selectableValues);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleMouseInput() throws IOException
|
||||
{
|
||||
super.handleMouseInput();
|
||||
this.entryList.handleMouseInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int x, int y, int mouseEvent)
|
||||
{
|
||||
if (mouseEvent != 0 || !this.entryList.mouseReleased(x, y, mouseEvent))
|
||||
{
|
||||
super.mouseReleased(x, y, mouseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3)
|
||||
{
|
||||
this.drawDefaultBackground();
|
||||
this.entryList.drawScreen(par1, par2, par3);
|
||||
this.drawCenteredString(this.fontRendererObj, this.title, this.width / 2, 8, 16777215);
|
||||
|
||||
if (this.titleLine2 != null)
|
||||
this.drawCenteredString(this.fontRendererObj, this.titleLine2, this.width / 2, 18, 16777215);
|
||||
|
||||
if (this.titleLine3 != null)
|
||||
this.drawCenteredString(this.fontRendererObj, this.titleLine3, this.width / 2, 28, 16777215);
|
||||
|
||||
this.btnDone.enabled = currentValue != null;
|
||||
this.btnDefault.enabled = enabled && !this.entryList.isDefault();
|
||||
this.btnUndoChanges.enabled = enabled && this.entryList.isChanged();
|
||||
super.drawScreen(par1, par2, par3);
|
||||
|
||||
if (this.tooltipHoverChecker != null && this.tooltipHoverChecker.checkHover(par1, par2))
|
||||
drawToolTip(this.toolTip, par1, par2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void drawToolTip(List stringList, int x, int y)
|
||||
{
|
||||
this.drawHoveringText(stringList, x, y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.SelectValueEntry;
|
||||
|
||||
/**
|
||||
* This class implements the scrolling list functionality of the GuiSelectString screen.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiSelectStringEntries extends GuiListExtended
|
||||
{
|
||||
public GuiSelectString owningScreen;
|
||||
public Minecraft mc;
|
||||
public IConfigElement configElement;
|
||||
public List<IGuiSelectStringListEntry> listEntries;
|
||||
public final Map<Object, String> selectableValues;
|
||||
public int selectedIndex = -1;
|
||||
public int maxEntryWidth = 0;
|
||||
|
||||
public GuiSelectStringEntries(GuiSelectString owningScreen, Minecraft mc, IConfigElement configElement, Map<Object, String> selectableValues)
|
||||
{
|
||||
super(mc, owningScreen.width, owningScreen.height, owningScreen.titleLine2 != null ? (owningScreen.titleLine3 != null ? 43 : 33) : 23,
|
||||
owningScreen.height - 32, 11);
|
||||
this.owningScreen = owningScreen;
|
||||
this.mc = mc;
|
||||
this.configElement = configElement;
|
||||
this.selectableValues = selectableValues;
|
||||
this.setShowSelectionBox(true);
|
||||
|
||||
listEntries = new ArrayList<IGuiSelectStringListEntry>();
|
||||
|
||||
int index = 0;
|
||||
List<Entry<Object, String>> sortedList = new ArrayList<Entry<Object, String>>(selectableValues.entrySet());
|
||||
Collections.sort(sortedList, new EntryComparator());
|
||||
|
||||
for (Entry<Object, String> entry : sortedList)
|
||||
{
|
||||
listEntries.add(new ListEntry(this, entry));
|
||||
if (mc.fontRendererObj.getStringWidth(entry.getValue()) > maxEntryWidth)
|
||||
maxEntryWidth = mc.fontRendererObj.getStringWidth(entry.getValue());
|
||||
|
||||
if (owningScreen.currentValue.equals(entry.getKey()))
|
||||
{
|
||||
this.selectedIndex = index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntryComparator implements Comparator<Entry<Object, String>>
|
||||
{
|
||||
@Override
|
||||
public int compare(Entry<Object, String> o1, Entry<Object, String> o2)
|
||||
{
|
||||
int compare = o1.getValue().toLowerCase(Locale.US).compareTo(o2.getValue().toLowerCase(Locale.US));
|
||||
|
||||
if (compare == 0)
|
||||
compare = o1.getKey().toString().toLowerCase(Locale.US).compareTo(o2.getKey().toString().toLowerCase(Locale.US));
|
||||
|
||||
return compare;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The element in the slot that was clicked, boolean for whether it was double clicked or not
|
||||
*/
|
||||
@Override
|
||||
protected void elementClicked(int index, boolean doubleClick, int mouseX, int mouseY)
|
||||
{
|
||||
selectedIndex = index;
|
||||
owningScreen.currentValue = listEntries.get(index).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the element passed in is currently selected
|
||||
*/
|
||||
@Override
|
||||
protected boolean isSelected(int index)
|
||||
{
|
||||
return index == selectedIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrollBarX()
|
||||
{
|
||||
return width / 2 + this.maxEntryWidth / 2 + 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the list
|
||||
*/
|
||||
@Override
|
||||
public int getListWidth()
|
||||
{
|
||||
return maxEntryWidth + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGuiSelectStringListEntry getListEntry(int index)
|
||||
{
|
||||
return listEntries.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize()
|
||||
{
|
||||
return listEntries.size();
|
||||
}
|
||||
|
||||
public boolean isChanged()
|
||||
{
|
||||
return owningScreen.beforeValue != null ? !owningScreen.beforeValue.equals(owningScreen.currentValue) : owningScreen.currentValue != null;
|
||||
}
|
||||
|
||||
public boolean isDefault()
|
||||
{
|
||||
return owningScreen.currentValue != null ? owningScreen.currentValue.equals(configElement.getDefault()) : configElement.getDefault() == null;
|
||||
}
|
||||
|
||||
public void saveChanges()
|
||||
{
|
||||
if (owningScreen.slotIndex != -1 && owningScreen.parentScreen != null
|
||||
&& owningScreen.parentScreen instanceof GuiConfig
|
||||
&& ((GuiConfig) owningScreen.parentScreen).entryList.getListEntry(owningScreen.slotIndex) instanceof SelectValueEntry)
|
||||
{
|
||||
SelectValueEntry entry = (SelectValueEntry) ((GuiConfig) owningScreen.parentScreen).entryList.getListEntry(owningScreen.slotIndex);
|
||||
|
||||
entry.setValueFromChildScreen(owningScreen.currentValue);
|
||||
}
|
||||
else
|
||||
configElement.set(owningScreen.currentValue);
|
||||
}
|
||||
|
||||
public static class ListEntry implements IGuiSelectStringListEntry
|
||||
{
|
||||
protected final GuiSelectStringEntries owningList;
|
||||
protected final Entry<Object, String> value;
|
||||
|
||||
public ListEntry(GuiSelectStringEntries owningList, Entry<Object, String> value)
|
||||
{
|
||||
this.owningList = owningList;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected)
|
||||
{
|
||||
owningList.mc.fontRendererObj.drawString(value.getValue(), x + 1, y, slotIndex == owningList.selectedIndex ? 16777215 : 14737632);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int index, int x, int y, int mouseEvent, int relativeX, int relativeY)
|
||||
{}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return value.getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_){}
|
||||
}
|
||||
|
||||
public static interface IGuiSelectStringListEntry extends GuiListExtended.IGuiListEntry
|
||||
{
|
||||
public Object getValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* This class is blatantly stolen from iChunUtils with permission.
|
||||
*
|
||||
* @author iChun
|
||||
*/
|
||||
public class GuiSlider extends GuiButtonExt
|
||||
{
|
||||
/** The value of this slider control. */
|
||||
public double sliderValue = 1.0F;
|
||||
|
||||
public String dispString = "";
|
||||
|
||||
/** Is this slider control being dragged. */
|
||||
public boolean dragging = false;
|
||||
public boolean showDecimal = true;
|
||||
|
||||
public double minValue = 0.0D;
|
||||
public double maxValue = 5.0D;
|
||||
public int precision = 1;
|
||||
|
||||
public ISlider parent = null;
|
||||
|
||||
public String suffix = "";
|
||||
|
||||
public boolean drawString = true;
|
||||
|
||||
public GuiSlider(int id, int xPos, int yPos, int width, int height, String prefix, String suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr)
|
||||
{
|
||||
this(id, xPos, yPos, width, height, prefix, suf, minVal, maxVal, currentVal, showDec, drawStr, null);
|
||||
}
|
||||
|
||||
public GuiSlider(int id, int xPos, int yPos, int width, int height, String prefix, String suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr, ISlider par)
|
||||
{
|
||||
super(id, xPos, yPos, width, height, prefix);
|
||||
minValue = minVal;
|
||||
maxValue = maxVal;
|
||||
sliderValue = (currentVal - minValue) / (maxValue - minValue);
|
||||
dispString = prefix;
|
||||
parent = par;
|
||||
suffix = suf;
|
||||
showDecimal = showDec;
|
||||
String val;
|
||||
|
||||
if (showDecimal)
|
||||
{
|
||||
val = Double.toString(sliderValue * (maxValue - minValue) + minValue);
|
||||
precision = Math.min(val.substring(val.indexOf(".") + 1).length(), 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = Integer.toString((int)Math.round(sliderValue * (maxValue - minValue) + minValue));
|
||||
precision = 0;
|
||||
}
|
||||
|
||||
displayString = dispString + val + suffix;
|
||||
|
||||
drawString = drawStr;
|
||||
if(!drawString)
|
||||
{
|
||||
displayString = "";
|
||||
}
|
||||
}
|
||||
|
||||
public GuiSlider(int id, int xPos, int yPos, String displayStr, double minVal, double maxVal, double currentVal, ISlider par)
|
||||
{
|
||||
this(id, xPos, yPos, 150, 20, displayStr, "", minVal, maxVal, currentVal, true, true, par);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
|
||||
* this button.
|
||||
*/
|
||||
@Override
|
||||
public int getHoverState(boolean par1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
|
||||
*/
|
||||
@Override
|
||||
protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3)
|
||||
{
|
||||
if (this.visible)
|
||||
{
|
||||
if (this.dragging)
|
||||
{
|
||||
this.sliderValue = (par2 - (this.xPosition + 4)) / (float)(this.width - 8);
|
||||
updateSlider();
|
||||
}
|
||||
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
|
||||
this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
|
||||
* e).
|
||||
*/
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3)
|
||||
{
|
||||
if (super.mousePressed(par1Minecraft, par2, par3))
|
||||
{
|
||||
this.sliderValue = (float)(par2 - (this.xPosition + 4)) / (float)(this.width - 8);
|
||||
updateSlider();
|
||||
this.dragging = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateSlider()
|
||||
{
|
||||
if (this.sliderValue < 0.0F)
|
||||
{
|
||||
this.sliderValue = 0.0F;
|
||||
}
|
||||
|
||||
if (this.sliderValue > 1.0F)
|
||||
{
|
||||
this.sliderValue = 1.0F;
|
||||
}
|
||||
|
||||
String val;
|
||||
|
||||
if (showDecimal)
|
||||
{
|
||||
val = Double.toString(sliderValue * (maxValue - minValue) + minValue);
|
||||
|
||||
if (val.substring(val.indexOf(".") + 1).length() > precision)
|
||||
{
|
||||
val = val.substring(0, val.indexOf(".") + precision + 1);
|
||||
|
||||
if (val.endsWith("."))
|
||||
{
|
||||
val = val.substring(0, val.indexOf(".") + precision);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (val.substring(val.indexOf(".") + 1).length() < precision)
|
||||
{
|
||||
val = val + "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
val = Integer.toString((int)Math.round(sliderValue * (maxValue - minValue) + minValue));
|
||||
}
|
||||
|
||||
if(drawString)
|
||||
{
|
||||
displayString = dispString + val + suffix;
|
||||
}
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
parent.onChangeSliderValue(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
|
||||
*/
|
||||
@Override
|
||||
public void mouseReleased(int par1, int par2)
|
||||
{
|
||||
this.dragging = false;
|
||||
}
|
||||
|
||||
public int getValueInt()
|
||||
{
|
||||
return (int)Math.round(sliderValue * (maxValue - minValue) + minValue);
|
||||
}
|
||||
|
||||
public double getValue()
|
||||
{
|
||||
return sliderValue * (maxValue - minValue) + minValue;
|
||||
}
|
||||
|
||||
public void setValue(double d)
|
||||
{
|
||||
this.sliderValue = (d - minValue) / (maxValue - minValue);
|
||||
}
|
||||
|
||||
public static interface ISlider
|
||||
{
|
||||
void onChangeSliderValue(GuiSlider slider);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* This class provides a button that shows a string glyph at the beginning. The glyph can be scaled using the glyphScale parameter.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiUnicodeGlyphButton extends GuiButtonExt
|
||||
{
|
||||
public String glyph;
|
||||
public float glyphScale;
|
||||
|
||||
public GuiUnicodeGlyphButton(int id, int xPos, int yPos, int width, int height, String displayString, String glyph, float glyphScale)
|
||||
{
|
||||
super(id, xPos, yPos, width, height, displayString);
|
||||
this.glyph = glyph;
|
||||
this.glyphScale = glyphScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY)
|
||||
{
|
||||
if (this.visible)
|
||||
{
|
||||
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
||||
int k = this.getHoverState(this.hovered);
|
||||
GuiUtils.drawContinuousTexturedBox(buttonTextures, this.xPosition, this.yPosition, 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, this.zLevel);
|
||||
this.mouseDragged(mc, mouseX, mouseY);
|
||||
int color = 14737632;
|
||||
|
||||
if (packedFGColour != 0)
|
||||
{
|
||||
color = packedFGColour;
|
||||
}
|
||||
else if (!this.enabled)
|
||||
{
|
||||
color = 10526880;
|
||||
}
|
||||
else if (this.hovered)
|
||||
{
|
||||
color = 16777120;
|
||||
}
|
||||
|
||||
String buttonText = this.displayString;
|
||||
int glyphWidth = (int) (mc.fontRendererObj.getStringWidth(glyph) * glyphScale);
|
||||
int strWidth = mc.fontRendererObj.getStringWidth(buttonText);
|
||||
int elipsisWidth = mc.fontRendererObj.getStringWidth("...");
|
||||
int totalWidth = strWidth + glyphWidth;
|
||||
|
||||
if (totalWidth > width - 6 && totalWidth > elipsisWidth)
|
||||
buttonText = mc.fontRendererObj.trimStringToWidth(buttonText, width - 6 - elipsisWidth).trim() + "...";
|
||||
|
||||
strWidth = mc.fontRendererObj.getStringWidth(buttonText);
|
||||
totalWidth = glyphWidth + strWidth;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(glyphScale, glyphScale, 1.0F);
|
||||
this.drawCenteredString(mc.fontRendererObj, glyph,
|
||||
(int) (((this.xPosition + (this.width / 2) - (strWidth / 2)) / glyphScale) - (glyphWidth / (2 * glyphScale)) + 2),
|
||||
(int) (((this.yPosition + ((this.height - 8) / glyphScale) / 2) - 1) / glyphScale), color);
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
this.drawCenteredString(mc.fontRendererObj, buttonText, (int) (this.xPosition + (this.width / 2) + (glyphWidth / glyphScale)),
|
||||
this.yPosition + (this.height - 8) / 2, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* This class provides several methods and constants used by the Config GUI classes.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class GuiUtils
|
||||
{
|
||||
public static final String UNDO_CHAR = "\u21B6";
|
||||
public static final String RESET_CHAR = "\u2604";
|
||||
public static final String VALID = "\u2714";
|
||||
public static final String INVALID = "\u2715";
|
||||
|
||||
public static int[] colorCodes = new int[] { 0, 170, 43520, 43690, 11141120, 11141290, 16755200, 11184810, 5592405, 5592575, 5635925, 5636095, 16733525, 16733695, 16777045, 16777215,
|
||||
0, 42, 10752, 10794, 2752512, 2752554, 2763264, 2763306, 1381653, 1381695, 1392405, 1392447, 4134165, 4134207, 4144917, 4144959 };
|
||||
|
||||
public static int getColorCode(char c, boolean isLighter)
|
||||
{
|
||||
return colorCodes[isLighter ? "0123456789abcdef".indexOf(c) : "0123456789abcdef".indexOf(c) + 16];
|
||||
}
|
||||
/**
|
||||
* Draws a textured box of any size (smallest size is borderSize * 2 square) based on a fixed size textured box with continuous borders
|
||||
* and filler. It is assumed that the desired texture ResourceLocation object has been bound using
|
||||
* Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation).
|
||||
*
|
||||
* @param x x axis offset
|
||||
* @param y y axis offset
|
||||
* @param u bound resource location image x offset
|
||||
* @param v bound resource location image y offset
|
||||
* @param width the desired box width
|
||||
* @param height the desired box height
|
||||
* @param textureWidth the width of the box texture in the resource location image
|
||||
* @param textureHeight the height of the box texture in the resource location image
|
||||
* @param borderSize the size of the box's borders
|
||||
* @param zLevel the zLevel to draw at
|
||||
*/
|
||||
public static void drawContinuousTexturedBox(int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight,
|
||||
int borderSize, float zLevel)
|
||||
{
|
||||
drawContinuousTexturedBox(x, y, u, v, width, height, textureWidth, textureHeight, borderSize, borderSize, borderSize, borderSize, zLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a textured box of any size (smallest size is borderSize * 2 square) based on a fixed size textured box with continuous borders
|
||||
* and filler. The provided ResourceLocation object will be bound using
|
||||
* Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation).
|
||||
*
|
||||
* @param res the ResourceLocation object that contains the desired image
|
||||
* @param x x axis offset
|
||||
* @param y y axis offset
|
||||
* @param u bound resource location image x offset
|
||||
* @param v bound resource location image y offset
|
||||
* @param width the desired box width
|
||||
* @param height the desired box height
|
||||
* @param textureWidth the width of the box texture in the resource location image
|
||||
* @param textureHeight the height of the box texture in the resource location image
|
||||
* @param borderSize the size of the box's borders
|
||||
* @param zLevel the zLevel to draw at
|
||||
*/
|
||||
public static void drawContinuousTexturedBox(ResourceLocation res, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight,
|
||||
int borderSize, float zLevel)
|
||||
{
|
||||
drawContinuousTexturedBox(res, x, y, u, v, width, height, textureWidth, textureHeight, borderSize, borderSize, borderSize, borderSize, zLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a textured box of any size (smallest size is borderSize * 2 square) based on a fixed size textured box with continuous borders
|
||||
* and filler. The provided ResourceLocation object will be bound using
|
||||
* Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation).
|
||||
*
|
||||
* @param res the ResourceLocation object that contains the desired image
|
||||
* @param x x axis offset
|
||||
* @param y y axis offset
|
||||
* @param u bound resource location image x offset
|
||||
* @param v bound resource location image y offset
|
||||
* @param width the desired box width
|
||||
* @param height the desired box height
|
||||
* @param textureWidth the width of the box texture in the resource location image
|
||||
* @param textureHeight the height of the box texture in the resource location image
|
||||
* @param topBorder the size of the box's top border
|
||||
* @param bottomBorder the size of the box's bottom border
|
||||
* @param leftBorder the size of the box's left border
|
||||
* @param rightBorder the size of the box's right border
|
||||
* @param zLevel the zLevel to draw at
|
||||
*/
|
||||
public static void drawContinuousTexturedBox(ResourceLocation res, int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight,
|
||||
int topBorder, int bottomBorder, int leftBorder, int rightBorder, float zLevel)
|
||||
{
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(res);
|
||||
drawContinuousTexturedBox(x, y, u, v, width, height, textureWidth, textureHeight, topBorder, bottomBorder, leftBorder, rightBorder, zLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a textured box of any size (smallest size is borderSize * 2 square) based on a fixed size textured box with continuous borders
|
||||
* and filler. It is assumed that the desired texture ResourceLocation object has been bound using
|
||||
* Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation).
|
||||
*
|
||||
* @param x x axis offset
|
||||
* @param y y axis offset
|
||||
* @param u bound resource location image x offset
|
||||
* @param v bound resource location image y offset
|
||||
* @param width the desired box width
|
||||
* @param height the desired box height
|
||||
* @param textureWidth the width of the box texture in the resource location image
|
||||
* @param textureHeight the height of the box texture in the resource location image
|
||||
* @param topBorder the size of the box's top border
|
||||
* @param bottomBorder the size of the box's bottom border
|
||||
* @param leftBorder the size of the box's left border
|
||||
* @param rightBorder the size of the box's right border
|
||||
* @param zLevel the zLevel to draw at
|
||||
*/
|
||||
public static void drawContinuousTexturedBox(int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight,
|
||||
int topBorder, int bottomBorder, int leftBorder, int rightBorder, float zLevel)
|
||||
{
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
|
||||
int fillerWidth = textureWidth - leftBorder - rightBorder;
|
||||
int fillerHeight = textureHeight - topBorder - bottomBorder;
|
||||
int canvasWidth = width - leftBorder - rightBorder;
|
||||
int canvasHeight = height - topBorder - bottomBorder;
|
||||
int xPasses = canvasWidth / fillerWidth;
|
||||
int remainderWidth = canvasWidth % fillerWidth;
|
||||
int yPasses = canvasHeight / fillerHeight;
|
||||
int remainderHeight = canvasHeight % fillerHeight;
|
||||
|
||||
// Draw Border
|
||||
// Top Left
|
||||
drawTexturedModalRect(x, y, u, v, leftBorder, topBorder, zLevel);
|
||||
// Top Right
|
||||
drawTexturedModalRect(x + leftBorder + canvasWidth, y, u + leftBorder + fillerWidth, v, rightBorder, topBorder, zLevel);
|
||||
// Bottom Left
|
||||
drawTexturedModalRect(x, y + topBorder + canvasHeight, u, v + topBorder + fillerHeight, leftBorder, bottomBorder, zLevel);
|
||||
// Bottom Right
|
||||
drawTexturedModalRect(x + leftBorder + canvasWidth, y + topBorder + canvasHeight, u + leftBorder + fillerWidth, v + topBorder + fillerHeight, rightBorder, bottomBorder, zLevel);
|
||||
|
||||
for (int i = 0; i < xPasses + (remainderWidth > 0 ? 1 : 0); i++)
|
||||
{
|
||||
// Top Border
|
||||
drawTexturedModalRect(x + leftBorder + (i * fillerWidth), y, u + leftBorder, v, (i == xPasses ? remainderWidth : fillerWidth), topBorder, zLevel);
|
||||
// Bottom Border
|
||||
drawTexturedModalRect(x + leftBorder + (i * fillerWidth), y + topBorder + canvasHeight, u + leftBorder, v + topBorder + fillerHeight, (i == xPasses ? remainderWidth : fillerWidth), bottomBorder, zLevel);
|
||||
|
||||
// Throw in some filler for good measure
|
||||
for (int j = 0; j < yPasses + (remainderHeight > 0 ? 1 : 0); j++)
|
||||
drawTexturedModalRect(x + leftBorder + (i * fillerWidth), y + topBorder + (j * fillerHeight), u + leftBorder, v + topBorder, (i == xPasses ? remainderWidth : fillerWidth), (j == yPasses ? remainderHeight : fillerHeight), zLevel);
|
||||
}
|
||||
|
||||
// Side Borders
|
||||
for (int j = 0; j < yPasses + (remainderHeight > 0 ? 1 : 0); j++)
|
||||
{
|
||||
// Left Border
|
||||
drawTexturedModalRect(x, y + topBorder + (j * fillerHeight), u, v + topBorder, leftBorder, (j == yPasses ? remainderHeight : fillerHeight), zLevel);
|
||||
// Right Border
|
||||
drawTexturedModalRect(x + leftBorder + canvasWidth, y + topBorder + (j * fillerHeight), u + leftBorder + fillerWidth, v + topBorder, rightBorder, (j == yPasses ? remainderHeight : fillerHeight), zLevel);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float zLevel)
|
||||
{
|
||||
float var7 = 0.00390625F;
|
||||
float var8 = 0.00390625F;
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldr = tessellator.getWorldRenderer();
|
||||
worldr.startDrawingQuads();
|
||||
worldr.addVertexWithUV((x + 0), (y + height), zLevel, ((u + 0) * var7), ((v + height) * var8));
|
||||
worldr.addVertexWithUV((x + width), (y + height), zLevel, ((u + width) * var7), ((v + height) * var8));
|
||||
worldr.addVertexWithUV((x + width), (y + 0), zLevel, ((u + width) * var7), ((v + 0) * var8));
|
||||
worldr.addVertexWithUV((x + 0), (y + 0), zLevel, ((u + 0) * var7), ((v + 0) * var8));
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
/**
|
||||
* This class implements an easy way to check if the mouse has hovered within a certain region of the screen for a given
|
||||
* period of time. The region can be defined manually or by supplying a GuiButton object.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public class HoverChecker
|
||||
{
|
||||
private int top, bottom, left, right, threshold;
|
||||
private GuiButton button;
|
||||
private long hoverStart;
|
||||
|
||||
public HoverChecker(int top, int bottom, int left, int right, int threshold)
|
||||
{
|
||||
this.top = top;
|
||||
this.bottom = bottom;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.threshold = threshold;
|
||||
this.hoverStart = -1;
|
||||
}
|
||||
|
||||
public HoverChecker(GuiButton button, int threshold)
|
||||
{
|
||||
this.button = button;
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method if the intended region has changed such as if the region must follow a scrolling list.
|
||||
* It is not necessary to call this method if a GuiButton defines the hover region.
|
||||
*/
|
||||
public void updateBounds(int top, int bottom, int left, int right)
|
||||
{
|
||||
this.top = top;
|
||||
this.bottom = bottom;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the mouse is in the hover region. If the specified time period has elapsed the method returns true.
|
||||
* The hover timer is reset if the mouse is not within the region.
|
||||
*/
|
||||
public boolean checkHover(int mouseX, int mouseY)
|
||||
{
|
||||
return checkHover(mouseX, mouseY, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the mouse is in the hover region. If the specified time period has elapsed the method returns true.
|
||||
* The hover timer is reset if the mouse is not within the region.
|
||||
*/
|
||||
public boolean checkHover(int mouseX, int mouseY, boolean canHover)
|
||||
{
|
||||
if (this.button != null)
|
||||
{
|
||||
this.top = button.yPosition;
|
||||
this.bottom = button.yPosition + button.height;
|
||||
this.left = button.xPosition;
|
||||
this.right = button.xPosition + button.width;
|
||||
canHover = canHover && button.visible;
|
||||
}
|
||||
|
||||
if (canHover && hoverStart == -1 && mouseY >= top && mouseY <= bottom && mouseX >= left && mouseX <= right)
|
||||
hoverStart = System.currentTimeMillis();
|
||||
else if (!canHover || mouseY < top || mouseY > bottom || mouseX < left || mouseX > right)
|
||||
resetHoverTimer();
|
||||
|
||||
return canHover && hoverStart != -1 && System.currentTimeMillis() - hoverStart >= threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually resets the hover timer.
|
||||
*/
|
||||
public void resetHoverTimer()
|
||||
{
|
||||
hoverStart = -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry;
|
||||
import net.minecraftforge.fml.client.config.GuiEditArrayEntries.IArrayEntry;
|
||||
|
||||
/**
|
||||
* This interface provides the information needed by GuiConfig and GuiConfigEntries to display config elements for editing.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
public interface IConfigElement
|
||||
{
|
||||
/**
|
||||
* [Property, Category] Is this object a property object?
|
||||
*/
|
||||
public boolean isProperty();
|
||||
|
||||
/**
|
||||
* This method returns a class that implements {@code IConfigEntry} or null. This class MUST
|
||||
* provide a constructor with the following parameter types: {@code GuiConfig}, {@code GuiConfigEntries}, {@code IConfigElement}
|
||||
*/
|
||||
public Class<? extends IConfigEntry> getConfigEntryClass();
|
||||
|
||||
/**
|
||||
* This method returns a class that implements {@code IArrayEntry}. This class MUST provide a constructor with the
|
||||
* following parameter types: {@code GuiEditArray}, {@code GuiEditArrayEntries}, {@code IConfigElement}, {@code Object}
|
||||
*/
|
||||
public Class<? extends IArrayEntry> getArrayEntryClass();
|
||||
|
||||
/**
|
||||
* [Property, Category] Gets the name of this object.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* [Category] Gets the qualified name of this object. This is typically only used for category objects.
|
||||
*/
|
||||
public String getQualifiedName();
|
||||
|
||||
/**
|
||||
* [Property, Category] Gets a language key for localization of config GUI entry names. If the same key is specified with .tooltip
|
||||
* appended to the end, that key will return a localized tooltip when the mouse hovers over the property label/category button.
|
||||
*/
|
||||
public String getLanguageKey();
|
||||
|
||||
/**
|
||||
* [Property, Category] Gets the comment for this object. Used for the tooltip if getLanguageKey() + ".tooltip" is not defined in the
|
||||
* .lang file.
|
||||
*/
|
||||
public String getComment();
|
||||
|
||||
/**
|
||||
* [Category] Gets this category's child categories/properties.
|
||||
*/
|
||||
public List<IConfigElement> getChildElements();
|
||||
|
||||
/**
|
||||
* [Property, Category] Gets the ConfigGuiType value corresponding to the type of this property object, or CONFIG_CATEGORY if this is a
|
||||
* category object.
|
||||
*/
|
||||
public ConfigGuiType getType();
|
||||
|
||||
/**
|
||||
* [Property] Is this property object a list?
|
||||
*/
|
||||
public boolean isList();
|
||||
|
||||
/**
|
||||
* [Property] Does this list property have to remain a fixed length?
|
||||
*/
|
||||
public boolean isListLengthFixed();
|
||||
|
||||
/**
|
||||
* [Property] Gets the max length of this list property, or -1 if the length is unlimited.
|
||||
*/
|
||||
public int getMaxListLength();
|
||||
|
||||
/**
|
||||
* [Property] Is this property value equal to the default value?
|
||||
*/
|
||||
public boolean isDefault();
|
||||
|
||||
/**
|
||||
* [Property] Gets this property's default value. If this element is an array, this method should return a String
|
||||
* representation of that array using Arrays.toString()
|
||||
*/
|
||||
public Object getDefault();
|
||||
|
||||
/**
|
||||
* [Property] Gets this property's default values.
|
||||
*/
|
||||
public Object[] getDefaults();
|
||||
|
||||
/**
|
||||
* [Property] Sets this property's value to the default value.
|
||||
*/
|
||||
public void setToDefault();
|
||||
|
||||
/**
|
||||
* [Property, Category] Whether or not this element is safe to modify while a world is running. For Categories return false if ANY properties
|
||||
* in the category are modifiable while a world is running, true if all are not.
|
||||
*/
|
||||
public boolean requiresWorldRestart();
|
||||
|
||||
/**
|
||||
* [Property, Category] Whether or not this element should be allowed to show on config GUIs.
|
||||
*/
|
||||
public boolean showInGui();
|
||||
|
||||
/**
|
||||
* [Property, Category] Whether or not this element requires Minecraft to be restarted when changed.
|
||||
*/
|
||||
public boolean requiresMcRestart();
|
||||
|
||||
/**
|
||||
* [Property] Gets this property value.
|
||||
*/
|
||||
public Object get();
|
||||
|
||||
/**
|
||||
* [Property] Gets this property value as a list. Generally you should be sure of whether the property is a list before calling this.
|
||||
*/
|
||||
public Object[] getList();
|
||||
|
||||
/**
|
||||
* [Property] Sets this property's value.
|
||||
*/
|
||||
public void set(Object value);
|
||||
|
||||
/**
|
||||
* [Property] Sets this property's value to the specified array.
|
||||
*/
|
||||
public void set(Object[] aVal);
|
||||
|
||||
/**
|
||||
* [Property] Gets a String array of valid values for this property. This is generally used for String properties to allow the user to
|
||||
* select a value from a list of valid values.
|
||||
*/
|
||||
public String[] getValidValues();
|
||||
|
||||
/**
|
||||
* [Property] Gets this property's minimum value.
|
||||
*/
|
||||
public Object getMinValue();
|
||||
|
||||
/**
|
||||
* [Property] Gets this property's maximum value.
|
||||
*/
|
||||
public Object getMaxValue();
|
||||
|
||||
/**
|
||||
* [Property] Gets a Pattern object used in String property input validation.
|
||||
*/
|
||||
public Pattern getValidationPattern();
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2014 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors (this class):
|
||||
* bspkrs - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.event;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
|
||||
|
||||
/**
|
||||
* These events are posted from the GuiConfig screen when the done button is pressed. The events are only posted
|
||||
* if the parent screen is not an instance of GuiConfig or if the configID field has been set for
|
||||
* the GuiConfig screen.
|
||||
*
|
||||
* Listeners for this event should use OnConfigChanged or PostConfigChanged and check for a specific mod ID.
|
||||
* For best results the listener should refresh any objects/fields that are set based on the mod's config
|
||||
* and should serialize the modified config.
|
||||
*
|
||||
* @author bspkrs
|
||||
*/
|
||||
@HasResult
|
||||
public class ConfigChangedEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The Mod ID of the mod whose configuration just changed.
|
||||
*/
|
||||
public final String modID;
|
||||
/**
|
||||
* Whether or not a world is currently running.
|
||||
*/
|
||||
public final boolean isWorldRunning;
|
||||
/**
|
||||
* Will be set to true if any elements were changed that require a restart of Minecraft.
|
||||
*/
|
||||
public final boolean requiresMcRestart;
|
||||
/**
|
||||
* A String identifier for this ConfigChangedEvent.
|
||||
*/
|
||||
public final String configID;
|
||||
|
||||
public ConfigChangedEvent(String modID, String configID, boolean isWorldRunning, boolean requiresMcRestart)
|
||||
{
|
||||
this.modID = modID;
|
||||
this.configID = configID;
|
||||
this.isWorldRunning = isWorldRunning;
|
||||
this.requiresMcRestart = requiresMcRestart;
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is intended to be consumed by the mod whose config has been changed. It fires when the Done button
|
||||
* has been clicked on a GuiConfig screen and the following conditions are met:<br/>
|
||||
* - at least one config element has been changed<br/>
|
||||
* - one of these 2 conditions are met:<br/>
|
||||
* 1) the parent screen is null or is not an instance of GuiConfig<br/>
|
||||
* 2) the configID field has been set to a non-null value for the GuiConfig screen<br/><br/>
|
||||
* Modders should check the modID field of the event to ensure they are only acting on their own config screen's event!
|
||||
*/
|
||||
public static class OnConfigChangedEvent extends ConfigChangedEvent
|
||||
{
|
||||
public OnConfigChangedEvent(String modID, String configID, boolean isWorldRunning, boolean requiresMcRestart)
|
||||
{
|
||||
super(modID, configID, isWorldRunning, requiresMcRestart);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is provided for mods to consume if they want to be able to check if other mods' configs have been changed.
|
||||
* This event only fires if the OnConfigChangedEvent result is not DENY.
|
||||
*/
|
||||
public static class PostConfigChangedEvent extends ConfigChangedEvent
|
||||
{
|
||||
public PostConfigChangedEvent(String modID, String configID, boolean isWorldRunning, boolean requiresMcRestart)
|
||||
{
|
||||
super(modID, configID, isWorldRunning, requiresMcRestart);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.client.registry;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
public class ClientRegistry
|
||||
{
|
||||
/**
|
||||
*
|
||||
* Utility method for registering a tile entity and it's renderer at once - generally you should register them separately
|
||||
*
|
||||
* @param tileEntityClass
|
||||
* @param id
|
||||
* @param specialRenderer
|
||||
*/
|
||||
public static void registerTileEntity(Class <? extends TileEntity > tileEntityClass, String id, TileEntitySpecialRenderer specialRenderer)
|
||||
{
|
||||
GameRegistry.registerTileEntity(tileEntityClass, id);
|
||||
bindTileEntitySpecialRenderer(tileEntityClass, specialRenderer);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void bindTileEntitySpecialRenderer(Class <? extends TileEntity> tileEntityClass, TileEntitySpecialRenderer specialRenderer)
|
||||
{
|
||||
TileEntityRendererDispatcher.instance.mapSpecialRenderers.put(tileEntityClass, specialRenderer);
|
||||
specialRenderer.setRendererDispatcher(TileEntityRendererDispatcher.instance);
|
||||
}
|
||||
|
||||
public static void registerKeyBinding(KeyBinding key)
|
||||
{
|
||||
Minecraft.getMinecraft().gameSettings.keyBindings = ArrayUtils.add(Minecraft.getMinecraft().gameSettings.keyBindings, key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
package net.minecraftforge.fml.client.registry;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public class RenderingRegistry
|
||||
{
|
||||
private static final RenderingRegistry INSTANCE = new RenderingRegistry();
|
||||
|
||||
private List<EntityRendererInfo> entityRenderers = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* Register an entity rendering handler. This will, after mod initialization, be inserted into the main
|
||||
* render map for entities
|
||||
*
|
||||
* @param entityClass
|
||||
* @param renderer
|
||||
*/
|
||||
public static void registerEntityRenderingHandler(Class<? extends Entity> entityClass, Render renderer)
|
||||
{
|
||||
INSTANCE.entityRenderers.add(new EntityRendererInfo(entityClass, renderer));
|
||||
}
|
||||
|
||||
private static class EntityRendererInfo
|
||||
{
|
||||
public EntityRendererInfo(Class<? extends Entity> target, Render renderer)
|
||||
{
|
||||
this.target = target;
|
||||
this.renderer = renderer;
|
||||
}
|
||||
private Class<? extends Entity> target;
|
||||
private Render renderer;
|
||||
}
|
||||
|
||||
public static void loadEntityRenderers(Map<Class<? extends Entity>, Render> rendererMap)
|
||||
{
|
||||
for (EntityRendererInfo info : INSTANCE.entityRenderers)
|
||||
{
|
||||
rendererMap.put(info.target, info.renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user