Improvements to the usability of the number entry widgets (Priority, Level Emitter, Craft Amount): (#4737)

- Fixed tab order
- Introduced focus state for corner buttons
- Allowed the player to enter any text, but add validation that only persist it if it is a valid number
- Enter will now confirm these dialogs and return to the previous dialog
- The text field is automatically focused and its contents are selected
This commit is contained in:
shartte
2020-09-19 16:27:29 +02:00
committed by GitHub
parent f368f9dac2
commit 971a9d22e8
45 changed files with 574 additions and 527 deletions
@@ -0,0 +1,65 @@
package appeng.client.gui.widgets;
import java.util.ArrayList;
import java.util.List;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.text.ITextComponent;
/**
* Displays a small icon that shows validation errors for some input control.
*/
public class ValidationIcon extends IconButton {
private final List<ITextComponent> tooltip = new ArrayList<>();
private boolean valid;
public ValidationIcon(int x, int y) {
super(x, y, btn -> {
});
setDisableBackground(true);
setDisableClickSound(true);
setHalfSize(true);
}
public void setValid(boolean valid) {
setVisibility(!valid);
if (valid) {
this.tooltip.clear();
}
}
public void setTooltip(List<ITextComponent> lines) {
this.tooltip.clear();
this.tooltip.addAll(lines);
}
@Override
protected int getIconIndex() {
return 16 * 8;
}
@Override
public boolean changeFocus(boolean flag) {
return false; // Cannot focus this element
}
@Override
public void renderToolTip(MatrixStack matrices, int mouseX, int mouseY) {
if (this.tooltip.isEmpty()) {
return;
}
Minecraft client = Minecraft.getInstance();
Screen screen = client.currentScreen;
if (screen == null) {
return;
}
screen.renderToolTip(matrices, this.tooltip, x, y, client.fontRenderer);
}
}