Search in sources :

Example 11 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.

the class WindowResourceList method onOpened.

@Override
public void onOpened() {
    final ClientPlayerEntity player = Minecraft.getInstance().player;
    if (this.builder == null) {
        player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.resourcescroll.nobuilder"), player.getUUID());
        close();
        return;
    }
    super.onOpened();
    pullResourcesFromHut();
    final ScrollingList resourceList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
    if (resourceList == null) {
        player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.resourcescroll.null"), player.getUUID());
        close();
        return;
    }
    resourceList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return resources.size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            updateResourcePane(index, rowPane);
        }
    });
    final BuildingResourcesModuleView moduleView = builder.getModuleView(BuildingResourcesModuleView.class);
    // Make sure we have a fresh view
    Network.getNetwork().sendToServer(new MarkBuildingDirtyMessage(builder));
    findPaneOfTypeByID(LABEL_WORKERNAME, Text.class).setText(builder.getWorkerName());
    findPaneOfTypeByID(LABEL_CONSTRUCTION_NAME, Text.class).setText(moduleView.getConstructionName());
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Text(com.ldtteam.blockout.controls.Text) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) BuildingResourcesModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.BuildingResourcesModuleView) MarkBuildingDirtyMessage(com.minecolonies.coremod.network.messages.server.colony.building.MarkBuildingDirtyMessage)

Example 12 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.

the class WindowBuildBuilding method updateResourceList.

public void updateResourceList() {
    final ScrollingList recourseList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
    recourseList.enable();
    recourseList.show();
    final List<ItemStorage> tempRes = new ArrayList<>(resources.values());
    // Creates a dataProvider for the unemployed recourseList.
    recourseList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return tempRes.size();
        }

        /**
         * Inserts the elements into each row.
         * @param index the index of the row/list element.
         * @param rowPane the parent Pane for the row, containing the elements to update.
         */
        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final ItemStorage resource = tempRes.get(index);
            final Text resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Text.class);
            final Text quantityLabel = rowPane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class);
            resourceLabel.setText(resource.getItemStack().getHoverName());
            quantityLabel.setText(Integer.toString(resource.getAmount()));
            resourceLabel.setColors(WHITE);
            quantityLabel.setColors(WHITE);
            final ItemStack itemIcon = new ItemStack(resource.getItem(), 1);
            itemIcon.setTag(resource.getItemStack().getTag());
            rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(itemIcon);
        }
    });
}
Also used : Text(com.ldtteam.blockout.controls.Text) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 13 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.

the class WindowHireWorker method onOpened.

/**
 * Called when the GUI has been opened. Will fill the fields and lists.
 */
@Override
public void onOpened() {
    updateCitizens();
    findPaneOfTypeByID(AUTO_HIRE_WARN, Text.class).off();
    citizenList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return citizens.size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            @NotNull final ICitizenDataView citizen = citizens.get(index);
            final Button isPaused = rowPane.findPaneOfTypeByID(BUTTON_PAUSE, Button.class);
            if (selectedModule.canAssign(citizen) && !selectedModule.isFull() && !selectedModule.getAssignedCitizens().contains(citizen.getId())) {
                rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).off();
                rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).on();
                isPaused.off();
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
            } else if ((selectedModule.isFull()) && !selectedModule.getAssignedCitizens().contains(citizen.getId())) {
                rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).off();
                rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).off();
                isPaused.off();
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
            } else {
                rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).off();
                rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).on();
                if ((!selectedModule.getColony().isManualHiring() && selectedModule.getHiringMode() == HiringMode.DEFAULT) || (selectedModule.getHiringMode() == HiringMode.AUTO)) {
                    rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).disable();
                    findPaneOfTypeByID(AUTO_HIRE_WARN, Text.class).on();
                }
                isPaused.on();
                isPaused.setText(LanguageHandler.format(citizen.isPaused() ? COM_MINECOLONIES_COREMOD_GUI_HIRE_UNPAUSE : COM_MINECOLONIES_COREMOD_GUI_HIRE_PAUSE));
            }
            if (citizen.isPaused()) {
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).on();
            } else {
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
            }
            final StringTextComponent intermString = new StringTextComponent(" ");
            final TextBuilder textBuilder = PaneBuilders.textBuilder();
            textBuilder.append(new StringTextComponent(""));
            int skillCount = citizen.getCitizenSkillHandler().getSkills().entrySet().size();
            final Skill primary = selectedModule instanceof WorkerBuildingModuleView ? ((WorkerBuildingModuleView) selectedModule).getPrimarySkill() : null;
            final Skill secondary = selectedModule instanceof WorkerBuildingModuleView ? ((WorkerBuildingModuleView) selectedModule).getSecondarySkill() : null;
            for (final Map.Entry<Skill, Tuple<Integer, Double>> entry : citizen.getCitizenSkillHandler().getSkills().entrySet()) {
                final String skillName = entry.getKey().name().toLowerCase(Locale.US);
                final int skillLevel = entry.getValue().getA();
                final Style skillStyle = createColor(primary, secondary, entry.getKey());
                textBuilder.append(new TranslationTextComponent("com.minecolonies.coremod.gui.citizen.skills." + skillName).setStyle(skillStyle));
                textBuilder.append(new StringTextComponent(": " + skillLevel).setStyle(skillStyle));
                if (--skillCount > 0) {
                    textBuilder.append(intermString);
                }
            }
            // finish the current line
            textBuilder.newLine();
            rowPane.findPaneOfTypeByID(CITIZEN_LABEL, Text.class).setText((citizen.getJob().isEmpty() ? "" : LanguageHandler.format(citizen.getJob()) + ": ") + citizen.getName());
            rowPane.findPaneOfTypeByID(ATTRIBUTES_LABEL, Text.class).setText(textBuilder.getText());
            final JobEntry entry = selectedModule.getJobEntry();
            PaneBuilders.tooltipBuilder().hoverPane(rowPane.findPaneOfTypeByID(ATTRIBUTES_LABEL, Text.class)).build().setText(new TranslationTextComponent(entry.getKey().toString() + ".skills.desc"));
        }
    });
    jobList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return moduleViews.size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final JobEntry entry = moduleViews.get(index).getJobEntry();
            final Button button = rowPane.findPaneOfTypeByID(BUTTON_JOB, Button.class);
            button.setText(new TranslationTextComponent(entry.getTranslationKey()));
            if (entry.equals(selectedModule.getJobEntry())) {
                button.disable();
            } else {
                button.enable();
            }
            PaneBuilders.tooltipBuilder().hoverPane(button).build().setText(new TranslationTextComponent(entry.getKey().toString() + ".job.desc"));
        }
    });
}
Also used : Text(com.ldtteam.blockout.controls.Text) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) Pane(com.ldtteam.blockout.Pane) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) Skill(com.minecolonies.api.entity.citizen.Skill) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) TextBuilder(com.ldtteam.blockout.controls.AbstractTextBuilder.TextBuilder) Button(com.ldtteam.blockout.controls.Button) Style(net.minecraft.util.text.Style) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Example 14 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.

