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