Search in sources :

Example 1 with View

use of com.ldtteam.blockout.views.View in project minecolonies by Minecolonies.

the class CitizenWindowUtils method createSaturationBar.

/**
 * Creates an health bar according to the citizen maxHealth and currentHealth.
 *
 * @param citizen the citizen.
 * @param view    the view to add these to.
 */
public static void createSaturationBar(final ICitizenDataView citizen, final View view) {
    view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).setAlignment(Alignment.MIDDLE_RIGHT);
    // Max saturation (Black food items).
    for (int i = 0; i < ICitizenData.MAX_SATURATION; i++) {
        @NotNull final Image saturation = new Image();
        saturation.setImage(Screen.GUI_ICONS_LOCATION, EMPTY_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
        saturation.setPosition(getXOffsetModifier(i) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(i));
        view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
    }
    // Current saturation (Full food hearts).
    int saturationPos;
    for (saturationPos = 0; saturationPos < ((int) citizen.getSaturation()); saturationPos++) {
        @NotNull final Image saturation = new Image();
        saturation.setImage(Screen.GUI_ICONS_LOCATION, FULL_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
        saturation.setPosition(getXOffsetModifier(saturationPos) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(saturationPos));
        view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
    }
    // Half food items.
    if (citizen.getSaturation() / 2 % 1 > 0) {
        @NotNull final Image saturation = new Image();
        saturation.setImage(Screen.GUI_ICONS_LOCATION, HALF_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
        saturation.setPosition(getXOffsetModifier(saturationPos) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(saturationPos));
        view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
    }
}
Also used : Image(com.ldtteam.blockout.controls.Image) View(com.ldtteam.blockout.views.View) IColonyView(com.minecolonies.api.colony.IColonyView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with View

use of com.ldtteam.blockout.views.View 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(LanguageHandler.format("com.minecolonies.coremod.gui.townhall.happiness." + 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 : ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) View(com.ldtteam.blockout.views.View) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView)

Example 3 with View

use of com.ldtteam.blockout.views.View in project Structurize by ldtteam.

the class WindowMultiBlock method rightClick.

@Override
public boolean rightClick(final double mx, final double my) {
    Pane pane = this.findPaneForClick(mx, my);
    if (pane instanceof View) {
        pane = ((View) pane).findPaneForClick(mx, my);
    }
    if (pane instanceof Button && pane.isEnabled()) {
        final Direction newFacing;
        switch(pane.getID()) {
            case BUTTON_UP:
                newFacing = UP;
                break;
            case BUTTON_DOWN:
                newFacing = DOWN;
                break;
            case BUTTON_FORWARD:
                newFacing = NORTH;
                break;
            case BUTTON_BACKWARD:
                newFacing = SOUTH;
                break;
            case BUTTON_RIGHT:
                newFacing = EAST;
                break;
            case BUTTON_LEFT:
                newFacing = WEST;
                break;
            default:
                newFacing = UP;
                break;
        }
        enable(output, newFacing, true);
        return true;
    }
    return false;
}
Also used : Button(com.ldtteam.blockout.controls.Button) Pane(com.ldtteam.blockout.Pane) View(com.ldtteam.blockout.views.View) Direction(net.minecraft.util.Direction)

Example 4 with View

use of com.ldtteam.blockout.views.View in project minecolonies by ldtteam.

the class CitizenWindowUtils method createHappinessBar.

/**
 * Creates an Happiness bar according to the citizen maxHappiness and currentHappiness.
 *
 * @param citizen pointer to the citizen data view
 * @param window  pointer to the current window
 */
public static void createHappinessBar(final ICitizenDataView citizen, final AbstractWindowSkeleton window) {
    // Calculates how much percent of the next level has been completed.
    final double experienceRatio = (citizen.getHappiness() / HappinessConstants.MAX_HAPPINESS) * XP_BAR_WIDTH;
    window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS_BAR, View.class).setAlignment(Alignment.MIDDLE_RIGHT);
    window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS, Text.class).setText(Integer.toString((int) citizen.getHappiness()));
    @NotNull final Image xpBar = new Image();
    xpBar.setImage(Screen.GUI_ICONS_LOCATION, XP_BAR_ICON_COLUMN, HAPPINESS_BAR_EMPTY_ROW, XP_BAR_WIDTH, XP_HEIGHT, false);
    xpBar.setPosition(LEFT_BORDER_X, LEFT_BORDER_Y);
    @NotNull final Image xpBar2 = new Image();
    xpBar2.setImage(Screen.GUI_ICONS_LOCATION, XP_BAR_ICON_COLUMN_END, HAPPINESS_BAR_EMPTY_ROW, XP_BAR_ICON_COLUMN_END_WIDTH, XP_HEIGHT, false);
    xpBar2.setPosition(XP_BAR_ICON_END_OFFSET + LEFT_BORDER_X, LEFT_BORDER_Y);
    window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS_BAR, View.class).addChild(xpBar);
    window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS_BAR, View.class).addChild(xpBar2);
    if (experienceRatio > 0) {
        @NotNull final Image xpBarFull = new Image();
        xpBarFull.setImage(Screen.GUI_ICONS_LOCATION, XP_BAR_ICON_COLUMN, HAPPINESS_BAR_FULL_ROW, (int) experienceRatio, XP_HEIGHT, false);
        xpBarFull.setPosition(LEFT_BORDER_X, LEFT_BORDER_Y);
        window.findPaneOfTypeByID(WINDOW_ID_HAPPINESS_BAR, View.class).addChild(xpBarFull);
    }
}
Also used : Text(com.ldtteam.blockout.controls.Text) Image(com.ldtteam.blockout.controls.Image) View(com.ldtteam.blockout.views.View) IColonyView(com.minecolonies.api.colony.IColonyView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with View

use of com.ldtteam.blockout.views.View in project minecolonies by ldtteam.

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(LanguageHandler.format("com.minecolonies.coremod.gui.townhall.happiness." + 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 : ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) View(com.ldtteam.blockout.views.View) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView)

Aggregations

View (com.ldtteam.blockout.views.View)10 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)6 Image (com.ldtteam.blockout.controls.Image)4 IColonyView (com.minecolonies.api.colony.IColonyView)4 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)4 WorkerBuildingModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView)4 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)4 NotNull (org.jetbrains.annotations.NotNull)4 ItemIcon (com.ldtteam.blockout.controls.ItemIcon)2 Text (com.ldtteam.blockout.controls.Text)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)2 Pane (com.ldtteam.blockout.Pane)1 Button (com.ldtteam.blockout.controls.Button)1 Shape (com.ldtteam.structurize.api.util.Shape)1 Direction (net.minecraft.util.Direction)1