Search in sources :

Example 1 with TriggerActivation

use of de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation in project litiengine by gurkenlabs.

the class TriggerPanel method setupChangedListeners.

private void setupChangedListeners() {
    this.chckbxOneTimeOnly.addActionListener(new MapObjectPropertyActionListener(m -> m.setCustomProperty(MapObjectProperty.TRIGGER_ONETIME, Boolean.toString(this.chckbxOneTimeOnly.isSelected()))));
    this.textFieldMessage.addFocusListener(new MapObjectPropteryFocusListener(m -> m.setCustomProperty(MapObjectProperty.TRIGGER_MESSAGE, textFieldMessage.getText())));
    this.textFieldMessage.addActionListener(new MapObjectPropertyActionListener(m -> m.setCustomProperty(MapObjectProperty.TRIGGER_MESSAGE, textFieldMessage.getText())));
    this.comboBoxActivationType.addActionListener(new MapObjectPropertyActionListener(m -> {
        TriggerActivation act = (TriggerActivation) this.comboBoxActivationType.getSelectedItem();
        m.setCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION, act.toString());
    }));
    this.model.addTableModelListener(t -> {
        if (getDataSource() == null || isFocussing) {
            return;
        }
        List<String> activators = new ArrayList<>();
        for (int row = 0; row < model.getRowCount(); row++) {
            Object activator = model.getValueAt(row, 0);
            if (activator != null) {
                activators.add(activator.toString());
            }
        }
        getDataSource().setCustomProperty(MapObjectProperty.TRIGGER_ACTIVATORS, String.join(",", activators));
    });
    this.targetsModel.addTableModelListener(t -> {
        if (getDataSource() == null || isFocussing) {
            return;
        }
        List<String> targets = new ArrayList<>();
        for (int row = 0; row < targetsModel.getRowCount(); row++) {
            Object target = targetsModel.getValueAt(row, 0);
            if (target != null) {
                targets.add(target.toString());
            }
        }
        getDataSource().setCustomProperty(MapObjectProperty.TRIGGER_TARGETS, String.join(",", targets));
    });
    this.spinnerCooldown.addChangeListener(new MapObjectPropertyChangeListener(m -> m.setCustomProperty(MapObjectProperty.TRIGGER_COOLDOWN, Integer.toString((int) this.spinnerCooldown.getValue()))));
}
Also used : Color(java.awt.Color) Insets(java.awt.Insets) JTextField(javax.swing.JTextField) LineBorder(javax.swing.border.LineBorder) TriggerActivation(de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) ArrayList(java.util.ArrayList) TitledBorder(javax.swing.border.TitledBorder) MapObjectProperty(de.gurkenlabs.litiengine.environment.tilemap.MapObjectProperty) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JComboBox(javax.swing.JComboBox) Resources(de.gurkenlabs.litiengine.Resources) JButton(javax.swing.JButton) JSpinner(javax.swing.JSpinner) DefaultTableModel(javax.swing.table.DefaultTableModel) Font(java.awt.Font) ArrayUtilities(de.gurkenlabs.litiengine.util.ArrayUtilities) ComponentPlacement(javax.swing.LayoutStyle.ComponentPlacement) JScrollPane(javax.swing.JScrollPane) List(java.util.List) Alignment(javax.swing.GroupLayout.Alignment) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) JCheckBox(javax.swing.JCheckBox) JTable(javax.swing.JTable) TriggerActivation(de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation) ArrayList(java.util.ArrayList) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 2 with TriggerActivation

use of de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation in project litiengine by gurkenlabs.

the class TriggerMapObjectLoader method load.

@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
    if (MapObjectType.get(mapObject.getType()) != MapObjectType.TRIGGER) {
        throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + TriggerMapObjectLoader.class);
    }
    final String message = mapObject.getCustomProperty(MapObjectProperty.TRIGGER_MESSAGE);
    final TriggerActivation act = mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION) != null ? TriggerActivation.valueOf(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION)) : TriggerActivation.COLLISION;
    final boolean oneTime = mapObject.getCustomPropertyBool(MapObjectProperty.TRIGGER_ONETIME);
    final int coolDown = mapObject.getCustomPropertyInt(MapObjectProperty.TRIGGER_COOLDOWN);
    final Trigger trigger = this.createTrigger(mapObject, act, message, oneTime, coolDown, mapObject);
    loadDefaultProperties(trigger, mapObject);
    this.loadTargets(mapObject, trigger);
    this.loadActivators(mapObject, trigger);
    Collection<IEntity> entities = super.load(environment, mapObject);
    entities.add(trigger);
    return entities;
}
Also used : TriggerActivation(de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation) Trigger(de.gurkenlabs.litiengine.entities.Trigger) IEntity(de.gurkenlabs.litiengine.entities.IEntity)

Example 3 with TriggerActivation

use of de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation in project litiengine by gurkenlabs.

the class TriggerPanel method setControlValues.

@Override
protected void setControlValues(IMapObject mapObject) {
    this.textFieldMessage.setText(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_MESSAGE));
    String targets = mapObject.getCustomProperty(MapObjectProperty.TRIGGER_TARGETS);
    this.targetsModel.setRowCount(0);
    for (int target : ArrayUtilities.getIntegerArray(targets)) {
        this.targetsModel.addRow(new Object[] { target });
    }
    this.chckbxOneTimeOnly.setSelected(mapObject.getCustomPropertyBool(MapObjectProperty.TRIGGER_ONETIME));
    final TriggerActivation act = mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION) == null ? TriggerActivation.COLLISION : TriggerActivation.valueOf(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION));
    this.comboBoxActivationType.setSelectedItem(act);
    String activators = mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATORS);
    this.model.setRowCount(0);
    for (int activator : ArrayUtilities.getIntegerArray(activators)) {
        this.model.addRow(new Object[] { activator });
    }
    this.spinnerCooldown.setValue(mapObject.getCustomPropertyInt(MapObjectProperty.TRIGGER_COOLDOWN));
}
Also used : TriggerActivation(de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation)

Aggregations

TriggerActivation (de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation)3 Resources (de.gurkenlabs.litiengine.Resources)1 IEntity (de.gurkenlabs.litiengine.entities.IEntity)1 Trigger (de.gurkenlabs.litiengine.entities.Trigger)1 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)1 MapObjectProperty (de.gurkenlabs.litiengine.environment.tilemap.MapObjectProperty)1 ArrayUtilities (de.gurkenlabs.litiengine.util.ArrayUtilities)1 Color (java.awt.Color)1 Font (java.awt.Font)1 Insets (java.awt.Insets)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 GroupLayout (javax.swing.GroupLayout)1 Alignment (javax.swing.GroupLayout.Alignment)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JScrollPane (javax.swing.JScrollPane)1