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