package NET.worlds.scape; import NET.worlds.network.URL; import java.io.IOException; import java.util.StringTokenizer; public class WearWall extends Rect { char limb = ' '; String tileList = ""; WObject[] subs; private static Object classCookie = new Object(); WearWall() { } public void rebuild() { this.unbuild(); if (this.limb != ' ') { int count = 0; StringTokenizer st = new StringTokenizer(this.tileList); while (st.hasMoreTokens()) { count++; st.nextToken(); } if (count != 0) { float width = this.getScaleX(); float height = this.getScaleZ(); int wNum = 1; int hNum = 1; while (wNum * hNum < count) { if (height * (wNum + 1) > width * (hNum + 1)) { hNum++; } else { wNum++; } } this.subs = new WObject[count]; float tw = 1.0F / wNum; float th = 1.0F / hNum; float wHalfSide = tw * this.getScaleX(); float hHalfSide = th * this.getScaleZ(); float sideLen = wHalfSide < hHalfSide ? wHalfSide : hHalfSide; wHalfSide = (sideLen - 6.0F) / this.getScaleX() / 2.0F; hHalfSide = (sideLen - 6.0F) / this.getScaleZ() / 2.0F; st = new StringTokenizer(this.tileList); float y = -1.0F / this.getScaleY(); float z = 1.0F - th / 2.0F; int i = 0; for (int row = 0; row < hNum; z -= th) { float x = tw / 2.0F; for (int col = 0; col < wNum; x += tw) { if (!st.hasMoreTokens()) { return; } Material m = null; String s = st.nextToken(); String bodyType = null; label91: { try { char c = s.charAt(0); if (c != 'C' && c != 'T') { String name = PosableShape.readName(s, 0); if (this.limb == 'H') { bodyType = name; } else { if (this.limb != 'E') { break label91; } name = PosableShape.getFace(name); m = PosableShape.readTexture(name, 0); } } else { if (this.limb == 'H' || this.limb == 'E') { break label91; } if (c == 'C') { m = PosableShape.readColor(s, 1); } else { m = PosableShape.readTexture(s, 1); } } } catch (StringIndexOutOfBoundsException var25) { break label91; } if (bodyType != null) { s = PosableShape.getAvURL(bodyType).getAbsolute(); int start; if (s != null && (start = s.indexOf(".0E")) >= 0) { start = PosableShape.skipLimb(s, start + 3); if (start >= 0) { int headIndex = s.lastIndexOf("NS"); if (headIndex >= 0) { PosableShape p = new PosableShape( URL.make(s.substring(0, start) + "PGNG" + PosableShape.getBodyType(bodyType) + "Q" + s.substring(headIndex + 1)), false ); p.scale(750.0F / this.getScaleX(), 750.0F / this.getScaleY(), 750.0F / this.getScaleZ()); p.spin(0.0F, 1.0F, 1.0F, 180.0F); p.spin(0.0F, 1.0F, 0.0F, 180.0F); p.moveTo(x, y * 10.0F, z - hHalfSide / 2.0F); WearAction action = new WearAction(); action.limb = this.limb; action.val = bodyType; p.addAction(action); p.addHandler(new ClickSensor(action, 1)); this.add(p); this.subs[i] = p; } } } } else if (m != null) { m.setAmbient(0.75F); m.setDiffuse(0.0F); Rect r = new Rect(x - wHalfSide, y, z - hHalfSide, x + wHalfSide, y, z + hHalfSide, m); WearAction action = new WearAction(); action.limb = this.limb; action.val = s; r.addAction(action); r.addHandler(new ClickSensor(action, 1)); this.add(r); this.subs[i] = r; } } col++; i++; } row++; } } } } private void unbuild() { if (this.subs != null) { int i = this.subs.length; while (--i >= 0) { if (this.subs[i] != null) { this.subs[i].detach(); } } } this.subs = null; } @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 = StringPropertyEditor.make(new Property(this, index, "Limb")); } else if (mode == 1) { ret = new String("" + this.limb); } else if (mode == 2) { String s = (String)value; if (s.length() >= 1) { this.limb = s.charAt(0); this.rebuild(); } } break; case 1: if (mode == 0) { ret = StringPropertyEditor.make(new Property(this, index, "Tile List")); } else if (mode == 1) { ret = new String(this.tileList); } else if (mode == 2) { this.tileList = (String)value; this.rebuild(); } break; default: ret = super.properties(index, offset + 2, mode, value); } return ret; } @Override public void saveState(Saver s) throws IOException { this.unbuild(); s.saveVersion(2, classCookie); super.saveState(s); this.rebuild(); } @Override public void restoreState(Restorer r) throws IOException, TooNewException { int vers = r.restoreVersion(classCookie); switch (vers) { case 0: super.restoreState(r); r.restoreString(); r.restoreString(); break; case 1: super.restoreState(r); r.restoreString(); break; case 2: super.restoreState(r); break; default: throw new TooNewException(); } this.rebuild(); } }