Add hint to GuiTextField
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
package de.johni0702.minecraft.gui.element;
|
package de.johni0702.minecraft.gui.element;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||||
import de.johni0702.minecraft.gui.RenderInfo;
|
import de.johni0702.minecraft.gui.RenderInfo;
|
||||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
@@ -29,7 +30,9 @@ import de.johni0702.minecraft.gui.function.Clickable;
|
|||||||
import de.johni0702.minecraft.gui.function.Focusable;
|
import de.johni0702.minecraft.gui.function.Focusable;
|
||||||
import de.johni0702.minecraft.gui.function.Tickable;
|
import de.johni0702.minecraft.gui.function.Tickable;
|
||||||
import de.johni0702.minecraft.gui.function.Typeable;
|
import de.johni0702.minecraft.gui.function.Typeable;
|
||||||
|
import lombok.Getter;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
import org.lwjgl.util.ReadableDimension;
|
import org.lwjgl.util.ReadableDimension;
|
||||||
import org.lwjgl.util.ReadablePoint;
|
import org.lwjgl.util.ReadablePoint;
|
||||||
@@ -43,6 +46,9 @@ public abstract class AbstractGuiTextField<T extends AbstractGuiTextField<T>>
|
|||||||
|
|
||||||
private Focusable next, previous;
|
private Focusable next, previous;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private String hint;
|
||||||
|
|
||||||
public AbstractGuiTextField() {
|
public AbstractGuiTextField() {
|
||||||
this.wrapped = new net.minecraft.client.gui.GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, 0, 0, 0, 0);
|
this.wrapped = new net.minecraft.client.gui.GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
@@ -59,7 +65,18 @@ public abstract class AbstractGuiTextField<T extends AbstractGuiTextField<T>>
|
|||||||
wrapped.yPosition = position.getY();
|
wrapped.yPosition = position.getY();
|
||||||
wrapped.width = size.getWidth();
|
wrapped.width = size.getWidth();
|
||||||
wrapped.height = size.getHeight();
|
wrapped.height = size.getHeight();
|
||||||
wrapped.drawTextBox();
|
|
||||||
|
if (wrapped.text.isEmpty() && !isFocused() && !Strings.isNullOrEmpty(hint)) {
|
||||||
|
wrapped.setEnabled(false);
|
||||||
|
wrapped.setDisabledTextColour(0xff404040);
|
||||||
|
wrapped.text = hint;
|
||||||
|
wrapped.drawTextBox();
|
||||||
|
wrapped.text = "";
|
||||||
|
wrapped.setDisabledTextColour(0xff707070);
|
||||||
|
wrapped.setEnabled(isEnabled());
|
||||||
|
} else {
|
||||||
|
wrapped.drawTextBox();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -196,4 +213,15 @@ public abstract class AbstractGuiTextField<T extends AbstractGuiTextField<T>>
|
|||||||
this.textChanged = textChanged;
|
this.textChanged = textChanged;
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setHint(String hint) {
|
||||||
|
this.hint = hint;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T setI18nHint(String hint, Object... args) {
|
||||||
|
return setHint(I18n.format(hint));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,9 @@ public interface IGuiTextField<T extends IGuiTextField<T>> extends GuiElement<T>
|
|||||||
|
|
||||||
T onEnter(Runnable onEnter);
|
T onEnter(Runnable onEnter);
|
||||||
T onTextChanged(Runnable textChanged);
|
T onTextChanged(Runnable textChanged);
|
||||||
|
|
||||||
|
String getHint();
|
||||||
|
T setHint(String hint);
|
||||||
|
|
||||||
|
T setI18nHint(String hint, Object... args);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user