Search in sources :

Example 11 with ICitizenDataView

use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by Minecolonies.

the class WindowHireWorker method doneClicked.

/**
 * Hire clicked to persist the changes.
 *
 * @param button the clicked button.
 */
private void doneClicked(@NotNull final Button button) {
    final int row = citizenList.getListElementIndexByPane(button);
    @NotNull final ICitizenDataView citizen = citizens.get(row);
    // Fire citizen if they already have a job
    if (citizen.getWorkBuilding() != null && selectedModule instanceof WorkerBuildingModuleView) {
        IBuildingView oldJob = colony.getBuilding(citizen.getWorkBuilding());
        oldJob.getModuleViewMatching(IAssignmentModuleView.class, m -> m.getJobEntry() == citizen.getJobView().getEntry()).removeCitizen(citizen);
    }
    selectedModule.addCitizen(citizen);
    onOpened();
}
Also used : IAssignmentModuleView(com.minecolonies.api.colony.buildings.modules.IAssignmentModuleView) net.minecraft.util.text(net.minecraft.util.text) java.util(java.util) ScrollingList(com.ldtteam.blockout.views.ScrollingList) TextBuilder(com.ldtteam.blockout.controls.AbstractTextBuilder.TextBuilder) IAssignmentModuleView(com.minecolonies.api.colony.buildings.modules.IAssignmentModuleView) COM_MINECOLONIES_COREMOD_GUI_HIRE_UNPAUSE(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_GUI_HIRE_UNPAUSE) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) RestartCitizenMessage(com.minecolonies.coremod.network.messages.server.colony.citizen.RestartCitizenMessage) Network(com.minecolonies.coremod.Network) PaneBuilders(com.ldtteam.blockout.PaneBuilders) Constants(com.minecolonies.api.util.constant.Constants) IColonyView(com.minecolonies.api.colony.IColonyView) PauseCitizenMessage(com.minecolonies.coremod.network.messages.server.colony.citizen.PauseCitizenMessage) Skill(com.minecolonies.api.entity.citizen.Skill) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Tuple(net.minecraft.util.Tuple) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) BlockPos(net.minecraft.util.math.BlockPos) Pane(com.ldtteam.blockout.Pane) CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView) Collectors(java.util.stream.Collectors) Text(com.ldtteam.blockout.controls.Text) COM_MINECOLONIES_COREMOD_GUI_HIRE_PAUSE(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_GUI_HIRE_PAUSE) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) Button(com.ldtteam.blockout.controls.Button) WindowConstants(com.minecolonies.api.util.constant.WindowConstants) PupilBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.PupilBuildingModuleView) HiringMode(com.minecolonies.api.colony.buildings.HiringMode) NotNull(org.jetbrains.annotations.NotNull) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with ICitizenDataView

use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by Minecolonies.

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 13 with ICitizenDataView

use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by Minecolonies.

the class WindowHappinessPage method updateHappiness.

/**
 * Update the display for the happiness
 */
private void updateHappiness() {
    final Map<String, Double> happinessMap = new HashMap<>();
    for (final ICitizenDataView data : building.getColony().getCitizens().values()) {
        for (final String modifier : data.getHappinessHandler().getModifiers()) {
            happinessMap.put(modifier, happinessMap.getOrDefault(modifier, 0.0) + data.getHappinessHandler().getModifier(modifier).getFactor());
        }
    }
    final View pane = findPaneOfTypeByID("happinesspage", View.class);
    int yPos = 62;
    for (final Map.Entry<String, Double> entry : happinessMap.entrySet()) {
        final double value = entry.getValue() / building.getColony().getCitizenCount();
        final Image image = new Image();
        image.setSize(11, 11);
        image.setPosition(0, yPos);
        final Text label = new Text();
        label.setSize(136, 11);
        label.setPosition(25, yPos);
        label.setColors(BLACK);
        label.setText(new TranslationTextComponent(PARTIAL_HAPPINESS_MODIFIER_NAME + entry.getKey()));
        if (value > 1.0) {
            image.setImage(GREEN_ICON);
        } else if (value == 1) {
            image.setImage(BLUE_ICON);
        } else if (value > 0.75) {
            image.setImage(YELLOW_ICON);
        } else {
            image.setImage(RED_ICON);
        }
        pane.addChild(image);
        pane.addChild(label);
        PaneBuilders.tooltipBuilder().hoverPane(label).append(new TranslationTextComponent("com.minecolonies.coremod.gui.townhall.happiness.desc." + entry.getKey())).build();
        yPos += 12;
    }
}
Also used : HashMap(java.util.HashMap) Text(com.ldtteam.blockout.controls.Text) Image(com.ldtteam.blockout.controls.Image) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) View(com.ldtteam.blockout.views.View) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with ICitizenDataView

use of com.minecolonies.api.colony.ICitizenDataView 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(new TranslationTextComponent(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(WARNING_POPULATION_NEEDS_HOUSING, this.building.getColony().getName()));
        totalCitizenLabel.setColors(ORANGE);
    } else {
        if (citizensCap < MineColonies.getConfig().getServer().maxCitizenPerColony.get()) {
            hoverText.add(new TranslationTextComponent(WARNING_POPULATION_RESEARCH_LIMITED, this.building.getColony().getName()));
        } else {
            hoverText.add(new TranslationTextComponent(WARNING_POPULATION_CONFIG_LIMITED, this.building.getColony().getName()));
        }
        totalCitizenLabel.setText(new TranslationTextComponent(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 ITextComponent numberOfUnemployed = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_UNEMPLOYED, unemployedCount);
    final ITextComponent numberOfKids = new TranslationTextComponent(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());
    theList.sort(Map.Entry.comparingByKey());
    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 ITextComponent job = new TranslationTextComponent(entry.getKey());
                final ITextComponent numberOfWorkers = new TranslationTextComponent(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) ITextComponent(net.minecraft.util.text.ITextComponent) 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) Text(com.ldtteam.blockout.controls.Text) 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 15 with ICitizenDataView

use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by Minecolonies.

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

ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)37 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)22 Pane (com.ldtteam.blockout.Pane)21 ScrollingList (com.ldtteam.blockout.views.ScrollingList)21 Text (com.ldtteam.blockout.controls.Text)14 NotNull (org.jetbrains.annotations.NotNull)14 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)13 WorkerBuildingModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView)13 Button (com.ldtteam.blockout.controls.Button)7 Image (com.ldtteam.blockout.controls.Image)7 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)7 View (com.ldtteam.blockout.views.View)6 Tuple (com.minecolonies.api.util.Tuple)6 ArrayList (java.util.ArrayList)6 IColonyView (com.minecolonies.api.colony.IColonyView)5 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)4 SettingsModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.SettingsModuleView)4 StringTextComponent (net.minecraft.util.text.StringTextComponent)4 TextBuilder (com.ldtteam.blockout.controls.AbstractTextBuilder.TextBuilder)3 IAssignmentModuleView (com.minecolonies.api.colony.buildings.modules.IAssignmentModuleView)3