Merging 1.7.5 Source: ui changes

This commit is contained in:
Evan Debenham 2015-01-30 14:05:10 -05:00
parent 4499685b09
commit 894f7d9d06
9 changed files with 148 additions and 37 deletions

View File

@ -37,10 +37,12 @@ public class CheckBox extends RedButton {
text.x = PixelScene.align( PixelScene.uiCamera, x + margin ); text.x = PixelScene.align( PixelScene.uiCamera, x + margin );
text.y = PixelScene.align( PixelScene.uiCamera, y + margin ); text.y = PixelScene.align( PixelScene.uiCamera, y + margin );
icon.x = PixelScene.align( PixelScene.uiCamera, x + width - margin - icon.width ); margin = (height - icon.height) / 2;
icon.y = PixelScene.align( PixelScene.uiCamera, y + (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() { public boolean checked() {
return checked; return checked;

View File

@ -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 <http://www.gnu.org/licenses/>
*/
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();
}
}

View File

@ -50,8 +50,9 @@ public class ItemSlot extends Button {
private static final String TXT_KEY_DEPTH = "\u007F%d"; private static final String TXT_KEY_DEPTH = "\u007F%d";
private static final String TXT_LEVEL = "%+d"; private static final String TXT_LEVEL = "%+d";
private static final String TXT_CURSED = "";//"-";
// Special items for containers
// Special "virtual items"
public static final Item CHEST = new Item() { public static final Item CHEST = new Item() {
public int image() { return ItemSpriteSheet.CHEST; }; public int image() { return ItemSpriteSheet.CHEST; };
}; };
@ -172,8 +173,8 @@ public class ItemSlot extends Button {
int level = item.visiblyUpgraded(); int level = item.visiblyUpgraded();
if (level != 0) { if (level != 0) {
bottomRight.text( item.levelKnown ? Utils.format( TXT_LEVEL, level ) : "" ); bottomRight.text( item.levelKnown ? Utils.format( TXT_LEVEL, level ) : TXT_CURSED );
bottomRight.measure(); bottomRight.measure();
bottomRight.hardlight( level > 0 ? UPGRADED : DEGRADED ); bottomRight.hardlight( level > 0 ? UPGRADED : DEGRADED );
} else { } else {
bottomRight.text( null ); bottomRight.text( null );

View File

@ -63,8 +63,8 @@ public class LootIndicator extends Tag {
Heap heap = Dungeon.level.heaps.get( Dungeon.hero.pos ); Heap heap = Dungeon.level.heaps.get( Dungeon.hero.pos );
if (heap != null) { if (heap != null) {
Item item = Item item =
heap.type == Heap.Type.CHEST ? ItemSlot.CHEST : 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.LOCKED_CHEST ? ItemSlot.LOCKED_CHEST :
heap.type == Heap.Type.CRYSTAL_CHEST ? ItemSlot.CRYSTAL_CHEST : heap.type == Heap.Type.CRYSTAL_CHEST ? ItemSlot.CRYSTAL_CHEST :
heap.type == Heap.Type.TOMB ? ItemSlot.TOMB : heap.type == Heap.Type.TOMB ? ItemSlot.TOMB :

View File

@ -66,18 +66,18 @@ public class RedButton extends Button {
icon.x = x + text.x - icon.width() - 2; icon.x = x + text.x - icon.width() - 2;
icon.y = y + (height - icon.height()) / 2; icon.y = y + (height - icon.height()) / 2;
} }
}; }
@Override @Override
protected void onTouchDown() { protected void onTouchDown() {
bg.brightness( 1.2f ); bg.brightness( 1.2f );
Sample.INSTANCE.play( Assets.SND_CLICK ); Sample.INSTANCE.play( Assets.SND_CLICK );
}; }
@Override @Override
protected void onTouchUp() { protected void onTouchUp() {
bg.resetColor(); bg.resetColor();
}; }
public void enable( boolean value ) { public void enable( boolean value ) {
active = value; active = value;
@ -89,7 +89,11 @@ public class RedButton extends Button {
text.measure(); text.measure();
layout(); layout();
} }
public void textColor( int value ) {
text.hardlight( value );
}
public void icon( Image icon ) { public void icon( Image icon ) {
if (this.icon != null) { if (this.icon != null) {
remove( this.icon ); remove( this.icon );

View File

@ -1,6 +1,7 @@
package com.shatteredpixel.shatteredpixeldungeon.ui; package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image; import com.watabou.noosa.Image;
/** /**
@ -22,15 +23,17 @@ public class ResumeIndicator extends Tag {
@Override @Override
protected void createChildren() { protected void createChildren() {
super.createChildren(); super.createChildren();
icon = Icons.get(Icons.RESUME);
add(icon); icon = Icons.get( Icons.RESUME );
add( icon );
} }
@Override @Override
protected void layout() { protected void layout() {
super.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 @Override

View File

@ -108,11 +108,9 @@ public class ScrollPane extends Component {
ScrollPane.this.onClick( p.x, p.y ); ScrollPane.this.onClick( p.x, p.y );
} }
} }
// true if dragging is in progress
private boolean dragging = false; private boolean dragging = false;
// last touch coords
private PointF lastPos = new PointF(); private PointF lastPos = new PointF();
@Override @Override

View File

@ -120,12 +120,12 @@ public class StatusPane extends Component {
danger = new DangerIndicator(); danger = new DangerIndicator();
add( danger ); add( danger );
resume = new ResumeIndicator();
add ( resume );
loot = new LootIndicator(); loot = new LootIndicator();
add( loot ); add( loot );
resume = new ResumeIndicator();
add ( resume );
buffs = new BuffIndicator( Dungeon.hero ); buffs = new BuffIndicator( Dungeon.hero );
add( buffs ); add( buffs );
} }
@ -151,21 +151,49 @@ public class StatusPane extends Component {
keys.y = 6; keys.y = 6;
danger.setPos( width - danger.width(), 20 ); layoutTags();
loot.setPos( width - loot.width(), danger.bottom() + 2 );
resume.setPos( width - resume.width(), (loot.visible ? loot.bottom() : danger.bottom()) + 2 );
buffs.setPos( 32, 11 ); buffs.setPos( 32, 11 );
btnMenu.setPos( width - btnMenu.width(), 1 ); 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 @Override
public void update() { public void update() {
super.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; float health = (float)Dungeon.hero.HP / Dungeon.hero.HT;
if (health == 0) { if (health == 0) {
@ -211,8 +239,6 @@ public class StatusPane extends Component {
lastTier = tier; lastTier = tier;
avatar.copy( HeroSprite.avatar( Dungeon.hero.heroClass, 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 { private static class MenuButton extends Button {

View File

@ -29,6 +29,7 @@ import com.watabou.noosa.Group;
import com.watabou.noosa.NinePatch; import com.watabou.noosa.NinePatch;
import com.watabou.noosa.TouchArea; import com.watabou.noosa.TouchArea;
import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.effects.ShadowBox;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.utils.Signal; import com.watabou.utils.Signal;
@ -38,7 +39,8 @@ public class Window extends Group implements Signal.Listener<Key> {
protected int height; protected int height;
protected TouchArea blocker; protected TouchArea blocker;
protected NinePatch chrome; protected ShadowBox shadow;
protected NinePatch chrome;
public static final int TITLE_COLOR = 0xFFFF44; public static final int TITLE_COLOR = 0xFFFF44;
public static final int SHPX_COLOR = 0x33BB33; public static final int SHPX_COLOR = 0x33BB33;
@ -69,10 +71,16 @@ public class Window extends Group implements Signal.Listener<Key> {
add( blocker ); add( blocker );
this.chrome = chrome; this.chrome = chrome;
this.width = width; this.width = width;
this.height = height; 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.x = -chrome.marginLeft();
chrome.y = -chrome.marginTop(); chrome.y = -chrome.marginTop();
chrome.size( chrome.size(
@ -88,7 +96,12 @@ public class Window extends Group implements Signal.Listener<Key> {
camera.y = (int)(Game.height - camera.height * camera.zoom) / 2; camera.y = (int)(Game.height - camera.height * camera.zoom) / 2;
camera.scroll.set( chrome.x, chrome.y ); camera.scroll.set( chrome.x, chrome.y );
Camera.add( camera ); Camera.add( camera );
shadow.boxRect(
camera.x / camera.zoom,
camera.y / camera.zoom,
chrome.width(), chrome.height );
Keys.event.add( this ); Keys.event.add( this );
} }
@ -103,6 +116,8 @@ public class Window extends Group implements Signal.Listener<Key> {
camera.resize( (int)chrome.width, (int)chrome.height ); camera.resize( (int)chrome.width, (int)chrome.height );
camera.x = (int)(Game.width - camera.screenWidth()) / 2; camera.x = (int)(Game.width - camera.screenWidth()) / 2;
camera.y = (int)(Game.height - camera.screenHeight()) / 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() { public void hide() {