Search in sources :

Example 1 with AbstractApplication

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

the class TerminalOSWidget method openApplication.

public void openApplication(AbstractApplication application, boolean isClient) {
    desktop.removeAllDialogs();
    NBTTagCompound nbt = tabletNBT.getCompoundTag(application.getRegistryName());
    if (!TerminalBehaviour.isCreative(itemStack)) {
        List<Hardware> hwDemand = TerminalRegistry.getAppHardwareDemand(application.getRegistryName(), Math.min(nbt.getInteger("_tier"), application.getMaxTier()));
        List<Hardware> unMatch = hwDemand.stream().filter(demand -> getHardware().stream().noneMatch(hw -> hw.isHardwareAdequate(demand))).collect(Collectors.toList());
        if (unMatch.size() > 0) {
            if (isClient) {
                StringBuilder tooltips = new StringBuilder("\n");
                for (Hardware match : unMatch) {
                    String info = match.addInformation();
                    String name = match.getLocalizedName();
                    if (info == null) {
                        tooltips.append(name);
                    } else if (match instanceof BatteryHardware) {
                        IElectricItem energyItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
                        if (energyItem != null && energyItem.getCharge() <= 0) {
                            tooltips.append(I18n.format("terminal.battery.low_energy"));
                        } else {
                            tooltips.append(String.format("%s (%s+)", name, info));
                        }
                    } else {
                        tooltips.append(String.format("%s (%s)", name, info));
                    }
                    tooltips.append(" ");
                }
                TerminalDialogWidget.showInfoDialog(this, "terminal.component.error", I18n.format("terminal.os.hw_demand") + tooltips).setClientSide().open();
            }
            return;
        }
    }
    if (!application.canPlayerUse(gui.entityPlayer)) {
        return;
    }
    if (focusApp != null) {
        closeApplication(focusApp, isClient);
    }
    for (AbstractApplication app : openedApps) {
        if (app.getRegistryName().equals(application.getRegistryName()) && application.canLaunchConcurrently(app)) {
            app.onOSSizeUpdate(this.getSize().width, this.getSize().height);
            maximizeApplication(app, isClient);
            return;
        }
    }
    AbstractApplication app = application.createAppInstance(this, isClient, nbt);
    if (app != null) {
        desktop.addWidget(app);
        app.setOs(this).initApp();
        app.onOSSizeUpdate(this.getSize().width, this.getSize().height);
        openedApps.add(app);
        maximizeApplication(app, isClient);
    }
}
Also used : AbstractWidgetGroup(gregtech.api.gui.widgets.AbstractWidgetGroup) IRenderContext(gregtech.api.gui.IRenderContext) Size(gregtech.api.util.Size) Constants(net.minecraftforge.common.util.Constants) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) ArrayList(java.util.ArrayList) TerminalRegistry(gregtech.api.terminal.TerminalRegistry) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) Widget(gregtech.api.gui.Widget) Minecraft(net.minecraft.client.Minecraft) RenderUtil(gregtech.client.utils.RenderUtil) net.minecraft.nbt(net.minecraft.nbt) LinkedList(java.util.LinkedList) TerminalBehaviour(gregtech.common.items.behaviors.TerminalBehaviour) DeviceHardware(gregtech.common.terminal.hardware.DeviceHardware) HardwareProvider(gregtech.api.terminal.hardware.HardwareProvider) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) Hardware(gregtech.api.terminal.hardware.Hardware) Collectors(java.util.stream.Collectors) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) IElectricItem(gregtech.api.capability.IElectricItem) AtomicLong(java.util.concurrent.atomic.AtomicLong) Position(gregtech.api.util.Position) List(java.util.List) GregtechCapabilities(gregtech.api.capability.GregtechCapabilities) TextureArea(gregtech.api.gui.resources.TextureArea) TerminalMenuWidget(gregtech.api.terminal.os.menu.TerminalMenuWidget) IGuiTexture(gregtech.api.gui.resources.IGuiTexture) ModularUI(gregtech.api.gui.ModularUI) Collections(java.util.Collections) OsSettings(gregtech.common.terminal.app.settings.widgets.OsSettings) PacketBuffer(net.minecraft.network.PacketBuffer) IElectricItem(gregtech.api.capability.IElectricItem) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) DeviceHardware(gregtech.common.terminal.hardware.DeviceHardware) Hardware(gregtech.api.terminal.hardware.Hardware)

