v0.8.1: refactored item windows

This commit is contained in:
Evan Debenham 2020-06-16 15:38:02 -04:00
parent d75fa20337
commit 5db6795d54
12 changed files with 119 additions and 223 deletions

View File

@ -183,13 +183,11 @@ windows.wndstory.caves=These sparsely populated caves stretch down under the aba
windows.wndstory.city=The Dwarven Metropolis was once the greatest of all dwarven city-states. In its heyday the dwarves built wondrous machines of metal and magic that allowed their city to expand rapidly.\n\nThen, one day, the city gates were barred and nobody heard from the dwarves again. The few who escaped the city as it closed told stories of a mad warlock who stole the throne, and the terrible magic he had learned to harness. windows.wndstory.city=The Dwarven Metropolis was once the greatest of all dwarven city-states. In its heyday the dwarves built wondrous machines of metal and magic that allowed their city to expand rapidly.\n\nThen, one day, the city gates were barred and nobody heard from the dwarves again. The few who escaped the city as it closed told stories of a mad warlock who stole the throne, and the terrible magic he had learned to harness.
windows.wndstory.halls=These deep halls of the Dwarven Metropolis have been twisted by dark magic. In the past these regions played host to the Dwarf King's court of elite warlocks, but now they seem to have been taken over by something even more sinister...\n\nAll sorts of horrific demonic creatures inhabit these halls, being lead by some terrible dark power. If the King of Dwarves wasn't the source of the spreading corruption, whatever is down here must be.\n\nTread carefully, very few adventurers have ever descended this far... windows.wndstory.halls=These deep halls of the Dwarven Metropolis have been twisted by dark magic. In the past these regions played host to the Dwarf King's court of elite warlocks, but now they seem to have been taken over by something even more sinister...\n\nAll sorts of horrific demonic creatures inhabit these halls, being lead by some terrible dark power. If the King of Dwarves wasn't the source of the spreading corruption, whatever is down here must be.\n\nTread carefully, very few adventurers have ever descended this far...
windows.wndtradeitem.sale=FOR SALE: %1$s - %2$dg
windows.wndtradeitem.buy=Buy for %dg windows.wndtradeitem.buy=Buy for %dg
windows.wndtradeitem.steal=Steal with %d%% chance windows.wndtradeitem.steal=Steal with %d%% chance
windows.wndtradeitem.sell=Sell for %dg windows.wndtradeitem.sell=Sell for %dg
windows.wndtradeitem.sell_1=Sell 1 for %dg windows.wndtradeitem.sell_1=Sell 1 for %dg
windows.wndtradeitem.sell_all=Sell all for %dg windows.wndtradeitem.sell_all=Sell all for %dg
windows.wndtradeitem.cancel=Never mind
windows.wndwandmaker.dust=Oh, I see you have the dust! Don't worry about the wraiths, I can deal with them. As I promised, you can choose one of my high quality wands. windows.wndwandmaker.dust=Oh, I see you have the dust! Don't worry about the wraiths, I can deal with them. As I promised, you can choose one of my high quality wands.
windows.wndwandmaker.ember=Oh, I see you have the embers! I do hope the fire elemental wasn't too much trouble. As I promised, you can choose one of my high quality wands. windows.wndwandmaker.ember=Oh, I see you have the embers! I do hope the fire elemental wasn't too much trouble. As I promised, you can choose one of my high quality wands.

View File

@ -680,7 +680,7 @@ public class Hero extends Char {
Game.runOnRenderThread(new Callback() { Game.runOnRenderThread(new Callback() {
@Override @Override
public void call() { public void call() {
GameScene.show( new WndTradeItem( heap, true ) ); GameScene.show( new WndTradeItem( heap ) );
} }
}); });
} }

View File

@ -31,7 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import java.util.ArrayList; import java.util.ArrayList;
@ -69,7 +69,7 @@ public class BrokenSeal extends Item {
curItem = this; curItem = this;
GameScene.selectItem(armorSelector, WndBag.Mode.ARMOR, Messages.get(this, "prompt")); GameScene.selectItem(armorSelector, WndBag.Mode.ARMOR, Messages.get(this, "prompt"));
} else if (action.equals(AC_INFO)) { } else if (action.equals(AC_INFO)) {
GameScene.show(new WndItem(null, this, true)); GameScene.show(new WndUseItem(null, this));
} }
} }

