Search in sources :

Example 26 with ICitizenDataView

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

the class WindowAssignCitizen method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    updateCitizens();
    citizenList.enable();
    citizenList.show();
    // Creates a dataProvider for the homeless citizenList.
    citizenList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return citizens.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) {
            @NotNull final ICitizenDataView citizen = citizens.get(index);
            final Button done = rowPane.findPaneOfTypeByID(CITIZEN_DONE, Button.class);
            final BlockPos home = citizen.getHomeBuilding();
            final BlockPos work = citizen.getWorkBuilding();
            boolean assign = false;
            if (home != null && home.equals(building.getPosition())) {
                done.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonunassign"));
            } else {
                assign = true;
                done.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign"));
            }
            final Text citizenLabel = rowPane.findPaneOfTypeByID(CITIZEN_LABEL, Text.class);
            citizenLabel.setText(citizen.getName());
            if (assign) {
                citizenLabel.setColors(YELLOW);
            } else {
                citizenLabel.setColors(DARKGREEN);
            }
            String workString = "";
            double newDistance = 0;
            if (work != null) {
                newDistance = BlockPosUtil.getDistance2D(work, building.getPosition());
                workString = " " + new TranslationTextComponent("com.minecolonies.coremod.gui.home.new", newDistance).getString();
            }
            String homeString = new TranslationTextComponent("com.minecolonies.coremod.gui.home.homeless").getString();
            boolean better = false;
            boolean badCurrentLiving = true;
            if (home != null) {
                if (work != null) {
                    final double oldDistance = BlockPosUtil.getDistance2D(work, home);
                    homeString = new TranslationTextComponent("com.minecolonies.coremod.gui.home.currently", oldDistance).getString();
                    better = newDistance < oldDistance;
                    if (oldDistance < FAR_DISTANCE_THRESHOLD) {
                        badCurrentLiving = false;
                    }
                } else {
                    homeString = new TranslationTextComponent("com.minecolonies.coremod.gui.home.currently", home.getX(), home.getY(), home.getZ()).getString();
                }
            }
            final Text newLivingLabel = rowPane.findPaneOfTypeByID(CITIZEN_JOB, Text.class);
            if (citizen.getJobView() != null) {
                newLivingLabel.setText(new TranslationTextComponent(citizen.getJobView().getEntry().getTranslationKey()).getString() + ":" + workString);
                if (better) {
                    newLivingLabel.setColors(DARKGREEN);
                }
            }
            final Text currentLivingLabel = rowPane.findPaneOfTypeByID(CITIZEN_LIVING, Text.class);
            if (assign) {
                currentLivingLabel.setText(homeString);
                if (badCurrentLiving) {
                    currentLivingLabel.setColors(RED);
                }
            } else {
                currentLivingLabel.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.home.liveshere"));
            }
            if ((colony.isManualHousing() || building.getHiringMode() == HiringMode.MANUAL) && !(building.getHiringMode() == HiringMode.AUTO) && (!assign || building.getResidents().size() < building.getMax())) {
                done.enable();
            } else {
                done.disable();
            }
        }
    });
}
Also used : Button(com.ldtteam.blockout.controls.Button) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) Text(com.ldtteam.blockout.controls.Text) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 27 with ICitizenDataView

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

the class CitizenWindowUtils method createHappinessBar.

/**
 * Creates an Happiness bar according to the citizen maxHappiness and currentHappiness.
 *
 * @param citizen pointer to the citizen data view
 * @param window  pointer to the current window
 */
public static void createHappinessBar(final ICitizenDataView citizen, final AbstractWindowSkeleton window) {
    // Calculates how much percent of the next level has been completed.
    final double experienceRatio = (citizen.getHappiness() / HappinessConstants.MAX_HAPPINESS) * XP_BAR_WIDTH;
    window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS_BAR, View.class).setAlignment(Alignment.MIDDLE_RIGHT);
    window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS, Text.class).setText(Integer.toString((int) citizen.getHappiness()));
    @NotNull final Image xpBar = new Image();
    xpBar.setImage(Screen.GUI_ICONS_LOCATION, XP_BAR_ICON_COLUMN, HAPPINESS_BAR_EMPTY_ROW, XP_BAR_WIDTH, XP_HEIGHT, false);
    xpBar.setPosition(LEFT_BORDER_X, LEFT_BORDER_Y);
    @NotNull final Image xpBar2 = new Image();
    xpBar2.setImage(Screen.GUI_ICONS_LOCATION, XP_BAR_ICON_COLUMN_END, HAPPINESS_BAR_EMPTY_ROW, XP_BAR_ICON_COLUMN_END_WIDTH, XP_HEIGHT, false);
    xpBar2.setPosition(XP_BAR_ICON_END_OFFSET + LEFT_BORDER_X, LEFT_BORDER_Y);
    window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS_BAR, View.class).addChild(xpBar);
    window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS_BAR, View.class).addChild(xpBar2);
    if (experienceRatio > 0) {
        @NotNull final Image xpBarFull = new Image();
        xpBarFull.setImage(Screen.GUI_ICONS_LOCATION, XP_BAR_ICON_COLUMN, HAPPINESS_BAR_FULL_ROW, (int) experienceRatio, XP_HEIGHT, false);
        xpBarFull.setPosition(LEFT_BORDER_X, LEFT_BORDER_Y);
        window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS_BAR, View.class).addChild(xpBarFull);
    }
}
Also used : Text(com.ldtteam.blockout.controls.Text) 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 28 with ICitizenDataView

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

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);
    selectedModule.addCitizen(citizen);
    onOpened();
}
Also used : ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with ICitizenDataView

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

the class WindowHireWorker method fireClicked.

/**
 * Fire citizen clicked to fire a citizen.
 *
 * @param button the clicked button.
 */
private void fireClicked(@NotNull final Button button) {
    final int row = citizenList.getListElementIndexByPane(button);
    @NotNull final ICitizenDataView citizen = citizens.get(row);
    selectedModule.removeCitizen(citizen);
    onOpened();
}
Also used : ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with ICitizenDataView

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

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