Search in sources :

Example 1 with ParticleType

use of de.gurkenlabs.litiengine.graphics.particles.xml.ParticleType in project litiengine by gurkenlabs.

the class EmitterPropertyPanel method setupChangedListeners.

private void setupChangedListeners() {
    this.btnSelectColor.addActionListener(a -> {
        if (table.getSelectedRow() == -1) {
            return;
        }
        ParticleColor color = colors.get(table.getSelectedRow());
        Color result = ColorChooser.showRgbDialog(Resources.get("panel_selectEmitterColor"), color.toColor());
        if (result == null) {
            return;
        }
        ParticleColor c = new ParticleColor(result);
        colors.set(table.getSelectedRow(), c);
        model.setValueAt(c, table.getSelectedRow(), 1);
        if (getDataSource() != null) {
            String commaSeperated = ArrayUtilities.getCommaSeparatedString(colors);
            this.getDataSource().setCustomProperty(MapObjectProperty.Emitter.COLORS, commaSeperated);
        }
    });
    this.btnRemoveColor.addActionListener(a -> {
        for (int removeIndex = 0; removeIndex < colors.size(); removeIndex++) {
            if (removeIndex == table.getSelectedRow()) {
                colors.remove(removeIndex);
                break;
            }
        }
        if (table.getSelectedRow() != -1) {
            model.removeRow(table.getSelectedRow());
        }
    });
    this.btnAddColor.addActionListener(a -> {
        ParticleColor c = new ParticleColor();
        colors.add(c);
        model.addRow(new Object[] { null, c.toString() });
    });
    this.comboBoxParticleType.addActionListener(new MapObjectPropertyActionListener(m -> {
        ParticleType particleType = (ParticleType) this.comboBoxParticleType.getSelectedItem();
        this.updateTabbedGroup();
        this.txt.setEnabled(particleType == ParticleType.TEXT);
        m.setCustomProperty(MapObjectProperty.Emitter.PARTICLETYPE, particleType.toString());
    }));
    this.comboBoxCollisionType.addActionListener(new MapObjectPropertyActionListener(m -> {
        m.setCustomProperty(MapObjectProperty.Particle.COLLISIONTYPE, this.comboBoxCollisionType.getSelectedItem().toString());
    }));
    this.comboBoxSprite.addActionListener(new MapObjectPropertyActionListener(m -> {
        String sprite = this.comboBoxSprite.getSelectedItem().toString();
        m.setCustomProperty(MapObjectProperty.Particle.SPRITE, sprite);
    }));
    this.spinnerSpawnRate.addChangeListener(new SpinnerListener(MapObjectProperty.Emitter.SPAWNRATE, this.spinnerSpawnRate));
    this.spinnerSpawnAmount.addChangeListener(new SpinnerListener(MapObjectProperty.Emitter.SPAWNAMOUNT, this.spinnerSpawnAmount));
    this.spinnerUpdateRate.addChangeListener(new SpinnerListener(MapObjectProperty.Emitter.UPDATERATE, this.spinnerUpdateRate));
    this.spinnerTTL.addChangeListener(new SpinnerListener(MapObjectProperty.Emitter.TIMETOLIVE, this.spinnerTTL));
    this.spinnerMaxParticles.addChangeListener(new SpinnerListener(MapObjectProperty.Emitter.MAXPARTICLES, this.spinnerMaxParticles));
    this.spinnerMinDeltaX.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINDELTAX, this.spinnerMinDeltaX));
    this.spinnerMaxDeltaX.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXDELTAX, this.spinnerMaxDeltaX));
    this.spinnerMinDeltaY.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINDELTAY, this.spinnerMinDeltaY));
    this.spinnerMaxDeltaY.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXDELTAY, this.spinnerMaxDeltaY));
    this.spinnerMinGravityX.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINGRAVITYX, this.spinnerMinGravityX));
    this.spinnerMaxGravityX.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXGRAVITYX, this.spinnerMaxGravityX));
    this.spinnerMinGravityY.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINGRAVITYY, this.spinnerMinGravityY));
    this.spinnerMaxGravityY.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXGRAVITYY, this.spinnerMaxGravityY));
    this.spinnerMinStartWidth.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINSTARTWIDTH, this.spinnerMinStartWidth));
    this.spinnerMaxStartWidth.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXSTARTWIDTH, this.spinnerMaxStartWidth));
    this.spinnerMinStartHeight.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINSTARTHEIGHT, this.spinnerMinStartHeight));
    this.spinnerMaxStartHeight.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXSTARTHEIGHT, this.spinnerMaxStartHeight));
    this.spinnerMinDeltaWidth.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINDELTAWIDTH, this.spinnerMinDeltaWidth));
    this.spinnerMaxDeltaWidth.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXDELTAWIDTH, this.spinnerMaxDeltaWidth));
    this.spinnerMinDeltaHeight.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINDELTAHEIGHT, this.spinnerMinDeltaHeight));
    this.spinnerMaxDeltaHeight.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXDELTAHEIGHT, this.spinnerMaxDeltaHeight));
    this.spinnerMinParticleTTL.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINTTL, this.spinnerMinParticleTTL));
    this.spinnerMaxParticleTTL.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXTTL, this.spinnerMaxParticleTTL));
    this.spinnerMinStartX.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINX, this.spinnerMinStartX));
    this.spinnerMaxStartX.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXX, this.spinnerMaxStartX));
    this.spinnerMinStartY.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MINY, this.spinnerMinStartY));
    this.spinnerMaxStartY.addChangeListener(new SpinnerListener(MapObjectProperty.Particle.MAXY, this.spinnerMaxStartY));
    this.spinnerColorDeviation.addChangeListener(new SpinnerListener(MapObjectProperty.Emitter.COLORDEVIATION, this.spinnerColorDeviation));
    this.spinnerAlphaDeviation.addChangeListener(new SpinnerListener(MapObjectProperty.Emitter.ALPHADEVIATION, this.spinnerAlphaDeviation));
    this.txt.addActionListener(new MapObjectPropertyActionListener(m -> m.setCustomProperty(MapObjectProperty.Particle.TEXT, this.txt.getText())));
}
Also used : Color(java.awt.Color) JTextField(javax.swing.JTextField) EditorScreen(de.gurkenlabs.utiliti.EditorScreen) SpinnerNumberModel(javax.swing.SpinnerNumberModel) SwingConstants(javax.swing.SwingConstants) SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) ArrayList(java.util.ArrayList) Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) EmitterMapObjectLoader(de.gurkenlabs.litiengine.environment.EmitterMapObjectLoader) JTabbedPane(javax.swing.JTabbedPane) ImageIcon(javax.swing.ImageIcon) MapObjectProperty(de.gurkenlabs.litiengine.environment.tilemap.MapObjectProperty) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JComboBox(javax.swing.JComboBox) ItemEvent(java.awt.event.ItemEvent) Resources(de.gurkenlabs.litiengine.Resources) JButton(javax.swing.JButton) JSpinner(javax.swing.JSpinner) ButtonGroup(javax.swing.ButtonGroup) DefaultTableModel(javax.swing.table.DefaultTableModel) Font(java.awt.Font) CollisionType(de.gurkenlabs.litiengine.physics.CollisionType) ArrayUtilities(de.gurkenlabs.litiengine.util.ArrayUtilities) ComponentPlacement(javax.swing.LayoutStyle.ComponentPlacement) Component(java.awt.Component) JRadioButton(javax.swing.JRadioButton) JScrollPane(javax.swing.JScrollPane) Program(de.gurkenlabs.utiliti.Program) Dimension(java.awt.Dimension) List(java.util.List) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Alignment(javax.swing.GroupLayout.Alignment) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) JTable(javax.swing.JTable) EmptyBorder(javax.swing.border.EmptyBorder) ColorChooser(de.gurkenlabs.utiliti.swing.ColorChooser) JPanel(javax.swing.JPanel) ParticleColor(de.gurkenlabs.litiengine.graphics.particles.xml.ParticleColor) ParticleType(de.gurkenlabs.litiengine.graphics.particles.xml.ParticleType) Color(java.awt.Color) ParticleColor(de.gurkenlabs.litiengine.graphics.particles.xml.ParticleColor) ParticleColor(de.gurkenlabs.litiengine.graphics.particles.xml.ParticleColor) ParticleType(de.gurkenlabs.litiengine.graphics.particles.xml.ParticleType)

