Search in sources :

Example 1 with SideType

use of com.almuradev.almura.feature.store.SideType in project Almura by AlmuraDev.

the class StoreScreen method drawScreen.

@Override
public void drawScreen(final int mouseX, final int mouseY, final float partialTick) {
    // Update colors
    this.updateTabs(this.buyTabContainer, this.buyTabLabel);
    this.updateTabs(this.sellTabContainer, this.sellTabLabel);
    // Hover logic
    this.getTabContainer(mouseX, mouseY).ifPresent(tab -> {
        final SideType tabType = (SideType) tab.getData();
        if (tabType == SideType.BUY && this.store.getBuyingItems().size() == 0) {
            return;
        }
        if (tabType == SideType.SELL && this.store.getSellingItems().size() == 0) {
            return;
        }
        if (this.currentSide != tabType) {
            tab.setColor(hoveredTabColor);
        }
    });
    super.drawScreen(mouseX, mouseY, partialTick);
}
Also used : SideType(com.almuradev.almura.feature.store.SideType)

Example 2 with SideType

use of com.almuradev.almura.feature.store.SideType in project Almura by AlmuraDev.

the class ClientStoreManager method filterLocalItems.

@SuppressWarnings("unchecked")
public <T extends StoreItem> List<T> filterLocalItems(final String id, @Nullable final String filter, @Nullable final String sort, final SideType targetSide) {
    checkNotNull(id);
    checkNotNull(targetSide);
    final Store axs = this.getStore(id);
    checkNotNull(axs);
    Stream<T> stream = targetSide == SideType.BUY ? (Stream<T>) axs.getBuyingItems().stream() : (Stream<T>) axs.getSellingItems().stream();
    if (filter != null) {
        final List<FilterRegistry.FilterElement<StoreItem>> elements = FilterRegistry.instance.getFilterElements(filter);
        stream = stream.filter(storeItem -> elements.stream().allMatch(element -> element.getFilter().test(storeItem, element.getValue())));
    }
    if (sort != null) {
        final List<FilterRegistry.SorterElement<StoreItem>> elements = FilterRegistry.instance.getSortingElements(sort);
        final Comparator<StoreItem> comparator = FilterRegistry.instance.buildSortingComparator(elements).orElse(null);
        if (comparator != null) {
            stream = stream.sorted(comparator);
        }
    }
    return stream.collect(Collectors.toList());
}
Also used : FMLNetworkEvent(net.minecraftforge.fml.common.network.FMLNetworkEvent) Almura(com.almuradev.almura.Almura) FilterRegistry(com.almuradev.almura.shared.feature.filter.FilterRegistry) Inject(com.google.inject.Inject) ServerboundListItemsRequestPacket(com.almuradev.almura.feature.store.network.ServerboundListItemsRequestPacket) Singleton(javax.inject.Singleton) StoreModifyType(com.almuradev.almura.feature.store.StoreModifyType) BuyingItem(com.almuradev.almura.feature.store.listing.BuyingItem) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) Minecraft(net.minecraft.client.Minecraft) ServerboundDelistItemsPacket(com.almuradev.almura.feature.store.network.ServerboundDelistItemsPacket) SellingItem(com.almuradev.almura.feature.store.listing.SellingItem) StoreItem(com.almuradev.almura.feature.store.listing.StoreItem) StoreItemSegmentType(com.almuradev.almura.feature.store.StoreItemSegmentType) Nullable(javax.annotation.Nullable) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) ServerboundItemTransactionPacket(com.almuradev.almura.feature.store.network.ServerboundItemTransactionPacket) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FeatureConstants(com.almuradev.almura.shared.feature.FeatureConstants) Store(com.almuradev.almura.feature.store.Store) StoreScreen(com.almuradev.almura.feature.store.client.gui.StoreScreen) Set(java.util.Set) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) SideType(com.almuradev.almura.feature.store.SideType) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) StoreManagementScreen(com.almuradev.almura.feature.store.client.gui.StoreManagementScreen) ChannelBinding(org.spongepowered.api.network.ChannelBinding) GuiScreen(net.minecraft.client.gui.GuiScreen) List(java.util.List) Stream(java.util.stream.Stream) Witness(com.almuradev.core.event.Witness) ServerboundModifyStorePacket(com.almuradev.almura.feature.store.network.ServerboundModifyStorePacket) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ChannelId(org.spongepowered.api.network.ChannelId) Comparator(java.util.Comparator) ServerboundModifyItemsPacket(com.almuradev.almura.feature.store.network.ServerboundModifyItemsPacket) StoreItem(com.almuradev.almura.feature.store.listing.StoreItem) Store(com.almuradev.almura.feature.store.Store)

Example 3 with SideType

use of com.almuradev.almura.feature.store.SideType in project Almura by AlmuraDev.

the class StoreScreen method mouseClicked.

@Override
protected void mouseClicked(final int x, final int y, final int button) {
    this.getTabContainer(x, y).ifPresent(tab -> {
        final SideType targetSide = (SideType) tab.getData();
        ;
        if (targetSide == SideType.BUY && this.store.getBuyingItems().size() == 0) {
            return;
        }
        if (targetSide == SideType.SELL && this.store.getSellingItems().size() == 0) {
            return;
        }
        this.currentSide = targetSide;
        this.refresh(false);
    });
    super.mouseClicked(x, y, button);
}
Also used : SideType(com.almuradev.almura.feature.store.SideType)

Aggregations

SideType (com.almuradev.almura.feature.store.SideType)3 Almura (com.almuradev.almura.Almura)1 Store (com.almuradev.almura.feature.store.Store)1 StoreItemSegmentType (com.almuradev.almura.feature.store.StoreItemSegmentType)1 StoreModifyType (com.almuradev.almura.feature.store.StoreModifyType)1 StoreManagementScreen (com.almuradev.almura.feature.store.client.gui.StoreManagementScreen)1 StoreScreen (com.almuradev.almura.feature.store.client.gui.StoreScreen)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 ServerboundDelistItemsPacket (com.almuradev.almura.feature.store.network.ServerboundDelistItemsPacket)1 ServerboundItemTransactionPacket (com.almuradev.almura.feature.store.network.ServerboundItemTransactionPacket)1 ServerboundListItemsRequestPacket (com.almuradev.almura.feature.store.network.ServerboundListItemsRequestPacket)1 ServerboundModifyItemsPacket (com.almuradev.almura.feature.store.network.ServerboundModifyItemsPacket)1 ServerboundModifyStorePacket (com.almuradev.almura.feature.store.network.ServerboundModifyStorePacket)1 FeatureConstants (com.almuradev.almura.shared.feature.FeatureConstants)1 FilterRegistry (com.almuradev.almura.shared.feature.filter.FilterRegistry)1 VanillaStack (com.almuradev.almura.shared.item.VanillaStack)1 NetworkConfig (com.almuradev.almura.shared.network.NetworkConfig)1 Witness (com.almuradev.core.event.Witness)1