improved metadata analysis, added persij as library, added refresh to gui interface

This commit is contained in:
Raybz@Raybz 2013-06-28 08:57:30 +02:00
parent d37263b4bf
commit 4513c6b6bb
26 changed files with 223 additions and 664 deletions

Binary file not shown.

Binary file not shown.

View File

@ -32,18 +32,19 @@ dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath= endorsed.classpath=
excludes= excludes=
file.reference.AudioProcessing-1.0.jar=lib\\AudioProcessing-1.0.jar file.reference.AudioProcessing-1.0.jar=lib\\AudioProcessing-1.0.jar
file.reference.BaseIO-1.0.jar=lib/BaseIO-1.0.jar
file.reference.commons-codec-1.4.jar=lib\\commons-codec-1.4.jar file.reference.commons-codec-1.4.jar=lib\\commons-codec-1.4.jar
file.reference.commons-io-2.1.jar=lib\\commons-io-2.1.jar file.reference.commons-io-2.1.jar=lib\\commons-io-2.1.jar
file.reference.commons-lang3-3.1.jar=lib\\commons-lang3-3.1.jar file.reference.commons-lang3-3.1.jar=lib\\commons-lang3-3.1.jar
file.reference.commons-logging-1.1.1.jar=lib\\commons-logging-1.1.1.jar file.reference.commons-logging-1.1.1.jar=lib\\commons-logging-1.1.1.jar
file.reference.httpclient-4.1.3.jar=lib\\httpclient-4.1.3.jar file.reference.httpclient-4.1.3.jar=lib\\httpclient-4.1.3.jar
file.reference.httpcore-4.1.4.jar=lib\\httpcore-4.1.4.jar file.reference.httpcore-4.1.4.jar=lib\\httpcore-4.1.4.jar
file.reference.jaudiotagger-2.2.0.jar=lib\\jaudiotagger-2.2.0.jar
file.reference.jl1.0.1.jar=lib\\jl1.0.1.jar file.reference.jl1.0.1.jar=lib\\jl1.0.1.jar
file.reference.jna-3.5.2.jar=lib\\jna-3.5.2.jar file.reference.jna-3.5.2.jar=lib\\jna-3.5.2.jar
file.reference.jogg-0.0.7.jar=lib\\jogg-0.0.7.jar file.reference.jogg-0.0.7.jar=lib\\jogg-0.0.7.jar
file.reference.jorbis-0.0.15.jar=lib\\jorbis-0.0.15.jar file.reference.jorbis-0.0.15.jar=lib\\jorbis-0.0.15.jar
file.reference.mp3spi1.9.5.jar=lib\\mp3spi1.9.5.jar file.reference.mp3spi1.9.5.jar=lib\\mp3spi1.9.5.jar
file.reference.PersiJ-1.0.jar=lib/PersiJ-1.0.jar
file.reference.platform-3.5.2.jar=lib\\platform-3.5.2.jar file.reference.platform-3.5.2.jar=lib\\platform-3.5.2.jar
file.reference.sqlite-jdbc-3.7.2.jar=lib\\sqlite-jdbc-3.7.2.jar file.reference.sqlite-jdbc-3.7.2.jar=lib\\sqlite-jdbc-3.7.2.jar
file.reference.tritonus_aos-0.3.6.jar=lib\\tritonus_aos-0.3.6.jar file.reference.tritonus_aos-0.3.6.jar=lib\\tritonus_aos-0.3.6.jar
@ -72,7 +73,6 @@ javac.classpath=\
${file.reference.tritonus_share-0.3.6.jar}:\ ${file.reference.tritonus_share-0.3.6.jar}:\
${file.reference.AudioProcessing-1.0.jar}:\ ${file.reference.AudioProcessing-1.0.jar}:\
${libs.jme3-libraries-effects.classpath}:\ ${libs.jme3-libraries-effects.classpath}:\
${file.reference.jaudiotagger-2.2.0.jar}:\
${file.reference.commons-codec-1.4.jar}:\ ${file.reference.commons-codec-1.4.jar}:\
${file.reference.commons-io-2.1.jar}:\ ${file.reference.commons-io-2.1.jar}:\
${file.reference.commons-lang3-3.1.jar}:\ ${file.reference.commons-lang3-3.1.jar}:\
@ -87,7 +87,9 @@ javac.classpath=\
${file.reference.xmlpull-1.1.3.1.jar}:\ ${file.reference.xmlpull-1.1.3.1.jar}:\
${file.reference.xpp3_min-1.1.4c.jar}:\ ${file.reference.xpp3_min-1.1.4c.jar}:\
${file.reference.xstream-1.4.2.jar}:\ ${file.reference.xstream-1.4.2.jar}:\
${file.reference.sqlite-jdbc-3.7.2.jar} ${file.reference.sqlite-jdbc-3.7.2.jar}:\
${file.reference.BaseIO-1.0.jar}:\
${file.reference.PersiJ-1.0.jar}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=
javac.deprecation=false javac.deprecation=false

View File

@ -1,32 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
/**
* Exception thrown by the PersiJConstructor
*
* @author Darth Affe
*/
public class NoSuitableConstructorFoundException extends Exception {
NoSuitableConstructorFoundException() {
}
NoSuitableConstructorFoundException(String msg) {
super(msg);
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marks an Constructor for primary use by the PersiJConstructor
*
* @author Darth Affe
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.CONSTRUCTOR)
public @interface PersiJConstructor {
/**
* Returns the default state of the annotation
*
* @return true if default; false otherwise
*/
boolean isDefault();
/**
* Returns the id of the param mapping
*
* @return id of the param mapping
*/
int customParamMappingId() default -1;
}

View File

@ -1,172 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Mapping and object container for PersiJ
*
* @author Darth Affe
*/
public final class PersiJContainer {
private static final Logger logger = Logger.getLogger("org.wyrez.persij");
private final HashMap<Class, PersiJMapping> mappings = new HashMap<Class, PersiJMapping>();
public PersiJContainer() {
registerSingleton(PersiJContainer.class, this);
}
/**
* Registers a mapping
*
* @param type Type which should be mapped
*/
public final <T> void registerType(Class<T> type) {
registerType(type, false);
}
/**
* Registers a mapping
*
* @param type Type which should be mapped
* @param singleton Singleton indicator
*/
public final <T> void registerType(Class<T> type, boolean singleton) {
registerType(type, type, singleton);
}
/**
* Registers a mapping
*
* @param type Source-type which should be mapped
* @param mapping Target-type which should be mapped
*/
public final <T> void registerType(Class<T> type, Class<? extends T> mapping) {
registerType(type, mapping, false);
}
/**
* Registers a mapping
*
* @param type Source-type which should be mapped
* @param mapping Target-type which should be mapped
* @param singleton Singleton indicator
*/
public final <T> void registerType(Class<T> type, Class<? extends T> mapping, boolean singleton) {
mappings.put(type, new PersiJMapping(mapping, singleton));
}
/**
* Registers a singleton-mapping to an existing object
*
* @param type Source-type which should be mapped
* @param instance Singleton instance
*/
public final <T> void registerSingleton(Class<T> type, T instance) {
mappings.put(type, new PersiJMapping(type, instance));
}
/**
* Tests if the specified type is registered
*
* @param type Type which should be tested
* @return true if the type is registered; else otherwise
*/
public final boolean isTypeRegistered(Class type) {
return mappings.containsKey(type);
}
/**
* Creates an instance of the type mapped to the given type
*
* @param <T> Type to resolve
* @param type Class of the type to resolve
* @return Insance of T
*/
public final <T> T resolve(Class<T> type) {
PersiJMapping mapping = mappings.get(type);
if (mapping != null) {
try {
return (T) mapping.getInstance(this, null);
} catch (NoSuitableConstructorFoundException ex) {
logger.log(Level.WARNING, "Can't create object for type: "
+ type.getName(), ex);
return null;
}
} else {
logger.log(Level.WARNING, "Can't find a mapping for type: "
+ type.getName());
return null;
}
}
/**
* Creates an instance of the type mapped to the given type
*
* @param <T> Type to resolve
* @param type Class of the type to resolve
* @param paramMapping
* @return Instance of T
*/
public final <T> T resolve(Class<T> type, PersiJParamMapping paramMapping) {
PersiJMapping mapping = mappings.get(type);
if (mapping != null) {
try {
return (T) mapping.getInstance(this, paramMapping);
} catch (NoSuitableConstructorFoundException ex) {
logger.log(Level.WARNING, "Can't create object for type: "
+ type.getName(), ex);
return null;
}
} else {
logger.log(Level.WARNING, "Can't find a mapping for type: "
+ type.getName());
return null;
}
}
/**
* Creates an array with instances of the type mapped to the given type
*
* @param <T> Type to resolve
* @param type Class of the type to resolve
* @param number Size of the array
* @return Array of T
*/
public final <T> T[] resolve(Class<T> type, int number) {
PersiJMapping mapping = mappings.get(type);
if (mapping != null) {
try {
T[] array = (T[]) Array.newInstance(type, number);
return (T[]) mapping.getInstances(this, null, array);
} catch (NoSuitableConstructorFoundException ex) {
logger.log(Level.WARNING, "Can't create object for type: "
+ type.getName(), ex);
return null;
}
} else {
logger.log(Level.WARNING, "Can't find a mapping for type: "
+ type.getName());
return null;
}
}
}

View File

@ -1,208 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Darth Affe
*/
final class PersiJMapping {
private static final Logger logger = Logger.getLogger("org.wyrez.persij");
private Object singletonInstance;
private Class type;
private boolean singleton;
PersiJMapping(Class type, boolean singleton) {
this.type = type;
this.singleton = singleton;
}
PersiJMapping(Class type, Object singleton) {
this.type = type;
this.singleton = true;
singletonInstance = singleton;
}
final boolean isSingleton() {
return singleton;
}
/**
* Creates a new instance
*
* @param container Container to resolve missing dependencies
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @return New instance
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
final Object getInstance(PersiJContainer container, PersiJParamMapping paramMapping) throws NoSuitableConstructorFoundException {
if (isSingleton()) {
if (singletonInstance == null) {
singletonInstance = createInstance(container, paramMapping);
}
return singletonInstance;
} else {
return createInstance(container, paramMapping);
}
}
/**
* Creates an array with new instances
*
* @param container Container to resolve missing dependencies
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @param array Array which should be filled and returned
* @return New array with instances
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
final Object getInstances(PersiJContainer container, PersiJParamMapping paramMapping, Object[] array) throws NoSuitableConstructorFoundException {
if (isSingleton()) {
if (singletonInstance == null) {
singletonInstance = createInstance(container, paramMapping);
}
for (int i = 0; i < array.length; i++) {
array[i] = singletonInstance;
}
return array;
} else {
return createInstances(container, paramMapping, array);
}
}
/**
* Creates a new instance
*
* @param container Container to resolve missing dependencies
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @return New instance
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
private Object createInstance(PersiJContainer container, PersiJParamMapping paramMapping) throws NoSuitableConstructorFoundException {
Constructor constructor = getBestConstructor(container, paramMapping);
return createInstance(container, constructor, paramMapping);
}
/**
* Creates an array with new instances
*
* @param container Container to resolve missing dependencies
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @param array Array which should be filled and returned
* @return New array with instances
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
private Object createInstances(PersiJContainer container, PersiJParamMapping paramMapping, Object[] array) throws NoSuitableConstructorFoundException {
Constructor constructor = getBestConstructor(container, paramMapping);
for (int i = 0; i < array.length; i++) {
array[i] = createInstance(container, constructor, paramMapping);
}
return array;
}
/**
* Creates an instance using the given constructor
*
* @param container Container to resolve missing dependencies
* @param constructor Constructor to instantiate
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @return New instance
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
private Object createInstance(PersiJContainer container, Constructor constructor, PersiJParamMapping paramMapping) throws NoSuitableConstructorFoundException {
Object[] params;
if (paramMapping != null && paramMapping.getType() == type) {
params = paramMapping.getParams();
} else {
Class[] conParams = constructor.getParameterTypes();
int paramCount = conParams.length;
params = new Object[paramCount];
for (int i = 0; i < paramCount; i++) {
params[i] = container.resolve(conParams[i], paramMapping);
}
}
try {
return constructor.newInstance(params);
} catch (Exception ex) {
logger.log(Level.WARNING, "Error while creating instance of an object", ex);
return null;
}
}
/**
* Determines the best constructor to instantiate
*
* @param container Container to check registered types
* @param paramMapping Optional parameters used to resolve dependencies
* (null if not used)
* @return Best constructor to instantiate
* @throws NoSuitableConstructorFoundException thrown if no suitable
* constructor to instantiate could be found
*/
private Constructor getBestConstructor(PersiJContainer container, PersiJParamMapping paramMapping) throws NoSuitableConstructorFoundException {
Constructor bestToCreate = null;
int paramCount = -1;
for (Constructor c : type.getConstructors()) {
Annotation annotation = c.getAnnotation(PersiJConstructor.class);
if (paramMapping != null && paramMapping.getType() == type) {
if (annotation != null && ((PersiJConstructor) annotation).customParamMappingId() == paramMapping.getParamMappingId()) {
bestToCreate = c;
break;
}
} else {
boolean possible = true;
for (Class t : c.getParameterTypes()) {
if (t.isPrimitive() || t == String.class || t == Object.class || !container.isTypeRegistered(t)) {
possible = false;
break;
}
}
if (possible) {
int pCount = c.getParameterTypes().length;
if (annotation != null) {
if (((PersiJConstructor) annotation).isDefault()) {
bestToCreate = c;
break;
}
} else if (pCount > paramCount) {
bestToCreate = c;
paramCount = pCount;
}
}
}
}
if (bestToCreate == null) {
throw new NoSuitableConstructorFoundException();
}
return bestToCreate;
}
}

View File

@ -1,65 +0,0 @@
/*
* Copyright (C) 2012 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.persij;
/**
*
* @author Darth Affe
*/
public final class PersiJParamMapping {
private Class type;
private Object[] params;
private int paramMappingId;
public PersiJParamMapping(Class type, Object... params) {
this(-1, type, params);
}
public PersiJParamMapping(int paramMappingId, Class type, Object... params) {
this.type = type;
this.params = params;
this.paramMappingId = paramMappingId;
}
/**
* Returns the Type to which the ParamMapping belongs
*
* @return Type of the ParamMapping
*/
public final Class getType() {
return type;
}
/**
* Returns the mapped parameters
*
* @return Array with mapped parameters
*/
public final Object[] getParams() {
return params;
}
/**
* Returns the id of the mapping
*
* @return id of the mapping
*/
public final int getParamMappingId() {
return paramMappingId;
}
}

View File

@ -17,6 +17,7 @@
package org.wyrez.shootingstars.controls; package org.wyrez.shootingstars.controls;
import com.jme3.effect.ParticleEmitter; import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.shapes.EmitterShape;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control; import com.jme3.scene.control.Control;
@ -63,12 +64,13 @@ public class StarDeathControl extends BaseControl {
effect.setEndColor(new ColorRGBA(points.getColor().r, effect.setEndColor(new ColorRGBA(points.getColor().r,
points.getColor().g, points.getColor().b, 0f)); points.getColor().g, points.getColor().b, 0f));
} }
effect.setStartSize((Float) spatial.getUserData(UserDataKeys.SIZE)); effect.setStartSize((Float) spatial.getUserData(UserDataKeys.SIZE)*0.5f);
effect.setEndSize(0f); effect.setEndSize(0f);
effect.setHighLife(FX_TIME); effect.setHighLife(FX_TIME);
effect.setLowLife(0f); effect.setLowLife(0f);
effect.setLocalTranslation(spatial.getLocalTranslation()); effect.setLocalTranslation(spatial.getLocalTranslation());
effect.setParticlesPerSec(0f); effect.setParticlesPerSec(0f);
effect.setRandomAngle(true);
spatial.getParent().attachChild(effect); spatial.getParent().attachChild(effect);
spatial.setCullHint(Spatial.CullHint.Always); spatial.setCullHint(Spatial.CullHint.Always);

