Support bringing non-active items to front

This commit is contained in:
drdev
2014-07-21 03:49:33 +00:00
parent a471d88ade
commit 8fc35fc858
2 changed files with 39 additions and 14 deletions

View File

@@ -333,6 +333,7 @@ public class GuiMobile implements IGuiBase {
ZoneType zoneType = zones.get(0); ZoneType zoneType = zones.get(0);
switch (zoneType) { switch (zoneType) {
case Battlefield: case Battlefield:
players.clear(); //clear since no zones need to be restored
return true; //Battlefield is always open return true; //Battlefield is always open
default: default:
//open zone tab for given zone if needed //open zone tab for given zone if needed

View File

@@ -45,6 +45,7 @@ public class VStack extends FDropDown {
private final MagicStack stack; private final MagicStack stack;
private final LobbyPlayer localPlayer; private final LobbyPlayer localPlayer;
private SpellAbilityStackInstance activeStackInstance;
private int stackSize; private int stackSize;
@@ -58,8 +59,14 @@ public class VStack extends FDropDown {
return false; return false;
} }
//temporarily reveal zones targeted by active stack instance
private void revealTargetZones() {
}
@Override @Override
public void update() { public void update() {
activeStackInstance = null; //reset before updating stack
if (stackSize != stack.size()) { if (stackSize != stack.size()) {
int oldStackSize = stackSize; int oldStackSize = stackSize;
stackSize = stack.size(); stackSize = stack.size();
@@ -68,6 +75,7 @@ public class VStack extends FDropDown {
if (stackSize > 0) { if (stackSize > 0) {
if (!isVisible()) { if (!isVisible()) {
if (stackSize > oldStackSize) { //don't re-show stack if user hid it and then resolved an item on the stack if (stackSize > oldStackSize) { //don't re-show stack if user hid it and then resolved an item on the stack
revealTargetZones();
show(); show();
} }
return; //don't call super.update() either way since show handles this return; //don't call super.update() either way since show handles this
@@ -85,7 +93,6 @@ public class VStack extends FDropDown {
protected ScrollBounds updateAndGetPaneSize(float maxWidth, float maxVisibleHeight) { protected ScrollBounds updateAndGetPaneSize(float maxWidth, float maxVisibleHeight) {
clear(); clear();
float height;
float x = MARGINS; float x = MARGINS;
float y = MARGINS; float y = MARGINS;
float totalWidth = Math.min(4 * CARD_WIDTH, maxWidth); float totalWidth = Math.min(4 * CARD_WIDTH, maxWidth);
@@ -94,27 +101,39 @@ public class VStack extends FDropDown {
if (stack.isEmpty()) { //show label if stack empty if (stack.isEmpty()) { //show label if stack empty
FLabel label = add(new FLabel.Builder().text("[Empty]").font(FONT).align(HAlignment.CENTER).build()); FLabel label = add(new FLabel.Builder().text("[Empty]").font(FONT).align(HAlignment.CENTER).build());
height = Math.round(label.getAutoSizeBounds().height) + 2 * PADDING; float height = Math.round(label.getAutoSizeBounds().height) + 2 * PADDING;
label.setBounds(x, y, width, height); label.setBounds(x, y, width, height);
return new ScrollBounds(totalWidth, y + height + MARGINS); return new ScrollBounds(totalWidth, y + height + MARGINS);
} }
else { else {
//iterate stack in reverse so most recent items appear on bottom //iterate stack in reverse so most recent items appear on bottom
height = 0; SpellAbilityStackInstance stackInstance = null;
StackInstanceDisplay display = null;
StackInstanceDisplay activeDisplay = null;
float overlap = Math.round(CARD_HEIGHT / 2 + PADDING + BORDER_THICKNESS); float overlap = Math.round(CARD_HEIGHT / 2 + PADDING + BORDER_THICKNESS);
Iterator<SpellAbilityStackInstance> iterator = stack.reverseIterator(); Iterator<SpellAbilityStackInstance> iterator = stack.reverseIterator();
while (true) { while (iterator.hasNext()) {
StackInstanceDisplay display = add(new StackInstanceDisplay(iterator.next(), width)); stackInstance = iterator.next();
if (iterator.hasNext()) { //make items have top half of card be overlapped display = new StackInstanceDisplay(stackInstance, width);
display.setBounds(x, y, width, overlap); if (activeStackInstance == stackInstance) {
y += overlap; activeDisplay = display;
} }
else { //use full preferred height of display for bottom item on stack else { //only add non-active items here
display.setBounds(x, y, width, display.preferredHeight); add(display);
y += display.preferredHeight;
break;
} }
//use full preferred height of display for topmost item on stack, overlap amount for other items
display.setBounds(x, y, width, iterator.hasNext() ? overlap : display.preferredHeight);
y += display.getHeight();
} }
if (activeStackInstance == null) {
activeStackInstance = stackInstance; //use topmost item on stack as default active item
activeDisplay = display;
}
else {
activeDisplay.setHeight(display.preferredHeight); //increase active item height to preferred height if needed
add(activeDisplay);
}
scrollIntoView(activeDisplay); //scroll active display into view
} }
return new ScrollBounds(totalWidth, y + MARGINS); return new ScrollBounds(totalWidth, y + MARGINS);
} }
@@ -186,6 +205,11 @@ public class VStack extends FDropDown {
@Override @Override
public boolean tap(float x, float y, int count) { public boolean tap(float x, float y, int count) {
if (activeStackInstance != stackInstance) { //set as active stack instance if not already such
activeStackInstance = stackInstance;
VStack.this.updateSizeAndPosition();
return true;
}
final Player player = stackInstance.getSpellAbility().getActivatingPlayer(); final Player player = stackInstance.getSpellAbility().getActivatingPlayer();
final PlayerController controller = player.getController(); final PlayerController controller = player.getController();
if (stackInstance.getSpellAbility().isOptionalTrigger() && player.getLobbyPlayer() == localPlayer && controller != null) { if (stackInstance.getSpellAbility().isOptionalTrigger() && player.getLobbyPlayer() == localPlayer && controller != null) {
@@ -247,8 +271,8 @@ public class VStack extends FDropDown {
float w = getWidth(); float w = getWidth();
float h = preferredHeight; float h = preferredHeight;
boolean needAlpha = h > getHeight(); boolean needAlpha = (activeStackInstance != stackInstance);
if (needAlpha) { //use alpha for cards below top of stack if (needAlpha) { //use alpha for non-active items on stack
g.setAlphaComposite(ALPHA_COMPOSITE); g.setAlphaComposite(ALPHA_COMPOSITE);
} }