mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Merge branch 'optimize' into 'master'
optimize redisplay of floating card areas See merge request core-developers/forge!1337
This commit is contained in:
@@ -291,6 +291,10 @@ public abstract class CardPanelContainer extends SkinnedPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void removeCardPanel(final CardPanel fromPanel) {
|
public final void removeCardPanel(final CardPanel fromPanel) {
|
||||||
|
removeCardPanel(fromPanel,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void removeCardPanel(final CardPanel fromPanel, final boolean repaint) {
|
||||||
FThreads.assertExecutedByEdt(true);
|
FThreads.assertExecutedByEdt(true);
|
||||||
if (getMouseDragPanel() != null) {
|
if (getMouseDragPanel() != null) {
|
||||||
CardPanel.getDragAnimationPanel().setVisible(false);
|
CardPanel.getDragAnimationPanel().setVisible(false);
|
||||||
@@ -303,9 +307,11 @@ public abstract class CardPanelContainer extends SkinnedPanel {
|
|||||||
fromPanel.dispose();
|
fromPanel.dispose();
|
||||||
getCardPanels().remove(fromPanel);
|
getCardPanels().remove(fromPanel);
|
||||||
remove(fromPanel);
|
remove(fromPanel);
|
||||||
invalidate();
|
if ( repaint ) {
|
||||||
repaint();
|
invalidate();
|
||||||
doingLayout();
|
repaint();
|
||||||
|
doingLayout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setCardPanels(final List<CardPanel> cardPanels) {
|
public final void setCardPanels(final List<CardPanel> cardPanels) {
|
||||||
@@ -325,23 +331,28 @@ public abstract class CardPanelContainer extends SkinnedPanel {
|
|||||||
for (final CardPanel cardPanel : cardPanels) {
|
for (final CardPanel cardPanel : cardPanels) {
|
||||||
this.add(cardPanel);
|
this.add(cardPanel);
|
||||||
}
|
}
|
||||||
this.doLayout();
|
//pfps the validate just below will do the layout, so don't do it here this.doLayout();
|
||||||
this.invalidate();
|
this.invalidate();
|
||||||
this.getParent().validate();
|
this.getParent().validate();
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void clear() {
|
public final void clear() {
|
||||||
|
clear(true);
|
||||||
|
}
|
||||||
|
public final void clear(final boolean repaint) {
|
||||||
FThreads.assertExecutedByEdt(true);
|
FThreads.assertExecutedByEdt(true);
|
||||||
for (final CardPanel p : getCardPanels()) {
|
for (final CardPanel p : getCardPanels()) {
|
||||||
p.dispose();
|
p.dispose();
|
||||||
}
|
}
|
||||||
getCardPanels().clear();
|
getCardPanels().clear();
|
||||||
removeAll();
|
removeAll();
|
||||||
setPreferredSize(new Dimension(0, 0));
|
if ( repaint ) {
|
||||||
invalidate();
|
setPreferredSize(new Dimension(0, 0));
|
||||||
getParent().validate();
|
invalidate();
|
||||||
repaint();
|
getParent().validate();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final FScrollPane getScrollPane() {
|
public final FScrollPane getScrollPane() {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package forge.view.arcane;
|
|||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@@ -52,7 +53,6 @@ public abstract class FloatingCardArea extends CardArea {
|
|||||||
protected FPref locPref;
|
protected FPref locPref;
|
||||||
protected boolean hasBeenShown, locLoaded;
|
protected boolean hasBeenShown, locLoaded;
|
||||||
|
|
||||||
protected abstract FDialog getWindow();
|
|
||||||
protected abstract Iterable<CardView> getCards();
|
protected abstract Iterable<CardView> getCards();
|
||||||
|
|
||||||
protected FloatingCardArea(final CMatchUI matchUI) {
|
protected FloatingCardArea(final CMatchUI matchUI) {
|
||||||
@@ -71,11 +71,14 @@ public abstract class FloatingCardArea extends CardArea {
|
|||||||
onShow();
|
onShow();
|
||||||
getWindow().setFocusableWindowState(false); // should probably do this earlier
|
getWindow().setFocusableWindowState(false); // should probably do this earlier
|
||||||
getWindow().setVisible(false);
|
getWindow().setVisible(false);
|
||||||
|
getWindow().dispose(); //pfps so that old content does not show up
|
||||||
}
|
}
|
||||||
protected void showOrHideWindow() {
|
protected void showOrHideWindow() {
|
||||||
onShow();
|
if (getWindow().isVisible()) {
|
||||||
getWindow().setFocusableWindowState(false); // should probably do this earlier
|
hideWindow();
|
||||||
getWindow().setVisible(!getWindow().isVisible());
|
} else {
|
||||||
|
showWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
protected void onShow() {
|
protected void onShow() {
|
||||||
if (!hasBeenShown) {
|
if (!hasBeenShown) {
|
||||||
@@ -88,6 +91,35 @@ public abstract class FloatingCardArea extends CardArea {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
protected final FDialog window = new FDialog(false, true, "0") {
|
||||||
|
@Override
|
||||||
|
public void setLocationRelativeTo(Component c) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if (b0) {
|
||||||
|
doRefresh(); // force a refresh before showing to pick up any changes when hidden
|
||||||
|
hasBeenShown = true;
|
||||||
|
}
|
||||||
|
super.setVisible(b0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
protected FDialog getWindow() {
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
protected void loadLocation() {
|
protected void loadLocation() {
|
||||||
if (locPref != null) {
|
if (locPref != null) {
|
||||||
String value = prefs.getPref(locPref);
|
String value = prefs.getPref(locPref);
|
||||||
@@ -165,11 +197,12 @@ public abstract class FloatingCardArea extends CardArea {
|
|||||||
setCardPanels(cardPanels);
|
setCardPanels(cardPanels);
|
||||||
getWindow().setTitle(String.format(title, cardPanels.size()));
|
getWindow().setTitle(String.format(title, cardPanels.size()));
|
||||||
|
|
||||||
//if window had cards and now doesn't, hide window
|
//pfps - rather suspect, so commented out for now
|
||||||
//(e.g. cast final card from Flashback zone)
|
// //if window had cards and now doesn't, hide window
|
||||||
if (hadCardPanels && cardPanels.size() == 0) {
|
// //(e.g. cast final card from Flashback zone)
|
||||||
getWindow().setVisible(false);
|
// if (hadCardPanels && cardPanels.size() == 0) {
|
||||||
}
|
// getWindow().setVisible(false);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,11 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package forge.view.arcane;
|
package forge.view.arcane;
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
|
import javax.swing.WindowConstants;
|
||||||
|
|
||||||
import forge.assets.FSkinProp;
|
import forge.assets.FSkinProp;
|
||||||
import forge.game.card.CardView;
|
import forge.game.card.CardView;
|
||||||
@@ -31,9 +31,7 @@ import forge.properties.ForgePreferences.FPref;
|
|||||||
import forge.screens.match.CMatchUI;
|
import forge.screens.match.CMatchUI;
|
||||||
import forge.toolbox.FScrollPane;
|
import forge.toolbox.FScrollPane;
|
||||||
import forge.toolbox.FSkin;
|
import forge.toolbox.FSkin;
|
||||||
//import forge.util.collect.FCollectionView;
|
|
||||||
import forge.util.Lang;
|
import forge.util.Lang;
|
||||||
import forge.view.FDialog;
|
|
||||||
|
|
||||||
public class FloatingZone extends FloatingCardArea {
|
public class FloatingZone extends FloatingCardArea {
|
||||||
private static final long serialVersionUID = 1927906492186378596L;
|
private static final long serialVersionUID = 1927906492186378596L;
|
||||||
@@ -103,36 +101,6 @@ public class FloatingZone extends FloatingCardArea {
|
|||||||
private final ZoneType zone;
|
private final ZoneType zone;
|
||||||
private PlayerView player;
|
private PlayerView player;
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
protected FDialog getWindow() {
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
protected Iterable<CardView> getCards() {
|
protected Iterable<CardView> getCards() {
|
||||||
return player.getCards(zone);
|
return player.getCards(zone);
|
||||||
}
|
}
|
||||||
@@ -140,6 +108,7 @@ public class FloatingZone extends FloatingCardArea {
|
|||||||
private FloatingZone(final CMatchUI matchUI, final PlayerView player0, final ZoneType zone0) {
|
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));
|
super(matchUI, new FScrollPane(false, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
|
||||||
window.add(getScrollPane(), "grow, push");
|
window.add(getScrollPane(), "grow, push");
|
||||||
|
window.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); //pfps so that old content does not reappear?
|
||||||
getScrollPane().setViewportView(this);
|
getScrollPane().setViewportView(this);
|
||||||
setOpaque(false);
|
setOpaque(false);
|
||||||
switch (zone0) {
|
switch (zone0) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package forge.view.arcane;
|
package forge.view.arcane;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
@@ -29,7 +28,6 @@ import java.util.List;
|
|||||||
import forge.game.card.CardView;
|
import forge.game.card.CardView;
|
||||||
import forge.screens.match.CMatchUI;
|
import forge.screens.match.CMatchUI;
|
||||||
import forge.view.arcane.util.CardPanelMouseAdapter;
|
import forge.view.arcane.util.CardPanelMouseAdapter;
|
||||||
import forge.view.FDialog;
|
|
||||||
|
|
||||||
import forge.toolbox.FButton;
|
import forge.toolbox.FButton;
|
||||||
|
|
||||||
@@ -50,6 +48,7 @@ public class ListCardArea extends FloatingCardArea {
|
|||||||
private ListCardArea(final CMatchUI matchUI) {
|
private ListCardArea(final CMatchUI matchUI) {
|
||||||
super(matchUI);
|
super(matchUI);
|
||||||
window.add(getScrollPane(),"grow, push");
|
window.add(getScrollPane(),"grow, push");
|
||||||
|
window.setModal(true);
|
||||||
getScrollPane().setViewportView(this);
|
getScrollPane().setViewportView(this);
|
||||||
doneButton = new FButton("Done");
|
doneButton = new FButton("Done");
|
||||||
doneButton.addActionListener(new ActionListener() {
|
doneButton.addActionListener(new ActionListener() {
|
||||||
@@ -77,7 +76,6 @@ public class ListCardArea extends FloatingCardArea {
|
|||||||
storedArea.toAnywhere = toAnywhere0;
|
storedArea.toAnywhere = toAnywhere0;
|
||||||
storedArea.setDragEnabled(true);
|
storedArea.setDragEnabled(true);
|
||||||
storedArea.setVertical(true);
|
storedArea.setVertical(true);
|
||||||
storedArea.doRefresh();
|
|
||||||
storedArea.showWindow();
|
storedArea.showWindow();
|
||||||
return storedArea;
|
return storedArea;
|
||||||
}
|
}
|
||||||
@@ -107,36 +105,6 @@ public class ListCardArea extends FloatingCardArea {
|
|||||||
return cardList;
|
return cardList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
protected final FDialog window = new FDialog(true, true, "0") {
|
|
||||||
@Override
|
|
||||||
public void setLocationRelativeTo(Component c) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected FDialog getWindow() {
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void showWindow() {
|
protected void showWindow() {
|
||||||
onShow();
|
onShow();
|
||||||
@@ -146,8 +114,8 @@ public class ListCardArea extends FloatingCardArea {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onShow() {
|
protected void onShow() {
|
||||||
|
super.onShow();
|
||||||
if (!hasBeenShown) {
|
if (!hasBeenShown) {
|
||||||
loadLocation();
|
|
||||||
this.addCardPanelMouseListener(new CardPanelMouseAdapter() {
|
this.addCardPanelMouseListener(new CardPanelMouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragEnd(final CardPanel dragPanel, final MouseEvent evt) {
|
public void mouseDragEnd(final CardPanel dragPanel, final MouseEvent evt) {
|
||||||
@@ -208,22 +176,6 @@ public class ListCardArea extends FloatingCardArea {
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// protected void refresh() {
|
|
||||||
// doRefresh();
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doLayout() {
|
|
||||||
// if (window.isResizing()) {
|
|
||||||
// //delay layout slightly to reduce flicker during window resize
|
|
||||||
// layoutTimer.restart();
|
|
||||||
// }
|
|
||||||
//else {
|
|
||||||
finishDoLayout();
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
// move to beginning of list if allowable else to beginning of bottom if allowable
|
// move to beginning of list if allowable else to beginning of bottom if allowable
|
||||||
@Override
|
@Override
|
||||||
public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) {
|
public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) {
|
||||||
|
|||||||
@@ -620,11 +620,11 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
|||||||
toDelete.removeAll(notToDelete);
|
toDelete.removeAll(notToDelete);
|
||||||
|
|
||||||
if (toDelete.size() == getCardPanels().size()) {
|
if (toDelete.size() == getCardPanels().size()) {
|
||||||
clear();
|
clear(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (final CardView card : toDelete) {
|
for (final CardView card : toDelete) {
|
||||||
removeCardPanel(getCardPanel(card.getId()));
|
removeCardPanel(getCardPanel(card.getId()),false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,19 +646,21 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
|||||||
needLayoutRefresh = true;
|
needLayoutRefresh = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (needLayoutRefresh) {
|
if (needLayoutRefresh) {
|
||||||
doLayout();
|
doLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
invalidate(); //pfps do the extra invalidate before any scrolling
|
||||||
if (!newPanels.isEmpty()) {
|
if (!newPanels.isEmpty()) {
|
||||||
|
int i = newPanels.size();
|
||||||
for (final CardPanel toPanel : newPanels) {
|
for (final CardPanel toPanel : newPanels) {
|
||||||
scrollRectToVisible(new Rectangle(toPanel.getCardX(), toPanel.getCardY(), toPanel.getCardWidth(), toPanel.getCardHeight()));
|
if ( --i == 0 ) { // only scroll to last panel to be added
|
||||||
|
scrollRectToVisible(new Rectangle(toPanel.getCardX(), toPanel.getCardY(), toPanel.getCardWidth(), toPanel.getCardHeight()));
|
||||||
|
}
|
||||||
Animation.moveCard(toPanel);
|
Animation.moveCard(toPanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
repaint();
|
||||||
invalidate();
|
|
||||||
repaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateCard(final CardView card, boolean fromRefresh) {
|
public boolean updateCard(final CardView card, boolean fromRefresh) {
|
||||||
|
|||||||
@@ -332,8 +332,12 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(final GameEventCardChangeZone event) {
|
public Void visit(final GameEventCardChangeZone event) {
|
||||||
updateZone(event.from);
|
//pfps the change to the zones have already been performed with add and remove calls
|
||||||
return updateZone(event.to);
|
// this is only for playing a sound
|
||||||
|
// updateZone(event.from);
|
||||||
|
//return updateZone(event.to);
|
||||||
|
return processEvent();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -355,7 +359,10 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visit(final GameEventShuffle event) {
|
public Void visit(final GameEventShuffle event) {
|
||||||
return updateZone(event.player.getZone(ZoneType.Library));
|
//pfps the change to the library has already been performed by a setCards call
|
||||||
|
// this is only for playing a sound
|
||||||
|
// return updateZone(event.player.getZone(ZoneType.Library));
|
||||||
|
return processEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user