Search in sources :

Example 11 with Text

use of com.ldtteam.blockout.controls.Text in project minecolonies by Minecolonies.

the class WindowBuilderResModule method updateResourcePane.

/**
 * Update one row pad with its resource informations.
 *
 * @param index   index in the list of resources.
 * @param rowPane The Pane to use to display the information.
 */
private void updateResourcePane(final int index, @NotNull final Pane rowPane) {
    final BuildingBuilderResource resource = resources.get(index);
    final Text resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Text.class);
    final Text resourceMissingLabel = rowPane.findPaneOfTypeByID(RESOURCE_MISSING, Text.class);
    final Text neededLabel = rowPane.findPaneOfTypeByID(RESOURCE_AVAILABLE_NEEDED, Text.class);
    final Button addButton = rowPane.findPaneOfTypeByID(RESOURCE_ADD, Button.class);
    switch(resource.getAvailabilityStatus()) {
        case DONT_HAVE:
            addButton.disable();
            resourceLabel.setColors(RED);
            resourceMissingLabel.setColors(RED);
            neededLabel.setColors(RED);
            break;
        case NEED_MORE:
            addButton.enable();
            resourceLabel.setColors(ORANGE);
            resourceMissingLabel.setColors(ORANGE);
            neededLabel.setColors(ORANGE);
            break;
        case HAVE_ENOUGH:
            addButton.enable();
            resourceLabel.setColors(DARKGREEN);
            resourceMissingLabel.setColors(DARKGREEN);
            neededLabel.setColors(DARKGREEN);
            break;
        case NOT_NEEDED:
        default:
            addButton.disable();
            resourceLabel.setColors(BLACK);
            resourceMissingLabel.setColors(BLACK);
            neededLabel.setColors(BLACK);
            break;
    }
    // position the addResource Button to the right
    final int buttonX = rowPane.getWidth() - addButton.getWidth() - (rowPane.getHeight() - addButton.getHeight()) / 2;
    final int buttonY = rowPane.getHeight() - addButton.getHeight() - 2;
    addButton.setPosition(buttonX, buttonY);
    resourceLabel.setText(resource.getName());
    final int missing = resource.getMissingFromPlayer();
    if (missing < 0) {
        resourceMissingLabel.setText(Integer.toString(missing));
    } else {
        resourceMissingLabel.clearText();
    }
    neededLabel.setText(resource.getAvailable() + " / " + resource.getAmount());
    rowPane.findPaneOfTypeByID(RESOURCE_ID, Text.class).setText(Integer.toString(index));
    rowPane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class).setText(Integer.toString(resource.getAmount() - resource.getAvailable()));
    final ItemStack stack = new ItemStack(resource.getItem(), 1);
    stack.setTag(resource.getItemStack().getTag());
    rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(stack);
}
Also used : Button(com.ldtteam.blockout.controls.Button) ItemIcon(com.ldtteam.blockout.controls.ItemIcon) Text(com.ldtteam.blockout.controls.Text) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack)

Example 12 with Text

use of com.ldtteam.blockout.controls.Text in project minecolonies by Minecolonies.

the class WindowHappinessPage method updateHappiness.

/**
 * Update the display for the happiness
 */
private void updateHappiness() {
    final Map<String, Double> happinessMap = new HashMap<>();
    for (final ICitizenDataView data : building.getColony().getCitizens().values()) {
        for (final String modifier : data.getHappinessHandler().getModifiers()) {
            happinessMap.put(modifier, happinessMap.getOrDefault(modifier, 0.0) + data.getHappinessHandler().getModifier(modifier).getFactor());
        }
    }
    final View pane = findPaneOfTypeByID("happinesspage", View.class);
    int yPos = 62;
    for (final Map.Entry<String, Double> entry : happinessMap.entrySet()) {
        final double value = entry.getValue() / building.getColony().getCitizenCount();
        final Image image = new Image();
        image.setSize(11, 11);
        image.setPosition(0, yPos);
        final Text label = new Text();
        label.setSize(136, 11);
        label.setPosition(25, yPos);
        label.setColors(BLACK);
        label.setText(new TranslationTextComponent(PARTIAL_HAPPINESS_MODIFIER_NAME + entry.getKey()));
        if (value > 1.0) {
            image.setImage(GREEN_ICON);
        } else if (value == 1) {
            image.setImage(BLUE_ICON);
        } else if (value > 0.75) {
            image.setImage(YELLOW_ICON);
        } else {
            image.setImage(RED_ICON);
        }
        pane.addChild(image);
        pane.addChild(label);
        PaneBuilders.tooltipBuilder().hoverPane(label).append(new TranslationTextComponent("com.minecolonies.coremod.gui.townhall.happiness.desc." + entry.getKey())).build();
        yPos += 12;
    }
}
Also used : HashMap(java.util.HashMap) Text(com.ldtteam.blockout.controls.Text) Image(com.ldtteam.blockout.controls.Image) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) View(com.ldtteam.blockout.views.View) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Text

use of com.ldtteam.blockout.controls.Text in project minecolonies by Minecolonies.

the class WindowInfoPage method createAndSetStatistics.

/**
 * Creates several statistics and sets them in the building GUI.
 */
private void createAndSetStatistics() {
    final DecimalFormat df = new DecimalFormat("#.#");
    df.setRoundingMode(RoundingMode.CEILING);
    final String roundedHappiness = df.format(building.getColony().getOverallHappiness());
    findPaneOfTypeByID(HAPPINESS_LABEL, Text.class).setText(roundedHappiness);
    final int citizensSize = building.getColony().getCitizens().size();
    final int citizensCap;
    if (MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().hasResearchEffect(CITIZEN_CAP)) {
        citizensCap = (int) (Math.min(MineColonies.getConfig().getServer().maxCitizenPerColony.get(), 25 + this.building.getColony().getResearchManager().getResearchEffects().getEffectStrength(CITIZEN_CAP)));
    } else {
        citizensCap = MineColonies.getConfig().getServer().maxCitizenPerColony.get();
    }
    final Text totalCitizenLabel = findPaneOfTypeByID(TOTAL_CITIZENS_LABEL, Text.class);
    totalCitizenLabel.setText(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_TOTALCITIZENS_COUNT, citizensSize, Math.max(citizensSize, building.getColony().getCitizenCountLimit())));
    List<IFormattableTextComponent> hoverText = new ArrayList<>();
    if (citizensSize < (citizensCap * 0.9) && citizensSize < (building.getColony().getCitizenCountLimit() * 0.9)) {
        totalCitizenLabel.setColors(DARKGREEN);
    } else if (citizensSize < citizensCap) {
        hoverText.add(new TranslationTextComponent(WARNING_POPULATION_NEEDS_HOUSING, this.building.getColony().getName()));
        totalCitizenLabel.setColors(ORANGE);
    } else {
        if (citizensCap < MineColonies.getConfig().getServer().maxCitizenPerColony.get()) {
            hoverText.add(new TranslationTextComponent(WARNING_POPULATION_RESEARCH_LIMITED, this.building.getColony().getName()));
        } else {
            hoverText.add(new TranslationTextComponent(WARNING_POPULATION_CONFIG_LIMITED, this.building.getColony().getName()));
        }
        totalCitizenLabel.setText(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_TOTALCITIZENS_COUNT, citizensSize, citizensCap));
        totalCitizenLabel.setColors(RED);
    }
    PaneBuilders.tooltipBuilder().hoverPane(totalCitizenLabel).build().setText(hoverText);
    int children = 0;
    final Map<String, Tuple<Integer, Integer>> jobMaxCountMap = new HashMap<>();
    for (@NotNull final IBuildingView building : building.getColony().getBuildings()) {
        if (building instanceof AbstractBuildingView) {
            for (final WorkerBuildingModuleView module : building.getModuleViews(WorkerBuildingModuleView.class)) {
                int max = module.getMaxInhabitants();
                int workers = module.getAssignedCitizens().size();
                final String jobName = module.getJobDisplayName().toLowerCase(Locale.ENGLISH);
                final Tuple<Integer, Integer> tuple = jobMaxCountMap.getOrDefault(jobName, new Tuple<>(0, 0));
                jobMaxCountMap.put(jobName, new Tuple<>(tuple.getA() + workers, tuple.getB() + max));
            }
        }
    }
    // calculate number of children
    int unemployedCount = 0;
    for (ICitizenDataView iCitizenDataView : building.getColony().getCitizens().values()) {
        if (iCitizenDataView.isChild()) {
            children++;
        } else if (iCitizenDataView.getJobView() == null) {
            unemployedCount++;
        }
    }
    final ITextComponent numberOfUnemployed = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_UNEMPLOYED, unemployedCount);
    final ITextComponent numberOfKids = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_CHILDS, children);
    final ScrollingList list = findPaneOfTypeByID("citizen-stats", ScrollingList.class);
    if (list == null) {
        return;
    }
    final int maxJobs = jobMaxCountMap.size();
    final List<Map.Entry<String, Tuple<Integer, Integer>>> theList = new ArrayList<>(jobMaxCountMap.entrySet());
    theList.sort(Map.Entry.comparingByKey());
    list.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return maxJobs + 2;
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final Text label = rowPane.findPaneOfTypeByID(CITIZENS_AMOUNT_LABEL, Text.class);
            if (index < theList.size()) {
                final Map.Entry<String, Tuple<Integer, Integer>> entry = theList.get(index);
                final ITextComponent job = new TranslationTextComponent(entry.getKey());
                final ITextComponent numberOfWorkers = new TranslationTextComponent(COM_MINECOLONIES_COREMOD_GUI_TOWNHALL_POPULATION_EACH, job, entry.getValue().getA(), entry.getValue().getB());
                label.setText(numberOfWorkers);
            } else {
                if (index == maxJobs + 1) {
                    label.setText(numberOfUnemployed);
                } else {
                    label.setText(numberOfKids);
                }
            }
        }
    });
}
Also used : DecimalFormat(java.text.DecimalFormat) ITextComponent(net.minecraft.util.text.ITextComponent) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) NotNull(org.jetbrains.annotations.NotNull) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) Text(com.ldtteam.blockout.controls.Text) Pane(com.ldtteam.blockout.Pane) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Tuple(com.minecolonies.api.util.Tuple)

