All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.badlogic.gdx.tools.flame.ParticleControllerInfluencerPanel Maven / Gradle / Ivy

The newest version!

package com.badlogic.gdx.tools.flame;

import java.awt.GridBagConstraints;
import java.awt.Insets;

import com.badlogic.gdx.graphics.g3d.particles.ParticleController;
import com.badlogic.gdx.graphics.g3d.particles.ParticleEffect;
import com.badlogic.gdx.graphics.g3d.particles.influencers.ParticleControllerInfluencer;
import com.badlogic.gdx.utils.Array;

/** @author Inferno */
public class ParticleControllerInfluencerPanel extends InfluencerPanel
	implements TemplatePickerPanel.Listener, LoaderButton.Listener, EventManager.Listener {
	TemplatePickerPanel controllerPicker;

	public ParticleControllerInfluencerPanel (FlameMain editor, ParticleControllerInfluencer influencer, boolean single,
		String name, String desc) {
		super(editor, influencer, name, desc, true, false);
		controllerPicker.setMultipleSelectionAllowed(!single);
		EventManager.get().attach(FlameMain.EVT_ASSET_RELOADED, this);
	}

	@Override
	public void setValue (ParticleControllerInfluencer value) {
		super.setValue(value);
		if (value == null) return;
		controllerPicker.setValue(value.templates);
	}

	protected void initializeComponents () {
		super.initializeComponents();
		controllerPicker = new TemplatePickerPanel(editor, null, this, ParticleController.class) {
			@Override
			protected String getTemplateName (ParticleController template, int index) {
				return template.name;
			}
		};
		reloadControllers();
		controllerPicker.setIsAlwayShown(true);

		contentPanel.add(new LoaderButton.ParticleEffectLoaderButton(editor, this), new GridBagConstraints(0, 0, 1, 1, 1, 1,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
		contentPanel.add(controllerPicker, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.CENTER,
			GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
	}

	@Override
	public void onTemplateChecked (ParticleController model, boolean isChecked) {
		editor.restart();
	}

	@Override
	public void onResourceLoaded (ParticleEffect resource) {
		reloadControllers();
	}

	private void reloadControllers () {
		Array effects = new Array();
		Array controllers = new Array();
		editor.assetManager.getAll(ParticleEffect.class, effects);
		for (ParticleEffect effect : effects) {
			controllers.addAll(effect.getControllers());
		}
		controllerPicker.setLoadedTemplates(controllers);
	}

	@Override
	public void handle (int aEventType, Object aEventData) {
		if (aEventType == FlameMain.EVT_ASSET_RELOADED) {
			Object[] data = (Object[])aEventData;
			if (data[0] instanceof ParticleEffect) {
				ParticleEffect oldEffect = (ParticleEffect)data[0];
				int currentCount = value.templates.size;
				value.templates.removeAll(oldEffect.getControllers(), true);
				if (value.templates.size != currentCount) {
					int diff = currentCount - value.templates.size;
					if (diff > 0) {
						ParticleEffect newEffect = (ParticleEffect)data[1];
						Array newControllers = newEffect.getControllers();
						if (newControllers.size > 0) {
							for (int i = 0, c = Math.min(diff, newControllers.size); i < c; ++i)
								value.templates.add(newControllers.get(i));
						}
					} else {
						value.templates
							.addAll(((ParticleEffect)editor.assetManager.get(FlameMain.DEFAULT_BILLBOARD_PARTICLE)).getControllers());
					}

					controllerPicker.reloadTemplates();
					controllerPicker.setValue(value.templates);
					editor.restart();
				}
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy