v0.6.1: Journal interface redesign pt.1

- moved catalogs and notes into one window, added tab for guide
This commit is contained in:
Evan Debenham 2017-07-06 01:37:04 -04:00
parent a8b3b76053
commit 3fccd85589
2 changed files with 389 additions and 137 deletions

View File

@ -65,15 +65,26 @@ public class RedButton extends Button {
bg.y = y;
bg.size( width, height );
text.x = x + (width - text.width()) / 2;
text.y = y + (height - text.baseLine()) / 2;
PixelScene.align(text);
float componentWidth = 0;
if (icon != null) componentWidth += icon.width() + 2;
if (text != null && !text.text().equals("")){
componentWidth += text.width() + 2;
text.x = x + (width() - componentWidth)/2f + 1;
text.y = y + (height() - text.baseLine()) / 2f;
PixelScene.align(text);
}
if (icon != null) {
icon.x = x + text.x - icon.width() - 2;
icon.y = y + (height - icon.height()) / 2;
icon.x = x + (width() + componentWidth)/2f - icon.width() - 1;
icon.y = y + (height() - icon.height()) / 2f;
PixelScene.align(icon);
}
}
@Override
@ -113,10 +124,24 @@ public class RedButton extends Button {
}
public float reqWidth() {
return text.width() + 2f;
float reqWidth = 0;
if (icon != null){
reqWidth += icon.width() + 2;
}
if (text != null && !text.text().equals("")){
reqWidth += text.width() + 2;
}
return reqWidth;
}
public float reqHeight() {
return text.baseLine() + 4;
float reqHeight = 0;
if (icon != null){
reqHeight = Math.max(icon.height() + 4, reqHeight);
}
if (text != null && !text.text().equals("")){
reqHeight = Math.max(text.baseLine() + 4, reqHeight);
}
return reqHeight;
}
}

View File

