mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
- Fix match music not stopping when moving Forge to background
- Fix quit warning not mentioning matches when one or more are active - Some minor fixes and cleanup
This commit is contained in:
@@ -274,6 +274,8 @@ public class GuiDesktop implements IGuiBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HostedMatch hostMatch() {
|
public HostedMatch hostMatch() {
|
||||||
return new HostedMatch();
|
final HostedMatch match = new HostedMatch();
|
||||||
|
Singletons.getControl().addMatch(match);
|
||||||
|
return match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,7 @@ import java.awt.event.KeyEvent;
|
|||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
@@ -34,6 +35,7 @@ import javax.swing.JLayeredPane;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.WindowConstants;
|
import javax.swing.WindowConstants;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.ImageCache;
|
import forge.ImageCache;
|
||||||
@@ -86,6 +88,28 @@ public enum FControl implements KeyEventDispatcher {
|
|||||||
EXIT_FORGE;
|
EXIT_FORGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasCurrentMatches() {
|
||||||
|
cleanMatches();
|
||||||
|
return !currentMatches.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HostedMatch> getCurrentMatches() {
|
||||||
|
cleanMatches();
|
||||||
|
return Collections.unmodifiableList(currentMatches);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMatch(final HostedMatch match) {
|
||||||
|
cleanMatches();
|
||||||
|
currentMatches.add(match);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanMatches() {
|
||||||
|
for (final HostedMatch match : ImmutableList.copyOf(currentMatches)) {
|
||||||
|
if (match.isMatchOver()) {
|
||||||
|
currentMatches.remove(match);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* FControl.
|
* FControl.
|
||||||
@@ -139,7 +163,7 @@ public enum FControl implements KeyEventDispatcher {
|
|||||||
return closeAction;
|
return closeAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCloseAction(CloseAction closeAction0) {
|
public void setCloseAction(final CloseAction closeAction0) {
|
||||||
if (closeAction == closeAction0) { return; }
|
if (closeAction == closeAction0) { return; }
|
||||||
closeAction = closeAction0;
|
closeAction = closeAction0;
|
||||||
Singletons.getView().getNavigationBar().updateBtnCloseTooltip();
|
Singletons.getView().getNavigationBar().updateBtnCloseTooltip();
|
||||||
@@ -149,13 +173,14 @@ public enum FControl implements KeyEventDispatcher {
|
|||||||
prefs.save();
|
prefs.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canExitForge(boolean forRestart) {
|
public boolean canExitForge(final boolean forRestart) {
|
||||||
String action = (forRestart ? "Restart" : "Exit");
|
final String action = (forRestart ? "Restart" : "Exit");
|
||||||
String userPrompt = "Are you sure you wish to " + (forRestart ? "restart" : "exit") + " Forge?";
|
String userPrompt = "Are you sure you wish to " + (forRestart ? "restart" : "exit") + " Forge?";
|
||||||
if (!currentMatches.isEmpty()) {
|
final boolean hasCurrentMatches = hasCurrentMatches();
|
||||||
userPrompt = "A game is currently active. " + userPrompt;
|
if (hasCurrentMatches) {
|
||||||
|
userPrompt = "One or more games are currently active. " + userPrompt;
|
||||||
}
|
}
|
||||||
if (!FOptionPane.showConfirmDialog(userPrompt, action + " Forge", action, "Cancel", currentMatches.isEmpty())) { //default Yes if no game active
|
if (!FOptionPane.showConfirmDialog(userPrompt, action + " Forge", action, "Cancel", !hasCurrentMatches)) { //default Yes if no game active
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!CDeckEditorUI.SINGLETON_INSTANCE.canSwitchAway(true)) {
|
if (!CDeckEditorUI.SINGLETON_INSTANCE.canSwitchAway(true)) {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import javax.swing.MenuElement;
|
|||||||
import javax.swing.MenuSelectionManager;
|
import javax.swing.MenuSelectionManager;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
@@ -60,6 +59,7 @@ import forge.game.combat.CombatView;
|
|||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.DelayedReveal;
|
import forge.game.player.DelayedReveal;
|
||||||
import forge.game.player.IHasIcon;
|
import forge.game.player.IHasIcon;
|
||||||
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerView;
|
import forge.game.player.PlayerView;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
@@ -105,7 +105,6 @@ import forge.toolbox.special.PhaseIndicator;
|
|||||||
import forge.toolbox.special.PhaseLabel;
|
import forge.toolbox.special.PhaseLabel;
|
||||||
import forge.util.FCollectionView;
|
import forge.util.FCollectionView;
|
||||||
import forge.util.ITriggerEvent;
|
import forge.util.ITriggerEvent;
|
||||||
import forge.util.gui.SGuiChoose;
|
|
||||||
import forge.util.gui.SOptionPane;
|
import forge.util.gui.SOptionPane;
|
||||||
import forge.view.FView;
|
import forge.view.FView;
|
||||||
import forge.view.arcane.CardPanel;
|
import forge.view.arcane.CardPanel;
|
||||||
@@ -249,7 +248,7 @@ public final class CMatchUI
|
|||||||
view.getLblAvatar().getResizeTimer().start();
|
view.getLblAvatar().getResizeTimer().start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initMatch(final FCollectionView<PlayerView> sortedPlayers, final FCollectionView<PlayerView> myPlayers) {
|
public void initMatch(final FCollectionView<PlayerView> sortedPlayers, final Iterable<PlayerView> myPlayers) {
|
||||||
this.sortedPlayers = sortedPlayers;
|
this.sortedPlayers = sortedPlayers;
|
||||||
this.setLocalPlayers(myPlayers);
|
this.setLocalPlayers(myPlayers);
|
||||||
allHands = sortedPlayers.size() == getLocalPlayerCount();
|
allHands = sortedPlayers.size() == getLocalPlayerCount();
|
||||||
@@ -766,7 +765,7 @@ public final class CMatchUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openView(final FCollectionView<PlayerView> myPlayers) {
|
public void openView(final Iterable<PlayerView> myPlayers) {
|
||||||
final GameView gameView = getGameView();
|
final GameView gameView = getGameView();
|
||||||
gameView.getGameLog().addObserver(getCLog());
|
gameView.getGameLog().addObserver(getCLog());
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ import javax.swing.JRootPane;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
|
|
||||||
|
import forge.Singletons;
|
||||||
import forge.gui.framework.SDisplayUtil;
|
import forge.gui.framework.SDisplayUtil;
|
||||||
import forge.gui.framework.SResizingUtil;
|
import forge.gui.framework.SResizingUtil;
|
||||||
|
import forge.match.HostedMatch;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
import forge.properties.ForgePreferences;
|
import forge.properties.ForgePreferences;
|
||||||
import forge.properties.ForgePreferences.FPref;
|
import forge.properties.ForgePreferences.FPref;
|
||||||
@@ -90,14 +92,18 @@ public class FFrame extends SkinnedFrame implements ITitleBarOwner {
|
|||||||
private void pause() {
|
private void pause() {
|
||||||
if (paused || !isMainFrame) { return; }
|
if (paused || !isMainFrame) { return; }
|
||||||
|
|
||||||
//HostedMatch.pause();
|
for (final HostedMatch hostedMatch : Singletons.getControl().getCurrentMatches()) {
|
||||||
|
hostedMatch.pause();
|
||||||
|
}
|
||||||
paused = true;
|
paused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resume() {
|
private void resume() {
|
||||||
if (!paused || !isMainFrame) { return; }
|
if (!paused || !isMainFrame) { return; }
|
||||||
|
|
||||||
//HostedMatch.resume();
|
for (final HostedMatch hostedMatch : Singletons.getControl().getCurrentMatches()) {
|
||||||
|
hostedMatch.resume();
|
||||||
|
}
|
||||||
paused = false;
|
paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public class MatchController extends AbstractGuiGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openView(final FCollectionView<PlayerView> myPlayers) {
|
public void openView(final Iterable<PlayerView> myPlayers) {
|
||||||
setLocalPlayers(myPlayers);
|
setLocalPlayers(myPlayers);
|
||||||
final boolean noHumans = !hasLocalPlayers();
|
final boolean noHumans = !hasLocalPlayers();
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public interface IGuiGame {
|
|||||||
void setGameView(GameView gameView);
|
void setGameView(GameView gameView);
|
||||||
void setGameController(PlayerView player, IGameController gameController);
|
void setGameController(PlayerView player, IGameController gameController);
|
||||||
boolean resetForNewGame();
|
boolean resetForNewGame();
|
||||||
void openView(FCollectionView<PlayerView> myPlayers);
|
void openView(Iterable<PlayerView> myPlayers);
|
||||||
void afterGameEnd();
|
void afterGameEnd();
|
||||||
void showCombat();
|
void showCombat();
|
||||||
void showPromptMessage(PlayerView playerView, String message);
|
void showPromptMessage(PlayerView playerView, String message);
|
||||||
|
|||||||
@@ -28,15 +28,16 @@ import forge.interfaces.IButton;
|
|||||||
import forge.interfaces.IGameController;
|
import forge.interfaces.IGameController;
|
||||||
import forge.interfaces.IGuiGame;
|
import forge.interfaces.IGuiGame;
|
||||||
import forge.interfaces.IMayViewCards;
|
import forge.interfaces.IMayViewCards;
|
||||||
|
import forge.util.FCollection;
|
||||||
import forge.util.FCollectionView;
|
import forge.util.FCollectionView;
|
||||||
|
|
||||||
public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
|
public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards {
|
||||||
private FCollectionView<PlayerView> localPlayers;
|
private FCollectionView<PlayerView> localPlayers = new FCollection<PlayerView>();
|
||||||
private PlayerView currentPlayer = null;
|
private PlayerView currentPlayer = null;
|
||||||
|
|
||||||
protected final void setLocalPlayers(final FCollectionView<PlayerView> players) {
|
protected final void setLocalPlayers(final Iterable<PlayerView> myPlayers) {
|
||||||
this.localPlayers = players;
|
this.localPlayers = myPlayers == null ? new FCollection<PlayerView>() : new FCollection<PlayerView>(myPlayers);
|
||||||
this.currentPlayer = players == null ? null : Iterables.getFirst(players, null);
|
this.currentPlayer = Iterables.getFirst(this.localPlayers, null);
|
||||||
}
|
}
|
||||||
public final boolean hasLocalPlayers() {
|
public final boolean hasLocalPlayers() {
|
||||||
return localPlayers != null && !localPlayers.isEmpty();
|
return localPlayers != null && !localPlayers.isEmpty();
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class HostedMatch {
|
|||||||
private FControlGamePlayback playbackControl = null;
|
private FControlGamePlayback playbackControl = null;
|
||||||
private final MatchUiEventVisitor visitor = new MatchUiEventVisitor();
|
private final MatchUiEventVisitor visitor = new MatchUiEventVisitor();
|
||||||
private final Map<PlayerControllerHuman, NextGameDecision> nextGameDecisions = Maps.newHashMap();
|
private final Map<PlayerControllerHuman, NextGameDecision> nextGameDecisions = Maps.newHashMap();
|
||||||
|
private boolean isMatchOver = false;
|
||||||
|
|
||||||
public HostedMatch() {
|
public HostedMatch() {
|
||||||
}
|
}
|
||||||
@@ -222,7 +223,7 @@ public class HostedMatch {
|
|||||||
match.startGame(game);
|
match.startGame(game);
|
||||||
|
|
||||||
// After game is over...
|
// After game is over...
|
||||||
if (humanCount == 0) {
|
if (match.isMatchOver() && humanCount == 0) {
|
||||||
// ... if no human players, let AI decide next game
|
// ... if no human players, let AI decide next game
|
||||||
addNextGameDecision(null, NextGameDecision.CONTINUE);
|
addNextGameDecision(null, NextGameDecision.CONTINUE);
|
||||||
}
|
}
|
||||||
@@ -256,6 +257,7 @@ public class HostedMatch {
|
|||||||
humanController.getGui().afterGameEnd();
|
humanController.getGui().afterGameEnd();
|
||||||
}
|
}
|
||||||
humanControllers.clear();
|
humanControllers.clear();
|
||||||
|
isMatchOver = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause() {
|
public void pause() {
|
||||||
@@ -273,6 +275,10 @@ public class HostedMatch {
|
|||||||
SoundSystem.instance.resume();
|
SoundSystem.instance.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMatchOver() {
|
||||||
|
return isMatchOver;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns a random name from the supplied list. */
|
/** Returns a random name from the supplied list. */
|
||||||
public static String getRandomName() {
|
public static String getRandomName() {
|
||||||
final String playerName = GuiDisplayUtil.getPlayerName();
|
final String playerName = GuiDisplayUtil.getPlayerName();
|
||||||
|
|||||||
Reference in New Issue
Block a user