View File

@ -56,7 +56,7 @@ public class StarPointControl extends BaseControl {
@Override @Override
protected void controlUpdate(float tpf) { protected void controlUpdate(float tpf) {
if ((Boolean)spatial.getUserData(UserDataKeys.HITTED) && !isHitted) { if ((Boolean) spatial.getUserData(UserDataKeys.HITTED) && !isHitted) {
player.setUserData(UserDataKeys.POINTS, (Integer) (player.getUserData(UserDataKeys.POINTS)) player.setUserData(UserDataKeys.POINTS, (Integer) (player.getUserData(UserDataKeys.POINTS))
+ (int) Math.round(points)); + (int) Math.round(points));
isHitted = true; isHitted = true;
@ -64,10 +64,10 @@ public class StarPointControl extends BaseControl {
if (points > 1f) { if (points > 1f) {
points -= 2f * tpf; points -= 2f * tpf;
color = ColorHelper.calcColor(points / MAX_POINTS); color = ColorHelper.calcColor(points / MAX_POINTS);
} else if (points < 1f) { } else if (points <= 1f) {
spatial.setUserData(UserDataKeys.HITTED, true); //TODO test
points = 1f; points = 1f;
color = ColorHelper.calcColor(points / MAX_POINTS); color = ColorHelper.calcColor(points / MAX_POINTS);
spatial.setUserData(UserDataKeys.HITTED, true);
} }
material.setColor("Color", color); material.setColor("Color", color);
} else { } else {

View File

@ -16,7 +16,6 @@ package org.wyrez.shootingstars.data;
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import com.github.axet.vget.VGet; import com.github.axet.vget.VGet;
import com.github.axet.vget.info.VideoInfo; import com.github.axet.vget.info.VideoInfo;
import com.github.axet.vget.info.VideoInfo.VideoQuality; import com.github.axet.vget.info.VideoInfo.VideoQuality;
@ -30,6 +29,7 @@ import java.net.URL;
public class YTDownloader { public class YTDownloader {
private File lastTarget; private File lastTarget;
private String lastTitle;
public YTDownloader() { public YTDownloader() {
} }
@ -50,6 +50,7 @@ public class YTDownloader {
VGet v = new VGet(info, new File(targetFolder)); VGet v = new VGet(info, new File(targetFolder));
v.download(); v.download();
lastTarget = v.getTarget(); lastTarget = v.getTarget();
lastTitle = v.getVideo().getTitle();
System.out.println("success!"); System.out.println("success!");
return true; return true;
} catch (Exception e) { } catch (Exception e) {
@ -70,4 +71,8 @@ public class YTDownloader {
public File getLastTarget() { public File getLastTarget() {
return lastTarget; return lastTarget;
} }
public String getLastTitle() {
return lastTitle;
}
} }

View File

@ -35,18 +35,21 @@ public class GameSettings {
private boolean useVideo; private boolean useVideo;
private String trackTitle; private String trackTitle;
private String trackArtist; private String trackArtist;
private int trackLength;
public GameSettings() { public GameSettings() {
} }
public void setAudioFile(String audioFile) { public void setAudioFile(String audioFile) {
this.audioFile = audioFile; this.audioFile = audioFile;
this.useVideo = false;
} }
public void setVideoFile(String videoFile) { public void setVideoFile(String videoFile) {
this.videoFile = videoFile; this.videoFile = videoFile;
this.useVideo = true; }
public void useVideo(boolean useVideo) {
this.useVideo = useVideo;
} }
public void setTrackTitle(String trackTitle) { public void setTrackTitle(String trackTitle) {
@ -57,6 +60,10 @@ public class GameSettings {
this.trackArtist = trackArtist; this.trackArtist = trackArtist;
} }
public void setTrackLength(int length) {
this.trackLength = length;
}
public String getAudioFile() { public String getAudioFile() {
return audioFile; return audioFile;
} }
@ -96,4 +103,8 @@ public class GameSettings {
public String getTrackTitle() { public String getTrackTitle() {
return trackTitle; return trackTitle;
} }
public int getTrackLength() {
return trackLength;
}
} }

View File

@ -19,11 +19,9 @@ package org.wyrez.shootingstars.game;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
import com.jme3.input.InputManager; import com.jme3.input.InputManager;
import com.jme3.light.AmbientLight; import com.jme3.light.AmbientLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
@ -41,6 +39,7 @@ import org.wyrez.shootingstars.helper.MathHelper;
import org.wyrez.shootingstars.helper.UserDataKeys; import org.wyrez.shootingstars.helper.UserDataKeys;
import org.wyrez.shootingstars.mesh.HexPrism; import org.wyrez.shootingstars.mesh.HexPrism;
import org.wyrez.shootingstars.states.StateManager; import org.wyrez.shootingstars.states.StateManager;
import org.wyrez.shootingstars.states.util.OptionSettings;
/** /**
* *
@ -54,13 +53,15 @@ public class Player extends Node {
public Player(Node rootNode, StateManager stateManager, AssetManager assetManager, public Player(Node rootNode, StateManager stateManager, AssetManager assetManager,
ViewPort viewPort, GameGUI gui, InputManager inputManager, Camera camera, ViewPort viewPort, GameGUI gui, InputManager inputManager, Camera camera,
AudioDataManager audioDataManager, Node starNode) { AudioDataManager audioDataManager, Node starNode, OptionSettings settings) {
super("Player"); super("Player");
initPlayer(inputManager, camera, audioDataManager, gui); initPlayer(inputManager, camera, audioDataManager, gui);
initWeapon(assetManager); if (settings.isShowWeaponEnabled()) {
initProjectile(rootNode); initWeapon(assetManager);
initWeaponContainer(); initProjectile(rootNode);
initWeaponContainer();
}
initGhostProjectile(starNode); initGhostProjectile(starNode);
addLight(); addLight();
} }
@ -95,7 +96,7 @@ public class Player extends Node {
geom2.setMaterial(Materials.WEAPON.create()); geom2.setMaterial(Materials.WEAPON.create());
geom2.move(0f, 0.25f, -5f); geom2.move(0f, 0.25f, -5f);
projectile.attachChild(geom2); projectile.attachChild(geom2);
projectile.addControl(new WeaponProjectileControl(rootNode, this)); projectile.addControl(new WeaponProjectileControl(rootNode, this));
} }
@ -111,13 +112,13 @@ public class Player extends Node {
this.attachChild(weaponContainer); this.attachChild(weaponContainer);
} }
private void initGhostProjectile(Node starNode) { private void initGhostProjectile(Node starNode) {
Geometry ghostProjectile = new Geometry("ghostProjectile", new Box(0.1f, 0.1f, 2500f)); Geometry ghostProjectile = new Geometry("ghostProjectile", new Box(0.1f, 0.1f, 2500f));
ghostProjectile.setMaterial(Materials.UNSHADED.create()); ghostProjectile.setMaterial(Materials.UNSHADED.create());
ghostProjectile.setCullHint(CullHint.Always); ghostProjectile.setCullHint(CullHint.Always);
ghostProjectile.move(0f,0f,2510f); ghostProjectile.move(0f, 0f, 2510f);
ghostProjectile.addControl(new WeaponProjectileCollisionControl(starNode,this)); ghostProjectile.addControl(new WeaponProjectileCollisionControl(starNode, this));
this.attachChild(ghostProjectile); this.attachChild(ghostProjectile);
} }

View File

@ -38,7 +38,7 @@ import org.wyrez.shootingstars.states.GameState;
* *
* @author Darth Affe * @author Darth Affe
*/ */
public class StarManager{ public class StarManager {
private static final Random random; private static final Random random;
private static final float MAX_STAR_SIZE = 15f; private static final float MAX_STAR_SIZE = 15f;
@ -93,7 +93,7 @@ public class StarManager{
star.addControl(new StarFaceControl(player)); star.addControl(new StarFaceControl(player));
star.addControl(new StarDeathControl()); star.addControl(new StarDeathControl());
star.addControl(new StarPointControl(player, value)); star.addControl(new StarPointControl(player, value));
starNode.attachChild(star); starNode.attachChild(star);
} }

View File

@ -19,11 +19,6 @@ package org.wyrez.shootingstars.gui;
import com.jme3.input.event.MouseButtonEvent; import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import java.io.File; import java.io.File;
import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.AudioHeader;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.game.GameSettings;
import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.listener.FileMetaInfoListener; import org.wyrez.shootingstars.gui.listener.FileMetaInfoListener;
@ -42,10 +37,10 @@ public class FileMetaInfoGUI extends Panel implements Gui {
private FileMetaInfoListener listener; private FileMetaInfoListener listener;
private GameSettings settings; private GameSettings settings;
private ScreenHelper screenHelper; private ScreenHelper screenHelper;
private String fileName = ""; private Label lblFileName;
private String duration = ""; private Label lblArtist;
private String title = ""; private Label lblTitel;
private String artist = ""; private Label lblDuration;
public FileMetaInfoGUI(Screen screen, FileMetaInfoListener listener, GameSettings settings, ScreenHelper screenHelper) { public FileMetaInfoGUI(Screen screen, FileMetaInfoListener listener, GameSettings settings, ScreenHelper screenHelper) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f));
@ -63,48 +58,35 @@ public class FileMetaInfoGUI extends Panel implements Gui {
float marginLeft = screenHelper.calcX(110f); float marginLeft = screenHelper.calcX(110f);
float buttonWidth = screenHelper.calcX(153.6f); float buttonWidth = screenHelper.calcX(153.6f);
float labelFontSize = screenHelper.calcX(20f); float labelFontSize = screenHelper.calcX(20f);
File file = null;
if(settings.useVideo()) {
file = new File(settings.getVideoFile());
} else {
file = new File(settings.getAudioFile());
}
readMetaData(file);
Label lblFileNameHead = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f))); Label lblFileNameHead = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f)));
lblFileNameHead.setText("Track Name"); lblFileNameHead.setText("Track Name");
lblFileNameHead.setFontSize(labelFontSize); lblFileNameHead.setFontSize(labelFontSize);
Label lblFileName = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f))); lblFileName = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblFileName.setText(fileName);
lblFileName.setFontSize(labelFontSize); lblFileName.setFontSize(labelFontSize);
Label lblArtistHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(50f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f))); Label lblArtistHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(50f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f)));
lblArtistHead.setText("Artist"); lblArtistHead.setText("Artist");
lblArtistHead.setFontSize(labelFontSize); lblArtistHead.setFontSize(labelFontSize);
Label lblArtist = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(50f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f))); lblArtist = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(50f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblArtist.setText(artist);
lblArtist.setFontSize(labelFontSize); lblArtist.setFontSize(labelFontSize);
Label lblTitelHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(100f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f))); Label lblTitelHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(100f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f)));
lblTitelHead.setText("Titel"); lblTitelHead.setText("Titel");
lblTitelHead.setFontSize(labelFontSize); lblTitelHead.setFontSize(labelFontSize);
Label lblTitel = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(100f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f))); lblTitel = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(100f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblTitel.setText(title);
lblTitel.setFontSize(labelFontSize); lblTitel.setFontSize(labelFontSize);
Label lblDurationHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(150f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f))); Label lblDurationHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(150f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f)));
lblDurationHead.setText("Duration"); lblDurationHead.setText("Duration");
lblDurationHead.setFontSize(labelFontSize); lblDurationHead.setFontSize(labelFontSize);
Label lblDuration = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(150f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f))); lblDuration = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(150f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f)));
lblDuration.setText(duration);
lblDuration.setFontSize(labelFontSize); lblDuration.setFontSize(labelFontSize);
Button btnStartLoading = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(653f), startPointy + screenHelper.calcY(438.8f)), new Vector2f(buttonWidth, screenHelper.calcY(40))) { Button btnStartLoading = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(653f), startPointy + screenHelper.calcY(438.8f)), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -113,7 +95,7 @@ public class FileMetaInfoGUI extends Panel implements Gui {
}; };
btnStartLoading.setText("Play"); btnStartLoading.setText("Play");
btnStartLoading.setFontSize(labelFontSize); btnStartLoading.setFontSize(labelFontSize);
Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(836f), startPointy + screenHelper.calcY(438.8f)), new Vector2f(buttonWidth, screenHelper.calcY(40))) { Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(836f), startPointy + screenHelper.calcY(438.8f)), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -122,7 +104,7 @@ public class FileMetaInfoGUI extends Panel implements Gui {
}; };
btnCancel.setText("Cancel"); btnCancel.setText("Cancel");
btnCancel.setFontSize(labelFontSize); btnCancel.setFontSize(labelFontSize);
this.addChild(lblFileNameHead); this.addChild(lblFileNameHead);
this.addChild(lblFileName); this.addChild(lblFileName);
this.addChild(lblArtistHead); this.addChild(lblArtistHead);
@ -135,27 +117,11 @@ public class FileMetaInfoGUI extends Panel implements Gui {
this.addChild(btnCancel); this.addChild(btnCancel);
} }
private void readMetaData(File file) { public void refresh() {
try { lblDuration.setText(String.valueOf(settings.getTrackLength()) + " s");
fileName = file.getName(); lblTitel.setText(settings.getTrackTitle());
AudioFile f = AudioFileIO.read(file); lblArtist.setText(settings.getTrackArtist());
Tag tag = f.getTag(); lblFileName.setText(new File(settings.getVideoFile()).getName());
AudioHeader ah = f.getAudioHeader();
if (ah != null) {
duration = String.valueOf(ah.getTrackLength()) + " s";
}
if (tag != null) {
if (tag.hasField(FieldKey.TITLE)) {
title = tag.getFirst(FieldKey.TITLE);
settings.setTrackTitle(title);
}
artist = tag.getFirst(FieldKey.ARTIST);
settings.setTrackArtist(artist);
}
} catch (Exception ex) {
}
} }
public void attach() { public void attach() {

View File

@ -22,6 +22,8 @@ package org.wyrez.shootingstars.gui;
*/ */
public interface Gui { public interface Gui {
public void refresh();
public void attach(); public void attach();
public void detach(); public void detach();

View File

@ -45,7 +45,7 @@ public class HighscoreGUI extends Panel implements Gui {
this.highscoreManager = highscoreManager; this.highscoreManager = highscoreManager;
this.screenHelper = screenHelper; this.screenHelper = screenHelper;
this.setIgnoreMouse(true); this.setIgnoreMouse(true);
this.setIsVisible(false); this.setIsVisible(false);
create(); create();
} }
@ -66,7 +66,7 @@ public class HighscoreGUI extends Panel implements Gui {
float marginScoreSongNameLeft = screenHelper.calcX(600f); float marginScoreSongNameLeft = screenHelper.calcX(600f);
float marginScoreTop = screenHelper.calcY(50f); float marginScoreTop = screenHelper.calcY(50f);
float labelFontSize = screenHelper.calcX(20f); float labelFontSize = screenHelper.calcX(20f);
List<Score> highscores = highscoreManager.getScores(); List<Score> highscores = highscoreManager.getScores();
@ -84,12 +84,12 @@ public class HighscoreGUI extends Panel implements Gui {
lblScoreSongNameHead.setFontSize(labelFontSize); lblScoreSongNameHead.setFontSize(labelFontSize);
int maxScores = 0; int maxScores = 0;
if(highscores.size() > 10) { if (highscores.size() > 10) {
maxScores = 10; maxScores = 10;
} else { } else {
maxScores = highscores.size(); maxScores = highscores.size();
} }
for (int i = 0; i < maxScores; i++) { for (int i = 0; i < maxScores; i++) {
Score score = highscores.get(i); Score score = highscores.get(i);
Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f))); Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f)));
@ -101,7 +101,7 @@ public class HighscoreGUI extends Panel implements Gui {
lblScorePoints.setFontSize(labelFontSize); lblScorePoints.setFontSize(labelFontSize);
Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(600f), screenHelper.calcY(40f))); Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(600f), screenHelper.calcY(40f)));
lblScoreSongName.setText(score.getSongName());
lblScoreSongName.setFontSize(labelFontSize); lblScoreSongName.setFontSize(labelFontSize);
this.addChild(lblScoreName); this.addChild(lblScoreName);
@ -124,4 +124,7 @@ public class HighscoreGUI extends Panel implements Gui {
this.addChild(lblScoreSongNameHead); this.addChild(lblScoreSongNameHead);
this.addChild(btnBack); this.addChild(btnBack);
} }
public void refresh() {
}
} }

