Last active
June 7, 2017 10:12
-
-
Save Antonystar/3229f0cf23c442ba4ba366fcaaa88d59 to your computer and use it in GitHub Desktop.
EffectManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package tonegod.gui.effects; | |
import com.jme3.export.JmeExporter; | |
import com.jme3.export.JmeImporter; | |
import com.jme3.renderer.RenderManager; | |
import com.jme3.renderer.ViewPort; | |
import com.jme3.scene.Spatial; | |
import com.jme3.scene.control.Control; | |
import com.jme3.util.SafeArrayList; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import tonegod.gui.core.Screen; | |
/** | |
* | |
* @author t0neg0d | |
*/ | |
public class EffectManager implements Control { | |
Screen screen; | |
Spatial spatial; | |
// private Map<String, Effect> currentEffects = new HashMap(); | |
private SafeArrayList<Effect> currentEffects = new SafeArrayList<Effect>(Effect.class); | |
private SafeArrayList<EffectQueue> currentEffectQueues = new SafeArrayList<EffectQueue>(EffectQueue.class); | |
private SafeArrayList<BatchEffect> currentBatchEffects = new SafeArrayList<BatchEffect>(BatchEffect.class); | |
public EffectManager(Screen screen) { | |
this.screen = screen; | |
} | |
public void applyEffect(Effect effect) { | |
if (effect != null) { | |
for (Effect ef : currentEffects) { | |
if (effect.getElement().getUID().equals(ef.getElement().getUID())) { | |
if (ef.getEffectType() == Effect.EffectType.Pulse || ef.getEffectType() == Effect.EffectType.PulseColor) | |
ef.setIsActive(false); | |
} | |
} | |
currentEffects.add(effect); | |
if (effect.getAudioFile() != null) { | |
if (screen.getUseUIAudio()) | |
screen.playAudioNode(effect.getAudioFile(), effect.getAudioVolume()); | |
} | |
} | |
} | |
public void applyEffectQueue(EffectQueue queue) { | |
queue.setEffectManager(this); | |
currentEffectQueues.add(queue); | |
} | |
public void applyBatchEffect(BatchEffect batch) { | |
batch.setEffectManager(this); | |
currentBatchEffects.add(batch); | |
batch.startBatch(); | |
} | |
@Override | |
public void update(float tpf) { | |
try { | |
for (Effect effect : currentEffects.getArray()) { | |
if (effect.getIsActive()) | |
effect.update(tpf); | |
else { | |
currentEffects.remove(effect); | |
} | |
} | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
} | |
for (EffectQueue queue : currentEffectQueues.getArray()) { | |
if (queue.getIsActive()) | |
queue.update(tpf); | |
else { | |
currentEffectQueues.remove(queue); | |
} | |
} | |
for (BatchEffect batch : currentBatchEffects.getArray()) { | |
if (batch.getIsActive()) | |
batch.update(tpf); | |
else { | |
currentBatchEffects.remove(batch); | |
} | |
} | |
} | |
@Override | |
public Control cloneForSpatial(Spatial spatial) { | |
return this; | |
} | |
@Override | |
public void setSpatial(Spatial spatial) { | |
this.spatial = spatial; | |
} | |
@Override | |
public void render(RenderManager rm, ViewPort vp) { } | |
@Override | |
public void write(JmeExporter ex) throws IOException { } | |
@Override | |
public void read(JmeImporter im) throws IOException { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment