Search in sources :

Example 21 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.

the class WindowBuilderResModule method transferItems.

/**
 * On Button click transfert Items.
 *
 * @param button the clicked button.
 */
private void transferItems(@NotNull final Button button) {
    final Pane pane = button.getParent();
    button.disable();
    final Text idLabel = pane.findPaneOfTypeByID(RESOURCE_ID, Text.class);
    final int index = Integer.parseInt(idLabel.getTextAsString());
    final BuildingBuilderResource res = resources.get(index);
    if (res == null) {
        Log.getLogger().warn("WindowHutBuilder.transferItems: Error - Could not find the resource.");
    } else {
        // The itemStack size should not be greater than itemStack.getMaxStackSize, We send 1 instead
        // and use quantity for the size
        @NotNull final ItemStack itemStack = res.getItemStack().copy();
        itemStack.setCount(1);
        final Text quantityLabel = pane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class);
        final int quantity = Integer.parseInt(quantityLabel.getTextAsString());
        final int needed = res.getAmount() - res.getAvailable();
        res.setAvailable(Math.min(res.getAmount(), res.getAvailable() + res.getPlayerAmount()));
        res.setPlayerAmount(Math.max(0, res.getPlayerAmount() - needed));
        resources.sort(new BuildingBuilderResource.ResourceComparator());
        Network.getNetwork().sendToServer(new TransferItemsRequestMessage(this.buildingView, itemStack, quantity, true));
    }
}
Also used : Text(com.ldtteam.blockout.controls.Text) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack) Pane(com.ldtteam.blockout.Pane) NotNull(org.jetbrains.annotations.NotNull) TransferItemsRequestMessage(com.minecolonies.coremod.network.messages.server.colony.building.TransferItemsRequestMessage)

Example 22 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.

the class WindowMineGuardModule method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    guardsList = findPaneOfTypeByID(LIST_GUARDS, ScrollingList.class);
    guardsList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return guardsInfo.size();
        }

        @Override
        public void updateElement(final int i, final Pane pane) {
            final ICitizenDataView citizen = guardsInfo.get(i);
            if (citizen != null) {
                final IBuildingView building = buildingView.getColony().getBuilding(citizen.getWorkBuilding());
                if (building instanceof AbstractBuildingGuards.View) {
                    pane.findPaneOfTypeByID("guardName", Text.class).setText(citizen.getName());
                    final AbstractBuildingGuards.View guardbuilding = (AbstractBuildingGuards.View) building;
                    final Button button = pane.findPaneOfTypeByID("assignGuard", Button.class);
                    if (guardbuilding.getMinePos() == null) {
                        button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign"));
                        if (assignedGuards >= getMaxGuards()) {
                            button.setEnabled(false);
                        } else {
                            button.setEnabled(true);
                        }
                    } else if (guardbuilding.getMinePos().equals(buildingView.getPosition())) {
                        button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonunassign"));
                    } else {
                        button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign"));
                        button.setEnabled(false);
                    }
                }
            } else {
                final Button button = pane.findPaneOfTypeByID("assignGuard", Button.class);
                button.setEnabled(false);
            }
        }
    });
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) Button(com.ldtteam.blockout.controls.Button) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) SettingsModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.SettingsModuleView)

Example 23 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.

the class WindowSettingsPage method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    final Pane pane = findPaneByID(DROPDOWN_TEXT_ID);
    if (isFeatureUnlocked.get()) {
        pane.enable();
    } else {
        pane.disable();
        AbstractTextBuilder.TooltipBuilder hoverText = PaneBuilders.tooltipBuilder().hoverPane(pane);
        hoverText.append(new TranslationTextComponent("com.minecolonies.core.townhall.patreon")).paragraphBreak();
        hoverText.build();
    }
}
Also used : AbstractTextBuilder(com.ldtteam.blockout.controls.AbstractTextBuilder) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Pane(com.ldtteam.blockout.Pane)

Example 24 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.

the class WindowWorkOrderPage method fillWorkOrderList.

/**
 * Fills the workOrder list inside the townhall GUI.
 */
private void fillWorkOrderList() {
    final ScrollingList workOrderList = findPaneOfTypeByID(LIST_WORKORDER, ScrollingList.class);
    workOrderList.enable();
    workOrderList.show();
    // Creates a dataProvider for the unemployed citizenList.
    workOrderList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return workOrders.size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final WorkOrderView workOrder = workOrders.get(index);
            String claimingCitizen = "";
            final int numElements = getElementCount();
            if (index == 0) {
                if (numElements == 1) {
                    rowPane.findPaneOfTypeByID(BUTTON_DOWN, Button.class).hide();
                } else {
                    rowPane.findPaneOfTypeByID(BUTTON_DOWN, Button.class).show();
                }
                rowPane.findPaneOfTypeByID(BUTTON_UP, Button.class).hide();
            } else if (index == numElements - 1) {
                rowPane.findPaneOfTypeByID(BUTTON_DOWN, Button.class).hide();
            }
            // Searches citizen of id x
            for (@NotNull final IBuildingView buildingView : building.getColony().getBuildings()) {
                if (buildingView.getPosition().equals(workOrder.getClaimedBy()) && buildingView instanceof AbstractBuildingBuilderView) {
                    claimingCitizen = ((AbstractBuildingBuilderView) buildingView).getWorkerName();
                    break;
                }
            }
            rowPane.findPaneOfTypeByID(WORK_LABEL, Text.class).setText(workOrder.getDisplayName());
            rowPane.findPaneOfTypeByID(ASSIGNEE_LABEL, Text.class).setText(claimingCitizen);
            rowPane.findPaneOfTypeByID(HIDDEN_WORKORDER_ID, Text.class).setText(Integer.toString(workOrder.getId()));
        }
    });
}
Also used : WorkOrderView(com.minecolonies.api.colony.workorders.WorkOrderView) AbstractBuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingBuilderView) Button(com.ldtteam.blockout.controls.Button) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 25 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by Minecolonies.

