mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-25 01:09:46 +01:00
task 10
This commit is contained in:
parent
c8621e02c6
commit
c0a3e8b37a
@ -272,12 +272,15 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
stateManager.attachAll(new EditorAppState(), new BattleAppState(), new SeaAppState());
|
||||
}
|
||||
|
||||
private void attachGameMusic() {
|
||||
final GameMusic gameMusic = new GameMusic();
|
||||
gameMusic.setEnabled(GameMusic.enabledInPreferences());
|
||||
stateManager.attach(gameMusic);
|
||||
private void atttachGameMusic() {
|
||||
final GameMusic gameSound = new GameMusic();
|
||||
gameSound.setEnabled(GameMusic.enabledInPreferences());
|
||||
stateManager.attach(gameSound);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Attaches the game sound state and sets its initial enabled state.
|
||||
*
|
||||
|
@ -12,6 +12,8 @@ import com.jme3.app.state.AbstractAppState;
|
||||
import com.jme3.app.state.AppStateManager;
|
||||
import pp.battleship.game.client.ClientGameLogic;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class representing a state in the Battleship game.
|
||||
* Extends the AbstractAppState from jMonkeyEngine to manage state behavior.
|
||||
|
@ -87,7 +87,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
* @param name The name of the sound file.
|
||||
* @return The loaded AudioNode.
|
||||
*/
|
||||
private AudioNode loadSound(Application app, String name) {
|
||||
public AudioNode loadSound(Application app, String name) {
|
||||
try {
|
||||
final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer);
|
||||
sound.setLooping(false);
|
||||
|
@ -32,7 +32,7 @@ class Menu extends Dialog {
|
||||
private static final Preferences PREFERENCES = getPreferences(Menu.class);
|
||||
private static final String LAST_PATH = "last.file.path";
|
||||
|
||||
private final VolumeSlider slider;
|
||||
// private final VolumeSlider slider;
|
||||
private final BattleshipApp app;
|
||||
private final Button loadButton = new Button(lookup("menu.map.load"));
|
||||
private final Button saveButton = new Button(lookup("menu.map.save"));
|
||||
@ -42,13 +42,14 @@ class Menu extends Dialog {
|
||||
*
|
||||
* @param app the BattleshipApp instance
|
||||
*/
|
||||
|
||||
public Menu(BattleshipApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
addChild(new Label(lookup("battleship.name"), new ElementId("header"))); //NON-NLS
|
||||
addChild(new Checkbox(lookup("menu.sound-enabled"),
|
||||
new StateCheckboxModel(app, GameSound.class)));
|
||||
slider = new VolumeSlider(app.getStateManager().getState(GameMusic.class));
|
||||
// slider = new VolumeSlider(app.getStateManager().getState(GameMusic.class));
|
||||
addChild(loadButton)
|
||||
.addClickCommands(s -> ifTopDialog(this::loadDialog));
|
||||
addChild(saveButton)
|
||||
@ -61,8 +62,7 @@ class Menu extends Dialog {
|
||||
addChild(new Checkbox(lookup("menu.sound-enabled"), new StateCheckboxModel(app, GameSound.class)));
|
||||
|
||||
addChild(new Checkbox(lookup("menu.background-sound-enabled"), new StateCheckboxModel(app, GameMusic.class)));
|
||||
|
||||
addChild(slider);
|
||||
// addChild(slider);
|
||||
|
||||
}
|
||||
|
||||
@ -74,11 +74,15 @@ class Menu extends Dialog {
|
||||
loadButton.setEnabled(app.getGameLogic().mayLoadMap());
|
||||
saveButton.setEnabled(app.getGameLogic().maySaveMap());
|
||||
}
|
||||
@Override
|
||||
public void update(float delta){
|
||||
|
||||
/* @Override
|
||||
public void update(float delta) {
|
||||
slider.update();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* As an escape action, this method closes the menu if it is the top dialog.
|
||||
*/
|
||||
|
@ -1,12 +1,5 @@
|
||||
package pp.battleship.game.client;
|
||||
|
||||
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import com.jme3.app.Application;
|
||||
import com.jme3.app.state.AbstractAppState;
|
||||
import com.jme3.app.state.AppStateManager;
|
||||
@ -15,6 +8,12 @@ import com.jme3.asset.AssetNotFoundException;
|
||||
import com.jme3.audio.AudioData;
|
||||
import com.jme3.audio.AudioNode;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
public class GameMusic extends AbstractAppState{
|
||||
private static final Logger LOGGER = System.getLogger(GameMusic.class.getName());
|
||||
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
|
||||
@ -43,7 +42,7 @@ public class GameMusic extends AbstractAppState{
|
||||
|
||||
/**
|
||||
* Initializes the sound effects for the game.
|
||||
* Overrides {@link AbstractAppState#initialize(AppStateManager, Application)}
|
||||
* Overrides {@link com.jme3.app.state.AbstractAppState#initialize(com.jme3.app.state.AppStateManager, com.jme3.app.Application)}
|
||||
*
|
||||
* @param stateManager The state manager
|
||||
* @param app The application
|
||||
@ -51,7 +50,7 @@ public class GameMusic extends AbstractAppState{
|
||||
@Override
|
||||
public void initialize(AppStateManager stateManager, Application app) {
|
||||
super.initialize(stateManager, app);
|
||||
music = loadSound(app, "Sound/DasBootMenu.ogg");
|
||||
music = loadSoundb(app, "Sound/Music/My_heart_will_go_on.ogg");
|
||||
setVolume(volumeInPreferences());
|
||||
music.setLooping(true);
|
||||
if (isEnabled() && music != null) {
|
||||
@ -66,7 +65,7 @@ public class GameMusic extends AbstractAppState{
|
||||
* @param name The name of the sound file.
|
||||
* @return The loaded AudioNode.
|
||||
*/
|
||||
/* private AudioNode loadSound(Application app, String name) {
|
||||
private AudioNode loadSoundb(Application app, String name) {
|
||||
try{
|
||||
final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer);
|
||||
sound.setLooping(false);
|
||||
@ -79,7 +78,7 @@ public class GameMusic extends AbstractAppState{
|
||||
return null;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Sets the enabled state of this AppState.
|
||||
|
Loading…
Reference in New Issue
Block a user