org.newdawn.slick.util.ResourceLoader Java Examples

The following examples show how to use org.newdawn.slick.util.ResourceLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Fonts.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes all fonts.
 * @throws SlickException if ASCII glyphs could not be loaded
 * @throws FontFormatException if any font stream data does not contain the required font tables
 * @throws IOException if a font stream cannot be completely read
 */
public static void init() throws SlickException, FontFormatException, IOException {
	float fontBase = 12f * GameImage.getUIscale();
	Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Constants.FONT_NAME));
	Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	DEFAULT = new UnicodeFont(font);
	BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
	XLARGE = new UnicodeFont(font.deriveFont(fontBase * 3));
	LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
	MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
	MEDIUMBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase * 3 / 2));
	SMALL = new UnicodeFont(font.deriveFont(fontBase));
	SMALLBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase));
	ColorEffect colorEffect = new ColorEffect();
	loadFont(DEFAULT, colorEffect);
	loadFont(BOLD, colorEffect);
	loadFont(XLARGE, colorEffect);
	loadFont(LARGE, colorEffect);
	loadFont(MEDIUM, colorEffect);
	loadFont(MEDIUMBOLD, colorEffect);
	loadFont(SMALL, colorEffect);
	loadFont(SMALLBOLD, colorEffect);
}
 
Example #2
Source File: SoundController.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads and returns a Clip from a resource.
 * @param ref the resource name
 * @param isMP3 true if MP3, false if WAV
 * @return the loaded and opened clip
 */
private static MultiClip loadClip(String ref, boolean isMP3) {
	try {
		URL url = ResourceLoader.getResource(ref);

		// check for 0 length files
		InputStream in = url.openStream();
		if (in.available() == 0) {
			in.close();
			return new MultiClip(ref, null);
		}
		in.close();

		AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
		return loadClip(ref, audioIn, isMP3);
	} catch (Exception e) {
		softErr(e, "Failed to load clip %s", ref);
		return null;
	}
}
 
Example #3
Source File: SoundController.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the sound file name, with extension, by first looking through
 * the skins directory and then the default resource locations.
 * @param filename the base file name
 * @return the full file name, or null if no file found
 */
private static String getSoundFileName(String filename) {
	String wav = String.format("%s.wav", filename), mp3 = String.format("%s.mp3", filename);
	File skinDir = SkinService.skin.getDirectory();
	if (skinDir != null) {
		File skinWAV = new File(skinDir, wav), skinMP3 = new File(skinDir, mp3);
		if (skinWAV.isFile())
			return skinWAV.getAbsolutePath();
		if (skinMP3.isFile())
			return skinMP3.getAbsolutePath();
	}
	if (ResourceLoader.resourceExists(wav))
		return wav;
	if (ResourceLoader.resourceExists(mp3))
		return mp3;
	return null;
}
 
Example #4
Source File: FEResources.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Load resources.
 */
public static void loadResources() {
	try {
		//Load bitmap fonts
		loadBitmapFonts();
		
		// Textures
		textures.put("whoops", new AnimationData("res/whoops.png"));
		loadTextures();	
		//load audio
		audio.put("miss", AudioLoader.getAudio("WAV",
				ResourceLoader.getResourceAsStream("res/sfx/miss.wav")));
		
	} catch (IOException e) {
		int max = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE);
		System.out.println(max);
		e.printStackTrace();
	}
	System.gc();
}
 
Example #5
Source File: FEResources.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the texture data.
 *
 * @param string the string
 * @return the texture data
 */
public static AnimationData getTextureData(String string) {
	AnimationData t = textures.get(string);
	if(t != null) {
		return t;
	} else {
		//try to get it, in case we forgot
		System.err.println("Warn: " + string + " not explicitly defined");
		for(String loc: searchFolders){
			if(ResourceLoader.resourceExists("res/" + loc + "/" + string + ".png")){
				AnimationData txt = new AnimationData("res/" + loc + "/" + string + ".png");
				textures.put(string, txt);
				return txt;
			}
			
		}
		return textures.get("whoops");
	}
}
 
