Support playing background music for mobile game

This commit is contained in:
drdev
2014-06-28 23:52:09 +00:00
parent eee745010a
commit 4135b2006e
33 changed files with 72 additions and 2 deletions

28
.gitattributes vendored
View File

@@ -15282,6 +15282,34 @@ forge-gui/res/lists/quest-pet-shop-icons.txt svneol=native#text/plain
forge-gui/res/lists/quest-pet-token-images.txt svneol=native#text/plain
forge-gui/res/lists/token-images.txt svneol=native#text/plain
forge-gui/res/lists/tournamentpack-images.txt svneol=native#text/plain
forge-gui/res/music/Credit.txt -text
forge-gui/res/music/match/8bit[!!-~]Dungeon[!!-~]Boss.mp3 -text
forge-gui/res/music/match/Dama-May.mp3 -text
forge-gui/res/music/match/Dangerous.mp3 -text
forge-gui/res/music/match/Exciting[!!-~]Trailer.mp3 -text
forge-gui/res/music/match/Faceoff.mp3 -text
forge-gui/res/music/match/Failing[!!-~]Defense.mp3 -text
forge-gui/res/music/match/Five[!!-~]Armies.mp3 -text
forge-gui/res/music/match/Hitman.mp3 -text
forge-gui/res/music/match/Machinations.mp3 -text
forge-gui/res/music/match/Movement[!!-~]Proposition.mp3 -text
forge-gui/res/music/match/Prelude[!!-~]and[!!-~]Action.mp3 -text
forge-gui/res/music/match/Round[!!-~]Drums.mp3 -text
forge-gui/res/music/match/The[!!-~]Complex.mp3 -text
forge-gui/res/music/match/The[!!-~]Descent.mp3 -text
forge-gui/res/music/match/Truth[!!-~]of[!!-~]the[!!-~]Legend.mp3 -text
forge-gui/res/music/menus/Angevin.mp3 -text
forge-gui/res/music/menus/At[!!-~]Launch.mp3 -text
forge-gui/res/music/menus/Enchanted[!!-~]Valley.mp3 -text
forge-gui/res/music/menus/Evil[!!-~]March.mp3 -text
forge-gui/res/music/menus/Heroic[!!-~]Age.mp3 -text
forge-gui/res/music/menus/Ignosi.mp3 -text
forge-gui/res/music/menus/Lord[!!-~]of[!!-~]the[!!-~]Land.mp3 -text
forge-gui/res/music/menus/Majestic[!!-~]Hills.mp3 -text
forge-gui/res/music/menus/Mighty[!!-~]and[!!-~]Meek.mp3 -text
forge-gui/res/music/menus/Myst.mp3 -text
forge-gui/res/music/menus/The[!!-~]Pyre.mp3 -text
forge-gui/res/music/menus/Willow[!!-~]and[!!-~]the[!!-~]Light.mp3 -text
forge-gui/res/quest/bazaar/ape_pet_l1.txt -text
forge-gui/res/quest/bazaar/ape_pet_l2.txt -text
forge-gui/res/quest/bazaar/ape_pet_l3.txt -text

View File

