Add new Gui API
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user