v0.3.4a: re-added align methods pt.2

Also moved rendered text multiline into the core game
This commit is contained in:
Evan Debenham
2016-02-12 13:46:42 -05:00
committed by Evan Debenham
parent ac9c50f2ac
commit b110c0db8c
49 changed files with 465 additions and 203 deletions
@@ -22,20 +22,19 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes;
import android.content.Intent;
import android.net.Uri;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.RenderedTextMultiline;
import com.watabou.noosa.TouchArea;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
public class AboutScene extends PixelScene {
@@ -65,6 +64,7 @@ public class AboutScene extends PixelScene {
Image shpx = Icons.SHPX.get();
shpx.x = (colWidth - shpx.width()) / 2;
shpx.y = colTop;
align(shpx);
add( shpx );
new Flare( 7, 64 ).color( 0x225511, true ).show( shpx, 0 ).angularSpeed = +20;
@@ -75,12 +75,14 @@ public class AboutScene extends PixelScene {
shpxtitle.x = (colWidth - shpxtitle.width()) / 2;
shpxtitle.y = shpx.y + shpx.height + 5;
align(shpxtitle);
RenderedTextMultiline shpxtext = renderMultiline( TXT_SHPX, 8 );
shpxtext.maxWidth((int)Math.min(colWidth, 120));
add( shpxtext );
shpxtext.setPos((colWidth - shpxtext.width()) / 2, shpxtitle.y + shpxtitle.height() + 12);
align(shpxtext);
RenderedTextMultiline shpxlink = renderMultiline( LNK_SHPX, 8 );
shpxlink.maxWidth(shpxtext.maxWidth());
@@ -88,6 +90,7 @@ public class AboutScene extends PixelScene {
add( shpxlink );
shpxlink.setPos((colWidth - shpxlink.width()) / 2, shpxtext.bottom() + 6);
align(shpxlink);
TouchArea shpxhotArea = new TouchArea( shpxlink.left(), shpxlink.top(), shpxlink.width(), shpxlink.height() ) {
@Override
@@ -103,6 +106,7 @@ public class AboutScene extends PixelScene {
wata.y = ShatteredPixelDungeon.landscape() ?
colTop:
shpxlink.top() + wata.height + 20;
align(wata);
add( wata );
new Flare( 7, 64 ).color( 0x112233, true ).show( wata, 0 ).angularSpeed = +20;
@@ -113,12 +117,14 @@ public class AboutScene extends PixelScene {
wataTitle.x = wataOffset + (colWidth - wataTitle.width()) / 2;
wataTitle.y = wata.y + wata.height + 11;
align(wataTitle);
RenderedTextMultiline wataText = renderMultiline( TXT_WATA, 8 );
wataText.maxWidth((int)Math.min(colWidth, 120));
add( wataText );
wataText.setPos(wataOffset + (colWidth - wataText.width()) / 2, wataTitle.y + wataTitle.height() + 12);
align(wataText);
RenderedTextMultiline wataLink = renderMultiline( LNK_WATA, 8 );
wataLink.maxWidth((int)Math.min(colWidth, 120));
@@ -126,6 +132,7 @@ public class AboutScene extends PixelScene {
add(wataLink);
wataLink.setPos(wataOffset + (colWidth - wataLink.width()) / 2 , wataText.bottom() + 6);
align(wataLink);
TouchArea hotArea = new TouchArea( wataLink.left(), wataLink.top(), wataLink.width(), wataLink.height() ) {
@Override
@@ -20,17 +20,17 @@
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.items.Amulet;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.Amulet;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.watabou.noosa.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.utils.Random;
public class AmuletScene extends PixelScene {
@@ -84,7 +84,8 @@ public class AmuletScene extends PixelScene {
amulet.x = (Camera.main.width - amulet.width) / 2;
amulet.y = (Camera.main.height - height) / 2;
align(amulet);
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP );
btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
@@ -93,8 +94,10 @@ public class AmuletScene extends PixelScene {
amulet.x = (Camera.main.width - amulet.width) / 2;
amulet.y = (Camera.main.height - height) / 2;
align(amulet);
text.setPos((Camera.main.width - text.width()) / 2, amulet.y + amulet.height + LARGE_GAP);
align(text);
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, text.top() + text.height() + LARGE_GAP );
btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
@@ -20,20 +20,20 @@
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.audio.Music;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.Callback;
@@ -75,6 +75,7 @@ public class BadgesScene extends PixelScene {
title.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2 ;
title.y = (top - title.baseLine()) / 2 ;
align(title);
add(title);
Badges.loadGlobal();
@@ -88,6 +89,7 @@ public class BadgesScene extends PixelScene {
button.setPos(
left + j * size + (size - button.width()) / 2,
top + i * size + (size - button.height()) / 2);
align(button);
add( button );
}
}
@@ -25,12 +25,12 @@ import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.noosa.Camera;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.RenderedTextMultiline;
import com.watabou.noosa.ui.Component;
//TODO: update this class with relevant info as new versions come out.
@@ -98,6 +98,7 @@ public class ChangesScene extends PixelScene {
title.hardlight(Window.TITLE_COLOR);
title.x = (w - title.width()) / 2 ;
title.y = 4;
align(title);
add(title);
ExitButton btnExit = new ExitButton();
@@ -556,8 +556,8 @@ public class GameScene extends PixelScene {
private void showBanner( Banner banner ) {
banner.camera = uiCamera;
banner.x = (uiCamera.width - banner.width) / 2 ;
banner.y = (uiCamera.height - banner.height) / 3 ;
banner.x = align( uiCamera, (uiCamera.width - banner.width) / 2 );
banner.y = align( uiCamera, (uiCamera.height - banner.height) / 3 );
add( banner );
}
@@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.glwrap.Texture;
import com.watabou.input.Touchscreen;
@@ -35,9 +36,9 @@ import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.RenderedTextMultiline;
import com.watabou.noosa.Scene;
import com.watabou.noosa.Visual;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.BitmapCache;
import javax.microedition.khronos.opengles.GL10;
@@ -217,23 +218,25 @@ public class PixelScene extends Scene {
}
/**
* These three methods align UI elements to device pixels.
* These methods align UI elements to device pixels.
* e.g. if we have a scale of 3x then valid positions are #.0, #.33, #.67
*/
public static float align( float pos ) {
return Math.round(pos * defaultZoom) / (float)defaultZoom;
}
public static float align( Camera camera, float pos ) {
return Math.round(pos * camera.zoom) / camera.zoom;
}
// This one should be used for UI elements
public static float align( float pos ) {
return Math.round(pos * defaultZoom) / (float)defaultZoom;
public static void align( Visual v ) {
v.x = align( v.x );
v.y = align( v.y );
}
public static void align( Visual v ) {
Camera c = v.camera();
v.x = align( c, v.x );
v.y = align( c, v.y );
public static void align( Component c ){
c.setPos(align(c.left()), align(c.top()));
}
public static boolean noFade = false;
@@ -252,8 +255,8 @@ public class PixelScene extends Scene {
public static void showBadge( Badges.Badge badge ) {
BadgeBanner banner = BadgeBanner.show( badge.image );
banner.camera = uiCamera;
banner.x = (banner.camera.width - banner.width) / 2 ;
banner.y = (banner.camera.height - banner.height) / 3 ;
banner.x = align( banner.camera, (banner.camera.width - banner.width) / 2 );
banner.y = align( banner.camera, (banner.camera.height - banner.height) / 3 );
Game.scene().add( banner );
}
@@ -313,8 +316,8 @@ public class PixelScene extends Scene {
@Override
protected void updateMatrix() {
float sx = Math.round(scroll.x + shakeX);
float sy = Math.round(scroll.y + shakeY);
float sx = align( this, scroll.x + shakeX );
float sy = align( this, scroll.y + shakeY );
matrix[0] = +zoom * invW2;
matrix[5] = -zoom * invH2;
@@ -30,6 +30,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndError;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndRanking;
@@ -37,7 +38,6 @@ import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.RenderedTextMultiline;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.GameMath;
@@ -76,6 +76,7 @@ public class RankingsScene extends PixelScene {
title.hardlight(Window.SHPX_COLOR);
title.x = (w - title.width()) / 2;
title.y = GAP;
align(title);
add(title);
if (Rankings.INSTANCE.records.size() > 0) {
@@ -123,6 +124,10 @@ public class RankingsScene extends PixelScene {
total.x = won.x + won.width();
label.y = won.y = total.y = h - label.height() - GAP;
align(label);
align(total);
align(won);
}
} else {
@@ -256,10 +261,12 @@ public class RankingsScene extends PixelScene {
super.layout();
shield.x = x;
shield.y = y + (height - shield.height) / 2;
shield.y = y + (height - shield.height) / 2f;
align(shield);
position.x = shield.x + (shield.width - position.width()) / 2;
position.y = shield.y + (shield.height - position.height()) / 2 + 1;
position.x = shield.x + (shield.width - position.width()) / 2f;
position.y = shield.y + (shield.height - position.height()) / 2f + 1;
align(position);
if (flare != null) {
flare.point( shield.center() );
@@ -268,17 +275,20 @@ public class RankingsScene extends PixelScene {
classIcon.x = x + width - classIcon.width;
classIcon.y = shield.y;
level.x = classIcon.x + (classIcon.width - level.width()) / 2;
level.y = classIcon.y + (classIcon.height - level.height()) / 2 + 1;
level.x = classIcon.x + (classIcon.width - level.width()) / 2f;
level.y = classIcon.y + (classIcon.height - level.height()) / 2f + 1;
align(level);
steps.x = x + width - steps.width - classIcon.width;
steps.y = shield.y;
depth.x = steps.x + (steps.width - depth.width()) / 2;
depth.y = steps.y + (steps.height - depth.height()) / 2 + 1;
depth.x = steps.x + (steps.width - depth.width()) / 2f;
depth.y = steps.y + (steps.height - depth.height()) / 2f + 1;
align(depth);
desc.maxWidth((int)(steps.x - (shield.x + shield.width + GAP)));
desc.setPos(shield.x + shield.width + GAP, shield.y + (shield.height - desc.height()) / 2 + 1);
desc.setPos(shield.x + shield.width + GAP, shield.y + (shield.height - desc.height()) / 2f + 1);
align(desc);
}
@Override
@@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndChallenges;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndClass;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage;
@@ -43,7 +44,6 @@ import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.RenderedTextMultiline;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.BitmaskEmitter;
import com.watabou.noosa.particles.Emitter;
@@ -108,6 +108,7 @@ public class StartScene extends PixelScene {
Image title = BannerSprites.get( Type.SELECT_YOUR_HERO );
title.x = (w - title.width()) / 2;
title.y = top;
align( title );
add( title );
buttonX = left;
@@ -163,6 +164,7 @@ public class StartScene extends PixelScene {
for (int i=0; i < classes.length; i++) {
ClassShield shield = shields.get( classes[i] );
shield.setRect( left + i * shieldW, top, shieldW, shieldH );
align(shield);
}
ChallengeButton challenge = new ChallengeButton();
@@ -181,12 +183,14 @@ public class StartScene extends PixelScene {
left + (i % 2) * shieldW,
top + (i / 2) * shieldH,
shieldW, shieldH );
align(shield);
}
ChallengeButton challenge = new ChallengeButton();
challenge.setPos(
w/2 - challenge.width()/2,
top + shieldH - challenge.height()/2 );
align(challenge);
add( challenge );
}
@@ -200,6 +204,7 @@ public class StartScene extends PixelScene {
text.maxWidth((int)width);
text.hardlight( 0xFFFF00 );
text.setPos(w / 2 - text.width() / 2, (bottom - BUTTON_HEIGHT) + (BUTTON_HEIGHT - text.height()) / 2);
align(text);
unlock.add(text);
}
@@ -332,6 +337,8 @@ public class StartScene extends PixelScene {
} else {
text.y = y + (height - text.baseLine()) / 2;
}
align(text);
align(secondary);
}
public void secondary( String text, boolean highlighted ) {
@@ -411,9 +418,11 @@ public class StartScene extends PixelScene {
avatar.x = x + (width - avatar.width()) / 2;
avatar.y = y + (height - avatar.height() - name.height()) / 2;
align(avatar);
name.x = x + (width - name.width()) / 2;
name.y = avatar.y + avatar.height() + SCALE;
align(name);
}
@@ -20,11 +20,15 @@
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import java.nio.FloatBuffer;
import java.util.Calendar;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.RatSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.watabou.gltextures.Gradient;
import com.watabou.gltextures.SmartTexture;
import com.watabou.glwrap.Matrix;
@@ -40,16 +44,12 @@ import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.Visual;
import com.watabou.noosa.audio.Music;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
import com.shatteredpixel.shatteredpixeldungeon.sprites.RatSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.watabou.utils.Point;
import com.watabou.utils.Random;
import java.nio.FloatBuffer;
import java.util.Calendar;
public class SurfaceScene extends PixelScene {
private static final int FRAME_WIDTH = 88;
@@ -85,8 +85,8 @@ public class SurfaceScene extends PixelScene {
archs.setSize( w, h );
add( archs );
float vx = (w - SKY_WIDTH) / 2;
float vy = (h - SKY_HEIGHT - BUTTON_HEIGHT) / 2;
float vx = align((w - SKY_WIDTH) / 2f);
float vy = align((h - SKY_HEIGHT - BUTTON_HEIGHT) / 2f);
Point s = Camera.main.cameraToScreen( vx, vy );
viewport = new Camera( s.x, s.y, SKY_WIDTH, SKY_HEIGHT, defaultZoom );
@@ -132,12 +132,14 @@ public class SurfaceScene extends PixelScene {
a.am = 2; a.aa = -1;
a.x = (SKY_WIDTH - a.width) / 2;
a.y = SKY_HEIGHT - a.height;
align(a);
window.add( a );
final Pet pet = new Pet();
pet.rm = pet.gm = pet.bm = 1.2f;
pet.x = SKY_WIDTH / 2 + 2;
pet.y = SKY_HEIGHT - pet.height;
align(pet);
window.add( pet );
window.add( new TouchArea( sky ) {
@@ -212,9 +212,11 @@ public class TitleScene extends PixelScene {
image.x = x + (width - image.width()) / 2;
image.y = y;
align(image);
label.x = x + (width - label.width()) / 2;
label.y = image.y + image.height() +2;
align(label);
}
@Override
@@ -9,10 +9,10 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites;
import com.shatteredpixel.shatteredpixeldungeon.effects.Fireball;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.RenderedTextMultiline;
import com.watabou.noosa.audio.Sample;
import javax.microedition.khronos.opengles.GL10;