- 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:
elcnesh
2015-02-22 00:18:50 +00:00
parent 215ccc4c78
commit ab1d24cc8a
8 changed files with 59 additions and 20 deletions

View File

@@ -274,6 +274,8 @@ public class GuiDesktop implements IGuiBase {
@Override
public HostedMatch hostMatch() {
return new HostedMatch();
final HostedMatch match = new HostedMatch();
Singletons.getControl().addMatch(match);
return match;
}
}

View File

@@ -27,6 +27,7 @@ import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.Collections;
import java.util.List;
import javax.swing.ImageIcon;
@@ -34,6 +35,7 @@ import javax.swing.JLayeredPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import forge.ImageCache;
@@ -86,6 +88,28 @@ public enum FControl implements KeyEventDispatcher {
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>
* FControl.
@@ -139,7 +163,7 @@ public enum FControl implements KeyEventDispatcher {
return closeAction;
}
public void setCloseAction(CloseAction closeAction0) {
public void setCloseAction(final CloseAction closeAction0) {
if (closeAction == closeAction0) { return; }
closeAction = closeAction0;
Singletons.getView().getNavigationBar().updateBtnCloseTooltip();
@@ -149,13 +173,14 @@ public enum FControl implements KeyEventDispatcher {
prefs.save();
}
public boolean canExitForge(boolean forRestart) {
String action = (forRestart ? "Restart" : "Exit");
public boolean canExitForge(final boolean forRestart) {
final String action = (forRestart ? "Restart" : "Exit");
String userPrompt = "Are you sure you wish to " + (forRestart ? "restart" : "exit") + " Forge?";
if (!currentMatches.isEmpty()) {
userPrompt = "A game is currently active. " + userPrompt;
final boolean hasCurrentMatches = hasCurrentMatches();
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;
}
if (!CDeckEditorUI.SINGLETON_INSTANCE.canSwitchAway(true)) {

View File

@@ -36,7 +36,6 @@ import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.SwingUtilities;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Function;
@@ -60,6 +59,7 @@ import forge.game.combat.CombatView;
import forge.game.phase.PhaseType;
import forge.game.player.DelayedReveal;
import forge.game.player.IHasIcon;
import forge.game.player.Player;
import forge.game.player.PlayerView;
import forge.game.spellability.SpellAbility;
import forge.game.zone.ZoneType;
@@ -105,7 +105,6 @@ import forge.toolbox.special.PhaseIndicator;
import forge.toolbox.special.PhaseLabel;
import forge.util.FCollectionView;
import forge.util.ITriggerEvent;
import forge.util.gui.SGuiChoose;
import forge.util.gui.SOptionPane;
import forge.view.FView;
import forge.view.arcane.CardPanel;
@@ -249,7 +248,7 @@ public final class CMatchUI
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.setLocalPlayers(myPlayers);
allHands = sortedPlayers.size() == getLocalPlayerCount();
@@ -766,7 +765,7 @@ public final class CMatchUI
}
@Override
public void openView(final FCollectionView<PlayerView> myPlayers) {
public void openView(final Iterable<PlayerView> myPlayers) {
final GameView gameView = getGameView();
gameView.getGameLog().addObserver(getCLog());

View File

@@ -19,8 +19,10 @@ import javax.swing.JRootPane;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import forge.Singletons;
import forge.gui.framework.SDisplayUtil;
import forge.gui.framework.SResizingUtil;
import forge.match.HostedMatch;
import forge.model.FModel;
import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.FPref;
@@ -90,14 +92,18 @@ public class FFrame extends SkinnedFrame implements ITitleBarOwner {
private void pause() {
if (paused || !isMainFrame) { return; }
//HostedMatch.pause();
for (final HostedMatch hostedMatch : Singletons.getControl().getCurrentMatches()) {
hostedMatch.pause();
}
paused = true;
}
private void resume() {
if (!paused || !isMainFrame) { return; }
//HostedMatch.resume();
for (final HostedMatch hostedMatch : Singletons.getControl().getCurrentMatches()) {
hostedMatch.resume();
}
paused = false;
}