use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.
the class WindowRequestDetail method onOpened.
/**
* Called when the GUI has been opened. Will fill the fields and lists.
*/
@Override
public void onOpened() {
final Box box = findPaneOfTypeByID(BOX_ID_REQUEST, Box.class);
final Text description = PaneBuilders.textBuilder().style(TextFormatting.getByCode('r')).style(TextFormatting.getByCode('0')).append(request.getLongDisplayString()).build();
description.setPosition(1, 1);
description.setSize(box.getWidth() - 2, AbstractTextElement.SIZE_FOR_UNLIMITED_ELEMENTS);
box.addChild(description);
box.setSize(box.getWidth(), description.getRenderedTextHeight() + 2);
description.setSize(box.getWidth() - 2, box.getHeight());
final Image logo = findPaneOfTypeByID(DELIVERY_IMAGE, Image.class);
final ItemIcon exampleStackDisplay = findPaneOfTypeByID(LIST_ELEMENT_ID_REQUEST_STACK, ItemIcon.class);
final List<ItemStack> displayStacks = request.getDisplayStacks();
final IColonyView colony = IColonyManager.getInstance().getColonyView(colonyId, Minecraft.getInstance().level.dimension());
if (!displayStacks.isEmpty()) {
exampleStackDisplay.setItem(displayStacks.get((lifeCount / LIFE_COUNT_DIVIDER) % displayStacks.size()));
} else if (!request.getDisplayIcon().equals(MISSING)) {
logo.setVisible(true);
logo.setImage(request.getDisplayIcon());
PaneBuilders.tooltipBuilder().hoverPane(logo).build().setText(request.getResolverToolTip(colony));
}
findPaneOfTypeByID(REQUESTER, Text.class).setText(request.getRequester().getRequesterDisplayName(colony.getRequestManager(), request));
findPaneOfTypeByID(LIST_ELEMENT_ID_REQUEST_LOCATION, Text.class).setText(request.getRequester().getLocation().toString());
if (colony == null) {
Log.getLogger().warn("---Colony Null in WindowRequestDetail---");
return;
}
try {
final IRequestResolver<?> resolver = colony.getRequestManager().getResolverForRequest(request.getId());
if (resolver == null) {
Log.getLogger().warn("---IRequestResolver Null in WindowRequestDetail---");
return;
}
findPaneOfTypeByID(RESOLVER, Text.class).setText("Resolver: " + resolver.getRequesterDisplayName(colony.getRequestManager(), request).getString());
} catch (@SuppressWarnings(EXCEPTION_HANDLERS_SHOULD_PRESERVE_THE_ORIGINAL_EXCEPTIONS) final IllegalArgumentException e) {
/*
* Do nothing we just need to know if it has a resolver or not.
*/
Log.getLogger().warn("---IRequestResolver Null in WindowRequestDetail---", e);
}
// Checks if fulfill button should be displayed
Pane fulfillButton = this.window.getChildren().stream().filter(pane -> pane.getID().equals(REQUEST_FULLFIL)).findFirst().get();
if ((this.prevWindow instanceof RequestWindowCitizen && !((RequestWindowCitizen) prevWindow).fulfillable(request)) || this.prevWindow instanceof WindowClipBoard) {
fulfillButton.hide();
}
// Checks if cancel button should be displayed
Pane cancelButton = this.window.getChildren().stream().filter(pane -> pane.getID().equals(REQUEST_CANCEL)).findFirst().get();
if (this.prevWindow instanceof RequestWindowCitizen && !((RequestWindowCitizen) prevWindow).cancellable(request)) {
cancelButton.hide();
}
}
use of com.ldtteam.blockout.Pane 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();
}
use of com.ldtteam.blockout.Pane 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.ldtteam.blockout.Pane 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.ldtteam.blockout.Pane in project minecolonies by ldtteam.
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