2014-07-27 13:39:07 +00:00
|
|
|
/*
|
|
|
|
* Pixel Dungeon
|
|
|
|
* Copyright (C) 2012-2014 Oleg Dolya
|
|
|
|
*
|
|
|
|
* 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/>
|
|
|
|
*/
|
2014-08-03 18:46:22 +00:00
|
|
|
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
2015-01-21 21:13:54 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
2014-07-27 13:39:07 +00:00
|
|
|
import com.watabou.noosa.Game;
|
|
|
|
import com.watabou.noosa.Gizmo;
|
|
|
|
import com.watabou.noosa.Image;
|
|
|
|
import com.watabou.noosa.ui.Button;
|
|
|
|
import com.watabou.noosa.ui.Component;
|
2014-08-03 18:46:22 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.CellSelector;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndCatalogus;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoCell;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoItem;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoMob;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoPlant;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTradeItem;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
public class Toolbar extends Component {
|
|
|
|
|
|
|
|
private Tool btnWait;
|
|
|
|
private Tool btnSearch;
|
|
|
|
private Tool btnInfo;
|
|
|
|
private Tool btnResume;
|
|
|
|
private Tool btnInventory;
|
|
|
|
private Tool btnQuick;
|
2015-01-21 21:13:54 +00:00
|
|
|
private Tool btnQuick2;
|
|
|
|
|
|
|
|
public static int QuickSlots;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
private PickedUpItem pickedUp;
|
|
|
|
|
|
|
|
private boolean lastEnabled = true;
|
|
|
|
|
|
|
|
public Toolbar() {
|
|
|
|
super();
|
2015-01-21 21:13:54 +00:00
|
|
|
|
|
|
|
QuickSlots = ShatteredPixelDungeon.quickSlots();
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
height = btnInventory.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void createChildren() {
|
|
|
|
|
|
|
|
add( btnWait = new Tool( 0, 7, 20, 24 ) {
|
|
|
|
@Override
|
|
|
|
protected void onClick() {
|
|
|
|
Dungeon.hero.rest( false );
|
|
|
|
};
|
|
|
|
protected boolean onLongClick() {
|
|
|
|
Dungeon.hero.rest( true );
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
add( btnSearch = new Tool( 20, 7, 20, 24 ) {
|
|
|
|
@Override
|
|
|
|
protected void onClick() {
|
|
|
|
Dungeon.hero.search( true );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
add( btnInfo = new Tool( 40, 7, 21, 24 ) {
|
|
|
|
@Override
|
|
|
|
protected void onClick() {
|
|
|
|
GameScene.selectCell( informer );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
add( btnResume = new Tool( 61, 7, 21, 24 ) {
|
|
|
|
@Override
|
|
|
|
protected void onClick() {
|
|
|
|
Dungeon.hero.resume();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
add( btnInventory = new Tool( 82, 7, 23, 24 ) {
|
|
|
|
private GoldIndicator gold;
|
|
|
|
@Override
|
|
|
|
protected void onClick() {
|
|
|
|
GameScene.show( new WndBag( Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null ) );
|
|
|
|
}
|
|
|
|
protected boolean onLongClick() {
|
|
|
|
GameScene.show( new WndCatalogus() );
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
@Override
|
|
|
|
protected void createChildren() {
|
|
|
|
super.createChildren();
|
|
|
|
gold = new GoldIndicator();
|
|
|
|
add( gold );
|
|
|
|
};
|
|
|
|
@Override
|
|
|
|
protected void layout() {
|
|
|
|
super.layout();
|
|
|
|
gold.fill( this );
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
2015-01-21 21:13:54 +00:00
|
|
|
add( btnQuick = new QuickslotTool( 105, 7, 22, 24, 0) );
|
|
|
|
|
|
|
|
add( btnQuick2 = new QuickslotTool( 105, 7, 22, 24, 1)) ;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
add( pickedUp = new PickedUpItem() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void layout() {
|
|
|
|
btnWait.setPos( x, y );
|
|
|
|
btnSearch.setPos( btnWait.right(), y );
|
|
|
|
btnInfo.setPos( btnSearch.right(), y );
|
|
|
|
btnResume.setPos( btnInfo.right(), y );
|
|
|
|
btnQuick.setPos( width - btnQuick.width(), y );
|
2015-01-21 21:13:54 +00:00
|
|
|
btnQuick2.setPos( btnQuick.left() - btnQuick2.width(), y );
|
|
|
|
if (QuickSlots == 2){
|
|
|
|
btnQuick2.visible = btnQuick2.active = true;
|
|
|
|
btnInventory.setPos( btnQuick2.left() - btnInventory.width(), y );
|
|
|
|
} else {
|
|
|
|
btnQuick2.visible = btnQuick2.active = false;
|
|
|
|
btnInventory.setPos( btnQuick.left() - btnInventory.width(), y );
|
|
|
|
}
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
super.update();
|
|
|
|
|
|
|
|
if (lastEnabled != Dungeon.hero.ready) {
|
|
|
|
lastEnabled = Dungeon.hero.ready;
|
|
|
|
|
|
|
|
for (Gizmo tool : members) {
|
|
|
|
if (tool instanceof Tool) {
|
|
|
|
((Tool)tool).enable( lastEnabled );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
btnResume.visible = Dungeon.hero.lastAction != null;
|
|
|
|
|
|
|
|
if (!Dungeon.hero.isAlive()) {
|
|
|
|
btnInventory.enable( true );
|
|
|
|
}
|
2015-01-21 21:13:54 +00:00
|
|
|
|
|
|
|
//If we have 2 slots, and 2nd one isn't visible, or we have 1, and 2nd one is visible...
|
|
|
|
if ((QuickSlots == 1) == btnQuick2.visible){
|
|
|
|
layout();
|
|
|
|
}
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void pickup( Item item ) {
|
|
|
|
pickedUp.reset( item,
|
|
|
|
btnInventory.centerX(),
|
|
|
|
btnInventory.centerY() );
|
|
|
|
}
|
|
|
|
|
|
|
|
private static CellSelector.Listener informer = new CellSelector.Listener() {
|
|
|
|
@Override
|
|
|
|
public void onSelect( Integer cell ) {
|
|
|
|
|
|
|
|
if (cell == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell < 0 || cell > Level.LENGTH || (!Dungeon.level.visited[cell] && !Dungeon.level.mapped[cell])) {
|
|
|
|
GameScene.show( new WndMessage( "You don't know what is there." ) ) ;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Dungeon.visible[cell]) {
|
|
|
|
GameScene.show( new WndInfoCell( cell ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell == Dungeon.hero.pos) {
|
|
|
|
GameScene.show( new WndHero() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mob mob = (Mob)Actor.findChar( cell );
|
|
|
|
if (mob != null) {
|
|
|
|
GameScene.show( new WndInfoMob( mob ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Heap heap = Dungeon.level.heaps.get( cell );
|
|
|
|
if (heap != null) {
|
|
|
|
if (heap.type == Heap.Type.FOR_SALE && heap.size() == 1 && heap.peek().price() > 0) {
|
|
|
|
GameScene.show( new WndTradeItem( heap, false ) );
|
|
|
|
} else {
|
|
|
|
GameScene.show( new WndInfoItem( heap ) );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plant plant = Dungeon.level.plants.get( cell );
|
|
|
|
if (plant != null) {
|
|
|
|
GameScene.show( new WndInfoPlant( plant ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameScene.show( new WndInfoCell( cell ) );
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public String prompt() {
|
|
|
|
return "Select a cell to examine";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private static class Tool extends Button {
|
|
|
|
|
|
|
|
private static final int BGCOLOR = 0x7B8073;
|
|
|
|
|
|
|
|
private Image base;
|
|
|
|
|
|
|
|
public Tool( int x, int y, int width, int height ) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
base.frame( x, y, width, height );
|
|
|
|
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void createChildren() {
|
|
|
|
super.createChildren();
|
|
|
|
|
|
|
|
base = new Image( Assets.TOOLBAR );
|
|
|
|
add( base );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void layout() {
|
|
|
|
super.layout();
|
|
|
|
|
|
|
|
base.x = x;
|
|
|
|
base.y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onTouchDown() {
|
|
|
|
base.brightness( 1.4f );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onTouchUp() {
|
|
|
|
if (active) {
|
|
|
|
base.resetColor();
|
|
|
|
} else {
|
|
|
|
base.tint( BGCOLOR, 0.7f );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void enable( boolean value ) {
|
|
|
|
if (value != active) {
|
|
|
|
if (value) {
|
|
|
|
base.resetColor();
|
|
|
|
} else {
|
|
|
|
base.tint( BGCOLOR, 0.7f );
|
|
|
|
}
|
|
|
|
active = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class QuickslotTool extends Tool {
|
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
private QuickSlotButton slot;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
public QuickslotTool( int x, int y, int width, int height, int slotNum ) {
|
2014-07-27 13:39:07 +00:00
|
|
|
super( x, y, width, height );
|
2015-01-21 21:13:54 +00:00
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
slot = new QuickSlotButton( slotNum );
|
2014-07-27 13:39:07 +00:00
|
|
|
add( slot );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void layout() {
|
|
|
|
super.layout();
|
|
|
|
slot.setRect( x + 1, y + 2, width - 2, height - 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void enable( boolean value ) {
|
2015-01-21 21:13:54 +00:00
|
|
|
super.enable( value );
|
2014-07-27 13:39:07 +00:00
|
|
|
slot.enable( value );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class PickedUpItem extends ItemSprite {
|
|
|
|
|
|
|
|
private static final float DISTANCE = DungeonTilemap.SIZE;
|
|
|
|
private static final float DURATION = 0.2f;
|
|
|
|
|
|
|
|
private float dstX;
|
|
|
|
private float dstY;
|
|
|
|
private float left;
|
|
|
|
|
|
|
|
public PickedUpItem() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
originToCenter();
|
|
|
|
|
|
|
|
active =
|
|
|
|
visible =
|
|
|
|
false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reset( Item item, float dstX, float dstY ) {
|
|
|
|
view( item.image(), item.glowing() );
|
|
|
|
|
|
|
|
active =
|
|
|
|
visible =
|
|
|
|
true;
|
|
|
|
|
|
|
|
this.dstX = dstX - ItemSprite.SIZE / 2;
|
|
|
|
this.dstY = dstY - ItemSprite.SIZE / 2;
|
|
|
|
left = DURATION;
|
|
|
|
|
|
|
|
x = this.dstX - DISTANCE;
|
|
|
|
y = this.dstY - DISTANCE;
|
|
|
|
alpha( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
super.update();
|
|
|
|
|
|
|
|
if ((left -= Game.elapsed) <= 0) {
|
|
|
|
|
|
|
|
visible =
|
|
|
|
active =
|
|
|
|
false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
float p = left / DURATION;
|
|
|
|
scale.set( (float)Math.sqrt( p ) );
|
|
|
|
float offset = DISTANCE * p;
|
|
|
|
x = dstX - offset;
|
|
|
|
y = dstY - offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|