View File

@ -40,12 +40,12 @@ public class MenuGUI extends Panel implements Gui {
this.listener = listener; this.listener = listener;
this.screenHelper = screenHelper; this.screenHelper = screenHelper;
this.setIgnoreMouse(true); this.setIgnoreMouse(true);
this.setIsVisible(false); this.setIsVisible(false);
create(); create();
} }
private void create() { private void create() {
float startPointx = screenHelper.calcX(256f); float startPointx = screenHelper.calcX(256f);
float startPointy = screenHelper.calcY(252f); float startPointy = screenHelper.calcY(252f);
float labelFontSize = screenHelper.calcX(89f); float labelFontSize = screenHelper.calcX(89f);
@ -56,11 +56,11 @@ public class MenuGUI extends Panel implements Gui {
float marginButtonTop = screenHelper.calcY(25f); float marginButtonTop = screenHelper.calcY(25f);
float distanceLabelLabely = screenHelper.calcY(60f); float distanceLabelLabely = screenHelper.calcY(60f);
float buttonFontSize = screenHelper.calcX(20f); float buttonFontSize = screenHelper.calcX(20f);
Label lblWyrez = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(300), screenHelper.calcY(40))); Label lblWyrez = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(300), screenHelper.calcY(40)));
lblWyrez.setFontSize(labelFontSize); lblWyrez.setFontSize(labelFontSize);
lblWyrez.setText("Wyrez"); lblWyrez.setText("Wyrez");
Label lblShootingStars = new Label(screen, new Vector2f(startPointx, startPointy + distanceLabelLabely), new Vector2f(screenHelper.calcX(500), screenHelper.calcY(40))); Label lblShootingStars = new Label(screen, new Vector2f(startPointx, startPointy + distanceLabelLabely), new Vector2f(screenHelper.calcX(500), screenHelper.calcY(40)));
lblShootingStars.setFontSize(labelFontSize); lblShootingStars.setFontSize(labelFontSize);
lblShootingStars.setText("Shooting Stars"); lblShootingStars.setText("Shooting Stars");
@ -73,7 +73,7 @@ public class MenuGUI extends Panel implements Gui {
}; };
btnStart.setText("Start Game"); btnStart.setText("Start Game");
btnStart.setFontSize(buttonFontSize); btnStart.setFontSize(buttonFontSize);
Button btnHighscore = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + marginButtonTop), new Vector2f(buttonWidth, screenHelper.calcY(40))) { Button btnHighscore = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + marginButtonTop), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -82,7 +82,7 @@ public class MenuGUI extends Panel implements Gui {
}; };
btnHighscore.setText("Highscore"); btnHighscore.setText("Highscore");
btnHighscore.setFontSize(buttonFontSize); btnHighscore.setFontSize(buttonFontSize);
Button btnOptions = new ButtonBase(screen, new Vector2f(startPointx + buttonLabelDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, screenHelper.calcY(40))) { Button btnOptions = new ButtonBase(screen, new Vector2f(startPointx + buttonLabelDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -91,7 +91,7 @@ public class MenuGUI extends Panel implements Gui {
}; };
btnOptions.setText("Options"); btnOptions.setText("Options");
btnOptions.setFontSize(buttonFontSize); btnOptions.setFontSize(buttonFontSize);
Button btnExit = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, screenHelper.calcY(40))) { Button btnExit = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, screenHelper.calcY(40))) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -109,6 +109,9 @@ public class MenuGUI extends Panel implements Gui {
this.addChild(lblShootingStars); this.addChild(lblShootingStars);
} }
public void refresh() {
}
public void attach() { public void attach() {
screen.addElement(this); screen.addElement(this);
} }

