Add new Gui API
This commit is contained in:
48
src/main/java/de/johni0702/minecraft/gui/GuiRenderer.java
Normal file
48
src/main/java/de/johni0702/minecraft/gui/GuiRenderer.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui;
|
||||||
|
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.util.ReadableColor;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
public interface GuiRenderer {
|
||||||
|
|
||||||
|
ReadablePoint getOpenGlOffset();
|
||||||
|
|
||||||
|
ReadableDimension getSize();
|
||||||
|
|
||||||
|
void bindTexture(ResourceLocation location);
|
||||||
|
|
||||||
|
void drawTexturedRect(int x, int y, int u, int v, int width, int height);
|
||||||
|
|
||||||
|
int drawString(int x, int y, int color, String text);
|
||||||
|
|
||||||
|
int drawString(int x, int y, ReadableColor color, String text);
|
||||||
|
|
||||||
|
int drawCenteredString(int x, int y, int color, String text);
|
||||||
|
|
||||||
|
int drawCenteredString(int x, int y, ReadableColor color, String text);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.client.gui.Gui;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.util.*;
|
||||||
|
|
||||||
|
public class MinecraftGuiRenderer implements GuiRenderer {
|
||||||
|
|
||||||
|
private final Gui gui = new Gui();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final ReadableDimension size;
|
||||||
|
|
||||||
|
public MinecraftGuiRenderer(ReadableDimension size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadablePoint getOpenGlOffset() {
|
||||||
|
return new Point(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindTexture(ResourceLocation location) {
|
||||||
|
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawTexturedRect(int x, int y, int u, int v, int width, int height) {
|
||||||
|
gui.drawTexturedModalRect(x, y, u, v, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drawString(int x, int y, int color, String text) {
|
||||||
|
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
|
||||||
|
return fontRenderer.drawStringWithShadow(text, x, y, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drawString(int x, int y, ReadableColor color, String text) {
|
||||||
|
return drawString(x, y, color(color), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drawCenteredString(int x, int y, int color, String text) {
|
||||||
|
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
|
||||||
|
return fontRenderer.drawStringWithShadow(text, x - fontRenderer.getStringWidth(text) / 2, y, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drawCenteredString(int x, int y, ReadableColor color, String text) {
|
||||||
|
return drawCenteredString(x, y, color(color), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int color(ReadableColor color) {
|
||||||
|
return color.getAlpha() << 24
|
||||||
|
| color.getRed() << 16
|
||||||
|
| color.getGreen() << 8
|
||||||
|
| color.getBlue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
import org.lwjgl.util.ReadableColor;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
public class OffsetGuiRenderer implements GuiRenderer {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final GuiRenderer renderer;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final ReadablePoint position;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final ReadableDimension size;
|
||||||
|
|
||||||
|
public OffsetGuiRenderer(GuiRenderer renderer, ReadablePoint position, ReadableDimension size) {
|
||||||
|
this.renderer = renderer;
|
||||||
|
this.position = position;
|
||||||
|
this.size = size;
|
||||||
|
if (size.getHeight() > renderer.getSize().getHeight()
|
||||||
|
|| size.getWidth() > renderer.getSize().getWidth()) {
|
||||||
|
throw new IllegalArgumentException("Size must not be larger than size of renderer.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadablePoint getOpenGlOffset() {
|
||||||
|
ReadablePoint parentOffset = renderer.getOpenGlOffset();
|
||||||
|
return new Point(parentOffset.getX() + position.getX(), parentOffset.getY() + position.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindTexture(ResourceLocation location) {
|
||||||
|
renderer.bindTexture(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawTexturedRect(int x, int y, int u, int v, int width, int height) {
|
||||||
|
renderer.drawTexturedRect(x + position.getX(), y + position.getY(), u, v, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drawString(int x, int y, int color, String text) {
|
||||||
|
return renderer.drawString(x + position.getX(), y + position.getY(), color, text) - position.getX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drawString(int x, int y, ReadableColor color, String text) {
|
||||||
|
return renderer.drawString(x + position.getX(), y + position.getY(), color, text) - position.getX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drawCenteredString(int x, int y, int color, String text) {
|
||||||
|
return renderer.drawCenteredString(x + position.getX(), y + position.getY(), color, text) - position.getX();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int drawCenteredString(int x, int y, ReadableColor color, String text) {
|
||||||
|
return renderer.drawCenteredString(x + position.getX(), y + position.getY(), color, text) - position.getX();
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/main/java/de/johni0702/minecraft/gui/RenderInfo.java
Normal file
45
src/main/java/de/johni0702/minecraft/gui/RenderInfo.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import net.minecraft.crash.CrashReport;
|
||||||
|
import net.minecraft.crash.CrashReportCategory;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RenderInfo {
|
||||||
|
public final float partialTick;
|
||||||
|
public final int mouseX;
|
||||||
|
public final int mouseY;
|
||||||
|
|
||||||
|
public RenderInfo offsetMouse(int minusX, int minusY) {
|
||||||
|
return new RenderInfo(partialTick, mouseX - minusX, mouseY - minusY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addTo(CrashReport crashReport) {
|
||||||
|
CrashReportCategory category = crashReport.makeCategory("Render info details");
|
||||||
|
category.addCrashSection("Partial Tick", partialTick);
|
||||||
|
category.addCrashSection("Mouse X", mouseX);
|
||||||
|
category.addCrashSection("Mouse Y", mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.container;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.OffsetGuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
|
import de.johni0702.minecraft.gui.element.AbstractComposedGuiElement;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||||
|
import de.johni0702.minecraft.gui.layout.Layout;
|
||||||
|
import de.johni0702.minecraft.gui.layout.LayoutData;
|
||||||
|
import net.minecraft.crash.CrashReport;
|
||||||
|
import net.minecraft.crash.CrashReportCategory;
|
||||||
|
import net.minecraft.util.ReportedException;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
public abstract class AbstractGuiContainer<T extends AbstractGuiContainer<T>>
|
||||||
|
extends AbstractComposedGuiElement<T> implements GuiContainer<T> {
|
||||||
|
|
||||||
|
private final Map<GuiElement, LayoutData> elements = new LinkedHashMap<GuiElement, LayoutData>();
|
||||||
|
|
||||||
|
private Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layedOutElements;
|
||||||
|
|
||||||
|
private Layout layout;
|
||||||
|
|
||||||
|
public AbstractGuiContainer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractGuiContainer(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setLayout(Layout layout) {
|
||||||
|
this.layout = layout;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Layout getLayout() {
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertFor(GuiElement element, Point point) {
|
||||||
|
checkState(layedOutElements != null, "Cannot convert position unless rendered at least once.");
|
||||||
|
Pair<ReadablePoint, ReadableDimension> pair = layedOutElements.get(element);
|
||||||
|
checkState(pair != null, "Element " + element + " not part of " + this);
|
||||||
|
ReadablePoint pos = pair.getKey();
|
||||||
|
point.translate(-pos.getX(), -pos.getY());
|
||||||
|
if (getContainer() != null) {
|
||||||
|
getContainer().convertFor(element, point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<GuiElement> getChildren() {
|
||||||
|
return Collections.unmodifiableCollection(elements.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<GuiElement, LayoutData> getElements() {
|
||||||
|
return Collections.unmodifiableMap(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T addElements(LayoutData layoutData, GuiElement... elements) {
|
||||||
|
if (layoutData == null) {
|
||||||
|
layoutData = LayoutData.NONE;
|
||||||
|
}
|
||||||
|
for (GuiElement element : elements) {
|
||||||
|
this.elements.put(element, layoutData);
|
||||||
|
element.setContainer(this);
|
||||||
|
}
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
|
try {
|
||||||
|
layedOutElements = layout.layOut(this, size);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
CrashReport crashReport = CrashReport.makeCrashReport(ex, "Gui Layout");
|
||||||
|
renderInfo.addTo(crashReport);
|
||||||
|
CrashReportCategory category = crashReport.makeCategory("Gui container details");
|
||||||
|
category.addCrashSectionCallable("Container", new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
category.addCrashSectionCallable("Layout", new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
throw new ReportedException(crashReport);
|
||||||
|
}
|
||||||
|
for (final Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> e : layedOutElements.entrySet()) {
|
||||||
|
final ReadablePoint ePosition = e.getValue().getLeft();
|
||||||
|
final ReadableDimension eSize = e.getValue().getRight();
|
||||||
|
try {
|
||||||
|
OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, ePosition, eSize);
|
||||||
|
e.getKey().draw(eRenderer, eSize, renderInfo.offsetMouse(ePosition.getX(), ePosition.getY()));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
CrashReport crashReport = CrashReport.makeCrashReport(ex, "Rendering Gui");
|
||||||
|
renderInfo.addTo(crashReport);
|
||||||
|
CrashReportCategory category = crashReport.makeCategory("Gui container details");
|
||||||
|
category.addCrashSectionCallable("Container", new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
category.addCrashSection("Width", size.getWidth());
|
||||||
|
category.addCrashSection("Height", size.getHeight());
|
||||||
|
category = crashReport.makeCategory("Gui element details");
|
||||||
|
category.addCrashSectionCallable("Element", new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
return e.getKey();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
category.addCrashSectionCallable("Position", new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
return ePosition;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
category.addCrashSectionCallable("Size", new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
return eSize;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
throw new ReportedException(crashReport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getMinSize() {
|
||||||
|
return layout.calcMinSize(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.container;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.MinecraftGuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.OffsetGuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||||
|
import de.johni0702.minecraft.gui.function.*;
|
||||||
|
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.util.Dimension;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public abstract class AbstractGuiScreen<T extends AbstractGuiScreen<T>> extends AbstractGuiContainer<T> {
|
||||||
|
|
||||||
|
private final MinecraftGuiScreen wrapped = new MinecraftGuiScreen();
|
||||||
|
|
||||||
|
private Dimension screenSize;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean drawBackground = true;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private boolean enabledRepeatedKeyEvents = true;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private GuiLabel title;
|
||||||
|
|
||||||
|
public net.minecraft.client.gui.GuiScreen toMinecraft() {
|
||||||
|
return wrapped;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
|
if (drawBackground) {
|
||||||
|
wrapped.drawDefaultBackground();
|
||||||
|
}
|
||||||
|
if (title != null) {
|
||||||
|
int x = screenSize.getWidth() / 2 - title.getMinSize().getWidth() / 2;
|
||||||
|
OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, new Point(x, 10), new Dimension(0, 0));
|
||||||
|
title.draw(eRenderer, null, null);
|
||||||
|
}
|
||||||
|
super.draw(renderer, size, renderInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getMinSize() {
|
||||||
|
return screenSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getPreferredSize() {
|
||||||
|
return screenSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getMaxSize() {
|
||||||
|
return screenSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabledRepeatedKeyEvents(boolean enableRepeatKeyEvents) {
|
||||||
|
this.enabledRepeatedKeyEvents = enableRepeatKeyEvents;
|
||||||
|
if (wrapped.active) {
|
||||||
|
Keyboard.enableRepeatEvents(enableRepeatKeyEvents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void display() {
|
||||||
|
getMinecraft().displayGuiScreen(toMinecraft());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class MinecraftGuiScreen extends net.minecraft.client.gui.GuiScreen {
|
||||||
|
private MinecraftGuiRenderer renderer;
|
||||||
|
private boolean active;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||||
|
draw(renderer, screenSize, new RenderInfo(partialTicks, mouseX, mouseY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||||
|
forEach(Typeable.class).typeKey(MouseUtils.getMousePos(), keyCode, typedChar, isCtrlKeyDown(), isShiftKeyDown());
|
||||||
|
super.keyTyped(typedChar, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||||
|
forEach(Clickable.class).mouseClick(new Point(mouseX, mouseY), mouseButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseReleased(int mouseX, int mouseY, int mouseButton) {
|
||||||
|
forEach(Draggable.class).mouseClick(new Point(mouseX, mouseY), mouseButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
|
||||||
|
forEach(Draggable.class).mouseDrag(new Point(mouseX, mouseY), mouseButton, timeSinceLastClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
forEach(Tickable.class).tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuiClosed() {
|
||||||
|
forEach(Closeable.class).close();
|
||||||
|
active = false;
|
||||||
|
if (enabledRepeatedKeyEvents) {
|
||||||
|
Keyboard.enableRepeatEvents(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initGui() {
|
||||||
|
active = false;
|
||||||
|
if (enabledRepeatedKeyEvents) {
|
||||||
|
Keyboard.enableRepeatEvents(true);
|
||||||
|
}
|
||||||
|
screenSize = new Dimension(width, height);
|
||||||
|
renderer = new MinecraftGuiRenderer(screenSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getWrapper() {
|
||||||
|
return AbstractGuiScreen.this.getThis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.container;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.element.ComposedGuiElement;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||||
|
import de.johni0702.minecraft.gui.layout.Layout;
|
||||||
|
import de.johni0702.minecraft.gui.layout.LayoutData;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface GuiContainer<T extends GuiContainer<T>> extends ComposedGuiElement<T> {
|
||||||
|
|
||||||
|
T setLayout(Layout layout);
|
||||||
|
Layout getLayout();
|
||||||
|
|
||||||
|
void convertFor(GuiElement element, Point point);
|
||||||
|
|
||||||
|
Map<GuiElement, LayoutData> getElements();
|
||||||
|
T addElements(LayoutData layoutData, GuiElement...elements);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.container;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||||
|
import de.johni0702.minecraft.gui.layout.Layout;
|
||||||
|
import de.johni0702.minecraft.gui.layout.LayoutData;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Singular;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class GuiPanel extends AbstractGuiContainer<GuiPanel> {
|
||||||
|
|
||||||
|
public GuiPanel() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuiPanel(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
GuiPanel(Layout layout, int width , int height, @Singular("with") Map<GuiElement, LayoutData> withElements) {
|
||||||
|
setLayout(layout);
|
||||||
|
setSize(width, height);
|
||||||
|
for (Map.Entry<GuiElement, LayoutData> e : withElements.entrySet()) {
|
||||||
|
addElements(e.getValue(), e.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiPanel getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.container;
|
||||||
|
|
||||||
|
public class GuiScreen extends AbstractGuiScreen<GuiScreen> {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static GuiScreen from(net.minecraft.client.gui.GuiScreen minecraft) {
|
||||||
|
return ((GuiScreen.MinecraftGuiScreen) minecraft).getWrapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiScreen getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import net.minecraft.crash.CrashReport;
|
||||||
|
import net.minecraft.crash.CrashReportCategory;
|
||||||
|
import net.minecraft.util.ReportedException;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
public abstract class AbstractComposedGuiElement<T extends AbstractComposedGuiElement<T>>
|
||||||
|
extends AbstractGuiElement<T> implements ComposedGuiElement<T> {
|
||||||
|
public AbstractComposedGuiElement() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractComposedGuiElement(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <C> C forEach(final Class<C> ofType) {
|
||||||
|
return (C) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{ofType}, new InvocationHandler() {
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
|
Object handled = null;
|
||||||
|
for (final GuiElement element : getChildren()) {
|
||||||
|
try {
|
||||||
|
if (element instanceof ComposedGuiElement) {
|
||||||
|
handled = method.invoke(((ComposedGuiElement) element).forEach(ofType), args);
|
||||||
|
} else if (ofType.isInstance(element)) {
|
||||||
|
handled = method.invoke(element, args);
|
||||||
|
}
|
||||||
|
if (Boolean.TRUE.equals(handled)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
CrashReport crash = CrashReport.makeCrashReport(e, "Calling Gui method");
|
||||||
|
CrashReportCategory category = crash.makeCategory("Gui");
|
||||||
|
category.addCrashSection("Method", method);
|
||||||
|
category.addCrashSectionCallable("ComposedElement", new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
category.addCrashSectionCallable("Element", new Callable() {
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
throw new ReportedException(crash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import de.johni0702.minecraft.gui.function.Clickable;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.util.Dimension;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
|
||||||
|
|
||||||
|
public abstract class AbstractGuiButton<T extends AbstractGuiButton<T>> extends AbstractGuiClickable<T> implements Clickable, IGuiButton<T> {
|
||||||
|
protected static final ResourceLocation BUTTON_SOUND = new ResourceLocation("gui.button.press");
|
||||||
|
protected static final ResourceLocation WIDGETS_TEXTURE = new ResourceLocation("textures/gui/widgets.png");
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
public AbstractGuiButton() {
|
||||||
|
setSize(new Dimension(200, 20));
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractGuiButton(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
setSize(new Dimension(200, 20));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
|
super.draw(renderer, size, renderInfo);
|
||||||
|
|
||||||
|
renderer.bindTexture(WIDGETS_TEXTURE);
|
||||||
|
GlStateManager.color(1, 1, 1, 1);
|
||||||
|
|
||||||
|
byte texture = 1;
|
||||||
|
int color = 0xe0e0e0;
|
||||||
|
if (!isEnabled()) {
|
||||||
|
texture = 0;
|
||||||
|
color = 0xa0a0a0;
|
||||||
|
} else if (isMouseHovering(new Point(renderInfo.mouseX, renderInfo.mouseY))) {
|
||||||
|
texture = 2;
|
||||||
|
color = 0xffffa0;
|
||||||
|
}
|
||||||
|
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||||
|
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
int textureY = 46 + texture * 20;
|
||||||
|
int halfWidth = size.getWidth() / 2;
|
||||||
|
|
||||||
|
renderer.drawTexturedRect(0, 0, 0, textureY, halfWidth, size.getHeight());
|
||||||
|
renderer.drawTexturedRect(halfWidth, 0, 200 - halfWidth, textureY, halfWidth, size.getHeight());
|
||||||
|
renderer.drawCenteredString(halfWidth, (size.getHeight() - 8) / 2, color, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getMinSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F));
|
||||||
|
super.onClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setI18nLabel(String label, Object... args) {
|
||||||
|
return setLabel(I18n.format(label, args));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import de.johni0702.minecraft.gui.function.Clickable;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
public abstract class AbstractGuiClickable<T extends AbstractGuiClickable<T>> extends AbstractGuiElement<T> implements Clickable, IGuiClickable<T> {
|
||||||
|
private Runnable onClick;
|
||||||
|
private ReadableDimension size;
|
||||||
|
|
||||||
|
public AbstractGuiClickable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractGuiClickable(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClick(ReadablePoint position, int button) {
|
||||||
|
Point pos = new Point(position);
|
||||||
|
if (getContainer() != null) {
|
||||||
|
getContainer().convertFor(this, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMouseHovering(pos) && isEnabled()) {
|
||||||
|
onClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isMouseHovering(ReadablePoint pos) {
|
||||||
|
return pos.getX() > 0 && pos.getY() > 0
|
||||||
|
&& pos.getX() < size.getWidth() && pos.getY() < size.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onClick() {
|
||||||
|
if (onClick != null) {
|
||||||
|
onClick.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T onClick(Runnable onClick) {
|
||||||
|
this.onClick = onClick;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.lwjgl.util.Dimension;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
|
||||||
|
public abstract class AbstractGuiElement<T extends AbstractGuiElement<T>> implements GuiElement<T> {
|
||||||
|
@Getter
|
||||||
|
private final Minecraft minecraft = Minecraft.getMinecraft();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private GuiContainer container;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private boolean enabled = true;
|
||||||
|
|
||||||
|
private Dimension maxSize, preferredSize;
|
||||||
|
|
||||||
|
public AbstractGuiElement() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractGuiElement(GuiContainer container) {
|
||||||
|
container.addElements(null, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract T getThis();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setEnabled() {
|
||||||
|
return setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setDisabled() {
|
||||||
|
return setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setContainer(GuiContainer container) {
|
||||||
|
this.container = container;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T setMaxSize(ReadableDimension maxSize) {
|
||||||
|
this.maxSize = new Dimension(maxSize);
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T setPreferredSize(ReadableDimension preferredSize) {
|
||||||
|
this.preferredSize = new Dimension(preferredSize);
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T setSize(ReadableDimension size) {
|
||||||
|
Dimension dimension = new Dimension(size);
|
||||||
|
maxSize = preferredSize = dimension;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T setSize(int width, int height) {
|
||||||
|
return setSize(new Dimension(width, height));
|
||||||
|
}
|
||||||
|
|
||||||
|
public T setWidth(int width) {
|
||||||
|
if (maxSize == null) {
|
||||||
|
maxSize = new Dimension(width, 0);
|
||||||
|
} else {
|
||||||
|
maxSize.setWidth(width);
|
||||||
|
}
|
||||||
|
if (preferredSize == null) {
|
||||||
|
preferredSize = new Dimension(width, 0);
|
||||||
|
} else {
|
||||||
|
preferredSize.setWidth(width);
|
||||||
|
}
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T setHeight(int height) {
|
||||||
|
if (maxSize == null) {
|
||||||
|
maxSize = new Dimension(0, height);
|
||||||
|
} else {
|
||||||
|
maxSize.setHeight(height);
|
||||||
|
}
|
||||||
|
if (preferredSize == null) {
|
||||||
|
preferredSize = new Dimension(0, height);
|
||||||
|
} else {
|
||||||
|
preferredSize.setHeight(height);
|
||||||
|
}
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getMaxSize() {
|
||||||
|
return maxSize == null ? getPreferredSize() : maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getPreferredSize() {
|
||||||
|
return preferredSize == null ? getMinSize() : preferredSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
|
import org.lwjgl.util.Dimension;
|
||||||
|
import org.lwjgl.util.ReadableColor;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
|
||||||
|
public abstract class AbstractGuiLabel<T extends AbstractGuiLabel<T>> extends AbstractGuiElement<T> implements IGuiLabel<T> {
|
||||||
|
@Getter
|
||||||
|
private String text = "";
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private ReadableColor color = ReadableColor.WHITE, disabledColor = ReadableColor.GREY;
|
||||||
|
|
||||||
|
public AbstractGuiLabel() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractGuiLabel(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
|
renderer.drawString(0, 0, isEnabled() ? color : disabledColor, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getMinSize() {
|
||||||
|
FontRenderer fontRenderer = getMinecraft().fontRendererObj;
|
||||||
|
return new Dimension(fontRenderer.getStringWidth(text), fontRenderer.FONT_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setI18nText(String text, Object... args) {
|
||||||
|
return setText(I18n.format(text, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setColor(ReadableColor color) {
|
||||||
|
this.color = color;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setDisabledColor(ReadableColor disabledColor) {
|
||||||
|
this.disabledColor = disabledColor;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
|
||||||
|
public abstract class AbstractGuiPasswordField<T extends AbstractGuiPasswordField<T>> extends AbstractGuiTextField<T> {
|
||||||
|
public AbstractGuiPasswordField() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractGuiPasswordField(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
|
String text = getText();
|
||||||
|
setText(StringUtils.repeat('*', text.length()));
|
||||||
|
super.draw(renderer, size, renderInfo);
|
||||||
|
setText(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import de.johni0702.minecraft.gui.function.Clickable;
|
||||||
|
import de.johni0702.minecraft.gui.function.Focusable;
|
||||||
|
import de.johni0702.minecraft.gui.function.Tickable;
|
||||||
|
import de.johni0702.minecraft.gui.function.Typeable;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
public abstract class AbstractGuiTextField<T extends AbstractGuiTextField<T>>
|
||||||
|
extends AbstractGuiElement<T> implements Clickable, Tickable, Typeable, IGuiTextField<T> {
|
||||||
|
private final net.minecraft.client.gui.GuiTextField wrapped;
|
||||||
|
|
||||||
|
private Runnable textChanged;
|
||||||
|
private Runnable onEnter;
|
||||||
|
|
||||||
|
private Focusable next, previous;
|
||||||
|
|
||||||
|
public AbstractGuiTextField() {
|
||||||
|
this.wrapped = new net.minecraft.client.gui.GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractGuiTextField(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
this.wrapped = new net.minecraft.client.gui.GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||||
|
ReadablePoint position = renderer.getOpenGlOffset();
|
||||||
|
wrapped.xPosition = position.getX();
|
||||||
|
wrapped.yPosition = position.getY();
|
||||||
|
wrapped.width = size.getWidth();
|
||||||
|
wrapped.height = size.getHeight();
|
||||||
|
wrapped.drawTextBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getMinSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClick(ReadablePoint position, int button) {
|
||||||
|
wrapped.mouseClicked(position.getX(), position.getY(), button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
|
||||||
|
if (!isFocused()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyCode == Keyboard.KEY_RETURN) {
|
||||||
|
onEnter();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyCode == Keyboard.KEY_TAB) {
|
||||||
|
Focusable other = shiftDown ? previous : next;
|
||||||
|
if (other != null) {
|
||||||
|
setFocused(false);
|
||||||
|
other.setFocused(true);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String before = wrapped.getText();
|
||||||
|
wrapped.textboxKeyTyped(keyChar, keyCode);
|
||||||
|
String after = wrapped.getText();
|
||||||
|
if (!before.equals(after)) {
|
||||||
|
textChanged.run();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setText(String text) {
|
||||||
|
if (text.length() > wrapped.getMaxStringLength()) {
|
||||||
|
wrapped.text = text.substring(0, wrapped.getMaxStringLength());
|
||||||
|
} else {
|
||||||
|
wrapped.text = text;
|
||||||
|
}
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getText() {
|
||||||
|
return wrapped.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFocused() {
|
||||||
|
return wrapped.isFocused();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setFocused(boolean focused) {
|
||||||
|
wrapped.setFocused(focused);
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Focusable getNext() {
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setNext(Focusable next) {
|
||||||
|
if (this.next == next) return getThis();
|
||||||
|
if (this.next != null) {
|
||||||
|
this.next.setPrevious(null);
|
||||||
|
}
|
||||||
|
this.next = next;
|
||||||
|
if (this.next != null) {
|
||||||
|
this.next.setPrevious(this);
|
||||||
|
}
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Focusable getPrevious() {
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setPrevious(Focusable previous) {
|
||||||
|
if (this.previous == previous) return getThis();
|
||||||
|
if (this.previous != null) {
|
||||||
|
this.previous.setNext(null);
|
||||||
|
}
|
||||||
|
this.previous = previous;
|
||||||
|
if (this.previous != null) {
|
||||||
|
this.previous.setNext(this);
|
||||||
|
}
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxLength() {
|
||||||
|
return wrapped.getMaxStringLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setMaxLength(int maxLength) {
|
||||||
|
wrapped.setMaxStringLength(maxLength);
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
wrapped.updateCursorCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onEnter() {
|
||||||
|
if (onEnter != null) {
|
||||||
|
onEnter.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T onEnter(Runnable onEnter) {
|
||||||
|
this.onEnter = onEnter;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T onTextChanged(Runnable textChanged) {
|
||||||
|
this.textChanged = textChanged;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface ComposedGuiElement<T extends ComposedGuiElement<T>> extends GuiElement<T> {
|
||||||
|
Collection<GuiElement> getChildren();
|
||||||
|
|
||||||
|
<C> C forEach(Class<C> ofType);
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
|
||||||
|
public class GuiButton extends AbstractGuiButton<GuiButton> {
|
||||||
|
public GuiButton() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuiButton(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiButton getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
|
||||||
|
public interface GuiElement<T extends GuiElement<T>> {
|
||||||
|
|
||||||
|
Minecraft getMinecraft();
|
||||||
|
|
||||||
|
GuiContainer getContainer();
|
||||||
|
T setContainer(GuiContainer container);
|
||||||
|
|
||||||
|
void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo);
|
||||||
|
|
||||||
|
ReadableDimension getMinSize();
|
||||||
|
ReadableDimension getPreferredSize();
|
||||||
|
ReadableDimension getMaxSize();
|
||||||
|
|
||||||
|
T setPreferredSize(ReadableDimension preferredSize);
|
||||||
|
T setMaxSize(ReadableDimension maxSize);
|
||||||
|
|
||||||
|
boolean isEnabled();
|
||||||
|
T setEnabled(boolean enabled);
|
||||||
|
T setEnabled();
|
||||||
|
T setDisabled();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
|
||||||
|
public class GuiLabel extends AbstractGuiLabel<GuiLabel> {
|
||||||
|
public GuiLabel() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuiLabel(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiLabel getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
|
||||||
|
public class GuiPasswordField extends AbstractGuiPasswordField<GuiPasswordField> {
|
||||||
|
public GuiPasswordField() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuiPasswordField(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiPasswordField getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
|
||||||
|
public class GuiTextField extends AbstractGuiTextField<GuiTextField> {
|
||||||
|
public GuiTextField() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GuiTextField(GuiContainer container) {
|
||||||
|
super(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiTextField getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
public interface IGuiButton<T extends AbstractGuiButton<T>> extends IGuiClickable<T> {
|
||||||
|
T setLabel(String label);
|
||||||
|
|
||||||
|
T setI18nLabel(String label, Object... args);
|
||||||
|
|
||||||
|
String getLabel();
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
public interface IGuiClickable<T extends AbstractGuiClickable<T>> extends GuiElement<T> {
|
||||||
|
T onClick(Runnable onClick);
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import org.lwjgl.util.ReadableColor;
|
||||||
|
|
||||||
|
public interface IGuiLabel<T extends AbstractGuiLabel<T>> extends GuiElement<T> {
|
||||||
|
T setText(String text);
|
||||||
|
|
||||||
|
T setI18nText(String text, Object... args);
|
||||||
|
|
||||||
|
T setColor(ReadableColor color);
|
||||||
|
|
||||||
|
T setDisabledColor(ReadableColor disabledColor);
|
||||||
|
|
||||||
|
String getText();
|
||||||
|
|
||||||
|
ReadableColor getColor();
|
||||||
|
|
||||||
|
ReadableColor getDisabledColor();
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.function.Focusable;
|
||||||
|
|
||||||
|
public interface IGuiTextField<T extends IGuiTextField<T>> extends GuiElement<T>, Focusable<T> {
|
||||||
|
T setText(String text);
|
||||||
|
String getText();
|
||||||
|
|
||||||
|
int getMaxLength();
|
||||||
|
T setMaxLength(int maxLength);
|
||||||
|
|
||||||
|
T onEnter(Runnable onEnter);
|
||||||
|
T onTextChanged(Runnable textChanged);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.function;
|
||||||
|
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
public interface Clickable {
|
||||||
|
void mouseClick(ReadablePoint position, int button);
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.function;
|
||||||
|
|
||||||
|
public interface Closeable {
|
||||||
|
void close();
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.function;
|
||||||
|
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
public interface Draggable extends Clickable {
|
||||||
|
void mouseDrag(ReadablePoint position, int button, long timeSinceLastCall);
|
||||||
|
void mouseRelease(ReadablePoint position, int button);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.function;
|
||||||
|
|
||||||
|
public interface Focusable<T extends Focusable<T>> {
|
||||||
|
|
||||||
|
boolean isFocused();
|
||||||
|
T setFocused(boolean focused);
|
||||||
|
|
||||||
|
Focusable getNext();
|
||||||
|
T setNext(Focusable next);
|
||||||
|
|
||||||
|
Focusable getPrevious();
|
||||||
|
T setPrevious(Focusable previous);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.function;
|
||||||
|
|
||||||
|
public interface Tickable {
|
||||||
|
void tick();
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.function;
|
||||||
|
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
public interface Typeable {
|
||||||
|
boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown);
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.layout;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.lwjgl.util.Dimension;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class CustomLayout<T extends GuiContainer<T>> implements Layout {
|
||||||
|
private Map<GuiElement, Pair<Point, Dimension>> result = Maps.newHashMap();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer container, ReadableDimension size) {
|
||||||
|
result.clear();
|
||||||
|
Collection<GuiElement> elements = container.getChildren();
|
||||||
|
for (GuiElement element : elements) {
|
||||||
|
result.put(element, Pair.of(new Point(0, 0), new Dimension(element.getPreferredSize())));
|
||||||
|
}
|
||||||
|
|
||||||
|
layout((T) container, size.getWidth(), size.getHeight());
|
||||||
|
|
||||||
|
return (Map) result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pair<Point, Dimension> entry(GuiElement element) {
|
||||||
|
return result.get(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void set(GuiElement element, int x, int y, int width, int height) {
|
||||||
|
Pair<Point, Dimension> entry = entry(element);
|
||||||
|
entry.getLeft().setLocation(x, y);
|
||||||
|
entry.getRight().setSize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void pos(GuiElement element, int x, int y) {
|
||||||
|
entry(element).getLeft().setLocation(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void size(GuiElement element, int width, int height) {
|
||||||
|
entry(element).getRight().setSize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void x(GuiElement element, int x) {
|
||||||
|
entry(element).getLeft().setX(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void y(GuiElement element, int y) {
|
||||||
|
entry(element).getLeft().setY(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void width(GuiElement element, int width) {
|
||||||
|
entry(element).getRight().setWidth(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void height(GuiElement element, int height) {
|
||||||
|
entry(element).getRight().setHeight(height);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int x(GuiElement element) {
|
||||||
|
return entry(element).getLeft().getX();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int y(GuiElement element) {
|
||||||
|
return entry(element).getLeft().getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int width(GuiElement element) {
|
||||||
|
return entry(element).getRight().getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int height(GuiElement element) {
|
||||||
|
return entry(element).getRight().getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void layout(T container, int width, int height);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension calcMinSize(GuiContainer<?> container) {
|
||||||
|
return container.getPreferredSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.layout;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.lwjgl.util.Dimension;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HorizontalLayout implements Layout {
|
||||||
|
private static final Data DEFAULT_DATA = new Data(0);
|
||||||
|
|
||||||
|
private final Alignment alignment;
|
||||||
|
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private int spacing;
|
||||||
|
|
||||||
|
public HorizontalLayout() {
|
||||||
|
this(Alignment.LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HorizontalLayout(Alignment alignment) {
|
||||||
|
this.alignment = alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
|
||||||
|
int x = 0;
|
||||||
|
int spacing = 0;
|
||||||
|
Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = Maps.newHashMap();
|
||||||
|
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
|
||||||
|
x += spacing;
|
||||||
|
spacing = this.spacing;
|
||||||
|
|
||||||
|
GuiElement element = entry.getKey();
|
||||||
|
Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
|
||||||
|
Dimension minSize = new Dimension(element.getMinSize());
|
||||||
|
if (minSize.getHeight() < data.minHeight) {
|
||||||
|
minSize.setHeight(data.minHeight);
|
||||||
|
}
|
||||||
|
int y;
|
||||||
|
if (data.alignment == VerticalLayout.Alignment.BOTTOM) {
|
||||||
|
y = size.getHeight() - minSize.getHeight() - data.yOffset;
|
||||||
|
} else if (data.alignment == VerticalLayout.Alignment.CENTER) {
|
||||||
|
y = (size.getHeight() - minSize.getHeight()) / 2 + data.yOffset;
|
||||||
|
} else {
|
||||||
|
y = data.yOffset;
|
||||||
|
}
|
||||||
|
map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), minSize));
|
||||||
|
x += minSize.getWidth();
|
||||||
|
}
|
||||||
|
if (alignment != Alignment.LEFT) {
|
||||||
|
int remaining = size.getWidth() - x;
|
||||||
|
if (alignment == Alignment.CENTER) {
|
||||||
|
remaining /= 2;
|
||||||
|
}
|
||||||
|
for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
|
||||||
|
((Point) pair.getLeft()).translate(remaining, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension calcMinSize(GuiContainer<?> container) {
|
||||||
|
int maxHeight = 0;
|
||||||
|
int width = 0;
|
||||||
|
int spacing = 0;
|
||||||
|
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
|
||||||
|
width += spacing;
|
||||||
|
spacing = this.spacing;
|
||||||
|
|
||||||
|
GuiElement element = entry.getKey();
|
||||||
|
Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
|
||||||
|
ReadableDimension minSize = element.getMinSize();
|
||||||
|
int height = Math.max(minSize.getHeight(), data.getMinHeight()) + data.yOffset;
|
||||||
|
if (height > maxHeight) {
|
||||||
|
maxHeight = height;
|
||||||
|
}
|
||||||
|
width += minSize.getWidth();
|
||||||
|
}
|
||||||
|
return new Dimension(width, maxHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@lombok.Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class Data implements LayoutData {
|
||||||
|
private int yOffset;
|
||||||
|
private VerticalLayout.Alignment alignment;
|
||||||
|
private int minHeight;
|
||||||
|
|
||||||
|
public Data(int yOffset) {
|
||||||
|
this(yOffset, VerticalLayout.Alignment.TOP, 0);
|
||||||
|
}
|
||||||
|
public Data(int yOffset, VerticalLayout.Alignment alignment) {
|
||||||
|
this(yOffset, alignment, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Alignment {
|
||||||
|
LEFT, RIGHT, CENTER
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/main/java/de/johni0702/minecraft/gui/layout/Layout.java
Normal file
39
src/main/java/de/johni0702/minecraft/gui/layout/Layout.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.layout;
|
||||||
|
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface Layout {
|
||||||
|
|
||||||
|
Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size);
|
||||||
|
|
||||||
|
ReadableDimension calcMinSize(GuiContainer<?> container);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.layout;
|
||||||
|
|
||||||
|
public interface LayoutData {
|
||||||
|
LayoutData NONE = VoidLayoutData.INSTANCE;
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.layout;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.lwjgl.util.Dimension;
|
||||||
|
import org.lwjgl.util.Point;
|
||||||
|
import org.lwjgl.util.ReadableDimension;
|
||||||
|
import org.lwjgl.util.ReadablePoint;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class VerticalLayout implements Layout {
|
||||||
|
private static final Data DEFAULT_DATA = new Data(0);
|
||||||
|
|
||||||
|
private final Alignment alignment;
|
||||||
|
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private int spacing;
|
||||||
|
|
||||||
|
public VerticalLayout() {
|
||||||
|
this(Alignment.TOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VerticalLayout(Alignment alignment) {
|
||||||
|
this.alignment = alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
|
||||||
|
int y = 0;
|
||||||
|
int spacing = 0;
|
||||||
|
Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = Maps.newHashMap();
|
||||||
|
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
|
||||||
|
y += spacing;
|
||||||
|
spacing = this.spacing;
|
||||||
|
|
||||||
|
GuiElement element = entry.getKey();
|
||||||
|
Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
|
||||||
|
Dimension minSize = new Dimension(element.getMinSize());
|
||||||
|
if (minSize.getWidth() < data.minWidth) {
|
||||||
|
minSize.setWidth(data.minWidth);
|
||||||
|
}
|
||||||
|
int x;
|
||||||
|
if (data.alignment == HorizontalLayout.Alignment.RIGHT) {
|
||||||
|
x = size.getWidth() - minSize.getWidth() - data.xOffset;
|
||||||
|
} else if (data.alignment == HorizontalLayout.Alignment.CENTER) {
|
||||||
|
x = (size.getWidth() - minSize.getWidth()) / 2 + data.xOffset;
|
||||||
|
} else {
|
||||||
|
x = data.xOffset;
|
||||||
|
}
|
||||||
|
map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), minSize));
|
||||||
|
y += minSize.getHeight();
|
||||||
|
}
|
||||||
|
if (alignment != Alignment.TOP) {
|
||||||
|
int remaining = size.getHeight() - y;
|
||||||
|
if (alignment == Alignment.CENTER) {
|
||||||
|
remaining /= 2;
|
||||||
|
}
|
||||||
|
for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
|
||||||
|
((Point) pair.getLeft()).translate(0, remaining);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadableDimension calcMinSize(GuiContainer<?> container) {
|
||||||
|
int maxWidth = 0;
|
||||||
|
int height = 0;
|
||||||
|
int spacing = 0;
|
||||||
|
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
|
||||||
|
height += spacing;
|
||||||
|
spacing = this.spacing;
|
||||||
|
|
||||||
|
GuiElement element = entry.getKey();
|
||||||
|
Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
|
||||||
|
ReadableDimension minSize = element.getMinSize();
|
||||||
|
int width = Math.max(minSize.getWidth(), data.minWidth) + data.xOffset;
|
||||||
|
if (width > maxWidth) {
|
||||||
|
maxWidth = width;
|
||||||
|
}
|
||||||
|
height += minSize.getHeight();
|
||||||
|
}
|
||||||
|
return new Dimension(maxWidth, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@lombok.Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class Data implements LayoutData {
|
||||||
|
private int xOffset;
|
||||||
|
private HorizontalLayout.Alignment alignment;
|
||||||
|
private int minWidth;
|
||||||
|
|
||||||
|
public Data(int xOffset) {
|
||||||
|
this(xOffset, HorizontalLayout.Alignment.LEFT, 0);
|
||||||
|
}
|
||||||
|
public Data(int xOffset, HorizontalLayout.Alignment alignment) {
|
||||||
|
this(xOffset, alignment, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Alignment {
|
||||||
|
TOP, BOTTOM, CENTER
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015 johni0702
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.johni0702.minecraft.gui.layout;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class VoidLayoutData implements LayoutData {
|
||||||
|
public static final VoidLayoutData INSTANCE = new VoidLayoutData();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user