Search in sources :

Example 1 with TextFieldWidget2

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);
}
Also used : SimpleTextWidget(gregtech.api.gui.widgets.SimpleTextWidget) MetaItems(gregtech.common.items.MetaItems) MACHINE(gregtech.common.blocks.MetaBlocks.MACHINE) EnumHand(net.minecraft.util.EnumHand) ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) Block(net.minecraft.block.Block) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemUIFactory(gregtech.api.items.gui.ItemUIFactory) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) ImageCycleButtonWidget(gregtech.api.gui.widgets.ImageCycleButtonWidget) BlockPos(net.minecraft.util.math.BlockPos) MetaTileEntityClipboard(gregtech.common.metatileentities.MetaTileEntityClipboard) GuiTextures(gregtech.api.gui.GuiTextures) ActionResult(net.minecraft.util.ActionResult) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) RayTracer(codechicken.lib.raytracer.RayTracer) ModularUI(gregtech.api.gui.ModularUI) PlayerInventoryHolder(gregtech.api.items.gui.PlayerInventoryHolder) CLIPBOARD_TILE(gregtech.common.metatileentities.MetaTileEntities.CLIPBOARD_TILE) ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) ModularUI(gregtech.api.gui.ModularUI) ArrayList(java.util.ArrayList) ImageCycleButtonWidget(gregtech.api.gui.widgets.ImageCycleButtonWidget) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2) SimpleTextWidget(gregtech.api.gui.widgets.SimpleTextWidget)

Example 2 with TextFieldWidget2

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();
    }));
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) java.util(java.util) GlStateManager(net.minecraft.client.renderer.GlStateManager) DrawableWidget(gregtech.api.gui.widgets.DrawableWidget) GuiTextures(gregtech.api.gui.GuiTextures) ImageWidget(gregtech.api.gui.widgets.ImageWidget) I18n(net.minecraft.client.resources.I18n) Consumer(java.util.function.Consumer) ItemStack(net.minecraft.item.ItemStack) Widget(gregtech.api.gui.Widget) OreDictExprFilter(gregtech.api.util.OreDictExprFilter) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2) Pattern(java.util.regex.Pattern) OreDictFilterTestSlot(gregtech.api.gui.widgets.OreDictFilterTestSlot) ItemStackKey(gregtech.api.util.ItemStackKey) OreDictFilterTestSlot(gregtech.api.gui.widgets.OreDictFilterTestSlot) DrawableWidget(gregtech.api.gui.widgets.DrawableWidget) ImageWidget(gregtech.api.gui.widgets.ImageWidget) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2)

Example 3 with TextFieldWidget2

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);
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) Matrix4(codechicken.lib.vec.Matrix4) Textures(gregtech.client.renderer.texture.Textures) IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Function(java.util.function.Function) ImageWidget(gregtech.api.gui.widgets.ImageWidget) ItemStack(net.minecraft.item.ItemStack) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) CycleButtonWidget(gregtech.api.gui.widgets.CycleButtonWidget) Pair(org.apache.commons.lang3.tuple.Pair) ColourOperation(gregtech.client.renderer.cclop.ColourOperation) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2) PhantomSlotWidget(gregtech.api.gui.widgets.PhantomSlotWidget) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CCRenderState(codechicken.lib.render.CCRenderState) GuiTextures(gregtech.api.gui.GuiTextures) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ResourceLocation(net.minecraft.util.ResourceLocation) ModularUI(gregtech.api.gui.ModularUI) TileEntity(net.minecraft.tileentity.TileEntity) GTUtility(gregtech.api.util.GTUtility) PhantomSlotWidget(gregtech.api.gui.widgets.PhantomSlotWidget) ModularUI(gregtech.api.gui.ModularUI) CycleButtonWidget(gregtech.api.gui.widgets.CycleButtonWidget) ImageWidget(gregtech.api.gui.widgets.ImageWidget) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2)

