use of com.ldtteam.blockout.views.ScrollingList in project minecolonies by Minecolonies.
the class WindowBuildBuilding method updateResourceList.
public void updateResourceList() {
final ScrollingList recourseList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
recourseList.enable();
recourseList.show();
final List<ItemStorage> tempRes = new ArrayList<>(resources.values());
// Creates a dataProvider for the unemployed recourseList.
recourseList.setDataProvider(new ScrollingList.DataProvider() {
/**
* The number of rows of the list.
* @return the number.
*/
@Override
public int getElementCount() {
return tempRes.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) {
final ItemStorage resource = tempRes.get(index);
final Text resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Text.class);
final Text quantityLabel = rowPane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class);
resourceLabel.setText(resource.getItemStack().getHoverName());
quantityLabel.setText(Integer.toString(resource.getAmount()));
resourceLabel.setColors(WHITE);
quantityLabel.setColors(WHITE);
final ItemStack itemIcon = new ItemStack(resource.getItem(), 1);
itemIcon.setTag(resource.getItemStack().getTag());
rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(itemIcon);
}
});
}
use of com.ldtteam.blockout.views.ScrollingList in project minecolonies by Minecolonies.
the class WindowInfoPage method createAndSetStatistics.
/**
* Creates several statistics and sets them in the building GUI.
*/
private void createAndSetStatistics() {
final DecimalFormat df = new DecimalFormat("#.#");
df.setRoundingMode(RoundingMode.CEILING);
final String roundedHappiness = df.format(building.getColony().getOverallHappiness());
findPaneOfTypeByID(HAPPINESS_LABEL, Text.class).setText(roundedHappiness);
final int citizensSize = building.getColony().getCitizens().size();
final int citizensCap;
if (MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().hasResearchEffect(CITIZEN_CAP)) {
citizensCap = (int) (Math.min(MineColonies.getConfig().getServer().maxCitizenPerColony.get(), 25 + this.building.getColony().getResearchManager().getResearchEffects().getEffectStrength(CITIZEN_CAP)));
} else {
citizensCap = MineColonies.getConfig().getServer().maxCitizenPerColony.get();
}
final Text totalCitizenLabel = findPaneOfTypeByID(TOTAL_CITIZENS_LABEL, Text.class);
totalCitizenLabel.setText(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_TOTALCITIZENS_COUNT, citizensSize, Math.max(citizensSize, building.getColony().getCitizenCountLimit())));
List<IFormattableTextComponent> hoverText = new ArrayList<>();
if (citizensSize < (citizensCap * 0.9) && citizensSize < (building.getColony().getCitizenCountLimit() * 0.9)) {
totalCitizenLabel.setColors(DARKGREEN);
} else if (citizensSize < citizensCap) {
hoverText.add(new TranslationTextComponent("com.minecolonies.coremod.gui.townhall.population.totalcitizens.houselimited", this.building.getColony().getName()));
totalCitizenLabel.setColors(ORANGE);
} else {
if (citizensCap < MineColonies.getConfig().getServer().maxCitizenPerColony.get()) {
hoverText.add(new TranslationTextComponent("com.minecolonies.coremod.gui.townhall.population.totalcitizens.researchlimited", this.building.getColony().getName()));
} else {
hoverText.add(new TranslationTextComponent("com.minecolonies.coremod.gui.townhall.population.totalcitizens.configlimited", this.building.getColony().getName()));
}
totalCitizenLabel.setText(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_TOTALCITIZENS_COUNT, citizensSize, citizensCap));
totalCitizenLabel.setColors(RED);
}
PaneBuilders.tooltipBuilder().hoverPane(totalCitizenLabel).build().setText(hoverText);
int children = 0;
final Map<String, Tuple<Integer, Integer>> jobMaxCountMap = new HashMap<>();
for (@NotNull final IBuildingView building : building.getColony().getBuildings()) {
if (building instanceof AbstractBuildingView) {
for (final WorkerBuildingModuleView module : building.getModuleViews(WorkerBuildingModuleView.class)) {
int max = module.getMaxInhabitants();
int workers = module.getAssignedCitizens().size();
final String jobName = module.getJobDisplayName().toLowerCase(Locale.ENGLISH);
final Tuple<Integer, Integer> tuple = jobMaxCountMap.getOrDefault(jobName, new Tuple<>(0, 0));
jobMaxCountMap.put(jobName, new Tuple<>(tuple.getA() + workers, tuple.getB() + max));
}
}
}
// calculate number of children
int unemployedCount = 0;
for (ICitizenDataView iCitizenDataView : building.getColony().getCitizens().values()) {
if (iCitizenDataView.isChild()) {
children++;
} else if (iCitizenDataView.getJobView() == null) {
unemployedCount++;
}
}
final String numberOfUnemployed = LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_UNEMPLOYED, unemployedCount);
final String numberOfKids = LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_CHILDS, children);
final ScrollingList list = findPaneOfTypeByID("citizen-stats", ScrollingList.class);
if (list == null) {
return;
}
final int maxJobs = jobMaxCountMap.size();
final List<Map.Entry<String, Tuple<Integer, Integer>>> theList = new ArrayList<>(jobMaxCountMap.entrySet());
list.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return maxJobs + 2;
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final Text label = rowPane.findPaneOfTypeByID(CITIZENS_AMOUNT_LABEL, Text.class);
if (index < theList.size()) {
final Map.Entry<String, Tuple<Integer, Integer>> entry = theList.get(index);
final String job = LanguageHandler.format(entry.getKey());
final String numberOfWorkers = LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_EACH, job, entry.getValue().getA(), entry.getValue().getB());
label.setText(numberOfWorkers);
} else {
if (index == maxJobs + 1) {
label.setText(numberOfUnemployed);
} else {
label.setText(numberOfKids);
}
}
}
});
}
use of com.ldtteam.blockout.views.ScrollingList in project minecolonies by Minecolonies.
the class WindowBuilderResModule method onOpened.
@Override
public void onOpened() {
super.onOpened();
pullResourcesFromHut();
final ScrollingList resourceList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
resourceList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return resources.size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
updateResourcePane(index, rowPane);
}
});
// Make sure we have a fresh view
Network.getNetwork().sendToServer(new MarkBuildingDirtyMessage(this.buildingView));
findPaneOfTypeByID(LABEL_CONSTRUCTION_NAME, Text.class).setText(moduleView.getConstructionName());
findPaneOfTypeByID(STEP_PROGRESS, Text.class).setText(new TranslationTextComponent("com.minecolonies.coremod.gui.progress.step", moduleView.getCurrentStage(), moduleView.getTotalStages()));
}
use of com.ldtteam.blockout.views.ScrollingList in project minecolonies by Minecolonies.
the class GraveyardManagementWindow method onOpened.
@Override
public void onOpened() {
super.onOpened();
/*
* ScrollList with the graves.
*/
final ScrollingList graveList = findPaneOfTypeByID(LIST_GRAVES, ScrollingList.class);
graveList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return moduleView.getGraves().size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final BlockPos grave = moduleView.getGraves().get(index);
@NotNull final String distance = Integer.toString((int) Math.sqrt(BlockPosUtil.getDistanceSquared(grave, buildingView.getPosition())));
final String direction = BlockPosUtil.calcDirection(buildingView.getPosition(), grave);
final TileEntity entity = world.getBlockEntity(grave);
if (entity instanceof TileEntityGrave) {
rowPane.findPaneOfTypeByID(TAG_NAME, Text.class).setText("Grave of " + ((((TileEntityGrave) entity).getGraveData() != null) ? ((TileEntityGrave) entity).getGraveData().getCitizenName() : "Unknown Citizen"));
rowPane.findPaneOfTypeByID(TAG_DISTANCE, Text.class).setText(distance + "m");
rowPane.findPaneOfTypeByID(TAG_DIRECTION, Text.class).setText(direction);
}
}
});
/*
* ScrollList with the resting citizen.
*/
final ScrollingList ripList = findPaneOfTypeByID(LIST_CITIZEN, ScrollingList.class);
ripList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return moduleView.getRestingCitizen().size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final String citizenName = moduleView.getRestingCitizen().get(index);
rowPane.findPaneOfTypeByID(TAG_CITIZEN_NAME, Text.class).setText(citizenName);
}
});
}
use of com.ldtteam.blockout.views.ScrollingList in project minecolonies by Minecolonies.
the class SpecialAssignmentModuleWindow method onOpened.
@Override
public void onOpened() {
super.onOpened();
final List<Tuple<String, Integer>> workers = new ArrayList<>();
for (final IAssignmentModuleView module : buildingView.getModuleViews(IAssignmentModuleView.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 = buildingView.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());
}
}
});
}
}
Aggregations