diff --git a/.classpath b/.classpath deleted file mode 100644 index 701c38c..0000000 --- a/.classpath +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore index e660fd9..a141cd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,40 @@ + +# eclipse +.project +.classpath +.settings + +# eclipse and mcp use this bin/ + +# all of mcp +CHANGELOG +cleanup.bat +cleanup.sh +conf/ +decompile.bat +decompile.sh +docs/ +eclipse/ +jars/ +lib/ +LICENSE +logs/ +recompile.bat +recompile.sh +reobf/ +reobfuscate.bat +reobfuscate.sh +runtime/ +startclient.bat +startclient.sh +startserver.bat +startserver.sh +temp/ +updatemcp.bat +updatemcp.sh +updatemd5.bat +updatemd5.sh +updatenames.bat +updatenames.sh + diff --git a/.project b/.project deleted file mode 100644 index c978ea6..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - GuiAPI - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index f0b25bb..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Mon Apr 04 18:27:12 MDT 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/GuiAPIAnt.xml b/GuiAPIAnt.xml new file mode 100644 index 0000000..b236a6c --- /dev/null +++ b/GuiAPIAnt.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.creole b/README.creole deleted file mode 100644 index a37c87e..0000000 --- a/README.creole +++ /dev/null @@ -1,15 +0,0 @@ -= GuiAPI = - -GuiAPI uses the TWL library from Matthias Mann (probably spelled his name wrong), see [[http://twl.l33tlabs.org/|twl.l33tlabs.org]] - -==Building== -* First decompile the needed minecraft classes with jad, then run them through astyle --break-blocks --delete-empty-lines --style=java -* Apply the diffs in diffs/ to your decompiled minecraft and copy those java files to src/ -* Build (I use eclipse) -** You need .minecraft/bin/*.jar, Modloader, twl/bin, and xpp on your build classpath. - -==Packaging== -To create a distributable archive, package twl/bin/*, xpp*/*, theme/*, and bin/*. - -==Credits== -Lots of people who I forget. Open an issue or something if you helped ... diff --git a/bin/GuiModScreen.class b/bin/GuiModScreen.class deleted file mode 100644 index 9f685ef..0000000 Binary files a/bin/GuiModScreen.class and /dev/null differ diff --git a/bin/GuiModSelect.class b/bin/GuiModSelect.class deleted file mode 100644 index 9556b2d..0000000 Binary files a/bin/GuiModSelect.class and /dev/null differ diff --git a/bin/GuiWidgetScreen.class b/bin/GuiWidgetScreen.class deleted file mode 100644 index 71da91f..0000000 Binary files a/bin/GuiWidgetScreen.class and /dev/null differ diff --git a/bin/ModAction.class b/bin/ModAction.class deleted file mode 100644 index 06263aa..0000000 Binary files a/bin/ModAction.class and /dev/null differ diff --git a/bin/ModCallback.class b/bin/ModCallback.class deleted file mode 100644 index 47a56c3..0000000 Binary files a/bin/ModCallback.class and /dev/null differ diff --git a/bin/ModSettingScreen.class b/bin/ModSettingScreen.class deleted file mode 100644 index f1e18ea..0000000 Binary files a/bin/ModSettingScreen.class and /dev/null differ diff --git a/bin/ModSettings.class b/bin/ModSettings.class deleted file mode 100644 index 927240d..0000000 Binary files a/bin/ModSettings.class and /dev/null differ diff --git a/bin/ScreenScaleProxy.class b/bin/ScreenScaleProxy.class deleted file mode 100644 index a89b4cc..0000000 Binary files a/bin/ScreenScaleProxy.class and /dev/null differ diff --git a/bin/Setting.class b/bin/Setting.class deleted file mode 100644 index 574d7b0..0000000 Binary files a/bin/Setting.class and /dev/null differ diff --git a/bin/SettingBoolean.class b/bin/SettingBoolean.class deleted file mode 100644 index 03aa6de..0000000 Binary files a/bin/SettingBoolean.class and /dev/null differ diff --git a/bin/SettingFloat.class b/bin/SettingFloat.class deleted file mode 100644 index 47154f7..0000000 Binary files a/bin/SettingFloat.class and /dev/null differ diff --git a/bin/SettingInt.class b/bin/SettingInt.class deleted file mode 100644 index b7cecd8..0000000 Binary files a/bin/SettingInt.class and /dev/null differ diff --git a/bin/SettingKey.class b/bin/SettingKey.class deleted file mode 100644 index 1981d13..0000000 Binary files a/bin/SettingKey.class and /dev/null differ diff --git a/bin/SettingMulti.class b/bin/SettingMulti.class deleted file mode 100644 index 9179c7e..0000000 Binary files a/bin/SettingMulti.class and /dev/null differ diff --git a/bin/SettingText.class b/bin/SettingText.class deleted file mode 100644 index ce2c3a6..0000000 Binary files a/bin/SettingText.class and /dev/null differ diff --git a/bin/Subscreen.class b/bin/Subscreen.class deleted file mode 100644 index 895e21b..0000000 Binary files a/bin/Subscreen.class and /dev/null differ diff --git a/bin/WidgetBoolean.class b/bin/WidgetBoolean.class deleted file mode 100644 index 7505ee7..0000000 Binary files a/bin/WidgetBoolean.class and /dev/null differ diff --git a/bin/WidgetClassicTwocolumn.class b/bin/WidgetClassicTwocolumn.class deleted file mode 100644 index d7cc426..0000000 Binary files a/bin/WidgetClassicTwocolumn.class and /dev/null differ diff --git a/bin/WidgetClassicWindow.class b/bin/WidgetClassicWindow.class deleted file mode 100644 index 0d9c8b9..0000000 Binary files a/bin/WidgetClassicWindow.class and /dev/null differ diff --git a/bin/WidgetFloat.class b/bin/WidgetFloat.class deleted file mode 100644 index 79832a1..0000000 Binary files a/bin/WidgetFloat.class and /dev/null differ diff --git a/bin/WidgetInt.class b/bin/WidgetInt.class deleted file mode 100644 index 920b85f..0000000 Binary files a/bin/WidgetInt.class and /dev/null differ diff --git a/bin/WidgetKeybinding.class b/bin/WidgetKeybinding.class deleted file mode 100644 index 1584afc..0000000 Binary files a/bin/WidgetKeybinding.class and /dev/null differ diff --git a/bin/WidgetMulti.class b/bin/WidgetMulti.class deleted file mode 100644 index e473399..0000000 Binary files a/bin/WidgetMulti.class and /dev/null differ diff --git a/bin/WidgetSetting.class b/bin/WidgetSetting.class deleted file mode 100644 index 3d758bf..0000000 Binary files a/bin/WidgetSetting.class and /dev/null differ diff --git a/bin/WidgetSimplewindow.class b/bin/WidgetSimplewindow.class deleted file mode 100644 index 096b5b1..0000000 Binary files a/bin/WidgetSimplewindow.class and /dev/null differ diff --git a/bin/WidgetSingleRow.class b/bin/WidgetSingleRow.class deleted file mode 100644 index 4c5f949..0000000 Binary files a/bin/WidgetSingleRow.class and /dev/null differ diff --git a/bin/WidgetSinglecolumn.class b/bin/WidgetSinglecolumn.class deleted file mode 100644 index d97d871..0000000 Binary files a/bin/WidgetSinglecolumn.class and /dev/null differ diff --git a/bin/WidgetSlider.class b/bin/WidgetSlider.class deleted file mode 100644 index e4eab73..0000000 Binary files a/bin/WidgetSlider.class and /dev/null differ diff --git a/bin/WidgetText.class b/bin/WidgetText.class deleted file mode 100644 index 28431f9..0000000 Binary files a/bin/WidgetText.class and /dev/null differ diff --git a/bin/ch.class b/bin/ch.class deleted file mode 100644 index 425b726..0000000 Binary files a/bin/ch.class and /dev/null differ diff --git a/bin/oa.class b/bin/oa.class deleted file mode 100644 index 0d04200..0000000 Binary files a/bin/oa.class and /dev/null differ diff --git a/bin/qp.class b/bin/qp.class deleted file mode 100644 index b1a829f..0000000 Binary files a/bin/qp.class and /dev/null differ diff --git a/bin/uq.class b/bin/uq.class deleted file mode 100644 index dd409e3..0000000 Binary files a/bin/uq.class and /dev/null differ diff --git a/mcp/sharose/mods/guiapi/GuiAPI.java b/mcp/sharose/mods/guiapi/GuiAPI.java new file mode 100644 index 0000000..91e9a6a --- /dev/null +++ b/mcp/sharose/mods/guiapi/GuiAPI.java @@ -0,0 +1,160 @@ +package sharose.mods.guiapi; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; + +import cpw.mods.fml.common.ITickHandler; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.ObfuscationReflectionHelper; +import cpw.mods.fml.common.Mod.Init; +import cpw.mods.fml.common.Mod.PreInit; +import cpw.mods.fml.common.TickType; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.registry.TickRegistry; +import cpw.mods.fml.relauncher.IFMLLoadingPlugin; +import cpw.mods.fml.relauncher.Side; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.*; +import net.minecraft.client.settings.EnumOptions; +import net.minecraft.src.BaseMod; +import net.minecraft.src.ModLoader; + +@Mod(name = "GuiAPI", modid = "GuiAPI", version = "0.15.5 - DEBUG", acceptedMinecraftVersions = "1.5.1") +public class GuiAPI implements ITickHandler { + + Object cacheCheck = null; + Field controlListField; + + @Init + public void init(FMLInitializationEvent event) { + + try + { + controlListField = GuiScreen.class.getDeclaredField(ObfuscationReflectionHelper + .remapFieldNames("net.minecraft.client.gui.GuiScreen", "buttonList")[0]); + controlListField.setAccessible(true); + } + catch(Throwable e) + { + try + { + controlListField = GuiScreen.class.getDeclaredField("buttonList"); + controlListField.setAccessible(true); + } + catch(Throwable e2) + { + try { + Field[] fields = GuiScreen.class.getDeclaredFields(); + for (int i = 0; i < fields.length; i++) { + if (fields[i].getType() == List.class) { + controlListField = fields[i]; + controlListField.setAccessible(true); + break; + } + } + if (controlListField == null) { + throw new Exception("No fields found on GuiScreen (" + + GuiScreen.class.getSimpleName() + + ") of type List! This should never happen!"); + } + } catch (Throwable e3) { + throw new RuntimeException( + "Unable to get Field reference for GuiScreen.controlList!", + e3); + } + } + + } + + + TickRegistry.registerTickHandler(this, Side.CLIENT); + } + + public List getControlList(GuiOptions gui) { + try { + return (List) controlListField.get(gui); + } catch (Throwable e) { + return null; // This should really print something, but it should + // never (ever) fire. + } + } + + public void processGuiOptions(GuiOptions gui) { + List controlList = getControlList(gui); + if (controlList == null) { + return; + } + if (controlList.get(0) == cacheCheck) { + // Cached so we don't have to check this every frame + return; + } + + // I hacked this out so it just sticks it between touchscreen mode and difficulty. I'm so sorry. + + // First get a list of buttons + ArrayList buttonsPreSorted = new ArrayList(); + for (Object guiButton : controlList) { + if (guiButton instanceof GuiSmallButton) + buttonsPreSorted.add((GuiSmallButton) guiButton); + } + + + + int xPos = -1; // difficulty + int yPos = -1; // touchscreen mode + for (GuiSmallButton guiButton : buttonsPreSorted) { + if(guiButton.returnEnumOptions() == EnumOptions.DIFFICULTY) + { + xPos = guiButton.xPosition; + } + + if(guiButton.returnEnumOptions() == EnumOptions.TOUCHSCREEN) + { + yPos = guiButton.yPosition; + } + } + + + controlList.add(new GuiApiButton(300, xPos, yPos, 150, 20, + "Global Mod Options")); + + // set the cache! + cacheCheck = controlList.get(0); + } + + @Override + public void tickStart(EnumSet type, Object... tickData) { + if (!type.contains(TickType.RENDER)) { + return; + } + if (Minecraft.getMinecraft() == null) { + return; // what + } + if (Minecraft.getMinecraft().currentScreen == null) { + return; + } + if (Minecraft.getMinecraft().currentScreen instanceof GuiOptions) { + processGuiOptions((GuiOptions) Minecraft.getMinecraft().currentScreen); + } + } + + @Override + public void tickEnd(EnumSet type, Object... tickData) { + + } + + @Override + public EnumSet ticks() { + return EnumSet.of(TickType.RENDER); + } + + @Override + public String getLabel() { + return "GuiAPI main menu checker"; + } +} diff --git a/mcp/sharose/mods/guiapi/GuiAPIDummyCoreMod.java b/mcp/sharose/mods/guiapi/GuiAPIDummyCoreMod.java new file mode 100644 index 0000000..eb8bf94 --- /dev/null +++ b/mcp/sharose/mods/guiapi/GuiAPIDummyCoreMod.java @@ -0,0 +1,32 @@ +package sharose.mods.guiapi; + +import java.util.Map; + +import cpw.mods.fml.relauncher.IFMLLoadingPlugin; + +@IFMLLoadingPlugin.MCVersion("1.5.1") +public class GuiAPIDummyCoreMod implements IFMLLoadingPlugin { + @Override + public String[] getLibraryRequestClass() { + return null; + } + + @Override + public String[] getASMTransformerClass() { + return null; + } + + @Override + public String getModContainerClass() { + return null; + } + + @Override + public String getSetupClass() { + return null; + } + + @Override + public void injectData(Map data) { + } +} diff --git a/mcp/sharose/mods/guiapi/GuiApiButton.java b/mcp/sharose/mods/guiapi/GuiApiButton.java new file mode 100644 index 0000000..38d61e7 --- /dev/null +++ b/mcp/sharose/mods/guiapi/GuiApiButton.java @@ -0,0 +1,26 @@ +package sharose.mods.guiapi; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; + +public class GuiApiButton extends GuiButton { + + public GuiApiButton(int par1, int par2, int par3, int par4, int par5, + String par6Str) { + super(par1, par2, par3, par4, par5, par6Str); + } + + @Override + public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) + { + if(super.mousePressed(par1Minecraft, par2, par3)) + { + par1Minecraft.gameSettings.saveOptions(); + ModSettingScreen.guiContext = ""; + WidgetSetting.updateAll(); + GuiModScreen.show(new GuiModSelect(par1Minecraft.currentScreen)); + return true; + } + return false; + } +} diff --git a/mcp/sharose/mods/guiapi/GuiApiFontHelper.java b/mcp/sharose/mods/guiapi/GuiApiFontHelper.java new file mode 100644 index 0000000..7b7e4a1 --- /dev/null +++ b/mcp/sharose/mods/guiapi/GuiApiFontHelper.java @@ -0,0 +1,257 @@ +package sharose.mods.guiapi; + +import java.util.HashMap; +import java.util.Map; + +import de.matthiasmann.twl.Color; +import de.matthiasmann.twl.EditField; +import de.matthiasmann.twl.TextWidget; +import de.matthiasmann.twl.Widget; +import de.matthiasmann.twl.renderer.AnimationStateString; +import de.matthiasmann.twl.renderer.lwjgl.LWJGLFont; + +/** + * This class is designed to enable you to make clones of the GuiAPI font, + * colour it and add options as you want, and then set that font to specific + * kinds of widgets. + * + * @author ShaRose + * + */ +public class GuiApiFontHelper { + /** + * These are the font states you can use for your settings. Most of the + * time, the only ones you will use would be normal and hover. + * + * @author ShaRose + * + */ + public enum FontStates { + disabled, error, hover, normal, textSelection, warning + } + + private static Map customFontWidgets; + private static Map stateTable; + static { + GuiApiFontHelper.customFontWidgets = new HashMap(); + try { + GuiApiFontHelper.stateTable = new HashMap(); + FontStates[] states = FontStates.values(); + for (int i = 0; i < states.length; i++) { + GuiApiFontHelper.stateTable.put(states[i], + new AnimationStateString(states[i].name())); + } + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + + /** + * This method is used internally to resync the font references. This has to + * be used each time the theme is applied (After you set the screen, + * specifically), otherwise TWL will automatically replace it with the + * default font. + */ + public static void resyncCustomFonts() { + for (Map.Entry entry : GuiApiFontHelper.customFontWidgets + .entrySet()) { + // probably going to want to optimize this I think + GuiApiFontHelper font = entry.getValue(); + Widget widget = entry.getKey(); + if (widget instanceof TextWidget) { + font.setFont((TextWidget) widget); + } + if (widget instanceof EditField) { + font.setFont((EditField) widget); + } + if (widget instanceof WidgetText) { + font.setFont((WidgetText) widget); + } + } + } + + private LWJGLFont myFont; + + /** + * This creates a new GuiApiFontHelper with it's own internal font + * reference. + */ + public GuiApiFontHelper() { + GuiWidgetScreen widgetScreen = GuiWidgetScreen.getInstance(); + LWJGLFont baseFont = (LWJGLFont) widgetScreen.theme.getDefaultFont(); + myFont = baseFont.clone(); + } + + /** + * @param state + * The font state you want to check. + * @return The Color for this font according to the specified state. + */ + public Color getColor(FontStates state) { + return myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .getColor(); + } + + /** + * @param state + * The font state you want to check. + * @return The LineThrough for this font according to the specified state. + */ + public boolean getLineThrough(FontStates state) { + return myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .getLineThrough(); + } + + /** + * @param state + * The font state you want to check. + * @return The OffsetX for this font according to the specified state. + */ + public int getOffsetX(FontStates state) { + return myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .getOffsetX(); + } + + /** + * @param state + * The font state you want to check. + * @return The OffsetY for this font according to the specified state. + */ + public int getOffsetY(FontStates state) { + return myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .getOffsetY(); + } + + /** + * @param state + * The font state you want to check. + * @return The Underline for this font according to the specified state. + */ + public boolean getUnderline(FontStates state) { + return myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .getUnderline(); + } + + /** + * @param state + * The font state you want to check. + * @return The UnderlineOffset for this font according to the specified + * state. + */ + public int getUnderlineOffset(FontStates state) { + return myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .getUnderlineOffset(); + } + + /** + * @param state + * The font state you want to set. + * @param col + * The Color you wish to this fontstate to have for this font. + */ + public void setColor(FontStates state, Color col) { + myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)).setColor( + col); + GuiApiFontHelper.resyncCustomFonts(); + } + + /** + * @param widget + * The EditField (Or derived class) you wish to set. + */ + public void setFont(EditField widget) { + try { + setFont(widget.textRenderer); + GuiApiFontHelper.customFontWidgets.put(widget, this); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + /** + * @param widget + * The TextWidget (Or derived class) you wish to set. + */ + public void setFont(TextWidget widget) { + widget.setFont(myFont); + GuiApiFontHelper.customFontWidgets.put(widget, this); + } + + /** + * @param widget + * The WidgetText (Or derived class) you wish to set. This will + * set the display label (if it has one) and the edit field. + */ + public void setFont(WidgetText widget) { + if (widget.displayLabel != null) { + widget.displayLabel.setFont(myFont); + GuiApiFontHelper.customFontWidgets.put(widget, this); + } + setFont(widget.editField); + GuiApiFontHelper.customFontWidgets.put(widget, this); + } + + /** + * @param state + * The font state you want to set. + * @param val + * The LineThrough you wish to this fontstate to have for this + * font. + */ + public void setLineThrough(FontStates state, boolean val) { + myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .setLineThrough(val); + GuiApiFontHelper.resyncCustomFonts(); + } + + /** + * @param state + * The font state you want to set. + * @param i + * The OffsetX you wish to this fontstate to have for this font. + */ + public void setOffsetX(FontStates state, int i) { + myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .setOffsetX(i); + GuiApiFontHelper.resyncCustomFonts(); + } + + /** + * @param state + * The font state you want to set. + * @param i + * The OffsetY you wish to this fontstate to have for this font. + */ + public void setOffsetY(FontStates state, int i) { + myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .setOffsetY(i); + GuiApiFontHelper.resyncCustomFonts(); + } + + /** + * @param state + * The font state you want to set. + * @param val + * The Underline you wish to this fontstate to have for this + * font. + */ + public void setUnderline(FontStates state, boolean val) { + myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .setUnderline(val); + GuiApiFontHelper.resyncCustomFonts(); + } + + /** + * @param state + * The font state you want to set. + * @param i + * The UnderlineOffset you wish to this fontstate to have for + * this font. + */ + public void setUnderlineOffset(FontStates state, int i) { + myFont.evalFontState(GuiApiFontHelper.stateTable.get(state)) + .setUnderlineOffset(i); + GuiApiFontHelper.resyncCustomFonts(); + } + +} diff --git a/mcp/sharose/mods/guiapi/GuiApiHelper.java b/mcp/sharose/mods/guiapi/GuiApiHelper.java new file mode 100644 index 0000000..6fef51a --- /dev/null +++ b/mcp/sharose/mods/guiapi/GuiApiHelper.java @@ -0,0 +1,368 @@ +package sharose.mods.guiapi; + +import java.util.AbstractMap; +import java.util.ArrayList; + +import de.matthiasmann.twl.Button; +import de.matthiasmann.twl.TextArea; +import de.matthiasmann.twl.Widget; +import de.matthiasmann.twl.model.SimpleButtonModel; +import de.matthiasmann.twl.textarea.HTMLTextAreaModel; +import de.matthiasmann.twl.textarea.SimpleTextAreaModel; +import de.matthiasmann.twl.textarea.TextAreaModel; + +/** + * This is just a class for helping ease common and somewhat long operations + * with GuiAPI. + * + * @author ShaRose + */ +public class GuiApiHelper { + /** + * This is a static ModAction to go back to the previous menu. + */ + public final static ModAction backModAction; + /** + * This is a static ModAction to play the 'click' sound you usually hear + * when pressing a button in minecraft. + */ + public final static ModAction clickModAction; + + static { + backModAction = new ModAction(GuiModScreen.class, "back"); + GuiApiHelper.backModAction.setTag("Helper Back ModAction"); + clickModAction = new ModAction(GuiModScreen.class, "clicksound"); + GuiApiHelper.clickModAction.setTag("Helper ClickSound ModAction"); + } + + /** + * This method is one of the overloads to create a choice menu, so the user + * is presented a textbox and user configurable buttons beneath it. This + * overload is the most advanced option, though uses more code. Call this + * method, use the returned GuiApiHelper instance to add the buttons you + * want, then generate the widget. + * + * @param displayText + * The text to be displayed to the user. + * @return An instance of GuiApiHelper. Use the addButton methods to add + * buttons to the menu, and then when you are done use genWidget to + * create the choice menu. + */ + public static GuiApiHelper createChoiceMenu(String displayText) { + return new GuiApiHelper(displayText); + } + + /** + * This method is one of the overloads to create a choice menu, so the user + * is presented a textbox and user configurable buttons beneath it. This + * overload uses variable arguments to choose it. + * + * @param displayText + * The text to display. + * @param showBackButton + * Whether to automatically show a 'back' button or not. + * @param autoBack + * Whether to automatically merge a 'back' ModAction with the + * buttons. + * @param args + * The button information. Enter it in the form of String (Name + * on the button), ModAction (The ModAction to call when the + * button is pressed). + * @return The generated widget. Use GuiModScreen.show to display it. + */ + public static Widget createChoiceMenu(String displayText, + Boolean showBackButton, Boolean autoBack, Object... args) { + if ((args.length % 2) == 1) { + throw new IllegalArgumentException( + "Arguments not in correct format. You need to have an even number of arguments, in the form of String, ModAction for each button."); + } + GuiApiHelper helper = new GuiApiHelper(displayText); + try { + for (int i = 0; i < args.length; i += 2) { + helper.addButton((String) args[i], (ModAction) args[i + 1], + autoBack); + } + } catch (Throwable e) { + throw new IllegalArgumentException( + "Arguments not in correct format. You need to have an even number of arguments, in the form of String, ModAction for each button.", + e); + } + return helper.genWidget(showBackButton); + } + + /** + * This method is one of the overloads to create a choice menu, so the user + * is presented a textbox and user configurable buttons beneath it. This + * overload uses two tables that match up to create the buttons. + * + * @param displayText + * The text to display. + * @param showBackButton + * Whether to automatically show a 'back' button or not. + * @param autoBack + * Whether to automatically merge a 'back' ModAction with the + * buttons. + * @param buttonTexts + * The text for the buttons you want to show. + * @param buttonActions + * The corresponding ModActions for the buttons. + * @return The generated widget. Use GuiModScreen.show to display it. + */ + public static Widget createChoiceMenu(String displayText, + Boolean showBackButton, Boolean autoBack, String[] buttonTexts, + ModAction[] buttonActions) { + if (buttonTexts.length != buttonActions.length) { + throw new IllegalArgumentException( + "Arguments not in correct format. buttonTexts needs to be the same size as buttonActions."); + } + GuiApiHelper helper = new GuiApiHelper(displayText); + for (int i = 0; i < buttonTexts.length; i += 2) { + helper.addButton(buttonTexts[i], buttonActions[i], autoBack); + } + return helper.genWidget(showBackButton); + } + + /** + * This method creates a button widget for you. + * + * @param displayText + * The text to display on the button. + * @param action + * The ModAction to call when clicked. + * @param addClick + * Set this to true and it will automatically play the Click + * sound. + * @return The new Button widget. + */ + public static Button makeButton(String displayText, ModAction action, + Boolean addClick) { + SimpleButtonModel simplebuttonmodel = new SimpleButtonModel(); + if (addClick) { + action = action.mergeAction(GuiApiHelper.clickModAction); + } + simplebuttonmodel.addActionCallback(action); + Button button = new Button(simplebuttonmodel); + button.setText(displayText); + return button; + } + + /** + * This method creates a button widget for you. + * + * @param displayText + * The text to display on the button. + * @param methodName + * The name of the method to call when clicked. + * @param me + * The Object or Class that has the method you want to call. + * @param addClick + * Set this to true and it will automatically play the Click + * sound. + * @return The new Button widget. + */ + public static Button makeButton(String displayText, String methodName, + Object me, Boolean addClick) { + return GuiApiHelper.makeButton(displayText, new ModAction(me, + methodName), addClick); + } + + /** + * This method creates a button widget for you. + * + * @param displayText + * The text to display on the button. + * @param methodName + * The name of the method to call when clicked. + * @param me + * The Object or Class that has the method you want to call. + * @param addClick + * Set this to true and it will automatically play the Click + * sound. + * @param classes + * The argument classes for the method you want to call. + * @param arguments + * The defaulted arguments you want to use. + * @return The new Button widget. + */ + @SuppressWarnings("rawtypes") + public static Button makeButton(String displayText, String methodName, + Object me, Boolean addClick, Class[] classes, Object... arguments) { + return GuiApiHelper.makeButton(displayText, new ModAction(me, + methodName, classes).setDefaultArguments(arguments), addClick); + } + + /** + * This is a small helper to create TextAreas, which is basically a label + * that wraps text. + * + * @param text + * The text to show. + * @param htmlMode + * Whether to create the Textbox to render HTML, or standard + * text. + * @return The TextArea widget. + */ + public static TextArea makeTextArea(String text, Boolean htmlMode) { + if (!htmlMode) { + SimpleTextAreaModel model = new SimpleTextAreaModel(); + model.setText(text, false); + return new TextArea(model); + } + HTMLTextAreaModel model = new HTMLTextAreaModel(); + model.setHtml(text); + return new TextArea(model); + } + + /** + * This method is designed to provide an easy way to make popups or + * information notices. + * + * @param titleText + * This is the text for the title on top of the display. If you + * set this to null, it will simply not have a top bar. + * @param displayText + * This is the text to be displayed below the title bar (If there + * is one). + * @param buttonText + * This is the text you want the back button to have. Something + * like 'OK' or 'Back' is what you usually use. + * @param htmlMode + * This is if you want the text to be rendered as if it were + * HTML. + * @return The generated widget. Use GuiModScreen.show to display it. + */ + public static Widget makeTextDisplayAndGoBack(String titleText, + String displayText, String buttonText, Boolean htmlMode) { + WidgetSinglecolumn widget = new WidgetSinglecolumn(new Widget[0]); + widget.add(GuiApiHelper.makeTextArea(displayText, htmlMode)); + widget.overrideHeight = false; + WidgetSimplewindow window = new WidgetSimplewindow(widget, titleText); + window.backButton.setText(buttonText); + return window; + } + + /** + * This is a small helper method to set the text of a TextArea. It supposed + * Simple and HTML TextAreas. + * + * @param textArea + * The TextArea you wish to set the text of. + * @param text + * The text to set. + */ + public static void setTextAreaText(TextArea textArea, String text) { + TextAreaModel model = textArea.getModel(); + if (model instanceof SimpleTextAreaModel) { + ((SimpleTextAreaModel) model).setText(text, false); + } else { + ((HTMLTextAreaModel) model).setHtml(text); + } + } + + /** The button info. */ + private ArrayList> buttonInfo_; + + /** The display text. */ + private String displayText_; + + /** + * Instantiates a new gui api helper. + * + * @param displayText + * the display text + */ + private GuiApiHelper(String displayText) { + displayText_ = displayText; + buttonInfo_ = new ArrayList>(); + } + + /** + * This method adds a button to the choice menu. The arguments are the same + * as the related makeButton method. + * + * @param text + * The text for the button. + * @param action + * The action to use when pressed. + * @param mergeBack + * Whether or not to automatically to back after the button is + * pressed. + */ + public void addButton(String text, ModAction action, Boolean mergeBack) { + ModAction buttonAction = action; + if (mergeBack) { + buttonAction = buttonAction.mergeAction(GuiApiHelper.backModAction); + buttonAction.setTag("Button '" + text + "' with back."); + } + buttonInfo_.add(new AbstractMap.SimpleEntry(text, + buttonAction)); + } + + /** + * This method adds a button to the choice menu. The arguments are the same + * as the related makeButton method. + * + * @param text + * The text for the button. + * @param methodName + * The method to call. + * @param me + * The object or class with the method you wish to call. + * @param mergeBack + * Whether or not to automatically to back after the button is + * pressed. + */ + public void addButton(String text, String methodName, Object me, + Boolean mergeBack) { + addButton(text, new ModAction(me, methodName), mergeBack); + } + + /** + * This method adds a button to the choice menu. The arguments are the same + * as the related makeButton method. + * + * @param text + * The text for the button. + * @param methodName + * The method to call. + * @param me + * The object or class with the method you wish to call. + * @param types + * The types of the arguments required for the method. + * @param mergeBack + * Whether or not to automatically to back after the button is + * pressed. + * @param arguments + * The arguments you wish to use when this button is pressed. + */ + @SuppressWarnings("rawtypes") + public void addButton(String text, String methodName, Object me, + Class[] types, Boolean mergeBack, Object... arguments) { + addButton(text, + new ModAction(me, methodName, types) + .setDefaultArguments(arguments), mergeBack); + } + + /** + * This creates the Choice Menu from the Display Text entered earlier and + * the buttons you have added. + * + * @param showBackButton + * If true, show a bar on the bottom with a button to go back to + * the previous menu. If false, don't. + * @return The generated widget. Use GuiModScreen.show to display it. + */ + public WidgetSimplewindow genWidget(Boolean showBackButton) { + WidgetSinglecolumn widget = new WidgetSinglecolumn(new Widget[0]); + TextArea textarea = GuiApiHelper.makeTextArea(displayText_, false); + widget.add(textarea); + widget.heightOverrideExceptions.put(textarea, 0); + for (AbstractMap.SimpleEntry entry : buttonInfo_) { + widget.add(GuiApiHelper.makeButton(entry.getKey(), + entry.getValue(), true)); + } + WidgetSimplewindow window = new WidgetSimplewindow(widget, null, + showBackButton); + return window; + } +} diff --git a/mcp/sharose/mods/guiapi/GuiModScreen.java b/mcp/sharose/mods/guiapi/GuiModScreen.java new file mode 100644 index 0000000..273e426 --- /dev/null +++ b/mcp/sharose/mods/guiapi/GuiModScreen.java @@ -0,0 +1,161 @@ +package sharose.mods.guiapi; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import de.matthiasmann.twl.Widget; +import de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer; +import de.matthiasmann.twl.renderer.lwjgl.RenderScale; + +/** + * GuiModScreen is the minecraft screen subclass that controls and renders TWL. + * normally you will want to call it's static methods to use it, though + * subclassing it and/or instantiating it are also possible. however, to do so + * would use unsafe api (I still might change things.) + * + * @author lahwran + * + * @see GuiModScreen#show(GuiModScreen) + * @see GuiModScreen#show(Widget) + */ +public class GuiModScreen extends GuiScreen { + /** + * Used by static methods. Is the currently displayed screen. + */ + public static GuiModScreen currentScreen; + + /** + * Hide current screen and show parent screen. + */ + public static void back() { + if (GuiModScreen.currentScreen != null) { + Minecraft m = ModSettings.getMcinst(); + m.displayGuiScreen(GuiModScreen.currentScreen.parentScreen); + if (GuiModScreen.currentScreen.parentScreen instanceof GuiModScreen) { + GuiModScreen.currentScreen = (GuiModScreen) GuiModScreen.currentScreen.parentScreen; + GuiModScreen.currentScreen.setActive(); + } else { + GuiModScreen.currentScreen = null; + } + } + } + + /** + * Play a click sound. Call after the user performs an action. Already + * called from setting widgets. + */ + public static void clicksound() { + Minecraft m = ModSettings.getMcinst(); + m.sndManager.playSoundFX("random.click", 1.0F, 1.0F); + } + + /** + * Show a screen - GuiModScreen version. Show an instance of GuiModScreen - + * Does not set the parent screen, you have to deal with that yourself! + * + * @param screen + * GuiModScreen instance or subclass to show with parent screen + * already set to current screen. + */ + public static void show(GuiModScreen screen) { + Minecraft m = ModSettings.getMcinst(); + m.displayGuiScreen(screen); + screen.setActive(); + } + + /** + * Show a screen - TWL widget version. This is the recommended way to show a + * TWL widget as a screen. + * + * @param screen + * widget to show - will be sized to size of screen when twl was + * started. + */ + public static void show(Widget screen) { + GuiModScreen.show(new GuiModScreen(GuiModScreen.currentScreen, screen)); + } + + /** + * The type of background to draw. 0 is the default background. If you are + * in game, it will shade the screen grey before it draws your widget, like + * when you pause the game normally. If you are not in game, it will show + * the dirt background, like on the main menu. 1 is force the main menu + * (dirt) background. Anything else is no background, completely clear. + */ + public int backgroundType = 0; + /** + * Actual main widget of this GuiModScreen + */ + public Widget mainwidget; + /** + * Reference to parent screen, is used by GuiModScreen#back() + * + * @see GuiModScreen#back() + */ + public GuiScreen parentScreen; + + /** + * Only use this constructor from subclasses. does not take a widget, so + * that the subclass can build the widget before storing it. put your main + * widget in mainwidget, of course. + * + * @param screen + * parent screen + * + * @see GuiModScreen#back() + */ + protected GuiModScreen(GuiScreen screen) { + parentScreen = screen; + GuiModScreen.currentScreen = this; + allowUserInput = false; + } + + /** + * main constructor, to be used if you are instantiating this class. + * + * @param screen + * parent screen - make sure this is right! + * @param widget + * main widget to display + */ + public GuiModScreen(GuiScreen screen, Widget widget) { + mainwidget = widget; + parentScreen = screen; + GuiModScreen.currentScreen = this; + allowUserInput = false; + } + + @Override + public void drawScreen(int var1, int var2, float var3) { + switch (backgroundType) { + case 0: { + drawDefaultBackground(); + break; + } + case 1: { + drawBackground(0); + break; + } + default: { + break; + } + } + LWJGLRenderer var4 = (LWJGLRenderer) GuiWidgetScreen.getInstance().gui + .getRenderer(); + ScaledResolution var5 = new ScaledResolution( + GuiWidgetScreen.getInstance().minecraftInstance.gameSettings, + GuiWidgetScreen.getInstance().minecraftInstance.displayWidth, + GuiWidgetScreen.getInstance().minecraftInstance.displayHeight); + RenderScale.scale = var5.getScaleFactor(); + var4.syncViewportSize(); + GuiWidgetScreen.getInstance().gui.update(); + } + + @Override + public void handleInput() { + } + + private void setActive() { + GuiWidgetScreen.getInstance().setScreen(mainwidget); + } +} diff --git a/mcp/sharose/mods/guiapi/GuiModSelect.java b/mcp/sharose/mods/guiapi/GuiModSelect.java new file mode 100644 index 0000000..c4aecb0 --- /dev/null +++ b/mcp/sharose/mods/guiapi/GuiModSelect.java @@ -0,0 +1,41 @@ +package sharose.mods.guiapi; + +import net.minecraft.client.gui.GuiScreen; + +/** + * This is a Subclass of GuiModScreen, and acts as the entry point from the + * button in the options menu. This is just used internally. It is also where + * the code to enable MLProps edting is. + * + * @author lahwran + * @author ShaRose + */ +public class GuiModSelect extends GuiModScreen { + static { + + } + + @SuppressWarnings("unused") + private static void selectScreen(Integer i) { + GuiModScreen.show(ModSettingScreen.modScreens.get(i).theWidget); + GuiModScreen.clicksound(); + } + + protected GuiModSelect(GuiScreen screen) { + super(screen); + WidgetClassicTwocolumn w = new WidgetClassicTwocolumn(); + w.verticalPadding = 10; + for (int i = 0; i < ModSettingScreen.modScreens.size(); i++) { + ModSettingScreen m = ModSettingScreen.modScreens.get(i); + w.add(GuiApiHelper + .makeButton(m.buttonTitle, "selectScreen", + GuiModSelect.class, false, + new Class[] { Integer.class }, i)); + } + WidgetSimplewindow mainwidget = new WidgetSimplewindow(w, + "Select a Mod"); + mainwidget.hPadding = 0; + mainwidget.mainWidget.setTheme("scrollpane-notch"); + this.mainwidget = mainwidget; + } +} diff --git a/mcp/sharose/mods/guiapi/GuiWidgetScreen.java b/mcp/sharose/mods/guiapi/GuiWidgetScreen.java new file mode 100644 index 0000000..6716b72 --- /dev/null +++ b/mcp/sharose/mods/guiapi/GuiWidgetScreen.java @@ -0,0 +1,169 @@ +package sharose.mods.guiapi; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; + +import org.lwjgl.opengl.Util; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import de.matthiasmann.twl.GUI; +import de.matthiasmann.twl.Widget; +import de.matthiasmann.twl.input.lwjgl.LWJGLInput; +import de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer; +import de.matthiasmann.twl.theme.ThemeManager; + +/** + * TWL Widget that switches out child widgets. the Minecraft gui end and twl + * rendering is managed from GuiModScreen. + * + * @author lahwran + */ +public class GuiWidgetScreen extends Widget { + /** + * The initialized instance of GuiWidgetScreen. + */ + public static GuiWidgetScreen instance; + /** + * The height of the screen that the widget will render on. + */ + public static int screenheight; + /** + * The width of the screen that the widget will render on. + */ + public static int screenwidth; + + public static URL themeURL; + + /** + * get the instance of GuiWidget, creating it if needed + * + * @return GuiWidgetScreen singleton + */ + public static GuiWidgetScreen getInstance() { + if (GuiWidgetScreen.instance != null) { + return GuiWidgetScreen.instance; + } + + try { + Util.checkGLError(); + GuiWidgetScreen.instance = new GuiWidgetScreen(); + Util.checkGLError(); + GuiWidgetScreen.instance.renderer = new LWJGLRenderer(); + Util.checkGLError(); + String themename = "twlGuiTheme.xml"; + Util.checkGLError(); + GuiWidgetScreen.instance.gui = new GUI(GuiWidgetScreen.instance, + GuiWidgetScreen.instance.renderer, new LWJGLInput()); + Util.checkGLError(); + GuiWidgetScreen.themeURL = new URL("classloader","",-1,themename,new URLStreamHandler(){ + @Override + protected URLConnection openConnection(URL paramURL) throws IOException { + String file = paramURL.getFile(); + if(file.startsWith("/")) { file = file.substring(1); } + return GuiWidgetScreen.class.getClassLoader().getResource(file).openConnection(); + } + }); + Util.checkGLError(); + //GuiWidgetScreen.themeURL = new URL("file:\\G:\\MineCraft\\GitHub\\GuiAPI\\theme\\twlGuiTheme.xml"); + Util.checkGLError(); + GuiWidgetScreen.instance.theme = ThemeManager + .createThemeManager(GuiWidgetScreen.themeURL, + GuiWidgetScreen.instance.renderer); + Util.checkGLError(); + if (GuiWidgetScreen.instance.theme == null) { + throw new RuntimeException( + "I don't think you installed the theme correctly ..."); + } + GuiWidgetScreen.instance.setTheme(""); + GuiWidgetScreen.instance.gui + .applyTheme(GuiWidgetScreen.instance.theme); + GuiWidgetScreen.instance.minecraftInstance = ModSettings + .getMcinst(); + GuiWidgetScreen.instance.screenSize = new ScaledResolution( + GuiWidgetScreen.instance.minecraftInstance.gameSettings, + GuiWidgetScreen.instance.minecraftInstance.displayWidth, + GuiWidgetScreen.instance.minecraftInstance.displayHeight); + } catch (Throwable e) { + e.printStackTrace(); + RuntimeException e2 = new RuntimeException("error loading theme"); + e2.initCause(e); + throw e2; + } + return GuiWidgetScreen.instance; + } + + /** + * The widget that is currently displayed. + */ + public Widget currentWidget = null; + /** + * This is a reference to a TWL class that is used to render the widgets. + */ + public GUI gui = null; + /** + * This is a reference to Minecraft. + */ + public Minecraft minecraftInstance; + /** + * This is the rendered used by TWL. + */ + public LWJGLRenderer renderer = null; + /** + * This is the ScaledResolution class that is used to scale all of the + * widgets. + */ + public ScaledResolution screenSize = null; + /** + * This the the ThemeManager for GuiAPI. + */ + public ThemeManager theme = null; + + /** + * This creates a new instance of GuiWidgetScreen. It should only be used + * internally. Please use the static method getInstance() instead. + */ + public GuiWidgetScreen() { + } + + @Override + public void layout() { + screenSize = new ScaledResolution(minecraftInstance.gameSettings, + minecraftInstance.displayWidth, minecraftInstance.displayHeight); + if (currentWidget != null) { + GuiWidgetScreen.screenwidth = screenSize.getScaledWidth(); + GuiWidgetScreen.screenheight = screenSize.getScaledHeight(); + currentWidget.setSize(GuiWidgetScreen.screenwidth, + GuiWidgetScreen.screenheight); + currentWidget.setPosition(0, 0); + } + } + + /** + * Removes all children and clears the current widget. + */ + public void resetScreen() { + removeAllChildren(); + currentWidget = null; + } + + /** + * to be called only from GuiModScreen, sets the widget to display. + * GuiModScreen manages this. + * + * @param widget + * widget to display + */ + public void setScreen(Widget widget) { + gui.resyncTimerAfterPause(); + gui.clearKeyboardState(); + gui.clearMouseState(); + removeAllChildren(); + add(widget); + GuiApiFontHelper.resyncCustomFonts(); + + currentWidget = widget; + } +} diff --git a/mcp/sharose/mods/guiapi/IWidgetAlwaysDraw.java b/mcp/sharose/mods/guiapi/IWidgetAlwaysDraw.java new file mode 100644 index 0000000..d7ffdc4 --- /dev/null +++ b/mcp/sharose/mods/guiapi/IWidgetAlwaysDraw.java @@ -0,0 +1,5 @@ +package sharose.mods.guiapi; + +public interface IWidgetAlwaysDraw { + +} diff --git a/mcp/sharose/mods/guiapi/ModAction.java b/mcp/sharose/mods/guiapi/ModAction.java new file mode 100644 index 0000000..fe3c4ae --- /dev/null +++ b/mcp/sharose/mods/guiapi/ModAction.java @@ -0,0 +1,304 @@ +package sharose.mods.guiapi; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Method; +import java.security.InvalidParameterException; +import java.util.ArrayList; + +import de.matthiasmann.twl.CallbackWithReason; +import de.matthiasmann.twl.ListBox; +import de.matthiasmann.twl.ListBox.CallbackReason; +import de.matthiasmann.twl.TextArea; + +/** + * This class is a helper designed to make it easier to use callbacks. It + * implements Runnable and PropertyChangeListener, and you can use it in several + * ways. + * + * @author _303 + * @author ShaRose + */ +@SuppressWarnings("rawtypes") +public class ModAction implements Runnable, PropertyChangeListener, + TextArea.Callback, CallbackWithReason { + @SuppressWarnings("unchecked") + private static Boolean checkArguments(Class[] classTypes, Object[] arguments) { + if (classTypes.length != arguments.length) { + return false; + } + for (int i = 0; i < classTypes.length; i++) { + if (!classTypes[i].isAssignableFrom(arguments[i].getClass())) { + return false; + } + } + return true; + } + + private Object[] defaultArguments; + + private ArrayList mergedActions = new ArrayList(); + private String methodName; + private Class[] methodParams = new Class[0]; + private Object objectRef; + private Object tag; + + /** + * This is the most common ModAction constructor. You simply specify what + * has the method you want, and the method's name and (Optionally) the + * parameters. + * + * @param o + * The object reference or class that contains the method you + * wish to call. + * @param method + * The name of the method you wish to call. + * @param params + * The parameters of the method you wish to call. + */ + public ModAction(Object o, String method, Class... params) { + setTag(method); + methodParams = params; + setupHandler(o, method); + } + + /** + * This is an overload to allow the nameRef string. + * + * @param o + * The object reference or class that contains the method you + * wish to call. + * @param method + * The name of the method you wish to call. + * @param name + * The name of this ModAction. Something else you can use to keep + * track, and this is included within exceptions. + * @param params + * The parameters of the method you wish to call. + */ + public ModAction(Object o, String method, String name, Class... params) { + this(o, method, params); + setTag(name); + } + + /** + * This is a constructor that is only supposed to be used internally. It + * sets no actual handler, only a name. + * + * @param name + * The name to use for this ModAction. + */ + private ModAction(String name) { + setTag(name); + } + + /** + * Call this ModAction and any Merged actions with the provided arguments. + * If the arguments do not match it will try using the default arguments, if + * they exist. If not, it will throw an exception. + * + * @param args + * The arguments to try and call for the ModAction (And any + * merged ModActions) + * @return The return values for each ModAction. + * @throws Exception + * Any exception thrown when the ModAction attempts to run. + */ + public Object[] call(Object... args) throws Exception { + try { + if (mergedActions.isEmpty()) { + return new Object[] { callInternal(args) }; + } + Object[] returnvals = new Object[mergedActions.size()]; + for (int i = 0; i < returnvals.length; i++) { + returnvals[i] = mergedActions.get(i).call(args); + } + return returnvals; + } catch (Exception e) { + e.printStackTrace(); + throw new Exception("error calling callback '" + getTag() + "'.", e); + } + } + + @Override + public void callback(CallbackReason reason) { + if ((methodParams.length != 1) + || (methodParams[0] != CallbackReason.class)) { + throw new RuntimeException( + "invalid method parameters for a CallbackWithReason callback. Modaction is '" + + getTag() + "'."); + } + try { + call(reason); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException( + "Error when calling CallbackWithReason callback. Modaction is '" + + getTag() + "'.", e); + } + } + + private Object callInternal(Object... args) throws Exception { + if (!ModAction.checkArguments(methodParams, args)) { + if (defaultArguments != null) { + args = defaultArguments; + } + } + try { + Method meth = getMethodRecursively(objectRef, methodName); + return meth.invoke(objectRef instanceof Class ? null : objectRef, + args); + } catch (Exception e) { + throw new Exception("error calling callback '" + getTag() + "'.", e); + } + } + + private Method getMethodRecursively(Object o, String method) + throws Exception { + Class currentclass = (o instanceof Class ? (Class) o : o + .getClass()); + while (true) { + if (currentclass == null) { + throw new Exception( + "Unable to locate method '" + + method + + "' anywhere in the inheritance chain of object '" + + (o instanceof Class ? (Class) o : o + .getClass()).getName() + "'!"); + } + try { + Method returnval = currentclass.getDeclaredMethod(method, + methodParams); + if (returnval != null) { + returnval.setAccessible(true); + return returnval; + } + } catch (Throwable x) { + } + currentclass = currentclass.getSuperclass(); + } + } + + /** + * @return The tag of this ModAction. + */ + public Object getTag() { + return tag; + } + + @Override + public void handleLinkClicked(String link) { + if ((methodParams.length != 1) || (methodParams[0] != String.class)) { + throw new RuntimeException( + "invalid method parameters for a TextArea.Callback callback. Modaction is '" + + getTag() + "'."); + } + try { + call(link); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException( + "Error when calling TextArea.Callback callback. Modaction is '" + + getTag() + "'.", e); + } + } + + /** + * Merge[s] newAction[s] with this action. + * + * @param newActions + * The new Action[s] to merge with. + * @return The Merged ModAction. + */ + public ModAction mergeAction(ModAction... newActions) { + if (mergedActions.isEmpty()) { + ModAction merged = new ModAction("Merged ModAction"); + merged.mergedActions.add(this); + for (ModAction modAction : newActions) { + merged.mergedActions.add(modAction); + } + + return merged; + } + for (ModAction modAction : newActions) { + mergedActions.add(modAction); + } + return this; + } + + @Override + public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent) { + if ((methodParams.length != 1) + || (methodParams[0] != PropertyChangeEvent.class)) { + throw new RuntimeException( + "invalid method parameters for a PropertyChangeListener callback. Modaction is '" + + getTag() + "'."); + } + try { + call(paramPropertyChangeEvent); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException( + "Error when calling PropertyChangeListener callback. Modaction is '" + + getTag() + "'.", e); + } + } + + @Override + public void run() { + try { + call(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException( + "Error when calling Runnable callback. Modaction is '" + + getTag() + "'.", e); + } + } + + /** + * Set the arguments to use if no or invalid arguments are provided. Throws + * InvalidParameterException if the arguments provided do not match the + * method parameters, or are not assignable to those types. + * + * @param Arguments + * The arguments to try and call. + * @return this + */ + public ModAction setDefaultArguments(Object... Arguments) { + if (!ModAction.checkArguments(methodParams, Arguments)) { + throw new InvalidParameterException( + "Arguments do not match the parameters."); + } + defaultArguments = Arguments; + return this; + } + + /** + * Sets the tag of this ModAction. Used for tracking, and is included with + * exceptions. + * + * @param tag + * The tag to assign to this ModAction. + */ + public void setTag(Object tag) { + this.tag = tag; + } + + private void setupHandler(Object o, String method) { + try { + getMethodRecursively(o, method); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException( + "Could not locate Method with included information.", e); + } + methodName = method; + objectRef = o; + } + + @Override + public String toString() { + return "ModAction [methodName=" + methodName + ", tag=" + tag + "]"; + } +} \ No newline at end of file diff --git a/mcp/sharose/mods/guiapi/ModSettingScreen.java b/mcp/sharose/mods/guiapi/ModSettingScreen.java new file mode 100644 index 0000000..cd98e7e --- /dev/null +++ b/mcp/sharose/mods/guiapi/ModSettingScreen.java @@ -0,0 +1,134 @@ +package sharose.mods.guiapi; + +import java.util.ArrayList; + +import de.matthiasmann.twl.Widget; + +/** + * This is the class that GuiModSelect uses to show Subscreens. Create one of + * these to create your own subscreen, from which you can add widgets to. This + * automatically registers the button on the Mod Setting Screen. + * + * @author lahwran + */ +public class ModSettingScreen { + /** + * The current context. + */ + public static String guiContext = ""; + /** + * The list of currently registered ModScreens. + */ + public static ArrayList modScreens = new ArrayList(); + /** + * title to show on button to this modscreen + */ + public String buttonTitle; + /** + * name to show at top of screen + */ + public String niceName; + /** + * the main widget to pass into GuiModScreen.show() + */ + public Widget theWidget; + /** + * the column widget to show the child widgets in + */ + public WidgetClassicTwocolumn widgetColumn; + + /** + * convenience constructor for when you want to show the same name on the + * button and screen title + * + * @param name + * mod nice name + */ + public ModSettingScreen(String name) { + this(name, name); + } + + /** + * The main Constructor for ModSettingScreen. Creates a WidgetSimplewindow + * as the main Widget, sets the title for said WidgetSimplewindow, and + * registers this ModSettingScreen on the settings screen. + * + * @param nicename + * The title that will be on the WidgetSimplewindow. + * @param buttontitle + * button-to-screen title + */ + public ModSettingScreen(String nicename, String buttontitle) { + ModSettingScreen.modScreens.add(this); + buttonTitle = buttontitle; + niceName = nicename; + widgetColumn = new WidgetClassicTwocolumn(); + theWidget = new WidgetSimplewindow(widgetColumn, niceName); + } + + /** + * An alternate Constructor for ModSettingScreen. Instead of creating a + * WidgetSimplewindow, this simply lets you pass a widget of your choosing. + * + * @param widget + * The main widget you want to use for this ModSettingScreen. + * @param buttontitle + * button-to-screen title + */ + public ModSettingScreen(Widget widget, String buttontitle) { + ModSettingScreen.modScreens.add(this); + buttonTitle = buttontitle; + theWidget = widget; + } + + /** + * Add a widget + * + * @param newwidget + * the widget to add + */ + public void append(Widget newwidget) { + if (widgetColumn != null) { + widgetColumn.add(newwidget); + } else { + theWidget.add(newwidget); + } + } + + /** + * Remove a widget + * + * @param child + * widget to remove + */ + public void remove(Widget child) { + if (widgetColumn != null) { + widgetColumn.removeChild(child); + } else { + theWidget.removeChild(child); + } + } + + /** + * Changes the widgetColumn to or from WidgetClassicTwocolumn or + * WidgetSinglecolumn. + * + * @param value + * What to change it to. True for WidgetSinglecolumn, False for + * WidgetClassicTwocolumn. + */ + public void setSingleColumn(Boolean value) { + Boolean isSingle = WidgetSinglecolumn.class.isInstance(widgetColumn); + if (isSingle == value) { + return; + } + WidgetClassicTwocolumn w2 = (value ? new WidgetSinglecolumn() + : new WidgetClassicTwocolumn()); + for (int i = 0; i < widgetColumn.getNumChildren(); i++) { + w2.add(widgetColumn.getChild(i)); + } + widgetColumn = w2; + theWidget = new WidgetSimplewindow(widgetColumn, + ((WidgetSimplewindow) theWidget).titleWidget.getText()); + } +} diff --git a/mcp/sharose/mods/guiapi/ModSettings.java b/mcp/sharose/mods/guiapi/ModSettings.java new file mode 100644 index 0000000..e9808c1 --- /dev/null +++ b/mcp/sharose/mods/guiapi/ModSettings.java @@ -0,0 +1,1022 @@ +package sharose.mods.guiapi; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.security.InvalidParameterException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Properties; + +import net.minecraft.client.Minecraft; +import de.matthiasmann.twl.Widget; + +/** + * Main interface class for Settings API + * + * @author lahwran + */ +public class ModSettings { + /** + * A list of all ModSettings instances. + */ + public static ArrayList all = new ArrayList(); + /** + * A map of context names and the directories they save to. + */ + public static HashMap contextDatadirs; + /** + * The current context. + */ + public static String currentContext; + /** + * Debug mode flag. Should always be false. + */ + public static final boolean debug = false; + + static { + ModSettings.contextDatadirs = new HashMap(); + ModSettings.currentContext = ""; + ModSettings.contextDatadirs.put("", "mods"); + } + + /** + * Debug printer. This prints to System.out, and only works when in debug + * mode. + * + * @param s + * The string to output. + */ + public static void dbgout(String s) { + if (ModSettings.debug) { + System.out.println(s); + } + } + + /** + * Returns, and creates if needed, an application directory. + * + * @param app + * The name of the application. + * @return A File reference to the directory created. + */ + public static File getAppDir(String app) { + try { + return new File(Minecraft.getMinecraftDir(), app) + .getCanonicalFile(); // Attempt to clean it up a bit. + } catch (IOException e) { + // If it can't be cleaned for whatever reason, just return the + // 'unclean' path. Normally I would just add throws, but that might + // break other mods. + return new File(Minecraft.getMinecraftDir(), app); + } + } + + /** + * This finds and returns a Minecraft instance. It caches it if it has + * already been located. + * + * @return The minecraft instance. + */ + public static Minecraft getMcinst() { + return Minecraft.getMinecraft(); + } + + /** + * Loads all saved settings for a specific context. + * + * @param context + * The context to load from. + */ + public static void loadAll(String context) { + for (int i = 0; i < ModSettings.all.size(); i++) { + ModSettings.all.get(i).load(context); + } + } + + /** + * Sets the context for mods. This means you can specify a context on a per + * world / per server basis, or anything else you would prefer. This will + * carry thoughout all mods. + * + * @param name + * The name reference of the context. + * @param location + * The location that this context stores and loads data from. + */ + public static void setContext(String name, String location) { + if (name != null) { + ModSettings.contextDatadirs.put(name, location); + ModSettings.currentContext = name; + if (!name.equals("")) { + ModSettings.loadAll(ModSettings.currentContext); + } + } else { + ModSettings.currentContext = ""; + } + } + + /** + * Mod name as used in .minecraft/mods/${modbackendname}/ + */ + public String backendname; + /** + * all registered settings for this mod + */ + @SuppressWarnings("rawtypes") + public ArrayList Settings; + /** + * Whether or not Settings have been loaded for this mod. + */ + public boolean settingsLoaded = false; + + /** + * @param modbackendname + * used to initialize class modbackendname field + */ + @SuppressWarnings("rawtypes") + public ModSettings(String modbackendname) { + backendname = modbackendname; + Settings = new ArrayList(); + ModSettings.all.add(this); + } + + /** + * convenience boolean setting adder + */ + public SettingBoolean addSetting(ModSettingScreen screen, String nicename, + String backendname, boolean value) { + SettingBoolean s = new SettingBoolean(backendname, value); + WidgetBoolean w = new WidgetBoolean(s, nicename); + screen.append(w); + append(s); + return s; + } + + /** + * convenience boolean setting adder + */ + public SettingBoolean addSetting(ModSettingScreen screen, String nicename, + String backendname, boolean value, String truestring, + String falsestring) { + SettingBoolean s = new SettingBoolean(backendname, value); + WidgetBoolean w = new WidgetBoolean(s, nicename, truestring, + falsestring); + screen.append(w); + append(s); + return s; + } + + /** + * convenience float setting adder + */ + public SettingFloat addSetting(ModSettingScreen screen, String nicename, + String backendname, float value) { + SettingFloat s = new SettingFloat(backendname, value); + WidgetFloat w = new WidgetFloat(s, nicename); + screen.append(w); + append(s); + return s; + } + + /** + * convenience float setting adder + */ + public SettingFloat addSetting(ModSettingScreen screen, String nicename, + String backendname, float value, float min, float step, float max) { + SettingFloat s = new SettingFloat(backendname, value, min, step, max); + WidgetFloat w = new WidgetFloat(s, nicename); + screen.append(w); + append(s); + return s; + } + + /** + * convenience key setting adder + */ + public SettingKey addSetting(ModSettingScreen screen, String nicename, + String backendname, int value) { + SettingKey s = new SettingKey(backendname, value); + WidgetKeybinding w = new WidgetKeybinding(s, nicename); + screen.append(w); + append(s); + return s; + } + + /** + * convenience int setting adder + */ + public SettingInt addSetting(ModSettingScreen screen, String nicename, + String backendname, int value, int min, int max) { + SettingInt s = new SettingInt(backendname, value, min, 1, max); + WidgetInt w = new WidgetInt(s, nicename); + screen.append(w); + append(s); + return s; + } + + /** + * convenience int setting adder + */ + public SettingInt addSetting(ModSettingScreen screen, String nicename, + String backendname, int value, int min, int step, int max) { + SettingInt s = new SettingInt(backendname, value, min, step, max); + WidgetInt w = new WidgetInt(s, nicename); + screen.append(w); + append(s); + return s; + } + + /** + * convenience multi setting adder + */ + public SettingMulti addSetting(ModSettingScreen screen, String nicename, + String backendname, int value, String... labels) { + SettingMulti s = new SettingMulti(backendname, value, labels); + WidgetMulti w = new WidgetMulti(s, nicename); + screen.append(w); + append(s); + return s; + } + + /** + * convenience text setting adder + */ + public SettingText addSetting(ModSettingScreen screen, String nicename, + String backendname, String value) { + SettingText s = new SettingText(backendname, value); + WidgetText w = new WidgetText(s, nicename); + screen.append(w); + append(s); + return s; + } + + /** + * convenience boolean setting adder + */ + public SettingBoolean addSetting(Widget w2, String nicename, + String backendname, boolean value) { + SettingBoolean s = new SettingBoolean(backendname, value); + WidgetBoolean w = new WidgetBoolean(s, nicename); + w2.add(w); + append(s); + return s; + } + + /** + * convenience boolean setting adder + */ + public SettingBoolean addSetting(Widget w2, String nicename, + String backendname, boolean value, String truestring, + String falsestring) { + SettingBoolean s = new SettingBoolean(backendname, value); + WidgetBoolean w = new WidgetBoolean(s, nicename, truestring, + falsestring); + w2.add(w); + append(s); + return s; + } + + /** + * convenience float setting adder + */ + public SettingFloat addSetting(Widget w2, String nicename, + String backendname, float value) { + SettingFloat s = new SettingFloat(backendname, value); + WidgetFloat w = new WidgetFloat(s, nicename); + w2.add(w); + append(s); + return s; + } + + /** + * convenience float setting adder + */ + public SettingFloat addSetting(Widget w2, String nicename, + String backendname, float value, float min, float step, float max) { + SettingFloat s = new SettingFloat(backendname, value, min, step, max); + WidgetFloat w = new WidgetFloat(s, nicename); + w2.add(w); + append(s); + return s; + } + + /** + * convenience key setting adder + */ + public SettingKey addSetting(Widget w2, String nicename, + String backendname, int value) { + SettingKey s = new SettingKey(backendname, value); + WidgetKeybinding w = new WidgetKeybinding(s, nicename); + w2.add(w); + append(s); + return s; + } + + /** + * convenience int setting adder + */ + public SettingInt addSetting(Widget w2, String nicename, + String backendname, int value, int min, int max) { + SettingInt s = new SettingInt(backendname, value, min, 1, max); + WidgetInt w = new WidgetInt(s, nicename); + w2.add(w); + append(s); + return s; + } + + /** + * convenience int setting adder + */ + public SettingInt addSetting(Widget w2, String nicename, + String backendname, int value, int min, int step, int max) { + SettingInt s = new SettingInt(backendname, value, min, step, max); + WidgetInt w = new WidgetInt(s, nicename); + w2.add(w); + append(s); + return s; + } + + /** + * convenience multi setting adder + */ + public SettingMulti addSetting(Widget w2, String nicename, + String backendname, int value, String... labels) { + SettingMulti s = new SettingMulti(backendname, value, labels); + WidgetMulti w = new WidgetMulti(s, nicename); + w2.add(w); + append(s); + return s; + } + + /** + * convenience list setting adder + */ + public SettingList addSetting(Widget w2, String nicename, + String backendname, String... options) { + + ArrayList arrayList = new ArrayList(); + + for (int i = 0; i < options.length; i++) { + arrayList.add(options[i]); + } + + SettingList s = new SettingList(backendname, arrayList); + WidgetList w = new WidgetList(s, nicename); + w2.add(w); + append(s); + return s; + } + + /** + * convenience text setting adder + */ + public SettingText addSetting(Widget w2, String nicename, + String backendname, String value) { + SettingText s = new SettingText(backendname, value); + WidgetText w = new WidgetText(s, nicename); + w2.add(w); + append(s); + return s; + } + + /** + * add a setting to be saved. + * + * @param s + * setting to add - sets s.parent as well, don't add a setting to + * more than one modsettings + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void append(Setting s) { + Settings.add(s); + s.parent = this; + } + + /** + * Copies the saved settings from one context to another. + * + * @param src + * The source context from which to copy. + * @param dest + * The destination context to save to. + */ + public void copyContextAll(String src, String dest) { + for (int i = 0; i < Settings.size(); i++) { + Settings.get(i).copyContext(src, dest); + } + } + + /** + * Get a list of all Boolean settings for the current context. + * + * @return The list of settings. + */ + public ArrayList getAllBooleanSettings() { + return getAllBooleanSettings(ModSettings.currentContext); + } + + /** + * Get a list of all Boolean settings for the specified context. + * + * @param context + * The context from which to copy from. + * @return The list of settings. + */ + @SuppressWarnings("rawtypes") + public ArrayList getAllBooleanSettings(String context) { + ArrayList settings = new ArrayList(); + for (Setting setting : Settings) { + if (!SettingBoolean.class.isAssignableFrom(setting.getClass())) { + continue; + } + settings.add((SettingBoolean) setting); + } + return settings; + } + + /** + * Get a list of all Float settings for the current context. + * + * @return The list of settings. + */ + public ArrayList getAllFloatSettings() { + return getAllFloatSettings(ModSettings.currentContext); + } + + /** + * Get a list of all Float settings for the specified context. + * + * @param context + * The context from which to copy from. + * @return The list of settings. + */ + @SuppressWarnings("rawtypes") + public ArrayList getAllFloatSettings(String context) { + ArrayList settings = new ArrayList(); + for (Setting setting : Settings) { + if (!SettingFloat.class.isAssignableFrom(setting.getClass())) { + continue; + } + settings.add((SettingFloat) setting); + } + return settings; + } + + /** + * Get a list of all Int settings for the current context. + * + * @return The list of settings. + */ + public ArrayList getAllIntSettings() { + return getAllIntSettings(ModSettings.currentContext); + } + + /** + * Get a list of all Int settings for the specified context. + * + * @param context + * The context from which to copy from. + * @return The list of settings. + */ + @SuppressWarnings("rawtypes") + public ArrayList getAllIntSettings(String context) { + ArrayList settings = new ArrayList(); + for (Setting setting : Settings) { + if (!SettingInt.class.isAssignableFrom(setting.getClass())) { + continue; + } + settings.add((SettingInt) setting); + } + return settings; + } + + /** + * Get a list of all Key settings for the current context. + * + * @return The list of settings. + */ + public ArrayList getAllKeySettings() { + return getAllKeySettings(ModSettings.currentContext); + } + + /** + * Get a list of all Key settings for the specified context. + * + * @param context + * The context from which to copy from. + * @return The list of settings. + */ + @SuppressWarnings("rawtypes") + public ArrayList getAllKeySettings(String context) { + ArrayList settings = new ArrayList(); + for (Setting setting : Settings) { + if (!SettingKey.class.isAssignableFrom(setting.getClass())) { + continue; + } + settings.add((SettingKey) setting); + } + return settings; + } + + /** + * Get a list of all Multi settings for the current context. + * + * @return The list of settings. + */ + public ArrayList getAllMultiSettings() { + return getAllMultiSettings(ModSettings.currentContext); + } + + /** + * Get a list of all Multi settings for the specified context. + * + * @param context + * The context from which to copy from. + * @return The list of settings. + */ + @SuppressWarnings("rawtypes") + public ArrayList getAllMultiSettings(String context) { + ArrayList settings = new ArrayList(); + for (Setting setting : Settings) { + if (!SettingMulti.class.isAssignableFrom(setting.getClass())) { + continue; + } + settings.add((SettingMulti) setting); + } + return settings; + } + + /** + * Get a list of all Text settings for the current context. + * + * @return The list of settings. + */ + public ArrayList getAllTextSettings() { + return getAllTextSettings(ModSettings.currentContext); + } + + /** + * Get a list of all Text settings for the specified context. + * + * @param context + * The context from which to copy from. + * @return The list of settings. + */ + @SuppressWarnings("rawtypes") + public ArrayList getAllTextSettings(String context) { + ArrayList settings = new ArrayList(); + for (Setting setting : Settings) { + if (!SettingText.class.isAssignableFrom(setting.getClass())) { + continue; + } + settings.add((SettingText) setting); + } + return settings; + } + + /** + * Gets the value of a setting by backend name from the current context. + * + * @param backendName + * The backend name of the setting. + * @return The boolean value. + */ + public Boolean getBooleanSettingValue(String backendName) { + return getBooleanSettingValue(backendName, ModSettings.currentContext); + } + + /** + * Gets the value of a setting by backend name from the specified context. + * + * @param backendName + * The backend name of the setting. + * @param context + * The context from which to copy from. + * @return The boolean value. + */ + @SuppressWarnings("rawtypes") + public Boolean getBooleanSettingValue(String backendName, String context) { + return getSettingBoolean(backendName).get(context); + } + + /** + * Gets the value of a setting by backend name from the current context. + * + * @param backendName + * The backend name of the setting. + * @return The Float value. + */ + public Float getFloatSettingValue(String backendName) { + return getFloatSettingValue(backendName, ModSettings.currentContext); + } + + /** + * Gets the value of a setting by backend name from the specified context. + * + * @param backendName + * The backend name of the setting. + * @param context + * The context from which to copy from. + * @return The Float value. + */ + @SuppressWarnings("rawtypes") + public Float getFloatSettingValue(String backendName, String context) { + return getSettingFloat(backendName).get(context); + } + + /** + * Gets the value of a setting by backend name from the current context. + * + * @param backendName + * The backend name of the setting. + * @return The Int value. + */ + public Integer getIntSettingValue(String backendName) { + return getIntSettingValue(backendName, ModSettings.currentContext); + } + + /** + * Gets the value of a setting by backend name from the specified context. + * + * @param backendName + * The backend name of the setting. + * @param context + * The context from which to copy from. + * @return The Int value. + */ + @SuppressWarnings("rawtypes") + public Integer getIntSettingValue(String backendName, String context) { + return getSettingInt(backendName).get(context); + } + + /** + * Gets the value of a setting by backend name from the current context. + * + * @param backendName + * The backend name of the setting. + * @return The Key value. + */ + public Integer getKeySettingValue(String backendName) { + return getKeySettingValue(backendName, ModSettings.currentContext); + } + + /** + * Gets the value of a setting by backend name from the specified context. + * + * @param backendName + * The backend name of the setting. + * @param context + * The context from which to copy from. + * @return The Key value. + */ + @SuppressWarnings("rawtypes") + public Integer getKeySettingValue(String backendName, String context) { + return getSettingKey(backendName).get(context); + } + + /** + * Gets the value of a setting by backend name from the current context. + * + * @param backendName + * The backend name of the setting. + * @return The text label for the value. + */ + public String getMultiSettingLabel(String backendName) { + return getMultiSettingLabel(backendName, ModSettings.currentContext); + } + + /** + * Gets the value of a setting by backend name from the specified context. + * + * @param backendName + * The backend name of the setting. + * @param context + * The context from which to copy from. + * @return The text label for the value. + */ + @SuppressWarnings("rawtypes") + public String getMultiSettingLabel(String backendName, String context) { + SettingMulti setting = getSettingMulti(backendName); + + return setting.labelValues[setting.get(context)]; + } + + /** + * Gets the value of a setting by backend name from the current context. + * + * @param backendName + * The backend name of the setting. + * @return The Multi value. + */ + public Integer getMultiSettingValue(String backendName) { + return getMultiSettingValue(backendName, ModSettings.currentContext); + } + + /** + * Gets the value of a setting by backend name from the specified context. + * + * @param backendName + * The backend name of the setting. + * @param context + * The context from which to copy from. + * @return The Multi value. + */ + @SuppressWarnings("rawtypes") + public Integer getMultiSettingValue(String backendName, String context) { + return getSettingMulti(backendName).get(context); + } + + /** + * Gets a setting by backend name. + * + * @param backendName + * The backend name of the setting. + * @return The SettingBoolean. + */ + public SettingBoolean getSettingBoolean(String backendName) { + for (Setting setting : Settings) { + if (!SettingBoolean.class.isAssignableFrom(setting.getClass())) { + continue; + } + if (setting.backendName.equals(backendName)) { + return (SettingBoolean) setting; + } + } + throw new InvalidParameterException("SettingBoolean '" + backendName + + "' not found."); + } + + /** + * Gets a setting by backend name. + * + * @param backendName + * The backend name of the setting. + * @return The SettingFloat. + */ + public SettingFloat getSettingFloat(String backendName) { + for (Setting setting : Settings) { + if (!SettingFloat.class.isAssignableFrom(setting.getClass())) { + continue; + } + if (setting.backendName.equals(backendName)) { + return (SettingFloat) setting; + } + } + throw new InvalidParameterException("SettingFloat '" + backendName + + "' not found."); + } + + /** + * Gets a setting by backend name. + * + * @param backendName + * The backend name of the setting. + * @return The SettingInt. + */ + public SettingInt getSettingInt(String backendName) { + for (Setting setting : Settings) { + if (!SettingInt.class.isAssignableFrom(setting.getClass())) { + continue; + } + if (setting.backendName.equals(backendName)) { + return (SettingInt) setting; + } + } + throw new InvalidParameterException("SettingInt '" + backendName + + "' not found."); + } + + /** + * Gets a setting by backend name. + * + * @param backendName + * The backend name of the setting. + * @return The SettingKey. + */ + public SettingKey getSettingKey(String backendName) { + for (Setting setting : Settings) { + if (!SettingKey.class.isAssignableFrom(setting.getClass())) { + continue; + } + if (setting.backendName.equals(backendName)) { + return (SettingKey) setting; + } + } + throw new InvalidParameterException("SettingKey '" + backendName + + "' not found."); + } + + /** + * Gets a setting by backend name. + * + * @param backendName + * The backend name of the setting. + * @return The SettingList. + */ + public SettingDictionary getSettingList(String backendName) { + for (Setting setting : Settings) { + if (!SettingDictionary.class.isAssignableFrom(setting.getClass())) { + continue; + } + if (setting.backendName.equals(backendName)) { + return (SettingDictionary) setting; + } + } + throw new InvalidParameterException("SettingList '" + backendName + + "' not found."); + } + + /** + * Gets a setting by backend name. + * + * @param backendName + * The backend name of the setting. + * @return The SettingMulti. + */ + public SettingMulti getSettingMulti(String backendName) { + for (Setting setting : Settings) { + if (!SettingMulti.class.isAssignableFrom(setting.getClass())) { + continue; + } + if (setting.backendName.equals(backendName)) { + return (SettingMulti) setting; + } + } + throw new InvalidParameterException("SettingMulti '" + backendName + + "' not found."); + } + + /** + * Gets a setting by backend name. + * + * @param backendName + * The backend name of the setting. + * @return The SettingText. + */ + public SettingText getSettingText(String backendName) { + for (Setting setting : Settings) { + if (!SettingText.class.isAssignableFrom(setting.getClass())) { + continue; + } + if (setting.backendName.equals(backendName)) { + return (SettingText) setting; + } + } + throw new InvalidParameterException("SettingText '" + backendName + + "' not found."); + } + + /** + * Gets the value of a setting by backend name from the current context. + * + * @param backendName + * The backend name of the setting. + * @return The Text value. + */ + public String getTextSettingValue(String backendName) { + return getTextSettingValue(backendName, ModSettings.currentContext); + } + + /** + * Gets the value of a setting by backend name from the specified context. + * + * @param backendName + * The backend name of the setting. + * @param context + * The context from which to copy from. + * @return The Text value. + */ + @SuppressWarnings("rawtypes") + public String getTextSettingValue(String backendName, String context) { + return getSettingText(backendName).get(context); + } + + /** + * Loads the settings for the default context. + */ + public void load() { + load(""); + settingsLoaded = true; + } + + /** + * must be called after all settings are added for loading/saving to work. + * loads from .minecraft/mods/$backendname/guiconfig.properties if it + * exists. coming soon: set name of config file + * + * @param context + * The context to load from. + */ + @SuppressWarnings("rawtypes") + public void load(String context) { + for (;;) { + try { + if (ModSettings.contextDatadirs.get(context) == null) { + break; + } + File path = ModSettings.getAppDir("/" + + ModSettings.contextDatadirs.get(context) + "/" + + backendname + "/"); + if (!path.exists()) { + break; + } + File file = new File(path, "guiconfig.properties"); + if (!file.exists()) { + break; + } + Properties p = new Properties(); + p.load(new FileInputStream(file)); + for (int i = 0; i < Settings.size(); i++) { + ModSettings.dbgout("setting load"); + Setting z = Settings.get(i); + if (p.containsKey(z.backendName)) { + ModSettings.dbgout("setting " + + (String) p.get(z.backendName)); + z.fromString((String) p.get(z.backendName), context); + } + } + break; + } catch (Exception e) { + System.out.println(e); + break; + } + } + } + + /** + * removes a setting using ArrayList.remove + * + * @param s + * setting to remove + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void remove(Setting s) { + Settings.remove(s); + s.parent = null; + } + + /** + * Resets all settings for the current context. + */ + public void resetAll() { + resetAll(ModSettings.currentContext); + } + + /** + * Resets all settings for the specified context. + * + * @param context + * The context to reset. + */ + public void resetAll(String context) { + for (int i = 0; i < Settings.size(); i++) { + Settings.get(i).reset(context); + } + } + + /** + * called every time a setting is changed saves settings file to + * .minecraft/mods/$backendname/guiconfig.properties coming soon: set name + * of config file + * + * @param context + * The context to save. + */ + @SuppressWarnings("rawtypes") + public void save(String context) { + if (!settingsLoaded) { + return; + } + try { + File path = ModSettings.getAppDir("/" + + ModSettings.contextDatadirs.get(context) + "/" + + backendname + "/"); + ModSettings.dbgout("saving context " + context + " (" + + path.getAbsolutePath() + " [" + + ModSettings.contextDatadirs.get(context) + "])"); + if (!path.exists()) { + path.mkdirs(); + } + File file = new File(path, "guiconfig.properties"); + Properties p = new Properties(); + for (int i = 0; i < Settings.size(); i++) { + Setting z = Settings.get(i); + p.put(z.backendName, z.toString(context)); + } + FileOutputStream out = new FileOutputStream(file); + p.store(out, ""); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * @return number of settings registered + */ + public int size() { + return Settings.size(); + } +} diff --git a/mcp/sharose/mods/guiapi/Setting.java b/mcp/sharose/mods/guiapi/Setting.java new file mode 100644 index 0000000..a3f2db9 --- /dev/null +++ b/mcp/sharose/mods/guiapi/Setting.java @@ -0,0 +1,120 @@ +package sharose.mods.guiapi; + +import java.util.HashMap; + +import de.matthiasmann.twl.Widget; + +/** + * This is the base class for Settings. + * + * @author lahwran + * @param + * The type that this Setting will use. + */ +public abstract class Setting extends Widget { + /** + * The name used by ModSettings to save and load the setting. + */ + public String backendName; + /** + * The default value for this setting. + */ + public T defaultValue; + /** + * A reference to the Widget that displays this setting. + */ + public WidgetSetting displayWidget = null; + /** + * Reference to the ModSettings this Setting is a child of. + */ + public ModSettings parent = null; + /** + * value. do not write directly if you want things to update! + */ + public HashMap values = new HashMap(); + + /** + * This is the basic constructor for Setting. Internal use only. + */ + public Setting() { + } + + /** + * Copies a setting from the source context to the destination context. + * + * @param srccontext + * The source context to copy data from. + * @param destcontext + * The destination context you would like to save the data to. + */ + public void copyContext(String srccontext, String destcontext) { + values.put(destcontext, values.get(srccontext)); + } + + /** + * load back a string from toString() + */ + public abstract void fromString(String s, String context); + + /** + * Returns the setting for the current context. + * + * @return The setting. + */ + public T get() { + return get(ModSettings.currentContext); + } + + /** + * Returns the setting for the specified context. + * + * @param context + * The context to retrieve from. + * @return The setting. + */ + public abstract T get(String context); + + /** + * Resets this setting for the current context, saving the default and + * updating the display. + */ + public void reset() { + reset(ModSettings.currentContext); + } + + /** + * Resets this setting for the specified context, saving the default and + * updating the display. + * + * @param context + * The context to reset. + */ + public void reset(String context) { + set(defaultValue, context); + } + + /** + * Sets the value for this setting to the current context. + * + * @param v + * The value. + */ + public void set(T v) { + set(v, ModSettings.currentContext); + } + + /** + * Sets the value for this setting to the specified context. + * + * @param v + * The value. + * @param context + * The context to set. + */ + public abstract void set(T v, String context); + + /** + * return string to save, called from ModSettings.save() + */ + public abstract String toString(String context); +} \ No newline at end of file diff --git a/mcp/sharose/mods/guiapi/SettingBoolean.java b/mcp/sharose/mods/guiapi/SettingBoolean.java new file mode 100644 index 0000000..0ac422b --- /dev/null +++ b/mcp/sharose/mods/guiapi/SettingBoolean.java @@ -0,0 +1,68 @@ +package sharose.mods.guiapi; + +/** + * This is the Setting type for Booleans. + * + * @author lahwran + */ +public class SettingBoolean extends Setting { + /** + * This is the constructor for SettingBoolean. It sets the default value as + * false. + * + * @param name + * The backend name for this setting. + */ + public SettingBoolean(String name) { + this(name, false); + } + + /** + * This is the constructor for SettingBoolean. + * + * @param name + * The backend name for this setting. + * @param defValue + * The default value. + */ + public SettingBoolean(String name, Boolean defValue) { + defaultValue = defValue; + values.put("", defaultValue); + backendName = name; + } + + @Override + public void fromString(String s, String context) { + values.put(context, s.equals("true")); + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public Boolean get(String context) { + if (values.get(context) != null) { + return values.get(context); + } else if (values.get("") != null) { + return values.get(""); + } else { + return defaultValue; + } + } + + @Override + public void set(Boolean v, String context) { + values.put(context, v); + if (parent != null) { + parent.save(context); + } + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public String toString(String context) { + return (get(context) ? "true" : "false"); + } +} \ No newline at end of file diff --git a/mcp/sharose/mods/guiapi/SettingDictionary.java b/mcp/sharose/mods/guiapi/SettingDictionary.java new file mode 100644 index 0000000..a67d062 --- /dev/null +++ b/mcp/sharose/mods/guiapi/SettingDictionary.java @@ -0,0 +1,77 @@ +package sharose.mods.guiapi; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Properties; + +/** + * This is the Setting type for the Properties class. That is, a Dictionary of + * strings addressable by strings. + * + * @author ShaRose + */ +public class SettingDictionary extends Setting { + + public SettingDictionary(String title) { + this(title, new Properties()); + } + + public SettingDictionary(String title, Properties defaultvalue) { + backendName = title; + defaultValue = defaultvalue; + values.put("", defaultvalue); + } + + @Override + public void fromString(String s, String context) { + Properties prop = new Properties(); + try { + prop.loadFromXML(new ByteArrayInputStream(s.getBytes("UTF-8"))); + } catch (Throwable e) { + ModSettings.dbgout("Error reading SettingDictionary from context '" + + context + "': " + e); + } + values.put(context, prop); + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public Properties get(String context) { + if (values.get(context) != null) { + return values.get(context); + } else if (values.get("") != null) { + return values.get(""); + } else { + return defaultValue; + } + } + + @Override + public void set(Properties v, String context) { + values.put(context, v); + if (parent != null) { + parent.save(context); + } + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public String toString(String context) { + try { + Properties prop = get(context); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + prop.storeToXML(output, "GuiAPI SettingDictionary: DO NOT EDIT."); + return output.toString("UTF-8"); + } catch (IOException e) { + ModSettings.dbgout("Error writing SettingDictionary from context '" + + context + "': " + e); + return ""; + } + } + +} diff --git a/mcp/sharose/mods/guiapi/SettingFloat.java b/mcp/sharose/mods/guiapi/SettingFloat.java new file mode 100644 index 0000000..3085a08 --- /dev/null +++ b/mcp/sharose/mods/guiapi/SettingFloat.java @@ -0,0 +1,130 @@ +package sharose.mods.guiapi; + +/** + * This is the Setting type for Floats. + * + * @author lahwran + */ +public class SettingFloat extends Setting { + /** + * The maximum value. + */ + public float maximumValue; + /** + * The minimum value. + */ + public float minimumValue; + /** + * The step value. + */ + public float stepValue; + + /** + * A constructor for SettingFloat. Defaults settings to default value of 0, + * range of 0.0-1.0, and a step of 0.1. + * + * @param title + * The backend name for this setting. + */ + public SettingFloat(String title) { + this(title, 0.0f, 0.0f, 0.1f, 1.0f); + } + + /** + * A constructor for SettingFloat. Defaults settings to range of 0.0-1.0 and + * a step of 0.1. + * + * @param title + * The backend name for this setting. + * @param defValue + * The default value. + */ + public SettingFloat(String title, float defValue) { + this(title, defValue, 0.0f, 0.1f, 1.0f); + } + + /** + * A constructor for SettingFloat. Defaults settings to a step of 0.1. + * + * @param title + * The backend name for this setting. + * @param defValue + * The default value. + * @param minValue + * The minimum value. + * @param maxValue + * The maximum value. + */ + public SettingFloat(String title, float defValue, float minValue, + float maxValue) { + this(title, defValue, minValue, 0.1f, maxValue); + } + + /** + * A constructor for SettingFloat. + * + * @param title + * The backend name for this setting. + * @param defValue + * The default value. + * @param minValue + * The minimum value. + * @param stepValue + * The step value. + * @param maxValue + * The maximum value. + */ + public SettingFloat(String title, float defValue, float minValue, + float stepValue, float maxValue) { + values.put("", defValue); + defaultValue = defValue; + minimumValue = minValue; + this.stepValue = stepValue; + maximumValue = maxValue; + backendName = title; + if (minimumValue > maximumValue) { + float t = minimumValue; + minimumValue = maximumValue; + maximumValue = t; + } + } + + @Override + public void fromString(String s, String context) { + values.put(context, new Float(s)); + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public Float get(String context) { + if (values.get(context) != null) { + return values.get(context); + } else if (values.get("") != null) { + return values.get(""); + } else { + return defaultValue; + } + } + + @Override + public void set(Float v, String context) { + if (stepValue > 0) { + values.put(context, Math.round(v / stepValue) * stepValue); + } else { + values.put(context, v); + } + if (parent != null) { + parent.save(context); + } + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public String toString(String context) { + return "" + get(context); + } +} \ No newline at end of file diff --git a/mcp/sharose/mods/guiapi/SettingInt.java b/mcp/sharose/mods/guiapi/SettingInt.java new file mode 100644 index 0000000..5c64a2b --- /dev/null +++ b/mcp/sharose/mods/guiapi/SettingInt.java @@ -0,0 +1,133 @@ +package sharose.mods.guiapi; + +/** + * This is the Setting type for Ints. + * + * @author lahwran + */ +public class SettingInt extends Setting { + /** + * The maximum value. + */ + public int maximumValue; + /** + * The minimum value. + */ + public int minimumValue; + /** + * The step value. + */ + public int stepValue; + + /** + * A constructor for SettingInt. Defaults settings to default value of 0, + * range of 1-100, and a step of 1. + * + * @param title + * The backend name for this setting. + */ + public SettingInt(String title) { + this(title, 0, 0, 1, 100); + } + + /** + * A constructor for SettingInt. Defaults settings to range of 1-100, and a + * step of 1. + * + * @param title + * The backend name for this setting. + * @param defValue + * The default value. + */ + public SettingInt(String title, int defValue) { + this(title, defValue, 0, 1, 100); + } + + /** + * A constructor for SettingInt. Defaults settings to a step of 1. + * + * @param title + * The backend name for this setting. + * @param defValue + * The default value. + * @param minValue + * The minimum value. + * @param maxValue + * The maximum value. + */ + public SettingInt(String title, int defValue, int minValue, int maxValue) { + this(title, defValue, minValue, 1, maxValue); + } + + /** + * A constructor for SettingInt. + * + * @param title + * The backend name for this setting. + * @param defValue + * The default value. + * @param minValue + * The minimum value. + * @param stepValue + * The step value. + * @param maxValue + * The maximum value. + */ + public SettingInt(String title, int defValue, int minValue, int stepValue, + int maxValue) { + values.put("", defValue); + defaultValue = defValue; + minimumValue = minValue; + this.stepValue = stepValue; + maximumValue = maxValue; + backendName = title; + if (minimumValue > maximumValue) { + int t = minimumValue; + minimumValue = maximumValue; + maximumValue = t; + } + } + + @Override + public void fromString(String s, String context) { + values.put(context, new Integer(s)); + if (displayWidget != null) { + displayWidget.update(); + } + ModSettings.dbgout("fromstring " + s); + } + + @Override + public Integer get(String context) { + if (values.get(context) != null) { + return values.get(context); + } else if (values.get("") != null) { + return values.get(""); + } else { + return defaultValue; + } + } + + @Override + public void set(Integer v, String context) { + ModSettings.dbgout("set " + v); + if (stepValue > 1) { + values.put( + context, + (int) (Math.round((float) v / (float) stepValue) * (float) stepValue)); + } else { + values.put(context, v); + } + if (parent != null) { + parent.save(context); + } + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public String toString(String context) { + return "" + get(context); + } +} \ No newline at end of file diff --git a/mcp/sharose/mods/guiapi/SettingKey.java b/mcp/sharose/mods/guiapi/SettingKey.java new file mode 100644 index 0000000..20d0580 --- /dev/null +++ b/mcp/sharose/mods/guiapi/SettingKey.java @@ -0,0 +1,121 @@ +package sharose.mods.guiapi; + +import org.lwjgl.input.Keyboard; + +/** + * This is the Setting type for Keys. + * + * @author lahwran + */ +public class SettingKey extends Setting { + /** + * Constructor for SettingKey. + * + * @param title + * The backend name for this setting. + * @param key + * The key you want as default, as a int keycode. + */ + public SettingKey(String title, int key) { + defaultValue = key; + values.put("", key); + backendName = title; + } + + /** + * Constructor for SettingKey. + * + * @param title + * The backend name for this setting. + * @param key + * key The key you want as default, as a string. + */ + public SettingKey(String title, String key) { + this(title, Keyboard.getKeyIndex(key)); + } + + @Override + public void fromString(String s, String context) { + if (s.equals("UNBOUND")) { + values.put(context, Keyboard.KEY_NONE); + } else { + values.put(context, Keyboard.getKeyIndex(s)); + } + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public Integer get(String context) { + if (values.get(context) != null) { + return values.get(context); + } else if (values.get("") != null) { + return values.get(""); + } else { + return defaultValue; + } + } + + /** + * An easy helper to see if the current key is down. + * + * @return true if the key specified to this setting (In the current + * context) is down. + */ + public boolean isKeyDown() { + return isKeyDown(ModSettings.currentContext); + } + + /** + * An easy helper to see if the current key is down. + * + * @param context + * The context to get the key from. + * @return true if the key specified to this setting is down. + */ + public boolean isKeyDown(String context) { + if (get(context) != -1) { + return Keyboard.isKeyDown(get(context)); + } + return false; + } + + @Override + public void set(Integer v, String context) { + values.put(context, v); + if (parent != null) { + parent.save(context); + } + if (displayWidget != null) { + displayWidget.update(); + } + } + + /** + * Sets the value for this setting to the current context. + * + * @param v + * The value, as a string. + */ + public void set(String v) { + set(v, ModSettings.currentContext); + } + + /** + * Sets the value for this setting to the specified context. + * + * @param v + * The value, as a string. + * @param context + * The context to set. + */ + public void set(String v, String context) { + set(Keyboard.getKeyIndex(v), context); + } + + @Override + public String toString(String context) { + return Keyboard.getKeyName(get(context)); + } +} \ No newline at end of file diff --git a/mcp/sharose/mods/guiapi/SettingList.java b/mcp/sharose/mods/guiapi/SettingList.java new file mode 100644 index 0000000..9892063 --- /dev/null +++ b/mcp/sharose/mods/guiapi/SettingList.java @@ -0,0 +1,118 @@ +package sharose.mods.guiapi; + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.Iterator; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class SettingList extends Setting> { + + public SettingList(String title) { + this(title, new ArrayList()); + } + + public SettingList(String title, ArrayList defaultvalue) { + backendName = title; + defaultValue = defaultvalue; + values.put("", defaultvalue); + } + + @Override + public void fromString(String s, String context) { + ArrayList list = new ArrayList(); + try { + + DocumentBuilderFactory builderFact = DocumentBuilderFactory + .newInstance(); + builderFact.setIgnoringElementContentWhitespace(true); + builderFact.setValidating(true); + builderFact.setCoalescing(true); + builderFact.setIgnoringComments(true); + DocumentBuilder docBuilder = builderFact.newDocumentBuilder(); + Document doc = docBuilder.parse(s); + + Element localElement = (Element) doc.getChildNodes().item(1); + + NodeList localNodeList = localElement.getChildNodes(); + + for (int i = 0; i < localNodeList.getLength(); i++) { + String val = localNodeList.item(i).getNodeValue(); + list.add(val); + } + values.put(context, list); + if (displayWidget != null) { + displayWidget.update(); + } + } catch (Throwable e) { + + } + } + + @Override + public ArrayList get(String context) { + if (values.get(context) != null) { + return values.get(context); + } else if (values.get("") != null) { + return values.get(""); + } else { + return defaultValue; + } + } + + @Override + public void set(ArrayList v, String context) { + values.put(context, v); + if (parent != null) { + parent.save(context); + } + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public String toString(String context) { + try { + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance() + .newDocumentBuilder(); + Document doc = docBuilder.newDocument(); + Element baseElement = (Element) doc.appendChild(doc + .createElement("list")); + ArrayList prop = get(context); + synchronized (prop) { + Iterator localIterator = prop.iterator(); + while (localIterator.hasNext()) { + String str = localIterator.next(); + baseElement.appendChild(doc.createTextNode(str)); + } + } + + TransformerFactory localTransformerFactory = TransformerFactory + .newInstance(); + Transformer localTransformer = null; + localTransformer = localTransformerFactory.newTransformer(); + localTransformer.setOutputProperty("method", "xml"); + localTransformer.setOutputProperty("encoding", "UTF8"); + DOMSource localDOMSource = new DOMSource(doc); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + StreamResult localStreamResult = new StreamResult(output); + localTransformer.transform(localDOMSource, localStreamResult); + + return output.toString("UTF-8"); + } catch (Throwable e) { + ModSettings.dbgout("Error writing SettingList from context '" + + context + "': " + e); + return ""; + } + } +} diff --git a/mcp/sharose/mods/guiapi/SettingMulti.java b/mcp/sharose/mods/guiapi/SettingMulti.java new file mode 100644 index 0000000..699f310 --- /dev/null +++ b/mcp/sharose/mods/guiapi/SettingMulti.java @@ -0,0 +1,165 @@ +package sharose.mods.guiapi; + +/** + * This is the Setting type for Multis. + * + * @author lahwran + */ +public class SettingMulti extends Setting { + /** + * A string array of labels for the button. + */ + public String[] labelValues; + + /** + * A constructor for SettingMulti. + * + * @param title + * The backend name for this setting. + * @param defValue + * The default value for this Multi. + * @param labelValues + * The text labels you would like this multi to have. Must have + * at least one. + */ + public SettingMulti(String title, int defValue, String... labelValues) { + if (labelValues.length == 0) { + return; + } + values.put("", defValue); + defaultValue = defValue; + this.labelValues = labelValues; + backendName = title; + } + + /** + * A constructor for SettingMulti. Default value is 0, or the first label to + * be defined. + * + * @param title + * The backend name for this setting. + * @param labelValues + * The text labels you would like this multi to have. Must have + * at least one. + */ + public SettingMulti(String title, String... labelValues) { + this(title, 0, labelValues); + } + + @Override + public void fromString(String s, String context) { + int x = -1; + for (int i = 0; i < labelValues.length; i++) { + if (labelValues[i].equals(s)) { + x = i; + } + } + if (x != -1) { + values.put(context, x); + } else { + values.put(context, new Float(s).intValue()); + } + ModSettings.dbgout("fromstring multi " + s); + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public Integer get(String context) { + if (values.get(context) != null) { + return values.get(context); + } else if (values.get("") != null) { + return values.get(""); + } else { + return defaultValue; + } + } + + /** + * Helper to get the text label for the current context and value. + * + * @return The label. + */ + public String getLabel() { + return labelValues[get()]; + } + + /** + * Helper to get the text label for the specified context and value. + * + * @param context + * The context to get the value from. + * @return The label. + */ + public String getLabel(String context) { + return labelValues[get(context)]; + } + + /** + * Shifts the value forward for the current context. + */ + public void next() { + next(ModSettings.currentContext); + } + + /** + * Shifts the value forward for the specified context. + * + * @param context + * The context to change. + */ + public void next(String context) { + int tempvalue = get(context) + 1; + while (tempvalue >= labelValues.length) { + tempvalue -= labelValues.length; + } + set(tempvalue, context); + } + + @Override + public void set(Integer v, String context) { + values.put(context, v); + if (parent != null) { + parent.save(context); + } + if (displayWidget != null) { + displayWidget.update(); + } + } + + /** + * Sets the value for this setting to the current context. + * + * @param v + * The value, in the label representation. + */ + public void set(String v) { + set(v, ModSettings.currentContext); + } + + /** + * Sets the value for this setting to the specified context. + * + * @param v + * The value, in the label representation. + * @param context + * The context to set. + */ + public void set(String v, String context) { + int x = -1; + for (int i = 0; i < labelValues.length; i++) { + if (labelValues[i].equals(v)) { + x = i; + } + } + if (x != -1) { + set(x, context); + } + } + + @Override + public String toString(String context) { + return labelValues[get(context)]; + } +} \ No newline at end of file diff --git a/mcp/sharose/mods/guiapi/SettingText.java b/mcp/sharose/mods/guiapi/SettingText.java new file mode 100644 index 0000000..5d31447 --- /dev/null +++ b/mcp/sharose/mods/guiapi/SettingText.java @@ -0,0 +1,57 @@ +package sharose.mods.guiapi; + +/** + * This is the Setting type for Text. + * + * @author lahwran + */ +public class SettingText extends Setting { + /** + * A constructor for SettingText. + * + * @param title + * The backend name for this setting. + * @param defaulttext + * The default text for this Setting. + */ + public SettingText(String title, String defaulttext) { + values.put("", defaulttext); + defaultValue = defaulttext; + backendName = title; + } + + @Override + public void fromString(String s, String context) { + values.put(context, s); + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public String get(String context) { + if (values.get(context) != null) { + return values.get(context); + } else if (values.get("") != null) { + return values.get(""); + } else { + return defaultValue; + } + } + + @Override + public void set(String v, String context) { + values.put(context, v); + if (parent != null) { + parent.save(context); + } + if (displayWidget != null) { + displayWidget.update(); + } + } + + @Override + public String toString(String context) { + return get(context); + } +} \ No newline at end of file diff --git a/mcp/sharose/mods/guiapi/WidgetBoolean.java b/mcp/sharose/mods/guiapi/WidgetBoolean.java new file mode 100644 index 0000000..f79adb3 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetBoolean.java @@ -0,0 +1,118 @@ +package sharose.mods.guiapi; + +import de.matthiasmann.twl.Button; +import de.matthiasmann.twl.model.SimpleButtonModel; + +/** + * This is the Widget for boolean settings. It uses a button to display to the + * user. + * + * @author lahwran + */ +public class WidgetBoolean extends WidgetSetting implements Runnable { + /** + * The reference to the underlying Button. + */ + public Button button; + /** + * The text to display on the button when the setting is false. + */ + public String falseText; + /** + * The reference to the SettingBoolean that this WidgetBoolean uses. + */ + public SettingBoolean settingReference = null; + /** + * The text to display on the button when the setting is true. + */ + public String trueText; + + /** + * This creates a new WidgetBoolean using the SettingBoolean and String + * provided. It uses 'true' and 'false' for the text. + * + * @param setting + * The backing setting. + * @param title + * The title for this Widget. It is what will show on the button, + * asides from it's current value. + */ + public WidgetBoolean(SettingBoolean setting, String title) { + this(setting, title, "true", "false"); + } + + /** + * This creates a new WidgetBoolean using the WidgetBoolean and String + * provided, as well as setting the true and false text. + * + * @param setting + * The backing setting. + * @param title + * The title for this Widget. It is what will show on the button, + * asides from it's current value. + * @param truetext + * The text to display what the setting is true. + * @param falsetext + * The text to display what the setting is false. + */ + public WidgetBoolean(SettingBoolean setting, String title, String truetext, + String falsetext) { + super(title); + setTheme(""); + trueText = truetext; + falseText = falsetext; + SimpleButtonModel bmodel = new SimpleButtonModel(); + button = new Button(bmodel); + bmodel.addActionCallback(this); + add(button); + settingReference = setting; + settingReference.displayWidget = this; + update(); + } + + @Override + public void addCallback(Runnable paramRunnable) { + button.getModel().addActionCallback(paramRunnable); + } + + @Override + public void removeCallback(Runnable paramRunnable) { + button.getModel().removeActionCallback(paramRunnable); + } + + @Override + public void run() { + if (settingReference != null) { + settingReference.set( + !settingReference.get(ModSettingScreen.guiContext), + ModSettingScreen.guiContext); + } + update(); + GuiModScreen.clicksound(); + } + + @Override + public void update() { + button.setText(userString()); + } + + @Override + public String userString() { + if (settingReference != null) { + if (niceName.length() > 0) { + return String.format("%s: %s", niceName, settingReference + .get(ModSettingScreen.guiContext) ? trueText + : falseText); + } else { + return settingReference.get(ModSettingScreen.guiContext) ? trueText + : falseText; + } + } else { + if (niceName.length() > 0) { + return String.format("%s: %s", niceName, "no value"); + } else { + return "no value or title"; + } + } + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetClassicTwocolumn.java b/mcp/sharose/mods/guiapi/WidgetClassicTwocolumn.java new file mode 100644 index 0000000..ba20c49 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetClassicTwocolumn.java @@ -0,0 +1,267 @@ +package sharose.mods.guiapi; + +import java.util.HashMap; +import java.util.Map; + +import de.matthiasmann.twl.GUI; +import de.matthiasmann.twl.ScrollPane; +import de.matthiasmann.twl.Widget; + +/** + * This widget is designed to arrange widgets into two columns. The width and + * height is enforced, but they can be configured by the programmer. + * + * @author lahwran + * @author ShaRose + */ +public class WidgetClassicTwocolumn extends Widget { + /** + * This is the default height to enforce for widgets. + */ + public int childDefaultHeight = 20; + /** + * This is the default width to enforce for widgets. + */ + public int childDefaultWidth = 150; + /** + * This is the amount of padding to use between widgets vertically. + */ + public int defaultPadding = 4; + + protected void paintChildren(GUI gui) { + + ScrollPane pane = ScrollPane.getContainingScrollPane(this); + boolean isScrolling = pane != null; + + int minY = 0; + int maxY = 0; + if(isScrolling) + { + minY = getParent().getY(); + maxY = minY + pane.getContentAreaHeight(); + } + + for(int i=0,n=getNumChildren() ; i= minY && child.getY() <= maxY) + { + draw = true; + } + } + } + if(draw) + { + paintChild(gui, child); + } + } + } + } + + /** + * This is a map to override the heights of specific widgets. It is an + * override to overrideHeight. If you set the Integer as 0, it will use what + * the widget wants as it's height. If it is set negative, it will keep the + * positive part as the minimum size, but if the widget wants to grow it + * can. If you set anything else, it will use that height. Note that with + * TwoColumn widgets it will try and keep the height the same between two + * widgets opposite each other, so the one with the biggest height will + * override the other. + */ + public Map heightOverrideExceptions = new HashMap(); + /** + * This says whether it should override the height for all widgets. + */ + public boolean overrideHeight = true; + /** + * This is the amount of room between the two columns. + */ + public int splitDistance = 10; + /** + * This is the amount of padding to have before any widgets are positioned. + */ + public int verticalPadding = 0; + /** + * This is a map to override the width of specific widgets. It is an + * override to childWidth. If you set the Integer as 0, it will use what the + * widget wants as it's width. If it is set negative, it will keep the + * positive part as the minimum size, but if the widget wants to grow it + * can. If you set anything else, it will use that width. Note that with + * TwoColumn widgets it will try and keep the width the same between two + * widgets opposite each other, so the one with the biggest width will + * override the other. + */ + public Map widthOverrideExceptions = new HashMap(); + + /** + * This creates the WidgetClassicTwocolumn and adds the requested widgets. + * + * @param widgets + */ + public WidgetClassicTwocolumn(Widget... widgets) { + for (int i = 0; i < widgets.length; ++i) { + add(widgets[i]); + } + setTheme(""); + } + + @Override + public int getPreferredHeight() { + int totalheight = verticalPadding; + for (int i = 0; i < getNumChildren(); i += 2) { + Widget w = getChild(i); + Widget w2 = null; + if ((i + 1) != getNumChildren()) { + w2 = getChild(i + 1); + } + int height = childDefaultHeight; + if (!overrideHeight) { + height = w.getPreferredHeight(); + } + if (heightOverrideExceptions.containsKey(w)) { + Integer heightSet = heightOverrideExceptions.get(w); + if (heightSet < 1) { + height = w.getPreferredHeight(); + heightSet = -heightSet; + if ((heightSet != 0) && (heightSet > height)) { + height = heightSet; + } + } else { + height = heightSet; + } + } + if (w2 != null) { + int temp = height; + if (!overrideHeight) { + temp = w2.getPreferredHeight(); + } + if (heightOverrideExceptions.containsKey(w2)) { + Integer heightSet = heightOverrideExceptions.get(w2); + if (heightSet < 1) { + height = w.getPreferredHeight(); + heightSet = -heightSet; + if ((heightSet != 0) && (heightSet > height)) { + height = heightSet; + } + } else { + height = heightSet; + } + } + if (temp > height) { + height = temp; + } + } + totalheight += height + defaultPadding; + } + return totalheight; + } + + @Override + public int getPreferredWidth() { + return getParent().getWidth(); + } + + @Override + public void layout() { + if (getParent().getTheme().equals("scrollpane-notch")) { + verticalPadding = 10; + } + int totalheight = verticalPadding; + for (int i = 0; i < getNumChildren(); i += 2) { + Widget w = getChild(i); + Widget w2 = null; + try { + w2 = getChild(i + 1); + } catch (IndexOutOfBoundsException e) { + // do nothing, just means it's uneven. + } + int height = childDefaultHeight; + int width = childDefaultWidth; + if (!overrideHeight) { + height = w.getPreferredHeight(); + } + if (heightOverrideExceptions.containsKey(w)) { + Integer heightSet = heightOverrideExceptions.get(w); + + if (heightSet < 1) { + height = w.getPreferredHeight(); + heightSet = -heightSet; + if ((heightSet != 0) && (heightSet > height)) { + height = heightSet; + } + } else { + height = heightSet; + } + } + if (widthOverrideExceptions.containsKey(w)) { + Integer widthSet = widthOverrideExceptions.get(w); + + if (widthSet < 1) { + width = w.getPreferredWidth(); + widthSet = -widthSet; + if ((widthSet != 0) && (widthSet > width)) { + width = widthSet; + } + } else { + width = widthSet; + } + } + if (w2 != null) { + int temph = height; + int tempw = width; + if (!overrideHeight) { + temph = w2.getPreferredHeight(); + } + if (heightOverrideExceptions.containsKey(w2)) { + Integer heightSet = heightOverrideExceptions.get(w2); + if (heightSet < 1) { + height = w.getPreferredHeight(); + heightSet = -heightSet; + if ((heightSet != 0) && (heightSet > height)) { + height = heightSet; + } + } else { + height = heightSet; + } + } + if (widthOverrideExceptions.containsKey(w2)) { + Integer widthSet = widthOverrideExceptions.get(w2); + + if (widthSet < 1) { + width = w2.getPreferredWidth(); + widthSet = -widthSet; + if ((widthSet != 0) && (widthSet > width)) { + width = widthSet; + } + } else { + width = widthSet; + } + } + if (temph > height) { + height = temph; + } + if (tempw > width) { + width = tempw; + } + } + w.setSize(width, height); + w.setPosition((getX() + (getWidth() / 2)) + - (width + (splitDistance / 2)), getY() + totalheight); + if (w2 != null) { + w2.setSize(width, height); + w2.setPosition(getX() + (getWidth() / 2) + (splitDistance / 2), + getY() + totalheight); + } + totalheight += height + defaultPadding; + } + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetFloat.java b/mcp/sharose/mods/guiapi/WidgetFloat.java new file mode 100644 index 0000000..a58bb88 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetFloat.java @@ -0,0 +1,94 @@ +package sharose.mods.guiapi; + +import de.matthiasmann.twl.model.SimpleFloatModel; + +/** + * This is the Widget for Float settings. It uses a WidgetSlider to display to + * the user. + * + * @author lahwran + */ +public class WidgetFloat extends WidgetSetting implements Runnable { + /** + * The number of decimal places to display to the user. + */ + public int decimalPlaces; + /** + * The reference to the SettingInt that this WidgetInt uses. + */ + public SettingFloat settingReference; + /** + * The reference to the underlying WidgetSlider. + */ + public WidgetSlider slider; + + /** + * This creates a new WidgetInt using the SettingInt and String provided. It + * defaults the decimal places to display at 2. + * + * @param setting + * The backing setting. + * @param title + * The text that will show on the WidgetSlider. + */ + public WidgetFloat(SettingFloat setting, String title) { + this(setting, title, 2); + } + + /** + * This creates a new WidgetInt using the SettingInt and String provided, as + * well as setting how many decimal places to use. + * + * @param setting + * The backing setting. + * @param title + * The text that will show on the WidgetSlider. + */ + public WidgetFloat(SettingFloat setting, String title, int _decimalPlaces) { + super(title); + setTheme(""); + decimalPlaces = _decimalPlaces; + settingReference = setting; + settingReference.displayWidget = this; + SimpleFloatModel smodel = new SimpleFloatModel( + settingReference.minimumValue, settingReference.maximumValue, + settingReference.get()); + smodel.addCallback(this); + slider = new WidgetSlider(smodel); + if ((settingReference.stepValue > 0.0f) + && (settingReference.stepValue <= settingReference.maximumValue)) { + slider.setStepSize(settingReference.stepValue); + } + slider.setFormat(String.format("%s: %%.%df", niceName, decimalPlaces)); + add(slider); + update(); + } + + @Override + public void addCallback(Runnable paramRunnable) { + slider.getModel().addCallback(paramRunnable); + } + + @Override + public void removeCallback(Runnable paramRunnable) { + slider.getModel().removeCallback(paramRunnable); + } + + @Override + public void run() { + settingReference.set(slider.getValue(), ModSettingScreen.guiContext); + } + + @Override + public void update() { + slider.setValue(settingReference.get(ModSettingScreen.guiContext)); + slider.setMinMaxValue(settingReference.minimumValue, settingReference.maximumValue); + slider.setFormat(String.format("%s: %%.%df", niceName, decimalPlaces)); + } + + @Override + public String userString() { + String l = String.format("%02d", decimalPlaces); + return String.format("%s: %." + l + "f", niceName, settingReference); + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetInt.java b/mcp/sharose/mods/guiapi/WidgetInt.java new file mode 100644 index 0000000..3ecb282 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetInt.java @@ -0,0 +1,80 @@ +package sharose.mods.guiapi; + +import de.matthiasmann.twl.model.SimpleFloatModel; + +/** + * This is the Widget for Integer settings. It uses a WidgetSlider to display to + * the user. + * + * @author lahwran + */ +public class WidgetInt extends WidgetSetting implements Runnable { + /** + * The reference to the SettingInt that this WidgetInt uses. + */ + public SettingInt settingReference; + /** + * The reference to the underlying WidgetSlider. + */ + public WidgetSlider slider; + + /** + * This creates a new WidgetInt using the SettingInt and String provided. + * + * @param setting + * The backing setting. + * @param title + * The text that will show on the WidgetSlider. + */ + public WidgetInt(SettingInt setting, String title) { + super(title); + setTheme(""); + settingReference = setting; + settingReference.displayWidget = this; + SimpleFloatModel smodel = new SimpleFloatModel( + settingReference.minimumValue, settingReference.maximumValue, + settingReference.get()); + slider = new WidgetSlider(smodel); + slider.setFormat(String.format("%s: %%.0f", niceName)); + if ((settingReference.stepValue > 1) + && (settingReference.stepValue <= settingReference.maximumValue)) { + slider.setStepSize(settingReference.stepValue); + } + smodel.addCallback(this); + add(slider); + update(); + } + + @Override + public void addCallback(Runnable paramRunnable) { + slider.getModel().addCallback(paramRunnable); + } + + @Override + public void removeCallback(Runnable paramRunnable) { + slider.getModel().removeCallback(paramRunnable); + } + + @Override + public void run() { + ModSettings.dbgout("run " + (int) slider.getValue()); + settingReference.set((int) slider.getValue(), + ModSettingScreen.guiContext); + } + + @Override + public void update() { + slider.setValue(settingReference.get(ModSettingScreen.guiContext)); + slider.setMinMaxValue(settingReference.minimumValue, settingReference.maximumValue); + slider.setFormat(String.format("%s: %%.0f", niceName)); + ModSettings.dbgout("update " + + settingReference.get(ModSettingScreen.guiContext) + " -> " + + (int) slider.getValue()); + } + + @Override + public String userString() { + return String.format("%s: %.0d", niceName, + settingReference.get(ModSettingScreen.guiContext)); + } +} \ No newline at end of file diff --git a/mcp/sharose/mods/guiapi/WidgetItem2DRender.java b/mcp/sharose/mods/guiapi/WidgetItem2DRender.java new file mode 100644 index 0000000..b2d76de --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetItem2DRender.java @@ -0,0 +1,278 @@ +package sharose.mods.guiapi; + +import java.lang.reflect.Field; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.common.ObfuscationReflectionHelper; +import cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper; + +import de.matthiasmann.twl.GUI; +import de.matthiasmann.twl.Widget; + +/** + * This is a widget designed to render Minecraft objects. It has a MINIMUM size + * of 16X16 by default. It also (Again, by default) renders a background and + * border as per the theme for progressbars. This can be changed via setTheme, + * see mod_GuiApiTWLExamples.SetUpColouringWindow comments for details. + * + * @author ShaRose + * + */ +public class WidgetItem2DRender extends Widget { + + private static RenderItem itemRenderer = new RenderItem(); + + private ItemStack renderStack; + + private int scaleType = 0; + + /** + * This sets up the Widget to render no object (Air, specifically). + */ + public WidgetItem2DRender() { + this(0); + } + + /** + * This makes the widget render the Item that is in the slot dictated by + * renderID. Note, if that ID slot is empty it will render as if you pass 0, + * and that the damage will be 0. + * + * @param renderID + */ + public WidgetItem2DRender(int renderID) { + this(new ItemStack(renderID, 0, 0)); + } + + /** + * This makes the widget render the ItemStack passed. + * + * @param renderStack + */ + public WidgetItem2DRender(ItemStack renderStack) { + setMinSize(16, 16); + setTheme("/progressbar"); + setRenderStack(renderStack); + } + + /** + * This gets the current ID this Widget is supposed to render. + * + * @return The current ID to render. + */ + public int getRenderID() { + return renderStack == null ? 0 : renderStack.itemID; + } + + /** + * This gets the ItemStack this Widget is supposed to render. + * + * @return The current ID to render. + */ + public ItemStack getRenderStack() { + return renderStack; + } + + /** + * This returns an integer that specifies what kind of Scale type it is. + * + * @return The scale type. + */ + public int getScaleType() { + return scaleType; + } + + @Override + protected void paintWidget(GUI gui) { + + Minecraft minecraft = ModSettings.getMcinst(); + + int x = getX(); + int y = getY(); + float scalex = 1f; + float scaley = 1f; + + int maxWidth = getInnerWidth() - 4; + int maxHeight = getInnerHeight() - 4; + + int scale = getScaleType(); + + if ((scale == -1) && ((maxWidth < 16) || (maxHeight < 16))) { + scale = 0; + } + + switch (scale) { + case 0: { + // largest square + int size = 0; + if (maxWidth > maxHeight) { + size = maxHeight; + } else { + size = maxWidth; + } + + x += ((maxWidth - size) / 2); + y += ((maxHeight - size) / 2); + + scalex = size / 16f; + scaley = scalex; + x /= scalex; + y /= scaley; + break; + } + + case -1: { + // default size in middle + int size = maxWidth - 16; + x += size / 2; + + size = maxHeight - 16; + y += size / 2; + break; + } + + case 1: { + // fill / stretch + scalex = maxWidth / 16f; + scaley = maxHeight / 16f; + x /= scalex; + y /= scaley; + break; + } + default: + throw new IndexOutOfBoundsException( + "Scale Type is out of bounds! This should never happen!"); + } + + x += 2; + y += 1; + + if ((minecraft == null) || (getRenderStack() == null) + || (getRenderStack().getItem() == null)) { + // draw black or something? Maybe NULL? + return; + } + + GuiWidgetScreen screen = GuiWidgetScreen.getInstance(); + screen.renderer.pauseRendering(); + + screen.renderer.setClipRect(); + GL11.glEnable(GL11.GL_SCISSOR_TEST); + GL11.glPushMatrix(); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(32826 /* GL_RESCALE_NORMAL_EXT *//* GL_RESCALE_NORMAL_EXT */); + RenderHelper.enableStandardItemLighting(); + RenderHelper.enableGUIStandardItemLighting(); + + GL11.glScalef(scalex, scaley, 1); + + ItemStack stack = getRenderStack(); + + Tessellator.instance.isDrawing = false; + + int stackBeforeDraw = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH); + try { + + WidgetItem2DRender.itemRenderer + .renderItemIntoGUI(minecraft.fontRenderer, + minecraft.renderEngine, stack, x, y); + Tessellator.instance.isDrawing = false; + WidgetItem2DRender.itemRenderer + .renderItemOverlayIntoGUI(minecraft.fontRenderer, + minecraft.renderEngine, stack, x, y); + Tessellator.instance.isDrawing = false; + } catch (Throwable e) { + Tessellator.instance.isDrawing = false; + } + + int stackAfterDraw = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH); + + if(stackBeforeDraw != stackAfterDraw) + { + //Yes, this IS stuff to work around 'bad' mods :D + for (int i = 0; i < (stackAfterDraw - stackBeforeDraw); i++) { + GL11.glPopMatrix(); + } + } + + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(32826 /* GL_RESCALE_NORMAL_EXT *//* GL_RESCALE_NORMAL_EXT */); + + GL11.glPopMatrix(); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + screen.renderer.resumeRendering(); + } + + /** + * This sets the current ID to render. This checks bounds. ItemStack damage + * and count will stay the same. + * + * @param renderID + * The ID you want this widget to render. + */ + public void setRenderID(int renderID) { + if ((renderID >= Item.itemsList.length) || (renderID < 0)) { + throw new IndexOutOfBoundsException( + String.format( + "Render ID must be within the possible bounds of an Item ID! (%s - %s)", + 0, Item.itemsList.length - 1)); + } + if (renderStack == null) { + renderStack = new ItemStack(renderID, 0, 0); + } + renderStack.itemID = renderID; + } + + /** + * This sets the ItemStack to render. This checks bounds. + * + * @param stack + * The ItemStack you want this widget to render. Can't be null. + */ + public void setRenderStack(ItemStack stack) { + if (stack == null) { + throw new IllegalArgumentException("stack cannot be null."); + } + if ((stack.itemID >= Item.itemsList.length) || (stack.itemID < 0)) { + throw new IndexOutOfBoundsException( + String.format( + "Render ID must be within the possible bounds of an Item ID! (%s - %s)", + 0, Item.itemsList.length - 1)); + } + renderStack = stack; + } + + /** + * This sets what kind of scaling to use for this widget. Possible types + * are: + * + * -1: This doesn't scale it at all. It will be rendered right in the + * middle, at 16x16 size if possible. If it needs to be smaller, it will + * scale. + * + * 0: This is the default mode. It scales to the biggest square it can, at + * stays in the middle. + * + * 1: This scales to fill all the space, whether or not that space is + * square. + * + * @param scaleType + */ + public void setScaleType(int scaleType) { + if (scaleType > 1) { + scaleType = 1; + } + if (scaleType < -1) { + scaleType = -1; + } + this.scaleType = scaleType; + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetKeybinding.java b/mcp/sharose/mods/guiapi/WidgetKeybinding.java new file mode 100644 index 0000000..f98ded2 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetKeybinding.java @@ -0,0 +1,108 @@ +package sharose.mods.guiapi; + +import org.lwjgl.input.Keyboard; + +import de.matthiasmann.twl.Event; +import de.matthiasmann.twl.ToggleButton; +import de.matthiasmann.twl.model.SimpleBooleanModel; + +/** + * This is the Widget for Key binding settings. It uses a ToggleButton to + * display to the user. + * + * @author lahwran + */ +public class WidgetKeybinding extends WidgetSetting implements Runnable { + /** + * The reference to the underlying SimpleBooleanModel. + */ + public SimpleBooleanModel booleanModel; + /** + * The constant for clearing the existing key. + */ + public int CLEARKEY = Keyboard.KEY_DELETE; + /** + * The constant for exiting and keeping the existing key. + */ + public int NEVERMINDKEY = Keyboard.KEY_ESCAPE; + /** + * The reference to the SettingKey that this WidgetKeybinding uses. + */ + public SettingKey settingReference; + /** + * The reference to the underlying ToggleButton. + */ + public ToggleButton toggleButton; + + /** + * This creates a new WidgetKeybinding using the WidgetKeybinding and String + * provided. + * + * @param setting + * The backing setting. + * @param title + * The text that will show on the WidgetSlider. + */ + public WidgetKeybinding(SettingKey setting, String title) { + super(title); + setTheme(""); + settingReference = setting; + settingReference.displayWidget = this; + booleanModel = new SimpleBooleanModel(false); + toggleButton = new ToggleButton(booleanModel); + add(toggleButton); + update(); + } + + @Override + public void addCallback(Runnable paramRunnable) { + booleanModel.addCallback(paramRunnable); + } + + @Override + public boolean handleEvent(Event evt) { + if ((evt.isKeyEvent() && !evt.isKeyPressedEvent()) + && booleanModel.getValue()) { + System.out.println(Keyboard.getKeyName(evt.getKeyCode())); + int tmpvalue = evt.getKeyCode(); + if (tmpvalue == CLEARKEY) { + settingReference.set(Keyboard.KEY_NONE, + ModSettingScreen.guiContext); + } else if (tmpvalue != NEVERMINDKEY) { + settingReference.set(tmpvalue, ModSettingScreen.guiContext); + } + booleanModel.setValue(false); + update(); + GuiModScreen.clicksound(); + return true; + } + return false; + } + + @Override + public void keyboardFocusLost() { + GuiModScreen.clicksound(); + booleanModel.setValue(false); + } + + @Override + public void removeCallback(Runnable paramRunnable) { + booleanModel.removeCallback(paramRunnable); + } + + @Override + public void run() { + GuiModScreen.clicksound(); + } + + @Override + public void update() { + toggleButton.setText(userString()); + } + + @Override + public String userString() { + return String.format("%s: %s", niceName, Keyboard + .getKeyName(settingReference.get(ModSettingScreen.guiContext))); + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetList.java b/mcp/sharose/mods/guiapi/WidgetList.java new file mode 100644 index 0000000..c9f1b59 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetList.java @@ -0,0 +1,100 @@ +package sharose.mods.guiapi; + +import de.matthiasmann.twl.CallbackWithReason; +import de.matthiasmann.twl.Label; +import de.matthiasmann.twl.ListBox; +import de.matthiasmann.twl.ListBox.CallbackReason; +import de.matthiasmann.twl.model.SimpleChangableListModel; +import de.matthiasmann.twl.utils.CallbackSupport; + +public class WidgetList extends WidgetSetting implements + CallbackWithReason { + + private Runnable[] callbacks; + public Label displayLabel; + + /** + * The reference to the underlying WidgetSlider. + */ + public ListBox listBox; + + public SimpleChangableListModel listBoxModel; + + /** + * The reference to the SettingInt that this WidgetInt uses. + */ + public SettingList settingReference; + + public WidgetList(SettingList setting, String title) { + super(title); + setTheme(""); + settingReference = setting; + settingReference.displayWidget = this; + if (title != null) { + displayLabel = new Label(); + displayLabel.setText(niceName); + add(displayLabel); + } + + listBoxModel = new SimpleChangableListModel(setting.get()); + listBox = new ListBox(listBoxModel); + add(listBox); + listBox.addCallback(this); + update(); + } + + @Override + public void addCallback(Runnable callback) { + callbacks = (CallbackSupport.addCallbackToList(callbacks, callback, + Runnable.class)); + } + + @Override + public void callback(CallbackReason paramT) { + CallbackSupport.fireCallbacks(callbacks); + } + + @Override + public void layout() { + if (displayLabel != null) { + displayLabel.setPosition(getX(), getY()); + int offset = displayLabel.computeTextHeight(); + displayLabel.setSize(getWidth(), offset); + listBox.setPosition(getX(), getY() + offset); + listBox.setSize(getWidth(), getHeight() - offset); + } else { + listBox.setPosition(getX(), getY()); + listBox.setSize(getWidth(), getHeight()); + } + } + + @Override + public void removeCallback(Runnable callback) { + callbacks = (CallbackSupport + .removeCallbackFromList(callbacks, callback)); + } + + @Override + public void update() { + listBoxModel.clear(); + listBoxModel.addElements(settingReference.get()); + } + + @Override + public String userString() { + String output = ""; + if (niceName != null) { + output = niceName + ": "; + } + + int sel = listBox.getSelected(); + String text = sel != -1 ? listBoxModel.getEntry(sel) : "NOTHING"; + + output += String.format( + "%s (Entry %s) currently selected from %s items.", text, sel, + settingReference.get().size()); + + return output; + } + +} diff --git a/mcp/sharose/mods/guiapi/WidgetMulti.java b/mcp/sharose/mods/guiapi/WidgetMulti.java new file mode 100644 index 0000000..0537264 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetMulti.java @@ -0,0 +1,76 @@ +package sharose.mods.guiapi; + +import de.matthiasmann.twl.Button; +import de.matthiasmann.twl.model.SimpleButtonModel; + +/** + * This is the Widget for Multi settings. It uses a button to display to the + * user, and cycles the values. + * + * @author lahwran + */ +public class WidgetMulti extends WidgetSetting implements Runnable { + /** + * The reference to the underlying Button. + */ + public Button button; + /** + * The reference to the SettingMulti that this WidgetMulti uses. + */ + public SettingMulti value; + + /** + * This creates a new WidgetMulti using the SettingMulti and String + * provided. + * + * @param setting + * The backing setting. + * @param title + * The title for this Widget. It is what will show on the button, + * asides from it's current value. + */ + public WidgetMulti(SettingMulti setting, String title) { + super(title); + setTheme(""); + value = setting; + value.displayWidget = this; + SimpleButtonModel model = new SimpleButtonModel(); + button = new Button(model); + model.addActionCallback(this); + add(button); + update(); + } + + @Override + public void addCallback(Runnable paramRunnable) { + button.getModel().addActionCallback(paramRunnable); + } + + @Override + public void removeCallback(Runnable paramRunnable) { + button.getModel().removeActionCallback(paramRunnable); + } + + @Override + public void run() { + value.next(ModSettingScreen.guiContext); + update(); + GuiModScreen.clicksound(); + } + + @Override + public void update() { + button.setText(userString()); + ModSettings.dbgout("multi update " + userString()); + } + + @Override + public String userString() { + if (niceName.length() > 0) { + return String.format("%s: %s", niceName, + value.getLabel(ModSettingScreen.guiContext)); + } else { + return value.getLabel(ModSettingScreen.guiContext); + } + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetSetting.java b/mcp/sharose/mods/guiapi/WidgetSetting.java new file mode 100644 index 0000000..bb93ba8 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetSetting.java @@ -0,0 +1,94 @@ +package sharose.mods.guiapi; + +import java.util.ArrayList; + +import de.matthiasmann.twl.Widget; + +/** + * This is the base class for Widgets that are supposed to be front ends for + * Settings. + * + * @author lahwran + */ +public abstract class WidgetSetting extends Widget { + /** + * This is a list of all WidgetSetting instances. + */ + public static ArrayList all = new ArrayList(); + + /** + * This updates all Widgets with the backing setting's current values. + */ + public static void updateAll() { + for (int i = 0; i < WidgetSetting.all.size(); i++) { + WidgetSetting.all.get(i).update(); + } + } + + /** + * The name that will be shown on the widget. + */ + public String niceName; + + /** + * This sets the Nice Name and adds itself to the list of instances. Note + * this class is abstract, so you will not be using this constructor. + * + * @param nicename + * The nice name for this WidgetSetting. + */ + public WidgetSetting(String nicename) { + niceName = nicename; + WidgetSetting.all.add(this); + } + + @Override + public void add(Widget child) { + String T = child.getTheme(); + if (T.length() == 0) { + child.setTheme("/-defaults"); + } else if (!T.substring(0, 1).equals("/")) { + child.setTheme("/" + T); + } + super.add(child); + } + + /** + * This adds a callback to the displayed widget (Button, Slider, etc) + * + * @param paramRunnable + * The Runnable callback you wish to call if the value changes. + */ + public abstract void addCallback(Runnable paramRunnable); + + @Override + public void layout() { + for (int i = 0; i < getNumChildren(); i++) { + Widget w = getChild(i); + w.setPosition(getX(), getY()); + w.setSize(getWidth(), getHeight()); + } + } + + /** + * This removes a callback to the displayed widget (Button, Slider, etc) if + * you previously set one up. + * + * @param paramRunnable + * The Runnable callback you wish to remove. + */ + public abstract void removeCallback(Runnable paramRunnable); + + /** + * This method updates the widget with the backing setting store. + */ + public abstract void update(); + + /** + * This returns a clean string that shows the Nice Name and the current + * value. + * + * @return A descriptor string. + */ + public abstract String userString(); +} diff --git a/mcp/sharose/mods/guiapi/WidgetSimplewindow.java b/mcp/sharose/mods/guiapi/WidgetSimplewindow.java new file mode 100644 index 0000000..f12acb1 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetSimplewindow.java @@ -0,0 +1,160 @@ +package sharose.mods.guiapi; + +import de.matthiasmann.twl.Button; +import de.matthiasmann.twl.Label; +import de.matthiasmann.twl.ScrollPane; +import de.matthiasmann.twl.Widget; +import de.matthiasmann.twl.model.SimpleButtonModel; + +/** + * This widget is designed to make an easy base for menus. It include a + * ScrollPane for the main widget, a title bar on top, and a button to go back + * to the previous menu. + * + * @author lahwran + * @author ShaRose + */ +public class WidgetSimplewindow extends Widget { + /** + * This is a reference to the back button, if created. + */ + public Button backButton = new Button(); + /** + * This is a reference to the row at the bottom that contains the back + * button. + */ + public WidgetSingleRow buttonBar = new WidgetSingleRow(0, 0); + /** + * This is the padding to use on each side of the main widget. + */ + public int hPadding = 30; + /** + * This is a reference to the main widget in the center. + */ + public Widget mainWidget = new Widget(); + + /** + * This is a reference to the ScrollPane that the Main Widget is in. + */ + public Widget scrollPane = null; //TODO: Make this ScrollPane next release. + /** + * This is a reference to the Label that acts as the title on top. + */ + public Label titleWidget = new Label(); + /** + * This is the padding on the bottom. Generally, this is to keep room + * between the bottom of the main widget's ScrollPane and the button bar. + */ + public int vBottomPadding = 40; + /** + * This is the padding on the top. Generally, this is to keep room between + * the top of the main widget's ScrollPane and the Label. + */ + public int vTopPadding = 30; + + /** + * This is a basic constructor. It sets the title as an empty string and it + * creates a new WidgetClassicTwocolumn for the main widget. + */ + public WidgetSimplewindow() { + this(new WidgetClassicTwocolumn(), "", true); + } + + /** + * This is a basic constructor. It uses the passed widget as the main widget + * and sets the title as an empty string. + * + * @param w + * The widget to use in the center. + */ + public WidgetSimplewindow(Widget w) { + this(w, "", true); + } + + /** + * This is the most common constructor. This keeps everything default, + * although you can pass null for the title and it will remove the title bar + * for you. + * + * @param w + * The widget to use in the center. + * @param s + * The title to show on top. If null, the title bar will not be + * created. + */ + public WidgetSimplewindow(Widget w, String s) { + this(w, s, true); + } + + /** + * This is the more advanced constructor. This can also skip the back button + * creation. + * + * @param w + * The widget to use in the center. + * @param s + * The title to show on top. If null, the title bar will not be + * created. + * @param showbackButton + */ + public WidgetSimplewindow(Widget w, String s, Boolean showbackButton) { + ScrollPane scrollpane = new ScrollPane(w); + scrollpane.setFixed(ScrollPane.Fixed.HORIZONTAL); + this.scrollPane = scrollpane; + mainWidget = w; + setTheme(""); + init(showbackButton, s); + } + + /** + * Initializes the WidgetSimplewindow's widgets. This is used internally. + * + * @param showBack + * Whether or not to show the back button. + * @param titleText + * What to set the label text to. If null, it will not have a + * label. + */ + protected void init(Boolean showBack, String titleText) { + if (titleText != null) { + titleWidget = new Label(titleText); + add(titleWidget); + } else { + vTopPadding = 10; + } + if (showBack) { + backButton = new Button(new SimpleButtonModel()); + backButton.getModel().addActionCallback( + GuiApiHelper.backModAction + .mergeAction(GuiApiHelper.clickModAction)); + backButton.setText("Back"); + buttonBar = new WidgetSingleRow(200, 20, backButton); + add(buttonBar); + } else { + vBottomPadding = 0; + } + add(scrollPane); + } + + @Override + public void layout() { + if (buttonBar != null) { + buttonBar.setSize(buttonBar.getPreferredWidth(), + buttonBar.getPreferredHeight()); + buttonBar.setPosition( + (getWidth() / 2) - (buttonBar.getPreferredWidth() / 2), + getHeight() - (buttonBar.getPreferredHeight() + 4)); + } + if (titleWidget != null) { + titleWidget + .setPosition( + (getWidth() / 2) + - (titleWidget.computeTextWidth() / 2), 10); + titleWidget.setSize(titleWidget.computeTextWidth(), + titleWidget.computeTextHeight()); + } + scrollPane.setPosition(hPadding, vTopPadding); + scrollPane.setSize(getWidth() - (hPadding * 2), getHeight() + - (vTopPadding + vBottomPadding)); + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetSingleRow.java b/mcp/sharose/mods/guiapi/WidgetSingleRow.java new file mode 100644 index 0000000..336d215 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetSingleRow.java @@ -0,0 +1,137 @@ +package sharose.mods.guiapi; + +import java.util.ArrayList; + +import de.matthiasmann.twl.Widget; + +/** + * This is a layout widget designed to arrange your widgets in a row. It + * specifies height and width for each widget when you add them. + * + * @author lahwran + */ +public class WidgetSingleRow extends Widget { + /** + * This is the default height of any new widgets. + */ + public int defaultHeight = 20; + /** + * This is the default width of any new widgets. + */ + public int defaultWidth = 150; + protected ArrayList heights = new ArrayList(); + protected ArrayList widgets = new ArrayList(); + protected ArrayList widths = new ArrayList(); + /** + * This defines the space between child widgets. + */ + public int xSpacing = 3; + + /** + * This creates a new WidgetSingleRow, specifying the default width and + * height for any new widgets, as well as adding any widgets you would like + * to add. + * + * @param defwidth + * The default width to use for any new widgets. + * @param defheight + * The default height to use for any new widgets. + * @param widgets + * The widgets you are adding. + */ + public WidgetSingleRow(int defwidth, int defheight, Widget... widgets) { + setTheme(""); + defaultWidth = defwidth; + defaultHeight = defheight; + for (int i = 0; i < widgets.length; i++) { + add(widgets[i]); + } + } + + @Override + public void add(Widget widget) { + add(widget, defaultWidth, defaultHeight); + } + + /** + * This adds a new Widget with specified width and height. + * + * @param widget + * The widget you are adding. + * @param width + * The width of the widget you are adding. + * @param height + * The height of the widget you are adding. + */ + public void add(Widget widget, int width, int height) { + widgets.add(widget); + heights.add(height); + widths.add(width); + super.add(widget); + } + + private int getHeight(int idx) { + if (heights.get(idx) >= 0) { + return heights.get(idx); + } else { + return widgets.get(idx).getPreferredHeight(); + } + } + + @Override + public int getPreferredHeight() { + int maxheights = 0; + for (int i = 0; i < heights.size(); i++) { + if (getHeight(i) > maxheights) { + maxheights = getHeight(i); + } + } + return maxheights; + } + + @Override + public int getPreferredWidth() { + int totalwidth = (widths.size() - 1) * xSpacing; + totalwidth = totalwidth >= 0 ? totalwidth : 0; + for (int i = 0; i < widths.size(); i++) { + totalwidth += getWidth(i); + } + return totalwidth; + } + + private int getWidth(int idx) { + if (widths.get(idx) >= 0) { + return widths.get(idx); + } else { + return widgets.get(idx).getPreferredWidth(); + } + } + + @Override + public void layout() { + int curXpos = 0; + for (int i = 0; i < widgets.size(); i++) { + Widget w = widgets.get(i); + w.setPosition(curXpos + getX(), getY()); + w.setSize(getWidth(i), getHeight(i)); + curXpos += getWidth(i) + xSpacing; + } + } + + @Override + public Widget removeChild(int idx) { + widgets.remove(idx); + heights.remove(idx); + widths.remove(idx); + return super.removeChild(idx); + } + + @Override + public boolean removeChild(Widget widget) { + int idx = widgets.indexOf(widget); + widgets.remove(idx); + heights.remove(idx); + widths.remove(idx); + return super.removeChild(widget); + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetSinglecolumn.java b/mcp/sharose/mods/guiapi/WidgetSinglecolumn.java new file mode 100644 index 0000000..9c5408e --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetSinglecolumn.java @@ -0,0 +1,100 @@ +package sharose.mods.guiapi; + +import de.matthiasmann.twl.Widget; + +/** + * This is a widget designed to arrange other widgets into a single column. + * + * @author lahwran + * @author ShaRose + */ +public class WidgetSinglecolumn extends WidgetClassicTwocolumn { + /** + * This creates the WidgetSinglecolumn with the specified Widgets. It + * chooses a default Width of 200. + * + * @param widgets + * The widgets to add. + */ + public WidgetSinglecolumn(Widget... widgets) { + super(widgets); + childDefaultWidth = 200; + } + + @Override + public int getPreferredHeight() { + int totalheight = verticalPadding; + for (int i = 0; i < getNumChildren(); ++i) { + Widget widget = getChild(i); + int height = childDefaultHeight; + if (!overrideHeight) { + height = widget.getPreferredHeight(); + } + if (heightOverrideExceptions.containsKey(widget)) { + Integer heightSet = heightOverrideExceptions.get(widget); + if (heightSet < 1) { + height = widget.getPreferredHeight(); + heightSet = -heightSet; + if ((heightSet != 0) && (heightSet > height)) { + height = heightSet; + } + } else { + height = heightSet; + } + } + totalheight += height + defaultPadding; + } + return totalheight; + } + + @Override + public int getPreferredWidth() { + // I can't see why we do a check here and not on TwoColoumn, and I don't + // really want to loop widthOverrideExceptions, so let's just remove + // this particular check, mmkay? + // return Math.max(getParent().getWidth(), childWidth); + return getParent().getWidth(); + } + + @Override + public void layout() { + int totalheight = verticalPadding; + for (int i = 0; i < getNumChildren(); ++i) { + Widget w = getChild(i); + int height = childDefaultHeight; + int width = childDefaultWidth; + if (!overrideHeight) { + height = w.getPreferredHeight(); + } + if (heightOverrideExceptions.containsKey(w)) { + Integer heightSet = heightOverrideExceptions.get(w); + if (heightSet < 1) { + height = w.getPreferredHeight(); + heightSet = -heightSet; + if ((heightSet != 0) && (heightSet > height)) { + height = heightSet; + } + } else { + height = heightSet; + } + } + if (widthOverrideExceptions.containsKey(w)) { + Integer widthSet = widthOverrideExceptions.get(w); + + if (widthSet < 1) { + width = w.getPreferredWidth(); + widthSet = -widthSet; + if ((widthSet != 0) && (widthSet > width)) { + width = widthSet; + } + } else { + width = widthSet; + } + } + w.setSize(width, height); + w.setPosition((getX() + (getWidth() / 2)) - (width / 2), getY() + + totalheight); + totalheight += height + defaultPadding; + } + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetSlider.java b/mcp/sharose/mods/guiapi/WidgetSlider.java new file mode 100644 index 0000000..4449ff4 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetSlider.java @@ -0,0 +1,60 @@ +package sharose.mods.guiapi; + +import de.matthiasmann.twl.ValueAdjusterFloat; +import de.matthiasmann.twl.model.FloatModel; + +/** + * This is a simple extension of ValueAdjusterFloat so that it always updates + * the setting. Used internally. + * + * @author lahwran + */ +public class WidgetSlider extends ValueAdjusterFloat { + /** + * This is the basic constructor. It just calls the ValueAdjusterFloat + * constructor, as well as adding an option to allow editing the value with text. + * + * @param f + * The FloatModel to use. + */ + public WidgetSlider(FloatModel f) { + super(f); + } + + private boolean canEdit = false;; + + /** + * Specifies whether or not to allow the user to click on the Slider to enter a numberic value. + * @param value Whether or not to allow Editing. + */ + public void setCanEdit(boolean value) + { + canEdit = value; + } + + /** + * @return True if the user can edit this Slider by clicking on it: False otherwise. + */ + public boolean getCanEdit() + { + return canEdit; + } + + @Override + public void startEdit() { + if(!getCanEdit()) + { + cancelEdit(); + } + else + { + super.startEdit(); + } + } + + @Override + protected String onEditStart() + { + return Float.toString(getValue()); + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetText.java b/mcp/sharose/mods/guiapi/WidgetText.java new file mode 100644 index 0000000..8245a13 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetText.java @@ -0,0 +1,131 @@ +package sharose.mods.guiapi; + +import de.matthiasmann.twl.EditField; +import de.matthiasmann.twl.Label; +import de.matthiasmann.twl.model.StringModel; +import de.matthiasmann.twl.utils.CallbackSupport; + +/** + * This is the Widget for Text settings. It uses an EditField for the user to + * edit, and a Label for the name. + * + * @author lahwran + * @author ShaRose + */ +public class WidgetText extends WidgetSetting implements StringModel { + private Runnable[] callbacks; + /** + * The label that displays to the user what the nice name of this setting + * is. + */ + public Label displayLabel; + /** + * The EditField that the user actually changes the setting with. + */ + public EditField editField; + /** + * This is a control number to who and what can edit this setting. 0 means + * that both the SettingText and the user can edit. Below 0 means that only + * the user can edit: So resetting to default will not change the text the + * user sees. Over 0 means that the user can't edit the field, but if the + * SettingText updates, it will replace what the user sees. + */ + public int setmode = 0; + /** + * The reference to the SettingText that this WidgetText uses. + */ + public SettingText settingReference; + + /** + * This creates a new WidgetText using the SettingText and String provided. + * + * @param setting + * The backing setting. + * @param title + * The text that will show on the Label. If null, it will not + * have a label at all. + */ + public WidgetText(SettingText setting, String title) { + super(title); + setTheme(""); + settingReference = setting; + settingReference.displayWidget = this; + editField = new EditField(); + add(editField); + if (title != null) { + displayLabel = new Label(); + displayLabel.setText(String.format("%s: ", niceName)); + add(displayLabel); + } + editField.setModel(this); + update(); + } + + @Override + public void addCallback(Runnable callback) { + callbacks = (CallbackSupport.addCallbackToList(callbacks, callback, + Runnable.class)); + } + + @Override + public String getValue() { + return settingReference.get(); + } + + @Override + public void layout() { + if (displayLabel != null) { + displayLabel.setPosition(getX(), (getY() + (getHeight() / 2)) + - (displayLabel.computeTextHeight() / 2)); + displayLabel.setSize(displayLabel.computeTextWidth(), + displayLabel.computeTextHeight()); + editField.setPosition(getX() + displayLabel.computeTextWidth(), + getY()); + editField.setSize(getWidth() - displayLabel.computeTextWidth(), + getHeight()); + } else { + editField.setPosition(getX(), getY()); + editField.setSize(getWidth(), getHeight()); + } + } + + @Override + public void removeCallback(Runnable callback) { + callbacks = (CallbackSupport + .removeCallbackFromList(callbacks, callback)); + } + + @Override + public void setValue(String _value) { + GuiModScreen.clicksound(); + ModSettings.dbgout(String.format("setvalue %s", editField.getText())); + if (setmode <= 0) { + setmode = -1; + settingReference.set(editField.getText(), + ModSettingScreen.guiContext); + setmode = 0; + } + CallbackSupport.fireCallbacks(callbacks); + } + + @Override + public void update() { + ModSettings.dbgout("update"); + if (displayLabel != null) { + displayLabel.setText(String.format("%s: ", niceName)); + } + if (setmode >= 0) { + setmode = 1; + editField + .setText(settingReference.get(ModSettingScreen.guiContext)); + setmode = 0; + } + ModSettings.dbgout(String.format("update %s", editField.getText())); + } + + @Override + public String userString() { + return String.format("%s: %s", niceName, + settingReference.get(ModSettingScreen.guiContext)); + } +} diff --git a/mcp/sharose/mods/guiapi/WidgetTick.java b/mcp/sharose/mods/guiapi/WidgetTick.java new file mode 100644 index 0000000..14b12b2 --- /dev/null +++ b/mcp/sharose/mods/guiapi/WidgetTick.java @@ -0,0 +1,301 @@ +package sharose.mods.guiapi; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import de.matthiasmann.twl.GUI; +import de.matthiasmann.twl.Widget; + +/** + * This is a dummy Widget that you can use to call a Runnable object every + * frame, or every X milliseconds. You can also use it for one-off events, such + * as calling a method 5 seconds after a Widget is shown. + * + * @author ShaRose + */ +public class WidgetTick extends Widget implements IWidgetAlwaysDraw { + + /** + * This is a Tick that calls the passed Runnable each time a specific delay + * is passed. + * + * @author ShaRose + */ + public class DelayTick implements iTick { + + long lastTick; + boolean removeSelf = false; + Runnable tickCallback; + long timeToTick; + + /** + * Creates a new DelayTick that calls each time a specific delay passes. + * + * @param callback + * The Runnable it will call. + * @param delay + * The delay on the tick. If 0, it will call on the first + * frame it is checked. + */ + public DelayTick(Runnable callback, int delay) { + if (callback == null) { + throw new IllegalArgumentException("Callback cannot be null."); + } + if (delay < 0) { + throw new IllegalArgumentException("Delay must be 0 or higher."); + } + lastTick = 0; + timeToTick = delay; + tickCallback = callback; + } + + @Override + public void checkTick() { + long millis = System.currentTimeMillis(); + if ((lastTick + timeToTick) < millis) { + lastTick = millis; + tickCallback.run(); + } + } + + /** + * If this method is called, this tick will remove itself next frame. + */ + public void removeSelf() { + removeSelf = true; + } + + @Override + public boolean shouldRemove() { + return removeSelf; + } + } + + /** + * This is a Tick that calls the passed Runnable each frame. + * + * @author ShaRose + */ + public class FrameTick implements iTick { + boolean removeSelf = false; + + Runnable tickCallback; + + /** + * Creates a new FrameTick that calls each frame. + * + * @param callback + * The Runnable it will call. + */ + public FrameTick(Runnable callback) { + if (callback == null) { + throw new IllegalArgumentException("Callback cannot be null."); + } + tickCallback = callback; + } + + @Override + public void checkTick() { + tickCallback.run(); + } + + /** + * If this method is called, this tick will remove itself next frame. + */ + public void removeSelf() { + removeSelf = true; + } + + @Override + public boolean shouldRemove() { + return removeSelf; + } + + @Override + public String toString() { + return "FrameTick [tickCallback=" + tickCallback + "]"; + } + } + + /** + * This is an interface that is used by GuiAPI for ticks. You can use it as + * well for creating custom tick patterns. + * + * @author ShaRose + */ + public interface iTick { + /** + * This is called once a frame if this Tick is added to a WidgetTick, + * and said WidgetTick is drawn. + */ + void checkTick(); + + /** + * @return Should this Tick be removed from the list? + */ + boolean shouldRemove(); + } + + /** + * This is a Tick that calls the passed Runnable after a configurable delay. + * After it is called, it tries to remove itself. + * + * @author ShaRose + */ + public class SingleTick implements iTick { + int delayBeforeRemove; + + Runnable tickCallback; + long timeToTick; + + /** + * Creates a new SingleTick that is only called once, with a + * configurable delay. After this one tick it removes itself. + * + * @param callback + * The Runnable it will call. + * @param delay + * The delay on the tick. If 0, it will call on the first + * frame it is checked. + */ + public SingleTick(Runnable callback, int delay) { + if (callback == null) { + throw new IllegalArgumentException("Callback cannot be null."); + } + if (delay < 0) { + throw new IllegalArgumentException("Delay must be 0 or higher."); + } + timeToTick = -1; + delayBeforeRemove = delay; + tickCallback = callback; + } + + @Override + public void checkTick() { + if (delayBeforeRemove == 0) { + tickCallback.run(); + } + if (timeToTick == -1) { + timeToTick = System.currentTimeMillis() + delayBeforeRemove; + } else { + if (timeToTick < System.currentTimeMillis()) { + tickCallback.run(); + } + } + } + + @Override + public boolean shouldRemove() { + if (delayBeforeRemove == 0) { + return true; + } + return timeToTick < System.currentTimeMillis(); + } + + @Override + public String toString() { + return "SingleTick [tickCallback=" + tickCallback + "]"; + } + } + + protected ArrayList ticks = new ArrayList(); + + /** + * This creates a new WidgetTick. It does nothing besides setting the max + * size to 0,0. + */ + public WidgetTick() { + setMaxSize(0, 0); + } + + /** + * This creates and adds a new Tick that calls every frame. + * + * @param callback + * The callback you want this to call. + * @return {@link WidgetTick.FrameTick} + */ + public FrameTick addCallback(Runnable callback) { + FrameTick tick = new FrameTick(callback); + ticks.add(tick); + return tick; + } + + /** + * This creates and adds a tick that calls at a configurable delay. + * + * @param callback + * The callback you want this to call. + * @param timepertick + * @return {@link WidgetTick.DelayTick} + */ + public DelayTick addCallback(Runnable callback, int timepertick) { + DelayTick tick = new DelayTick(callback, timepertick); + ticks.add(tick); + return tick; + } + + /** + * This adds an {@link WidgetTick.iTick} to the internal array. This is so you can + * create your own custom ticks and add them if you want something more + * powerful. + * + * @param tick + * The {@link WidgetTick.iTick} to add. + * @return true if it was able to be added, false otherwise. + */ + public boolean addCustomTick(iTick tick) { + return ticks.add(tick); + } + + /** + * This creates and adds a tick that is called only once after a delay, and + * then removes itself. + * + * @param callback + * The callback you want this to call. + * @param delay + * The delay on the tick. + * @return The created {@link WidgetTick.SingleTick} + */ + public SingleTick addTimedCallback(Runnable callback, int delay) { + SingleTick tick = new SingleTick(callback, delay); + ticks.add(tick); + return tick; + } + + /** + * Gets an unmodifiable copy of the currently registered ticks. + * + * @return A unmodifiable copy of the tick list. + */ + public List getTickArrayCopy() { + return Collections.unmodifiableList(ticks); + } + + @Override + protected void paintWidget(GUI gui) { + iTick[] removedTicks = new iTick[ticks.size()]; + for (int i = 0; i < ticks.size(); i++) { + iTick tick = ticks.get(i); + try { + tick.checkTick(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Error when calling tick " + tick + + " at position " + i + " in WidgetTick.", e); + } + if (tick.shouldRemove()) { + removedTicks[i] = tick; + } + } + for (int i = 0; i < removedTicks.length; i++) { + iTick tick = removedTicks[i]; + if (tick != null) { + ticks.remove(tick); + } + } + + } +} diff --git a/mcp/sharose/mods/guiapi/examples/ItemGuiApiExample.java b/mcp/sharose/mods/guiapi/examples/ItemGuiApiExample.java new file mode 100644 index 0000000..083f262 --- /dev/null +++ b/mcp/sharose/mods/guiapi/examples/ItemGuiApiExample.java @@ -0,0 +1,65 @@ +package sharose.mods.guiapi.examples; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import sharose.mods.guiapi.GuiApiHelper; +import sharose.mods.guiapi.GuiModScreen; +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import de.matthiasmann.twl.Widget; + +/** + * This is a small example for displaying widgets in game. When you use this + * item, it simply shows a text display with a back button. + * + * @author ShaRose + */ +public class ItemGuiApiExample extends Item { + + /** + * Default constructor for Items. + * + * @param itemID + */ + protected ItemGuiApiExample(int itemID) { + super(itemID); + } + + @Override + public int getColorFromItemStack(ItemStack par1ItemStack, int par2) { + // This simply tints the sign black to differentiate it. This way I + // didn't have to use a sprite. (This isn't a part of GuiAPI) + return 986895; + } + + @Override + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, + EntityPlayer par3EntityPlayer) { + Widget textDisplay = GuiApiHelper + .makeTextDisplayAndGoBack( + "An example message.", + "This is a message that should be displayed when you right click with the test item selected.", + "Go back to the game.", false); + // I'm going to be creating a simple text display widget. To keep things + // small, I'll be using an existing feature from GuiApiHelper: + // makeTextDisplayAndGoBack. It makes a window with a text bar on top, a + // message (that will size itself, and if needed will use scrollbars), + // and a button to go back to whatever was open previously. It should be + // easy to see what's what for this method. + GuiModScreen.show(textDisplay); + // Finally, 'show' your new widget. + return par1ItemStack; + // Return the ItemStack without any changes (we aren't using it up). + } + + @Override + @SideOnly(Side.CLIENT) + public void updateIcons(IconRegister par1IconRegister) + { + this.iconIndex = Item.sign.getIconFromDamage(0); + return; // Please, please never do this. This is just a hack. + } +} diff --git a/mcp/sharose/mods/guiapi/examples/mod_GuiApiBasicExample.java b/mcp/sharose/mods/guiapi/examples/mod_GuiApiBasicExample.java new file mode 100644 index 0000000..decc540 --- /dev/null +++ b/mcp/sharose/mods/guiapi/examples/mod_GuiApiBasicExample.java @@ -0,0 +1,143 @@ +package sharose.mods.guiapi.examples; + +import sharose.mods.guiapi.GuiApiHelper; +import sharose.mods.guiapi.GuiModScreen; +import sharose.mods.guiapi.ModSettingScreen; +import sharose.mods.guiapi.ModSettings; +import net.minecraft.src.BaseMod; + +/** + * This is the BASIC example of GuiAPI usage. We are going to create a + * ModSettings object, and use the 'easy' way of getting settings. Note, the + * easy was is slower than the intermediate way of doing things, so if you are + * getting your setting values several times a second you might want to read + * that after this tutorial. As well, this tutorial will show you some usage of + * the 'makeButton' and 'showTextDisplay' method in the GuiApiHelper class. + * + * @author ShaRose + */ +public class mod_GuiApiBasicExample extends BaseMod { + /** The mod screen. */ + public ModSettingScreen myModScreen; + /** The settings. */ + public ModSettings mySettings; + + @Override + public String getVersion() { + return "1.1"; + } + + @Override + public void load() { + // First, create the settings class. The string in question is the + // 'backend' name, usually the actual mod class name. + mySettings = new ModSettings("mod_GuiApiBasicExample"); + // This is the Mod screen. It will automatically register the button in + // the settings menu. This is two seperate steps, because you don't HAVE + // to have this step there, like if you only want to store the settings + // without a user-accessible gui. + // Since we are adding one with longish names, we are going to make this + // in single column mode. + myModScreen = new ModSettingScreen("GuiAPI Basic Example"); + // If you want to leave it in two column mode, you don't need this part. + // Now let's add a few settings. Since we are doing it in 'easy' mode, + // we'll just discard the return values in this case. + myModScreen.setSingleColumn(true); + // default is 5, min is 1, max is 10 + mySettings.addSetting(myModScreen, "Nice Name for Int A", + "backendIntA", 5, 1, 10); + // default is 0.5, min is 0.1, step is 0.01, max is 1.0. + mySettings.addSetting(myModScreen, "Nice Name for Float B", + "backendFloatB", 0.5f, 0.1f, 0.01f, 1.0f); + // Multi options, default at 'Option A', go between Option A-F + mySettings.addSetting(myModScreen, "Nice Name for Multi C", + "backendMultiC", 0, "Option A", "Option B", "Option C", + "Option D", "Option E", "Option F"); + // boolean, default at true + mySettings.addSetting(myModScreen, "Nice Name for Boolean D", + "backendBooleanD", true); + // boolean, default at true, with custom names + mySettings.addSetting(myModScreen, "Nice Name for Boolean E", + "backendBooleanE", false, "Yes!", "Noo!"); + // Text setting + mySettings.addSetting(myModScreen, "Nice Name for Text F", + "backendTextF", "This is the Default Value"); + // This makes a button which will call the 'ShowAllTheSettings' method + // below. If the method in question is a static method, please use the + // class. For example, mod_GuiAPIBasicExample.class instead of this. + // Note you don't have to use this either, it can be any object, and the + // method does not need to be public, as this can and will call private + // methods as well. The boolean at the end controls whether or not to + // automatically add the click sound. Use false if you want it to be + // silent, or if you want to call it manually with GuiModScreen.back() + myModScreen.append(GuiApiHelper.makeButton("Display all my settings!", + "ShowAllTheSettings", this, true)); + // We'll also add a button to reset all of the settings to default. You + // can do this on a per setting basis as well, but we'll learn that in + // the Intermediate example mod. As well, you can see that I am calling + // mySettings.resetAll() with this button, and it will click. + myModScreen.append(GuiApiHelper.makeButton("Default all my settings!", + "resetAll", mySettings, true)); + // And finally, don't forget to load any settings you saved earlier! + mySettings.load(); + } + + /** + * This is the method that will be called if you press the + * "Display Settings" button. It doesn't have to be public, so you can make + * this private and it will work. However, since we are calling this from a + * button, it needs to return void. + */ + public void ShowAllTheSettings() { + StringBuilder displayTextBuilder = new StringBuilder(); + displayTextBuilder.append("Int A: "); + // this finds the setting by backend name. It makes sure that it is an + // int type, and gets the value of the current context (like a global + // context, or a per world context. By default, the context will not + // change, but you can specify specific ones if you want). You can + // specify one as an argument if you want as well. + displayTextBuilder.append(mySettings.getIntSettingValue("backendIntA")); + displayTextBuilder.append("\r\n\r\n"); + displayTextBuilder.append("Float B: "); + // Now Float B. + displayTextBuilder.append(mySettings + .getFloatSettingValue("backendFloatB")); + displayTextBuilder.append("\r\n\r\n"); + displayTextBuilder.append("Multi C: "); + // Now Multi C, as an int which you can use in your code. + displayTextBuilder.append(mySettings + .getMultiSettingValue("backendMultiC")); + displayTextBuilder.append("\r\n\r\n"); + displayTextBuilder.append("Multi C (Displayed): "); + // Now Multi C, as the displayed string on the menu. + displayTextBuilder.append(mySettings + .getMultiSettingLabel("backendMultiC")); + displayTextBuilder.append("\r\n\r\n"); + displayTextBuilder.append("Boolean D: "); + // Now Boolean D. + displayTextBuilder.append(mySettings + .getBooleanSettingValue("backendBooleanD")); + displayTextBuilder.append("\r\n\r\n"); + displayTextBuilder.append("Boolean E: "); + // Now Boolean E. Note that it is not any different whether you + // specified display names or not. + displayTextBuilder.append(mySettings + .getBooleanSettingValue("backendBooleanE")); + displayTextBuilder.append("\r\n\r\n"); + displayTextBuilder.append("Text F: "); + // Now String F. + displayTextBuilder.append(mySettings + .getTextSettingValue("backendTextF")); + // Display your menu. It will have a title bar that says 'My Current + // Settings', will use all the text you just created using the + // StringBuilder and the settings helpers in a long textbox, and at the + // bottom will have a button that says 'OK, Go back to the settings + // now.' which, when pressed, will just go back to the last menu. In + // this case, your settings menu. It automatically sets up a scrollbar + // for you as well. Of course, we also call GuiModScreen.show to display + // the widget that makeTextDisplayAndGoBack creates. + GuiModScreen.show(GuiApiHelper.makeTextDisplayAndGoBack( + "My Current Settings", displayTextBuilder.toString(), + "OK, Go back to the settings now.", false)); + } +} diff --git a/mcp/sharose/mods/guiapi/examples/mod_GuiApiIngameMessageExample.java b/mcp/sharose/mods/guiapi/examples/mod_GuiApiIngameMessageExample.java new file mode 100644 index 0000000..ab6c1da --- /dev/null +++ b/mcp/sharose/mods/guiapi/examples/mod_GuiApiIngameMessageExample.java @@ -0,0 +1,38 @@ +package sharose.mods.guiapi.examples; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.src.BaseMod; +import net.minecraft.src.ModLoader; + +/** + * This is a small example for how to make a user dialog. This part is just + * creating the item. Please view {@link ItemGuiApiExample} for the real code. + * + * @author ShaRose + */ +public class mod_GuiApiIngameMessageExample extends BaseMod { + + /** + * A reference to the Example item. + */ + Item exampleItem; + + @Override + public String getVersion() { + return "1.0"; + } + + @Override + public void load() { + exampleItem = new ItemGuiApiExample(28000).setUnlocalizedName( + "GuiApiExampleItem"); + // Create the example item, set the Name. It will use the sign's icon itself. + ModLoader.addName(exampleItem, "GuiAPI Example Item"); + // Give it a 'real' name. + ModLoader.addShapelessRecipe(new ItemStack(exampleItem), new Object[] { + new ItemStack(Item.sign), new ItemStack(Item.paper) }); + // Just a shapeless recipe. Normal sign and some paper. + } + +} diff --git a/mcp/sharose/mods/guiapi/examples/mod_GuiApiIntermediateExample.java b/mcp/sharose/mods/guiapi/examples/mod_GuiApiIntermediateExample.java new file mode 100644 index 0000000..01ad73c --- /dev/null +++ b/mcp/sharose/mods/guiapi/examples/mod_GuiApiIntermediateExample.java @@ -0,0 +1,263 @@ +package sharose.mods.guiapi.examples; + +import sharose.mods.guiapi.GuiApiHelper; +import sharose.mods.guiapi.GuiModScreen; +import sharose.mods.guiapi.ModAction; +import sharose.mods.guiapi.ModSettingScreen; +import sharose.mods.guiapi.ModSettings; +import sharose.mods.guiapi.Setting; +import sharose.mods.guiapi.SettingBoolean; +import sharose.mods.guiapi.SettingFloat; +import sharose.mods.guiapi.SettingInt; +import sharose.mods.guiapi.SettingMulti; +import sharose.mods.guiapi.SettingText; +import sharose.mods.guiapi.WidgetSimplewindow; +import sharose.mods.guiapi.WidgetSinglecolumn; +import net.minecraft.src.BaseMod; +import de.matthiasmann.twl.TextArea; +import de.matthiasmann.twl.Widget; + +/** + * This is the INTERMEDIATE example of GuiAPI usage. We are going to do the more + * correct, but slightly more complex, way of retrieving settings, learn about + * Callback usage within GuiAPI, and some more interesting usages of ModAction + * relating to that. We will also learn about subscreens and how to use them + * within your mod. We'll also be looking at the createChoiceMenu method in + * GuiApiHelper. + * + * @author ShaRose + */ +public class mod_GuiApiIntermediateExample extends BaseMod { + /** + * This is a method designed to update the text area, depending on what kind + * of setting is passed. Please view the source code comments for more. + * + * @param textArea + * The textarea to update. + * @param setting + * The setting to get info from. This particular method supports + * SettingInt, SettingFloat, and SettingText. + */ + private static void updateTextArea(TextArea textArea, + @SuppressWarnings("rawtypes") Setting setting) { + String text = ""; + // Instead of making different method for each one, We'll just check + // what type of setting each is, place the text you want in the text + // variable, and then set the TextArea. + if (setting instanceof SettingInt) { + SettingInt settingint = (SettingInt) setting; + text = (((settingint.get() - settingint.minimumValue) / (float) (settingint.maximumValue - settingint.minimumValue)) * 100) + + "%"; + } + if (setting instanceof SettingFloat) { + SettingFloat settingfloat = (SettingFloat) setting; + float val = (settingfloat.get() - settingfloat.minimumValue) + / (settingfloat.maximumValue - settingfloat.minimumValue); + if (val < 0) { + val = 0; + } + text = (val * 100) + "%"; + } + if (setting instanceof SettingText) { + SettingText settingtext = (SettingText) setting; + text = settingtext.get(); + } + // Here's how you normally would set the TextArea's text, but we are + // going to use one of the helpers for it. It's still one line, but this + // way is a bit messy. + // ((SimpleTextAreaModel) textArea.getModel()).setText(text, false); + // Here's the cleaner way to do it, and this also works if you set it to + // use HTML mode. + GuiApiHelper.setTextAreaText(textArea, text); + } + + /** The mod screen. */ + public ModSettingScreen myModScreen; + + /** The settings. */ + public ModSettings mySettings; + + /** The setting boolean d. */ + public SettingBoolean settingBooleanD; + + /** The setting boolean e. */ + public SettingBoolean settingBooleanE; + + /** The setting float b. */ + public SettingFloat settingFloatB; + + /** The setting int a. */ + public SettingInt settingIntA; + + /** The setting multi c. */ + public SettingMulti settingMultiC; + + /** The setting text f. */ + public SettingText settingTextF; + + /** The subscreen for booleans. */ + public WidgetSimplewindow subscreenBooleans; + + /** The subscreen for numberics. */ + public WidgetSimplewindow subscreenNumberics; + + /** The subscreen for others. */ + public WidgetSimplewindow subscreenOthers; + + @Override + public String getVersion() { + return "1.0"; + } + + @Override + public void load() { + // We need to set up our settings and modscreen, so let's do that. + mySettings = new ModSettings("mod_GuiApiIntermediateExample"); + myModScreen = new ModSettingScreen("GuiAPI Intermediate Example"); + // Now we are going to start setting up our subscreens. I want it in one + // column, so I'm using the WidgetSinglecolumn class. If you want to use + // the normal two column version, use WidgetClassicTwocolumn instead. + WidgetSinglecolumn numbericBaseWidget = new WidgetSinglecolumn(); + // Note that this time we are saving the SettingInt that is returned. + // This is a faster way to get settings than the easy way shown in the + // basic example, but it takes up more space for field declarations. As + // well note instead of adding it to the modscreen, we are telling it to + // use the WidgetSinglecolumn we made just previous. + settingIntA = mySettings.addSetting(numbericBaseWidget, + "Nice Name for Int A", "backendIntA", 0, -100, 100); + // We are also going to have a TextArea display the percentage of what's + // selected. I'm leave the text blank for now, we will update it after + // we load the saved settings. As well, the reason for the false at the + // end is because we are just using simple text mode. If you want a + // TextBox to render HTML, set that to true. + TextArea textAreaA = GuiApiHelper.makeTextArea("", false); + // Add it to the subscreen we are making as well. + numbericBaseWidget.add(textAreaA); + // This is how you set up a callback when the value is changed. This + // code creates a ModAction that calls the static updateTextArea method + // in this class. It has two arguments: a TextArea and a Setting, so we + // specify that. Since there's no way for it to specify that kind of + // argument (The callback has no arguments to send), we are also going + // to tell it to use the references to the textarea we created for this + // setting, and the setting itself. After we create the setting, we use + // the setting to get a reference to the widget that is actually + // displayed, and add a callback. + settingIntA.displayWidget.addCallback(new ModAction( + mod_GuiApiIntermediateExample.class, "updateTextArea", + "Callback for TextArea A", TextArea.class, Setting.class) + .setDefaultArguments(textAreaA, settingIntA)); + // You should already know what this is. + settingFloatB = mySettings.addSetting(numbericBaseWidget, + "Nice Name for Float B", "backendFloatB", 0f, -2.0f, 0.01f, + 2.0f); + TextArea textAreaB = GuiApiHelper.makeTextArea("", false); + numbericBaseWidget.add(textAreaB); + // And again, this is much the same. Note that for both of these + // ModActions, we specifically set a 'name' for it, so in case anything + // happens and an exception is thrown, you will see 'Callback for + // TextArea B' in the stack trace. This is useful for debugging, as + // usually you won't see what the method that actually crashed is, but + // now you can see what method it was, where the ModAction was created, + // etc. As long as you set your names that is. + settingFloatB.displayWidget.addCallback(new ModAction( + mod_GuiApiIntermediateExample.class, "updateTextArea", + "Callback for TextArea B", TextArea.class, Setting.class) + .setDefaultArguments(textAreaB, settingFloatB)); + // Now we are going to merge the reset ModActions for the two 'numberic' + // settings. + ModAction mergedResetNumberics = new ModAction(settingIntA, "reset") + .mergeAction(new ModAction(settingFloatB, "reset")); + // And add a button for it to the subscreen. + numbericBaseWidget.add(GuiApiHelper.makeButton("Reset Numberic Values", + mergedResetNumberics, true)); + // Now we finish creating the subscreen. The WidgetSimplewindow sets up + // a title bar on top, and a button bar to go back on the bottom. There + // is an option to disable the back button as well. + subscreenNumberics = new WidgetSimplewindow(numbericBaseWidget, + "Numberic Settings"); + // And now create a Button to open your new SubScreen. We are going to + // use use the makeButton overloads this time, as we don't need to merge + // any ModActions. This one calls the static GuiModScreen.show method, + // which takes a Widget class as an parameter. When the button is + // clicked, it will call that method using subscreenNumberics as the + // argument. + myModScreen.append(GuiApiHelper.makeButton("Open Numberic Settings", + "show", GuiModScreen.class, true, new Class[] { Widget.class }, + subscreenNumberics)); + // And now we will do 2 other subscreens. There won't be anything + // special for these, so you should be able to follow along with what I + // am doing easily. + WidgetSinglecolumn booleanBaseWidget = new WidgetSinglecolumn(); + settingBooleanD = mySettings.addSetting(booleanBaseWidget, + "Nice Name for Boolean D", "backendBooleanD", true); + settingBooleanE = mySettings.addSetting(booleanBaseWidget, + "Nice Name for Boolean E", "backendBooleanE", false, "Yes!", + "Noo!"); + ModAction mergedResetBooleans = new ModAction(settingBooleanD, "reset") + .mergeAction(new ModAction(settingBooleanE, "reset")); + booleanBaseWidget.add(GuiApiHelper.makeButton("Reset Boolean Values", + mergedResetBooleans, true)); + subscreenBooleans = new WidgetSimplewindow(booleanBaseWidget, + "Boolean Settings"); + myModScreen.append(GuiApiHelper.makeButton("Open Boolean Settings", + "show", GuiModScreen.class, true, new Class[] { Widget.class }, + subscreenBooleans)); + WidgetSinglecolumn otherBaseWidget = new WidgetSinglecolumn(); + settingMultiC = mySettings.addSetting(otherBaseWidget, + "Nice Name for Multi C", "backendMultiC", 0, "Option A", + "Option B", "Option C", "Option D", "Option E", "Option F"); + // Actually, let's do something nice for the text widget. It's a bit + // small to see when editing, so we'll add a TextArea below it that + // shows what you have. + settingTextF = mySettings.addSetting(otherBaseWidget, + "Nice Name for Text F", "backendTextF", + "This is the Default Value"); + TextArea textAreaF = GuiApiHelper.makeTextArea("", false); + otherBaseWidget.add(textAreaF); + // This line of code adds the TextArea to the override list so it won't + // be overridden to anything. Normally, WidgetClassicTwocolumn and + // WidgetSinglecolumn override the height and width of all widgets. + // There's a boolean to not do that for everything, but if you do, it + // makes buttons thin and ugly looking. So, we are going to add it + // specifically so it doesn't override the height. As well, you can use + // this to specify a height to override to, by changing the integer. + otherBaseWidget.heightOverrideExceptions.put(textAreaF, 0); + // And we'll add the callback. It's pretty much the same as the numberic + // callbacks, since in this case we are using a single method for each. + settingTextF.displayWidget.addCallback(new ModAction( + mod_GuiApiIntermediateExample.class, "updateTextArea", + "Callback for TextArea F", TextArea.class, Setting.class) + .setDefaultArguments(textAreaF, settingTextF)); + ModAction mergedResetOthers = new ModAction(settingMultiC, "reset") + .mergeAction(new ModAction(settingTextF, "reset")); + otherBaseWidget.add(GuiApiHelper.makeButton("Reset Other Values", + mergedResetOthers, true)); + subscreenOthers = new WidgetSimplewindow(otherBaseWidget, + "Other Settings"); + myModScreen.append(GuiApiHelper.makeButton("Open Other Settings", + "show", GuiModScreen.class, true, new Class[] { Widget.class }, + subscreenOthers)); + myModScreen.append(GuiApiHelper.makeButton("Reset ALL settings", + "resetAll", mySettings, true)); + // And as well, we'll use GuiApiHelper.createChoiceMenu for a reset menu + // as well. + Widget choiceMenu = GuiApiHelper + .createChoiceMenu( + "Which settings would you like to reset? You can pick to reset any of the groups from here, or you can also reset all the settings as once.", + true, true, "Reset the Numberic Settings.", + mergedResetNumberics, "Reset the Boolean Settings.", + mergedResetBooleans, "Reset the Other settings.", + mergedResetOthers, "Reset everything.", new ModAction( + mySettings, "resetAll")); + // And a button to show the choice menu. + myModScreen.append(GuiApiHelper.makeButton("Reset Settings with Menu", + "show", GuiModScreen.class, true, new Class[] { Widget.class }, + choiceMenu)); + mySettings.load(); + // Finally, make sure all of those TextAreas are updated with the loaded + // values. + mod_GuiApiIntermediateExample.updateTextArea(textAreaA, settingIntA); + mod_GuiApiIntermediateExample.updateTextArea(textAreaB, settingFloatB); + mod_GuiApiIntermediateExample.updateTextArea(textAreaF, settingTextF); + } +} diff --git a/mcp/sharose/mods/guiapi/examples/mod_GuiApiItemTickExample.java b/mcp/sharose/mods/guiapi/examples/mod_GuiApiItemTickExample.java new file mode 100644 index 0000000..651d020 --- /dev/null +++ b/mcp/sharose/mods/guiapi/examples/mod_GuiApiItemTickExample.java @@ -0,0 +1,194 @@ + package sharose.mods.guiapi.examples; + +import sharose.mods.guiapi.ModAction; +import sharose.mods.guiapi.ModSettingScreen; +import sharose.mods.guiapi.ModSettings; +import sharose.mods.guiapi.SettingBoolean; +import sharose.mods.guiapi.SettingInt; +import sharose.mods.guiapi.WidgetItem2DRender; +import sharose.mods.guiapi.WidgetTick; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.src.BaseMod; + +/** + * This is an example specifically focused to some usage of {@link WidgetTick} + * and {@link WidgetItem2DRender}. We'll be making a {@link ModSettingScreen} that lets + * you select an Item ID and a damage value to display, as well as making it so + * that if the selected Item ID is a SubItem, if a toggle is on it will + * automatically cycle it once a second. + * + * @author ShaRose + */ +public class mod_GuiApiItemTickExample extends BaseMod { + + /** The mod screen. */ + public ModSettingScreen myModScreen; + + /** The settings. */ + public ModSettings mySettings; + + /** The setting boolean Auto Cycle SubItems. */ + public SettingBoolean settingBooleanAutoCycleSubItems; + + /** The setting int for Item Damage. */ + public SettingInt settingIntItemDamage; + + /** The setting int Item ID. */ + public SettingInt settingIntItemID; + + /** The {@link WidgetItem2DRender} this uses to render Item Icons. */ + public WidgetItem2DRender widgetRenderer; + + /** + * This {@link WidgetTick} is used to call {@link #onTick()} every 1000ms (1 + * second). + */ + public WidgetTick widgetTicker; + + @Override + public String getVersion() { + return "1.0"; + } + + @Override + public void load() { + // Create the ModSettings, ModSettingScreen, and set the + // ModSettingScreen to use a single column, like in the intermediate + // examples. + mySettings = new ModSettings("mod_GuiApiItemTickExample"); + myModScreen = new ModSettingScreen("GuiAPI Item / Tick Example"); + myModScreen.setSingleColumn(true); + + // Create a ModAction for the onUpdate() method. + ModAction onUpdateAction = new ModAction(this, "onUpdate"); + + // Create a SettingInt with a range between 1 and the max Item id, and + // then add it to the ModSettingScreen using a ModSettings helper. + settingIntItemID = mySettings.addSetting(myModScreen, + "Selected Item ID", "settingIntItemID", 1, 1, + Item.itemsList.length - 1); + + // Add a callback so whenever it's changed, it calls that onUpdate + // ModAction from earlier. + settingIntItemID.displayWidget.addCallback(onUpdateAction); + + // Create a SettingInt with the full range of a Short (Damage is saved + // as a Short for ItemStacks), and then add it to the ModSettingScreen + // using a ModSettings helper. + settingIntItemDamage = mySettings.addSetting(myModScreen, + "SubItem / Damage", "settingIntItemDamage", 0, Short.MIN_VALUE, + Short.MAX_VALUE); + + // Add a callback so whenever it's changed, it calls that onUpdate + // ModAction from earlier. + settingIntItemDamage.displayWidget.addCallback(onUpdateAction); + + // Create a SettingBoolean to enable / disable automated SubItem + // cycling, and then add it to the ModSettingScreen using a ModSettings + // helper. + settingBooleanAutoCycleSubItems = mySettings.addSetting(myModScreen, + "Automatically cycle SubItems", + "settingBooleanAutoCycleSubItems", true, "Yes", "No"); + + // Make a new WidgetItem2DRender. + widgetRenderer = new WidgetItem2DRender(new ItemStack(1, 1, 0)); + + // Add it to the ModSettingScreen. + myModScreen.append(widgetRenderer); + + // Now create a new WidgetTick. + widgetTicker = new WidgetTick(); + + // Add it to myModScreen.theWidget. It will be a WidgetSimplewindow by + // default, so you can do the same for any SubScreens you use. + // Preferably do NOT add this to any layout columns like + // WidgetClassicTwocolumn or WidgetSinglecolumn, as it will draw a space + // for the WidgetTick. We don't want it drawn, so we'll add it to a + // widget that won't add it to the layout. + myModScreen.theWidget.add(widgetTicker); + + // Create a ModAction for onTick, and then add it to the WidgetTick we + // created so it will call it every 1000 milliseconds, or 1 second. For + // example, to make it 'tick' twice a second, the second argument would + // be 500. If you wanted it to call every frame, make it 0. + widgetTicker.addCallback(new ModAction(this, "onTick"), 1000); + + // Load any saved settings, if any. This will call the onUpdate method + // automatically. + mySettings.load(); + } + + /** + * This method is called every 1000ms (1 second) by {@link #widgetTicker}. + */ + @SuppressWarnings("unused") + private void onTick() { + // Are we supposed to cycle SubItems in the first place? If not, return. + if (!settingBooleanAutoCycleSubItems.get()) { + return; + } + + // Get the current stack. + ItemStack stack = new ItemStack(settingIntItemID.get(), 1, + settingIntItemDamage.get()); + + // Is the Item null, or is it NOT a subtype? If so, return. + if ((stack.getItem() == null) || !stack.getHasSubtypes()) { + return; + } + + // Get the damage. + int value = stack.getItemDamage(); + + if ((value >= 31) || (value < 0)) { + value = 0; // If greater than or equal to 31 or lower than 0, make + // it 0. + } else { + value++; // Else, increase. + } + + // And set settingIntItemDamage's value. This will also call onUpdate() + // for us, since it will call settingIntItemDamage's callbacks. + settingIntItemDamage.set(value); + } + + /** + * This is called whenever {@link #settingIntItemID} or + * {@link #settingIntItemDamage} change. It sets max / min bounds depending + * on if it's a subitem or not, and updates {@link #widgetRenderer} so it + * renders with the new Item ID and Damage value. + */ + @SuppressWarnings("unused") + private void onUpdate() { + // Get the current stack. + ItemStack stack = new ItemStack(settingIntItemID.get(), 1, + settingIntItemDamage.get()); + // Is the current item not null, AND have the SubTypes flag set? + if ((stack.getItem() != null) && stack.getHasSubtypes()) { + // If yes, set the range as 0 - 31. Normally SubItems only use 0 - + // 15, to keep compatibility with blocks, and as well there are a + // few ways of trying to find the max SubItem index for any given + // Item, but they don't always work, so we are hardcoding it for + // this demo's purposes. + settingIntItemDamage.maximumValue = 31; + settingIntItemDamage.minimumValue = 0; + // Make sure to update the Display Widget so it reflects the correct + // range. Note, this WILL cap the value if needed. + settingIntItemDamage.displayWidget.update(); + } else { + // If not, set the range as the same as a Short. This is what + // ItemStack saves damage as. + settingIntItemDamage.maximumValue = Short.MAX_VALUE; + settingIntItemDamage.minimumValue = Short.MIN_VALUE; + // Make sure to update the Display Widget so it reflects the correct + // range. Note, this WILL cap the value if needed. + settingIntItemDamage.displayWidget.update(); + } + // Finally, set the Render Stack. Note, that if the Item is null, the + // WidgetItem2DRender will just not render anything, which is what we + // want. + widgetRenderer.setRenderStack(stack); + } + +} diff --git a/mcp/sharose/mods/guiapi/examples/mod_GuiApiTWLExamples.java b/mcp/sharose/mods/guiapi/examples/mod_GuiApiTWLExamples.java new file mode 100644 index 0000000..ba930fe --- /dev/null +++ b/mcp/sharose/mods/guiapi/examples/mod_GuiApiTWLExamples.java @@ -0,0 +1,199 @@ +package sharose.mods.guiapi.examples; + +import java.util.Random; + +import sharose.mods.guiapi.GuiApiFontHelper; +import sharose.mods.guiapi.GuiApiHelper; +import sharose.mods.guiapi.GuiModScreen; +import sharose.mods.guiapi.ModAction; +import sharose.mods.guiapi.ModSettingScreen; +import sharose.mods.guiapi.ModSettings; +import sharose.mods.guiapi.SettingList; +import sharose.mods.guiapi.SettingText; +import sharose.mods.guiapi.WidgetList; +import sharose.mods.guiapi.WidgetSimplewindow; +import sharose.mods.guiapi.WidgetSingleRow; +import sharose.mods.guiapi.WidgetSinglecolumn; +import sharose.mods.guiapi.WidgetText; +import sharose.mods.guiapi.GuiApiFontHelper.FontStates; + +import net.minecraft.src.BaseMod; +import de.matthiasmann.twl.ColorSelector; +import de.matthiasmann.twl.Label; +import de.matthiasmann.twl.ListBox; +import de.matthiasmann.twl.ProgressBar; +import de.matthiasmann.twl.Widget; +import de.matthiasmann.twl.model.ColorSpaceHSL; + +public class mod_GuiApiTWLExamples extends BaseMod { + + @SuppressWarnings("unused") + private static void addRandomListboxOption(SettingList setting) { + Random rand = new Random(); + setting.get().add("Option " + rand.nextInt(10000)); + setting.displayWidget.update(); + } + + @SuppressWarnings("unused") + private static void removeSelectedListboxOption(SettingList setting) { + + ListBox listbox = ((WidgetList) setting.displayWidget).listBox; + int selected = listbox.getSelected(); + if (selected == -1) { + return; + } + setting.get().remove(selected); + setting.displayWidget.update(); + + if (selected == listbox.getNumEntries()) // I'm only removing one at a + // time, so this is OK. + { + selected--; + } + if (selected == -1) { + return; // This is if there aren't any entries to select left. I + // could also check getNumEntries to see if it's 0. + } + + listbox.setSelected(selected); + } + + @SuppressWarnings("unused") + private static void showSelectedListboxOption(SettingList setting) { + GuiModScreen.show(GuiApiHelper.makeTextDisplayAndGoBack( + "ListBox Status", setting.displayWidget.userString(), + "Go Back", false)); + } + + private WidgetText colorEditField; + private GuiApiFontHelper colorFontHelper; + private Label colorLabel; + private ProgressBar colorProgressBar; + private ColorSelector colorSelector; + private SettingList listBoxSettingTest; + private ModSettingScreen modScreen; + + private ModSettings modSettings; + + private WidgetSimplewindow screenColoringWindow; + + private WidgetSimplewindow screenListBoxTest; + + @Override + public String getVersion() { + return "1.0"; + } + + @Override + public void load() { + modSettings = new ModSettings("mod_GuiApiTWLExamples"); + SetUpColouringWindow(); + + SetUpListBox(); + + SetUpModWindow(); + } + + private void SetUpColouringWindow() { + colorFontHelper = new GuiApiFontHelper(); + WidgetSinglecolumn widgetSingleColumn = new WidgetSinglecolumn(); + widgetSingleColumn.childDefaultWidth = 300; + + colorLabel = new Label("This is an example of coloring a label's Text."); + widgetSingleColumn.add(colorLabel); + colorFontHelper.setFont(colorLabel); + colorProgressBar = new ProgressBar(); + colorProgressBar.setValue(0.7f); + colorProgressBar.setTheme("/progressbar"); + // This sets the theme manually. I'm not currently sure why but unless + // you set this it won't actually render the progress bar part, only the + // text. You can use this to change it somewhat though. The available + // themes for this are: + // /progressbar - The standard. + // /progressbar-white - Changes the progress image to a plain white + // area. + // /progressbar-noback - Removes the background image. + // /progressbar-white-noback - Changes the progress image to a plain + // white area and removes the background image. + colorProgressBar.setText("Coloring Progressbar!"); + widgetSingleColumn.add(colorProgressBar); + colorFontHelper.setFont(colorProgressBar); + + widgetSingleColumn.heightOverrideExceptions.put(colorProgressBar, 30); + colorEditField = new WidgetText( + new SettingText("dummyText", "Edit Me!"), null); + widgetSingleColumn.add(colorEditField); + colorFontHelper.setFont(colorEditField); + widgetSingleColumn.heightOverrideExceptions.put(colorEditField, 30); + + colorSelector = new ColorSelector(new ColorSpaceHSL()); + colorSelector.setShowAlphaAdjuster(false); + colorSelector.setShowNativeAdjuster(true); + colorSelector.setShowRGBAdjuster(true); + colorSelector.setShowPreview(true); + colorSelector.addCallback(new ModAction(this, "updateColors", + "Updates the colors for the 'color' window.")); + colorSelector.setColor(colorFontHelper.getColor(FontStates.normal)); + widgetSingleColumn.add(colorSelector); + widgetSingleColumn.heightOverrideExceptions.put(colorSelector, 0); + + screenColoringWindow = new WidgetSimplewindow(widgetSingleColumn, + "GuiAPI / TWL Coloring examples!"); + } + + + private void SetUpListBox() { + WidgetSinglecolumn widgetSingleColumn = new WidgetSinglecolumn(); + listBoxSettingTest = modSettings.addSetting(widgetSingleColumn, + "ListBox Test One", "listboxTest1", "Option 1", "Option 2", + "Option 3", "Option 4", "Option 5", "Option 6"); + ((WidgetList) listBoxSettingTest.displayWidget).listBox + .setTheme("/listbox"); + widgetSingleColumn.heightOverrideExceptions.put( + listBoxSettingTest.displayWidget, 140); + + WidgetSingleRow listBoxRow = new WidgetSingleRow(110, 20); + + listBoxRow + .add(GuiApiHelper.makeButton("Add Random", new ModAction(this, + "addRandomListboxOption", SettingList.class) + .setDefaultArguments(listBoxSettingTest), true)); + + listBoxRow.add(GuiApiHelper.makeButton("Display Selected", + new ModAction(this, "showSelectedListboxOption", + SettingList.class) + .setDefaultArguments(listBoxSettingTest), true)); + + listBoxRow.add(GuiApiHelper.makeButton("Remove Selected", + new ModAction(this, "removeSelectedListboxOption", + SettingList.class) + .setDefaultArguments(listBoxSettingTest), true)); + + widgetSingleColumn.add(listBoxRow); + widgetSingleColumn.widthOverrideExceptions.put(listBoxRow, 0); + screenListBoxTest = new WidgetSimplewindow(widgetSingleColumn, + "GuiAPI / TWL ListBox example!"); + } + + private void SetUpModWindow() { + modSettings.load(); + modScreen = new ModSettingScreen("GuiAPI TWL Examples"); + if (screenColoringWindow != null) { + modScreen.append(GuiApiHelper.makeButton("Open Coloring Examples", + "show", GuiModScreen.class, true, + new Class[] { Widget.class }, screenColoringWindow)); + } + + if (screenListBoxTest != null) { + modScreen.append(GuiApiHelper.makeButton("Open Listbox Example", + "show", GuiModScreen.class, true, + new Class[] { Widget.class }, screenListBoxTest)); + } + } + + @SuppressWarnings("unused") + private void updateColors() { + colorFontHelper.setColor(FontStates.normal, colorSelector.getColor()); + } + +} diff --git a/newtheme b/newtheme deleted file mode 160000 index 80e3c47..0000000 --- a/newtheme +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 80e3c47b96b81b08593cc9dd099ae8ff5590d646 diff --git a/newtheme/Eforen.png b/newtheme/Eforen.png new file mode 100644 index 0000000..6c6260e Binary files /dev/null and b/newtheme/Eforen.png differ diff --git a/newtheme/Eforen.xml b/newtheme/Eforen.xml new file mode 100644 index 0000000..7305c14 --- /dev/null +++ b/newtheme/Eforen.xml @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/newtheme/EforenArrows.png b/newtheme/EforenArrows.png new file mode 100644 index 0000000..25e9584 Binary files /dev/null and b/newtheme/EforenArrows.png differ diff --git a/newtheme/TWL Logo.png b/newtheme/TWL Logo.png new file mode 100644 index 0000000..ffff7f1 Binary files /dev/null and b/newtheme/TWL Logo.png differ diff --git a/newtheme/chaos_sphere_blue_800x600.png b/newtheme/chaos_sphere_blue_800x600.png new file mode 100644 index 0000000..e97708c Binary files /dev/null and b/newtheme/chaos_sphere_blue_800x600.png differ diff --git a/newtheme/cursors.png b/newtheme/cursors.png new file mode 100644 index 0000000..ad105af Binary files /dev/null and b/newtheme/cursors.png differ diff --git a/newtheme/cursors.xml b/newtheme/cursors.xml new file mode 100644 index 0000000..a3f9f71 --- /dev/null +++ b/newtheme/cursors.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/newtheme/font.fnt b/newtheme/font.fnt new file mode 100644 index 0000000..8b3120c --- /dev/null +++ b/newtheme/font.fnt @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/theme/font/default.png b/newtheme/font/default.png similarity index 100% rename from theme/font/default.png rename to newtheme/font/default.png diff --git a/newtheme/font_00.png b/newtheme/font_00.png new file mode 100644 index 0000000..ae2b88b Binary files /dev/null and b/newtheme/font_00.png differ diff --git a/newtheme/gui.png b/newtheme/gui.png new file mode 100644 index 0000000..6d09238 Binary files /dev/null and b/newtheme/gui.png differ diff --git a/newtheme/gui.xml b/newtheme/gui.xml new file mode 100644 index 0000000..12a950b --- /dev/null +++ b/newtheme/gui.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/theme/gui/background.png b/newtheme/gui/background.png similarity index 100% rename from theme/gui/background.png rename to newtheme/gui/background.png diff --git a/theme/gui/container.png b/newtheme/gui/container.png similarity index 100% rename from theme/gui/container.png rename to newtheme/gui/container.png diff --git a/theme/gui/crafting.png b/newtheme/gui/crafting.png similarity index 100% rename from theme/gui/crafting.png rename to newtheme/gui/crafting.png diff --git a/theme/gui/furnace.png b/newtheme/gui/furnace.png similarity index 100% rename from theme/gui/furnace.png rename to newtheme/gui/furnace.png diff --git a/theme/gui/gui.png b/newtheme/gui/gui.png similarity index 100% rename from theme/gui/gui.png rename to newtheme/gui/gui.png diff --git a/theme/gui/icons.png b/newtheme/gui/icons.png similarity index 100% rename from theme/gui/icons.png rename to newtheme/gui/icons.png diff --git a/theme/gui/inventory.png b/newtheme/gui/inventory.png similarity index 100% rename from theme/gui/inventory.png rename to newtheme/gui/inventory.png diff --git a/theme/gui/items.png b/newtheme/gui/items.png similarity index 100% rename from theme/gui/items.png rename to newtheme/gui/items.png diff --git a/theme/gui/logo.png b/newtheme/gui/logo.png similarity index 100% rename from theme/gui/logo.png rename to newtheme/gui/logo.png diff --git a/theme/gui/particles.png b/newtheme/gui/particles.png similarity index 100% rename from theme/gui/particles.png rename to newtheme/gui/particles.png diff --git a/theme/gui/slot.png b/newtheme/gui/slot.png similarity index 100% rename from theme/gui/slot.png rename to newtheme/gui/slot.png diff --git a/theme/gui/trap.png b/newtheme/gui/trap.png similarity index 100% rename from theme/gui/trap.png rename to newtheme/gui/trap.png diff --git a/theme/gui/unknown_pack.png b/newtheme/gui/unknown_pack.png similarity index 100% rename from theme/gui/unknown_pack.png rename to newtheme/gui/unknown_pack.png diff --git a/newtheme/guiTheme.xml b/newtheme/guiTheme.xml new file mode 100644 index 0000000..0b93402 --- /dev/null +++ b/newtheme/guiTheme.xml @@ -0,0 +1,468 @@ + + + + + + + + + + + + + + + + + + + + + ctrl A + ctrl X + ctrl C + ctrl V + + + + none + none + normal + left + 0 + 0 + 0 + 0 + eforen.cursor.normal + -defaultInputMap + + + + left + + + + editfield.* + eforen.editfield.* + background.border + 0x25CF + 32767 + 5 + + eforen.cursor.text + 150 + + + + eforen.button.* + background.border + center + 56 + + + + eforen.togglebutton.* + background.border + + + + + + eforen.checkbox.* + + + + eforen.progressbar.* + background.border + 100 + + + + eforen.progressbar.progressImage-glow + + + + eforen.progressbar.progressImage-glow-anim + + + + eforen.hscrollbar.background + + eforen.hscrollbar.leftbutton.* + + + eforen.hscrollbar.rightbutton.* + + + eforen.hscrollbar.thumb.* + + true + 106 + + + + eforen.vscrollbar.background + + eforen.vscrollbar.upbutton.* + + + eforen.vscrollbar.downbutton.* + + + eforen.vscrollbar.thumb.* + + true + 106 + + + + + listbox.background + 22 + SINGLE_COLUMN + true + false + false + 8000 + 8000 + + + listbox.display.* + listbox-display + 1,2,1,2 + + + + + eforen.combobox.background + 150 + + eforen.combobox.display.selection + 4,8,4,8 + 100 + left + + + eforen.combobox.button.* + + + + + + eforen.combobox.listbox.background + + + + + valuadjuster.button.* + background.border + + + + + - + + + + + + + center + + + valuadjuster.edit.background + + 100 + true + + + + + + + 100 + 100 + 32767 + 32767 + true + 5 + 10 + + scrollpane.dragbutton.* + + + + + + + normal + + + + + + + box + background.border + + + box.separator + background.border + + none + + + none + pathbutton.* + + + + + + tooltip.background + background.border + 250 + + + + + 8,8 + 12,12 + 20,20 + 25,25 + + + + + + + colorselector.* + 2 + 30 + 128 + + + colorselector.* + 2 + 128 + 128 + + + 32767 + + + Current color: + + + 2 + 64 + 64 + + white + + + eforen.cursor.arrow.* + + + + eforen.frame.resizeable + background.border + 5 + 5 + -5 + 5 + false + 0 + 0 + false + 0 + 0 + eforen.cursor.arrow.* + #F888 + 200 + 200 + 200 + 200 + + top + + + eforen.frame.closebutton.* + background.border + 0 + + + + + + eforen.frame.resizeable-title + background.border + 10 + 30 + -70 + 27 + true + -28 + 15 + + + + eforen.graph.background + background.border + 100 + 100 + 5 + 8 + + + white + 1.0 + + + + none + + + + + 13 + 20,19 + + + none + none + table.* + table.* + 20 + + + + + + + eforen.tableheader.background + + 256 + 20 + 3 + eforen.cursor.arrow.left + none + + + ctrl SPACE + + + + 20 + + + 20 + + + + + + box + background.border + + + + + 0 + + + + + + + + + none + + + Animate images + Animate the images while they are displayed + + + editfield.* + eforen.editfield.* + background.border + + none + 0 + + topleft + + + 100 + 100 + + + + + none + + + Accept + + + Cancel + + + + + eforen.frame.fixed + background.border + + + + + gui.background + + + + + 0,0,0,10 + + twl-logo + textarea.ul-bullet + + 400 + + + 42,25,26,15 + + + + + + + + + + + + + + center + + + + white + center + + + + + + + + 5 + CENTER + + diff --git a/newtheme/simple.png b/newtheme/simple.png new file mode 100644 index 0000000..63daa3c Binary files /dev/null and b/newtheme/simple.png differ diff --git a/newtheme/simple.xml b/newtheme/simple.xml new file mode 100644 index 0000000..fb41fdd --- /dev/null +++ b/newtheme/simple.xml @@ -0,0 +1,1121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ctrl A + ctrl X + ctrl C + ctrl V + + + + none + none + normal + left + 0 + 0 + 0 + 0 + -defaultInputMap + + + + button.* + background.border + center + + + + togglebutton.* + background.border + + + + radiobutton.* + background.border + + + + checkbox.* + 13 + 13 + + + + + + + editfield.* + background.border + 0x25CF + 32767 + 5 + + cursor.text + 150 + + + -borderG + background.border + + + + + -borderG + background.border + 0 + + + + + scrollbar.background + + hscrollbar.leftbutton.* + 16 + + + hscrollbar.rightbutton.* + 16 + + + scrollbar.thumb.* + + true + 48 + 16 + + + + scrollbar.background + + vscrollbar.upbutton.* + 16 + + + vscrollbar.downbutton.* + 16 + + + scrollbar.thumb.* + + true + 16 + 48 + + + + + + + -button-depressed + background.border + font.lineHeight + 4 + SINGLE_COLUMN + true + false + false + 8000 + 8000 + + + listbox.display.* + listbox-display + 2 + + + + + -button-depressed + + combobox.display.* + 3 + 50 + left + combobox + + + combobox.button.* + 18 + + + + + -borderH + 2 + + none + 0 + + 150 + + + + + + 100 + 100 + 32767 + 32767 + false + 5 + 10 + + + + + + splitpane.splitter.* + background.border + cursor.resizecolumn + + + splitpane.vsplitter.* + background.border + cursor.resizerow + + + + + 5,5 + 8,8 + 10,10 + 15,15 + + + + + -button-depressed + background.border + + normal + + + + + + + + + 15 + 14,11 + + + font.lineHeight + 6 + + listbox-display + 0,3,0,0 + + + + + + propertysheet.sublist.* + + + + + treetable.treebutton.* + + + columnHeader.* + + 256 + 20 + 3 + cursor.resizecolumn + none + + table.row.* + + ctrl SPACE + DOWN + UP + NEXT + PRIOR + HOME + END + shift DOWN + shift UP + shift NEXT + shift PRIOR + shift HOME + shift END + ctrl DOWN + ctrl UP + ctrl NEXT + ctrl PRIOR + ctrl HOME + ctrl END + ADD + SUBTRACT + + + + 20 + + + 20 + + + + + -borderH + 10 + + + + 20 + + + + + + + 0 + + treepathdisplay.node.* + + + cursor.text + 2,0 + + node.font.lineHeight + 4 + center + cursor.text + + + + + + -button-depressed + treecomboboxPopup + + combobox.display.* + 50 + + 3 + + combobox + + + combobox + + + + + combobox.button.* + 18 + + + + -borderH + 2 + + + none + 0 + 0 + + + 300 + + + + -borderG + + + + + + + 32767 + + + fileselector.buttonOneLevelUp.* + 21 + + + fileselector.buttonHome.* + 21 + + + fileselector.buttonMRU.* + 20 + Shows recently used folders + + + fileselector.buttonMRU.* + 20 + Shows recently opened files + + + OK + 80 + + + Cancel + 80 + + + fileselector.buttonShowFolders.* + Shows folders in the file table + 20 + 20 + + + fileselector.buttonShowHidden.* + Shows hidden or system files + 20 + 20 + + + fileselector.buttonRefresh.* + Refreshes the file table + 20 + 20 + + + -button-depressed + 2 + + + 70 + 80 + 140 + + + + + + BACK + RETURN + + + + 20 + 18 + + + + -borderH + 2 + + none + 0 + + + + -borderH + 2 + + + none + 0 + + + OK + 80 + + + Cancel + 80 + + + + + + -button-depressed + background.border + 100 + 100 + 1 + 1 + + + black + 1.0 + + + + + + + none + + - + 0 + 16 + + + + + 0 + 16 + + + valueadjuster.display.* + center + + + 100 + true + + + + + -borderE + -gradC + 2 + 100 + + + + + + + + + -button-depressed + 2 + 30 + 128 + colorselector.* + + + -button-depressed + 2 + 128 + 128 + colorselector.* + + + 32767 + + + Current color: + + + -button-depressed + 2 + 64 + 64 + + white + + + + Current color in ARGB hex format + + + + + frame.resizeable-title + background.border + 4 + 6 + -24 + 20 + true + -22 + 6 + false + -18 + -18 + white + 0 + 0 + 0 + 0 + arrow.* + + left + + + + + + frame.closebutton.* + 16 + 14 + + + frame.resizeIcon + + + + -borderA + background.border + false + 4 + + + true + + + + + + + popupmenu.button.* + popupmenu-button + 5,2 + + + + -borderA + background.border + + + + popupmenu.separator + + + 0 + + + + + + + + 0 + BOTTOMLEFT + + + + CTRL TAB + CTRL SHIFT TAB + + + + + + + + + + + + none + + twl-logo + textarea.ul-bullet + + 400 + + + -button-depressed + background.border + + + + + + + + + -button-depressed + 2 + + + + none + 4 + + + editfield.* + background.border + + none + 0 + + topleft + + + 100 + 100 + + + + + + + + image + + + + + + + Accept + + + Cancel + + + + -borderA + 6 + + + + + buttonBox.background + 3,2,1,2 + + 5 + BOTTOM + + + + -button-normal + background.border + + -button-depressed + background.border + + + + blockgame0 + blockgame1 + blockgame2 + blockgame3 + blockgame4 + blockgame5 + blockgame6 + blockgame7 + + + + + + + + + + black + center + + + + white + center + + + + + + + + -button-depressed + background.border + 0 + 150 + + none + 384 + 400 + + + + + + + + -button-depressed + background.border + + none + 10 + + + + diff --git a/newtheme/simple.xml.old b/newtheme/simple.xml.old new file mode 100644 index 0000000..b420e81 --- /dev/null +++ b/newtheme/simple.xml.old @@ -0,0 +1,1106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ctrl A + ctrl X + ctrl C + ctrl V + + + + none + none + normal + left + 0 + 0 + 0 + 0 + -defaultInputMap + + + + button.* + background.border + center + + + + togglebutton.* + background.border + + + + radiobutton.* + background.border + + + + checkbox.* + 13 + 13 + + + + + + + editfield.* + background.border + 0x25CF + 32767 + 5 + + cursor.text + 150 + + + -borderG + background.border + + + + + -borderG + background.border + 0 + + + + + scrollbar.background + + hscrollbar.leftbutton.* + 16 + + + hscrollbar.rightbutton.* + 16 + + + scrollbar.thumb.* + + true + 48 + 16 + + + + scrollbar.background + + vscrollbar.upbutton.* + 16 + + + vscrollbar.downbutton.* + 16 + + + scrollbar.thumb.* + + true + 16 + 48 + + + + + + + -borderC + background.border + font.lineHeight + 4 + SINGLE_COLUMN + true + false + false + 8000 + 8000 + + + listbox.display.* + listbox-display + 2 + + + + + -borderC + + combobox.display.* + 3 + 50 + left + combobox + + + combobox.button.* + 18 + + + + + -borderH + 2 + + none + 0 + + 150 + + + + + + 100 + 100 + 32767 + 32767 + false + 5 + 10 + + + + + + splitpane.splitter.* + background.border + cursor.resizecolumn + + + splitpane.vsplitter.* + background.border + cursor.resizerow + + + + + 5,5 + 8,8 + 10,10 + 15,15 + + + + + -borderC + background.border + + normal + + + + + + + + + 15 + 14,11 + + + font.lineHeight + 6 + + listbox-display + 0,3,0,0 + + + + + + propertysheet.sublist.* + + + + + treetable.treebutton.* + + + columnHeader.* + + 256 + 20 + 3 + cursor.resizecolumn + none + + table.row.* + + ctrl SPACE + DOWN + UP + NEXT + PRIOR + HOME + END + shift DOWN + shift UP + shift NEXT + shift PRIOR + shift HOME + shift END + ctrl DOWN + ctrl UP + ctrl NEXT + ctrl PRIOR + ctrl HOME + ctrl END + ADD + SUBTRACT + + + + 20 + + + 20 + + + + + -borderH + 10 + + + + 20 + + + + + + + 0 + + treepathdisplay.node.* + + + cursor.text + 2,0 + + node.font.lineHeight + 4 + center + cursor.text + + + + + + -borderC + treecomboboxPopup + + combobox.display.* + 50 + + 3 + + combobox + + + combobox + + + + + combobox.button.* + 18 + + + + -borderH + 2 + + + none + 0 + 0 + + + 300 + + + + -borderG + + + + + + + 32767 + + + fileselector.buttonOneLevelUp.* + 21 + + + fileselector.buttonHome.* + 21 + + + fileselector.buttonMRU.* + 20 + Shows recently used folders + + + fileselector.buttonMRU.* + 20 + Shows recently opened files + + + OK + 80 + + + Cancel + 80 + + + fileselector.buttonShowFolders.* + Shows folders in the file table + 20 + 20 + + + fileselector.buttonShowHidden.* + Shows hidden or system files + 20 + 20 + + + fileselector.buttonRefresh.* + Refreshes the file table + 20 + 20 + + + -borderC + 2 + + + 70 + 80 + 140 + + + + + + BACK + RETURN + + + + 20 + 18 + + + + -borderH + 2 + + none + 0 + + + + -borderH + 2 + + + none + 0 + + + OK + 80 + + + Cancel + 80 + + + + + + -borderC + background.border + 100 + 100 + 1 + 1 + + + black + 1.0 + + + + + + + none + + - + 0 + 16 + + + + + 0 + 16 + + + valueadjuster.display.* + center + + + 100 + true + + + + + -borderE + -gradC + 2 + 100 + + + + + + + + + -borderC + 2 + 30 + 128 + colorselector.* + + + -borderC + 2 + 128 + 128 + colorselector.* + + + 32767 + + + Current color: + + + -borderC + 2 + 64 + 64 + + white + + + + Current color in ARGB hex format + + + + + frame.resizeable-title + background.border + 4 + 6 + -24 + 20 + true + -22 + 6 + false + -18 + -18 + white + 0 + 0 + 0 + 0 + arrow.* + + left + + + + + + frame.closebutton.* + 16 + 14 + + + frame.resizeIcon + + + + -borderA + background.border + false + 4 + + + true + + + + + + + popupmenu.button.* + popupmenu-button + 5,2 + + + + -borderA + background.border + + + + popupmenu.separator + + + 0 + + + + + + + + 0 + BOTTOMLEFT + + + + CTRL TAB + CTRL SHIFT TAB + + + + + + + + + + + + none + + twl-logo + textarea.ul-bullet + + 400 + + + -borderC + background.border + + + + + + + + + -borderC + 2 + + + + none + 4 + + + editfield.* + background.border + + none + 0 + + topleft + + + 100 + 100 + + + + + + + + image + + + + + + + Accept + + + Cancel + + + + -borderA + 6 + + + + + buttonBox.background + 3,2,1,2 + + 5 + BOTTOM + + + + -button-normal + background.border + + -borderC + background.border + + + + blockgame0 + blockgame1 + blockgame2 + blockgame3 + blockgame4 + blockgame5 + blockgame6 + blockgame7 + + + + + + + + + + black + center + + + + white + center + + + + + + + + -borderC + background.border + 0 + 150 + + none + 384 + 400 + + + + + + + + -borderC + background.border + + none + 10 + + + + diff --git a/newtheme/simpleGameMenu.xml b/newtheme/simpleGameMenu.xml new file mode 100644 index 0000000..6893f06 --- /dev/null +++ b/newtheme/simpleGameMenu.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + ctrl A + ctrl X + ctrl C + ctrl V + + + + none + none + normal + left + 0 + 0 + 0 + 0 + -defaultInputMap + + + + button.* + background.border + center + + + + chaos_sphere + + + white + + + \ No newline at end of file diff --git a/pack.path b/pack.path deleted file mode 100644 index 89b787f..0000000 --- a/pack.path +++ /dev/null @@ -1 +0,0 @@ -'/home/blendmaster/workspace/GuiAPI/twl/bin':'/home/blendmaster/workspace/GuiAPI/xpp3-1.1.4c':'/home/blendmaster/workspace/GuiAPI/theme':'/home/blendmaster/workspace/GuiAPI/bin' diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..b30b83d --- /dev/null +++ b/readme.md @@ -0,0 +1,31 @@ +GuiAPI +====== + +GuiAPI uses the TWL library from Matthias Mann, see http://twl.l33tlabs.org/ + +Building +-------- + +* Use the forge installer script. (It will decompile minecraft for you, as well as download it, etc) +* Now, download the Dev package you need for your version of GuiAPI. For example, if you were developing for 0.15.1, since there's no 0.15.1 dev package, you would download the dev package for 0.15.0. Copy the contents of this into Minecraft.jar. + * Dev Packages and all previous versions of GuiAPI are available in the 'releases' branch. +* After that, drag in all the mcp source files from mcp/* into the src\minecraft directory in MCP. +* Now recompile and test! You are all done. + +Packaging +--------- + +To create a distributable archive, package twl/bin/*, xpp*/*, theme/*, and bin/*. + +Credits +------- + +- lahwran +- ShaRose +- _303 +- Lots of people who I forget. Open an issue or something if you helped... + +Documentation +------------- + +All releases should be tagged here on github, and you can view the docs there. I haven't bothered setting up proper javadocs hosting on github yet. diff --git a/release b/release deleted file mode 100644 index e69de29..0000000 diff --git a/src/GuiModScreen.java b/src/GuiModScreen.java deleted file mode 100644 index 6c28473..0000000 --- a/src/GuiModScreen.java +++ /dev/null @@ -1,281 +0,0 @@ -/** - * GuiModScreen is the minecraft screen subclass that controls and renders TWL. - * normally you will want to call it's static methods to use it, though - * subclassing it and/or instantiating it - * are also possible. however, to do so would use unsafe api (I still might - * change things.) - * - * @author lahwran - * @version 0.9.5 - * @see show - */ - -import net.minecraft.client.Minecraft; -import de.matthiasmann.twl.Widget; -import de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer; -import de.matthiasmann.twl.renderer.lwjgl.RenderScale; - -public class GuiModScreen extends da { - /** - * reference to parent screen, is used to go back() - * @see back() - */ - public da parentScreen; - public boolean drawbg = true; - /** - * actual main widget of this guiscreen - */ - public Widget mainwidget; - - /* - * public static int lastMouseX=0; - * public static int lastMouseY=0; - * public static boolean mousepressed[]; - * - * static { - * mousepressed=new boolean[Mouse.getButtonCount()]; - * for(int i=0;i8| - Minecraft m = ModSettings.getMcinst(); - m.a(screen); - screen.setActive(); - } - - /** - * play a click sound. call after the user performs an action. already - * called from setting widgets. - */ - public static void clicksound() - { - Minecraft m = ModSettings.getMcinst(); - m.B.a("random.click", 1.0F, 1.0F); - - } - - /** - * internal - actually sets the TWL screen. - */ - private void setActive() - { - GuiWidgetScreen.getInstance().setScreen(mainwidget); - } - - // protected void a(int x, int y, int button){} - private int t = 0; - - //handleInput - is empty as this is where input is normally handled and we handle it elsewhere - public void e(){} - - public void a(int j, int k, float f) - { - if (drawbg) i();// render default background - // GL11.glClearColor(0.96f, 0.97f, 1.0f, 1.0f); - // GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); - - // mouse doesn't like to respond unless we do this - /* - * if(t==20) - * { - * System.out.println(j); - * System.out.println(Mouse.getX()); - * System.out.println(k); - * System.out.println(Mouse.getY()); - * - * System.out.println(Mouse.isButtonDown(0)); - * t=0; - * } - * else - * { - * t++; - * } - */ - // LWJGLRenderer r = (LWJGLRenderer) - // GuiWidgetScreen.getInstance().gui.getRenderer(); - // r.syncViewportSize(); - // GuiWidgetScreen.getInstance().layout(); - // for (int i=0; i E = new ArrayList(); - * E.add(new Integer(Mouse.getEventX())); - * E.add(new Integer(Mouse.getEventY())); - * E.add(new Integer(Mouse.getEventButton())); - * E.add(new Boolean(Mouse.getEventButtonState())); - * int wheeldelta = Mouse.getEventDWheel(); - * if(wheeldelta>0) - * E.add(new Integer(wheeldelta)); - * MCTWLInput.instance.MouseEvents.add(E);* / - * } - * public void f() - * { - * GuiWidgetScreen.getInstance().gui.handleKey( - * Keyboard.getEventKey(), - * Keyboard.getEventCharacter(), - * Keyboard.getEventKeyState()); - * /* - * ArrayList E = new ArrayList(); - * E.add(new Integer(Keyboard.getEventKey())); - * E.add(new Character(Keyboard.getEventCharacter())); - * E.add(new Boolean(Keyboard.getEventKeyState())); - * MCTWLInput.instance.KeyEvents.add(E);* / - * } - */ - -} diff --git a/src/GuiModSelect.java b/src/GuiModSelect.java deleted file mode 100644 index 85b2096..0000000 --- a/src/GuiModSelect.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * subclass of guimodscreen, is the entry point from the button in the options menu. - * @author lahwran - * @version 0.9.5 - */ -import de.matthiasmann.twl.Button; -import de.matthiasmann.twl.model.SimpleButtonModel; - - -public class GuiModSelect extends GuiModScreen { - - protected GuiModSelect(da by1) { - super(by1); - WidgetClassicTwocolumn w=new WidgetClassicTwocolumn(); - w.vpad = 10; - for(int i=0; i - *
- * example:
- *
- * assuming x.addCallback takes a runnable:
- * public void F(T x)
- * {
- * x.addCallback(new ModAction(this, "callback"));
- * }
- *
- * public void callback()
- * {
- * //do stuff here
- * }
- * - * @author 303 (Patch by ShaRose) - * @version 0.9.5 - */ -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.security.InvalidParameterException; - -public class ModAction implements Runnable { - protected List handlerObjects = new ArrayList(); - protected List handlerMethods = new ArrayList(); - - protected Object[] defaultArguments; - - @SuppressWarnings("unchecked") - protected Class[] params; - /** - * coming soon, this will be useful enough to document - */ - public String name; - /** - * coming soon, this will be useful enough to document - */ - public Object data; - - /** - * "normal" constructor. - * @param name_ name used in error messages. set to something you'll - * recognize. - * @param params_ paramaters types that you will pass through call to your - * handlers. - */ - @SuppressWarnings("unchecked") - public ModAction(String name_, Class... params_) - { - name = name_; - params = params_; - } - - /** - * condensed constructor, for use when a runnable is needed. combines - * constructor and call to addhandler. - * @param o object on which to call handler - * @param method handler method name - * @param params_ you won't want to pass any into this for runnables, but - * same meaning as for the normal constructor. - */ - @SuppressWarnings("unchecked") - public ModAction(Object o, String method, Class... params_) - { - name = method; // cheating? - params = params_; // will usually be empty in this constructor - addHandler(o, method); - } - - /** - * coming soon, this will be useful enough to document - * @param o - - * @param method - - * @param _name - - * @param params_ - - */ - @SuppressWarnings("unchecked") - public ModAction(Object o, String method, String _name, Class... params_) - { - name = _name; // cheating? - params = params_; // will usually be empty in this constructor - addHandler(o, method); - } - - /** - * coming soon, this will be useful enough to document - * @param o - - * @param method - - * @param _data - - * @param params_ - - */ - @SuppressWarnings("unchecked") - public ModAction(Object o, String method, Object _data, Class... params_) - { - name = method; // cheating? - data = _data; - params = params_; // will usually be empty in this constructor - addHandler(o, method); - } - - /** - * adds a handler. - * @param o object on which to call the handler - * @param method method on object to call for handler - * @return this (for chaining calls) - */ - @SuppressWarnings("unchecked") - public ModAction addHandler(Object o, String method) - { - try - { - @SuppressWarnings("unused") - Method meth = GetMethodRecursively(o, method);// (o instanceof Class - // ? (Class)o : - // o.getClass()).getDeclaredMethod(method, - // params); - } - catch (Exception e) - { - e.printStackTrace(); - throw new RuntimeException("invalid method parameters"); - } - - for (int i = 0; i < handlerObjects.size(); ++i) - { - Object oo = handlerObjects.get(i); - String omethod = handlerMethods.get(i); - - if (oo == o && omethod.equals(method)) - { - System.err.println(String.format("WARNING: event handler is already registered: %s: %s.%s", name, o.getClass().getName(), method)); - return this; - } - } - - handlerObjects.add(o); - handlerMethods.add(method); - - return this; - } - - /** - * call all handlers. - * @param args arguments list to pass to handlers - make sure it matches - * what you passed in in the constructor. - * @return list of what each handler returns. - */ - @SuppressWarnings("unchecked") - public Object[] call(Object... args) - { - Object[] returns = new Object[handlerObjects.size()]; - for (int i = 0; i < handlerObjects.size(); ++i) - { - Object o = handlerObjects.get(i); - String method = handlerMethods.get(i); - - try - { - Method meth = GetMethodRecursively(o, method);// (o instanceof - // Class ? - // (Class)o : - // o.getClass()).getDeclaredMethod(method, - // params); - returns[i] = meth.invoke(o instanceof Class ? null : o, args); - } - catch (Exception e) - { - e.printStackTrace(); - throw new RuntimeException("error calling callback"); - } - } - return returns; - } - - public boolean hasHandler(Object o, String method) - { - for (int i = 0; i < handlerObjects.size(); ++i) - { - Object oo = handlerObjects.get(i); - String omethod = handlerMethods.get(i); - - if (oo == o && omethod.equals(method)) { return true; } - } - - return false; - } - - public boolean removeHandler(Object o, String method) - { - for (int i = 0; i < handlerObjects.size(); ++i) - { - Object oo = handlerObjects.get(i); - String omethod = handlerMethods.get(i); - - if (oo == o && omethod.equals(method)) - { - handlerObjects.remove(i); - handlerMethods.remove(i); - return true; - } - } - - return false; - } - - Method GetMethodRecursively(Object o, String method) // Why do this? Because - // Class.getMethod - // doesn't include - // private methods, and - // Class.getDeclaredMethod - // doesn't return - // superclass methods. - { - Class currentclass = (o instanceof Class ? (Class)o : o.getClass()); - while (true) - { - try - { - if (currentclass == null) // End of the line, return null. - return null; - - Method returnval = currentclass.getDeclaredMethod(method, params); - if (returnval != null) - { - returnval.setAccessible(true); - return returnval; // hey look at that, a method! - } - } - catch (Throwable x) - {} // Exception? Oh well! - currentclass = currentclass.getSuperclass(); // We don't need to - // worry about - // exceptions here, if - // it's a primitive - // type or something it - // will return null on - // the next loop. - } - } - - /** - * This sets the arguments to use when using run(). - * If this is not used, run calls the requested method with no arguments. - * Throws InvalidParameterException if the arguments provided do not match the method parameters, or are unassignable to those types. - */ - @SuppressWarnings("rawtypes") - public ModAction setDefaultArguments(Object... Arguments) - { - if(Arguments.length != params.length) - throw new InvalidParameterException("Arguments do not match the parameters."); - for (int i = 0; i < params.length; i++) { - Class value = params[i]; - if(!value.isInstance(Arguments[i])) - throw new InvalidParameterException("Arguments do not match the parameters."); - } - defaultArguments = Arguments; - return this; - } - - /** -* Runnable call. If no default arguments are present it will call the method with no arguments. If the method has parameters, it will throw an exception. -* If default arguments are provided using setDefaultArguments, it will use those arguments. -*/ - @Override - public void run() - { - if(defaultArguments == null) - call(); - else - call(defaultArguments); - } -} \ No newline at end of file diff --git a/src/ModCallback.java b/src/ModCallback.java deleted file mode 100644 index 7879f97..0000000 --- a/src/ModCallback.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * class that should be completely replaced by modaction, but is not. use if you dare. - * @author lahwran - * @version 0.9.5 - */ -public class ModCallback implements Runnable { - - public static final int BACK = 0; - public static final int SELECTMOD = 1; - - public Object data; - public int type; - - public ModCallback(int t, Object _data) - { - type = t; - data = _data; - } - - @Override - public void run() { - // TODO Auto-generated method stub - if (type == BACK) - { - GuiModScreen.back(); - GuiModScreen.clicksound(); - } - else if (type == SELECTMOD) - { - //there has got to be a better way to do this - Integer i = (Integer) data; - int modnum = i; - GuiModScreen.show(ModSettingScreen.modscreens.get(modnum).thewidget); - GuiModScreen.clicksound(); - } - } - -} diff --git a/src/ModSettingScreen.java b/src/ModSettingScreen.java deleted file mode 100644 index 6469baf..0000000 --- a/src/ModSettingScreen.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * class that GuiModSelect uses to show subscreens. instantiate to add your own subscreen. - * @author lahwran - * @version 0.9.5 - */ -import java.util.ArrayList; - -import de.matthiasmann.twl.Widget; - - -public class ModSettingScreen { - /** - * actual list of mod screens - */ - - public static ArrayList modscreens = new ArrayList(); - public static String guicontext = ""; - - /** - * the main widget to pass into GuiModScreen.show() - */ - public Widget thewidget; - /** - * the twocolumn widget to show the child widgets in - */ - public WidgetClassicTwocolumn w; - - /** - * title to show on button to this modscreen - */ - public String buttontitle; - /** - * name to show at top of screen - */ - public String nicename; - /** - * convenience constructor for when you want to show the same name on the button and screen title - * @param name mod nice name - */ - public ModSettingScreen(String name) - { - this(name, name); - } - - /** - * - * @param _nicename screen title - * @param _buttontitle button-to-screen title - */ - public ModSettingScreen(String _nicename, String _buttontitle) - { - modscreens.add(this); //// is this a bad idea? - - buttontitle=_buttontitle; - nicename = _nicename; - - w = new WidgetClassicTwocolumn(); - - - thewidget = new WidgetSimplewindow(w, nicename); - - - } - public ModSettingScreen(Widget _w, String _buttontitle) - { - modscreens.add(this); - buttontitle=_buttontitle; - thewidget = _w; - } - /** - * add a widget - * @param newwidget the widget to add - */ - public void append(Widget newwidget) - { - if(w != null) - w.add(newwidget); - else - thewidget.add(newwidget); - } - - /** - * remove a widget - * @param child widget to remove - */ - public void remove(Widget child) - { - if(w != null) - w.removeChild(child); - else - thewidget.removeChild(child); - } - - - -} diff --git a/src/ModSettings.java b/src/ModSettings.java deleted file mode 100644 index 4f3a7d2..0000000 --- a/src/ModSettings.java +++ /dev/null @@ -1,588 +0,0 @@ -/** - * Main interface class for Settings API - * @author lahwran - * @version 0.9.5 - */ -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Properties; - -import de.matthiasmann.twl.Widget; - -import net.minecraft.client.Minecraft; -//import java.util.Vector; - - -public class ModSettings { - //public Vector settings; - /** - * all registered settings for this mod - */ - public ArrayList Settings; - //public HashMap NameID; - - public static ArrayList all = new ArrayList(); - - /** - * Mod name as used in .minecraft/mods/${modbackendname}/ - */ - public String backendname; - - public static String currentContext; - public static HashMap contextDatadirs; - static { - contextDatadirs=new HashMap(); - currentContext = ""; - contextDatadirs.put("", "mods"); - } - //public Widget mainwidget = null; - - public boolean have_loaded = false; - - private static Minecraft mcinst; - public static void presetMcint(Minecraft m) - { - mcinst = m; - } - public static Minecraft getMcinst() - { - if(mcinst != null) return mcinst; - Field f; - try { - - f = Minecraft.class.getDeclaredFields()[1]; - f.setAccessible(true); - - Minecraft m = (Minecraft)f.get(null); - - if(m != null) - { - mcinst = m; - return m; - } - - f = Thread.class.getDeclaredField("target"); - f.setAccessible(true); - - ThreadGroup group = Thread.currentThread().getThreadGroup(); - int count = group.activeCount(); - Thread[] threads = new Thread[count]; - group.enumerate(threads); - for (int i = 0; i < threads.length; i++) - if (threads[i].getName().equals("Minecraft main thread")) { - m = (Minecraft)f.get(threads[i]); - if(m != null) - { - mcinst = m; - return m; - } - } - } - catch (Throwable t) - { - throw new RuntimeException(t); - } - throw new RuntimeException("You are a godless monkey! why are you doing weird things with the innards of minecraft?"); - } - - /** - * @param modbackendname used to initialize class modbackendname field - */ - public ModSettings(String modbackendname) - { - //modnicename = _modnicename; - backendname = modbackendname; - Settings = new ArrayList(); - all.add(this); - //NameID = new HashMap(); - } - //boolean - /** - * convenience boolean setting adder - */ - public SettingBoolean addSetting(ModSettingScreen screen, String nicename, String backendname, boolean value) - { - SettingBoolean s = new SettingBoolean(backendname, value); - WidgetBoolean w = new WidgetBoolean(s, nicename); - screen.append(w); - this.append(s); - return s; - } - /** - * convenience boolean setting adder - */ - public SettingBoolean addSetting(ModSettingScreen screen, String nicename, String backendname, boolean value, String truestring, String falsestring) - { - SettingBoolean s = new SettingBoolean(backendname, value); - WidgetBoolean w = new WidgetBoolean(s, nicename, truestring, falsestring); - screen.append(w); - this.append(s); - return s; - } - //float - /** - * convenience float setting adder - */ - public SettingFloat addSetting(ModSettingScreen screen, String nicename, String backendname, float value) - { - SettingFloat s = new SettingFloat(backendname, value); - WidgetFloat w = new WidgetFloat(s, nicename); - screen.append(w); - this.append(s); - return s; - } - /** - * convenience float setting adder - */ - public SettingFloat addSetting(ModSettingScreen screen, String nicename, String backendname, float value, float min, float step, float max) - { - SettingFloat s = new SettingFloat(backendname, value, min, step, max); - WidgetFloat w = new WidgetFloat(s, nicename); - screen.append(w); - this.append(s); - return s; - } - //int - /** - * convenience int setting adder - */ - public SettingInt addSetting(ModSettingScreen screen, String nicename, String backendname, int value, int min, int max) - { - SettingInt s = new SettingInt(backendname, value, min, 1, max); - WidgetInt w = new WidgetInt(s, nicename); - screen.append(w); - this.append(s); - return s; - } - /** - * convenience int setting adder - */ - public SettingInt addSetting(ModSettingScreen screen, String nicename, String backendname, int value, int min, int step, int max) - { - SettingInt s = new SettingInt(backendname, value, min, step, max); - WidgetInt w = new WidgetInt(s, nicename); - screen.append(w); - this.append(s); - return s; - } - - //key - /** - * convenience key setting adder - */ - public SettingKey addSetting(ModSettingScreen screen, String nicename, String backendname, int value) - { - SettingKey s = new SettingKey(backendname, value); - WidgetKeybinding w = new WidgetKeybinding(s, nicename); - screen.append(w); - this.append(s); - return s; - } - - //multi - /** - * convenience multi setting adder - */ - public SettingMulti addSetting(ModSettingScreen screen, String nicename, String backendname, int value, String... labels) - { - SettingMulti s = new SettingMulti(backendname, value, labels); - WidgetMulti w = new WidgetMulti(s, nicename); - screen.append(w); - this.append(s); - return s; - } - - //text - /** - * convenience text setting adder - */ - public SettingText addSetting(ModSettingScreen screen, String nicename, String backendname, String value) - { - SettingText s = new SettingText(backendname, value); - WidgetText w = new WidgetText(s, nicename); - screen.append(w); - this.append(s); - return s; - } - - ///disgusting shitloads of overloads - - /** - * convenience boolean setting adder - */ - public SettingBoolean addSetting(Widget w2, String nicename, String backendname, boolean value) - { - SettingBoolean s = new SettingBoolean(backendname, value); - WidgetBoolean w = new WidgetBoolean(s, nicename); - w2.add(w); - this.append(s); - return s; - } - /** - * convenience boolean setting adder - */ - public SettingBoolean addSetting(Widget w2, String nicename, String backendname, boolean value, String truestring, String falsestring) - { - SettingBoolean s = new SettingBoolean(backendname, value); - WidgetBoolean w = new WidgetBoolean(s, nicename, truestring, falsestring); - w2.add(w); - this.append(s); - return s; - } - //float - /** - * convenience float setting adder - */ - public SettingFloat addSetting(Widget w2, String nicename, String backendname, float value) - { - SettingFloat s = new SettingFloat(backendname, value); - WidgetFloat w = new WidgetFloat(s, nicename); - w2.add(w); - this.append(s); - return s; - } - /** - * convenience float setting adder - */ - public SettingFloat addSetting(Widget w2, String nicename, String backendname, float value, float min, float step, float max) - { - SettingFloat s = new SettingFloat(backendname, value, min, step, max); - WidgetFloat w = new WidgetFloat(s, nicename); - w2.add(w); - this.append(s); - return s; - } - //int - /** - * convenience int setting adder - */ - public SettingInt addSetting(Widget w2, String nicename, String backendname, int value, int min, int max) - { - SettingInt s = new SettingInt(backendname, value, min, 1, max); - WidgetInt w = new WidgetInt(s, nicename); - w2.add(w); - this.append(s); - return s; - } - /** - * convenience int setting adder - */ - public SettingInt addSetting(Widget w2, String nicename, String backendname, int value, int min, int step, int max) - { - SettingInt s = new SettingInt(backendname, value, min, step, max); - WidgetInt w = new WidgetInt(s, nicename); - w2.add(w); - this.append(s); - return s; - } - - //key - /** - * convenience key setting adder - */ - public SettingKey addSetting(Widget w2, String nicename, String backendname, int value) - { - SettingKey s = new SettingKey(backendname, value); - WidgetKeybinding w = new WidgetKeybinding(s, nicename); - w2.add(w); - this.append(s); - return s; - } - - //multi - /** - * convenience multi setting adder - */ - public SettingMulti addSetting(Widget w2, String nicename, String backendname, int value, String... labels) - { - SettingMulti s = new SettingMulti(backendname, value, labels); - WidgetMulti w = new WidgetMulti(s, nicename); - w2.add(w); - this.append(s); - return s; - } - - //text - /** - * convenience text setting adder - */ - public SettingText addSetting(Widget w2, String nicename, String backendname, String value) - { - SettingText s = new SettingText(backendname, value); - WidgetText w = new WidgetText(s, nicename); - w2.add(w); - this.append(s); - return s; - } - - /*public Widget getWidget() - { - //TODO: should add new settings to screen - if (mainwidget == null) - { - Widget subwidget = new WidgetClassicTwocolumn(); - for (int i=0; i= 8) - // return s; - Settings.add(s); - if(s instanceof Setting) - { - ((Setting)s).nicename = nicename; - ((Setting)s).backendname = backendname; //backendname needs/has uniqueness constraint - ((Setting)s).parentmod = this; - ((Setting)s).update(); - } - if (context == null) - return defvalue; - if(nicename != backendname) - { - NameID.put(backendname, Settings.indexOf(s)); - NameID.put(nicename, Settings.indexOf(s)); - } - else - { - NameID.put(backendname, Settings.indexOf(s));// - } - return s; - } - - /** - * Add a setting to setting list, single name version - * this must be called on a setting for it to function correctly. - * @param name Name to use for setting - must be unique, recommended no special characters (use seperate name version for that) - * @param s Setting object to register - * @return Setting object passed in - * @see Setting - * / - public Widget addSetting(String name, Widget s) - { - return genericAddSetting(name, name, s); - } - public Setting addSetting(String name, Setting s) - { - return (Setting)genericAddSetting(name, name, s); - } - - /* * - * Add a setting to setting list, seperate name version - * this must be called on a setting for it to function correctly. - * @param nicename Name used in GUI - * @param backendname Name used in config file - recommended no special characters, must be unique - * @param s Setting to register - * @return Setting passed in - * @see Setting - * / - public Widget addSetting(String nicename, String backendname, Widget s) - { - return genericAddSetting(nicename, backendname, s); - } - public Setting addSetting(String nicename, String backendname, Setting s) - { - return (Setting)genericAddSetting(nicename, backendname, s); - }*/ - - public static void setContext(String name, String location) - { - if(name != null) - { - - contextDatadirs.put(name, location); - currentContext = name; - if(!name.equals("")) - ModSettings.loadAll(ModSettings.currentContext); - } - else - { - currentContext = ""; - } - } - /** - * add a setting to be saved. - * @param s setting to add - sets s.parent as well, don't add a setting to more than one modsettings - */ - public void append(Setting s) - { - Settings.add(s); - s.parent=this; - } - /** - * removes a setting using ArrayList.remove - * @param s setting to remove - */ - public void remove(Setting s) - { - Settings.remove(s); - s.parent = null; - } - /** - * - * @return count of settings registered - */ - public int size() - { - return Settings.size(); - } - /** - * reset all settings to default values. use as the handler for a modaction passed into a button handler. - */ - public void resetAll(String context) - { - for(int i=0;i - * saves settings file to .minecraft/mods/$backendname/guiconfig.properties
- * coming soon: set name of config file - */ - public void save(String context) - { - if (! have_loaded) - { - return; - } - try{ - File path = getAppDir("minecraft/"+contextDatadirs.get(context)+"/"+backendname+"/"); - dbgout("saving context "+context+" (" + path.getAbsolutePath() +" ["+contextDatadirs.get(context)+"])"); - if (! path.exists()) - { - path.mkdirs(); - } - File file = new File(path,"guiconfig.properties"); - Properties p = new Properties(); - for (int i = 0; i < Settings.size(); i++) - { - - Setting z = (Setting)Settings.get(i); - p.put(z.backendname, z.toString(context)); - } - - - FileOutputStream out = new FileOutputStream(file); - p.store(out, ""); - } - catch (Exception e) { - e.printStackTrace(); - } - } - /** - * must be called after all settings are added for loading/saving to work.
- * loads from .minecraft/mods/$backendname/guiconfig.properties if it exists.
- * coming soon: set name of config file - */ - public void load(String context) - { - for(;;) - { - try{ - if(contextDatadirs.get(context) == null) - break; - File path = getAppDir("minecraft/"+contextDatadirs.get(context)+"/"+backendname+"/"); - if (! path.exists()) break; - File file = new File(path,"guiconfig.properties"); - if (!file.exists()) break; - Properties p = new Properties(); - p.load(new FileInputStream(file)); - for (int i = 0; i < Settings.size(); i++) //TODO: could be more effecient - { //TODO: file version handling - if(Settings.get(i) instanceof Setting) - { - dbgout("setting load"); - Setting z = (Setting)Settings.get(i); - if(p.containsKey(z.backendname)) - { - dbgout("setting "+(String)p.get(z.backendname)); - z.fromString((String)p.get(z.backendname), context); - } - } - } - break; - } - catch (Exception e) { - System.out.println(e); - break; - } - } - } - public void load() - { - load(""); - have_loaded = true; - } - public static void loadAll(String context) - { - for(int i=0; i extends Widget { - - /** - * value. do not write directly if you want things to update! - */ - public HashMap values = new HashMap(); - /** - * default value - */ - public T defvalue; - - /** - * name used to save setting by ModSettings - */ - public String backendname; - - /** - * reference to frontend, so it can tell the gui when to update - set from gui constructor - */ - public WidgetSetting gui = null; - - /** - * reference to modsettings - set from ModSettings.append - used to save when something has changed - */ - public ModSettings parent = null; - public Setting() - { - - } - - /** - * return string to save, called from ModSettings.save() - */ - public abstract String toString(String context); - - /** - * load back a string from toString() - */ - public abstract void fromString(String s, String context); - /*{ - return; - }*/ - - public void reset() - { - reset(ModSettings.currentContext); - } - - /** - * reset setting to default value, including saving and updating the display - */ - public void reset(String context) { - set(defvalue,context); - } - - public void copyContext(String srccontext, String destcontext) { - values.put(destcontext,values.get(srccontext)); - } - - public abstract void set(T v,String context); - public void set(T v) - { - set(v, ModSettings.currentContext); - } - - - public abstract T get(String context); - public T get() - { - return get(ModSettings.currentContext); - } - - //public boolean hasGlobal() -} diff --git a/src/SettingBoolean.java b/src/SettingBoolean.java deleted file mode 100644 index b7db47a..0000000 --- a/src/SettingBoolean.java +++ /dev/null @@ -1,80 +0,0 @@ -import java.util.HashMap; - -/** - * boolean setting, goes with WidgetBoolean - * @author lahwran - * @version 0.9.5 - */ -public class SettingBoolean extends Setting { - - - /** - * - * @param name name to use in config file - * @param _value default value - */ - public SettingBoolean(String name, Boolean _defvalue) - { - defvalue = _defvalue; - values.put("",defvalue); - backendname = name; - } - /** - * you'd call this if the default is "false" - * @param name name to pass to other constructor - */ - public SettingBoolean(String name) - { - this(name, false); - } - - @Override - public String toString(String context) { - return (get(context) ? "true" : "false"); - } - - @Override - public void fromString(String s, String context) - { - values.put(context, s.equals("true")); - - if(gui != null) - { - gui.update(); - } - } - - /** - * return current value. value is no longer accessible, please use this. - * @return - */ - @Override - public Boolean get(String context) - { - if(values.get(context) != null) - return values.get(context); - else if (values.get("") != null) - return values.get(""); - else return defvalue; - } - - /** - * set and save value - * @param v value - */ - @Override - public void set(Boolean v,String context) - { - values.put(context,v); - if (parent != null) - { - parent.save(context); - - } - if(gui != null) - { - gui.update(); - } - } - -} diff --git a/src/SettingFloat.java b/src/SettingFloat.java deleted file mode 100644 index 44d7bea..0000000 --- a/src/SettingFloat.java +++ /dev/null @@ -1,117 +0,0 @@ -import java.util.HashMap; - -/** - * float setting - * @author lahwran - * @version 0.9.5 - * - */ -public class SettingFloat extends Setting { - public float step; - public float min; - public float max; - - /** - * - * @param title name used in config file - */ - public SettingFloat(String title) - { - this(title, 0.0f, 0.0f, 0.1f, 1.0f); - } - /** - * - * @param title name used in config file - * @param _value default value - */ - public SettingFloat(String title, float _value) - { - this(title, _value, 0.0f, 0.1f, 1.0f); - } - /** - * - * @param title name used in config file - * @param _value default value - * @param _min minimum - * @param _max maximum - */ - public SettingFloat(String title, float _value, float _min, float _max) - { - - this(title, _value, _min, 0.1f, _max); - } - /** - * - * @param title name used in config file - * @param _value default value - * @param _min minimum - * @param _step stepsize - * @param _max maximum - */ - public SettingFloat(String title, float _value, float _min, float _step, float _max) - { - values.put("",_value); - defvalue = _value; - min=_min; - step=_step; - max=_max; - backendname = title; - - if (min > max) - { - float t = min; - min = max; - max = t; - } - } - - - public String toString(String context) { - return ""+get(context); - } - public void fromString(String s, String context) - { - values.put(context, new Float(s)); - if(gui != null) - { - gui.update(); - } - } - - /** - * set and save value - * @param v value - */ - @Override - public void set(Float v, String context) - { - if (step > 0) - values.put(context, Math.round(v/step)*step); - else - values.put(context, v); - if (parent != null) - { - parent.save(context); - - } - if(gui != null) - { - gui.update(); - } - } - /** - * return current value. not really needed because value is public, but is nice to have - * @return - */ - @Override - public Float get(String context) - { - if(values.get(context) != null) - return values.get(context); - else if (values.get("") != null) - return values.get(""); - else return defvalue; - } - - -} diff --git a/src/SettingInt.java b/src/SettingInt.java deleted file mode 100644 index 34132b3..0000000 --- a/src/SettingInt.java +++ /dev/null @@ -1,116 +0,0 @@ -import java.util.HashMap; - - -public class SettingInt extends Setting { - public int step; - public int min; - public int max; - - /** - * - * @param title name used in config file - */ - public SettingInt(String title) - { - - this(title, 0, 0, 1, 100); - } - /** - * - * @param title name used in config file - * @param _value default value - */ - public SettingInt(String title, int _value) - { - this(title, _value, 0, 1, 100); - } - /** - * - * @param title name used in config file - * @param _value default value - * @param _min minimum - * @param _max maximum - */ - public SettingInt(String title, int _value, int _min, int _max) - { - - this(title, _value, _min, 1, _max); - } - /** - * - * @param title name used in config file - * @param _value default value - * @param _min minimum - * @param _step stepsize - * @param _max maximum - */ - public SettingInt(String title, int _value, int _min, int _step, int _max) - { - values.put("",_value); - defvalue = _value; - min=_min; - step=_step; - max=_max; - backendname = title; - - if (min > max) - { - int t = min; - min = max; - max = t; - } - } - - - public String toString(String context) { - return ""+get(context); - } - public void fromString(String s, String context) - { - values.put(context, new Integer(s)); - if(gui != null) - { - gui.update(); - } - ModSettings.dbgout("fromstring " +s); - } - - /** - * set and save value - * @param v value - */ - @Override - public void set(Integer v, String context) - { - ModSettings.dbgout("set " +v); - if (step > 1) - values.put(context, (int)(Math.round( (float)v /(float)step)*(float)step)); - else - values.put(context, v); - if (parent != null) - { - parent.save(context); - - } - if(gui != null) - { - gui.update(); - } - } - /** - * return current value. not really needed because value is public, but is nice to have - * @return - */ - @Override - public Integer get(String context) - { - if(values.get(context) != null) - return values.get(context); - else if (values.get("") != null) - return values.get(""); - else return defvalue; - } - - - -} diff --git a/src/SettingKey.java b/src/SettingKey.java deleted file mode 100644 index 206d302..0000000 --- a/src/SettingKey.java +++ /dev/null @@ -1,119 +0,0 @@ -import java.util.HashMap; - -import org.lwjgl.input.Keyboard; - - -public class SettingKey extends Setting { - - /** - * - * @param title name used in conf file - * @param key default keycode - */ - public SettingKey(String title,int key) - { - defvalue = key; - values.put("",key); - backendname = title; - } - /** - * - * @param title name used in conf file - * @param key default key - */ - public SettingKey(String title, String key) - { - this(title, Keyboard.getKeyIndex(key)); - } - - @Override - public String toString(String context) { - return Keyboard.getKeyName(get(context)); - } - - - - @Override - public void fromString(String s, String context) { - - if (s.equals("UNBOUND")) - values.put(context, Keyboard.KEY_NONE); - else - values.put(context,Keyboard.getKeyIndex(s)); - - if(gui != null) - { - gui.update(); - } - } - /** - * set and save value keycode version - used internally - * @param v value - */ - @Override - public void set(Integer v, String context) - { - values.put(context, v); - if (parent != null) - { - parent.save(context); - - } - if(gui != null) - { - gui.update(); - } - } - - /** - * set and save value keyname version - * @param v value - */ - public void set(String v, String context) - { - set(Keyboard.getKeyIndex(v), context); - } - public void set(String v) - { - set(v, ModSettings.currentContext); - } - - /** - * return current value. not really needed because value is public, but is nice to have - * @return - */ - @Override - public Integer get(String context) - { - if(values.get(context) != null) - { - return values.get(context); - } - else if (values.get("") != null) - { - return values.get(""); - } - else - { - return defvalue; - } - - } - - /** - * - * @return true if the key is down. ya think? - */ - public boolean isKeyDown(String context) - { - if (get(context) != -1) - { - return Keyboard.isKeyDown(get(context)); - } - return false; //mildly redundant - } - public boolean isKeyDown() - { - return isKeyDown(ModSettings.currentContext); - } -} diff --git a/src/SettingMulti.java b/src/SettingMulti.java deleted file mode 100644 index 14d4ea4..0000000 --- a/src/SettingMulti.java +++ /dev/null @@ -1,147 +0,0 @@ -import java.util.HashMap; - -import org.lwjgl.input.Keyboard; - - -public class SettingMulti extends Setting { - - public String[] labels; - /** - * - * @param title name to use in config file - * @param def default index - * @param _labels labels of each option - must be at least one - */ - public SettingMulti(String title, int def, String... _labels) - { - if (_labels.length == 0) - return;//should cause an error ... damnit can't actually throw - values.put("", def); - defvalue=def; - - labels = _labels; - - backendname = title; - } - /** - * - * @param title name to use in config file - * @param _labels labels of each option - must be at least one - */ - public SettingMulti(String title, String... _labels) - { - this(title, 0, _labels); - } - - /** - * now uses the label value instead of label idx - */ - @Override - public String toString(String context) { - return labels[get(context)]; - } - /** - * now uses the label value instead of label idx - */ - @Override - public void fromString(String s, String context) - { - int x=-1; - for (int i=0;i= labels.length) - { - tempvalue -= labels.length; - } - set(tempvalue, context); - } - public void next() - { - next(ModSettings.currentContext); - } -} diff --git a/src/SettingText.java b/src/SettingText.java deleted file mode 100644 index c59335b..0000000 --- a/src/SettingText.java +++ /dev/null @@ -1,65 +0,0 @@ -import java.util.HashMap; - - -public class SettingText extends Setting { - - /** - * - * @param title name in config file - * @param defaulttext default text - */ - public SettingText(String title, String defaulttext) - { - values.put("", defaulttext); - defvalue = defaulttext; - - backendname = title; - } - - @Override - public void fromString(String s, String context) { - values.put(context, s); - if(gui != null) - { - gui.update(); - } - } - - @Override - public String toString(String context) { - return get(context); - } - /** - * return current value. not really needed because value is public, but is nice to have - * @return - */ - @Override - public String get(String context) - { - if(values.get(context) != null) - return values.get(context); - else if (values.get("") != null) - return values.get(""); - else return defvalue; - } - /** - * set and save value - * @param v value - */ - @Override - public void set(String v, String context) - { - values.put(context, v); - - if (parent != null) - { - parent.save(context); - - } - if(gui != null) - { - gui.update(); - } - } - -} diff --git a/src/Subscreen.java b/src/Subscreen.java deleted file mode 100644 index 2a9e0b6..0000000 --- a/src/Subscreen.java +++ /dev/null @@ -1,56 +0,0 @@ -import java.util.ArrayList; - -import de.matthiasmann.twl.Button; -import de.matthiasmann.twl.Widget; -import de.matthiasmann.twl.model.SimpleButtonModel; - - -public class Subscreen extends Button implements Runnable { - public ArrayList children = new ArrayList(); - - public Widget subscreenwindow; - public Widget subsubWindow; - public Subscreen(String menutitle, String buttontitle) - { - super(buttontitle); - setTheme("/button"); - subsubWindow = new WidgetClassicTwocolumn(); - subscreenwindow = new WidgetSimplewindow(subsubWindow,menutitle); - SimpleButtonModel s = new SimpleButtonModel(); - s.addActionCallback(this); - setModel(s); - } - public Subscreen(String menutitle, String buttontitle, Widget subwidget) - { - super(buttontitle); - setTheme("/button"); - subsubWindow = subwidget; - subscreenwindow = new WidgetSimplewindow(subsubWindow,menutitle); - SimpleButtonModel s = new SimpleButtonModel(); - s.addActionCallback(this); - setModel(s); - } - public Subscreen(String buttontitle, Widget subwidget) - { - super(buttontitle); - setTheme("/button"); - subsubWindow = subwidget; - subscreenwindow = subwidget; - SimpleButtonModel s = new SimpleButtonModel(); - s.addActionCallback(this); - setModel(s); - } - - public void add(Widget w) - { - subsubWindow.add(w); - } - - public void run() - { - - GuiModScreen.show(subscreenwindow); - } - - -} diff --git a/src/WidgetBoolean.java b/src/WidgetBoolean.java deleted file mode 100644 index 910608c..0000000 --- a/src/WidgetBoolean.java +++ /dev/null @@ -1,78 +0,0 @@ -import de.matthiasmann.twl.Button; -import de.matthiasmann.twl.Widget; -import de.matthiasmann.twl.model.SimpleButtonModel; - - - - -public class WidgetBoolean extends WidgetSetting implements Runnable { - - public String ttext; - public String ftext; - public Button b; - - public SettingBoolean value = null; - - public WidgetBoolean(SettingBoolean setting, String title) - { - this(setting, title, "true", "false"); - } - public WidgetBoolean(SettingBoolean setting, String title, String _ttext, String _ftext) - { - super(title); - setTheme(""); - ttext = _ttext; - ftext = _ftext; - SimpleButtonModel bmodel = new SimpleButtonModel(); - b = new Button(bmodel); - bmodel.addActionCallback(this); - add(b); - value = setting; - value.gui = this; - update(); - } - - - public String userString() - { - if(value != null) - { - if (nicename.length() > 0) - return String.format("%s: %s", nicename, value.get(ModSettingScreen.guicontext) ? ttext : ftext); - else - return value.get(ModSettingScreen.guicontext) ? ttext : ftext; - } - else - { - if (nicename.length() > 0) - return String.format("%s: %s", nicename, "no value"); - else - return "no value or title"; - } - } - /* - public String toString() { - return (value ? "true" : "false"); - } - public void fromString(String s) - { - value = s.equals("true"); - }*/ - //@Override - public void update() { - // TO DO Auto-generated method stub - b.setText(userString()); - } - @Override - public void run() { - // TO DO Auto-generated method stub - if(value != null) - value.set(!value.get(ModSettingScreen.guicontext), ModSettingScreen.guicontext); - update(); - //if(parentmod != null) - // parentmod.save(); - GuiModScreen.clicksound(); - //ModSettings.dbgout("safe"); - } - -} diff --git a/src/WidgetClassicTwocolumn.java b/src/WidgetClassicTwocolumn.java deleted file mode 100644 index 78676ac..0000000 --- a/src/WidgetClassicTwocolumn.java +++ /dev/null @@ -1,71 +0,0 @@ -import de.matthiasmann.twl.Button; -import de.matthiasmann.twl.Widget; - -public class WidgetClassicTwocolumn extends Widget { - public int defaultwidth = 150; - public int defaultheight = 20; - public int defaultpad = 4; - public boolean overridewidth = true; - public boolean overrideheight = true; - - public WidgetClassicTwocolumn(Widget... ws) - { - for(int i=0; i> 1) + vpad); - } - else - { - w.setPosition( getX()+getWidth()/2 + (split/2), getY() + (defaultheight+defaultpad) * (i >> 1) + vpad); - } - - } - } - - public int getPreferredWidth() - { - return getParent().getWidth(); - } - - public int getPreferredHeight() - { - return (defaultheight+defaultpad) * (1 * (getNumChildren() + 1)>>1) + vpad*2; - } -} diff --git a/src/WidgetClassicWindow.java b/src/WidgetClassicWindow.java deleted file mode 100644 index 279df6b..0000000 --- a/src/WidgetClassicWindow.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @deprecated Use WSimpleWindow - * @author blendmaster - * - */ -public class WidgetClassicWindow extends WidgetSimplewindow { - - @Deprecated - public void init() - { - super.init(); - System.err.println("WidgetClassicWindow is deprecated, please update mods using it to use WSimplewindow"); - } -} diff --git a/src/WidgetFloat.java b/src/WidgetFloat.java deleted file mode 100644 index a09c26c..0000000 --- a/src/WidgetFloat.java +++ /dev/null @@ -1,103 +0,0 @@ - -import de.matthiasmann.twl.model.SimpleFloatModel; - - - - -public class WidgetFloat extends WidgetSetting implements Runnable { - - //public boolean isSlider; - //public String name; - - - public int displaylen; - public String formatstring; - public WidgetSlider slider; - - public SettingFloat value; - - public WidgetFloat(SettingFloat s,String title) - { - - this( s,title, 2, ""); - } - public WidgetFloat(SettingFloat s, String title, int _displaylen) - { - this( s,title, _displaylen, ""); - } - public WidgetFloat(SettingFloat setting, String title, int _displaylen, String formatstr) - { - super(title); - setTheme(""); - displaylen=_displaylen; - formatstring=formatstr; - - - - - value = setting; - value.gui = this; - SimpleFloatModel smodel = new SimpleFloatModel(value.min, value.max, value.get()); - smodel.addCallback(this); - - slider = new WidgetSlider(smodel); - - if(value.step > 0.0f && value.step <= value.max) - slider.setStepSize(value.step); - slider.setFormat(String.format("%s: %%.%df",nicename,displaylen)); - - //smodel. - //s. - //l.setLabelFor(s); - //s.getChild(index) - //setDepthFocusTraversal(false); - //s.setTheme(""); - add(slider); - update(); - } - - /*public boolean handleEvent(Event e) - { - return s.handleEvent(e); - }*/ - - public String userString() - { - String l = String.format("%02d", displaylen); - return String.format("%s: %."+l+"f", nicename, value); - } - - /*public float floatValue() - { - //System.out.println("floatValue() returning "+((value-min)/(max-min))); - //System.out.println(""+max+" "+min+" "+value+" "+(max-min)+" "+(value-min)); - return Math.min(Math.max((value-min)/(max-min),0.0f),1.0f); - } - public void setFloatValue(float f) - { - f -= min; - //if (step > 0.0) - // f = (float)((int)(f/step))*step; - f += min; - value = f; - //update(); - }*/ - /* - */ - //@Override - public void update() { - // TODO Auto-generated method stub - slider.setValue(value.get(ModSettingScreen.guicontext)); - slider.setFormat(String.format("%s: %%.%df",nicename,displaylen)); - } - @Override - public void run() { - // TODO Auto-generated method stub - //System.out.println(s.getValue()); - value.set(slider.getValue(), ModSettingScreen.guicontext); - //if(parentmod != null) - // parentmod.save(); - } - - -} diff --git a/src/WidgetInt.java b/src/WidgetInt.java deleted file mode 100644 index ae3c3ca..0000000 --- a/src/WidgetInt.java +++ /dev/null @@ -1,192 +0,0 @@ -import de.matthiasmann.twl.ValueAdjusterFloat; -import de.matthiasmann.twl.ValueAdjusterInt; -import de.matthiasmann.twl.model.SimpleFloatModel; -import de.matthiasmann.twl.model.SimpleIntegerModel; - - -public class WidgetInt extends WidgetSetting implements Runnable { - - //public boolean isSlider; - //public String name; - public int displaylen; - public String formatstring; - //public static final boolean hasValue = true; - //public ValueAdjusterFloat s; - public WidgetSlider s; - - public SettingInt value; - - public WidgetInt(SettingInt setting, String title) - { - - this(setting, title, 15); - } - public WidgetInt(SettingInt setting, String title, int _displaylen) - { - super(title); - setTheme(""); - displaylen=_displaylen; - value = setting; - - value.gui = this; - - SimpleFloatModel smodel = new SimpleFloatModel((float)value.min, (float)value.max, (float)value.get()); - s = new WidgetSlider(smodel); - s.setFormat(String.format("%s: %%.0f",nicename)); - - if(value.step > 1 && value.step <= value.max) - s.setStepSize((float)value.step); - //smodel. - //s. - smodel.addCallback(this); - //l.setLabelFor(s); - //s.getChild(index) - //setDepthFocusTraversal(false); - //s.setTheme(""); - add(s); - update(); - } - /* - public IntSliderSetting(int _value, int _min, int _step, int _max, String formatstr) - { - super(""); - value=_value; - min=_min; - step=_step; - max=_max; - displaylen=5; - formatstring=formatstr; - isSlider = true; - init(); - }*/ - - /*public boolean handleEvent(Event e) - { - return s.handleEvent(e); - }*/ - - public String userString() - { - String l = String.format("%d", displaylen); - return String.format("%s: %."+l+"d", nicename, value.get(ModSettingScreen.guicontext)); - } - - /*public String toString() { - return ""+value; - } - public void fromString(String s) - { - value = new Integer(s); - }*/ - //@Override - public void update() { - // TODO Auto-generated method stub - s.setValue((float)value.get(ModSettingScreen.guicontext)); - s.setFormat(String.format("%s: %%.0f",nicename)); - ModSettings.dbgout("update " +value.get(ModSettingScreen.guicontext)+" -> "+(int)s.getValue()); - } - @Override - public void run() { - // TODO Auto-generated method stub - //System.out.println(s.getValue()); - ModSettings.dbgout("run " +(int)s.getValue()); - value.set((int)s.getValue(), ModSettingScreen.guicontext); - //if(parentmod != null) - // parentmod.save(); - } - - -} -/* - -public class IntSliderSetting extends FloatSliderSetting { - public int value; - public int step; - public int min; - public int max; - public int displaylen; - public static final boolean hasValue = true; - - - public IntSliderSetting() - { - value=0; - min=0; - step=0; - max=100; - displaylen=0; - isSlider = true; - } - public IntSliderSetting(int _value) - { - value=_value; - min=0; - step=0; - max=100; - displaylen=0; - isSlider = true; - } - public IntSliderSetting(int _value, int _min, int _max) - { - value=_value; - min=_min; - max=_max; - step=0; - displaylen=0; - isSlider = true; - } - public IntSliderSetting(int _value, int _min, int _step, int _max) - { - value=_value; - min=_min; - step=_step; - max=_max; - displaylen=0; - isSlider = true; - } - public IntSliderSetting(int _value, int _min, int _step, int _max, int _displaylen) - { - value=_value; - min=_min; - step=_step; - max=_max; - displaylen=_displaylen; - isSlider = true; - } - - - - - public String userString() - { - String l = ""; - if(displaylen > 0) - { - l = String.format("%02d", displaylen); - } - return String.format("%s: %"+l+"d", nicename, value); - } - - public float floatValue() - { - return Math.min(Math.max(((float)value-(float)min)/((float)max-(float)min),0.0f),1.0f); - } - @Override - public void setFloatValue(float f) - { - f *= (float)max - (float)min; - if ((float)step > 0.0) - f = (float)((int)(f/(float)step))*(float)step; - f += (float)min; - value = (int)f; - - } - public String toString() { - return ""+value; - } - public void fromString(String s) - { - value = new Float(s).intValue(); - } -} -*/ \ No newline at end of file diff --git a/src/WidgetKeybinding.java b/src/WidgetKeybinding.java deleted file mode 100644 index 9b7446a..0000000 --- a/src/WidgetKeybinding.java +++ /dev/null @@ -1,131 +0,0 @@ - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -import org.lwjgl.input.*; - -import de.matthiasmann.twl.Button; -import de.matthiasmann.twl.Event; -import de.matthiasmann.twl.ToggleButton; -import de.matthiasmann.twl.Widget; -import de.matthiasmann.twl.model.BooleanModel; -import de.matthiasmann.twl.model.SimpleBooleanModel; - -public class WidgetKeybinding extends WidgetSetting implements Runnable { - - public SettingKey value; - - //public boolean isdown = false; - public SimpleBooleanModel bmodel; - public ToggleButton b; - - public int CLEARKEY = Keyboard.KEY_DELETE; - public int NEVERMINDKEY = Keyboard.KEY_ESCAPE; - - public WidgetKeybinding(SettingKey setting, String title) - { - super(title); - setTheme(""); - value = setting; - - value.gui = this; - - bmodel = new SimpleBooleanModel(false); - b = new ToggleButton(bmodel); //bs? - //b.addPropertyChangeListener("value",this); - //this.handleEvent( - //this.keyboardFocusLost() - add(b); - update(); - } - - public boolean handleEvent(Event evt) - { - if((evt.isKeyEvent() && !evt.isKeyPressedEvent()) && bmodel.getValue()) - { - System.out.println(Keyboard.getKeyName(evt.getKeyCode())); - int tmpvalue = evt.getKeyCode(); - if (tmpvalue == CLEARKEY) - { - value.set(Keyboard.KEY_NONE, ModSettingScreen.guicontext); - } - else if (tmpvalue != NEVERMINDKEY) - { - value.set(tmpvalue, ModSettingScreen.guicontext); - } - bmodel.setValue(false); - //if (parentmod != null) - // parentmod.save(); - update(); - GuiModScreen.clicksound(); - return true; - } - - return false; - } - - public void keyboardFocusLost() - { - GuiModScreen.clicksound(); - bmodel.setValue(false); - } - //@Override - public String userString() { - - return String.format("%s: %s",nicename,Keyboard.getKeyName(value.get(ModSettingScreen.guicontext))); - } - /*@Override - public String toString() { - return Keyboard.getKeyName(value); - } - - - - @Override - public void fromString(String s) { - - if (s.equals("UNBOUND")) - value = Keyboard.KEY_NONE; - else - value = Keyboard.getKeyIndex(s); - } - - */ - - //@Override - public void update() { - // TODO Auto-generated method stub - b.setText(userString()); - } - - @Override - public void run() { - // TODO Auto-generated method stub - //boolean isdown = bmodel.getValue(); - //b//oolean isfocused = b.isActive(); - GuiModScreen.clicksound(); - - //ModSettings.dbgout("run: "+isdown+" "+isfocused); - } - - - /*@Override - public void addCallback(Runnable callback) { - // TODO Auto-generated method stub - - } - @Override - public boolean getValue() { - return isdown; - } - @Override - public void removeCallback(Runnable callback) { - // TODO Auto-generated method stub - - } - @Override - public void setValue(boolean value) { - isdown = value; - }*/ - -} diff --git a/src/WidgetMulti.java b/src/WidgetMulti.java deleted file mode 100644 index e047060..0000000 --- a/src/WidgetMulti.java +++ /dev/null @@ -1,73 +0,0 @@ -import de.matthiasmann.twl.Button; -import de.matthiasmann.twl.Widget; -import de.matthiasmann.twl.model.SimpleButtonModel; - - - - -public class WidgetMulti extends WidgetSetting implements Runnable { - - //public boolean isSlider; - //public String name; - public SettingMulti value; - public Button b = null; - - - - public WidgetMulti(SettingMulti setting, String title) - { - super(title); - setTheme(""); - value=setting; - value.gui=this; - - - SimpleButtonModel model = new SimpleButtonModel(); - b = new Button(model); - model.addActionCallback(this); - add(b); - update(); - } - - - - - public String userString() - { - if (nicename.length() > 0) - return String.format("%s: %s", nicename, value.getLabel(ModSettingScreen.guicontext)); - else - return value.getLabel(ModSettingScreen.guicontext); - } - - /* public String toString() { - return ""+value; - } - public void fromString(String s) - { - value = new Float(s).intValue(); - } */ - - //@Override - public void update() { - // TODO Auto-generated method stub - b.setText(userString()); - ModSettings.dbgout("multi update "+userString()); - } - - @Override - public void run() { // change - // TODO Auto-generated method stub - value.next(ModSettingScreen.guicontext); - update(); - - //if(parentmod != null) - // parentmod.save(); - GuiModScreen.clicksound(); - } - - - - - -} diff --git a/src/WidgetSetting.java b/src/WidgetSetting.java deleted file mode 100644 index 5eca9bf..0000000 --- a/src/WidgetSetting.java +++ /dev/null @@ -1,49 +0,0 @@ -import java.util.ArrayList; - -import de.matthiasmann.twl.Widget; - - -public abstract class WidgetSetting extends Widget { - - public String nicename; - - //public Setting backend; - - public static ArrayList all = new ArrayList(); - - public WidgetSetting(String _nicename) - { - nicename = _nicename; - all.add(this); - } - - public void add(Widget child) - { - String T=child.getTheme(); - if (T.length() == 0) - child.setTheme("/-defaults"); - else if(!T.substring(0, 1).equals("/")) - child.setTheme("/"+T); - super.add(child); - } - @Override - public void layout() - { - for(int i=0; i wiggets = new ArrayList(); - protected ArrayList heights = new ArrayList(); - protected ArrayList widths = new ArrayList(); - - public WidgetSingleRow(int defwidth, int defheight, Widget... widgets_) - { - setTheme(""); - defaultwidth = defwidth; - defaultheight = defheight; - for(int i=0; i=0) - return heights.get(idx); - else - return wiggets.get(idx).getPreferredHeight(); - } - private int getWidth(int idx) - { - if(widths.get(idx)>=0) - return widths.get(idx); - else - return wiggets.get(idx).getPreferredWidth(); - } - @Override - public int getPreferredWidth() - { - int totalwidth=(widths.size()-1)*xSpacing; - totalwidth = totalwidth>=0?totalwidth:0; - for(int i=0; imaxheights) - maxheights = getHeight(i); - return maxheights; - } - public void layout() - { - int curXpos=0; - for(int i=0; i= 0) - { - setmode = 1; - e.setText(value.get(ModSettingScreen.guicontext)); - setmode = 0; - } - ModSettings.dbgout(String.format("update %s", e.getText())); - } - - -} diff --git a/src/co.java b/src/co.java deleted file mode 100644 index d5d7d7e..0000000 --- a/src/co.java +++ /dev/null @@ -1,94 +0,0 @@ -// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov. -// Jad home page: http://www.kpdus.com/jad.html -// Decompiler options: packimports(3) fieldsfirst safe -// Source File Name: SourceFile - -import java.util.List; -import net.minecraft.client.Minecraft; - -public class co extends da { - - private da i; - protected String a; - private kv j; - private static ht l[]; - - public co(da da1, kv kv1) { - a = "Options"; - i = da1; - j = kv1; - } - - public void b() { - nh nh1 = nh.a(); - a = nh1.a("options.title"); - int k = 0; - ht aht[] = l; - int i1 = aht.length; - - for(int j1 = 0; j1 < i1; j1++) { - ht ht1 = aht[j1]; - - if(!ht1.a()) - e.add(((Object) (new ab(ht1.c(), (c / 2 - 155) + (k % 2) * 160, d / 6 + 24 * (k >> 1), ht1, j.c(ht1))))); - else - e.add(((Object) (new vz(ht1.c(), (c / 2 - 155) + (k % 2) * 160, d / 6 + 24 * (k >> 1), ht1, j.c(ht1), j.a(ht1))))); - - k++; - } - - // TODO: update (d / 6 + 96 + 12) - e.add(((Object) (new ke(101, c / 2 - 100, d / 6 + 96, nh1.a("options.video"))))); - // TODO: update (d / 6 + 120 + 12) - e.add(((Object) (new ke(100, c / 2 - 100, d / 6 + 120, nh1.a("options.controls"))))); - // TODO: update (new) - e.add(((Object) (new ke(300, c / 2 - 100, d / 6 + 144, "Global Mod Settings")))); - e.add(((Object) (new ke(200, c / 2 - 100, d / 6 + 168, nh1.a("gui.done"))))); - } - - protected void a(ke ke1) { - if(!ke1.g) - return; - - if(ke1.f < 100 && (ke1 instanceof ab)) { - j.a(((ab)ke1).a(), 1); - ke1.e = j.c(ht.a(ke1.f)); - } - - if(ke1.f == 101) { - b.z.b(); - b.a(((da) (new nj(((da) (this)), j)))); - } - - if(ke1.f == 100) { - b.z.b(); - b.a(((da) (new up(((da) (this)), j)))); - } - - if(ke1.f == 200) { - b.z.b(); - b.a(i); - } - - //TODO: update - if (ke1.f == 300) - { - b.z.b(); - ModSettingScreen.guicontext = ""; - WidgetSetting.updateAll(); - GuiModScreen.show(new GuiModSelect(this)); - } - } - - public void a(int k, int i1, float f) { - i(); - a(g, a, c / 2, 20, 0xffffff); - super.a(k, i1, f); - } - - static { - l = (new ht[] { - ht.a, ht.b, ht.c, ht.d, ht.j - }); - } -} diff --git a/theme-dev/font/default.png b/theme-dev/font/default.png new file mode 100644 index 0000000..fb7686e Binary files /dev/null and b/theme-dev/font/default.png differ diff --git a/theme-dev/gui/background.png b/theme-dev/gui/background.png new file mode 100644 index 0000000..b29e009 Binary files /dev/null and b/theme-dev/gui/background.png differ diff --git a/theme-dev/gui/container.png b/theme-dev/gui/container.png new file mode 100644 index 0000000..bd1d383 Binary files /dev/null and b/theme-dev/gui/container.png differ diff --git a/theme-dev/gui/crafting.png b/theme-dev/gui/crafting.png new file mode 100644 index 0000000..da83118 Binary files /dev/null and b/theme-dev/gui/crafting.png differ diff --git a/theme-dev/gui/furnace.png b/theme-dev/gui/furnace.png new file mode 100644 index 0000000..a5834e1 Binary files /dev/null and b/theme-dev/gui/furnace.png differ diff --git a/theme-dev/gui/gui.png b/theme-dev/gui/gui.png new file mode 100644 index 0000000..81af329 Binary files /dev/null and b/theme-dev/gui/gui.png differ diff --git a/theme-dev/gui/icons.png b/theme-dev/gui/icons.png new file mode 100644 index 0000000..73fe9bb Binary files /dev/null and b/theme-dev/gui/icons.png differ diff --git a/theme-dev/gui/inventory.png b/theme-dev/gui/inventory.png new file mode 100644 index 0000000..0b5f291 Binary files /dev/null and b/theme-dev/gui/inventory.png differ diff --git a/theme-dev/gui/items.png b/theme-dev/gui/items.png new file mode 100644 index 0000000..e415946 Binary files /dev/null and b/theme-dev/gui/items.png differ diff --git a/theme-dev/gui/logo.png b/theme-dev/gui/logo.png new file mode 100644 index 0000000..b7c2879 Binary files /dev/null and b/theme-dev/gui/logo.png differ diff --git a/theme-dev/gui/particles.png b/theme-dev/gui/particles.png new file mode 100644 index 0000000..ac7e39f Binary files /dev/null and b/theme-dev/gui/particles.png differ diff --git a/theme-dev/gui/slot.png b/theme-dev/gui/slot.png new file mode 100644 index 0000000..4eb39ba Binary files /dev/null and b/theme-dev/gui/slot.png differ diff --git a/theme-dev/gui/trap.png b/theme-dev/gui/trap.png new file mode 100644 index 0000000..e8d25ab Binary files /dev/null and b/theme-dev/gui/trap.png differ diff --git a/theme-dev/gui/unknown_pack.png b/theme-dev/gui/unknown_pack.png new file mode 100644 index 0000000..3a45a90 Binary files /dev/null and b/theme-dev/gui/unknown_pack.png differ diff --git a/scrollwindow.xcf.bz2 b/theme-dev/scrollwindow.xcf.bz2 similarity index 100% rename from scrollwindow.xcf.bz2 rename to theme-dev/scrollwindow.xcf.bz2 diff --git a/theme/scrollwindow.png b/theme/scrollwindow.png index 6b30b65..c8b1020 100644 Binary files a/theme/scrollwindow.png and b/theme/scrollwindow.png differ diff --git a/theme/twlGuiTheme.xml b/theme/twlGuiTheme.xml index 0b4162f..0a0ea2e 100644 --- a/theme/twlGuiTheme.xml +++ b/theme/twlGuiTheme.xml @@ -33,11 +33,11 @@