From c1f3f5ca8f29e58430e64b7286a22abe9dc2244f Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 14 Nov 2021 14:45:24 -0500 Subject: [PATCH] v1.1.0: added functionality for converting items into energy --- .../messages/windows/windows.properties | 5 + .../scenes/AlchemyScene.java | 34 +++- .../windows/WndEnergizeItem.java | 173 ++++++++++++++++++ .../windows/WndTradeItem.java | 9 +- 4 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndEnergizeItem.java diff --git a/core/src/main/assets/messages/windows/windows.properties b/core/src/main/assets/messages/windows/windows.properties index b2962ad15..099c7cc6b 100644 --- a/core/src/main/assets/messages/windows/windows.properties +++ b/core/src/main/assets/messages/windows/windows.properties @@ -23,6 +23,11 @@ windows.wndcombo.title=choose a combo move windows.wnddocument.missing=page missing +windows.wndenergizeitem.prompt=Energize an Item +windows.wndenergizeitem.energize=Turn into %d energy +windows.wndenergizeitem.energize_1=Turn 1 into %d energy +windows.wndenergizeitem.energize_all=Turn all into %d energy + windows.wnderror.title=ERROR windows.wndgame.settings=Settings diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java index db5e25b90..4288e10f5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/AlchemyScene.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; +import com.shatteredpixel.shatteredpixeldungeon.effects.particles.SparkParticle; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Recipe; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.AlchemistsToolkit; @@ -44,6 +45,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndEnergizeItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal; import com.watabou.gltextures.TextureCache; @@ -70,6 +72,7 @@ public class AlchemyScene extends PixelScene { private Emitter smokeEmitter; private Emitter bubbleEmitter; + private Emitter sparkEmitter; private Emitter lowerBubbles; private SkinnedBlock water; @@ -304,13 +307,22 @@ public class AlchemyScene extends PixelScene { align(energyIcon); add(energyIcon); - //TODO does nothing currently - energyAdd = new IconButton(Icons.get(Icons.PLUS)); + energyAdd = new IconButton(Icons.get(Icons.PLUS)){ + @Override + protected void onClick() { + WndEnergizeItem.openItemSelector(); + } + }; energyAdd.setRect(energyLeft.right(), energyIcon.y, 16, 16); add(energyAdd); energyCost = PixelScene.renderTextBlock(6); add(energyCost); + + sparkEmitter = new Emitter(); + sparkEmitter.pos(energyLeft.left(), energyLeft.top(), energyLeft.width(), energyLeft.height()); + sparkEmitter.autoKill = false; + add(sparkEmitter); fadeIn(); @@ -534,6 +546,24 @@ public class AlchemyScene extends PixelScene { } } } + + public void createEnergy(){ + energyLeft.text(Messages.get(AlchemyScene.class, "energy", Dungeon.energy)); + energyLeft.setPos( + (Camera.main.width - energyLeft.width())/2, + Camera.main.height - 8 - energyLeft.height() + ); + + energyIcon.x = energyLeft.left() - energyIcon.width(); + energyIcon.y = energyLeft.top() - (energyIcon.height() - energyLeft.height())/2; + align(energyIcon); + + energyAdd.setRect(energyLeft.right(), energyIcon.y, 16, 16); + + bubbleEmitter.start(Speck.factory( Speck.BUBBLE ), 0.01f, 100 ); + sparkEmitter.burst(SparkParticle.FACTORY, 20); + Sample.INSTANCE.play( Assets.Sounds.LIGHTNING ); + } public static class ItemButton extends Component { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndEnergizeItem.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndEnergizeItem.java new file mode 100644 index 000000000..c61cadfd1 --- /dev/null +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndEnergizeItem.java @@ -0,0 +1,173 @@ +package com.shatteredpixel.shatteredpixeldungeon.windows; + +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Shopkeeper; +import com.shatteredpixel.shatteredpixeldungeon.items.EnergyCrystal; +import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; +import com.shatteredpixel.shatteredpixeldungeon.items.Gold; +import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; +import com.shatteredpixel.shatteredpixeldungeon.scenes.AlchemyScene; +import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; +import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; +import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; +import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; + +public class WndEnergizeItem extends WndInfoItem { + + private static final float GAP = 2; + private static final int BTN_HEIGHT = 18; + + private WndBag owner; + + public WndEnergizeItem(Item item, WndBag owner) { + super(item); + + this.owner = owner; + + float pos = height; + + if (item.quantity() == 1) { + + RedButton btnEnergize = new RedButton( Messages.get(this, "energize", item.energyVal()) ) { + @Override + protected void onClick() { + energize( item ); + hide(); + } + }; + btnEnergize.setRect( 0, pos + GAP, width, BTN_HEIGHT ); + btnEnergize.icon(new ItemSprite(ItemSpriteSheet.ENERGY)); + add( btnEnergize ); + + pos = btnEnergize.bottom(); + + } else { + + int energyAll = item.energyVal(); + RedButton btnEnergize1 = new RedButton( Messages.get(this, "energize_1", energyAll / item.quantity()) ) { + @Override + protected void onClick() { + energizeOne( item ); + hide(); + } + }; + btnEnergize1.setRect( 0, pos + GAP, width, BTN_HEIGHT ); + btnEnergize1.icon(new ItemSprite(ItemSpriteSheet.ENERGY)); + add( btnEnergize1 ); + RedButton btnEnergizeAll = new RedButton( Messages.get(this, "energize_all", energyAll ) ) { + @Override + protected void onClick() { + energize( item ); + hide(); + } + }; + btnEnergizeAll.setRect( 0, btnEnergize1.bottom() + 1, width, BTN_HEIGHT ); + btnEnergizeAll.icon(new ItemSprite(ItemSpriteSheet.ENERGY)); + add( btnEnergizeAll ); + + pos = btnEnergizeAll.bottom(); + + } + + resize( width, (int)pos ); + + } + + @Override + public void hide() { + + super.hide(); + + if (owner != null) { + owner.hide(); + openItemSelector(); + } + } + + private void energize( Item item ) { + + Hero hero = Dungeon.hero; + + if (item.isEquipped( hero ) && !((EquipableItem)item).doUnequip( hero, false )) { + return; + } + item.detachAll( hero.belongings.backpack ); + + if (ShatteredPixelDungeon.scene() instanceof AlchemyScene){ + + Dungeon.energy += item.energyVal(); + ((AlchemyScene) ShatteredPixelDungeon.scene()).createEnergy(); + + } else { + + //selling items in the sell interface doesn't spend time + hero.spend(-hero.cooldown()); + + new EnergyCrystal(item.energyVal()).doPickUp(hero); + + } + } + + private void energizeOne( Item item ) { + + if (item.quantity() <= 1) { + energize( item ); + } else { + + Hero hero = Dungeon.hero; + + item = item.detach( hero.belongings.backpack ); + + if (ShatteredPixelDungeon.scene() instanceof AlchemyScene){ + + Dungeon.energy += item.energyVal(); + ((AlchemyScene) ShatteredPixelDungeon.scene()).createEnergy(); + + } else { + + //selling items in the sell interface doesn't spend time + hero.spend(-hero.cooldown()); + + new EnergyCrystal(item.energyVal()).doPickUp(hero); + } + } + } + + public static WndBag openItemSelector(){ + if (ShatteredPixelDungeon.scene() instanceof GameScene) { + return GameScene.selectItem( selector ); + } else { + WndBag window = WndBag.getBag( selector ); + ShatteredPixelDungeon.scene().addToFront(window); + return window; + } + } + + public static WndBag.ItemSelector selector = new WndBag.ItemSelector() { + @Override + public String textPrompt() { + return Messages.get(WndEnergizeItem.class, "prompt"); + } + + @Override + public boolean itemSelectable(Item item) { + return item.energyVal() > 0; + } + + @Override + public void onSelect(Item item) { + if (item != null) { + WndBag parentWnd = openItemSelector(); + if (ShatteredPixelDungeon.scene() instanceof GameScene) { + GameScene.show(new WndEnergizeItem(item, parentWnd)); + } else { + ShatteredPixelDungeon.scene().addToFront(new WndEnergizeItem(item, parentWnd)); + } + } + } + }; + +} diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTradeItem.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTradeItem.java index 0cfea1c04..d0b80baed 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTradeItem.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndTradeItem.java @@ -31,12 +31,14 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.MasterThievesArmband; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; +import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; +import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; public class WndTradeItem extends WndInfoItem { private static final float GAP = 2; - private static final int BTN_HEIGHT = 16; + private static final int BTN_HEIGHT = 18; private WndBag owner; @@ -59,6 +61,7 @@ public class WndTradeItem extends WndInfoItem { } }; btnSell.setRect( 0, pos + GAP, width, BTN_HEIGHT ); + btnSell.icon(new ItemSprite(ItemSpriteSheet.GOLD)); add( btnSell ); pos = btnSell.bottom(); @@ -74,6 +77,7 @@ public class WndTradeItem extends WndInfoItem { } }; btnSell1.setRect( 0, pos + GAP, width, BTN_HEIGHT ); + btnSell1.icon(new ItemSprite(ItemSpriteSheet.GOLD)); add( btnSell1 ); RedButton btnSellAll = new RedButton( Messages.get(this, "sell_all", priceAll ) ) { @Override @@ -83,6 +87,7 @@ public class WndTradeItem extends WndInfoItem { } }; btnSellAll.setRect( 0, btnSell1.bottom() + 1, width, BTN_HEIGHT ); + btnSellAll.icon(new ItemSprite(ItemSpriteSheet.GOLD)); add( btnSellAll ); pos = btnSellAll.bottom(); @@ -111,6 +116,7 @@ public class WndTradeItem extends WndInfoItem { } }; btnBuy.setRect( 0, pos + GAP, width, BTN_HEIGHT ); + btnBuy.icon(new ItemSprite(ItemSpriteSheet.GOLD)); btnBuy.enable( price <= Dungeon.gold ); add( btnBuy ); @@ -143,6 +149,7 @@ public class WndTradeItem extends WndInfoItem { } }; btnSteal.setRect(0, pos + 1, width, BTN_HEIGHT); + btnSteal.icon(new ItemSprite(ItemSpriteSheet.ARTIFACT_ARMBAND)); add(btnSteal); pos = btnSteal.bottom();