View File

@ -42,10 +42,8 @@ public class OptionsGUI extends Panel implements Gui {
private OptionsListener listener; private OptionsListener listener;
private OptionSettings settings; private OptionSettings settings;
private ScreenHelper screenHelper; private ScreenHelper screenHelper;
//General Controls //General Controls
private TextField txtPlayerName; private TextField txtPlayerName;
//Video Controls //Video Controls
private ComboBox cboResolution; private ComboBox cboResolution;
private ComboBox cboFrequency; private ComboBox cboFrequency;
@ -83,7 +81,7 @@ public class OptionsGUI extends Panel implements Gui {
float buttonWidth = screenHelper.calcX(153.6f); float buttonWidth = screenHelper.calcX(153.6f);
float buttonHeight = screenHelper.calcY(40f); float buttonHeight = screenHelper.calcY(40f);
float labelFontSize = screenHelper.calcX(20f); float labelFontSize = screenHelper.calcX(20f);
createGeneral(labelFontSize); createGeneral(labelFontSize);
@ -123,10 +121,10 @@ public class OptionsGUI extends Panel implements Gui {
Label lblPlayerName = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(120f), screenHelper.calcY(40f))); Label lblPlayerName = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(120f), screenHelper.calcY(40f)));
lblPlayerName.setText("Player Name"); lblPlayerName.setText("Player Name");
lblPlayerName.setFontSize(labelFontSize); lblPlayerName.setFontSize(labelFontSize);
txtPlayerName = new TextField(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(7f)), new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f))); txtPlayerName = new TextField(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(7f)), new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f)));
txtPlayerName.setFontSize(labelFontSize); txtPlayerName.setFontSize(labelFontSize);
this.addChild(lblPlayerName); this.addChild(lblPlayerName);
this.addChild(txtPlayerName); this.addChild(txtPlayerName);
} }
@ -138,13 +136,13 @@ public class OptionsGUI extends Panel implements Gui {
float marginLeftControls = screenHelper.calcX(115.8f); float marginLeftControls = screenHelper.calcX(115.8f);
float labelWitdh = screenHelper.calcX(120f); float labelWitdh = screenHelper.calcX(120f);
float labelHeight = screenHelper.calcY(40f); float labelHeight = screenHelper.calcY(40f);
float comboBoxWidth = screenHelper.calcX(200f); float comboBoxWidth = screenHelper.calcX(200f);
float comboBoxHeight = screenHelper.calcY(30f); float comboBoxHeight = screenHelper.calcY(30f);
float checkBoxWitdh = screenHelper.calcX(20f); float checkBoxWitdh = screenHelper.calcX(20f);
float checkBoxHeight = screenHelper.calcX(20f); float checkBoxHeight = screenHelper.calcX(20f);
float sliderWitdh = screenHelper.calcX(200f); float sliderWitdh = screenHelper.calcX(200f);
float sliderHeight = screenHelper.calcY(30f); float sliderHeight = screenHelper.calcY(30f);
@ -165,7 +163,7 @@ public class OptionsGUI extends Panel implements Gui {
lblPostProcessing.setFontSize(labelFontSize); lblPostProcessing.setFontSize(labelFontSize);
chkShowWeapon = new CheckBox(screen, new Vector2f(startPointx + marginLeftControls + screenHelper.calcX(800f), startPointy + screenHelper.calcY(12f)), new Vector2f(checkBoxWitdh, checkBoxHeight)); chkShowWeapon = new CheckBox(screen, new Vector2f(startPointx + marginLeftControls + screenHelper.calcX(800f), startPointy + screenHelper.calcY(12f)), new Vector2f(checkBoxWitdh, checkBoxHeight));
Label lblResolution = new Label(screen, "lblResolution", new Vector2f(startPointx, startPointy + screenHelper.calcY(50f)), new Vector2f(labelWitdh, labelHeight)); Label lblResolution = new Label(screen, "lblResolution", new Vector2f(startPointx, startPointy + screenHelper.calcY(50f)), new Vector2f(labelWitdh, labelHeight));
lblResolution.setText("Resolution"); lblResolution.setText("Resolution");
lblResolution.setFontSize(labelFontSize); lblResolution.setFontSize(labelFontSize);
@ -192,9 +190,9 @@ public class OptionsGUI extends Panel implements Gui {
cboFrequency.setFontSize(labelFontSize); cboFrequency.setFontSize(labelFontSize);
for (String s : DisplayHelper.getFrequencys()) { for (String s : DisplayHelper.getFrequencys()) {
cboFrequency.addListItem(s, s); cboFrequency.addListItem(s, s);
} }
Label lblParticleDensity = new Label(screen, "lblParticleDensity", new Vector2f(startPointx + screenHelper.calcX(800f), startPointy +screenHelper.calcY(50f)), new Vector2f(labelWitdh, labelHeight)); Label lblParticleDensity = new Label(screen, "lblParticleDensity", new Vector2f(startPointx + screenHelper.calcX(800f), startPointy + screenHelper.calcY(50f)), new Vector2f(labelWitdh, labelHeight));
lblParticleDensity.setText("Particle Density"); lblParticleDensity.setText("Particle Density");
lblParticleDensity.setFontSize(labelFontSize); lblParticleDensity.setFontSize(labelFontSize);
@ -205,7 +203,7 @@ public class OptionsGUI extends Panel implements Gui {
}; };
sldParticleDensity.setStepIntegerRange(0, 3, 1); sldParticleDensity.setStepIntegerRange(0, 3, 1);
this.addChild(lblVSync); this.addChild(lblVSync);
this.addChild(chkVSync); this.addChild(chkVSync);
this.addChild(lblFullscreen); this.addChild(lblFullscreen);
@ -224,10 +222,10 @@ public class OptionsGUI extends Panel implements Gui {
float startPointx = screenHelper.calcX(64f); float startPointx = screenHelper.calcX(64f);
float startPointy = screenHelper.calcY(290f); float startPointy = screenHelper.calcY(290f);
float marginLeftControls = screenHelper.calcX(115.8f); float marginLeftControls = screenHelper.calcX(115.8f);
float labelWitdh = screenHelper.calcX(120f); float labelWitdh = screenHelper.calcX(120f);
float labelHeight = screenHelper.calcY(40f); float labelHeight = screenHelper.calcY(40f);
float sliderWitdh = screenHelper.calcX(200f); float sliderWitdh = screenHelper.calcX(200f);
float sliderHeight = screenHelper.calcY(30f); float sliderHeight = screenHelper.calcY(30f);
@ -245,7 +243,7 @@ public class OptionsGUI extends Panel implements Gui {
Label lblFXVolume = new Label(screen, "lblFXVolume", new Vector2f(startPointx + screenHelper.calcX(400f), startPointy), new Vector2f(labelWitdh, labelHeight)); Label lblFXVolume = new Label(screen, "lblFXVolume", new Vector2f(startPointx + screenHelper.calcX(400f), startPointy), new Vector2f(labelWitdh, labelHeight));
lblFXVolume.setText("Menu Volume"); lblFXVolume.setText("Menu Volume");
lblFXVolume.setFontSize(labelFontSize); lblFXVolume.setFontSize(labelFontSize);
sldMenuVolume = new Slider(screen, new Vector2f(startPointx + marginLeftControls + screenHelper.calcX(400f), startPointy + screenHelper.calcY(7f)), new Vector2f(sliderWitdh, sliderHeight), Slider.Orientation.HORIZONTAL, false) { sldMenuVolume = new Slider(screen, new Vector2f(startPointx + marginLeftControls + screenHelper.calcX(400f), startPointy + screenHelper.calcY(7f)), new Vector2f(sliderWitdh, sliderHeight), Slider.Orientation.HORIZONTAL, false) {
@Override @Override
public void onChange(int selectedIndex, Object value) { public void onChange(int selectedIndex, Object value) {
@ -277,7 +275,7 @@ public class OptionsGUI extends Panel implements Gui {
//General //General
txtPlayerName.setText(settings.getUsername()); txtPlayerName.setText(settings.getUsername());
//Video //Video
setComboBoxValue(cboResolution, resolution); setComboBoxValue(cboResolution, resolution);
setComboBoxValue(cboFrequency, String.valueOf(settings.getFrequency())); setComboBoxValue(cboFrequency, String.valueOf(settings.getFrequency()));
@ -303,7 +301,7 @@ public class OptionsGUI extends Panel implements Gui {
private void saveControlValues() { private void saveControlValues() {
//General //General
settings.setUsername(txtPlayerName.getText()); settings.setUsername(txtPlayerName.getText());
//Video //Video
String resolution[] = cboResolution.getSelectedListItem().getValue().toString().split(" x "); String resolution[] = cboResolution.getSelectedListItem().getValue().toString().split(" x ");
settings.setWidth(Integer.parseInt(resolution[0])); settings.setWidth(Integer.parseInt(resolution[0]));
@ -321,4 +319,7 @@ public class OptionsGUI extends Panel implements Gui {
settings.save(); settings.save();
} }
public void refresh() {
}
} }

View File

@ -30,11 +30,11 @@ import tonegod.gui.core.Screen;
* *
* @author Snowsun * @author Snowsun
*/ */
public class SelectTrackGUI extends Panel implements Gui{ public class SelectTrackGUI extends Panel implements Gui {
private SelectFileListener listener; private SelectFileListener listener;
private ScreenHelper screenHelper; private ScreenHelper screenHelper;
public SelectTrackGUI(Screen screen, SelectFileListener listener, ScreenHelper screenHelper) { public SelectTrackGUI(Screen screen, SelectFileListener listener, ScreenHelper screenHelper) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
this.listener = listener; this.listener = listener;
@ -43,7 +43,7 @@ public class SelectTrackGUI extends Panel implements Gui{
this.setIsVisible(false); this.setIsVisible(false);
create(); create();
} }
private void create() { private void create() {
float startPointx = screenHelper.calcX(576f); float startPointx = screenHelper.calcX(576f);
float startPointy = screenHelper.calcY(260f); float startPointy = screenHelper.calcY(260f);
@ -56,7 +56,7 @@ public class SelectTrackGUI extends Panel implements Gui{
float labelWitdh = screenHelper.calcX(100f); float labelWitdh = screenHelper.calcX(100f);
float labelHeight = screenHelper.calcY(40f); float labelHeight = screenHelper.calcY(40f);
float buttonFontSize = screenHelper.calcX(20f); float buttonFontSize = screenHelper.calcX(20f);
Button btnSelectFile = new ButtonBase(screen, new Vector2f(startPointx, startPointy), new Vector2f(buttonWidth, buttonHeight)) { Button btnSelectFile = new ButtonBase(screen, new Vector2f(startPointx, startPointy), new Vector2f(buttonWidth, buttonHeight)) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -65,11 +65,11 @@ public class SelectTrackGUI extends Panel implements Gui{
}; };
btnSelectFile.setText("Select File"); btnSelectFile.setText("Select File");
btnSelectFile.setFontSize(buttonFontSize); btnSelectFile.setFontSize(buttonFontSize);
Label lblOr = new Label(screen, new Vector2f(startPointx + marginLabelOrLeft, startPointy + marginLabelOrTop), new Vector2f(labelWitdh, labelHeight)); Label lblOr = new Label(screen, new Vector2f(startPointx + marginLabelOrLeft, startPointy + marginLabelOrTop), new Vector2f(labelWitdh, labelHeight));
lblOr.setFontSize(labelFontSize); lblOr.setFontSize(labelFontSize);
lblOr.setText("Or"); lblOr.setText("Or");
Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop), new Vector2f(buttonWidth, buttonHeight)) { Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop), new Vector2f(buttonWidth, buttonHeight)) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -78,7 +78,7 @@ public class SelectTrackGUI extends Panel implements Gui{
}; };
btnYTDownload.setText("YT Download"); btnYTDownload.setText("YT Download");
btnYTDownload.setFontSize(buttonFontSize); btnYTDownload.setFontSize(buttonFontSize);
Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop + screenHelper.calcY(114f)), new Vector2f(buttonWidth, buttonHeight)) { Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop + screenHelper.calcY(114f)), new Vector2f(buttonWidth, buttonHeight)) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -87,13 +87,16 @@ public class SelectTrackGUI extends Panel implements Gui{
}; };
btnCancel.setText("Cancel"); btnCancel.setText("Cancel");
btnCancel.setFontSize(buttonFontSize); btnCancel.setFontSize(buttonFontSize);
this.addChild(btnSelectFile); this.addChild(btnSelectFile);
this.addChild(lblOr); this.addChild(lblOr);
this.addChild(btnYTDownload); this.addChild(btnYTDownload);
this.addChild(btnCancel); this.addChild(btnCancel);
} }
public void refresh() {
}
public void attach() { public void attach() {
screen.addElement(this); screen.addElement(this);
} }

View File

@ -31,11 +31,11 @@ import tonegod.gui.core.Screen;
* *
* @author Snowsun * @author Snowsun
*/ */
public class YTDownloadGUI extends Panel implements Gui{ public class YTDownloadGUI extends Panel implements Gui {
private YTDownloadListener listener; private YTDownloadListener listener;
private ScreenHelper screenHelper; private ScreenHelper screenHelper;
public YTDownloadGUI(Screen screen, YTDownloadListener listener, ScreenHelper screenHelper) { public YTDownloadGUI(Screen screen, YTDownloadListener listener, ScreenHelper screenHelper) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
this.listener = listener; this.listener = listener;
@ -44,7 +44,7 @@ public class YTDownloadGUI extends Panel implements Gui{
this.setIsVisible(false); this.setIsVisible(false);
create(); create();
} }
private void create() { private void create() {
float startPointx = screenHelper.calcX(384f); float startPointx = screenHelper.calcX(384f);
float startPointy = screenHelper.calcY(324f); float startPointy = screenHelper.calcY(324f);
@ -58,20 +58,20 @@ public class YTDownloadGUI extends Panel implements Gui{
float marginYTButtonTop = screenHelper.calcY(72f); float marginYTButtonTop = screenHelper.calcY(72f);
float labelWitdh = screenHelper.calcX(160f); float labelWitdh = screenHelper.calcX(160f);
float labelHeight = screenHelper.calcY(40f); float labelHeight = screenHelper.calcY(40f);
float buttonFontSize = screenHelper.calcX(20f); float buttonFontSize = screenHelper.calcX(20f);
float buttonHeight = screenHelper.calcY(40f); float buttonHeight = screenHelper.calcY(40f);
float textFieldHeight = screenHelper.calcY(40f); float textFieldHeight = screenHelper.calcY(40f);
Label lblYTLink = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(labelWitdh, labelHeight)); Label lblYTLink = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(labelWitdh, labelHeight));
lblYTLink.setFontSize(labelFontSize); lblYTLink.setFontSize(labelFontSize);
lblYTLink.setText("YT Link"); lblYTLink.setText("YT Link");
final TextField txtYTLink = new TextField(screen,"txtYTLink", new Vector2f(startPointx + marginTextFieldLeft, startPointy + marginTextFieldTop), new Vector2f(textFieldWitdh, textFieldHeight)); final TextField txtYTLink = new TextField(screen, "txtYTLink", new Vector2f(startPointx + marginTextFieldLeft, startPointy + marginTextFieldTop), new Vector2f(textFieldWitdh, textFieldHeight));
txtYTLink.setType(TextField.Type.DEFAULT); txtYTLink.setType(TextField.Type.DEFAULT);
txtYTLink.setFontSize(buttonFontSize); txtYTLink.setFontSize(buttonFontSize);
Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx + marginYTButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, buttonHeight)) { Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx + marginYTButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, buttonHeight)) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -80,7 +80,7 @@ public class YTDownloadGUI extends Panel implements Gui{
}; };
btnYTDownload.setText("Download"); btnYTDownload.setText("Download");
btnYTDownload.setFontSize(buttonFontSize); btnYTDownload.setFontSize(buttonFontSize);
Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx + marginCancelButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, buttonHeight)) { Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx + marginCancelButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, buttonHeight)) {
@Override @Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
@ -89,13 +89,16 @@ public class YTDownloadGUI extends Panel implements Gui{
}; };
btnCancel.setText("Cancel"); btnCancel.setText("Cancel");
btnCancel.setFontSize(buttonFontSize); btnCancel.setFontSize(buttonFontSize);
this.addChild(lblYTLink); this.addChild(lblYTLink);
this.addChild(txtYTLink); this.addChild(txtYTLink);
this.addChild(btnYTDownload); this.addChild(btnYTDownload);
this.addChild(btnCancel); this.addChild(btnCancel);
} }
public void refresh() {
}
public void attach() { public void attach() {
screen.addElement(this); screen.addElement(this);
} }
@ -103,5 +106,4 @@ public class YTDownloadGUI extends Panel implements Gui{
public void detach() { public void detach() {
screen.removeElement(this); screen.removeElement(this);
} }
} }

