package NET.worlds.scape; import java.awt.Color; import java.io.IOException; public class BuildRamp extends SwitchableBehavior implements FrameHandler, Persister { protected boolean doBuild = false; protected boolean built = false; protected WrRamp ramp = null; protected String stairName = "ramp"; protected float length = 1000.0F; protected float width = 300.0F; protected float pWidth = 250.0F; protected float pHeight = 240.0F; protected float dz = 300.0F; protected float lintelZ = 50.0F; protected float floorTileX = 300.0F; protected float floorTileY = 200.0F; protected float ceilTileX = 300.0F; protected float ceilTileY = 200.0F; protected float leftTileX = 100.0F; protected float leftTileY = 100.0F; protected float rightTileX = 100.0F; protected float rightTileY = 100.0F; protected Material floor = new Material(Color.green); protected Material left = new Material(Color.cyan); protected Material right = new Material(Color.red); protected Material doorpost = new Material(Color.yellow); protected Material lintel = new Material(Color.magenta); protected Material ceiling = new Material(Color.blue); protected String worldURL = null; protected void build(Portal end1) { Room room = end1.getRoom(); World world = room.getWorld(); this.ramp = new WrRamp( world, this.stairName, this.length, this.width, this.pWidth, this.pHeight, this.dz, this.lintelZ, this.floorTileX, this.floorTileY, this.ceilTileX, this.ceilTileY, this.leftTileX, this.leftTileY, this.rightTileX, this.rightTileY, this.floor, this.left, this.right, this.doorpost, this.lintel, this.ceiling ); end1.biconnect(this.ramp.portal1); this.built = true; end1.removeHandler(this); } protected void unbuild(Portal end1) { this.built = false; } @Override public boolean handle(FrameEvent e) { if (!this.built && this.doBuild && e.target instanceof Portal) { this.build((Portal)e.target); } else if (this.built && !this.doBuild && e.target instanceof Portal) { this.unbuild((Portal)e.target); } return true; } @Override public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException { Object ret = null; switch (index - offset) { case 0: if (mode == 0) { ret = new ClassProperty(this, index, "BuildRamp"); } break; case 1: if (mode == 0) { ret = BooleanPropertyEditor.make(new Property(this, index, "Build now?"), "Later", "Now"); } else if (mode == 1) { ret = new Boolean(this.doBuild); } else if (mode == 2) { this.doBuild = (Boolean)value; } break; case 2: if (mode == 0) { ret = StringPropertyEditor.make(new Property(this, index, "Staircase Name")); } else if (mode == 1) { ret = this.stairName; } else if (mode == 2) { this.stairName = (String)value; } break; case 3: if (mode == 0) { ret = FloatPropertyEditor.make(new Property(this, index, "Portal-to-portal Distance")); } else if (mode == 1) { ret = new Float(this.length); } else if (mode == 2) { this.length = (Float)value; } break; case 4: if (mode == 0) { ret = FloatPropertyEditor.make(new Property(this, index, "Stairwell Width")); } else if (mode == 1) { ret = new Float(this.width); } else if (mode == 2) { this.width = (Float)value; } break; case 5: if (mode == 0) { ret = FloatPropertyEditor.make(new Property(this, index, "Portal Width")); } else if (mode == 1) { ret = new Float(this.pWidth); } else if (mode == 2) { this.pWidth = (Float)value; } break; case 6: if (mode == 0) { ret = FloatPropertyEditor.make(new Property(this, index, "Portal Height")); } else if (mode == 1) { ret = new Float(this.pHeight); } else if (mode == 2) { this.pHeight = (Float)value; } break; case 7: if (mode == 0) { ret = FloatPropertyEditor.make(new Property(this, index, "Total Rise")); } else if (mode == 1) { ret = new Float(this.dz); } else if (mode == 2) { this.dz = (Float)value; } break; case 8: if (mode == 0) { ret = FloatPropertyEditor.make(new Property(this, index, "Lintel Height")); } else if (mode == 1) { ret = new Float(this.lintelZ); } else if (mode == 2) { this.lintelZ = (Float)value; } break; case 9: if (mode == 0) { ret = Point2PropertyEditor.make(new Property(this, index, "Floor Tile Size")); } else if (mode == 1) { Point2 coords = new Point2(); coords.x = this.floorTileX; coords.y = this.floorTileY; ret = coords; } else if (mode == 2) { this.floorTileX = ((Point2)value).x; this.floorTileY = ((Point2)value).y; } break; case 10: if (mode == 0) { ret = Point2PropertyEditor.make(new Property(this, index, "Ceiling Tile Size")); } else if (mode == 1) { Point2 coords = new Point2(); coords.x = this.ceilTileX; coords.y = this.ceilTileY; ret = coords; } else if (mode == 2) { this.ceilTileX = ((Point2)value).x; this.ceilTileY = ((Point2)value).y; } break; case 11: if (mode == 0) { ret = Point2PropertyEditor.make(new Property(this, index, "Left Wall Tile Size")); } else if (mode == 1) { Point2 coords = new Point2(); coords.x = this.leftTileX; coords.y = this.leftTileY; ret = coords; } else if (mode == 2) { this.leftTileX = ((Point2)value).x; this.leftTileY = ((Point2)value).y; } break; case 12: if (mode == 0) { ret = Point2PropertyEditor.make(new Property(this, index, "Right Wall Tile Size")); } else if (mode == 1) { Point2 coords = new Point2(); coords.x = this.rightTileX; coords.y = this.rightTileY; ret = coords; } else if (mode == 2) { this.rightTileX = ((Point2)value).x; this.rightTileY = ((Point2)value).y; } break; case 13: if (mode == 0) { ret = new Property(this, index, "Floor Material"); } else if (mode == 1) { ret = this.floor; } break; case 14: if (mode == 0) { ret = new Property(this, index, "Left Wall Material"); } else if (mode == 1) { ret = this.left; } break; case 15: if (mode == 0) { ret = new Property(this, index, "Right Wall Material"); } else if (mode == 1) { ret = this.right; } break; case 16: if (mode == 0) { ret = new Property(this, index, "Doorpost Material"); } else if (mode == 1) { ret = this.doorpost; } break; case 17: if (mode == 0) { ret = new Property(this, index, "Lintel Material"); } else if (mode == 1) { ret = this.lintel; } break; case 18: if (mode == 0) { ret = new Property(this, index, "Ceiling Material"); } else if (mode == 1) { ret = this.ceiling; } break; default: ret = super.properties(index, offset + 19, mode, value); } return ret; } @Override public String toString() { return "Ramp: built=" + this.built; } @Override public void saveState(Saver s) throws IOException { s.saveBoolean(this.built); s.saveString(this.stairName); s.saveFloat(this.length); s.saveFloat(this.width); s.saveFloat(this.pWidth); s.saveFloat(this.pHeight); s.saveFloat(this.dz); s.saveFloat(this.lintelZ); s.saveFloat(this.floorTileX); s.saveFloat(this.floorTileY); s.saveFloat(this.ceilTileX); s.saveFloat(this.ceilTileY); s.saveFloat(this.leftTileX); s.saveFloat(this.leftTileY); s.saveFloat(this.rightTileX); s.saveFloat(this.rightTileY); } @Override public void restoreState(Restorer r) throws IOException { this.built = r.restoreBoolean(); this.stairName = r.restoreString(); this.length = r.restoreFloat(); this.width = r.restoreFloat(); this.pWidth = r.restoreFloat(); this.pHeight = r.restoreFloat(); this.dz = r.restoreFloat(); this.lintelZ = r.restoreFloat(); this.floorTileX = r.restoreFloat(); this.floorTileY = r.restoreFloat(); this.ceilTileX = r.restoreFloat(); this.ceilTileY = r.restoreFloat(); this.leftTileX = r.restoreFloat(); this.leftTileY = r.restoreFloat(); this.rightTileX = r.restoreFloat(); this.rightTileY = r.restoreFloat(); } @Override public void postRestore(int version) { } }