Search in sources :

Example 56 with Pane

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

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)

Example 57 with Pane

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

the class AbstractWindowWorkerModuleBuilding method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    final List<Tuple<String, Integer>> workers = new ArrayList<>();
    for (final WorkerBuildingModuleView module : buildingView.getModuleViews(WorkerBuildingModuleView.class)) {
        for (final int worker : module.getAssignedCitizens()) {
            workers.add(new Tuple<>(new TranslationTextComponent(module.getJobEntry().getTranslationKey()).getString(), worker));
        }
    }
    if (findPaneByID(LIST_WORKERS) != null) {
        ScrollingList workerList = findPaneOfTypeByID(LIST_WORKERS, ScrollingList.class);
        workerList.setDataProvider(new ScrollingList.DataProvider() {

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

            @Override
            public void updateElement(final int index, @NotNull final Pane rowPane) {
                final ICitizenDataView worker = building.getColony().getCitizen(workers.get(index).getB());
                if (worker != null) {
                    rowPane.findPaneOfTypeByID(LABEL_WORKERNAME, Text.class).setText(new TranslationTextComponent(workers.get(index).getA()).getString() + ": " + worker.getName());
                }
            }
        });
    }
    updatePriorityLabel();
}
Also used : ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) Tuple(com.minecolonies.api.util.Tuple)

Example 58 with Pane

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

the class WindowAssignCitizen method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    updateCitizens();
    citizenList.enable();
    citizenList.show();
    // Creates a dataProvider for the homeless citizenList.
    citizenList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return citizens.size();
        }

        /**
         * Inserts the elements into each row.
         * @param index the index of the row/list element.
         * @param rowPane the parent Pane for the row, containing the elements to update.
         */
        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            @NotNull final ICitizenDataView citizen = citizens.get(index);
            final Button done = rowPane.findPaneOfTypeByID(CITIZEN_DONE, Button.class);
            final BlockPos home = citizen.getHomeBuilding();
            final BlockPos work = citizen.getWorkBuilding();
            boolean assign = false;
            if (home != null && home.equals(building.getPosition())) {
                done.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonunassign"));
            } else {
                assign = true;
                done.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign"));
            }
            final Text citizenLabel = rowPane.findPaneOfTypeByID(CITIZEN_LABEL, Text.class);
            citizenLabel.setText(citizen.getName());
            if (assign) {
                citizenLabel.setColors(YELLOW);
            } else {
                citizenLabel.setColors(DARKGREEN);
            }
            String workString = "";
            double newDistance = 0;
            if (work != null) {
                newDistance = BlockPosUtil.getDistance2D(work, building.getPosition());
                workString = " " + new TranslationTextComponent("com.minecolonies.coremod.gui.home.new", newDistance).getString();
            }
            String homeString = new TranslationTextComponent("com.minecolonies.coremod.gui.home.homeless").getString();
            boolean better = false;
            boolean badCurrentLiving = true;
            if (home != null) {
                if (work != null) {
                    final double oldDistance = BlockPosUtil.getDistance2D(work, home);
                    homeString = new TranslationTextComponent("com.minecolonies.coremod.gui.home.currently", oldDistance).getString();
                    better = newDistance < oldDistance;
                    if (oldDistance < FAR_DISTANCE_THRESHOLD) {
                        badCurrentLiving = false;
                    }
                } else {
                    homeString = new TranslationTextComponent("com.minecolonies.coremod.gui.home.currently", home.getX(), home.getY(), home.getZ()).getString();
                }
            }
            final Text newLivingLabel = rowPane.findPaneOfTypeByID(CITIZEN_JOB, Text.class);
            if (citizen.getJobView() != null) {
                newLivingLabel.setText(new TranslationTextComponent(citizen.getJobView().getEntry().getTranslationKey()).getString() + ":" + workString);
                if (better) {
                    newLivingLabel.setColors(DARKGREEN);
                }
            }
            final Text currentLivingLabel = rowPane.findPaneOfTypeByID(CITIZEN_LIVING, Text.class);
            if (assign) {
                currentLivingLabel.setText(homeString);
                if (badCurrentLiving) {
                    currentLivingLabel.setColors(RED);
                }
            } else {
                currentLivingLabel.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.home.liveshere"));
            }
            if ((colony.isManualHousing() || building.getHiringMode() == HiringMode.MANUAL) && !(building.getHiringMode() == HiringMode.AUTO) && (!assign || building.getResidents().size() < building.getMax())) {
                done.enable();
            } else {
                done.disable();
            }
        }
    });
}
Also used : Button(com.ldtteam.blockout.controls.Button) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) Text(com.ldtteam.blockout.controls.Text) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 59 with Pane

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