Example 4 with TextFieldWidget2

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);
}
Also used : IEnergyContainer(gregtech.api.capability.IEnergyContainer) Matrix4(codechicken.lib.vec.Matrix4) Textures(gregtech.client.renderer.texture.Textures) IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) Function(java.util.function.Function) ImageWidget(gregtech.api.gui.widgets.ImageWidget) CycleButtonWidget(gregtech.api.gui.widgets.CycleButtonWidget) Pair(org.apache.commons.lang3.tuple.Pair) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CCRenderState(codechicken.lib.render.CCRenderState) EnumFacing(net.minecraft.util.EnumFacing) GuiTextures(gregtech.api.gui.GuiTextures) Capability(net.minecraftforge.common.capabilities.Capability) GTValues(gregtech.api.GTValues) GregtechCapabilities(gregtech.api.capability.GregtechCapabilities) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) ModularUI(gregtech.api.gui.ModularUI) TileEntity(net.minecraft.tileentity.TileEntity) GTUtility(gregtech.api.util.GTUtility) ColourMultiplier(codechicken.lib.render.pipeline.ColourMultiplier) Cuboid6(codechicken.lib.vec.Cuboid6) ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) ModularUI(gregtech.api.gui.ModularUI) CycleButtonWidget(gregtech.api.gui.widgets.CycleButtonWidget) ImageWidget(gregtech.api.gui.widgets.ImageWidget) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2)

Example 5 with TextFieldWidget2

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);
}
Also used : Matrix4(codechicken.lib.vec.Matrix4) Textures(gregtech.client.renderer.texture.Textures) Constants(net.minecraftforge.common.util.Constants) IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Function(java.util.function.Function) ImageWidget(gregtech.api.gui.widgets.ImageWidget) Lists(com.google.common.collect.Lists) CycleButtonWidget(gregtech.api.gui.widgets.CycleButtonWidget) Pair(org.apache.commons.lang3.tuple.Pair) PhantomFluidWidget(gregtech.api.gui.widgets.PhantomFluidWidget) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CCRenderState(codechicken.lib.render.CCRenderState) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) EnumFacing(net.minecraft.util.EnumFacing) GuiTextures(gregtech.api.gui.GuiTextures) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) FLUID_NBT_KEY(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack.FLUID_NBT_KEY) ModularUI(gregtech.api.gui.ModularUI) TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) FluidTank(net.minecraftforge.fluids.FluidTank) GTUtility(gregtech.api.util.GTUtility) ColourMultiplier(codechicken.lib.render.pipeline.ColourMultiplier) ModularUI(gregtech.api.gui.ModularUI) CycleButtonWidget(gregtech.api.gui.widgets.CycleButtonWidget) PhantomFluidWidget(gregtech.api.gui.widgets.PhantomFluidWidget) ImageWidget(gregtech.api.gui.widgets.ImageWidget) TextFieldWidget2(gregtech.api.gui.widgets.TextFieldWidget2)

Aggregations

GuiTextures (gregtech.api.gui.GuiTextures)5 TextFieldWidget2 (gregtech.api.gui.widgets.TextFieldWidget2)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 ModularUI (gregtech.api.gui.ModularUI)4 ImageWidget (gregtech.api.gui.widgets.ImageWidget)4 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 CCRenderState (codechicken.lib.render.CCRenderState)3 IVertexOperation (codechicken.lib.render.pipeline.IVertexOperation)3 Matrix4 (codechicken.lib.vec.Matrix4)3 CycleButtonWidget (gregtech.api.gui.widgets.CycleButtonWidget)3 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)3 GTUtility (gregtech.api.util.GTUtility)3 Textures (gregtech.client.renderer.texture.Textures)3 Function (java.util.function.Function)3 ItemStack (net.minecraft.item.ItemStack)3 ColourMultiplier (codechicken.lib.render.pipeline.ColourMultiplier)2 ClickButtonWidget (gregtech.api.gui.widgets.ClickButtonWidget)2 List (java.util.List)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2