Search in sources :

Example 6 with WorkerBuildingModuleView

use of com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView in project minecolonies by Minecolonies.

the class WindowHireWorker method onOpened.

/**
 * Called when the GUI has been opened. Will fill the fields and lists.
 */
@Override
public void onOpened() {
    updateCitizens();
    findPaneOfTypeByID(AUTO_HIRE_WARN, Text.class).off();
    citizenList.setDataProvider(new ScrollingList.DataProvider() {

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

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            @NotNull final ICitizenDataView citizen = citizens.get(index);
            final Button isPaused = rowPane.findPaneOfTypeByID(BUTTON_PAUSE, Button.class);
            if (selectedModule.canAssign(citizen) && !selectedModule.isFull() && !selectedModule.getAssignedCitizens().contains(citizen.getId())) {
                rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).off();
                rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).on();
                isPaused.off();
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
            } else if ((selectedModule.isFull()) && !selectedModule.getAssignedCitizens().contains(citizen.getId())) {
                rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).off();
                rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).off();
                isPaused.off();
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
            } else {
                rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).off();
                rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).on();
                if ((!selectedModule.getColony().isManualHiring() && selectedModule.getHiringMode() == HiringMode.DEFAULT) || (selectedModule.getHiringMode() == HiringMode.AUTO)) {
                    rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).disable();
                    findPaneOfTypeByID(AUTO_HIRE_WARN, Text.class).on();
                }
                isPaused.on();
                isPaused.setText(LanguageHandler.format(citizen.isPaused() ? COM_MINECOLONIES_COREMOD_GUI_HIRE_UNPAUSE : COM_MINECOLONIES_COREMOD_GUI_HIRE_PAUSE));
            }
            if (citizen.isPaused()) {
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).on();
            } else {
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
            }
            final StringTextComponent intermString = new StringTextComponent(" ");
            final TextBuilder textBuilder = PaneBuilders.textBuilder();
            textBuilder.append(new StringTextComponent(""));
            int skillCount = citizen.getCitizenSkillHandler().getSkills().entrySet().size();
            final Skill primary = selectedModule instanceof WorkerBuildingModuleView ? ((WorkerBuildingModuleView) selectedModule).getPrimarySkill() : null;
            final Skill secondary = selectedModule instanceof WorkerBuildingModuleView ? ((WorkerBuildingModuleView) selectedModule).getSecondarySkill() : null;
            for (final Map.Entry<Skill, Tuple<Integer, Double>> entry : citizen.getCitizenSkillHandler().getSkills().entrySet()) {
                final String skillName = entry.getKey().name().toLowerCase(Locale.US);
                final int skillLevel = entry.getValue().getA();
                final Style skillStyle = createColor(primary, secondary, entry.getKey());
                textBuilder.append(new TranslationTextComponent("com.minecolonies.coremod.gui.citizen.skills." + skillName).setStyle(skillStyle));
                textBuilder.append(new StringTextComponent(": " + skillLevel).setStyle(skillStyle));
                if (--skillCount > 0) {
                    textBuilder.append(intermString);
                }
            }
            // finish the current line
            textBuilder.newLine();
            rowPane.findPaneOfTypeByID(CITIZEN_LABEL, Text.class).setText((citizen.getJob().isEmpty() ? "" : LanguageHandler.format(citizen.getJob()) + ": ") + citizen.getName());
            rowPane.findPaneOfTypeByID(ATTRIBUTES_LABEL, Text.class).setText(textBuilder.getText());
        }
    });
    jobList.setDataProvider(new ScrollingList.DataProvider() {

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

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final JobEntry entry = moduleViews.get(index).getJobEntry();
            final Button button = rowPane.findPaneOfTypeByID(BUTTON_JOB, Button.class);
            button.setText(new TranslationTextComponent(entry.getTranslationKey()));
            if (entry.equals(selectedModule.getJobEntry())) {
                button.disable();
            } else {
                button.enable();
            }
        }
    });
}
Also used : Text(com.ldtteam.blockout.controls.Text) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) Pane(com.ldtteam.blockout.Pane) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) Skill(com.minecolonies.api.entity.citizen.Skill) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) TextBuilder(com.ldtteam.blockout.controls.AbstractTextBuilder.TextBuilder) Button(com.ldtteam.blockout.controls.Button) Style(net.minecraft.util.text.Style) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Example 7 with WorkerBuildingModuleView

use of com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView in project minecolonies by Minecolonies.

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 8 with WorkerBuildingModuleView

use of com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView 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 9 with WorkerBuildingModuleView

use of com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView in project minecolonies by ldtteam.

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 10 with WorkerBuildingModuleView

use of com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView 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)

Aggregations

WorkerBuildingModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView)10 Pane (com.ldtteam.blockout.Pane)8 ScrollingList (com.ldtteam.blockout.views.ScrollingList)8 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)8 Text (com.ldtteam.blockout.controls.Text)6 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 Image (com.ldtteam.blockout.controls.Image)4 Skill (com.minecolonies.api.entity.citizen.Skill)4 Tuple (com.minecolonies.api.util.Tuple)4 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)4 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)4 TextBuilder (com.ldtteam.blockout.controls.AbstractTextBuilder.TextBuilder)2 Button (com.ldtteam.blockout.controls.Button)2 LanguageHandler (com.ldtteam.structurize.util.LanguageHandler)2 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)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