Example 2 with ParticleType

use of de.gurkenlabs.litiengine.graphics.particles.xml.ParticleType in project litiengine by gurkenlabs.

the class EmitterPropertyPanel method setControlValues.

@Override
protected void setControlValues(IMapObject mapObject) {
    ParticleType type = mapObject.getCustomPropertyEnum(MapObjectProperty.Emitter.PARTICLETYPE, ParticleType.class, ParticleType.RECTANGLE);
    this.comboBoxParticleType.setSelectedItem(type);
    this.updateTabbedGroup();
    this.comboBoxSprite.setSelectedItem(mapObject.getCustomProperty(MapObjectProperty.Particle.SPRITE));
    this.comboBoxCollisionType.setSelectedItem(mapObject.getCustomPropertyEnum(MapObjectProperty.Particle.COLLISIONTYPE, CollisionType.class, CollisionType.NONE));
    // TODO: implement this
    this.comboBoxSpriteType.setSelectedIndex(0);
    this.spinnerSpawnRate.setValue(mapObject.getCustomPropertyInt(MapObjectProperty.Emitter.SPAWNRATE));
    this.spinnerSpawnAmount.setValue(mapObject.getCustomPropertyInt(MapObjectProperty.Emitter.SPAWNAMOUNT, Emitter.DEFAULT_SPAWNAMOUNT));
    this.spinnerUpdateRate.setValue(mapObject.getCustomPropertyInt(MapObjectProperty.Emitter.UPDATERATE));
    this.spinnerTTL.setValue(mapObject.getCustomPropertyInt(MapObjectProperty.Emitter.TIMETOLIVE));
    this.spinnerMaxParticles.setValue(mapObject.getCustomPropertyInt(MapObjectProperty.Emitter.MAXPARTICLES, Emitter.DEFAULT_MAXPARTICLES));
    // TODO: implement this
    this.spinnerColorDeviation.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Emitter.COLORDEVIATION));
    this.spinnerAlphaDeviation.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Emitter.ALPHADEVIATION));
    this.spinnerMinDeltaX.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINDELTAX, -PARTICLEDELTA_DEFAULT_VALUE));
    this.spinnerMaxDeltaX.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXDELTAX, PARTICLEDELTA_DEFAULT_VALUE));
    this.spinnerMinDeltaY.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINDELTAY, -PARTICLEDELTA_DEFAULT_VALUE));
    this.spinnerMaxDeltaY.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXDELTAY, PARTICLEDELTA_DEFAULT_VALUE));
    this.spinnerMinGravityX.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINGRAVITYX));
    this.spinnerMaxGravityX.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXGRAVITYX));
    this.spinnerMinGravityY.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINGRAVITYY));
    this.spinnerMaxGravityY.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXGRAVITYY));
    this.spinnerMinStartWidth.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINSTARTWIDTH, 1));
    this.spinnerMaxStartWidth.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXSTARTWIDTH, 1));
    this.spinnerMinStartHeight.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINSTARTHEIGHT, 1));
    this.spinnerMaxStartHeight.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXSTARTHEIGHT, 1));
    this.spinnerMinDeltaWidth.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINDELTAWIDTH));
    this.spinnerMaxDeltaWidth.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXDELTAWIDTH));
    this.spinnerMinDeltaHeight.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINDELTAHEIGHT));
    this.spinnerMaxDeltaHeight.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXDELTAHEIGHT));
    this.spinnerMinParticleTTL.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINTTL, PARTICLEMINTTL_DEFAULT_VALUE));
    this.spinnerMaxParticleTTL.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXTTL));
    this.spinnerMinStartX.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINX));
    this.spinnerMaxStartX.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXX));
    this.spinnerMinStartY.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MINY));
    this.spinnerMaxStartY.setValue(mapObject.getCustomPropertyDouble(MapObjectProperty.Particle.MAXY));
    this.txt.setText(mapObject.getCustomProperty(MapObjectProperty.Particle.TEXT));
    this.rdbtnRandomDeltaX.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.DELTAX_RANDOM, true));
    this.rdbtnRandomDeltaY.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.DELTAY_RANDOM, true));
    this.rdbtnRandomGravityX.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.GRAVITYX_RANDOM));
    this.rdbtnRandomGravityY.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.GRAVITYY_RANDOM));
    this.rdbtnRandomStartWidth.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.STARTWIDTH_RANDOM));
    this.rdbtnRandomStartHeight.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.STARTHEIGHT_RANDOM));
    this.rdbtnRandomDeltaWidth.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.DELTAWIDTH_RANDOM));
    this.rdbtnRandomDeltaHeight.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.DELTAHEIGHT_RANDOM));
    this.rdbtnRandomParticleTTL.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.TTL_RANDOM));
    this.rdbtnRandomStartX.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.X_RANDOM));
    this.rdbtnRandomStartY.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.Particle.Y_RANDOM));
    this.model.setRowCount(0);
    for (ParticleColor color : EmitterMapObjectLoader.getColors(mapObject)) {
        this.colors.add(color);
        this.model.addRow(new Object[] { null, color.toString() });
    }
}
Also used : CollisionType(de.gurkenlabs.litiengine.physics.CollisionType) ParticleColor(de.gurkenlabs.litiengine.graphics.particles.xml.ParticleColor) ParticleType(de.gurkenlabs.litiengine.graphics.particles.xml.ParticleType)

Aggregations

ParticleColor (de.gurkenlabs.litiengine.graphics.particles.xml.ParticleColor)2 ParticleType (de.gurkenlabs.litiengine.graphics.particles.xml.ParticleType)2 CollisionType (de.gurkenlabs.litiengine.physics.CollisionType)2 Resources (de.gurkenlabs.litiengine.Resources)1 SpriteSheetInfo (de.gurkenlabs.litiengine.SpriteSheetInfo)1 EmitterMapObjectLoader (de.gurkenlabs.litiengine.environment.EmitterMapObjectLoader)1 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)1 MapObjectProperty (de.gurkenlabs.litiengine.environment.tilemap.MapObjectProperty)1 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)1 ArrayUtilities (de.gurkenlabs.litiengine.util.ArrayUtilities)1 EditorScreen (de.gurkenlabs.utiliti.EditorScreen)1 Program (de.gurkenlabs.utiliti.Program)1 ColorChooser (de.gurkenlabs.utiliti.swing.ColorChooser)1 Color (java.awt.Color)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 ItemEvent (java.awt.event.ItemEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1