Example #6
Source File: FEResources.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
	 * Gets the audio.
	 *
	 * @param name the name
	 * @return the audio
	 */
	public static Audio getAudio(String name) {
		Audio a = audio.get(name);
		if(a == null) {
//			System.err.println("Warn: " + name + " not explicitly defined");
			try{
				Audio b = AudioLoader.getAudio("WAV",
						ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav"));
				audio.put(name, b);
				return b;
			} catch (Exception e){
				return null;
			}
		} else {
			return a;
		}
	}
 
Example #7
Source File: Options.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads the skin given by the current skin directory.
 * If the directory is invalid, the default skin will be loaded.
 */
public static void loadSkin() {
	File skinDir = getSkinDir();
	if (skinDir == null)  // invalid skin name
		skinName = Skin.DEFAULT_SKIN_NAME;

	// set skin and modify resource locations
	ResourceLoader.removeAllResourceLocations();
	if (skinDir == null)
		skin = new Skin(null);
	else {
		// load the skin
		skin = SkinLoader.loadSkin(skinDir);
		ResourceLoader.addResourceLocation(new FileSystemLocation(skinDir));
	}
	ResourceLoader.addResourceLocation(new ClasspathLocation());
	ResourceLoader.addResourceLocation(new FileSystemLocation(new File(".")));
	ResourceLoader.addResourceLocation(new FileSystemLocation(new File("./res/")));
}
 
Example #8
Source File: SoundController.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the sound file name, with extension, by first looking through
 * the skins directory and then the default resource locations.
 * @param filename the base file name
 * @return the full file name, or null if no file found
 */
private static String getSoundFileName(String filename) {
	String wav = String.format("%s.wav", filename), mp3 = String.format("%s.mp3", filename);
	File skinDir = Options.getSkin().getDirectory();
	if (skinDir != null) {
		File skinWAV = new File(skinDir, wav), skinMP3 = new File(skinDir, mp3);
		if (skinWAV.isFile())
			return skinWAV.getAbsolutePath();
		if (skinMP3.isFile())
			return skinMP3.getAbsolutePath();
	}
	if (ResourceLoader.resourceExists(wav))
		return wav;
	if (ResourceLoader.resourceExists(mp3))
		return mp3;
	return null;
}
 
Example #9
Source File: FEResources.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public static void loadResources() {
	try {
		//Load bitmap fonts
		loadBitmapFonts();
		
		// Textures
		textures.put("whoops", new AnimationData("res/whoops.png"));
		loadTextures();	
		//load audio
		audio.put("miss", AudioLoader.getAudio("WAV",
				ResourceLoader.getResourceAsStream("res/sfx/miss.wav")));
		
	} catch (IOException e) {
		int max = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE);
		System.out.println(max);
		e.printStackTrace();
	}
	System.gc();
}
 
Example #10
Source File: FEResources.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public static AnimationData getTextureData(String string) {
	AnimationData t = textures.get(string);
	if(t != null) {
		return t;
	} else {
		//try to get it, in case we forgot
		System.err.println("Warn: " + string + " not explicitly defined");
		for(String loc: searchFolders){
			if(ResourceLoader.resourceExists("res/" + loc + "/" + string + ".png")){
				AnimationData txt = new AnimationData("res/" + loc + "/" + string + ".png");
				textures.put(string, txt);
				return txt;
			}
			
		}
		return textures.get("whoops");
	}
}
 
