mirror of
https://github.com/seppukudevelopment/seppuku
synced 2025-03-04 03:37:33 +00:00
Adds backspace holding to TextComponent & ColorComponent
This commit is contained in:
parent
fb803fcdd9
commit
1734e6d88d
@ -5,6 +5,7 @@ import me.rigamortis.seppuku.api.texture.Texture;
|
||||
import me.rigamortis.seppuku.api.util.ColorUtil;
|
||||
import me.rigamortis.seppuku.api.util.RenderUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@ -82,6 +83,19 @@ public class ColorComponent extends TextComponent {
|
||||
// check
|
||||
this.checkTexture.bind();
|
||||
this.checkTexture.render(this.getX() + this.getW() - 19, this.getY() + 0.5f, 8, 8);
|
||||
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_BACK) || Keyboard.isKeyDown(Keyboard.KEY_DELETE)) {
|
||||
if (this.doBackspacing && this.backspaceWaitTimer.passed(750)) {
|
||||
if (this.backspaceTimer.passed(75)) {
|
||||
if (this.displayValue.length() > 0) {
|
||||
this.displayValue = this.displayValue.substring(0, this.displayValue.length() - 1);
|
||||
}
|
||||
this.backspaceTimer.reset();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.doBackspacing = false;
|
||||
}
|
||||
} else {
|
||||
// draw gear
|
||||
this.gearTexture.bind();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package me.rigamortis.seppuku.api.gui.hud.component;
|
||||
|
||||
import me.rigamortis.seppuku.api.util.RenderUtil;
|
||||
import me.rigamortis.seppuku.api.util.Timer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@ -15,6 +16,9 @@ public class TextComponent extends HudComponent {
|
||||
public ComponentListener returnListener;
|
||||
public TextComponentListener textListener;
|
||||
|
||||
protected Timer backspaceTimer = new Timer(), backspaceWaitTimer = new Timer();
|
||||
protected boolean doBackspacing = false;
|
||||
|
||||
public TextComponent(String name, String displayValue, boolean digitOnly) {
|
||||
super(name);
|
||||
|
||||
@ -39,6 +43,19 @@ public class TextComponent extends HudComponent {
|
||||
int blockWidth = 2;
|
||||
int blockHeight = Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 2;
|
||||
RenderUtil.drawRect(blockX, blockY, blockX + blockWidth, blockY + blockHeight, 0xFFFFFFFF);
|
||||
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_BACK) || Keyboard.isKeyDown(Keyboard.KEY_DELETE)) {
|
||||
if (this.doBackspacing && this.backspaceWaitTimer.passed(750)) {
|
||||
if (this.backspaceTimer.passed(75)) {
|
||||
if (this.displayValue.length() > 0) {
|
||||
this.displayValue = this.displayValue.substring(0, this.displayValue.length() - 1);
|
||||
}
|
||||
this.backspaceTimer.reset();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.doBackspacing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,6 +94,9 @@ public class TextComponent extends HudComponent {
|
||||
// }
|
||||
// break;
|
||||
case Keyboard.KEY_BACK:
|
||||
case Keyboard.KEY_DELETE:
|
||||
this.backspaceWaitTimer.reset();
|
||||
this.doBackspacing = true;
|
||||
if (this.displayValue.length() > 0) {
|
||||
this.displayValue = this.displayValue.substring(0, this.displayValue.length() - 1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user