Search in sources :

Example 1 with TextField

use of com.ldtteam.blockout.controls.TextField in project minecolonies by ldtteam.

the class WindowPostBox method requestClicked.

/**
 * Action executed when request is clicked.
 *
 * @param button the clicked button.
 */
private void requestClicked(final Button button) {
    final int row = stackList.getListElementIndexByPane(button);
    final ItemStack stack = allItems.get(row);
    int qty = stack.getMaxStackSize();
    for (final Pane child : button.getParent().getChildren()) {
        if (child.getID().equals(INPUT_QTY)) {
            try {
                qty = Integer.parseInt(((TextField) child).getText());
            } catch (final NumberFormatException ex) {
            // Be quiet about it.
            }
        }
    }
    Network.getNetwork().sendToServer(new PostBoxRequestMessage(buildingView, stack.copy(), qty, deliverAvailable));
}
Also used : PostBoxRequestMessage(com.minecolonies.coremod.network.messages.server.colony.building.postbox.PostBoxRequestMessage) TextField(com.ldtteam.blockout.controls.TextField) ItemStack(net.minecraft.item.ItemStack) Pane(com.ldtteam.blockout.Pane)

Example 2 with TextField

use of com.ldtteam.blockout.controls.TextField in project minecolonies by ldtteam.

the class WindowPermissionsPage method addBlock.

/**
 * Called when the "addBlock" button has been triggered. Tries to add the content of the input field as block or position to the colony.
 */
private void addBlock() {
    final TextField input = findPaneOfTypeByID(INPUT_BLOCK_NAME, TextField.class);
    final String inputText = input.getText();
    try {
        final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(inputText));
        if (block != null) {
            building.getColony().addFreeBlock(block);
            Network.getNetwork().sendToServer(new ChangeFreeToInteractBlockMessage(building.getColony(), block, ChangeFreeToInteractBlockMessage.MessageType.ADD_BLOCK));
        }
    } catch (final ResourceLocationException e) {
    // Do nothing.
    }
    final BlockPos pos = BlockPosUtil.getBlockPosOfString(inputText);
    if (pos != null) {
        Network.getNetwork().sendToServer(new ChangeFreeToInteractBlockMessage(building.getColony(), pos, ChangeFreeToInteractBlockMessage.MessageType.ADD_BLOCK));
        building.getColony().addFreePosition(pos);
    }
    fillFreeBlockList();
    input.setText("");
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ResourceLocationException(net.minecraft.util.ResourceLocationException) TextField(com.ldtteam.blockout.controls.TextField) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with TextField

use of com.ldtteam.blockout.controls.TextField in project minecolonies by Minecolonies.

the class WindowHutCrusherModule method saveCrushingMode.

/**
 * Save the crushing mode.
 */
private void saveCrushingMode() {
    final TextField crushingSettingsInput = findPaneOfTypeByID(QTY_INPUT, TextField.class);
    try {
        final int qty = Integer.parseInt(crushingSettingsInput.getText());
        building.setCrusherMode(mode, qty);
    } catch (final NumberFormatException ex) {
        Log.getLogger().warn("Wrong input!");
    }
}
Also used : TextField(com.ldtteam.blockout.controls.TextField)

Example 4 with TextField

use of com.ldtteam.blockout.controls.TextField in project minecolonies by Minecolonies.

the class WindowPermissionsPage method addBlock.

/**
 * Called when the "addBlock" button has been triggered. Tries to add the content of the input field as block or position to the colony.
 */
private void addBlock() {
    final TextField input = findPaneOfTypeByID(INPUT_BLOCK_NAME, TextField.class);
    final String inputText = input.getText();
    try {
        final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(inputText));
        if (block != null) {
            building.getColony().addFreeBlock(block);
            Network.getNetwork().sendToServer(new ChangeFreeToInteractBlockMessage(building.getColony(), block, ChangeFreeToInteractBlockMessage.MessageType.ADD_BLOCK));
        }
    } catch (final ResourceLocationException e) {
    // Do nothing.
    }
    final BlockPos pos = BlockPosUtil.getBlockPosOfString(inputText);
    if (pos != null) {
        Network.getNetwork().sendToServer(new ChangeFreeToInteractBlockMessage(building.getColony(), pos, ChangeFreeToInteractBlockMessage.MessageType.ADD_BLOCK));
        building.getColony().addFreePosition(pos);
    }
    fillFreeBlockList();
    input.setText("");
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ResourceLocationException(net.minecraft.util.ResourceLocationException) TextField(com.ldtteam.blockout.controls.TextField) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ChangeFreeToInteractBlockMessage(com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage)

Example 5 with TextField

use of com.ldtteam.blockout.controls.TextField in project minecolonies by Minecolonies.

the class WindowPostBox method requestClicked.

/**
 * Action executed when request is clicked.
 *
 * @param button the clicked button.
 */
private void requestClicked(final Button button) {
    final int row = stackList.getListElementIndexByPane(button);
    final ItemStack stack = allItems.get(row);
    int qty = stack.getMaxStackSize();
    for (final Pane child : button.getParent().getChildren()) {
        if (child.getID().equals(INPUT_QTY)) {
            try {
                qty = Integer.parseInt(((TextField) child).getText());
            } catch (final NumberFormatException ex) {
            // Be quiet about it.
            }
        }
    }
    Network.getNetwork().sendToServer(new PostBoxRequestMessage(buildingView, stack.copy(), qty, deliverAvailable));
}
Also used : PostBoxRequestMessage(com.minecolonies.coremod.network.messages.server.colony.building.postbox.PostBoxRequestMessage) TextField(com.ldtteam.blockout.controls.TextField) ItemStack(net.minecraft.item.ItemStack) Pane(com.ldtteam.blockout.Pane)

Aggregations

TextField (com.ldtteam.blockout.controls.TextField)10 PermissionsMessage (com.minecolonies.coremod.network.messages.PermissionsMessage)4 Pane (com.ldtteam.blockout.Pane)2 Text (com.ldtteam.blockout.controls.Text)2 PostBoxRequestMessage (com.minecolonies.coremod.network.messages.server.colony.building.postbox.PostBoxRequestMessage)2 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ResourceLocationException (net.minecraft.util.ResourceLocationException)2 BlockPos (net.minecraft.util.math.BlockPos)2 ChangeFreeToInteractBlockMessage (com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage)1