the class WindowHutCrafterTaskModule method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    final List<IToken<?>> tasks = new ArrayList<>();
    for (final WorkerBuildingModuleView moduleView : buildingView.getModuleViews(WorkerBuildingModuleView.class)) {
        for (final int citizenId : moduleView.getAssignedCitizens()) {
            ICitizenDataView citizen = buildingView.getColony().getCitizen(citizenId);
            if (citizen != null) {
                if (citizen.getJobView() instanceof CrafterJobView) {
                    tasks.addAll(((CrafterJobView) citizen.getJobView()).getDataStore().getQueue());
                } else if (citizen.getJobView() instanceof DmanJobView) {
                    tasks.addAll(((DmanJobView) citizen.getJobView()).getDataStore().getQueue());
                }
            }
        }
    }
    final ScrollingList deliveryList = findPaneOfTypeByID(LIST_TASKS, ScrollingList.class);
    deliveryList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            tasks.removeIf(token -> buildingView.getColony().getRequestManager().getRequestForToken(token) == null);
            return tasks.size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final IRequest<?> request = buildingView.getColony().getRequestManager().getRequestForToken(tasks.get(index));
            final IRequest<?> parent = buildingView.getColony().getRequestManager().getRequestForToken(request.getParent());
            if (parent != null) {
                rowPane.findPaneOfTypeByID(REQUESTER, Text.class).setText(request.getRequester().getRequesterDisplayName(buildingView.getColony().getRequestManager(), request).getString() + " ->");
                rowPane.findPaneOfTypeByID(PARENT, Text.class).setText(parent.getRequester().getRequesterDisplayName(buildingView.getColony().getRequestManager(), parent));
            } else {
                rowPane.findPaneOfTypeByID(REQUESTER, Text.class).setText(request.getRequester().getRequesterDisplayName(buildingView.getColony().getRequestManager(), request));
                rowPane.findPaneOfTypeByID(PARENT, Text.class).clearText();
            }
            rowPane.findPaneOfTypeByID(REQUEST_SHORT_DETAIL, Text.class).setText(request.getShortDisplayString().getString().replace("§f", ""));
            if (request.getRequest() instanceof IDeliverymanRequestable) {
                rowPane.findPaneOfTypeByID(REQUEST_PRIORITY, Text.class).setText(LanguageHandler.format(COM_MINECOLONIES_COREMOD_ENTITY_DELIVERYMAN_PRIORITY) + ((IDeliverymanRequestable) (request.getRequest())).getPriority());
            }
            final Image logo = rowPane.findPaneOfTypeByID(DELIVERY_IMAGE, Image.class);
            logo.setImage(request.getDisplayIcon());
        }
    });
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) COM_MINECOLONIES_COREMOD_ENTITY_DELIVERYMAN_PRIORITY(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_ENTITY_DELIVERYMAN_PRIORITY) Text(com.ldtteam.blockout.controls.Text) ArrayList(java.util.ArrayList) DmanJobView(com.minecolonies.coremod.colony.jobs.views.DmanJobView) List(java.util.List) Image(com.ldtteam.blockout.controls.Image) IDeliverymanRequestable(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable) WindowConstants(com.minecolonies.api.util.constant.WindowConstants) AbstractModuleWindow(com.minecolonies.coremod.client.gui.AbstractModuleWindow) CrafterJobView(com.minecolonies.coremod.colony.jobs.views.CrafterJobView) NotNull(org.jetbrains.annotations.NotNull) ArrayList(java.util.ArrayList) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) Image(com.ldtteam.blockout.controls.Image) Pane(com.ldtteam.blockout.Pane) CrafterJobView(com.minecolonies.coremod.colony.jobs.views.CrafterJobView) IDeliverymanRequestable(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable) DmanJobView(com.minecolonies.coremod.colony.jobs.views.DmanJobView) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Example 60 with Pane

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

the class SpecialAssignmentModuleWindow method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    final List<Tuple<String, Integer>> workers = new ArrayList<>();
    for (final IAssignmentModuleView module : buildingView.getModuleViews(IAssignmentModuleView.class)) {
        for (final int worker : module.getAssignedCitizens()) {
            workers.add(new Tuple<>(new TranslationTextComponent(module.getJobEntry().getTranslationKey()).getString(), worker));
        }
    }
    if (findPaneByID(LIST_WORKERS) != null) {
        ScrollingList workerList = findPaneOfTypeByID(LIST_WORKERS, ScrollingList.class);
        workerList.setDataProvider(new ScrollingList.DataProvider() {

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

            @Override
            public void updateElement(final int index, @NotNull final Pane rowPane) {
                final ICitizenDataView worker = buildingView.getColony().getCitizen(workers.get(index).getB());
                if (worker != null) {
                    rowPane.findPaneOfTypeByID(LABEL_WORKERNAME, Text.class).setText(new TranslationTextComponent(workers.get(index).getA()).getString() + ": " + worker.getName());
                }
            }
        });
    }
}
Also used : IAssignmentModuleView(com.minecolonies.api.colony.buildings.modules.IAssignmentModuleView) ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) Tuple(com.minecolonies.api.util.Tuple)

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