split client and server 1
This commit is contained in:
parent
26a15a0b15
commit
2fa521c3d1
661 changed files with 3058 additions and 2826 deletions
106
java/src/client/audio/Volume.java
Normal file
106
java/src/client/audio/Volume.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
package client.audio;
|
||||
|
||||
import client.Game;
|
||||
import client.gui.element.Slider;
|
||||
import game.color.TextColor;
|
||||
import game.sound.EventType;
|
||||
import game.vars.CVar;
|
||||
import game.vars.CVarCategory;
|
||||
|
||||
public enum Volume implements CVar {
|
||||
MASTER("master", "Gesamt"),
|
||||
MUSIC("music", "Musik"),
|
||||
SFX("sfx", "Geräusche", EventType.SOUND_EFFECT),
|
||||
GUI("gui", "Oberfläche", EventType.UI_INTERFACE);
|
||||
|
||||
private static final Volume[] LOOKUP = new Volume[EventType.values().length];
|
||||
|
||||
public final String id;
|
||||
public final String name;
|
||||
public final EventType type;
|
||||
|
||||
private int value = 100;
|
||||
|
||||
private Volume(String id, String name, EventType type) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private Volume(String id, String name) {
|
||||
this(id, name, null);
|
||||
}
|
||||
|
||||
static {
|
||||
for(Volume volume : values()) {
|
||||
if(volume.type != null)
|
||||
LOOKUP[volume.type.ordinal()] = volume;
|
||||
}
|
||||
}
|
||||
|
||||
public static Volume getByType(EventType type) {
|
||||
return LOOKUP[type.ordinal()];
|
||||
}
|
||||
|
||||
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, "%");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue