From 2466974a7144fe1a9fd04c061951e30dfe64ff23 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 5 Feb 2024 17:11:48 -0500 Subject: [PATCH] v2.4.0: cleaned up various allocations that occurred every frame --- .../main/java/com/watabou/input/KeyEvent.java | 4 + .../java/com/watabou/input/PointerEvent.java | 4 + .../java/com/watabou/input/ScrollEvent.java | 4 + .../main/java/com/watabou/noosa/Camera.java | 35 +++-- .../actors/buffs/Burning.java | 2 +- .../actors/buffs/Frost.java | 2 +- .../actors/buffs/LostInventory.java | 22 +++ .../actors/hero/Belongings.java | 38 ++--- .../actors/hero/Talent.java | 3 +- .../effects/CircleArc.java | 49 ++++--- .../items/EquipableItem.java | 3 +- .../levels/rooms/special/SentryRoom.java | 3 +- .../scenes/CellSelector.java | 12 +- .../scenes/GameScene.java | 10 +- .../shatteredpixeldungeon/ui/GameLog.java | 137 +++++++++--------- .../ui/InventoryPane.java | 5 +- .../ui/InventorySlot.java | 3 +- .../ui/QuickSlotButton.java | 5 +- .../shatteredpixeldungeon/ui/StatusPane.java | 17 ++- .../shatteredpixeldungeon/ui/Toolbar.java | 7 +- 20 files changed, 209 insertions(+), 156 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/input/KeyEvent.java b/SPD-classes/src/main/java/com/watabou/input/KeyEvent.java index ed025d839..4335c8ac4 100644 --- a/SPD-classes/src/main/java/com/watabou/input/KeyEvent.java +++ b/SPD-classes/src/main/java/com/watabou/input/KeyEvent.java @@ -62,6 +62,10 @@ public class KeyEvent { } public static synchronized void processKeyEvents(){ + if (keyEvents.isEmpty()) { + return; + } + for (KeyEvent k : keyEvents){ if (KeyBindings.getActionForKey(k) == GameAction.LEFT_CLICK){ Game.inputHandler.emulateTouch(ControllerHandler.CONTROLLER_POINTER_ID, PointerEvent.LEFT, k.pressed); diff --git a/SPD-classes/src/main/java/com/watabou/input/PointerEvent.java b/SPD-classes/src/main/java/com/watabou/input/PointerEvent.java index ebbe4eb5b..d9dfae076 100644 --- a/SPD-classes/src/main/java/com/watabou/input/PointerEvent.java +++ b/SPD-classes/src/main/java/com/watabou/input/PointerEvent.java @@ -136,6 +136,10 @@ public class PointerEvent { public static boolean clearKeyboardThisPress = true; public static synchronized void processPointerEvents(){ + if (pointerEvents.isEmpty()){ + return; + } + //handle any hover events separately first as we may need to add drag events boolean hovered = false; for (PointerEvent p : pointerEvents){ diff --git a/SPD-classes/src/main/java/com/watabou/input/ScrollEvent.java b/SPD-classes/src/main/java/com/watabou/input/ScrollEvent.java index 43d4672ca..efdffa183 100644 --- a/SPD-classes/src/main/java/com/watabou/input/ScrollEvent.java +++ b/SPD-classes/src/main/java/com/watabou/input/ScrollEvent.java @@ -62,6 +62,10 @@ public class ScrollEvent { } public static synchronized void processScrollEvents(){ + if (scrollEvents.isEmpty()) { + return; + } + for (ScrollEvent k : scrollEvents){ scrollSignal.dispatch(k); } diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Camera.java b/SPD-classes/src/main/java/com/watabou/noosa/Camera.java index a79801b11..a9eae3115 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Camera.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Camera.java @@ -178,36 +178,39 @@ public class Camera extends Gizmo { float deadX = 0; float deadY = 0; 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; deadY = height * followDeadzone /2f; } if (panIntensity > 0f){ - PointF panMove = new PointF(); - panMove.x = panTarget.x - (scroll.x + width/2f); - panMove.y = panTarget.y - (scroll.y + height/2f); + float panX = panTarget.x - (scroll.x + width/2f); + float panY = panTarget.y - (scroll.y + height/2f); - if (panMove.x > deadX){ - panMove.x -= deadX; - } else if (panMove.x < -deadX){ - panMove.x += deadX; + if (panX > deadX){ + panX -= deadX; + } else if (panX < -deadX){ + panX += deadX; } else { - panMove.x = 0; + panX = 0; } - if (panMove.y > deadY){ - panMove.y -= deadY; - } else if (panMove.y < -deadY){ - panMove.y += deadY; + if (panY > deadY){ + panY -= deadY; + } else if (panY < -deadY){ + panY += deadY; } 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) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java index e7c4439f3..9ebe9aac7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Burning.java @@ -107,7 +107,7 @@ public class Burning extends Buff implements Hero.Doom { ArrayList burnable = new ArrayList<>(); //does not reach inside of containers - if (hero.buff(LostInventory.class) == null) { + if (!hero.belongings.lostInventory()) { for (Item i : hero.belongings.backpack.items) { if (!i.unique && (i instanceof Scroll || i instanceof MysteryMeat || i instanceof FrozenCarpaccio)) { burnable.add(i); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java index a35d80573..0b0188253 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Frost.java @@ -61,7 +61,7 @@ public class Frost extends FlavourBuff { Hero hero = (Hero)target; ArrayList freezable = new ArrayList<>(); //does not reach inside of containers - if (hero.buff(LostInventory.class) == null) { + if (!hero.belongings.lostInventory()) { for (Item i : hero.belongings.backpack.items) { if (!i.unique && (i instanceof Potion || i instanceof MysteryMeat)) { freezable.add(i); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/LostInventory.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/LostInventory.java index fa3caf0b2..c50c3e2d6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/LostInventory.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/LostInventory.java @@ -21,6 +21,8 @@ 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; public class LostInventory extends Buff { @@ -29,6 +31,26 @@ public class LostInventory extends Buff { 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 public int icon() { return BuffIndicator.NOINV; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java index 12c925aa5..92251679b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java @@ -101,9 +101,18 @@ public class Belongings implements Iterable { 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(){ - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; - if (!lostInvent || (weapon != null && weapon.keptThroughLostInventory())){ + if (!lostInventory() || (weapon != null && weapon.keptThroughLostInventory())){ return weapon; } else { return null; @@ -111,8 +120,7 @@ public class Belongings implements Iterable { } public Armor armor(){ - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; - if (!lostInvent || (armor != null && armor.keptThroughLostInventory())){ + if (!lostInventory() || (armor != null && armor.keptThroughLostInventory())){ return armor; } else { return null; @@ -120,8 +128,7 @@ public class Belongings implements Iterable { } public Artifact artifact(){ - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; - if (!lostInvent || (artifact != null && artifact.keptThroughLostInventory())){ + if (!lostInventory() || (artifact != null && artifact.keptThroughLostInventory())){ return artifact; } else { return null; @@ -129,8 +136,7 @@ public class Belongings implements Iterable { } public KindofMisc misc(){ - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; - if (!lostInvent || (misc != null && misc.keptThroughLostInventory())){ + if (!lostInventory() || (misc != null && misc.keptThroughLostInventory())){ return misc; } else { return null; @@ -138,8 +144,7 @@ public class Belongings implements Iterable { } public Ring ring(){ - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; - if (!lostInvent || (ring != null && ring.keptThroughLostInventory())){ + if (!lostInventory() || (ring != null && ring.keptThroughLostInventory())){ return ring; } else { return null; @@ -147,8 +152,7 @@ public class Belongings implements Iterable { } public KindOfWeapon secondWep(){ - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; - if (!lostInvent || (secondWep != null && secondWep.keptThroughLostInventory())){ + if (!lostInventory() || (secondWep != null && secondWep.keptThroughLostInventory())){ return secondWep; } else { return null; @@ -232,7 +236,7 @@ public class Belongings implements Iterable { @SuppressWarnings("unchecked") public T getItem( Class itemClass ) { - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + boolean lostInvent = lostInventory(); for (Item item : this) { if (itemClass.isInstance( item )) { @@ -248,7 +252,7 @@ public class Belongings implements Iterable { public ArrayList getAllItems( Class itemClass ) { ArrayList result = new ArrayList<>(); - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + boolean lostInvent = lostInventory(); for (Item item : this) { if (itemClass.isInstance( item )) { @@ -263,7 +267,7 @@ public class Belongings implements Iterable { public boolean contains( Item contains ){ - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + boolean lostInvent = lostInventory(); for (Item item : this) { if (contains == item) { @@ -278,7 +282,7 @@ public class Belongings implements Iterable { public Item getSimilar( Item similar ){ - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + boolean lostInvent = lostInventory(); for (Item item : this) { if (similar != item && similar.isSimilar(item)) { @@ -294,7 +298,7 @@ public class Belongings implements Iterable { public ArrayList getAllSimilar( Item similar ){ ArrayList result = new ArrayList<>(); - boolean lostInvent = owner != null && owner.buff(LostInventory.class) != null; + boolean lostInvent = lostInventory(); for (Item item : this) { if (item != similar && similar.isSimilar(item)) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java index 7e14a3ba4..20f388f19 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java @@ -35,7 +35,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.EnhancedRings; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FlavourBuff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Haste; 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.Recharging; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.RevealedArea; @@ -431,7 +430,7 @@ public enum Talent { if (talent == LIGHT_CLOAK && hero.heroClass == HeroClass.ROGUE){ for (Item item : Dungeon.hero.belongings.backpack){ if (item instanceof CloakOfShadows){ - if (hero.buff(LostInventory.class) == null || item.keptThroughLostInventory()) { + if (!hero.belongings.lostInventory() || item.keptThroughLostInventory()) { ((CloakOfShadows) item).activate(Dungeon.hero); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/CircleArc.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/CircleArc.java index 0bd761dd8..988d4c25e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/CircleArc.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/CircleArc.java @@ -48,8 +48,9 @@ public class CircleArc extends Visual { private boolean lightMode = true; private SmartTexture texture; - - private FloatBuffer vertices; + + protected float[] vertices; + private FloatBuffer verticesBuffer; private ShortBuffer indices; private int nTris; @@ -64,8 +65,9 @@ public class CircleArc extends Visual { this.nTris = triangles; this.rad = radius; - - vertices = ByteBuffer. + + vertices = new float[4]; + verticesBuffer = ByteBuffer. allocateDirect( (nTris * 2 + 1) * 4 * (Float.SIZE / 8) ). order( ByteOrder.nativeOrder() ). asFloatBuffer(); @@ -105,8 +107,10 @@ public class CircleArc extends Visual { } public void setSweep( float sweep ){ - this.sweep = sweep; - dirty = true; + if (sweep != this.sweep) { + this.sweep = sweep; + dirty = true; + } } public float getSweep(){ @@ -116,19 +120,18 @@ public class CircleArc extends Visual { private void updateTriangles(){ dirty = false; - float v[] = new float[4]; ((Buffer)indices).position( 0 ); - ((Buffer)vertices).position( 0 ); + ((Buffer)verticesBuffer).position( 0 ); - v[0] = 0; - v[1] = 0; - v[2] = 0.25f; - v[3] = 0; - vertices.put( v ); - - v[2] = 0.75f; - v[3] = 0; + vertices[0] = 0; + vertices[1] = 0; + vertices[2] = 0.25f; + vertices[3] = 0; + verticesBuffer.put( vertices ); + + vertices[2] = 0.75f; + vertices[3] = 0; //starting position is very top by default, use angle to adjust this. 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++) { double a = start + i * Math.PI * 2 / nTris * sweep; - v[0] = (float)Math.cos( a ) * rad; - v[1] = (float)Math.sin( a ) * rad; - vertices.put( v ); + vertices[0] = (float)Math.cos( a ) * rad; + vertices[1] = (float)Math.sin( a ) * rad; + verticesBuffer.put( vertices ); a += 3.1415926f * 2 / nTris * sweep; - v[0] = (float)Math.cos( a ) * rad; - v[1] = (float)Math.sin( a ) * rad; - vertices.put( v ); + vertices[0] = (float)Math.cos( a ) * rad; + vertices[1] = (float)Math.sin( a ) * rad; + verticesBuffer.put( vertices ); indices.put( (short)0 ); indices.put( (short)(1 + i * 2) ); @@ -189,7 +192,7 @@ public class CircleArc extends Visual { ra, ga, ba, aa ); script.camera( camera ); - script.drawElements( vertices, indices, nTris * 3 ); + script.drawElements( verticesBuffer, indices, nTris * 3 ); if (lightMode) Blending.setNormalMode(); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java index 6c37c1633..23b3af342 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/EquipableItem.java @@ -24,7 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon.items; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; 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.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle; @@ -127,7 +126,7 @@ public abstract class EquipableItem extends Item { if (cursed && hero.buff(MagicImmune.class) == null - && (hero.buff(LostInventory.class) == null || keptThroughLostInventory())) { + && (!hero.belongings.lostInventory() || keptThroughLostInventory())) { GLog.w(Messages.get(EquipableItem.class, "unequip_cursed")); return false; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SentryRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SentryRoom.java index 91b9eb973..b4d6e62df 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SentryRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SentryRoom.java @@ -28,7 +28,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; 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.npcs.NPC; import com.shatteredpixel.shatteredpixeldungeon.effects.Beam; @@ -242,7 +241,7 @@ public class SentryRoom extends SpecialRoom { if (fieldOfView[Dungeon.hero.pos] && Dungeon.level.map[Dungeon.hero.pos] == Terrain.EMPTY_SP && 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 == initialChargeDelay) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java index 4813e70d3..f3a074ade 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java @@ -356,13 +356,17 @@ public class CellSelector extends ScrollArea { public void update() { super.update(); - if (GameScene.interfaceBlockingHero()){ - return; - } - GameAction newLeftStick = actionFromStick(ControllerHandler.leftStickPosition.x, 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 (leftStickAction == SPDAction.NONE){ heldDelay = initialDelay(); 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 d0896a6af..275038a19 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -757,11 +757,13 @@ public class GameScene extends PixelScene { } cellSelector.enable(Dungeon.hero.ready); - - for (Gizmo g : toDestroy){ - g.destroy(); + + if (!toDestroy.isEmpty()) { + for (Gizmo g : toDestroy) { + g.destroy(); + } + toDestroy.clear(); } - toDestroy.clear(); } private static Point lastOffset = null; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/GameLog.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/GameLog.java index 8cc3f34c9..ce13bfba8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/GameLog.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/GameLog.java @@ -53,78 +53,79 @@ public class GameLog extends Component implements Signal.Listener { @Override 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 )){ - 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()) { + if (!textsToAdd.isEmpty()){ + int maxLines = SPDSettings.interfaceSize() > 0 ? 5 : 3; + for (String text : textsToAdd){ + if (length != entries.size()){ + clear(); + recreateLines(); + } + + if (text.equals( GLog.NEW_LINE )){ 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(); textsToAdd.clear(); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java index 0e5f7294e..2480c3b1d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventoryPane.java @@ -26,7 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.SPDAction; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; -import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.items.Item; 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){ b.enable(lastEnabled && !(b.item() instanceof WndBag.Placeholder) @@ -451,7 +450,7 @@ public class InventoryPane extends Component { if (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){ b.enable(lastEnabled && !(b.item() instanceof WndBag.Placeholder) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventorySlot.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventorySlot.java index 3b876b1bd..5c46938b7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventorySlot.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/InventorySlot.java @@ -23,7 +23,6 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory; import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; import com.shatteredpixel.shatteredpixeldungeon.items.Gold; import com.shatteredpixel.shatteredpixeldungeon.items.Item; @@ -101,7 +100,7 @@ public class InventorySlot extends ItemSlot { if (item.name() == null) { enable( false ); - } else if (Dungeon.hero.buff(LostInventory.class) != null + } else if (Dungeon.hero.belongings.lostInventory() && !item.keptThroughLostInventory()){ enable(false); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java index a53d3df2c..2a6493699 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java @@ -28,18 +28,17 @@ import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; -import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LostInventory; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Waterskin; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; -import com.watabou.utils.BArray; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings; import com.watabou.input.GameAction; import com.watabou.noosa.Image; +import com.watabou.utils.BArray; import com.watabou.utils.PathFinder; public class QuickSlotButton extends Button { @@ -304,7 +303,7 @@ public class QuickSlotButton extends Button { private void enableSlot() { 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){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java index 503561794..9b37070b2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -235,6 +235,10 @@ public class StatusPane extends Component { private static final int[] warningColors = new int[]{0x660000, 0xCC0000, 0x660000}; + private int oldHP = 0; + private int oldShield = 0; + private int oldMax = 0; + @Override public void update() { super.update(); @@ -265,10 +269,15 @@ public class StatusPane extends Component { rawShielding.scale.x = 0; } - if (shield <= 0){ - hpText.text(health + "/" + max); - } else { - hpText.text(health + "+" + shield + "/" + max); + if (oldHP != health || oldShield != shield || oldMax != max){ + if (shield <= 0) { + hpText.text(health + "/" + max); + } else { + hpText.text(health + "+" + shield + "/" + max); + } + oldHP = health; + oldShield = shield; + oldMax = max; } if (large) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java index 3be4a7fb0..de80d3e8d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java @@ -28,7 +28,6 @@ import com.shatteredpixel.shatteredpixeldungeon.SPDAction; import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; 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.Talent; import com.shatteredpixel.shatteredpixeldungeon.items.Item; @@ -128,7 +127,7 @@ public class Toolbar extends Component { Item item = Dungeon.quickslot.getItem(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()); slotIcons[i] = new ItemSprite(item); } else { @@ -154,7 +153,7 @@ public class Toolbar extends Component { Item item = Dungeon.quickslot.getItem(idx); if (item == null || Dungeon.quickslot.isPlaceholder(idx) - || (Dungeon.hero.buff(LostInventory.class) != null && !item.keptThroughLostInventory()) + || (Dungeon.hero.belongings.lostInventory() && !item.keptThroughLostInventory()) || alt){ //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 @@ -420,7 +419,7 @@ public class Toolbar extends Component { for(Item i : bag.items){ 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){