Search in sources :

Example 1 with IngameFeature

use of com.almuradev.almura.shared.feature.IngameFeature in project Almura by AlmuraDev.

the class IngameFeatureManagementScreen method construct.

@SuppressWarnings("unchecked")
@Override
public void construct() {
    this.guiscreenBackground = false;
    this.form = new BasicForm(this, requiredScreenWidth, requiredScreenHeight, this.title);
    this.featureList = new BasicList<>(this, 120, requiredScreenHeight - 40);
    this.featureList.setSelectConsumer(this.onSelect());
    this.featureList.setItemComponentFactory((g, l, i) -> new IngameFeatureItemComponent(this, l, i));
    this.featureList.setItemComponentSpacing(1);
    this.featureList.setCanDeselect(false);
    this.featureList.setBorder(0xFFFFFF, 1, 215);
    this.featureList.setPadding(2, 2);
    this.featureList.setPosition(1, 0);
    this.featureList.register(this);
    this.form.add(this.featureList);
    final BasicContainer<?> container = new BasicContainer(this);
    container.setBorder(0xFFFFFF, 1, 215);
    container.setPadding(4, 4);
    container.setAnchor(Anchor.RIGHT | Anchor.TOP);
    container.setPosition(-1, 0);
    container.setSize(244, requiredScreenHeight - 40);
    container.setBackgroundAlpha(0);
    // ID
    this.tbId = new BasicTextBox(this, "");
    this.tbId.setAcceptsReturn(false);
    this.tbId.setAcceptsTab(false);
    this.tbId.setTabIndex(0);
    this.tbId.setOnEnter(tb -> this.save());
    this.tbId.setSize(140, 0);
    this.tbId.setPosition(0, 0, Anchor.RIGHT | Anchor.TOP);
    this.tbId.setEditable(false);
    this.tbId.register(this);
    this.tbId.setFilter(s -> s.replaceAll(filter, "").toLowerCase());
    final UILabel idLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.id") + ":").setPosition(0, this.tbId.getY() + 3, Anchor.LEFT | Anchor.TOP);
    // Title
    this.tbTitle = new BasicTextBox(this, "");
    this.tbTitle.setAcceptsReturn(false);
    this.tbTitle.setAcceptsTab(false);
    this.tbTitle.setTabIndex(1);
    this.tbTitle.setOnEnter(tb -> this.save());
    this.tbTitle.setSize(140, 0);
    this.tbTitle.setPosition(0, BasicScreen.getPaddedY(this.tbId, 2), Anchor.RIGHT | Anchor.TOP);
    this.tbTitle.register(this);
    final UILabel titleLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.title") + ":").setPosition(0, this.tbTitle.getY() + 3, Anchor.LEFT | Anchor.TOP);
    // Permission
    this.tbPermission = new BasicTextBox(this, "");
    this.tbPermission.setAcceptsReturn(false);
    this.tbPermission.setAcceptsTab(false);
    this.tbPermission.setTabIndex(2);
    this.tbPermission.setOnEnter(tb -> this.save());
    this.tbPermission.setSize(140, 0);
    this.tbPermission.setPosition(0, BasicScreen.getPaddedY(this.tbTitle, 2), Anchor.RIGHT | Anchor.TOP);
    this.tbPermission.register(this);
    this.tbPermission.setFilter(s -> s.replaceAll(filter, "").toLowerCase());
    final UILabel permissionLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.permission") + ":").setPosition(0, this.tbPermission.getY() + 3, Anchor.LEFT | Anchor.TOP);
    // Created by (name)
    this.tbCreatorName = new BasicTextBox(this, "");
    this.tbCreatorName.setSize(140, 0);
    this.tbCreatorName.setPosition(0, BasicScreen.getPaddedY(this.tbPermission, 2), Anchor.RIGHT | Anchor.TOP);
    this.tbCreatorName.setEditable(false);
    this.creatorNameLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.creator_name") + ":").setPosition(0, this.tbCreatorName.getY() + 3, Anchor.LEFT | Anchor.TOP);
    // Created by (Unique ID)
    this.tbCreatorUniqueId = new BasicTextBox(this, "");
    this.tbCreatorUniqueId.setSize(140, 0);
    this.tbCreatorUniqueId.setPosition(0, BasicScreen.getPaddedY(this.tbCreatorName, 2), Anchor.RIGHT | Anchor.TOP);
    this.tbCreatorUniqueId.setEditable(false);
    this.creatorUniqueIdLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.creator_uuid") + ":").setPosition(0, this.tbCreatorUniqueId.getY() + 3, Anchor.LEFT | Anchor.TOP);
    // Created on
    this.tbCreated = new BasicTextBox(this, "");
    this.tbCreated.setSize(140, 0);
    this.tbCreated.setPosition(0, BasicScreen.getPaddedY(this.tbCreatorUniqueId, 2), Anchor.RIGHT | Anchor.TOP);
    this.tbCreated.setEditable(false);
    this.createdLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.created") + ":").setPosition(0, this.tbCreated.getY() + 3, Anchor.LEFT | Anchor.TOP);
    this.hiddenCheckbox = new UICheckBox(this);
    this.hiddenCheckbox.setText(TextFormatting.WHITE + I18n.format("almura.feature.common.text.hidden"));
    this.hiddenCheckbox.setPosition(0, 0, Anchor.LEFT | Anchor.BOTTOM);
    this.hiddenCheckbox.setChecked(false);
    this.hiddenCheckbox.setName("checkbox.hidden");
    this.hiddenCheckbox.register(this);
    this.buttonSave = new UIButtonBuilder(this).width(40).text(I18n.format("almura.button.save")).anchor(Anchor.BOTTOM | Anchor.RIGHT).enabled(false).onClick(this::save).build("button.save");
    this.buttonOpen = new UIButtonBuilder(this).width(40).text(I18n.format("almura.button.open")).position(BasicScreen.getPaddedX(this.buttonSave, 2, Anchor.RIGHT), 0).anchor(Anchor.BOTTOM | Anchor.RIGHT).enabled(false).onClick(this::open).build("button.open");
    container.add(this.tbId, idLabel, this.tbTitle, titleLabel, this.tbPermission, permissionLabel, this.tbCreatorName, creatorNameLabel, this.tbCreatorUniqueId, creatorUniqueIdLabel, this.tbCreated, createdLabel, this.hiddenCheckbox, this.buttonOpen, this.buttonSave);
    // Add button
    this.buttonAdd = new UIButtonBuilder(this).text(TextFormatting.GREEN + "+").anchor(Anchor.BOTTOM | Anchor.LEFT).onClick(() -> {
        this.featureList.setSelectedItem(null);
        this.tbId.focus();
    }).build("button.add");
    // Remove button
    this.buttonDelete = new UIButtonBuilder(this).x(BasicScreen.getPaddedX(this.buttonAdd, 2)).text(TextFormatting.RED + "-").anchor(Anchor.BOTTOM | Anchor.LEFT).onClick(() -> {
        final IngameFeature selectedFeature = this.featureList.getSelectedItem();
        if (selectedFeature != null) {
            BasicMessageBox.showDialog(this, I18n.format("almura.feature.common.title.are_you_sure"), I18n.format("almura.feature.common.text.delete_feature", selectedFeature.getId(), name), MessageBoxButtons.YES_NO, (result) -> {
                if (result != MessageBoxResult.YES)
                    return;
                this.onDelete.accept(this, Optional.ofNullable(this.featureList.getSelectedItem()));
            });
        }
    }).build("button.delete");
    // Close button
    final UIButton buttonClose = new UIButtonBuilder(this).width(40).anchor(Anchor.BOTTOM | Anchor.RIGHT).text(I18n.format("almura.button.close")).onClick(this::close).build("button.close");
    this.form.add(this.featureList, container, this.buttonAdd, this.buttonDelete, buttonClose);
    this.addToScreen(this.form);
    this.refresh();
}
Also used : UILabel(net.malisis.core.client.gui.component.decoration.UILabel) IngameFeature(com.almuradev.almura.shared.feature.IngameFeature) BasicForm(net.malisis.core.client.gui.component.container.BasicForm) UIButtonBuilder(net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder) UIButton(net.malisis.core.client.gui.component.interaction.UIButton) BasicContainer(net.malisis.core.client.gui.component.container.BasicContainer) UICheckBox(net.malisis.core.client.gui.component.interaction.UICheckBox) BasicTextBox(net.malisis.core.client.gui.component.interaction.BasicTextBox)

Aggregations

IngameFeature (com.almuradev.almura.shared.feature.IngameFeature)1 BasicContainer (net.malisis.core.client.gui.component.container.BasicContainer)1 BasicForm (net.malisis.core.client.gui.component.container.BasicForm)1 UILabel (net.malisis.core.client.gui.component.decoration.UILabel)1 BasicTextBox (net.malisis.core.client.gui.component.interaction.BasicTextBox)1 UIButton (net.malisis.core.client.gui.component.interaction.UIButton)1 UICheckBox (net.malisis.core.client.gui.component.interaction.UICheckBox)1 UIButtonBuilder (net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder)1