use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.
the class MapComponent method createNewMapObject.
private IMapObject createNewMapObject(MapObjectType type) {
final Rectangle2D newObjectArea = this.getMouseSelectArea(true);
IMapObject mo = new MapObject();
mo.setType(type.toString());
mo.setX((float) newObjectArea.getX());
mo.setY((float) newObjectArea.getY());
// ensure a minimum size for the new object
float width = (float) newObjectArea.getWidth();
float height = (float) newObjectArea.getHeight();
mo.setWidth(width == 0 ? 16 : width);
mo.setHeight(height == 0 ? 16 : height);
mo.setId(Game.world().environment().getNextMapId());
mo.setName("");
switch(type) {
case EMITTER:
EmitterData defaultData = new EmitterData();
defaultData.initDefaults();
defaultData.setWidth(mo.getWidth());
defaultData.setHeight(mo.getHeight());
defaultData.setName(mo.getName());
EmitterMapObjectLoader.updateMapObject(defaultData, mo);
break;
case PROP:
mo.setValue(MapObjectProperty.COLLISIONBOX_WIDTH, (newObjectArea.getWidth() * 0.4));
mo.setValue(MapObjectProperty.COLLISIONBOX_HEIGHT, (newObjectArea.getHeight() * 0.4));
mo.setValue(MapObjectProperty.COLLISION, true);
mo.setValue(MapObjectProperty.COMBAT_INDESTRUCTIBLE, false);
mo.setValue(MapObjectProperty.PROP_ADDSHADOW, true);
break;
case LIGHTSOURCE:
mo.setValue(MapObjectProperty.LIGHT_COLOR, Color.WHITE);
mo.setValue(MapObjectProperty.LIGHT_SHAPE, "ellipse");
mo.setValue(MapObjectProperty.LIGHT_ACTIVE, true);
break;
case COLLISIONBOX:
mo.setValue(MapObjectProperty.COLLISION_TYPE, Collision.STATIC);
break;
case SOUNDSOURCE:
mo.setValue(MapObjectProperty.SOUND_VOLUME, 1);
mo.setValue(MapObjectProperty.SOUND_LOOP, true);
break;
case SPAWNPOINT:
break;
default:
break;
}
this.add(mo);
return mo;
}
use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.
the class AssetPanelItem method addEntity.
private boolean addEntity() {
if (Game.world().environment() == null || Game.world().camera() == null) {
return false;
}
if (this.getOrigin() instanceof SpritesheetResource) {
SpritesheetResource info = (SpritesheetResource) this.getOrigin();
MapObject mo = new MapObject();
String propName = PropPanel.getIdentifierBySpriteName(info.getName());
String creatureName = CreaturePanel.getCreatureSpriteName(info.getName());
if (propName != null) {
mo.setType(MapObjectType.PROP.name());
mo.setValue(MapObjectProperty.SPRITESHEETNAME, propName);
} else if (creatureName != null) {
mo.setType(MapObjectType.CREATURE.name());
mo.setValue(MapObjectProperty.SPRITESHEETNAME, creatureName);
} else {
return false;
}
mo.setX((int) Game.world().camera().getFocus().getX() - info.getWidth() / 2f);
mo.setY((int) Game.world().camera().getFocus().getY() - info.getHeight() / 2f);
mo.setWidth(info.getWidth());
mo.setHeight(info.getHeight());
mo.setId(Game.world().environment().getNextMapId());
mo.setName("");
mo.setValue(MapObjectProperty.COLLISIONBOX_WIDTH, info.getWidth() * 0.4);
mo.setValue(MapObjectProperty.COLLISIONBOX_HEIGHT, info.getHeight() * 0.4);
mo.setValue(MapObjectProperty.COLLISION, true);
mo.setValue(MapObjectProperty.COMBAT_INDESTRUCTIBLE, false);
mo.setValue(MapObjectProperty.PROP_ADDSHADOW, true);
Editor.instance().getMapComponent().add(mo);
return true;
} else if (this.getOrigin() instanceof EmitterData) {
MapObject newEmitter = (MapObject) EmitterMapObjectLoader.createMapObject((EmitterData) this.getOrigin());
newEmitter.setX((int) (Game.world().camera().getFocus().getX() - newEmitter.getWidth()));
newEmitter.setY((int) (Game.world().camera().getFocus().getY() - newEmitter.getHeight()));
newEmitter.setId(Game.world().environment().getNextMapId());
Editor.instance().getMapComponent().add(newEmitter);
} else if (this.getOrigin() instanceof Blueprint) {
Blueprint blueprint = (Blueprint) this.getOrigin();
UndoManager.instance().beginOperation();
try {
List<IMapObject> newObjects = blueprint.build((int) Game.world().camera().getFocus().getX() - blueprint.getWidth() / 2, (int) Game.world().camera().getFocus().getY() - blueprint.getHeight() / 2);
for (IMapObject newMapObject : newObjects) {
Editor.instance().getMapComponent().add(newMapObject);
}
// gets added
for (IMapObject newMapObject : newObjects) {
Editor.instance().getMapComponent().setSelection(newMapObject, false);
}
} finally {
UndoManager.instance().endOperation();
}
}
return false;
}
use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.
the class AssetPanelItem method deleteAsset.
private void deleteAsset() {
if (getOrigin() instanceof SpritesheetResource) {
SpritesheetResource info = (SpritesheetResource) getOrigin();
int n = getDeleteDialog("spritesheet", info.getName());
if (n == JOptionPane.OK_OPTION) {
Editor.instance().getGameFile().getSpriteSheets().remove(getOrigin());
Resources.images().clear();
Resources.spritesheets().remove(info.getName());
Editor.instance().getMapComponent().reloadEnvironment();
UI.getAssetController().refresh();
}
} else if (getOrigin() instanceof EmitterData) {
EmitterData emitter = (EmitterData) getOrigin();
int n = getDeleteDialog("emitter", emitter.getName());
if (n == JOptionPane.OK_OPTION) {
Editor.instance().getGameFile().getEmitters().remove(getOrigin());
Editor.instance().getMapComponent().reloadEnvironment();
UI.getAssetController().refresh();
}
} else if (getOrigin() instanceof Blueprint) {
Blueprint blueprint = (Blueprint) getOrigin();
int n = getDeleteDialog("blueprint", blueprint.getName());
if (n == JOptionPane.OK_OPTION) {
Editor.instance().getGameFile().getBluePrints().remove(getOrigin());
UI.getAssetController().refresh();
}
} else if (getOrigin() instanceof SoundResource) {
SoundResource sound = (SoundResource) getOrigin();
int n = getDeleteDialog("sound", sound.getName());
if (n == JOptionPane.OK_OPTION) {
Editor.instance().getGameFile().getSounds().remove(getOrigin());
UI.getAssetController().refresh();
}
}
}
use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.
the class AssetPanelItem method canAdd.
private boolean canAdd() {
if (this.getOrigin() instanceof SpritesheetResource) {
SpritesheetResource info = (SpritesheetResource) this.getOrigin();
String propName = PropPanel.getIdentifierBySpriteName(info.getName());
return propName != null && !propName.isEmpty() || CreaturePanel.getCreatureSpriteName(info.getName()) != null;
}
return this.getOrigin() instanceof MapObject || this.getOrigin() instanceof EmitterData;
}
use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.
the class AssetPanelItem method exportEmitter.
private void exportEmitter() {
if (!(this.getOrigin() instanceof EmitterData)) {
return;
}
EmitterData emitter = (EmitterData) this.getOrigin();
XmlExportDialog.export(emitter, "Emitter", emitter.getName());
}
Aggregations