@ -23,169 +23,396 @@ 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.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.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.Icons;
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.BitmapText;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Component;
import java.util.ArrayList;
import java.util.Collections;
public class WndJournal extends Window {
private static final int WIDTH = 112;
private static final int HEIGHT = 160;
private static final int ITEM_HEIGHT = 17;
//FIXME a lot of cleanup and improvements to do here
public class WndJournal extends WndTabbed {
private RedButton btnTitle;
private RedButton btnCatalogues;
private ScrollPane list;
private static final int WIDTH = 112;
private static final int HEIGHT = 130;
public WndJournal() {
private static final int ITEM_HEIGHT = 18;
private Notes notes;
private Catalog catalog;
private static int last_index = 0;
public WndJournal(){
super();
resize( WIDTH, HEIGHT );
//does nothing, we're already in the journal
btnTitle = new RedButton( Messages.get(this, "title"), 9 );
btnTitle.textColor( Window.TITLE_COLOR );
btnTitle.setRect(0, 0, WIDTH/2f - 1, btnTitle.reqHeight());
PixelScene.align(btnTitle);
add( btnTitle );
btnCatalogues = new RedButton( Messages.get(WndCatalogs.class, "title"), 9 ){
@Override
protected void onClick() {
hide();
GameScene.show(new WndCatalogs());
}
resize(WIDTH, HEIGHT);
notes = new Notes();
add(notes);
notes.setRect(0, 0, WIDTH, HEIGHT);
notes.updateList();
catalog = new Catalog();
add(catalog);
catalog.setRect(0, 0, WIDTH, HEIGHT);
catalog.updateList();
Tab[] tabs = {
new LabeledTab( "Guide" ) {
protected void select( boolean value ) {
super.select( value );
if (value) last_index = 0;
};
},
new LabeledTab( "Notes" ) {
protected void select( boolean value ) {
super.select( value );
notes.active = notes.visible = value;
if (value) last_index = 1;
};
},
new LabeledTab( "Items" ) {
protected void select( boolean value ) {
super.select( value );
catalog.active = catalog.visible = value;
if (value) last_index = 2;
};
}
};
btnCatalogues.setRect(WIDTH/2f + 1, 0, WIDTH/2f - 1, btnCatalogues.reqHeight());
PixelScene.align( btnCatalogues );
add( btnCatalogues );
Component content = new Component();
Collections.sort( Journal.records );
float pos = 0;
//Keys
for (int i = Dungeon.hero.belongings.ironKeys.length-1; i > 0; i--){
if (Dungeon.hero.belongings.specialKeys[i] > 0){
String text;
if (i % 5 == 0)
text = Messages.capitalize(Messages.get(SkeletonKey.class, "name"));
else
text = Messages.capitalize(Messages.get(GoldenKey.class, "name"));
if (Dungeon.hero.belongings.specialKeys[i] > 1){
text += " x" + Dungeon.hero.belongings.specialKeys[i];
}
ListItem item = new ListItem( Messages.titleCase(text), i );
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
content.add( item );
pos += item.height();
}
if (Dungeon.hero.belongings.ironKeys[i] > 0){
String text = Messages.titleCase(Messages.get(IronKey.class, "name"));
if (Dungeon.hero.belongings.ironKeys[i] > 1){
text += " x" + Dungeon.hero.belongings.ironKeys[i];
}
ListItem item = new ListItem( text, i );
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
content.add( item );
pos += item.height();
}
}
//Journal entries
for (Journal.Record rec : Journal.records) {
ListItem item = new ListItem( rec.feature.desc(), rec.depth );
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
content.add( item );
pos += item.height();
for (Tab tab : tabs) {
add( tab );
}
content.setSize( WIDTH, pos );
layoutTabs();
list = new ScrollPane( content );
add( list );
list.setRect( 0, btnTitle.height() + 1, WIDTH, height - btnTitle.height() - 1 );
select(last_index);
}
private static class ListItem extends Component {
private static class Notes extends Component{
private RenderedTextMultiline feature;
private BitmapText depth;
private ColorBlock line;
private Image icon;
private ScrollPane list;
public ListItem( String text, int d ) {
super();
feature.text( text );
depth.text( Integer.toString( d ) );
depth.measure();
if (d == Dungeon.depth) {
feature.hardlight( TITLE_COLOR );
depth.hardlight( TITLE_COLOR );
}
}
@Override
protected void createChildren() {
feature = PixelScene.renderMultiline( 7 );
add( feature );
depth = new BitmapText( PixelScene.pixelFont);
add( depth );
line = new ColorBlock( 1, 1, 0xFF222222);
add(line);
icon = Icons.get( Icons.DEPTH );
add( icon );
public Notes(){
list = new ScrollPane( new Component() );
add( list );
}
@Override
protected void layout() {
depth.x = (8 - depth.width())/2f;
depth.y = y + 1.5f + (height() - 1 - depth.height()) / 2f;
PixelScene.align(depth);
icon.x = 8;
icon.y = y + 1 + (height() - 1 - icon.height()) / 2f;
PixelScene.align(icon);
line.size(width, 1);
line.x = 0;
line.y = y;
feature.maxWidth((int)(width - icon.width() - 8 - 1));
feature.setPos(icon.x + icon.width() + 1, y + 1 + (height() - 1 - feature.height()) / 2f);
PixelScene.align(feature);
super.layout();
list.setRect( 0, 0, width, height);
}
private void updateList(){
Component content = list.content();
Collections.sort( Journal.records );
float pos = 0;
//Keys
for (int i = Dungeon.hero.belongings.ironKeys.length-1; i > 0; i--){
if (Dungeon.hero.belongings.specialKeys[i] > 0){
String text;
if (i % 5 == 0)
text = Messages.capitalize(Messages.get(SkeletonKey.class, "name"));
else
text = Messages.capitalize(Messages.get(GoldenKey.class, "name"));
if (Dungeon.hero.belongings.specialKeys[i] > 1){
text += " x" + Dungeon.hero.belongings.specialKeys[i];
}
ListItem item = new ListItem( Messages.titleCase(text), i );
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
content.add( item );
pos += item.height();
}
if (Dungeon.hero.belongings.ironKeys[i] > 0){
String text = Messages.titleCase(Messages.get(IronKey.class, "name"));
if (Dungeon.hero.belongings.ironKeys[i] > 1){
text += " x" + Dungeon.hero.belongings.ironKeys[i];
}
ListItem item = new ListItem( text, i );
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
content.add( item );
pos += item.height();
}
}
//Journal entries
for (Journal.Record rec : Journal.records) {
ListItem item = new ListItem( rec.feature.desc(), rec.depth );
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
content.add( item );
pos += item.height();
}
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 ScrollPane list;
private ArrayList<ListItem> items = new ArrayList<>();
private static boolean showPotions = true;
public Catalog(){
super();
btnPotions = new RedButton( "" ){
@Override
protected void onClick() {
if (!showPotions){
showPotions = true;
updateList();
}
}
};
btnPotions.icon(new ItemSprite(ItemSpriteSheet.POTION_HOLDER, null));
add( btnPotions );
btnScrolls = new RedButton( "" ){
@Override
protected void onClick() {
if (showPotions){
showPotions = false;
updateList();
}
}
};
btnScrolls.icon(new ItemSprite(ItemSpriteSheet.SCROLL_HOLDER, null));
add( btnScrolls );
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 );
}
private static final int BUTTON_WIDTH = 55;
private static final int BUTTON_HEIGHT = 18;
@Override
protected void layout() {
super.layout();
btnPotions.setRect(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
PixelScene.align( btnPotions );
btnScrolls.setRect(width() - BUTTON_WIDTH, 0, BUTTON_WIDTH, BUTTON_HEIGHT);
PixelScene.align(btnScrolls);
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();
}
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( showPotions ? ItemSpriteSheet.POTION_HOLDER : ItemSpriteSheet.SCROLL_HOLDER, 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(showPotions ? ItemSpriteSheet.POTION_HOLDER : ItemSpriteSheet.SCROLL_HOLDER, null),
Messages.titleCase(item.trueName()), item.desc() ));
return true;
} else {
return false;
}
}
}
}
}