Search in sources :

Example 1 with Pane

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

the class WindowBuildBuilding method updateResourceList.

public void updateResourceList() {
    final ScrollingList recourseList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
    recourseList.enable();
    recourseList.show();
    final List<ItemStorage> tempRes = new ArrayList<>(resources.values());
    // Creates a dataProvider for the unemployed recourseList.
    recourseList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return tempRes.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) {
            final ItemStorage resource = tempRes.get(index);
            final Text resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Text.class);
            final Text quantityLabel = rowPane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class);
            resourceLabel.setText(resource.getItemStack().getHoverName());
            quantityLabel.setText(Integer.toString(resource.getAmount()));
            resourceLabel.setColors(WHITE);
            quantityLabel.setColors(WHITE);
            final ItemStack itemIcon = new ItemStack(resource.getItem(), 1);
            itemIcon.setTag(resource.getItemStack().getTag());
            rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(itemIcon);
        }
    });
}
Also used : Text(com.ldtteam.blockout.controls.Text) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 2 with Pane

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

the class WindowHutAllInventory method updateResourceList.

/**
 * Updates the resource list in the GUI with the info we need.
 */
private void updateResourceList() {
    stackList.enable();
    // Creates a dataProvider for the unemployed stackList.
    stackList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return allItems.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) {
            final ItemStorage resource = allItems.get(index);
            final Text resourceLabel = rowPane.findPaneOfTypeByID("ressourceStackName", Text.class);
            final String name = resource.getItemStack().getHoverName().getString();
            resourceLabel.setText(name.substring(0, Math.min(17, name.length())));
            final Text qtys = rowPane.findPaneOfTypeByID("quantities", Text.class);
            if (!Screen.hasShiftDown()) {
                qtys.setText(Utils.format(resource.getAmount()));
            } else {
                qtys.setText(Integer.toString(resource.getAmount()));
            }
            final Item imagesrc = resource.getItemStack().getItem();
            final ItemStack image = new ItemStack(imagesrc, 1);
            image.setTag(resource.getItemStack().getTag());
            rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(image);
        }
    });
}
Also used : Item(net.minecraft.item.Item) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 3 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)

Example 4 with Pane

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

