v0.6.1: improved journal window code and items tab
This commit is contained in:
parent
3fccd85589
commit
41da332ef9
|
@ -38,6 +38,7 @@ import com.watabou.utils.Random;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class Ring extends KindofMisc {
|
||||
|
||||
|
@ -207,6 +208,14 @@ public class Ring extends KindofMisc {
|
|||
return this;
|
||||
}
|
||||
|
||||
public static HashSet<Class<? extends Ring>> getKnown() {
|
||||
return handler.known();
|
||||
}
|
||||
|
||||
public static HashSet<Class<? extends Ring>> getUnknown() {
|
||||
return handler.unknown();
|
||||
}
|
||||
|
||||
public static boolean allKnown() {
|
||||
return handler.known().size() == rings.length - 2;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndCatalogs;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.Gizmo;
|
||||
import com.watabou.noosa.Image;
|
||||
|
@ -122,13 +121,6 @@ public class Toolbar extends Component {
|
|||
GameScene.show(new WndBag(Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null));
|
||||
}
|
||||
|
||||
protected boolean onLongClick() {
|
||||
GameScene.show(new WndCatalogs());
|
||||
return true;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
super.createChildren();
|
||||
|
|
|
@ -1,218 +0,0 @@
|
|||
/*
|
||||
* Pixel Dungeon
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* Shattered Pixel Dungeon
|
||||
* Copyright (C) 2014-2017 Evan Debenham
|
||||
*
|
||||
* 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;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||
import com.watabou.noosa.ColorBlock;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class WndCatalogs extends WndTabbed {
|
||||
|
||||
private static final int WIDTH = 112;
|
||||
private static final int HEIGHT = 141;
|
||||
|
||||
private static final int ITEM_HEIGHT = 17;
|
||||
|
||||
private RedButton btnJournal;
|
||||
private RedButton btnTitle;
|
||||
private ScrollPane list;
|
||||
|
||||
private ArrayList<ListItem> items = new ArrayList<>();
|
||||
|
||||
private static boolean showPotions = true;
|
||||
|
||||
public WndCatalogs() {
|
||||
|
||||
super();
|
||||
|
||||
resize( WIDTH, HEIGHT );
|
||||
|
||||
btnJournal = new RedButton( Messages.get(WndJournal.class, "title"), 9 ){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
hide();
|
||||
GameScene.show(new WndJournal());
|
||||
}
|
||||
};
|
||||
btnJournal.setRect(0, 0, WIDTH/2f - 1, btnJournal.reqHeight());
|
||||
PixelScene.align( btnJournal );
|
||||
add( btnJournal );
|
||||
|
||||
//does nothing, we're already in the catalog
|
||||
btnTitle = new RedButton( Messages.get(this, "title"), 9 );
|
||||
btnTitle.textColor( Window.TITLE_COLOR );
|
||||
btnTitle.setRect(WIDTH/2f+1, 0, WIDTH/2f - 1, btnTitle.reqHeight());
|
||||
PixelScene.align(btnTitle);
|
||||
add( btnTitle );
|
||||
|
||||
list = new ScrollPane( new Component() ) {
|
||||
@Override
|
||||
public void onClick( float x, float y ) {
|
||||
int size = items.size();
|
||||
for (int i=0; i < size; i++) {
|
||||
if (items.get( i ).onClick( x, y )) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
add( list );
|
||||
list.setRect( 0, btnTitle.height() + 1, width, height - btnTitle.height() - 1 );
|
||||
|
||||
boolean showPotions = WndCatalogs.showPotions;
|
||||
Tab[] tabs = {
|
||||
new LabeledTab( Messages.get(this, "potions") ) {
|
||||
protected void select( boolean value ) {
|
||||
super.select( value );
|
||||
WndCatalogs.showPotions = value;
|
||||
updateList();
|
||||
};
|
||||
},
|
||||
new LabeledTab( Messages.get(this, "scrolls") ) {
|
||||
protected void select( boolean value ) {
|
||||
super.select( value );
|
||||
WndCatalogs.showPotions = !value;
|
||||
updateList();
|
||||
};
|
||||
}
|
||||
};
|
||||
for (Tab tab : tabs) {
|
||||
add( tab );
|
||||
}
|
||||
|
||||
layoutTabs();
|
||||
|
||||
select( showPotions ? 0 : 1 );
|
||||
}
|
||||
|
||||
private void updateList() {
|
||||
|
||||
items.clear();
|
||||
|
||||
Component content = list.content();
|
||||
content.clear();
|
||||
list.scrollTo( 0, 0 );
|
||||
|
||||
float pos = 0;
|
||||
for (Class<? extends Item> itemClass : showPotions ? Potion.getKnown() : Scroll.getKnown()) {
|
||||
ListItem item = new ListItem( itemClass );
|
||||
item.setRect( 0, pos, width, ITEM_HEIGHT );
|
||||
content.add( item );
|
||||
items.add( item );
|
||||
|
||||
pos += item.height();
|
||||
}
|
||||
|
||||
for (Class<? extends Item> itemClass : showPotions ? Potion.getUnknown() : Scroll.getUnknown()) {
|
||||
ListItem item = new ListItem( itemClass );
|
||||
item.setRect( 0, pos, width, ITEM_HEIGHT );
|
||||
content.add( item );
|
||||
items.add( item );
|
||||
|
||||
pos += item.height();
|
||||
}
|
||||
|
||||
content.setSize( width, pos );
|
||||
list.setSize( list.width(), list.height() );
|
||||
}
|
||||
|
||||
private static class ListItem extends Component {
|
||||
|
||||
private Item item;
|
||||
private boolean identified;
|
||||
|
||||
private ItemSprite sprite;
|
||||
private RenderedTextMultiline label;
|
||||
private ColorBlock line;
|
||||
|
||||
public ListItem( Class<? extends Item> cl ) {
|
||||
super();
|
||||
|
||||
try {
|
||||
item = cl.newInstance();
|
||||
if (identified = item.isIdentified()) {
|
||||
sprite.view( item.image(), null );
|
||||
label.text( Messages.titleCase(item.name()) );
|
||||
} else {
|
||||
sprite.view( ItemSpriteSheet.SOMETHING, null );
|
||||
label.text( Messages.titleCase(item.trueName()) );
|
||||
label.hardlight( 0xCCCCCC );
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ShatteredPixelDungeon.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
sprite = new ItemSprite();
|
||||
add( sprite );
|
||||
|
||||
label = PixelScene.renderMultiline( 7 );
|
||||
add( label );
|
||||
|
||||
line = new ColorBlock( 1, 1, 0xFF222222);
|
||||
add(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
sprite.y = y + 1 + (height - 1 - sprite.height) / 2f;
|
||||
PixelScene.align(sprite);
|
||||
|
||||
line.size(width, 1);
|
||||
line.x = 0;
|
||||
line.y = y;
|
||||
|
||||
label.maxWidth((int)(width - sprite.width - 1));
|
||||
label.setPos(sprite.x + sprite.width + 1, y + 1 + (height - 1 - label.height()) / 2f);
|
||||
PixelScene.align(label);
|
||||
}
|
||||
|
||||
public boolean onClick( float x, float y ) {
|
||||
if (inside( x, y )) {
|
||||
if (identified)
|
||||
GameScene.show( new WndInfoItem( item ) );
|
||||
else
|
||||
GameScene.show( new WndTitledMessage( new ItemSprite(ItemSpriteSheet.SOMETHING, null),
|
||||
Messages.titleCase(item.trueName()), item.desc() ));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,11 +24,13 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Journal;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
|
@ -45,6 +47,7 @@ import com.watabou.noosa.Image;
|
|||
import com.watabou.noosa.ui.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
//FIXME a lot of cleanup and improvements to do here
|
||||
|
@ -106,7 +109,72 @@ public class WndJournal extends WndTabbed {
|
|||
select(last_index);
|
||||
}
|
||||
|
||||
private static class Notes extends Component{
|
||||
private static class ListItem extends Component {
|
||||
|
||||
protected RenderedTextMultiline label;
|
||||
protected BitmapText depth;
|
||||
protected ColorBlock line;
|
||||
protected Image icon;
|
||||
|
||||
public ListItem( Image icon, String text ) {
|
||||
this(icon, text, -1);
|
||||
}
|
||||
|
||||
public ListItem( Image icon, String text, int d ) {
|
||||
super();
|
||||
|
||||
this.icon.copy(icon);
|
||||
|
||||
label.text( text );
|
||||
|
||||
if (d >= 0) {
|
||||
depth.text(Integer.toString(d));
|
||||
depth.measure();
|
||||
|
||||
if (d == Dungeon.depth) {
|
||||
label.hardlight(TITLE_COLOR);
|
||||
depth.hardlight(TITLE_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
label = PixelScene.renderMultiline( 7 );
|
||||
add( label );
|
||||
|
||||
icon = new Image();
|
||||
add( icon );
|
||||
|
||||
depth = new BitmapText( PixelScene.pixelFont);
|
||||
add( depth );
|
||||
|
||||
line = new ColorBlock( 1, 1, 0xFF222222);
|
||||
add(line);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
|
||||
icon.y = y + 1 + (height() - 1 - icon.height()) / 2f;
|
||||
PixelScene.align(icon);
|
||||
|
||||
depth.x = icon.x + (icon.width - depth.width()) / 2f;
|
||||
depth.y = icon.y + (icon.height - depth.height()) / 2f + 1;
|
||||
PixelScene.align(depth);
|
||||
|
||||
line.size(width, 1);
|
||||
line.x = 0;
|
||||
line.y = y;
|
||||
|
||||
label.maxWidth((int)(width - icon.width() - 8 - 1));
|
||||
label.setPos(icon.x + icon.width() + 1, y + 1 + (height() - label.height()) / 2f);
|
||||
PixelScene.align(label);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Notes extends Component {
|
||||
|
||||
private ScrollPane list;
|
||||
|
||||
|
@ -140,7 +208,7 @@ public class WndJournal extends WndTabbed {
|
|||
if (Dungeon.hero.belongings.specialKeys[i] > 1){
|
||||
text += " x" + Dungeon.hero.belongings.specialKeys[i];
|
||||
}
|
||||
ListItem item = new ListItem( Messages.titleCase(text), i );
|
||||
ListItem item = new ListItem( Icons.get(Icons.DEPTH), Messages.titleCase(text), i );
|
||||
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
|
||||
content.add( item );
|
||||
|
||||
|
@ -153,7 +221,7 @@ public class WndJournal extends WndTabbed {
|
|||
text += " x" + Dungeon.hero.belongings.ironKeys[i];
|
||||
}
|
||||
|
||||
ListItem item = new ListItem( text, i );
|
||||
ListItem item = new ListItem( Icons.get(Icons.DEPTH), text, i );
|
||||
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
|
||||
content.add( item );
|
||||
|
||||
|
@ -164,7 +232,7 @@ public class WndJournal extends WndTabbed {
|
|||
|
||||
//Journal entries
|
||||
for (Journal.Record rec : Journal.records) {
|
||||
ListItem item = new ListItem( rec.feature.desc(), rec.depth );
|
||||
ListItem item = new ListItem( Icons.get(Icons.DEPTH), rec.feature.desc(), rec.depth );
|
||||
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
|
||||
content.add( item );
|
||||
|
||||
|
@ -174,78 +242,19 @@ public class WndJournal extends WndTabbed {
|
|||
content.setSize( WIDTH, pos );
|
||||
}
|
||||
|
||||
private static class ListItem extends Component {
|
||||
|
||||
private RenderedTextMultiline label;
|
||||
private BitmapText depth;
|
||||
private ColorBlock line;
|
||||
private Image icon;
|
||||
|
||||
public ListItem( String text ) {
|
||||
this(text, -1);
|
||||
}
|
||||
|
||||
public ListItem( String text, int d ) {
|
||||
super();
|
||||
|
||||
label.text( text );
|
||||
|
||||
if (d >= 0) {
|
||||
depth.text(Integer.toString(d));
|
||||
depth.measure();
|
||||
|
||||
if (d == Dungeon.depth) {
|
||||
label.hardlight(TITLE_COLOR);
|
||||
depth.hardlight(TITLE_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
label = PixelScene.renderMultiline( 7 );
|
||||
add( label );
|
||||
|
||||
icon = Icons.get( Icons.DEPTH );
|
||||
add( icon );
|
||||
|
||||
depth = new BitmapText( PixelScene.pixelFont);
|
||||
add( depth );
|
||||
|
||||
line = new ColorBlock( 1, 1, 0xFF222222);
|
||||
add(line);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
|
||||
icon.y = y + 1 + (height() - 1 - icon.height()) / 2f;
|
||||
PixelScene.align(icon);
|
||||
|
||||
depth.x = icon.x + (icon.width - depth.width()) / 2f;
|
||||
depth.y = icon.y + (icon.height - depth.height()) / 2f + 1;
|
||||
PixelScene.align(depth);
|
||||
|
||||
line.size(width, 1);
|
||||
line.x = 0;
|
||||
line.y = y;
|
||||
|
||||
label.maxWidth((int)(width - icon.width() - 8 - 1));
|
||||
label.setPos(icon.x + icon.width() + 1, y + 1 + (height() - 1 - label.height()) / 2f);
|
||||
PixelScene.align(label);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Catalog extends Component{
|
||||
|
||||
private RedButton btnPotions;
|
||||
private RedButton btnScrolls;
|
||||
private RedButton btnRings;
|
||||
|
||||
private static int latestPressedIdx = 0;
|
||||
|
||||
private ScrollPane list;
|
||||
|
||||
private ArrayList<ListItem> items = new ArrayList<>();
|
||||
private ArrayList<CatalogItem> items = new ArrayList<>();
|
||||
|
||||
private static boolean showPotions = true;
|
||||
|
||||
|
@ -256,10 +265,8 @@ public class WndJournal extends WndTabbed {
|
|||
btnPotions = new RedButton( "" ){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
if (!showPotions){
|
||||
showPotions = true;
|
||||
updateList();
|
||||
}
|
||||
latestPressedIdx = 0;
|
||||
updateList();
|
||||
}
|
||||
};
|
||||
btnPotions.icon(new ItemSprite(ItemSpriteSheet.POTION_HOLDER, null));
|
||||
|
@ -268,15 +275,23 @@ public class WndJournal extends WndTabbed {
|
|||
btnScrolls = new RedButton( "" ){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
if (showPotions){
|
||||
showPotions = false;
|
||||
updateList();
|
||||
}
|
||||
latestPressedIdx = 1;
|
||||
updateList();
|
||||
}
|
||||
};
|
||||
btnScrolls.icon(new ItemSprite(ItemSpriteSheet.SCROLL_HOLDER, null));
|
||||
add( btnScrolls );
|
||||
|
||||
btnRings = new RedButton( "" ){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
latestPressedIdx = 2;
|
||||
updateList();
|
||||
}
|
||||
};
|
||||
btnRings.icon(new ItemSprite(ItemSpriteSheet.RING_HOLDER, null));
|
||||
add( btnRings );
|
||||
|
||||
list = new ScrollPane( new Component() ) {
|
||||
@Override
|
||||
public void onClick( float x, float y ) {
|
||||
|
@ -291,7 +306,7 @@ public class WndJournal extends WndTabbed {
|
|||
add( list );
|
||||
}
|
||||
|
||||
private static final int BUTTON_WIDTH = 55;
|
||||
private static final int BUTTON_WIDTH = 36;
|
||||
private static final int BUTTON_HEIGHT = 18;
|
||||
|
||||
@Override
|
||||
|
@ -301,102 +316,85 @@ public class WndJournal extends WndTabbed {
|
|||
btnPotions.setRect(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
PixelScene.align( btnPotions );
|
||||
|
||||
btnScrolls.setRect(width() - BUTTON_WIDTH, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
btnScrolls.setRect((width() - BUTTON_WIDTH)/2f, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
PixelScene.align(btnScrolls);
|
||||
|
||||
btnRings.setRect(width() - BUTTON_WIDTH, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
PixelScene.align(btnRings);
|
||||
|
||||
list.setRect( 0, btnPotions.height() + 1, width, height - btnPotions.height() - 1 );
|
||||
}
|
||||
|
||||
private void updateList() {
|
||||
|
||||
if (showPotions){
|
||||
btnPotions.textColor(TITLE_COLOR);
|
||||
btnScrolls.textColor(0xFFFFFF);
|
||||
} else {
|
||||
btnPotions.textColor(0xFFFFFF);
|
||||
btnScrolls.textColor(TITLE_COLOR);
|
||||
}
|
||||
|
||||
items.clear();
|
||||
|
||||
Component content = list.content();
|
||||
content.clear();
|
||||
list.scrollTo( 0, 0 );
|
||||
|
||||
float pos = 0;
|
||||
for (Class<? extends Item> itemClass : showPotions ? Potion.getKnown() : Scroll.getKnown()) {
|
||||
ListItem item = new ListItem( itemClass );
|
||||
item.setRect( 0, pos, width, ITEM_HEIGHT );
|
||||
content.add( item );
|
||||
items.add( item );
|
||||
|
||||
pos += item.height();
|
||||
ArrayList<Class<?>> itemClasses;
|
||||
if (latestPressedIdx == 0){
|
||||
itemClasses = new ArrayList<>(Arrays.asList(Generator.Category.POTION.classes));
|
||||
for ( Class unknown : Potion.getUnknown()){
|
||||
if (itemClasses.remove(unknown)) itemClasses.add(unknown);
|
||||
}
|
||||
} else if (latestPressedIdx == 1) {
|
||||
itemClasses = new ArrayList<>(Arrays.asList(Generator.Category.SCROLL.classes));
|
||||
for ( Class unknown : Scroll.getUnknown()){
|
||||
if (itemClasses.remove(unknown)) itemClasses.add(unknown);
|
||||
}
|
||||
} else {
|
||||
itemClasses = new ArrayList<>(Arrays.asList(Generator.Category.RING.classes));
|
||||
for ( Class unknown : Ring.getUnknown()){
|
||||
if (itemClasses.remove(unknown)) itemClasses.add(unknown);
|
||||
}
|
||||
}
|
||||
|
||||
for (Class<? extends Item> itemClass : showPotions ? Potion.getUnknown() : Scroll.getUnknown()) {
|
||||
ListItem item = new ListItem( itemClass );
|
||||
item.setRect( 0, pos, width, ITEM_HEIGHT );
|
||||
content.add( item );
|
||||
items.add( item );
|
||||
|
||||
pos += item.height();
|
||||
float pos = 0;
|
||||
for (Class<?> itemClass : itemClasses) {
|
||||
try{
|
||||
CatalogItem item = new CatalogItem((Item) itemClass.newInstance());
|
||||
item.setRect( 0, pos, width, ITEM_HEIGHT );
|
||||
content.add( item );
|
||||
items.add( item );
|
||||
|
||||
pos += item.height();
|
||||
} catch (Exception e) {
|
||||
ShatteredPixelDungeon.reportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
content.setSize( width, pos );
|
||||
list.setSize( list.width(), list.height() );
|
||||
}
|
||||
|
||||
private static class ListItem extends Component {
|
||||
private static class CatalogItem extends ListItem {
|
||||
|
||||
private Item item;
|
||||
private boolean identified;
|
||||
|
||||
private ItemSprite sprite;
|
||||
private RenderedTextMultiline label;
|
||||
private ColorBlock line;
|
||||
|
||||
public ListItem( Class<? extends Item> cl ) {
|
||||
super();
|
||||
public CatalogItem(Item item ) {
|
||||
super( new ItemSprite(item), Messages.titleCase(item.name()));
|
||||
|
||||
try {
|
||||
item = cl.newInstance();
|
||||
if (identified = item.isIdentified()) {
|
||||
sprite.view( item.image(), null );
|
||||
label.text( Messages.titleCase(item.name()) );
|
||||
this.item = item;
|
||||
|
||||
if (!(identified = item.isIdentified())) {
|
||||
ItemSprite placeHolder;
|
||||
if (item instanceof Potion){
|
||||
placeHolder = new ItemSprite( ItemSpriteSheet.POTION_HOLDER, null);
|
||||
} else if (item instanceof Scroll){
|
||||
placeHolder = new ItemSprite( ItemSpriteSheet.SCROLL_HOLDER, null);
|
||||
} else if (item instanceof Ring){
|
||||
placeHolder = new ItemSprite( ItemSpriteSheet.RING_HOLDER, null);
|
||||
} else {
|
||||
sprite.view( showPotions ? ItemSpriteSheet.POTION_HOLDER : ItemSpriteSheet.SCROLL_HOLDER, null );
|
||||
label.text( Messages.titleCase(item.trueName()) );
|
||||
label.hardlight( 0xCCCCCC );
|
||||
placeHolder = new ItemSprite( ItemSpriteSheet.SOMETHING, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ShatteredPixelDungeon.reportException(e);
|
||||
icon.copy( placeHolder );
|
||||
label.text( Messages.titleCase(item.trueName()) );
|
||||
label.hardlight( 0xCCCCCC );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
sprite = new ItemSprite();
|
||||
add( sprite );
|
||||
|
||||
label = PixelScene.renderMultiline( 7 );
|
||||
add( label );
|
||||
|
||||
line = new ColorBlock( 1, 1, 0xFF222222);
|
||||
add(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
sprite.y = y + 1 + (height - 1 - sprite.height) / 2f;
|
||||
PixelScene.align(sprite);
|
||||
|
||||
line.size(width, 1);
|
||||
line.x = 0;
|
||||
line.y = y;
|
||||
|
||||
label.maxWidth((int)(width - sprite.width - 1));
|
||||
label.setPos(sprite.x + sprite.width + 1, y + 1 + (height - 1 - label.height()) / 2f);
|
||||
PixelScene.align(label);
|
||||
}
|
||||
|
||||
public boolean onClick( float x, float y ) {
|
||||
|
@ -404,7 +402,7 @@ public class WndJournal extends WndTabbed {
|
|||
if (identified)
|
||||
GameScene.show( new WndInfoItem( item ) );
|
||||
else
|
||||
GameScene.show( new WndTitledMessage( new ItemSprite(showPotions ? ItemSpriteSheet.POTION_HOLDER : ItemSpriteSheet.SCROLL_HOLDER, null),
|
||||
GameScene.show(new WndTitledMessage( new Image(icon),
|
||||
Messages.titleCase(item.trueName()), item.desc() ));
|
||||
return true;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user