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

129 lines
3.5 KiB
Java
Raw Normal View History

2014-07-27 13:39:07 +00:00
/*
* Pixel Dungeon
2015-06-12 20:44:04 +00:00
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2015 Evan Debenham
2014-07-27 13:39:07 +00:00
*
* 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
import java.util.Collections;
2015-02-06 06:07:22 +00:00
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
2014-07-27 13:39:07 +00:00
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Component;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Journal;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
2014-07-27 13:39:07 +00:00
public class WndJournal extends Window {
2015-02-06 06:07:22 +00:00
private static final int WIDTH = 112;
private static final int HEIGHT_P = 160;
private static final int HEIGHT_L = 144;
2014-07-27 13:39:07 +00:00
private static final int ITEM_HEIGHT = 18;
private static final String TXT_TITLE = "Journal";
private BitmapText txtTitle;
private ScrollPane list;
public WndJournal() {
super();
2015-02-06 06:07:22 +00:00
resize( WIDTH, ShatteredPixelDungeon.landscape() ? HEIGHT_L : HEIGHT_P );
2014-07-27 13:39:07 +00:00
txtTitle = PixelScene.createText( TXT_TITLE, 9 );
txtTitle.hardlight( Window.TITLE_COLOR );
txtTitle.measure();
txtTitle.x = PixelScene.align( PixelScene.uiCamera, (WIDTH - txtTitle.width()) / 2 );
add( txtTitle );
Component content = new Component();
Collections.sort( Journal.records );
float pos = 0;
for (Journal.Record rec : Journal.records) {
ListItem item = new ListItem( rec.feature, rec.depth );
item.setRect( 0, pos, WIDTH, ITEM_HEIGHT );
content.add( item );
pos += item.height();
}
content.setSize( WIDTH, pos );
list = new ScrollPane( content );
add( list );
2015-02-06 06:07:22 +00:00
list.setRect( 0, txtTitle.height(), WIDTH, height - txtTitle.height() );
2014-07-27 13:39:07 +00:00
}
private static class ListItem extends Component {
private BitmapText feature;
private BitmapText depth;
private Image icon;
public ListItem( Journal.Feature f, int d ) {
super();
feature.text( f.desc );
feature.measure();
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.createText( 9 );
add( feature );
depth = new BitmapText( PixelScene.pixelFont);
2014-07-27 13:39:07 +00:00
add( depth );
icon = Icons.get( Icons.DEPTH );
add( icon );
}
@Override
protected void layout() {
icon.x = width - icon.width;
depth.x = icon.x - 1 - depth.width();
depth.y = PixelScene.align( y + (height - depth.height()) / 2 );
icon.y = depth.y - 1;
feature.y = PixelScene.align( depth.y + depth.baseLine() - feature.baseLine() );
}
}
}