Search in sources :

Example 1 with SettingColor

use of net.spellcraftgaming.rpghud.settings.SettingColor in project RPG-Hud by KurodaAkira.

the class GuiSettingsMod method init.

@Override
public void init() {
    TextRenderer fontRenderer = client.textRenderer;
    if (this.subSetting.equals("")) {
        GuiButtonTooltip guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + 0 % 2 * 160, this.height / 6 - 14 + 20 * (0 >> 1), "general", new TranslatableText("gui.rpg.general"), button -> {
            GuiButtonTooltip b = (GuiButtonTooltip) button;
            if (b.enumOptions != null)
                client.setScreen(new GuiSettingsMod(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
        }).setTooltip(I18n.translate("tooltip.general", new Object[0]));
        this.addDrawableChild(guismallbutton);
        int count = 1;
        for (HudElementType type : HudElementType.values()) {
            List<String> settings = this.settings.getSettingsOf(type);
            if (!settings.isEmpty()) {
                guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + count % 2 * 160, this.height / 6 - 14 + 20 * (count >> 1), type.name(), new TranslatableText(type.getDisplayName()), button -> {
                    GuiButtonTooltip b = (GuiButtonTooltip) button;
                    if (b.enumOptions != null) {
                        this.client.setScreen(new GuiSettingsMod(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
                    }
                }).setTooltip(I18n.translate("tooltip.element", new Object[0]));
                this.addDrawableChild(guismallbutton);
                count++;
            }
        }
    } else {
        List<String> settingList = this.settings.getSettingsOf(this.subSetting);
        for (int i = 0; i < settingList.size(); i++) {
            if (this.settings.getSetting(settingList.get(i)) instanceof SettingPosition) {
                String[] values = ((String) this.settings.getSetting(settingList.get(i)).getValue()).split("_");
                List<TextFieldWidget> fields = new ArrayList<TextFieldWidget>();
                GuiTextLabel settingLabel = new GuiTextLabel(this.width / 2 - 152 + i % 2 * 160, this.height / 6 - 8 + 20 * (i >> 1), this.settings.getButtonString(settingList.get(i)));
                labelList.add(settingLabel);
                TextFieldWidget xPos = new TextFieldWidgetMod(fontRenderer, ValueType.POSITION, this.width / 2 - 100 + i % 2 * 160, this.height / 6 - 12 + 20 * (i >> 1), 45, 15, new TranslatableText(values[0]));
                xPos.setText(values[0]);
                xPos.setMaxLength(6);
                this.addDrawableChild(xPos);
                fields.add(xPos);
                TextFieldWidget yPos = new TextFieldWidgetMod(fontRenderer, ValueType.POSITION, this.width / 2 - 100 + i % 2 * 160 + 48, this.height / 6 - 12 + 20 * (i >> 1), 45, 15, new TranslatableText(values[1]));
                yPos.setText(values[1]);
                yPos.setMaxLength(6);
                this.addDrawableChild(yPos);
                fields.add(yPos);
                textFields.put(settingList.get(i), fields);
            } else if (this.settings.getSetting(settingList.get(i)) instanceof SettingDouble) {
                List<TextFieldWidget> fields = new ArrayList<TextFieldWidget>();
                GuiTextLabel scaleLabel = new GuiTextLabel(this.width / 2 - 151 + i % 2 * 160, this.height / 6 - 8 + 20 * (i >> 1), this.settings.getButtonString(settingList.get(i)));
                TextFieldWidget scale = new TextFieldWidgetMod(fontRenderer, ValueType.DOUBLE, this.width / 2 - 100 + i % 2 * 160 + 3, this.height / 6 - 12 + 20 * (i >> 1), 90, 15, new TranslatableText(String.valueOf(this.settings.getDoubleValue(settingList.get(i)))));
                scale.setText(String.valueOf(this.settings.getDoubleValue(settingList.get(i))));
                labelList.add(scaleLabel);
                this.addDrawableChild(scale);
                fields.add(scale);
                textFields.put(settingList.get(i), fields);
            } else {
                GuiButtonTooltip guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 14 + 20 * (i >> 1), settingList.get(i), new TranslatableText(this.settings.getButtonString(settingList.get(i))), button -> {
                    GuiButtonTooltip b = (GuiButtonTooltip) button;
                    if (b.enumOptions != null) {
                        if (settings.getSetting(b.enumOptions) instanceof SettingColor) {
                            client.setScreen(new GuiSettingsModColor(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
                        } else {
                            settings.increment(b.enumOptions);
                            button.setMessage(new TranslatableText(settings.getButtonString(b.enumOptions)));
                        }
                    }
                }).setTooltip(this.settings.getSetting(settingList.get(i)).getTooltip());
                this.addDrawableChild(guismallbutton);
            }
        }
    }
    this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, new TranslatableText("gui.done"), button -> {
        Settings settings = ModRPGHud.instance.settings;
        for (String settingID : textFields.keySet()) {
            for (TextFieldWidget t : textFields.get(settingID)) {
                if (t instanceof TextFieldWidgetMod) {
                    ValueType type = ((TextFieldWidgetMod) t).getValueType();
                    switch(type) {
                        case DOUBLE:
                            double value;
                            try {
                                value = Double.valueOf(textFields.get(settingID).get(0).getText());
                                this.settings.getSetting(settingID).setValue(value);
                            } catch (NumberFormatException e) {
                            }
                            break;
                        case POSITION:
                            this.settings.getSetting(settingID).setValue(textFields.get(settingID).get(0).getText() + "_" + textFields.get(settingID).get(1).getText());
                            break;
                    }
                }
            }
        }
        settings.saveSettings();
        client.setScreen(parent);
    }));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) ValueType(net.spellcraftgaming.rpghud.gui.TextFieldWidgetMod.ValueType) I18n(net.minecraft.client.resource.language.I18n) Environment(net.fabricmc.api.Environment) MatrixStack(net.minecraft.client.util.math.MatrixStack) TranslatableText(net.minecraft.text.TranslatableText) HashMap(java.util.HashMap) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ArrayList(java.util.ArrayList) List(java.util.List) ModRPGHud(net.spellcraftgaming.rpghud.main.ModRPGHud) SettingColor(net.spellcraftgaming.rpghud.settings.SettingColor) Screen(net.minecraft.client.gui.screen.Screen) Settings(net.spellcraftgaming.rpghud.settings.Settings) DrawableHelper(net.minecraft.client.gui.DrawableHelper) Map(java.util.Map) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) HudElementType(net.spellcraftgaming.rpghud.gui.hud.element.HudElementType) EnvType(net.fabricmc.api.EnvType) SettingPosition(net.spellcraftgaming.rpghud.settings.SettingPosition) Text(net.minecraft.text.Text) TextRenderer(net.minecraft.client.font.TextRenderer) SettingDouble(net.spellcraftgaming.rpghud.settings.SettingDouble) HudElementType(net.spellcraftgaming.rpghud.gui.hud.element.HudElementType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Settings(net.spellcraftgaming.rpghud.settings.Settings) SettingColor(net.spellcraftgaming.rpghud.settings.SettingColor) ValueType(net.spellcraftgaming.rpghud.gui.TextFieldWidgetMod.ValueType) SettingPosition(net.spellcraftgaming.rpghud.settings.SettingPosition) SettingDouble(net.spellcraftgaming.rpghud.settings.SettingDouble) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) TextRenderer(net.minecraft.client.font.TextRenderer)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 EnvType (net.fabricmc.api.EnvType)1 Environment (net.fabricmc.api.Environment)1 TextRenderer (net.minecraft.client.font.TextRenderer)1 DrawableHelper (net.minecraft.client.gui.DrawableHelper)1 Screen (net.minecraft.client.gui.screen.Screen)1 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)1 TextFieldWidget (net.minecraft.client.gui.widget.TextFieldWidget)1 I18n (net.minecraft.client.resource.language.I18n)1 MatrixStack (net.minecraft.client.util.math.MatrixStack)1 Text (net.minecraft.text.Text)1 TranslatableText (net.minecraft.text.TranslatableText)1 ValueType (net.spellcraftgaming.rpghud.gui.TextFieldWidgetMod.ValueType)1 HudElementType (net.spellcraftgaming.rpghud.gui.hud.element.HudElementType)1 ModRPGHud (net.spellcraftgaming.rpghud.main.ModRPGHud)1 SettingColor (net.spellcraftgaming.rpghud.settings.SettingColor)1 SettingDouble (net.spellcraftgaming.rpghud.settings.SettingDouble)1