Merge branch 'newBranch' into 'master'

Update Win/Lose Overlay (mobile)

Closes #1367 and #928

See merge request core-developers/forge!2760
This commit is contained in:
Michael Kamensky
2020-04-26 15:15:48 +00:00
16 changed files with 89 additions and 28 deletions

View File

@@ -672,21 +672,25 @@ public class Game {
// Rule 800.4 Losing a Multiplayer game
CardCollectionView cards = this.getCardsInGame();
boolean planarControllerLost = false;
boolean isMultiplayer = this.getPlayers().size() > 2;
for(Card c : cards) {
if (c.getController().equals(p) && (c.isPlane() || c.isPhenomenon())) {
planarControllerLost = true;
}
if (c.getOwner().equals(p)) {
c.ceaseToExist();
} else {
c.removeTempController(p);
if (c.getController().equals(p)) {
this.getAction().exile(c, null);
if(isMultiplayer) {
if (c.getOwner().equals(p)) {
c.ceaseToExist();
} else {
c.removeTempController(p);
if (c.getController().equals(p)) {
this.getAction().exile(c, null);
}
}
} else {
c.forceTurnFaceUp();
}
}
// 901.6: If the current planar controller would leave the game, instead the next player

View File

@@ -285,6 +285,12 @@ public class Match {
if (null != cardsComplained) {
rAICards.putAll(player, cardsComplained);
}
} else {
//reset cards to fix weird issues on netplay nextgame client
for (Card c : player.getCardsIn(ZoneType.Library)) {
c.setTapped(false);
c.resetActivationsPerTurn();
}
}
if (myRemovedAnteCards != null && !myRemovedAnteCards.isEmpty()) {

View File

@@ -6331,6 +6331,12 @@ public class Card extends GameEntity implements Comparable<Card> {
getGame().getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
}
public void forceTurnFaceUp() {
getGame().getTriggerHandler().suppressMode(TriggerType.TurnFaceUp);
turnFaceUp(false, false);
getGame().getTriggerHandler().clearSuppression(TriggerType.TurnFaceUp);
}
public final void addGoad(Long timestamp, final Player p) {
goad.put(timestamp, p);
updateAbilityTextForView();

View File

@@ -886,12 +886,6 @@ public class CardView extends GameEntityView {
}
public String getImageKey(Iterable<PlayerView> viewers) {
if (canBeShownToAny(viewers)) {
// Morph cards can only be present on the battlefield and on stack, otherwise show a standard card back
if (getZone() != ZoneType.Battlefield && getZone() != ZoneType.Stack) {
if (isFaceDown() && get(TrackableProperty.ImageKey).equals(ImageKeys.getTokenKey(ImageKeys.MORPH_IMAGE))) {
return ImageKeys.getTokenKey(ImageKeys.HIDDEN_CARD);
}
}
return get(TrackableProperty.ImageKey);
}
return ImageKeys.getTokenKey(ImageKeys.HIDDEN_CARD);

View File

@@ -61,8 +61,8 @@ public enum TrackableProperty {
Haunting(TrackableTypes.CardViewType),
MustBlockCards(TrackableTypes.CardViewCollectionType),
PairedWith(TrackableTypes.CardViewType),
CurrentState(TrackableTypes.CardStateViewType, FreezeMode.IgnoresFreezeIfUnset),
AlternateState(TrackableTypes.CardStateViewType),
CurrentState(TrackableTypes.CardStateViewType, FreezeMode.IgnoresFreeze),
AlternateState(TrackableTypes.CardStateViewType, FreezeMode.IgnoresFreeze),
HiddenId(TrackableTypes.IntegerType),
ExertedThisTurn(TrackableTypes.BooleanType),

View File

@@ -37,5 +37,9 @@ public abstract class CachedCardImage implements ImageFetcher.Callback {
return ImageCache.getImage(key, true);
}
public Texture getImage(String mykey) {
return ImageCache.getImage(mykey, true);
}
public abstract void onImageFetched();
}

View File

@@ -6,7 +6,6 @@ import com.badlogic.gdx.utils.Align;
import com.google.common.collect.ImmutableList;
import forge.Forge;
import forge.Graphics;
import forge.ImageKeys;
import forge.assets.FBufferedImage;
import forge.assets.FImage;
import forge.assets.FSkin;
@@ -334,7 +333,7 @@ public class CardImageRenderer {
public static void drawZoom(Graphics g, CardView card, GameView gameView, boolean altState, float x, float y, float w, float h, float dispW, float dispH, boolean isCurrentCard) {
boolean canshow = MatchController.instance.mayView(card);
final Texture image = ImageCache.getImage(card.getState(altState).getImageKey(MatchController.instance.getLocalPlayers()), true);
final Texture image = ImageCache.getImage(card.getState(altState).getImageKey(), true);
FImage sleeves = MatchController.getPlayerSleeve(card.getOwner());
if (image == null) { //draw details if can't draw zoom
drawDetails(g, card, gameView, altState, x, y, w, h);
@@ -388,7 +387,7 @@ public class CardImageRenderer {
} else
g.drawRotatedImage(image, new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, isAftermath ? 90 : -90);
} else {
if (Forge.enableUIMask && canshow && !ImageKeys.getTokenKey(ImageKeys.MORPH_IMAGE).equals(card.getState(altState).getImageKey())) {
if (Forge.enableUIMask && canshow) {
if (ImageCache.isExtendedArt(card))
g.drawImage(image, x, y, w, h);
else {
@@ -396,7 +395,7 @@ public class CardImageRenderer {
g.drawImage(ImageCache.croppedBorderImage(image, fullborder), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea);
}
} else {
if (canshow && !ImageKeys.getTokenKey(ImageKeys.MORPH_IMAGE).equals(card.getState(altState).getImageKey()))
if (canshow)
g.drawImage(image, x, y, w, h);
else // sleeve
g.drawImage(sleeves, x, y, w, h);

View File

@@ -19,7 +19,6 @@ import forge.CachedCardImage;
import forge.Forge;
import forge.FThreads;
import forge.Graphics;
import forge.ImageKeys;
import forge.StaticData;
import forge.assets.FImage;
import forge.assets.FImageComplex;
@@ -482,8 +481,8 @@ public class CardRenderer {
}
}
public static void drawCard(Graphics g, CardView card, float x, float y, float w, float h, CardStackPosition pos, boolean rotate) {
boolean canshow = MatchController.instance.mayView(card) && !ImageKeys.getTokenKey(ImageKeys.MORPH_IMAGE).equals(card.getCurrentState().getImageKey());
Texture image = new RendererCachedCardImage(card, false).getImage();
boolean canshow = MatchController.instance.mayView(card);
Texture image = new RendererCachedCardImage(card, false).getImage(card.getCurrentState().getImageKey());
FImage sleeves = MatchController.getPlayerSleeve(card.getOwner());
float radius = (h - w)/8;
float croppedArea = isModernFrame(card) ? CROP_MULTIPLIER : 0.97f;

View File

@@ -226,6 +226,11 @@ public class MatchController extends AbstractGuiGame {
view.getStack().checkEmptyStack();
}
public void showWinlose() {
if (view.getViewWinLose() != null)
view.getViewWinLose().setVisible(true);
}
@Override
public void updateTurn(final PlayerView player) {
}
@@ -254,7 +259,8 @@ public class MatchController extends AbstractGuiGame {
@Override
public void finishGame() {
if (hasLocalPlayers() || getGameView().isMatchOver()) {
new ViewWinLose(getGameView()).setVisible(true);
view.setViewWinLose(new ViewWinLose(getGameView()));
view.getViewWinLose().setVisible(true);
}
}

View File

@@ -9,6 +9,7 @@ import java.util.Set;
import com.badlogic.gdx.graphics.Color;
import forge.screens.match.winlose.ViewWinLose;
import forge.util.Localizer;
import org.apache.commons.lang3.tuple.Pair;
@@ -78,6 +79,8 @@ public class MatchScreen extends FScreen {
private VPlayerPanel bottomPlayerPanel, topPlayerPanel;
private AbilityEffect activeEffect;
private ViewWinLose viewWinLose = null;
public MatchScreen(List<VPlayerPanel> playerPanels0) {
super(new FMenuBar());
@@ -292,6 +295,14 @@ public class MatchScreen extends FScreen {
return topPlayerPanel;
}
public void setViewWinLose( ViewWinLose viewWinLose ){
this.viewWinLose = viewWinLose;
}
public ViewWinLose getViewWinLose() {
return viewWinLose;
}
public VPlayerPanel getBottomPlayerPanel() {
return bottomPlayerPanel;
}
@@ -482,9 +493,9 @@ public class MatchScreen extends FScreen {
}
public void resetFields() {
CardAreaPanel.resetForNewGame();
for (VPlayerPanel playerPanel : getPlayerPanels().values()) {
for (CardAreaPanel p : playerPanel.getField().getCardPanels()){
p.resetForNewGame();
p.reset();
}
playerPanel.getZoneTab(ZoneType.Hand).getDisplayArea().clear();

View File

@@ -92,5 +92,11 @@ public class VGameMenu extends FDropDownMenu {
SettingsScreen.show(false);
}
}));
addItem(new FMenuItem("Show WinLose Overlay", null, new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
MatchController.instance.showWinlose();
}
}));
}
}

View File

@@ -67,8 +67,8 @@ public class VZoneDisplay extends VCardDisplayArea {
private void setRevealedPanel(int idx) {
try {
revealedPanel = cardPanels.get(idx); //??? on network match, triggered by card ability
} catch (ArrayIndexOutOfBoundsException e) {
revealedPanel = cardPanels.get(idx); //on network match, when zoomed and cast a card would randomly trigger the bug
} catch (Exception e) { //before it was arrayindexoutofbounds, then indexoutofbounds, so just use a general exception
e.printStackTrace();
return;
}

View File

@@ -1,6 +1,8 @@
package forge.screens.match.winlose;
import forge.Forge;
import forge.game.GameView;
import forge.game.player.PlayerView;
import forge.screens.match.MatchController;
import forge.toolbox.FEvent;
import forge.toolbox.FEvent.FEventHandler;
@@ -14,12 +16,18 @@ import forge.toolbox.FEvent.FEventHandler;
public class ControlWinLose {
private final ViewWinLose view;
protected final GameView lastGame;
private int humancount;
/** @param v &emsp; ViewWinLose
* @param match */
public ControlWinLose(final ViewWinLose v, GameView game) {
view = v;
lastGame = game;
humancount = 0;
for(PlayerView p: game.getPlayers()){
if (!p.isAI())
humancount++;
}
addListeners();
}
@@ -46,6 +54,8 @@ public class ControlWinLose {
view.getBtnQuit().setEnabled(false);
}
});
if(humancount == 0)
view.getBtnRestart().setEnabled(false);
}
/** Action performed when "continue" button is pressed in default win/lose UI. */
@@ -72,6 +82,8 @@ public class ControlWinLose {
try { MatchController.getHostedMatch().endCurrentGame();
} catch (NullPointerException e) {}
view.hide();
if(humancount == 0)
Forge.back();
}
/**

View File

@@ -36,7 +36,7 @@ public class ViewWinLose extends FOverlay implements IWinLoseView<FButton> {
private static final float GAP_Y_FACTOR = 0.02f;
private final FButton btnContinue, btnRestart, btnQuit;
private final FLabel lblTitle, lblLog, lblStats, btnCopyLog;
private final FLabel lblTitle, lblLog, lblStats, btnCopyLog, btnMinimize;
private final FTextArea txtLog;
private final OutcomesPanel pnlOutcomes;
private final GameView game;
@@ -114,6 +114,12 @@ public class ViewWinLose extends FOverlay implements IWinLoseView<FButton> {
}
}).build());
btnMinimize = add(new FLabel.ButtonBuilder().text("Minimize").font(FSkinFont.get(12)).command(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
hide();
}
}).build());
lblTitle.setText(composeTitle(game0));
showGameOutcomeSummary();
@@ -200,6 +206,7 @@ public class ViewWinLose extends FOverlay implements IWinLoseView<FButton> {
float y2 = height - dy - h;
btnCopyLog.setBounds(width / 4, y2, width / 2, h);
txtLog.setBounds(x, y, w, y2 - y - dy);
btnMinimize.setBounds(0, 0, width, h);
}
private static class OutcomesPanel extends FContainer {

View File

@@ -182,6 +182,9 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
return true; //if not in game, card can be shown
}
if(GuiBase.getInterface().isLibgdxPort()){
if(gameView.isGameOver()) {
return true;
}
if(spectator!=null) { //workaround fix!! this is needed on above code or it will
gameControllers.remove(spectator); //bug the UI! remove spectator here since its must not be here...
return true;

View File

@@ -295,6 +295,7 @@ public class HostedMatch {
public void endCurrentGame() {
if (game == null) { return; }
boolean isMatchOver = game.getView().isMatchOver();
game = null;
@@ -304,7 +305,10 @@ public class HostedMatch {
humanController.getGui().clearAutoYields();
}
humanController.getGui().afterGameEnd();
if (humanCount > 0) //conceded
humanController.getGui().afterGameEnd();
else if (!GuiBase.getInterface().isLibgdxPort()||!isMatchOver)
humanController.getGui().afterGameEnd();
}
humanControllers.clear();
}