(Pixmap preferredIcons)
| 27 | |
| 28 | |
| 29 | public void load(Pixmap preferredIcons) { |
| 30 | FSkinProp.PropType type = skinProp.getType(); |
| 31 | String filename = type.getFilename(); |
| 32 | if (filename == null) { |
| 33 | return; |
| 34 | } |
| 35 | boolean is2D = type == FSkinProp.PropType.ADVENTURE; |
| 36 | FileHandle preferredFile = type == FSkinProp.PropType.MANAICONS ? FSkin.getDefaultSkinFile(filename) : FSkin.getSkinFile(filename); |
| 37 | Texture texture = Forge.getAssets().getTexture(preferredFile, is2D, false); |
| 38 | if (texture == null) { |
| 39 | if (preferredFile.exists()) { |
| 40 | try { |
| 41 | texture = Forge.getAssets().getTexture(preferredFile, is2D, false); |
| 42 | } |
| 43 | catch (final Exception e) { |
| 44 | System.err.println("Failed to load skin file: " + preferredFile); |
| 45 | //e.printStackTrace(); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | if (texture != null) { |
| 50 | if (!(type == FSkinProp.PropType.ABILITY || type == FSkinProp.PropType.IMAGE || type == FSkinProp.PropType.ICON || type == FSkinProp.PropType.MANAICONS)) { //just return region for preferred file if not icons file |
| 51 | textureRegion = new TextureRegion(texture, x, y, w, h); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | int fullWidth = texture.getWidth(); |
| 56 | int fullHeight = texture.getHeight(); |
| 57 | |
| 58 | // Test if requested sub-image in inside bounds of preferred sprite. |
| 59 | // (Height and width of preferred sprite were set in loadFontAndImages.) |
| 60 | if (x + w <= fullWidth && y + h <= fullHeight) { |
| 61 | // Test if various points of requested sub-image are transparent. |
| 62 | // If any return true, image exists. |
| 63 | int x0 = 0, y0 = 0; |
| 64 | Color c; |
| 65 | |
| 66 | // Center |
| 67 | x0 = (x + w / 2); |
| 68 | y0 = (y + h / 2); |
| 69 | c = new Color(preferredIcons.getPixel(x0, y0)); |
| 70 | if (c.a != 0) { |
| 71 | textureRegion = new TextureRegion(texture, x, y, w, h); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | x0 += 2; |
| 76 | y0 += 2; |
| 77 | c = new Color(preferredIcons.getPixel(x0, y0)); |
| 78 | if (c.a != 0) { |
| 79 | textureRegion = new TextureRegion(texture, x, y, w, h); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | x0 -= 4; |
| 84 | c = new Color(preferredIcons.getPixel(x0, y0)); |
| 85 | if (c.a != 0) { |
| 86 | textureRegion = new TextureRegion(texture, x, y, w, h); |
no test coverage detected