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()))));
}
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;
}
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));
}
Aggregations