diff options
author | Alkalus <Draknyte1@hotmail.com> | 2020-05-26 15:14:52 +0100 |
---|---|---|
committer | Alkalus <Draknyte1@hotmail.com> | 2020-05-26 15:14:52 +0100 |
commit | 8eb236fd8cc8189ccd0783aa4a6d2fbc48c319e2 (patch) | |
tree | c1c0076d14180d9ba836425be0acbf25dd9c5c30 /src/Java/gtPlusPlus/core/gui/widget | |
parent | ce84ae027d07500fd91f5b5708d885e4447eceab (diff) | |
download | GT5-Unofficial-8eb236fd8cc8189ccd0783aa4a6d2fbc48c319e2.tar.gz GT5-Unofficial-8eb236fd8cc8189ccd0783aa4a6d2fbc48c319e2.tar.bz2 GT5-Unofficial-8eb236fd8cc8189ccd0783aa4a6d2fbc48c319e2.zip |
$ Fixed shaped recipe creation.
$ Minor adjustments to the Volumetric Flask GUI.
Diffstat (limited to 'src/Java/gtPlusPlus/core/gui/widget')
-rw-r--r-- | src/Java/gtPlusPlus/core/gui/widget/GuiValueField.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/gui/widget/GuiValueField.java b/src/Java/gtPlusPlus/core/gui/widget/GuiValueField.java new file mode 100644 index 0000000000..ac4c1a8aee --- /dev/null +++ b/src/Java/gtPlusPlus/core/gui/widget/GuiValueField.java @@ -0,0 +1,86 @@ +package gtPlusPlus.core.gui.widget; + +import java.lang.reflect.Field; + +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiTextField; + +public class GuiValueField extends GuiTextField { + + private final FontRenderer mFontRenderer; + private final int mScreenLocationX; + private final int mScreenLocationY; + + public GuiValueField(FontRenderer aFontRenderer, int aX, int aY, int aScreenLocationX, int aScreenLocationY, int aWidth, int aHeight) { + super(aFontRenderer, aX, aY, aWidth, aHeight); + mFontRenderer = aFontRenderer; + mScreenLocationX = aScreenLocationX; + mScreenLocationY = aScreenLocationY; + } + + public boolean canLoseFocus() { + Field canLoseFocus = ReflectionUtils.getField(GuiTextField.class, "canLoseFocus"); + if (canLoseFocus != null) { + return (boolean) ReflectionUtils.getFieldValue(canLoseFocus, this); + } + return true; + } + + public boolean isFocused() { + Field isFocused = ReflectionUtils.getField(GuiTextField.class, "isFocused"); + if (isFocused != null) { + return (boolean) ReflectionUtils.getFieldValue(isFocused, this); + } + return false; + } + + public boolean isBackgroundDrawingEnabled() { + Field enableBackgroundDrawing = ReflectionUtils.getField(GuiTextField.class, "enableBackgroundDrawing"); + if (enableBackgroundDrawing != null) { + return (boolean) ReflectionUtils.getFieldValue(enableBackgroundDrawing, this); + } + return true; + } + public int getLineScrollOffset() { + Field lineScrollOffset = ReflectionUtils.getField(GuiTextField.class, "lineScrollOffset"); + if (lineScrollOffset != null) { + return (int) ReflectionUtils.getFieldValue(lineScrollOffset, this); + } + return 0; + } + + /** + * Args: x, y, buttonClicked + */ + public void mouseClicked(int aX, int aY, int aButton){ + + boolean flag = aX >= this.mScreenLocationX && aX < this.mScreenLocationX + this.width && aY >= this.mScreenLocationY && aY < this.mScreenLocationY + this.height; + + //Logger.INFO("Clicked X:"+aX); + //Logger.INFO("Clicked Y:"+aY); + //Logger.INFO("ScreenPos X:"+mScreenLocationX); + //Logger.INFO("ScreenPos Y:"+mScreenLocationY); + //Logger.INFO("Render X:"+xPosition); + //Logger.INFO("Render Y:"+yPosition); + + if (canLoseFocus()) + { + this.setFocused(flag); + } + + if (isFocused() && aButton == 0) + { + int l = aX - this.mScreenLocationX; + + if (isBackgroundDrawingEnabled()) + { + l -= 4; + } + + String s = this.mFontRenderer.trimStringToWidth(this.getText().substring(getLineScrollOffset()), this.getWidth()); + this.setCursorPosition(this.mFontRenderer.trimStringToWidth(s, l).length() + getLineScrollOffset()); + } + } + +} |