Search in sources :

Example 1 with IWorkOrderView

use of com.minecolonies.api.colony.workorders.IWorkOrderView in project minecolonies by Minecolonies.

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 IWorkOrderView 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;
                }
            }
            Text workOrderTextPanel = rowPane.findPaneOfTypeByID(WORK_LABEL, Text.class);
            PaneBuilders.tooltipBuilder().append(workOrder.getDisplayName()).hoverPane(workOrderTextPanel).build();
            workOrderTextPanel.setText(workOrder.getDisplayName());
            rowPane.findPaneOfTypeByID(ASSIGNEE_LABEL, Text.class).setText(new StringTextComponent(claimingCitizen));
            rowPane.findPaneOfTypeByID(HIDDEN_WORKORDER_ID, Text.class).setText(new StringTextComponent(Integer.toString(workOrder.getId())));
        }
    });
}
Also used : AbstractBuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingBuilderView) Button(com.ldtteam.blockout.controls.Button) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Text(com.ldtteam.blockout.controls.Text) StringTextComponent(net.minecraft.util.text.StringTextComponent) IWorkOrderView(com.minecolonies.api.colony.workorders.IWorkOrderView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 2 with IWorkOrderView

use of com.minecolonies.api.colony.workorders.IWorkOrderView in project minecolonies by Minecolonies.

the class WindowWorkOrderPage method updatePriority.

/**
 * On Button click update the priority.
 *
 * @param button the clicked button.
 */
private void updatePriority(@NotNull final Button button) {
    final int id = Integer.parseInt(button.getParent().findPaneOfTypeByID("hiddenId", Text.class).getTextAsString());
    final String buttonLabel = button.getID();
    for (int i = 0; i < workOrders.size(); i++) {
        final IWorkOrderView workOrder = workOrders.get(i);
        if (workOrder.getId() == id) {
            if (buttonLabel.equals(BUTTON_UP) && i > 0) {
                workOrder.setPriority(workOrders.get(i - 1).getPriority() + 1);
                Network.getNetwork().sendToServer(new WorkOrderChangeMessage(this.building, id, false, workOrder.getPriority()));
            } else if (buttonLabel.equals(BUTTON_DOWN) && i <= workOrders.size()) {
                workOrder.setPriority(workOrders.get(i + 1).getPriority() - 1);
                Network.getNetwork().sendToServer(new WorkOrderChangeMessage(this.building, id, false, workOrder.getPriority()));
            }
            sortWorkOrders();
            window.findPaneOfTypeByID(LIST_WORKORDER, ScrollingList.class).refreshElementPanes();
            return;
        }
    }
}
Also used : IWorkOrderView(com.minecolonies.api.colony.workorders.IWorkOrderView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) WorkOrderChangeMessage(com.minecolonies.coremod.network.messages.server.colony.WorkOrderChangeMessage)

Example 3 with IWorkOrderView

use of com.minecolonies.api.colony.workorders.IWorkOrderView in project minecolonies by Minecolonies.

the class MinerLevelManagementModuleView method deserialize.

@Override
public void deserialize(@NotNull final PacketBuffer buf) {
    current = buf.readInt();
    final int size = buf.readInt();
    levelsInfo = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        levelsInfo.add(i, new Tuple<>(buf.readInt(), buf.readInt()));
    }
    int woSize = buf.readInt();
    workOrders.clear();
    for (int i = 0; i < woSize; i++) {
        final IWorkOrderView woView = AbstractWorkOrder.createWorkOrderView(buf);
        if (woView instanceof WorkOrderMinerView) {
            workOrders.add((WorkOrderMinerView) woView);
        }
    }
}
Also used : IWorkOrderView(com.minecolonies.api.colony.workorders.IWorkOrderView) WorkOrderMinerView(com.minecolonies.coremod.colony.workorders.view.WorkOrderMinerView)

Example 4 with IWorkOrderView

