use of com.teamwizardry.librarianlib.features.gui.mixin.DragMixin in project Wizardry by TeamWizardry.
the class WorktableGui method load.
public void load() {
TileEntity tile = Minecraft.getMinecraft().world.getTileEntity(pos);
if (tile instanceof TileMagiciansWorktable) {
if (((TileMagiciansWorktable) tile).commonModules != null) {
Set<CommonWorktableModule> commonModules = ((TileMagiciansWorktable) tile).getCommonModules();
for (CommonWorktableModule commonHead : commonModules) {
if (commonHead != null) {
// ADDED HERE
CommonWorktableModule commonModule = commonHead;
TableModule lastModule = new TableModule(this, commonHead.module, true, false);
lastModule.setPos(commonHead.pos);
while (commonModule != null) {
lastModule.radius = 10;
lastModule.textRadius = 0;
paper.add(lastModule);
DragMixin drag = new DragMixin(lastModule, vec2d -> vec2d);
drag.setDragOffset(new Vec2d(6, 6));
for (ModuleInstanceModifier modifier : commonModule.modifiers.keySet()) {
lastModule.setData(Integer.class, modifier.getNBTKey(), commonModule.modifiers.get(modifier));
}
if (commonModule.linksTo != null) {
if (commonModule.linksTo.module != null) {
TableModule childModule = new TableModule(this, commonModule.linksTo.module, true, false);
childModule.setPos(commonModule.linksTo.pos);
lastModule.setLinksTo(childModule);
lastModule = childModule;
} else {
// If a module was removed from the mod, try and clear the table.
// This doesn't clear the whole table, but it's good enough.
((TileMagiciansWorktable) tile).setCommonModules(new NBTTagList());
syncToServer();
Minecraft.getMinecraft().player.sendMessage(new TextComponentString(TextFormatting.RED + "wizardry.table.no_component_error"));
return;
}
}
commonModule = commonModule.linksTo;
}
}
}
}
}
}
use of com.teamwizardry.librarianlib.features.gui.mixin.DragMixin in project Wizardry by TeamWizardry.
the class WorktableGui method playLoadAnimation.
public void playLoadAnimation(Set<CommonWorktableModule> commonModules, @Nullable Runnable finish) {
animationPlaying = true;
resetSelectedModule();
ComponentVoid bookIconMask = new ComponentVoid(0, -100, 180, 100);
paper.add(bookIconMask);
Vec2d bookOrigin = new Vec2d((bookIconMask.getSize().getX() / 2.0) - 8, -(bookIconMask.getSize().getY() / 2.0) - 4);
Runnable itemsRunnable = () -> {
// PAPER ITEMS ANIMATION
{
for (CommonWorktableModule commonHead : commonModules) {
CommonWorktableModule commonModule = commonHead;
TableModule lastModule = new TableModule(this, commonHead.module, true, false);
lastModule.setPos(commonHead.pos);
while (commonModule != null) {
paper.add(lastModule);
DragMixin drag = new DragMixin(lastModule, vec2d -> vec2d);
drag.setDragOffset(new Vec2d(6, 6));
lastModule.setData(Vec2d.class, "true_pos", commonModule.pos);
for (ModuleInstanceModifier modifier : commonModule.modifiers.keySet()) {
lastModule.setData(Integer.class, modifier.getNBTKey(), commonModule.modifiers.get(modifier));
}
lastModule.radius = 0;
lastModule.textRadius = 0;
if (commonModule.linksTo != null) {
TableModule childModule = new TableModule(this, commonModule.linksTo.module, true, false);
childModule.setPos(bookOrigin);
lastModule.setLinksTo(childModule);
lastModule = childModule;
}
commonModule = commonModule.linksTo;
}
}
for (GuiComponent component : paper.getChildren()) {
if (!(component instanceof TableModule))
continue;
TableModule module = (TableModule) component;
Vec2d target = module.getData(Vec2d.class, "true_pos");
if (target == null) {
module.invalidate();
continue;
}
Vec2d randGen = new Vec2d(RandUtil.nextDouble(-100, 100), RandUtil.nextDouble(-100, 100));
Vec2d random = bookOrigin.add(randGen);
float delay = RandUtil.nextFloat(0.2f, 0.3f);
float dur = RandUtil.nextFloat(70, 100);
ScheduledEventAnimation animSound1 = new ScheduledEventAnimation(dur * delay, () -> Minecraft.getMinecraft().player.playSound(ModSounds.WHOOSH, 1f, 1f));
KeyframeAnimation<TableModule> animX = new KeyframeAnimation<>(module, "pos.x");
animX.setDuration(dur);
animX.setKeyframes(new Keyframe[] { new Keyframe(delay, bookOrigin.getX(), Easing.easeOutQuint), new Keyframe(0.5f, random.getX(), Easing.easeOutQuint), new Keyframe(0.6f, random.getX(), Easing.easeOutQuint), new Keyframe(1f, target.getX(), Easing.easeOutQuint) });
KeyframeAnimation<TableModule> animY = new KeyframeAnimation<>(module, "pos.y");
animY.setDuration(dur);
animY.setKeyframes(new Keyframe[] { new Keyframe(delay, bookOrigin.getY(), Easing.easeOutQuint), new Keyframe(0.5f, random.getY(), Easing.easeOutQuint), new Keyframe(0.6f, random.getY(), Easing.easeOutQuint), new Keyframe(1f, target.getY(), Easing.easeOutQuint) });
animY.setCompletion(() -> {
BasicAnimation<TableModule> animRadius = new BasicAnimation<>(module, "radius");
animRadius.setDuration(20);
animRadius.setEasing(Easing.easeOutCubic);
animRadius.setTo(10);
module.add(animRadius);
BasicAnimation<TableModule> animText = new BasicAnimation<>(module, "textRadius");
animText.setDuration(40);
animText.setEasing(Easing.easeOutCubic);
animText.setTo(0);
module.add(animText);
});
module.add(animX, animY, animSound1);
}
}
};
Runnable runnable = () -> {
// GRAY BACKGROUND
{
ComponentRect grayBackground = new ComponentRect(0, 0, tableComponent.getSize().getXi(), tableComponent.getSize().getYi());
grayBackground.getColor().setValue(new Color(0.05f, 0.05f, 0.05f, 0f));
grayBackground.getTransform().setTranslateZ(200);
grayBackground.BUS.hook(GuiComponentEvents.ComponentTickEvent.class, event -> {
grayBackground.getColor().setValue(new Color(0.05f, 0.05f, 0.05f, backgroundAlpha));
});
// tableComponent.add(grayBackground);
KeyframeAnimation<WorktableGui> anim = new KeyframeAnimation<>(this, "backgroundAlpha");
anim.setDuration(100);
anim.setKeyframes(new Keyframe[] { new Keyframe(0, 0f, Easing.easeInOutQuint), new Keyframe(0.2f, 0.65f, Easing.easeInOutQuint), new Keyframe(0.7f, 0.65f, Easing.easeInOutQuint), new Keyframe(1f, 0f, Easing.easeInOutQuint) });
anim.setCompletion(grayBackground::invalidate);
// getMainComponents().add(anim);
}
// BOOK PEAK ANIMATION
{
ComponentSprite bookIcon = new ComponentSprite(BOOK_ICON, (int) ((bookIconMask.getSize().getX() / 2.0) - 16), (int) (bookIconMask.getSize().getY() + 50), 32, 32);
bookIconMask.add(bookIcon);
bookIcon.getTransform().setTranslateZ(200);
bookIconMask.clipping.setClipToBounds(true);
bookIconMask.getTransform().setTranslateZ(250);
final Vec2d originalPos = bookIcon.getPos();
KeyframeAnimation<ComponentSprite> anim = new KeyframeAnimation<>(bookIcon, "pos.y");
anim.setDuration(120);
anim.setKeyframes(new Keyframe[] { new Keyframe(0, originalPos.getY(), Easing.linear), new Keyframe(0.4f, (bookIconMask.getSize().getY() / 2.0) - 25, Easing.easeInBack), new Keyframe(0.5f, (bookIconMask.getSize().getY() / 2.0) - 10, Easing.easeOutBack), new Keyframe(0.8f, (bookIconMask.getSize().getY() / 2.0) - 10, Easing.easeInBack), new Keyframe(1f, originalPos.getY(), Easing.easeInBack) });
ScheduledEventAnimation animSound = new ScheduledEventAnimation(120 * 0.4f, () -> {
Minecraft.getMinecraft().player.playSound(ModSounds.WHOOSH, 1f, 1f);
itemsRunnable.run();
ScheduledEventAnimation animFinish = new ScheduledEventAnimation(100, () -> {
bookIcon.invalidate();
if (finish == null)
animationPlaying = false;
else {
finish.run();
}
});
getMainComponents().add(animFinish);
});
bookIcon.add(anim, animSound);
}
};
if (selectedModule != null) {
selectedModule = null;
getMainComponents().add(new ScheduledEventAnimation(5, runnable));
} else
runnable.run();
}
Aggregations