3 Commits

Author SHA1 Message Date
Luca Puderbach
14c68f55d9 ltl backgrounds 2024-12-08 01:16:26 +01:00
Yvonne Schmidt
392a81b2d8 fixed background music overlap 2024-12-07 18:29:41 +01:00
Yvonne Schmidt
944b6b674e replaced text displays with labels 2024-12-07 14:54:55 +01:00
16 changed files with 137 additions and 38 deletions

View File

@@ -3,6 +3,7 @@
// https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling // https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling
import com.jme3.math.ColorRGBA import com.jme3.math.ColorRGBA
import com.jme3.texture.Texture
import com.simsilica.lemur.* import com.simsilica.lemur.*
import com.simsilica.lemur.component.QuadBackgroundComponent import com.simsilica.lemur.component.QuadBackgroundComponent
import com.simsilica.lemur.Button import com.simsilica.lemur.Button
@@ -47,6 +48,23 @@ def orangeBorder = TbtQuadBackgroundComponent.create(
1f, false) 1f, false)
orangeBorder.color = color(1, 0.5, 0, 1) // Orange color orangeBorder.color = color(1, 0.5, 0, 1) // Orange color
def createCustomBackground(app) {
// Load the texture from the assets
Texture texture = app.getAssetManager().loadTexture("Pictures/kontobg.png")
// Create the TbtQuadBackgroundComponent
def backgroundCustom = TbtQuadBackgroundComponent.create(
texture, // The texture to use
1, 1, 1, // Insets for the 9-patch behavior
126, 126, // The size of the texture
1f, // The scale factor
false // No tiling
)
return backgroundCustom
}
selector("pp") { selector("pp") {
font = font("Interface/Fonts/Metropolis/Metropolis-Regular-32.fnt") font = font("Interface/Fonts/Metropolis/Metropolis-Regular-32.fnt")
} }
@@ -366,3 +384,12 @@ selector("button-toolbar", "pp") {
} }
selector("button-toolbar2", "pp") {
insets = new Insets3f(3, 3, 3, 3) // Adjust the border thickness
textHAlignment = HAlignment.Center
textVAlignment = VAlignment.Center
buttonCommands = stdButtonCommandsToolbar
}

View File