Example #11
Source File: FEResources.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public static Audio getAudio(String name) {
		Audio a = audio.get(name);
		if(a == null) {
//			System.err.println("Warn: " + name + " not explicitly defined");
			try{
				Audio b = AudioLoader.getAudio("WAV",
						ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav"));
				audio.put(name, b);
				return b;
			} catch (Exception e){
				return null;
			}
		} else {
			return a;
		}
	}
 
Example #12
Source File: PackedSpriteSheet.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Load the definition file and parse each of the sections
 * 
 * @param def The location of the definitions file
 * @param trans The color to be treated as transparent
 * @throws SlickException Indicates a failure to read or parse the definitions file
 * or referenced image.
 */
private void loadDefinition(String def, Color trans) throws SlickException {
	BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));

	try {
		image = new Image(basePath+reader.readLine(), false, filter, trans);
		while (reader.ready()) {
			if (reader.readLine() == null) {
				break;
			}
			
			Section sect = new Section(reader);
			sections.put(sect.name, sect);
			
			if (reader.readLine() == null) {
				break;
			}
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to process definitions file - invalid format?", e);
	}
}
 
Example #13
Source File: XMLPackedSheet.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
	image = new Image(imageRef, false, Image.FILTER_NEAREST);

	try {
		DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
		Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));
		
		NodeList list = doc.getElementsByTagName("sprite");
		for (int i=0;i<list.getLength();i++) {
			Element element = (Element) list.item(i);
			
			String name = element.getAttribute("name");
			int x = Integer.parseInt(element.getAttribute("x"));
			int y = Integer.parseInt(element.getAttribute("y"));
			int width = Integer.parseInt(element.getAttribute("width"));
			int height = Integer.parseInt(element.getAttribute("height"));
			
			sprites.put(name, image.getSubImage(x,y,width,height));
		}
	} catch (Exception e) {
		throw new SlickException("Failed to parse sprite sheet XML", e);
	}
}
 
Example #14
Source File: SoundTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	SoundStore.get().setMaxSources(32);
	
	myContainer = container;
	sound = new Sound("testdata/restart.ogg");
	charlie = new Sound("testdata/cbrown01.wav");
	try {
		engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
	} catch (IOException e) {
		throw new SlickException("Failed to load engine", e);
	}
	music = musica = new Music("testdata/SMB-X.XM");
	//music = musica = new Music("testdata/theme.ogg", true);
	musicb = new Music("testdata/kirby.ogg", true);
	burp = new Sound("testdata/burp.aif");
	
	music.play();
}
 
Example #15
Source File: SkinService.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads the skin given by the current skin directory.
 * If the directory is invalid, the default skin will be loaded.
 */
public void loadSkin() {
	File skinDir = getCurrentSkinDirectory();
	if (skinDir == null) {
		// invalid skin name
		usedSkinName = Skin.DEFAULT_SKIN_NAME;
	}

	// create available skins list
	File[] dirs = SkinLoader.getSkinDirectories(config.skinRootDir);
	availableSkinDirectories = new String[dirs.length + 1];
	availableSkinDirectories[0] = Skin.DEFAULT_SKIN_NAME;
	for (int i = 0; i < dirs.length; i++) {
		availableSkinDirectories[i + 1] = dirs[i].getName();
	}

	if (this.lastSkinLocation != null) {
		ResourceLoader.removeResourceLocation(this.lastSkinLocation);
		this.lastSkinLocation = null;
	}
	if (skinDir == null) {
		skin = new Skin(null);
		return;
	}

	// load the skin
	skin = SkinLoader.loadSkin(skinDir);
	this.lastSkinLocation = new FileSystemLocation(skinDir);
	ResourceLoader.addPrimaryResourceLocation(this.lastSkinLocation);
}
 
Example #16
Source File: MiscUtils.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Properties get() {
	Properties props = new Properties();
	try {
		props.load(ResourceLoader.getResourceAsStream(Constants.VERSION_FILE));
	} catch (IOException e) {
		Log.error("Could not read version file", e);
	}
	return props;
}
 
Example #17
Source File: MusicController.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Plays an audio file at the preview position.
 * If the audio file is already playing, then nothing will happen.
 * @param beatmap the beatmap to play
 * @param loop whether or not to loop the track
 * @param preview whether to start at the preview time (true) or beginning (false)
 */
public static void play(final Beatmap beatmap, final boolean loop, final boolean preview) {
	// new track: load and play
	if (lastBeatmap == null || !beatmap.audioFilename.equals(lastBeatmap.audioFilename)) {
		final File audioFile = beatmap.audioFilename;
		if (!audioFile.isFile() && !ResourceLoader.resourceExists(audioFile.getPath())) {
			barNotifs.sendf("Could not find track '%s'.", audioFile.getName());
			return;
		}

		final Beatmap previousMap = lastBeatmap; // persist over reset call below
		reset();
		System.gc();

		switch (Utils.getFileExtension(beatmap.audioFilename.getName())) {
		case "ogg":
		case "mp3":
			trackLoader = new Thread() {
				@Override
				public void run() {
					loadTrack(audioFile, (preview) ? beatmap.previewTime : 0, loop);
				}
			};
			trackLoader.start();
			break;
		default:
			break;
		}
		updateSongHistory(previousMap, beatmap);
	} else if (beatmap.previewTime != lastBeatmap.previewTime) {
		playAt(beatmap.previewTime, loop);
	}

	lastBeatmap = beatmap;
	dynBg.songChanged();
}
 
Example #18
Source File: FEMultiplayer.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
public void init(int width, int height, String name) {
	super.init(width, height, name);
	Player p1 = new Player("Player", (byte) 0);
	localPlayer = p1;
	ByteBuffer icon16, icon32;
	icon16 = icon32 = null;
	try {
		icon16 = ByteBuffer.wrap(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/gui/icon16.png")).getTextureData());
		icon32 = ByteBuffer.wrap(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/gui/icon32.png")).getTextureData());
	} catch (IOException e) {
		e.printStackTrace();
	}
	Display.setIcon(new ByteBuffer[]{icon16, icon32});
	FEResources.loadResources();
	FEResources.loadBitmapFonts();
	WeaponFactory.loadWeapons();
	UnitFactory.loadUnits();
	p1.getParty().setColor(Party.TEAM_BLUE);
	
	/* OpenGL final setup */
	glEnable(GL_LINE_SMOOTH);
	
	UnitFactory.getUnit("Lyn");
	connect = new ConnectStage();
	setCurrentStage(new TitleStage());
	SoundTrack.loop("main");
	
}
 
Example #19
Source File: SoundTrack.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loops the given audio according to settings.
 * 
 * @param name the music category
 */
public static void loop(String name){
	if (FEResources.getAudioVolume() <= 0) return;
	if (name.equals(currentName) && current.isPlaying()) return;
	
	current.stop();
	currentName = name;
	Map<String, ArrayList<String>> songs = loadAudioNames();
	
	try{
		String setting = FEResources.getAudioSetting(name.toUpperCase());
		if(setting.equals("random")){
			Random r = new Random();
			setting = name + "_" + songs.get(name).get(r.nextInt(songs.get(name).size()));
			if(setting.split("_").length<2)
				setting = name;
		}
		current = AudioLoader.getAudio("WAV",
				ResourceLoader.getResourceAsStream("res/music/"+setting+".wav"));
		current.playAsMusic(1.0f, FEResources.getAudioVolume(), true);
	} catch (Exception e){
		e.printStackTrace();
		System.err.println("Warn: Bad sound configuration: "+name);
		try{
			Audio b = AudioLoader.getAudio("WAV",
					ResourceLoader.getResourceAsStream("res/music/"+name+".wav"));
			b.playAsMusic(1.0f, FEResources.getAudioVolume(), true);
		}catch(Exception f){}
	}
}
 
Example #20
Source File: FEResources.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Load bitmap fonts.
 */
public static void loadBitmapFonts() {
	Scanner in = new Scanner(ResourceLoader.getResourceAsStream("res/fonts/fonts.txt"));
	while(in.hasNextLine()) {
		String line = in.nextLine();
		if(line.startsWith("#"))
			continue;
		if(line.startsWith("define")) {
			String name = line.split(":")[1];
			String texName = in.nextLine();
			char[] chars = in.nextLine().toCharArray();
			int height = Integer.parseInt(in.nextLine());
			int spacing = Integer.parseInt(in.nextLine());
			char[] widths = in.nextLine().toCharArray();
			
			BitmapFont font = new BitmapFont(texName);
			font.setHeight(height);
			font.setSpacing(spacing);
			int pos = 0;
			for(int i=0; i<chars.length; i++) {
				int width = Integer.parseInt(widths[i]+"");
				font.put(chars[i], pos, width);
				pos += width;
			}
			bitmapFonts.put(name, font);
			System.out.println(name+"(bitmap font) loaded");
		}
	}
	in.close();
}
 
Example #21
Source File: AnimationData.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the texture.
 *
 * @return the texture
 */
public Texture getTexture() {
	try {
		Texture t = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(path));
		System.out.println("Loaded "+path);
		return t;
	} catch (IOException e) {
		System.err.println("Texture not found: "+path);
		e.printStackTrace();
		return null;
	}
}
 
Example #22
Source File: Tileset.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new tileset.
 *
 * @param path the path
 * @param tileWidth the tile width
 * @param tileHeight the tile height
 */
public Tileset(String path, int tileWidth, int tileHeight) {
	try {
		tileset = TextureLoader.getTexture("PNG",
				ResourceLoader.getResourceAsStream(path));
		System.out.println("Loaded: "+path);
	} catch (IOException e) {
		e.printStackTrace();
	}
	this.tileWidth = tileWidth;
	this.tileHeight = tileHeight;
	width = tileset.getImageWidth();
	height = tileset.getImageHeight();
}
 
Example #23
Source File: BitmapFont.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new bitmap font.
 *
 * @param texName the tex name
 */
public BitmapFont(String texName) {
	try {
		texture = TextureLoader.getTexture("PNG", 
				ResourceLoader.getResourceAsStream("res/fonts/"+texName+".png"));
	} catch (IOException e) {
		e.printStackTrace();
	}
	glyphs = new HashMap<Character, Glyph>();
}
 
Example #24
Source File: GameContainer.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the build number of slick 
 * 
 * @return The build number of slick
 */
public static int getBuildVersion() {
	try {
		Properties props = new Properties();
		props.load(ResourceLoader.getResourceAsStream("version"));
		
		int build = Integer.parseInt(props.getProperty("build"));
		Log.info("Slick Build #"+build);
		
		return build;
	} catch (Exception e) {
		Log.info("Unable to determine Slick build number");
		return -1;
	}
}
 
Example #25
Source File: Updater.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads and returns the current program version.
 * @return the version string, or {@code null} if unable to determine the version
 */
public String getCurrentVersion() {
	if (currentVersion == null) {
		try {
			Properties props = new Properties();
			props.load(ResourceLoader.getResourceAsStream(Options.VERSION_FILE));
			if ((currentVersion = getVersion(props)) == null)
				return null;
		} catch (IOException e) {
			return null;
		}
	}
	return currentVersion.toString();
}
 
Example #26
Source File: Options.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void read(String s) {
	String oldThemeString = themeString;
	themeString = s;
	Beatmap beatmap = getThemeBeatmap();
	if (beatmap == null) {
		themeString = oldThemeString;
		Log.warn(String.format("The theme song string [%s] is malformed.", s));
	} else if (!beatmap.audioFilename.isFile() && !ResourceLoader.resourceExists(beatmap.audioFilename.getName())) {
		themeString = oldThemeString;
		Log.warn(String.format("Cannot find theme song [%s].", beatmap.audioFilename.getAbsolutePath()));
	}
}
 
Example #27
Source File: Fonts.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes all fonts.
 * @throws SlickException if ASCII glyphs could not be loaded
 * @throws FontFormatException if any font stream data does not contain the required font tables
 * @throws IOException if a font stream cannot be completely read
 */
public static void init() throws SlickException, FontFormatException, IOException {
	float fontBase = 12f * GameImage.getUIscale();
	Font javaFontMain = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_MAIN));
	Font javaFontBold = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_BOLD));
	Font javaFontCJK = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_CJK));
	Font fontMain = javaFontMain.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	Font fontBold = javaFontBold.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	Font fontCJK = javaFontCJK.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	DEFAULT = new UnicodeFont(fontMain);
	BOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD));
	XLARGE = new UnicodeFont(fontMain.deriveFont(fontBase * 3));
	LARGE = new UnicodeFont(fontMain.deriveFont(fontBase * 2));
	MEDIUM = new UnicodeFont(fontMain.deriveFont(fontBase * 3 / 2));
	MEDIUMBOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD, fontBase * 3 / 2));
	SMALL = new UnicodeFont(fontMain.deriveFont(fontBase));
	SMALLBOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD, fontBase));
	ColorEffect colorEffect = new ColorEffect();
	loadFont(DEFAULT, colorEffect, new UnicodeFont(fontCJK));
	loadFont(BOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD)));
	loadFont(XLARGE, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 3)));
	loadFont(LARGE, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 2)));
	loadFont(MEDIUM, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 3 / 2)));
	loadFont(MEDIUMBOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD, fontBase * 3 / 2)));
	loadFont(SMALL, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase)));
	loadFont(SMALLBOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD, fontBase)));
}
 
Example #28
Source File: MusicController.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Plays an audio file at the preview position.
 * If the audio file is already playing, then nothing will happen.
 * @param beatmap the beatmap to play
 * @param loop whether or not to loop the track
 * @param preview whether to start at the preview time (true) or beginning (false)
 */
public static void play(final Beatmap beatmap, final boolean loop, final boolean preview) {
	// new track: load and play
	if (lastBeatmap == null || !beatmap.audioFilename.equals(lastBeatmap.audioFilename)) {
		final File audioFile = beatmap.audioFilename;
		if (!audioFile.isFile() && !ResourceLoader.resourceExists(audioFile.getPath())) {
			UI.getNotificationManager().sendBarNotification(String.format("Could not find track '%s'.", audioFile.getName()));
			return;
		}

		reset();
		Utils.gc(false);

		switch (BeatmapParser.getExtension(beatmap.audioFilename.getName())) {
		case "ogg":
		case "mp3":
			trackLoader = new Thread() {
				@Override
				public void run() {
					loadTrack(audioFile, (preview) ? beatmap.previewTime : 0, loop);
				}
			};
			trackLoader.start();
			break;
		default:
			break;
		}
	}

	// new track position: play at position
	else if (beatmap.previewTime != lastBeatmap.previewTime)
		playAt(beatmap.previewTime, loop);

	lastBeatmap = beatmap;
}
 
