Search in sources :

Example 16 with ICitizenDataView

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

the class WindowAssignCitizen method hireClicked.

/**
 * When assignment was clicked.
 * @param button the clicked button.
 */
private void hireClicked(@NotNull final Button button) {
    final int row = citizenList.getListElementIndexByPane(button);
    final ICitizenDataView data = citizens.get(row);
    final boolean isAssign = button.getText().getString().equals(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign").getString());
    if (isAssign) {
        if (building.getResidents().size() >= building.getMax()) {
            return;
        }
        building.addResident(data.getId());
        data.setHomeBuilding(building.getPosition());
    } else {
        building.removeResident(data.getId());
        data.setHomeBuilding(null);
    }
    Network.getNetwork().sendToServer(new AssignUnassignMessage(this.building, isAssign, data.getId(), null));
    updateCitizens();
    citizenList.refreshElementPanes();
}
Also used : AssignUnassignMessage(com.minecolonies.coremod.network.messages.server.colony.building.home.AssignUnassignMessage) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView)

Example 17 with ICitizenDataView

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

the class CitizenWindowUtils method createSaturationBar.

/**
 * Creates an health bar according to the citizen maxHealth and currentHealth.
 *
 * @param citizen the citizen.
 * @param view    the view to add these to.
 */
public static void createSaturationBar(final ICitizenDataView citizen, final View view) {
    view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).setAlignment(Alignment.MIDDLE_RIGHT);
    // Max saturation (Black food items).
    for (int i = 0; i < ICitizenData.MAX_SATURATION; i++) {
        @NotNull final Image saturation = new Image();
        saturation.setImage(Screen.GUI_ICONS_LOCATION, EMPTY_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
        saturation.setPosition(getXOffsetModifier(i) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(i));
        view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
    }
    // Current saturation (Full food hearts).
    int saturationPos;
    for (saturationPos = 0; saturationPos < ((int) citizen.getSaturation()); saturationPos++) {
        @NotNull final Image saturation = new Image();
        saturation.setImage(Screen.GUI_ICONS_LOCATION, FULL_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
        saturation.setPosition(getXOffsetModifier(saturationPos) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(saturationPos));
        view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
    }
    // Half food items.
    if (citizen.getSaturation() / 2 % 1 > 0) {
        @NotNull final Image saturation = new Image();
        saturation.setImage(Screen.GUI_ICONS_LOCATION, HALF_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
        saturation.setPosition(getXOffsetModifier(saturationPos) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(saturationPos));
        view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
    }
}
Also used : Image(com.ldtteam.blockout.controls.Image) View(com.ldtteam.blockout.views.View) IColonyView(com.minecolonies.api.colony.IColonyView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with ICitizenDataView

use of com.minecolonies.api.colony.ICitizenDataView 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 19 with ICitizenDataView

use of com.minecolonies.api.colony.ICitizenDataView 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 20 with ICitizenDataView

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

the class WindowAssignCitizen method onButtonClicked.

/**
 * Called when any button has been clicked.
 *
 * @param button the clicked button.
 */
@Override
public void onButtonClicked(@NotNull final Button button) {
    if (button.getID().equals(BUTTON_DONE)) {
        final int row = citizenList.getListElementIndexByPane(button);
        final ICitizenDataView data = citizens.get(row);
        if (building instanceof LivingBuildingView) {
            ((LivingBuildingView) building).addResident(data.getId());
        }
        Network.getNetwork().sendToServer(new AssignUnassignMessage(this.building, true, data.getId(), null));
    } else if (!button.getID().equals(BUTTON_CANCEL)) {
        return;
    }
    if (colony.getTownHall() != null) {
        building.openGui(false);
    }
}
Also used : AssignUnassignMessage(com.minecolonies.coremod.network.messages.server.colony.building.home.AssignUnassignMessage) LivingBuildingView(com.minecolonies.coremod.colony.buildings.views.LivingBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView)

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