mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Merge branch 'newBranch' into 'master'
Fix Card Display on Network Client Closes #159 See merge request core-developers/forge!2775
This commit is contained in:
@@ -24,7 +24,6 @@ import java.util.List;
|
|||||||
public class GameView extends TrackableObject {
|
public class GameView extends TrackableObject {
|
||||||
private static final long serialVersionUID = 8522884512960961528L;
|
private static final long serialVersionUID = 8522884512960961528L;
|
||||||
|
|
||||||
private CombatView combatView;
|
|
||||||
private final transient Game game; //TODO: Remove this when possible before network support added
|
private final transient Game game; //TODO: Remove this when possible before network support added
|
||||||
|
|
||||||
public GameView(final Game game0) {
|
public GameView(final Game game0) {
|
||||||
@@ -140,15 +139,18 @@ public class GameView extends TrackableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CombatView getCombat() {
|
public CombatView getCombat() {
|
||||||
return combatView;
|
return get(TrackableProperty.CombatView);
|
||||||
|
}
|
||||||
|
public void updateCombatView(CombatView combatView) {
|
||||||
|
set(TrackableProperty.CombatView, combatView);
|
||||||
}
|
}
|
||||||
void updateCombat(Combat combat) {
|
void updateCombat(Combat combat) {
|
||||||
if (combat == null) {
|
if (combat == null) {
|
||||||
combatView = null;
|
set(TrackableProperty.CombatView, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
combatView = new CombatView(combat.getAttackingPlayer().getGame().getTracker());
|
final CombatView combatView = new CombatView(combat.getAttackingPlayer().getGame().getTracker());
|
||||||
for (final AttackingBand b : combat.getAttackingBands()) {
|
for (final AttackingBand b : combat.getAttackingBands()) {
|
||||||
if (b == null) continue;
|
if (b == null) continue;
|
||||||
final GameEntity defender = combat.getDefenderByAttacker(b);
|
final GameEntity defender = combat.getDefenderByAttacker(b);
|
||||||
@@ -160,6 +162,7 @@ public class GameView extends TrackableObject {
|
|||||||
isBlocked ? CardView.getCollection(blockers) : null,
|
isBlocked ? CardView.getCollection(blockers) : null,
|
||||||
CardView.getCollection(blockers));
|
CardView.getCollection(blockers));
|
||||||
}
|
}
|
||||||
|
updateCombatView(combatView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void serialize() {
|
public void serialize() {
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package forge.game.event;
|
||||||
|
|
||||||
|
import forge.game.card.Card;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GameEventCombatUpdate extends GameEvent {
|
||||||
|
|
||||||
|
public final List<Card> attackers;
|
||||||
|
public final List<Card> blockers;
|
||||||
|
|
||||||
|
public GameEventCombatUpdate(List<Card> attackers, List<Card> blockers) {
|
||||||
|
this.attackers = attackers;
|
||||||
|
this.blockers = blockers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T visit(IGameEventVisitor<T> visitor) {
|
||||||
|
return visitor.visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ public interface IGameEventVisitor<T> {
|
|||||||
T visit(GameEventCardCounters event);
|
T visit(GameEventCardCounters event);
|
||||||
T visit(GameEventCombatChanged event);
|
T visit(GameEventCombatChanged event);
|
||||||
T visit(GameEventCombatEnded event);
|
T visit(GameEventCombatEnded event);
|
||||||
|
T visit(GameEventCombatUpdate event);
|
||||||
T visit(GameEventGameFinished event);
|
T visit(GameEventGameFinished event);
|
||||||
T visit(GameEventGameOutcome event);
|
T visit(GameEventGameOutcome event);
|
||||||
T visit(GameEventFlipCoin event);
|
T visit(GameEventFlipCoin event);
|
||||||
@@ -69,6 +70,7 @@ public interface IGameEventVisitor<T> {
|
|||||||
public T visit(GameEventCardPhased event) { return null; }
|
public T visit(GameEventCardPhased event) { return null; }
|
||||||
public T visit(GameEventCombatChanged event) { return null; }
|
public T visit(GameEventCombatChanged event) { return null; }
|
||||||
public T visit(GameEventCombatEnded event) { return null; }
|
public T visit(GameEventCombatEnded event) { return null; }
|
||||||
|
public T visit(GameEventCombatUpdate event) { return null; }
|
||||||
public T visit(GameEventGameFinished event) { return null; }
|
public T visit(GameEventGameFinished event) { return null; }
|
||||||
public T visit(GameEventGameOutcome event) { return null; }
|
public T visit(GameEventGameOutcome event) { return null; }
|
||||||
public T visit(GameEventFlipCoin event) { return null; }
|
public T visit(GameEventFlipCoin event) { return null; }
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ public enum TrackableProperty {
|
|||||||
BandsWithBlockers(TrackableTypes.GenericMapType, FreezeMode.IgnoresFreeze),
|
BandsWithBlockers(TrackableTypes.GenericMapType, FreezeMode.IgnoresFreeze),
|
||||||
AttackersWithPlannedBlockers(TrackableTypes.GenericMapType, FreezeMode.IgnoresFreeze),
|
AttackersWithPlannedBlockers(TrackableTypes.GenericMapType, FreezeMode.IgnoresFreeze),
|
||||||
BandsWithPlannedBlockers(TrackableTypes.GenericMapType, FreezeMode.IgnoresFreeze),
|
BandsWithPlannedBlockers(TrackableTypes.GenericMapType, FreezeMode.IgnoresFreeze),
|
||||||
|
CombatView(TrackableTypes.CombatViewType, FreezeMode.IgnoresFreeze),
|
||||||
|
|
||||||
//Game
|
//Game
|
||||||
Players(TrackableTypes.PlayerViewCollectionType),
|
Players(TrackableTypes.PlayerViewCollectionType),
|
||||||
@@ -219,6 +220,10 @@ public enum TrackableProperty {
|
|||||||
return freezeMode;
|
return freezeMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TrackableType<?> getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> void updateObjLookup(Tracker tracker, T newObj) {
|
public <T> void updateObjLookup(Tracker tracker, T newObj) {
|
||||||
((TrackableType<T>)type).updateObjLookup(tracker, newObj);
|
((TrackableType<T>)type).updateObjLookup(tracker, newObj);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import forge.game.GameEntityView;
|
|||||||
import forge.game.card.CardView;
|
import forge.game.card.CardView;
|
||||||
import forge.game.card.CardView.CardStateView;
|
import forge.game.card.CardView.CardStateView;
|
||||||
import forge.game.card.CounterType;
|
import forge.game.card.CounterType;
|
||||||
|
import forge.game.combat.CombatView;
|
||||||
import forge.game.keyword.KeywordCollection.KeywordCollectionView;
|
import forge.game.keyword.KeywordCollection.KeywordCollectionView;
|
||||||
import forge.game.player.PlayerView;
|
import forge.game.player.PlayerView;
|
||||||
import forge.game.spellability.StackItemView;
|
import forge.game.spellability.StackItemView;
|
||||||
@@ -104,10 +105,16 @@ public class TrackableTypes {
|
|||||||
T newObj = newCollection.get(i);
|
T newObj = newCollection.get(i);
|
||||||
if (newObj != null) {
|
if (newObj != null) {
|
||||||
T existingObj = from.getTracker().getObj(itemType, newObj.getId());
|
T existingObj = from.getTracker().getObj(itemType, newObj.getId());
|
||||||
if (existingObj != null) { //if object exists already, update its changed properties
|
if (existingObj != null) { //fix cards with alternate state/ manifest/ morph/ adventure etc...
|
||||||
existingObj.copyChangedProps(newObj);
|
if (prop.getType() == TrackableTypes.CardViewCollectionType ||
|
||||||
newCollection.remove(i);
|
prop.getType() == TrackableTypes.StackItemViewListType) {
|
||||||
newCollection.add(i, existingObj);
|
newCollection.remove(i);
|
||||||
|
newCollection.add(i, newObj);
|
||||||
|
} else { //if object exists already, update its changed properties
|
||||||
|
existingObj.copyChangedProps(newObj);
|
||||||
|
newCollection.remove(i);
|
||||||
|
newCollection.add(i, existingObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else { //if object is new, cache in object lookup
|
else { //if object is new, cache in object lookup
|
||||||
from.getTracker().putObj(itemType, newObj.getId(), newObj);
|
from.getTracker().putObj(itemType, newObj.getId(), newObj);
|
||||||
@@ -626,4 +633,26 @@ public class TrackableTypes {
|
|||||||
public void serialize(TrackableSerializer ts, Map<Object, Object> value) {
|
public void serialize(TrackableSerializer ts, Map<Object, Object> value) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
public static final TrackableObjectType<CombatView> CombatViewType = new TrackableObjectType<CombatView>() {
|
||||||
|
@Override
|
||||||
|
protected CombatView getDefaultValue() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CombatView deserialize(TrackableDeserializer td, CombatView oldValue) {
|
||||||
|
oldValue.deserialize(td); //TODO handle old value being null or changing to null
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void serialize(TrackableSerializer ts, CombatView value) {
|
||||||
|
if (value == null) {
|
||||||
|
ts.write(-1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
value.serialize(ts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,8 +274,8 @@ public class Forge implements ApplicationListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run(Boolean result) {
|
public void run(Boolean result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
Dscreens.removeFirst();
|
Dscreens.pollFirst();
|
||||||
setCurrentScreen(Dscreens.getFirst());
|
setCurrentScreen(Dscreens.peekFirst());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -119,10 +119,7 @@ public class MatchController extends AbstractGuiGame {
|
|||||||
public void refreshField() {
|
public void refreshField() {
|
||||||
if(!GuiBase.isNetworkplay())
|
if(!GuiBase.isNetworkplay())
|
||||||
return;
|
return;
|
||||||
if(getGameView().getPhase() == null)
|
refreshCardDetails(null);
|
||||||
return;
|
|
||||||
if (getGameView().getPhase().phaseforUpdateField())
|
|
||||||
refreshCardDetails(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hotSeatMode() {
|
public boolean hotSeatMode() {
|
||||||
|
|||||||
@@ -361,6 +361,21 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
|||||||
return processCards(event.blockers, cardsUpdate);
|
return processCards(event.blockers, cardsUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void visit(final GameEventCombatUpdate event) {
|
||||||
|
if (!GuiBase.isNetworkplay())
|
||||||
|
return null; //not needed if single player only...
|
||||||
|
|
||||||
|
final CardCollection cards = new CardCollection();
|
||||||
|
cards.addAll(event.attackers);
|
||||||
|
cards.addAll(event.blockers);
|
||||||
|
|
||||||
|
refreshFieldUpdate = true;
|
||||||
|
|
||||||
|
processCards(cards, cardsRefreshDetails);
|
||||||
|
return processCards(cards, cardsUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(final GameEventCardChangeZone event) {
|
public Void visit(final GameEventCardChangeZone event) {
|
||||||
if(GuiBase.getInterface().isLibgdxPort()) {
|
if(GuiBase.getInterface().isLibgdxPort()) {
|
||||||
@@ -373,6 +388,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(final GameEventCardStatsChanged event) {
|
public Void visit(final GameEventCardStatsChanged event) {
|
||||||
|
refreshFieldUpdate = true;
|
||||||
processCards(event.cards, cardsRefreshDetails);
|
processCards(event.cards, cardsRefreshDetails);
|
||||||
return processCards(event.cards, cardsUpdate);
|
return processCards(event.cards, cardsUpdate);
|
||||||
}
|
}
|
||||||
@@ -397,6 +413,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(final GameEventTokenStateUpdate event) {
|
public Void visit(final GameEventTokenStateUpdate event) {
|
||||||
|
refreshFieldUpdate = true;
|
||||||
processCards(event.cards, cardsRefreshDetails);
|
processCards(event.cards, cardsRefreshDetails);
|
||||||
return processCards(event.cards, cardsUpdate);
|
return processCards(event.cards, cardsUpdate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import forge.game.card.CardPredicates.Presets;
|
|||||||
import forge.game.combat.AttackingBand;
|
import forge.game.combat.AttackingBand;
|
||||||
import forge.game.combat.Combat;
|
import forge.game.combat.Combat;
|
||||||
import forge.game.combat.CombatUtil;
|
import forge.game.combat.CombatUtil;
|
||||||
|
import forge.game.event.GameEventCombatUpdate;
|
||||||
import forge.game.keyword.Keyword;
|
import forge.game.keyword.Keyword;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerView;
|
import forge.game.player.PlayerView;
|
||||||
@@ -335,6 +336,9 @@ public class InputAttack extends InputSyncronizedBase {
|
|||||||
|
|
||||||
updatePrompt();
|
updatePrompt();
|
||||||
|
|
||||||
|
if (combat != null)
|
||||||
|
getController().getGame().fireEvent(new GameEventCombatUpdate(combat.getAttackers(), combat.getAllBlockers()));
|
||||||
|
|
||||||
getController().getGui().showCombat(); // redraw sword icons
|
getController().getGui().showCombat(); // redraw sword icons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import forge.game.card.CardView;
|
|||||||
import forge.game.combat.Combat;
|
import forge.game.combat.Combat;
|
||||||
import forge.game.combat.CombatUtil;
|
import forge.game.combat.CombatUtil;
|
||||||
import forge.game.event.GameEventCombatChanged;
|
import forge.game.event.GameEventCombatChanged;
|
||||||
|
import forge.game.event.GameEventCombatUpdate;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.player.PlayerControllerHuman;
|
import forge.player.PlayerControllerHuman;
|
||||||
@@ -89,6 +90,9 @@ public class InputBlock extends InputSyncronizedBase {
|
|||||||
showMessage(message);
|
showMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (combat != null)
|
||||||
|
getController().getGame().fireEvent(new GameEventCombatUpdate(combat.getAttackers(), combat.getAllBlockers()));
|
||||||
|
|
||||||
getController().getGui().showCombat();
|
getController().getGui().showCombat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user