Example 2 with AbstractApplication

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

the class TerminalOSWidget method readUpdateInfo.

@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
    if (id == -1) {
        // disCharge
        long charge = buffer.readLong();
        IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
        if (electricItem instanceof BatteryHardware) {
            ((BatteryHardware) electricItem).setCharge(charge);
        }
        if (charge <= 0) {
            List<AbstractApplication> toClosed = new LinkedList<>();
            for (AbstractApplication openedApp : openedApps) {
                TerminalRegistry.getAppHardwareDemand(openedApp.getRegistryName(), openedApp.getAppTier()).stream().filter(i -> i instanceof BatteryHardware).findFirst().ifPresent(x -> toClosed.add(openedApp));
            }
            for (AbstractApplication close : toClosed) {
                this.closeApplication(close, true);
            }
            TerminalDialogWidget.showInfoDialog(this, "terminal.component.warning", "terminal.battery.low_energy").setClientSide().open();
        }
    } else if (id == -2) {
        // shutdown
        shutdown(true);
    } else {
        super.readUpdateInfo(id, buffer);
    }
}
Also used : IElectricItem(gregtech.api.capability.IElectricItem) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) LinkedList(java.util.LinkedList)

Example 3 with AbstractApplication

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

the class GuideConfigEditor method loadJson.

public void loadJson() {
    if (pageEditor != null) {
        File file = new File(TerminalRegistry.TERMINAL_PATH, "guide");
        TerminalDialogWidget.showFileDialog(app.getOs(), "terminal.component.load_file", file, true, result -> {
            if (result != null && result.isFile()) {
                try {
                    JsonObject config = Objects.requireNonNull(FileUtility.loadJson(result)).getAsJsonObject();
                    pageEditor.loadJsonConfig(config);
                    getPageEditor().setSection(config.get("section").getAsString());
                    updateTitle(config.get("title").getAsString());
                    for (AbstractApplication app : TerminalRegistry.getAllApps()) {
                        if (app instanceof GuideApp) {
                            Object object = ((GuideApp<?>) app).ofJson(config);
                            if (object != null) {
                                type = app.getUnlocalizedName();
                                if (object instanceof ItemGuideApp.GuideItem) {
                                    handler.setStackInSlot(0, ((ItemGuideApp.GuideItem) object).stack.copy());
                                } else if (object instanceof MetaTileEntity) {
                                    handler.setStackInSlot(0, ((MetaTileEntity) object).getStackForm());
                                } else if (object instanceof ItemStack) {
                                    handler.setStackInSlot(0, ((ItemStack) object).copy());
                                } else {
                                    handler.setStackInSlot(0, ItemStack.EMPTY);
                                }
                                break;
                            }
                        }
                    }
                } catch (Exception e) {
                    TerminalDialogWidget.showInfoDialog(app.getOs(), "terminal.component.error", "terminal.component.load_file.error").setClientSide().open();
                }
            }
        }).setClientSide().open();
    }
}
Also used : AbstractApplication(gregtech.api.terminal.app.AbstractApplication) JsonObject(com.google.gson.JsonObject) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) JsonObject(com.google.gson.JsonObject) MultiBlockGuideApp(gregtech.common.terminal.app.guide.MultiBlockGuideApp) SimpleMachineGuideApp(gregtech.common.terminal.app.guide.SimpleMachineGuideApp) GuideApp(gregtech.common.terminal.app.guide.GuideApp) ItemGuideApp(gregtech.common.terminal.app.guide.ItemGuideApp) ItemStack(net.minecraft.item.ItemStack) File(java.io.File)

Example 4 with AbstractApplication

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

the class BatteryManagerApp method addBatteryApps.

