Search in sources :

Example 1 with CitizenDataView

use of com.minecolonies.coremod.colony.CitizenDataView in project minecolonies by Minecolonies.

the class WindowTownHallTest method setUp.

@Before
public void setUp() {
    final String[] jobs = { "com.minecolonies.coremod.gui.townHall.population.deliverymen", "com.minecolonies.coremod.gui.townHall.population.miners", "com.minecolonies.coremod.gui.townHall.population.fishermen", "com.minecolonies.coremod.gui.townHall.population.guards", "com.minecolonies.coremod.gui.townHall.population.lumberjacks", "com.minecolonies.coremod.gui.townHall.population.farmers", "com.minecolonies.coremod.gui.townHall.population.bakers", "com.minecolonies.coremod.gui.townHall.population.builders", "com.minecolonies.coremod.gui.townHall.population.cooks" };
    for (int i = 0; i < jobs.length; i++) {
        final CitizenDataView citizen = mock(CitizenDataView.class);
        when(citizen.getId()).thenReturn(i);
        when(citizen.getJob()).thenReturn(jobs[i]);
        citizensMap.put(citizen.getId(), citizen);
        citizensArray.add(citizen);
    }
}
Also used : CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView) Before(org.junit.Before)

Example 2 with CitizenDataView

use of com.minecolonies.coremod.colony.CitizenDataView in project minecolonies by Minecolonies.

the class AbstractWindowWorkerBuilding method onOpened.

/**
 * Called when the GUI has been opened.
 */
@Override
public void onOpened() {
    super.onOpened();
    String workerName = "";
    String workerLevel = "";
    if (!building.getWorkerId().isEmpty()) {
        final CitizenDataView worker = building.getColony().getCitizen(building.getWorkerId().get(0));
        if (worker != null) {
            workerName = worker.getName();
            workerLevel = String.format("%d", worker.getLevel());
        }
    }
    findPaneOfTypeByID(BUTTON_HIRE, Button.class).setLabel(LanguageHandler.format("com.minecolonies.coremod.gui.workerHuts.hire"));
    findPaneOfTypeByID(LABEL_WORKERNAME, Label.class).setLabelText(workerName);
    findPaneOfTypeByID(LABEL_WORKERLEVEL, Label.class).setLabelText(LanguageHandler.format("com.minecolonies.coremod.gui.workerHuts.workerLevel", workerLevel));
    findPaneOfTypeByID(LABEL_BUILDINGTYPE, Label.class).setLabelText(building.getBuildingDmPrio() + "/10");
}
Also used : Button(com.minecolonies.blockout.controls.Button) Label(com.minecolonies.blockout.controls.Label) CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView)

Example 3 with CitizenDataView

use of com.minecolonies.coremod.colony.CitizenDataView in project minecolonies by Minecolonies.

the class WindowTownHall method createAndSetStatistics.

/**
 * Creates several statistics and sets them in the townHall GUI.
 */
