v1.1.0: added functionality for converting items into energy
This commit is contained in:
parent
44782bc681
commit
c1f3f5ca8f
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user