use of gregtech.api.util.interpolate.Interpolator in project GregTech by GregTechCEu.
the class GuidePageEditorWidget method moveDown.
public void moveDown(Widget widget) {
int index = stream.indexOf(widget);
if (index >= 0 && index < stream.size() - 1) {
Widget target = stream.get(index + 1);
if (interpolator == null) {
int offsetD = 5 + target.getSize().height;
int offsetU = target.getPosition().y - widget.getPosition().y;
int y1 = widget.getSelfPosition().y;
int y2 = target.getSelfPosition().y;
interpolator = new Interpolator(0, 1, 10, Eases.EaseLinear, value -> {
widget.setSelfPosition(new Position(widget.getSelfPosition().x, (int) (y1 + value.floatValue() * offsetD)));
target.setSelfPosition(new Position(target.getSelfPosition().x, (int) (y2 - value.floatValue() * offsetU)));
if (widget == selected) {
setToolButton(selected);
}
widget.setVisible(widget.getSelfPosition().y < getSize().height - xBarHeight && widget.getSelfPosition().y + widget.getSize().height > 0);
target.setVisible(target.getSelfPosition().y < getSize().height - xBarHeight && target.getSelfPosition().y + target.getSize().height > 0);
}, value -> {
interpolator = null;
stream.remove(widget);
stream.add(index + 1, widget);
}).start();
}
} else {
int index2 = fixed.indexOf(widget);
if (index2 > 0) {
Widget target = fixed.get(index2 - 1);
fixed.remove(widget);
fixed.add(index2 - 1, widget);
}
}
}
use of gregtech.api.util.interpolate.Interpolator in project GregTech by GregTechCEu.
the class TerminalMenuWidget method hideMenu.
@SideOnly(Side.CLIENT)
public void hideMenu() {
if (!isHide && interpolator == null) {
int y = getSelfPosition().y;
interpolator = new Interpolator(getSelfPosition().x, getSelfPosition().x - getSize().width, 6, Eases.EaseLinear, value -> setSelfPosition(new Position(value.intValue(), y)), value -> {
setVisible(false);
interpolator = null;
isHide = true;
});
interpolator.start();
os.desktop.removeTopWidget(this);
}
}
use of gregtech.api.util.interpolate.Interpolator in project GregTech by GregTechCEu.
the class AppCardWidget method hookDrawInForeground.
@Override
public void hookDrawInForeground(int mouseX, int mouseY) {
// hover
int x = getPosition().x;
int y = getPosition().y;
int width = getSize().width;
int height = getSize().height;
if (isMouseOverElement(mouseX, mouseY) && store.getOs().desktop.widgets.stream().noneMatch(app -> app instanceof TerminalDialogWidget)) {
int dur = 7;
// 0-255!!!!!
int maxAlpha = 100;
float partialTicks = Minecraft.getMinecraft().getRenderPartialTicks();
if (alpha != maxAlpha && interpolator == null) {
interpolator = new Interpolator(0, maxAlpha, dur, Eases.EaseLinear, value -> alpha = value.intValue(), value -> interpolator = null);
interpolator.start();
}
// smooth
int color;
if (alpha == maxAlpha) {
color = TerminalTheme.COLOR_B_2.getColor() & 0x00ffffff | ((alpha) << 24);
} else {
color = TerminalTheme.COLOR_B_2.getColor() & 0x00ffffff | ((alpha + (int) (maxAlpha * partialTicks / dur)) << 24);
}
int finalColor = color;
RenderUtil.useScissor(store.getPosition().x, store.getPosition().y, store.getSize().width, store.getSize().height, () -> {
drawSolidRect(0, 0, gui.getScreenWidth(), y, finalColor);
drawSolidRect(0, y + height, gui.getScreenWidth(), gui.getScreenHeight(), finalColor);
drawSolidRect(0, y, x, height, finalColor);
drawSolidRect(x + width, y, gui.getScreenWidth(), height, finalColor);
drawBorder(x, y, width, height, application.getThemeColor(), -1);
});
} else {
alpha = 0;
}
super.hookDrawInForeground(mouseX, mouseY);
}
use of gregtech.api.util.interpolate.Interpolator 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();
}
Aggregations