Fix custom array entry class for config GUI being ignored when adding new entries (#3697)
This commit is contained in:
parent
9619be4a17
commit
52409e15cf
3 changed files with 50 additions and 4 deletions
src/main
java/net/minecraftforge/fml/client
resources/assets/forge/lang
|
@ -34,6 +34,8 @@ import net.minecraft.client.resources.I18n;
|
|||
import net.minecraftforge.fml.client.config.ConfigGuiType;
|
||||
import net.minecraftforge.fml.client.config.DummyConfigElement;
|
||||
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||
import net.minecraftforge.fml.client.config.GuiEditArray;
|
||||
import net.minecraftforge.fml.client.config.GuiEditArrayEntries;
|
||||
import net.minecraftforge.fml.client.config.IConfigElement;
|
||||
import net.minecraftforge.fml.client.config.DummyConfigElement.DummyCategoryElement;
|
||||
import net.minecraftforge.fml.client.config.DummyConfigElement.DummyListElement;
|
||||
|
@ -79,7 +81,8 @@ public class FMLConfigGuiFactory implements IModGuiFactory
|
|||
listsList.add(new DummyListElement("stringListFixed", new String[] {"A", "fixed", "length", "array", "of", "string", "values"}, ConfigGuiType.STRING, "fml.config.sample.stringListFixed", true));
|
||||
listsList.add(new DummyListElement("stringListMax", new String[] {"An", "array", "of", "string", "values", "with", "a", "max", "length", "of", "15"}, ConfigGuiType.STRING, "fml.config.sample.stringListMax", 15));
|
||||
listsList.add(new DummyListElement("stringListPattern", new String[] {"Valid", "Not Valid", "Is, Valid", "Comma, Separated, Value"}, ConfigGuiType.STRING, "fml.config.sample.stringListPattern", commaDelimitedPattern));
|
||||
|
||||
listsList.add(new DummyListElement("stringListCustom", new Object[0], ConfigGuiType.STRING, "fml.config.sample.stringListCustom").setArrayEntryClass(CustomArrayEntry.class));
|
||||
|
||||
list.add(new DummyCategoryElement("lists", "fml.config.sample.ctgy.lists", listsList));
|
||||
|
||||
// Strings category
|
||||
|
@ -112,6 +115,21 @@ public class FMLConfigGuiFactory implements IModGuiFactory
|
|||
return true;
|
||||
}
|
||||
|
||||
public static class CustomArrayEntry extends GuiEditArrayEntries.StringEntry
|
||||
{
|
||||
public CustomArrayEntry(GuiEditArray owningScreen, GuiEditArrayEntries owningEntryList, IConfigElement configElement, Object value)
|
||||
{
|
||||
super(owningScreen, owningEntryList, configElement, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected)
|
||||
{
|
||||
textFieldValue.setTextColor((int) (Math.random() * 0xFFFFFF));
|
||||
super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@ import net.minecraft.util.text.TextFormatting;
|
|||
import net.minecraftforge.fml.client.config.GuiConfigEntries.ArrayEntry;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import static net.minecraftforge.fml.client.config.GuiUtils.INVALID;
|
||||
|
@ -80,8 +81,7 @@ public class GuiEditArrayEntries extends GuiListExtended
|
|||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
FMLLog.severe("There was a critical error instantiating the custom IGuiEditListEntry for property %s.", configElement.getName());
|
||||
e.printStackTrace();
|
||||
FMLLog.log(Level.ERROR, e, "There was a critical error instantiating the custom IGuiEditListEntry for property %s.", configElement.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,34 @@ public class GuiEditArrayEntries extends GuiListExtended
|
|||
|
||||
public void addNewEntry(int index)
|
||||
{
|
||||
if (configElement.isList() && configElement.getType() == ConfigGuiType.BOOLEAN)
|
||||
if (configElement.isList() && configElement.getArrayEntryClass() != null)
|
||||
{
|
||||
Class<? extends IArrayEntry> clazz = configElement.getArrayEntryClass();
|
||||
try
|
||||
{
|
||||
Object value;
|
||||
switch (configElement.getType())
|
||||
{
|
||||
case BOOLEAN:
|
||||
value = true;
|
||||
break;
|
||||
case INTEGER:
|
||||
value = 0;
|
||||
break;
|
||||
case DOUBLE:
|
||||
value = 0.0D;
|
||||
break;
|
||||
default:
|
||||
value = "";
|
||||
}
|
||||
listEntries.add(index, clazz.getConstructor(GuiEditArray.class, GuiEditArrayEntries.class, IConfigElement.class, Object.class).newInstance(this.owningGui, this, configElement, value));
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
FMLLog.log(Level.ERROR, e, "There was a critical error instantiating the custom IGuiEditListEntry for property %s.", configElement.getName());
|
||||
}
|
||||
}
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.BOOLEAN)
|
||||
listEntries.add(index, new BooleanEntry(this.owningGui, this, this.configElement, true));
|
||||
else if (configElement.isList() && configElement.getType() == ConfigGuiType.INTEGER)
|
||||
listEntries.add(index, new IntegerEntry(this.owningGui, this, this.configElement, 0));
|
||||
|
|
|
@ -135,6 +135,7 @@ fml.config.sample.stringListMax.tooltip=A string list that has a max length of 1
|
|||
fml.config.sample.stringListMax=Max Length String List
|
||||
fml.config.sample.stringListPattern.tooltip=A string list that validates each value using a Pattern object.
|
||||
fml.config.sample.stringListPattern=Pattern Validated String List
|
||||
fml.config.sample.stringListCustom=Custom Entry List
|
||||
fml.config.sample.title=This is for playing with the Config GUI behavior. Changes are not saved.
|
||||
|
||||
fml.configgui.applyGlobally=Apply globally
|
||||
|
|
Loading…
Reference in a new issue