Abstracted gui option list and added patreon button

This commit is contained in:
Chicken-Bomes committed 2014-08-02 22:48:45 +10:00
1 parent ff5456cbd1
commit d7753d2e78
18 files changed
+253 -149

No files matched your search

+2 -2
View File
@@ -1,5 +1,5 @@
mc_version=1.7.10
forge_version=10.13.0.1151
ccl_version=1.1.1.96
ccc_version=1.0.2.+
mod_version=1.0.2
ccc_version=1.0.3.+
mod_version=1.0.3
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+8 -4
View File
@@ -1,13 +1,17 @@
[
[
{
"modid": "NotEnoughItems",
"name": "Not Enough Items",
"version": "${version}",
"mcversion": "${mc_version}",
"description": "Recipe Viewer, Inventory Manager, Item Spawner, Cheats and more.",
"description": "Recipe Viewer, Inventory Manager, Item Spawner, Cheats and more.
$plugins
§bSupporters:",
"url": "http://www.minecraftforum.net/topic/909223",
"credits": "Alexandria - Original Idea",
"authors": [ "ChickenBones" ],
"credits": "Alexandria - original idea",
"authorList": [ "ChickenBones" ],
"dependencies": [
"CodeChickenCore"
]
+2
View File
@@ -1,6 +1,7 @@
package codechicken.nei;
import codechicken.core.ClientUtils;
import codechicken.core.GuiModListScroll;
import codechicken.lib.packet.PacketCustom;
import codechicken.nei.api.API;
import codechicken.nei.api.ItemInfo;
@@ -115,6 +116,7 @@ public class ClientHandler
public static void load() {
instance = new ClientHandler();
GuiModListScroll.register("NotEnoughItems");
PacketCustom.assignHandler(NEICPH.channel, new NEICPH());
FMLCommonHandler.instance().bus().register(instance);
MinecraftForge.EVENT_BUS.register(instance);
+2 -8
View File
@@ -22,23 +22,17 @@ public class ItemList
/**
* Fields are replaced atomically and contents never modified.
*/
public static List<ItemStack> items = new ArrayList<ItemStack>();
public static volatile List<ItemStack> items = new ArrayList<ItemStack>();
/**
* Fields are replaced atomically and contents never modified.
*/
public static ListMultimap<Item, ItemStack> itemMap = ArrayListMultimap.create();
public static volatile ListMultimap<Item, ItemStack> itemMap = ArrayListMultimap.create();
/**
* Updates to this should be synchronised on this
*/
public static final List<ItemFilterProvider> itemFilterers = new LinkedList<ItemFilterProvider>();
public static final List<ItemsLoadedCallback> loadCallbacks = new LinkedList<ItemsLoadedCallback>();
private static boolean loading = false;
private static boolean reload = false;
private static boolean filtering = false;
private static boolean refilter = false;
private static HashSet<Item> erroredItems = new HashSet<Item>();
private static HashSet<String> stackTraces = new HashSet<String>();
+3
View File
@@ -17,6 +17,9 @@ import static codechicken.lib.gui.GuiDraw.drawRect;
public class ItemPanel extends Widget
{
/**
* Should not be externally modified, use updateItemList
*/
public static ArrayList<ItemStack> items = new ArrayList<ItemStack>();
/**
* Swapped into visible items on update
+1 -1
View File
@@ -272,7 +272,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
@Override
public boolean onButtonPress(boolean rightclick) {
if (!rightclick) {
getOptionList().showGui(getGuiContainer());
getOptionList().openGui(getGuiContainer(), false);
return true;
}
return false;
+14 -3
View File
@@ -9,6 +9,7 @@ import codechicken.nei.config.*;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.obfuscator.ObfuscationRun;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -151,16 +152,26 @@ public class NEIClientConfig
}
private static void linkOptionList() {
getOptionList().bindConfig(new IConfigSetHolder()
OptionList.setOptionList(new OptionList("nei.options")
{
@Override
public ConfigSet globalConfigSet() {
return global;
}
@Override
public ConfigSet worldConfigSet() {
return world;
}
@Override
public ConfigSet globalConfigSet() {
return global;
public OptionList configBase() {
return this;
}
@Override
public GuiOptionList getGui(GuiScreen parent, OptionList list, boolean world) {
return new GuiNEIOptionList(parent, list, world);
}
});
}
+14 -9
View File
@@ -28,7 +28,7 @@ public class NEIModContainer extends DummyModContainer
public NEIModContainer() {
super(MetadataCollection.from(MetadataCollection.class.getResourceAsStream("/neimod.info"), "NotEnoughItems").getMetadataForId("NotEnoughItems", null));
getMetadata();
loadMetadata();
}
@Override
@@ -43,24 +43,29 @@ public class NEIModContainer extends DummyModContainer
return new LinkedList<ArtifactVersion>(getRequirements());
}
private String description;
private void loadMetadata() {
description = super.getMetadata().description;
}
@Override
public ModMetadata getMetadata() {
ModMetadata meta = super.getMetadata();
meta.description = "Recipe Viewer, Inventory Manager, Item Spawner, Cheats and more.\n"+ EnumChatFormatting.WHITE+"\n";
String s_plugins = "";
if (plugins.size() == 0) {
meta.description += EnumChatFormatting.RED+"No installed plugins.";
s_plugins += EnumChatFormatting.RED+"No installed plugins.";
} else {
meta.description += EnumChatFormatting.GREEN+"Installed plugins: ";
s_plugins += EnumChatFormatting.GREEN+"Installed plugins: ";
for (int i = 0; i < plugins.size(); i++) {
if (i > 0)
meta.description += ", ";
s_plugins += ", ";
IConfigureNEI plugin = plugins.get(i);
meta.description += plugin.getName() + " " + plugin.getVersion();
s_plugins += plugin.getName() + " " + plugin.getVersion();
}
meta.description += ".";
s_plugins += ".";
}
ModMetadata meta = super.getMetadata();
meta.description = description.replace("$plugins", s_plugins);
return meta;
}
+2 -2
View File
@@ -193,7 +193,7 @@ public class NEIServerConfig
continue;
int delim = s.lastIndexOf('=');
if(delim < 0) {
System.err.println("line "+line+": Missing =");
logger.error("line "+line+": Missing =");
continue;
}
try {
@@ -203,7 +203,7 @@ public class NEIServerConfig
values.add(s2.trim());
bannedItems.put(InventoryUtils.loadPersistant(key), values);
} catch (Exception e) {
System.err.println("line "+line+": "+e.getMessage());
logger.error("line "+line+": "+e.getMessage());
}
}
r.close();
+1 -1
View File
@@ -12,7 +12,7 @@ public class NEIInfo
public static void load(World world) {
OptionCycled modeOption = (OptionCycled) NEIClientConfig.getOptionList().getOption("inventory.cheatmode");
modeOption.parent.synthesizeEnvironment();
modeOption.parent.synthesizeEnvironment(false);
if(!modeOption.optionValid(modeOption.value())) {
modeOption.copyGlobals();
modeOption.cycle();
+2 -2
View File
@@ -3,6 +3,7 @@ package codechicken.nei.config;
import codechicken.core.CommonUtils;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
@@ -41,8 +42,7 @@ public abstract class DataDumper extends Option
NEIClientUtils.printChatMessage(dumpMessage(file));
} catch (Exception e) {
System.err.println("Error dumping " + renderName() + " mode: " + getMode());
e.printStackTrace();
NEIClientConfig.logger.error("Error dumping " + renderName() + " mode: " + getMode(), e);
}
}
@@ -0,0 +1,54 @@
package codechicken.nei.config;
import codechicken.core.gui.GuiCCButton;
import codechicken.nei.NEIClientConfig;
import net.minecraft.client.gui.GuiConfirmOpenLink;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNoCallback;
import java.awt.*;
import java.net.URI;
public class GuiNEIOptionList extends GuiOptionList implements GuiYesNoCallback
{
private GuiCCButton patreonButton;
public GuiNEIOptionList(GuiScreen parent, OptionList optionList, boolean world) {
super(parent, optionList, world);
}
@Override
public void resize() {
super.resize();
patreonButton.x = width-73;
patreonButton.y = height-23;
}
@Override
public void addWidgets() {
super.addWidgets();
add(patreonButton = new PatreonButton(0, 0, 70, 20).setActionCommand("patreon"));
}
@Override
public void actionPerformed(String ident, Object... params) {
if (ident.equals("patreon")) {
GuiConfirmOpenLink gui = new GuiConfirmOpenLink(this, "patreon.com/cb", 0, true);
gui.func_146358_g();
mc.displayGuiScreen(gui);
} else
super.actionPerformed(ident, params);
}
@Override
public void confirmClicked(boolean yes, int id) {
if(yes && id == 0) {
try {
Desktop.getDesktop().browse(new URI("http://patreon.com/cb"));
} catch (Exception e) {
NEIClientConfig.logger.error("Failed to open patreon page", e);
}
}
mc.displayGuiScreen(this);
}
}
+19 -15
View File
@@ -6,10 +6,13 @@ import codechicken.core.gui.GuiScrollSlot;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.LayoutManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiConfirmOpenLink;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNoCallback;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
@@ -173,13 +176,13 @@ public class GuiOptionList extends GuiScreenWidget
}
}
private final GuiScreen parent;
private final OptionList optionList;
private boolean world;
protected final GuiScreen parent;
protected final OptionList optionList;
protected boolean world;
private OptionScrollSlot slot;
private GuiCCButton backButton;
private GuiCCButton worldButton;
protected OptionScrollSlot slot;
protected GuiCCButton backButton;
protected GuiCCButton worldButton;
public GuiOptionList(GuiScreen parent, OptionList optionList, boolean world) {
this.parent = parent;
@@ -193,14 +196,16 @@ public class GuiOptionList extends GuiScreenWidget
ySize = height;
super.initGui();
if (slot != null) {
slot.resize();
backButton.width = Math.min(200, width - 40);
backButton.x = (width - backButton.width) / 2;
backButton.y = height - 25;
worldButton.width = 60;
worldButton.x = width - worldButton.width - 15;
}
}
@Override
public void resize() {
slot.resize();
backButton.width = Math.min(200, width - 40);
backButton.x = (width - backButton.width) / 2;
backButton.y = height - 25;
worldButton.width = 60;
worldButton.x = width - worldButton.width - 15;
}
@Override
@@ -208,7 +213,6 @@ public class GuiOptionList extends GuiScreenWidget
add(slot = new OptionScrollSlot());
add(backButton = new GuiCCButton(0, 0, 0, 20, translateToLocal("nei.options.back")).setActionCommand("back"));
add(worldButton = new GuiCCButton(0, 2, 0, 16, worldButtonName()).setActionCommand("world"));
initGui();
}
private String worldButtonName() {
@@ -1,7 +0,0 @@
package codechicken.nei.config;
public interface IConfigSetHolder
{
public ConfigSet worldConfigSet();
public ConfigSet globalConfigSet();
}
+8 -3
View File
@@ -45,16 +45,21 @@ public abstract class Option
return 20;
}
private <T> T assertParentOverride(T elem) {
if(elem == null) throw new IllegalStateException("Option "+fullName()+" does not have a defined parent list. Use OptionList.setOptionList to insert a parent");
return elem;
}
public ConfigSet globalConfigSet() {
return parent.globalConfigSet();
return assertParentOverride(parent.globalConfigSet());
}
public ConfigSet worldConfigSet() {
return parent.worldConfigSet();
return assertParentOverride(parent.worldConfigSet());
}
public OptionList configBase() {
return parent.configBase();
return assertParentOverride(parent.configBase());
}
/**
+98 -92
View File
@@ -1,5 +1,6 @@
package codechicken.nei.config;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.config.GuiOptionList.OptionScrollSlot;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
@@ -9,147 +10,152 @@ import java.util.HashMap;
public class OptionList extends OptionButton
{
public static final OptionList top = new OptionList(null);
public static OptionList getOptionList(String fullName)
public static final OptionList root = new RootOptionList();
private static class RootOptionList extends OptionList
{
Option o = top.getOption(fullName);
if(o == null)
top.addOption(o = new OptionList(fullName));
public RootOptionList() {
super(null);
}
@Override
public ConfigSet globalConfigSet() {
return null;
}
@Override
public ConfigSet worldConfigSet() {
return null;
}
@Override
public OptionList configBase() {
return null;
}
@Override
public GuiOptionList getGui(GuiScreen parent, OptionList list, boolean world) {
return new GuiOptionList(parent, list, world);
}
}
public static OptionList getOptionList(String fullName) {
Option o = root.getOption(fullName);
if (o == null)
root.addOption(o = new OptionList(fullName));
return (OptionList) o;
}
public static String parent(String fullName)
{
public static void setOptionList(OptionList list) {
OptionList prev = (OptionList) root.getOption(list.fullName());
if (prev == null)
root.addOption(list);
else {
list.parent = prev.parent;
list.options = prev.options;
list.optionList = prev.optionList;
for (Option o : list.optionList)
o.parent = list;
list.parent.options.put(list.fullName(), list);
list.parent.optionList.remove(prev);
list.parent.addSorted(list);
}
}
public static String parent(String fullName) {
int i = fullName.indexOf('.');
if(i < 0)
if (i < 0)
return fullName;
return fullName.substring(0, i);
}
public static String child(String fullName)
{
public static String child(String fullName) {
int i = fullName.indexOf('.');
return fullName.substring(i+1);
return fullName.substring(i + 1);
}
public ArrayList<Option> optionList = new ArrayList<Option>();
public HashMap<String, Option> options = new HashMap<String, Option>();
public IConfigSetHolder config;
public OptionList(String name)
{
public OptionList(String name) {
super(name);
}
public OptionList bindConfig(IConfigSetHolder config)
{
this.config = config;
return this;
}
private OptionList subList(String fullName)
{
private OptionList subList(String fullName) {
OptionList o = (OptionList) getOption(fullName);
if(o == null)
if (o == null)
addOption(o = new OptionList(fullName));
return o;
}
public Option getOption(String fullName)
{
if(fullName.contains("."))
public Option getOption(String fullName) {
if (fullName.contains("."))
return subList(parent(fullName)).getOption(child(fullName));
return options.get(fullName);
}
public void addOption(Option o)
{
public void addOption(Option o) {
o.namespace = fullName();
addOption(o, o.fullName(), o.name);
}
private void addOption(Option o, String fullName, String subName)
{
if(subName.contains("."))
{
private void addOption(Option o, String fullName, String subName) {
if (subName.contains(".")) {
subList(parent(subName)).addOption(o, fullName, child(subName));
return;
}
if(options.containsKey(subName))
System.err.println("Warning, replacing option: "+fullName);
if (options.containsKey(subName))
NEIClientConfig.logger.warn("Replacing option: " + fullName);
options.put(subName, o);
addSorted(o);
o.onAdded(this);
}
public void addSorted(Option o)
{
public void addSorted(Option o) {
optionList.add(o);
}
public void expandOptionList(OptionList replacement)
{
addOption(replacement);
OptionList base = (OptionList) getOption(replacement.name);
replacement.options = base.options;
replacement.optionList = base.optionList;
options.remove(base.name);
optionList.remove(base);
/**
* Create an instance of a GuiOptionList subclass for the given parameter list
* @param parent The parent screen for the back button
* @param list The option list to be displayed in the gui
* @param world true if in world config mode, false for global
*/
public GuiOptionList getGui(GuiScreen parent, OptionList list, boolean world) {
return this.parent.getGui(parent, list, world);
}
public void showGui(GuiScreen parent)
{
Minecraft.getMinecraft().displayGuiScreen(new GuiOptionList(parent, this, false));
public void openGui(GuiScreen parent, boolean world) {
Minecraft.getMinecraft().displayGuiScreen(getGui(parent, this, world));
}
public void synthesizeEnvironment()
{
new GuiOptionList(null, this, false).addWidgets();
/**
* Adds this option to a temporary slot and gui for internal setting manipulation.
*/
public void synthesizeEnvironment(boolean world) {
getGui(null, this, world).addWidgets();
}
@Override
public boolean onClick(int button)
{
Minecraft.getMinecraft().displayGuiScreen(new GuiOptionList(slot.getGui(), OptionList.this, slot.getGui().worldConfig()));
public boolean onClick(int button) {
openGui(slot.getGui(), slot.getGui().worldConfig());
return true;
}
@Override
public boolean showWorldSelector()
{
public boolean showWorldSelector() {
return false;
}
@Override
public void onAdded(OptionScrollSlot slot)
{
public void onAdded(OptionScrollSlot slot) {
super.onAdded(slot);
globalConfigSet().config.getTag(configName()).useBraces();
worldConfigSet().config.getTag(configName()).useBraces();
}
@Override
public ConfigSet worldConfigSet()
{
return config != null ? config.worldConfigSet() : super.worldConfigSet();
}
@Override
public ConfigSet globalConfigSet()
{
return config != null ? config.globalConfigSet() : super.globalConfigSet();
}
@Override
public OptionList configBase()
{
return config != null ? this : super.configBase();
}
}
@@ -0,0 +1,23 @@
package codechicken.nei.config;
import codechicken.core.gui.GuiCCButton;
import codechicken.lib.render.CCRenderState;
import org.lwjgl.opengl.GL11;
public class PatreonButton extends GuiCCButton
{
public PatreonButton(int x, int y, int width, int height) {
super(x, y, width, height, null);
}
@Override
public void drawButtonTex(int mousex, int mousey) {
super.drawButtonTex(mousex, mousey);
GL11.glColor4f(1, 1, 1, 1);
CCRenderState.changeTexture("nei:textures/patreonNeon.png");
int texh = height-4;
int texw = texh*4;
func_146110_a(x+width/2-texw/2, y+height/2-texh/2, 0, 0, texw, texh, texw, texh);
}
}