aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/client/GT_GUI_ClientConfig.java
blob: 1e9841369b5da5f36a512299ddd9775fd9f098ff (plain)
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
package gregtech.client;

import static gregtech.api.enums.Mods.GregTech;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.IConfigElement;
import gregtech.api.GregTech_API;

public class GT_GUI_ClientConfig extends GuiConfig {

    public GT_GUI_ClientConfig(GuiScreen parentScreen) {
        super(
            parentScreen,
            getConfigElements(),
            GregTech.ID,
            "client",
            false,
            false,
            getAbridgedConfigPath(GregTech_API.sClientDataFile.mConfig.toString()));
    }

    @SuppressWarnings("rawtypes")
    private static List<IConfigElement> getConfigElements() {
        final Configuration config = GregTech_API.sClientDataFile.mConfig;
        setLanguageKeys(config);
        return config.getCategoryNames()
            .stream()
            .filter(name -> name.indexOf('.') == -1)
            .map(name -> new ConfigElement(config.getCategory(name)))
            .collect(Collectors.toList());
    }

    private static void setLanguageKeys(Configuration config) {
        for (String categoryName : config.getCategoryNames()) {
            ConfigCategory category = config.getCategory(categoryName);
            category.setLanguageKey("GT5U.config." + categoryName);
            for (Map.Entry<String, Property> entry : category.entrySet()) {
                // drop the default value in name
                String name = entry.getKey();
                int defaultStart = name.lastIndexOf('_');
                String realName = defaultStart >= 0 ? name.substring(0, defaultStart) : name;
                if (categoryName.equals("nei.recipe_categories")) {
                    // reuse existing translation for RecipeCategory
                    entry.getValue()
                        .setLanguageKey(name);
                } else {
                    entry.getValue()
                        .setLanguageKey(String.format("%s.%s", category.getLanguagekey(), realName));
                }
            }
        }
    }
}