Search in sources :

Example 6 with AbstractApplication

use of gregtech.api.terminal.app.AbstractApplication in project GregTech by GregTechCEu.

the class WorldProspectorARApp method initApp.

@Override
public AbstractApplication initApp() {
    addWidget(new ImageWidget(10, 10, 313, 212, new ColorRectTexture(TerminalTheme.COLOR_B_2.getColor())));
    addWidget(new LabelWidget(15 + 150 / 2, 232 / 2, "terminal.world_prospector.radius", -1, new Object[] { getMaxRadius() }).setShadow(true).setYCentered(true).setXCentered(true));
    int slotSize = (int) Math.pow(2, getAppTier());
    int x = 250 - slotSize * 12;
    int y = 232 / 2 - 18;
    handlers = new SingleItemStackHandler[slotSize];
    colors = new int[slotSize];
    for (int i = 0; i < slotSize; i++) {
        int index = i;
        Tuple<ItemStack, Integer> stack = getSlotStack(i);
        if (stack == null) {
            handlers[i] = new SingleItemStackHandler(ItemStack.EMPTY);
            colors[i] = 0;
        } else {
            handlers[i] = new SingleItemStackHandler(stack.getFirst());
            colors[i] = stack.getSecond();
        }
        RectButtonWidget buttonWidget = new RectButtonWidget(x + i * 24, y + 18, 18, 18, 1);
        addWidget(new PhantomSlotWidget(handlers[i], 0, x + i * 24, y) {

            @Override
            public boolean mouseClicked(int mouseX, int mouseY, int button) {
                if (handlers[index].getStackInSlot(0).isEmpty() && isMouseOverElement(mouseX, mouseY)) {
                    writeClientAction(-1, buffer -> {
                    });
                    selectReference(index, buttonWidget);
                    return true;
                }
                return super.mouseClicked(mouseX, mouseY, button);
            }

            @Override
            public void handleClientAction(int id, PacketBuffer buffer) {
                if (id == -1) {
                    selectReference(index, buttonWidget);
                } else {
                    super.handleClientAction(id, buffer);
                }
            }
        }.setBackgroundTexture(new ColorRectTexture(0x4fffffff)));
        addWidget(buttonWidget.setHoverText("terminal.world_prospector.color").setColors(0x4fffffff, -1, colors[i]).setClickListener(cd -> TerminalDialogWidget.showColorDialog(getOs(), "terminal.world_prospector.color", res -> {
            if (res != null) {
                buttonWidget.setFill(res | 0xff000000);
                colors[index] = res | 0xff000000;
            }
        }, colors[index]).open()));
    }
    addWidget(new CircleButtonWidget(333 / 2, 200).setClickListener(cd -> openAR()).setHoverText("terminal.ar.open").setColors(0, -1, TerminalTheme.COLOR_B_3.getColor()).setIcon(new ItemStackTexture(MetaItems.CAMERA.getStackForm())));
    return this;
}
Also used : java.util(java.util) IRenderContext(gregtech.api.gui.IRenderContext) Blocks(net.minecraft.init.Blocks) MetaItems(gregtech.common.items.MetaItems) BlockStateMatcher(gregtech.common.terminal.app.worldprospector.matcher.BlockStateMatcher) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TerminalTheme(gregtech.api.terminal.os.TerminalTheme) TerminalDialogWidget(gregtech.api.terminal.os.TerminalDialogWidget) RenderWorldLastEvent(net.minecraftforge.client.event.RenderWorldLastEvent) ItemStackTexture(gregtech.api.gui.resources.ItemStackTexture) ImageWidget(gregtech.api.gui.widgets.ImageWidget) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) ShaderTexture(gregtech.api.gui.resources.ShaderTexture) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) RenderBufferHelper(gregtech.client.utils.RenderBufferHelper) GL11(org.lwjgl.opengl.GL11) Shaders(gregtech.client.shader.Shaders) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) PhantomSlotWidget(gregtech.api.gui.widgets.PhantomSlotWidget) IMatcher(gregtech.common.terminal.app.worldprospector.matcher.IMatcher) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) DepthTextureUtil(gregtech.client.utils.DepthTextureUtil) Entity(net.minecraft.entity.Entity) BlockFalling(net.minecraft.block.BlockFalling) World(net.minecraft.world.World) GlStateManager(net.minecraft.client.renderer.GlStateManager) Tuple(net.minecraft.util.Tuple) ColorRectTexture(gregtech.api.gui.resources.ColorRectTexture) BlockPos(net.minecraft.util.math.BlockPos) LabelWidget(gregtech.api.gui.widgets.LabelWidget) ARApplication(gregtech.api.terminal.app.ARApplication) Framebuffer(net.minecraft.client.shader.Framebuffer) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) RectButtonWidget(gregtech.api.terminal.gui.widgets.RectButtonWidget) Tessellator(net.minecraft.client.renderer.Tessellator) SingleItemStackHandler(gregtech.common.inventory.handlers.SingleItemStackHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MathHelper(net.minecraft.util.math.MathHelper) CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget) ItemBlock(net.minecraft.item.ItemBlock) PacketBuffer(net.minecraft.network.PacketBuffer) ItemStackTexture(gregtech.api.gui.resources.ItemStackTexture) CircleButtonWidget(gregtech.api.terminal.gui.widgets.CircleButtonWidget) ColorRectTexture(gregtech.api.gui.resources.ColorRectTexture) SingleItemStackHandler(gregtech.common.inventory.handlers.SingleItemStackHandler) PhantomSlotWidget(gregtech.api.gui.widgets.PhantomSlotWidget) LabelWidget(gregtech.api.gui.widgets.LabelWidget) ImageWidget(gregtech.api.gui.widgets.ImageWidget) ItemStack(net.minecraft.item.ItemStack) PacketBuffer(net.minecraft.network.PacketBuffer) RectButtonWidget(gregtech.api.terminal.gui.widgets.RectButtonWidget)

Example 7 with AbstractApplication

use of gregtech.api.terminal.app.AbstractApplication in project GregTech by GregTechCEu.

the class HardwareManagerApp method initApp.

@Override
public AbstractApplication initApp() {
    apps = new WidgetGroup();
    this.addWidget(apps);
    int x = 10;
    int y = 65;
    for (Hardware hardware : os.hardwareProvider.getProviders().values()) {
        HardwareSlotWidget hardwareSlotWidget = new HardwareSlotWidget(x, y, os, hardware);
        this.addWidget(hardwareSlotWidget);
        hardwareSlotWidget.setOnSelected(() -> {
            selected = hardwareSlotWidget;
            apps.clearAllWidgets();
            AtomicInteger index = new AtomicInteger(0);
            for (AbstractApplication installed : getOs().installedApps) {
                TerminalRegistry.getAppHardwareDemand(installed.getRegistryName(), getOs().tabletNBT.getCompoundTag(installed.getRegistryName()).getInteger("_tier")).stream().filter(hardware::isHardwareAdequate).findFirst().ifPresent(X -> {
                    apps.addWidget(new RectButtonWidget(162 + (index.get() % 4) * 25, 122 + (index.get() / 4) * 30, 20, 20, 2).setIcon(installed.getIcon()).setHoverText(installed.getUnlocalizedName()).setColors(0, TerminalTheme.COLOR_7.getColor(), 0));
                    index.getAndIncrement();
                });
            }
        });
        x += 25;
    }
    return this;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) WidgetGroup(gregtech.api.gui.widgets.WidgetGroup) Hardware(gregtech.api.terminal.hardware.Hardware) RectButtonWidget(gregtech.api.terminal.gui.widgets.RectButtonWidget)

Example 8 with AbstractApplication

use of gregtech.api.terminal.app.AbstractApplication in project GregTech by GregTechCEu.

the class TerminalOSWidget method handleClientAction.

