mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Support double tapping card to select first option
This commit is contained in:
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
@@ -21,14 +22,17 @@ import forge.screens.FScreen;
|
||||
import forge.screens.match.views.VCardDisplayArea.CardAreaPanel;
|
||||
import forge.toolbox.FCardPanel;
|
||||
import forge.toolbox.FDisplayObject;
|
||||
import forge.toolbox.FGestureAdapter;
|
||||
import forge.toolbox.FList;
|
||||
import forge.util.Callback;
|
||||
import forge.util.Utils;
|
||||
|
||||
public class InputSelectCard {
|
||||
private static final float LIST_OPTION_HEIGHT = Utils.AVG_FINGER_HEIGHT;
|
||||
private static final long DOUBLE_TAP_INTERVAL = Utils.secondsToTimeSpan(FGestureAdapter.DOUBLE_TAP_INTERVAL);
|
||||
private static CardOptionsList<?> visibleList;
|
||||
private static CardOptionsList<?>.ListItem pressedItem;
|
||||
private static long lastSelectTime;
|
||||
|
||||
private InputSelectCard() {
|
||||
}
|
||||
@@ -37,14 +41,26 @@ public class InputSelectCard {
|
||||
Input currentInput = FControl.getInputQueue().getInput();
|
||||
if (currentInput == null) { return; }
|
||||
|
||||
long now = Gdx.input.getCurrentEventTime();
|
||||
|
||||
if (visibleList != null) {
|
||||
boolean isCurrentOwner = (visibleList.owner == cardPanel);
|
||||
CardOptionsList.hide();
|
||||
if (isCurrentOwner && visibleList.getCount() > 0 &&
|
||||
now - lastSelectTime <= DOUBLE_TAP_INTERVAL) {
|
||||
//auto-select first option if double tapped
|
||||
visibleList.getItemAt(0).tap(0, 0, 1);
|
||||
}
|
||||
else {
|
||||
//otherwise hide options when pressed a second time
|
||||
CardOptionsList.hide();
|
||||
}
|
||||
if (isCurrentOwner) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lastSelectTime = now;
|
||||
|
||||
final Card card = cardPanel.getCard();
|
||||
|
||||
if (currentInput instanceof InputPassPriority) {
|
||||
@@ -200,11 +216,13 @@ public class InputSelectCard {
|
||||
|
||||
@Override
|
||||
public boolean press(float x, float y) {
|
||||
if (visibleList == null) { return false; }
|
||||
CardAreaPanel owner = visibleList.owner;
|
||||
boolean onOwner = owner.contains(owner.getLeft() + owner.screenToLocalX(x), owner.getTop() + owner.screenToLocalY(y));
|
||||
hide(); //auto-hide when backdrop pressed
|
||||
return onOwner; //allow press to pass through to object if it's not the owner
|
||||
if (visibleList != null) {
|
||||
CardAreaPanel owner = visibleList.owner;
|
||||
if (!owner.contains(owner.getLeft() + owner.screenToLocalX(x), owner.getTop() + owner.screenToLocalY(y))) {
|
||||
hide(); //auto-hide when backdrop pressed unless on owner
|
||||
}
|
||||
}
|
||||
return false; //allow press to pass through to object
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,11 +76,11 @@ public abstract class FGestureAdapter extends InputAdapter {
|
||||
* @param flingDelay0 time in seconds the finger must have been dragged for a fling event to be fired. */
|
||||
public FGestureAdapter(float tapSquareSize0, float tapCountInterval0, float pressDelay0, float longPressDelay0, float quickTapDelay0, float flingDelay0) {
|
||||
tapSquareSize = tapSquareSize0;
|
||||
tapCountInterval = (long)(tapCountInterval0 * 1000000000l);
|
||||
tapCountInterval = Utils.secondsToTimeSpan(tapCountInterval0);
|
||||
pressDelay = pressDelay0;
|
||||
longPressDelay = longPressDelay0;
|
||||
quickTapDelay = quickTapDelay0;
|
||||
flingDelay = (long)(flingDelay0 * 1000000000l);
|
||||
flingDelay = Utils.secondsToTimeSpan(flingDelay0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,17 +2,6 @@ package forge.util;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
import forge.card.CardDb;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.generation.DeckGenerator2Color;
|
||||
import forge.deck.generation.DeckGenerator3Color;
|
||||
import forge.deck.generation.DeckGenerator5Color;
|
||||
import forge.deck.generation.DeckGeneratorBase;
|
||||
import forge.deck.generation.DeckGeneratorMonoColor;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.toolbox.FOptionPane;
|
||||
|
||||
public class Utils {
|
||||
private final static float ppcX = Gdx.graphics.getPpcX();
|
||||
private final static float ppcY = Gdx.graphics.getPpcY();
|
||||
@@ -28,37 +17,7 @@ public class Utils {
|
||||
return ppcY * cm;
|
||||
}
|
||||
|
||||
public static Deck generateRandomDeck(final int colorCount0) {
|
||||
try {
|
||||
CardDb cardDb = FModel.getMagicDb().getCommonCards();
|
||||
DeckGeneratorBase gen = null;
|
||||
switch (colorCount0) {
|
||||
case 1: gen = new DeckGeneratorMonoColor(cardDb, null); break;
|
||||
case 2: gen = new DeckGenerator2Color(cardDb, null, null); break;
|
||||
case 3: gen = new DeckGenerator3Color(cardDb, null, null, null); break;
|
||||
case 5: gen = new DeckGenerator5Color(cardDb); break;
|
||||
}
|
||||
|
||||
if (gen != null) {
|
||||
final Deck deck = new Deck();
|
||||
gen.setSingleton(false);
|
||||
gen.setUseArtifacts(false);
|
||||
deck.getMain().addAll(gen.getDeck(60, false));
|
||||
return deck;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
FOptionPane.showErrorDialog(ex.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPlayerName() {
|
||||
return FModel.getPreferences().getPref(FPref.PLAYER_NAME);
|
||||
}
|
||||
|
||||
public static String personalizeHuman(String text) {
|
||||
String playerName = FModel.getPreferences().getPref(FPref.PLAYER_NAME);
|
||||
return text.replaceAll("(?i)human", playerName);
|
||||
public static long secondsToTimeSpan(float seconds) {
|
||||
return (long)(seconds * 1000000000l);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user