2019-11-23 22:19:13 +01:00
|
|
|
package com.minelittlepony.client;
|
2018-05-13 18:43:49 +02:00
|
|
|
|
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;
|
2022-06-09 21:35:51 +02:00
|
|
|
import net.minecraft.text.*;
|
2019-03-24 00:04:54 +01:00
|
|
|
|
2019-11-30 12:12:46 +01:00
|
|
|
import com.minelittlepony.client.render.MobRenderers;
|
2019-07-10 17:09:40 +02:00
|
|
|
import com.minelittlepony.client.settings.ClientPonyConfig;
|
2019-06-01 15:49:17 +02:00
|
|
|
import com.minelittlepony.common.client.gui.GameGui;
|
|
|
|
import com.minelittlepony.common.client.gui.ScrollContainer;
|
2021-05-16 19:05:35 +02:00
|
|
|
import com.minelittlepony.common.client.gui.Tooltip;
|
|
|
|
import com.minelittlepony.common.client.gui.element.AbstractSlider;
|
2019-06-01 15:49:17 +02:00
|
|
|
import com.minelittlepony.common.client.gui.element.Button;
|
2019-07-10 17:09:40 +02:00
|
|
|
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;
|
2019-07-12 17:06:03 +02:00
|
|
|
import com.minelittlepony.common.util.settings.Setting;
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2021-06-10 19:32:21 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2019-07-16 17:52:39 +02:00
|
|
|
|
2018-05-13 18:43:49 +02:00
|
|
|
/**
|
|
|
|
* In-Game options menu.
|
|
|
|
*
|
|
|
|
*/
|
2019-12-05 14:46:28 +01: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.";
|
|
|
|
|
2022-06-09 21:35:51 +02:00
|
|
|
public static final Text SCALE_MEGA = Text.translatable("minelp.debug.scale.meg");
|
|
|
|
public static final Text SCALE_MAX = Text.translatable("minelp.debug.scale.max");
|
|
|
|
public static final Text SCALE_MID = Text.translatable("minelp.debug.scale.mid");
|
|
|
|
public static final Text SCALE_SHOW = Text.translatable("minelp.debug.scale.sa");
|
|
|
|
public static final Text SCALE_MIN = Text.translatable("minelp.debug.scale.min");
|
|
|
|
|
2019-07-10 17:09:40 +02:00
|
|
|
private ClientPonyConfig config;
|
2018-05-13 18:43:49 +02:00
|
|
|
|
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;
|
|
|
|
|
2019-07-16 17:52:39 +02:00
|
|
|
public GuiPonySettings(@Nullable Screen parent) {
|
2022-06-09 21:35:51 +02:00
|
|
|
super(Text.literal(OPTIONS_PREFIX + "title"), parent);
|
2019-06-01 15:49:17 +02:00
|
|
|
|
2019-07-10 17:09:40 +02:00
|
|
|
config = (ClientPonyConfig)MineLittlePony.getInstance().getConfig();
|
2019-06-01 15:49:17 +02:00
|
|
|
|
|
|
|
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;
|
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() {
|
2019-06-29 20:10:18 +02:00
|
|
|
content.init(this::rebuildContent);
|
|
|
|
}
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2019-07-12 17:06:03 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2019-06-29 20:10:18 +02:00
|
|
|
private void rebuildContent() {
|
2021-02-26 10:29:31 +01:00
|
|
|
|
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;
|
|
|
|
|
2021-06-06 20:38:11 +02:00
|
|
|
getChildElements().add(content);
|
2019-06-01 15:49:17 +02:00
|
|
|
|
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))
|
2019-07-22 09:54:54 +02:00
|
|
|
.onClick(sender -> finish())
|
2019-06-01 15:49:17 +02:00
|
|
|
.getStyle()
|
|
|
|
.setText("gui.done");
|
|
|
|
|
2019-06-01 20:48:09 +02:00
|
|
|
content.addButton(new Label(LEFT, row)).getStyle().setText(PONY_LEVEL);
|
2021-05-16 19:05:35 +02:00
|
|
|
|
|
|
|
content.addButton(new EnumSlider<>(LEFT, row += 20, config.ponyLevel.get())
|
|
|
|
.onChange(config.ponyLevel::set)
|
2022-06-09 21:35:51 +02:00
|
|
|
.setTextFormat(sender -> Text.translatable(PONY_LEVEL + "." + sender.getValue().name().toLowerCase()))
|
2021-05-16 19:05:35 +02:00
|
|
|
.setTooltipFormat(sender -> Tooltip.of(PONY_LEVEL + "." + sender.getValue().name().toLowerCase() + ".tooltip", 200)));
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2020-11-28 11:57:56 +01:00
|
|
|
boolean allowCameraChange = client.player == null || client.player.isCreative() || client.player.isSpectator() || client.isInSingleplayer();
|
|
|
|
|
|
|
|
if (hiddenOptions && allowCameraChange) {
|
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-06-05 15:42:20 +02:00
|
|
|
.onChange(config::setGlobalScaleFactor)
|
2021-05-16 19:05:35 +02:00
|
|
|
.setTextFormat(this::describeCurrentScale));
|
2019-06-05 15:42:20 +02:00
|
|
|
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");
|
2019-07-12 17:06:03 +02:00
|
|
|
|
2020-11-28 11:57:56 +01:00
|
|
|
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()))
|
2019-07-12 17:06:03 +02:00
|
|
|
.onChange((Setting<Boolean>)i)
|
2020-11-28 11:57:56 +01:00
|
|
|
.setEnabled(enabled);
|
|
|
|
button.getStyle().setText(OPTIONS_PREFIX + i.name().toLowerCase());
|
|
|
|
if (!enabled) {
|
|
|
|
button.getStyle()
|
2022-06-09 21:35:51 +02:00
|
|
|
.setTooltip(Text.translatable(OPTIONS_PREFIX + "option.disabled"))
|
2020-11-28 11:57:56 +01:00
|
|
|
.setTooltipOffset(0, 0);
|
|
|
|
}
|
2018-05-15 16:26:52 +02:00
|
|
|
}
|
2018-05-13 18:43:49 +02:00
|
|
|
|
2022-06-09 22:51:38 +02:00
|
|
|
if (hiddenOptions) {
|
|
|
|
for (Setting<?> i : config.getByCategory("customisation")) {
|
|
|
|
Button button = content
|
|
|
|
.addButton(new Toggle(LEFT, row += 20, ((Setting<Boolean>)i).get()))
|
|
|
|
.onChange((Setting<Boolean>)i);
|
|
|
|
button.getStyle().setText(OPTIONS_PREFIX + i.name().toLowerCase());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 17:09:40 +02:00
|
|
|
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())
|
2021-05-16 19:05:35 +02:00
|
|
|
.onChange(config.horseButton::set)
|
|
|
|
.setTooltipFormat(sender -> Tooltip.of(OPTIONS_PREFIX + "button." + sender.getValue().name().toLowerCase(), 200)));
|
2019-07-10 17:09:40 +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-11-30 12:12:46 +01:00
|
|
|
for (MobRenderers i : MobRenderers.REGISTRY.values()) {
|
2019-06-01 15:49:17 +02:00
|
|
|
content.addButton(new Toggle(RIGHT, row += 20, i.get()))
|
2019-07-12 17:06:03 +02:00
|
|
|
.onChange(i::set)
|
2019-11-30 12:12:46 +01:00
|
|
|
.getStyle().setText(MOB_PREFIX + i.name);
|
2018-05-15 16:26:52 +02:00
|
|
|
}
|
2021-05-16 19:05:35 +02:00
|
|
|
|
|
|
|
row += 15;
|
|
|
|
|
|
|
|
content.addButton(new Label(RIGHT, row)).getStyle().setText("minelp.options.skins");
|
2021-05-17 23:27:21 +02:00
|
|
|
SkinsProxy.instance.renderOption(this, parent, row, RIGHT, content);
|
2018-05-13 18:43:49 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 21:35:51 +02:00
|
|
|
public Text describeCurrentScale(AbstractSlider<Float> sender) {
|
2021-05-16 19:05:35 +02:00
|
|
|
float value = sender.getValue();
|
2018-10-23 09:59:29 +02:00
|
|
|
if (value >= 3) {
|
2022-06-09 21:35:51 +02:00
|
|
|
return SCALE_MEGA;
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
if (value == 2) {
|
2022-06-09 21:35:51 +02:00
|
|
|
return SCALE_MAX;
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
if (value == 1) {
|
2022-06-09 21:35:51 +02:00
|
|
|
return SCALE_MID;
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
if (value == 0.9F) {
|
2022-06-09 21:35:51 +02:00
|
|
|
return SCALE_SHOW;
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
if (value <= 0.1F) {
|
2022-06-09 21:35:51 +02:00
|
|
|
return SCALE_MIN;
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
2019-08-01 23:00:44 +02:00
|
|
|
|
|
|
|
value *= 100F;
|
|
|
|
value = Math.round(value);
|
|
|
|
value /= 100F;
|
|
|
|
|
2022-06-09 21:35:51 +02:00
|
|
|
return Text.translatable("minelp.debug.scale.value", value);
|
2018-10-23 09:59:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 18:43:49 +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);
|
2018-05-13 18:43:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-07-22 00:31:45 +02:00
|
|
|
public void removed() {
|
2019-03-23 18:48:20 +01:00
|
|
|
config.save();
|
2018-05-13 18:43:49 +02:00
|
|
|
}
|
|
|
|
}
|