diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/CheckBox.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/CheckBox.java index e709aad70..f3829acd9 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/CheckBox.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/CheckBox.java @@ -37,10 +37,12 @@ public class CheckBox extends RedButton { text.x = PixelScene.align( PixelScene.uiCamera, x + margin ); text.y = PixelScene.align( PixelScene.uiCamera, y + margin ); - - icon.x = PixelScene.align( PixelScene.uiCamera, x + width - margin - icon.width ); - icon.y = PixelScene.align( PixelScene.uiCamera, y + (height - icon.height()) / 2 ); - } + + margin = (height - icon.height) / 2; + + icon.x = PixelScene.align( PixelScene.uiCamera, x + width - margin - icon.width ); + icon.y = PixelScene.align( PixelScene.uiCamera, y + margin ); + } public boolean checked() { return checked; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java new file mode 100644 index 000000000..6e733139b --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java @@ -0,0 +1,62 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 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 + */ +package com.shatteredpixel.shatteredpixeldungeon.ui; + +import com.watabou.noosa.ColorBlock; +import com.watabou.noosa.ui.Component; + +public class HealthBar extends Component { + + private static final int COLOR_BG = 0xFFCC0000; + private static final int COLOR_LVL = 0xFF00EE00; + + private static final int HEIGHT = 2; + + private ColorBlock hpBg; + private ColorBlock hpLvl; + + private float level; + + @Override + protected void createChildren() { + hpBg = new ColorBlock( 1, 1, COLOR_BG ); + add( hpBg ); + + hpLvl = new ColorBlock( 1, 1, COLOR_LVL ); + add( hpLvl ); + + height = HEIGHT; + } + + @Override + protected void layout() { + + hpBg.x = hpLvl.x = x; + hpBg.y = hpLvl.y = y; + + hpBg.size( width, HEIGHT ); + hpLvl.size( width * level, HEIGHT ); + + height = HEIGHT; + } + + public void level( float value ) { + level = value; + layout(); + } +} diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/ItemSlot.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ItemSlot.java index eb708faa4..eaf3ba043 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/ItemSlot.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ItemSlot.java @@ -50,8 +50,9 @@ public class ItemSlot extends Button { private static final String TXT_KEY_DEPTH = "\u007F%d"; private static final String TXT_LEVEL = "%+d"; - - // Special items for containers + private static final String TXT_CURSED = "";//"-"; + + // Special "virtual items" public static final Item CHEST = new Item() { public int image() { return ItemSpriteSheet.CHEST; }; }; @@ -172,8 +173,8 @@ public class ItemSlot extends Button { int level = item.visiblyUpgraded(); if (level != 0) { - bottomRight.text( item.levelKnown ? Utils.format( TXT_LEVEL, level ) : "" ); - bottomRight.measure(); + bottomRight.text( item.levelKnown ? Utils.format( TXT_LEVEL, level ) : TXT_CURSED ); + bottomRight.measure(); bottomRight.hardlight( level > 0 ? UPGRADED : DEGRADED ); } else { bottomRight.text( null ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java index 7848d982c..c8430154d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java @@ -63,8 +63,8 @@ public class LootIndicator extends Tag { Heap heap = Dungeon.level.heaps.get( Dungeon.hero.pos ); if (heap != null) { - Item item = - heap.type == Heap.Type.CHEST ? ItemSlot.CHEST : + Item item = + heap.type == Heap.Type.CHEST || heap.type == Heap.Type.MIMIC ? ItemSlot.CHEST : heap.type == Heap.Type.LOCKED_CHEST ? ItemSlot.LOCKED_CHEST : heap.type == Heap.Type.CRYSTAL_CHEST ? ItemSlot.CRYSTAL_CHEST : heap.type == Heap.Type.TOMB ? ItemSlot.TOMB : diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/RedButton.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/RedButton.java index af4f8df06..77721d4a8 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/RedButton.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/RedButton.java @@ -66,18 +66,18 @@ public class RedButton extends Button { icon.x = x + text.x - icon.width() - 2; icon.y = y + (height - icon.height()) / 2; } - }; - + } + @Override protected void onTouchDown() { bg.brightness( 1.2f ); Sample.INSTANCE.play( Assets.SND_CLICK ); - }; + } @Override protected void onTouchUp() { bg.resetColor(); - }; + } public void enable( boolean value ) { active = value; @@ -89,7 +89,11 @@ public class RedButton extends Button { text.measure(); layout(); } - + + public void textColor( int value ) { + text.hardlight( value ); + } + public void icon( Image icon ) { if (this.icon != null) { remove( this.icon ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/ResumeIndicator.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ResumeIndicator.java index 379d5b0b2..4cc673e64 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/ResumeIndicator.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ResumeIndicator.java @@ -1,6 +1,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.watabou.noosa.Image; /** @@ -22,15 +23,17 @@ public class ResumeIndicator extends Tag { @Override protected void createChildren() { super.createChildren(); - icon = Icons.get(Icons.RESUME); - add(icon); + + icon = Icons.get( Icons.RESUME ); + add( icon ); } @Override protected void layout() { super.layout(); - icon.x = x + (width - icon.width()) / 2; - icon.y = y + (height - icon.height()) / 2; + + icon.x = PixelScene.align( PixelScene.uiCamera, x+1 + (width - icon.width) / 2 ); + icon.y = PixelScene.align( PixelScene.uiCamera, y + (height - icon.height) / 2 ); } @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/ScrollPane.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ScrollPane.java index ea2fed4c5..b7c8fcd43 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/ScrollPane.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ScrollPane.java @@ -108,11 +108,9 @@ public class ScrollPane extends Component { ScrollPane.this.onClick( p.x, p.y ); } - } - - // true if dragging is in progress + } + private boolean dragging = false; - // last touch coords private PointF lastPos = new PointF(); @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java index 7f8da7852..1e1325866 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -120,12 +120,12 @@ public class StatusPane extends Component { danger = new DangerIndicator(); add( danger ); - resume = new ResumeIndicator(); - add ( resume ); - loot = new LootIndicator(); add( loot ); + resume = new ResumeIndicator(); + add ( resume ); + buffs = new BuffIndicator( Dungeon.hero ); add( buffs ); } @@ -151,21 +151,49 @@ public class StatusPane extends Component { keys.y = 6; - danger.setPos( width - danger.width(), 20 ); - - loot.setPos( width - loot.width(), danger.bottom() + 2 ); - - resume.setPos( width - resume.width(), (loot.visible ? loot.bottom() : danger.bottom()) + 2 ); + layoutTags(); buffs.setPos( 32, 11 ); btnMenu.setPos( width - btnMenu.width(), 1 ); } + private void layoutTags() { + + float pos = 18; + + if (tagDanger) { + danger.setPos( width - danger.width(), pos ); + pos = danger.bottom() + 1; + } + + if (tagLoot) { + loot.setPos( width - loot.width(), pos ); + pos = loot.bottom() + 1; + } + + if (tagResume) { + resume.setPos( width - resume.width(), pos ); + } + } + + private boolean tagDanger = false; + private boolean tagLoot = false; + private boolean tagResume = false; + @Override public void update() { super.update(); + if (tagDanger != danger.visible || tagLoot != loot.visible || tagResume != resume.visible) { + + tagDanger = danger.visible; + tagLoot = loot.visible; + tagResume = resume.visible; + + layoutTags(); + } + float health = (float)Dungeon.hero.HP / Dungeon.hero.HT; if (health == 0) { @@ -211,8 +239,6 @@ public class StatusPane extends Component { lastTier = tier; avatar.copy( HeroSprite.avatar( Dungeon.hero.heroClass, tier ) ); } - - resume.setPos( width - resume.width(), (loot.visible ? loot.bottom() : danger.bottom()) + 2 ); } private static class MenuButton extends Button { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java index 619b6f345..2028c2869 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java @@ -29,6 +29,7 @@ import com.watabou.noosa.Group; import com.watabou.noosa.NinePatch; import com.watabou.noosa.TouchArea; import com.shatteredpixel.shatteredpixeldungeon.Chrome; +import com.shatteredpixel.shatteredpixeldungeon.effects.ShadowBox; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.watabou.utils.Signal; @@ -38,7 +39,8 @@ public class Window extends Group implements Signal.Listener { protected int height; protected TouchArea blocker; - protected NinePatch chrome; + protected ShadowBox shadow; + protected NinePatch chrome; public static final int TITLE_COLOR = 0xFFFF44; public static final int SHPX_COLOR = 0x33BB33; @@ -69,10 +71,16 @@ public class Window extends Group implements Signal.Listener { add( blocker ); this.chrome = chrome; - + this.width = width; this.height = height; - + + shadow = new ShadowBox(); + shadow.am = 0.5f; + shadow.camera = PixelScene.uiCamera.visible ? + PixelScene.uiCamera : Camera.main; + add( shadow ); + chrome.x = -chrome.marginLeft(); chrome.y = -chrome.marginTop(); chrome.size( @@ -88,7 +96,12 @@ public class Window extends Group implements Signal.Listener { camera.y = (int)(Game.height - camera.height * camera.zoom) / 2; camera.scroll.set( chrome.x, chrome.y ); Camera.add( camera ); - + + shadow.boxRect( + camera.x / camera.zoom, + camera.y / camera.zoom, + chrome.width(), chrome.height ); + Keys.event.add( this ); } @@ -103,6 +116,8 @@ public class Window extends Group implements Signal.Listener { camera.resize( (int)chrome.width, (int)chrome.height ); camera.x = (int)(Game.width - camera.screenWidth()) / 2; camera.y = (int)(Game.height - camera.screenHeight()) / 2; + + shadow.boxRect( camera.x / camera.zoom, camera.y / camera.zoom, chrome.width(), chrome.height ); } public void hide() {