Search in sources :

Example 1 with Box

use of com.ldtteam.blockout.views.Box in project minecolonies by Minecolonies.

the class RecruitmentInteraction method onWindowOpened.

@Override
@OnlyIn(Dist.CLIENT)
public void onWindowOpened(final Window window, final ICitizenDataView dataView) {
    final ButtonImage recruitButton = window.findPaneOfTypeByID(BUTTON_RESPONSE_ID + 2, ButtonImage.class);
    final Box group = window.findPaneOfTypeByID(RESPONSE_BOX_ID, Box.class);
    if (recruitButton != null && dataView instanceof IVisitorViewData) {
        final ItemStack recruitCost = ((IVisitorViewData) dataView).getRecruitCost();
        final IColonyView colony = ((IVisitorViewData) dataView).getColonyView();
        window.findPaneOfTypeByID(CHAT_LABEL_ID, Text.class).setText(PaneBuilders.textBuilder().append(new StringTextComponent(dataView.getName() + ": ")).append(this.getInquiry()).emptyLines(1).append(new TranslationTextComponent(colony.getCitizens().size() < colony.getCitizenCountLimit() ? "com.minecolonies.coremod.gui.chat.recruitcost" : "com.minecolonies.coremod.gui.chat.nospacerecruit", dataView.getName().split(" ")[0], recruitCost.getCount() + " " + recruitCost.getHoverName().getString())).getText());
        int iconPosX = recruitButton.getX() + recruitButton.getWidth() - 28;
        int iconPosY = recruitButton.getY() + recruitButton.getHeight() - 18;
        ItemIcon icon = new ItemIcon();
        icon.setID(RECRUITMENT_ICON);
        icon.setSize(15, 15);
        group.addChild(icon);
        icon.setItem(((IVisitorViewData) dataView).getRecruitCost());
        icon.setPosition(iconPosX, iconPosY);
        icon.setVisible(true);
    }
}
Also used : ButtonImage(com.ldtteam.blockout.controls.ButtonImage) ItemIcon(com.ldtteam.blockout.controls.ItemIcon) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Box(com.ldtteam.blockout.views.Box) Text(com.ldtteam.blockout.controls.Text) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 2 with Box

use of com.ldtteam.blockout.views.Box 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();
    }
}
Also used : Box(com.ldtteam.blockout.views.Box) ItemStack(net.minecraft.item.ItemStack) IColonyView(com.minecolonies.api.colony.IColonyView) Pane(com.ldtteam.blockout.Pane) RequestWindowCitizen(com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen)

Example 3 with Box

use of com.ldtteam.blockout.views.Box in project minecolonies by Minecolonies.

the class WindowInteraction method setupInteraction.

/**
 * Setup the current interaction.
 */
private void setupInteraction() {
    if (currentInteraction >= interactions.size()) {
        close();
        return;
    }
    final IInteractionResponseHandler handler = interactions.get(currentInteraction);
    final Box group = findPaneOfTypeByID(RESPONSE_BOX_ID, Box.class);
    int y = 0;
    int x = 0;
    final Text chatText = findPaneOfTypeByID(CHAT_LABEL_ID, Text.class);
    chatText.setTextAlignment(Alignment.TOP_LEFT);
    chatText.setAlignment(Alignment.TOP_LEFT);
    chatText.setText(citizen.getName() + ": " + handler.getInquiry().getString());
    int responseIndex = 1;
    for (final ITextComponent component : handler.getPossibleResponses()) {
        final ButtonImage button = new ButtonImage();
        button.setImage(new ResourceLocation(Constants.MOD_ID, MEDIUM_SIZED_BUTTON_RES));
        button.setSize(BUTTON_LENGTH, BUTTON_HEIGHT);
        button.setColors(SLIGHTLY_BLUE);
        button.setPosition(x, y);
        button.setID(BUTTON_RESPONSE_ID + responseIndex);
        button.setTextRenderBox(BUTTON_LENGTH, BUTTON_HEIGHT);
        button.setTextAlignment(Alignment.MIDDLE);
        button.setText(component);
        group.addChild(button);
        y += button.getHeight();
        if (y + button.getHeight() >= group.getHeight()) {
            y = 0;
            x += BUTTON_HEIGHT + BUTTON_BUFFER + button.getWidth();
        }
        responseIndex++;
    }
    handler.onWindowOpened(this, citizen);
}
Also used : IInteractionResponseHandler(com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler) ResourceLocation(net.minecraft.util.ResourceLocation) ITextComponent(net.minecraft.util.text.ITextComponent) ButtonImage(com.ldtteam.blockout.controls.ButtonImage) Box(com.ldtteam.blockout.views.Box) Text(com.ldtteam.blockout.controls.Text)

