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-03-28 19:48:39 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
|
2014-07-27 13:39:07 +00:00
|
|
|
import com.watabou.noosa.Image;
|
|
|
|
import com.watabou.noosa.ui.Button;
|
2014-08-03 18:46:22 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
public class QuickSlotButton extends Button implements WndBag.Listener {
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
private static final String TXT_SELECT_ITEM = "Select an item for the quickslot";
|
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
private static QuickSlotButton[] instance = new QuickSlotButton[4];
|
|
|
|
private int slotNum;
|
2015-02-10 21:44:29 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
private ItemSlot slot;
|
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
private static Image crossB;
|
|
|
|
private static Image crossM;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
private static boolean targeting = false;
|
|
|
|
private static Char lastTarget= null;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
public QuickSlotButton( int slotNum ) {
|
2014-07-27 13:39:07 +00:00
|
|
|
super();
|
2015-01-20 22:26:53 +00:00
|
|
|
this.slotNum = slotNum;
|
|
|
|
item( select( slotNum ) );
|
2014-07-27 13:39:07 +00:00
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
instance[slotNum] = this;
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void destroy() {
|
|
|
|
super.destroy();
|
|
|
|
|
2015-02-11 04:38:49 +00:00
|
|
|
reset();
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
2015-02-11 04:38:49 +00:00
|
|
|
|
|
|
|
public static void reset() {
|
|
|
|
instance = new QuickSlotButton[4];
|
|
|
|
|
|
|
|
lastTarget = null;
|
|
|
|
}
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void createChildren() {
|
|
|
|
super.createChildren();
|
|
|
|
|
|
|
|
slot = new ItemSlot() {
|
|
|
|
@Override
|
|
|
|
protected void onClick() {
|
|
|
|
if (targeting) {
|
|
|
|
GameScene.handleCell( lastTarget.pos );
|
|
|
|
} else {
|
2015-01-20 22:26:53 +00:00
|
|
|
Item item = select(slotNum);
|
2015-03-28 19:48:39 +00:00
|
|
|
if (item instanceof EquipableItem)
|
2015-01-22 04:55:37 +00:00
|
|
|
useTargeting();
|
2014-07-27 13:39:07 +00:00
|
|
|
item.execute( Dungeon.hero );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
protected boolean onLongClick() {
|
2015-01-20 22:26:53 +00:00
|
|
|
return QuickSlotButton.this.onLongClick();
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
protected void onTouchDown() {
|
|
|
|
icon.lightness( 0.7f );
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
protected void onTouchUp() {
|
|
|
|
icon.resetColor();
|
|
|
|
}
|
|
|
|
};
|
2015-03-14 23:35:49 +00:00
|
|
|
slot.showParams( true, false, true );
|
2014-07-27 13:39:07 +00:00
|
|
|
add( slot );
|
|
|
|
|
|
|
|
crossB = Icons.TARGET.get();
|
|
|
|
crossB.visible = false;
|
|
|
|
add( crossB );
|
|
|
|
|
|
|
|
crossM = new Image();
|
|
|
|
crossM.copy( crossB );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void layout() {
|
|
|
|
super.layout();
|
|
|
|
|
|
|
|
slot.fill( this );
|
|
|
|
|
|
|
|
crossB.x = PixelScene.align( x + (width - crossB.width) / 2 );
|
|
|
|
crossB.y = PixelScene.align( y + (height - crossB.height) / 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onClick() {
|
|
|
|
GameScene.selectItem( this, WndBag.Mode.QUICKSLOT, TXT_SELECT_ITEM );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onLongClick() {
|
|
|
|
GameScene.selectItem( this, WndBag.Mode.QUICKSLOT, TXT_SELECT_ITEM );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
private static Item select(int slotNum){
|
|
|
|
return Dungeon.quickslot.getItem( slotNum );
|
|
|
|
}
|
2014-10-22 21:11:30 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
@Override
|
|
|
|
public void onSelect( Item item ) {
|
|
|
|
if (item != null) {
|
2015-01-20 22:26:53 +00:00
|
|
|
Dungeon.quickslot.setSlot( slotNum , item );
|
2014-07-27 13:39:07 +00:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void item( Item item ) {
|
|
|
|
slot.item( item );
|
|
|
|
enableSlot();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void enable( boolean value ) {
|
|
|
|
active = value;
|
|
|
|
if (value) {
|
|
|
|
enableSlot();
|
|
|
|
} else {
|
|
|
|
slot.enable( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enableSlot() {
|
2015-02-10 21:44:29 +00:00
|
|
|
slot.enable(Dungeon.quickslot.isNonePlaceholder( slotNum ));
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void useTargeting() {
|
|
|
|
|
|
|
|
targeting = lastTarget != null && lastTarget.isAlive() && Dungeon.visible[lastTarget.pos];
|
|
|
|
|
|
|
|
if (targeting) {
|
|
|
|
if (Actor.all().contains( lastTarget )) {
|
|
|
|
lastTarget.sprite.parent.add( crossM );
|
|
|
|
crossM.point( DungeonTilemap.tileToWorld( lastTarget.pos ) );
|
2015-01-22 04:55:37 +00:00
|
|
|
crossB.x = PixelScene.align( x + (width - crossB.width) / 2 );
|
|
|
|
crossB.y = PixelScene.align( y + (height - crossB.height) / 2 );
|
2014-07-27 13:39:07 +00:00
|
|
|
crossB.visible = true;
|
|
|
|
} else {
|
|
|
|
lastTarget = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void refresh() {
|
2015-01-20 22:26:53 +00:00
|
|
|
for (int i = 0; i < instance.length; i++) {
|
|
|
|
if (instance[i] != null) {
|
|
|
|
instance[i].item(select(i));
|
|
|
|
}
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 22:26:53 +00:00
|
|
|
public static void target( Char target ) {
|
|
|
|
if (target != Dungeon.hero) {
|
|
|
|
lastTarget = target;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
HealthIndicator.instance.target( target );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void cancel() {
|
2015-01-20 22:26:53 +00:00
|
|
|
if (targeting) {
|
|
|
|
crossB.visible = false;
|
|
|
|
crossM.remove();
|
|
|
|
targeting = false;
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|