the class WindowRequestDetail method onOpened.

/**
 * Called when the GUI has been opened. Will fill the fields and lists.
 */
@Override
public void onOpened() {
    final Box box = findPaneOfTypeByID(BOX_ID_REQUEST, Box.class);
    final Text description = PaneBuilders.textBuilder().style(TextFormatting.getByCode('r')).style(TextFormatting.getByCode('0')).append(request.getLongDisplayString()).build();
    description.setPosition(1, 1);
    description.setSize(box.getWidth() - 2, AbstractTextElement.SIZE_FOR_UNLIMITED_ELEMENTS);
    box.addChild(description);
    box.setSize(box.getWidth(), description.getRenderedTextHeight() + 2);
    description.setSize(box.getWidth() - 2, box.getHeight());
    final Image logo = findPaneOfTypeByID(DELIVERY_IMAGE, Image.class);
    final ItemIcon exampleStackDisplay = findPaneOfTypeByID(LIST_ELEMENT_ID_REQUEST_STACK, ItemIcon.class);
    final List<ItemStack> displayStacks = request.getDisplayStacks();
    final IColonyView colony = IColonyManager.getInstance().getColonyView(colonyId, Minecraft.getInstance().level.dimension());
    if (!displayStacks.isEmpty()) {
        exampleStackDisplay.setItem(displayStacks.get((lifeCount / LIFE_COUNT_DIVIDER) % displayStacks.size()));
    } else if (!request.getDisplayIcon().equals(MISSING)) {
        logo.setVisible(true);
        logo.setImage(request.getDisplayIcon());
        PaneBuilders.tooltipBuilder().hoverPane(logo).build().setText(request.getResolverToolTip(colony));
    }
    findPaneOfTypeByID(REQUESTER, Text.class).setText(request.getRequester().getRequesterDisplayName(colony.getRequestManager(), request));
    findPaneOfTypeByID(LIST_ELEMENT_ID_REQUEST_LOCATION, Text.class).setText(request.getRequester().getLocation().toString());
    if (colony == null) {
        Log.getLogger().warn("---Colony Null in WindowRequestDetail---");
        return;
    }
    try {
        final IRequestResolver<?> resolver = colony.getRequestManager().getResolverForRequest(request.getId());
        if (resolver == null) {
            Log.getLogger().warn("---IRequestResolver Null in WindowRequestDetail---");
            return;
        }
        findPaneOfTypeByID(RESOLVER, Text.class).setText("Resolver: " + resolver.getRequesterDisplayName(colony.getRequestManager(), request).getString());
    } catch (@SuppressWarnings(EXCEPTION_HANDLERS_SHOULD_PRESERVE_THE_ORIGINAL_EXCEPTIONS) final IllegalArgumentException e) {
        /*
             * Do nothing we just need to know if it has a resolver or not.
             */
        Log.getLogger().warn("---IRequestResolver Null in WindowRequestDetail---", e);
    }
    // Checks if fulfill button should be displayed
    Pane fulfillButton = this.window.getChildren().stream().filter(pane -> pane.getID().equals(REQUEST_FULLFIL)).findFirst().get();
    if ((this.prevWindow instanceof RequestWindowCitizen && !((RequestWindowCitizen) prevWindow).fulfillable(request)) || this.prevWindow instanceof WindowClipBoard) {
        fulfillButton.hide();
    }
    // Checks if cancel button should be displayed
    Pane cancelButton = this.window.getChildren().stream().filter(pane -> pane.getID().equals(REQUEST_CANCEL)).findFirst().get();
    if (this.prevWindow instanceof RequestWindowCitizen && !((RequestWindowCitizen) prevWindow).cancellable(request)) {
        cancelButton.hide();
    }
}
Also used : Box(com.ldtteam.blockout.views.Box) ItemStack(net.minecraft.item.ItemStack) IColonyView(com.minecolonies.api.colony.IColonyView) Pane(com.ldtteam.blockout.Pane) RequestWindowCitizen(com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen)

Aggregations

Pane (com.ldtteam.blockout.Pane)64 ScrollingList (com.ldtteam.blockout.views.ScrollingList)40 Text (com.ldtteam.blockout.controls.Text)26 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)25 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)20 ItemStack (net.minecraft.item.ItemStack)13 Button (com.ldtteam.blockout.controls.Button)10 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)10 NotNull (org.jetbrains.annotations.NotNull)9 WorkerBuildingModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView)8 ArrayList (java.util.ArrayList)8 ItemStorage (com.minecolonies.api.crafting.ItemStorage)6 Tuple (com.minecolonies.api.util.Tuple)6 BlockPos (net.minecraft.util.math.BlockPos)6 List (java.util.List)5 StringTextComponent (net.minecraft.util.text.StringTextComponent)5 Skill (com.minecolonies.api.entity.citizen.Skill)4 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)4 MarkBuildingDirtyMessage (com.minecolonies.coremod.network.messages.server.colony.building.MarkBuildingDirtyMessage)4 TileEntity (net.minecraft.tileentity.TileEntity)4