2014-02-02 18:39:08 -03:00
|
|
|
package com.droidquest.materials;
|
|
|
|
|
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
|
|
|
import javax.swing.ImageIcon;
|
|
|
|
|
|
|
|
import com.droidquest.devices.ContactSensor;
|
|
|
|
import com.droidquest.devices.DirectionalSensor;
|
|
|
|
import com.droidquest.devices.RoomSensor;
|
|
|
|
import com.droidquest.items.Item;
|
|
|
|
|
2014-04-09 00:04:44 -03:00
|
|
|
public class ShapeEditor extends Material {
|
|
|
|
private Item target;
|
2014-02-02 18:39:08 -03:00
|
|
|
|
2014-04-09 00:04:44 -03:00
|
|
|
public ShapeEditor(Item item) {
|
|
|
|
super(true, false);
|
|
|
|
target = item;
|
|
|
|
GenerateIcons();
|
|
|
|
}
|
2014-02-02 18:39:08 -03:00
|
|
|
|
2014-04-09 00:04:44 -03:00
|
|
|
public void GenerateIcons() {
|
|
|
|
target.GenerateIcons();
|
|
|
|
BufferedImage bi = new BufferedImage(28, 32, BufferedImage.TYPE_4BYTE_ABGR);
|
|
|
|
Graphics g;
|
|
|
|
try {
|
|
|
|
g = bi.getGraphics();
|
|
|
|
}
|
|
|
|
catch (NullPointerException e) {
|
|
|
|
System.out.println("Could not get Graphics pointer to " + getClass() + "Image");
|
|
|
|
return;
|
|
|
|
}
|
2014-02-02 18:39:08 -03:00
|
|
|
|
2014-04-09 00:04:44 -03:00
|
|
|
g.setColor(Color.black);
|
|
|
|
g.fillRect(0, 0, 28, 32);
|
|
|
|
g.drawImage(target.currentIcon, 14 - target.getWidth() / 2, 16 - target.getHeight() / 2, level);
|
|
|
|
icon = new ImageIcon(bi);
|
|
|
|
}
|
2014-02-02 18:39:08 -03:00
|
|
|
|
2014-04-09 00:04:44 -03:00
|
|
|
public void TouchedByItem(Item item) {
|
|
|
|
Item newItem = null;
|
|
|
|
if (item.editable) {
|
|
|
|
if (item.getClass().toString().endsWith("Sensor")) {
|
|
|
|
Item newTarget = (Item) target.clone();
|
|
|
|
if (item.getClass().toString().endsWith("ContactSensor")) {
|
|
|
|
newItem = new ContactSensor(0, 0, null, newTarget);
|
|
|
|
}
|
|
|
|
else if (item.getClass().toString().endsWith("RoomSensor")) {
|
|
|
|
newItem = new RoomSensor(0, 0, null, newTarget);
|
|
|
|
}
|
|
|
|
else if (item.getClass().toString().endsWith("DirectionalSensor")) {
|
|
|
|
newItem = new DirectionalSensor(0, 0, null, newTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newItem = (Item) target.clone();
|
|
|
|
}
|
|
|
|
Item carrier = item.carriedBy;
|
|
|
|
carrier.Drops();
|
|
|
|
int itemX = item.x;
|
|
|
|
int itemY = item.y;
|
|
|
|
level.items.removeElement(item);
|
|
|
|
newItem.x = itemX;
|
|
|
|
newItem.y = itemY;
|
|
|
|
newItem.room = carrier.room;
|
|
|
|
level.items.addElement(newItem);
|
|
|
|
carrier.PicksUp(newItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equals(Material mat) {
|
|
|
|
if (super.equals(mat)) {
|
|
|
|
if (target == ((ShapeEditor) mat).target) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-02 18:39:08 -03:00
|
|
|
|
|
|
|
}
|
|
|
|
|