mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Add intermediate FloatingCardArea to hold commonalities between FloatingZone and ListCardArea
This commit is contained in:
@@ -290,12 +290,9 @@ public class GuiChoose {
|
||||
final Callable<List<Card>> callable = new Callable<List<Card>>() {
|
||||
@Override
|
||||
public List<Card> call() throws Exception {
|
||||
ListCardArea tempArea = new ListCardArea(gui,title,cards,manipulable,toTop,toBottom,toAnywhere);
|
||||
ListCardArea tempArea = ListCardArea.show(gui,title,cards,manipulable,toTop,toBottom,toAnywhere);
|
||||
// tempArea.pack();
|
||||
// window? tempArea.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
tempArea.show();
|
||||
// tempArea.dispose();
|
||||
//try { Thread.sleep(1000); } catch(InterruptedException ex) { }
|
||||
final List<Card> cardList = tempArea.getCardList();
|
||||
return cardList;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ import forge.util.ITriggerEvent;
|
||||
import forge.util.gui.SOptionPane;
|
||||
import forge.view.FView;
|
||||
import forge.view.arcane.CardPanel;
|
||||
import forge.view.arcane.FloatingCardArea;
|
||||
import forge.view.arcane.FloatingZone;
|
||||
import forge.match.input.*;
|
||||
|
||||
/**
|
||||
@@ -401,7 +401,7 @@ public final class CMatchUI
|
||||
break;
|
||||
default:
|
||||
updateZones = true;
|
||||
FloatingCardArea.refresh(owner, zone);
|
||||
FloatingZone.refresh(owner, zone);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -437,7 +437,7 @@ public final class CMatchUI
|
||||
break;
|
||||
case Hand: // controller hand always shown
|
||||
if (controller != player) {
|
||||
FloatingCardArea.show(this,player,zone);
|
||||
FloatingZone.show(this,player,zone);
|
||||
}
|
||||
break;
|
||||
case Library:
|
||||
@@ -445,7 +445,7 @@ public final class CMatchUI
|
||||
case Exile:
|
||||
case Flashback:
|
||||
case Command:
|
||||
FloatingCardArea.show(this,player,zone);
|
||||
FloatingZone.show(this,player,zone);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -469,7 +469,7 @@ public final class CMatchUI
|
||||
case Exile:
|
||||
case Flashback:
|
||||
case Command:
|
||||
FloatingCardArea.hide(this,player,zone);
|
||||
FloatingZone.hide(this,player,zone);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -519,7 +519,7 @@ public final class CMatchUI
|
||||
}
|
||||
break;
|
||||
default:
|
||||
FloatingCardArea.refresh(c.getController(),zone); // in case the card is visible in the zone
|
||||
FloatingZone.refresh(c.getController(),zone); // in case the card is visible in the zone
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -559,7 +559,7 @@ public final class CMatchUI
|
||||
layoutControl.initialize();
|
||||
layoutControl.update();
|
||||
}
|
||||
FloatingCardArea.closeAll();
|
||||
FloatingZone.closeAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -617,7 +617,7 @@ public final class CMatchUI
|
||||
case Exile:
|
||||
case Graveyard:
|
||||
case Library:
|
||||
return FloatingCardArea.getCardPanel(this, card);
|
||||
return FloatingZone.getCardPanel(this, card);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -728,7 +728,7 @@ public final class CMatchUI
|
||||
|
||||
@Override
|
||||
public void finishGame() {
|
||||
FloatingCardArea.closeAll(); //ensure floating card areas cleared and closed after the game
|
||||
FloatingZone.closeAll(); //ensure floating card areas cleared and closed after the game
|
||||
final GameView gameView = getGameView();
|
||||
if (hasLocalPlayers() || gameView.isMatchOver()) {
|
||||
new ViewWinLose(gameView, this).show();
|
||||
@@ -842,7 +842,7 @@ public final class CMatchUI
|
||||
} else {
|
||||
final ZoneType zone = hostCard.getZone();
|
||||
if (ImmutableList.of(ZoneType.Command, ZoneType.Exile, ZoneType.Graveyard, ZoneType.Library).contains(zone)) {
|
||||
FloatingCardArea.show(this, hostCard.getController(), zone);
|
||||
FloatingZone.show(this, hostCard.getController(), zone);
|
||||
}
|
||||
menuParent = panel.getParent();
|
||||
x = triggerEvent.getX();
|
||||
|
||||
@@ -2,7 +2,7 @@ package forge.screens.match;
|
||||
|
||||
import forge.game.player.PlayerView;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.view.arcane.FloatingCardArea;
|
||||
import forge.view.arcane.FloatingZone;
|
||||
|
||||
/**
|
||||
* Receives click and programmatic requests for viewing data stacks in the
|
||||
@@ -27,6 +27,6 @@ public final class ZoneAction implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
FloatingCardArea.showOrHide(matchUI, player, zone);
|
||||
FloatingZone.showOrHide(matchUI, player, zone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,25 +17,19 @@
|
||||
*/
|
||||
package forge.view.arcane;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.game.card.CardView;
|
||||
import forge.game.player.PlayerView;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.framework.SDisplayUtil;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences;
|
||||
@@ -43,194 +37,58 @@ import forge.properties.ForgePreferences.FPref;
|
||||
import forge.screens.match.CMatchUI;
|
||||
import forge.toolbox.FMouseAdapter;
|
||||
import forge.toolbox.FScrollPane;
|
||||
import forge.toolbox.FSkin;
|
||||
import forge.toolbox.MouseTriggerEvent;
|
||||
import forge.util.collect.FCollectionView;
|
||||
import forge.util.Lang;
|
||||
//import forge.util.collect.FCollectionView;
|
||||
import forge.view.FDialog;
|
||||
import forge.view.FFrame;
|
||||
|
||||
public class FloatingCardArea extends CardArea {
|
||||
private static final long serialVersionUID = 1927906492186378596L;
|
||||
// show some cards in a new window
|
||||
public abstract class FloatingCardArea extends CardArea {
|
||||
|
||||
private static final String COORD_DELIM = ",";
|
||||
protected static final String COORD_DELIM = ",";
|
||||
protected static final ForgePreferences prefs = FModel.getPreferences();
|
||||
|
||||
private static final ForgePreferences prefs = FModel.getPreferences();
|
||||
private static final Map<Integer, FloatingCardArea> floatingAreas = new HashMap<Integer, FloatingCardArea>();
|
||||
protected String title;
|
||||
protected FPref locPref;
|
||||
protected boolean hasBeenShown, locLoaded;
|
||||
|
||||
private static int getKey(final PlayerView player, final ZoneType zone) {
|
||||
return 40 * player.getId() + zone.hashCode();
|
||||
}
|
||||
public static void showOrHide(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
|
||||
final FloatingCardArea cardArea = _init(matchUI, player, zone);
|
||||
cardArea.showOrHideWindow();
|
||||
}
|
||||
public static void show(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
|
||||
final FloatingCardArea cardArea = _init(matchUI, player, zone);
|
||||
cardArea.showWindow();
|
||||
}
|
||||
public static void hide(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
|
||||
final FloatingCardArea cardArea = _init(matchUI, player, zone);
|
||||
cardArea.hideWindow();
|
||||
}
|
||||
private static FloatingCardArea _init(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
|
||||
final int key = getKey(player, zone);
|
||||
FloatingCardArea cardArea = floatingAreas.get(key);
|
||||
if (cardArea == null || cardArea.getMatchUI() != matchUI) {
|
||||
cardArea = new FloatingCardArea(matchUI, player, zone);
|
||||
floatingAreas.put(key, cardArea);
|
||||
} else {
|
||||
cardArea.setPlayer(player); //ensure player is updated if needed
|
||||
}
|
||||
return cardArea;
|
||||
}
|
||||
public static CardPanel getCardPanel(final CMatchUI matchUI, final CardView card) {
|
||||
final FloatingCardArea window = _init(matchUI, card.getController(), card.getZone());
|
||||
return window.getCardPanel(card.getId());
|
||||
}
|
||||
public static void refresh(final PlayerView player, final ZoneType zone) {
|
||||
FloatingCardArea cardArea = floatingAreas.get(getKey(player, zone));
|
||||
if (cardArea != null) {
|
||||
cardArea.setPlayer(player); //ensure player is updated if needed
|
||||
cardArea.refresh();
|
||||
}
|
||||
protected abstract FDialog getWindow();
|
||||
protected abstract Iterable<CardView> getCards();
|
||||
|
||||
//refresh flashback zone when graveyard, library, or exile zones updated
|
||||
switch (zone) {
|
||||
case Graveyard:
|
||||
case Library:
|
||||
case Exile:
|
||||
refresh(player, ZoneType.Flashback);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
protected FloatingCardArea(final CMatchUI matchUI) {
|
||||
this(matchUI, new FScrollPane(false, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
|
||||
}
|
||||
public static void closeAll() {
|
||||
for (final FloatingCardArea cardArea : floatingAreas.values()) {
|
||||
cardArea.window.setVisible(false);
|
||||
}
|
||||
floatingAreas.clear();
|
||||
protected FloatingCardArea(final CMatchUI matchUI, final FScrollPane scrollPane) {
|
||||
super(matchUI, scrollPane);
|
||||
}
|
||||
|
||||
private final ZoneType zone;
|
||||
private PlayerView player;
|
||||
private String title;
|
||||
private FPref locPref;
|
||||
private boolean hasBeenShown, locLoaded;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private final FDialog window = new FDialog(false, true, "0") {
|
||||
@Override
|
||||
public void setLocationRelativeTo(Component c) {
|
||||
//don't change location this way if dialog has already been shown or location was loaded from preferences
|
||||
if (hasBeenShown || locLoaded) { return; }
|
||||
super.setLocationRelativeTo(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean b0) {
|
||||
if (isVisible() == b0) { return; }
|
||||
if (!b0 && hasBeenShown && locPref != null) {
|
||||
//update preference before hiding window, as otherwise its location will be 0,0
|
||||
prefs.setPref(locPref,
|
||||
getX() + COORD_DELIM + getY() + COORD_DELIM +
|
||||
getWidth() + COORD_DELIM + getHeight());
|
||||
//don't call prefs.save(), instead allowing them to be saved when match ends
|
||||
}
|
||||
super.setVisible(b0);
|
||||
if (b0) {
|
||||
refresh();
|
||||
hasBeenShown = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private FloatingCardArea(final CMatchUI matchUI, final PlayerView player0, final ZoneType zone0) {
|
||||
super(matchUI, new FScrollPane(false, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
|
||||
window.add(getScrollPane(), "grow, push");
|
||||
getScrollPane().setViewportView(this);
|
||||
setOpaque(false);
|
||||
switch (zone0) {
|
||||
case Exile:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_EXILE));
|
||||
break;
|
||||
case Graveyard:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_GRAVEYARD));
|
||||
break;
|
||||
case Hand:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_HAND));
|
||||
break;
|
||||
case Library:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_LIBRARY));
|
||||
break;
|
||||
case Flashback:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_FLASHBACK));
|
||||
break;
|
||||
default:
|
||||
locPref = null;
|
||||
break;
|
||||
}
|
||||
zone = zone0;
|
||||
setPlayer(player0);
|
||||
setVertical(true);
|
||||
}
|
||||
|
||||
private void setPlayer(PlayerView player0) {
|
||||
if (player == player0) { return; }
|
||||
player = player0;
|
||||
title = Lang.getPossessedObject(player0.getName(), zone.name()) + " (%d)";
|
||||
|
||||
boolean isAi = player0.isAI();
|
||||
switch (zone) {
|
||||
case Exile:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_EXILE : FPref.ZONE_LOC_HUMAN_EXILE;
|
||||
break;
|
||||
case Graveyard:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_GRAVEYARD : FPref.ZONE_LOC_HUMAN_GRAVEYARD;
|
||||
break;
|
||||
case Hand:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_HAND : FPref.ZONE_LOC_HUMAN_HAND;
|
||||
break;
|
||||
case Library:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_LIBRARY : FPref.ZONE_LOC_HUMAN_LIBRARY;
|
||||
break;
|
||||
case Flashback:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_FLASHBACK : FPref.ZONE_LOC_HUMAN_FLASHBACK;
|
||||
break;
|
||||
default:
|
||||
locPref = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void showWindow() {
|
||||
protected void showWindow() {
|
||||
onShow();
|
||||
window.setFocusableWindowState(false); // should probably do this earlier
|
||||
window.setVisible(true);
|
||||
getWindow().setFocusableWindowState(false); // should probably do this earlier
|
||||
getWindow().setVisible(true);
|
||||
}
|
||||
private void hideWindow() {
|
||||
protected void hideWindow() {
|
||||
onShow();
|
||||
window.setFocusableWindowState(false); // should probably do this earlier
|
||||
window.setVisible(false);
|
||||
getWindow().setFocusableWindowState(false); // should probably do this earlier
|
||||
getWindow().setVisible(false);
|
||||
}
|
||||
private void showOrHideWindow() {
|
||||
protected void showOrHideWindow() {
|
||||
onShow();
|
||||
window.setFocusableWindowState(false); // should probably do this earlier
|
||||
window.setVisible(!window.isVisible());
|
||||
getWindow().setFocusableWindowState(false); // should probably do this earlier
|
||||
getWindow().setVisible(!getWindow().isVisible());
|
||||
}
|
||||
private void onShow() {
|
||||
protected void onShow() {
|
||||
if (!hasBeenShown) {
|
||||
loadLocation();
|
||||
window.getTitleBar().addMouseListener(new FMouseAdapter() {
|
||||
getWindow().getTitleBar().addMouseListener(new FMouseAdapter() {
|
||||
@Override public final void onLeftDoubleClick(final MouseEvent e) {
|
||||
window.setVisible(false); //hide window if titlebar double-clicked
|
||||
getWindow().setVisible(false); //hide window if titlebar double-clicked
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLocation() {
|
||||
protected void loadLocation() {
|
||||
if (locPref != null) {
|
||||
String value = prefs.getPref(locPref);
|
||||
if (value.length() > 0) {
|
||||
@@ -264,7 +122,7 @@ public class FloatingCardArea extends CardArea {
|
||||
y = screenBounds.y;
|
||||
}
|
||||
}
|
||||
window.setBounds(x, y, w, h);
|
||||
getWindow().setBounds(x, y, w, h);
|
||||
locLoaded = true;
|
||||
return;
|
||||
}
|
||||
@@ -278,14 +136,17 @@ public class FloatingCardArea extends CardArea {
|
||||
}
|
||||
//fallback default size
|
||||
FFrame mainFrame = Singletons.getView().getFrame();
|
||||
window.setSize(mainFrame.getWidth() / 5, mainFrame.getHeight() / 2);
|
||||
getWindow().setSize(mainFrame.getWidth() / 5, mainFrame.getHeight() / 2);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
if (!window.isVisible()) { return; } //don't refresh while window hidden
|
||||
protected void refresh() {
|
||||
if (!getWindow().isVisible()) { return; } //don't refresh while window hidden
|
||||
doRefresh();
|
||||
}
|
||||
|
||||
protected void doRefresh() {
|
||||
List<CardPanel> cardPanels = new ArrayList<CardPanel>();
|
||||
FCollectionView<CardView> cards = player.getCards(zone);
|
||||
Iterable<CardView> cards = getCards();
|
||||
if (cards != null) {
|
||||
for (final CardView card : cards) {
|
||||
CardPanel cardPanel = getCardPanel(card.getId());
|
||||
@@ -302,27 +163,26 @@ public class FloatingCardArea extends CardArea {
|
||||
|
||||
boolean hadCardPanels = getCardPanels().size() > 0;
|
||||
setCardPanels(cardPanels);
|
||||
window.setTitle(String.format(title, cardPanels.size()));
|
||||
getWindow().setTitle(String.format(title, cardPanels.size()));
|
||||
|
||||
//if window had cards and now doesn't, hide window
|
||||
//(e.g. cast final card from Flashback zone)
|
||||
if (hadCardPanels && cardPanels.size() == 0) {
|
||||
window.setVisible(false);
|
||||
getWindow().setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doLayout() {
|
||||
if (window.isResizing()) {
|
||||
if (getWindow().isResizing()) {
|
||||
//delay layout slightly to reduce flicker during window resize
|
||||
layoutTimer.restart();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
finishDoLayout();
|
||||
}
|
||||
}
|
||||
|
||||
private final Timer layoutTimer = new Timer(250, new ActionListener() {
|
||||
protected final Timer layoutTimer = new Timer(250, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
layoutTimer.stop();
|
||||
@@ -330,7 +190,7 @@ public class FloatingCardArea extends CardArea {
|
||||
}
|
||||
});
|
||||
|
||||
private void finishDoLayout() {
|
||||
protected void finishDoLayout() {
|
||||
super.doLayout();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,352 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.view.arcane;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.game.card.CardView;
|
||||
import forge.game.player.PlayerView;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.framework.SDisplayUtil;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.screens.match.CMatchUI;
|
||||
import forge.toolbox.FMouseAdapter;
|
||||
import forge.toolbox.FScrollPane;
|
||||
import forge.toolbox.FSkin;
|
||||
import forge.toolbox.MouseTriggerEvent;
|
||||
//import forge.util.collect.FCollectionView;
|
||||
import forge.util.Lang;
|
||||
import forge.view.FDialog;
|
||||
import forge.view.FFrame;
|
||||
|
||||
public class FloatingZone extends CardArea {
|
||||
private static final long serialVersionUID = 1927906492186378596L;
|
||||
|
||||
private static final String COORD_DELIM = ",";
|
||||
|
||||
private static final ForgePreferences prefs = FModel.getPreferences();
|
||||
private static final Map<Integer, FloatingZone> floatingAreas = new HashMap<Integer, FloatingZone>();
|
||||
|
||||
private static int getKey(final PlayerView player, final ZoneType zone) {
|
||||
return 40 * player.getId() + zone.hashCode();
|
||||
}
|
||||
public static void showOrHide(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
|
||||
final FloatingZone cardArea = _init(matchUI, player, zone);
|
||||
cardArea.showOrHideWindow();
|
||||
}
|
||||
public static void show(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
|
||||
final FloatingZone cardArea = _init(matchUI, player, zone);
|
||||
cardArea.showWindow();
|
||||
}
|
||||
public static void hide(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
|
||||
final FloatingZone cardArea = _init(matchUI, player, zone);
|
||||
cardArea.hideWindow();
|
||||
}
|
||||
private static FloatingZone _init(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
|
||||
final int key = getKey(player, zone);
|
||||
FloatingZone cardArea = floatingAreas.get(key);
|
||||
if (cardArea == null || cardArea.getMatchUI() != matchUI) {
|
||||
cardArea = new FloatingZone(matchUI, player, zone);
|
||||
floatingAreas.put(key, cardArea);
|
||||
} else {
|
||||
cardArea.setPlayer(player); //ensure player is updated if needed
|
||||
}
|
||||
return cardArea;
|
||||
}
|
||||
public static CardPanel getCardPanel(final CMatchUI matchUI, final CardView card) {
|
||||
final FloatingZone window = _init(matchUI, card.getController(), card.getZone());
|
||||
return window.getCardPanel(card.getId());
|
||||
}
|
||||
public static void refresh(final PlayerView player, final ZoneType zone) {
|
||||
FloatingZone cardArea = floatingAreas.get(getKey(player, zone));
|
||||
if (cardArea != null) {
|
||||
cardArea.setPlayer(player); //ensure player is updated if needed
|
||||
cardArea.refresh();
|
||||
}
|
||||
|
||||
//refresh flashback zone when graveyard, library, or exile zones updated
|
||||
switch (zone) {
|
||||
case Graveyard:
|
||||
case Library:
|
||||
case Exile:
|
||||
refresh(player, ZoneType.Flashback);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static void closeAll() {
|
||||
for (final FloatingZone cardArea : floatingAreas.values()) {
|
||||
cardArea.window.setVisible(false);
|
||||
}
|
||||
floatingAreas.clear();
|
||||
}
|
||||
|
||||
private final ZoneType zone;
|
||||
private PlayerView player;
|
||||
private String title;
|
||||
private FPref locPref;
|
||||
private boolean hasBeenShown, locLoaded;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private final FDialog window = new FDialog(false, true, "0") {
|
||||
@Override
|
||||
public void setLocationRelativeTo(Component c) {
|
||||
//don't change location this way if dialog has already been shown or location was loaded from preferences
|
||||
if (hasBeenShown || locLoaded) { return; }
|
||||
super.setLocationRelativeTo(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean b0) {
|
||||
if (isVisible() == b0) { return; }
|
||||
if (!b0 && hasBeenShown && locPref != null) {
|
||||
//update preference before hiding window, as otherwise its location will be 0,0
|
||||
prefs.setPref(locPref,
|
||||
getX() + COORD_DELIM + getY() + COORD_DELIM +
|
||||
getWidth() + COORD_DELIM + getHeight());
|
||||
//don't call prefs.save(), instead allowing them to be saved when match ends
|
||||
}
|
||||
super.setVisible(b0);
|
||||
if (b0) {
|
||||
refresh();
|
||||
hasBeenShown = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private FloatingZone(final CMatchUI matchUI, final PlayerView player0, final ZoneType zone0) {
|
||||
super(matchUI, new FScrollPane(false, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
|
||||
window.add(getScrollPane(), "grow, push");
|
||||
getScrollPane().setViewportView(this);
|
||||
setOpaque(false);
|
||||
switch (zone0) {
|
||||
case Exile:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_EXILE));
|
||||
break;
|
||||
case Graveyard:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_GRAVEYARD));
|
||||
break;
|
||||
case Hand:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_HAND));
|
||||
break;
|
||||
case Library:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_LIBRARY));
|
||||
break;
|
||||
case Flashback:
|
||||
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_FLASHBACK));
|
||||
break;
|
||||
default:
|
||||
locPref = null;
|
||||
break;
|
||||
}
|
||||
zone = zone0;
|
||||
setPlayer(player0);
|
||||
setVertical(true);
|
||||
}
|
||||
|
||||
private void setPlayer(PlayerView player0) {
|
||||
if (player == player0) { return; }
|
||||
player = player0;
|
||||
title = Lang.getPossessedObject(player0.getName(), zone.name()) + " (%d)";
|
||||
|
||||
boolean isAi = player0.isAI();
|
||||
switch (zone) {
|
||||
case Exile:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_EXILE : FPref.ZONE_LOC_HUMAN_EXILE;
|
||||
break;
|
||||
case Graveyard:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_GRAVEYARD : FPref.ZONE_LOC_HUMAN_GRAVEYARD;
|
||||
break;
|
||||
case Hand:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_HAND : FPref.ZONE_LOC_HUMAN_HAND;
|
||||
break;
|
||||
case Library:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_LIBRARY : FPref.ZONE_LOC_HUMAN_LIBRARY;
|
||||
break;
|
||||
case Flashback:
|
||||
locPref = isAi ? FPref.ZONE_LOC_AI_FLASHBACK : FPref.ZONE_LOC_HUMAN_FLASHBACK;
|
||||
break;
|
||||
default:
|
||||
locPref = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void showWindow() {
|
||||
onShow();
|
||||
window.setFocusableWindowState(false); // should probably do this earlier
|
||||
window.setVisible(true);
|
||||
}
|
||||
private void hideWindow() {
|
||||
onShow();
|
||||
window.setFocusableWindowState(false); // should probably do this earlier
|
||||
window.setVisible(false);
|
||||
}
|
||||
private void showOrHideWindow() {
|
||||
onShow();
|
||||
window.setFocusableWindowState(false); // should probably do this earlier
|
||||
window.setVisible(!window.isVisible());
|
||||
}
|
||||
private void onShow() {
|
||||
if (!hasBeenShown) {
|
||||
loadLocation();
|
||||
window.getTitleBar().addMouseListener(new FMouseAdapter() {
|
||||
@Override public final void onLeftDoubleClick(final MouseEvent e) {
|
||||
window.setVisible(false); //hide window if titlebar double-clicked
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLocation() {
|
||||
if (locPref != null) {
|
||||
String value = prefs.getPref(locPref);
|
||||
if (value.length() > 0) {
|
||||
String[] coords = value.split(COORD_DELIM);
|
||||
if (coords.length == 4) {
|
||||
try {
|
||||
int x = Integer.parseInt(coords[0]);
|
||||
int y = Integer.parseInt(coords[1]);
|
||||
int w = Integer.parseInt(coords[2]);
|
||||
int h = Integer.parseInt(coords[3]);
|
||||
|
||||
//ensure the window is accessible
|
||||
int centerX = x + w / 2;
|
||||
int centerY = y + h / 2;
|
||||
Rectangle screenBounds = SDisplayUtil.getScreenBoundsForPoint(new Point(centerX, centerY));
|
||||
if (centerX < screenBounds.x) {
|
||||
x = screenBounds.x;
|
||||
}
|
||||
else if (centerX > screenBounds.x + screenBounds.width) {
|
||||
x = screenBounds.x + screenBounds.width - w;
|
||||
if (x < screenBounds.x) {
|
||||
x = screenBounds.x;
|
||||
}
|
||||
}
|
||||
if (centerY < screenBounds.y) {
|
||||
y = screenBounds.y;
|
||||
}
|
||||
else if (centerY > screenBounds.y + screenBounds.height) {
|
||||
y = screenBounds.y + screenBounds.height - h;
|
||||
if (y < screenBounds.y) {
|
||||
y = screenBounds.y;
|
||||
}
|
||||
}
|
||||
window.setBounds(x, y, w, h);
|
||||
locLoaded = true;
|
||||
return;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
prefs.setPref(locPref, ""); //clear value if invalid
|
||||
prefs.save();
|
||||
}
|
||||
}
|
||||
//fallback default size
|
||||
FFrame mainFrame = Singletons.getView().getFrame();
|
||||
window.setSize(mainFrame.getWidth() / 5, mainFrame.getHeight() / 2);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
if (!window.isVisible()) { return; } //don't refresh while window hidden
|
||||
|
||||
List<CardPanel> cardPanels = new ArrayList<CardPanel>();
|
||||
Iterable<CardView> cards = player.getCards(zone);
|
||||
if (cards != null) {
|
||||
for (final CardView card : cards) {
|
||||
CardPanel cardPanel = getCardPanel(card.getId());
|
||||
if (cardPanel == null) {
|
||||
cardPanel = new CardPanel(getMatchUI(), card);
|
||||
cardPanel.setDisplayEnabled(true);
|
||||
}
|
||||
else {
|
||||
cardPanel.setCard(card); //ensure card view updated
|
||||
}
|
||||
cardPanels.add(cardPanel);
|
||||
}
|
||||
}
|
||||
|
||||
boolean hadCardPanels = getCardPanels().size() > 0;
|
||||
setCardPanels(cardPanels);
|
||||
window.setTitle(String.format(title, cardPanels.size()));
|
||||
|
||||
//if window had cards and now doesn't, hide window
|
||||
//(e.g. cast final card from Flashback zone)
|
||||
if (hadCardPanels && cardPanels.size() == 0) {
|
||||
window.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doLayout() {
|
||||
if (window.isResizing()) {
|
||||
//delay layout slightly to reduce flicker during window resize
|
||||
layoutTimer.restart();
|
||||
}
|
||||
else {
|
||||
finishDoLayout();
|
||||
}
|
||||
}
|
||||
|
||||
private final Timer layoutTimer = new Timer(250, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
layoutTimer.stop();
|
||||
finishDoLayout();
|
||||
}
|
||||
});
|
||||
|
||||
private void finishDoLayout() {
|
||||
super.doLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void mouseOver(final CardPanel panel, final MouseEvent evt) {
|
||||
getMatchUI().setCard(panel.getCard(), evt.isShiftDown());
|
||||
super.mouseOver(panel, evt);
|
||||
}
|
||||
@Override
|
||||
public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) {
|
||||
getMatchUI().getGameController().selectCard(panel.getCard(), null, new MouseTriggerEvent(evt));
|
||||
super.mouseLeftClicked(panel, evt);
|
||||
}
|
||||
@Override
|
||||
public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) {
|
||||
getMatchUI().getGameController().selectCard(panel.getCard(), null, new MouseTriggerEvent(evt));
|
||||
super.mouseRightClicked(panel, evt);
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,6 @@ package forge.view.arcane;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -28,51 +26,67 @@ import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.Timer;
|
||||
//import javax.swing.ScrollPaneConstants;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
import forge.gui.framework.SDisplayUtil;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
//import forge.game.card.CardCollection;
|
||||
import forge.screens.match.CMatchUI;
|
||||
import forge.view.arcane.util.CardPanelMouseAdapter;
|
||||
import forge.toolbox.FScrollPane;
|
||||
import forge.toolbox.MouseTriggerEvent;
|
||||
import forge.view.FFrame;
|
||||
//import forge.toolbox.FScrollPane;
|
||||
//import forge.util.collect.FCollectionView;
|
||||
//import forge.toolbox.MouseTriggerEvent;
|
||||
//import forge.view.FFrame;
|
||||
import forge.view.FDialog;
|
||||
|
||||
import forge.toolbox.FButton;
|
||||
|
||||
public class ListCardArea extends CardArea {
|
||||
// Show a list of cards in a new window
|
||||
// Allow moves of the visible cards to top, to bottom, or anywhere
|
||||
// Return a list of cards with the results of the moves
|
||||
// Really should have a difference between visible cards and moveable cards,
|
||||
// but that would require consirable changes to card panels and elsewhere
|
||||
public class ListCardArea extends FloatingCardArea {
|
||||
|
||||
private static final String COORD_DELIM = ",";
|
||||
private static final ForgePreferences prefs = FModel.getPreferences();
|
||||
private static ArrayList<Card> cardList;
|
||||
private static ArrayList<Card> moveableCards;
|
||||
|
||||
public void show() {
|
||||
this.showWindow();
|
||||
}
|
||||
public void hide() {
|
||||
this.hideWindow();
|
||||
}
|
||||
|
||||
private ArrayList<Card> cardList;
|
||||
private ArrayList<Card> moveableCards;
|
||||
private boolean toTop, toBottom, toAnywhere;
|
||||
private String title;
|
||||
private FPref locPref;
|
||||
private boolean hasBeenShown = false, locLoaded;
|
||||
private static ListCardArea storedArea;
|
||||
private static FButton doneButton;
|
||||
private boolean toTop, toBottom, toAnywhere;
|
||||
|
||||
private final FButton doneButton;
|
||||
private ListCardArea(final CMatchUI matchUI) {
|
||||
super(matchUI);
|
||||
window.add(getScrollPane(),"grow, push");
|
||||
getScrollPane().setViewportView(this);
|
||||
setOpaque(false);
|
||||
}
|
||||
|
||||
public static ListCardArea show(final CMatchUI matchUI, final String title0, final List<Card> cardList0, final List<Card> moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) {
|
||||
if (storedArea==null) {
|
||||
storedArea = new ListCardArea(matchUI);
|
||||
doneButton = new FButton("Done");
|
||||
doneButton.addActionListener(new ActionListener() {
|
||||
@Override public void actionPerformed(ActionEvent e) { window.setVisible(false); }
|
||||
});
|
||||
window.add(doneButton,BorderLayout.SOUTH);
|
||||
}
|
||||
cardList = new ArrayList<Card>(cardList0); // this is modified - pfps - is there a better way?
|
||||
moveableCards = new ArrayList<Card>(moveableCards0);
|
||||
storedArea.title = title0;
|
||||
storedArea.toTop = toTop0;
|
||||
storedArea.toBottom = toBottom0;
|
||||
storedArea.toAnywhere = toAnywhere0;
|
||||
storedArea.setDragEnabled(true);
|
||||
storedArea.setVertical(true);
|
||||
storedArea.showWindow();
|
||||
return storedArea;
|
||||
}
|
||||
|
||||
public ListCardArea(final CMatchUI matchUI, final String title0, final List<Card> cardList0, final List<Card> moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) {
|
||||
super(matchUI, new FScrollPane(false, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
|
||||
super(matchUI);
|
||||
window.add(getScrollPane(),"grow, push");
|
||||
try { Thread.sleep(1000); } catch(InterruptedException ex) { }
|
||||
// try { Thread.sleep(1000); } catch(InterruptedException ex) { }
|
||||
getScrollPane().setViewportView(this);
|
||||
setOpaque(false);
|
||||
doneButton = new FButton("Done");
|
||||
@@ -91,39 +105,48 @@ public class ListCardArea extends CardArea {
|
||||
storedArea = this;
|
||||
}
|
||||
|
||||
protected Iterable<CardView> getCards() {
|
||||
ArrayList<CardView> result = new ArrayList<CardView>();
|
||||
for ( Card c : cardList ) {
|
||||
result.add(c.getView());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Card> getCardList() {
|
||||
return cardList;
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
// private SkinnedFrame window = new SkinnedFrame() {
|
||||
private final FDialog window = new FDialog(true, true, "0") {
|
||||
protected static final FDialog window = new FDialog(true, true, "0") {
|
||||
@Override
|
||||
public void setLocationRelativeTo(Component c) {
|
||||
super.setLocationRelativeTo(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean b0) {
|
||||
if (isVisible() == b0) { return; }
|
||||
if (b0) {
|
||||
refresh();
|
||||
storedArea.refresh();
|
||||
}
|
||||
super.setVisible(b0);
|
||||
}
|
||||
};
|
||||
|
||||
private void showWindow() {
|
||||
onShow();
|
||||
window.setFocusableWindowState(true);
|
||||
window.setVisible(true);
|
||||
@Override
|
||||
protected FDialog getWindow() {
|
||||
return window;
|
||||
}
|
||||
private void hideWindow() {
|
||||
onShow();
|
||||
window.setFocusableWindowState(false); // should probably do this earlier
|
||||
window.setVisible(false);
|
||||
|
||||
@Override
|
||||
protected void showWindow() {
|
||||
onShow();
|
||||
getWindow().setFocusableWindowState(true);
|
||||
getWindow().setVisible(true);
|
||||
}
|
||||
private void onShow() {
|
||||
|
||||
@Override
|
||||
protected void onShow() {
|
||||
if (!hasBeenShown) {
|
||||
loadLocation();
|
||||
this.addCardPanelMouseListener(new CardPanelMouseAdapter() {
|
||||
@@ -193,83 +216,9 @@ public class ListCardArea extends CardArea {
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void loadLocation() {
|
||||
if (locPref != null) {
|
||||
String value = prefs.getPref(locPref);
|
||||
if (value.length() > 0) {
|
||||
String[] coords = value.split(COORD_DELIM);
|
||||
if (coords.length == 4) {
|
||||
try {
|
||||
int x = Integer.parseInt(coords[0]);
|
||||
int y = Integer.parseInt(coords[1]);
|
||||
int w = Integer.parseInt(coords[2]);
|
||||
int h = Integer.parseInt(coords[3]);
|
||||
|
||||
//ensure the window is accessible
|
||||
int centerX = x + w / 2;
|
||||
int centerY = y + h / 2;
|
||||
Rectangle screenBounds = SDisplayUtil.getScreenBoundsForPoint(new Point(centerX, centerY));
|
||||
if (centerX < screenBounds.x) {
|
||||
x = screenBounds.x;
|
||||
}
|
||||
else if (centerX > screenBounds.x + screenBounds.width) {
|
||||
x = screenBounds.x + screenBounds.width - w;
|
||||
if (x < screenBounds.x) {
|
||||
x = screenBounds.x;
|
||||
}
|
||||
}
|
||||
if (centerY < screenBounds.y) {
|
||||
y = screenBounds.y;
|
||||
}
|
||||
else if (centerY > screenBounds.y + screenBounds.height) {
|
||||
y = screenBounds.y + screenBounds.height - h;
|
||||
if (y < screenBounds.y) {
|
||||
y = screenBounds.y;
|
||||
}
|
||||
}
|
||||
window.setBounds(x, y, w, h);
|
||||
locLoaded = true;
|
||||
return;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
prefs.setPref(locPref, ""); //clear value if invalid
|
||||
prefs.save();
|
||||
}
|
||||
}
|
||||
//fallback default size
|
||||
FFrame mainFrame = Singletons.getView().getFrame();
|
||||
window.setSize(mainFrame.getWidth() / 5, mainFrame.getHeight() / 2);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
List<CardPanel> cardPanels = new ArrayList<CardPanel>();
|
||||
// FCollectionView<Card> cards = new FCollection<Card>(cardList);
|
||||
if (cardList != null) {
|
||||
for (final Card card : cardList) {
|
||||
CardPanel cardPanel = getCardPanel(card.getId());
|
||||
if (cardPanel == null) {
|
||||
cardPanel = new CardPanel(getMatchUI(), card.getView());
|
||||
cardPanel.setDisplayEnabled(true);
|
||||
}
|
||||
else {
|
||||
cardPanel.setCard(card.getView()); //ensure card view updated
|
||||
}
|
||||
cardPanels.add(cardPanel);
|
||||
}
|
||||
}
|
||||
|
||||
boolean hadCardPanels = getCardPanels().size() > 0;
|
||||
setCardPanels(cardPanels);
|
||||
window.setTitle(String.format(title, cardPanels.size()));
|
||||
|
||||
//if window had cards and now doesn't, hide window
|
||||
//(e.g. cast final card from Flashback zone)
|
||||
if (hadCardPanels && cardPanels.size() == 0) {
|
||||
window.setVisible(false);
|
||||
}
|
||||
@Override
|
||||
protected void refresh() {
|
||||
doRefresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -283,32 +232,4 @@ public class ListCardArea extends CardArea {
|
||||
//}
|
||||
}
|
||||
|
||||
private final Timer layoutTimer = new Timer(250, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
layoutTimer.stop();
|
||||
finishDoLayout();
|
||||
}
|
||||
});
|
||||
|
||||
private void finishDoLayout() {
|
||||
super.doLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void mouseOver(final CardPanel panel, final MouseEvent evt) {
|
||||
getMatchUI().setCard(panel.getCard(), evt.isShiftDown());
|
||||
super.mouseOver(panel, evt);
|
||||
}
|
||||
@Override
|
||||
public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) {
|
||||
getMatchUI().getGameController().selectCard(panel.getCard(), null, new MouseTriggerEvent(evt));
|
||||
super.mouseLeftClicked(panel, evt);
|
||||
}
|
||||
@Override
|
||||
public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) {
|
||||
getMatchUI().getGameController().selectCard(panel.getCard(), null, new MouseTriggerEvent(evt));
|
||||
super.mouseRightClicked(panel, evt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user