Example 4 with Box

use of com.ldtteam.blockout.views.Box in project minecolonies by ldtteam.

the class WindowInteraction method setupInteraction.

/**
 * Setup the current interaction.
 */
private void setupInteraction() {
    if (currentInteraction >= interactions.size()) {
        close();
        return;
    }
    final IInteractionResponseHandler handler = interactions.get(currentInteraction);
    final Box group = findPaneOfTypeByID(RESPONSE_BOX_ID, Box.class);
    int y = 0;
    int x = 0;
    final Text chatText = findPaneOfTypeByID(CHAT_LABEL_ID, Text.class);
    chatText.setTextAlignment(Alignment.TOP_LEFT);
    chatText.setAlignment(Alignment.TOP_LEFT);
    chatText.setText(citizen.getName() + ": " + handler.getInquiry().getString());
    int responseIndex = 1;
    for (final ITextComponent component : handler.getPossibleResponses()) {
        final ButtonImage button = new ButtonImage();
        button.setImage(new ResourceLocation(Constants.MOD_ID, MEDIUM_SIZED_BUTTON_RES));
        button.setSize(BUTTON_LENGTH, BUTTON_HEIGHT);
        button.setColors(SLIGHTLY_BLUE);
        button.setPosition(x, y);
        button.setID(BUTTON_RESPONSE_ID + responseIndex);
        button.setTextRenderBox(BUTTON_LENGTH, BUTTON_HEIGHT);
        button.setTextAlignment(Alignment.MIDDLE);
        button.setText(component);
        group.addChild(button);
        y += button.getHeight();
        if (y + button.getHeight() >= group.getHeight()) {
            y = 0;
            x += BUTTON_HEIGHT + BUTTON_BUFFER + button.getWidth();
        }
        responseIndex++;
    }
    handler.onWindowOpened(this, citizen);
}
Also used : IInteractionResponseHandler(com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler) ResourceLocation(net.minecraft.util.ResourceLocation) ITextComponent(net.minecraft.util.text.ITextComponent) ButtonImage(com.ldtteam.blockout.controls.ButtonImage) Box(com.ldtteam.blockout.views.Box) Text(com.ldtteam.blockout.controls.Text)

Example 5 with Box

use of com.ldtteam.blockout.views.Box 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();
    }
}
Also used : Box(com.ldtteam.blockout.views.Box) ItemStack(net.minecraft.item.ItemStack) IColonyView(com.minecolonies.api.colony.IColonyView) Pane(com.ldtteam.blockout.Pane) RequestWindowCitizen(com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen)

Aggregations

Box (com.ldtteam.blockout.views.Box)6 ButtonImage (com.ldtteam.blockout.controls.ButtonImage)4 Text (com.ldtteam.blockout.controls.Text)4 ItemStack (net.minecraft.item.ItemStack)4 Pane (com.ldtteam.blockout.Pane)2 ItemIcon (com.ldtteam.blockout.controls.ItemIcon)2 IColonyView (com.minecolonies.api.colony.IColonyView)2 IInteractionResponseHandler (com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler)2 RequestWindowCitizen (com.minecolonies.coremod.client.gui.citizen.RequestWindowCitizen)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ITextComponent (net.minecraft.util.text.ITextComponent)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)2