mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Add ReplacementEffectView, StaticAbility View for Netplay Dialog
This commit is contained in:
@@ -60,6 +60,7 @@ public abstract class ReplacementEffect extends TriggerReplacementBase {
|
|||||||
private boolean hasRun = false;
|
private boolean hasRun = false;
|
||||||
|
|
||||||
private List<ReplacementEffect> otherChoices = null;
|
private List<ReplacementEffect> otherChoices = null;
|
||||||
|
private ReplacementEffectView view = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the id.
|
* Gets the id.
|
||||||
@@ -109,6 +110,15 @@ public abstract class ReplacementEffect extends TriggerReplacementBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReplacementEffectView getView() {
|
||||||
|
if (view == null)
|
||||||
|
view = new ReplacementEffectView(this);
|
||||||
|
else {
|
||||||
|
view.updateHostCard(this);
|
||||||
|
view.updateDescription(this);
|
||||||
|
}
|
||||||
|
return view;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Sets the checks for run.
|
* Sets the checks for run.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package forge.game.replacement;
|
||||||
|
|
||||||
|
import forge.game.card.CardView;
|
||||||
|
import forge.game.card.IHasCardView;
|
||||||
|
import forge.trackable.TrackableObject;
|
||||||
|
import forge.trackable.TrackableProperty;
|
||||||
|
import forge.trackable.Tracker;
|
||||||
|
|
||||||
|
public class ReplacementEffectView extends TrackableObject implements IHasCardView {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
ReplacementEffectView(ReplacementEffect re) {
|
||||||
|
this(re, re.getHostCard() == null || re.getHostCard().getGame() == null ? null : re.getHostCard().getGame().getTracker());
|
||||||
|
}
|
||||||
|
|
||||||
|
ReplacementEffectView(ReplacementEffect re, Tracker tracker) {
|
||||||
|
super(re.getId(), tracker);
|
||||||
|
updateHostCard(re);
|
||||||
|
updateDescription(re);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CardView getCardView() {
|
||||||
|
return this.getHostCard();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CardView getHostCard() {
|
||||||
|
return get(TrackableProperty.RE_HostCard);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateHostCard(ReplacementEffect re) {
|
||||||
|
set(TrackableProperty.RE_HostCard, CardView.get(re.getHostCard()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return get(TrackableProperty.RE_Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateDescription(ReplacementEffect re) {
|
||||||
|
set(TrackableProperty.RE_Description, re.getDescription());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,6 +62,7 @@ public class StaticAbility extends CardTraitBase implements IIdentifiable, Clone
|
|||||||
private int mayPlayTurn = 0;
|
private int mayPlayTurn = 0;
|
||||||
|
|
||||||
private SpellAbility payingTrigSA;
|
private SpellAbility payingTrigSA;
|
||||||
|
private StaticAbilityView view = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getId() {
|
public final int getId() {
|
||||||
@@ -231,6 +232,16 @@ public class StaticAbility extends CardTraitBase implements IIdentifiable, Clone
|
|||||||
this.setCardState(state);
|
this.setCardState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StaticAbilityView getView() {
|
||||||
|
if (view == null)
|
||||||
|
view = new StaticAbilityView(this);
|
||||||
|
else {
|
||||||
|
view.updateHostCard(this);
|
||||||
|
view.updateDescription(this);
|
||||||
|
}
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
public final CardCollectionView applyContinuousAbilityBefore(final StaticAbilityLayer layer, final CardCollectionView preList) {
|
public final CardCollectionView applyContinuousAbilityBefore(final StaticAbilityLayer layer, final CardCollectionView preList) {
|
||||||
if (!shouldApplyContinuousAbility(layer, false)) {
|
if (!shouldApplyContinuousAbility(layer, false)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package forge.game.staticability;
|
||||||
|
|
||||||
|
import forge.game.card.CardView;
|
||||||
|
import forge.game.card.IHasCardView;
|
||||||
|
import forge.trackable.TrackableObject;
|
||||||
|
import forge.trackable.TrackableProperty;
|
||||||
|
import forge.trackable.Tracker;
|
||||||
|
|
||||||
|
public class StaticAbilityView extends TrackableObject implements IHasCardView {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
StaticAbilityView(StaticAbility st) {
|
||||||
|
this(st, st.getHostCard() == null || st.getHostCard().getGame() == null ? null : st.getHostCard().getGame().getTracker());
|
||||||
|
}
|
||||||
|
|
||||||
|
StaticAbilityView(StaticAbility st, Tracker tracker) {
|
||||||
|
super(st.getId(), tracker);
|
||||||
|
updateHostCard(st);
|
||||||
|
updateDescription(st);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CardView getCardView() {
|
||||||
|
return this.getHostCard();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CardView getHostCard() {
|
||||||
|
return get(TrackableProperty.ST_HostCard);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateHostCard(StaticAbility st) {
|
||||||
|
set(TrackableProperty.ST_HostCard, CardView.get(st.getHostCard()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return get(TrackableProperty.ST_Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateDescription(StaticAbility st) {
|
||||||
|
set(TrackableProperty.ST_Description, st.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -241,6 +241,14 @@ public enum TrackableProperty {
|
|||||||
CanPlay(TrackableTypes.BooleanType),
|
CanPlay(TrackableTypes.BooleanType),
|
||||||
PromptIfOnlyPossibleAbility(TrackableTypes.BooleanType),
|
PromptIfOnlyPossibleAbility(TrackableTypes.BooleanType),
|
||||||
|
|
||||||
|
//ReplacementEffectView
|
||||||
|
RE_HostCard(TrackableTypes.CardViewType),
|
||||||
|
RE_Description(TrackableTypes.StringType),
|
||||||
|
|
||||||
|
//StaticAbilityView
|
||||||
|
ST_HostCard(TrackableTypes.CardViewType),
|
||||||
|
ST_Description(TrackableTypes.StringType),
|
||||||
|
|
||||||
//HasBackSide
|
//HasBackSide
|
||||||
BackSideName(TrackableTypes.StringType),
|
BackSideName(TrackableTypes.StringType),
|
||||||
HasBackSide(TrackableTypes.BooleanType),
|
HasBackSide(TrackableTypes.BooleanType),
|
||||||
|
|||||||
@@ -35,9 +35,11 @@ import forge.game.player.*;
|
|||||||
import forge.game.player.actions.SelectCardAction;
|
import forge.game.player.actions.SelectCardAction;
|
||||||
import forge.game.player.actions.SelectPlayerAction;
|
import forge.game.player.actions.SelectPlayerAction;
|
||||||
import forge.game.replacement.ReplacementEffect;
|
import forge.game.replacement.ReplacementEffect;
|
||||||
|
import forge.game.replacement.ReplacementEffectView;
|
||||||
import forge.game.replacement.ReplacementLayer;
|
import forge.game.replacement.ReplacementLayer;
|
||||||
import forge.game.spellability.*;
|
import forge.game.spellability.*;
|
||||||
import forge.game.staticability.StaticAbility;
|
import forge.game.staticability.StaticAbility;
|
||||||
|
import forge.game.staticability.StaticAbilityView;
|
||||||
import forge.game.trigger.Trigger;
|
import forge.game.trigger.Trigger;
|
||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
import forge.game.trigger.WrappedAbility;
|
import forge.game.trigger.WrappedAbility;
|
||||||
@@ -1857,19 +1859,16 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
|||||||
if (possibleReplacers.size() == 1) {
|
if (possibleReplacers.size() == 1) {
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
final List<String> res = Lists.newArrayListWithCapacity(possibleReplacers.size());
|
final List<String> res = possibleReplacers.stream().map(ReplacementEffect::getDescription).collect(Collectors.toList());
|
||||||
for (ReplacementEffect r : possibleReplacers)
|
|
||||||
res.add(r.getDescription());
|
|
||||||
String prompt = localizer.getMessage("lblChooseFirstApplyReplacementEffect");
|
|
||||||
final String firstStr = res.get(0);
|
final String firstStr = res.get(0);
|
||||||
|
final String prompt = localizer.getMessage("lblChooseFirstApplyReplacementEffect");
|
||||||
for (int i = 1; i < res.size(); i++) {
|
for (int i = 1; i < res.size(); i++) {
|
||||||
// prompt user if there are multiple different options
|
// prompt user if there are multiple different options
|
||||||
if (!res.get(i).equals(firstStr)) {
|
if (!res.get(i).equals(firstStr)) {
|
||||||
if (!GuiBase.isNetworkplay()) //non network game show more info since they don't need serialization
|
if (!GuiBase.isNetworkplay()) //non network game don't need serialization
|
||||||
return getGui().one(prompt, possibleReplacers);
|
return getGui().one(prompt, possibleReplacers);
|
||||||
int index = res.indexOf(getGui().one(prompt, res));
|
ReplacementEffectView rev = getGui().one(prompt, possibleReplacers.stream().map(ReplacementEffect::getView).collect(Collectors.toList()));
|
||||||
if (index > -1)
|
return possibleReplacers.stream().filter(re -> re.getId() == rev.getId()).findAny().orElse(first);
|
||||||
return possibleReplacers.get(index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// return first option without prompting if all options are the same
|
// return first option without prompting if all options are the same
|
||||||
@@ -1882,18 +1881,15 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
|||||||
if (possibleStatics.size() == 1 || !fullControl) {
|
if (possibleStatics.size() == 1 || !fullControl) {
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
final List<String> sts = Lists.newArrayListWithCapacity(possibleStatics.size());
|
final List<String> sts = possibleStatics.stream().map(StaticAbility::toString).collect(Collectors.toList());
|
||||||
for (StaticAbility s : possibleStatics)
|
|
||||||
sts.add(s.toString());
|
|
||||||
final String firstStr = sts.get(0);
|
final String firstStr = sts.get(0);
|
||||||
for (int i = 1; i < sts.size(); i++) {
|
for (int i = 1; i < sts.size(); i++) {
|
||||||
// prompt user if there are multiple different options
|
// prompt user if there are multiple different options
|
||||||
if (!sts.get(i).equals(firstStr)) {
|
if (!sts.get(i).equals(firstStr)) {
|
||||||
if (!GuiBase.isNetworkplay()) //non network game show more info since they don't need serialization
|
if (!GuiBase.isNetworkplay()) //non network game don't need serialization
|
||||||
return getGui().one(prompt, possibleStatics);
|
return getGui().one(prompt, possibleStatics);
|
||||||
int index = sts.indexOf(getGui().one(prompt, sts));
|
StaticAbilityView stv = getGui().one(prompt, possibleStatics.stream().map(StaticAbility::getView).collect(Collectors.toList()));
|
||||||
if (index > -1)
|
return possibleStatics.stream().filter(st -> st.getId() == stv.getId()).findAny().orElse(first);
|
||||||
return possibleStatics.get(index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// return first option without prompting if all options are the same
|
// return first option without prompting if all options are the same
|
||||||
|
|||||||
Reference in New Issue
Block a user