private void addBatteryApps() {
    AtomicInteger index = new AtomicInteger();
    for (AbstractApplication installed : getOs().installedApps) {
        TerminalRegistry.getAppHardwareDemand(installed.getRegistryName(), getOs().tabletNBT.getCompoundTag(installed.getRegistryName()).getInteger("_tier")).stream().filter(i -> i instanceof BatteryHardware).findFirst().ifPresent(battery -> {
            long charge = ((BatteryHardware) battery).getCharge();
            this.addWidget(new RectButtonWidget(180 + (index.get() % 5) * 30, 15 + (index.get() / 5) * 30, 20, 20, 2).setIcon(installed.getIcon()).setHoverText(I18n.format("terminal.battery.hover", I18n.format(installed.getUnlocalizedName()), charge)).setColors(0, TerminalTheme.COLOR_7.getColor(), 0));
            index.getAndIncrement();
        });
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) BatteryHardware(gregtech.common.terminal.hardware.BatteryHardware) RectButtonWidget(gregtech.api.terminal.gui.widgets.RectButtonWidget)

Example 5 with AbstractApplication

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

the class MultiBlockPreviewARApp method initApp.

@Override
public AbstractApplication initApp() {
    // 232 333
    int bW = 120;
    int bH = 120;
    addWidget(new ImageWidget(10, 10, 313, 212, new ColorRectTexture(TerminalTheme.COLOR_B_2.getColor())));
    addWidget(new ImageWidget(333 / 2, 20, 1, 222 - 40, new ColorRectTexture(-1)));
    addWidget(new LabelWidget(10 + 313 / 4, 35, "terminal.multiblock_ar.tier.0", -1).setXCentered(true).setYCentered(true));
    addWidget(new RectButtonWidget(10 + (313 / 2 - bW) / 2, 50, bW, bH).setIcon(TextureArea.fullImage("textures/gui/terminal/multiblock_ar/profile.png")).setColors(-1, 0xff00ff00, 0).setHoverText("terminal.ar.open").setClickListener(clickData -> openAR()));
    addWidget(new LabelWidget(333 / 2 + 313 / 4, 35, "terminal.multiblock_ar.tier.1", getAppTier() == 0 ? 0xffff0000 : -1).setXCentered(true).setYCentered(true));
    addWidget(new RectButtonWidget(333 / 2 + (313 / 2 - bW) / 2, 50, bW, bH).setIcon(this::drawBuilderButton).setColors(getAppTier() == 0 ? 0xffff0000 : -1, getAppTier() == 0 ? 0xffff0000 : 0xff00ff00, 0).setHoverText(getAppTier() > 0 ? "terminal.multiblock_ar.builder.hover" : "terminal.multiblock_ar.unlock").setClickListener(clickData -> buildMode()));
    return this;
}
Also used : MultiblockShapeInfo(gregtech.api.pattern.MultiblockShapeInfo) java.util(java.util) IRenderContext(gregtech.api.gui.IRenderContext) TerminalTheme(gregtech.api.terminal.os.TerminalTheme) TerminalDialogWidget(gregtech.api.terminal.os.TerminalDialogWidget) RenderWorldLastEvent(net.minecraftforge.client.event.RenderWorldLastEvent) ImageWidget(gregtech.api.gui.widgets.ImageWidget) ConfigHolder(gregtech.common.ConfigHolder) MachineSceneWidget(gregtech.api.terminal.gui.widgets.MachineSceneWidget) ShaderTexture(gregtech.api.gui.resources.ShaderTexture) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) RenderUtil(gregtech.client.utils.RenderUtil) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) GL13(org.lwjgl.opengl.GL13) GL11(org.lwjgl.opengl.GL11) Shaders(gregtech.client.shader.Shaders) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) GLAllocation(net.minecraft.client.renderer.GLAllocation) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) WidgetGroup(gregtech.api.gui.widgets.WidgetGroup) GlStateManager(net.minecraft.client.renderer.GlStateManager) TextureMap(net.minecraft.client.renderer.texture.TextureMap) ColorRectTexture(gregtech.api.gui.resources.ColorRectTexture) BlockPos(net.minecraft.util.math.BlockPos) LabelWidget(gregtech.api.gui.widgets.LabelWidget) MultiblockPreviewRenderer(gregtech.client.renderer.handler.MultiblockPreviewRenderer) GuiTextures(gregtech.api.gui.GuiTextures) ARApplication(gregtech.api.terminal.app.ARApplication) AbstractApplication(gregtech.api.terminal.app.AbstractApplication) RectButtonWidget(gregtech.api.terminal.gui.widgets.RectButtonWidget) TextureArea(gregtech.api.gui.resources.TextureArea) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntity(net.minecraft.tileentity.TileEntity) LabelWidget(gregtech.api.gui.widgets.LabelWidget) ColorRectTexture(gregtech.api.gui.resources.ColorRectTexture) ImageWidget(gregtech.api.gui.widgets.ImageWidget) RectButtonWidget(gregtech.api.terminal.gui.widgets.RectButtonWidget)

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