merge latest trunk

This commit is contained in:
myk
2013-03-04 22:29:05 +00:00
36 changed files with 136 additions and 52 deletions

View File

@@ -8002,7 +8002,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*
* @param damage
* a int.
* @param possiblePrvenetion
* @param possiblePrevention
* a int.
* @param source
* a {@link forge.Card} object.
@@ -8010,7 +8010,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* a boolean.
* @return a int.
*/
public final int staticDamagePrevention(final int damage, final int possiblePrvenetion, final Card source,
public final int staticDamagePrevention(final int damage, final int possiblePrevention, final Card source,
final boolean isCombat) {
if (Singletons.getModel().getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) {
@@ -8047,9 +8047,9 @@ public class Card extends GameEntity implements Comparable<Card> {
}
}
int restDamage = damage - possiblePrvenetion;
int restDamage = damage - possiblePrevention;
restDamage = this.staticDamagePrevention(restDamage, source, isCombat);
restDamage = this.staticDamagePrevention(restDamage, source, isCombat, true);
return restDamage;
}
@@ -8070,7 +8070,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a int.
*/
@Override
public final int staticDamagePrevention(final int damageIn, final Card source, final boolean isCombat) {
public final int staticDamagePrevention(final int damageIn, final Card source, final boolean isCombat, final boolean isTest) {
if (Singletons.getModel().getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) {
return damageIn;
@@ -8138,7 +8138,7 @@ public class Card extends GameEntity implements Comparable<Card> {
for (final Card ca : Singletons.getModel().getGame().getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) {
final ArrayList<StaticAbility> staticAbilities = ca.getStaticAbilities();
for (final StaticAbility stAb : staticAbilities) {
restDamage = stAb.applyAbility("PreventDamage", source, this, restDamage, isCombat);
restDamage = stAb.applyAbility("PreventDamage", source, this, restDamage, isCombat, isTest);
}
}
@@ -8198,7 +8198,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return 0;
}
restDamage = this.staticDamagePrevention(restDamage, source, isCombat);
restDamage = this.staticDamagePrevention(restDamage, source, isCombat, false);
if (restDamage == 0) {
return 0;

View File

@@ -139,7 +139,7 @@ public abstract class GameEntity extends MyObservable {
* a boolean.
* @return a int.
*/
public int staticDamagePrevention(final int damage, final Card source, final boolean isCombat) {
public int staticDamagePrevention(final int damage, final Card source, final boolean isCombat, final boolean isTest) {
return 0;
}

View File

@@ -60,6 +60,6 @@ public class SpellApiBased extends Spell {
chance = ai.doTriggerNoCostWithSubs((AIPlayer)this.getActivatingPlayer(), this, mandatory);
}
chance = ai.doTriggerAI((AIPlayer)this.getActivatingPlayer(), this, mandatory);
return chance;
return chance && super.canPlayAI();
}
}

View File

@@ -30,7 +30,7 @@ public class BondEffect extends SpellAbilityEffect {
Card partner = cards.get(0);
// skip choice if only one card on list
if (cards.size() > 1) {
sa.getActivatingPlayer().getController().chooseSingleCardForEffect(cards, sa, "Select a card to pair with");
partner = sa.getActivatingPlayer().getController().chooseSingleCardForEffect(cards, sa, "Select a card to pair with");
}
// pair choices together

View File

@@ -224,7 +224,7 @@ public class CardFactory {
}
}
controller.getController().mayPlaySpellAbilityForFree(copySA);
controller.getController().playSpellAbilityForFree(copySA);
//c.addController(originalController);
}

View File

@@ -411,13 +411,19 @@ public class TargetSelection {
// If reached Minimum targets, enable OK button
if (!tgt.isMinTargetsChosen(sa.getSourceCard(), sa) || tgt.isDividedAsYouChoose()) {
ButtonUtil.enableOnlyCancel();
if (mandatory && tgt.hasCandidates(sa, true)) {
// Player has to click on a target
ButtonUtil.disableAll();
} else {
ButtonUtil.enableOnlyCancel();
}
} else {
ButtonUtil.enableAllFocusOk();
}
if (mandatory && tgt.hasCandidates(sa, true)) {
ButtonUtil.enableOnlyOk();
if (mandatory && tgt.hasCandidates(sa, true)) {
// Player has to click on a target or ok
ButtonUtil.enableOnlyOk();
} else {
ButtonUtil.enableAllFocusOk();
}
}
}

View File

@@ -253,12 +253,12 @@ public class StaticAbility {
* the target
* @param in
* the in
* @param b
* @param isCombat
* the b
* @return the int
*/
public final int applyAbility(final String mode, final Card source, final GameEntity target, final int in,
final boolean b) {
final boolean isCombat, final boolean isTest) {
// don't apply the ability if it hasn't got the right mode
if (!this.params.get("Mode").equals(mode)) {
@@ -270,7 +270,7 @@ public class StaticAbility {
}
if (mode.equals("PreventDamage")) {
return StaticAbilityPreventDamage.applyPreventDamageAbility(this, source, target, in, b);
return StaticAbilityPreventDamage.applyPreventDamageAbility(this, source, target, in, isCombat, isTest);
}
return in;

View File

@@ -44,7 +44,7 @@ public class StaticAbilityPreventDamage {
* @return the int
*/
public static int applyPreventDamageAbility(final StaticAbility stAb, final Card source, final GameEntity target,
final int damage, final boolean isCombat) {
final int damage, final boolean isCombat, final boolean isTest) {
final HashMap<String, String> params = stAb.getMapParams();
final Card hostCard = stAb.getHostCard();
int restDamage = damage;
@@ -71,9 +71,9 @@ public class StaticAbilityPreventDamage {
return restDamage;
}
if (params.containsKey("Optional")) { //Assume if param is present it should be optional
if (!isTest && params.containsKey("Optional")) { //Assume if param is present it should be optional
final String logic = params.containsKey("AILogic") ? params.get("AILogic") : "";
final String message = "Apply the effect of " + hostCard + "?";
final String message = "Apply the effect of " + hostCard + "? (Affected: " + target + ")";
boolean confirmed = hostCard.getController().getController().confirmStaticApplication(hostCard, target, logic, message);
if (!confirmed) {

View File

@@ -1857,7 +1857,7 @@ public class ComputerUtilCombat {
}
}
restDamage = target.staticDamagePrevention(restDamage, source, isCombat);
restDamage = target.staticDamagePrevention(restDamage, source, isCombat, true);
return restDamage;
}
@@ -1882,7 +1882,7 @@ public class ComputerUtilCombat {
int restDamage = damage;
restDamage = target.staticReplaceDamage(restDamage, source, isCombat);
restDamage = target.staticDamagePrevention(restDamage, source, isCombat);
restDamage = target.staticDamagePrevention(restDamage, source, isCombat, true);
return restDamage;
}

View File

@@ -672,7 +672,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* @return a int.
*/
@Override
public final int staticDamagePrevention(final int damage, final Card source, final boolean isCombat) {
public final int staticDamagePrevention(final int damage, final Card source, final boolean isCombat, final boolean isTest) {
if (Singletons.getModel().getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noPrevention)) {
return damage;
@@ -709,7 +709,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
for (final Card ca : game.getCardsIn(ZoneType.listValueOf("Battlefield,Command"))) {
final ArrayList<StaticAbility> staticAbilities = ca.getStaticAbilities();
for (final StaticAbility stAb : staticAbilities) {
restDamage = stAb.applyAbility("PreventDamage", source, this, restDamage, isCombat);
restDamage = stAb.applyAbility("PreventDamage", source, this, restDamage, isCombat, isTest);
}
}
@@ -884,7 +884,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
return 0;
}
restDamage = this.staticDamagePrevention(restDamage, source, isCombat);
restDamage = this.staticDamagePrevention(restDamage, source, isCombat, false);
if (restDamage >= this.getPreventNextDamage()) {
restDamage = restDamage - this.getPreventNextDamage();

View File

@@ -76,7 +76,7 @@ public abstract class PlayerController {
*/
public abstract void playFromSuspend(Card c);
public abstract boolean playCascade(Card cascadedCard, Card sourceCard);
public abstract void mayPlaySpellAbilityForFree(SpellAbility copySA);
public abstract void playSpellAbilityForFree(SpellAbility copySA);
/**
* @return the player
*/

View File

@@ -138,13 +138,14 @@ public class PlayerControllerAi extends PlayerController {
* @see forge.game.player.PlayerController#mayPlaySpellAbilityForFree(forge.card.spellability.SpellAbility)
*/
@Override
public void mayPlaySpellAbilityForFree(SpellAbility copySA) {
public void playSpellAbilityForFree(SpellAbility copySA) {
if (copySA instanceof Spell) {
Spell spell = (Spell) copySA;
if (spell.canPlayFromEffectAI(false, true)) {
if (spell.canPlayFromEffectAI(true, true)) {
ComputerUtil.playStackFree(getPlayer(), copySA);
}
} else if (copySA.canPlayAI()) {
} else {
copySA.canPlayAI();
ComputerUtil.playStackFree(getPlayer(), copySA);
}
}

View File

@@ -113,7 +113,7 @@ public class PlayerControllerHuman extends PlayerController {
* @see forge.game.player.PlayerController#mayPlaySpellAbilityForFree(forge.card.spellability.SpellAbility)
*/
@Override
public void mayPlaySpellAbilityForFree(SpellAbility copySA) {
public void playSpellAbilityForFree(SpellAbility copySA) {
game.getActionPlay().playSpellAbilityForFree(copySA);
}

View File

@@ -119,12 +119,18 @@ public final class SOverlayUtils {
return overlay;
}
private static boolean _overlayHasFocus;
public static boolean overlayHasFocus() {
return _overlayHasFocus;
}
private static Component prevFocusOwner;
public static void showOverlay() {
prevFocusOwner = FocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
FOverlay.SINGLETON_INSTANCE.getPanel().setVisible(true);
// ensure no background element has focus
FOverlay.SINGLETON_INSTANCE.getPanel().requestFocusInWindow();
_overlayHasFocus = true;
}
/**
@@ -137,6 +143,7 @@ public final class SOverlayUtils {
prevFocusOwner.requestFocusInWindow();
prevFocusOwner = null;
}
_overlayHasFocus = false;
}
public static void showTargetingOverlay() {

View File

@@ -19,6 +19,7 @@ package forge.view;
import javax.swing.JButton;
import forge.gui.SOverlayUtils;
import forge.gui.match.VMatchUI;
/**
@@ -50,7 +51,7 @@ public class ButtonUtil {
getOk().setEnabled(false);
getCancel().setEnabled(false);
}
public static void enableAllFocusOk() {
enableAndFocus(getOk());
getCancel().setEnabled(true);
@@ -58,7 +59,11 @@ public class ButtonUtil {
private static void enableAndFocus(final JButton button) {
button.setEnabled(true);
button.requestFocusInWindow();
// ensure we don't steal focus from an overlay
if (!SOverlayUtils.overlayHasFocus()) {
button.requestFocusInWindow();
}
}
private static JButton getOk() {

View File

@@ -570,8 +570,17 @@ public abstract class CardPanelContainer extends JPanel {
public final Card getHoveredCard(MouseEvent e) {
// re-evaluate cursor position so if we hovered over a card, alt-tabbed out of the application, then
// clicked back on the application somewhere else, the last hovered card won't register the click
// this cannot protect against alt tabbing off then re-focusing on the application by clicking on
// the already-hovered card, though, since we cannot tell the difference between that and clicking
// on the hovered card when the app already has focus.
CardPanel p = getCardPanel(e.getX(), e.getY());
return (p == null && p == hoveredPanel) ? null : p.getGameCard();
// if cursor has jumped, for example via the above alt-tabbing example, fix the card hover highlight
if (null != hoveredPanel && p != hoveredPanel) {
mouseOut(hoveredPanel, e);
}
return (null == p || p != hoveredPanel) ? null : p.getGameCard();
}
/**