v0.3.1d: added support for visuals layered over tiles
This commit is contained in:
parent
5cff3a6191
commit
44f8e32beb
|
@ -71,6 +71,7 @@ import com.shatteredpixel.shatteredpixeldungeon.mechanics.ShadowCaster;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.plants.BlandfruitBush;
|
import com.shatteredpixel.shatteredpixeldungeon.plants.BlandfruitBush;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.CustomTileVisual;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
|
@ -158,6 +159,7 @@ public abstract class Level implements Bundlable {
|
||||||
public HashMap<Class<? extends Blob>,Blob> blobs;
|
public HashMap<Class<? extends Blob>,Blob> blobs;
|
||||||
public SparseArray<Plant> plants;
|
public SparseArray<Plant> plants;
|
||||||
public SparseArray<Trap> traps;
|
public SparseArray<Trap> traps;
|
||||||
|
public HashSet<CustomTileVisual> customTiles;
|
||||||
|
|
||||||
protected ArrayList<Item> itemsToSpawn = new ArrayList<>();
|
protected ArrayList<Item> itemsToSpawn = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -177,6 +179,7 @@ public abstract class Level implements Bundlable {
|
||||||
private static final String HEAPS = "heaps";
|
private static final String HEAPS = "heaps";
|
||||||
private static final String PLANTS = "plants";
|
private static final String PLANTS = "plants";
|
||||||
private static final String TRAPS = "traps";
|
private static final String TRAPS = "traps";
|
||||||
|
private static final String CUSTOM_TILES= "customTiles";
|
||||||
private static final String MOBS = "mobs";
|
private static final String MOBS = "mobs";
|
||||||
private static final String BLOBS = "blobs";
|
private static final String BLOBS = "blobs";
|
||||||
private static final String FEELING = "feeling";
|
private static final String FEELING = "feeling";
|
||||||
|
@ -266,6 +269,7 @@ public abstract class Level implements Bundlable {
|
||||||
blobs = new HashMap<>();
|
blobs = new HashMap<>();
|
||||||
plants = new SparseArray<>();
|
plants = new SparseArray<>();
|
||||||
traps = new SparseArray<>();
|
traps = new SparseArray<>();
|
||||||
|
customTiles = new HashSet<>();
|
||||||
|
|
||||||
} while (!build());
|
} while (!build());
|
||||||
decorate();
|
decorate();
|
||||||
|
@ -297,6 +301,7 @@ public abstract class Level implements Bundlable {
|
||||||
blobs = new HashMap<>();
|
blobs = new HashMap<>();
|
||||||
plants = new SparseArray<>();
|
plants = new SparseArray<>();
|
||||||
traps = new SparseArray<>();
|
traps = new SparseArray<>();
|
||||||
|
customTiles = new HashSet<>();
|
||||||
|
|
||||||
map = bundle.getIntArray( MAP );
|
map = bundle.getIntArray( MAP );
|
||||||
|
|
||||||
|
@ -345,6 +350,15 @@ public abstract class Level implements Bundlable {
|
||||||
traps.put( trap.pos, trap );
|
traps.put( trap.pos, trap );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collection = bundle.getCollection( CUSTOM_TILES );
|
||||||
|
for (Bundlable p : collection) {
|
||||||
|
CustomTileVisual vis = (CustomTileVisual)p;
|
||||||
|
if (resizingNeeded) {
|
||||||
|
//TODO: add proper resizing logic here
|
||||||
|
}
|
||||||
|
customTiles.add( vis );
|
||||||
|
}
|
||||||
|
|
||||||
//for pre-0.3.1 saves
|
//for pre-0.3.1 saves
|
||||||
if (version < 52){
|
if (version < 52){
|
||||||
for (int i=0; i < map.length; i++){
|
for (int i=0; i < map.length; i++){
|
||||||
|
@ -394,6 +408,7 @@ public abstract class Level implements Bundlable {
|
||||||
bundle.put( HEAPS, heaps.values() );
|
bundle.put( HEAPS, heaps.values() );
|
||||||
bundle.put( PLANTS, plants.values() );
|
bundle.put( PLANTS, plants.values() );
|
||||||
bundle.put( TRAPS, traps.values() );
|
bundle.put( TRAPS, traps.values() );
|
||||||
|
bundle.put( CUSTOM_TILES, customTiles );
|
||||||
bundle.put( MOBS, mobs );
|
bundle.put( MOBS, mobs );
|
||||||
bundle.put( BLOBS, blobs.values() );
|
bundle.put( BLOBS, blobs.values() );
|
||||||
bundle.put( FEELING, feeling );
|
bundle.put( FEELING, feeling );
|
||||||
|
|
|
@ -32,6 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.bags.WandHolster;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation;
|
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.CustomTileVisual;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.LootIndicator;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.LootIndicator;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.ResumeIndicator;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.ResumeIndicator;
|
||||||
|
@ -116,6 +117,7 @@ public class GameScene extends PixelScene {
|
||||||
private static CellSelector cellSelector;
|
private static CellSelector cellSelector;
|
||||||
|
|
||||||
private Group terrain;
|
private Group terrain;
|
||||||
|
private Group customTiles;
|
||||||
private Group ripples;
|
private Group ripples;
|
||||||
private Group plants;
|
private Group plants;
|
||||||
private Group traps;
|
private Group traps;
|
||||||
|
@ -163,8 +165,15 @@ public class GameScene extends PixelScene {
|
||||||
tiles = new DungeonTilemap();
|
tiles = new DungeonTilemap();
|
||||||
terrain.add( tiles );
|
terrain.add( tiles );
|
||||||
|
|
||||||
|
customTiles = new Group();
|
||||||
|
terrain.add(customTiles);
|
||||||
|
|
||||||
Dungeon.level.addVisuals(this);
|
Dungeon.level.addVisuals(this);
|
||||||
|
|
||||||
|
for( CustomTileVisual visual : Dungeon.level.customTiles){
|
||||||
|
addCustomTile(visual.create());
|
||||||
|
}
|
||||||
|
|
||||||
traps = new Group();
|
traps = new Group();
|
||||||
add(traps);
|
add(traps);
|
||||||
|
|
||||||
|
@ -472,6 +481,10 @@ public class GameScene extends PixelScene {
|
||||||
fog.aa = 0f - shift;
|
fog.aa = 0f - shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addCustomTile( CustomTileVisual visual){
|
||||||
|
customTiles.add( visual.create() );
|
||||||
|
}
|
||||||
|
|
||||||
private void addHeapSprite( Heap heap ) {
|
private void addHeapSprite( Heap heap ) {
|
||||||
ItemSprite sprite = heap.sprite = (ItemSprite)heaps.recycle( ItemSprite.class );
|
ItemSprite sprite = heap.sprite = (ItemSprite)heaps.recycle( ItemSprite.class );
|
||||||
sprite.revive();
|
sprite.revive();
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* Pixel Dungeon
|
||||||
|
* Copyright (C) 2012-2015 Oleg Dolya
|
||||||
|
*
|
||||||
|
* Shattered Pixel Dungeon
|
||||||
|
* Copyright (C) 2014-2015 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 <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
package com.shatteredpixel.shatteredpixeldungeon.sprites;
|
||||||
|
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||||
|
import com.watabou.noosa.Image;
|
||||||
|
import com.watabou.utils.Bundlable;
|
||||||
|
import com.watabou.utils.Bundle;
|
||||||
|
|
||||||
|
public class CustomTileVisual extends Image implements Bundlable {
|
||||||
|
|
||||||
|
private static final int TILE_SIZE = 16;
|
||||||
|
|
||||||
|
private String tx;
|
||||||
|
private int txX, txY;
|
||||||
|
|
||||||
|
private int tileX, tileY, tileW, tileH;
|
||||||
|
|
||||||
|
public CustomTileVisual(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomTileVisual(String tx, int txX, int txY, int tileW, int tileH){
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.tx = tx;
|
||||||
|
this.txX = txX;
|
||||||
|
this.txY = txY;
|
||||||
|
|
||||||
|
this.tileW = tileW;
|
||||||
|
this.tileH = tileH;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pos(int pos) {
|
||||||
|
pos( pos%Level.WIDTH, pos/Level.WIDTH );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pos(int tileX, int tileY){
|
||||||
|
this.tileX = tileX;
|
||||||
|
this.tileY = tileY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomTileVisual create() {
|
||||||
|
texture(tx);
|
||||||
|
frame(texture.uvRect(txX * TILE_SIZE, txY * TILE_SIZE, (txX + tileW) * TILE_SIZE, (txY + tileH) * TILE_SIZE));
|
||||||
|
|
||||||
|
x = tileX*TILE_SIZE;
|
||||||
|
y = tileY*TILE_SIZE;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String TX = "tx";
|
||||||
|
private static final String TX_X= "txX";
|
||||||
|
private static final String TX_Y= "txY";
|
||||||
|
|
||||||
|
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) {
|
||||||
|
tx = bundle.getString(TX);
|
||||||
|
txX = bundle.getInt(TX_X);
|
||||||
|
txY = bundle.getInt(TX_Y);
|
||||||
|
|
||||||
|
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(TX, tx);
|
||||||
|
bundle.put(TX_X, txX);
|
||||||
|
bundle.put(TX_Y, txY);
|
||||||
|
|
||||||
|
bundle.put(TILE_X, tileX);
|
||||||
|
bundle.put(TILE_Y, tileY);
|
||||||
|
bundle.put(TILE_W, tileW);
|
||||||
|
bundle.put(TILE_H, tileH);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user