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
@@ -56,11 +56,11 @@ public class DatabaseDialog extends FloatingDialog{
UnlockableContent unlock = (UnlockableContent)array.get(i);
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);
ClickListener listener = new ClickListener();
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()));
}
@@ -2,7 +2,6 @@ package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.*;
import io.anuke.arc.input.*;
import io.anuke.arc.scene.event.*;
import io.anuke.arc.scene.ui.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.core.GameState.*;
@@ -33,7 +32,6 @@ public class FloatingDialog extends Dialog{
}
Sounds.back.play();
});
ClickListener.clicked = () -> Sounds.press.play();
shown(() -> {
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.mindustry.content.*;
import io.anuke.mindustry.content.TechTree.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.ui.*;
@@ -237,6 +238,7 @@ public class TechTreeDialog extends FloatingDialog{
treeLayout();
rebuild();
Core.scene.act();
Sounds.unlock.play();
}
void rebuild(){
@@ -1,15 +1,16 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.scene.ui.Button;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.arc.*;
import io.anuke.arc.graphics.*;
import io.anuke.arc.scene.ui.*;
import io.anuke.arc.scene.ui.layout.*;
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.Zone.ZoneRequirement;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Block.Icon;
import io.anuke.mindustry.type.Zone.*;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Block.*;
import static io.anuke.mindustry.Vars.*;
@@ -142,6 +143,7 @@ public class ZoneInfoDialog extends FloatingDialog{
Button button = cont.addButton(zone.locked() ? "$uncover" : "$launch", () -> {
if(!data.isUnlocked(zone)){
Sounds.unlock.play();
data.unlockContent(zone);
ui.deploy.setup();
setup(zone);
@@ -44,6 +44,7 @@ public class HudFragment extends Fragment{
private float lastCoreHP;
private Team lastTeam;
private float coreAttackOpacity = 0f;
private long lastToast;
public void build(Group parent){
@@ -372,25 +373,43 @@ public class HudFragment extends Fragment{
}
}
public void showToast(String text){
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();
private void scheduleToast(Runnable run){
long duration = (int)(3.5 * 1000);
long since = Time.timeSinceMillis(lastToast);
if(since > duration){
lastToast = Time.millis();
run.run();
}else{
Time.runTask((duration - since) / 1000f * 60f, run);
lastToast += duration;
}
}
//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.remove())));
public void showToast(String text){
if(state.is(State.menu)) return;
scheduleToast(() -> {
Sounds.message.play();
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(){
@@ -400,46 +419,50 @@ public class HudFragment extends Fragment{
/** Show unlock notification for a new recipe. */
public void showUnlock(UnlockableContent content){
//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(lastUnlockTable == null){
Table table = new Table("button");
table.update(() -> {
if(state.is(State.menu)){
table.remove();
lastUnlockLayout = null;
scheduleToast(() -> {
Table table = new Table("button");
table.update(() -> {
if(state.is(State.menu)){
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;
}
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{
//max column size
int col = 3;