Made settings GUI scrollable for future use.
Split mirror and array settings GUI into their own classes (scrollEntries).
This commit is contained in:
@@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
|
|||||||
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
|
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
|
||||||
|
|
||||||
|
|
||||||
version = "0.3.5"
|
version = "0.5"
|
||||||
group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
archivesBaseName = "effortlessbuilding"
|
archivesBaseName = "effortlessbuilding"
|
||||||
|
|
||||||
|
|||||||
@@ -46,23 +46,23 @@ public class BuildSettingsManager {
|
|||||||
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
|
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
|
||||||
if (m.radius < 1) {
|
if (m.radius < 1) {
|
||||||
m.radius = 1;
|
m.radius = 1;
|
||||||
error += "Mirror size is too small. Size has been reset to 1. ";
|
error += "Mirror size is too small. Size has been set to 1. ";
|
||||||
}
|
}
|
||||||
if (m.getReach() > maxReach) {
|
if (m.getReach() > maxReach) {
|
||||||
m.radius = maxReach / 2;
|
m.radius = maxReach / 2;
|
||||||
error += "Mirror exceeds your maximum reach. Reach has been reset to max. ";
|
error += "Mirror exceeds your maximum reach. Reach has been set to max. ";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Array settings
|
//Array settings
|
||||||
Array.ArraySettings a = buildSettings.getArraySettings();
|
Array.ArraySettings a = buildSettings.getArraySettings();
|
||||||
if (a.count < 0) {
|
if (a.count < 0) {
|
||||||
a.count = 0;
|
a.count = 0;
|
||||||
error += "Array count cannot be negative. Count has been reset to 0. ";
|
error += "Array count cannot be negative. Count has been set to 0. ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.getReach() > maxReach) {
|
if (a.getReach() > maxReach) {
|
||||||
a.count = 0;
|
a.count = 0;
|
||||||
error += "Array exceeds your maximum reach. Count has been reset to 0. ";
|
error += "Array exceeds your maximum reach. Count has been set to 0. ";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Other
|
//Other
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class EffortlessBuilding
|
|||||||
{
|
{
|
||||||
public static final String MODID = "effortlessbuilding";
|
public static final String MODID = "effortlessbuilding";
|
||||||
public static final String NAME = "Effortless Building";
|
public static final String NAME = "Effortless Building";
|
||||||
public static final String VERSION = "0.3.5";
|
public static final String VERSION = "0.5";
|
||||||
|
|
||||||
@Mod.Instance(EffortlessBuilding.MODID)
|
@Mod.Instance(EffortlessBuilding.MODID)
|
||||||
public static EffortlessBuilding instance;
|
public static EffortlessBuilding instance;
|
||||||
|
|||||||
@@ -0,0 +1,201 @@
|
|||||||
|
package nl.requios.effortlessbuilding.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.GuiButton;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraftforge.fml.client.config.GuiCheckBox;
|
||||||
|
import nl.requios.effortlessbuilding.Array;
|
||||||
|
import nl.requios.effortlessbuilding.BuildSettingsManager;
|
||||||
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ArraySettingsGui extends GuiCollapsibleScrollEntry {
|
||||||
|
|
||||||
|
protected List<GuiNumberField> arrayNumberFieldList = new ArrayList<>();
|
||||||
|
|
||||||
|
private GuiCheckBox buttonArrayEnabled;
|
||||||
|
private GuiNumberField textArrayOffsetX, textArrayOffsetY, textArrayOffsetZ, textArrayCount;
|
||||||
|
|
||||||
|
public ArraySettingsGui(GuiScrollPane scrollPane) {
|
||||||
|
super(scrollPane);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int initGui(int id, List<GuiButton> buttonList) {
|
||||||
|
id = super.initGui(id, buttonList);
|
||||||
|
|
||||||
|
int y = top;
|
||||||
|
buttonArrayEnabled = new GuiCheckBox(id++, left - 15 + 8, y, "", false);
|
||||||
|
buttonList.add(buttonArrayEnabled);
|
||||||
|
|
||||||
|
y = top + 20;
|
||||||
|
textArrayOffsetX = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 70, y, 50, 18);
|
||||||
|
textArrayOffsetX.setNumber(0);
|
||||||
|
textArrayOffsetX.setTooltip("How much each copy is shifted.");
|
||||||
|
arrayNumberFieldList.add(textArrayOffsetX);
|
||||||
|
|
||||||
|
textArrayOffsetY = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 140, y, 50, 18);
|
||||||
|
textArrayOffsetY.setNumber(0);
|
||||||
|
textArrayOffsetY.setTooltip("How much each copy is shifted.");
|
||||||
|
arrayNumberFieldList.add(textArrayOffsetY);
|
||||||
|
|
||||||
|
textArrayOffsetZ = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 210, y, 50, 18);
|
||||||
|
textArrayOffsetZ.setNumber(0);
|
||||||
|
textArrayOffsetZ.setTooltip("How much each copy is shifted.");
|
||||||
|
arrayNumberFieldList.add(textArrayOffsetZ);
|
||||||
|
|
||||||
|
y = top + 50;
|
||||||
|
textArrayCount = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 55, y, 50, 18);
|
||||||
|
textArrayCount.setNumber(5);
|
||||||
|
textArrayCount.setTooltip("How many copies should be made.");
|
||||||
|
arrayNumberFieldList.add(textArrayCount);
|
||||||
|
|
||||||
|
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(mc.player);
|
||||||
|
if (buildSettings != null) {
|
||||||
|
Array.ArraySettings a = buildSettings.getArraySettings();
|
||||||
|
buttonArrayEnabled.setIsChecked(a.enabled);
|
||||||
|
textArrayOffsetX.setNumber(a.offset.getX());
|
||||||
|
textArrayOffsetY.setNumber(a.offset.getY());
|
||||||
|
textArrayOffsetZ.setNumber(a.offset.getZ());
|
||||||
|
textArrayCount.setNumber(a.count);
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
super.updateScreen();
|
||||||
|
arrayNumberFieldList.forEach(GuiNumberField::update);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
|
||||||
|
boolean isSelected, float partialTicks) {
|
||||||
|
super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected, partialTicks);
|
||||||
|
|
||||||
|
int yy = y;
|
||||||
|
int offset = 8;
|
||||||
|
|
||||||
|
buttonArrayEnabled.drawButton(this.mc, mouseX, mouseY, partialTicks);
|
||||||
|
if (buttonArrayEnabled.isChecked()) {
|
||||||
|
buttonArrayEnabled.y = yy;
|
||||||
|
fontRenderer.drawString("Array enabled", left + offset, yy + 2, 0xFFFFFF, true);
|
||||||
|
|
||||||
|
yy = y + 20;
|
||||||
|
fontRenderer.drawString("Offset", left + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
fontRenderer.drawString("X", left + 50 + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
textArrayOffsetX.y = yy;
|
||||||
|
fontRenderer.drawString("Y", left + 120 + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
textArrayOffsetY.y = yy;
|
||||||
|
fontRenderer.drawString("Z", left + 190 + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
textArrayOffsetZ.y = yy;
|
||||||
|
|
||||||
|
yy = y + 50;
|
||||||
|
fontRenderer.drawString("Count", left + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
textArrayCount.y = yy;
|
||||||
|
|
||||||
|
int currentReach = Math.max(-1, getArrayReach());
|
||||||
|
int maxReach = BuildSettingsManager.getMaxReach(mc.player);
|
||||||
|
TextFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? TextFormatting.GRAY : TextFormatting.RED;
|
||||||
|
String reachText = "Reach: " + reachColor + currentReach + TextFormatting.GRAY + "/" + TextFormatting.GRAY + maxReach;
|
||||||
|
fontRenderer.drawString(reachText, left + 176 + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
|
||||||
|
arrayNumberFieldList.forEach(numberField -> numberField.drawNumberField(this.mc, mouseX, mouseY, partialTicks));
|
||||||
|
} else {
|
||||||
|
buttonArrayEnabled.y = yy;
|
||||||
|
fontRenderer.drawString("Array disabled", left + offset, yy + 2, 0x999999, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawTooltip(GuiScreen guiScreen, int mouseX, int mouseY) {
|
||||||
|
//Draw tooltips last
|
||||||
|
if (buttonArrayEnabled.isChecked())
|
||||||
|
{
|
||||||
|
arrayNumberFieldList.forEach(numberField -> numberField.drawTooltip(scrollPane.parent, mouseX, mouseY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePosition(int slotIndex, int x, int y, float partialTicks) {
|
||||||
|
super.updatePosition(slotIndex, x, y, partialTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||||
|
super.keyTyped(typedChar, keyCode);
|
||||||
|
for (GuiNumberField numberField : arrayNumberFieldList) {
|
||||||
|
numberField.keyTyped(typedChar, keyCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
|
||||||
|
super.mousePressed(slotIndex, mouseX, mouseY, mouseEvent, relativeX, relativeY);
|
||||||
|
arrayNumberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseEvent));
|
||||||
|
|
||||||
|
boolean insideArrayEnabledLabel = mouseX >= left && mouseX < right && relativeY >= -2 && relativeY < 12;
|
||||||
|
|
||||||
|
if (insideArrayEnabledLabel) {
|
||||||
|
buttonArrayEnabled.setIsChecked(!buttonArrayEnabled.isChecked());
|
||||||
|
buttonArrayEnabled.playPressSound(this.mc.getSoundHandler());
|
||||||
|
actionPerformed(buttonArrayEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(GuiButton button) {
|
||||||
|
super.actionPerformed(button);
|
||||||
|
arrayNumberFieldList.forEach(numberField -> numberField.actionPerformed(button));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Array.ArraySettings getArraySettings() {
|
||||||
|
boolean arrayEnabled = buttonArrayEnabled.isChecked();
|
||||||
|
BlockPos arrayOffset = new BlockPos(0, 0, 0);
|
||||||
|
try {
|
||||||
|
arrayOffset = new BlockPos(textArrayOffsetX.getNumber(), textArrayOffsetY.getNumber(), textArrayOffsetZ.getNumber());
|
||||||
|
} catch (NumberFormatException | NullPointerException ex) {
|
||||||
|
EffortlessBuilding.log(mc.player, "Array offset not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
int arrayCount = 5;
|
||||||
|
try {
|
||||||
|
arrayCount = (int) textArrayCount.getNumber();
|
||||||
|
} catch (NumberFormatException | NullPointerException ex) {
|
||||||
|
EffortlessBuilding.log(mc.player, "Array count not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Array.ArraySettings(arrayEnabled, arrayOffset, arrayCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getName() {
|
||||||
|
return "Array";
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getArrayReach() {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//find largest offset
|
||||||
|
double x = Math.abs(textArrayOffsetX.getNumber());
|
||||||
|
double y = Math.abs(textArrayOffsetY.getNumber());
|
||||||
|
double z = Math.abs(textArrayOffsetZ.getNumber());
|
||||||
|
double largestOffset = Math.max(Math.max(x, y), z);
|
||||||
|
return (int) (largestOffset * textArrayCount.getNumber());
|
||||||
|
} catch (NumberFormatException | NullPointerException ex) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCurrentReachValid(int currentReach, int maxReach) {
|
||||||
|
return currentReach <= maxReach && currentReach > -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package nl.requios.effortlessbuilding.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.client.gui.GuiButton;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class GuiCollapsibleScrollEntry implements GuiScrollPane.IScrollEntry {
|
||||||
|
|
||||||
|
public GuiScrollPane scrollPane;
|
||||||
|
protected FontRenderer fontRenderer;
|
||||||
|
protected Minecraft mc;
|
||||||
|
protected int left, right, top, bottom;
|
||||||
|
|
||||||
|
public GuiCollapsibleScrollEntry(GuiScrollPane scrollPane) {
|
||||||
|
this.scrollPane = scrollPane;
|
||||||
|
this.fontRenderer = scrollPane.fontRenderer;
|
||||||
|
this.mc = scrollPane.parent.mc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int initGui(int id, List<GuiButton> buttonList) {
|
||||||
|
|
||||||
|
left = scrollPane.width / 2 - 140;
|
||||||
|
right = scrollPane.width / 2 + 140;
|
||||||
|
top = scrollPane.height / 2 - 100;
|
||||||
|
bottom = scrollPane.height / 2 + 100;
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
|
||||||
|
boolean isSelected, float partialTicks) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawTooltip(GuiScreen guiScreen, int mouseX, int mouseY) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePosition(int slotIndex, int x, int y, float partialTicks) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyTyped(char eventChar, int eventKey) throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(GuiButton button) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuiClosed() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getName() {
|
||||||
|
return "Collapsible scroll entry";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,6 +73,10 @@ public class GuiNumberField extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawNumberField(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
public void drawNumberField(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||||
|
textField.y = y + 1;
|
||||||
|
minusButton.y = y - 1;
|
||||||
|
plusButton.y = y - 1;
|
||||||
|
|
||||||
textField.drawTextBox();
|
textField.drawTextBox();
|
||||||
minusButton.drawButton(mc, mouseX, mouseY, partialTicks);
|
minusButton.drawButton(mc, mouseX, mouseY, partialTicks);
|
||||||
plusButton.drawButton(mc, mouseX, mouseY, partialTicks);
|
plusButton.drawButton(mc, mouseX, mouseY, partialTicks);
|
||||||
@@ -131,19 +135,20 @@ public class GuiNumberField extends Gui {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleMouseInput(int mouseX, int mouseY) {
|
//Scroll inside textfield to change number
|
||||||
boolean insideTextField = mouseX >= x + buttonWidth && mouseX < x + width - buttonWidth && mouseY >= y && mouseY < y + height;
|
// public void handleMouseInput(int mouseX, int mouseY) {
|
||||||
|
// boolean insideTextField = mouseX >= x + buttonWidth && mouseX < x + width - buttonWidth && mouseY >= y && mouseY < y + height;
|
||||||
if (insideTextField)
|
//
|
||||||
{
|
// if (insideTextField)
|
||||||
int valueChanged = 0;
|
// {
|
||||||
if (Mouse.getEventDWheel() > 0)
|
// int valueChanged = 0;
|
||||||
valueChanged = 1;
|
// if (Mouse.getEventDWheel() > 0)
|
||||||
if (Mouse.getEventDWheel() < 0)
|
// valueChanged = 1;
|
||||||
valueChanged = -1;
|
// if (Mouse.getEventDWheel() < 0)
|
||||||
|
// valueChanged = -1;
|
||||||
if (valueChanged != 0)
|
//
|
||||||
setNumber(getNumber() + valueChanged);
|
// if (valueChanged != 0)
|
||||||
}
|
// setNumber(getNumber() + valueChanged);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,209 @@
|
|||||||
|
package nl.requios.effortlessbuilding.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.client.gui.GuiButton;
|
||||||
|
import net.minecraft.client.gui.GuiListExtended;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public class GuiScrollPane extends GuiListExtended {
|
||||||
|
|
||||||
|
public GuiScreen parent;
|
||||||
|
public FontRenderer fontRenderer;
|
||||||
|
public List<IScrollEntry> listEntries;
|
||||||
|
|
||||||
|
public GuiScrollPane(GuiScreen parent, FontRenderer fontRenderer, int top, int bottom) {
|
||||||
|
super(parent.mc, parent.width, parent.height, top, bottom, 100);
|
||||||
|
this.parent = parent;
|
||||||
|
this.fontRenderer = fontRenderer;
|
||||||
|
this.setShowSelectionBox(false);
|
||||||
|
listEntries = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IGuiListEntry getListEntry(int index) {
|
||||||
|
return listEntries.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getSize() {
|
||||||
|
return listEntries.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getContentHeight() {
|
||||||
|
//TODO add every entry height
|
||||||
|
return this.getSize() * this.slotHeight + this.headerPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getScrollBarX() {
|
||||||
|
//return width / 2 + 140 + 10;
|
||||||
|
return width - 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawScreen(int mouseXIn, int mouseYIn, float partialTicks)
|
||||||
|
{
|
||||||
|
if (this.visible)
|
||||||
|
{
|
||||||
|
this.mouseX = mouseXIn;
|
||||||
|
this.mouseY = mouseYIn;
|
||||||
|
int i = this.getScrollBarX();
|
||||||
|
int j = i + 6;
|
||||||
|
this.bindAmountScrolled();
|
||||||
|
GlStateManager.disableLighting();
|
||||||
|
GlStateManager.disableFog();
|
||||||
|
|
||||||
|
//Own code: clipping
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder bufferbuilder = tessellator.getBuffer();
|
||||||
|
int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
|
||||||
|
int l = this.top + 4 - (int)this.amountScrolled;
|
||||||
|
|
||||||
|
if (this.hasListHeader)
|
||||||
|
{
|
||||||
|
this.drawListHeader(k, l, tessellator);
|
||||||
|
}
|
||||||
|
|
||||||
|
//All entries
|
||||||
|
this.drawSelectionBox(k, l, mouseXIn, mouseYIn, partialTicks);
|
||||||
|
GlStateManager.disableDepth();
|
||||||
|
//Dirt overlays on top and bottom
|
||||||
|
this.overlayBackground(0, this.top, 255, 255);
|
||||||
|
this.overlayBackground(this.bottom, this.height, 255, 255);
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
|
||||||
|
GlStateManager.disableAlpha();
|
||||||
|
GlStateManager.shadeModel(7425);
|
||||||
|
GlStateManager.disableTexture2D();
|
||||||
|
//top fade
|
||||||
|
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||||
|
bufferbuilder.pos((double)this.left, (double)(this.top + 5), 0.0D).tex(0.0D, 1.0D).color(100, 100, 100, 0).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.right, (double)(this.top + 5), 0.0D).tex(1.0D, 1.0D).color(100, 100, 100, 0).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(100, 100, 100, 100).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(100, 100, 100, 100).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
//top line
|
||||||
|
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||||
|
bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 1.0D).color(20, 20, 20, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.right, (double)(this.top - 1), 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.left, (double)(this.top - 1), 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
//bottom fade
|
||||||
|
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||||
|
bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(10, 10, 10, 100).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(10, 10, 10, 100).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.right, (double)(this.bottom - 5), 0.0D).tex(1.0D, 0.0D).color(10, 10, 10, 0).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.left, (double)(this.bottom - 5), 0.0D).tex(0.0D, 0.0D).color(10, 10, 10, 0).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
//bottom line
|
||||||
|
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||||
|
bufferbuilder.pos((double)this.left, (double)(this.bottom + 1), 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.right, (double)(this.bottom + 1), 0.0D).tex(1.0D, 1.0D).color(20, 20, 20, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
int j1 = this.getMaxScroll();
|
||||||
|
|
||||||
|
if (j1 > 0)
|
||||||
|
{
|
||||||
|
int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
|
||||||
|
k1 = MathHelper.clamp(k1, 32, this.bottom - this.top - 8);
|
||||||
|
int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top;
|
||||||
|
|
||||||
|
if (l1 < this.top)
|
||||||
|
{
|
||||||
|
l1 = this.top;
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||||
|
bufferbuilder.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||||
|
bufferbuilder.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)j, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||||
|
bufferbuilder.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
|
||||||
|
bufferbuilder.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
GlStateManager.enableTexture2D();
|
||||||
|
GlStateManager.shadeModel(7424);
|
||||||
|
GlStateManager.enableAlpha();
|
||||||
|
GlStateManager.disableBlend();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//PASSTHROUGHS
|
||||||
|
public int initGui(int id, List<GuiButton> buttonList) {
|
||||||
|
for (IScrollEntry entry : this.listEntries) {
|
||||||
|
id = entry.initGui(id, buttonList);
|
||||||
|
}
|
||||||
|
registerScrollButtons(id++, id++);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateScreen() {
|
||||||
|
for (IScrollEntry entry : this.listEntries)
|
||||||
|
entry.updateScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawTooltip(GuiScreen guiScreen, int mouseX, int mouseY) {
|
||||||
|
for (IScrollEntry entry : this.listEntries)
|
||||||
|
entry.drawTooltip(guiScreen, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(char eventChar, int eventKey) throws IOException {
|
||||||
|
for (IScrollEntry entry : this.listEntries)
|
||||||
|
entry.keyTyped(eventChar, eventKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(GuiButton button) {
|
||||||
|
for (IScrollEntry entry : this.listEntries)
|
||||||
|
entry.actionPerformed(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onGuiClosed() {
|
||||||
|
for (IScrollEntry entry : this.listEntries)
|
||||||
|
entry.onGuiClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IScrollEntry extends GuiListExtended.IGuiListEntry {
|
||||||
|
int initGui(int id, List<GuiButton> buttonList);
|
||||||
|
|
||||||
|
void updateScreen();
|
||||||
|
|
||||||
|
void drawTooltip(GuiScreen guiScreen, int mouseX, int mouseY);
|
||||||
|
|
||||||
|
void keyTyped(char eventChar, int eventKey) throws IOException;
|
||||||
|
|
||||||
|
void actionPerformed(GuiButton button);
|
||||||
|
|
||||||
|
void onGuiClosed();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,284 @@
|
|||||||
|
package nl.requios.effortlessbuilding.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.GuiButton;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraftforge.fml.client.config.GuiCheckBox;
|
||||||
|
import nl.requios.effortlessbuilding.BuildSettingsManager;
|
||||||
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
|
import nl.requios.effortlessbuilding.Mirror;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MirrorSettingsGui extends GuiCollapsibleScrollEntry {
|
||||||
|
|
||||||
|
protected static final ResourceLocation BUILDING_ICONS = new ResourceLocation(EffortlessBuilding.MODID, "textures/gui/building_icons.png");
|
||||||
|
|
||||||
|
protected List<GuiButton> mirrorButtonList = new ArrayList<>();
|
||||||
|
protected List<GuiIconButton> mirrorIconButtonList = new ArrayList<>();
|
||||||
|
protected List<GuiNumberField> mirrorNumberFieldList = new ArrayList<>();
|
||||||
|
|
||||||
|
private GuiNumberField textMirrorPosX, textMirrorPosY, textMirrorPosZ, textMirrorRadius;
|
||||||
|
private GuiCheckBox buttonMirrorEnabled, buttonMirrorX, buttonMirrorY, buttonMirrorZ;
|
||||||
|
private GuiIconButton buttonCurrentPosition, buttonToggleOdd, buttonDrawPlanes, buttonDrawLines;
|
||||||
|
private boolean drawPlanes, drawLines, toggleOdd;
|
||||||
|
|
||||||
|
public MirrorSettingsGui(GuiScrollPane scrollPane) {
|
||||||
|
super(scrollPane);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int initGui(int id, List<GuiButton> buttonList) {
|
||||||
|
id = super.initGui(id, buttonList);
|
||||||
|
|
||||||
|
int y = top - 2;
|
||||||
|
buttonMirrorEnabled = new GuiCheckBox(id++, left - 15 + 8, y, "", false);
|
||||||
|
buttonList.add(buttonMirrorEnabled);
|
||||||
|
|
||||||
|
y = top + 18;
|
||||||
|
textMirrorPosX = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 58, y, 62, 18);
|
||||||
|
textMirrorPosX.setNumber(0);
|
||||||
|
textMirrorPosX.setTooltip(
|
||||||
|
Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
|
||||||
|
mirrorNumberFieldList.add(textMirrorPosX);
|
||||||
|
|
||||||
|
textMirrorPosY = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 138, y, 62, 18);
|
||||||
|
textMirrorPosY.setNumber(64);
|
||||||
|
textMirrorPosY.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
|
||||||
|
mirrorNumberFieldList.add(textMirrorPosY);
|
||||||
|
|
||||||
|
textMirrorPosZ = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 218, y, 62, 18);
|
||||||
|
textMirrorPosZ.setNumber(0);
|
||||||
|
textMirrorPosZ.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
|
||||||
|
mirrorNumberFieldList.add(textMirrorPosZ);
|
||||||
|
|
||||||
|
y = top + 50;
|
||||||
|
buttonMirrorX = new GuiCheckBox(id++, left + 60, y, " X", true);
|
||||||
|
mirrorButtonList.add(buttonMirrorX);
|
||||||
|
|
||||||
|
buttonMirrorY = new GuiCheckBox(id++, left + 100, y, " Y", false);
|
||||||
|
mirrorButtonList.add(buttonMirrorY);
|
||||||
|
|
||||||
|
buttonMirrorZ = new GuiCheckBox(id++, left + 140, y, " Z", false);
|
||||||
|
mirrorButtonList.add(buttonMirrorZ);
|
||||||
|
|
||||||
|
y = top + 47;
|
||||||
|
textMirrorRadius = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 218, y, 62, 18);
|
||||||
|
textMirrorRadius.setNumber(50);
|
||||||
|
//TODO change to diameter (remove /2)
|
||||||
|
textMirrorRadius.setTooltip(Arrays.asList("How far the mirror reaches in any direction.",
|
||||||
|
TextFormatting.GRAY + "Max: " + TextFormatting.GOLD + BuildSettingsManager.getMaxReach(mc.player) / 2,
|
||||||
|
TextFormatting.GRAY + "Upgradeable in survival with reach upgrades."));
|
||||||
|
mirrorNumberFieldList.add(textMirrorRadius);
|
||||||
|
|
||||||
|
y = top + 72;
|
||||||
|
buttonCurrentPosition = new GuiIconButton(id++, left + 5, y, 0, 0, BUILDING_ICONS);
|
||||||
|
buttonCurrentPosition.setTooltip("Set mirror position to current player position");
|
||||||
|
mirrorIconButtonList.add(buttonCurrentPosition);
|
||||||
|
|
||||||
|
buttonToggleOdd = new GuiIconButton(id++, left + 35, y, 0, 20, BUILDING_ICONS);
|
||||||
|
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
|
||||||
|
mirrorIconButtonList.add(buttonToggleOdd);
|
||||||
|
|
||||||
|
buttonDrawLines = new GuiIconButton(id++, left + 65, y, 0, 40, BUILDING_ICONS);
|
||||||
|
buttonDrawLines.setTooltip("Show lines");
|
||||||
|
mirrorIconButtonList.add(buttonDrawLines);
|
||||||
|
|
||||||
|
buttonDrawPlanes = new GuiIconButton(id++, left + 95, y, 0, 60, BUILDING_ICONS);
|
||||||
|
buttonDrawPlanes.setTooltip("Show area");
|
||||||
|
mirrorIconButtonList.add(buttonDrawPlanes);
|
||||||
|
|
||||||
|
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(mc.player);
|
||||||
|
if (buildSettings != null) {
|
||||||
|
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
|
||||||
|
buttonMirrorEnabled.setIsChecked(m.enabled);
|
||||||
|
textMirrorPosX.setNumber(m.position.x);
|
||||||
|
textMirrorPosY.setNumber(m.position.y);
|
||||||
|
textMirrorPosZ.setNumber(m.position.z);
|
||||||
|
buttonMirrorX.setIsChecked(m.mirrorX);
|
||||||
|
buttonMirrorY.setIsChecked(m.mirrorY);
|
||||||
|
buttonMirrorZ.setIsChecked(m.mirrorZ);
|
||||||
|
textMirrorRadius.setNumber(m.radius);
|
||||||
|
drawLines = m.drawLines;
|
||||||
|
drawPlanes = m.drawPlanes;
|
||||||
|
buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||||
|
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||||
|
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
|
||||||
|
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
|
||||||
|
if (textMirrorPosX.getNumber() == Math.floor(textMirrorPosX.getNumber())) {
|
||||||
|
toggleOdd = false;
|
||||||
|
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
|
||||||
|
} else {
|
||||||
|
toggleOdd = true;
|
||||||
|
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to corner of block", "for even numbered builds"));
|
||||||
|
}
|
||||||
|
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonList.addAll(mirrorButtonList);
|
||||||
|
buttonList.addAll(mirrorIconButtonList);
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
super.updateScreen();
|
||||||
|
mirrorNumberFieldList.forEach(GuiNumberField::update);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY,
|
||||||
|
boolean isSelected, float partialTicks) {
|
||||||
|
super.drawEntry(slotIndex, x, y, listWidth, slotHeight, mouseX, mouseY, isSelected, partialTicks);
|
||||||
|
|
||||||
|
int yy = y;
|
||||||
|
int offset = 8;
|
||||||
|
|
||||||
|
buttonMirrorEnabled.drawButton(this.mc, mouseX, mouseY, partialTicks);
|
||||||
|
if (buttonMirrorEnabled.isChecked()) {
|
||||||
|
buttonMirrorEnabled.y = yy;
|
||||||
|
fontRenderer.drawString("Mirror enabled", left + offset, yy + 2, 0xFFFFFF, true);
|
||||||
|
|
||||||
|
yy = y + 18;
|
||||||
|
fontRenderer.drawString("Position", left + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
fontRenderer.drawString("X", left + 40 + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
textMirrorPosX.y = yy;
|
||||||
|
fontRenderer.drawString("Y", left + 120 + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
textMirrorPosY.y = yy;
|
||||||
|
fontRenderer.drawString("Z", left + 200 + offset, yy + 5, 0xFFFFFF, true);
|
||||||
|
textMirrorPosZ.y = yy;
|
||||||
|
|
||||||
|
yy = y + 50;
|
||||||
|
fontRenderer.drawString("Direction", left + offset, yy + 2, 0xFFFFFF, true);
|
||||||
|
buttonMirrorX.y = yy;
|
||||||
|
buttonMirrorY.y = yy;
|
||||||
|
buttonMirrorZ.y = yy;
|
||||||
|
fontRenderer.drawString("Reach", left + 176 + offset, yy + 2, 0xFFFFFF, true);
|
||||||
|
textMirrorRadius.y = yy - 3;
|
||||||
|
|
||||||
|
yy = y + 72;
|
||||||
|
buttonCurrentPosition.y = yy;
|
||||||
|
buttonToggleOdd.y = yy;
|
||||||
|
buttonDrawLines.y = yy;
|
||||||
|
buttonDrawPlanes.y = yy;
|
||||||
|
|
||||||
|
mirrorButtonList.forEach(button -> button.drawButton(this.mc, mouseX, mouseY, partialTicks));
|
||||||
|
mirrorIconButtonList.forEach(button -> button.drawButton(this.mc, mouseX, mouseY, partialTicks));
|
||||||
|
mirrorNumberFieldList.forEach(numberField -> numberField.drawNumberField(this.mc, mouseX, mouseY, partialTicks));
|
||||||
|
} else {
|
||||||
|
buttonMirrorEnabled.y = yy;
|
||||||
|
fontRenderer.drawString("Mirror disabled", left + offset, yy + 2, 0x999999, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawTooltip(GuiScreen guiScreen, int mouseX, int mouseY) {
|
||||||
|
//Draw tooltips last
|
||||||
|
if (buttonMirrorEnabled.isChecked())
|
||||||
|
{
|
||||||
|
mirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(scrollPane.parent, mouseX, mouseY));
|
||||||
|
mirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(scrollPane.parent, mouseX, mouseY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePosition(int slotIndex, int x, int y, float partialTicks) {
|
||||||
|
super.updatePosition(slotIndex, x, y, partialTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||||
|
super.keyTyped(typedChar, keyCode);
|
||||||
|
for (GuiNumberField numberField : mirrorNumberFieldList) {
|
||||||
|
numberField.keyTyped(typedChar, keyCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY) {
|
||||||
|
super.mousePressed(slotIndex, mouseX, mouseY, mouseEvent, relativeX, relativeY);
|
||||||
|
mirrorNumberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseEvent));
|
||||||
|
|
||||||
|
boolean insideMirrorEnabledLabel = mouseX >= left && mouseX < right && relativeY >= -2 && relativeY < 12;
|
||||||
|
|
||||||
|
if (insideMirrorEnabledLabel) {
|
||||||
|
buttonMirrorEnabled.setIsChecked(!buttonMirrorEnabled.isChecked());
|
||||||
|
buttonMirrorEnabled.playPressSound(this.mc.getSoundHandler());
|
||||||
|
actionPerformed(buttonMirrorEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(GuiButton button) {
|
||||||
|
super.actionPerformed(button);
|
||||||
|
if (button == buttonCurrentPosition) {
|
||||||
|
Vec3d pos = new Vec3d(Math.floor(mc.player.posX) + 0.5, Math.floor(mc.player.posY) + 0.5, Math.floor(mc.player.posZ) + 0.5);
|
||||||
|
textMirrorPosX.setNumber(pos.x);
|
||||||
|
textMirrorPosY.setNumber(pos.y);
|
||||||
|
textMirrorPosZ.setNumber(pos.z);
|
||||||
|
}
|
||||||
|
if (button == buttonToggleOdd) {
|
||||||
|
toggleOdd = !toggleOdd;
|
||||||
|
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
||||||
|
if (toggleOdd) {
|
||||||
|
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to corner of block", "for even numbered builds"));
|
||||||
|
textMirrorPosX.setNumber(textMirrorPosX.getNumber() + 0.5);
|
||||||
|
textMirrorPosY.setNumber(textMirrorPosY.getNumber() + 0.5);
|
||||||
|
textMirrorPosZ.setNumber(textMirrorPosZ.getNumber() + 0.5);
|
||||||
|
} else {
|
||||||
|
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
|
||||||
|
textMirrorPosX.setNumber(Math.floor(textMirrorPosX.getNumber()));
|
||||||
|
textMirrorPosY.setNumber(Math.floor(textMirrorPosY.getNumber()));
|
||||||
|
textMirrorPosZ.setNumber(Math.floor(textMirrorPosZ.getNumber()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (button == buttonDrawLines) {
|
||||||
|
drawLines = !drawLines;
|
||||||
|
buttonDrawLines.setUseAlternateIcon(drawLines);
|
||||||
|
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
|
||||||
|
}
|
||||||
|
if (button == buttonDrawPlanes) {
|
||||||
|
drawPlanes = !drawPlanes;
|
||||||
|
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
||||||
|
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
|
||||||
|
}
|
||||||
|
mirrorNumberFieldList.forEach(numberField -> numberField.actionPerformed(button));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mirror.MirrorSettings getMirrorSettings() {
|
||||||
|
boolean mirrorEnabled = buttonMirrorEnabled.isChecked();
|
||||||
|
|
||||||
|
Vec3d mirrorPos = new Vec3d(0, 64, 0);
|
||||||
|
try {
|
||||||
|
mirrorPos = new Vec3d(textMirrorPosX.getNumber(), textMirrorPosY.getNumber(), textMirrorPosZ.getNumber());
|
||||||
|
} catch (NumberFormatException | NullPointerException ex) {
|
||||||
|
EffortlessBuilding.log(mc.player, "Mirror position not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean mirrorX = buttonMirrorX.isChecked();
|
||||||
|
boolean mirrorY = buttonMirrorY.isChecked();
|
||||||
|
boolean mirrorZ = buttonMirrorZ.isChecked();
|
||||||
|
|
||||||
|
int mirrorRadius = 50;
|
||||||
|
try {
|
||||||
|
mirrorRadius = (int) textMirrorRadius.getNumber();
|
||||||
|
} catch (NumberFormatException | NullPointerException ex) {
|
||||||
|
EffortlessBuilding.log(mc.player, "Mirror radius not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Mirror.MirrorSettings(mirrorEnabled, mirrorPos, mirrorX, mirrorY, mirrorZ, mirrorRadius, drawLines, drawPlanes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getName() {
|
||||||
|
return "Mirror";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,190 +2,53 @@ package nl.requios.effortlessbuilding.gui;
|
|||||||
|
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import net.minecraftforge.fml.client.config.GuiCheckBox;
|
|
||||||
import nl.requios.effortlessbuilding.Array;
|
import nl.requios.effortlessbuilding.Array;
|
||||||
import nl.requios.effortlessbuilding.BuildSettingsManager;
|
import nl.requios.effortlessbuilding.BuildSettingsManager;
|
||||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||||
import nl.requios.effortlessbuilding.Mirror;
|
import nl.requios.effortlessbuilding.Mirror;
|
||||||
import nl.requios.effortlessbuilding.network.BuildSettingsMessage;
|
import nl.requios.effortlessbuilding.network.BuildSettingsMessage;
|
||||||
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
||||||
import org.lwjgl.input.Mouse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SettingsGui extends GuiScreen {
|
public class SettingsGui extends GuiScreen {
|
||||||
|
|
||||||
protected static final ResourceLocation BUILDING_ICONS = new ResourceLocation(EffortlessBuilding.MODID, "textures/gui/building_icons.png");
|
private GuiScrollPane scrollPane;
|
||||||
|
|
||||||
protected List<GuiNumberField> numberFieldList = new ArrayList<>();
|
|
||||||
|
|
||||||
protected List<GuiButton> mirrorButtonList = new ArrayList<>();
|
|
||||||
protected List<GuiIconButton> mirrorIconButtonList = new ArrayList<>();
|
|
||||||
protected List<GuiNumberField> mirrorNumberFieldList = new ArrayList<>();
|
|
||||||
protected List<GuiNumberField> arrayNumberFieldList = new ArrayList<>();
|
|
||||||
|
|
||||||
private GuiNumberField textMirrorPosX, textMirrorPosY, textMirrorPosZ, textMirrorRadius;
|
|
||||||
private GuiCheckBox buttonMirrorEnabled, buttonMirrorX, buttonMirrorY, buttonMirrorZ;
|
|
||||||
private GuiIconButton buttonCurrentPosition, buttonToggleOdd, buttonDrawPlanes, buttonDrawLines;
|
|
||||||
private boolean drawPlanes, drawLines, toggleOdd;
|
|
||||||
private GuiButton buttonClose;
|
private GuiButton buttonClose;
|
||||||
|
|
||||||
private GuiCheckBox buttonArrayEnabled;
|
private MirrorSettingsGui mirrorSettingsGui;
|
||||||
private GuiNumberField textArrayOffsetX, textArrayOffsetY, textArrayOffsetZ, textArrayCount;
|
private ArraySettingsGui arraySettingsGui;
|
||||||
|
|
||||||
private int left, right, top, bottom;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
//Create buttons and labels and add them to buttonList/labelList
|
//Create buttons and labels and add them to buttonList/labelList
|
||||||
public void initGui() {
|
public void initGui() {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
left = width / 2 - 140;
|
|
||||||
right = width / 2 + 140;
|
|
||||||
top = height / 2 - 100;
|
|
||||||
bottom = height / 2 + 100;
|
|
||||||
|
|
||||||
//MIRROR
|
scrollPane = new GuiScrollPane(this, fontRenderer, 8, height - 17);
|
||||||
int y = top - 2;
|
|
||||||
buttonMirrorEnabled = new GuiCheckBox(id++, left - 15 + 8, y, "", false);
|
|
||||||
buttonList.add(buttonMirrorEnabled);
|
|
||||||
|
|
||||||
y = top + 18;
|
mirrorSettingsGui = new MirrorSettingsGui(scrollPane);
|
||||||
textMirrorPosX = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 58, y, 62, 18);
|
scrollPane.listEntries.add(mirrorSettingsGui);
|
||||||
textMirrorPosX.setNumber(0);
|
|
||||||
textMirrorPosX.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
|
|
||||||
mirrorNumberFieldList.add(textMirrorPosX);
|
|
||||||
|
|
||||||
textMirrorPosY = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 138, y, 62, 18);
|
arraySettingsGui = new ArraySettingsGui(scrollPane);
|
||||||
textMirrorPosY.setNumber(64);
|
scrollPane.listEntries.add(arraySettingsGui);
|
||||||
textMirrorPosY.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
|
|
||||||
mirrorNumberFieldList.add(textMirrorPosY);
|
|
||||||
|
|
||||||
textMirrorPosZ = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 218, y, 62, 18);
|
//TODO for testing
|
||||||
textMirrorPosZ.setNumber(0);
|
mirrorSettingsGui = new MirrorSettingsGui(scrollPane);
|
||||||
textMirrorPosZ.setTooltip(Arrays.asList("The position of the mirror.", TextFormatting.GRAY + "For odd numbered builds add 0.5."));
|
scrollPane.listEntries.add(mirrorSettingsGui);
|
||||||
mirrorNumberFieldList.add(textMirrorPosZ);
|
|
||||||
|
|
||||||
y = top + 50;
|
id = scrollPane.initGui(id, buttonList);
|
||||||
buttonMirrorX = new GuiCheckBox(id++, left + 60, y, " X", true);
|
|
||||||
mirrorButtonList.add(buttonMirrorX);
|
|
||||||
|
|
||||||
buttonMirrorY = new GuiCheckBox(id++, left + 100, y, " Y", false);
|
//Close button
|
||||||
mirrorButtonList.add(buttonMirrorY);
|
int y = height - 26;
|
||||||
|
|
||||||
buttonMirrorZ = new GuiCheckBox(id++, left + 140, y, " Z", false);
|
|
||||||
mirrorButtonList.add(buttonMirrorZ);
|
|
||||||
|
|
||||||
y = top + 47;
|
|
||||||
textMirrorRadius = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 218, y, 62, 18);
|
|
||||||
textMirrorRadius.setNumber(50);
|
|
||||||
//TODO change to diameter (remove /2)
|
|
||||||
textMirrorRadius.setTooltip(Arrays.asList("How far the mirror reaches in any direction.",
|
|
||||||
TextFormatting.GRAY + "Max: " + TextFormatting.GOLD + BuildSettingsManager.getMaxReach(mc.player) / 2,
|
|
||||||
TextFormatting.GRAY + "Upgradeable in survival with reach upgrades."));
|
|
||||||
mirrorNumberFieldList.add(textMirrorRadius);
|
|
||||||
|
|
||||||
y = top + 72;
|
|
||||||
buttonCurrentPosition = new GuiIconButton(id++, left + 5, y, 0, 0, BUILDING_ICONS);
|
|
||||||
buttonCurrentPosition.setTooltip("Set mirror position to current player position");
|
|
||||||
mirrorIconButtonList.add(buttonCurrentPosition);
|
|
||||||
|
|
||||||
buttonToggleOdd = new GuiIconButton(id++, left + 35, y, 0, 20, BUILDING_ICONS);
|
|
||||||
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
|
|
||||||
mirrorIconButtonList.add(buttonToggleOdd);
|
|
||||||
|
|
||||||
buttonDrawLines = new GuiIconButton(id++, left + 65, y, 0, 40, BUILDING_ICONS);
|
|
||||||
buttonDrawLines.setTooltip("Show lines");
|
|
||||||
mirrorIconButtonList.add(buttonDrawLines);
|
|
||||||
|
|
||||||
buttonDrawPlanes = new GuiIconButton(id++, left + 95, y, 0, 60, BUILDING_ICONS);
|
|
||||||
buttonDrawPlanes.setTooltip("Show area");
|
|
||||||
mirrorIconButtonList.add(buttonDrawPlanes);
|
|
||||||
|
|
||||||
//ARRAY
|
|
||||||
y = top + 100;
|
|
||||||
buttonArrayEnabled = new GuiCheckBox(id++, left - 15 + 8, y, "", false);
|
|
||||||
buttonList.add(buttonArrayEnabled);
|
|
||||||
|
|
||||||
y = top + 120;
|
|
||||||
textArrayOffsetX = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 70, y, 50, 18);
|
|
||||||
textArrayOffsetX.setNumber(0);
|
|
||||||
textArrayOffsetX.setTooltip("How much each copy is shifted.");
|
|
||||||
arrayNumberFieldList.add(textArrayOffsetX);
|
|
||||||
|
|
||||||
textArrayOffsetY = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 140, y, 50, 18);
|
|
||||||
textArrayOffsetY.setNumber(0);
|
|
||||||
textArrayOffsetY.setTooltip("How much each copy is shifted.");
|
|
||||||
arrayNumberFieldList.add(textArrayOffsetY);
|
|
||||||
|
|
||||||
textArrayOffsetZ = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 210, y, 50, 18);
|
|
||||||
textArrayOffsetZ.setNumber(0);
|
|
||||||
textArrayOffsetZ.setTooltip("How much each copy is shifted.");
|
|
||||||
arrayNumberFieldList.add(textArrayOffsetZ);
|
|
||||||
|
|
||||||
y = top + 150;
|
|
||||||
textArrayCount = new GuiNumberField(id++, id++, id++, fontRenderer, buttonList, left + 55, y, 50, 18);
|
|
||||||
textArrayCount.setNumber(5);
|
|
||||||
textArrayCount.setTooltip("How many copies should be made.");
|
|
||||||
arrayNumberFieldList.add(textArrayCount);
|
|
||||||
|
|
||||||
//CLOSE
|
|
||||||
y = height - 40;
|
|
||||||
buttonClose = new GuiButton(id++, width / 2 - 100, y, "Close");
|
buttonClose = new GuiButton(id++, width / 2 - 100, y, "Close");
|
||||||
buttonList.add(buttonClose);
|
buttonList.add(buttonClose);
|
||||||
|
|
||||||
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(mc.player);
|
|
||||||
if (buildSettings != null) {
|
|
||||||
//MIRROR
|
|
||||||
Mirror.MirrorSettings m = buildSettings.getMirrorSettings();
|
|
||||||
buttonMirrorEnabled.setIsChecked(m.enabled);
|
|
||||||
textMirrorPosX.setNumber(m.position.x);
|
|
||||||
textMirrorPosY.setNumber(m.position.y);
|
|
||||||
textMirrorPosZ.setNumber(m.position.z);
|
|
||||||
buttonMirrorX.setIsChecked(m.mirrorX);
|
|
||||||
buttonMirrorY.setIsChecked(m.mirrorY);
|
|
||||||
buttonMirrorZ.setIsChecked(m.mirrorZ);
|
|
||||||
textMirrorRadius.setNumber(m.radius);
|
|
||||||
drawLines = m.drawLines;
|
|
||||||
drawPlanes = m.drawPlanes;
|
|
||||||
buttonDrawLines.setUseAlternateIcon(drawLines);
|
|
||||||
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
|
||||||
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
|
|
||||||
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
|
|
||||||
if (textMirrorPosX.getNumber() == Math.floor(textMirrorPosX.getNumber())) {
|
|
||||||
toggleOdd = false;
|
|
||||||
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
|
|
||||||
} else {
|
|
||||||
toggleOdd = true;
|
|
||||||
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to corner of block", "for even numbered builds"));
|
|
||||||
}
|
|
||||||
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
|
||||||
|
|
||||||
//ARRAY
|
|
||||||
Array.ArraySettings a = buildSettings.getArraySettings();
|
|
||||||
buttonArrayEnabled.setIsChecked(a.enabled);
|
|
||||||
textArrayOffsetX.setNumber(a.offset.getX());
|
|
||||||
textArrayOffsetY.setNumber(a.offset.getY());
|
|
||||||
textArrayOffsetZ.setNumber(a.offset.getZ());
|
|
||||||
textArrayCount.setNumber(a.count);
|
|
||||||
}
|
|
||||||
|
|
||||||
buttonList.addAll(mirrorButtonList);
|
|
||||||
buttonList.addAll(mirrorIconButtonList);
|
|
||||||
numberFieldList.addAll(mirrorNumberFieldList);
|
|
||||||
numberFieldList.addAll(arrayNumberFieldList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
//Process general logic, i.e. hide buttons
|
//Process general logic, i.e. hide buttons
|
||||||
public void updateScreen() {
|
public void updateScreen() {
|
||||||
numberFieldList.forEach(GuiNumberField::update);
|
scrollPane.updateScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -194,75 +57,17 @@ public class SettingsGui extends GuiScreen {
|
|||||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||||
this.drawDefaultBackground();
|
this.drawDefaultBackground();
|
||||||
|
|
||||||
int y = top;
|
scrollPane.drawScreen(mouseX, mouseY, partialTicks);
|
||||||
int offset = 8;
|
|
||||||
|
|
||||||
buttonMirrorEnabled.drawButton(this.mc, mouseX, mouseY, partialTicks);
|
|
||||||
if (buttonMirrorEnabled.isChecked()) {
|
|
||||||
fontRenderer.drawString("Mirror enabled", left + offset, y, 0xFFFFFF, true);
|
|
||||||
|
|
||||||
y = top + 18 + 5;
|
|
||||||
fontRenderer.drawString("Position", left + offset, y, 0xFFFFFF, true);
|
|
||||||
fontRenderer.drawString("X", left + 40 + offset, y, 0xFFFFFF, true);
|
|
||||||
fontRenderer.drawString("Y", left + 120 + offset, y, 0xFFFFFF, true);
|
|
||||||
fontRenderer.drawString("Z", left + 200 + offset, y, 0xFFFFFF, true);
|
|
||||||
|
|
||||||
y = top + 52;
|
|
||||||
fontRenderer.drawString("Direction", left + offset, y, 0xFFFFFF, true);
|
|
||||||
fontRenderer.drawString("Reach", left + 176 + offset, y, 0xFFFFFF, true);
|
|
||||||
|
|
||||||
mirrorButtonList.forEach(button -> button.drawButton(this.mc, mouseX, mouseY, partialTicks));
|
|
||||||
mirrorIconButtonList.forEach(button -> button.drawButton(this.mc, mouseX, mouseY, partialTicks));
|
|
||||||
mirrorNumberFieldList.forEach(numberField -> numberField.drawNumberField(this.mc, mouseX, mouseY, partialTicks));
|
|
||||||
} else {
|
|
||||||
fontRenderer.drawString("Mirror disabled", left + offset, y, 0x999999, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
y = top + 100 + 2;
|
|
||||||
buttonArrayEnabled.drawButton(this.mc, mouseX, mouseY, partialTicks);
|
|
||||||
if (buttonArrayEnabled.isChecked()) {
|
|
||||||
fontRenderer.drawString("Array enabled", left + offset, y, 0xFFFFFF, true);
|
|
||||||
|
|
||||||
y = top + 120 + 5;
|
|
||||||
fontRenderer.drawString("Offset", left + offset, y, 0xFFFFFF, true);
|
|
||||||
fontRenderer.drawString("X", left + 50 + offset, y, 0xFFFFFF, true);
|
|
||||||
fontRenderer.drawString("Y", left + 120 + offset, y, 0xFFFFFF, true);
|
|
||||||
fontRenderer.drawString("Z", left + 190 + offset, y, 0xFFFFFF, true);
|
|
||||||
|
|
||||||
y = top + 150 + 5;
|
|
||||||
fontRenderer.drawString("Count", left + offset, y, 0xFFFFFF, true);
|
|
||||||
|
|
||||||
int currentReach = Math.max(-1, getArrayReach());
|
|
||||||
int maxReach = BuildSettingsManager.getMaxReach(mc.player);
|
|
||||||
TextFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? TextFormatting.GRAY : TextFormatting.RED;
|
|
||||||
String reachText = "Reach: " + reachColor + currentReach + TextFormatting.GRAY + "/" + TextFormatting.GRAY + maxReach;
|
|
||||||
fontRenderer.drawString(reachText, left + 176 + offset, y, 0xFFFFFF, true);
|
|
||||||
|
|
||||||
arrayNumberFieldList.forEach(numberField -> numberField.drawNumberField(this.mc, mouseX, mouseY, partialTicks));
|
|
||||||
} else {
|
|
||||||
fontRenderer.drawString("Array disabled", left + offset, y, 0x999999, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
buttonClose.drawButton(this.mc, mouseX, mouseY, partialTicks);
|
buttonClose.drawButton(this.mc, mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
//Draw tooltips last
|
scrollPane.drawTooltip(this, mouseX, mouseY);
|
||||||
if (buttonMirrorEnabled.isChecked())
|
|
||||||
{
|
|
||||||
mirrorIconButtonList.forEach(iconButton -> iconButton.drawTooltip(this, mouseX, mouseY));
|
|
||||||
mirrorNumberFieldList.forEach(numberField -> numberField.drawTooltip(this, mouseX, mouseY));
|
|
||||||
}
|
|
||||||
if (buttonArrayEnabled.isChecked())
|
|
||||||
{
|
|
||||||
arrayNumberFieldList.forEach(numberField -> numberField.drawTooltip(this, mouseX, mouseY));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||||
super.keyTyped(typedChar, keyCode);
|
super.keyTyped(typedChar, keyCode);
|
||||||
for (GuiNumberField numberField : numberFieldList) {
|
scrollPane.keyTyped(typedChar, keyCode);
|
||||||
numberField.keyTyped(typedChar, keyCode);
|
|
||||||
}
|
|
||||||
if (keyCode == ClientProxy.keyBindings[0].getKeyCode()) {
|
if (keyCode == ClientProxy.keyBindings[0].getKeyCode()) {
|
||||||
mc.player.closeScreen();
|
mc.player.closeScreen();
|
||||||
}
|
}
|
||||||
@@ -271,116 +76,44 @@ public class SettingsGui extends GuiScreen {
|
|||||||
@Override
|
@Override
|
||||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||||
numberFieldList.forEach(numberField -> numberField.mouseClicked(mouseX, mouseY, mouseButton));
|
scrollPane.mouseClicked(mouseX, mouseY, mouseButton);
|
||||||
|
|
||||||
boolean insideMirrorEnabledLabel = mouseX >= left && mouseX < right && mouseY >= top - 2 && mouseY < top + 10;
|
|
||||||
boolean insideArrayEnabledLabel = mouseX >= left && mouseX < right && mouseY >= top + 100 && mouseY < top + 112;
|
|
||||||
|
|
||||||
if (insideMirrorEnabledLabel) {
|
|
||||||
buttonMirrorEnabled.setIsChecked(!buttonMirrorEnabled.isChecked());
|
|
||||||
buttonMirrorEnabled.playPressSound(this.mc.getSoundHandler());
|
|
||||||
actionPerformed(buttonMirrorEnabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insideArrayEnabledLabel) {
|
@Override
|
||||||
buttonArrayEnabled.setIsChecked(!buttonArrayEnabled.isChecked());
|
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||||
buttonArrayEnabled.playPressSound(this.mc.getSoundHandler());
|
if (state != 0 || !scrollPane.mouseReleased(mouseX, mouseY, state))
|
||||||
actionPerformed(buttonArrayEnabled);
|
{
|
||||||
|
super.mouseReleased(mouseX, mouseY, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMouseInput() throws IOException {
|
public void handleMouseInput() throws IOException {
|
||||||
super.handleMouseInput();
|
super.handleMouseInput();
|
||||||
int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
scrollPane.handleMouseInput();
|
||||||
int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
|
||||||
numberFieldList.forEach(numberField -> numberField.handleMouseInput(mouseX, mouseY));
|
//Scrolling numbers
|
||||||
|
// int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
||||||
|
// int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
||||||
|
// numberFieldList.forEach(numberField -> numberField.handleMouseInput(mouseX, mouseY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton button) throws IOException {
|
protected void actionPerformed(GuiButton button) {
|
||||||
//check what button and action type (left/right click)
|
//check what button and action type (left/right click)
|
||||||
if (button == buttonClose) {
|
if (button == buttonClose) {
|
||||||
mc.player.closeScreen();
|
mc.player.closeScreen();
|
||||||
}
|
}
|
||||||
if (button == buttonCurrentPosition) {
|
scrollPane.actionPerformed(button);
|
||||||
Vec3d pos = new Vec3d(Math.floor(mc.player.posX) + 0.5, Math.floor(mc.player.posY) + 0.5, Math.floor(mc.player.posZ) + 0.5);
|
|
||||||
textMirrorPosX.setNumber(pos.x);
|
|
||||||
textMirrorPosY.setNumber(pos.y);
|
|
||||||
textMirrorPosZ.setNumber(pos.z);
|
|
||||||
}
|
|
||||||
if (button == buttonToggleOdd) {
|
|
||||||
toggleOdd = !toggleOdd;
|
|
||||||
buttonToggleOdd.setUseAlternateIcon(toggleOdd);
|
|
||||||
if (toggleOdd) {
|
|
||||||
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to corner of block", "for even numbered builds"));
|
|
||||||
textMirrorPosX.setNumber(textMirrorPosX.getNumber() + 0.5);
|
|
||||||
textMirrorPosY.setNumber(textMirrorPosY.getNumber() + 0.5);
|
|
||||||
textMirrorPosZ.setNumber(textMirrorPosZ.getNumber() + 0.5);
|
|
||||||
} else {
|
|
||||||
buttonToggleOdd.setTooltip(Arrays.asList("Set mirror position to middle of block", "for odd numbered builds"));
|
|
||||||
textMirrorPosX.setNumber(Math.floor(textMirrorPosX.getNumber()));
|
|
||||||
textMirrorPosY.setNumber(Math.floor(textMirrorPosY.getNumber()));
|
|
||||||
textMirrorPosZ.setNumber(Math.floor(textMirrorPosZ.getNumber()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (button == buttonDrawLines) {
|
|
||||||
drawLines = !drawLines;
|
|
||||||
buttonDrawLines.setUseAlternateIcon(drawLines);
|
|
||||||
buttonDrawLines.setTooltip(drawLines ? "Hide lines" : "Show lines");
|
|
||||||
}
|
|
||||||
if (button == buttonDrawPlanes) {
|
|
||||||
drawPlanes = !drawPlanes;
|
|
||||||
buttonDrawPlanes.setUseAlternateIcon(drawPlanes);
|
|
||||||
buttonDrawPlanes.setTooltip(drawPlanes ? "Hide area" : "Show area");
|
|
||||||
}
|
|
||||||
numberFieldList.forEach(numberField -> numberField.actionPerformed(button));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed() {
|
public void onGuiClosed() {
|
||||||
|
scrollPane.onGuiClosed();
|
||||||
|
|
||||||
//save everything
|
//save everything
|
||||||
|
Mirror.MirrorSettings m = mirrorSettingsGui.getMirrorSettings();
|
||||||
//MIRROR
|
Array.ArraySettings a = arraySettingsGui.getArraySettings();
|
||||||
boolean mirrorEnabled = buttonMirrorEnabled.isChecked();
|
|
||||||
|
|
||||||
Vec3d mirrorPos = new Vec3d(0, 64, 0);
|
|
||||||
try {
|
|
||||||
mirrorPos = new Vec3d(textMirrorPosX.getNumber(), textMirrorPosY.getNumber(), textMirrorPosZ.getNumber());
|
|
||||||
} catch (NumberFormatException | NullPointerException ex) {
|
|
||||||
EffortlessBuilding.log(mc.player, "Mirror position not valid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean mirrorX = buttonMirrorX.isChecked();
|
|
||||||
boolean mirrorY = buttonMirrorY.isChecked();
|
|
||||||
boolean mirrorZ = buttonMirrorZ.isChecked();
|
|
||||||
|
|
||||||
int mirrorRadius = 50;
|
|
||||||
try {
|
|
||||||
mirrorRadius = (int) textMirrorRadius.getNumber();
|
|
||||||
} catch (NumberFormatException | NullPointerException ex) {
|
|
||||||
EffortlessBuilding.log(mc.player, "Mirror radius not valid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Mirror.MirrorSettings m = new Mirror.MirrorSettings(mirrorEnabled, mirrorPos, mirrorX, mirrorY, mirrorZ, mirrorRadius, drawLines, drawPlanes);
|
|
||||||
|
|
||||||
//ARRAY
|
|
||||||
boolean arrayEnabled = buttonArrayEnabled.isChecked();
|
|
||||||
BlockPos arrayOffset = new BlockPos(0, 0, 0);
|
|
||||||
try {
|
|
||||||
arrayOffset = new BlockPos(textArrayOffsetX.getNumber(), textArrayOffsetY.getNumber(), textArrayOffsetZ.getNumber());
|
|
||||||
} catch (NumberFormatException | NullPointerException ex) {
|
|
||||||
EffortlessBuilding.log(mc.player, "Array offset not valid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
int arrayCount = 5;
|
|
||||||
try {
|
|
||||||
arrayCount = (int) textArrayCount.getNumber();
|
|
||||||
} catch (NumberFormatException | NullPointerException ex) {
|
|
||||||
EffortlessBuilding.log(mc.player, "Array count not valid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Array.ArraySettings a = new Array.ArraySettings(arrayEnabled, arrayOffset, arrayCount);
|
|
||||||
|
|
||||||
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(mc.player);
|
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(mc.player);
|
||||||
if (buildSettings == null) buildSettings = new BuildSettingsManager.BuildSettings();
|
if (buildSettings == null) buildSettings = new BuildSettingsManager.BuildSettings();
|
||||||
@@ -397,21 +130,4 @@ public class SettingsGui extends GuiScreen {
|
|||||||
EffortlessBuilding.packetHandler.sendToServer(new BuildSettingsMessage(buildSettings));
|
EffortlessBuilding.packetHandler.sendToServer(new BuildSettingsMessage(buildSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getArrayReach() {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//find largest offset
|
|
||||||
double x = Math.abs(textArrayOffsetX.getNumber());
|
|
||||||
double y = Math.abs(textArrayOffsetY.getNumber());
|
|
||||||
double z = Math.abs(textArrayOffsetZ.getNumber());
|
|
||||||
double largestOffset = Math.max(Math.max(x, y), z);
|
|
||||||
return (int) (largestOffset * textArrayCount.getNumber());
|
|
||||||
} catch (NumberFormatException | NullPointerException ex) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isCurrentReachValid(int currentReach, int maxReach) {
|
|
||||||
return currentReach <= maxReach && currentReach > -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user