From 789cc3cdb9c882945c0f45a7ef6d0aa58f2a5d5b Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 1 Jun 2020 23:17:55 -0400 Subject: [PATCH] Launch animation --- .../src/main/resources/classids.properties | 1 + .../revisions/LaunchCoreEntity/0.json | 1 + .../revisions/LaunchCoreEntity/1.json | 1 + .../revisions/LaunchCoreEntity/2.json | 1 + core/src/mindustry/Vars.java | 2 + core/src/mindustry/content/Blocks.java | 4 +- core/src/mindustry/content/Fx.java | 6 ++ .../mindustry/ctype/UnlockableContent.java | 5 - core/src/mindustry/game/GlobalData.java | 4 +- .../mindustry/ui/dialogs/PlanetDialog.java | 20 +++- .../mindustry/ui/fragments/HudFragment.java | 8 ++ .../world/blocks/campaign/CoreLauncher.java | 97 ++++++++++++++++++- 12 files changed, 136 insertions(+), 14 deletions(-) create mode 100644 annotations/src/main/resources/revisions/LaunchCoreEntity/0.json create mode 100644 annotations/src/main/resources/revisions/LaunchCoreEntity/1.json create mode 100644 annotations/src/main/resources/revisions/LaunchCoreEntity/2.json diff --git a/annotations/src/main/resources/classids.properties b/annotations/src/main/resources/classids.properties index 7ce51d941c..35bd0b348c 100644 --- a/annotations/src/main/resources/classids.properties +++ b/annotations/src/main/resources/classids.properties @@ -12,6 +12,7 @@ mindustry.entities.comp.PlayerComp=8 mindustry.entities.comp.PuddleComp=9 mindustry.entities.comp.TileComp=10 mindustry.type.Weather.WeatherComp=11 +mindustry.world.blocks.campaign.CoreLauncher.LaunchCoreComp=20 mindustry.world.blocks.campaign.LaunchPad.LaunchPayloadComp=12 oculon=13 phantom=14 diff --git a/annotations/src/main/resources/revisions/LaunchCoreEntity/0.json b/annotations/src/main/resources/revisions/LaunchCoreEntity/0.json new file mode 100644 index 0000000000..6fed0fac7f --- /dev/null +++ b/annotations/src/main/resources/revisions/LaunchCoreEntity/0.json @@ -0,0 +1 @@ +{fields:[{name:lifetime,type:float,size:4},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]} \ No newline at end of file diff --git a/annotations/src/main/resources/revisions/LaunchCoreEntity/1.json b/annotations/src/main/resources/revisions/LaunchCoreEntity/1.json new file mode 100644 index 0000000000..4575c931f1 --- /dev/null +++ b/annotations/src/main/resources/revisions/LaunchCoreEntity/1.json @@ -0,0 +1 @@ +{version:1,fields:[{name:block,type:mindustry.world.Block,size:-1},{name:lifetime,type:float,size:4},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]} \ No newline at end of file diff --git a/annotations/src/main/resources/revisions/LaunchCoreEntity/2.json b/annotations/src/main/resources/revisions/LaunchCoreEntity/2.json new file mode 100644 index 0000000000..0030ee7afd --- /dev/null +++ b/annotations/src/main/resources/revisions/LaunchCoreEntity/2.json @@ -0,0 +1 @@ +{version:2,fields:[{name:block,type:mindustry.world.Block,size:-1},{name:lifetime,type:float,size:4},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]} \ No newline at end of file diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index 959b0bc390..66ef20612e 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -83,6 +83,8 @@ public class Vars implements Loadable{ public static final float turnDuration = 5 * Time.toMinutes; /** min armor fraction damage; e.g. 0.05 = at least 5% damage */ public static final float minArmorDamage = 0.05f; + /** launch animation duration */ + public static final float launchDuration = 140f; /** tile used in certain situations, instead of null */ public static Tile emptyTile; /** for map generator dialog */ diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index c5e5830351..c51238281c 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -1786,8 +1786,10 @@ public class Blocks implements ContentList{ coreSilo = new CoreLauncher("core-silo"){{ requirements(Category.effect, BuildVisibility.campaignOnly, ItemStack.with(Items.copper, 350, Items.silicon, 140, Items.lead, 200, Items.titanium, 150)); size = 5; - itemCapacity = 1000; + itemCapacity = 500; hasPower = true; + + consumes.items(ItemStack.with(Items.copper, 500)); consumes.power(4f); }}; diff --git a/core/src/mindustry/content/Fx.java b/core/src/mindustry/content/Fx.java index 1a5b6621da..23d715fc3f 100644 --- a/core/src/mindustry/content/Fx.java +++ b/core/src/mindustry/content/Fx.java @@ -180,6 +180,12 @@ public class Fx{ Fill.circle(e.x, e.y, (1f + 6f * e.rotation) - e.fin()*2f); }), + rocketSmokeLarge = new Effect(220, e -> { + color(Color.gray); + alpha(Mathf.clamp(e.fout()*1.6f - Interp.pow3In.apply(e.rotation)*1.2f)); + Fill.circle(e.x, e.y, (1f + 6f * e.rotation * 1.3f) - e.fin()*2f); + }), + magmasmoke = new Effect(110, e -> { color(Color.gray); Fill.circle(e.x, e.y, e.fslope() * 6f); diff --git a/core/src/mindustry/ctype/UnlockableContent.java b/core/src/mindustry/ctype/UnlockableContent.java index caf059ee67..01881c8b64 100644 --- a/core/src/mindustry/ctype/UnlockableContent.java +++ b/core/src/mindustry/ctype/UnlockableContent.java @@ -62,11 +62,6 @@ public abstract class UnlockableContent extends MappableContent{ return false; } - /** Override to make content always unlocked. */ - public boolean alwaysUnlocked(){ - return alwaysUnlocked; - } - public final boolean unlocked(){ return Vars.data.isUnlocked(this); } diff --git a/core/src/mindustry/game/GlobalData.java b/core/src/mindustry/game/GlobalData.java index f20e46a2f4..a10e91486b 100644 --- a/core/src/mindustry/game/GlobalData.java +++ b/core/src/mindustry/game/GlobalData.java @@ -128,7 +128,7 @@ public class GlobalData{ /** Returns whether or not this piece of content is unlocked yet. */ public boolean isUnlocked(UnlockableContent content){ - return content.alwaysUnlocked() || unlocked.contains(content.name); + return content.alwaysUnlocked || unlocked.contains(content.name); } /** @@ -137,7 +137,7 @@ public class GlobalData{ * Results are not saved until you call {@link #save()}. */ public void unlockContent(UnlockableContent content){ - if(content.alwaysUnlocked()) return; + if(content.alwaysUnlocked) return; //fire unlock event so other classes can use it if(unlocked.add(content.name)){ diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index 27bdc86c23..4605d3f66a 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -22,6 +22,7 @@ import mindustry.graphics.g3d.PlanetRenderer.*; import mindustry.type.*; import mindustry.type.Sector.*; import mindustry.ui.*; +import mindustry.world.blocks.campaign.CoreLauncher.*; import static mindustry.Vars.*; import static mindustry.graphics.g3d.PlanetRenderer.*; @@ -35,6 +36,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ private int launchRange; private float zoom = 1f, selectAlpha = 1f; private @Nullable Sector selected, hovered, launchSector; + private CoreLauncherEntity launcher; private Mode mode = look; public PlanetDialog(){ @@ -96,7 +98,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ return super.show(); } - public void show(Sector sector, int range){ + public void show(Sector sector, int range, CoreLauncherEntity launcher){ + this.launcher = launcher; selected = null; hovered = null; @@ -193,6 +196,9 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ } void setup(){ + zoom = planets.zoom = 1f; + selectAlpha = 1f; + cont.clear(); titleTable.remove(); @@ -324,8 +330,18 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ ui.showInfo("You need a naval loadout to launch here."); return; } - control.playSector(sector); + hide(); + + if(mode == launch){ + launcher.launch(); + zoom = 0.5f; + + ui.hudfrag.showLaunchDirect(); + Time.runTask(launchDuration, () -> control.playSector(sector)); + }else{ + control.playSector(sector); + } }).growX().padTop(2f).height(50f).minWidth(170f); } diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java index 9879007ccb..79c7196693 100644 --- a/core/src/mindustry/ui/fragments/HudFragment.java +++ b/core/src/mindustry/ui/fragments/HudFragment.java @@ -509,6 +509,14 @@ public class HudFragment extends Fragment{ } } + public void showLaunchDirect(){ + Image image = new Image(); + image.getColor().a = 0f; + image.setFillParent(true); + image.actions(Actions.fadeIn(launchDuration / 60f, Interp.pow2In), Actions.delay(8f / 60f), Actions.remove()); + Core.scene.add(image); + } + public void showLaunch(){ Image image = new Image(); image.getColor().a = 0f; diff --git a/core/src/mindustry/world/blocks/campaign/CoreLauncher.java b/core/src/mindustry/world/blocks/campaign/CoreLauncher.java index fd3c0ddd14..ba6a407b23 100644 --- a/core/src/mindustry/world/blocks/campaign/CoreLauncher.java +++ b/core/src/mindustry/world/blocks/campaign/CoreLauncher.java @@ -1,9 +1,15 @@ package mindustry.world.blocks.campaign; +import arc.graphics.g2d.*; +import arc.math.*; +import arc.util.*; import mindustry.*; +import mindustry.annotations.Annotations.*; +import mindustry.content.*; import mindustry.gen.*; +import mindustry.graphics.*; +import mindustry.ui.*; import mindustry.world.*; -import mindustry.world.meta.*; import static mindustry.Vars.state; @@ -16,7 +22,8 @@ public class CoreLauncher extends Block{ hasItems = true; configurable = true; update = true; - buildPlaceability = BuildPlaceability.sectorCaptured; + //will be enabled when needed (if at all) + //buildPlaceability = BuildPlaceability.sectorCaptured; } public class CoreLauncherEntity extends TileEntity{ @@ -28,10 +35,92 @@ public class CoreLauncher extends Block{ @Override public boolean configTapped(){ - if(state.isCampaign()){ - Vars.ui.planet.show(state.rules.sector, range); + + if(state.isCampaign() && consValid()){ + Vars.ui.planet.show(state.rules.sector, range, this); + + cons.trigger(); } return false; } + + public void launch(){ + LaunchCorec ent = LaunchCoreEntity.create(); + ent.set(this); + ent.block(Blocks.coreShard); + ent.lifetime(Vars.launchDuration); + ent.add(); + } + } + + @EntityDef(value = LaunchCorec.class, serialize = false) + @Component + static abstract class LaunchCoreComp implements Drawc, Timedc{ + @Import float x, y; + + transient Interval in = new Interval(); + Block block; + + @Override + public void draw(){ + float alpha = fout(Interp.pow5Out); + float scale = (1f - alpha) * 1.4f + 1f; + float cx = cx(), cy = cy(); + float rotation = fin() * (140f + Mathf.randomSeedRange(id(), 50f)); + + Draw.z(Layer.effect + 0.001f); + + Draw.color(Pal.engine); + + float rad = 0.2f + fslope(); + float rscl = (block.size - 1) * 0.85f; + + Fill.light(cx, cy, 10, 25f * (rad + scale-1f) * rscl, Tmp.c2.set(Pal.engine).a(alpha), Tmp.c1.set(Pal.engine).a(0f)); + + Draw.alpha(alpha); + for(int i = 0; i < 4; i++){ + Drawf.tri(cx, cy, 6f * rscl, 40f * (rad + scale-1f) * rscl, i * 90f + rotation); + } + + Draw.color(); + + Draw.z(Layer.weather - 1); + + TextureRegion region = block.icon(Cicon.full); + float rw = region.getWidth() * Draw.scl * scale, rh = region.getHeight() * Draw.scl * scale; + + Draw.alpha(alpha); + Draw.rect(region, cx, cy, rw, rh, rotation - 45); + + Tmp.v1.trns(225f, fin(Interp.pow3In) * 250f); + + Draw.z(Layer.flyingUnit + 1); + Draw.color(0, 0, 0, 0.22f * alpha); + Draw.rect(region, cx + Tmp.v1.x, cy + Tmp.v1.y, rw, rh, rotation - 45); + + Draw.reset(); + } + + float cx(){ + return x + fin(Interp.pow2In) * (12f + Mathf.randomSeedRange(id() + 3, 4f)); + } + + float cy(){ + return y + fin(Interp.pow5In) * (100f + Mathf.randomSeedRange(id() + 2, 30f)); + } + + @Override + public void update(){ + float r = 4f; + if(in.get(3f - fin()*2f)){ + Fx.rocketSmokeLarge.at(cx() + Mathf.range(r), cy() + Mathf.range(r), fin()); + } + } + + @Override + public void remove(){ + + //TODO something + } } }