Only show targeting arrows for active stack instance

This commit is contained in:
drdev
2014-07-21 03:54:05 +00:00
parent 8fc35fc858
commit a7f7366771

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 StackInstanceDisplay activeItem;
private SpellAbilityStackInstance activeStackInstance; private SpellAbilityStackInstance activeStackInstance;
private int stackSize; private int stackSize;
@@ -65,6 +66,7 @@ public class VStack extends FDropDown {
@Override @Override
public void update() { public void update() {
activeItem = null;
activeStackInstance = null; //reset before updating stack activeStackInstance = null; //reset before updating stack
if (stackSize != stack.size()) { if (stackSize != stack.size()) {
@@ -109,14 +111,13 @@ public class VStack extends FDropDown {
//iterate stack in reverse so most recent items appear on bottom //iterate stack in reverse so most recent items appear on bottom
SpellAbilityStackInstance stackInstance = null; SpellAbilityStackInstance stackInstance = null;
StackInstanceDisplay display = 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 (iterator.hasNext()) { while (iterator.hasNext()) {
stackInstance = iterator.next(); stackInstance = iterator.next();
display = new StackInstanceDisplay(stackInstance, width); display = new StackInstanceDisplay(stackInstance, width);
if (activeStackInstance == stackInstance) { if (activeStackInstance == stackInstance) {
activeDisplay = display; activeItem = display;
} }
else { //only add non-active items here else { //only add non-active items here
add(display); add(display);
@@ -127,13 +128,13 @@ public class VStack extends FDropDown {
} }
if (activeStackInstance == null) { if (activeStackInstance == null) {
activeStackInstance = stackInstance; //use topmost item on stack as default active item activeStackInstance = stackInstance; //use topmost item on stack as default active item
activeDisplay = display; activeItem = display;
} }
else { else {
activeDisplay.setHeight(display.preferredHeight); //increase active item height to preferred height if needed activeItem.setHeight(display.preferredHeight); //increase active item height to preferred height if needed
add(activeDisplay); add(activeItem);
} }
scrollIntoView(activeDisplay); //scroll active display into view scrollIntoView(activeItem); //scroll active display into view
} }
return new ScrollBounds(totalWidth, y + MARGINS); return new ScrollBounds(totalWidth, y + MARGINS);
} }
@@ -145,22 +146,14 @@ public class VStack extends FDropDown {
@Override @Override
protected void drawOnContainer(Graphics g) { protected void drawOnContainer(Graphics g) {
//draw target arrows immediately above stack //draw target arrows immediately above stack for active item only
for (FDisplayObject child : getChildren()) { if (activeItem != null) {
Vector2 arrowOrigin = new Vector2( Vector2 arrowOrigin = new Vector2(
child.getLeft() + VStack.CARD_WIDTH * FCardPanel.TARGET_ORIGIN_FACTOR_X + VStack.PADDING + VStack.BORDER_THICKNESS, activeItem.getLeft() + VStack.CARD_WIDTH * FCardPanel.TARGET_ORIGIN_FACTOR_X + VStack.PADDING + VStack.BORDER_THICKNESS,
child.getTop() + VStack.CARD_HEIGHT * FCardPanel.TARGET_ORIGIN_FACTOR_Y + VStack.PADDING + VStack.BORDER_THICKNESS); activeItem.getTop() + VStack.CARD_HEIGHT * FCardPanel.TARGET_ORIGIN_FACTOR_Y + VStack.PADDING + VStack.BORDER_THICKNESS);
if (arrowOrigin.y < 0) { TargetChoices targets = activeStackInstance.getSpellAbility().getTargets();
continue; //don't draw arrow scrolled off top Player activator = activeStackInstance.getActivator();
}
if (arrowOrigin.y > getHeight()) {
break; //don't draw arrow scrolled off bottom
}
SpellAbilityStackInstance stackInstance = ((StackInstanceDisplay)child).getStackInstance();
TargetChoices targets = stackInstance.getSpellAbility().getTargets();
Player activator = stackInstance.getActivator();
arrowOrigin = arrowOrigin.add(getScreenPosition()); arrowOrigin = arrowOrigin.add(getScreenPosition());
for (Card c : targets.getTargetCards()) { for (Card c : targets.getTargetCards()) {
@@ -199,10 +192,6 @@ public class VStack extends FDropDown {
preferredHeight = Math.round(height); preferredHeight = Math.round(height);
} }
public SpellAbilityStackInstance getStackInstance() {
return stackInstance;
}
@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 if (activeStackInstance != stackInstance) { //set as active stack instance if not already such