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