Magic_Ling_Pixel_Dungeon/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoItem.java

143 lines
5.3 KiB
Java
Raw Normal View History

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/>
*/
package com.shatteredpixel.shatteredpixeldungeon.windows;
2014-07-27 13:39:07 +00:00
2014-09-15 00:43:13 +00:00
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
2014-07-27 13:39:07 +00:00
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap.Type;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
2014-07-27 13:39:07 +00:00
public class WndInfoItem extends Window {
private static final String TTL_CHEST = "Chest";
private static final String TTL_LOCKED_CHEST = "Locked chest";
private static final String TTL_CRYSTAL_CHEST = "Crystal chest";
private static final String TTL_TOMB = "Tomb";
private static final String TTL_SKELETON = "Skeletal remains";
private static final String TTL_REMAINS = "Heroes remains";
2014-07-27 13:39:07 +00:00
private static final String TXT_WONT_KNOW = "You won't know what's inside until you open it!";
private static final String TXT_NEED_KEY = TXT_WONT_KNOW + " But to open it you need a golden key.";
private static final String TXT_INSIDE = "You can see %s inside, but to open the chest you need a golden key.";
private static final String TXT_OWNER =
"This ancient tomb may contain something useful, " +
"but its owner will most certainly object to checking.";
private static final String TXT_SKELETON =
"This is all that's left of some unfortunate adventurer. " +
"Maybe it's worth checking for any valuables.";
private static final String TXT_REMAINS =
2014-07-27 13:39:07 +00:00
"This is all that's left from one of your predecessors. " +
"Maybe it's worth checking for any valuables.";
private static final float GAP = 2;
private static final int WIDTH = 120;
public WndInfoItem( Heap heap ) {
super();
if (heap.type == Heap.Type.HEAP || heap.type == Heap.Type.FOR_SALE) {
Item item = heap.peek();
int color = TITLE_COLOR;
if (item.levelKnown && item.level > 0) {
color = ItemSlot.UPGRADED;
} else if (item.levelKnown && item.level < 0) {
color = ItemSlot.DEGRADED;
}
fillFields( item.image(), item.glowing(), color, item.toString(), item.info() );
} else {
String title;
String info;
2015-02-06 06:07:22 +00:00
if (heap.type == Type.CHEST || heap.type == Type.MIMIC) {
title = TTL_CHEST;
2014-07-27 13:39:07 +00:00
info = TXT_WONT_KNOW;
} else if (heap.type == Type.TOMB) {
title = TTL_TOMB;
2014-07-27 13:39:07 +00:00
info = TXT_OWNER;
} else if (heap.type == Type.SKELETON) {
title = TTL_SKELETON;
info = TXT_SKELETON;
} else if (heap.type == Type.REMAINS) {
title = TTL_REMAINS;
info = TXT_REMAINS;
2014-07-27 13:39:07 +00:00
} else if (heap.type == Type.CRYSTAL_CHEST) {
title = TTL_CRYSTAL_CHEST;
2014-09-15 00:43:13 +00:00
if (heap.peek() instanceof Artifact)
info = Utils.format( TXT_INSIDE, "an artifact" );
else if (heap.peek() instanceof Wand)
info = Utils.format( TXT_INSIDE, "a wand" );
else if (heap.peek() instanceof Ring)
info = Utils.format( TXT_INSIDE, "a ring" );
else
2014-09-15 00:43:13 +00:00
info = Utils.format( TXT_INSIDE, Utils.indefinite( heap.peek().name() ) );
2014-07-27 13:39:07 +00:00
} else {
title = TTL_LOCKED_CHEST;
2014-07-27 13:39:07 +00:00
info = TXT_NEED_KEY;
}
fillFields( heap.image(), heap.glowing(), TITLE_COLOR, title, info );
}
}
public WndInfoItem( Item item ) {
super();
int color = TITLE_COLOR;
if (item.levelKnown && item.level > 0) {
color = ItemSlot.UPGRADED;
} else if (item.levelKnown && item.level < 0) {
color = ItemSlot.DEGRADED;
}
fillFields( item.image(), item.glowing(), color, item.toString(), item.info() );
}
private void fillFields( int image, ItemSprite.Glowing glowing, int titleColor, String title, String info ) {
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( image, glowing ) );
titlebar.label( Utils.capitalize( title ), titleColor );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
BitmapTextMultiline txtInfo = PixelScene.createMultiline( info, 6 );
txtInfo.maxWidth = WIDTH;
txtInfo.measure();
txtInfo.x = titlebar.left();
txtInfo.y = titlebar.bottom() + GAP;
add( txtInfo );
resize( WIDTH, (int)(txtInfo.y + txtInfo.height()) );
}
}