@@ -13,14 +13,13 @@ import com.jme3.asset.AssetLoadException;
import com.jme3.asset.AssetNotFoundException; 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;
/** /**
* Handles the background and secondary music in the game. * Handles the background and secondary music in the game.
* Allows playing, stopping, and toggling between background music and a secondary track. * Allows playing, stopping, and toggling between background music and a secondary track.
*/ */
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(pp.monopoly.client.GameMusic.class.getName());
private static final Preferences PREFERENCES = getPreferences(GameMusic.class); private static final Preferences PREFERENCES = getPreferences(pp.monopoly.client.GameMusic.class);
private static final String ENABLED_PREF = "enabled"; // NON-NLS private static final String ENABLED_PREF = "enabled"; // NON-NLS
private static final String VOLUME_PREF = "volume"; // NON-NLS private static final String VOLUME_PREF = "volume"; // NON-NLS
@@ -68,8 +67,9 @@ public class GameMusic extends AbstractAppState {
/** /**
* Plays the main music. * Plays the main music.
*/ */
private void playMainMusic() { public void playMainMusic() {
if (!isEnabled()) { if (!isEnabled()) {
return; // Sound is disabled return; // Sound is disabled
} }
@@ -92,11 +92,10 @@ public class GameMusic extends AbstractAppState {
/** /**
* Plays the secondary music and stops the main music. * Plays the secondary music and stops the main music.
* *
* @param app The application instance
* @param secondaryMusicFile The file path of the secondary audio file
*/ */
private void playSecondaryMusic() { public void playSecondaryMusic() {
if(!isEnabled()) { if (!isEnabled()) {
stopAllMusic();
return; return;
} }
if (isSecondaryMusicPlaying) { if (isSecondaryMusicPlaying) {
@@ -115,7 +114,7 @@ public class GameMusic extends AbstractAppState {
/** /**
* Stops the secondary music. * Stops the secondary music.
*/ */
private void stopSecondaryMusic() { public void stopSecondaryMusic() {
if (secondaryMusic != null && isSecondaryMusicPlaying) { if (secondaryMusic != null && isSecondaryMusicPlaying) {
secondaryMusic.stop(); secondaryMusic.stop();
isSecondaryMusicPlaying = false; isSecondaryMusicPlaying = false;
@@ -127,17 +126,17 @@ public class GameMusic extends AbstractAppState {
* If the secondary track is playing, it stops and resumes the background music. * If the secondary track is playing, it stops and resumes the background music.
* If the background music is playing, it pauses and plays the secondary track. * If the background music is playing, it pauses and plays the secondary track.
* *
* @param app The application instance
* @param secondaryMusicFile The file path of the secondary audio file
*/ */
public void toggleMusic() { public void toggleMusic() {
if(!isEnabled()) { if (!isEnabled()) {
stopAllMusic();
return; return;
} }
if (isSecondaryMusicPlaying) { if (isSecondaryMusicPlaying) {
stopSecondaryMusic(); stopSecondaryMusic();
playMainMusic(); playMainMusic();
} else { } else {
stopMainMusic();
playSecondaryMusic(); playSecondaryMusic();
} }
} }
@@ -153,6 +152,14 @@ public class GameMusic extends AbstractAppState {
PREFERENCES.putFloat(VOLUME_PREF, vol); PREFERENCES.putFloat(VOLUME_PREF, vol);
} }
/**
* Stops all music (both main and secondary).
*/
public void stopAllMusic() {
stopMainMusic();
stopSecondaryMusic();
}
/** /**
* Enables or disables the sound system. * Enables or disables the sound system.
* When disabled, all music stops. * When disabled, all music stops.
@@ -161,13 +168,14 @@ public class GameMusic extends AbstractAppState {
*/ */
@Override @Override
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
if (isEnabled() == enabled) return; if (isEnabled() == enabled) return; // Avoid redundant operations
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
if (enabled) { if (enabled) {
playMainMusic(); playMainMusic();
} else { } else {
stopMainMusic(); stopAllMusic();
stopSecondaryMusic();
} }
super.setEnabled(enabled); super.setEnabled(enabled);

View File

@@ -79,8 +79,9 @@ public class LobbyMenu extends Dialog {
this.app = app; this.app = app;
GameMusic music = app.getStateManager().getState(GameMusic.class); GameMusic music = app.getStateManager().getState(GameMusic.class);
music.toggleMusic(); if (music != null && music.isEnabled()) {
music.playSecondaryMusic();
}
playerInputField = new TextField("Spieler "+(app.getId()+1)); playerInputField = new TextField("Spieler "+(app.getId()+1));
// Hintergrundbild laden und hinzufügen // Hintergrundbild laden und hinzufügen
addBackgroundImage(); addBackgroundImage();
@@ -276,6 +277,12 @@ public class LobbyMenu extends Dialog {
new SettingsMenu(app).open(); new SettingsMenu(app).open();
} }
/**
* Updates the menu at regular intervals.
* Checks if the dropdown selection has been updated and invokes the selection change handler.
*
* @param tpf Time per frame, in seconds, since the last update.
*/
@Override @Override
public void update(float tpf) { public void update(float tpf) {
if (selectionRef.update()) { if (selectionRef.update()) {
@@ -283,10 +290,27 @@ public class LobbyMenu extends Dialog {
} }
} }
/**
* Closes the current menu and transitions music playback.
* Stops the secondary music (if playing) and resumes the main background music
* if music is enabled in the preferences. Ensures smooth transitions in audio.
*/
@Override
public void close() {
GameMusic music = app.getStateManager().getState(GameMusic.class);
if (music != null) {
music.stopSecondaryMusic();
if (music.isEnabled()) {
music.playMainMusic();
}
}
super.close();
}
/** /**
* Updates the selected figure based on the dropdown menu selection. * Updates the selected figure based on the dropdown menu selection.
* *
* @param selected the selected figure * @param selector the selected figure
*/ */
private void onDropdownSelectionChanged(Selector<String> selector) { private void onDropdownSelectionChanged(Selector<String> selector) {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);

View File

@@ -51,7 +51,17 @@ public class SettingsMenu extends Dialog {
private final SoundSlider soundSlider; private final SoundSlider soundSlider;
/** /**
* Constructs the Menu dialog for the Battleship application. * Checkbox for toggling sound effects.
*/
private final Checkbox soundCheckbox;
/**
* Checkbox for toggling background music.
*/
private final Checkbox musicCheckbox;
/**
* Constructs the Menu dialog for the Monopoly application.
* *
* @param app the MonopolyApp instance * @param app the MonopolyApp instance
*/ */
@@ -65,11 +75,15 @@ public class SettingsMenu extends Dialog {
addChild(soundSlider); addChild(soundSlider);
addChild(new Checkbox("Soundeffekte an / aus", new StateCheckboxModel(app, GameSound.class))); soundCheckbox = new Checkbox("Soundeffekte an / aus", new StateCheckboxModel(app, GameSound.class));
addChild(soundCheckbox);
addChild(new Label("Hintergrund Musik", new ElementId("label"))); //NON-NLS addChild(new Label("Hintergrund Musik", new ElementId("label"))); //NON-NLS
addChild(new Checkbox("Musik an / aus", new StateCheckboxModel(app, GameMusic.class)));
musicCheckbox = new Checkbox("Musik an / aus", new StateCheckboxModel(app, GameMusic.class));
musicCheckbox.addClickCommands(s -> toggleMusicPreference());
addChild(musicCheckbox);
addChild(musicSlider); addChild(musicSlider);
addChild(new Button("Zurück zum Spiel", new ElementId("button"))).addClickCommands(s -> ifTopDialog(() -> { addChild(new Button("Zurück zum Spiel", new ElementId("button"))).addClickCommands(s -> ifTopDialog(() -> {
@@ -84,16 +98,42 @@ public class SettingsMenu extends Dialog {
} }
/** /**
* Updates the state of the load and save buttons based on the game logic. * Toggles the music preference based on the state of the musicCheckbox.
* Enables or disables background music and starts playback if enabled.
*/
private void toggleMusicPreference() {
boolean enabled = musicCheckbox.isChecked();
GameMusic gameMusic = app.getStateManager().getState(GameMusic.class);
if (gameMusic != null) {
gameMusic.setEnabled(enabled);
if (enabled) {
gameMusic.playMainMusic();
}
}
}
/**
* Updates the state of the music checkbox to match the current preferences.
* This ensures the checkbox reflects the actual enabled/disabled state of the music.
*/ */
@Override @Override
public void update() { public void update() {
GameMusic gameMusic = app.getStateManager().getState(GameMusic.class);
if (gameMusic != null) {
musicCheckbox.setChecked(gameMusic.isEnabled());
}
} }
/**
* Updates UI elements such as sliders and synchronizes the state of the settings menu.
*
* @param delta the time in seconds since the last update
*/
@Override @Override
public void update(float delta) { public void update(float delta) {
musicSlider.update(); musicSlider.update();
soundSlider.update(); soundSlider.update();
update();
} }
/** /**

View File

@@ -257,7 +257,7 @@ public class Toolbar extends Dialog implements GameEventListener {
} }
private Button createPropertyMenuButton() { private Button createPropertyMenuButton() {
propertyMenuButton = new Button("", new ElementId("button-toolbar")); propertyMenuButton = new Button("", new ElementId("button-toolbar2"));
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0)); propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0));
String iconBuildingPath = "icons/icon-gebaude.png"; String iconBuildingPath = "icons/icon-gebaude.png";

View File

@@ -40,8 +40,8 @@ public class BuyHouse extends Dialog {
/** Background container providing a border for the popup. */ /** Background container providing a border for the popup. */
private final Container backgroundContainer; private final Container backgroundContainer;
/** TextField to display selected properties. */ /** Label to display selected properties. */
private TextField selectionDisplay; private Label selectionDisplay;
/** Reference for tracking dropdown selection changes. */ /** Reference for tracking dropdown selection changes. */
private VersionedReference<Set<Integer>> selectionRef; private VersionedReference<Set<Integer>> selectionRef;
@@ -162,7 +162,7 @@ public class BuyHouse extends Dialog {
selectionRef = propertySelector.getSelectionModel().createReference(); selectionRef = propertySelector.getSelectionModel().createReference();
// Initialize the selection display here // Initialize the selection display here
selectionDisplay = new TextField(""); // Create TextField for displaying selections selectionDisplay = new Label("");
selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0));
dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container

View File

@@ -45,8 +45,8 @@ public class RepayMortage extends Dialog {
/** Background container providing a border for the popup. */ /** Background container providing a border for the popup. */
private final Container backgroundContainer; private final Container backgroundContainer;
/** Text field to display selected properties. */ /** Label to display selected properties. */
private TextField selectionDisplay; private Label selectionDisplay;
/** Reference to track property selections in the dropdown menu. */ /** Reference to track property selections in the dropdown menu. */
private VersionedReference<Set<Integer>> selectionRef; private VersionedReference<Set<Integer>> selectionRef;
@@ -166,7 +166,7 @@ public class RepayMortage extends Dialog {
selectionRef = propertySelector.getSelectionModel().createReference(); selectionRef = propertySelector.getSelectionModel().createReference();
// Initialize the selection display here // Initialize the selection display here
selectionDisplay = new TextField(""); // Create TextField for displaying selections selectionDisplay = new Label(""); // Create TextField for displaying selections
selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0));
dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container

View File

@@ -45,8 +45,8 @@ public class SellHouse extends Dialog {
/** Background container providing a styled border around the main dialog. */ /** Background container providing a styled border around the main dialog. */
private final Container backgroundContainer; private final Container backgroundContainer;
/** Text field to display selected properties. */ /** Label to display selected properties. */
private TextField selectionDisplay; private Label selectionDisplay;
/** Reference to track selection changes in the property selector. */ /** Reference to track selection changes in the property selector. */
private VersionedReference<Set<Integer>> selectionRef; private VersionedReference<Set<Integer>> selectionRef;
@@ -86,7 +86,7 @@ public class SellHouse extends Dialog {
title.setFontSize(48); title.setFontSize(48);
title.setColor(ColorRGBA.Black); title.setColor(ColorRGBA.Black);
//Unterteilund des sellHouseContainer in drei "Untercontainer" //Unterteilung des sellHouseContainer in drei "Untercontainer"
Container upContainer = sellhouseContainer.addChild(new Container()); Container upContainer = sellhouseContainer.addChild(new Container());
Container middleContainer = sellhouseContainer.addChild(new Container()); Container middleContainer = sellhouseContainer.addChild(new Container());
Container downContainer = sellhouseContainer.addChild(new Container()); Container downContainer = sellhouseContainer.addChild(new Container());
@@ -172,7 +172,7 @@ public class SellHouse extends Dialog {
selectionRef = propertySelector.getSelectionModel().createReference(); selectionRef = propertySelector.getSelectionModel().createReference();
// Initialize the selection display here // Initialize the selection display here
selectionDisplay = new TextField(""); // Create TextField for displaying selections selectionDisplay = new Label("");
selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0));
dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container

View File

@@ -46,8 +46,8 @@ public class TakeMortage extends Dialog {
/** Background container providing a styled border around the main dialog. */ /** Background container providing a styled border around the main dialog. */
private final Container backgroundContainer; private final Container backgroundContainer;
/** Text field to display selected properties. */ /** Label to display selected properties. */
private TextField selectionDisplay; private Label selectionDisplay;
/** Reference to track selection changes in the property selector. */ /** Reference to track selection changes in the property selector. */
private VersionedReference<Set<Integer>> selectionRef; private VersionedReference<Set<Integer>> selectionRef;
@@ -172,7 +172,7 @@ public class TakeMortage extends Dialog {
selectionRef = propertySelector.getSelectionModel().createReference(); selectionRef = propertySelector.getSelectionModel().createReference();
// Initialize the selection display here // Initialize the selection display here
selectionDisplay = new TextField(""); // Create TextField for displaying selections selectionDisplay = new Label(""); // Create TextField for displaying selections
selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0));
dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB