Search in sources :

Example 1 with UIExchangeOfferContainer

use of com.almuradev.almura.feature.exchange.client.gui.component.UIExchangeOfferContainer in project Almura by AlmuraDev.

the class ExchangeOfferScreen method construct.

@Override
public void construct() {
    this.guiscreenBackground = false;
    // Form
    final BasicForm form = new BasicForm(this, 400, 325, I18n.format("almura.feature.exchange.title.offer"));
    // Fixes issue overlapping draws from parent
    form.setZIndex(10);
    form.setBackgroundAlpha(255);
    // OK/Cancel buttons
    final UIButton buttonOk = new UIButtonBuilder(this).width(40).text(I18n.format("almura.button.ok")).x(1).anchor(Anchor.BOTTOM | Anchor.RIGHT).onClick(this::transact).build("button.ok");
    final UIButton buttonCancel = new UIButtonBuilder(this).width(40).text(I18n.format("almura.button.cancel")).x(getPaddedX(buttonOk, 2, Anchor.RIGHT)).anchor(Anchor.BOTTOM | Anchor.RIGHT).onClick(this::close).build("button.cancel");
    // Swap container
    final NonNullList<ItemStack> mainInventory = Minecraft.getMinecraft().player.inventory.mainInventory;
    final int totalItemsForSale = this.exchange.getForSaleItemsFor(Minecraft.getMinecraft().player.getUniqueID()).map(List::size).orElse(0);
    this.offerContainer = new UIExchangeOfferContainer(this, getPaddedWidth(form), getPaddedHeight(form) - 20, TextFormatting.WHITE + I18n.format("almura.feature.exchange.text.inventory"), TextFormatting.WHITE + I18n.format("almura.feature.exchange.text.unlisted_items"), mainInventory.size(), this.limit, totalItemsForSale);
    this.offerContainer.register(this);
    // Populate offer container
    final List<VanillaStack> inventoryOffers = new ArrayList<>();
    mainInventory.stream().filter(i -> !i.isEmpty() && i.getItem() != null).forEach(i -> inventoryOffers.add(new BasicVanillaStack(i)));
    this.offerContainer.setItems(this.pendingItems, BasicDualListContainer.SideType.RIGHT);
    this.offerContainer.setItems(inventoryOffers, BasicDualListContainer.SideType.LEFT);
    form.add(this.offerContainer, buttonOk, buttonCancel);
    addToScreen(form);
}
Also used : UIButton(net.malisis.core.client.gui.component.interaction.UIButton) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) ClientExchangeManager(com.almuradev.almura.feature.exchange.client.ClientExchangeManager) InventoryAction(com.almuradev.almura.feature.exchange.InventoryAction) TextFormatting(net.minecraft.util.text.TextFormatting) UIButtonBuilder(net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder) UIExchangeOfferContainer(com.almuradev.almura.feature.exchange.client.gui.component.UIExchangeOfferContainer) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) BasicForm(net.malisis.core.client.gui.component.container.BasicForm) I18n(net.minecraft.client.resources.I18n) Inject(javax.inject.Inject) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) Anchor(net.malisis.core.client.gui.Anchor) BasicDualListContainer(net.malisis.core.client.gui.component.container.BasicDualListContainer) Subscribe(com.google.common.eventbus.Subscribe) BasicScreen(net.malisis.core.client.gui.BasicScreen) NonNullList(net.minecraft.util.NonNullList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Exchange(com.almuradev.almura.feature.exchange.Exchange) BasicForm(net.malisis.core.client.gui.component.container.BasicForm) UIButtonBuilder(net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder) UIExchangeOfferContainer(com.almuradev.almura.feature.exchange.client.gui.component.UIExchangeOfferContainer) UIButton(net.malisis.core.client.gui.component.interaction.UIButton) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack)

Aggregations

Exchange (com.almuradev.almura.feature.exchange.Exchange)1 InventoryAction (com.almuradev.almura.feature.exchange.InventoryAction)1 ClientExchangeManager (com.almuradev.almura.feature.exchange.client.ClientExchangeManager)1 UIExchangeOfferContainer (com.almuradev.almura.feature.exchange.client.gui.component.UIExchangeOfferContainer)1 BasicVanillaStack (com.almuradev.almura.shared.item.BasicVanillaStack)1 VanillaStack (com.almuradev.almura.shared.item.VanillaStack)1 Subscribe (com.google.common.eventbus.Subscribe)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Anchor (net.malisis.core.client.gui.Anchor)1 BasicScreen (net.malisis.core.client.gui.BasicScreen)1 BasicDualListContainer (net.malisis.core.client.gui.component.container.BasicDualListContainer)1 BasicForm (net.malisis.core.client.gui.component.container.BasicForm)1 UIButton (net.malisis.core.client.gui.component.interaction.UIButton)1 UIButtonBuilder (net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder)1 Minecraft (net.minecraft.client.Minecraft)1 I18n (net.minecraft.client.resources.I18n)1 ItemStack (net.minecraft.item.ItemStack)1