-
Notifications
You must be signed in to change notification settings - Fork 497
/
ConfigManager.java
113 lines (94 loc) · 3.15 KB
/
ConfigManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package buildcraft.core.config;
import java.util.ArrayList;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import cpw.mods.fml.client.IModGuiFactory;
import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.IConfigElement;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
public class ConfigManager implements IModGuiFactory {
public static Configuration config;
public static class GuiConfigManager extends GuiConfig {
public GuiConfigManager(GuiScreen parentScreen) {
super(parentScreen, new ArrayList<IConfigElement>(), "BuildCraft|Core", "config", false, false, I18n.format("config.buildcraft"));
for (String s : config.getCategoryNames()) {
configElements.add(new BCConfigElement(config.getCategory(s)));
}
}
}
public enum RestartRequirement {
NONE, WORLD, GAME;
}
public ConfigManager() {
}
public ConfigManager(Configuration c) {
this.config = c;
}
public ConfigCategory getCat(String name) {
return config.getCategory(name);
}
public Property get(String iName) {
String prefix = iName.substring(0, iName.lastIndexOf("."));
ConfigCategory c = config.getCategory(prefix);
return c.get(iName.substring(iName.lastIndexOf(".") + 1));
}
private Property create(String s, Object o) {
Property p = null;
if (o instanceof Integer) {
p = new Property(s, o.toString(), Property.Type.INTEGER);
} else if (o instanceof String) {
p = new Property(s, (String) o, Property.Type.STRING);
} else if (o instanceof Double) {
p = new Property(s, o.toString(), Property.Type.DOUBLE);
} else if (o instanceof Boolean) {
p = new Property(s, o.toString(), Property.Type.BOOLEAN);
} else if (o instanceof String[]) {
p = new Property(s, (String[]) o, Property.Type.STRING);
} else {
return null;
}
return p;
}
public Property register(String name, Object property, String comment, RestartRequirement restartRequirement) {
String prefix = name.substring(0, name.lastIndexOf("."));
String suffix = name.substring(name.lastIndexOf(".") + 1);
ConfigCategory c = config.getCategory(prefix);
ConfigCategory parent = c;
while (parent != null) {
parent.setLanguageKey("config." + parent.getQualifiedName());
parent = parent.parent;
}
Property p;
if (c.get(suffix) != null) {
p = c.get(suffix);
} else {
p = create(suffix, property);
c.put(suffix, p);
}
p.comment = comment;
RestartRequirement r = restartRequirement;
p.setLanguageKey("config." + name);
p.setRequiresWorldRestart(r == RestartRequirement.WORLD);
p.setRequiresMcRestart(r == RestartRequirement.GAME);
return p;
}
@Override
public void initialize(Minecraft minecraftInstance) {
}
@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
return GuiConfigManager.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}
@Override
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
return null;
}
}