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);
}
}
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");
}
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);
}
}
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()));
}
});
}
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());
}
});
}
Aggregations