forked from External/mage
Moved card layout strategy to separate class
This commit is contained in:
parent
0e71ac5e53
commit
ca49dc7a31
4 changed files with 119 additions and 76 deletions
|
|
@ -0,0 +1,13 @@
|
|||
package mage.client.util.layout;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Interface for operations that modify cards' layout
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public interface CardLayoutStrategy {
|
||||
|
||||
void doLayout(JLayeredPane jLayeredPane, int width);
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package mage.client.util.layout.impl;
|
||||
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.client.game.BattlefieldPanel;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.layout.CardLayoutStrategy;
|
||||
import mage.view.PermanentView;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Card layout for client version 1.3.0 and earlier.
|
||||
*
|
||||
* Save it here for a while.
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public class OldCardLayoutStrategy implements CardLayoutStrategy {
|
||||
|
||||
@Override
|
||||
public void doLayout(JLayeredPane jLayeredPane, int width) {
|
||||
Map<UUID, MagePermanent> permanents = ((BattlefieldPanel)jLayeredPane).getPermanents();
|
||||
JLayeredPane jPanel = ((BattlefieldPanel)jLayeredPane).getMainPanel();
|
||||
|
||||
int height = Plugins.getInstance().sortPermanents(((BattlefieldPanel)jLayeredPane).getUiComponentsList(), permanents.values());
|
||||
jPanel.setPreferredSize(new Dimension(width - 30, height));
|
||||
|
||||
for (PermanentView permanent: ((BattlefieldPanel)jLayeredPane).getBattlefield().values()) {
|
||||
if (permanent.getAttachments() != null) {
|
||||
groupAttachments(jLayeredPane, jPanel, permanents, permanent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void groupAttachments(JLayeredPane jLayeredPane, JLayeredPane jPanel, Map<UUID, MagePermanent> permanents, PermanentView permanent) {
|
||||
MagePermanent perm = permanents.get(permanent.getId());
|
||||
if (perm == null) {
|
||||
return;
|
||||
}
|
||||
int position = jLayeredPane.getPosition(perm);
|
||||
perm.getLinks().clear();
|
||||
Rectangle r = perm.getBounds();
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||
for (UUID attachmentId: permanent.getAttachments()) {
|
||||
MagePermanent link = permanents.get(attachmentId);
|
||||
if (link != null) {
|
||||
perm.getLinks().add(link);
|
||||
r.translate(20, 20);
|
||||
link.setBounds(r);
|
||||
jLayeredPane.setPosition(link, ++position);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int index = permanent.getAttachments().size();
|
||||
for (UUID attachmentId: permanent.getAttachments()) {
|
||||
MagePermanent link = permanents.get(attachmentId);
|
||||
if (link != null) {
|
||||
link.setBounds(r);
|
||||
perm.getLinks().add(link);
|
||||
r.translate(8, 10);
|
||||
perm.setBounds(r);
|
||||
jLayeredPane.moveToFront(link);
|
||||
jLayeredPane.moveToFront(perm);
|
||||
jPanel.setComponentZOrder(link, index);
|
||||
index--;
|
||||
}
|
||||
}
|
||||
jPanel.setComponentZOrder(perm, index);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue