tcr/java/src/game/audio/Volume.java

87 lines
1.6 KiB
Java
Raw Normal View History

2025-03-11 00:23:54 +01:00
package game.audio;
import game.CVar;
import game.CVarCategory;
import game.Game;
import game.Slider;
import game.color.TextColor;
public enum Volume implements CVar {
MASTER("master", "Gesamt"),
MUSIC("music", "Musik"),
SFX("sfx", "Geräusche"),
GUI("gui", "Oberfläche");
public final String id;
public final String name;
private int value = 100;
private Volume(String id, String name) {
this.id = id;
this.name = name;
}
public String getDisplay() {
return this.name;
}
public String getCVarName() {
return "snd_volume_" + this.id;
}
public String getType() {
return TextColor.DGREEN + "volume";
}
public CVarCategory getCategory() {
return CVarCategory.SOUND;
}
public boolean parse(String str) {
int value;
try {
value = Integer.parseInt(str);
}
catch(NumberFormatException e) {
return false;
}
if(value < 0 || value > 100)
return false;
this.value = value;
this.apply();
return true;
}
public String format() {
return "" + this.value;
}
public String getDefault() {
return "100";
}
public void setDefault() {
this.value = 100;
this.apply();
}
public String getValues() {
return "0..100";
}
public void apply() {
if(Game.getGame().getAudioInterface() != null)
Game.getGame().getAudioInterface().alSetVolume(this, (short)(((float)this.value) / 100.0f * 32767.0f));
}
public Slider selector(int x, int y, int w, int h) {
return new Slider(x, y, w, h, 0, 0, 100, 100, this.value, new Slider.Callback() {
public void use(Slider elem, int value) {
Volume.this.value = value;
Volume.this.apply();
}
}, this.name, "%");
}
}