From c3dbe9b09d73dd0b617117fb9365ac3a433e8661 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 6 Dec 2021 00:52:30 -0500 Subject: [PATCH] Animated item support --- android/AndroidManifest.xml | 2 +- core/src/mindustry/type/Item.java | 71 +++++++++++++++++++++++++++++++ gradle.properties | 2 +- 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 08422736a2..e322c6df18 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -9,7 +9,7 @@ 0, this item is animated. */ + public int frames = 0; + /** Number of generated transition frames between each frame */ + public int transitionFrames = 0; + /** Ticks in-between animation frames. */ + public float frameTime = 5f; + public Item(String name, Color color){ super(name); this.color = color; @@ -38,6 +51,40 @@ public class Item extends UnlockableContent{ this(name, new Color(Color.black)); } + @Override + public void loadIcon(){ + super.loadIcon(); + + //animation code ""borrowed"" from Project Unity - original implementation by GlennFolker and sk7725 + if(frames > 0){ + TextureRegion[] regions = new TextureRegion[frames * (transitionFrames + 1)]; + + if(transitionFrames <= 0){ + for(int i = 1; i <= frames; i++){ + regions[i - 1] = Core.atlas.find(name + i); + } + }else{ + for(int i = 0; i < frames; i++){ + regions[i * (transitionFrames + 1)] = Core.atlas.find(name + (i + 1)); + for(int j = 1; j <= transitionFrames; j++){ + int index = i * (transitionFrames + 1) + j; + regions[index] = Core.atlas.find(name + "-t" + index); + } + } + } + + fullIcon = new TextureRegion(fullIcon); + uiIcon = new TextureRegion(uiIcon); + + Events.run(Trigger.update, () -> { + int frame = (int)(Time.globalTime / frameTime) % regions.length; + + fullIcon.set(regions[frame]); + uiIcon.set(regions[frame]); + }); + } + } + @Override public void setStats(){ stats.addPercent(Stat.explosiveness, explosiveness); @@ -56,6 +103,30 @@ public class Item extends UnlockableContent{ return ContentType.item; } + @Override + public void createIcons(MultiPacker packer){ + super.createIcons(packer); + + //create transitions + if(frames > 0 && transitionFrames > 0){ + var pixmaps = new PixmapRegion[frames]; + + for(int i = 0; i < frames; i++){ + pixmaps[i] = Core.atlas.getPixmap(name + (i + 1)); + } + + for(int i = 0; i < frames; i++){ + for(int j = 1; j <= transitionFrames; j++){ + float f = (float)j / (transitionFrames + 1); + int index = i * (transitionFrames + 1) + j; + + Pixmap res = Pixmaps.blend(pixmaps[i], pixmaps[(i + 1) % frames], f); + packer.add(PageType.main, name + "-t" + index, res); + } + } + } + } + /** Allocates a new array containing all items that generate ores. */ public static Seq getAllOres(){ return content.blocks().select(b -> b instanceof OreBlock).map(b -> b.itemDrop); diff --git a/gradle.properties b/gradle.properties index 0564908d49..6ee9ccabfb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,4 +24,4 @@ android.useAndroidX=true #used for slow jitpack builds; TODO see if this actually works org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.connectionTimeout=100000 -archash=ed2c6c1e +archash=997803e9