Search in sources :

Example 6 with WorkOrderView

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

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 WorkOrderView 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 : WorkOrderView(com.minecolonies.api.colony.workorders.WorkOrderView) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

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