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 ); 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 ); return shrink( 1 );
} }
public Rect scale( int d ){
return new Rect( left * d, top * d, right * d, bottom * d );
}
public ArrayList<Point> getPoints() { public ArrayList<Point> getPoints() {
ArrayList<Point> points = new ArrayList<>(); ArrayList<Point> points = new ArrayList<>();
for (int i = left; i <= right; i++) for (int i = left; i <= right; i++)

View File

@@ -144,4 +144,8 @@ public class RectF {
return shrink( 1 ); 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.QuickSlotButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.ResumeIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.ResumeIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane; import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.Tag;
import com.shatteredpixel.shatteredpixeldungeon.ui.TargetHealthIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.TargetHealthIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.Toast; import com.shatteredpixel.shatteredpixeldungeon.ui.Toast;
import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar; 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.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter; import com.watabou.noosa.particles.Emitter;
import com.watabou.utils.DeviceCompat;
import com.watabou.utils.GameMath; import com.watabou.utils.GameMath;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import com.watabou.utils.RectF;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -725,38 +728,44 @@ public class GameScene extends PixelScene {
if (scene == null) return; 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()) { 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 { } 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(); float pos = scene.toolbar.top();
//FIXME adjusting this to position even without visibility resulted in deadlocks
if (scene.tagAttack){ if (scene.tagAttack){
scene.attack.setPos( tagLeft, pos - scene.attack.height()); scene.attack.setRect( tagLeft, pos - Tag.SIZE, tagWidth, Tag.SIZE );
scene.attack.flip(tagLeft == 0); scene.attack.flip(tagsOnLeft);
pos = scene.attack.top(); pos = scene.attack.top();
} }
if (scene.tagLoot) { if (scene.tagLoot) {
scene.loot.setPos( tagLeft, pos - scene.loot.height() ); scene.loot.setRect( tagLeft, pos - Tag.SIZE, tagWidth, Tag.SIZE );
scene.loot.flip(tagLeft == 0); scene.loot.flip(tagsOnLeft);
pos = scene.loot.top(); pos = scene.loot.top();
} }
if (scene.tagAction) { if (scene.tagAction) {
scene.action.setPos( tagLeft, pos - scene.action.height() ); scene.action.setRect( tagLeft, pos - Tag.SIZE, tagWidth, Tag.SIZE );
scene.action.flip(tagLeft == 0); scene.action.flip(tagsOnLeft);
pos = scene.action.top(); pos = scene.action.top();
} }
if (scene.tagResume) { if (scene.tagResume) {
scene.resume.setPos(tagLeft, pos - scene.resume.height()); scene.resume.setRect( tagLeft, pos - Tag.SIZE, tagWidth, Tag.SIZE );
scene.resume.flip(tagLeft == 0); scene.resume.flip(tagsOnLeft);
} }
} }

View File

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

View File

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

View File

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

View File

@@ -37,7 +37,7 @@ public class LootIndicator extends Tag {
public LootIndicator() { public LootIndicator() {
super( 0x1F75CC ); super( 0x1F75CC );
setSize( 24, 24 ); setSize( SIZE, SIZE );
visible = false; visible = false;
} }
@@ -67,7 +67,9 @@ public class LootIndicator extends Tag {
protected void layout() { protected void layout() {
super.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 @Override

View File

@@ -34,7 +34,7 @@ public class ResumeIndicator extends Tag {
public ResumeIndicator() { public ResumeIndicator() {
super(0xCDD5C0); super(0xCDD5C0);
setSize( 24, 24 ); setSize( SIZE, SIZE );
visible = false; visible = false;
@@ -57,7 +57,8 @@ public class ResumeIndicator extends Tag {
protected void layout() { protected void layout() {
super.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; icon.y = y + (height - icon.height) / 2f;
PixelScene.align(icon); PixelScene.align(icon);
} }

View File

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