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