View File

@ -32,12 +32,10 @@ import tonegod.gui.core.Screen;
public class FileMetaInfoState extends AbstractAppState implements FileMetaInfoListener { public class FileMetaInfoState extends AbstractAppState implements FileMetaInfoListener {
private StateManager stateManager; private StateManager stateManager;
private GameSettings settings;
private Gui gui; private Gui gui;
public FileMetaInfoState(Screen screen, StateManager stateManager, GameSettings settings, ScreenHelper screenHelper) { public FileMetaInfoState(Screen screen, StateManager stateManager, GameSettings settings, ScreenHelper screenHelper) {
this.stateManager = stateManager; this.stateManager = stateManager;
this.settings = settings;
this.gui = new FileMetaInfoGUI(screen, this, settings, screenHelper); this.gui = new FileMetaInfoGUI(screen, this, settings, screenHelper);
} }
@ -51,6 +49,7 @@ public class FileMetaInfoState extends AbstractAppState implements FileMetaInfoL
@Override @Override
public void stateAttached(AppStateManager stateManager) { public void stateAttached(AppStateManager stateManager) {
gui.refresh();
gui.attach(); gui.attach();
} }

View File

@ -95,7 +95,12 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
this.optionSettings = optionSettings; this.optionSettings = optionSettings;
this.highscoreManager = highscoreManager; this.highscoreManager = highscoreManager;
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet"); if (settings.useVideo()) {
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
} else {
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet",
"--audio-visual=visual", "--effect-list=scope");
}
this.settings = settings; this.settings = settings;
@ -113,6 +118,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(settings.getVideoFormat(), mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(settings.getVideoFormat(),
settings.getVideoWidth(), settings.getVideoHeight(), settings.getVideoWidth(), settings.getVideoHeight(),
settings.getVideoWidth() * settings.getVideoDepth(), cinema); settings.getVideoWidth() * settings.getVideoDepth(), cinema);
mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventListenerBase() { mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventListenerBase() {
@Override @Override
public void finished(MediaPlayer mp) { public void finished(MediaPlayer mp) {
@ -130,7 +136,7 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
public void loadPlayer() { public void loadPlayer() {
starNode = new Node(); starNode = new Node();
player = new Player(rootNode, stateManager, assetManager, viewPort, gui, player = new Player(rootNode, stateManager, assetManager, viewPort, gui,
inputManager, camera, audioDataManager, starNode); inputManager, camera, audioDataManager, starNode, optionSettings);
gui.setPlayer(player); gui.setPlayer(player);
@ -146,8 +152,8 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
public void start() { public void start() {
gui.setStart(); gui.setStart();
inputManager.setCursorVisible(false); inputManager.setCursorVisible(false);
mediaPlayer.setVolume(optionSettings.getMusicVolume() * mediaPlayer.setVolume(optionSettings.getMusicVolume()
Math.round((float)optionSettings.getMasterVolume() / 100f)); * Math.round((float) optionSettings.getMasterVolume() / 100f));
mediaPlayer.play(); mediaPlayer.play();
setRunning(true); setRunning(true);
} }
@ -238,13 +244,13 @@ public class GameState extends AbstractAppState implements GameListener, ActionL
public void finished() { public void finished() {
String songName = settings.getTrackArtist() + " - " + settings.getTrackTitle(); String songName = settings.getTrackArtist() + " - " + settings.getTrackTitle();
if(settings.useVideo()) { if (settings.useVideo()) {
highscoreManager.addScore(songName, optionSettings.getUsername(), Integer.valueOf(player.getUserData(UserDataKeys.POINTS).toString())); highscoreManager.addScore(songName, optionSettings.getUsername(), Integer.valueOf(player.getUserData(UserDataKeys.POINTS).toString()));
} else { } else {
highscoreManager.addScore(songName, optionSettings.getUsername(), Integer.valueOf(player.getUserData(UserDataKeys.POINTS).toString())); highscoreManager.addScore(songName, optionSettings.getUsername(), Integer.valueOf(player.getUserData(UserDataKeys.POINTS).toString()));
} }
stateManager.setState(State.HIGHSCORE); stateManager.setState(State.HIGHSCORE);
} }

View File

@ -18,6 +18,7 @@ package org.wyrez.shootingstars.states;
import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager; import com.jme3.app.state.AppStateManager;
import com.sun.jna.Memory;
import java.io.File; import java.io.File;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.game.GameSettings;
@ -25,6 +26,10 @@ import org.wyrez.shootingstars.gui.SelectTrackGUI;
import org.wyrez.shootingstars.gui.listener.SelectFileListener; import org.wyrez.shootingstars.gui.listener.SelectFileListener;
import org.wyrez.shootingstars.helper.ScreenHelper; import org.wyrez.shootingstars.helper.ScreenHelper;
import tonegod.gui.core.Screen; import tonegod.gui.core.Screen;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.direct.BufferFormat;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
import uk.co.caprica.vlcj.player.direct.RenderCallback;
/** /**
* *
@ -32,6 +37,8 @@ import tonegod.gui.core.Screen;
*/ */
public class SelectTrackState extends AbstractAppState implements SelectFileListener { public class SelectTrackState extends AbstractAppState implements SelectFileListener {
private static final int SLEEP = 1000;
/**/
private StateManager stateManager; private StateManager stateManager;
private GameSettings settings; private GameSettings settings;
private SelectTrackGUI gui; private SelectTrackGUI gui;
@ -39,7 +46,7 @@ public class SelectTrackState extends AbstractAppState implements SelectFileList
public SelectTrackState(Screen screen, StateManager stateManager, GameSettings settings, ScreenHelper screenHelper) { public SelectTrackState(Screen screen, StateManager stateManager, GameSettings settings, ScreenHelper screenHelper) {
this.stateManager = stateManager; this.stateManager = stateManager;
this.settings = settings; this.settings = settings;
this.gui = new SelectTrackGUI(screen, this,screenHelper); this.gui = new SelectTrackGUI(screen, this, screenHelper);
} }
@Override @Override
@ -59,10 +66,35 @@ public class SelectTrackState extends AbstractAppState implements SelectFileList
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = jFileChooser.getSelectedFile(); File file = jFileChooser.getSelectedFile();
settings.setVideoFile(file.getPath()); settings.setVideoFile(file.getPath());
readMetadata(settings.getVideoFile());
stateManager.setState(State.FILEMETAINFO); stateManager.setState(State.FILEMETAINFO);
} }
} }
private void readMetadata(String file) {
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
DirectMediaPlayer mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(1, 1, new RenderCallback() {
public void display(DirectMediaPlayer dmp, Memory[] memorys, BufferFormat bf) {
}
});
mediaPlayer.setVolume(0);
mediaPlayer.prepareMedia(file);
mediaPlayer.play();
try {
Thread.sleep(SLEEP);
} catch (Exception ex) {
}
settings.useVideo(mediaPlayer.getVideoTrackCount() > 0);
settings.setTrackTitle(mediaPlayer.getMediaMeta().getTitle());
settings.setTrackArtist(mediaPlayer.getMediaMeta().getArtist());
settings.setTrackLength(Math.round((float) mediaPlayer.getLength() / 1000f));
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayerFactory.release();
}
public void downloadYT() { public void downloadYT() {
stateManager.setState(State.YTDOWNLOAD); stateManager.setState(State.YTDOWNLOAD);
} }

View File

@ -18,9 +18,11 @@ package org.wyrez.shootingstars.states;
import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager; import com.jme3.app.state.AppStateManager;
import com.sun.jna.Memory;
import java.io.File; import java.io.File;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.wyrez.baseio.config.FlatFileConfig;
import org.wyrez.shootingstars.data.YTDownloader; import org.wyrez.shootingstars.data.YTDownloader;
import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.game.GameSettings;
import org.wyrez.shootingstars.gui.YTDownloadGUI; import org.wyrez.shootingstars.gui.YTDownloadGUI;
@ -28,6 +30,10 @@ import org.wyrez.shootingstars.gui.listener.YTDownloadListener;
import org.wyrez.shootingstars.helper.PathHelper; import org.wyrez.shootingstars.helper.PathHelper;
import org.wyrez.shootingstars.helper.ScreenHelper; import org.wyrez.shootingstars.helper.ScreenHelper;
import tonegod.gui.core.Screen; import tonegod.gui.core.Screen;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.direct.BufferFormat;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
import uk.co.caprica.vlcj.player.direct.RenderCallback;
/** /**
* *
@ -35,6 +41,10 @@ import tonegod.gui.core.Screen;
*/ */
public class YTDownloadState extends AbstractAppState implements YTDownloadListener { public class YTDownloadState extends AbstractAppState implements YTDownloadListener {
private static final int SLEEP = 1000;
private static final String META_EXTENSION = ".meta";
private static final String KEY_TITLE = "Title";
private static final String KEY_ARTIST = "Artist";
private static final Pattern YT_LINK_PATTERN = Pattern.compile("\\?v=[^\\&]*\\&??"); private static final Pattern YT_LINK_PATTERN = Pattern.compile("\\?v=[^\\&]*\\&??");
/**/ /**/
private StateManager stateManager; private StateManager stateManager;
@ -77,8 +87,10 @@ public class YTDownloadState extends AbstractAppState implements YTDownloadListe
path = PathHelper.getCacheFolder() + identifier path = PathHelper.getCacheFolder() + identifier
+ targetPath.substring(targetPath.lastIndexOf("."), targetPath.length()); + targetPath.substring(targetPath.lastIndexOf("."), targetPath.length());
new File(targetPath).renameTo(new File(path)); new File(targetPath).renameTo(new File(path));
createMetadataFile(path);
} }
settings.setVideoFile(path); settings.setVideoFile(path);
readMetadata();
stateManager.setState(State.FILEMETAINFO); stateManager.setState(State.FILEMETAINFO);
} catch (Exception ex) { } catch (Exception ex) {
stateManager.setState(State.MENU); stateManager.setState(State.MENU);
@ -95,6 +107,38 @@ public class YTDownloadState extends AbstractAppState implements YTDownloadListe
return null; return null;
} }
private void createMetadataFile(String file) {
FlatFileConfig config = new FlatFileConfig(file + META_EXTENSION);
config.putString(KEY_TITLE, downloader.getLastTitle());
config.putString(KEY_ARTIST, "Youtube download");
config.save();
}
private void readMetadata() {
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
DirectMediaPlayer mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(1, 1, new RenderCallback() {
public void display(DirectMediaPlayer dmp, Memory[] memorys, BufferFormat bf) {
}
});
mediaPlayer.setVolume(0);
mediaPlayer.prepareMedia(settings.getVideoFile());
mediaPlayer.play();
try {
Thread.sleep(SLEEP);
} catch (Exception ex) {
}
FlatFileConfig config = new FlatFileConfig(settings.getVideoFile() + META_EXTENSION);
settings.setTrackTitle(config.getString(KEY_TITLE));
settings.setTrackArtist(config.getString(KEY_ARTIST));
settings.useVideo(mediaPlayer.getVideoTrackCount() > 0);
settings.setTrackLength(Math.round((float) mediaPlayer.getLength() / 1000f));
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayerFactory.release();
}
public void cancel() { public void cancel() {
stateManager.setState(State.MENU); stateManager.setState(State.MENU);
} }