Search in sources :

Example 6 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.

the class CitizenWindowUtils method updateJobPage.

/**
 * Update the job page of the citizen.
 *
 * @param citizen       the citizen.
 * @param windowCitizen the window.
 * @param colony        the colony.
 */
public static void updateJobPage(final ICitizenDataView citizen, final JobWindowCitizen windowCitizen, final IColonyView colony) {
    final IBuildingView building = colony.getBuilding(citizen.getWorkBuilding());
    if (building instanceof AbstractBuildingView && building.getBuildingType() != ModBuildings.library && citizen.getJobView() != null) {
        final WorkerBuildingModuleView moduleView = building.getModuleViewMatching(WorkerBuildingModuleView.class, m -> m.getJobEntry() == citizen.getJobView().getEntry());
        if (moduleView == null) {
            return;
        }
        windowCitizen.findPaneOfTypeByID(JOB_TITLE_LABEL, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.label", LanguageHandler.format(citizen.getJob())));
        windowCitizen.findPaneOfTypeByID(JOB_DESC_LABEL, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.desc"));
        final Skill primary = moduleView.getPrimarySkill();
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_LABEL, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + primary.name().toLowerCase(Locale.US)) + " (100% XP)");
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_LABEL + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + primary.name().toLowerCase(Locale.US) + ".png");
        if (primary.getComplimentary() != null && primary.getAdverse() != null) {
            windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_COM, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + primary.getComplimentary().name().toLowerCase(Locale.US)) + " (" + PRIMARY_DEPENDENCY_SHARE + "% XP)");
            windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_COM + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + primary.getComplimentary().name().toLowerCase(Locale.US) + ".png");
            windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_ADV, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + primary.getAdverse().name().toLowerCase(Locale.US)) + " (-" + PRIMARY_DEPENDENCY_SHARE + "% XP)");
            windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_ADV + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + primary.getAdverse().name().toLowerCase(Locale.US) + ".png");
        }
        final Skill secondary = moduleView.getSecondarySkill();
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_LABEL, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + secondary.name().toLowerCase(Locale.US)) + " (50% XP)");
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_LABEL + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + secondary.name().toLowerCase(Locale.US) + ".png");
        if (secondary.getComplimentary() != null && secondary.getAdverse() != null) {
            windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_COM, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + secondary.getComplimentary().name().toLowerCase(Locale.US)) + " (" + SECONDARY_DEPENDENCY_SHARE + "% XP)");
            windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_COM + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + secondary.getComplimentary().name().toLowerCase(Locale.US) + ".png");
            windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_ADV, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + secondary.getAdverse().name().toLowerCase(Locale.US)) + " (-" + SECONDARY_DEPENDENCY_SHARE + "% XP)");
            windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_ADV + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + secondary.getAdverse().name().toLowerCase(Locale.US) + ".png");
        }
    } else {
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_LABEL + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_COM + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_ADV + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_LABEL + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_COM + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_ADV + IMAGE_APPENDIX, Image.class).hide();
    }
}
Also used : AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) Skill(com.minecolonies.api.entity.citizen.Skill) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Text(com.ldtteam.blockout.controls.Text) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) Image(com.ldtteam.blockout.controls.Image)

Example 7 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView 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)

Example 8 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.

the class WindowMineGuardModule method pullGuardsFromHut.

/**
 * Retrieve guards from the building to display in GUI.
 */
private void pullGuardsFromHut() {
    if (buildingView.getColony().getBuilding(buildingView.getID()) != null) {
        guardsInfo.clear();
        assignedGuards = 0;
        final List<IBuildingView> buildings = buildingView.getColony().getBuildings().stream().filter(entry -> entry instanceof AbstractBuildingGuards.View && entry.getModuleView(SettingsModuleView.class).getSetting(AbstractBuildingGuards.GUARD_TASK).getValue().equals(GuardTaskSetting.PATROL_MINE)).collect(Collectors.toList());
        for (final IBuildingView building : buildings) {
            final AbstractBuildingGuards.View guardbuilding = (AbstractBuildingGuards.View) building;
            if (guardbuilding.getMinePos() != null && guardbuilding.getMinePos().equals(buildingView.getPosition())) {
                assignedGuards++;
            }
            for (final Integer citizenId : guardbuilding.getGuards()) {
                guardsInfo.add(buildingView.getColony().getCitizen(citizenId));
            }
        }
        if (guardsInfo.isEmpty()) {
            findPaneOfTypeByID("noguardwarning", Text.class).setVisible(true);
        } else {
            findPaneOfTypeByID("noguardwarning", Text.class).setVisible(false);
        }
    }
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) GuardTaskSetting(com.minecolonies.coremod.colony.buildings.modules.settings.GuardTaskSetting) Pane(com.ldtteam.blockout.Pane) Collectors(java.util.stream.Collectors) Text(com.ldtteam.blockout.controls.Text) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) List(java.util.List) Button(com.ldtteam.blockout.controls.Button) AbstractModuleWindow(com.minecolonies.coremod.client.gui.AbstractModuleWindow) SettingsModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.SettingsModuleView) GuardSetMinePosMessage(com.minecolonies.coremod.network.messages.server.colony.building.guard.GuardSetMinePosMessage) Network(com.minecolonies.coremod.Network) Constants(com.minecolonies.api.util.constant.Constants) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Text(com.ldtteam.blockout.controls.Text) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) SettingsModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.SettingsModuleView)

Example 9 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView 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 10 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.

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)

Aggregations

IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)30 Pane (com.ldtteam.blockout.Pane)14 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)14 ScrollingList (com.ldtteam.blockout.views.ScrollingList)12 Text (com.ldtteam.blockout.controls.Text)10 IColonyView (com.minecolonies.api.colony.IColonyView)10 BlockPos (net.minecraft.util.math.BlockPos)10 Button (com.ldtteam.blockout.controls.Button)8 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)6 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)6 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)6 Constants (com.minecolonies.api.util.constant.Constants)6 Network (com.minecolonies.coremod.Network)6 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)6 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)6 List (java.util.List)6 ItemStack (net.minecraft.item.ItemStack)6 Image (com.ldtteam.blockout.controls.Image)4