Example 14 with Text

use of com.ldtteam.blockout.controls.Text 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())));
        }
    });
}
Also used : AbstractBuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingBuilderView) Button(com.ldtteam.blockout.controls.Button) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Text(com.ldtteam.blockout.controls.Text) StringTextComponent(net.minecraft.util.text.StringTextComponent) IWorkOrderView(com.minecolonies.api.colony.workorders.IWorkOrderView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 15 with Text

use of com.ldtteam.blockout.controls.Text in project minecolonies by Minecolonies.

the class WarehouseOptionsModuleWindow method updateResourcePane.

/**
 * Update one row pad with its resource informations.
 */
private void updateResourcePane() {
    final BuildingBuilderResource resource = new BuildingBuilderResource(new ItemStack(Blocks.EMERALD_BLOCK, 1), 1);
    final int amountToSet;
    final PlayerInventory inventory = this.mc.player.inventory;
    final boolean isCreative = this.mc.player.isCreative();
    if (isCreative) {
        amountToSet = resource.getAmount();
    } else {
        amountToSet = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), resource.getItem());
    }
    resource.setPlayerAmount(amountToSet);
    final Text resourceLabel = findPaneOfTypeByID(RESOURCE_NAME, Text.class);
    final Text resourceMissingLabel = findPaneOfTypeByID(RESOURCE_MISSING, Text.class);
    final Text neededLabel = findPaneOfTypeByID(RESOURCE_AVAILABLE_NEEDED, Text.class);
    final Button addButton = findPaneOfTypeByID(RESOURCE_ADD, Button.class);
    BuildingBuilderResource.RessourceAvailability availability = resource.getAvailabilityStatus();
    if (module.getStorageUpgradeLevel() >= BuildingWareHouse.MAX_STORAGE_UPGRADE || buildingView.getBuildingLevel() < buildingView.getBuildingMaxLevel() || lockUpgrade) {
        availability = BuildingBuilderResource.RessourceAvailability.NOT_NEEDED;
    }
    findPaneOfTypeByID(UPGRADE_PROGRESS_LABEL, Text.class).setText(new TranslationTextComponent(LABEL_X_OF_Z, module.getStorageUpgradeLevel(), BuildingWareHouse.MAX_STORAGE_UPGRADE));
    switch(availability) {
        case DONT_HAVE:
            addButton.disable();
            resourceLabel.setColors(RED);
            resourceMissingLabel.setColors(RED);
            neededLabel.setColors(RED);
            break;
        case NEED_MORE:
            addButton.enable();
            resourceLabel.setColors(RED);
            resourceMissingLabel.setColors(RED);
            neededLabel.setColors(RED);
            break;
        case HAVE_ENOUGH:
            addButton.enable();
            resourceLabel.setColors(DARKGREEN);
            resourceMissingLabel.setColors(DARKGREEN);
            neededLabel.setColors(DARKGREEN);
            break;
        case NOT_NEEDED:
        default:
            addButton.disable();
            resourceLabel.setColors(BLACK);
            resourceMissingLabel.setColors(BLACK);
            neededLabel.setColors(BLACK);
            if (buildingView.getBuildingLevel() < buildingView.getBuildingMaxLevel()) {
                resourceLabel.hide();
                resourceMissingLabel.hide();
                neededLabel.hide();
                addButton.setText(new StringTextComponent("X").setStyle(Style.EMPTY.withColor(TextFormatting.DARK_RED)));
                PaneBuilders.tooltipBuilder().append(new TranslationTextComponent("com.minecolonies.coremod.gui.warehouse.upgrade.disabled.1", buildingView.getBuildingMaxLevel())).appendNL(new TranslationTextComponent("com.minecolonies.coremod.gui.warehouse.upgrade.disabled.2", buildingView.getBuildingMaxLevel())).hoverPane(addButton).build();
            }
            break;
    }
    resourceLabel.setText(resource.getName());
    final int missing = resource.getMissingFromPlayer();
    if (missing < 0) {
        resourceMissingLabel.setText(Integer.toString(missing));
    } else {
        resourceMissingLabel.clearText();
    }
    neededLabel.setText(new StringTextComponent(resource.getAvailable() + " / " + resource.getAmount()));
    findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Text.class).setText(new StringTextComponent(Integer.toString(resource.getAmount() - resource.getAvailable())));
    if (buildingView.getBuildingLevel() >= buildingView.getBuildingMaxLevel()) {
        final ItemStack resourceStackOfOne = new ItemStack(resource.getItem(), 1);
        resourceStackOfOne.setTag(resource.getItemStack().getTag());
        findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(resourceStackOfOne);
    }
}
Also used : Button(com.ldtteam.blockout.controls.Button) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemIcon(com.ldtteam.blockout.controls.ItemIcon) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Text(com.ldtteam.blockout.controls.Text) StringTextComponent(net.minecraft.util.text.StringTextComponent) PlayerInventory(net.minecraft.entity.player.PlayerInventory) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Text (com.ldtteam.blockout.controls.Text)31 Pane (com.ldtteam.blockout.Pane)15 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)13 ItemStack (net.minecraft.item.ItemStack)12 ScrollingList (com.ldtteam.blockout.views.ScrollingList)11 Button (com.ldtteam.blockout.controls.Button)9 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)8 ItemIcon (com.ldtteam.blockout.controls.ItemIcon)6 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)6 StringTextComponent (net.minecraft.util.text.StringTextComponent)6 ButtonImage (com.ldtteam.blockout.controls.ButtonImage)5 Image (com.ldtteam.blockout.controls.Image)5 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)4 ItemStorage (com.minecolonies.api.crafting.ItemStorage)4 View (com.ldtteam.blockout.views.View)3 ITextComponent (net.minecraft.util.text.ITextComponent)3 NotNull (org.jetbrains.annotations.NotNull)3 Loader (com.ldtteam.blockout.Loader)2 TextField (com.ldtteam.blockout.controls.TextField)2 Box (com.ldtteam.blockout.views.Box)2