From bcdba04d42ce4591de366db9399437f1952719da Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 5 Oct 2015 22:51:13 -0400 Subject: [PATCH] v0.3.2: expansion to custom tile visuals, no an automated way of making a set of them to fill a room --- .../levels/painters/WeakFloorPainter.java | 2 - .../ui/CustomTileVisual.java | 52 +++++++++++++++++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/painters/WeakFloorPainter.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/painters/WeakFloorPainter.java index c37c53b44..2ab22ba9b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/painters/WeakFloorPainter.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/painters/WeakFloorPainter.java @@ -79,8 +79,6 @@ public class WeakFloorPainter extends Painter { tx = Assets.WEAK_FLOOR; txX = Dungeon.depth/5; txY = 0; - - tileW = tileH = 1; } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java index 906e28ff8..87ce6175c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java @@ -21,19 +21,25 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; +import com.shatteredpixel.shatteredpixeldungeon.levels.Room; import com.watabou.noosa.Image; import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; -public class CustomTileVisual extends Image implements Bundlable { +import java.util.ArrayList; + +public abstract class CustomTileVisual extends Image implements Bundlable { protected static final int TILE_SIZE = 16; protected String tx; //string for resource file protected int txX, txY; //position(in tiles) within resource file + //bundleable offsets from the standard texture xy, useful for mapping larger than 1x1 textures to many tiles + //(e.g. mapping a 3x3 texture to a room, where the corners are walls and the center is the floor) + private int ofsX = 0, ofsY = 0; protected int tileX, tileY; //x and y coords for texture within a level - protected int tileW, tileH; //width and height in tiles + protected int tileW = 1, tileH = 1; //width and height in tiles public void pos(int pos) { pos( pos%Level.WIDTH, pos/Level.WIDTH ); @@ -46,7 +52,8 @@ public class CustomTileVisual extends Image implements Bundlable { public CustomTileVisual create() { texture(tx); - frame(texture.uvRect(txX * TILE_SIZE, txY * TILE_SIZE, (txX + tileW) * TILE_SIZE, (txY + tileH) * TILE_SIZE)); + frame(texture.uvRect((txX + ofsX) * TILE_SIZE, (txY + ofsY) * TILE_SIZE, + (txX + ofsX + tileW) * TILE_SIZE, (txY + ofsY + tileH) * TILE_SIZE)); x = tileX*TILE_SIZE; y = tileY*TILE_SIZE; @@ -54,18 +61,57 @@ public class CustomTileVisual extends Image implements Bundlable { return this; } + // + public static ArrayList CustomTilesForRoom(Room r, Class c){ + ArrayList result = new ArrayList<>(); + + try { + for (int x = r.left; x <= r.right; x++) { + for (int y = r.top; y <= r.bottom; y++) { + CustomTileVisual vis = c.newInstance(); + + if (x == r.right) vis.ofsX = 2; + else if (x != r.left) vis.ofsX = 1; + + if (y == r.bottom) vis.ofsY = 2; + else if (y != r.top) vis.ofsY = 1; + + vis.pos(x, y); + result.add(vis); + } + } + } catch (InstantiationException | IllegalAccessException e) { + throw new RuntimeException("Something went wrong while making a bunch of tile visuals for a room!", e); + } + + return result; + } + private static final String TILE_X = "tileX"; private static final String TILE_Y = "tileY"; + private static final String OFS_X = "ofsX"; + private static final String OFS_Y = "ofsY"; + @Override public void restoreFromBundle(Bundle bundle) { tileX = bundle.getInt(TILE_X); tileY = bundle.getInt(TILE_Y); + + //if these weren't stored they will default to 0 + ofsX = bundle.getInt(OFS_X); + ofsY = bundle.getInt(OFS_Y); } @Override public void storeInBundle(Bundle bundle) { bundle.put(TILE_X, tileX); bundle.put(TILE_Y, tileY); + + //don't need to store this in all cases + if (ofsX != 0 || ofsY != 0){ + bundle.put(OFS_X, ofsX); + bundle.put(OFS_Y, ofsY); + } } }