use of gregtech.api.gui.widgets.TextFieldWidget2 in project GregTech by GregTechCEu.
the class ClipboardBehavior method createUI.
@Override
public ModularUI createUI(PlayerInventoryHolder holder, EntityPlayer entityPlayer) {
ModularUI.Builder builder = ModularUI.builder(GuiTextures.CLIPBOARD_BACKGROUND, 186, 263);
initNBT(holder.getCurrentItem());
List<TextFieldWidget2> textFields = new ArrayList<>();
builder.image(28, 28, 130, 12, GuiTextures.CLIPBOARD_TEXT_BOX);
textFields.add(new TextFieldWidget2(30, 30, 126, 9, () -> getTitle(holder), val -> setTitle(holder, val)).setMaxLength(25).setCentered(true).setTextColor(TEXT_COLOR));
for (int i = 0; i < 8; i++) {
int finalI = i;
builder.widget(new ImageCycleButtonWidget(14, 55 + 22 * i, 15, 15, GuiTextures.CLIPBOARD_BUTTON, 4, () -> getButtonState(holder, finalI), (x) -> setButton(holder, finalI, x)));
builder.image(32, 58 + 22 * i, 140, 12, GuiTextures.CLIPBOARD_TEXT_BOX);
textFields.add(new TextFieldWidget2(34, 60 + 22 * i, 136, 9, () -> getString(holder, finalI), val -> setString(holder, finalI, val)).setMaxLength(23).setTextColor(TEXT_COLOR));
}
for (TextFieldWidget2 textField : textFields) {
builder.widget(textField.setOnFocus(textField2 -> textFields.forEach(textField3 -> {
if (textField3 != textField2) {
textField3.unFocus();
}
})));
}
builder.widget(new ClickButtonWidget(38, 231, 16, 16, "", (x) -> incrPageNum(holder, x.isShiftClick ? -10 : -1)).setButtonTexture(GuiTextures.BUTTON_LEFT).setShouldClientCallback(true));
builder.widget(new ClickButtonWidget(132, 231, 16, 16, "", (x) -> incrPageNum(holder, x.isShiftClick ? 10 : 1)).setButtonTexture(GuiTextures.BUTTON_RIGHT).setShouldClientCallback(true));
builder.widget(new SimpleTextWidget(93, 240, "", TEXT_COLOR, () -> (getPageNum(holder) + 1) + " / " + MAX_PAGES, true));
builder.shouldColor(false);
return builder.build(holder, entityPlayer);
}
use of gregtech.api.gui.widgets.TextFieldWidget2 in project GregTech by GregTechCEu.
the class OreDictionaryItemFilter method initUI.
@Override
public void initUI(Consumer<Widget> widgetGroup) {
widgetGroup.accept(new ImageWidget(12, 0, 20, 20, GuiTextures.INFO_ICON).setTooltip("cover.ore_dictionary_filter.info"));
widgetGroup.accept(new ImageWidget(10, 25, 156, 14, GuiTextures.DISPLAY));
widgetGroup.accept(new TextFieldWidget2(14, 29, 152, 12, () -> oreDictFilterExpression, this::setOreDictFilterExpression).setAllowedChars(Pattern.compile("[(!]* *[0-9a-zA-Z*]* *\\)*( *[&|^]? *[(!]* *[0-9a-zA-Z*]* *\\)*)*")).setMaxLength(64).setScale(0.75f).setValidator(input -> {
// remove all operators that are double
input = input.replaceAll("\\*{2,}", "*");
input = input.replaceAll("&{2,}", "&");
input = input.replaceAll("\\|{2,}", "|");
input = input.replaceAll("!{2,}", "!");
input = input.replaceAll("\\^{2,}", "^");
input = input.replaceAll(" {2,}", " ");
// move ( and ) so it doesn't create invalid expressions f.e. xxx (& yyy) => xxx & (yyy)
// append or prepend ( and ) if the amount is not equal
StringBuilder builder = new StringBuilder();
int unclosed = 0;
char last = ' ';
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c == ' ') {
if (last != '(')
builder.append(" ");
continue;
}
if (c == '(')
unclosed++;
else if (c == ')') {
unclosed--;
if (last == '&' || last == '|' || last == '^') {
int l = builder.lastIndexOf(" " + last);
int l2 = builder.lastIndexOf("" + last);
builder.insert(l == l2 - 1 ? l : l2, ")");
continue;
}
if (i > 0 && builder.charAt(builder.length() - 1) == ' ') {
builder.deleteCharAt(builder.length() - 1);
}
} else if ((c == '&' || c == '|' || c == '^') && last == '(') {
builder.deleteCharAt(builder.lastIndexOf("("));
builder.append(c).append(" (");
continue;
}
builder.append(c);
last = c;
}
if (unclosed > 0) {
for (int i = 0; i < unclosed; i++) {
builder.append(")");
}
} else if (unclosed < 0) {
unclosed = -unclosed;
for (int i = 0; i < unclosed; i++) {
builder.insert(0, "(");
}
}
input = builder.toString();
input = input.replaceAll(" {2,}", " ");
return input;
}));
widgetGroup.accept(new DrawableWidget(36, 1, 100, 18).setBackgroundDrawer(((mouseX, mouseY, partialTicks, context, widget) -> {
if (testStack.isEmpty()) {
return;
}
int color = 0xD15858;
if (testResult) {
color = 0x66C261;
}
GlStateManager.pushMatrix();
GlStateManager.translate(widget.getPosition().x, widget.getPosition().y, 0);
GlStateManager.colorMask(true, true, true, true);
Widget.drawText(I18n.format(testMsg), 22, 6.5f, 0.75f, color, false);
color |= (140 & 0xFF) << 24;
Widget.drawGradientRect(0, 0, 18, 18, color, color);
GlStateManager.popMatrix();
})));
widgetGroup.accept(new OreDictFilterTestSlot(36, 1).setListener(stack -> {
testStack = stack;
updateTestMsg();
}));
}
use of gregtech.api.gui.widgets.TextFieldWidget2 in project GregTech by GregTechCEu.
the class MetaTileEntityCreativeChest method createUI.
@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 209).bindPlayerInventory(entityPlayer.inventory, 126);
builder.widget(new PhantomSlotWidget(handler, 0, 36, 6).setClearSlotOnRightClick(true).setBackgroundTexture(GuiTextures.SLOT).setChangeListener(this::markDirty));
builder.label(7, 9, "gregtech.creative.chest.item");
builder.widget(new ImageWidget(7, 48, 154, 14, GuiTextures.DISPLAY));
builder.widget(new TextFieldWidget2(9, 50, 152, 10, () -> String.valueOf(itemsPerCycle), value -> {
if (!value.isEmpty()) {
itemsPerCycle = Integer.parseInt(value);
}
}).setMaxLength(11).setNumbersOnly(1, Integer.MAX_VALUE));
builder.label(7, 28, "gregtech.creative.chest.ipc");
builder.widget(new ImageWidget(7, 85, 154, 14, GuiTextures.DISPLAY));
builder.widget(new TextFieldWidget2(9, 87, 152, 10, () -> String.valueOf(ticksPerCycle), value -> {
if (!value.isEmpty()) {
ticksPerCycle = Integer.parseInt(value);
}
}).setMaxLength(11).setNumbersOnly(1, Integer.MAX_VALUE));
builder.label(7, 65, "gregtech.creative.chest.tpc");
builder.widget(new CycleButtonWidget(7, 101, 162, 20, () -> active, value -> active = value, "gregtech.creative.activity.off", "gregtech.creative.activity.on"));
return builder.build(getHolder(), entityPlayer);
}
use of gregtech.api.gui.widgets.TextFieldWidget2 in project GregTech by GregTechCEu.
the class MetaTileEntityCreativeEnergy method createUI.
@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
ModularUI.Builder builder = ModularUI.defaultBuilder().widget(new CycleButtonWidget(7, 7, 30, 20, GTValues.VNF, () -> setTier, tier -> {
setTier = tier;
voltage = GTValues.V[setTier];
}));
builder.label(7, 32, "gregtech.creative.energy.voltage");
builder.widget(new ImageWidget(7, 44, 156, 20, GuiTextures.DISPLAY));
builder.widget(new TextFieldWidget2(9, 50, 152, 16, () -> String.valueOf(voltage), value -> {
if (!value.isEmpty()) {
voltage = Long.parseLong(value);
setTier = GTUtility.getTierByVoltage(voltage);
}
}).setAllowedChars(TextFieldWidget2.NATURAL_NUMS).setMaxLength(19).setValidator(getTextFieldValidator()));
builder.label(7, 74, "gregtech.creative.energy.amperage");
builder.widget(new ClickButtonWidget(7, 87, 20, 20, "-", data -> amps = amps-- == -1 ? 0 : amps--));
builder.widget(new ImageWidget(29, 87, 118, 20, GuiTextures.DISPLAY));
builder.widget(new TextFieldWidget2(31, 93, 114, 16, () -> String.valueOf(amps), value -> {
if (!value.isEmpty()) {
amps = Integer.parseInt(value);
}
}).setMaxLength(10).setNumbersOnly(0, Integer.MAX_VALUE));
builder.widget(new ClickButtonWidget(149, 87, 20, 20, "+", data -> amps++));
builder.widget(new CycleButtonWidget(7, 139, 162, 20, () -> active, value -> active = value, "gregtech.creative.activity.off", "gregtech.creative.activity.on"));
return builder.build(getHolder(), entityPlayer);
}
use of gregtech.api.gui.widgets.TextFieldWidget2 in project GregTech by GregTechCEu.
the class MetaTileEntityCreativeTank method createUI.
@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 209).bindPlayerInventory(entityPlayer.inventory, 126);
builder.widget(new PhantomFluidWidget(36, 6, 18, 18, () -> this.fluidTank.getFluid(), data -> {
this.fluidTank.setFluid(data);
}).showTip(false));
builder.label(7, 9, "gregtech.creative.tank.fluid");
builder.widget(new ImageWidget(7, 45, 154, 14, GuiTextures.DISPLAY));
builder.widget(new TextFieldWidget2(9, 47, 152, 10, () -> String.valueOf(mBPerCycle), value -> {
if (!value.isEmpty()) {
mBPerCycle = Integer.parseInt(value);
}
}).setMaxLength(11).setNumbersOnly(1, Integer.MAX_VALUE));
builder.label(7, 28, "gregtech.creative.tank.mbpc");
builder.widget(new ImageWidget(7, 82, 154, 14, GuiTextures.DISPLAY));
builder.widget(new TextFieldWidget2(9, 84, 152, 10, () -> String.valueOf(ticksPerCycle), value -> {
if (!value.isEmpty()) {
ticksPerCycle = Integer.parseInt(value);
}
}).setMaxLength(11).setNumbersOnly(1, Integer.MAX_VALUE));
builder.label(7, 65, "gregtech.creative.tank.tpc");
builder.widget(new CycleButtonWidget(7, 101, 162, 20, () -> active, value -> active = value, "gregtech.creative.activity.off", "gregtech.creative.activity.on"));
return builder.build(getHolder(), entityPlayer);
}
Aggregations