Merge remote-tracking branch 'remotes/core/master' into newBranch

This commit is contained in:
Anthony Calosa
2019-11-24 12:11:12 +08:00
23 changed files with 461 additions and 83 deletions

View File

@@ -239,8 +239,18 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override
public Void visit(final GameEventSpellAbilityCast event) {
needStackUpdate = true;
return processEvent();
needStackUpdate = true;
processEvent();
final Runnable notifyStackAddition = new Runnable() {
@Override
public void run() {
matchController.notifyStackAddition(event);
}
};
GuiBase.getInterface().invokeInEdtLater(notifyStackAddition);
return null;
}
@Override
@@ -252,7 +262,17 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override
public Void visit(final GameEventSpellRemovedFromStack event) {
needStackUpdate = true;
return processEvent();
processEvent();
final Runnable notifyStackAddition = new Runnable() {
@Override
public void run() {
matchController.notifyStackRemoval(event);
}
};
GuiBase.getInterface().invokeInEdtLater(notifyStackAddition);
return null;
}
@Override
@@ -340,10 +360,10 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
if(event.to.getZoneType() == ZoneType.Battlefield)
refreshFieldUpdate = true;
//pfps the change to the zones have already been performed with add and remove calls
// this is only for playing a sound
// updateZone(event.from);
// this is only for playing a sound
// updateZone(event.from);
//return updateZone(event.to);
return processEvent();
return processEvent();
}
@@ -373,9 +393,9 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override
public Void visit(final GameEventShuffle event) {
//pfps the change to the library has already been performed by a setCards call
// this is only for playing a sound
// return updateZone(event.player.getZone(ZoneType.Library));
return processEvent();
// this is only for playing a sound
// return updateZone(event.player.getZone(ZoneType.Library));
return processEvent();
}
@Override

View File

@@ -264,12 +264,8 @@ public abstract class GuiDownloadService implements Runnable {
count++;
cardSkipped = true; //assume skipped unless saved successfully
String url = kv.getValue();
/*
* decode URL Key, Reverted to old version,
* on Android 6.0 it throws an error
* when you download the card price
*/
String decodedKey = URLDecoder.decode(kv.getKey());
String decodedKey = decodeURL(kv.getKey());
final File fileDest = new File(decodedKey);
final String filePath = fileDest.getPath();
final String subLastIndex = filePath.contains("pics") ? "\\pics\\" : "\\db\\";
@@ -365,6 +361,16 @@ public abstract class GuiDownloadService implements Runnable {
GuiBase.getInterface().preventSystemSleep(false);
}
@SuppressWarnings("deprecation")
private static String decodeURL(String key) {
/*
* decode URL Key, Reverted to old version,
* on Android 6.0 it throws an error
* when you download the card price
*/
return URLDecoder.decode(key);
}
protected Proxy getProxy() {
if (type == 0) {
return Proxy.NO_PROXY;
@@ -385,7 +391,7 @@ public abstract class GuiDownloadService implements Runnable {
protected static void addMissingItems(Map<String, String> list, String nameUrlFile, String dir) {
for (Pair<String, String> nameUrlPair : FileUtil.readNameUrlFile(nameUrlFile)) {
File f = new File(dir, URLDecoder.decode(nameUrlPair.getLeft()));
File f = new File(dir, decodeURL(nameUrlPair.getLeft()));
//System.out.println(f.getAbsolutePath());
if (!f.exists()) {
list.put(f.getAbsolutePath(), nameUrlPair.getRight());

View File

@@ -12,6 +12,8 @@ import forge.deck.CardPool;
import forge.game.GameEntityView;
import forge.game.GameView;
import forge.game.card.CardView;
import forge.game.event.GameEventSpellAbilityCast;
import forge.game.event.GameEventSpellRemovedFromStack;
import forge.game.phase.PhaseType;
import forge.game.player.DelayedReveal;
import forge.game.player.IHasIcon;
@@ -47,6 +49,8 @@ public interface IGuiGame {
void showManaPool(PlayerView player);
void hideManaPool(PlayerView player);
void updateStack();
void notifyStackAddition(final GameEventSpellAbilityCast event);
void notifyStackRemoval(final GameEventSpellRemovedFromStack event);
Iterable<PlayerZoneUpdate> tempShowZones(PlayerView controller, Iterable<PlayerZoneUpdate> zonesToUpdate);
void hideZones(PlayerView controller, Iterable<PlayerZoneUpdate> zonesToUpdate);
void updateZones(Iterable<PlayerZoneUpdate> zonesToUpdate);

View File

@@ -24,6 +24,8 @@ import forge.assets.FSkinProp;
import forge.game.GameView;
import forge.game.card.CardView;
import forge.game.card.CardView.CardStateView;
import forge.game.event.GameEventSpellAbilityCast;
import forge.game.event.GameEventSpellRemovedFromStack;
import forge.game.player.PlayerView;
import forge.interfaces.IGameController;
import forge.interfaces.IGuiGame;
@@ -251,16 +253,16 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
private final Set<CardView> selectableCards = Sets.newHashSet();
public void setSelectables(final Iterable<CardView> cards) {
for ( CardView cv : cards ) { selectableCards.add(cv); }
for ( CardView cv : cards ) { selectableCards.add(cv); }
}
public void clearSelectables() {
selectableCards.clear();
selectableCards.clear();
}
public boolean isSelectable(final CardView card) {
return selectableCards.contains(card);
return selectableCards.contains(card);
}
public boolean isSelecting() {
return !selectableCards.isEmpty();
return !selectableCards.isEmpty();
}
public boolean isGamePaused() { return gamePause; }
public void setgamePause(boolean pause) { gamePause = pause; }
@@ -694,6 +696,14 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
final String yesButtonText, final String noButtonText) {
return showConfirmDialog(message, title, yesButtonText, noButtonText, true);
}
@Override
public void notifyStackAddition(GameEventSpellAbilityCast event) {
}
@Override
public void notifyStackRemoval(GameEventSpellRemovedFromStack event) {
}
// End of Choice code
}

View File

@@ -310,6 +310,11 @@ public final class ForgeConstants {
public static final String GRAVEYARD_ORDERING_OWN_CARDS = "With Relevant Cards";
public static final String GRAVEYARD_ORDERING_ALWAYS = "Always";
// Constants for Stack effect addition notification policy
public static final String STACK_EFFECT_NOTIFICATION_NEVER = "Never";
public static final String STACK_EFFECT_NOTIFICATION_ALWAYS = "Always";
public static final String STACK_EFFECT_NOTIFICATION_AI_AND_TRIGGERED = "AI cast/activated, or triggered by any player";
// Set boolean constant for landscape mode for gdx port
public static final boolean isGdxPortLandscape = FileUtil.doesFileExist(ASSETS_DIR + "switch_orientation.ini");

View File

@@ -119,6 +119,7 @@ public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
UI_HIDE_GAME_TABS ("false"), // Visibility of tabs in match screen.
UI_CLOSE_ACTION ("NONE"),
UI_MANA_LOST_PROMPT ("false"), // Prompt on losing mana when passing priority
UI_STACK_EFFECT_NOTIFICATION_POLICY ("Never"),
UI_PAUSE_WHILE_MINIMIZED("false"),
UI_TOKENS_IN_SEPARATE_ROW("false"), // Display tokens in their own battlefield row.
UI_DISPLAY_CURRENT_COLORS(ForgeConstants.DISP_CURRENT_COLORS_NEVER),

View File

@@ -0,0 +1,87 @@
package forge.util;
import org.apache.commons.lang3.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WordUtil {
public static String capitalize(String str) {
if (StringUtils.isEmpty(str)) {
return str;
}
final char[] buffer = str.toCharArray();
boolean capitalizeNext = true;
for (int i = 0; i < buffer.length; i++) {
final char ch = buffer[i];
if (Character.isWhitespace(ch)) {
capitalizeNext = true;
} else if (capitalizeNext) {
buffer[i] = Character.toTitleCase(ch);
capitalizeNext = false;
}
}
return new String(buffer);
}
private final static Pattern patternToWrapOn = Pattern.compile(" ");
public static String wordWrapAsHTML(String str) {
String result = null;
int wrapLength = 40;
String newLineStr = "<br>";
if (str != null) {
final int inputLineLength = str.length();
int offset = 0;
final StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32);
while (offset < inputLineLength) {
int spaceToWrapAt = -1;
Matcher matcher = patternToWrapOn.matcher(str.substring(offset, Math.min(offset + wrapLength + 1, inputLineLength)));
if (matcher.find()) {
if (matcher.start() == 0) {
offset += matcher.end();
continue;
}
spaceToWrapAt = matcher.start() + offset;
}
// only last line without leading spaces is left
if (inputLineLength - offset <= wrapLength) {
break;
}
while (matcher.find()) {
spaceToWrapAt = matcher.start() + offset;
}
if (spaceToWrapAt >= offset) {
// normal case
wrappedLine.append(str, offset, spaceToWrapAt);
wrappedLine.append(newLineStr);
offset = spaceToWrapAt + 1;
} else {
// do not wrap really long word, just extend beyond limit
matcher = patternToWrapOn.matcher(str.substring(offset + wrapLength));
if (matcher.find()) {
spaceToWrapAt = matcher.start() + offset + wrapLength;
}
if (spaceToWrapAt >= 0) {
wrappedLine.append(str, offset, spaceToWrapAt);
wrappedLine.append(newLineStr);
offset = spaceToWrapAt + 1;
} else {
wrappedLine.append(str, offset, str.length());
offset = inputLineLength;
}
}
}// Whatever is left in line is short enough to just pass through
wrappedLine.append(str, offset, str.length());
result = wrappedLine.toString();
}
return "<html>" + result + "</html>";
}
private WordUtil() {}
}