use of com.teamwizardry.librarianlib.features.gui.components.ComponentVoid in project Wizardry by TeamWizardry.
the class GuiPearlSwap method update.
public void update(int originalPearlCount, int newPearlCount, int index) {
unlock();
EntityPlayer player = Minecraft.getMinecraft().player;
if (originalPearlCount != newPearlCount) {
if (originalPearlCount == 0) {
dilateItems();
} else {
contractItems();
if (newPearlCount != 0)
ANIMATOR.add(new ScheduledEventAnimation(10, this::dilateItems));
}
player.playSound(ModSounds.POP, 1f, 1f);
} else if (newPearlCount != 0 && index != -1) {
contractItem(index);
ANIMATOR.add(new ScheduledEventAnimation(10, () -> dilateItem(index)));
player.playSound(ModSounds.POP, 1f, 1f);
} else {
player.playSound(ModSounds.SPELL_FAIL, 1f, 1f);
}
double centerRad = newPearlCount == 0 ? getGuiHeight() : getGuiHeight() * 0.75;
new BasicAnimation<>(this, "parasolGradientRadius").to(centerRad * 1.5).ease(Easing.easeOutQuart).duration(15).addTo(ANIMATOR);
centerRadiusAnim = (BasicAnimation<ComponentVoid>) new BasicAnimation<>(componentCentralCircle, "size.x").to(centerRad).ease(Easing.easeOutQuint).duration(20).addTo(ANIMATOR);
}
use of com.teamwizardry.librarianlib.features.gui.components.ComponentVoid 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();
}
use of com.teamwizardry.librarianlib.features.gui.components.ComponentVoid in project Wizardry by TeamWizardry.
the class WorktableGui method playSaveAnimation.
public void playSaveAnimation(@Nullable Runnable finish) {
animationPlaying = true;
resetSelectedModule();
Runnable runnable = () -> {
ComponentVoid fakePaper = new ComponentVoid(180, 19, 180, 188);
fakePaper.getTransform().setTranslateZ(100);
getMainComponents().add(fakePaper);
ComponentVoid bookIconMask = new ComponentVoid(0, -100, 180, 100);
fakePaper.add(bookIconMask);
// 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) });
anim.setCompletion(() -> {
fakePaper.invalidate();
if (finish == null)
animationPlaying = false;
else {
finish.run();
}
});
ScheduledEventAnimation animSound = new ScheduledEventAnimation(120 * 0.5f, () -> Minecraft.getMinecraft().player.playSound(ModSounds.SCRIBBLING, 1f, 1f));
bookIcon.add(anim, animSound);
}
// PAPER ITEMS ANIMATION
{
HashMap<TableModule, UUID> links = new HashMap<>();
for (GuiComponent component : paper.getChildren()) {
if (!(component instanceof TableModule))
continue;
TableModule tableModule = (TableModule) component;
TableModule fakeModule = new TableModule(this, tableModule.getModule(), false, true);
fakeModule.setPos(tableModule.getPos());
for (Object tag : tableModule.getTagList()) fakeModule.addTag(tag);
fakeModule.getTransform().setTranslateZ(230);
fakePaper.add(fakeModule);
for (ModuleInstance module : ModuleRegistry.INSTANCE.getModules(ModuleType.MODIFIER)) {
if (tableModule.hasData(Integer.class, module.getNBTKey())) {
fakeModule.setData(Integer.class, module.getNBTKey(), tableModule.getData(Integer.class, module.getNBTKey()));
}
}
UUID uuid = tableModule.getData(UUID.class, "uuid");
if (uuid != null)
fakeModule.setData(UUID.class, "uuid", uuid);
TableModule linkedModule = tableModule.getLinksTo();
if (linkedModule == null)
continue;
UUID linkTo = linkedModule.getData(UUID.class, "uuid");
if (linkTo != null)
links.put(fakeModule, linkTo);
}
for (TableModule module : links.keySet()) {
if (!links.containsKey(module))
continue;
UUID linkTo = links.get(module);
if (linkTo == null)
continue;
for (GuiComponent child : fakePaper.getChildren()) {
UUID uuid = child.getData(UUID.class, "uuid");
if (uuid == null)
continue;
if (!linkTo.equals(uuid))
continue;
if (!(child instanceof TableModule))
continue;
TableModule reverseUUIDLink = (TableModule) child;
module.setLinksTo(reverseUUIDLink);
break;
}
}
for (GuiComponent component : fakePaper.getChildren()) {
if (!(component instanceof TableModule))
continue;
TableModule fakeModule = (TableModule) component;
Vec2d random = fakeModule.getPos().add(RandUtil.nextDouble(-20, 20), RandUtil.nextDouble(-20, 20));
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.POP, 1f, 1f));
ScheduledEventAnimation animSound2 = new ScheduledEventAnimation(dur * 0.75f, () -> Minecraft.getMinecraft().player.playSound(ModSounds.WHOOSH, 1f, 1f));
KeyframeAnimation<TableModule> animX = new KeyframeAnimation<>(fakeModule, "pos.x");
animX.setDuration(dur);
animX.setKeyframes(new Keyframe[] { new Keyframe(delay, fakeModule.getPos().getX(), Easing.easeOutQuint), new Keyframe(0.45f, random.getX(), Easing.easeOutQuint), new Keyframe(0.6f, random.getX(), Easing.easeOutQuint), new Keyframe(1f, (bookIconMask.getSize().getX() / 2.0) - 8, Easing.easeInOutQuint) });
KeyframeAnimation<TableModule> animY = new KeyframeAnimation<>(fakeModule, "pos.y");
animY.setDuration(dur);
animY.setKeyframes(new Keyframe[] { new Keyframe(delay, fakeModule.getPos().getY(), Easing.easeOutQuint), new Keyframe(0.45f, random.getY(), Easing.easeOutQuint), new Keyframe(0.6f, random.getY(), Easing.easeOutQuint), new Keyframe(1f, -(bookIconMask.getSize().getY() / 2.0) - 4, Easing.easeInOutQuint) });
BasicAnimation<TableModule> animRadius = new BasicAnimation<>(fakeModule, "radius");
animRadius.setDuration(20);
animRadius.setEasing(Easing.easeOutCubic);
animRadius.setTo(0);
BasicAnimation<TableModule> animText = new BasicAnimation<>(fakeModule, "textRadius");
animText.setDuration(40);
animText.setEasing(Easing.easeOutCubic);
animText.setTo(0);
animY.setCompletion(fakeModule::invalidate);
fakeModule.add(animX, animY, animSound1, animSound2, animRadius, animText);
}
}
};
if (selectedModule != null) {
selectedModule = null;
getMainComponents().add(new ScheduledEventAnimation(5, runnable));
} else
runnable.run();
}
use of com.teamwizardry.librarianlib.features.gui.components.ComponentVoid in project Wizardry by TeamWizardry.
the class ComponentSpellRecipe method components.
public static List<PaginationContext> components(GuiBook book) {
List<PaginationContext> contexts = Lists.newArrayList();
if (book.getBookItemStack().isEmpty())
return contexts;
ItemStack bookStack = book.getBookItemStack();
if (!NBTHelper.getBoolean(bookStack, "has_spell", false))
return contexts;
NBTTagList moduleList = NBTHelper.getList(bookStack, NBTConstants.NBT.SPELL, net.minecraftforge.common.util.Constants.NBT.TAG_STRING);
if (moduleList == null)
return contexts;
List<List<ModuleInstance>> spellModules = SpellUtils.deserializeModuleList(moduleList);
List<ItemStack> spellItems = SpellUtils.getSpellItems(spellModules);
spellModules = SpellUtils.getEssentialModules(spellModules);
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
int widthOfSpace = fr.getStringWidth(" ");
StringBuilder builder = new StringBuilder(LibrarianLib.PROXY.translate("wizardry.book.spell_recipe_structure") + "\n");
for (List<ModuleInstance> spellModuleList : spellModules) {
String margin = null;
for (ModuleInstance module : spellModuleList) {
if (margin == null) {
margin = " - ";
builder.append(margin).append(module.getReadableName()).append("\n");
} else {
int realLength = fr.getStringWidth(margin);
int nbOfSpace = MathHelper.clamp(realLength / widthOfSpace, 0, 17);
margin = StringUtils.repeat(" ", nbOfSpace) + "|_ ";
builder.append(margin).append(module.getReadableName()).append("\n");
if (nbOfSpace >= 16) {
builder.append(" ________________|").append("\n");
margin = " ";
}
}
}
}
String[] lines = builder.toString().split("\n");
StringBuilder pageChunk = new StringBuilder();
int count = 0;
for (String line : lines) {
pageChunk.append(line).append("\n");
if (++count >= 16) {
count = 0;
pageFromString(book, contexts, pageChunk);
pageChunk = new StringBuilder();
}
}
if (count != 0)
pageFromString(book, contexts, pageChunk);
Consumer<ComponentVoid> applier = component -> {
};
for (int i = 0; i < spellItems.size(); i++) {
ItemStack stack = spellItems.get(i);
int index = i;
applier = applier.andThen(component -> {
ComponentStack componentStack = new ComponentStack((index % 4) * 32, (index / 4) * 16);
componentStack.getStack().setValue(stack);
component.add(componentStack);
if (index != spellItems.size() - 1 && (index % 4) < 3) {
ComponentSprite nextItem = new ComponentSprite(book.getHomeSprite(), 32 + (index % 4) * 32, (index / 4) * 16 + 13, 16, 8);
nextItem.getColor().setValue(book.getBook().getHighlightColor());
nextItem.getTransform().setRotate(Math.toRadians(180));
component.add(nextItem);
}
});
if ((index / 4) >= 9) {
Consumer<ComponentVoid> spellApplier = applier;
contexts.add(new PaginationContext(() -> {
ComponentVoid component = new ComponentVoid(16, 16, book.getMainBookComponent().getSize().getXi() - 32, book.getMainBookComponent().getSize().getYi() - 32);
spellApplier.accept(component);
return component;
}));
applier = component -> {
};
}
}
Consumer<ComponentVoid> spellApplier = applier;
contexts.add(new PaginationContext(() -> {
ComponentVoid component = new ComponentVoid(16, 16, book.getMainBookComponent().getSize().getXi() - 32, book.getMainBookComponent().getSize().getYi() - 32);
spellApplier.accept(component);
return component;
}));
return contexts;
}
Aggregations