use of com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen 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();
}
}
use of com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen in project minecolonies by Minecolonies.
the class WindowRequestDetail method onButtonClicked.
/**
* Called when any button has been clicked.
*
* @param button the clicked button.
*/
@Override
public void onButtonClicked(@NotNull final Button button) {
if (button.getID().equals(REQUEST_FULLFIL)) {
if (this.prevWindow instanceof RequestWindowCitizen) {
((RequestWindowCitizen) this.prevWindow).fulfill(request);
// because this isn't an AbstractWindowSkeleton, and we want to trigger an advancement...
Network.getNetwork().sendToServer(new ClickGuiButtonTriggerMessage(button.getID(), Constants.MOD_ID + CITIZEN_REQ_DETAIL_SUFFIX));
}
this.window.close();
} else if (button.getID().equals(REQUEST_CANCEL)) {
if (this.prevWindow instanceof RequestWindowCitizen) {
((RequestWindowCitizen) this.prevWindow).cancel(request);
}
this.window.close();
} else {
prevWindow.open();
}
}
use of com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen in project minecolonies by ldtteam.
the class RequestBasedInteraction method onClientResponseTriggered.
@Override
@OnlyIn(Dist.CLIENT)
public boolean onClientResponseTriggered(final ITextComponent response, final PlayerEntity player, final ICitizenDataView data, final Window window) {
if (response.equals(new TranslationTextComponent("com.minecolonies.coremod.gui.chat.fulfill"))) {
final IColony colony = IColonyManager.getInstance().getColonyView(data.getColonyId(), player.level.dimension());
if (colony != null) {
final IRequest<?> request = colony.getRequestManager().getRequestForToken(token);
if (request != null) {
final RequestWindowCitizen windowCitizen = new RequestWindowCitizen(data);
windowCitizen.open();
final WindowRequestDetail windowRequestDetail = new WindowRequestDetail(windowCitizen, request, data.getColonyId());
windowRequestDetail.open();
return false;
}
}
} else {
return super.onClientResponseTriggered(response, player, data, window);
}
return true;
}
use of com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen in project minecolonies by Minecolonies.
the class RequestBasedInteraction method onClientResponseTriggered.
@Override
@OnlyIn(Dist.CLIENT)
public boolean onClientResponseTriggered(final ITextComponent response, final PlayerEntity player, final ICitizenDataView data, final Window window) {
if (response.equals(new TranslationTextComponent("com.minecolonies.coremod.gui.chat.fulfill"))) {
final IColony colony = IColonyManager.getInstance().getColonyView(data.getColonyId(), player.level.dimension());
if (colony != null) {
final IRequest<?> request = colony.getRequestManager().getRequestForToken(token);
if (request != null) {
final RequestWindowCitizen windowCitizen = new RequestWindowCitizen(data);
windowCitizen.open();
final WindowRequestDetail windowRequestDetail = new WindowRequestDetail(windowCitizen, request, data.getColonyId());
windowRequestDetail.open();
return false;
}
}
} else {
return super.onClientResponseTriggered(response, player, data, window);
}
return true;
}
use of com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen 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();
}
}
Aggregations