v3.2.4: adjusted how buff bar handles display cutouts
This commit is contained in:
@@ -368,26 +368,23 @@ public class GameScene extends PixelScene {
|
||||
|
||||
int uiSize = SPDSettings.interfaceSize();
|
||||
|
||||
//TODO make top bar transparent and add 1px of top status and menu bar to it?
|
||||
|
||||
//most cutouts supported by the game are small
|
||||
// but some are more 'medium' can can be supported with a little UI offsetting
|
||||
float mediumCutoutOffset = 0;
|
||||
//Some more medium sized display cutouts can obstruct the buff bar, so we limit the length
|
||||
// of the 1st row in some cases
|
||||
float buffBarTopRowMaxWidth = 50; //default max width
|
||||
if (largeInsetTop != insets.top){
|
||||
//most notably iOS's Dynamic island, which must exist in this case
|
||||
if (DeviceCompat.isiOS()){
|
||||
//TODO we should handle this logic in platformSupport, not hardcode it here
|
||||
mediumCutoutOffset = 7;
|
||||
//TODO bad to hardcode this atm, need to change this so platformsupport returns cutout dimensions
|
||||
buffBarTopRowMaxWidth = 15;
|
||||
} else if (DeviceCompat.isAndroid()) {
|
||||
//some android hole punches can also be big too
|
||||
RectF cutout = Game.platform.getDisplayCutout().scale(1f / defaultZoom);
|
||||
//if the cutout is positioned to obstruct the buff bar
|
||||
//TODO could buff bar just be squished in some cases here?
|
||||
if (cutout.left < 80
|
||||
&& cutout.top < 10
|
||||
&& cutout.right > 32
|
||||
&& cutout.bottom > 11) {
|
||||
mediumCutoutOffset = (int) Math.floor(cutout.bottom - 11);
|
||||
&& cutout.bottom > 12) {
|
||||
buffBarTopRowMaxWidth = cutout.left - 32; //subtract starting position
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -404,7 +401,7 @@ public class GameScene extends PixelScene {
|
||||
|
||||
status = new StatusPane( SPDSettings.interfaceSize() > 0 );
|
||||
status.camera = uiCamera;
|
||||
StatusPane.cutoutOffset = mediumCutoutOffset;
|
||||
StatusPane.buffBarTopRowMaxWidth = buffBarTopRowMaxWidth;
|
||||
status.setRect(insets.left, uiSize > 0 ? uiCamera.height-39-insets.bottom : screentop, uiCamera.width - insets.left - insets.right, 0 );
|
||||
add(status);
|
||||
|
||||
|
||||
@@ -149,6 +149,8 @@ public class BuffIndicator extends Component {
|
||||
|
||||
private boolean large = false;
|
||||
|
||||
public float firstRowWidth = -1;
|
||||
|
||||
public BuffIndicator( Char ch, boolean large ) {
|
||||
super();
|
||||
|
||||
@@ -226,31 +228,62 @@ public class BuffIndicator extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO several aspects of the layout code have been a bit hackily changed to support 2 rows
|
||||
// should clean this up
|
||||
|
||||
//layout
|
||||
int row = 0;
|
||||
int pos = 0;
|
||||
float lastIconLeft = 0;
|
||||
int total = 0;
|
||||
for (BuffButton icon : buffButtons.values()){
|
||||
if (total >= 14){ //buff bar supports a max of 14 buffs at once
|
||||
icon.visible = false;
|
||||
continue;
|
||||
}
|
||||
icon.visible = true;
|
||||
|
||||
icon.topOffset = (row > 0 && !large) ? -1 : 0;
|
||||
icon.updateIcon();
|
||||
//button areas are slightly oversized, especially on small buttons
|
||||
icon.setRect(x + pos * (size + 1), y, size + 1, size + (large ? 0 : 5));
|
||||
icon.setRect(x + pos * (size + 1), y + row*(size+1)-icon.topOffset, size + 1, size + (large ? 0 : 5));
|
||||
PixelScene.align(icon);
|
||||
pos++;
|
||||
|
||||
icon.visible = icon.left() <= right();
|
||||
lastIconLeft = icon.left();
|
||||
|
||||
if ((row+1)*(size+1) <= height
|
||||
&& (pos * (size + 1) > width || (row == 0 && firstRowWidth != -1 && pos * (size + 1) > firstRowWidth))){
|
||||
row++;
|
||||
pos = 0;
|
||||
}
|
||||
total++;
|
||||
}
|
||||
|
||||
buffsHidden = false;
|
||||
//squish buff icons together if there isn't enough room
|
||||
float excessWidth = lastIconLeft - right();
|
||||
if (excessWidth > 0) {
|
||||
float leftAdjust = excessWidth/(buffButtons.size()-1);
|
||||
//can't squish by more than 50% on large and 62% on small
|
||||
if (large && leftAdjust >= size*0.48f) leftAdjust = size*0.5f;
|
||||
if (!large && leftAdjust >= size*0.62f) leftAdjust = size*0.65f;
|
||||
float cumulativeAdjust = leftAdjust * (buffButtons.size()-1);
|
||||
|
||||
ArrayList<BuffButton> buttons = new ArrayList<>(buffButtons.values());
|
||||
if (excessWidth > 0) {
|
||||
//if multiple rows, only compress last row
|
||||
ArrayList<BuffButton> buttons = new ArrayList<>();
|
||||
float lastRowY = y + row*(size+1);
|
||||
int i = 1;
|
||||
for (BuffButton button : buffButtons.values()){
|
||||
if (i > 14){
|
||||
button.visible = false;
|
||||
buffsHidden = true;
|
||||
continue;
|
||||
}
|
||||
if (button.top()+button.topOffset == lastRowY){
|
||||
buttons.add(button);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
float leftAdjust = excessWidth/(buttons.size()-1);
|
||||
float cumulativeAdjust = leftAdjust * (buttons.size()-1);
|
||||
|
||||
Collections.reverse(buttons);
|
||||
for (BuffButton icon : buttons) {
|
||||
icon.setPos(icon.left() - cumulativeAdjust, icon.top());
|
||||
@@ -277,6 +310,7 @@ public class BuffIndicator extends Component {
|
||||
private Buff buff;
|
||||
|
||||
private boolean large;
|
||||
private int topOffset = 0;
|
||||
|
||||
public Image grey; //only for small
|
||||
public BitmapText text; //only for large
|
||||
@@ -329,7 +363,7 @@ public class BuffIndicator extends Component {
|
||||
protected void layout() {
|
||||
super.layout();
|
||||
grey.x = icon.x = this.x + (large ? 0 : 1);
|
||||
grey.y = icon.y = this.y + (large ? 0 : 2);
|
||||
grey.y = icon.y = this.y + (large ? 0 : 2) + topOffset;
|
||||
|
||||
if (text.width > width()){
|
||||
text.scale.set(PixelScene.align(0.5f));
|
||||
|
||||
@@ -80,6 +80,7 @@ public class StatusPane extends Component {
|
||||
|
||||
//lower the buff indicator to avoid larger cutouts (e.g. iPhone dynamic island)
|
||||
public static float cutoutOffset;
|
||||
public static float buffBarTopRowMaxWidth = 50;
|
||||
|
||||
public StatusPane( boolean large ){
|
||||
super();
|
||||
@@ -232,7 +233,8 @@ public class StatusPane extends Component {
|
||||
|
||||
heroInfoOnBar.setRect(heroInfo.right(), y, 50, 9);
|
||||
|
||||
buffs.setRect( x + 31, y + 8 + cutoutOffset, 50, 8 );
|
||||
buffs.firstRowWidth = buffBarTopRowMaxWidth;
|
||||
buffs.setRect( x + 31, y + 8 + cutoutOffset, 50, 15 );
|
||||
|
||||
busy.x = x + 1;
|
||||
busy.y = y + 37;
|
||||
|
||||
Reference in New Issue
Block a user