View File

@ -61,7 +61,7 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.IconTitle; import com.shatteredpixel.shatteredpixeldungeon.windows.IconTitle;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBlacksmith; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBlacksmith;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest; import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
@ -127,7 +127,7 @@ public class DriedRose extends Artifact {
if (action.equals(AC_SUMMON)) { if (action.equals(AC_SUMMON)) {
if (!Ghost.Quest.completed()) GameScene.show(new WndItem(null, this, true)); if (!Ghost.Quest.completed()) GameScene.show(new WndUseItem(null, this));
else if (ghost != null) GLog.i( Messages.get(this, "spawned") ); else if (ghost != null) GLog.i( Messages.get(this, "spawned") );
else if (!isEquipped( hero )) GLog.i( Messages.get(Artifact.class, "need_to_equip") ); else if (!isEquipped( hero )) GLog.i( Messages.get(Artifact.class, "need_to_equip") );
else if (charge != chargeCap) GLog.i( Messages.get(this, "no_charge") ); else if (charge != chargeCap) GLog.i( Messages.get(this, "no_charge") );

View File

@ -67,7 +67,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
@ -246,7 +246,7 @@ public class Potion extends Item {
if (action.equals( AC_CHOOSE )){ if (action.equals( AC_CHOOSE )){
GameScene.show(new WndItem(null, this, true) ); GameScene.show(new WndUseItem(null, this) );
} else if (action.equals( AC_DRINK )) { } else if (action.equals( AC_DRINK )) {

View File

@ -43,7 +43,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter; import com.watabou.noosa.particles.Emitter;
@ -124,7 +124,7 @@ public class MagesStaff extends MeleeWeapon {
} else if (action.equals(AC_ZAP)){ } else if (action.equals(AC_ZAP)){
if (wand == null) { if (wand == null) {
GameScene.show(new WndItem(null, this, true)); GameScene.show(new WndUseItem(null, this));
return; return;
} }

View File

@ -1114,12 +1114,7 @@ public class GameScene extends PixelScene {
} else if ( o instanceof Mob ){ } else if ( o instanceof Mob ){
GameScene.show(new WndInfoMob((Mob) o)); GameScene.show(new WndInfoMob((Mob) o));
} else if ( o instanceof Heap ){ } else if ( o instanceof Heap ){
Heap heap = (Heap)o; GameScene.show(new WndInfoItem((Heap)o));
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));
}
} else if ( o instanceof Plant ){ } else if ( o instanceof Plant ){
GameScene.show( new WndInfoPlant((Plant) o) ); GameScene.show( new WndInfoPlant((Plant) o) );
} else if ( o instanceof Trap ){ } else if ( o instanceof Trap ){

View File

@ -48,7 +48,6 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.SpiritBow;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant.Seed;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
@ -452,7 +451,7 @@ public class WndBag extends WndTabbed {
} else { } else {
Game.scene().addToFront(new WndItem( WndBag.this, item ) ); Game.scene().addToFront(new WndUseItem( WndBag.this, item ) );
} }
} }

View File

@ -32,8 +32,8 @@ public class WndInfoItem extends Window {
private static final float GAP = 2; private static final float GAP = 2;
private static final int WIDTH_P = 120; private static final int WIDTH_MIN = 120;
private static final int WIDTH_L = 144; private static final int WIDTH_MAX = 220;
public WndInfoItem( Heap heap ) { public WndInfoItem( Heap heap ) {
@ -56,19 +56,12 @@ public class WndInfoItem extends Window {
private void fillFields( Heap heap ) { private void fillFields( Heap heap ) {
int width = PixelScene.landscape() ? WIDTH_L : WIDTH_P;
IconTitle titlebar = new IconTitle( heap ); IconTitle titlebar = new IconTitle( heap );
titlebar.color( TITLE_COLOR ); titlebar.color( TITLE_COLOR );
titlebar.setRect( 0, 0, width, 0 );
add( titlebar );
RenderedTextBlock txtInfo = PixelScene.renderTextBlock( heap.info(), 6 ); RenderedTextBlock txtInfo = PixelScene.renderTextBlock( heap.info(), 6 );
txtInfo.maxWidth(width);
txtInfo.setPos(titlebar.left(), titlebar.bottom() + GAP);
add( txtInfo );
resize( width, (int)(txtInfo.bottom() + 2) ); layoutFields(titlebar, txtInfo);
} }
private void fillFields( Item item ) { private void fillFields( Item item ) {
@ -80,18 +73,33 @@ public class WndInfoItem extends Window {
color = ItemSlot.DEGRADED; color = ItemSlot.DEGRADED;
} }
int width = PixelScene.landscape() ? WIDTH_L : WIDTH_P;
IconTitle titlebar = new IconTitle( item ); IconTitle titlebar = new IconTitle( item );
titlebar.color( color ); titlebar.color( color );
titlebar.setRect( 0, 0, width, 0 );
add( titlebar );
RenderedTextBlock txtInfo = PixelScene.renderTextBlock( item.info(), 6 ); RenderedTextBlock txtInfo = PixelScene.renderTextBlock( item.info(), 6 );
txtInfo.maxWidth(width);
txtInfo.setPos(titlebar.left(), titlebar.bottom() + GAP);
add( txtInfo );
resize( width, (int)(txtInfo.bottom() + 2) ); layoutFields(titlebar, txtInfo);
}
private void layoutFields(IconTitle title, RenderedTextBlock info){
int width = WIDTH_MIN;
info.maxWidth(width);
//window can go out of the screen on landscape, so widen it as appropriate
while (PixelScene.landscape()
&& info.height() > 100
&& width < WIDTH_MAX){
width += 20;
info.maxWidth(width);
}
title.setRect( 0, 0, width, 0 );
add( title );
info.setPos(title.left(), title.bottom() + GAP);
add( info );
resize( width, (int)(info.bottom() + 2) );
} }
} }

View File

@ -359,7 +359,7 @@ public class WndRanking extends WndTabbed {
@Override @Override
protected void onClick() { protected void onClick() {
Game.scene().add( new WndItem( null, item ) ); Game.scene().add( new WndInfoItem( item ) );
} }
} }
@ -403,7 +403,7 @@ public class WndRanking extends WndTabbed {
@Override @Override
protected void onClick() { protected void onClick() {
Game.scene().add(new WndItem(null, item)); Game.scene().add(new WndInfoItem(item));
} }
} }
} }