private void createAndSetStatistics() {
    final int citizensSize = townHall.getColony().getCitizens().size();
    final Map<String, Integer> jobCountMap = new HashMap<>();
    for (@NotNull final CitizenDataView citizen : citizens) {
        final int length = citizen.getJob().split("\\.").length;
        final String job = citizen.getJob().split("\\.")[length - 1].toLowerCase(Locale.ENGLISH);
        jobCountMap.put(job, jobCountMap.get(job) == null ? 1 : (jobCountMap.get(job) + 1));
    }
    final String numberOfCitizens = LanguageHandler.format("com.minecolonies.coremod.gui.townHall.population.totalCitizens", citizensSize, townHall.getColony().getMaxCitizens());
    final DecimalFormat df = new DecimalFormat("#.#");
    df.setRoundingMode(RoundingMode.CEILING);
    final String roundedHappiness = df.format(building.getColony().getOverallHappiness());
    findPaneOfTypeByID(HAPPINESS_LABEL, Label.class).setLabelText(roundedHappiness);
    findPaneOfTypeByID(TOTAL_CITIZENS_LABEL, Label.class).setLabelText(numberOfCitizens);
    final Group group = findPaneOfTypeByID("citizen-stats", Group.class);
    if (group == null) {
        return;
    }
    final Integer unemployed = jobCountMap.get("") == null ? 0 : jobCountMap.get("");
    jobCountMap.remove("");
    final Label unemployedLabel = new Label();
    unemployedLabel.setSize(STATISTICS_LABEL_WIDTH, STATISTICS_LABEL_HEIGHT);
    unemployedLabel.setTextAlignment(Alignment.MIDDLE_LEFT);
    unemployedLabel.setColor(BLACK, BLACK);
    final String numberOfUnemployed = LanguageHandler.format("com.minecolonies.coremod.gui.townHall.population.unemployed", unemployed);
    unemployedLabel.setLabelText(numberOfUnemployed);
    group.addChild(unemployedLabel);
    for (final Map.Entry<String, Integer> entry : jobCountMap.entrySet()) {
        final Label workerLabel = new Label();
        workerLabel.setSize(STATISTICS_LABEL_WIDTH, STATISTICS_LABEL_HEIGHT);
        workerLabel.setTextAlignment(Alignment.MIDDLE_LEFT);
        workerLabel.setColor(BLACK, BLACK);
        final String job = entry.getKey();
        final String labelJobKey = job.endsWith("man") ? job.replace("man", "men") : (job + "s");
        final String numberOfWorkers = LanguageHandler.format("com.minecolonies.coremod.gui.townHall.population." + labelJobKey, entry.getValue());
        workerLabel.setLabelText(numberOfWorkers);
        group.addChild(workerLabel);
    }
}
Also used : Group(com.minecolonies.blockout.views.Group) DecimalFormat(java.text.DecimalFormat) TextComponentString(net.minecraft.util.text.TextComponentString) CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with CitizenDataView

use of com.minecolonies.coremod.colony.CitizenDataView in project minecolonies by Minecolonies.

the class WindowTownHall 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 CitizenDataView citizen : citizens) {
                if (citizen.getId() == workOrder.getClaimedBy()) {
                    claimingCitizen = citizen.getName();
                    break;
                }
            }
            rowPane.findPaneOfTypeByID(WORK_LABEL, Label.class).setLabelText(workOrder.getValue());
            rowPane.findPaneOfTypeByID(ASSIGNEE_LABEL, Label.class).setLabelText(claimingCitizen);
            rowPane.findPaneOfTypeByID(HIDDEN_WORKORDER_ID, Label.class).setLabelText(Integer.toString(workOrder.getId()));
        }
    });
}
Also used : WorkOrderView(com.minecolonies.coremod.colony.WorkOrderView) TextComponentString(net.minecraft.util.text.TextComponentString) CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Pane(com.minecolonies.blockout.Pane)

Example 5 with CitizenDataView

use of com.minecolonies.coremod.colony.CitizenDataView in project minecolonies by Minecolonies.

the class WindowTownHall method fillCitizensList.

/**
 * Fills the citizens list in the GUI.
 */
private void fillCitizensList() {
    final ScrollingList citizenList = findPaneOfTypeByID(LIST_CITIZENS, ScrollingList.class);
    citizenList.setDataProvider(new ScrollingList.DataProvider() {

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

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final CitizenDataView citizen = citizens.get(index);
            rowPane.findPaneOfTypeByID(NAME_LABEL, Label.class).setLabelText(citizen.getName());
        }
    });
}
Also used : CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Pane(com.minecolonies.blockout.Pane)

Aggregations

CitizenDataView (com.minecolonies.coremod.colony.CitizenDataView)8 Pane (com.minecolonies.blockout.Pane)3 ScrollingList (com.minecolonies.blockout.views.ScrollingList)3 ColonyView (com.minecolonies.coremod.colony.ColonyView)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 Button (com.minecolonies.blockout.controls.Button)1 Label (com.minecolonies.blockout.controls.Label)1 Group (com.minecolonies.blockout.views.Group)1 WorkOrderView (com.minecolonies.coremod.colony.WorkOrderView)1 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 AbstractEntityAIStructure (com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure)1 AssignUnassignMessage (com.minecolonies.coremod.network.messages.AssignUnassignMessage)1 Structure (com.minecolonies.structures.helpers.Structure)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 BlockPos (net.minecraft.util.math.BlockPos)1