@Override
public void handleClientAction(int id, PacketBuffer buffer) {
    if (id == -1) {
        // shutdown
        NBTTagCompound nbt = null;
        try {
            nbt = buffer.readCompoundTag();
        } catch (IOException e) {
            e.printStackTrace();
        }
        for (AbstractApplication openedApp : openedApps) {
            String appName = openedApp.getRegistryName();
            NBTTagCompound data = openedApp.closeApp();
            if (data != null && !data.isEmpty()) {
                tabletNBT.setTag(appName, data);
            } else if (nbt != null && openedApp.isClientSideApp() && nbt.hasKey(appName)) {
                tabletNBT.setTag(appName, nbt.getCompoundTag(appName));
            }
        }
        // must close tablet from server side.
        this.getModularUI().entityPlayer.closeScreen();
    } else if (id == -2) {
        // closeApp sync
        String appName = buffer.readString(32767);
        NBTTagCompound nbt = null;
        try {
            nbt = buffer.readCompoundTag();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (nbt != null) {
            tabletNBT.setTag(appName, nbt);
        }
    } else {
        super.handleClientAction(id, buffer);
    }
}
Also used : AbstractApplication(gregtech.api.terminal.app.AbstractApplication) IOException(java.io.IOException)

Example 9 with AbstractApplication

use of gregtech.api.terminal.app.AbstractApplication in project GregTech by GregTechCEu.

the class TerminalOSWidget method disCharge.

private long disCharge() {
    IElectricItem electricItem = hardwareProvider.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
    if (electricItem != null && !TerminalBehaviour.isCreative(itemStack)) {
        AtomicLong costs = new AtomicLong(0);
        List<AbstractApplication> charged = new ArrayList<>();
        for (AbstractApplication openedApp : openedApps) {
            TerminalRegistry.getAppHardwareDemand(openedApp.getRegistryName(), openedApp.getAppTier()).stream().filter(i -> i instanceof BatteryHardware).findFirst().ifPresent(battery -> {
                costs.addAndGet(((BatteryHardware) battery).getCharge());
                charged.add(openedApp);
            });
        }
        for (DeviceHardware hardware : getHardware(DeviceHardware.class)) {
            if (hardware.getDevice() == DeviceHardware.DEVICE.SOLAR_LV) {
                costs.addAndGet(-200);
            }
        }
        if (costs.get() > 0 && electricItem.discharge(costs.get(), 999, true, false, false) != costs.get()) {
            charged.forEach(app -> closeApplication(app, false));
        } else if (costs.get() < 0) {
            electricItem.charge(-costs.get(), 999, true, false);
        }
        return electricItem.getCharge();
    }
    return lastCharge;
}
Also used : IElectricItem(gregtech.api.capability.IElectricItem) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) ArrayList(java.util.ArrayList) DeviceHardware(gregtech.common.terminal.hardware.DeviceHardware)

Example 10 with AbstractApplication

use of gregtech.api.terminal.app.AbstractApplication in project GregTech by GregTechCEu.

the class TerminalOSWidget method shutdown.

public void shutdown(boolean isClient) {
    if (isClient) {
        NBTTagCompound nbt = new NBTTagCompound();
        for (AbstractApplication openedApp : openedApps) {
            String appName = openedApp.getRegistryName();
            NBTTagCompound synced = openedApp.closeApp();
            if (synced != null && !synced.isEmpty()) {
                tabletNBT.setTag(appName, synced);
                if (openedApp.isClientSideApp()) {
                    // if its a clientSideApp and the nbt not null, meaning this nbt should be synced to the server side.
                    nbt.setTag(appName, synced);
                }
            }
        }
        writeClientAction(-1, buffer -> buffer.writeCompoundTag(nbt));
    } else {
        // request shutdown from the server side
        writeUpdateInfo(-2, packetBuffer -> {
        });
    }
}
Also used : AbstractApplication(gregtech.api.terminal.app.AbstractApplication)

Aggregations

AbstractApplication (gregtech.api.terminal.app.AbstractApplication)14 ImageWidget (gregtech.api.gui.widgets.ImageWidget)5 LabelWidget (gregtech.api.gui.widgets.LabelWidget)5 RectButtonWidget (gregtech.api.terminal.gui.widgets.RectButtonWidget)5 ColorRectTexture (gregtech.api.gui.resources.ColorRectTexture)4 TerminalTheme (gregtech.api.terminal.os.TerminalTheme)4 IElectricItem (gregtech.api.capability.IElectricItem)3 IRenderContext (gregtech.api.gui.IRenderContext)3 WidgetGroup (gregtech.api.gui.widgets.WidgetGroup)3 ARApplication (gregtech.api.terminal.app.ARApplication)3 BatteryHardware (gregtech.common.terminal.hardware.BatteryHardware)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 GuiTextures (gregtech.api.gui.GuiTextures)2 Widget (gregtech.api.gui.Widget)2 ShaderTexture (gregtech.api.gui.resources.ShaderTexture)2 TextTexture (gregtech.api.gui.resources.TextTexture)2 TextureArea (gregtech.api.gui.resources.TextureArea)2 DraggableScrollableWidgetGroup (gregtech.api.terminal.gui.widgets.DraggableScrollableWidgetGroup)2 Hardware (gregtech.api.terminal.hardware.Hardware)2 TerminalDialogWidget (gregtech.api.terminal.os.TerminalDialogWidget)2