v1.2.0: added margin functionality to item slots

This commit is contained in:
Evan Debenham 2022-02-28 11:36:15 -05:00
parent 2105c9147a
commit b0835c5483
4 changed files with 32 additions and 14 deletions

View File

@ -33,6 +33,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Image;
import com.watabou.utils.Rect;
public class ItemSlot extends Button {
@ -44,7 +45,9 @@ public class ItemSlot extends Button {
private static final float ENABLED = 1.0f;
private static final float DISABLED = 0.3f;
private Rect margin = new Rect();
protected ItemSprite sprite;
protected Item item;
protected BitmapText status;
@ -110,8 +113,8 @@ public class ItemSlot extends Button {
protected void layout() {
super.layout();
sprite.x = x + (width - sprite.width) / 2f;
sprite.y = y + (height - sprite.height) / 2f;
sprite.x = x + margin.left + (width - sprite.width - (margin.left + margin.right)) / 2f;
sprite.y = y + margin.top + (height - sprite.height - (margin.top + margin.bottom)) / 2f;
PixelScene.align(sprite);
if (status != null) {
@ -121,14 +124,14 @@ public class ItemSlot extends Button {
} else {
status.scale.set(1f);
}
status.x = x;
status.y = y;
status.x = x + margin.left;
status.y = y + margin.top;
PixelScene.align(status);
}
if (extra != null) {
extra.x = x + (width - extra.width());
extra.y = y;
extra.x = x + (width - extra.width()) - margin.right;
extra.y = y + margin.top;
PixelScene.align(extra);
if ((status.width() + extra.width()) > width){
@ -139,14 +142,14 @@ public class ItemSlot extends Button {
}
if (itemIcon != null){
itemIcon.x = x + width - (ItemSpriteSheet.Icons.SIZE + itemIcon.width())/2f;
itemIcon.y = y + (ItemSpriteSheet.Icons.SIZE - itemIcon.height)/2f;
itemIcon.x = x + width - (ItemSpriteSheet.Icons.SIZE + itemIcon.width())/2f - margin.right;
itemIcon.y = y + (ItemSpriteSheet.Icons.SIZE - itemIcon.height)/2f + margin.top;
PixelScene.align(itemIcon);
}
if (level != null) {
level.x = x + (width - level.width());
level.y = y + (height - level.baseLine() - 1);
level.x = x + (width - level.width()) - margin.right;
level.y = y + (height - level.baseLine() - 1) - margin.bottom;
PixelScene.align(level);
}
@ -274,6 +277,11 @@ public class ItemSlot extends Button {
}
public void setMargins( int left, int top, int right, int bottom){
margin.set(left, top, right, bottom);
layout();
}
@Override
protected String hoverText() {
if (item != null && item.name() != null) {

View File

@ -68,8 +68,13 @@ public class LootIndicator extends Tag {
protected void layout() {
super.layout();
if (!flipped) slot.setRect( x+2, y+2, SIZE-3, height-4 );
else slot.setRect( x+(width()-SIZE)+1, y+2, SIZE-3, height-4 );
if (!flipped) {
slot.setRect( x, y, SIZE, height );
slot.setMargins(2, 2, 0, 2);
} else {
slot.setRect( x+(width()-SIZE), y, SIZE, height );
slot.setMargins(0, 2, 2, 2);
}
}

View File

@ -254,6 +254,10 @@ public class QuickSlotButton extends Button {
&& (Dungeon.hero.buff(LostInventory.class) == null || Dungeon.quickslot.getItem(slotNum).keptThoughLostInvent));
}
public void slotMargins( int left, int top, int right, int bottom){
slot.setMargins(left, top, right, bottom);
}
public static void useTargeting(int idx){
instance[idx].useTargeting();
}

View File

@ -460,7 +460,8 @@ public class Toolbar extends Component {
@Override
protected void layout() {
super.layout();
slot.setRect( x + borderLeft, y + 2, width - borderLeft-borderRight, height - 4 );
slot.setRect( x, y, width, height );
slot.slotMargins(borderLeft, 2, borderRight, 2);
}
@Override