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();
}
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);
}
}
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;
}
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);
}
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);
}
}
}
}
Aggregations