Search in sources :

Example 1 with Group

use of com.minecolonies.blockout.views.Group in project minecolonies by Minecolonies.

the class WindowTownHallTest method testJobs.

@Test
public void testJobs() throws Exception {
    final WindowTownHall windowTownHall = mock(WindowTownHall.class);
    when(colony.getCitizens()).thenReturn(Collections.unmodifiableMap(citizensMap));
    when(colony.getMaxCitizens()).thenReturn(4);
    when(townHall.getColony()).thenReturn(colony);
    when(building.getColony()).thenReturn(colony);
    when(windowTownHall.findPaneOfTypeByID("happiness", Label.class)).thenReturn(new Label());
    when(windowTownHall.findPaneOfTypeByID("totalCitizens", Label.class)).thenReturn(new Label());
    when(windowTownHall.findPaneOfTypeByID("citizen-stats", Group.class)).thenReturn(new Group());
    Whitebox.setInternalState(windowTownHall, "townHall", townHall);
    Whitebox.setInternalState(windowTownHall, "citizens", citizensArray);
    Whitebox.setInternalState(windowTownHall, "building", building);
    Whitebox.setInternalState(windowTownHall, "townHall", townHall);
    Whitebox.invokeMethod(windowTownHall, "createAndSetStatistics");
    assertEquals(1L, citizensMap.get(1).getId());
    verify(windowTownHall, times(1)).findPaneOfTypeByID("citizen-stats", Group.class);
}
Also used : Group(com.minecolonies.blockout.views.Group) Label(com.minecolonies.blockout.controls.Label) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with Group

use of com.minecolonies.blockout.views.Group 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)

Aggregations

Group (com.minecolonies.blockout.views.Group)2 Label (com.minecolonies.blockout.controls.Label)1 CitizenDataView (com.minecolonies.coremod.colony.CitizenDataView)1 DecimalFormat (java.text.DecimalFormat)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1