Example #29
Source File: FEMultiplayer.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public void init(int width, int height, String name) {
	super.init(width, height, name);
	Player p1 = new Player("Player", (byte) 0);
	localPlayer = p1;
	ByteBuffer icon16, icon32;
	icon16 = icon32 = null;
	try {
		icon16 = ByteBuffer.wrap(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/gui/icon16.png")).getTextureData());
		icon32 = ByteBuffer.wrap(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/gui/icon32.png")).getTextureData());
	} catch (IOException e) {
		e.printStackTrace();
	}
	Display.setIcon(new ByteBuffer[]{icon16, icon32});
	FEResources.loadResources();
	FEResources.loadBitmapFonts();
	WeaponFactory.loadWeapons();
	UnitFactory.loadUnits();
	p1.getParty().setColor(Party.TEAM_BLUE);
	
	/* OpenGL final setup */
	glEnable(GL_LINE_SMOOTH);
	
	UnitFactory.getUnit("Lyn");
	connect = new ConnectStage();
	setCurrentStage(new TitleStage());
	messages = new CopyOnWriteArrayList<Message>();
	SoundTrack.loop("main_theme");
	
}
 
Example #30
Source File: SoundTrack.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public static void loop(String name){
	if(!enabled) return;
	if(name.equals(current)) return;
	try {
		current = name;
		Audio a = AudioLoader.getStreamingAudio("OGG", 
				ResourceLoader.getResource("res/music/"+name+".ogg"));
		a.playAsMusic(1, 1, true);
	} catch (IOException e) {
		e.printStackTrace();
	}
}