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);
}
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);
}
Aggregations