the class FamilyWindowCitizen method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    final String firstParent = citizen.getParents().getA();
    final String secondParent = citizen.getParents().getB();
    findPaneOfTypeByID("parentA", Text.class).setText(firstParent.isEmpty() ? new TranslationTextComponent("com.minecolonies.coremod.gui.citizen.family.unknown") : new StringTextComponent(firstParent));
    findPaneOfTypeByID("parentB", Text.class).setText(secondParent.isEmpty() ? new TranslationTextComponent("com.minecolonies.coremod.gui.citizen.family.unknown") : new StringTextComponent(secondParent));
    final int partner = citizen.getPartner();
    final ICitizenDataView partnerView = colony.getCitizen(partner);
    final Text partnerText = findPaneOfTypeByID("partner", Text.class);
    if (partnerView == null) {
        partnerText.setText(new StringTextComponent("-"));
    } else {
        partnerText.setText(new StringTextComponent(partnerView.getName()));
    }
    childrenList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return citizen.getChildren().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) {
            rowPane.findPaneOfTypeByID("name", Text.class).setText(new StringTextComponent(colony.getCitizen(citizen.getChildren().get(index)).getName()));
        }
    });
    siblingList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return citizen.getSiblings().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) {
            rowPane.findPaneOfTypeByID("name", Text.class).setText(new StringTextComponent(colony.getCitizen(citizen.getSiblings().get(index)).getName()));
        }
    });
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Text(com.ldtteam.blockout.controls.Text) StringTextComponent(net.minecraft.util.text.StringTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 5 with Pane

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

the class WindowInfoPage method createAndSetStatistics.

/**
 * Creates several statistics and sets them in the building GUI.
 */
private void createAndSetStatistics() {
    final DecimalFormat df = new DecimalFormat("#.#");
    df.setRoundingMode(RoundingMode.CEILING);
    final String roundedHappiness = df.format(building.getColony().getOverallHappiness());
    findPaneOfTypeByID(HAPPINESS_LABEL, Text.class).setText(roundedHappiness);
    final int citizensSize = building.getColony().getCitizens().size();
    final int citizensCap;
    if (MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().hasResearchEffect(CITIZEN_CAP)) {
        citizensCap = (int) (Math.min(MineColonies.getConfig().getServer().maxCitizenPerColony.get(), 25 + this.building.getColony().getResearchManager().getResearchEffects().getEffectStrength(CITIZEN_CAP)));
    } else {
        citizensCap = MineColonies.getConfig().getServer().maxCitizenPerColony.get();
    }
    final Text totalCitizenLabel = findPaneOfTypeByID(TOTAL_CITIZENS_LABEL, Text.class);
    totalCitizenLabel.setText(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_TOTALCITIZENS_COUNT, citizensSize, Math.max(citizensSize, building.getColony().getCitizenCountLimit())));
    List<IFormattableTextComponent> hoverText = new ArrayList<>();
    if (citizensSize < (citizensCap * 0.9) && citizensSize < (building.getColony().getCitizenCountLimit() * 0.9)) {
        totalCitizenLabel.setColors(DARKGREEN);
    } else if (citizensSize < citizensCap) {
        hoverText.add(new TranslationTextComponent("com.minecolonies.coremod.gui.townhall.population.totalcitizens.houselimited", this.building.getColony().getName()));
        totalCitizenLabel.setColors(ORANGE);
    } else {
        if (citizensCap < MineColonies.getConfig().getServer().maxCitizenPerColony.get()) {
            hoverText.add(new TranslationTextComponent("com.minecolonies.coremod.gui.townhall.population.totalcitizens.researchlimited", this.building.getColony().getName()));
        } else {
            hoverText.add(new TranslationTextComponent("com.minecolonies.coremod.gui.townhall.population.totalcitizens.configlimited", this.building.getColony().getName()));
        }
        totalCitizenLabel.setText(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_TOTALCITIZENS_COUNT, citizensSize, citizensCap));
        totalCitizenLabel.setColors(RED);
    }
    PaneBuilders.tooltipBuilder().hoverPane(totalCitizenLabel).build().setText(hoverText);
    int children = 0;
    final Map<String, Tuple<Integer, Integer>> jobMaxCountMap = new HashMap<>();
    for (@NotNull final IBuildingView building : building.getColony().getBuildings()) {
        if (building instanceof AbstractBuildingView) {
            for (final WorkerBuildingModuleView module : building.getModuleViews(WorkerBuildingModuleView.class)) {
                int max = module.getMaxInhabitants();
                int workers = module.getAssignedCitizens().size();
                final String jobName = module.getJobDisplayName().toLowerCase(Locale.ENGLISH);
                final Tuple<Integer, Integer> tuple = jobMaxCountMap.getOrDefault(jobName, new Tuple<>(0, 0));
                jobMaxCountMap.put(jobName, new Tuple<>(tuple.getA() + workers, tuple.getB() + max));
            }
        }
    }
    // calculate number of children
    int unemployedCount = 0;
    for (ICitizenDataView iCitizenDataView : building.getColony().getCitizens().values()) {
        if (iCitizenDataView.isChild()) {
            children++;
        } else if (iCitizenDataView.getJobView() == null) {
            unemployedCount++;
        }
    }
    final String numberOfUnemployed = LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_UNEMPLOYED, unemployedCount);
    final String numberOfKids = LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_CHILDS, children);
    final ScrollingList list = findPaneOfTypeByID("citizen-stats", ScrollingList.class);
    if (list == null) {
        return;
    }
    final int maxJobs = jobMaxCountMap.size();
    final List<Map.Entry<String, Tuple<Integer, Integer>>> theList = new ArrayList<>(jobMaxCountMap.entrySet());
    list.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return maxJobs + 2;
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final Text label = rowPane.findPaneOfTypeByID(CITIZENS_AMOUNT_LABEL, Text.class);
            if (index < theList.size()) {
                final Map.Entry<String, Tuple<Integer, Integer>> entry = theList.get(index);
                final String job = LanguageHandler.format(entry.getKey());
                final String numberOfWorkers = LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_EACH, job, entry.getValue().getA(), entry.getValue().getB());
                label.setText(numberOfWorkers);
            } else {
                if (index == maxJobs + 1) {
                    label.setText(numberOfUnemployed);
                } else {
                    label.setText(numberOfKids);
                }
            }
        }
    });
}
Also used : DecimalFormat(java.text.DecimalFormat) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) NotNull(org.jetbrains.annotations.NotNull) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) Pane(com.ldtteam.blockout.Pane) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Tuple(com.minecolonies.api.util.Tuple)

Aggregations

Pane (com.ldtteam.blockout.Pane)62 ScrollingList (com.ldtteam.blockout.views.ScrollingList)38 Text (com.ldtteam.blockout.controls.Text)21 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)21 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)19 ItemStack (net.minecraft.item.ItemStack)13 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)10 NotNull (org.jetbrains.annotations.NotNull)9 Button (com.ldtteam.blockout.controls.Button)8 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 List (java.util.List)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 View (com.ldtteam.blockout.views.View)3 TileEntity (net.minecraft.tileentity.TileEntity)3 BlockPos (net.minecraft.util.math.BlockPos)3