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())));
}
});
}
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;
}
}
}
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);
}
}
}
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"));
}
}
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()));
}
}
Aggregations