V0.1.0 Partial Commit

changed package and application names to differentiate from main PD
release
This commit is contained in:
Evan Debenham
2014-08-03 14:46:22 -04:00
parent 65dd9c2dc0
commit aed303672a
474 changed files with 3468 additions and 3458 deletions
@@ -0,0 +1,89 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Component;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class IconTitle extends Component {
private static final float FONT_SIZE = 9;
private static final float GAP = 2;
protected Image imIcon;
protected BitmapTextMultiline tfLabel;
public IconTitle() {
super();
}
public IconTitle( Image icon, String label ) {
super();
icon( icon );
label( label );
}
@Override
protected void createChildren() {
imIcon = new Image();
add( imIcon );
tfLabel = PixelScene.createMultiline( FONT_SIZE );
tfLabel.hardlight( Window.TITLE_COLOR );
add( tfLabel );
}
@Override
protected void layout() {
imIcon.x = 0;
imIcon.y = 0;
tfLabel.x = PixelScene.align( PixelScene.uiCamera, imIcon.x + imIcon.width() + GAP );
tfLabel.maxWidth = (int)(width - tfLabel.x);
tfLabel.measure();
tfLabel.y = PixelScene.align( PixelScene.uiCamera,
imIcon.height > tfLabel.height() ?
(imIcon.height() - tfLabel.baseLine()) / 2 :
imIcon.y );
height = Math.max( imIcon.y + imIcon.height(), tfLabel.y + tfLabel.height() );
}
public void icon( Image icon ) {
remove( imIcon );
add( imIcon = icon );
}
public void label( String label ) {
tfLabel.text( label );
}
public void label( String label, int color ) {
tfLabel.text( label );
tfLabel.hardlight( color );
}
public void color( int color ) {
tfLabel.hardlight( color );
}
}
@@ -0,0 +1,64 @@
/*
* 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;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.Image;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndBadge extends Window {
private static final int WIDTH = 120;
private static final int MARGIN = 4;
public WndBadge( Badges.Badge badge ) {
super();
Image icon = BadgeBanner.image( badge.image );
icon.scale.set( 2 );
add( icon );
BitmapTextMultiline info = PixelScene.createMultiline( badge.description, 8 );
info.maxWidth = WIDTH - MARGIN * 2;
info.measure();
float w = Math.max( icon.width(), info.width() ) + MARGIN * 2;
icon.x = (w - icon.width()) / 2;
icon.y = MARGIN;
float pos = icon.y + icon.height() + MARGIN;
for (BitmapText line : info.new LineSplitter().split()) {
line.measure();
line.x = PixelScene.align( (w - line.width()) / 2 );
line.y = PixelScene.align( pos );
add( line );
pos += line.height();
}
resize( (int)w, (int)(pos + MARGIN) );
BadgeBanner.highlight( icon, badge.image );
}
}
@@ -0,0 +1,399 @@
/*
* 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;
import android.graphics.RectF;
import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Gold;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.SeedPouch;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.WandHolster;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.Boomerang;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant.Seed;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndBag extends WndTabbed {
public static enum Mode {
ALL,
UNIDENTIFED,
UPGRADEABLE,
QUICKSLOT,
FOR_SALE,
WEAPON,
ARMOR,
WAND,
SEED
}
protected static final int COLS = 4;
protected static final int SLOT_SIZE = 28;
protected static final int SLOT_MARGIN = 1;
protected static final int TAB_WIDTH = 30;
protected static final int TITLE_HEIGHT = 12;
@SuppressWarnings("unused")
protected static final int ROWS =
(Belongings.BACKPACK_SIZE + 4 + 1) / COLS + ((Belongings.BACKPACK_SIZE + 4 + 1) % COLS > 0 ? 1 : 0);
private Listener listener;
private WndBag.Mode mode;
private String title;
protected int count;
protected int col;
protected int row;
private static Mode lastMode;
private static Bag lastBag;
public WndBag( Bag bag, Listener listener, Mode mode, String title ) {
super();
this.listener = listener;
this.mode = mode;
this.title = title;
lastMode = mode;
lastBag = bag;
BitmapText txtTitle = PixelScene.createText( title != null ? title : Utils.capitalize( bag.name() ), 9 );
txtTitle.hardlight( TITLE_COLOR );
txtTitle.measure();
txtTitle.x = (int)(SLOT_SIZE * COLS + SLOT_MARGIN * (COLS - 1) - txtTitle.width()) / 2;
txtTitle.y = (int)(TITLE_HEIGHT - txtTitle.height()) / 2;
add( txtTitle );
placeItems( bag );
resize(
SLOT_SIZE * COLS + SLOT_MARGIN * (COLS - 1),
SLOT_SIZE * ROWS + SLOT_MARGIN * (ROWS - 1) + TITLE_HEIGHT );
Belongings stuff = Dungeon.hero.belongings;
Bag[] bags = {
stuff.backpack,
stuff.getItem( SeedPouch.class ),
stuff.getItem( ScrollHolder.class ),
stuff.getItem( WandHolster.class )};
for (Bag b : bags) {
if (b != null) {
BagTab tab = new BagTab( b );
tab.setSize( TAB_WIDTH, tabHeight() );
add( tab );
tab.select( b == bag );
}
}
}
public static WndBag lastBag( Listener listener, Mode mode, String title ) {
if (mode == lastMode && lastBag != null &&
Dungeon.hero.belongings.backpack.contains( lastBag )) {
return new WndBag( lastBag, listener, mode, title );
} else {
return new WndBag( Dungeon.hero.belongings.backpack, listener, mode, title );
}
}
public static WndBag seedPouch( Listener listener, Mode mode, String title ) {
SeedPouch pouch = Dungeon.hero.belongings.getItem( SeedPouch.class );
return pouch != null ?
new WndBag( pouch, listener, mode, title ) :
new WndBag( Dungeon.hero.belongings.backpack, listener, mode, title );
}
protected void placeItems( Bag container ) {
// Equipped items
Belongings stuff = Dungeon.hero.belongings;
placeItem( stuff.weapon != null ? stuff.weapon : new Placeholder( ItemSpriteSheet.WEAPON ) );
placeItem( stuff.armor != null ? stuff.armor : new Placeholder( ItemSpriteSheet.ARMOR ) );
placeItem( stuff.ring1 != null ? stuff.ring1 : new Placeholder( ItemSpriteSheet.RING ) );
placeItem( stuff.ring2 != null ? stuff.ring2 : new Placeholder( ItemSpriteSheet.RING ) );
// Unequipped items
for (Item item : container.items) {
placeItem( item );
}
// Empty slots
while (count-4 < container.size) {
placeItem( null );
}
// Gold
if (container == Dungeon.hero.belongings.backpack) {
row = ROWS - 1;
col = COLS - 1;
placeItem( new Gold( Dungeon.gold ) );
}
}
protected void placeItem( final Item item ) {
int x = col * (SLOT_SIZE + SLOT_MARGIN);
int y = TITLE_HEIGHT + row * (SLOT_SIZE + SLOT_MARGIN);
add( new ItemButton( item ).setPos( x, y ) );
if (++col >= COLS) {
col = 0;
row++;
}
count++;
}
@Override
public void onMenuPressed() {
if (listener == null) {
hide();
}
}
@Override
public void onBackPressed() {
if (listener != null) {
listener.onSelect( null );
}
super.onBackPressed();
}
@Override
protected void onClick( Tab tab ) {
hide();
GameScene.show( new WndBag( ((BagTab)tab).bag, listener, mode, title ) );
}
@Override
protected int tabHeight() {
return 20;
}
private class BagTab extends Tab {
private Image icon;
private Bag bag;
public BagTab( Bag bag ) {
super();
this.bag = bag;
icon = icon();
add( icon );
}
@Override
protected void select( boolean value ) {
super.select( value );
icon.am = selected ? 1.0f : 0.6f;
}
@Override
protected void layout() {
super.layout();
icon.copy( icon() );
icon.x = x + (width - icon.width) / 2;
icon.y = y + (height - icon.height) / 2 - 2 - (selected ? 0 : 1);
if (!selected && icon.y < y + CUT) {
RectF frame = icon.frame();
frame.top += (y + CUT - icon.y) / icon.texture.height;
icon.frame( frame );
icon.y = y + CUT;
}
}
private Image icon() {
if (bag instanceof SeedPouch) {
return Icons.get( Icons.SEED_POUCH );
} else if (bag instanceof ScrollHolder) {
return Icons.get( Icons.SCROLL_HOLDER );
} else if (bag instanceof WandHolster) {
return Icons.get( Icons.WAND_HOLSTER );
} else {
return Icons.get( Icons.BACKPACK );
}
}
}
private static class Placeholder extends Item {
{
name = null;
}
public Placeholder( int image ) {
this.image = image;
}
@Override
public boolean isIdentified() {
return true;
}
@Override
public boolean isEquipped( Hero hero ) {
return true;
}
}
private class ItemButton extends ItemSlot {
private static final int NORMAL = 0xFF4A4D44;
private static final int EQUIPPED = 0xFF63665B;
private Item item;
private ColorBlock bg;
public ItemButton( Item item ) {
super( item );
this.item = item;
if (item instanceof Gold) {
bg.visible = false;
}
width = height = SLOT_SIZE;
}
@Override
protected void createChildren() {
bg = new ColorBlock( SLOT_SIZE, SLOT_SIZE, NORMAL );
add( bg );
super.createChildren();
}
@Override
protected void layout() {
bg.x = x;
bg.y = y;
super.layout();
}
@Override
public void item( Item item ) {
super.item( item );
if (item != null) {
bg.texture( TextureCache.createSolid( item.isEquipped( Dungeon.hero ) ? EQUIPPED : NORMAL ) );
if (item.cursed && item.cursedKnown) {
bg.ra = +0.2f;
bg.ga = -0.1f;
} else if (!item.isIdentified()) {
bg.ra = 0.1f;
bg.ba = 0.1f;
}
if (item.name() == null) {
enable( false );
} else {
enable(
mode == Mode.FOR_SALE && (item.price() > 0) && (!item.isEquipped( Dungeon.hero ) || !item.cursed) ||
mode == Mode.UPGRADEABLE && item.isUpgradable() ||
mode == Mode.UNIDENTIFED && !item.isIdentified() ||
mode == Mode.QUICKSLOT && (item.defaultAction != null) ||
mode == Mode.WEAPON && (item instanceof MeleeWeapon || item instanceof Boomerang) ||
mode == Mode.ARMOR && (item instanceof Armor) ||
mode == Mode.WAND && (item instanceof Wand) ||
mode == Mode.SEED && (item instanceof Seed) ||
mode == Mode.ALL
);
}
} else {
bg.color( NORMAL );
}
}
@Override
protected void onTouchDown() {
bg.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
};
protected void onTouchUp() {
bg.brightness( 1.0f );
};
@Override
protected void onClick() {
if (listener != null) {
hide();
listener.onSelect( item );
} else {
WndBag.this.add( new WndItem( WndBag.this, item ) );
}
}
@Override
protected boolean onLongClick() {
if (listener == null && item.defaultAction != null) {
hide();
Dungeon.quickslot = item instanceof Wand ? item : item.getClass();
QuickSlot.refresh();
return true;
} else {
return false;
}
}
}
public interface Listener {
void onSelect( Item item );
}
}
@@ -0,0 +1,176 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Component;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Blacksmith;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndBlacksmith extends Window {
private static final int BTN_SIZE = 36;
private static final float GAP = 2;
private static final float BTN_GAP = 10;
private static final int WIDTH = 116;
private ItemButton btnPressed;
private ItemButton btnItem1;
private ItemButton btnItem2;
private RedButton btnReforge;
private static final String TXT_PROMPT =
"Ok, a deal is a deal, dat's what I can do for you: I can reforge " +
"2 items and turn them into one of a better quality.";
private static final String TXT_SELECT =
"Select an item to reforge";
private static final String TXT_REFORGE =
"Reforge them";
public WndBlacksmith( Blacksmith troll, Hero hero ) {
super();
IconTitle titlebar = new IconTitle();
titlebar.icon( troll.sprite() );
titlebar.label( Utils.capitalize( troll.name ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
BitmapTextMultiline message = PixelScene.createMultiline( TXT_PROMPT, 6 );
message.maxWidth = WIDTH;
message.measure();
message.y = titlebar.bottom() + GAP;
add( message );
btnItem1 = new ItemButton() {
@Override
protected void onClick() {
btnPressed = btnItem1;
GameScene.selectItem( itemSelector, WndBag.Mode.UPGRADEABLE, TXT_SELECT );
}
};
btnItem1.setRect( (WIDTH - BTN_GAP) / 2 - BTN_SIZE, message.y + message.height() + BTN_GAP, BTN_SIZE, BTN_SIZE );
add( btnItem1 );
btnItem2 = new ItemButton() {
@Override
protected void onClick() {
btnPressed = btnItem2;
GameScene.selectItem( itemSelector, WndBag.Mode.UPGRADEABLE, TXT_SELECT );
}
};
btnItem2.setRect( btnItem1.right() + BTN_GAP, btnItem1.top(), BTN_SIZE, BTN_SIZE );
add( btnItem2 );
btnReforge = new RedButton( TXT_REFORGE ) {
@Override
protected void onClick() {
Blacksmith.upgrade( btnItem1.item, btnItem2.item );
hide();
}
};
btnReforge.enable( false );
btnReforge.setRect( 0, btnItem1.bottom() + BTN_GAP, WIDTH, 20 );
add( btnReforge );
resize( WIDTH, (int)btnReforge.bottom() );
}
protected WndBag.Listener itemSelector = new WndBag.Listener() {
@Override
public void onSelect( Item item ) {
if (item != null) {
btnPressed.item( item );
if (btnItem1.item != null && btnItem2.item != null) {
String result = Blacksmith.verify( btnItem1.item, btnItem2.item );
if (result != null) {
GameScene.show( new WndMessage( result ) );
btnReforge.enable( false );
} else {
btnReforge.enable( true );
}
}
}
}
};
public static class ItemButton extends Component {
protected NinePatch bg;
protected ItemSlot slot;
public Item item = null;
@Override
protected void createChildren() {
super.createChildren();
bg = Chrome.get( Chrome.Type.BUTTON );
add( bg );
slot = new ItemSlot() {
@Override
protected void onTouchDown() {
bg.brightness( 1.2f );
Sample.INSTANCE.play( Assets.SND_CLICK );
};
@Override
protected void onTouchUp() {
bg.resetColor();
}
@Override
protected void onClick() {
ItemButton.this.onClick();
}
};
add( slot );
}
protected void onClick() {};
@Override
protected void layout() {
super.layout();
bg.x = x;
bg.y = y;
bg.size( width, height );
slot.setRect( x + 2, y + 2, width - 4, height - 4 );
};
public void item( Item item ) {
slot.item( this.item = item );
}
}
}
@@ -0,0 +1,189 @@
/*
* 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;
import java.util.ArrayList;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.ui.Component;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndCatalogus extends WndTabbed {
private static final int WIDTH = 112;
private static final int HEIGHT = 160;
private static final int ITEM_HEIGHT = 18;
private static final int TAB_WIDTH = 50;
private static final String TXT_POTIONS = "Potions";
private static final String TXT_SCROLLS = "Scrolls";
private static final String TXT_TITLE = "Catalogus";
private BitmapText txtTitle;
private ScrollPane list;
private ArrayList<ListItem> items = new ArrayList<WndCatalogus.ListItem>();
private static boolean showPotions = true;
public WndCatalogus() {
super();
resize( WIDTH, HEIGHT );
txtTitle = PixelScene.createText( TXT_TITLE, 9 );
txtTitle.hardlight( Window.TITLE_COLOR );
txtTitle.measure();
add( txtTitle );
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, txtTitle.height(), WIDTH, HEIGHT - txtTitle.height() );
boolean showPotions = WndCatalogus.showPotions;
Tab[] tabs = {
new LabeledTab( TXT_POTIONS ) {
protected void select( boolean value ) {
super.select( value );
WndCatalogus.showPotions = value;
updateList();
};
},
new LabeledTab( TXT_SCROLLS ) {
protected void select( boolean value ) {
super.select( value );
WndCatalogus.showPotions = !value;
updateList();
};
}
};
for (Tab tab : tabs) {
tab.setSize( TAB_WIDTH, tabHeight() );
add( tab );
}
select( showPotions ? 0 : 1 );
}
private void updateList() {
txtTitle.text( Utils.format( TXT_TITLE, showPotions ? TXT_POTIONS : TXT_SCROLLS ) );
txtTitle.measure();
txtTitle.x = PixelScene.align( PixelScene.uiCamera, (WIDTH - txtTitle.width()) / 2 );
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 );
}
private static class ListItem extends Component {
private Item item;
private boolean identified;
private ItemSprite sprite;
private BitmapText label;
public ListItem( Class<? extends Item> cl ) {
super();
try {
item = cl.newInstance();
if (identified = item.isIdentified()) {
sprite.view( item.image(), null );
label.text( item.name() );
} else {
sprite.view( 127, null );
label.text( item.trueName() );
label.hardlight( 0xCCCCCC );
}
} catch (Exception e) {
//
}
}
@Override
protected void createChildren() {
sprite = new ItemSprite();
add( sprite );
label = PixelScene.createText( 8 );
add( label );
}
@Override
protected void layout() {
sprite.y = PixelScene.align( y + (height - sprite.height) / 2 );
label.x = sprite.x + sprite.width;
label.y = PixelScene.align( y + (height - label.baseLine()) / 2 );
}
public boolean onClick( float x, float y ) {
if (identified && inside( x, y )) {
GameScene.show( new WndInfoItem( item ) );
return true;
} else {
return false;
}
}
}
}
@@ -0,0 +1,102 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass;
import com.shatteredpixel.shatteredpixeldungeon.items.TomeOfMastery;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndChooseWay extends Window {
private static final String TXT_MESSAGE = "Which way will you follow?";
private static final String TXT_CANCEL = "I'll decide later";
private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 18;
private static final float GAP = 2;
public WndChooseWay( final TomeOfMastery tome, final HeroSubClass way1, final HeroSubClass way2 ) {
super();
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( tome.image(), null ) );
titlebar.label( tome.name() );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
Highlighter hl = new Highlighter( way1.desc() + "\n\n" + way2.desc() + "\n\n" + TXT_MESSAGE );
BitmapTextMultiline normal = PixelScene.createMultiline( hl.text, 6 );
normal.maxWidth = WIDTH;
normal.measure();
normal.x = titlebar.left();
normal.y = titlebar.bottom() + GAP;
add( normal );
if (hl.isHighlighted()) {
normal.mask = hl.inverted();
BitmapTextMultiline highlighted = PixelScene.createMultiline( hl.text, 6 );
highlighted.maxWidth = normal.maxWidth;
highlighted.measure();
highlighted.x = normal.x;
highlighted.y = normal.y;
add( highlighted );
highlighted.mask = hl.mask;
highlighted.hardlight( TITLE_COLOR );
}
RedButton btnWay1 = new RedButton( Utils.capitalize( way1.title() ) ) {
@Override
protected void onClick() {
hide();
tome.choose( way1 );
}
};
btnWay1.setRect( 0, normal.y + normal.height() + GAP, (WIDTH - GAP) / 2, BTN_HEIGHT );
add( btnWay1 );
RedButton btnWay2 = new RedButton( Utils.capitalize( way2.title() ) ) {
@Override
protected void onClick() {
hide();
tome.choose( way2 );
}
};
btnWay2.setRect( btnWay1.right() + GAP, btnWay1.top(), btnWay1.width(), BTN_HEIGHT );
add( btnWay2 );
RedButton btnCancel = new RedButton( TXT_CANCEL ) {
@Override
protected void onClick() {
hide();
}
};
btnCancel.setRect( 0, btnWay2.bottom() + GAP, WIDTH, BTN_HEIGHT );
add( btnCancel );
resize( WIDTH, (int)btnCancel.bottom() );
}
}
@@ -0,0 +1,30 @@
/*
* 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;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
public class WndError extends WndTitledMessage {
private static final String TXT_TITLE = "ERROR";
public WndError( String message ) {
super( Icons.WARNING.get(), TXT_TITLE, message );
}
}
@@ -0,0 +1,120 @@
/*
* 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;
import java.io.IOException;
import com.watabou.noosa.Game;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.RankingsScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndGame extends Window {
private static final String TXT_SETTINGS = "Settings";
private static final String TXT_RANKINGS = "Rankings";
private static final String TXT_START = "Start New Game";
private static final String TXT_MENU = "Main Menu";
private static final String TXT_EXIT = "Exit Pixel Dungeon";
private static final String TXT_RETURN = "Return to Game";
private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 20;
private static final int GAP = 2;
private int pos;
public WndGame() {
super();
addButton( new RedButton( TXT_SETTINGS ) {
@Override
protected void onClick() {
hide();
GameScene.show( new WndSettings( true ) );
}
} );
// Restart
if (!Dungeon.hero.isAlive()) {
RedButton btnStart;
addButton( btnStart = new RedButton( TXT_START ) {
@Override
protected void onClick() {
Dungeon.hero = null;
InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
InterlevelScene.noStory = true;
Game.switchScene( InterlevelScene.class );
}
} );
btnStart.icon( Icons.get( Dungeon.hero.heroClass ) );
addButton( new RedButton( TXT_RANKINGS ) {
@Override
protected void onClick() {
InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
Game.switchScene( RankingsScene.class );
}
} );
}
// Main menu
addButton( new RedButton( TXT_MENU ) {
@Override
protected void onClick() {
try {
Dungeon.saveAll();
} catch (IOException e) {
//
}
Game.switchScene( TitleScene.class );
}
} );
// Exit
addButton( new RedButton( TXT_EXIT ) {
@Override
protected void onClick() {
Game.instance.finish();
}
} );
// Cancel
addButton( new RedButton( TXT_RETURN ) {
@Override
protected void onClick() {
hide();
}
} );
resize( WIDTH, pos );
}
private void addButton( RedButton btn ) {
add( btn );
btn.setRect( 0, pos > 0 ? pos += GAP : 0, WIDTH, BTN_HEIGHT );
pos += BTN_HEIGHT;
}
}
@@ -0,0 +1,209 @@
/*
* 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;
import java.util.Locale;
import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.TextureFilm;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndHero extends WndTabbed {
private static final String TXT_STATS = "Stats";
private static final String TXT_BUFFS = "Buffs";
private static final String TXT_EXP = "Experience";
private static final String TXT_STR = "Strength";
private static final String TXT_HEALTH = "Health";
private static final String TXT_GOLD = "Gold Collected";
private static final String TXT_DEPTH = "Maximum Depth";
private static final int WIDTH = 100;
private static final int TAB_WIDTH = 40;
private StatsTab stats;
private BuffsTab buffs;
private SmartTexture icons;
private TextureFilm film;
public WndHero() {
super();
icons = TextureCache.get( Assets.BUFFS_LARGE );
film = new TextureFilm( icons, 16, 16 );
stats = new StatsTab();
add( stats );
buffs = new BuffsTab();
add( buffs );
add( new LabeledTab( TXT_STATS ) {
protected void select( boolean value ) {
super.select( value );
stats.visible = stats.active = selected;
};
} );
add( new LabeledTab( TXT_BUFFS ) {
protected void select( boolean value ) {
super.select( value );
buffs.visible = buffs.active = selected;
};
} );
for (Tab tab : tabs) {
tab.setSize( TAB_WIDTH, tabHeight() );
}
resize( WIDTH, (int)Math.max( stats.height(), buffs.height() ) );
select( 0 );
}
private class StatsTab extends Group {
private static final String TXT_TITLE = "Level %d %s";
private static final String TXT_CATALOGUS = "Catalogus";
private static final String TXT_JOURNAL = "Journal";
private static final int GAP = 5;
private float pos;
public StatsTab() {
Hero hero = Dungeon.hero;
BitmapText title = PixelScene.createText(
Utils.format( TXT_TITLE, hero.lvl, hero.className() ).toUpperCase( Locale.ENGLISH ), 9 );
title.hardlight( TITLE_COLOR );
title.measure();
add( title );
RedButton btnCatalogus = new RedButton( TXT_CATALOGUS ) {
@Override
protected void onClick() {
hide();
GameScene.show( new WndCatalogus() );
}
};
btnCatalogus.setRect( 0, title.y + title.height(), btnCatalogus.reqWidth() + 2, btnCatalogus.reqHeight() + 2 );
add( btnCatalogus );
RedButton btnJournal = new RedButton( TXT_JOURNAL ) {
@Override
protected void onClick() {
hide();
GameScene.show( new WndJournal() );
}
};
btnJournal.setRect(
btnCatalogus.right() + 1, btnCatalogus.top(),
btnJournal.reqWidth() + 2, btnJournal.reqHeight() + 2 );
add( btnJournal );
pos = btnCatalogus.bottom() + GAP;
statSlot( TXT_STR, hero.STR() );
statSlot( TXT_HEALTH, hero.HP + "/" + hero.HT );
statSlot( TXT_EXP, hero.exp + "/" + hero.maxExp() );
pos += GAP;
statSlot( TXT_GOLD, Statistics.goldCollected );
statSlot( TXT_DEPTH, Statistics.deepestFloor );
pos += GAP;
}
private void statSlot( String label, String value ) {
BitmapText txt = PixelScene.createText( label, 8 );
txt.y = pos;
add( txt );
txt = PixelScene.createText( value, 8 );
txt.measure();
txt.x = PixelScene.align( WIDTH * 0.65f );
txt.y = pos;
add( txt );
pos += GAP + txt.baseLine();
}
private void statSlot( String label, int value ) {
statSlot( label, Integer.toString( value ) );
}
public float height() {
return pos;
}
}
private class BuffsTab extends Group {
private static final int GAP = 2;
private float pos;
public BuffsTab() {
for (Buff buff : Dungeon.hero.buffs()) {
buffSlot( buff );
}
}
private void buffSlot( Buff buff ) {
int index = buff.icon();
if (index != BuffIndicator.NONE) {
Image icon = new Image( icons );
icon.frame( film.get( index ) );
icon.y = pos;
add( icon );
BitmapText txt = PixelScene.createText( buff.toString(), 8 );
txt.x = icon.width + GAP;
txt.y = pos + (int)(icon.height - txt.baseLine()) / 2;
add( txt );
pos += GAP + icon.height;
}
}
public float height() {
return pos;
}
}
}
@@ -0,0 +1,90 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Imp;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.quest.DwarfToken;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndImp extends Window {
private static final String TXT_MESSAGE =
"Oh yes! You are my hero!\n" +
"Regarding your reward, I don't have cash with me right now, but I have something better for you. " +
"This is my family heirloom ring: my granddad took it off a dead paladin's finger.";
private static final String TXT_REWARD = "Take the ring";
private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 18;
private static final float GAP = 2;
public WndImp( final Imp imp, final DwarfToken tokens ) {
super();
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( tokens.image(), null ) );
titlebar.label( Utils.capitalize( tokens.name() ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
BitmapTextMultiline message = PixelScene.createMultiline( TXT_MESSAGE, 6 );
message.maxWidth = WIDTH;
message.measure();
message.y = titlebar.bottom() + GAP;
add( message );
RedButton btnReward = new RedButton( TXT_REWARD ) {
@Override
protected void onClick() {
takeReward( imp, tokens, Imp.Quest.reward );
}
};
btnReward.setRect( 0, message.y + message.height() + GAP, WIDTH, BTN_HEIGHT );
add( btnReward );
resize( WIDTH, (int)btnReward.bottom() );
}
private void takeReward( Imp imp, DwarfToken tokens, Item reward ) {
hide();
tokens.detachAll( Dungeon.hero.belongings.backpack );
reward.identify();
if (reward.doPickUp( Dungeon.hero )) {
GLog.i( Hero.TXT_YOU_NOW_HAVE, reward.name() );
} else {
Dungeon.level.drop( reward, imp.pos ).sprite.drop();
}
imp.flee();
Imp.Quest.complete();
}
}
@@ -0,0 +1,84 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.Image;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndInfoCell extends Window {
private static final float GAP = 2;
private static final int WIDTH = 120;
private static final String TXT_NOTHING = "There is nothing here.";
public WndInfoCell( int cell ) {
super();
int tile = Dungeon.level.map[cell];
if (Level.water[cell]) {
tile = Terrain.WATER;
} else if (Level.pit[cell]) {
tile = Terrain.CHASM;
}
IconTitle titlebar = new IconTitle();
if (tile == Terrain.WATER) {
Image water = new Image( Dungeon.level.waterTex() );
water.frame( 0, 0, DungeonTilemap.SIZE, DungeonTilemap.SIZE );
titlebar.icon( water );
} else {
titlebar.icon( DungeonTilemap.tile( tile ) );
}
titlebar.label( Dungeon.level.tileName( tile ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
BitmapTextMultiline info = PixelScene.createMultiline( 6 );
add( info );
StringBuilder desc = new StringBuilder( Dungeon.level.tileDesc( tile ) );
final char newLine = '\n';
for (Blob blob:Dungeon.level.blobs.values()) {
if (blob.cur[cell] > 0 && blob.tileDesc() != null) {
if (desc.length() > 0) {
desc.append( newLine );
}
desc.append( blob.tileDesc() );
}
}
info.text( desc.length() > 0 ? desc.toString() : TXT_NOTHING );
info.maxWidth = WIDTH;
info.measure();
info.x = titlebar.left();
info.y = titlebar.bottom() + GAP;
resize( WIDTH, (int)(info.y + info.height()) );
}
}
@@ -0,0 +1,125 @@
/*
* 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;
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;
public class WndInfoItem extends Window {
private static final String TXT_CHEST = "Chest";
private static final String TXT_LOCKED_CHEST = "Locked chest";
private static final String TXT_CRYSTAL_CHEST = "Crystal chest";
private static final String TXT_TOMB = "Tomb";
private static final String TXT_SKELETON = "Skeletal remains";
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_REMAINS =
"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;
if (heap.type == Type.CHEST) {
title = TXT_CHEST;
info = TXT_WONT_KNOW;
} else if (heap.type == Type.TOMB) {
title = TXT_TOMB;
info = TXT_OWNER;
} else if (heap.type == Type.SKELETON) {
title = TXT_SKELETON;
info = TXT_REMAINS;
} else if (heap.type == Type.CRYSTAL_CHEST) {
title = TXT_CRYSTAL_CHEST;
info = Utils.format( TXT_INSIDE, Utils.indefinite( heap.peek().name() ) );
} else {
title = TXT_LOCKED_CHEST;
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()) );
}
}
@@ -0,0 +1,130 @@
/*
* 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;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.ui.Component;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndInfoMob extends WndTitledMessage {
private static final String TXT_SLEEPNIG = "\n\nThis %s is sleeping.";
private static final String TXT_HUNTING = "\n\nThis %s is hunting.";
private static final String TXT_WANDERING = "\n\nThis %s is wandering.";
private static final String TXT_FLEEING = "\n\nThis %s is fleeing.";
private static final String TXT_PASSIVE = "\n\nThe %s is passive.";
public WndInfoMob( Mob mob ) {
super( new MobTitle( mob ), desc( mob ) );
}
private static String desc( Mob mob ) {
StringBuilder builder = new StringBuilder( mob.description() );
switch (mob.state) {
case SLEEPING:
builder.append( String.format( TXT_SLEEPNIG, mob.name ) );
break;
case HUNTING:
builder.append( String.format( TXT_HUNTING, mob.name ) );
break;
case WANDERING:
builder.append( String.format( TXT_WANDERING, mob.name ) );
break;
case FLEEING:
builder.append( String.format( TXT_FLEEING, mob.name ) );
break;
case PASSIVE:
builder.append( String.format( TXT_PASSIVE, mob.name ) );
break;
}
return builder.toString();
}
private static class MobTitle extends Component {
private static final int COLOR_BG = 0xFFCC0000;
private static final int COLOR_LVL = 0xFF00EE00;
private static final int BAR_HEIGHT = 2;
private static final int GAP = 2;
private CharSprite image;
private BitmapText name;
private ColorBlock hpBg;
private ColorBlock hpLvl;
private BuffIndicator buffs;
private float hp;
public MobTitle( Mob mob ) {
hp = (float)mob.HP / mob.HT;
name = PixelScene.createText( Utils.capitalize( mob.name ), 9 );
name.hardlight( TITLE_COLOR );
name.measure();
add( name );
image = mob.sprite();
add( image );
hpBg = new ColorBlock( 1, 1, COLOR_BG );
add( hpBg );
hpLvl = new ColorBlock( 1, 1, COLOR_LVL );
add( hpLvl );
buffs = new BuffIndicator( mob );
add( buffs );
}
@Override
protected void layout() {
image.x = 0;
image.y = Math.max( 0, name.height() + GAP + BAR_HEIGHT - image.height );
name.x = image.width + GAP;
name.y = image.height - BAR_HEIGHT - GAP - name.baseLine();
float w = width - image.width - GAP;
hpBg.size( w, BAR_HEIGHT );
hpLvl.size( w * hp, BAR_HEIGHT );
hpBg.x = hpLvl.x = image.width + GAP;
hpBg.y = hpLvl.y = image.height - BAR_HEIGHT;
buffs.setPos(
name.x + name.width() + GAP,
name.y + name.baseLine() - BuffIndicator.SIZE );
height = hpBg.y + hpBg.height();
}
}
}
@@ -0,0 +1,53 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.PlantSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndInfoPlant extends Window {
private static final float GAP = 2;
private static final int WIDTH = 120;
public WndInfoPlant( Plant plant ) {
super();
IconTitle titlebar = new IconTitle();
titlebar.icon( new PlantSprite( plant.image ) );
titlebar.label( plant.plantName );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
BitmapTextMultiline info = PixelScene.createMultiline( 6 );
add( info );
info.text( plant.desc() );
info.maxWidth = WIDTH;
info.measure();
info.x = titlebar.left();
info.y = titlebar.bottom() + GAP;
resize( WIDTH, (int)(info.y + info.height()) );
}
}
@@ -0,0 +1,90 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
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.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndItem extends Window {
private static final float BUTTON_WIDTH = 36;
private static final float BUTTON_HEIGHT = 16;
private static final float GAP = 2;
private static final int WIDTH = 120;
public WndItem( final WndBag owner, final Item item ) {
super();
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( item.image(), item.glowing() ) );
titlebar.label( Utils.capitalize( item.toString() ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
if (item.levelKnown && item.level > 0) {
titlebar.color( ItemSlot.UPGRADED );
} else if (item.levelKnown && item.level < 0) {
titlebar.color( ItemSlot.DEGRADED );
}
BitmapTextMultiline info = PixelScene.createMultiline( item.info(), 6 );
info.maxWidth = WIDTH;
info.measure();
info.x = titlebar.left();
info.y = titlebar.bottom() + GAP;
add( info );
float y = info.y + info.height() + GAP;
float x = 0;
if (Dungeon.hero.isAlive() && owner != null) {
for (final String action:item.actions( Dungeon.hero )) {
RedButton btn = new RedButton( action ) {
@Override
protected void onClick() {
item.execute( Dungeon.hero, action );
hide();
owner.hide();
};
};
btn.setSize( Math.max( BUTTON_WIDTH, btn.reqWidth() ), BUTTON_HEIGHT );
if (x + btn.width() > WIDTH) {
x = 0;
y += BUTTON_HEIGHT + GAP;
}
btn.setPos( x, y );
add( btn );
x += btn.width() + GAP;
}
}
resize( WIDTH, (int)(y + (x > 0 ? BUTTON_HEIGHT : 0)) );
}
}
@@ -0,0 +1,123 @@
/*
* 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;
import java.util.Collections;
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;
public class WndJournal extends Window {
private static final int WIDTH = 112;
private static final int HEIGHT = 160;
private static final int ITEM_HEIGHT = 18;
private static final String TXT_TITLE = "Journal";
private BitmapText txtTitle;
private ScrollPane list;
public WndJournal() {
super();
resize( WIDTH, HEIGHT );
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 );
list.setRect( 0, txtTitle.height(), WIDTH, HEIGHT - txtTitle.height() );
}
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.font1x );
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() );
}
}
}
@@ -0,0 +1,72 @@
/*
* 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;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndList extends Window {
private static final int WIDTH = 120;
private static final int MARGIN = 4;
private static final int GAP = 4;
private static final String DOT = "\u007F";
public WndList( String[] items ) {
super();
float pos = MARGIN;
float dotWidth = 0;
float maxWidth = 0;
for (int i=0; i < items.length; i++) {
if (i > 0) {
pos += GAP;
}
BitmapText dot = PixelScene.createText( DOT, 6 );
dot.x = MARGIN;
dot.y = pos;
if (dotWidth == 0) {
dot.measure();
dotWidth = dot.width();
}
add( dot );
BitmapTextMultiline item = PixelScene.createMultiline( items[i], 6 );
item.x = dot.x + dotWidth;
item.y = pos;
item.maxWidth = (int)(WIDTH - MARGIN * 2 - dotWidth);
item.measure();
add( item );
pos += item.height();
float w = item.width();
if (w > maxWidth) {
maxWidth = w;
}
}
resize( (int)(maxWidth + dotWidth + MARGIN * 2), (int)(pos + MARGIN) );
}
}
@@ -0,0 +1,43 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndMessage extends Window {
private static final int WIDTH = 120;
private static final int MARGIN = 4;
public WndMessage( String text ) {
super();
BitmapTextMultiline info = PixelScene.createMultiline( text, 6 );
info.maxWidth = WIDTH - MARGIN * 2;
info.measure();
info.x = info.y = MARGIN;
add( info );
resize(
(int)info.width() + MARGIN * 2,
(int)info.height() + MARGIN * 2 );
}
}
@@ -0,0 +1,69 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndOptions extends Window {
private static final int WIDTH = 120;
private static final int MARGIN = 2;
private static final int BUTTON_HEIGHT = 20;
public WndOptions( String title, String message, String... options ) {
super();
BitmapTextMultiline tfTitle = PixelScene.createMultiline( title, 9 );
tfTitle.hardlight( TITLE_COLOR );
tfTitle.x = tfTitle.y = MARGIN;
tfTitle.maxWidth = WIDTH - MARGIN * 2;
tfTitle.measure();
add( tfTitle );
BitmapTextMultiline tfMesage = PixelScene.createMultiline( message, 8 );
tfMesage.maxWidth = WIDTH - MARGIN * 2;
tfMesage.measure();
tfMesage.x = MARGIN;
tfMesage.y = tfTitle.y + tfTitle.height() + MARGIN;
add( tfMesage );
float pos = tfMesage.y + tfMesage.height() + MARGIN;
for (int i=0; i < options.length; i++) {
final int index = i;
RedButton btn = new RedButton( options[i] ) {
@Override
protected void onClick() {
hide();
onSelect( index );
}
};
btn.setRect( MARGIN, pos, WIDTH - MARGIN * 2, BUTTON_HEIGHT );
add( btn );
pos += BUTTON_HEIGHT + MARGIN;
}
resize( WIDTH, (int)pos );
}
protected void onSelect( int index ) {};
}
@@ -0,0 +1,28 @@
/*
* 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;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndQuest extends WndTitledMessage {
public WndQuest( Mob.NPC questgiver, String text ) {
super( questgiver.sprite(), Utils.capitalize( questgiver.name ), text );
}
}
@@ -0,0 +1,345 @@
/*
* 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;
import java.util.Locale;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.BadgesList;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndRanking extends WndTabbed {
private static final String TXT_ERROR = "Unable to load additional information";
private static final String TXT_STATS = "Stats";
private static final String TXT_ITEMS = "Items";
private static final String TXT_BADGES = "Badges";
private static final int WIDTH = 112;
private static final int HEIGHT = 144;
private static final int TAB_WIDTH = 40;
private Thread thread;
private String error = null;
private Image busy;
public WndRanking( final String gameFile ) {
super();
resize( WIDTH, HEIGHT );
thread = new Thread() {
@Override
public void run() {
try {
Badges.loadGlobal();
Dungeon.loadGame( gameFile );
} catch (Exception e ) {
error = TXT_ERROR;
}
}
};
thread.start();
busy = Icons.BUSY.get();
busy.origin.set( busy.width / 2, busy.height / 2 );
busy.angularSpeed = 720;
busy.x = (WIDTH - busy.width) / 2;
busy.y = (HEIGHT - busy.height) / 2;
add( busy );
}
@Override
public void update() {
super.update();
if (thread != null && !thread.isAlive()) {
thread = null;
if (error == null) {
remove( busy );
createControls();
} else {
hide();
Game.scene().add( new WndError( TXT_ERROR ) );
}
}
}
private void createControls() {
String[] labels =
{TXT_STATS, TXT_ITEMS, TXT_BADGES};
Group[] pages =
{new StatsTab(), new ItemsTab(), new BadgesTab()};
for (int i=0; i < pages.length; i++) {
add( pages[i] );
Tab tab = new RankingTab( labels[i], pages[i] );
tab.setSize( TAB_WIDTH, tabHeight() );
add( tab );
}
select( 0 );
}
private class RankingTab extends LabeledTab {
private Group page;
public RankingTab( String label, Group page ) {
super( label );
this.page = page;
}
@Override
protected void select( boolean value ) {
super.select( value );
if (page != null) {
page.visible = page.active = selected;
}
}
}
private class StatsTab extends Group {
private static final int GAP = 4;
private static final String TXT_TITLE = "Level %d %s";
private static final String TXT_HEALTH = "Health";
private static final String TXT_STR = "Strength";
private static final String TXT_DURATION = "Game Duration";
private static final String TXT_DEPTH = "Maximum Depth";
private static final String TXT_ENEMIES = "Mobs Killed";
private static final String TXT_GOLD = "Gold Collected";
private static final String TXT_FOOD = "Food Eaten";
private static final String TXT_ALCHEMY = "Potions Cooked";
private static final String TXT_ANKHS = "Ankhs Used";
public StatsTab() {
super();
String heroClass = Dungeon.hero.className();
IconTitle title = new IconTitle();
title.icon( HeroSprite.avatar( Dungeon.hero.heroClass, Dungeon.hero.tier() ) );
title.label( Utils.format( TXT_TITLE, Dungeon.hero.lvl, heroClass ).toUpperCase( Locale.ENGLISH ) );
title.setRect( 0, 0, WIDTH, 0 );
add( title );
float pos = title.bottom() + GAP + GAP;
pos = statSlot( this, TXT_STR, Integer.toString( Dungeon.hero.STR ), pos );
pos = statSlot( this, TXT_HEALTH, Integer.toString( Dungeon.hero.HT ), pos );
pos += GAP;
pos = statSlot( this, TXT_DURATION, Integer.toString( (int)Statistics.duration ), pos );
pos += GAP;
pos = statSlot( this, TXT_DEPTH, Integer.toString( Statistics.deepestFloor ), pos );
pos = statSlot( this, TXT_ENEMIES, Integer.toString( Statistics.enemiesSlain ), pos );
pos = statSlot( this, TXT_GOLD, Integer.toString( Statistics.goldCollected ), pos );
pos += GAP;
pos = statSlot( this, TXT_FOOD, Integer.toString( Statistics.foodEaten ), pos );
pos = statSlot( this, TXT_ALCHEMY, Integer.toString( Statistics.potionsCooked ), pos );
pos = statSlot( this, TXT_ANKHS, Integer.toString( Statistics.ankhsUsed ), pos );
}
private float statSlot( Group parent, String label, String value, float pos ) {
BitmapText txt = PixelScene.createText( label, 7 );
txt.y = pos;
parent.add( txt );
txt = PixelScene.createText( value, 7 );
txt.measure();
txt.x = PixelScene.align( WIDTH * 0.65f );
txt.y = pos;
parent.add( txt );
return pos + GAP + txt.baseLine();
}
}
private class ItemsTab extends Group {
private float pos;
public ItemsTab() {
super();
Belongings stuff = Dungeon.hero.belongings;
if (stuff.weapon != null) {
addItem( stuff.weapon );
}
if (stuff.armor != null) {
addItem( stuff.armor );
}
if (stuff.ring1 != null) {
addItem( stuff.ring1 );
}
if (stuff.ring2 != null) {
addItem( stuff.ring2 );
}
if (Dungeon.quickslot instanceof Item &&
Dungeon.hero.belongings.backpack.contains( (Item)Dungeon.quickslot )) {
addItem( (Item)Dungeon.quickslot );
} else if (Dungeon.quickslot instanceof Class){
@SuppressWarnings("unchecked")
Item item = Dungeon.hero.belongings.getItem( (Class<? extends Item>)Dungeon.quickslot );
if (item != null) {
addItem( item );
}
}
}
private void addItem( Item item ) {
ItemButton slot = new ItemButton( item );
slot.setRect( 0, pos, width, ItemButton.HEIGHT );
add( slot );
pos += slot.height() + 1;
}
}
private class BadgesTab extends Group {
public BadgesTab() {
super();
camera = WndRanking.this.camera;
ScrollPane list = new BadgesList( false );
add( list );
list.setSize( WIDTH, HEIGHT );
}
}
private class ItemButton extends Button {
public static final int HEIGHT = 28;
private Item item;
private ItemSlot slot;
private ColorBlock bg;
private BitmapText name;
public ItemButton( Item item ) {
super();
this.item = item;
slot.item( item );
if (item.cursed && item.cursedKnown) {
bg.ra = +0.2f;
bg.ga = -0.1f;
} else if (!item.isIdentified()) {
bg.ra = 0.1f;
bg.ba = 0.1f;
}
}
@Override
protected void createChildren() {
bg = new ColorBlock( HEIGHT, HEIGHT, 0xFF4A4D44 );
add( bg );
slot = new ItemSlot();
add( slot );
name = PixelScene.createText( "?", 7 );
add( name );
super.createChildren();
}
@Override
protected void layout() {
bg.x = x;
bg.y = y;
slot.setRect( x, y, HEIGHT, HEIGHT );
name.x = slot.right() + 2;
name.y = y + (height - name.baseLine()) / 2;
String str = Utils.capitalize( item.name() );
name.text( str );
name.measure();
if (name.width() > width - name.x) {
do {
str = str.substring( 0, str.length() - 1 );
name.text( str + "..." );
name.measure();
} while (name.width() > width - name.x);
}
super.layout();
}
@Override
protected void onTouchDown() {
bg.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
};
protected void onTouchUp() {
bg.brightness( 1.0f );
};
@Override
protected void onClick() {
Game.scene().add( new WndItem( null, item ) );
}
}
}
@@ -0,0 +1,102 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.Game;
import com.shatteredpixel.shatteredpixeldungeon.Rankings;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Ankh;
import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndResurrect extends Window {
private static final String TXT_MESSAGE = "You died, but you were given another chance to win this dungeon. Will you take it?";
private static final String TXT_YES = "Yes, I will fight!";
private static final String TXT_NO = "No, I give up";
private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 18;
private static final float GAP = 2;
public static WndResurrect instance;
public static Object causeOfDeath;
public WndResurrect( final Ankh ankh, Object causeOfDeath ) {
super();
instance = this;
WndResurrect.causeOfDeath = causeOfDeath;
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( ankh.image(), null ) );
titlebar.label( ankh.name() );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
BitmapTextMultiline message = PixelScene.createMultiline( TXT_MESSAGE, 6 );
message.maxWidth = WIDTH;
message.measure();
message.y = titlebar.bottom() + GAP;
add( message );
RedButton btnYes = new RedButton( TXT_YES ) {
@Override
protected void onClick() {
hide();
Statistics.ankhsUsed++;
InterlevelScene.mode = InterlevelScene.Mode.RESURRECT;
Game.switchScene( InterlevelScene.class );
}
};
btnYes.setRect( 0, message.y + message.height() + GAP, WIDTH, BTN_HEIGHT );
add( btnYes );
RedButton btnNo = new RedButton( TXT_NO ) {
@Override
protected void onClick() {
hide();
Rankings.INSTANCE.submit( false );
Hero.reallyDie( WndResurrect.causeOfDeath );
}
};
btnNo.setRect( 0, btnYes.bottom() + GAP, WIDTH, BTN_HEIGHT );
add( btnNo );
resize( WIDTH, (int)btnNo.bottom() );
}
@Override
public void destroy() {
super.destroy();
instance = null;
}
@Override
public void onBackPressed() {
}
}
@@ -0,0 +1,104 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Ghost;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.quest.DriedRose;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndSadGhost extends Window {
private static final String TXT_ROSE =
"Yes! Yes!!! This is it! Please give it to me! " +
"And you can take one of these items, maybe they " +
"will be useful to you in your journey...";
private static final String TXT_RAT =
"Yes! The ugly creature is slain and I can finally rest... " +
"Please take one of these items, maybe they " +
"will be useful to you in your journey...";
private static final String TXT_WEAPON = "Ghost's weapon";
private static final String TXT_ARMOR = "Ghost's armor";
private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 18;
private static final float GAP = 2;
public WndSadGhost( final Ghost ghost, final Item item ) {
super();
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( item.image(), null ) );
titlebar.label( Utils.capitalize( item.name() ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
BitmapTextMultiline message = PixelScene.createMultiline( item instanceof DriedRose ? TXT_ROSE : TXT_RAT, 6 );
message.maxWidth = WIDTH;
message.measure();
message.y = titlebar.bottom() + GAP;
add( message );
RedButton btnWeapon = new RedButton( TXT_WEAPON ) {
@Override
protected void onClick() {
selectReward( ghost, item, Ghost.Quest.weapon );
}
};
btnWeapon.setRect( 0, message.y + message.height() + GAP, WIDTH, BTN_HEIGHT );
add( btnWeapon );
RedButton btnArmor = new RedButton( TXT_ARMOR ) {
@Override
protected void onClick() {
selectReward( ghost, item, Ghost.Quest.armor );
}
};
btnArmor.setRect( 0, btnWeapon.bottom() + GAP, WIDTH, BTN_HEIGHT );
add( btnArmor );
resize( WIDTH, (int)btnArmor.bottom() );
}
private void selectReward( Ghost ghost, Item item, Item reward ) {
hide();
item.detach( Dungeon.hero.belongings.backpack );
if (reward.doPickUp( Dungeon.hero )) {
GLog.i( Hero.TXT_YOU_NOW_HAVE, reward.name() );
} else {
Dungeon.level.drop( reward, ghost.pos ).sprite.drop();
}
ghost.yell( "Farewell, adventurer!" );
ghost.die( null );
Ghost.Quest.complete();
}
}
@@ -0,0 +1,171 @@
/*
* 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;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.watabou.noosa.Camera;
import com.watabou.noosa.audio.Sample;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.CheckBox;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndSettings extends Window {
private static final String TXT_ZOOM_IN = "+";
private static final String TXT_ZOOM_OUT = "-";
private static final String TXT_ZOOM_DEFAULT = "Default Zoom";
private static final String TXT_SCALE_UP = "Scale up UI";
private static final String TXT_MUSIC = "Music";
private static final String TXT_SOUND = "Sound FX";
private static final String TXT_BRIGHTNESS = "Brightness";
private static final String TXT_SWITCH_PORT = "Switch to portrait";
private static final String TXT_SWITCH_LAND = "Switch to landscape";
private static final int WIDTH = 112;
private static final int BTN_HEIGHT = 20;
private static final int GAP = 2;
private RedButton btnZoomOut;
private RedButton btnZoomIn;
public WndSettings( boolean inGame ) {
super();
if (inGame) {
int w = BTN_HEIGHT;
// Zoom out
btnZoomOut = new RedButton( TXT_ZOOM_OUT ) {
@Override
protected void onClick() {
zoom( Camera.main.zoom - 1 );
}
};
add( btnZoomOut.setRect( 0, 0, w, BTN_HEIGHT) );
// Zoom in
btnZoomIn = new RedButton( TXT_ZOOM_IN ) {
@Override
protected void onClick() {
zoom( Camera.main.zoom + 1 );
}
};
add( btnZoomIn.setRect( WIDTH - w, 0, w, BTN_HEIGHT) );
// Default zoom
add( new RedButton( TXT_ZOOM_DEFAULT ) {
@Override
protected void onClick() {
zoom( PixelScene.defaultZoom );
}
}.setRect( btnZoomOut.right(), 0, WIDTH - btnZoomIn.width() - btnZoomOut.width(), BTN_HEIGHT ) );
} else {
CheckBox btnScaleUp = new CheckBox( TXT_SCALE_UP ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.scaleUp(checked());
}
};
btnScaleUp.setRect( 0, 0, WIDTH, BTN_HEIGHT );
btnScaleUp.checked( ShatteredPixelDungeon.scaleUp() );
add( btnScaleUp );
}
CheckBox btnMusic = new CheckBox( TXT_MUSIC ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.music(checked());
}
};
btnMusic.setRect( 0, BTN_HEIGHT + GAP, WIDTH, BTN_HEIGHT );
btnMusic.checked( ShatteredPixelDungeon.music() );
add( btnMusic );
CheckBox btnSound = new CheckBox( TXT_SOUND ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.soundFx(checked());
Sample.INSTANCE.play( Assets.SND_CLICK );
}
};
btnSound.setRect( 0, btnMusic.bottom() + GAP, WIDTH, BTN_HEIGHT );
btnSound.checked( ShatteredPixelDungeon.soundFx() );
add( btnSound );
if (!inGame) {
RedButton btnOrientation = new RedButton( orientationText() ) {
@Override
protected void onClick() {
ShatteredPixelDungeon.landscape(!ShatteredPixelDungeon.landscape());
}
};
btnOrientation.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT );
add( btnOrientation );
resize( WIDTH, (int)btnOrientation.bottom() );
} else {
CheckBox btnBrightness = new CheckBox( TXT_BRIGHTNESS ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.brightness(checked());
}
};
btnBrightness.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT );
btnBrightness.checked( ShatteredPixelDungeon.brightness() );
add( btnBrightness );
resize( WIDTH, (int)btnBrightness.bottom() );
}
}
private void zoom( float value ) {
Camera.main.zoom( value );
ShatteredPixelDungeon.zoom((int) (value - PixelScene.defaultZoom));
updateEnabled();
}
private void updateEnabled() {
float zoom = Camera.main.zoom;
btnZoomIn.enable( zoom < PixelScene.maxZoom );
btnZoomOut.enable( zoom > PixelScene.minZoom );
}
private String orientationText() {
return ShatteredPixelDungeon.landscape() ? TXT_SWITCH_PORT : TXT_SWITCH_LAND;
}
}
@@ -0,0 +1,133 @@
/*
* 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;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.Game;
import com.watabou.noosa.TouchArea;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.utils.SparseArray;
public class WndStory extends Window {
private static final int WIDTH = 120;
private static final int MARGIN = 6;
private static final float bgR = 0.77f;
private static final float bgG = 0.73f;
private static final float bgB = 0.62f;
public static final int ID_SEWERS = 0;
public static final int ID_PRISON = 1;
public static final int ID_CAVES = 2;
public static final int ID_METROPOLIS = 3;
public static final int ID_HALLS = 4;
private static final SparseArray<String> CHAPTERS = new SparseArray<String>();
static {
CHAPTERS.put( ID_SEWERS,
"The Dungeon lies right beneath the City, its upper levels actually constitute the City's sewer system. " +
"Being nominally a part of the City, these levels are not that dangerous. No one will call it a safe place, " +
"but at least you won't need to deal with evil magic here." );
CHAPTERS.put( ID_PRISON,
"Many years ago an underground prison was built here for the most dangerous criminals. At the time it seemed " +
"like a very clever idea, because this place indeed was very hard to escape. But soon dark miasma started to permeate " +
"from below, driving prisoners and guards insane. In the end the prison was abandoned, though some convicts " +
"were left locked up here." );
CHAPTERS.put( ID_CAVES,
"The caves, which stretch down under the abandoned prison, are sparcely populated. They lie too deep to be exploited " +
"by the City and they are too poor in minerals to interest the dwarves. In the past there was a trade outpost " +
"somewhere here on the route between these two states, but it has perished since the decline of Dwarven Metropolis. " +
"Only omnipresent gnolls and subterranean animals dwell here now." );
CHAPTERS.put( ID_METROPOLIS,
"Dwarven Metropolis was once the greatest of dwarven city-states. In its heyday the mechanized army of dwarves " +
"has successfully repelled the invasion of the old god and his demon army. But it is said, that the returning warriors " +
"have brought seeds of corruption with them, and that victory was the beginning of the end for the underground kingdom." );
CHAPTERS.put( ID_HALLS,
"In the past these levels were the outskirts of Metropolis. After the costly victory in the war with the old god " +
"dwarves were too weakened to clear them of remaining demons. Gradually demons have tightened their grip on this place " +
"and now it's called Demon Halls.\n\n" +
"Very few adventurers have ever descended this far..." );
};
private BitmapTextMultiline tf;
private float delay;
public WndStory( String text ) {
super( 0, 0, Chrome.get( Chrome.Type.SCROLL ) );
tf = PixelScene.createMultiline( text, 7 );
tf.maxWidth = WIDTH - MARGIN * 2;
tf.measure();
tf.ra = bgR;
tf.ga = bgG;
tf.ba = bgB;
tf.rm = -bgR;
tf.gm = -bgG;
tf.bm = -bgB;
tf.x = MARGIN;
add( tf );
add( new TouchArea( chrome ) {
@Override
protected void onClick( Touch touch ) {
hide();
}
} );
resize( (int)(tf.width() + MARGIN * 2), (int)Math.min( tf.height(), 180 ) );
}
@Override
public void update() {
super.update();
if (delay > 0 && (delay -= Game.elapsed) <= 0) {
chrome.visible = tf.visible = true;
}
}
public static void showChapter( int id ) {
if (Dungeon.chapters.contains( id )) {
return;
}
String text = CHAPTERS.get( id );
if (text != null) {
WndStory wnd = new WndStory( text );
if ((wnd.delay = 0.6f) > 0) {
wnd.chrome.visible = wnd.tf.visible = false;
}
Game.scene().add( wnd );
Dungeon.chapters.add( id );
}
}
}
@@ -0,0 +1,187 @@
/*
* 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;
import java.util.ArrayList;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Game;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndTabbed extends Window {
protected ArrayList<Tab> tabs = new ArrayList<WndTabbed.Tab>();
protected Tab selected;
public WndTabbed() {
super( 0, 0, Chrome.get( Chrome.Type.TAB_SET ) );
}
protected Tab add( Tab tab ) {
tab.setPos( tabs.size() == 0 ?
-chrome.marginLeft() + 1 :
tabs.get( tabs.size() - 1 ).right(), height );
tab.select( false );
super.add( tab );
tabs.add( tab );
return tab;
}
public void select( int index ) {
select( tabs.get( index ) );
}
public void select( Tab tab ) {
if (tab != selected) {
for (Tab t : tabs) {
if (t == selected) {
t.select( false );
} else if (t == tab) {
t.select( true );
}
}
selected = tab;
}
}
@Override
public void resize( int w, int h ) {
// -> super.resize(...)
this.width = w;
this.height = h;
chrome.size(
width + chrome.marginHor(),
height + chrome.marginVer() );
camera.resize( (int)chrome.width, (int)(chrome.marginTop() + height + tabHeight()) );
camera.x = (int)(Game.width - camera.screenWidth()) / 2;
camera.y = (int)(Game.height - camera.screenHeight()) / 2;
// <- super.resize(...)
for (Tab tab : tabs) {
remove( tab );
}
ArrayList<Tab> tabs = new ArrayList<WndTabbed.Tab>( this.tabs );
this.tabs.clear();
for (Tab tab : tabs) {
add( tab );
}
}
protected int tabHeight() {
return 25;
}
protected void onClick( Tab tab ) {
select( tab );
}
protected class Tab extends Button {
protected final int CUT = 5;
protected boolean selected;
protected NinePatch bg;
@Override
protected void layout() {
super.layout();
if (bg != null) {
bg.x = x;
bg.y = y;
bg.size( width, height );
}
}
protected void select( boolean value ) {
active = !(selected = value);
if (bg != null) {
remove( bg );
}
bg = Chrome.get( selected ?
Chrome.Type.TAB_SELECTED :
Chrome.Type.TAB_UNSELECTED );
addToBack( bg );
layout();
}
@Override
protected void onClick() {
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
WndTabbed.this.onClick( this );
}
}
protected class LabeledTab extends Tab {
private BitmapText btLabel;
public LabeledTab( String label ) {
super();
btLabel.text( label );
btLabel.measure();
}
@Override
protected void createChildren() {
super.createChildren();
btLabel = PixelScene.createText( 9 );
add( btLabel );
}
@Override
protected void layout() {
super.layout();
btLabel.x = PixelScene.align( x + (width - btLabel.width()) / 2 );
btLabel.y = PixelScene.align( y + (height - btLabel.baseLine()) / 2 ) - 1;
if (!selected) {
btLabel.y -= 2;
}
}
@Override
protected void select( boolean value ) {
super.select( value );
btLabel.am = selected ? 1.0f : 0.6f;
}
}
}
@@ -0,0 +1,72 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Component;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class WndTitledMessage extends Window {
private static final int WIDTH = 120;
private static final int GAP = 2;
private BitmapTextMultiline normal;
private BitmapTextMultiline highlighted;
public WndTitledMessage( Image icon, String title, String message ) {
this( new IconTitle( icon, title ), message );
}
public WndTitledMessage( Component titlebar, String message ) {
super();
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
Highlighter hl = new Highlighter( message );
normal = PixelScene.createMultiline( hl.text, 6 );
normal.maxWidth = WIDTH;
normal.measure();
normal.x = titlebar.left();
normal.y = titlebar.bottom() + GAP;
add( normal );
if (hl.isHighlighted()) {
normal.mask = hl.inverted();
highlighted = PixelScene.createMultiline( hl.text, 6 );
highlighted.maxWidth = normal.maxWidth;
highlighted.measure();
highlighted.x = normal.x;
highlighted.y = normal.y;
add( highlighted );
highlighted.mask = hl.mask;
highlighted.hardlight( TITLE_COLOR );
}
resize( WIDTH, (int)(normal.y + normal.height()) );
}
}
@@ -0,0 +1,250 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Shopkeeper;
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
import com.shatteredpixel.shatteredpixeldungeon.items.Gold;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfHaggler;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndTradeItem extends Window {
private static final float GAP = 2;
private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 18;
private static final String TXT_SALE = "FOR SALE: %s - %dg";
private static final String TXT_BUY = "Buy for %dg";
private static final String TXT_SELL = "Sell for %dg";
private static final String TXT_SELL_1 = "Sell 1 for %dg";
private static final String TXT_SELL_ALL = "Sell all for %dg";
private static final String TXT_CANCEL = "Never mind";
private static final String TXT_SOLD = "You've sold your %s for %dg";
private static final String TXT_BOUGHT = "You've bought %s for %dg";
private WndBag owner;
public WndTradeItem( final Item item, WndBag owner ) {
super();
this.owner = owner;
float pos = createDescription( item, false );
if (item.quantity() == 1) {
RedButton btnSell = new RedButton( Utils.format( TXT_SELL, item.price() ) ) {
@Override
protected void onClick() {
sell( item );
hide();
}
};
btnSell.setRect( 0, pos + GAP, WIDTH, BTN_HEIGHT );
add( btnSell );
pos = btnSell.bottom();
} else {
int priceAll= item.price();
RedButton btnSell1 = new RedButton( Utils.format( TXT_SELL_1, priceAll / item.quantity() ) ) {
@Override
protected void onClick() {
sellOne( item );
hide();
}
};
btnSell1.setRect( 0, pos + GAP, WIDTH, BTN_HEIGHT );
add( btnSell1 );
RedButton btnSellAll = new RedButton( Utils.format( TXT_SELL_ALL, priceAll ) ) {
@Override
protected void onClick() {
sell( item );
hide();
}
};
btnSellAll.setRect( 0, btnSell1.bottom() + GAP, WIDTH, BTN_HEIGHT );
add( btnSellAll );
pos = btnSellAll.bottom();
}
RedButton btnCancel = new RedButton( TXT_CANCEL ) {
@Override
protected void onClick() {
hide();
}
};
btnCancel.setRect( 0, pos + GAP, WIDTH, BTN_HEIGHT );
add( btnCancel );
resize( WIDTH, (int)btnCancel.bottom() );
}
public WndTradeItem( final Heap heap, boolean canBuy ) {
super();
Item item = heap.peek();
float pos = createDescription( item, true );
int price = price( item );
if (canBuy) {
RedButton btnBuy = new RedButton( Utils.format( TXT_BUY, price ) ) {
@Override
protected void onClick() {
hide();
buy( heap );
}
};
btnBuy.setRect( 0, pos + GAP, WIDTH, BTN_HEIGHT );
btnBuy.enable( price <= Dungeon.gold );
add( btnBuy );
RedButton btnCancel = new RedButton( TXT_CANCEL ) {
@Override
protected void onClick() {
hide();
}
};
btnCancel.setRect( 0, btnBuy.bottom() + GAP, WIDTH, BTN_HEIGHT );
add( btnCancel );
resize( WIDTH, (int)btnCancel.bottom() );
} else {
resize( WIDTH, (int)pos );
}
}
@Override
public void hide() {
super.hide();
if (owner != null) {
owner.hide();
Shopkeeper.sell();
}
}
private float createDescription( Item item, boolean forSale ) {
// Title
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( item.image(), item.glowing() ) );
titlebar.label( forSale ?
Utils.format( TXT_SALE, item.toString(), price( item ) ) :
Utils.capitalize( item.toString() ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
// Upgraded / degraded
if (item.levelKnown && item.level > 0) {
titlebar.color( ItemSlot.UPGRADED );
} else if (item.levelKnown && item.level < 0) {
titlebar.color( ItemSlot.DEGRADED );
}
// Description
BitmapTextMultiline info = PixelScene.createMultiline( item.info(), 6 );
info.maxWidth = WIDTH;
info.measure();
info.x = titlebar.left();
info.y = titlebar.bottom() + GAP;
add( info );
return info.y + info.height();
}
private void sell( Item item ) {
Hero hero = Dungeon.hero;
if (item.isEquipped( hero ) && !((EquipableItem)item).doUnequip( hero, false )) {
return;
}
item.detachAll( hero.belongings.backpack );
int price = item.price();
new Gold( price ).doPickUp( hero );
GLog.i( TXT_SOLD, item.name(), price );
}
private void sellOne( Item item ) {
if (item.quantity() <= 1) {
sell( item );
} else {
Hero hero = Dungeon.hero;
item = item.detach( hero.belongings.backpack );
int price = item.price();
new Gold( price ).doPickUp( hero );
GLog.i( TXT_SOLD, item.name(), price );
}
}
private int price( Item item ) {
// This formula is not completely correct...
int price = item.price() * 5 * (Dungeon.depth / 5 + 1);
if (Dungeon.hero.buff( RingOfHaggler.Haggling.class ) != null && price >= 2) {
price /= 2;
}
return price;
}
private void buy( Heap heap ) {
Hero hero = Dungeon.hero;
Item item = heap.pickUp();
int price = price( item );
Dungeon.gold -= price;
GLog.i( TXT_BOUGHT, item.name(), price );
if (!item.doPickUp( hero )) {
Dungeon.level.drop( item, heap.pos ).sprite.drop();
}
}
}
@@ -0,0 +1,104 @@
/*
* 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;
import com.watabou.noosa.BitmapTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Wandmaker;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
public class WndWandmaker extends Window {
private static final String TXT_MESSAGE =
"Oh, I see you have succeeded! I do hope it hasn't troubled you too much. " +
"As I promised, you can choose one of my high quality wands.";
private static final String TXT_BATTLE = "Battle wand";
private static final String TXT_NON_BATTLE = "Non-battle wand";
private static final String TXT_FARAWELL = "Good luck in your quest, %s!";
private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 18;
private static final float GAP = 2;
public WndWandmaker( final Wandmaker wandmaker, final Item item ) {
super();
IconTitle titlebar = new IconTitle();
titlebar.icon( new ItemSprite( item.image(), null ) );
titlebar.label( Utils.capitalize( item.name() ) );
titlebar.setRect( 0, 0, WIDTH, 0 );
add( titlebar );
BitmapTextMultiline message = PixelScene.createMultiline( TXT_MESSAGE, 6 );
message.maxWidth = WIDTH;
message.measure();
message.y = titlebar.bottom() + GAP;
add( message );
RedButton btnBattle = new RedButton( TXT_BATTLE ) {
@Override
protected void onClick() {
selectReward( wandmaker, item, Wandmaker.Quest.wand1 );
}
};
btnBattle.setRect( 0, message.y + message.height() + GAP, WIDTH, BTN_HEIGHT );
add( btnBattle );
RedButton btnNonBattle = new RedButton( TXT_NON_BATTLE ) {
@Override
protected void onClick() {
selectReward( wandmaker, item, Wandmaker.Quest.wand2 );
}
};
btnNonBattle.setRect( 0, btnBattle.bottom() + GAP, WIDTH, BTN_HEIGHT );
add( btnNonBattle );
resize( WIDTH, (int)btnNonBattle.bottom() );
}
private void selectReward( Wandmaker wandmaker, Item item, Wand reward ) {
hide();
item.detach( Dungeon.hero.belongings.backpack );
reward.identify();
if (reward.doPickUp( Dungeon.hero )) {
GLog.i( Hero.TXT_YOU_NOW_HAVE, reward.name() );
} else {
Dungeon.level.drop( reward, wandmaker.pos ).sprite.drop();
}
wandmaker.yell( Utils.format( TXT_FARAWELL, Dungeon.hero.className() ) );
wandmaker.destroy();
wandmaker.sprite.die();
Wandmaker.Quest.complete();
}
}