mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Use a scrolling container for the settings menu. (Fixes overflowing issues)
This commit is contained in:
parent
17187a7fb0
commit
461e0863b1
2 changed files with 56 additions and 31 deletions
|
@ -4,7 +4,6 @@ import com.minelittlepony.MineLittlePony;
|
||||||
import com.minelittlepony.client.gui.GuiPonySettings;
|
import com.minelittlepony.client.gui.GuiPonySettings;
|
||||||
import com.minelittlepony.client.pony.PonyManager;
|
import com.minelittlepony.client.pony.PonyManager;
|
||||||
import com.minelittlepony.client.render.tileentities.skull.PonySkullRenderer;
|
import com.minelittlepony.client.render.tileentities.skull.PonySkullRenderer;
|
||||||
import com.minelittlepony.common.client.gui.GuiHost;
|
|
||||||
import com.minelittlepony.settings.PonyConfig;
|
import com.minelittlepony.settings.PonyConfig;
|
||||||
|
|
||||||
import net.minecraft.ChatFormat;
|
import net.minecraft.ChatFormat;
|
||||||
|
@ -74,7 +73,7 @@ public class MineLPClient extends MineLittlePony {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mainMenu || inGame) && keyBinding.isPressed()) {
|
if ((mainMenu || inGame) && keyBinding.isPressed()) {
|
||||||
minecraft.openScreen(new GuiHost(new GuiPonySettings()));
|
minecraft.openScreen(new GuiPonySettings());
|
||||||
} else if (inGame) {
|
} else if (inGame) {
|
||||||
long handle = minecraft.window.getHandle();
|
long handle = minecraft.window.getHandle();
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package com.minelittlepony.client.gui;
|
package com.minelittlepony.client.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.Element;
|
||||||
import net.minecraft.client.gui.Screen;
|
import net.minecraft.client.gui.Screen;
|
||||||
import net.minecraft.client.resource.language.I18n;
|
import net.minecraft.client.resource.language.I18n;
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
|
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.MineLittlePony;
|
||||||
import com.minelittlepony.client.render.entities.MobRenderers;
|
import com.minelittlepony.client.render.entities.MobRenderers;
|
||||||
import com.minelittlepony.common.client.gui.GuiHost;
|
import com.minelittlepony.common.client.gui.GameGui;
|
||||||
import com.minelittlepony.common.client.gui.IGuiGuest;
|
import com.minelittlepony.common.client.gui.ScrollContainer;
|
||||||
|
import com.minelittlepony.common.client.gui.element.Button;
|
||||||
import com.minelittlepony.common.client.gui.element.Label;
|
import com.minelittlepony.common.client.gui.element.Label;
|
||||||
import com.minelittlepony.common.client.gui.element.Slider;
|
import com.minelittlepony.common.client.gui.element.Slider;
|
||||||
import com.minelittlepony.common.client.gui.element.Toggle;
|
import com.minelittlepony.common.client.gui.element.Toggle;
|
||||||
|
@ -14,11 +17,13 @@ import com.minelittlepony.settings.PonyConfig;
|
||||||
import com.minelittlepony.settings.PonyLevel;
|
import com.minelittlepony.settings.PonyLevel;
|
||||||
import com.minelittlepony.settings.PonySettings;
|
import com.minelittlepony.settings.PonySettings;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In-Game options menu.
|
* In-Game options menu.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GuiPonySettings implements IGuiGuest {
|
public class GuiPonySettings extends GameGui {
|
||||||
|
|
||||||
private static final String OPTIONS_PREFIX = "minelp.options.";
|
private static final String OPTIONS_PREFIX = "minelp.options.";
|
||||||
|
|
||||||
|
@ -28,23 +33,46 @@ public class GuiPonySettings implements IGuiGuest {
|
||||||
|
|
||||||
private PonyConfig config;
|
private PonyConfig config;
|
||||||
|
|
||||||
|
private final ScrollContainer content = new ScrollContainer();
|
||||||
|
|
||||||
public GuiPonySettings() {
|
public GuiPonySettings() {
|
||||||
|
super(new TranslatableComponent(OPTIONS_PREFIX + "title"));
|
||||||
|
|
||||||
config = MineLittlePony.getInstance().getConfig();
|
config = MineLittlePony.getInstance().getConfig();
|
||||||
|
|
||||||
|
content.margin.top = 30;
|
||||||
|
content.margin.bottom = 30;
|
||||||
|
content.padding.top = 10;
|
||||||
|
content.padding.right = 10;
|
||||||
|
content.padding.bottom = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initGui(GuiHost host) {
|
protected void init() {
|
||||||
final int LEFT = host.width / 10;
|
content.init();
|
||||||
final int RIGHT = host.mustScroll() ? LEFT : host.width - host.width / 3 - 16;
|
content.buttons().clear();
|
||||||
|
content.children().clear();
|
||||||
|
|
||||||
int row = host.mustScroll() ? 0 : 32;
|
int LEFT = content.width / 2 - 210;
|
||||||
|
int RIGHT = content.width / 2 + 10;
|
||||||
|
|
||||||
if (!host.mustScroll()) {
|
if (LEFT < 0) {
|
||||||
host.addButton(new Label(host.width / 2, 12).setCentered()).getStyle().setText(getTitle());
|
LEFT = content.width / 2 - 100;
|
||||||
|
RIGHT = LEFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
host.addButton(new Label(LEFT, row += 15)).getStyle().setText(PONY_LEVEL);
|
int row = 0;
|
||||||
host.addButton(new Slider(LEFT, row += 15, 0, 2, config.getPonyLevel().ordinal())
|
|
||||||
|
((List<Element>)children()).add(content);
|
||||||
|
|
||||||
|
addButton(new Label(width / 2, 12).setCentered()).getStyle().setText(getTitle().getString());
|
||||||
|
addButton(new Button(width / 2 - 100, height - 25))
|
||||||
|
.onClick(sender -> onClose())
|
||||||
|
.getStyle()
|
||||||
|
.setText("gui.done");
|
||||||
|
|
||||||
|
content.addButton(new Label(LEFT, row += 15)).getStyle().setText(PONY_LEVEL);
|
||||||
|
content.addButton(new Slider(LEFT, row += 15, 0, 2, config.getPonyLevel().ordinal())
|
||||||
.onChange(v -> {
|
.onChange(v -> {
|
||||||
PonyLevel level = PonyLevel.valueFor(v);
|
PonyLevel level = PonyLevel.valueFor(v);
|
||||||
config.setPonyLevel(level);
|
config.setPonyLevel(level);
|
||||||
|
@ -53,8 +81,8 @@ public class GuiPonySettings implements IGuiGuest {
|
||||||
.setFormatter(value -> I18n.translate(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase())));
|
.setFormatter(value -> I18n.translate(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase())));
|
||||||
|
|
||||||
if (Screen.hasControlDown() && Screen.hasShiftDown()) {
|
if (Screen.hasControlDown() && Screen.hasShiftDown()) {
|
||||||
host.addButton(new Label(LEFT, row += 30)).getStyle().setText("minelp.debug.scale");
|
content.addButton(new Label(LEFT, row += 30)).getStyle().setText("minelp.debug.scale");
|
||||||
host.addButton(new Slider(LEFT, row += 15, 0.1F, 3, config.getGlobalScaleFactor())
|
content.addButton(new Slider(LEFT, row += 15, 0.1F, 3, config.getGlobalScaleFactor())
|
||||||
.onChange(v -> {
|
.onChange(v -> {
|
||||||
config.setGlobalScaleFactor(v);
|
config.setGlobalScaleFactor(v);
|
||||||
return config.getGlobalScaleFactor();
|
return config.getGlobalScaleFactor();
|
||||||
|
@ -63,25 +91,26 @@ public class GuiPonySettings implements IGuiGuest {
|
||||||
}
|
}
|
||||||
|
|
||||||
row += 15;
|
row += 15;
|
||||||
host.addButton(new Label(LEFT, row += 15)).getStyle().setText(OPTIONS_PREFIX + "options");
|
content.addButton(new Label(LEFT, row += 15)).getStyle().setText(OPTIONS_PREFIX + "options");
|
||||||
for (PonySettings i : PonySettings.values()) {
|
for (PonySettings i : PonySettings.values()) {
|
||||||
host.addButton(new Toggle(LEFT, row += 20, i.get()))
|
content.addButton(new Toggle(LEFT, row += 20, i.get()))
|
||||||
.onChange(i)
|
.onChange(i)
|
||||||
.getStyle().setText(OPTIONS_PREFIX + i.name().toLowerCase());
|
.getStyle().setText(OPTIONS_PREFIX + i.name().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host.mustScroll()) {
|
if (RIGHT != LEFT) {
|
||||||
row += 15;
|
row = 0;
|
||||||
} else {
|
} else {
|
||||||
row = 32;
|
row += 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
host.addButton(new Label(RIGHT, row += 15)).getStyle().setText(MOB_PREFIX + "title");
|
content.addButton(new Label(RIGHT, row += 15)).getStyle().setText(MOB_PREFIX + "title");
|
||||||
for (MobRenderers i : MobRenderers.registry) {
|
for (MobRenderers i : MobRenderers.registry) {
|
||||||
host.addButton(new Toggle(RIGHT, row += 20, i.get()))
|
content.addButton(new Toggle(RIGHT, row += 20, i.get()))
|
||||||
.onChange(i)
|
.onChange(i)
|
||||||
.getStyle().setText(MOB_PREFIX + i.name().toLowerCase());
|
.getStyle().setText(MOB_PREFIX + i.name().toLowerCase());
|
||||||
}
|
}
|
||||||
|
content.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String describeCurrentScale(float value) {
|
public String describeCurrentScale(float value) {
|
||||||
|
@ -104,18 +133,15 @@ public class GuiPonySettings implements IGuiGuest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean render(GuiHost host, int mouseX, int mouseY, float partialTicks) {
|
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||||
host.renderBackground();
|
renderBackground();
|
||||||
return true;
|
super.render(mouseX, mouseY, partialTicks);
|
||||||
|
content.render(mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed(GuiHost host) {
|
public void onClose() {
|
||||||
|
super.onClose();
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTitle() {
|
|
||||||
return OPTIONS_PREFIX + "title";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue