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

130 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 com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Journal;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Component;
import java.util.Collections;
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 RenderedText txtTitle;
2014-07-27 13:39:07 +00:00
private ScrollPane list;
public WndJournal() {
super();
2015-02-06 06:07:22 +00:00
resize( WIDTH, ShatteredPixelDungeon.landscape() ? HEIGHT_L : HEIGHT_P );
txtTitle = PixelScene.renderText( Messages.get(this, "title"), 9 );
2014-07-27 13:39:07 +00:00
txtTitle.hardlight( Window.TITLE_COLOR );
txtTitle.x = (WIDTH - txtTitle.width()) / 2;
PixelScene.align(txtTitle);
2014-07-27 13:39:07 +00:00
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 RenderedText feature;
2014-07-27 13:39:07 +00:00
private BitmapText depth;
private Image icon;
public ListItem( Journal.Feature f, int d ) {
super();
2015-12-31 05:13:13 +00:00
feature.text( f.desc() );
2014-07-27 13:39:07 +00:00
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.renderText( 9 );
2014-07-27 13:39:07 +00:00
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 = y + (height - depth.height()) / 2;
PixelScene.align(depth);
2014-07-27 13:39:07 +00:00
icon.y = depth.y - 1;
feature.y = depth.y + depth.baseLine() - feature.baseLine();
PixelScene.align(feature);
2014-07-27 13:39:07 +00:00
}
}
}