use of gregtech.api.terminal.os.TerminalOSWidget in project GregTech by GregTechCEu.
the class AppPageWidget method updateTerminalAppTier.
private void updateTerminalAppTier(int tier, int lastTier) {
TerminalOSWidget os = store.getOs();
os.openedApps.stream().filter(app -> app.getRegistryName().equals(this.application.getRegistryName())).findFirst().ifPresent(app -> os.closeApplication(app, os.isRemote()));
if (lastTier == -1) {
// update terminal
NBTTagList installed = os.tabletNBT.getTagList("_installed", Constants.NBT.TAG_STRING);
installed.appendTag(new NBTTagString(application.getRegistryName()));
os.tabletNBT.setTag("_installed", installed);
os.installApplication(application);
}
NBTTagCompound tag = os.tabletNBT.getCompoundTag(application.getRegistryName());
tag.setInteger("_tier", tier);
os.tabletNBT.setTag(application.getRegistryName(), tag);
lineWidth = 0;
}
use of gregtech.api.terminal.os.TerminalOSWidget in project GregTech by GregTechCEu.
the class AppPageWidget method hookDrawInBackground.
@Override
public void hookDrawInBackground(int mouseX, int mouseY, float partialTicks, IRenderContext context) {
int x = getPosition().x;
int y = getPosition().y;
int width = getSize().width;
int height = getSize().height;
GlStateManager.disableDepth();
drawSolidRect(x, y, width, height, store.darkMode ? 0xcf000000 : 0xdfdddddd);
super.hookDrawInBackground(mouseX, mouseY, partialTicks, context);
int stage;
TerminalOSWidget os = store.getOs();
if (!os.installedApps.contains(application)) {
stage = 0;
} else if (TerminalBehaviour.isCreative(os.itemStack)) {
stage = application.getMaxTier() + 1;
} else {
stage = Math.min(os.tabletNBT.getCompoundTag(application.getRegistryName()).getInteger("_tier"), application.getMaxTier()) + 1;
}
int maxStage = application.getMaxTier() + 1;
int color = application.getThemeColor();
int lightColor = color & 0x00ffffff | ((0x6f) << 24);
int dur = 323 / (maxStage + 1);
int hover = -1;
for (int i = 0; i < buttons.length; i++) {
if (buttons[i].isMouseOverElement(mouseX, mouseY)) {
hover = i;
}
}
// draw current tier
drawSolidRect(x, y + 110 - 2, dur * stage, 4, color);
if (stage == maxStage) {
drawSolidRect(x + stage * dur, y + 110 - 2, dur, 4, color);
} else {
drawSolidRect(x + stage * dur, y + 110 - 2, dur, 4, lightColor);
}
int end = dur * (hover + 1 - stage);
if (hover + 1 > stage) {
if (lineWidth != end && (interpolator == null || back)) {
back = false;
interpolator = new Interpolator(lineWidth, end, (end - lineWidth) / 15, Eases.EaseLinear, value -> lineWidth = value.intValue(), value -> interpolator = null);
interpolator.start();
}
} else {
if (lineWidth != 0 && (interpolator == null || !back)) {
back = true;
interpolator = new Interpolator(lineWidth, 0, lineWidth / 15, Eases.EaseLinear, value -> lineWidth = value.intValue(), value -> interpolator = null);
interpolator.start();
}
}
if (lineWidth != 0) {
int smoothWidth = lineWidth;
if (hover + 1 > stage) {
if (lineWidth != end) {
smoothWidth += partialTicks * end / 10;
}
} else {
smoothWidth -= partialTicks * end / 10;
}
drawSolidRect(x + stage * dur, y + 110 - 2, smoothWidth, 4, color);
}
// description
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
List<String> description = fr.listFormattedStringToWidth(application.getDescription(), 210);
int fColor = store.darkMode ? -1 : 0xff333333;
String localizedName = I18n.format(application.getUnlocalizedName());
drawStringSized(localizedName, x + 100, y + 14, fColor, store.darkMode, 2, false);
if (isMouseOver(x + 100, y + 14, fr.getStringWidth(localizedName) * 2, fr.FONT_HEIGHT * 2, mouseX, mouseY)) {
drawHoveringText(ItemStack.EMPTY, Collections.singletonList("(" + application.getRegistryName() + ")"), 200, mouseX, mouseY);
}
for (int i = 0; i < description.size(); i++) {
fr.drawString(description.get(i), x + 100, y + 35 + i * fr.FONT_HEIGHT, fColor, store.darkMode);
}
drawBorder(x + 10, y + 15, 80, 80, store.darkMode ? -1 : 0xff333333, 2);
GlStateManager.enableDepth();
}
use of gregtech.api.terminal.os.TerminalOSWidget in project GregTech by GregTechCEu.
the class AppPageWidget method buttonClicked.
private void buttonClicked(int tier) {
int lastTier;
TerminalOSWidget os = store.getOs();
if (!os.installedApps.contains(application)) {
lastTier = -1;
} else if (TerminalBehaviour.isCreative(os.itemStack)) {
lastTier = application.getMaxTier();
} else {
lastTier = Math.min(os.tabletNBT.getCompoundTag(application.getRegistryName()).getInteger("_tier"), application.getMaxTier());
}
String name = application.getRegistryName();
if (tier > lastTier) {
// inventory match
boolean match = true;
List<ItemStack> requirements = new ArrayList<>();
ItemStack missStack = null;
if (!gui.entityPlayer.isCreative()) {
for (int i = lastTier + 1; i <= tier; i++) {
for (ItemStack condition : TerminalRegistry.getAppHardwareUpgradeConditions(name, i)) {
boolean miss = true;
for (ItemStack requirement : requirements) {
if (requirement.isItemEqual(condition)) {
requirement.setCount(requirement.getCount() + condition.getCount());
miss = false;
break;
}
}
if (miss) {
requirements.add(condition.copy());
}
}
}
for (ItemStack requirement : requirements) {
int left = requirement.getCount();
for (ItemStack hold : gui.entityPlayer.inventory.mainInventory) {
if (requirement.isItemEqual(hold)) {
if (hold.getCount() < left) {
left -= hold.getCount();
} else {
left = 0;
}
if (left == 0) {
break;
}
}
}
if (left > 0) {
missStack = requirement.copy();
missStack.setCount(left);
match = false;
break;
}
}
}
if (match) {
if (os.isRemote()) {
appCardWidget.updateState(tier == application.getMaxTier() ? 0 : 1);
}
if (!gui.entityPlayer.isCreative()) {
// cost
TerminalDialogWidget.showConfirmDialog(store.getOs(), "terminal.dialog.notice", "terminal.store.match", res -> {
if (res) {
for (ItemStack requirement : requirements) {
int left = requirement.getCount();
for (ItemStack hold : gui.entityPlayer.inventory.mainInventory) {
if (requirement.isItemEqual(hold)) {
if (hold.getCount() <= left) {
hold.setCount(0);
left -= hold.getCount();
} else {
hold.setCount(hold.getCount() - left);
left = 0;
}
if (left == 0) {
break;
}
}
}
}
updateTerminalAppTier(tier, lastTier);
}
}).open();
} else {
updateTerminalAppTier(tier, lastTier);
}
} else {
if (isRemote()) {
TerminalDialogWidget.showInfoDialog(store.getOs(), "terminal.dialog.notice", I18n.format("terminal.store.miss", missStack.getDisplayName(), missStack.getCount())).setClientSide().open();
}
}
}
}
Aggregations