-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: Heartsystem, warning-popups, weekendreport, styling and major bu…
…g fixes
- Loading branch information
Showing
24 changed files
with
282 additions
and
239 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Audio/Audio.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.Audio; | ||
|
|
||
| public enum Audio { | ||
|
|
||
| // Sound effects | ||
| OPEN_APP("/Audio/open_app.wav"), | ||
| CLOSE_APP("/Audio/close_app.wav"), | ||
| CLOCK("/Audio/clock.wav"), | ||
| TRANSACTION("/Audio/transaction.wav"), | ||
|
|
||
| // Background music | ||
| WORK_THEME("/Audio/work_theme.mp3"), | ||
| WEEKEND_THEME("/Audio/weekend_theme.mp3"); | ||
|
|
||
| private String path; | ||
|
|
||
| Audio(String path) { | ||
| this.path = path; | ||
| } | ||
|
|
||
| public String getPath() { | ||
| return path; | ||
| } | ||
| } |
74 changes: 43 additions & 31 deletions
74
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Audio/AudioManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,60 @@ | ||
| package edu.ntnu.idi.idatt2003.gruppe42.Audio; | ||
|
|
||
| import javafx.scene.media.Media; | ||
| import javafx.scene.media.MediaPlayer; | ||
|
|
||
| import java.util.EnumMap; | ||
| import java.util.Map; | ||
| import javafx.scene.Node; | ||
| import javafx.scene.input.MouseEvent; | ||
| import javafx.scene.media.AudioClip; | ||
|
|
||
| /** | ||
| * Zero-latency sound effect player. | ||
| * | ||
| * <p>All assets in {@link SoundEffect} are decoded into in-memory | ||
| * {@link AudioClip}s on first instantiation, so {@link #play(SoundEffect)} | ||
| * fires immediately without any I/O.</p> | ||
| */ | ||
| public final class AudioManager { | ||
|
|
||
| private static final AudioManager INSTANCE = new AudioManager(); | ||
| public class AudioManager { | ||
|
|
||
| private final Map<SoundEffect, AudioClip> clips = new EnumMap<>(SoundEffect.class); | ||
| private double volume = 1.0; | ||
| private static final AudioManager instance = new AudioManager(); | ||
| private final Map<Audio, String> urlCache = new EnumMap<>(Audio.class); | ||
| private MediaPlayer bgPlayer; | ||
|
|
||
| private AudioManager() { | ||
| for (SoundEffect effect : SoundEffect.values()) { | ||
| AudioClip clip = new AudioClip( | ||
| getClass().getResource(effect.getPath()).toExternalForm() | ||
| ); | ||
| clips.put(effect, clip); | ||
| for (Audio audio : Audio.values()) { | ||
| var url = getClass().getResource(audio.getPath()); | ||
| urlCache.put(audio, url.toExternalForm()); | ||
| } | ||
| } | ||
|
|
||
| public static AudioManager getInstance() { | ||
| return INSTANCE; | ||
| public static AudioManager getInstance() { return instance; } | ||
|
|
||
| public void playSFX(Audio audio) { | ||
| String url = urlCache.get(audio); | ||
|
|
||
| if (url == null) { | ||
| return; | ||
| } | ||
|
|
||
| MediaPlayer sfxPlayer = new MediaPlayer(new Media(url)); | ||
| sfxPlayer.setOnEndOfMedia(() -> { | ||
| sfxPlayer.stop(); | ||
| sfxPlayer.dispose(); | ||
| }); | ||
|
|
||
| sfxPlayer.play(); | ||
| } | ||
|
|
||
| /** Plays the given sound at the current master volume. */ | ||
| public void play(final SoundEffect sound) { | ||
| AudioClip clip = clips.get(sound); | ||
| if (clip != null) { | ||
| clip.play(volume); | ||
| public void playBgMusic(Audio audio) { | ||
| stopBgMusic(); | ||
|
|
||
| String url = urlCache.get(audio); | ||
| if (url == null) { | ||
| return; | ||
| } | ||
|
|
||
| bgPlayer = new MediaPlayer(new Media(url)); | ||
| bgPlayer.setVolume(1); | ||
| bgPlayer.play(); | ||
| } | ||
|
|
||
| /** Sets the master volume in the range [0.0, 1.0]. */ | ||
| public void setVolume(final double volume) { | ||
| this.volume = Math.max(0.0, Math.min(1.0, volume)); | ||
| public void stopBgMusic() { | ||
| if (bgPlayer != null) { | ||
| bgPlayer.stop(); | ||
| bgPlayer.dispose(); | ||
| bgPlayer = null; | ||
| } | ||
| } | ||
| } | ||
| } |
23 changes: 0 additions & 23 deletions
23
src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Audio/SoundEffect.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.