Search in sources :

Example 1 with WorkOrderView

use of com.minecolonies.api.colony.workorders.WorkOrderView in project minecolonies by ldtteam.

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 WorkOrderView view = new WorkOrderView();
        view.deserialize(buf);
        workOrders.add(view);
    }
}
Also used : WorkOrderView(com.minecolonies.api.colony.workorders.WorkOrderView)

Example 2 with WorkOrderView

use of com.minecolonies.api.colony.workorders.WorkOrderView in project minecolonies by ldtteam.

the class ColonyView method handleColonyViewWorkOrderMessage.

/**
 * Update a ColonyView's workOrders given a network data ColonyView update packet. This uses a full-replacement - workOrders do not get updated and are instead overwritten.
 *
 * @param buf Network data.
 * @return null == no response.
 */
@Override
@Nullable
public IMessage handleColonyViewWorkOrderMessage(final PacketBuffer buf) {
    workOrders.clear();
    final int amount = buf.readInt();
    for (int i = 0; i < amount; i++) {
        @Nullable final WorkOrderView workOrder = AbstractWorkOrder.createWorkOrderView(buf);
        if (workOrder != null) {
            workOrders.put(workOrder.getId(), workOrder);
        }
    }
    return null;
}
Also used : WorkOrderView(com.minecolonies.api.colony.workorders.WorkOrderView) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with WorkOrderView

use of com.minecolonies.api.colony.workorders.WorkOrderView 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()));
        }
    });
}
Also used : WorkOrderView(com.minecolonies.api.colony.workorders.WorkOrderView) AbstractBuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingBuilderView) Button(com.ldtteam.blockout.controls.Button) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 4 with WorkOrderView

use of com.minecolonies.api.colony.workorders.WorkOrderView in project minecolonies by ldtteam.

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 WorkOrderView 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 : WorkOrderView(com.minecolonies.api.colony.workorders.WorkOrderView) BuilderSelectWorkOrderMessage(com.minecolonies.coremod.network.messages.server.colony.building.builder.BuilderSelectWorkOrderMessage) WorkOrderChangeMessage(com.minecolonies.coremod.network.messages.server.colony.WorkOrderChangeMessage)

Example 5 with WorkOrderView

use of com.minecolonies.api.colony.workorders.WorkOrderView in project minecolonies by ldtteam.

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 WorkOrderView order = workOrders.get(index);
    rowPane.findPaneOfTypeByID(WORK_ORDER_NAME, Text.class).setText(order.getDisplayName());
    rowPane.findPaneOfTypeByID(WORK_ORDER_POS, Text.class).setText(new TranslationTextComponent("com.minecolonies.coremod.gui.blocks.distance", BlockPosUtil.getDistance2D(order.getPos(), 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 : WorkOrderView(com.minecolonies.api.colony.workorders.WorkOrderView) ButtonImage(com.ldtteam.blockout.controls.ButtonImage) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Text(com.ldtteam.blockout.controls.Text)

Aggregations

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