mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Support dragging up to select ability
This commit is contained in:
@@ -26,15 +26,18 @@ import forge.util.Callback;
|
|||||||
import forge.util.Utils;
|
import forge.util.Utils;
|
||||||
|
|
||||||
public class InputSelectCard {
|
public class InputSelectCard {
|
||||||
|
private static final float LIST_OPTION_HEIGHT = Utils.AVG_FINGER_HEIGHT;
|
||||||
|
private static CardOptionsList<?> visibleList;
|
||||||
|
|
||||||
private InputSelectCard() {
|
private InputSelectCard() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void selectCard(CardAreaPanel cardPanel, List<Card> orderedCards) {
|
public static void selectCard(CardAreaPanel cardPanel) {
|
||||||
Input currentInput = FControl.getInputQueue().getInput();
|
Input currentInput = FControl.getInputQueue().getInput();
|
||||||
if (currentInput == null) { return; }
|
if (currentInput == null) { return; }
|
||||||
|
|
||||||
if (CardOptionsList.visibleList != null) {
|
if (visibleList != null) {
|
||||||
boolean isCurrentOwner = (CardOptionsList.visibleList.owner == cardPanel);
|
boolean isCurrentOwner = (visibleList.owner == cardPanel);
|
||||||
CardOptionsList.hide();
|
CardOptionsList.hide();
|
||||||
if (isCurrentOwner) {
|
if (isCurrentOwner) {
|
||||||
return;
|
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 {
|
public enum AttackOption {
|
||||||
DECLARE_AS_ATTACKER("Declare as Attacker"),
|
DECLARE_AS_ATTACKER("Declare as Attacker"),
|
||||||
REMOVE_FROM_COMBAT("Remove from Combat"),
|
REMOVE_FROM_COMBAT("Remove from Combat"),
|
||||||
@@ -95,9 +118,7 @@ public class InputSelectCard {
|
|||||||
|
|
||||||
private static class CardOptionsList<T> extends FList<T> {
|
private static class CardOptionsList<T> extends FList<T> {
|
||||||
private static final FSkinColor BACK_COLOR = FSkinColor.get(Colors.CLR_OVERLAY).alphaColor(0.5f);
|
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 final Backdrop backdrop = new Backdrop();
|
||||||
|
|
||||||
private static <T> void show(CardAreaPanel cardPanel, Collection<T> options, final Callback<T> callback) {
|
private static <T> void show(CardAreaPanel cardPanel, Collection<T> options, final Callback<T> callback) {
|
||||||
@@ -140,7 +161,7 @@ public class InputSelectCard {
|
|||||||
visibleList = optionsList;
|
visibleList = optionsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CardAreaPanel owner;
|
private final CardAreaPanel owner;
|
||||||
|
|
||||||
private CardOptionsList(CardAreaPanel owner0, Iterable<T> options) {
|
private CardOptionsList(CardAreaPanel owner0, Iterable<T> options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|||||||
@@ -168,10 +168,18 @@ public abstract class VCardDisplayArea extends VDisplayArea {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean press(float x, float y) {
|
public boolean press(float x, float y) {
|
||||||
if (displayArea != null) {
|
InputSelectCard.selectCard(this);
|
||||||
InputSelectCard.selectCard(this, displayArea.orderedCards);
|
|
||||||
}
|
|
||||||
return true;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ public class FList<E> extends FScrollPane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class ListItem extends FDisplayObject {
|
public class ListItem extends FDisplayObject {
|
||||||
private final E value;
|
private final E value;
|
||||||
private boolean pressed;
|
private boolean pressed;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user