v0.9.3b: added a quick-use inventory window
This commit is contained in:
parent
57d9f7ffad
commit
85e5e1a12e
|
@ -27,7 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuickBag;
|
||||||
import com.watabou.utils.Bundlable;
|
import com.watabou.utils.Bundlable;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class Bag extends Item implements Iterable<Item> {
|
||||||
|
|
||||||
if (action.equals( AC_OPEN )) {
|
if (action.equals( AC_OPEN )) {
|
||||||
|
|
||||||
GameScene.show( new WndBag( this, null, WndBag.Mode.ALL, null ) );
|
GameScene.show( new WndQuickBag( this ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap;
|
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuickBag;
|
||||||
import com.watabou.input.GameAction;
|
import com.watabou.input.GameAction;
|
||||||
import com.watabou.noosa.Camera;
|
import com.watabou.noosa.Camera;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
|
@ -153,8 +153,7 @@ public class Toolbar extends Component {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onLongClick() {
|
protected boolean onLongClick() {
|
||||||
WndJournal.last_index = 3; //catalog page
|
GameScene.show(new WndQuickBag(null));
|
||||||
GameScene.show(new WndJournal());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||||
import com.watabou.gltextures.TextureCache;
|
import com.watabou.gltextures.TextureCache;
|
||||||
import com.watabou.input.KeyBindings;
|
import com.watabou.input.KeyBindings;
|
||||||
import com.watabou.input.KeyEvent;
|
import com.watabou.input.KeyEvent;
|
||||||
|
@ -68,8 +69,8 @@ import com.watabou.noosa.audio.Sample;
|
||||||
|
|
||||||
public class WndBag extends WndTabbed {
|
public class WndBag extends WndTabbed {
|
||||||
|
|
||||||
//only one wnditem can appear at a time
|
//only one bag window can appear at a time
|
||||||
private static WndBag INSTANCE;
|
public static Window INSTANCE;
|
||||||
|
|
||||||
//FIXME this is getting cumbersome, there should be a better way to manage this
|
//FIXME this is getting cumbersome, there should be a better way to manage this
|
||||||
public static enum Mode {
|
public static enum Mode {
|
||||||
|
|
|
@ -0,0 +1,224 @@
|
||||||
|
package com.shatteredpixel.shatteredpixeldungeon.windows;
|
||||||
|
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.CloakOfShadows;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.messages.Languages;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||||
|
import com.watabou.gltextures.TextureCache;
|
||||||
|
import com.watabou.noosa.ColorBlock;
|
||||||
|
import com.watabou.noosa.Game;
|
||||||
|
import com.watabou.noosa.audio.Sample;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class WndQuickBag extends Window {
|
||||||
|
|
||||||
|
public WndQuickBag(Bag bag){
|
||||||
|
super(0, 0, 0, Chrome.get(Chrome.Type.TOAST_TR));
|
||||||
|
|
||||||
|
if( WndBag.INSTANCE != null ){
|
||||||
|
WndBag.INSTANCE.hide();
|
||||||
|
}
|
||||||
|
WndBag.INSTANCE = this;
|
||||||
|
|
||||||
|
float width = 0, height = 0;
|
||||||
|
int maxWidth = PixelScene.landscape() ? 240 : 135;
|
||||||
|
int left = 0;
|
||||||
|
int top = 10;
|
||||||
|
|
||||||
|
ArrayList<Item> items = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Item i : bag == null ? Dungeon.hero.belongings : bag){
|
||||||
|
if (i.defaultAction == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i instanceof Bag) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i instanceof Artifact
|
||||||
|
&& !i.isEquipped(Dungeon.hero)
|
||||||
|
&& (!(i instanceof CloakOfShadows) || !Dungeon.hero.hasTalent(Talent.LIGHT_CLOAK))){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
items.add(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(items, quickBagComparator);
|
||||||
|
|
||||||
|
if (items.isEmpty()){
|
||||||
|
hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int btnWidth = 16;
|
||||||
|
int btnHeight = 20;
|
||||||
|
|
||||||
|
//height of the toolbar and status pane, plus a little extra
|
||||||
|
int targetHeight = PixelScene.uiCamera.height - 100;
|
||||||
|
int rows = (int)Math.ceil(items.size() / (float)((maxWidth+1) / (btnWidth+1)));
|
||||||
|
int expectedHeight = rows * btnHeight + (rows-1);
|
||||||
|
while (expectedHeight > targetHeight && btnHeight > 16){
|
||||||
|
btnHeight--;
|
||||||
|
expectedHeight -= rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Item i : items){
|
||||||
|
QuickItemButton btn = new QuickItemButton(i);
|
||||||
|
btn.setRect(left, top, btnWidth, btnHeight);
|
||||||
|
add(btn);
|
||||||
|
|
||||||
|
if (width < btn.right()) width = btn.right();
|
||||||
|
if (height < btn.bottom()) height = btn.bottom();
|
||||||
|
|
||||||
|
left += btnWidth+1;
|
||||||
|
|
||||||
|
if (left + btnWidth > maxWidth){
|
||||||
|
left = 0;
|
||||||
|
top += btnHeight+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO translate this!
|
||||||
|
RenderedTextBlock txtTitle;
|
||||||
|
if ( Messages.lang() == Languages.ENGLISH){
|
||||||
|
txtTitle = PixelScene.renderTextBlock( "Quick-use an Item", 8 );
|
||||||
|
} else {
|
||||||
|
txtTitle = PixelScene.renderTextBlock( Messages.titleCase(bag != null ? bag.name() : Dungeon.hero.belongings.backpack.name()), 8 );
|
||||||
|
}
|
||||||
|
txtTitle.hardlight( TITLE_COLOR );
|
||||||
|
if (txtTitle.width() > width) width = txtTitle.width();
|
||||||
|
|
||||||
|
txtTitle.setPos(
|
||||||
|
(width - txtTitle.width())/2f,
|
||||||
|
(10 - txtTitle.height()) / 2f - 1);
|
||||||
|
PixelScene.align(txtTitle);
|
||||||
|
add( txtTitle );
|
||||||
|
|
||||||
|
resize((int)width, (int)height);
|
||||||
|
|
||||||
|
int bottom = GameScene.uiCamera.height;
|
||||||
|
|
||||||
|
//offset to be above the toolbar
|
||||||
|
offset((int) (bottom/2 - 30 - height/2));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Comparator<Item> quickBagComparator = new Comparator<Item>() {
|
||||||
|
@Override
|
||||||
|
public int compare( Item lhs, Item rhs ) {
|
||||||
|
if (lhs.isEquipped(Dungeon.hero) && !rhs.isEquipped(Dungeon.hero)){
|
||||||
|
return -1;
|
||||||
|
} else if (!lhs.isEquipped(Dungeon.hero) && rhs.isEquipped(Dungeon.hero)){
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return Generator.Category.order(lhs) - Generator.Category.order(rhs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hide() {
|
||||||
|
super.hide();
|
||||||
|
if (WndBag.INSTANCE == this){
|
||||||
|
WndBag.INSTANCE = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class QuickItemButton extends ItemSlot {
|
||||||
|
|
||||||
|
private static final int NORMAL = 0x9953564D;
|
||||||
|
private static final int EQUIPPED = 0x9991938C;
|
||||||
|
private Item item;
|
||||||
|
private ColorBlock bg;
|
||||||
|
|
||||||
|
public QuickItemButton(Item item) {
|
||||||
|
|
||||||
|
super(item);
|
||||||
|
showExtraInfo(false);
|
||||||
|
|
||||||
|
this.item = item;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createChildren() {
|
||||||
|
bg = new ColorBlock(1, 1, NORMAL);
|
||||||
|
add(bg);
|
||||||
|
|
||||||
|
super.createChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void layout() {
|
||||||
|
bg.size(width, height);
|
||||||
|
bg.x = x;
|
||||||
|
bg.y = y;
|
||||||
|
|
||||||
|
super.layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void item(Item item) {
|
||||||
|
|
||||||
|
super.item(item);
|
||||||
|
if (item != null) {
|
||||||
|
|
||||||
|
bg.texture( TextureCache.createSolid( item.isEquipped( Dungeon.hero ) ? EQUIPPED : NORMAL ) );
|
||||||
|
if (item.cursed && item.cursedKnown) {
|
||||||
|
bg.ra = +0.3f;
|
||||||
|
bg.ga = -0.15f;
|
||||||
|
} else if (!item.isIdentified()) {
|
||||||
|
if ((item instanceof EquipableItem || item instanceof Wand) && item.cursedKnown) {
|
||||||
|
bg.ba = 0.3f;
|
||||||
|
} else {
|
||||||
|
bg.ra = 0.3f;
|
||||||
|
bg.ba = 0.3f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
bg.color(NORMAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPointerDown() {
|
||||||
|
bg.brightness(1.5f);
|
||||||
|
Sample.INSTANCE.play(Assets.Sounds.CLICK, 0.7f, 0.7f, 1.2f);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onPointerUp() {
|
||||||
|
bg.brightness(1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
hide();
|
||||||
|
item.execute(Dungeon.hero); //TODO targeting?
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean onLongClick() {
|
||||||
|
Game.scene().addToFront(new WndUseItem(WndQuickBag.this, item));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class WndUseItem extends WndInfoItem {
|
||||||
|
|
||||||
private static final float GAP = 2;
|
private static final float GAP = 2;
|
||||||
|
|
||||||
public WndUseItem(final WndBag owner, final Item item ) {
|
public WndUseItem( final Window owner, final Item item ) {
|
||||||
|
|
||||||
super(item);
|
super(item);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user