use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by ldtteam.
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 ldtteam.
the class WindowAssignCitizen method hireClicked.
/**
* When assignment was clicked.
* @param button the clicked button.
*/
private void hireClicked(@NotNull final Button button) {
final int row = citizenList.getListElementIndexByPane(button);
final ICitizenDataView data = citizens.get(row);
final boolean isAssign = button.getText().getString().equals(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign").getString());
if (isAssign) {
if (building.getResidents().size() >= building.getMax()) {
return;
}
building.addResident(data.getId());
data.setHomeBuilding(building.getPosition());
} else {
building.removeResident(data.getId());
data.setHomeBuilding(null);
}
Network.getNetwork().sendToServer(new AssignUnassignMessage(this.building, isAssign, data.getId(), null));
updateCitizens();
citizenList.refreshElementPanes();
}
use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by ldtteam.
the class CitizenWindowUtils method createSaturationBar.
/**
* Creates an health bar according to the citizen maxHealth and currentHealth.
*
* @param citizen the citizen.
* @param view the view to add these to.
*/
public static void createSaturationBar(final ICitizenDataView citizen, final View view) {
view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).setAlignment(Alignment.MIDDLE_RIGHT);
// Max saturation (Black food items).
for (int i = 0; i < ICitizenData.MAX_SATURATION; i++) {
@NotNull final Image saturation = new Image();
saturation.setImage(Screen.GUI_ICONS_LOCATION, EMPTY_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
saturation.setPosition(getXOffsetModifier(i) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(i));
view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
}
// Current saturation (Full food hearts).
int saturationPos;
for (saturationPos = 0; saturationPos < ((int) citizen.getSaturation()); saturationPos++) {
@NotNull final Image saturation = new Image();
saturation.setImage(Screen.GUI_ICONS_LOCATION, FULL_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
saturation.setPosition(getXOffsetModifier(saturationPos) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(saturationPos));
view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
}
// Half food items.
if (citizen.getSaturation() / 2 % 1 > 0) {
@NotNull final Image saturation = new Image();
saturation.setImage(Screen.GUI_ICONS_LOCATION, HALF_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
saturation.setPosition(getXOffsetModifier(saturationPos) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(saturationPos));
view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
}
}
use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by ldtteam.
the class WindowHutCrafterTaskModule method onOpened.
@Override
public void onOpened() {
super.onOpened();
final List<IToken<?>> tasks = new ArrayList<>();
for (final WorkerBuildingModuleView moduleView : buildingView.getModuleViews(WorkerBuildingModuleView.class)) {
for (final int citizenId : moduleView.getAssignedCitizens()) {
ICitizenDataView citizen = buildingView.getColony().getCitizen(citizenId);
if (citizen != null) {
if (citizen.getJobView() instanceof CrafterJobView) {
tasks.addAll(((CrafterJobView) citizen.getJobView()).getDataStore().getQueue());
} else if (citizen.getJobView() instanceof DmanJobView) {
tasks.addAll(((DmanJobView) citizen.getJobView()).getDataStore().getQueue());
}
}
}
}
final ScrollingList deliveryList = findPaneOfTypeByID(LIST_TASKS, ScrollingList.class);
deliveryList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
tasks.removeIf(token -> buildingView.getColony().getRequestManager().getRequestForToken(token) == null);
return tasks.size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final IRequest<?> request = buildingView.getColony().getRequestManager().getRequestForToken(tasks.get(index));
final IRequest<?> parent = buildingView.getColony().getRequestManager().getRequestForToken(request.getParent());
if (parent != null) {
rowPane.findPaneOfTypeByID(REQUESTER, Text.class).setText(request.getRequester().getRequesterDisplayName(buildingView.getColony().getRequestManager(), request).getString() + " ->");
rowPane.findPaneOfTypeByID(PARENT, Text.class).setText(parent.getRequester().getRequesterDisplayName(buildingView.getColony().getRequestManager(), parent));
} else {
rowPane.findPaneOfTypeByID(REQUESTER, Text.class).setText(request.getRequester().getRequesterDisplayName(buildingView.getColony().getRequestManager(), request));
rowPane.findPaneOfTypeByID(PARENT, Text.class).clearText();
}
rowPane.findPaneOfTypeByID(REQUEST_SHORT_DETAIL, Text.class).setText(request.getShortDisplayString().getString().replace("§f", ""));
if (request.getRequest() instanceof IDeliverymanRequestable) {
rowPane.findPaneOfTypeByID(REQUEST_PRIORITY, Text.class).setText(LanguageHandler.format(COM_MINECOLONIES_COREMOD_ENTITY_DELIVERYMAN_PRIORITY) + ((IDeliverymanRequestable) (request.getRequest())).getPriority());
}
final Image logo = rowPane.findPaneOfTypeByID(DELIVERY_IMAGE, Image.class);
logo.setImage(request.getDisplayIcon());
}
});
}
use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by ldtteam.
the class WindowMineGuardModule method assignGuardClicked.
private void assignGuardClicked(final Button button) {
final int guardRow = guardsList.getListElementIndexByPane(button);
final ICitizenDataView guard = guardsInfo.get(guardRow);
if (guard != null) {
final AbstractBuildingGuards.View guardbuilding = (AbstractBuildingGuards.View) buildingView.getColony().getBuilding(guard.getWorkBuilding());
if (guardbuilding.getMinePos() == null) {
if (assignedGuards < getMaxGuards()) {
Network.getNetwork().sendToServer(new GuardSetMinePosMessage(guardbuilding, buildingView.getPosition()));
button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonunassign"));
guardbuilding.setMinePos(buildingView.getPosition());
assignedGuards++;
}
} else if (guardbuilding.getMinePos().equals(buildingView.getPosition())) {
Network.getNetwork().sendToServer(new GuardSetMinePosMessage(guardbuilding));
button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign"));
guardbuilding.setMinePos(null);
assignedGuards--;
}
}
pullGuardsFromHut();
}
Aggregations