Search in sources :

Example 1 with UISeparator

use of net.malisis.core.client.gui.component.decoration.UISeparator 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)

Aggregations

UIFormContainer (com.almuradev.almura.shared.client.ui.component.UIFormContainer)1 UIButtonBuilder (com.almuradev.almura.shared.client.ui.component.button.UIButtonBuilder)1 UIBackgroundContainer (net.malisis.core.client.gui.component.container.UIBackgroundContainer)1 UISlimScrollbar (net.malisis.core.client.gui.component.control.UISlimScrollbar)1 UIImage (net.malisis.core.client.gui.component.decoration.UIImage)1 UILabel (net.malisis.core.client.gui.component.decoration.UILabel)1 UISeparator (net.malisis.core.client.gui.component.decoration.UISeparator)1 UIButton (net.malisis.core.client.gui.component.interaction.UIButton)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