From cc4d4965d7b34a6d66a461df78c09503c8a3c6a6 Mon Sep 17 00:00:00 2001 From: drdev Date: Wed, 16 Apr 2014 04:15:20 +0000 Subject: [PATCH] Support dragging up to select ability --- .../forge/screens/match/InputSelectCard.java | 33 +++++++++++++++---- .../screens/match/views/VCardDisplayArea.java | 14 ++++++-- forge-gui-mobile/src/forge/toolbox/FList.java | 2 +- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/forge-gui-mobile/src/forge/screens/match/InputSelectCard.java b/forge-gui-mobile/src/forge/screens/match/InputSelectCard.java index 314c0737304..c48a4cb3f40 100644 --- a/forge-gui-mobile/src/forge/screens/match/InputSelectCard.java +++ b/forge-gui-mobile/src/forge/screens/match/InputSelectCard.java @@ -26,15 +26,18 @@ import forge.util.Callback; import forge.util.Utils; public class InputSelectCard { + private static final float LIST_OPTION_HEIGHT = Utils.AVG_FINGER_HEIGHT; + private static CardOptionsList visibleList; + private InputSelectCard() { } - public static void selectCard(CardAreaPanel cardPanel, List orderedCards) { + public static void selectCard(CardAreaPanel cardPanel) { Input currentInput = FControl.getInputQueue().getInput(); if (currentInput == null) { return; } - if (CardOptionsList.visibleList != null) { - boolean isCurrentOwner = (CardOptionsList.visibleList.owner == cardPanel); + if (visibleList != null) { + boolean isCurrentOwner = (visibleList.owner == cardPanel); CardOptionsList.hide(); if (isCurrentOwner) { return; @@ -75,6 +78,26 @@ public class InputSelectCard { } } + public static boolean handlePan(CardAreaPanel cardPanel, float x, float y, boolean isPanStop) { + if (visibleList == null || visibleList.owner != cardPanel) { + return false; + } + if (y < 0 && visibleList.getCount() > 0) { + int index = Math.round(visibleList.getCount() + y / LIST_OPTION_HEIGHT); + if (index < 0) { + index = 0; + } + if (isPanStop) { + visibleList.getItemAt(index).tap(0, 0, 1); + } + else { + //visibleList.getItemAt(index).press(0, 0); + } + return true; + } + return false; + } + public enum AttackOption { DECLARE_AS_ATTACKER("Declare as Attacker"), REMOVE_FROM_COMBAT("Remove from Combat"), @@ -95,9 +118,7 @@ public class InputSelectCard { private static class CardOptionsList extends FList { private static final FSkinColor BACK_COLOR = FSkinColor.get(Colors.CLR_OVERLAY).alphaColor(0.5f); - private static final float LIST_OPTION_HEIGHT = Utils.AVG_FINGER_HEIGHT; - private static CardOptionsList visibleList; private static final Backdrop backdrop = new Backdrop(); private static void show(CardAreaPanel cardPanel, Collection options, final Callback callback) { @@ -140,7 +161,7 @@ public class InputSelectCard { visibleList = optionsList; } - private CardAreaPanel owner; + private final CardAreaPanel owner; private CardOptionsList(CardAreaPanel owner0, Iterable options) { super(options); diff --git a/forge-gui-mobile/src/forge/screens/match/views/VCardDisplayArea.java b/forge-gui-mobile/src/forge/screens/match/views/VCardDisplayArea.java index be6f1ac3bb8..2f92dc5ba45 100644 --- a/forge-gui-mobile/src/forge/screens/match/views/VCardDisplayArea.java +++ b/forge-gui-mobile/src/forge/screens/match/views/VCardDisplayArea.java @@ -168,10 +168,18 @@ public abstract class VCardDisplayArea extends VDisplayArea { @Override public boolean press(float x, float y) { - if (displayArea != null) { - InputSelectCard.selectCard(this, displayArea.orderedCards); - } + InputSelectCard.selectCard(this); return true; } + + @Override + public boolean pan(float x, float y, float deltaX, float deltaY) { + return InputSelectCard.handlePan(this, x, y, false); + } + + @Override + public boolean panStop(float x, float y) { + return InputSelectCard.handlePan(this, x, y, true); + } } } diff --git a/forge-gui-mobile/src/forge/toolbox/FList.java b/forge-gui-mobile/src/forge/toolbox/FList.java index d023b8d39da..e1048bcd77a 100644 --- a/forge-gui-mobile/src/forge/toolbox/FList.java +++ b/forge-gui-mobile/src/forge/toolbox/FList.java @@ -229,7 +229,7 @@ public class FList extends FScrollPane { } } - protected class ListItem extends FDisplayObject { + public class ListItem extends FDisplayObject { private final E value; private boolean pressed;