Search in sources :

Example 1 with UISlimScrollbar

use of net.malisis.core.client.gui.component.control.UISlimScrollbar in project Almura by AlmuraDev.

the class IngameFarmersAlmanac method construct.

// TODO: Translation support
@SuppressWarnings("deprecation")
@Override
public void construct() {
    guiscreenBackground = false;
    final UIFormContainer form = new UIFormContainer(this, formWidth, formHeight, formTitle);
    form.setAnchor(Anchor.CENTER | Anchor.MIDDLE);
    form.setMovable(true);
    form.setClosable(false);
    form.setBorder(FontColors.WHITE, 1, formAlpha);
    form.setBackgroundAlpha(formAlpha);
    final WorldClient world = this.client.world;
    final RayTraceResult omo = this.client.objectMouseOver;
    final BlockPos blockPos = omo.getBlockPos();
    final IBlockState blockState = getState(world, blockPos);
    final Block block = blockState.getBlock();
    // Block image
    final ItemStack pickStack = blockState.getBlock().getPickBlock(blockState, omo, this.client.world, omo.getBlockPos(), this.client.player);
    final UIImage blockImage = new UIImage(this, pickStack);
    blockImage.setPosition(leftPad / 2, 0, Anchor.LEFT | Anchor.TOP);
    form.add(blockImage);
    // Localized name
    final UILabel labelLocalizedName = new UILabel(this, block.getLocalizedName());
    labelLocalizedName.setFontOptions(FontColors.WHITE_FO);
    labelLocalizedName.setPosition(SimpleScreen.getPaddedX(blockImage, 4), 0);
    form.add(labelLocalizedName);
    // Registry name
    final String registryName = block.getRegistryName() == null ? "unknown" : block.getRegistryName().toString();
    final UILabel labelRegistryName = new UILabel(this, registryName);
    labelRegistryName.setFontOptions(FontColors.GRAY_FO);
    labelRegistryName.setPosition(labelLocalizedName.getX(), SimpleScreen.getPaddedY(labelLocalizedName, 2));
    form.add(labelRegistryName);
    // Line separator
    final UISeparator separator = new UISeparator(this);
    separator.setSize(form.getWidth() - 15, 1);
    separator.setPosition(0, SimpleScreen.getPaddedY(labelRegistryName, 3), Anchor.TOP | Anchor.CENTER);
    form.add(separator);
    // Property container
    this.propertyContainer = new UIBackgroundContainer(this);
    new UISlimScrollbar(this, this.propertyContainer, UIScrollBar.Type.VERTICAL).setAutoHide(true);
    this.propertyContainer.setBackgroundAlpha(50);
    this.propertyContainer.setPosition(0, SimpleScreen.getPaddedY(separator, 5));
    form.add(this.propertyContainer);
    // Get all displayed properties
    loadProperties(world, blockState, blockPos);
    // Adjust the size of the container to reach at most the specified max height
    propertyContainer.setSize(UIComponent.INHERITED, Math.min(propertyContainerMaxHeight, propertyContainer.getContentHeight()));
    final UIButton closeButton = new UIButtonBuilder(this).text("Close").anchor(Anchor.BOTTOM | Anchor.RIGHT).position(-4, -4).onClick(this::close).build("button.close");
    form.add(closeButton);
    // Adjust the size of the form to better fit content
    form.setSize(form.getContentWidth() + leftPad, form.getContentHeight() + closeButton.getHeight() + 10);
    // Readjust size for width because MalisisCore doesn't account for the scrollbar with UIComponent.INHERITED
    propertyContainer.setSize(propertyContainer.getWidth() - 1, propertyContainer.getHeight());
    addToScreen(form);
    Mouse.setGrabbed(false);
}
Also used : UILabel(net.malisis.core.client.gui.component.decoration.UILabel) IBlockState(net.minecraft.block.state.IBlockState) UISlimScrollbar(net.malisis.core.client.gui.component.control.UISlimScrollbar) RayTraceResult(net.minecraft.util.math.RayTraceResult) UIFormContainer(com.almuradev.almura.shared.client.ui.component.UIFormContainer) UISeparator(net.malisis.core.client.gui.component.decoration.UISeparator) WorldClient(net.minecraft.client.multiplayer.WorldClient) UIButtonBuilder(com.almuradev.almura.shared.client.ui.component.button.UIButtonBuilder) UIButton(net.malisis.core.client.gui.component.interaction.UIButton) Block(net.minecraft.block.Block) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) UIImage(net.malisis.core.client.gui.component.decoration.UIImage) UIBackgroundContainer(net.malisis.core.client.gui.component.container.UIBackgroundContainer)