use of com.minecolonies.api.colony.workorders.IWorkOrderView in project minecolonies by Minecolonies.

the class WorkOrderModuleWindow method updateAvailableWorkOrders.

/**
 * Updates the available work orders page.
 *
 * @param index   index in the list of resources.
 * @param rowPane The Pane to use to display the information.
 */
private void updateAvailableWorkOrders(final int index, @NotNull final Pane rowPane) {
    final IWorkOrderView order = workOrders.get(index);
    Text workOrderTextPanel = rowPane.findPaneOfTypeByID(WORK_ORDER_NAME, Text.class);
    PaneBuilders.tooltipBuilder().append(order.getDisplayName()).hoverPane(workOrderTextPanel).build();
    workOrderTextPanel.setText(order.getDisplayName());
    rowPane.findPaneOfTypeByID(WORK_ORDER_POS, Text.class).setText(new TranslationTextComponent("com.minecolonies.coremod.gui.blocks.distance", BlockPosUtil.getDistance2D(order.getLocation(), buildingView.getPosition())));
    if (order.getClaimedBy().equals(buildingView.getPosition())) {
        rowPane.findPaneOfTypeByID(WORK_ORDER_SELECT, ButtonImage.class).setText(new TranslationTextComponent("com.minecolonies.coremod.gui.builder.cancel"));
    } else if (manualMode) {
        rowPane.findPaneOfTypeByID(WORK_ORDER_SELECT, ButtonImage.class).setText(new TranslationTextComponent("com.minecolonies.coremod.gui.builder.select"));
    }
}
Also used : ButtonImage(com.ldtteam.blockout.controls.ButtonImage) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Text(com.ldtteam.blockout.controls.Text) IWorkOrderView(com.minecolonies.api.colony.workorders.IWorkOrderView)

Example 5 with IWorkOrderView

use of com.minecolonies.api.colony.workorders.IWorkOrderView in project minecolonies by Minecolonies.

the class WorkOrderModuleWindow method selectWorkOrder.

/**
 * On click select the clicked work order.
 *
 * @param button the clicked button.
 */
private void selectWorkOrder(@NotNull final Button button) {
    final int row = workOrdersList.getListElementIndexByPane(button);
    final IWorkOrderView view = workOrders.get(row);
    if (view.getClaimedBy().equals(buildingView.getPosition())) {
        view.setClaimedBy(buildingView.getPosition());
        Network.getNetwork().sendToServer(new WorkOrderChangeMessage(buildingView, view.getId(), true, 0));
    } else {
        Network.getNetwork().sendToServer(new BuilderSelectWorkOrderMessage(buildingView, view.getId()));
    }
}
Also used : BuilderSelectWorkOrderMessage(com.minecolonies.coremod.network.messages.server.colony.building.builder.BuilderSelectWorkOrderMessage) IWorkOrderView(com.minecolonies.api.colony.workorders.IWorkOrderView) WorkOrderChangeMessage(com.minecolonies.coremod.network.messages.server.colony.WorkOrderChangeMessage)

Aggregations

IWorkOrderView (com.minecolonies.api.colony.workorders.IWorkOrderView)6 Text (com.ldtteam.blockout.controls.Text)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 WorkOrderChangeMessage (com.minecolonies.coremod.network.messages.server.colony.WorkOrderChangeMessage)2 Pane (com.ldtteam.blockout.Pane)1 Button (com.ldtteam.blockout.controls.Button)1 ButtonImage (com.ldtteam.blockout.controls.ButtonImage)1 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)1 AbstractBuildingBuilderView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingBuilderView)1 WorkOrderMinerView (com.minecolonies.coremod.colony.workorders.view.WorkOrderMinerView)1 BuilderSelectWorkOrderMessage (com.minecolonies.coremod.network.messages.server.colony.building.builder.BuilderSelectWorkOrderMessage)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1 Nullable (org.jetbrains.annotations.Nullable)1