v1.1.2: added inset support for notched iPhones in landscape

This commit is contained in:
Evan Debenham 2022-01-06 12:06:52 -05:00
parent 16f3774a1a
commit cc221bc089
10 changed files with 64 additions and 25 deletions

View File

@ -71,4 +71,13 @@ public class DeviceCompat {
Gdx.app.log( tag, message );
}
public static RectF getSafeInsets(){
RectF result = new RectF();
result.left = Gdx.graphics.getSafeInsetLeft();
result.top = Gdx.graphics.getSafeInsetTop();
result.right = Gdx.graphics.getSafeInsetRight();
result.bottom = Gdx.graphics.getSafeInsetBottom();
return result;
}
}

View File

@ -148,6 +148,10 @@ public class Rect {
return shrink( 1 );
}
public Rect scale( int d ){
return new Rect( left * d, top * d, right * d, bottom * d );
}
public ArrayList<Point> getPoints() {
ArrayList<Point> points = new ArrayList<>();
for (int i = left; i <= right; i++)

View File

@ -143,5 +143,9 @@ public class RectF {
public RectF shrink() {
return shrink( 1 );
}
public RectF scale( float d ){
return new RectF( left * d, top * d, right * d, bottom * d );
}
}

View File

@ -87,6 +87,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.LootIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.ResumeIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Tag;
import com.shatteredpixel.shatteredpixeldungeon.ui.TargetHealthIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.Toast;
import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar;
@ -116,8 +117,10 @@ import com.watabou.noosa.Visual;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
import com.watabou.utils.DeviceCompat;
import com.watabou.utils.GameMath;
import com.watabou.utils.Random;
import com.watabou.utils.RectF;
import java.io.IOException;
import java.util.ArrayList;
@ -725,38 +728,44 @@ public class GameScene extends PixelScene {
if (scene == null) return;
float tagLeft = SPDSettings.flipTags() ? 0 : uiCamera.width - scene.attack.width();
//primarily for phones displays with notches
//TODO Android never draws into notch atm, perhaps allow it for center notches?
RectF insets = DeviceCompat.getSafeInsets();
insets = insets.scale(1f / uiCamera.zoom);
boolean tagsOnLeft = SPDSettings.flipTags();
float tagWidth = Tag.SIZE + (tagsOnLeft ? insets.left : insets.right);
float tagLeft = tagsOnLeft ? 0 : uiCamera.width - tagWidth;
if (SPDSettings.flipTags()) {
scene.log.setRect(scene.attack.width(), scene.toolbar.top()-2, uiCamera.width - scene.attack.width(), 0);
scene.log.setRect(tagWidth, scene.toolbar.top()-2, uiCamera.width - tagWidth - insets.right, 0);
} else {
scene.log.setRect(0, scene.toolbar.top()-2, uiCamera.width - scene.attack.width(), 0 );
scene.log.setRect(insets.left, scene.toolbar.top()-2, uiCamera.width - tagWidth - insets.left, 0);
}
float pos = scene.toolbar.top();
//FIXME adjusting this to position even without visibility resulted in deadlocks
if (scene.tagAttack){
scene.attack.setPos( tagLeft, pos - scene.attack.height());
scene.attack.flip(tagLeft == 0);
scene.attack.setRect( tagLeft, pos - Tag.SIZE, tagWidth, Tag.SIZE );
scene.attack.flip(tagsOnLeft);
pos = scene.attack.top();
}
if (scene.tagLoot) {
scene.loot.setPos( tagLeft, pos - scene.loot.height() );
scene.loot.flip(tagLeft == 0);
scene.loot.setRect( tagLeft, pos - Tag.SIZE, tagWidth, Tag.SIZE );
scene.loot.flip(tagsOnLeft);
pos = scene.loot.top();
}
if (scene.tagAction) {
scene.action.setPos( tagLeft, pos - scene.action.height() );
scene.action.flip(tagLeft == 0);
scene.action.setRect( tagLeft, pos - Tag.SIZE, tagWidth, Tag.SIZE );
scene.action.flip(tagsOnLeft);
pos = scene.action.top();
}
if (scene.tagResume) {
scene.resume.setPos(tagLeft, pos - scene.resume.height());
scene.resume.flip(tagLeft == 0);
scene.resume.setRect( tagLeft, pos - Tag.SIZE, tagWidth, Tag.SIZE );
scene.resume.flip(tagsOnLeft);
}
}

View File

@ -39,7 +39,7 @@ public class ActionIndicator extends Tag {
instance = this;
setSize( 24, 24 );
setSize( SIZE, SIZE );
visible = false;
}
@ -59,8 +59,9 @@ public class ActionIndicator extends Tag {
super.layout();
if (icon != null){
icon.x = x + (width - icon.width()) / 2;
icon.y = y + (height - icon.height()) / 2;
if (!flipped) icon.x = x + (SIZE - icon.width()) / 2f + 1;
else icon.x = x + width - (SIZE + icon.width()) / 2f - 1;
icon.y = y + (height - icon.height()) / 2f;
PixelScene.align(icon);
if (!members.contains(icon))
add(icon);

View File

@ -56,7 +56,7 @@ public class AttackIndicator extends Tag {
instance = this;
lastTarget = null;
setSize(24, 24);
setSize(SIZE, SIZE);
visible(false);
enable(false);
}
@ -75,10 +75,11 @@ public class AttackIndicator extends Tag {
@Override
protected synchronized void layout() {
super.layout();
if (sprite != null) {
sprite.x = x + (width - sprite.width()) / 2 + 1;
sprite.y = y + (height - sprite.height()) / 2;
if (!flipped) sprite.x = x + (SIZE - sprite.width()) / 2f + 1;
else sprite.x = x + width - (SIZE + sprite.width()) / 2f - 1;
sprite.y = y + (height - sprite.height()) / 2f;
PixelScene.align(sprite);
}
}

View File

@ -40,11 +40,13 @@ public class DangerIndicator extends Tag {
private int enemyIndex = 0;
private int lastNumber = -1;
public static int HEIGHT = 16;
public DangerIndicator() {
super( 0xFF4C4C );
setSize( 24, 16 );
setSize( SIZE, HEIGHT );
visible = false;
}

View File

@ -37,7 +37,7 @@ public class LootIndicator extends Tag {
public LootIndicator() {
super( 0x1F75CC );
setSize( 24, 24 );
setSize( SIZE, SIZE );
visible = false;
}
@ -66,8 +66,10 @@ public class LootIndicator extends Tag {
@Override
protected void layout() {
super.layout();
slot.setRect( x + 2, y + 3, width - 3, height - 6 );
if (!flipped) slot.setRect( x + 1, y, SIZE, height );
else slot.setRect( x + (width() - SIZE) - 1, y, SIZE, height );
}
@Override

View File

@ -34,7 +34,7 @@ public class ResumeIndicator extends Tag {
public ResumeIndicator() {
super(0xCDD5C0);
setSize( 24, 24 );
setSize( SIZE, SIZE );
visible = false;
@ -57,7 +57,8 @@ public class ResumeIndicator extends Tag {
protected void layout() {
super.layout();
icon.x = x+1 + (width - icon.width) / 2f;
if (!flipped) icon.x = x + (SIZE - icon.width()) / 2f + 1;
else icon.x = x + width - (SIZE + icon.width()) / 2f - 1;
icon.y = y + (height - icon.height) / 2f;
PixelScene.align(icon);
}

View File

@ -34,6 +34,10 @@ public class Tag extends Button {
protected NinePatch bg;
protected float lightness = 0;
public static int SIZE = 24;
protected boolean flipped = false;
public Tag( int color ) {
super();
@ -68,7 +72,9 @@ public class Tag extends Button {
}
public void flip(boolean value){
flipped = value;
bg.flipHorizontal(value);
layout();
}
@Override