MineLittlePony/src/main/java/com/minelittlepony/client/GuiPonySettings.java

179 lines
6.6 KiB
Java
Raw Normal View History

2019-11-23 22:19:13 +01:00
package com.minelittlepony.client;
2019-06-01 21:40:06 +02:00
import net.minecraft.client.gui.screen.Screen;
2020-04-30 18:11:49 +02:00
import net.minecraft.client.util.math.MatrixStack;
2019-06-27 19:28:21 +02:00
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
2019-11-30 12:12:46 +01:00
import com.minelittlepony.client.render.MobRenderers;
import com.minelittlepony.client.settings.ClientPonyConfig;
import com.minelittlepony.common.client.gui.GameGui;
import com.minelittlepony.common.client.gui.ScrollContainer;
import com.minelittlepony.common.client.gui.Tooltip;
import com.minelittlepony.common.client.gui.element.AbstractSlider;
import com.minelittlepony.common.client.gui.element.Button;
import com.minelittlepony.common.client.gui.element.EnumSlider;
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;
import com.minelittlepony.common.util.settings.Setting;
import javax.annotation.Nullable;
/**
* In-Game options menu.
*
*/
2019-12-05 14:46:28 +01:00
public class GuiPonySettings extends GameGui {
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 ClientPonyConfig config;
private final ScrollContainer content = new ScrollContainer();
private final boolean hiddenOptions;
public GuiPonySettings(@Nullable Screen parent) {
super(new LiteralText(OPTIONS_PREFIX + "title"), parent);
config = (ClientPonyConfig)MineLittlePony.getInstance().getConfig();
content.margin.top = 30;
content.margin.bottom = 30;
2021-06-06 20:38:11 +02:00
content.getContentPadding().top = 10;
content.getContentPadding().right = 10;
content.getContentPadding().bottom = 20;
content.getContentPadding().left = 10;
hiddenOptions = Screen.hasControlDown() && Screen.hasShiftDown();
}
@Override
protected void init() {
2019-06-29 20:10:18 +02:00
content.init(this::rebuildContent);
}
@SuppressWarnings("unchecked")
2019-06-29 20:10:18 +02:00
private void rebuildContent() {
int LEFT = content.width / 2 - 210;
int RIGHT = content.width / 2 + 10;
if (LEFT < 0) {
LEFT = content.width / 2 - 100;
RIGHT = LEFT;
}
int row = 0;
2021-06-06 20:38:11 +02:00
getChildElements().add(content);
2019-06-01 20:48:09 +02:00
addButton(new Label(width / 2, 5).setCentered()).getStyle().setText(getTitle().getString());
addButton(new Button(width / 2 - 100, height - 25))
2019-07-22 09:54:54 +02:00
.onClick(sender -> finish())
.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 EnumSlider<>(LEFT, row += 20, config.ponyLevel.get())
.onChange(config.ponyLevel::set)
.setTextFormat(sender -> new TranslatableText(PONY_LEVEL + "." + sender.getValue().name().toLowerCase()))
.setTooltipFormat(sender -> Tooltip.of(PONY_LEVEL + "." + sender.getValue().name().toLowerCase() + ".tooltip", 200)));
boolean allowCameraChange = client.player == null || client.player.isCreative() || client.player.isSpectator() || client.isInSingleplayer();
if (hiddenOptions && allowCameraChange) {
content.addButton(new Label(LEFT, row += 30)).getStyle().setText("minelp.debug.scale");
content.addButton(new Slider(LEFT, row += 15, 0.1F, 3, config.getGlobalScaleFactor())
.onChange(config::setGlobalScaleFactor)
.setTextFormat(this::describeCurrentScale));
content.addButton(new Label(LEFT, row += 30)).getStyle().setText("minelp.debug.size");
2019-07-11 19:20:13 +02:00
content.addButton(new EnumSlider<>(LEFT, row += 15, config.sizeOverride.get())
.onChange(config.sizeOverride::set));
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");
for (Setting<?> i : config.getByCategory("settings")) {
boolean enabled = i != config.fillycam || allowCameraChange;
Button button = content
.addButton(new Toggle(LEFT, row += 20, ((Setting<Boolean>)i).get()))
.onChange((Setting<Boolean>)i)
.setEnabled(enabled);
button.getStyle().setText(OPTIONS_PREFIX + i.name().toLowerCase());
if (!enabled) {
button.getStyle()
.setTooltip(new TranslatableText(OPTIONS_PREFIX + "option.disabled"))
.setTooltipOffset(0, 0);
}
}
content.addButton(new Label(LEFT, row += 20)).getStyle().setText(OPTIONS_PREFIX + "button");
2019-07-11 19:20:13 +02:00
content.addButton(new EnumSlider<>(LEFT, row += 20, config.horseButton.get())
.onChange(config.horseButton::set)
.setTooltipFormat(sender -> Tooltip.of(OPTIONS_PREFIX + "button." + sender.getValue().name().toLowerCase(), 200)));
if (RIGHT != LEFT) {
row = 0;
} else {
row += 15;
}
2019-06-01 20:48:09 +02:00
content.addButton(new Label(RIGHT, row)).getStyle().setText(MOB_PREFIX + "title");
2019-11-30 12:12:46 +01:00
for (MobRenderers i : MobRenderers.REGISTRY.values()) {
content.addButton(new Toggle(RIGHT, row += 20, i.get()))
.onChange(i::set)
2019-11-30 12:12:46 +01:00
.getStyle().setText(MOB_PREFIX + i.name);
}
row += 15;
content.addButton(new Label(RIGHT, row)).getStyle().setText("minelp.options.skins");
SkinsProxy.instance.renderOption(this, parent, row, RIGHT, content);
}
public TranslatableText describeCurrentScale(AbstractSlider<Float> sender) {
float value = sender.getValue();
2018-10-23 09:59:29 +02:00
if (value >= 3) {
return new TranslatableText("minelp.debug.scale.meg");
2018-10-23 09:59:29 +02:00
}
if (value == 2) {
return new TranslatableText("minelp.debug.scale.max");
2018-10-23 09:59:29 +02:00
}
if (value == 1) {
return new TranslatableText("minelp.debug.scale.mid");
2018-10-23 09:59:29 +02:00
}
if (value == 0.9F) {
return new TranslatableText("minelp.debug.scale.sa");
2018-10-23 09:59:29 +02:00
}
if (value <= 0.1F) {
return new TranslatableText("minelp.debug.scale.min");
2018-10-23 09:59:29 +02:00
}
value *= 100F;
value = Math.round(value);
value /= 100F;
return new TranslatableText("minelp.debug.scale.value", value);
2018-10-23 09:59:29 +02:00
}
@Override
2020-04-30 18:11:49 +02:00
public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
renderBackground(matrices);
super.render(matrices, mouseX, mouseY, partialTicks);
content.render(matrices, mouseX, mouseY, partialTicks);
}
@Override
public void removed() {
config.save();
}
}