Search in sources :

Example 11 with ScrollingList

use of com.ldtteam.blockout.views.ScrollingList in project minecolonies by ldtteam.

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)

Example 12 with ScrollingList

use of com.ldtteam.blockout.views.ScrollingList 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 13 with ScrollingList

use of com.ldtteam.blockout.views.ScrollingList in project minecolonies by Minecolonies.

the class WindowCitizenPage method fillCitizensList.

/**
 * Fills the citizens list in the GUI.
 */
private void fillCitizensList() {
    final ScrollingList citizenList = findPaneOfTypeByID(LIST_CITIZENS, ScrollingList.class);
    citizenList.setDataProvider(new ScrollingList.DataProvider() {

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

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final ICitizenDataView citizen = citizens.get(index);
            rowPane.findPaneOfTypeByID(NAME_LABEL, ButtonImage.class).setText(citizen.getName());
        }
    });
}
Also used : ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 14 with ScrollingList

use of com.ldtteam.blockout.views.ScrollingList in project minecolonies by Minecolonies.

the class WindowCitizenPage method fillCitizenInfo.

/**
 * Executed when fill citizen is clicked.
 *
 * @param button the clicked button.
 */
private void fillCitizenInfo(final Button button) {
    final ScrollingList citizenList = findPaneOfTypeByID(LIST_CITIZENS, ScrollingList.class);
    for (final Pane pane : citizenList.getContainer().getChildren()) {
        pane.findPaneOfTypeByID(NAME_LABEL, ButtonImage.class).enable();
    }
    final int row = citizenList.getListElementIndexByPane(button);
    findPaneByID(CITIZEN_INFO).show();
    button.disable();
    final ICitizenDataView view = citizens.get(row);
    CitizenWindowUtils.createHappinessBar(view, this);
    CitizenWindowUtils.createSkillContent(view, this);
    findPaneOfTypeByID(JOB_LABEL, Text.class).setText("§l" + LanguageHandler.format(view.getJob().trim().isEmpty() ? COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_CITIZEN_UNEMPLOYED : view.getJob()));
    findPaneOfTypeByID(HIDDEN_CITIZEN_ID, Text.class).setText(String.valueOf(view.getId()));
}
Also used : ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 15 with ScrollingList

use of com.ldtteam.blockout.views.ScrollingList in project minecolonies by Minecolonies.

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)

Aggregations

Pane (com.ldtteam.blockout.Pane)24 ScrollingList (com.ldtteam.blockout.views.ScrollingList)24 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)12 Text (com.ldtteam.blockout.controls.Text)10 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)10 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)6 Tuple (com.minecolonies.api.util.Tuple)6 WorkerBuildingModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView)6 ArrayList (java.util.ArrayList)6 ItemStorage (com.minecolonies.api.crafting.ItemStorage)4 MarkBuildingDirtyMessage (com.minecolonies.coremod.network.messages.server.colony.building.MarkBuildingDirtyMessage)4 ItemStack (net.minecraft.item.ItemStack)4 NotNull (org.jetbrains.annotations.NotNull)4 Button (com.ldtteam.blockout.controls.Button)2 Image (com.ldtteam.blockout.controls.Image)2 LanguageHandler (com.ldtteam.structurize.util.LanguageHandler)2 IAssignmentModuleView (com.minecolonies.api.colony.buildings.modules.IAssignmentModuleView)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 IDeliverymanRequestable (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable)2 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)2