Fixed a bug where sounds weren't reloaded when changing skins.
When restarting the program through the options menu, all sounds now get reloaded if the skin was changed. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
f3825eba5e
commit
90c8c9e705
|
@ -911,15 +911,12 @@ public class Options {
|
||||||
* If the directory is invalid, the default skin will be loaded.
|
* If the directory is invalid, the default skin will be loaded.
|
||||||
*/
|
*/
|
||||||
public static void loadSkin() {
|
public static void loadSkin() {
|
||||||
File root = getSkinRootDir();
|
File skinDir = getSkinDir();
|
||||||
File skinDir = new File(root, skinName);
|
if (skinDir == null) // invalid skin name
|
||||||
if (!skinDir.isDirectory()) { // invalid skin name
|
|
||||||
skinName = Skin.DEFAULT_SKIN_NAME;
|
skinName = Skin.DEFAULT_SKIN_NAME;
|
||||||
skinDir = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create available skins list
|
// create available skins list
|
||||||
File[] dirs = SkinLoader.getSkinDirectories(root);
|
File[] dirs = SkinLoader.getSkinDirectories(getSkinRootDir());
|
||||||
skinDirs = new String[dirs.length + 1];
|
skinDirs = new String[dirs.length + 1];
|
||||||
skinDirs[0] = Skin.DEFAULT_SKIN_NAME;
|
skinDirs[0] = Skin.DEFAULT_SKIN_NAME;
|
||||||
for (int i = 0; i < dirs.length; i++)
|
for (int i = 0; i < dirs.length; i++)
|
||||||
|
@ -953,6 +950,21 @@ public class Options {
|
||||||
*/
|
*/
|
||||||
public static Skin getSkin() { return skin; }
|
public static Skin getSkin() { return skin; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current skin directory.
|
||||||
|
* <p>
|
||||||
|
* NOTE: This directory will differ from that of the currently loaded skin
|
||||||
|
* if {@link #loadSkin()} has not been called after a directory change.
|
||||||
|
* Use {@link Skin#getDirectory()} to get the directory of the currently
|
||||||
|
* loaded skin.
|
||||||
|
* @return the skin directory, or null for the default skin
|
||||||
|
*/
|
||||||
|
public static File getSkinDir() {
|
||||||
|
File root = getSkinRootDir();
|
||||||
|
File dir = new File(root, skinName);
|
||||||
|
return (dir.isDirectory()) ? dir : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a dummy Beatmap containing the theme song.
|
* Returns a dummy Beatmap containing the theme song.
|
||||||
* @return the theme song beatmap
|
* @return the theme song beatmap
|
||||||
|
|
|
@ -105,6 +105,12 @@ public enum HitSound implements SoundController.SoundComponent {
|
||||||
return (currentSampleSet != null) ? clips.get(currentSampleSet) : null;
|
return (currentSampleSet != null) ? clips.get(currentSampleSet) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Clip associated with the given sample set.
|
||||||
|
* @param s the sample set
|
||||||
|
*/
|
||||||
|
public MultiClip getClip(SampleSet s) { return clips.get(s); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the hit sound Clip for the sample type.
|
* Sets the hit sound Clip for the sample type.
|
||||||
* @param s the sample set
|
* @param s the sample set
|
||||||
|
|
|
@ -207,7 +207,14 @@ public class SoundController {
|
||||||
ErrorHandler.error(String.format("Could not find sound file '%s'.", s.getFileName()), null, false);
|
ErrorHandler.error(String.format("Could not find sound file '%s'.", s.getFileName()), null, false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
s.setClip(loadClip(currentFileName, currentFileName.endsWith(".mp3")));
|
MultiClip newClip = loadClip(currentFileName, currentFileName.endsWith(".mp3"));
|
||||||
|
if (s.getClip() != null) { // clip previously loaded (e.g. program restart)
|
||||||
|
if (newClip != null) {
|
||||||
|
s.getClip().destroy(); // destroy previous clip
|
||||||
|
s.setClip(newClip);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
s.setClip(newClip);
|
||||||
currentFileIndex++;
|
currentFileIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +226,14 @@ public class SoundController {
|
||||||
ErrorHandler.error(String.format("Could not find hit sound file '%s'.", filename), null, false);
|
ErrorHandler.error(String.format("Could not find hit sound file '%s'.", filename), null, false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
s.setClip(ss, loadClip(currentFileName, false));
|
MultiClip newClip = loadClip(currentFileName, false);
|
||||||
|
if (s.getClip(ss) != null) { // clip previously loaded (e.g. program restart)
|
||||||
|
if (newClip != null) {
|
||||||
|
s.getClip(ss).destroy(); // destroy previous clip
|
||||||
|
s.setClip(ss, newClip);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
s.setClip(ss, newClip);
|
||||||
currentFileIndex++;
|
currentFileIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,9 @@ public class Splash extends BasicGameState {
|
||||||
/** Number of times the 'Esc' key has been pressed. */
|
/** Number of times the 'Esc' key has been pressed. */
|
||||||
private int escapeCount = 0;
|
private int escapeCount = 0;
|
||||||
|
|
||||||
|
/** Whether the skin being loaded is a new skin (for program restarts). */
|
||||||
|
private boolean newSkin = false;
|
||||||
|
|
||||||
// game-related variables
|
// game-related variables
|
||||||
private int state;
|
private int state;
|
||||||
private GameContainer container;
|
private GameContainer container;
|
||||||
|
@ -69,6 +72,10 @@ public class Splash extends BasicGameState {
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
|
||||||
|
// check if skin changed
|
||||||
|
if (Options.getSkin() != null)
|
||||||
|
this.newSkin = (Options.getSkin().getDirectory() != Options.getSkinDir());
|
||||||
|
|
||||||
// load Utils class first (needed in other 'init' methods)
|
// load Utils class first (needed in other 'init' methods)
|
||||||
Utils.init(container, game);
|
Utils.init(container, game);
|
||||||
|
|
||||||
|
@ -89,11 +96,27 @@ public class Splash extends BasicGameState {
|
||||||
if (!init) {
|
if (!init) {
|
||||||
init = true;
|
init = true;
|
||||||
|
|
||||||
|
// resources already loaded (from application restart)
|
||||||
if (BeatmapSetList.get() != null) {
|
if (BeatmapSetList.get() != null) {
|
||||||
// resources already loaded (from application restart)
|
// reload sounds if skin changed
|
||||||
finished = true;
|
if (newSkin) {
|
||||||
} else {
|
thread = new Thread() {
|
||||||
// load resources in a new thread
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// TODO: only reload each sound if actually needed?
|
||||||
|
SoundController.init();
|
||||||
|
|
||||||
|
finished = true;
|
||||||
|
thread = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
thread.start();
|
||||||
|
} else // don't reload anything
|
||||||
|
finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// load all resources in a new thread
|
||||||
|
else {
|
||||||
thread = new Thread() {
|
thread = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user