Search in sources :

Example 1 with UISelect

use of net.malisis.core.client.gui.component.interaction.UISelect in project Almura by AlmuraDev.

the class StoreScreen method construct.

@Override
public void construct() {
    guiscreenBackground = false;
    final BasicForm form = new BasicForm(this, 257, 300, this.store.getName());
    form.setBackgroundAlpha(255);
    final BasicContainer<?> storeContainer = new BasicContainer<>(this, 251, UIComponent.INHERITED);
    storeContainer.setBorder(FontColors.WHITE, 1, 185);
    storeContainer.setPadding(3);
    storeContainer.setColor(0);
    // Buy tab
    final int leftOffset = storeContainer.getLeftPadding() - storeContainer.getLeftBorderSize();
    this.buyTabContainer = new BasicContainer<>(this, this.tabWidth, this.tabHeight);
    this.buyTabContainer.setBorders(FontColors.WHITE, 185, 1, 1, 1, 0);
    this.buyTabContainer.setPosition(2, 2);
    this.buyTabContainer.setColor(defaultTabColor);
    this.buyTabContainer.attachData(SideType.BUY);
    // Buy tab label
    this.buyTabLabel = new UILabel(this, I18n.format("almura.feature.common.button.buy"));
    this.buyTabLabel.setPosition(0, 1, Anchor.MIDDLE | Anchor.CENTER);
    // Always use the same data as their parent
    this.buyTabLabel.attachData(this.buyTabContainer.getData());
    this.buyTabContainer.add(this.buyTabLabel);
    // Sell tab
    this.sellTabContainer = new BasicContainer<>(this, this.tabWidth, this.tabHeight);
    this.sellTabContainer.setBorders(FontColors.WHITE, 185, 1, 1, 1, 0);
    this.sellTabContainer.setColor(defaultTabColor);
    this.sellTabContainer.setPosition(-2, 2, Anchor.TOP | Anchor.RIGHT);
    this.sellTabContainer.attachData(SideType.SELL);
    // Sell tab label
    this.sellTabLabel = new UILabel(this, I18n.format("almura.feature.common.button.sell"));
    this.sellTabLabel.setPosition(0, 1, Anchor.MIDDLE | Anchor.CENTER);
    // Always use the same data as their parent
    this.sellTabLabel.attachData(this.sellTabContainer.getData());
    this.sellTabContainer.add(this.sellTabLabel);
    // Doesn't exist.
    this.thisDoesNotExistLine = new BasicLine(this, this.tabWidth - 2);
    this.thisDoesNotExistLine.setBackgroundAlpha(255);
    this.thisDoesNotExistLine.setColor(selectedTabColor);
    // Bottom tab line
    final BasicLine tabContainerLineBottom = new BasicLine(this, storeContainer.getWidth() - (storeContainer.getLeftBorderSize() + storeContainer.getRightBorderSize()), 1);
    tabContainerLineBottom.setPosition(-leftOffset, BasicScreen.getPaddedY(this.buyTabContainer, 0));
    // Search Y
    final int searchY = BasicScreen.getPaddedY(tabContainerLineBottom, 2);
    // Item Display Name Search Label
    final UILabel itemSearchLabel = new UILabel(this, I18n.format("almura.feature.exchange.text.item_name") + ":");
    itemSearchLabel.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).build());
    itemSearchLabel.setPosition(1, searchY + 3, Anchor.LEFT | Anchor.TOP);
    // Item Display Name Search Text Box
    this.itemDisplayNameSearchBox = new BasicTextBox(this, "");
    this.itemDisplayNameSearchBox.setAcceptsReturn(false);
    this.itemDisplayNameSearchBox.setAcceptsTab(false);
    this.itemDisplayNameSearchBox.setTabIndex(0);
    this.itemDisplayNameSearchBox.setOnEnter((tb) -> this.search());
    this.itemDisplayNameSearchBox.setSize(60, 0);
    this.itemDisplayNameSearchBox.setPosition(BasicScreen.getPaddedX(itemSearchLabel, innerPadding), searchY + 1, Anchor.LEFT | Anchor.TOP);
    this.itemDisplayNameSearchBox.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).shadow(false).build());
    // Sort combobox
    this.comboBoxSortType = new UISelect<>(this, 78);
    this.comboBoxSortType.setPosition(BasicScreen.getPaddedX(this.itemDisplayNameSearchBox, innerPadding), searchY + 1);
    this.comboBoxSortType.setOptions(Arrays.asList(FeatureSortTypes.ITEM_DISPLAY_NAME_ASC, FeatureSortTypes.ITEM_DISPLAY_NAME_DESC, FeatureSortTypes.PRICE_ASC, FeatureSortTypes.PRICE_DESC));
    this.comboBoxSortType.setOptionsWidth(UISelect.LONGEST_OPTION);
    // Because that's reasonable.
    this.comboBoxSortType.setLabelFunction(type -> type == null ? "" : type.getName());
    this.comboBoxSortType.select(FeatureSortTypes.ITEM_DISPLAY_NAME_ASC);
    // Search button
    final UIButton buttonSearch = new UIButtonBuilder(this).width(50).anchor(Anchor.RIGHT | Anchor.TOP).position(0, searchY).text(I18n.format("almura.feature.common.button.search")).onClick(this::search).build("button.search");
    // List
    this.itemList = new BasicList<>(this, UIComponent.INHERITED, BasicScreen.getPaddedHeight(form) - this.buyTabContainer.getHeight() - tabContainerLineBottom.getHeight() - buttonSearch.getHeight() - 30);
    this.itemList.setPosition(0, BasicScreen.getPaddedY(buttonSearch, 2));
    this.itemList.setSelectConsumer(i -> this.updateStoreControls());
    this.itemList.setItemComponentSpacing(1);
    this.itemList.setBorder(FontColors.WHITE, 1, 185);
    this.itemList.setPadding(2);
    this.itemList.setItemComponentFactory(StoreItemComponent::new);
    this.buttonTransactOne = new UIButtonBuilder(this).width(60).anchor(Anchor.BOTTOM | Anchor.LEFT).enabled(false).onClick(() -> this.transact(1)).build("button.transact.single");
    this.buttonTransactStack = new UIButtonBuilder(this).width(60).x(BasicScreen.getPaddedX(this.buttonTransactOne, 2)).anchor(Anchor.BOTTOM | Anchor.LEFT).enabled(false).onClick(() -> {
        if (this.itemList.getSelectedItem() == null) {
            return;
        }
        final int value = this.itemList.getSelectedItem().asRealStack().getMaxStackSize();
        this.transact(value);
    }).build("button.transact.stack");
    this.buttonTransactAll = new UIButtonBuilder(this).width(60).anchor(Anchor.BOTTOM | Anchor.RIGHT).enabled(false).onClick(() -> {
        final StoreItem selectedItem = this.itemList.getSelectedItem();
        if (selectedItem == null) {
            return;
        }
        // Determine the value to transact
        final int value;
        if (this.currentSide == SideType.BUY) {
            // If we are buying then base the value on the quantity remaining for the item to purchase
            value = this.itemList.getSelectedItem().getQuantity();
        } else {
            // If we're selling then base it on how many we have in our main inventory
            value = Minecraft.getMinecraft().player.inventory.mainInventory.stream().filter(i -> ItemStack.areItemsEqual(i, selectedItem.asRealStack())).mapToInt(ItemStack::getCount).sum();
        }
        this.transact(value);
    }).build("button.transact.all");
    this.buttonTransactQuantity = new UIButtonBuilder(this).width(60).x(BasicScreen.getPaddedX(this.buttonTransactAll, 2, Anchor.RIGHT)).anchor(Anchor.BOTTOM | Anchor.RIGHT).enabled(false).onClick(() -> {
        final StoreItem selectedItem = this.itemList.getSelectedItem();
        if (selectedItem == null) {
            return;
        }
        new StoreTransactQuantityScreen(this, this.store, selectedItem, this.currentSide).display();
    }).build("button.transact.quantity");
    storeContainer.add(this.buyTabContainer, this.sellTabContainer, tabContainerLineBottom, this.thisDoesNotExistLine, itemSearchLabel, this.itemDisplayNameSearchBox, this.comboBoxSortType, buttonSearch, this.itemList, this.buttonTransactOne, this.buttonTransactStack, this.buttonTransactQuantity, this.buttonTransactAll);
    form.add(storeContainer);
    // Logic for admin pane
    if (this.isAdmin) {
        // Adjust form width
        form.setWidth(form.getWidth() + 224);
        // Create admin pane
        final BasicContainer<?> adminContainer = new BasicContainer(this, 220, UIComponent.INHERITED);
        adminContainer.setPosition(BasicScreen.getPaddedX(storeContainer, 4), 0);
        adminContainer.setBorder(FontColors.WHITE, 1, 185);
        adminContainer.setPadding(3);
        adminContainer.setColor(0);
        // Buy tab label
        this.typeLabel = new UILabel(this, TextFormatting.WHITE + "Type: ");
        this.typeLabel.setPosition(0, 2, Anchor.TOP | Anchor.LEFT);
        // Item location selection
        this.locationSelect = new UISelect<>(this, UIComponent.INHERITED);
        this.locationSelect.setOptions(itemFinderRelationshipMap.keySet());
        this.locationSelect.setLabelFunction(o -> I18n.format(o.translationKey));
        this.locationSelect.setPosition(30, 0);
        this.locationSelect.setSize(184, 12);
        this.locationSelect.maxDisplayedOptions(24);
        this.locationSelect.register(this);
        // Search text box
        this.adminSearchTextBox = new BasicTextBox(this, "");
        this.adminSearchTextBox.setSize(UIComponent.INHERITED, this.locationSelect.getHeight());
        this.adminSearchTextBox.setPosition(0, BasicScreen.getPaddedY(this.locationSelect, 2));
        this.adminSearchTextBox.register(this);
        // Item list
        this.adminItemList = new BasicList<>(this, UIComponent.INHERITED, BasicScreen.getPaddedHeight(form) - this.locationSelect.getHeight() - this.adminSearchTextBox.getHeight() - 28);
        this.adminItemList.setItemComponentFactory(AdminItemComponent::new);
        this.adminItemList.setItemComponentSpacing(1);
        this.adminItemList.setPosition(0, BasicScreen.getPaddedY(this.adminSearchTextBox, 2));
        this.adminItemList.setPadding(2);
        this.adminItemList.setBorder(FontColors.WHITE, 1, 185);
        this.adminItemList.setSelectConsumer(i -> this.updateAdminControls());
        this.buttonAdminList = new UIButtonBuilder(this).width(50).anchor(Anchor.BOTTOM | Anchor.LEFT).enabled(false).onClick(this::listOrModify).text(I18n.format("almura.feature.common.button.list")).build("button.list");
        this.buttonAdminUnlist = new UIButtonBuilder(this).width(50).anchor(Anchor.BOTTOM | Anchor.LEFT).position(BasicScreen.getPaddedX(this.buttonAdminList, 2), 0).enabled(false).onClick(this::unlist).text(I18n.format("almura.feature.common.button.unlist")).build("button.unlist");
        this.adminListTotalLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.total") + ": ");
        this.adminListTotalLabel.setPosition(0, -2, Anchor.BOTTOM | Anchor.RIGHT);
        adminContainer.add(this.typeLabel, this.locationSelect, this.adminSearchTextBox, this.adminItemList, this.buttonAdminList, this.buttonAdminUnlist, this.adminListTotalLabel);
        form.add(adminContainer);
        // Select the first item
        this.locationSelect.selectFirst();
    }
    addToScreen(form);
}
Also used : UILabel(net.malisis.core.client.gui.component.decoration.UILabel) Arrays(java.util.Arrays) UIComponent(net.malisis.core.client.gui.component.UIComponent) BuyingItem(com.almuradev.almura.feature.store.listing.BuyingItem) I18n(net.minecraft.client.resources.I18n) BigDecimal(java.math.BigDecimal) UISaneTooltip(com.almuradev.almura.shared.client.ui.component.UISaneTooltip) MalisisGui(net.malisis.core.client.gui.MalisisGui) BasicTextBox(net.malisis.core.client.gui.component.interaction.BasicTextBox) Side(net.minecraftforge.fml.relauncher.Side) Map(java.util.Map) BasicList(net.malisis.core.client.gui.component.container.BasicList) BasicContainer(net.malisis.core.client.gui.component.container.BasicContainer) NonNullList(net.minecraft.util.NonNullList) FontColors(net.malisis.core.util.FontColors) FeatureConstants(com.almuradev.almura.shared.feature.FeatureConstants) StoreModule(com.almuradev.almura.feature.store.StoreModule) UIButtonBuilder(net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder) ClientStoreManager(com.almuradev.almura.feature.store.client.ClientStoreManager) UITooltip(net.malisis.core.client.gui.component.decoration.UITooltip) Collectors(java.util.stream.Collectors) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) UIImage(net.malisis.core.client.gui.component.decoration.UIImage) Optional(java.util.Optional) SortType(com.almuradev.almura.feature.SortType) BasicLine(net.malisis.core.client.gui.component.decoration.BasicLine) HashMap(java.util.HashMap) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) FeatureSortTypes(com.almuradev.almura.FeatureSortTypes) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft) Anchor(net.malisis.core.client.gui.Anchor) SellingItem(com.almuradev.almura.feature.store.listing.SellingItem) StoreItem(com.almuradev.almura.feature.store.listing.StoreItem) Subscribe(com.google.common.eventbus.Subscribe) BasicScreen(net.malisis.core.client.gui.BasicScreen) UIExpandingLabel(com.almuradev.almura.shared.client.ui.component.UIExpandingLabel) CreativeTabs(net.minecraft.creativetab.CreativeTabs) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) UISelect(net.malisis.core.client.gui.component.interaction.UISelect) ComponentEvent(net.malisis.core.client.gui.event.ComponentEvent) Nullable(javax.annotation.Nullable) UIButton(net.malisis.core.client.gui.component.interaction.UIButton) UITextField(net.malisis.core.client.gui.component.interaction.UITextField) UILabel(net.malisis.core.client.gui.component.decoration.UILabel) TextFormatting(net.minecraft.util.text.TextFormatting) Store(com.almuradev.almura.feature.store.Store) SideType(com.almuradev.almura.feature.store.SideType) BasicForm(net.malisis.core.client.gui.component.container.BasicForm) FontRenderer(net.minecraft.client.gui.FontRenderer) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) Comparator(java.util.Comparator) FontOptions(net.malisis.core.renderer.font.FontOptions) BasicLine(net.malisis.core.client.gui.component.decoration.BasicLine) StoreItem(com.almuradev.almura.feature.store.listing.StoreItem) 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) ItemStack(net.minecraft.item.ItemStack) BasicTextBox(net.malisis.core.client.gui.component.interaction.BasicTextBox)

Aggregations

FeatureSortTypes (com.almuradev.almura.FeatureSortTypes)1 SortType (com.almuradev.almura.feature.SortType)1 SideType (com.almuradev.almura.feature.store.SideType)1 Store (com.almuradev.almura.feature.store.Store)1 StoreModule (com.almuradev.almura.feature.store.StoreModule)1 ClientStoreManager (com.almuradev.almura.feature.store.client.ClientStoreManager)1 BuyingItem (com.almuradev.almura.feature.store.listing.BuyingItem)1 SellingItem (com.almuradev.almura.feature.store.listing.SellingItem)1 StoreItem (com.almuradev.almura.feature.store.listing.StoreItem)1 UIExpandingLabel (com.almuradev.almura.shared.client.ui.component.UIExpandingLabel)1 UISaneTooltip (com.almuradev.almura.shared.client.ui.component.UISaneTooltip)1 FeatureConstants (com.almuradev.almura.shared.feature.FeatureConstants)1 Subscribe (com.google.common.eventbus.Subscribe)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1