Animated item support
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:resizeableActivity="false"
|
android:resizeableActivity="true"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
package mindustry.type;
|
package mindustry.type;
|
||||||
|
|
||||||
|
import arc.*;
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
|
import arc.graphics.g2d.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
|
import arc.util.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
|
import mindustry.game.EventType.*;
|
||||||
|
import mindustry.graphics.*;
|
||||||
|
import mindustry.graphics.MultiPacker.*;
|
||||||
import mindustry.world.blocks.environment.*;
|
import mindustry.world.blocks.environment.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
@@ -29,6 +35,13 @@ public class Item extends UnlockableContent{
|
|||||||
/** if true, this item is of lowest priority to drills. */
|
/** if true, this item is of lowest priority to drills. */
|
||||||
public boolean lowPriority;
|
public boolean lowPriority;
|
||||||
|
|
||||||
|
/** If >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){
|
public Item(String name, Color color){
|
||||||
super(name);
|
super(name);
|
||||||
this.color = color;
|
this.color = color;
|
||||||
@@ -38,6 +51,40 @@ public class Item extends UnlockableContent{
|
|||||||
this(name, new Color(Color.black));
|
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
|
@Override
|
||||||
public void setStats(){
|
public void setStats(){
|
||||||
stats.addPercent(Stat.explosiveness, explosiveness);
|
stats.addPercent(Stat.explosiveness, explosiveness);
|
||||||
@@ -56,6 +103,30 @@ public class Item extends UnlockableContent{
|
|||||||
return ContentType.item;
|
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. */
|
/** Allocates a new array containing all items that generate ores. */
|
||||||
public static Seq<Item> getAllOres(){
|
public static Seq<Item> getAllOres(){
|
||||||
return content.blocks().select(b -> b instanceof OreBlock).map(b -> b.itemDrop);
|
return content.blocks().select(b -> b instanceof OreBlock).map(b -> b.itemDrop);
|
||||||
|
|||||||
@@ -24,4 +24,4 @@ android.useAndroidX=true
|
|||||||
#used for slow jitpack builds; TODO see if this actually works
|
#used for slow jitpack builds; TODO see if this actually works
|
||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
archash=ed2c6c1e
|
archash=997803e9
|
||||||
|
|||||||
Reference in New Issue
Block a user