mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48: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) {
|
||||
removeCardPanel(fromPanel,true);
|
||||
}
|
||||
|
||||
public final void removeCardPanel(final CardPanel fromPanel, final boolean repaint) {
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
if (getMouseDragPanel() != null) {
|
||||
CardPanel.getDragAnimationPanel().setVisible(false);
|
||||
@@ -303,9 +307,11 @@ public abstract class CardPanelContainer extends SkinnedPanel {
|
||||
fromPanel.dispose();
|
||||
getCardPanels().remove(fromPanel);
|
||||
remove(fromPanel);
|
||||
invalidate();
|
||||
repaint();
|
||||
doingLayout();
|
||||
if ( repaint ) {
|
||||
invalidate();
|
||||
repaint();
|
||||
doingLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public final void setCardPanels(final List<CardPanel> cardPanels) {
|
||||
@@ -325,23 +331,28 @@ public abstract class CardPanelContainer extends SkinnedPanel {
|
||||
for (final CardPanel cardPanel : cardPanels) {
|
||||
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.getParent().validate();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
clear(true);
|
||||
}
|
||||
public final void clear(final boolean repaint) {
|
||||
FThreads.assertExecutedByEdt(true);
|
||||
for (final CardPanel p : getCardPanels()) {
|
||||
p.dispose();
|
||||
}
|
||||
getCardPanels().clear();
|
||||
removeAll();
|
||||
setPreferredSize(new Dimension(0, 0));
|
||||
invalidate();
|
||||
getParent().validate();
|
||||
repaint();
|
||||
if ( repaint ) {
|
||||
setPreferredSize(new Dimension(0, 0));
|
||||
invalidate();
|
||||
getParent().validate();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public final FScrollPane getScrollPane() {
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.view.arcane;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -52,7 +53,6 @@ public abstract class FloatingCardArea extends CardArea {
|
||||
protected FPref locPref;
|
||||
protected boolean hasBeenShown, locLoaded;
|
||||
|
||||
protected abstract FDialog getWindow();
|
||||
protected abstract Iterable<CardView> getCards();
|
||||
|
||||
protected FloatingCardArea(final CMatchUI matchUI) {
|
||||
@@ -71,11 +71,14 @@ public abstract class FloatingCardArea extends CardArea {
|
||||
onShow();
|
||||
getWindow().setFocusableWindowState(false); // should probably do this earlier
|
||||
getWindow().setVisible(false);
|
||||
getWindow().dispose(); //pfps so that old content does not show up
|
||||
}
|
||||
protected void showOrHideWindow() {
|
||||
onShow();
|
||||
getWindow().setFocusableWindowState(false); // should probably do this earlier
|
||||
getWindow().setVisible(!getWindow().isVisible());
|
||||
if (getWindow().isVisible()) {
|
||||
hideWindow();
|
||||
} else {
|
||||
showWindow();
|
||||
}
|
||||
}
|
||||
protected void onShow() {
|
||||
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() {
|
||||
if (locPref != null) {
|
||||
String value = prefs.getPref(locPref);
|
||||
@@ -165,11 +197,12 @@ public abstract class FloatingCardArea extends CardArea {
|
||||
setCardPanels(cardPanels);
|
||||
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) {
|
||||
getWindow().setVisible(false);
|
||||
}
|
||||
//pfps - rather suspect, so commented out for now
|
||||
// //if window had cards and now doesn't, hide window
|
||||
// //(e.g. cast final card from Flashback zone)
|
||||
// if (hadCardPanels && cardPanels.size() == 0) {
|
||||
// getWindow().setVisible(false);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
*/
|
||||
package forge.view.arcane;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.game.card.CardView;
|
||||
@@ -31,9 +31,7 @@ import forge.properties.ForgePreferences.FPref;
|
||||
import forge.screens.match.CMatchUI;
|
||||
import forge.toolbox.FScrollPane;
|
||||
import forge.toolbox.FSkin;
|
||||
//import forge.util.collect.FCollectionView;
|
||||
import forge.util.Lang;
|
||||
import forge.view.FDialog;
|
||||
|
||||
public class FloatingZone extends FloatingCardArea {
|
||||
private static final long serialVersionUID = 1927906492186378596L;
|
||||
@@ -103,36 +101,6 @@ public class FloatingZone extends FloatingCardArea {
|
||||
private final ZoneType zone;
|
||||
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() {
|
||||
return player.getCards(zone);
|
||||
}
|
||||
@@ -140,6 +108,7 @@ public class FloatingZone extends FloatingCardArea {
|
||||
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");
|
||||
window.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); //pfps so that old content does not reappear?
|
||||
getScrollPane().setViewportView(this);
|
||||
setOpaque(false);
|
||||
switch (zone0) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package forge.view.arcane;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -29,7 +28,6 @@ import java.util.List;
|
||||
import forge.game.card.CardView;
|
||||
import forge.screens.match.CMatchUI;
|
||||
import forge.view.arcane.util.CardPanelMouseAdapter;
|
||||
import forge.view.FDialog;
|
||||
|
||||
import forge.toolbox.FButton;
|
||||
|
||||
@@ -50,6 +48,7 @@ public class ListCardArea extends FloatingCardArea {
|
||||
private ListCardArea(final CMatchUI matchUI) {
|
||||
super(matchUI);
|
||||
window.add(getScrollPane(),"grow, push");
|
||||
window.setModal(true);
|
||||
getScrollPane().setViewportView(this);
|
||||
doneButton = new FButton("Done");
|
||||
doneButton.addActionListener(new ActionListener() {
|
||||
@@ -77,7 +76,6 @@ public class ListCardArea extends FloatingCardArea {
|
||||
storedArea.toAnywhere = toAnywhere0;
|
||||
storedArea.setDragEnabled(true);
|
||||
storedArea.setVertical(true);
|
||||
storedArea.doRefresh();
|
||||
storedArea.showWindow();
|
||||
return storedArea;
|
||||
}
|
||||
@@ -107,36 +105,6 @@ public class ListCardArea extends FloatingCardArea {
|
||||
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
|
||||
protected void showWindow() {
|
||||
onShow();
|
||||
@@ -146,8 +114,8 @@ public class ListCardArea extends FloatingCardArea {
|
||||
|
||||
@Override
|
||||
protected void onShow() {
|
||||
super.onShow();
|
||||
if (!hasBeenShown) {
|
||||
loadLocation();
|
||||
this.addCardPanelMouseListener(new CardPanelMouseAdapter() {
|
||||
@Override
|
||||
public void mouseDragEnd(final CardPanel dragPanel, final MouseEvent evt) {
|
||||
@@ -208,22 +176,6 @@ public class ListCardArea extends FloatingCardArea {
|
||||
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
|
||||
@Override
|
||||
public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) {
|
||||
|
||||
@@ -620,11 +620,11 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
toDelete.removeAll(notToDelete);
|
||||
|
||||
if (toDelete.size() == getCardPanels().size()) {
|
||||
clear();
|
||||
clear(false);
|
||||
}
|
||||
else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (needLayoutRefresh) {
|
||||
doLayout();
|
||||
}
|
||||
if (needLayoutRefresh) {
|
||||
doLayout();
|
||||
}
|
||||
|
||||
invalidate(); //pfps do the extra invalidate before any scrolling
|
||||
if (!newPanels.isEmpty()) {
|
||||
int i = newPanels.size();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
invalidate();
|
||||
repaint();
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
public boolean updateCard(final CardView card, boolean fromRefresh) {
|
||||
|
||||
@@ -332,8 +332,12 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
|
||||
@Override
|
||||
public Void visit(final GameEventCardChangeZone event) {
|
||||
updateZone(event.from);
|
||||
return updateZone(event.to);
|
||||
//pfps the change to the zones have already been performed with add and remove calls
|
||||
// this is only for playing a sound
|
||||
// updateZone(event.from);
|
||||
//return updateZone(event.to);
|
||||
return processEvent();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -355,7 +359,10 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user