use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.
the class WindowBuilderResModule method transferItems.
/**
* On Button click transfert Items.
*
* @param button the clicked button.
*/
private void transferItems(@NotNull final Button button) {
final Pane pane = button.getParent();
button.disable();
final Text idLabel = pane.findPaneOfTypeByID(RESOURCE_ID, Text.class);
final int index = Integer.parseInt(idLabel.getTextAsString());
final BuildingBuilderResource res = resources.get(index);
if (res == null) {
Log.getLogger().warn("WindowHutBuilder.transferItems: Error - Could not find the resource.");
} else {
// The itemStack size should not be greater than itemStack.getMaxStackSize, We send 1 instead
// and use quantity for the size
@NotNull final ItemStack itemStack = res.getItemStack().copy();
itemStack.setCount(1);
final Text quantityLabel = pane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class);
final int quantity = Integer.parseInt(quantityLabel.getTextAsString());
final int needed = res.getAmount() - res.getAvailable();
res.setAvailable(Math.min(res.getAmount(), res.getAvailable() + res.getPlayerAmount()));
res.setPlayerAmount(Math.max(0, res.getPlayerAmount() - needed));
resources.sort(new BuildingBuilderResource.ResourceComparator());
Network.getNetwork().sendToServer(new TransferItemsRequestMessage(this.buildingView, itemStack, quantity, true));
}
}
use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.
the class WindowMineGuardModule method onOpened.
@Override
public void onOpened() {
super.onOpened();
guardsList = findPaneOfTypeByID(LIST_GUARDS, ScrollingList.class);
guardsList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return guardsInfo.size();
}
@Override
public void updateElement(final int i, final Pane pane) {
final ICitizenDataView citizen = guardsInfo.get(i);
if (citizen != null) {
final IBuildingView building = buildingView.getColony().getBuilding(citizen.getWorkBuilding());
if (building instanceof AbstractBuildingGuards.View) {
pane.findPaneOfTypeByID("guardName", Text.class).setText(citizen.getName());
final AbstractBuildingGuards.View guardbuilding = (AbstractBuildingGuards.View) building;
final Button button = pane.findPaneOfTypeByID("assignGuard", Button.class);
if (guardbuilding.getMinePos() == null) {
button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign"));
if (assignedGuards >= getMaxGuards()) {
button.setEnabled(false);
} else {
button.setEnabled(true);
}
} else if (guardbuilding.getMinePos().equals(buildingView.getPosition())) {
button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonunassign"));
} else {
button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign"));
button.setEnabled(false);
}
}
} else {
final Button button = pane.findPaneOfTypeByID("assignGuard", Button.class);
button.setEnabled(false);
}
}
});
}
use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.
the class WindowSettingsPage method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
final Pane pane = findPaneByID(DROPDOWN_TEXT_ID);
if (isFeatureUnlocked.get()) {
pane.enable();
} else {
pane.disable();
AbstractTextBuilder.TooltipBuilder hoverText = PaneBuilders.tooltipBuilder().hoverPane(pane);
hoverText.append(new TranslationTextComponent("com.minecolonies.core.townhall.patreon")).paragraphBreak();
hoverText.build();
}
}
use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.
the class WindowWorkOrderPage 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 IBuildingView buildingView : building.getColony().getBuildings()) {
if (buildingView.getPosition().equals(workOrder.getClaimedBy()) && buildingView instanceof AbstractBuildingBuilderView) {
claimingCitizen = ((AbstractBuildingBuilderView) buildingView).getWorkerName();
break;
}
}
rowPane.findPaneOfTypeByID(WORK_LABEL, Text.class).setText(workOrder.getDisplayName());
rowPane.findPaneOfTypeByID(ASSIGNEE_LABEL, Text.class).setText(claimingCitizen);
rowPane.findPaneOfTypeByID(HIDDEN_WORKORDER_ID, Text.class).setText(Integer.toString(workOrder.getId()));
}
});
}
use of com.ldtteam.blockout.Pane in project minecolonies by Minecolonies.
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();
}
}
Aggregations