@@ -23,6 +23,7 @@ import forge.screens.FScreen;
import forge.screens.SplashScreen;
import forge.screens.home.HomeScreen;
import forge.screens.match.FControl;
import forge.sound.MusicPlayer;
import forge.sound.SoundSystem;
import forge.toolbox.FContainer;
import forge.toolbox.FDisplayObject;
@@ -45,6 +46,7 @@ public class Forge implements ApplicationListener {
private static FScreen currentScreen;
private static SplashScreen splashScreen;
private static KeyInputAdapter keyInputAdapter;
private static MusicPlayer musicPlayer;
private static final SoundSystem soundSystem = new SoundSystem();
private static final Stack<FScreen> screens = new Stack<FScreen>();
@@ -67,6 +69,7 @@ public class Forge implements ApplicationListener {
graphics = new Graphics();
splashScreen = new SplashScreen();
musicPlayer = new MusicPlayer(ForgeConstants.MUSIC_DIR + "menus");
String skinName;
if (FileUtil.doesFileExist(ForgeConstants.MAIN_PREFS_FILE)) {
@@ -106,6 +109,8 @@ public class Forge implements ApplicationListener {
FSkin.loadFull(splashScreen);
musicPlayer.play(); //start background music
Gdx.input.setInputProcessor(new MainInputProcessor());
Gdx.input.setCatchBackKey(true);
Gdx.input.setCatchMenuKey(true);
@@ -195,6 +200,10 @@ public class Forge implements ApplicationListener {
return soundSystem;
}
public static MusicPlayer getMusicPlayer() {
return musicPlayer;
}
@Override
public void render() {
try {
@@ -249,6 +258,7 @@ public class Forge implements ApplicationListener {
@Override
public void resume() {
FControl.resume();
}
@Override
@@ -264,6 +274,8 @@ public class Forge implements ApplicationListener {
}
screens.clear();
graphics.dispose();
musicPlayer.dispose();
FControl.dispose();
if (onExit != null) {
onExit.run();

View File

@@ -57,6 +57,7 @@ import forge.match.input.InputProxy;
import forge.match.input.InputQueue;
import forge.model.FModel;
import forge.player.LobbyPlayerHuman;
import forge.properties.ForgeConstants;
import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.FPref;
import forge.quest.QuestController;
@@ -66,6 +67,7 @@ import forge.screens.match.views.VCardDisplayArea.CardAreaPanel;
import forge.screens.match.views.VPhaseIndicator;
import forge.screens.match.views.VPhaseIndicator.PhaseLabel;
import forge.screens.match.views.VPlayerPanel;
import forge.sound.MusicPlayer;
import forge.toolbox.FCardPanel;
import forge.toolbox.FDisplayObject;
import forge.toolbox.FOptionPane;
@@ -85,6 +87,7 @@ public class FControl {
private static List<Player> sortedPlayers;
private static final EventBus uiEvents;
private static boolean gameHasHumanPlayer;
private static final MusicPlayer matchMusicPlayer = new MusicPlayer(ForgeConstants.MUSIC_DIR + "match");
private static final MatchUiEventVisitor visitor = new MatchUiEventVisitor();
private static final FControlGameEventHandler fcVisitor = new FControlGameEventHandler();
private static final FControlGamePlayback playbackControl = new FControlGamePlayback();
@@ -119,6 +122,9 @@ public class FControl {
public static void startGame(final Match match) {
CardAreaPanel.resetForNewGame(); //ensure card panels reset between games
Forge.getMusicPlayer().stop(); //switch out menu music for random match screen track
matchMusicPlayer.changeTrack();
game = match.createGame();
if (game.getRules().getGameType() == GameType.Quest) {
@@ -567,12 +573,23 @@ public class FControl {
}
public static void pause() {
Forge.getMusicPlayer().pause();
matchMusicPlayer.pause();
//pause playback if needed
if (inputQueue != null && inputQueue.getInput() instanceof InputPlaybackControl) {
((InputPlaybackControl)inputQueue.getInput()).pause();
}
}
public static void resume() {
Forge.getMusicPlayer().resume();
matchMusicPlayer.resume();
}
public static void dispose() {
matchMusicPlayer.dispose();
}
private final static boolean LOG_UIEVENTS = false;
// UI-related events should arrive here
@@ -776,6 +793,13 @@ public class FControl {
return cl;
}
public static void onViewClosed() {
matchMusicPlayer.stop();
Forge.getMusicPlayer().changeTrack(); //switch back to random menu screen music
writeMatchPreferences();
}
public static void writeMatchPreferences() {
ForgePreferences prefs = FModel.getPreferences();

View File

@@ -122,7 +122,7 @@ public class MatchScreen extends FScreen {
@Override
public void onClose(Callback<Boolean> canCloseCallback) {
FControl.writeMatchPreferences();
FControl.onViewClosed();
super.onClose(canCloseCallback);
}

View File

@@ -0,0 +1,5 @@
Music contained within this folder is credited to:
Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 3.0
http://creativecommons.org/licenses/by/3.0/

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -55,6 +55,7 @@ public final class ForgeConstants {
public static final String DECK_CUBE_DIR = RES_DIR + "cube/";
public static final String AI_PROFILE_DIR = RES_DIR + "ai/";
public static final String SOUND_DIR = RES_DIR + "sound/";
public static final String MUSIC_DIR = RES_DIR + "music/";
private static final String QUEST_DIR = RES_DIR + "quest/";
public static final String QUEST_WORLD_DIR = QUEST_DIR + "world/";