mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-14 17:58: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 List<ReplacementEffect> otherChoices = null;
|
||||
private ReplacementEffectView view = null;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
||||
@@ -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 SpellAbility payingTrigSA;
|
||||
private StaticAbilityView view = null;
|
||||
|
||||
@Override
|
||||
public final int getId() {
|
||||
@@ -231,6 +232,16 @@ public class StaticAbility extends CardTraitBase implements IIdentifiable, Clone
|
||||
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) {
|
||||
if (!shouldApplyContinuousAbility(layer, false)) {
|
||||
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),
|
||||
PromptIfOnlyPossibleAbility(TrackableTypes.BooleanType),
|
||||
|
||||
//ReplacementEffectView
|
||||
RE_HostCard(TrackableTypes.CardViewType),
|
||||
RE_Description(TrackableTypes.StringType),
|
||||
|
||||
//StaticAbilityView
|
||||
ST_HostCard(TrackableTypes.CardViewType),
|
||||
ST_Description(TrackableTypes.StringType),
|
||||
|
||||
//HasBackSide
|
||||
BackSideName(TrackableTypes.StringType),
|
||||
HasBackSide(TrackableTypes.BooleanType),
|
||||
|
||||
@@ -35,9 +35,11 @@ import forge.game.player.*;
|
||||
import forge.game.player.actions.SelectCardAction;
|
||||
import forge.game.player.actions.SelectPlayerAction;
|
||||
import forge.game.replacement.ReplacementEffect;
|
||||
import forge.game.replacement.ReplacementEffectView;
|
||||
import forge.game.replacement.ReplacementLayer;
|
||||
import forge.game.spellability.*;
|
||||
import forge.game.staticability.StaticAbility;
|
||||
import forge.game.staticability.StaticAbilityView;
|
||||
import forge.game.trigger.Trigger;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.game.trigger.WrappedAbility;
|
||||
@@ -1857,19 +1859,16 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
||||
if (possibleReplacers.size() == 1) {
|
||||
return first;
|
||||
}
|
||||
final List<String> res = Lists.newArrayListWithCapacity(possibleReplacers.size());
|
||||
for (ReplacementEffect r : possibleReplacers)
|
||||
res.add(r.getDescription());
|
||||
String prompt = localizer.getMessage("lblChooseFirstApplyReplacementEffect");
|
||||
final List<String> res = possibleReplacers.stream().map(ReplacementEffect::getDescription).collect(Collectors.toList());
|
||||
final String firstStr = res.get(0);
|
||||
final String prompt = localizer.getMessage("lblChooseFirstApplyReplacementEffect");
|
||||
for (int i = 1; i < res.size(); i++) {
|
||||
// prompt user if there are multiple different options
|
||||
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);
|
||||
int index = res.indexOf(getGui().one(prompt, res));
|
||||
if (index > -1)
|
||||
return possibleReplacers.get(index);
|
||||
ReplacementEffectView rev = getGui().one(prompt, possibleReplacers.stream().map(ReplacementEffect::getView).collect(Collectors.toList()));
|
||||
return possibleReplacers.stream().filter(re -> re.getId() == rev.getId()).findAny().orElse(first);
|
||||
}
|
||||
}
|
||||
// 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) {
|
||||
return first;
|
||||
}
|
||||
final List<String> sts = Lists.newArrayListWithCapacity(possibleStatics.size());
|
||||
for (StaticAbility s : possibleStatics)
|
||||
sts.add(s.toString());
|
||||
final List<String> sts = possibleStatics.stream().map(StaticAbility::toString).collect(Collectors.toList());
|
||||
final String firstStr = sts.get(0);
|
||||
for (int i = 1; i < sts.size(); i++) {
|
||||
// prompt user if there are multiple different options
|
||||
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);
|
||||
int index = sts.indexOf(getGui().one(prompt, sts));
|
||||
if (index > -1)
|
||||
return possibleStatics.get(index);
|
||||
StaticAbilityView stv = getGui().one(prompt, possibleStatics.stream().map(StaticAbility::getView).collect(Collectors.toList()));
|
||||
return possibleStatics.stream().filter(st -> st.getId() == stv.getId()).findAny().orElse(first);
|
||||
}
|
||||
}
|
||||
// return first option without prompting if all options are the same
|
||||
|
||||
Reference in New Issue
Block a user