Search in sources :

Example 6 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class AbstractWidgetGroup method onPositionUpdate.

@Override
protected void onPositionUpdate() {
    Position selfPosition = getPosition();
    for (Widget widget : widgets) {
        widget.setParentPosition(selfPosition);
    }
    recomputeSize();
}
Also used : Position(gregtech.api.util.Position) INativeWidget(gregtech.api.gui.INativeWidget) Widget(gregtech.api.gui.Widget)

Example 7 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class AbstractWidgetGroup method readUpdateInfo.

@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
    if (id == 1) {
        int widgetIndex = buffer.readVarInt();
        int widgetUpdateId = buffer.readVarInt();
        Widget widget = widgets.get(widgetIndex);
        widget.readUpdateInfo(widgetUpdateId, buffer);
    }
}
Also used : INativeWidget(gregtech.api.gui.INativeWidget) Widget(gregtech.api.gui.Widget)

Example 8 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class TabGroup method getContainedWidgets.

@Override
public List<Widget> getContainedWidgets(boolean includeHidden) {
    ArrayList<Widget> containedWidgets = new ArrayList<>(widgets.size());
    if (includeHidden) {
        for (Widget widget : tabWidgets.values()) {
            containedWidgets.add(widget);
            if (widget instanceof AbstractWidgetGroup)
                containedWidgets.addAll(((AbstractWidgetGroup) widget).getContainedWidgets(true));
        }
    } else {
        AbstractWidgetGroup widgetGroup = tabWidgets.get(selectedTabIndex);
        containedWidgets.add(widgetGroup);
        containedWidgets.addAll(widgetGroup.getContainedWidgets(false));
    }
    return containedWidgets;
}
Also used : Widget(gregtech.api.gui.Widget) ArrayList(java.util.ArrayList)

Example 9 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class ModularUIGui method updateScreen.

@Override
public void updateScreen() {
    super.updateScreen();
    PacketUIWidgetUpdate packet = queuingWidgetUpdates.poll();
    if (packet != null && packet.windowId == inventorySlots.windowId) {
        Widget<?> widget = modularUI.guiWidgets.get(packet.widgetId);
        int discriminator = packet.updateData.readInt();
        if (widget != null)
            widget.readUpdateInfo(discriminator, packet.updateData);
    }
    modularUI.guiWidgets.values().forEach(Widget::updateScreen);
}
Also used : PacketUIWidgetUpdate(gregtech.api.net.PacketUIWidgetUpdate) Widget(gregtech.api.gui.Widget)

Example 10 with Widget

use of gregtech.api.gui.Widget in project GregTech by GregTechCE.

the class ModularUIContainer method notifyWidgetChange.

// WARNING! WIDGET CHANGES SHOULD BE *STRICTLY* SYNCHRONIZED BETWEEN SERVER AND CLIENT,
// OTHERWISE ID MISMATCH CAN HAPPEN BETWEEN ASSIGNED SLOTS!
@Override
public void notifyWidgetChange() {
    List<INativeWidget> nativeWidgets = modularUI.guiWidgets.values().stream().flatMap(widget -> widget.getNativeWidgets().stream()).collect(Collectors.toList());
    Set<INativeWidget> removedWidgets = new HashSet<>(slotMap.values());
    removedWidgets.removeAll(nativeWidgets);
    if (!removedWidgets.isEmpty()) {
        for (INativeWidget removedWidget : removedWidgets) {
            Slot slotHandle = removedWidget.getHandle();
            this.slotMap.remove(slotHandle);
            // replace removed slot with empty placeholder to avoid list index shift
            EmptySlotPlaceholder emptySlotPlaceholder = new EmptySlotPlaceholder();
            emptySlotPlaceholder.slotNumber = slotHandle.slotNumber;
            this.inventorySlots.set(slotHandle.slotNumber, emptySlotPlaceholder);
            this.inventoryItemStacks.set(slotHandle.slotNumber, ItemStack.EMPTY);
        }
    }
    Set<INativeWidget> addedWidgets = new HashSet<>(nativeWidgets);
    addedWidgets.removeAll(slotMap.values());
    if (!addedWidgets.isEmpty()) {
        int[] emptySlotIndexes = inventorySlots.stream().filter(it -> it instanceof EmptySlotPlaceholder).mapToInt(slot -> slot.slotNumber).toArray();
        int currentIndex = 0;
        for (INativeWidget addedWidget : addedWidgets) {
            Slot slotHandle = addedWidget.getHandle();
            // add or replace empty slot in inventory
            this.slotMap.put(slotHandle, addedWidget);
            if (currentIndex < emptySlotIndexes.length) {
                int slotIndex = emptySlotIndexes[currentIndex++];
                slotHandle.slotNumber = slotIndex;
                this.inventorySlots.set(slotIndex, slotHandle);
                this.inventoryItemStacks.set(slotIndex, ItemStack.EMPTY);
            } else {
                slotHandle.slotNumber = this.inventorySlots.size();
                this.inventorySlots.add(slotHandle);
                this.inventoryItemStacks.add(ItemStack.EMPTY);
            }
        }
    }
}
Also used : INativeWidget(gregtech.api.gui.INativeWidget) WidgetUIAccess(gregtech.api.gui.widgets.WidgetUIAccess) java.util(java.util) PacketUIWidgetUpdate(gregtech.api.net.PacketUIWidgetUpdate) Collectors(java.util.stream.Collectors) Unpooled(io.netty.buffer.Unpooled) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Consumer(java.util.function.Consumer) ItemStack(net.minecraft.item.ItemStack) Widget(gregtech.api.gui.Widget) PacketUIClientAction(gregtech.api.net.PacketUIClientAction) EntityPlayer(net.minecraft.entity.player.EntityPlayer) NetworkHandler(gregtech.api.net.NetworkHandler) ModularUI(gregtech.api.gui.ModularUI) PerTickIntCounter(gregtech.api.util.PerTickIntCounter) net.minecraft.inventory(net.minecraft.inventory) SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) GTUtility(gregtech.api.util.GTUtility) PacketBuffer(net.minecraft.network.PacketBuffer) SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) INativeWidget(gregtech.api.gui.INativeWidget)

Aggregations

Widget (gregtech.api.gui.Widget)20 INativeWidget (gregtech.api.gui.INativeWidget)9 Position (gregtech.api.util.Position)4 Consumer (java.util.function.Consumer)3 ScrollableListWidget (gregtech.api.gui.widgets.ScrollableListWidget)2 SlotWidget (gregtech.api.gui.widgets.SlotWidget)2 TankWidget (gregtech.api.gui.widgets.TankWidget)2 PacketUIWidgetUpdate (gregtech.api.net.PacketUIWidgetUpdate)2 Size (gregtech.api.util.Size)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 FluidTankList (gregtech.api.capability.impl.FluidTankList)1 GuiTextures (gregtech.api.gui.GuiTextures)1 IRenderContext (gregtech.api.gui.IRenderContext)1 ModularUI (gregtech.api.gui.ModularUI)1 IGhostIngredientTarget (gregtech.api.gui.igredient.IGhostIngredientTarget)1 IIngredientSlot (gregtech.api.gui.igredient.IIngredientSlot)1 IRecipeTransferHandlerWidget (gregtech.api.gui.igredient.IRecipeTransferHandlerWidget)1 LabelWidget (gregtech.api.gui.widgets.LabelWidget)1