the class WindowHutAllInventory method updateResourceList.

/**
 * Updates the resource list in the GUI with the info we need.
 */
private void updateResourceList() {
    stackList.enable();
    // Creates a dataProvider for the unemployed stackList.
    stackList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return allItems.size();
        }

        /**
         * Inserts the elements into each row.
         * @param index the index of the row/list element.
         * @param rowPane the parent Pane for the row, containing the elements to update.
         */
        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final ItemStorage resource = allItems.get(index);
            final Text resourceLabel = rowPane.findPaneOfTypeByID("ressourceStackName", Text.class);
            final String name = resource.getItemStack().getHoverName().getString();
            resourceLabel.setText(name.substring(0, Math.min(17, name.length())));
            final Text qtys = rowPane.findPaneOfTypeByID("quantities", Text.class);
            if (!Screen.hasShiftDown()) {
                qtys.setText(Utils.format(resource.getAmount()));
            } else {
                qtys.setText(Integer.toString(resource.getAmount()));
            }
            final Item imagesrc = resource.getItemStack().getItem();
            final ItemStack image = new ItemStack(imagesrc, 1);
            image.setTag(resource.getItemStack().getTag());
            rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(image);
        }
    });
}
Also used : Item(net.minecraft.item.Item) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 15 with Pane

use of com.ldtteam.blockout.Pane in project minecolonies by ldtteam.

the class GraveyardManagementWindow method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    /*
         * ScrollList with the graves.
         */
    final ScrollingList graveList = findPaneOfTypeByID(LIST_GRAVES, ScrollingList.class);
    graveList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return moduleView.getGraves().size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final BlockPos grave = moduleView.getGraves().get(index);
            @NotNull final String distance = Integer.toString((int) Math.sqrt(BlockPosUtil.getDistanceSquared(grave, buildingView.getPosition())));
            final String direction = BlockPosUtil.calcDirection(buildingView.getPosition(), grave);
            final TileEntity entity = world.getBlockEntity(grave);
            if (entity instanceof TileEntityGrave) {
                rowPane.findPaneOfTypeByID(TAG_NAME, Text.class).setText("Grave of " + ((((TileEntityGrave) entity).getGraveData() != null) ? ((TileEntityGrave) entity).getGraveData().getCitizenName() : "Unknown Citizen"));
                rowPane.findPaneOfTypeByID(TAG_DISTANCE, Text.class).setText(distance + "m");
                rowPane.findPaneOfTypeByID(TAG_DIRECTION, Text.class).setText(direction);
            }
        }
    });
    /*
         * ScrollList with the resting citizen.
         */
    final ScrollingList ripList = findPaneOfTypeByID(LIST_CITIZEN, ScrollingList.class);
    ripList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return moduleView.getRestingCitizen().size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final String citizenName = moduleView.getRestingCitizen().get(index);
            rowPane.findPaneOfTypeByID(TAG_CITIZEN_NAME, Text.class).setText(citizenName);
        }
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Aggregations

Pane (com.ldtteam.blockout.Pane)64 ScrollingList (com.ldtteam.blockout.views.ScrollingList)40 Text (com.ldtteam.blockout.controls.Text)26 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)25 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)20 ItemStack (net.minecraft.item.ItemStack)13 Button (com.ldtteam.blockout.controls.Button)10 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)10 NotNull (org.jetbrains.annotations.NotNull)9 WorkerBuildingModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView)8 ArrayList (java.util.ArrayList)8 ItemStorage (com.minecolonies.api.crafting.ItemStorage)6 Tuple (com.minecolonies.api.util.Tuple)6 BlockPos (net.minecraft.util.math.BlockPos)6 List (java.util.List)5 StringTextComponent (net.minecraft.util.text.StringTextComponent)5 Skill (com.minecolonies.api.entity.citizen.Skill)4 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)4 MarkBuildingDirtyMessage (com.minecolonies.coremod.network.messages.server.colony.building.MarkBuildingDirtyMessage)4 TileEntity (net.minecraft.tileentity.TileEntity)4