2019-03-23 20:49:34 +01:00
|
|
|
package com.minelittlepony.client.gui;
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2019-06-01 15:49:17 +02:00
|
|
|
import net.minecraft.client.gui.Element;
|
2019-06-01 21:40:06 +02:00
|
|
|
import net.minecraft.client.gui.screen.Screen;
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.client.resource.language.I18n;
|
2019-06-01 15:49:17 +02:00
|
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
2019-03-24 00:04:54 +01:00
|
|
|
|
2019-03-23 20:58:50 +01:00
|
|
|
import com.minelittlepony.MineLittlePony;
|
2019-03-23 20:49:34 +01:00
|
|
|
import com.minelittlepony.client.render.entities.MobRenderers;
|
2019-06-01 15:49:17 +02:00
|
|
|
import com.minelittlepony.common.client.gui.GameGui;
|
|
|
|
import com.minelittlepony.common.client.gui.ScrollContainer;
|
|
|
|
import com.minelittlepony.common.client.gui.element.Button;
|
2019-04-14 13:32:01 +02:00
|
|
|
import com.minelittlepony.common.client.gui.element.Label;
|
|
|
|
import com.minelittlepony.common.client.gui.element.Slider;
|
|
|
|
import com.minelittlepony.common.client.gui.element.Toggle;
|
2019-03-23 20:58:50 +01:00
|
|
|
import com.minelittlepony.settings.PonyConfig;
|
|
|
|
import com.minelittlepony.settings.PonyLevel;
|
2019-05-28 10:26:26 +02:00
|
|
|
import com.minelittlepony.settings.PonySettings;
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2019-06-01 15:49:17 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-05-13 18:43:49 +02:00
|
|
|
/**
|
|
|
|
* In-Game options menu.
|
|
|
|
*
|
|
|
|
*/
|
2019-06-01 15:49:17 +02:00
|
|
|
public class GuiPonySettings extends GameGui {
|
2018-05-13 18:43:49 +02:00
|
|
|
|
|
|
|
private static final String OPTIONS_PREFIX = "minelp.options.";
|
|
|
|
|
|
|
|
private static final String PONY_LEVEL = OPTIONS_PREFIX + "ponylevel";
|
|
|
|
|
|
|
|
private static final String MOB_PREFIX = "minelp.mobs.";
|
|
|
|
|
|
|
|
private PonyConfig config;
|
|
|
|
|
2019-06-01 15:49:17 +02:00
|
|
|
private final ScrollContainer content = new ScrollContainer();
|
|
|
|
|
2019-06-02 15:13:26 +02:00
|
|
|
private final boolean hiddenOptions;
|
|
|
|
|
2018-05-13 18:43:49 +02:00
|
|
|
public GuiPonySettings() {
|
2019-06-01 15:49:17 +02:00
|
|
|
super(new TranslatableComponent(OPTIONS_PREFIX + "title"));
|
|
|
|
|
2019-03-23 19:17:46 +01:00
|
|
|
config = MineLittlePony.getInstance().getConfig();
|
2019-06-01 15:49:17 +02:00
|
|
|
|
|
|
|
content.margin.top = 30;
|
|
|
|
content.margin.bottom = 30;
|
|
|
|
content.padding.top = 10;
|
|
|
|
content.padding.right = 10;
|
|
|
|
content.padding.bottom = 20;
|
2019-06-02 15:13:26 +02:00
|
|
|
|
|
|
|
hiddenOptions = Screen.hasControlDown() && Screen.hasShiftDown();
|
2018-05-13 18:43:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-01 15:49:17 +02:00
|
|
|
protected void init() {
|
|
|
|
content.init();
|
|
|
|
content.buttons().clear();
|
|
|
|
content.children().clear();
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2019-06-01 20:48:09 +02:00
|
|
|
content.padding.left = 10;
|
|
|
|
|
2019-06-01 15:49:17 +02:00
|
|
|
int LEFT = content.width / 2 - 210;
|
|
|
|
int RIGHT = content.width / 2 + 10;
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2019-06-01 15:49:17 +02:00
|
|
|
if (LEFT < 0) {
|
|
|
|
LEFT = content.width / 2 - 100;
|
|
|
|
RIGHT = LEFT;
|
2018-05-13 18:43:49 +02:00
|
|
|
}
|
|
|
|
|
2019-06-01 15:49:17 +02:00
|
|
|
int row = 0;
|
|
|
|
|
|
|
|
((List<Element>)children()).add(content);
|
|
|
|
|
2019-06-01 20:48:09 +02:00
|
|
|
addButton(new Label(width / 2, 5).setCentered()).getStyle().setText(getTitle().getString());
|
2019-06-01 15:49:17 +02:00
|
|
|
addButton(new Button(width / 2 - 100, height - 25))
|
|
|
|
.onClick(sender -> onClose())
|
|
|
|
.getStyle()
|
|
|
|
.setText("gui.done");
|
|
|
|
|
2019-06-01 20:48:09 +02:00
|
|
|
content.addButton(new Label(LEFT, row)).getStyle().setText(PONY_LEVEL);
|
|
|
|
content.addButton(new Slider(LEFT, row += 20, 0, 2, config.getPonyLevel().ordinal())
|
2019-04-14 13:32:01 +02:00
|
|
|
.onChange(v -> {
|
|
|
|
PonyLevel level = PonyLevel.valueFor(v);
|
|
|
|
config.setPonyLevel(level);
|
|
|
|
return (float)level.ordinal();
|
|
|
|
})
|
2019-05-27 17:59:15 +02:00
|
|
|
.setFormatter(value -> I18n.translate(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase())));
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2019-06-02 15:13:26 +02:00
|
|
|
if (hiddenOptions) {
|
2019-06-01 15:49:17 +02:00
|
|
|
content.addButton(new Label(LEFT, row += 30)).getStyle().setText("minelp.debug.scale");
|
|
|
|
content.addButton(new Slider(LEFT, row += 15, 0.1F, 3, config.getGlobalScaleFactor())
|
2019-04-14 13:32:01 +02:00
|
|
|
.onChange(v -> {
|
|
|
|
config.setGlobalScaleFactor(v);
|
|
|
|
return config.getGlobalScaleFactor();
|
|
|
|
})
|
2019-05-27 17:59:15 +02:00
|
|
|
.setFormatter(value -> I18n.translate("minelp.debug.scale.value", I18n.translate(describeCurrentScale(value)))));
|
2018-10-21 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2019-06-01 20:48:09 +02:00
|
|
|
row += 20;
|
|
|
|
content.addButton(new Label(LEFT, row)).getStyle().setText(OPTIONS_PREFIX + "options");
|
2018-05-15 16:26:52 +02:00
|
|
|
for (PonySettings i : PonySettings.values()) {
|
2019-06-01 15:49:17 +02:00
|
|
|
content.addButton(new Toggle(LEFT, row += 20, i.get()))
|
2019-04-14 13:32:01 +02:00
|
|
|
.onChange(i)
|
|
|
|
.getStyle().setText(OPTIONS_PREFIX + i.name().toLowerCase());
|
2018-05-15 16:26:52 +02:00
|
|
|
}
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2019-06-01 15:49:17 +02:00
|
|
|
if (RIGHT != LEFT) {
|
|
|
|
row = 0;
|
2018-05-13 18:43:49 +02:00
|
|
|
} else {
|
2019-06-01 15:49:17 +02:00
|
|
|
row += 15;
|
2018-05-13 18:43:49 +02:00
|
|
|
}
|
|
|
|
|
2019-06-01 20:48:09 +02:00
|
|
|
content.addButton(new Label(RIGHT, row)).getStyle().setText(MOB_PREFIX + "title");
|
2019-05-28 10:26:26 +02:00
|
|
|
for (MobRenderers i : MobRenderers.registry) {
|
2019-06-01 15:49:17 +02:00
|
|
|
content.addButton(new Toggle(RIGHT, row += 20, i.get()))
|
2019-04-14 13:32:01 +02:00
|
|
|
.onChange(i)
|
|
|
|
.getStyle().setText(MOB_PREFIX + i.name().toLowerCase());
|
2018-05-15 16:26:52 +02:00
|
|
|
}
|
2019-06-01 15:49:17 +02:00
|
|
|
content.init();
|
2018-05-13 18:43:49 +02:00
|
|
|
}
|
|
|
|
|
2018-10-23 09:59:29 +02:00
|
|
|
public String describeCurrentScale(float value) {
|
|
|
|
if (value >= 3) {
|
2019-05-27 17:59:15 +02:00
|
|
|
return I18n.translate("minelp.debug.scale.meg");
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
if (value == 2) {
|
2019-05-27 17:59:15 +02:00
|
|
|
return I18n.translate("minelp.debug.scale.max");
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
if (value == 1) {
|
2019-05-27 17:59:15 +02:00
|
|
|
return I18n.translate("minelp.debug.scale.mid");
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
if (value == 0.9F) {
|
2019-05-27 17:59:15 +02:00
|
|
|
return I18n.translate("minelp.debug.scale.sa");
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
if (value <= 0.1F) {
|
2019-05-27 17:59:15 +02:00
|
|
|
return I18n.translate("minelp.debug.scale.min");
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
return String.format("%f", value);
|
|
|
|
}
|
|
|
|
|
2018-05-13 18:43:49 +02:00
|
|
|
@Override
|
2019-06-01 15:49:17 +02:00
|
|
|
public void render(int mouseX, int mouseY, float partialTicks) {
|
|
|
|
renderBackground();
|
|
|
|
super.render(mouseX, mouseY, partialTicks);
|
|
|
|
content.render(mouseX, mouseY, partialTicks);
|
2018-05-13 18:43:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-01 15:49:17 +02:00
|
|
|
public void onClose() {
|
|
|
|
super.onClose();
|
2019-03-23 18:48:20 +01:00
|
|
|
config.save();
|
2018-05-13 18:43:49 +02:00
|
|
|
}
|
|
|
|
}
|