View File

@ -35,24 +35,22 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot; import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndTradeItem extends Window { public class WndTradeItem extends WndInfoItem {
private static final float GAP = 2; private static final float GAP = 2;
private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 16; private static final int BTN_HEIGHT = 16;
private WndBag owner; private WndBag owner;
//selling
public WndTradeItem( final Item item, WndBag owner ) { public WndTradeItem( final Item item, WndBag owner ) {
super(); super(item);
this.owner = owner; this.owner = owner;
float pos = createDescription( item, false ); float pos = height;
if (item.quantity() == 1) { if (item.quantity() == 1) {
@ -63,7 +61,7 @@ public class WndTradeItem extends Window {
hide(); hide();
} }
}; };
btnSell.setRect( 0, pos + GAP, WIDTH, BTN_HEIGHT ); btnSell.setRect( 0, pos + GAP, width, BTN_HEIGHT );
add( btnSell ); add( btnSell );
pos = btnSell.bottom(); pos = btnSell.bottom();
@ -78,7 +76,7 @@ public class WndTradeItem extends Window {
hide(); hide();
} }
}; };
btnSell1.setRect( 0, pos + GAP, WIDTH, BTN_HEIGHT ); btnSell1.setRect( 0, pos + GAP, width, BTN_HEIGHT );
add( btnSell1 ); add( btnSell1 );
RedButton btnSellAll = new RedButton( Messages.get(this, "sell_all", priceAll ) ) { RedButton btnSellAll = new RedButton( Messages.get(this, "sell_all", priceAll ) ) {
@Override @Override
@ -87,97 +85,74 @@ public class WndTradeItem extends Window {
hide(); hide();
} }
}; };
btnSellAll.setRect( 0, btnSell1.bottom() + GAP, WIDTH, BTN_HEIGHT ); btnSellAll.setRect( 0, btnSell1.bottom() + 1, width, BTN_HEIGHT );
add( btnSellAll ); add( btnSellAll );
pos = btnSellAll.bottom(); pos = btnSellAll.bottom();
} }
RedButton btnCancel = new RedButton( Messages.get(this, "cancel") ) { resize( width, (int)pos );
@Override
protected void onClick() {
hide();
}
};
btnCancel.setRect( 0, pos + GAP, WIDTH, BTN_HEIGHT );
add( btnCancel );
resize( WIDTH, (int)btnCancel.bottom() );
} }
public WndTradeItem( final Heap heap, boolean canBuy ) { //buying
public WndTradeItem( final Heap heap ) {
super(); super(heap);
Item item = heap.peek(); Item item = heap.peek();
float pos = createDescription( item, true ); float pos = height;
final int price = price( item ); final int price = price( item );
if (canBuy) { RedButton btnBuy = new RedButton( Messages.get(this, "buy", price) ) {
@Override
protected void onClick() {
hide();
buy( heap );
}
};
btnBuy.setRect( 0, pos + GAP, width, BTN_HEIGHT );
btnBuy.enable( price <= Dungeon.gold );
add( btnBuy );
RedButton btnBuy = new RedButton( Messages.get(this, "buy", price) ) { pos = btnBuy.bottom();
final MasterThievesArmband.Thievery thievery = Dungeon.hero.buff(MasterThievesArmband.Thievery.class);
if (thievery != null && !thievery.isCursed()) {
final float chance = thievery.stealChance(price);
RedButton btnSteal = new RedButton(Messages.get(this, "steal", Math.min(100, (int) (chance * 100)))) {
@Override @Override
protected void onClick() { protected void onClick() {
hide(); if (thievery.steal(price)) {
buy( heap ); Hero hero = Dungeon.hero;
} Item item = heap.pickUp();
}; hide();
btnBuy.setRect( 0, pos + GAP, WIDTH, BTN_HEIGHT );
btnBuy.enable( price <= Dungeon.gold );
add( btnBuy );
RedButton btnCancel = new RedButton( Messages.get(this, "cancel") ) { if (!item.doPickUp(hero)) {
@Override Dungeon.level.drop(item, heap.pos).sprite.drop();
protected void onClick() {
hide();
}
};
final MasterThievesArmband.Thievery thievery = Dungeon.hero.buff(MasterThievesArmband.Thievery.class);
if (thievery != null && !thievery.isCursed()) {
final float chance = thievery.stealChance(price);
RedButton btnSteal = new RedButton( Messages.get(this, "steal", Math.min(100, (int)(chance*100)))) {
@Override
protected void onClick() {
if(thievery.steal(price)){
Hero hero = Dungeon.hero;
Item item = heap.pickUp();
hide();
if (!item.doPickUp( hero )) {
Dungeon.level.drop( item, heap.pos ).sprite.drop();
}
} else {
for (Mob mob : Dungeon.level.mobs){
if (mob instanceof Shopkeeper) {
mob.yell(Messages.get(mob, "thief"));
((Shopkeeper) mob).flee();
break;
}
}
hide();
} }
} else {
for (Mob mob : Dungeon.level.mobs) {
if (mob instanceof Shopkeeper) {
mob.yell(Messages.get(mob, "thief"));
((Shopkeeper) mob).flee();
break;
}
}
hide();
} }
}; }
btnSteal.setRect(0, btnBuy.bottom() + GAP, WIDTH, BTN_HEIGHT); };
add(btnSteal); btnSteal.setRect(0, pos + 1, width, BTN_HEIGHT);
add(btnSteal);
btnCancel.setRect( 0, btnSteal.bottom() + GAP, WIDTH, BTN_HEIGHT ); pos = btnSteal.bottom();
} else
btnCancel.setRect( 0, btnBuy.bottom() + GAP, WIDTH, BTN_HEIGHT );
add( btnCancel );
resize( WIDTH, (int)btnCancel.bottom() );
} else {
resize( WIDTH, (int)pos );
} }
resize(width, (int) pos);
} }
@Override @Override
@ -191,35 +166,6 @@ public class WndTradeItem extends Window {
} }
} }
private float createDescription( Item item, boolean forSale ) {
// Title
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( item ) );
titlebar.label( forSale ?
Messages.get(this, "sale", item.toString(), price( item ) ) :
Messages.titleCase( item.toString() ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
// Upgraded / degraded
if (item.levelKnown) {
if (item.level() < 0) {
titlebar.color( ItemSlot.DEGRADED );
} else if (item.level() > 0) {
titlebar.color( ItemSlot.UPGRADED );
}
}
// Description
RenderedTextBlock info = PixelScene.renderTextBlock( item.info(), 6 );
info.maxWidth(WIDTH);
info.setPos(titlebar.left(), titlebar.bottom() + GAP);
add( info );
return info.bottom();
}
private void sell( Item item ) { private void sell( Item item ) {
Hero hero = Dungeon.hero; Hero hero = Dungeon.hero;

View File

@ -24,71 +24,33 @@ 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.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
public class WndItem extends Window { public class WndUseItem extends WndInfoItem {
//only one wnditem can appear at a time //only one wnduseitem can appear at a time
private static WndItem INSTANCE; private static WndUseItem INSTANCE;
private static final float BUTTON_HEIGHT = 16; private static final float BUTTON_HEIGHT = 16;
private static final float GAP = 2; private static final float GAP = 2;
private static final int WIDTH_MIN = 120; public WndUseItem(final WndBag owner, final Item item ) {
private static final int WIDTH_MAX = 220;
public WndItem( final WndBag owner, final Item item ){ super(item);
this( owner, item, owner != null );
}
public WndItem( final WndBag owner, final Item item , final boolean options ) {
super();
if( INSTANCE != null ){ if( INSTANCE != null ){
INSTANCE.hide(); INSTANCE.hide();
} }
INSTANCE = this; INSTANCE = this;
int width = WIDTH_MIN; float y = height + GAP;
RenderedTextBlock info = PixelScene.renderTextBlock( item.info(), 6 ); if (Dungeon.hero.isAlive()) {
info.maxWidth(width);
//info box can go out of the screen on landscape, so widen it
while (PixelScene.landscape()
&& info.height() > 100
&& width < WIDTH_MAX){
width += 20;
info.maxWidth(width);
}
IconTitle titlebar = new IconTitle( item );
titlebar.setRect( 0, 0, width, 0 );
add( titlebar );
if (item.levelKnown && item.level() > 0) {
titlebar.color( ItemSlot.UPGRADED );
} else if (item.levelKnown && item.level() < 0) {
titlebar.color( ItemSlot.DEGRADED );
}
info.setPos(titlebar.left(), titlebar.bottom() + GAP);
add( info );
float y = info.top() + info.height() + GAP;
if (Dungeon.hero.isAlive() && options) {
ArrayList<RedButton> buttons = new ArrayList<>(); ArrayList<RedButton> buttons = new ArrayList<>();
for (final String action:item.actions( Dungeon.hero )) { for (final String action : item.actions( Dungeon.hero )) {
RedButton btn = new RedButton( Messages.get(item, "ac_" + action), 8 ) { RedButton btn = new RedButton( Messages.get(item, "ac_" + action), 8 ) {
@Override @Override
@ -210,16 +172,4 @@ public class WndItem extends Window {
} }
} }
private static Comparator<RedButton> widthComparator = new Comparator<RedButton>() {
@Override
public int compare(RedButton lhs, RedButton rhs) {
if (lhs.width() < rhs.width()){
return -1;
} else if (lhs.width() == rhs.width()){
return 0;
} else {
return 1;
}
}
};
} }