Work on sound effects

This commit is contained in:
Anuken
2019-08-11 10:47:22 -04:00
parent 2341da995e
commit 4c08c98f8c
17 changed files with 115 additions and 86 deletions
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
@@ -1,6 +1,7 @@
package io.anuke.mindustry.core; package io.anuke.mindustry.core;
import io.anuke.arc.*; import io.anuke.arc.*;
import io.anuke.arc.Application.*;
import io.anuke.arc.graphics.*; import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.input.*; import io.anuke.arc.input.*;
@@ -175,6 +176,10 @@ public class Control implements ApplicationListener{
Events.on(ZoneConfigureCompleteEvent.class, e -> { Events.on(ZoneConfigureCompleteEvent.class, e -> {
ui.hudfrag.showToast(Core.bundle.format("zone.config.complete", e.zone.configureWave)); ui.hudfrag.showToast(Core.bundle.format("zone.config.complete", e.zone.configureWave));
}); });
if(Core.app.getType() == ApplicationType.Android){
Sounds.empty.loop(0f, 1f, 0f);
}
} }
void createPlayer(){ void createPlayer(){
+3
View File
@@ -23,6 +23,7 @@ import io.anuke.arc.util.*;
import io.anuke.mindustry.core.GameState.*; import io.anuke.mindustry.core.GameState.*;
import io.anuke.mindustry.editor.*; import io.anuke.mindustry.editor.*;
import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.ui.dialogs.*; import io.anuke.mindustry.ui.dialogs.*;
import io.anuke.mindustry.ui.fragments.*; import io.anuke.mindustry.ui.fragments.*;
@@ -88,6 +89,8 @@ public class UI implements ApplicationListener{
Core.app.post(() -> showError("Failed to access local storage.\nSettings will not be saved.")); Core.app.post(() -> showError("Failed to access local storage.\nSettings will not be saved."));
}); });
ClickListener.clicked = () -> Sounds.press.play();
Colors.put("accent", Pal.accent); Colors.put("accent", Pal.accent);
Colors.put("highlight", Pal.accent.cpy().lerp(Color.WHITE, 0.3f)); Colors.put("highlight", Pal.accent.cpy().lerp(Color.WHITE, 0.3f));
Colors.put("stat", Pal.stat); Colors.put("stat", Pal.stat);
@@ -14,7 +14,7 @@ import static io.anuke.mindustry.Vars.*;
/** Controls playback of multiple music tracks.*/ /** Controls playback of multiple music tracks.*/
public class MusicControl{ public class MusicControl{
private static final float finTime = 120f, foutTime = 120f, musicInterval = 60 * 60 * 3f, musicChance = 0.25f, musicWaveChance = 0.2f; private static final float finTime = 120f, foutTime = 120f, musicInterval = 60 * 60 * 3f, musicChance = 0.3f, musicWaveChance = 0.24f;
/** normal, ambient music, plays at any time */ /** normal, ambient music, plays at any time */
public final Array<Music> ambientMusic = Array.with(Musics.game1, Musics.game3, Musics.game4, Musics.game6); public final Array<Music> ambientMusic = Array.with(Musics.game1, Musics.game3, Musics.game4, Musics.game6);
@@ -30,6 +30,7 @@ public class MusicControl{
private boolean silenced; private boolean silenced;
public MusicControl(){ public MusicControl(){
//only run music 10 seconds after a wave spawns
Events.on(WaveEvent.class, e -> Time.run(60f * 10f, () -> { Events.on(WaveEvent.class, e -> Time.run(60f * 10f, () -> {
if(Mathf.chance(musicWaveChance)){ if(Mathf.chance(musicWaveChance)){
playRandom(); playRandom();
@@ -40,6 +41,7 @@ public class MusicControl{
/** Update and play the right music track.*/ /** Update and play the right music track.*/
public void update(){ public void update(){
if(state.is(State.menu)){ if(state.is(State.menu)){
silenced = false;
if(ui.deploy.isShown()){ if(ui.deploy.isShown()){
play(Musics.launch); play(Musics.launch);
}else if(ui.editor.isShown()){ }else if(ui.editor.isShown()){
@@ -48,6 +50,7 @@ public class MusicControl{
play(Musics.menu); play(Musics.menu);
} }
}else if(state.rules.editor){ }else if(state.rules.editor){
silenced = false;
play(Musics.editor); play(Musics.editor);
}else{ }else{
//this just fades out the last track to make way for ingame music //this just fades out the last track to make way for ingame music
@@ -79,17 +82,13 @@ public class MusicControl{
return true; return true;
} }
if(state.enemies() > 25){
//many enemies -> dark
return true;
}
//it may be dark based on wave //it may be dark based on wave
if(Mathf.chance((float)(Math.log10((state.wave - 17f)/19f) + 1) / 4f)){ if(Mathf.chance((float)(Math.log10((state.wave - 17f)/19f) + 1) / 4f)){
return true; return true;
} }
return false; //dark based on enemies
return Mathf.chance(state.enemies() / 70f);
} }
/** Plays and fades in a music track. This must be called every frame. /** Plays and fades in a music track. This must be called every frame.
@@ -56,11 +56,11 @@ public class DatabaseDialog extends FloatingDialog{
UnlockableContent unlock = (UnlockableContent)array.get(i); UnlockableContent unlock = (UnlockableContent)array.get(i);
Image image = unlocked(unlock) ? new Image(unlock.getContentIcon()) : new Image("icon-locked", Pal.gray); Image image = unlocked(unlock) ? new Image(unlock.getContentIcon()) : new Image("icon-locked", Pal.gray);
image.addListener(new HandCursorListener());
list.add(image).size(unlocked(unlock) ? 8*4 : Vars.iconsize).pad(3); list.add(image).size(unlocked(unlock) ? 8*4 : Vars.iconsize).pad(3);
ClickListener listener = new ClickListener(); ClickListener listener = new ClickListener();
image.addListener(listener); image.addListener(listener);
if(!Vars.mobile){ if(!Vars.mobile && unlocked(unlock)){
image.addListener(new HandCursorListener());
image.update(() -> image.getColor().lerp(!listener.isOver() ? Color.LIGHT_GRAY : Color.WHITE, 0.4f * Time.delta())); image.update(() -> image.getColor().lerp(!listener.isOver() ? Color.LIGHT_GRAY : Color.WHITE, 0.4f * Time.delta()));
} }
@@ -2,7 +2,6 @@ package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.*; import io.anuke.arc.*;
import io.anuke.arc.input.*; import io.anuke.arc.input.*;
import io.anuke.arc.scene.event.*;
import io.anuke.arc.scene.ui.*; import io.anuke.arc.scene.ui.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.mindustry.core.GameState.*; import io.anuke.mindustry.core.GameState.*;
@@ -33,7 +32,6 @@ public class FloatingDialog extends Dialog{
} }
Sounds.back.play(); Sounds.back.play();
}); });
ClickListener.clicked = () -> Sounds.press.play();
shown(() -> { shown(() -> {
if(shouldPause && !state.is(State.menu)){ if(shouldPause && !state.is(State.menu)){
@@ -15,6 +15,7 @@ import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*; import io.anuke.arc.util.*;
import io.anuke.mindustry.content.*; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.content.TechTree.*; import io.anuke.mindustry.content.TechTree.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.ui.*; import io.anuke.mindustry.ui.*;
@@ -237,6 +238,7 @@ public class TechTreeDialog extends FloatingDialog{
treeLayout(); treeLayout();
rebuild(); rebuild();
Core.scene.act(); Core.scene.act();
Sounds.unlock.play();
} }
void rebuild(){ void rebuild(){
@@ -1,15 +1,16 @@
package io.anuke.mindustry.ui.dialogs; package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.Core; import io.anuke.arc.*;
import io.anuke.arc.graphics.Color; import io.anuke.arc.graphics.*;
import io.anuke.arc.scene.ui.Button; import io.anuke.arc.scene.ui.*;
import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.scene.ui.layout.*;
import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.*;
import io.anuke.mindustry.graphics.Pal; import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.type.Zone.ZoneRequirement; import io.anuke.mindustry.type.Zone.*;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Block.Icon; import io.anuke.mindustry.world.Block.*;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
@@ -142,6 +143,7 @@ public class ZoneInfoDialog extends FloatingDialog{
Button button = cont.addButton(zone.locked() ? "$uncover" : "$launch", () -> { Button button = cont.addButton(zone.locked() ? "$uncover" : "$launch", () -> {
if(!data.isUnlocked(zone)){ if(!data.isUnlocked(zone)){
Sounds.unlock.play();
data.unlockContent(zone); data.unlockContent(zone);
ui.deploy.setup(); ui.deploy.setup();
setup(zone); setup(zone);
@@ -44,6 +44,7 @@ public class HudFragment extends Fragment{
private float lastCoreHP; private float lastCoreHP;
private Team lastTeam; private Team lastTeam;
private float coreAttackOpacity = 0f; private float coreAttackOpacity = 0f;
private long lastToast;
public void build(Group parent){ public void build(Group parent){
@@ -372,25 +373,43 @@ public class HudFragment extends Fragment{
} }
} }
public void showToast(String text){ private void scheduleToast(Runnable run){
Table table = new Table("button"); long duration = (int)(3.5 * 1000);
table.update(() -> { long since = Time.timeSinceMillis(lastToast);
if(state.is(State.menu)){ if(since > duration){
table.remove(); lastToast = Time.millis();
} run.run();
}); }else{
table.margin(12); Time.runTask((duration - since) / 1000f * 60f, run);
table.addImage("icon-check").size(iconsize).pad(3); lastToast += duration;
table.add(text).wrap().width(280f).get().setAlignment(Align.center, Align.center); }
table.pack(); }
//create container table which will align and move public void showToast(String text){
Table container = Core.scene.table(); if(state.is(State.menu)) return;
container.top().add(table);
container.setTranslation(0, table.getPrefHeight()); scheduleToast(() -> {
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(4f), Sounds.message.play();
//nesting actions() calls is necessary so the right prefHeight() is used
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.remove()))); Table table = new Table("button");
table.update(() -> {
if(state.is(State.menu)){
table.remove();
}
});
table.margin(12);
table.addImage("icon-check").size(iconsize).pad(3);
table.add(text).wrap().width(280f).get().setAlignment(Align.center, Align.center);
table.pack();
//create container table which will align and move
Table container = Core.scene.table();
container.top().add(table);
container.setTranslation(0, table.getPrefHeight());
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(2.5f),
//nesting actions() calls is necessary so the right prefHeight() is used
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.remove())));
});
} }
public boolean shown(){ public boolean shown(){
@@ -400,46 +419,50 @@ public class HudFragment extends Fragment{
/** Show unlock notification for a new recipe. */ /** Show unlock notification for a new recipe. */
public void showUnlock(UnlockableContent content){ public void showUnlock(UnlockableContent content){
//some content may not have icons... yet //some content may not have icons... yet
if(content.getContentIcon() == null) return; if(content.getContentIcon() == null || state.is(State.menu)) return;
Sounds.message.play();
//if there's currently no unlock notification... //if there's currently no unlock notification...
if(lastUnlockTable == null){ if(lastUnlockTable == null){
Table table = new Table("button"); scheduleToast(() -> {
table.update(() -> { Table table = new Table("button");
if(state.is(State.menu)){ table.update(() -> {
table.remove(); if(state.is(State.menu)){
lastUnlockLayout = null; table.remove();
lastUnlockLayout = null;
lastUnlockTable = null;
}
});
table.margin(12);
Table in = new Table();
//create texture stack for displaying
Image image = new Image(content.getContentIcon());
image.setScaling(Scaling.fit);
in.add(image).size(48f).pad(2);
//add to table
table.add(in).padRight(8);
table.add("$unlocked");
table.pack();
//create container table which will align and move
Table container = Core.scene.table();
container.top().add(table);
container.setTranslation(0, table.getPrefHeight());
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(2.5f),
//nesting actions() calls is necessary so the right prefHeight() is used
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.run(() -> {
lastUnlockTable = null; lastUnlockTable = null;
} lastUnlockLayout = null;
}), Actions.remove())));
lastUnlockTable = container;
lastUnlockLayout = in;
}); });
table.margin(12);
Table in = new Table();
//create texture stack for displaying
Image image = new Image(content.getContentIcon());
image.setScaling(Scaling.fit);
in.add(image).size(48f).pad(2);
//add to table
table.add(in).padRight(8);
table.add("$unlocked");
table.pack();
//create container table which will align and move
Table container = Core.scene.table();
container.top().add(table);
container.setTranslation(0, table.getPrefHeight());
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(4f),
//nesting actions() calls is necessary so the right prefHeight() is used
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.run(() -> {
lastUnlockTable = null;
lastUnlockLayout = null;
}), Actions.remove())));
lastUnlockTable = container;
lastUnlockLayout = in;
}else{ }else{
//max column size //max column size
int col = 3; int col = 3;
@@ -1,25 +1,22 @@
package io.anuke.mindustry.world.blocks.storage; package io.anuke.mindustry.world.blocks.storage;
import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.*;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.*; import io.anuke.arc.*;
import io.anuke.arc.collection.EnumSet; import io.anuke.arc.collection.*;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.*;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.*;
import io.anuke.mindustry.content.Fx; import io.anuke.mindustry.content.*;
import io.anuke.mindustry.content.Mechs; import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.entities.Effects; import io.anuke.mindustry.entities.traits.*;
import io.anuke.mindustry.entities.traits.SpawnerTrait;
import io.anuke.mindustry.entities.type.*; import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.Pal; import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.meta.BlockFlag; import io.anuke.mindustry.world.meta.*;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;