Make it so selection updated when card zoomed closed on a different card

This commit is contained in:
drdev
2015-04-10 20:51:51 +00:00
parent a2879c55b2
commit fba0ae22f1
2 changed files with 22 additions and 1 deletions

View File

@@ -27,7 +27,7 @@ public class CardZoom extends FOverlay {
private static final CardZoom cardZoom = new CardZoom(); private static final CardZoom cardZoom = new CardZoom();
private static List<?> items; private static List<?> items;
private static int currentIndex; private static int currentIndex, initialIndex;
private static CardView currentCard, prevCard, nextCard; private static CardView currentCard, prevCard, nextCard;
private static boolean zoomMode = true; private static boolean zoomMode = true;
private static boolean oneCardView = false; private static boolean oneCardView = false;
@@ -49,6 +49,7 @@ public class CardZoom extends FOverlay {
items = items0; items = items0;
activateHandler = activateHandler0; activateHandler = activateHandler0;
currentIndex = currentIndex0; currentIndex = currentIndex0;
initialIndex = currentIndex0;
currentCard = getCardView(items.get(currentIndex)); currentCard = getCardView(items.get(currentIndex));
prevCard = currentIndex > 0 ? getCardView(items.get(currentIndex - 1)) : null; prevCard = currentIndex > 0 ? getCardView(items.get(currentIndex - 1)) : null;
nextCard = currentIndex < items.size() - 1 ? getCardView(items.get(currentIndex + 1)) : null; nextCard = currentIndex < items.size() - 1 ? getCardView(items.get(currentIndex + 1)) : null;
@@ -67,6 +68,18 @@ public class CardZoom extends FOverlay {
private CardZoom() { private CardZoom() {
} }
@Override
public void setVisible(boolean visible0) {
if (this.isVisible() == visible0) { return; }
super.setVisible(visible0);
//update selected index when hidden if current index is different than initial index
if (!visible0 && activateHandler != null && currentIndex != initialIndex) {
activateHandler.setSelectedIndex(currentIndex);
}
}
private static void incrementCard(int dir) { private static void incrementCard(int dir) {
if (dir > 0) { if (dir > 0) {
if (currentIndex == items.size() - 1) { return; } if (currentIndex == items.size() - 1) { return; }
@@ -227,6 +240,7 @@ public class CardZoom extends FOverlay {
public static interface ActivateHandler { public static interface ActivateHandler {
String getActivateAction(int index); String getActivateAction(int index);
void setSelectedIndex(int index);
void activate(int index); void activate(int index);
} }
} }

View File

@@ -183,6 +183,13 @@ public abstract class VCardDisplayArea extends VDisplayArea implements ActivateH
return MatchController.instance.getGameController().getActivateDescription(orderedCards.get(index)); return MatchController.instance.getGameController().getActivateDescription(orderedCards.get(index));
} }
@Override
public void setSelectedIndex(int index) {
//just scroll card into view
final CardAreaPanel cardPanel = CardAreaPanel.get(orderedCards.get(index));
scrollIntoView(cardPanel);
}
@Override @Override
public void activate(int index) { public void activate(int index) {
final CardAreaPanel cardPanel = CardAreaPanel.get(orderedCards.get(index)); final CardAreaPanel cardPanel = CardAreaPanel.get(orderedCards.get(index));