mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-21 12:42:10 +00:00
Abstracted gui option list and added patreon button
This commit is contained in:
1 parent
ff5456cbd1
commit
d7753d2e78
18 files changed
+253
-149
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user