Example 2 with UISlimScrollbar

use of net.malisis.core.client.gui.component.control.UISlimScrollbar in project Almura by AlmuraDev.

the class UIMessageBox method construct.

private void construct(MalisisGui gui) {
    setTopPadding(topPadding);
    setBottomPadding(bottomPadding);
    if (!this.message.isEmpty()) {
        final UILabel messageLabel = new UILabel(gui, this.message, true);
        messageLabel.setSize(UIComponent.INHERITED, UIComponent.INHERITED);
        final UISlimScrollbar scrollbar = new UISlimScrollbar(gui, messageLabel, UIScrollBar.Type.VERTICAL);
        scrollbar.setAutoHide(true);
        add(messageLabel.setAnchor(Anchor.CENTER | Anchor.MIDDLE));
    }
    final UIBackgroundContainer buttonContainer = new UIBackgroundContainer(gui);
    final List<UIButton> buttons = new ArrayList<>();
    switch(this.messageBoxButtons) {
        case OK:
            buttons.add(buildButton(gui, "button.ok"));
            break;
        case OK_CANCEL:
            buttons.add(buildButton(gui, "button.ok"));
            buttons.add(buildButton(gui, "button.cancel"));
            break;
        case YES_NO:
            buttons.add(buildButton(gui, "button.yes"));
            buttons.add(buildButton(gui, "button.no"));
            break;
        case YES_NO_CANCEL:
            buttons.add(buildButton(gui, "button.yes"));
            buttons.add(buildButton(gui, "button.no"));
            buttons.add(buildButton(gui, "button.cancel"));
            break;
        case CLOSE:
            buttons.add(buildButton(gui, "button.close"));
    }
    int width = 0;
    int x = 0;
    for (UIButton button : buttons) {
        buttonContainer.add(button.setPosition(x, 0));
        x += button.getWidth() + buttonPadding;
        width += button.getWidth();
    }
    width += buttonPadding * (buttons.size() - 1);
    buttonContainer.setSize(width, GuiConfig.Button.HEIGHT);
    buttonContainer.setPosition(0, 5, Anchor.BOTTOM | Anchor.RIGHT);
    buttonContainer.setBackgroundAlpha(0);
    add(buttonContainer);
}
Also used : UILabel(net.malisis.core.client.gui.component.decoration.UILabel) UISlimScrollbar(net.malisis.core.client.gui.component.control.UISlimScrollbar) UIButton(net.malisis.core.client.gui.component.interaction.UIButton) ArrayList(java.util.ArrayList) UIBackgroundContainer(net.malisis.core.client.gui.component.container.UIBackgroundContainer)

Aggregations

UIBackgroundContainer (net.malisis.core.client.gui.component.container.UIBackgroundContainer)2 UISlimScrollbar (net.malisis.core.client.gui.component.control.UISlimScrollbar)2 UILabel (net.malisis.core.client.gui.component.decoration.UILabel)2 UIButton (net.malisis.core.client.gui.component.interaction.UIButton)2 UIFormContainer (com.almuradev.almura.shared.client.ui.component.UIFormContainer)1 UIButtonBuilder (com.almuradev.almura.shared.client.ui.component.button.UIButtonBuilder)1 ArrayList (java.util.ArrayList)1 UIImage (net.malisis.core.client.gui.component.decoration.UIImage)1 UISeparator (net.malisis.core.client.gui.component.decoration.UISeparator)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 EnumSkyBlock (net.minecraft.world.EnumSkyBlock)1