v2.4.0: cleaned up various allocations that occurred every frame

This commit is contained in:
Evan Debenham
2024-02-05 17:11:48 -05:00
parent 94bf5b88c4
commit 2466974a71
20 changed files with 209 additions and 156 deletions

View File

@@ -62,6 +62,10 @@ public class KeyEvent {
} }
public static synchronized void processKeyEvents(){ public static synchronized void processKeyEvents(){
if (keyEvents.isEmpty()) {
return;
}
for (KeyEvent k : keyEvents){ for (KeyEvent k : keyEvents){
if (KeyBindings.getActionForKey(k) == GameAction.LEFT_CLICK){ if (KeyBindings.getActionForKey(k) == GameAction.LEFT_CLICK){
Game.inputHandler.emulateTouch(ControllerHandler.CONTROLLER_POINTER_ID, PointerEvent.LEFT, k.pressed); Game.inputHandler.emulateTouch(ControllerHandler.CONTROLLER_POINTER_ID, PointerEvent.LEFT, k.pressed);

View File

@@ -136,6 +136,10 @@ public class PointerEvent {
public static boolean clearKeyboardThisPress = true; public static boolean clearKeyboardThisPress = true;
public static synchronized void processPointerEvents(){ public static synchronized void processPointerEvents(){
if (pointerEvents.isEmpty()){
return;
}
//handle any hover events separately first as we may need to add drag events //handle any hover events separately first as we may need to add drag events
boolean hovered = false; boolean hovered = false;
for (PointerEvent p : pointerEvents){ for (PointerEvent p : pointerEvents){

View File

@@ -62,6 +62,10 @@ public class ScrollEvent {
} }
public static synchronized void processScrollEvents(){ public static synchronized void processScrollEvents(){
if (scrollEvents.isEmpty()) {
return;
}
for (ScrollEvent k : scrollEvents){ for (ScrollEvent k : scrollEvents){
scrollSignal.dispatch(k); scrollSignal.dispatch(k);
} }

View File

@@ -178,36 +178,39 @@ public class Camera extends Gizmo {
float deadX = 0; float deadX = 0;
float deadY = 0; float deadY = 0;
if (followTarget != null){ if (followTarget != null){
panTarget = followTarget.center().offset(centerOffset); //manually assign here to avoid an allocation from sprite.center()
panTarget.x = followTarget.x + followTarget.width()/2;
panTarget.y = followTarget.y + followTarget.height()/2;
panTarget.offset(centerOffset);
deadX = width * followDeadzone /2f; deadX = width * followDeadzone /2f;
deadY = height * followDeadzone /2f; deadY = height * followDeadzone /2f;
} }
if (panIntensity > 0f){ if (panIntensity > 0f){
PointF panMove = new PointF(); float panX = panTarget.x - (scroll.x + width/2f);
panMove.x = panTarget.x - (scroll.x + width/2f); float panY = panTarget.y - (scroll.y + height/2f);
panMove.y = panTarget.y - (scroll.y + height/2f);
if (panMove.x > deadX){ if (panX > deadX){
panMove.x -= deadX; panX -= deadX;
} else if (panMove.x < -deadX){ } else if (panX < -deadX){
panMove.x += deadX; panX += deadX;
} else { } else {
panMove.x = 0; panX = 0;
} }
if (panMove.y > deadY){ if (panY > deadY){
panMove.y -= deadY; panY -= deadY;
} else if (panMove.y < -deadY){ } else if (panY < -deadY){
panMove.y += deadY; panY += deadY;
} else { } else {
panMove.y = 0; panY = 0;
} }
panMove.scale(Math.min(1f, Game.elapsed * panIntensity)); panX *= Math.min(1f, Game.elapsed * panIntensity);
panY *= Math.min(1f, Game.elapsed * panIntensity);
scroll.offset(panMove); scroll.offset(panX, panY);
} }
if ((shakeTime -= Game.elapsed) > 0) { if ((shakeTime -= Game.elapsed) > 0) {

View File

@@ -107,7 +107,7 @@ public class Burning extends Buff implements Hero.Doom {
ArrayList<Item> burnable = new ArrayList<>(); ArrayList<Item> burnable = new ArrayList<>();
//does not reach inside of containers //does not reach inside of containers
if (hero.buff(LostInventory.class) == null) { if (!hero.belongings.lostInventory()) {
for (Item i : hero.belongings.backpack.items) { for (Item i : hero.belongings.backpack.items) {
if (!i.unique && (i instanceof Scroll || i instanceof MysteryMeat || i instanceof FrozenCarpaccio)) { if (!i.unique && (i instanceof Scroll || i instanceof MysteryMeat || i instanceof FrozenCarpaccio)) {
burnable.add(i); burnable.add(i);

View File

@@ -61,7 +61,7 @@ public class Frost extends FlavourBuff {
Hero hero = (Hero)target; Hero hero = (Hero)target;
ArrayList<Item> freezable = new ArrayList<>(); ArrayList<Item> freezable = new ArrayList<>();
//does not reach inside of containers //does not reach inside of containers
if (hero.buff(LostInventory.class) == null) { if (!hero.belongings.lostInventory()) {
for (Item i : hero.belongings.backpack.items) { for (Item i : hero.belongings.backpack.items) {
if (!i.unique && (i instanceof Potion || i instanceof MysteryMeat)) { if (!i.unique && (i instanceof Potion || i instanceof MysteryMeat)) {
freezable.add(i); freezable.add(i);

View File

@@ -21,6 +21,8 @@
package com.shatteredpixel.shatteredpixeldungeon.actors.buffs; package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
public class LostInventory extends Buff { public class LostInventory extends Buff {
@@ -29,6 +31,26 @@ public class LostInventory extends Buff {
type = buffType.NEGATIVE; type = buffType.NEGATIVE;
} }
@Override
public boolean attachTo( Char target ) {
if (super.attachTo( target )) {
if (target instanceof Hero && ((Hero) target).belongings != null){
((Hero) target).belongings.lostInventory(true);
}
return true;
} else {
return false;
}
}
@Override
public void detach() {
super.detach();
if (target instanceof Hero && ((Hero) target).belongings != null){
((Hero) target).belongings.lostInventory(false);
}
}
@Override @Override
public int icon() { public int icon() {
return BuffIndicator.NOINV; return BuffIndicator.NOINV;

View File

@@ -101,9 +101,18 @@ public class Belongings implements Iterable<Item> {
return weapon(); return weapon();
} }
//we cache whether belongings are lost to avoid lots of calls to hero.buff(LostInventory.class)
private boolean lostInvent;
public void lostInventory( boolean val ){
lostInvent = val;
}
public boolean lostInventory(){
return lostInvent;
}
public KindOfWeapon weapon(){ public KindOfWeapon weapon(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; if (!lostInventory() || (weapon != null && weapon.keptThroughLostInventory())){
if (!lostInvent || (weapon != null && weapon.keptThroughLostInventory())){
return weapon; return weapon;
} else { } else {
return null; return null;
@@ -111,8 +120,7 @@ public class Belongings implements Iterable<Item> {
} }
public Armor armor(){ public Armor armor(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; if (!lostInventory() || (armor != null && armor.keptThroughLostInventory())){
if (!lostInvent || (armor != null && armor.keptThroughLostInventory())){
return armor; return armor;
} else { } else {
return null; return null;
@@ -120,8 +128,7 @@ public class Belongings implements Iterable<Item> {
} }
public Artifact artifact(){ public Artifact artifact(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; if (!lostInventory() || (artifact != null && artifact.keptThroughLostInventory())){
if (!lostInvent || (artifact != null && artifact.keptThroughLostInventory())){
return artifact; return artifact;
} else { } else {
return null; return null;
@@ -129,8 +136,7 @@ public class Belongings implements Iterable<Item> {
} }
public KindofMisc misc(){ public KindofMisc misc(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; if (!lostInventory() || (misc != null && misc.keptThroughLostInventory())){
if (!lostInvent || (misc != null && misc.keptThroughLostInventory())){
return misc; return misc;
} else { } else {
return null; return null;
@@ -138,8 +144,7 @@ public class Belongings implements Iterable<Item> {
} }
public Ring ring(){ public Ring ring(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; if (!lostInventory() || (ring != null && ring.keptThroughLostInventory())){
if (!lostInvent || (ring != null && ring.keptThroughLostInventory())){
return ring; return ring;
} else { } else {
return null; return null;
@@ -147,8 +152,7 @@ public class Belongings implements Iterable<Item> {
} }
public KindOfWeapon secondWep(){ public KindOfWeapon secondWep(){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; if (!lostInventory() || (secondWep != null && secondWep.keptThroughLostInventory())){
if (!lostInvent || (secondWep != null && secondWep.keptThroughLostInventory())){
return secondWep; return secondWep;
} else { } else {
return null; return null;
@@ -232,7 +236,7 @@ public class Belongings implements Iterable<Item> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public<T extends Item> T getItem( Class<T> itemClass ) { public<T extends Item> T getItem( Class<T> itemClass ) {
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = lostInventory();
for (Item item : this) { for (Item item : this) {
if (itemClass.isInstance( item )) { if (itemClass.isInstance( item )) {
@@ -248,7 +252,7 @@ public class Belongings implements Iterable<Item> {
public<T extends Item> ArrayList<T> getAllItems( Class<T> itemClass ) { public<T extends Item> ArrayList<T> getAllItems( Class<T> itemClass ) {
ArrayList<T> result = new ArrayList<>(); ArrayList<T> result = new ArrayList<>();
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = lostInventory();
for (Item item : this) { for (Item item : this) {
if (itemClass.isInstance( item )) { if (itemClass.isInstance( item )) {
@@ -263,7 +267,7 @@ public class Belongings implements Iterable<Item> {
public boolean contains( Item contains ){ public boolean contains( Item contains ){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = lostInventory();
for (Item item : this) { for (Item item : this) {
if (contains == item) { if (contains == item) {
@@ -278,7 +282,7 @@ public class Belongings implements Iterable<Item> {
public Item getSimilar( Item similar ){ public Item getSimilar( Item similar ){
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = lostInventory();
for (Item item : this) { for (Item item : this) {
if (similar != item && similar.isSimilar(item)) { if (similar != item && similar.isSimilar(item)) {
@@ -294,7 +298,7 @@ public class Belongings implements Iterable<Item> {
public ArrayList<Item> getAllSimilar( Item similar ){ public ArrayList<Item> getAllSimilar( Item similar ){
ArrayList<Item> result = new ArrayList<>(); ArrayList<Item> result = new ArrayList<>();
boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; boolean lostInvent = lostInventory();
for (Item item : this) { for (Item item : this) {
if (item != similar && similar.isSimilar(item)) { if (item != similar && similar.isSimilar(item)) {

View File

@@ -35,7 +35,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.EnhancedRings;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FlavourBuff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FlavourBuff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Haste; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Haste;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.PhysicalEmpower; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.PhysicalEmpower;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.RevealedArea; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.RevealedArea;
@@ -431,7 +430,7 @@ public enum Talent {
if (talent == LIGHT_CLOAK && hero.heroClass == HeroClass.ROGUE){ if (talent == LIGHT_CLOAK && hero.heroClass == HeroClass.ROGUE){
for (Item item : Dungeon.hero.belongings.backpack){ for (Item item : Dungeon.hero.belongings.backpack){
if (item instanceof CloakOfShadows){ if (item instanceof CloakOfShadows){
if (hero.buff(LostInventory.class) == null || item.keptThroughLostInventory()) { if (!hero.belongings.lostInventory() || item.keptThroughLostInventory()) {
((CloakOfShadows) item).activate(Dungeon.hero); ((CloakOfShadows) item).activate(Dungeon.hero);
} }
} }

View File

@@ -48,8 +48,9 @@ public class CircleArc extends Visual {
private boolean lightMode = true; private boolean lightMode = true;
private SmartTexture texture; private SmartTexture texture;
private FloatBuffer vertices; protected float[] vertices;
private FloatBuffer verticesBuffer;
private ShortBuffer indices; private ShortBuffer indices;
private int nTris; private int nTris;
@@ -64,8 +65,9 @@ public class CircleArc extends Visual {
this.nTris = triangles; this.nTris = triangles;
this.rad = radius; this.rad = radius;
vertices = ByteBuffer. vertices = new float[4];
verticesBuffer = ByteBuffer.
allocateDirect( (nTris * 2 + 1) * 4 * (Float.SIZE / 8) ). allocateDirect( (nTris * 2 + 1) * 4 * (Float.SIZE / 8) ).
order( ByteOrder.nativeOrder() ). order( ByteOrder.nativeOrder() ).
asFloatBuffer(); asFloatBuffer();
@@ -105,8 +107,10 @@ public class CircleArc extends Visual {
} }
public void setSweep( float sweep ){ public void setSweep( float sweep ){
this.sweep = sweep; if (sweep != this.sweep) {
dirty = true; this.sweep = sweep;
dirty = true;
}
} }
public float getSweep(){ public float getSweep(){
@@ -116,19 +120,18 @@ public class CircleArc extends Visual {
private void updateTriangles(){ private void updateTriangles(){
dirty = false; dirty = false;
float v[] = new float[4];
((Buffer)indices).position( 0 ); ((Buffer)indices).position( 0 );
((Buffer)vertices).position( 0 ); ((Buffer)verticesBuffer).position( 0 );
v[0] = 0; vertices[0] = 0;
v[1] = 0; vertices[1] = 0;
v[2] = 0.25f; vertices[2] = 0.25f;
v[3] = 0; vertices[3] = 0;
vertices.put( v ); verticesBuffer.put( vertices );
v[2] = 0.75f; vertices[2] = 0.75f;
v[3] = 0; vertices[3] = 0;
//starting position is very top by default, use angle to adjust this. //starting position is very top by default, use angle to adjust this.
double start = 2 * (Math.PI - Math.PI*sweep) - Math.PI/2.0; double start = 2 * (Math.PI - Math.PI*sweep) - Math.PI/2.0;
@@ -136,14 +139,14 @@ public class CircleArc extends Visual {
for (int i = 0; i < nTris; i++) { for (int i = 0; i < nTris; i++) {
double a = start + i * Math.PI * 2 / nTris * sweep; double a = start + i * Math.PI * 2 / nTris * sweep;
v[0] = (float)Math.cos( a ) * rad; vertices[0] = (float)Math.cos( a ) * rad;
v[1] = (float)Math.sin( a ) * rad; vertices[1] = (float)Math.sin( a ) * rad;
vertices.put( v ); verticesBuffer.put( vertices );
a += 3.1415926f * 2 / nTris * sweep; a += 3.1415926f * 2 / nTris * sweep;
v[0] = (float)Math.cos( a ) * rad; vertices[0] = (float)Math.cos( a ) * rad;
v[1] = (float)Math.sin( a ) * rad; vertices[1] = (float)Math.sin( a ) * rad;
vertices.put( v ); verticesBuffer.put( vertices );
indices.put( (short)0 ); indices.put( (short)0 );
indices.put( (short)(1 + i * 2) ); indices.put( (short)(1 + i * 2) );
@@ -189,7 +192,7 @@ public class CircleArc extends Visual {
ra, ga, ba, aa ); ra, ga, ba, aa );
script.camera( camera ); script.camera( camera );
script.drawElements( vertices, indices, nTris * 3 ); script.drawElements( verticesBuffer, indices, nTris * 3 );
if (lightMode) Blending.setNormalMode(); if (lightMode) Blending.setNormalMode();
} }

View File

@@ -24,7 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicImmune; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicImmune;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
@@ -127,7 +126,7 @@ public abstract class EquipableItem extends Item {
if (cursed if (cursed
&& hero.buff(MagicImmune.class) == null && hero.buff(MagicImmune.class) == null
&& (hero.buff(LostInventory.class) == null || keptThroughLostInventory())) { && (!hero.belongings.lostInventory() || keptThroughLostInventory())) {
GLog.w(Messages.get(EquipableItem.class, "unequip_cursed")); GLog.w(Messages.get(EquipableItem.class, "unequip_cursed"));
return false; return false;
} }

View File

@@ -28,7 +28,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Eye; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Eye;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.NPC; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.NPC;
import com.shatteredpixel.shatteredpixeldungeon.effects.Beam; import com.shatteredpixel.shatteredpixeldungeon.effects.Beam;
@@ -242,7 +241,7 @@ public class SentryRoom extends SpecialRoom {
if (fieldOfView[Dungeon.hero.pos] if (fieldOfView[Dungeon.hero.pos]
&& Dungeon.level.map[Dungeon.hero.pos] == Terrain.EMPTY_SP && Dungeon.level.map[Dungeon.hero.pos] == Terrain.EMPTY_SP
&& room.inside(Dungeon.level.cellToPoint(Dungeon.hero.pos)) && room.inside(Dungeon.level.cellToPoint(Dungeon.hero.pos))
&& Dungeon.hero.buff(LostInventory.class) == null){ && !Dungeon.hero.belongings.lostInventory()){
if (curChargeDelay > 0.001f){ //helps prevent rounding errors if (curChargeDelay > 0.001f){ //helps prevent rounding errors
if (curChargeDelay == initialChargeDelay) { if (curChargeDelay == initialChargeDelay) {

View File

@@ -356,13 +356,17 @@ public class CellSelector extends ScrollArea {
public void update() { public void update() {
super.update(); super.update();
if (GameScene.interfaceBlockingHero()){
return;
}
GameAction newLeftStick = actionFromStick(ControllerHandler.leftStickPosition.x, GameAction newLeftStick = actionFromStick(ControllerHandler.leftStickPosition.x,
ControllerHandler.leftStickPosition.y); ControllerHandler.leftStickPosition.y);
//skip logic here if there's no input, or if input is blocked
if ((newLeftStick == leftStickAction
&& leftStickAction == GameAction.NONE
&& heldAction1 == SPDAction.NONE)
|| GameScene.interfaceBlockingHero()){
return;
}
if (newLeftStick != leftStickAction){ if (newLeftStick != leftStickAction){
if (leftStickAction == SPDAction.NONE){ if (leftStickAction == SPDAction.NONE){
heldDelay = initialDelay(); heldDelay = initialDelay();

View File

@@ -757,11 +757,13 @@ public class GameScene extends PixelScene {
} }
cellSelector.enable(Dungeon.hero.ready); cellSelector.enable(Dungeon.hero.ready);
for (Gizmo g : toDestroy){ if (!toDestroy.isEmpty()) {
g.destroy(); for (Gizmo g : toDestroy) {
g.destroy();
}
toDestroy.clear();
} }
toDestroy.clear();
} }
private static Point lastOffset = null; private static Point lastOffset = null;

View File

@@ -53,78 +53,79 @@ public class GameLog extends Component implements Signal.Listener<String> {
@Override @Override
public synchronized void update() { public synchronized void update() {
int maxLines = SPDSettings.interfaceSize() > 0 ? 5 : 3;
for (String text : textsToAdd){
if (length != entries.size()){
clear();
recreateLines();
}
if (text.equals( GLog.NEW_LINE )){ if (!textsToAdd.isEmpty()){
lastEntry = null; int maxLines = SPDSettings.interfaceSize() > 0 ? 5 : 3;
continue; for (String text : textsToAdd){
} if (length != entries.size()){
clear();
int color = CharSprite.DEFAULT; recreateLines();
if (text.startsWith( GLog.POSITIVE )) { }
text = text.substring( GLog.POSITIVE.length() );
color = CharSprite.POSITIVE; if (text.equals( GLog.NEW_LINE )){
} else
if (text.startsWith( GLog.NEGATIVE )) {
text = text.substring( GLog.NEGATIVE.length() );
color = CharSprite.NEGATIVE;
} else
if (text.startsWith( GLog.WARNING )) {
text = text.substring( GLog.WARNING.length() );
color = CharSprite.WARNING;
} else
if (text.startsWith( GLog.HIGHLIGHT )) {
text = text.substring( GLog.HIGHLIGHT.length() );
color = CharSprite.NEUTRAL;
}
if (lastEntry != null && color == lastColor && lastEntry.nLines < maxLines) {
String lastMessage = lastEntry.text();
lastEntry.text( lastMessage.length() == 0 ? text : lastMessage + " " + text );
entries.get( entries.size() - 1 ).text = lastEntry.text();
} else {
lastEntry = PixelScene.renderTextBlock( text, 6 );
lastEntry.setHightlighting( false );
lastEntry.hardlight( color );
lastColor = color;
add( lastEntry );
entries.add( new Entry( text, color ) );
}
if (length > 0) {
int nLines;
do {
nLines = 0;
for (int i = 0; i < length-1; i++) {
nLines += ((RenderedTextBlock) members.get(i)).nLines;
}
if (nLines > maxLines) {
RenderedTextBlock r = ((RenderedTextBlock) members.get(0));
remove(r);
r.destroy();
entries.remove( 0 );
}
} while (nLines > maxLines);
if (entries.isEmpty()) {
lastEntry = null; lastEntry = null;
continue;
}
int color = CharSprite.DEFAULT;
if (text.startsWith( GLog.POSITIVE )) {
text = text.substring( GLog.POSITIVE.length() );
color = CharSprite.POSITIVE;
} else
if (text.startsWith( GLog.NEGATIVE )) {
text = text.substring( GLog.NEGATIVE.length() );
color = CharSprite.NEGATIVE;
} else
if (text.startsWith( GLog.WARNING )) {
text = text.substring( GLog.WARNING.length() );
color = CharSprite.WARNING;
} else
if (text.startsWith( GLog.HIGHLIGHT )) {
text = text.substring( GLog.HIGHLIGHT.length() );
color = CharSprite.NEUTRAL;
}
if (lastEntry != null && color == lastColor && lastEntry.nLines < maxLines) {
String lastMessage = lastEntry.text();
lastEntry.text( lastMessage.length() == 0 ? text : lastMessage + " " + text );
entries.get( entries.size() - 1 ).text = lastEntry.text();
} else {
lastEntry = PixelScene.renderTextBlock( text, 6 );
lastEntry.setHightlighting( false );
lastEntry.hardlight( color );
lastColor = color;
add( lastEntry );
entries.add( new Entry( text, color ) );
}
if (length > 0) {
int nLines;
do {
nLines = 0;
for (int i = 0; i < length-1; i++) {
nLines += ((RenderedTextBlock) members.get(i)).nLines;
}
if (nLines > maxLines) {
RenderedTextBlock r = ((RenderedTextBlock) members.get(0));
remove(r);
r.destroy();
entries.remove( 0 );
}
} while (nLines > maxLines);
if (entries.isEmpty()) {
lastEntry = null;
}
} }
} }
}
if (!textsToAdd.isEmpty()){
layout(); layout();
textsToAdd.clear(); textsToAdd.clear();
} }

View File

@@ -26,7 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDAction; import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag; import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
@@ -361,7 +360,7 @@ public class InventoryPane extends Component {
} }
} }
boolean lostInvent = Dungeon.hero.buff(LostInventory.class) != null; boolean lostInvent = Dungeon.hero.belongings.lostInventory();
for (InventorySlot b : equipped){ for (InventorySlot b : equipped){
b.enable(lastEnabled b.enable(lastEnabled
&& !(b.item() instanceof WndBag.Placeholder) && !(b.item() instanceof WndBag.Placeholder)
@@ -451,7 +450,7 @@ public class InventoryPane extends Component {
if (lastEnabled != (Dungeon.hero.ready || !Dungeon.hero.isAlive())) { if (lastEnabled != (Dungeon.hero.ready || !Dungeon.hero.isAlive())) {
lastEnabled = (Dungeon.hero.ready || !Dungeon.hero.isAlive()); lastEnabled = (Dungeon.hero.ready || !Dungeon.hero.isAlive());
boolean lostInvent = Dungeon.hero.buff(LostInventory.class) != null; boolean lostInvent = Dungeon.hero.belongings.lostInventory();
for (InventorySlot b : equipped){ for (InventorySlot b : equipped){
b.enable(lastEnabled b.enable(lastEnabled
&& !(b.item() instanceof WndBag.Placeholder) && !(b.item() instanceof WndBag.Placeholder)

View File

@@ -23,7 +23,6 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory;
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
import com.shatteredpixel.shatteredpixeldungeon.items.Gold; import com.shatteredpixel.shatteredpixeldungeon.items.Gold;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
@@ -101,7 +100,7 @@ public class InventorySlot extends ItemSlot {
if (item.name() == null) { if (item.name() == null) {
enable( false ); enable( false );
} else if (Dungeon.hero.buff(LostInventory.class) != null } else if (Dungeon.hero.belongings.lostInventory()
&& !item.keptThroughLostInventory()){ && !item.keptThroughLostInventory()){
enable(false); enable(false);
} }

View File

@@ -28,18 +28,17 @@ import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.Waterskin; import com.shatteredpixel.shatteredpixeldungeon.items.Waterskin;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.watabou.utils.BArray;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings; import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings;
import com.watabou.input.GameAction; import com.watabou.input.GameAction;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
import com.watabou.utils.BArray;
import com.watabou.utils.PathFinder; import com.watabou.utils.PathFinder;
public class QuickSlotButton extends Button { public class QuickSlotButton extends Button {
@@ -304,7 +303,7 @@ public class QuickSlotButton extends Button {
private void enableSlot() { private void enableSlot() {
slot.enable(Dungeon.quickslot.isNonePlaceholder( slotNum ) slot.enable(Dungeon.quickslot.isNonePlaceholder( slotNum )
&& (Dungeon.hero.buff(LostInventory.class) == null || Dungeon.quickslot.getItem(slotNum).keptThroughLostInventory())); && (!Dungeon.hero.belongings.lostInventory() || Dungeon.quickslot.getItem(slotNum).keptThroughLostInventory()));
} }
public void slotMargins( int left, int top, int right, int bottom){ public void slotMargins( int left, int top, int right, int bottom){

View File

@@ -235,6 +235,10 @@ public class StatusPane extends Component {
private static final int[] warningColors = new int[]{0x660000, 0xCC0000, 0x660000}; private static final int[] warningColors = new int[]{0x660000, 0xCC0000, 0x660000};
private int oldHP = 0;
private int oldShield = 0;
private int oldMax = 0;
@Override @Override
public void update() { public void update() {
super.update(); super.update();
@@ -265,10 +269,15 @@ public class StatusPane extends Component {
rawShielding.scale.x = 0; rawShielding.scale.x = 0;
} }
if (shield <= 0){ if (oldHP != health || oldShield != shield || oldMax != max){
hpText.text(health + "/" + max); if (shield <= 0) {
} else { hpText.text(health + "/" + max);
hpText.text(health + "+" + shield + "/" + max); } else {
hpText.text(health + "+" + shield + "/" + max);
}
oldHP = health;
oldShield = shield;
oldMax = max;
} }
if (large) { if (large) {

View File

@@ -28,7 +28,6 @@ import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.HoldFast; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.HoldFast;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
@@ -128,7 +127,7 @@ public class Toolbar extends Component {
Item item = Dungeon.quickslot.getItem(i); Item item = Dungeon.quickslot.getItem(i);
if (item != null && !Dungeon.quickslot.isPlaceholder(i) && if (item != null && !Dungeon.quickslot.isPlaceholder(i) &&
(Dungeon.hero.buff(LostInventory.class) == null || item.keptThroughLostInventory())){ (!Dungeon.hero.belongings.lostInventory() || item.keptThroughLostInventory())){
slotNames[i] = Messages.titleCase(item.name()); slotNames[i] = Messages.titleCase(item.name());
slotIcons[i] = new ItemSprite(item); slotIcons[i] = new ItemSprite(item);
} else { } else {
@@ -154,7 +153,7 @@ public class Toolbar extends Component {
Item item = Dungeon.quickslot.getItem(idx); Item item = Dungeon.quickslot.getItem(idx);
if (item == null || Dungeon.quickslot.isPlaceholder(idx) if (item == null || Dungeon.quickslot.isPlaceholder(idx)
|| (Dungeon.hero.buff(LostInventory.class) != null && !item.keptThroughLostInventory()) || (Dungeon.hero.belongings.lostInventory() && !item.keptThroughLostInventory())
|| alt){ || alt){
//TODO would be nice to use a radial menu for this too //TODO would be nice to use a radial menu for this too
// Also a bunch of code could be moved out of here into subclasses of RadialMenu // Also a bunch of code could be moved out of here into subclasses of RadialMenu
@@ -420,7 +419,7 @@ public class Toolbar extends Component {
for(Item i : bag.items){ for(Item i : bag.items){
if (i instanceof Bag) items.remove(i); if (i instanceof Bag) items.remove(i);
if (Dungeon.hero.buff(LostInventory.class) != null && !i.keptThroughLostInventory()) items.remove(i); if (Dungeon.hero.belongings.lostInventory() && !i.keptThroughLostInventory()) items.remove(i);
} }
if (idx == 0){ if (idx == 0){