From 2d0986904447b289daaa970fcdab919149b344cb Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 16 Feb 2017 17:25:13 -0500 Subject: [PATCH] v0.5.0b: completely refactored custom tiled visuals --- .../main/java/com/watabou/noosa/Tilemap.java | 7 +- .../main/assets/custom_tiles/prison_exit.png | Bin 1924 -> 3002 bytes .../assets/custom_tiles/prison_quests.png | Bin 1608 -> 1583 bytes .../shatteredpixeldungeon/levels/Level.java | 6 +- .../levels/PrisonBossLevel.java | 39 ++++-- .../levels/painters/MassGravePainter.java | 48 +++++-- .../levels/painters/RitualSitePainter.java | 26 ++-- .../levels/painters/WeakFloorPainter.java | 29 ++-- .../scenes/GameScene.java | 8 +- .../tiles/CustomTiledVisual.java | 131 ++++++++++++++++++ .../ui/CustomTileVisual.java | 124 ----------------- .../windows/WndInfoCell.java | 34 +++-- 12 files changed, 268 insertions(+), 184 deletions(-) create mode 100644 core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/CustomTiledVisual.java delete mode 100644 core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Tilemap.java b/SPD-classes/src/main/java/com/watabou/noosa/Tilemap.java index ad4fd1b76..21a7c4037 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Tilemap.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Tilemap.java @@ -202,8 +202,9 @@ public class Tilemap extends Visual { } Camera c = Camera.main; - camX = (int)c.scroll.x/16; - camY = (int)c.scroll.y/16; + //we treat the position of the tilemap as (0,0) here + camX = (int)(c.scroll.x/cellW - x/cellW); + camY = (int)(c.scroll.y/cellH - y/cellH); camW = (int)Math.ceil(c.width/cellW); camH = (int)Math.ceil(c.height/cellH); @@ -221,7 +222,7 @@ public class Tilemap extends Visual { bottomRight = Math.min(camX+camW, mapWidth-1) + Math.min((camY+camH)*mapWidth, (mapHeight-1)*mapWidth); - if (topLeft >= size || bottomRight <= 0) + if (topLeft >= size || bottomRight < 0) length = 0; else length = bottomRight - topLeft + 1; diff --git a/core/src/main/assets/custom_tiles/prison_exit.png b/core/src/main/assets/custom_tiles/prison_exit.png index bce4a8700778ccc9fac952eafbbb551c257a8eac..85edb73957b8aa9761460440b8250cc1b7c23cba 100644 GIT binary patch delta 2761 zcmY+GX;f3!8ivnFz`(+q*h+&|N$PMxYY8}lKym^^2}p>5G6w<*L?8qrNJ!u$6qSlX z)LM!nAf;--B?uxYgQ--bf(ms2Aq=7>%9Joh2+6tF_TJmOf9&PuIiVwC%>=#^;Gqx zTyAVo;pz12WhYAWC2^bph`hxG+D3DAfGAtyIgx>WK1?r9it~=Nlt?ONYaGX4kivGQ zZcm8aAH2_Z55o&0J947~++4PEqx^X>fg!NJpRYHAN^wezkBSIk&|K{kq63l+2K(*t zc7dE(f&2IgG5omDoo){NxRA(D@5Gou4|nIiK1^3CIV{Nk5RVfP%-BWS!HMuq=CWum zlb>04cko0Kn9U?nd=X1>Z_*!QX9h zMvt4#H&2CK2^?3=EnT_4riFB$b53=jH)ZwRX$$#Y`^yQIX}c8e>&;=2!x|J1qggag z0As#g_WEUX<80W(e9+>iHG~t%#GUyR41}F$zh9+x&9*DENLqjEM<3XGOf~eV)FKNN zbGv?QY|L_#zHUnu3;(KXme#p-Luti^GZ)xF+pe$doOJ5fI#W#Mfjl)^Q!sMZn&H0k z7tW8-fv1##x!b*RHp(Nazo{s@cBYJ8eslEpO+q(e@v5PMk^3Ch%jNO9#1U2UnBx)s z4o)%tOs~F?(2O);RV!h@$mGcpF@>>optvX17O)UYfS*1b?77*?4LfuK+RsfV%X0BX)F0elV`qPPP=2-i+@*)rm#jC1U;gS6C*acfQO>K} zH(l3Mw{leu{emUoDh$oyYu_G8@wI>hcODoOd(6p?SEQ9iwYj zcXMOFhQt*rPC;jUk&@G|eWR%CG)TktnI^SB%i1oO-|(q?w_NyeM#`qQT96}t%Cqf- zr-SdN%?!TM3I^j@=5~#XB$EAOMrGB7k3R!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^~l%=S{dUrOrQ(K7SdjPTbB!3V+@C1w=AmV-n zkkJe1dO)datFD{yQ#5r`DV6O3q~0_1-h&`{fbiRcJ$V5=4_GTA7iTA{c6hjcdSdfE zKrDJsxc-B!2k1Ar*kI2CrKm|gyu6y&iENE#=l|k?w*Mr$9st>H^gUqCO<7NMJRuqV z-yUGs1Ap7G1I-A6Ab$wM5^{kBoIe16KmfS+f4FRi)pbF@G{PKEmQ%oVeg1t9tndNJ z{r~$ONFTr%A0YSt2k8NPrXMim0}}iHknjTE!w+!E2c-A^{iQtsD_?$qb3PFJ|ICyZ zRHkzK!JrSs{y(!EUzM?P`@y6SNZtdS@Bf*}djMyBz7kb&+v+! z!w;4hi2YB$|J)AxJ|O&Hd4b;l+8!X-UZCv(POQ$7$LAQ1TuXy+jx zcncp;iJ$uX{jt12?f>+F+r#)(e*V6^!0JET1$Kd5U>Dd0c7a{s-xc@,Blob> blobs; public SparseArray plants; public SparseArray traps; - public HashSet customTiles; + public HashSet customTiles; protected ArrayList itemsToSpawn = new ArrayList<>(); @@ -361,7 +361,7 @@ public abstract class Level implements Bundlable { collection = bundle.getCollection( CUSTOM_TILES ); for (Bundlable p : collection) { - CustomTileVisual vis = (CustomTileVisual)p; + CustomTiledVisual vis = (CustomTiledVisual)p; customTiles.add( vis ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java index dacab602f..8c3a3452e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java @@ -38,7 +38,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.plants.Plant; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; -import com.shatteredpixel.shatteredpixeldungeon.ui.CustomTileVisual; +import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual; import com.shatteredpixel.shatteredpixeldungeon.ui.HealthIndicator; import com.watabou.noosa.Group; import com.watabou.noosa.audio.Sample; @@ -340,7 +340,7 @@ public class PrisonBossLevel extends Level { case FIGHT_ARENA: unseal(); - CustomTileVisual vis = new exitVisual(); + CustomTiledVisual vis = new exitVisual(); vis.pos(11, 8); customTiles.add(vis); ((GameScene)ShatteredPixelDungeon.scene()).addCustomTile(vis); @@ -526,15 +526,36 @@ public class PrisonBossLevel extends Level { W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W}; - public static class exitVisual extends CustomTileVisual{ + public static class exitVisual extends CustomTiledVisual { - { - name = "prison exit"; + private static short[] render = new short[]{ + 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; - tx = Assets.PRISON_EXIT; - txX = txY = 0; + public exitVisual() { + super(Assets.PRISON_EXIT); + } + + @Override + public CustomTiledVisual create() { tileW = 12; tileH = 15; + mapSimpleImage(0, 0); + return super.create(); } //for compatibility with pre-0.4.3 saves @@ -545,8 +566,8 @@ public class PrisonBossLevel extends Level { } @Override - public String desc() { - return super.desc(); + protected boolean needsRender(int pos) { + return render[pos] != 0; } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MassGravePainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MassGravePainter.java index 8f6462026..288dc6d6e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MassGravePainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MassGravePainter.java @@ -32,7 +32,8 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; -import com.shatteredpixel.shatteredpixeldungeon.ui.CustomTileVisual; +import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual; +import com.watabou.noosa.Image; import com.watabou.utils.Random; import java.util.ArrayList; @@ -48,7 +49,10 @@ public class MassGravePainter extends Painter { fill(level, room, Terrain.WALL); fill(level, room, 1, Terrain.EMPTY_SP); - level.customTiles.addAll(Bones.CustomTilesForRoom(room, Bones.class)); + Bones b = new Bones(); + + b.setRect(room.left+1, room.top, room.width()-1, room.height()); + level.customTiles.add(b); //50% 1 skeleton, 50% 2 skeletons for (int i = 0; i <= Random.Int(2); i++){ @@ -82,22 +86,40 @@ public class MassGravePainter extends Painter { } } - public static class Bones extends CustomTileVisual { - { - name = Messages.get(this, "name"); + public static class Bones extends CustomTiledVisual { - tx = Assets.PRISON_QUEST; - txX = 3; - txY = 0; + private static final int WALL_OVERLAP = 3; + private static final int FLOOR = 7; + + public Bones(){ + super(Assets.PRISON_QUEST); } @Override - public String desc() { - if (ofsX == 1 && ofsY == 1) { - return Messages.get(this, "desc"); - } else { - return null; + public CustomTiledVisual create() { + int data[] = new int[tileW*tileH]; + for (int i = 0; i < data.length; i++){ + if (i < tileW) data[i] = WALL_OVERLAP; + else data[i] = FLOOR; } + map( data, tileW ); + return super.create(); + } + + @Override + public Image image(int tileX, int tileY) { + if (tileY == 0) return null; + else return super.image(tileX, tileY); + } + + @Override + public String name(int tileX, int tileY) { + return Messages.get(this, "name"); + } + + @Override + public String desc(int tileX, int tileY) { + return Messages.get(this, "desc"); } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RitualSitePainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RitualSitePainter.java index 6e359f8b0..d6011563e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RitualSitePainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RitualSitePainter.java @@ -26,7 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; -import com.shatteredpixel.shatteredpixeldungeon.ui.CustomTileVisual; +import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual; import com.watabou.utils.Point; public class RitualSitePainter extends Painter { @@ -56,18 +56,26 @@ public class RitualSitePainter extends Painter { CeremonialCandle.ritualPos = c.x + (level.width() * c.y); } - public static class RitualMarker extends CustomTileVisual{ + public static class RitualMarker extends CustomTiledVisual { - { - name = Messages.get(this, "name"); - - tx = Assets.PRISON_QUEST; - txX = txY = 0; - tileW = tileH = 3; + public RitualMarker(){ + super( Assets.PRISON_QUEST ); } @Override - public String desc() { + public CustomTiledVisual create() { + tileH = tileW = 3; + mapSimpleImage(0, 0); + return super.create(); + } + + @Override + public String name(int tileX, int tileY) { + return Messages.get(this, "name"); + } + + @Override + public String desc(int tileX, int tileY) { return Messages.get(this, "desc"); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/WeakFloorPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/WeakFloorPainter.java index 1c6392f71..610d1ae0b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/WeakFloorPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/WeakFloorPainter.java @@ -26,7 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; -import com.shatteredpixel.shatteredpixeldungeon.ui.CustomTileVisual; +import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual; import com.watabou.utils.Point; import com.watabou.utils.Random; @@ -69,24 +69,33 @@ public class WeakFloorPainter extends Painter { well = new Point( Random.Int( 2 ) == 0 ? room.left + 1 : room.right - 1, room.top+2 ); } set(level, well, Terrain.CHASM); - CustomTileVisual vis = new HiddenWell(); + CustomTiledVisual vis = new HiddenWell(); vis.pos(well.x, well.y); level.customTiles.add(vis); } - public static class HiddenWell extends CustomTileVisual{ + public static class HiddenWell extends CustomTiledVisual { - { - name = Messages.get(this, "name"); - - tx = Assets.WEAK_FLOOR; - txX = Dungeon.depth/5; - txY = 0; + public HiddenWell(){ + super(Assets.WEAK_FLOOR); } @Override - public String desc() { + public CustomTiledVisual create() { + tileW = tileH = 1; + map( new int[]{Dungeon.depth/5}, 1); + return super.create(); + } + + @Override + public String name(int tileX, int tileY) { + return Messages.get(this, "name"); + } + + @Override + public String desc(int tileX, int tileY) { return Messages.get(this, "desc"); } + } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 09fd0e296..140958074 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -25,6 +25,7 @@ import android.opengl.GLES20; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual; import com.shatteredpixel.shatteredpixeldungeon.tiles.GridTileMap; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap; @@ -65,7 +66,6 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.ActionIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.Banner; import com.shatteredpixel.shatteredpixeldungeon.ui.BusyIndicator; -import com.shatteredpixel.shatteredpixeldungeon.ui.CustomTileVisual; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonWallsTilemap; import com.shatteredpixel.shatteredpixeldungeon.ui.GameLog; import com.shatteredpixel.shatteredpixeldungeon.ui.HealthIndicator; @@ -200,8 +200,8 @@ public class GameScene extends PixelScene { customTiles = new Group(); terrain.add(customTiles); - for( CustomTileVisual visual : Dungeon.level.customTiles){ - addCustomTile(visual.create()); + for( CustomTiledVisual visual : Dungeon.level.customTiles){ + addCustomTile(visual); } visualGrid = new GridTileMap(); @@ -535,7 +535,7 @@ public class GameScene extends PixelScene { } } - public void addCustomTile( CustomTileVisual visual){ + public void addCustomTile( CustomTiledVisual visual){ customTiles.add( visual.create() ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/CustomTiledVisual.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/CustomTiledVisual.java new file mode 100644 index 000000000..a4e27b452 --- /dev/null +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/tiles/CustomTiledVisual.java @@ -0,0 +1,131 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 Oleg Dolya + * + * Shattered Pixel Dungeon + * Copyright (C) 2014-2016 Evan Debenham + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ +package com.shatteredpixel.shatteredpixeldungeon.tiles; + +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.watabou.noosa.Image; +import com.watabou.noosa.TextureFilm; +import com.watabou.noosa.Tilemap; +import com.watabou.utils.Bundlable; +import com.watabou.utils.Bundle; + +public abstract class CustomTiledVisual extends Tilemap implements Bundlable { + + protected static final int SIZE = DungeonTilemap.SIZE; + + public int tileX, tileY; //x and y coords for texture within a level + public int tileW = 1, tileH = 1; //width and height in tiles + + public CustomTiledVisual(Object tx) { + super(tx, new TextureFilm( tx, SIZE, SIZE ) ); + } + + public void pos(int pos) { + pos( pos%Dungeon.level.width(), pos/Dungeon.level.width() ); + } + + public void pos(int tileX, int tileY){ + this.tileX = tileX; + this.tileY = tileY; + } + + public void setRect(int topLeft, int bottomRight){ + setRect( topLeft%Dungeon.level.width(), + topLeft/Dungeon.level.width(), + bottomRight%Dungeon.level.width() - topLeft%Dungeon.level.width(), + bottomRight/Dungeon.level.width() - topLeft/Dungeon.level.width() + ); + } + + public void setRect(int tileX, int tileY, int tileW, int tileH){ + this.tileX = tileX; + this.tileY = tileY; + this.tileW = tileW; + this.tileH = tileH; + } + + public CustomTiledVisual create(){ + x = tileX*SIZE; + y = tileY*SIZE; + return this; + } + + //assumes that width and height are already set. + protected void mapSimpleImage(int txX, int txY){ + int data[] = new int[tileW * tileH]; + int texTileWidth = texture.width/SIZE; + int x = txX, y = txY; + for (int i = 0; i < data.length; i++){ + data[i] = x + (texTileWidth*y); + + x++; + if ((x - txX) == tileW){ + x = txX; + y++; + } + } + + map(data, tileW); + } + + //x and y here are the coordinates tapped within the tile visual + public Image image(int tileX, int tileY){ + if (!needsRender(tileX + mapWidth*tileY)){ + return null; + } else { + Image img = new Image(texture); + img.frame(tileset.get(data[tileX + mapWidth * tileY])); + return img; + } + } + + public String name(int tileX, int tileY){ + return null; + } + + public String desc(int tileX, int tileY){ + return null; + } + + private static final String TILE_X = "tileX"; + private static final String TILE_Y = "tileY"; + + private static final String TILE_W = "tileW"; + private static final String TILE_H = "tileH"; + + @Override + public void restoreFromBundle(Bundle bundle) { + tileX = bundle.getInt(TILE_X); + tileY = bundle.getInt(TILE_Y); + + tileW = bundle.getInt(TILE_W); + tileH = bundle.getInt(TILE_H); + } + + @Override + public void storeInBundle(Bundle bundle) { + bundle.put(TILE_X, tileX); + bundle.put(TILE_Y, tileY); + + bundle.put(TILE_W, tileW); + bundle.put(TILE_H, tileH); + } +} diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java deleted file mode 100644 index e72b852f9..000000000 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Pixel Dungeon - * Copyright (C) 2012-2015 Oleg Dolya - * - * Shattered Pixel Dungeon - * Copyright (C) 2014-2016 Evan Debenham - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see - */ -package com.shatteredpixel.shatteredpixeldungeon.ui; - -import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -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; - -import java.util.ArrayList; - -public abstract class CustomTileVisual extends Image implements Bundlable { - - protected static final int TILE_SIZE = 16; - - public String name; - - 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) - protected int ofsX = 0, ofsY = 0; - - public int tileX, tileY; //x and y coords for texture within a level - public int tileW = 1, tileH = 1; //width and height in tiles - - public void pos(int pos) { - pos( pos% Dungeon.level.width(), pos/Dungeon.level.width() ); - } - - public void pos(int tileX, int tileY){ - this.tileX = tileX; - this.tileY = tileY; - } - - public String desc(){ - return null; - } - - public CustomTileVisual create() { - texture(tx); - 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; - - return this; - } - - //returns a number of 1x1 tiles to fill a room, based on a 3x3 texture, not dissimilar to a ninepatch. - 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 (Exception 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); - } - } -} diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoCell.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoCell.java index b7940a041..e389b9bb3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoCell.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoCell.java @@ -21,13 +21,13 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTiledVisual; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; -import com.shatteredpixel.shatteredpixeldungeon.ui.CustomTileVisual; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline; import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.watabou.noosa.Image; @@ -49,14 +49,17 @@ public class WndInfoCell extends Window { tile = Terrain.CHASM; } - CustomTileVisual vis = null; + CustomTiledVisual customTile = null; + Image customImage = null; int x = cell % Dungeon.level.width(); int y = cell / Dungeon.level.width(); - for (CustomTileVisual i : Dungeon.level.customTiles){ + for (CustomTiledVisual i : Dungeon.level.customTiles){ if ((x >= i.tileX && x < i.tileX+i.tileW) && (y >= i.tileY && y < i.tileY+i.tileH)){ - if (i.desc() != null) { - vis = i; + if ((customImage = i.image(x - i.tileX, y - i.tileY)) != null) { + x -= i.tileX; + y -= i.tileY; + customTile = i; break; } } @@ -66,10 +69,23 @@ public class WndInfoCell extends Window { String desc = ""; IconTitle titlebar = new IconTitle(); - if (vis != null){ - titlebar.icon(new Image(vis)); - titlebar.label(vis.name); - desc += vis.desc(); + if (customTile != null){ + titlebar.icon(customImage); + + String customName = customTile.name(x, y); + if (customName != null) { + titlebar.label(customName); + } else { + titlebar.label(Dungeon.level.tileName(tile)); + } + + String customDesc = customTile.desc(x, y); + if (customDesc != null) { + desc += customDesc; + } else { + desc += Dungeon.level.tileDesc(tile); + } + } else { if (tile == Terrain.WATER) {