This commit is contained in:
Mythril382
2024-05-27 03:35:37 +08:00
committed by GitHub
parent bc2be5de25
commit 7f80a1879e
3 changed files with 43 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
package mindustry.logic;
import arc.*;
import arc.audio.*;
import arc.files.*;
import arc.graphics.*;
import arc.math.*;
@@ -9,6 +10,7 @@ import arc.util.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.game.*;
import mindustry.logic.LExecutor.*;
import mindustry.type.*;
@@ -35,7 +37,9 @@ public class GlobalVars{
private IntSet privilegedIds = new IntSet();
private UnlockableContent[][] logicIdToContent;
private int[][] contentIdToLogicId;
public static final Seq<String> soundNames = new Seq<>();
public void init(){
putEntryOnly("sectionProcessor");
@@ -89,6 +93,16 @@ public class GlobalVars{
put("@ctrlProcessor", ctrlProcessor);
put("@ctrlPlayer", ctrlPlayer);
put("@ctrlCommand", ctrlCommand);
//sounds
for(Sound sound : Core.assets.getAll(Sound.class, new Seq<>(Sound.class))){
if(sound != Sounds.none && sound != Sounds.swish){
String name = sound.toString();
name = name.substring(20, name.length - 4);
soundNames.put(name);
put("@sfx-" + name, Sounds.getSoundId(sound));
}
}
//store base content

View File

@@ -1,6 +1,7 @@
package mindustry.logic;
import arc.*;
import arc.audio.*;
import arc.graphics.*;
import arc.math.*;
import arc.math.geom.*;
@@ -2025,15 +2026,14 @@ public class LExecutor{
public static class PlaySoundI implements LInstruction{
public boolean positional;
public LogicSound sound;
public int volume, pitch, pan, x, y;
public int id, volume, pitch, pan, x, y;
public PlaySoundI(){
}
public PlaySoundI(boolean positional, LogicSound sound, int volume, int pitch, int pan, int x, int y){
public PlaySoundI(boolean positional, int id, int volume, int pitch, int pan, int x, int y){
this.positional = positional;
this.sound = sound;
this.id = id;
this.volume = volume;
this.pitch = pitch;
this.pan = pan;
@@ -2043,10 +2043,13 @@ public class LExecutor{
@Override
public void run(LExecutor exec){
Sound sound = Sounds.getSound(exec.numi(id));
if(sound == Sounds.none || sound == Sounds.swish) sound = Sounds.pew; //no.
if(positional){
sound.sound.at(World.unconv(exec.numf(x)), World.unconv(exec.numf(y)), exec.numf(pitch), exec.numf(volume));
sound.at(World.unconv(exec.numf(x)), World.unconv(exec.numf(y)), exec.numf(pitch), exec.numf(volume));
}else{
sound.sound.play(exec.numf(volume) * (Core.settings.getInt("sfxvol") / 100f), exec.numf(pitch), exec.numf(pan));
sound.play(exec.numf(volume) * (Core.settings.getInt("sfxvol") / 100f), exec.numf(pitch), exec.numf(pan));
}
}
}

View File

@@ -1,6 +1,7 @@
package mindustry.logic;
import arc.*;
import arc.audio.*;
import arc.func.*;
import arc.graphics.*;
import arc.scene.style.*;
@@ -2089,8 +2090,9 @@ public class LStatements{
@RegisterStatement("playsound")
public static class PlaySoundStatement extends LStatement{
public boolean positional;
public LogicSound sound = LogicSound.pew;
public String volume = "1", pitch = "1", pan = "0", x = "@thisx", y = "@thisy";
public String id = "@sfx-pew", volume = "1", pitch = "1", pan = "0", x = "@thisx", y = "@thisy";
private transient TextField tfield;
@Override
public void build(Table table){
@@ -2107,15 +2109,18 @@ public class LStatements{
row(table);
table.add("play");
table.add("play ");
tfield = field(table, id, str -> id = str).padRight(0f).get();
table.button(b -> {
b.label(() -> sound.name());
b.clicked(() -> showSelect(b, LogicSound.all, sound, s -> {
sound = s;
b.image(Icon.pencilSmall);
b.clicked(() -> showSelect(b, GlobalVars.soundNames.toArray(String.class), id, t -> {
sid("@sfx-" + t);
rebuild(table);
}, 3, cell -> cell.size(150, 50)));
}, Styles.logict, () -> {}).size(190, 40).color(table.color).left().padLeft(2);
}, 4, cell -> cell.size(160, 50)));
}, Styles.logict, () -> {}).size(40).color(table.color).left().padLeft(-1);
row(table);
@@ -2137,6 +2142,11 @@ public class LStatements{
}
}
private void sid(String text){
tfield.setText(text);
id = text;
}
@Override
public boolean privileged(){
return true;
@@ -2144,7 +2154,7 @@ public class LStatements{
@Override
public LInstruction build(LAssembler builder){
return new PlaySoundI(positional, sound, builder.var(volume), builder.var(pitch), builder.var(pan), builder.var(x), builder.var(y));
return new PlaySoundI(positional, builder.var(id), builder.var(volume), builder.var(pitch), builder.var(pan), builder.var(x), builder.var(y));
}
@Override