Search in sources :

Example 1 with WorkOrderView

use of com.minecolonies.coremod.colony.WorkOrderView in project minecolonies by Minecolonies.

the class WindowTownHall 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 CitizenDataView citizen : citizens) {
                if (citizen.getId() == workOrder.getClaimedBy()) {
                    claimingCitizen = citizen.getName();
                    break;
                }
            }
            rowPane.findPaneOfTypeByID(WORK_LABEL, Label.class).setLabelText(workOrder.getValue());
            rowPane.findPaneOfTypeByID(ASSIGNEE_LABEL, Label.class).setLabelText(claimingCitizen);
            rowPane.findPaneOfTypeByID(HIDDEN_WORKORDER_ID, Label.class).setLabelText(Integer.toString(workOrder.getId()));
        }
    });
}
Also used : WorkOrderView(com.minecolonies.coremod.colony.WorkOrderView) TextComponentString(net.minecraft.util.text.TextComponentString) CitizenDataView(com.minecolonies.coremod.colony.CitizenDataView) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Pane(com.minecolonies.blockout.Pane)

Example 2 with WorkOrderView

use of com.minecolonies.coremod.colony.WorkOrderView in project minecolonies by Minecolonies.

the class WindowTownHall method updatePriority.

/**
 * On Button click update the priority.
 *
 * @param button the clicked button.
 */
private void updatePriority(@NotNull final Button button) {
    @NotNull final Label idLabel = (Label) button.getParent().getChildren().get(HIDDEN_ID_POSITION);
    final int id = Integer.parseInt(idLabel.getLabelText());
    final String buttonLabel = button.getID();
    for (int i = 0; i < workOrders.size(); i++) {
        final WorkOrderView workOrder = workOrders.get(i);
        if (workOrder.getId() == id) {
            if (buttonLabel.equals(BUTTON_UP) && i > 0) {
                workOrder.setPriority(workOrders.get(i - 1).getPriority() + 1);
                MineColonies.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);
                MineColonies.getNetwork().sendToServer(new WorkOrderChangeMessage(this.building, id, false, workOrder.getPriority()));
            }
            sortWorkOrders();
            window.findPaneOfTypeByID(LIST_WORKORDER, ScrollingList.class).refreshElementPanes();
            return;
        }
    }
}
Also used : WorkOrderView(com.minecolonies.coremod.colony.WorkOrderView) TextComponentString(net.minecraft.util.text.TextComponentString) NotNull(org.jetbrains.annotations.NotNull) ScrollingList(com.minecolonies.blockout.views.ScrollingList)

Aggregations

ScrollingList (com.minecolonies.blockout.views.ScrollingList)2 WorkOrderView (com.minecolonies.coremod.colony.WorkOrderView)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 Pane (com.minecolonies.blockout.Pane)1 CitizenDataView (com.minecolonies.coremod.colony.CitizenDataView)1 NotNull (org.jetbrains.annotations.NotNull)1