v0.3.1d: removed strict pixel align pt.2
there is no need to enforce whole interger positions for UI elements. Especially with the recent font changes this was causing alignment problems on high resolution displays. Elements with non-whole number sizes and positions should be used sparingly, but there's no reason to strictly align them.
This commit is contained in:
@@ -65,8 +65,8 @@ public class AboutScene extends PixelScene {
|
||||
final float wataOffset = ShatteredPixelDungeon.landscape() ? colWidth : 0;
|
||||
|
||||
Image shpx = Icons.SHPX.get();
|
||||
shpx.x = align( (colWidth - shpx.width()) / 2 );
|
||||
shpx.y = align( colTop );
|
||||
shpx.x = (colWidth - shpx.width()) / 2;
|
||||
shpx.y = colTop;
|
||||
add( shpx );
|
||||
|
||||
new Flare( 7, 64 ).color( 0x225511, true ).show( shpx, 0 ).angularSpeed = +20;
|
||||
@@ -77,16 +77,16 @@ public class AboutScene extends PixelScene {
|
||||
shpxtitle.hardlight( Window.SHPX_COLOR );
|
||||
add( shpxtitle );
|
||||
|
||||
shpxtitle.x = align( (colWidth - shpxtitle.width()) / 2 );
|
||||
shpxtitle.y = align( shpx.y + shpx.height + 5 );
|
||||
shpxtitle.x = (colWidth - shpxtitle.width()) / 2;
|
||||
shpxtitle.y = shpx.y + shpx.height + 5;
|
||||
|
||||
BitmapTextMultiline shpxtext = createMultiline( TXT_SHPX, 8 );
|
||||
shpxtext.maxWidth = shpxtitle.maxWidth;
|
||||
shpxtext.measure();
|
||||
add( shpxtext );
|
||||
|
||||
shpxtext.x = align( (colWidth - shpxtext.width()) / 2 );
|
||||
shpxtext.y = align( shpxtitle.y + shpxtitle.height() + 12 );
|
||||
shpxtext.x = (colWidth - shpxtext.width()) / 2;
|
||||
shpxtext.y = shpxtitle.y + shpxtitle.height() + 12;
|
||||
|
||||
BitmapTextMultiline shpxlink = createMultiline( LNK_SHPX, 8 );
|
||||
shpxlink.maxWidth = shpxtitle.maxWidth;
|
||||
@@ -107,10 +107,10 @@ public class AboutScene extends PixelScene {
|
||||
add( shpxhotArea );
|
||||
|
||||
Image wata = Icons.WATA.get();
|
||||
wata.x = align( wataOffset + (colWidth - wata.width()) / 2 );
|
||||
wata.y = align( ShatteredPixelDungeon.landscape() ?
|
||||
wata.x = wataOffset + (colWidth - wata.width()) / 2;
|
||||
wata.y = ShatteredPixelDungeon.landscape() ?
|
||||
colTop:
|
||||
shpxlink.y + wata.height + 20);
|
||||
shpxlink.y + wata.height + 20;
|
||||
add( wata );
|
||||
|
||||
new Flare( 7, 64 ).color( 0x112233, true ).show( wata, 0 ).angularSpeed = +20;
|
||||
@@ -121,16 +121,16 @@ public class AboutScene extends PixelScene {
|
||||
wataTitle.hardlight(Window.TITLE_COLOR);
|
||||
add( wataTitle );
|
||||
|
||||
wataTitle.x = align( wataOffset + (colWidth - wataTitle.width()) / 2 );
|
||||
wataTitle.y = align( wata.y + wata.height + 11 );
|
||||
wataTitle.x = wataOffset + (colWidth - wataTitle.width()) / 2;
|
||||
wataTitle.y = wata.y + wata.height + 11;
|
||||
|
||||
BitmapTextMultiline wataText = createMultiline( TXT_WATA, 8 );
|
||||
wataText.maxWidth = wataTitle.maxWidth;
|
||||
wataText.measure();
|
||||
add( wataText );
|
||||
|
||||
wataText.x = align( wataOffset + (colWidth - wataText.width()) / 2 );
|
||||
wataText.y = align( wataTitle.y + wataTitle.height() + 12 );
|
||||
wataText.x = wataOffset + (colWidth - wataText.width()) / 2;
|
||||
wataText.y = wataTitle.y + wataTitle.height() + 12;
|
||||
|
||||
BitmapTextMultiline wataLink = createMultiline( LNK_WATA, 8 );
|
||||
wataLink.maxWidth = wataTitle.maxWidth;
|
||||
|
||||
@@ -91,8 +91,8 @@ public class AmuletScene extends PixelScene {
|
||||
if (noText) {
|
||||
height = amulet.height + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
|
||||
|
||||
amulet.x = align( (Camera.main.width - amulet.width) / 2 );
|
||||
amulet.y = align( (Camera.main.height - height) / 2 );
|
||||
amulet.x = (Camera.main.width - amulet.width) / 2;
|
||||
amulet.y = (Camera.main.height - height) / 2;
|
||||
|
||||
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP );
|
||||
btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
|
||||
@@ -100,10 +100,10 @@ public class AmuletScene extends PixelScene {
|
||||
} else {
|
||||
height = amulet.height + LARGE_GAP + text.height() + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
|
||||
|
||||
amulet.x = align( (Camera.main.width - amulet.width) / 2 );
|
||||
amulet.y = align( (Camera.main.height - height) / 2 );
|
||||
amulet.x = (Camera.main.width - amulet.width) / 2;
|
||||
amulet.y = (Camera.main.height - height) / 2;
|
||||
|
||||
text.x = align( (Camera.main.width - text.width()) / 2 );
|
||||
text.x = (Camera.main.width - text.width()) / 2;
|
||||
text.y = amulet.y + amulet.height + LARGE_GAP;
|
||||
|
||||
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, text.y + text.height() + LARGE_GAP );
|
||||
|
||||
@@ -71,8 +71,8 @@ public class BadgesScene extends PixelScene {
|
||||
BitmapText title = PixelScene.createText( TXT_TITLE, 9 );
|
||||
title.hardlight( Window.TITLE_COLOR );
|
||||
title.measure();
|
||||
title.x = align( (w - title.width()) / 2 );
|
||||
title.y = align( (panel.y - title.baseLine()) / 2 );
|
||||
title.x = (w - title.width()) / 2;
|
||||
title.y = (panel.y - title.baseLine()) / 2;
|
||||
add( title );
|
||||
|
||||
Badges.loadGlobal();
|
||||
|
||||
@@ -188,11 +188,6 @@ public class PixelScene extends Scene {
|
||||
return result;
|
||||
}
|
||||
|
||||
// This one should be used for UI elements
|
||||
public static float align( float pos ) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public static boolean noFade = false;
|
||||
protected void fadeIn() {
|
||||
if (noFade) {
|
||||
|
||||
@@ -79,8 +79,8 @@ public class RankingsScene extends PixelScene {
|
||||
BitmapText title = PixelScene.createText(TXT_TITLE, 9);
|
||||
title.hardlight(Window.SHPX_COLOR);
|
||||
title.measure();
|
||||
title.x = align((w - title.width()) / 2);
|
||||
title.y = align( GAP );
|
||||
title.x = (w - title.width()) / 2;
|
||||
title.y = GAP;
|
||||
add(title);
|
||||
|
||||
if (Rankings.INSTANCE.records.size() > 0) {
|
||||
@@ -89,7 +89,7 @@ public class RankingsScene extends PixelScene {
|
||||
float rowHeight = GameMath.gate(ROW_HEIGHT_MIN, (uiCamera.height - 26)/Rankings.INSTANCE.records.size(), ROW_HEIGHT_MAX);
|
||||
|
||||
float left = (w - Math.min( MAX_ROW_WIDTH, w )) / 2 + GAP;
|
||||
float top = align( (h - rowHeight * Rankings.INSTANCE.records.size()) / 2 );
|
||||
float top = (h - rowHeight * Rankings.INSTANCE.records.size()) / 2;
|
||||
|
||||
int pos = 0;
|
||||
|
||||
@@ -121,15 +121,15 @@ public class RankingsScene extends PixelScene {
|
||||
BitmapText total = PixelScene.createText( "/" + Rankings.INSTANCE.totalNumber, 8 );
|
||||
total.hardlight( 0xCCCCCC );
|
||||
total.measure();
|
||||
total.x = align( (w - total.width()) / 2 );
|
||||
total.y = align( top + pos * rowHeight + GAP );
|
||||
total.x = (w - total.width()) / 2;
|
||||
total.y = top + pos * rowHeight + GAP;
|
||||
add( total );
|
||||
|
||||
float tw = label.width() + won.width() + total.width();
|
||||
label.x = align( (w - tw) / 2 );
|
||||
label.x = (w - tw) / 2;
|
||||
won.x = label.x + label.width();
|
||||
total.x = won.x + won.width();
|
||||
label.y = won.y = total.y = align( h - label.height() - GAP );
|
||||
label.y = won.y = total.y = h - label.height() - GAP;
|
||||
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ public class RankingsScene extends PixelScene {
|
||||
BitmapText noRec = PixelScene.createText(TXT_NO_GAMES, 8);
|
||||
noRec.hardlight( 0xCCCCCC );
|
||||
noRec.measure();
|
||||
noRec.x = align((w - noRec.width()) / 2);
|
||||
noRec.y = align((h - noRec.height()) / 2);
|
||||
noRec.x = (w - noRec.width()) / 2;
|
||||
noRec.y = (h - noRec.height()) / 2;
|
||||
add(noRec);
|
||||
|
||||
}
|
||||
@@ -267,29 +267,29 @@ public class RankingsScene extends PixelScene {
|
||||
shield.x = x;
|
||||
shield.y = y + (height - shield.height) / 2;
|
||||
|
||||
position.x = align( shield.x + (shield.width - position.width()) / 2 );
|
||||
position.y = align( shield.y + (shield.height - position.height()) / 2 + 1 );
|
||||
position.x = shield.x + (shield.width - position.width()) / 2;
|
||||
position.y = shield.y + (shield.height - position.height()) / 2 + 1;
|
||||
|
||||
if (flare != null) {
|
||||
flare.point( shield.center() );
|
||||
}
|
||||
|
||||
classIcon.x = align(x + width - classIcon.width);
|
||||
classIcon.x = x + width - classIcon.width;
|
||||
classIcon.y = shield.y;
|
||||
|
||||
level.x = align( classIcon.x + (classIcon.width - level.width()) / 2 );
|
||||
level.y = align( classIcon.y + (classIcon.height - level.height()) / 2 + 1 );
|
||||
level.x = classIcon.x + (classIcon.width - level.width()) / 2;
|
||||
level.y = classIcon.y + (classIcon.height - level.height()) / 2 + 1;
|
||||
|
||||
steps.x = align(x + width - steps.width - classIcon.width);
|
||||
steps.x = x + width - steps.width - classIcon.width;
|
||||
steps.y = shield.y;
|
||||
|
||||
depth.x = align( steps.x + (steps.width - depth.width()) / 2 );
|
||||
depth.y = align( steps.y + (steps.height - depth.height()) / 2 + 1 );
|
||||
depth.x = steps.x + (steps.width - depth.width()) / 2;
|
||||
depth.y = steps.y + (steps.height - depth.height()) / 2 + 1;
|
||||
|
||||
desc.x = shield.x + shield.width + GAP;
|
||||
desc.maxWidth = (int)(steps.x - desc.x);
|
||||
desc.measure();
|
||||
desc.y = align( shield.y + (shield.height - desc.height()) / 2 + 1 );
|
||||
desc.y = shield.y + (shield.height - desc.height()) / 2 + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -121,8 +121,8 @@ public class StartScene extends PixelScene {
|
||||
add( archs );
|
||||
|
||||
Image title = BannerSprites.get( Type.SELECT_YOUR_HERO );
|
||||
title.x = align( (w - title.width()) / 2 );
|
||||
title.y = align( top );
|
||||
title.x = (w - title.width()) / 2;
|
||||
title.y = top;
|
||||
add( title );
|
||||
|
||||
buttonX = left;
|
||||
@@ -215,8 +215,8 @@ public class StartScene extends PixelScene {
|
||||
for (BitmapText line : text.new LineSplitter().split()) {
|
||||
line.measure();
|
||||
line.hardlight( 0xFFFF00 );
|
||||
line.x = PixelScene.align( w / 2 - line.width() / 2 );
|
||||
line.y = PixelScene.align( pos );
|
||||
line.x = w / 2 - line.width() / 2;
|
||||
line.y = pos;
|
||||
unlock.add( line );
|
||||
|
||||
pos += line.height();
|
||||
@@ -344,12 +344,12 @@ public class StartScene extends PixelScene {
|
||||
super.layout();
|
||||
|
||||
if (secondary.text().length() > 0) {
|
||||
text.y = align( y + (height - text.height() - secondary.baseLine()) / 2 );
|
||||
text.y = y + (height - text.height() - secondary.baseLine()) / 2;
|
||||
|
||||
secondary.x = align( x + (width - secondary.width()) / 2 );
|
||||
secondary.y = align( text.y + text.height() );
|
||||
secondary.x = x + (width - secondary.width()) / 2;
|
||||
secondary.y = text.y + text.height();
|
||||
} else {
|
||||
text.y = align( y + (height - text.baseLine()) / 2 );
|
||||
text.y = y + (height - text.baseLine()) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,10 +430,10 @@ public class StartScene extends PixelScene {
|
||||
|
||||
super.layout();
|
||||
|
||||
avatar.x = align( x + (width - avatar.width()) / 2 );
|
||||
avatar.y = align( y + (height - avatar.height() - name.height()) / 2 );
|
||||
avatar.x = x + (width - avatar.width()) / 2;
|
||||
avatar.y = y + (height - avatar.height() - name.height()) / 2;
|
||||
|
||||
name.x = align( x + (width - name.width()) / 2 );
|
||||
name.x = x + (width - name.width()) / 2;
|
||||
name.y = avatar.y + avatar.height() + SCALE;
|
||||
|
||||
emitter.pos( avatar.x, avatar.y, avatar.width(), avatar.height() );
|
||||
@@ -505,8 +505,8 @@ public class StartScene extends PixelScene {
|
||||
|
||||
super.layout();
|
||||
|
||||
image.x = align( x );
|
||||
image.y = align( y );
|
||||
image.x = x;
|
||||
image.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -84,8 +84,8 @@ public class SurfaceScene extends PixelScene {
|
||||
archs.setSize( w, h );
|
||||
add( archs );
|
||||
|
||||
float vx = align( (w - SKY_WIDTH) / 2 );
|
||||
float vy = align( (h - SKY_HEIGHT - BUTTON_HEIGHT) / 2 );
|
||||
float vx = (w - SKY_WIDTH) / 2;
|
||||
float vy = (h - SKY_HEIGHT - BUTTON_HEIGHT) / 2;
|
||||
|
||||
Point s = Camera.main.cameraToScreen( vx, vy );
|
||||
viewport = new Camera( s.x, s.y, SKY_WIDTH, SKY_HEIGHT, defaultZoom );
|
||||
@@ -129,7 +129,7 @@ public class SurfaceScene extends PixelScene {
|
||||
Avatar a = new Avatar( Dungeon.hero.heroClass );
|
||||
// Removing semitransparent contour
|
||||
a.am = 2; a.aa = -1;
|
||||
a.x = PixelScene.align( (SKY_WIDTH - a.width) / 2 );
|
||||
a.x = (SKY_WIDTH - a.width);
|
||||
a.y = SKY_HEIGHT - a.height;
|
||||
window.add( a );
|
||||
|
||||
|
||||
@@ -213,11 +213,11 @@ public class TitleScene extends PixelScene {
|
||||
protected void layout() {
|
||||
super.layout();
|
||||
|
||||
image.x = align( x + (width - image.width()) / 2 );
|
||||
image.y = align( y );
|
||||
image.x = x + (width - image.width()) / 2;
|
||||
image.y = y;
|
||||
|
||||
label.x = align( x + (width - label.width()) / 2 );
|
||||
label.y = align( image.y + image.height() +2 );
|
||||
label.x = x + (width - label.width()) / 2;
|
||||
label.y = image.y + image.height() +2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -138,8 +138,8 @@ public class WelcomeScene extends PixelScene {
|
||||
title.measure();
|
||||
title.hardlight(Window.SHPX_COLOR);
|
||||
|
||||
title.x = align( (w - title.width()) / 2 );
|
||||
title.y = align( 8 );
|
||||
title.x = (w - title.width()) / 2;
|
||||
title.y = 8;
|
||||
add( title );
|
||||
|
||||
NinePatch panel = Chrome.get(Chrome.Type.WINDOW);
|
||||
|
||||
Reference in New Issue
Block a user