forked from External/mage
refactor: moved draft grid component to correct package, improved netbeans editor compatibility
This commit is contained in:
parent
0dbd86fb58
commit
df26ab5156
4 changed files with 23 additions and 16 deletions
29
Mage.Client/src/main/java/mage/client/draft/DraftGrid.form
Normal file
29
Mage.Client/src/main/java/mage/client/draft/DraftGrid.form
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Form>
|
||||
197
Mage.Client/src/main/java/mage/client/draft/DraftGrid.java
Normal file
197
Mage.Client/src/main/java/mage/client/draft/DraftGrid.java
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
package mage.client.draft;
|
||||
|
||||
import mage.abilities.icon.CardIconRenderSettings;
|
||||
import mage.cards.CardDimensions;
|
||||
import mage.cards.MageCard;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.ClientEventType;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.Listener;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.comparators.CardViewRarityComparator;
|
||||
import mage.constants.Constants;
|
||||
import mage.view.CardView;
|
||||
import mage.view.CardsView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.CardEventProducer;
|
||||
import mage.client.cards.CardEventSource;
|
||||
|
||||
/**
|
||||
* Drafting: panel with the picks
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com, JayDi85
|
||||
*/
|
||||
public class DraftGrid extends javax.swing.JPanel implements CardEventProducer {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DraftGrid.class);
|
||||
|
||||
private DraftPanel parentPanel;
|
||||
|
||||
protected final CardEventSource cardEventSource = new CardEventSource();
|
||||
protected BigCard bigCard;
|
||||
protected MageCard markedCard;
|
||||
protected boolean emptyGrid;
|
||||
|
||||
public DraftGrid() {
|
||||
initComponents();
|
||||
markedCard = null;
|
||||
emptyGrid = true;
|
||||
|
||||
// ENABLE picks and other actions
|
||||
cardEventSource.addListener(event -> {
|
||||
if (this.parentPanel == null) {
|
||||
this.parentPanel = (DraftPanel) this.getParent();
|
||||
}
|
||||
|
||||
if (event.getEventType() == ClientEventType.CARD_DOUBLE_CLICK
|
||||
|| event.getEventType() == ClientEventType.CARD_CLICK) {
|
||||
// There is a protection against picking too early in DraftPanel logic.
|
||||
// So, when double clicking early, we do mark the card as selected like
|
||||
// a single click would.
|
||||
|
||||
CardView card = (CardView) event.getSource();
|
||||
if(event.getEventType() == ClientEventType.CARD_DOUBLE_CLICK
|
||||
&& parentPanel.isAllowedToPick()
|
||||
) {
|
||||
cardEventSource.fireEvent(card, ClientEventType.DRAFT_PICK_CARD);
|
||||
hidePopup();
|
||||
AudioManager.playOnDraftSelect();
|
||||
} else {
|
||||
MageCard cardPanel = (MageCard) event.getComponent();
|
||||
if (markedCard != null) {
|
||||
markedCard.setSelected(false);
|
||||
}
|
||||
cardEventSource.fireEvent(card, ClientEventType.DRAFT_MARK_CARD);
|
||||
markedCard = cardPanel;
|
||||
markedCard.setSelected(true);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
markedCard = null;
|
||||
for (Component comp : getComponents()) {
|
||||
if (comp instanceof MageCard) {
|
||||
this.remove(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadBooster(CardsView booster, BigCard bigCard) {
|
||||
if (booster != null && booster.isEmpty()) {
|
||||
emptyGrid = true;
|
||||
} else {
|
||||
if (!emptyGrid) {
|
||||
AudioManager.playOnDraftSelect();
|
||||
}
|
||||
emptyGrid = false;
|
||||
}
|
||||
this.bigCard = bigCard;
|
||||
this.removeAll();
|
||||
|
||||
if (booster == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int maxRows = 4;
|
||||
|
||||
int numColumns = 5;
|
||||
int curColumn = 0;
|
||||
int curRow = 0;
|
||||
int offsetX = 5;
|
||||
int offsetY = 3;
|
||||
|
||||
CardDimensions cardDimension = null;
|
||||
int maxCards;
|
||||
double scale;
|
||||
|
||||
for (int i = 1; i < maxRows; i++) {
|
||||
scale = (double) (this.getHeight() / i) / Constants.FRAME_MAX_HEIGHT;
|
||||
cardDimension = new CardDimensions(scale);
|
||||
maxCards = this.getWidth() / (cardDimension.getFrameWidth() + offsetX);
|
||||
if ((maxCards * i) >= booster.size()) {
|
||||
numColumns = booster.size() / i;
|
||||
if (booster.size() % i > 0) {
|
||||
numColumns++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cardDimension != null) {
|
||||
Rectangle rectangle = new Rectangle(cardDimension.getFrameWidth(), cardDimension.getFrameHeight());
|
||||
Dimension dimension = new Dimension(cardDimension.getFrameWidth(), cardDimension.getFrameHeight());
|
||||
|
||||
List<CardView> sortedCards = new ArrayList<>(booster.values());
|
||||
sortedCards.sort(new CardViewRarityComparator());
|
||||
for (CardView card : sortedCards) {
|
||||
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), dimension, null, true, true, PreferencesDialog.getRenderMode(), true);
|
||||
cardImg.setCardContainerRef(this);
|
||||
cardImg.update(card);
|
||||
this.add(cardImg);
|
||||
|
||||
rectangle.setLocation(curColumn * (cardDimension.getFrameWidth() + offsetX) + offsetX, curRow * (rectangle.height + offsetY) + offsetY);
|
||||
cardImg.setCardBounds(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
||||
curColumn++;
|
||||
if (curColumn == numColumns) {
|
||||
curColumn = 0;
|
||||
curRow++;
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
} else {
|
||||
logger.warn("Draft Grid - no possible fit of cards");
|
||||
}
|
||||
}
|
||||
|
||||
public void addCardEventListener(Listener<Event> listener) {
|
||||
cardEventSource.addListener(listener);
|
||||
}
|
||||
|
||||
private void hidePopup() {
|
||||
Plugins.instance.getActionCallback().mouseExited(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 400, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
@Override
|
||||
public CardEventSource getCardEventSource() {
|
||||
return cardEventSource;
|
||||
}
|
||||
|
||||
public boolean isEmptyGrid() {
|
||||
return emptyGrid;
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
|
|
@ -527,7 +527,7 @@
|
|||
</Container>
|
||||
<Component class="mage.client.cards.CardsList" name="draftPicks">
|
||||
</Component>
|
||||
<Container class="mage.client.cards.DraftGrid" name="draftBooster">
|
||||
<Container class="mage.client.draft.DraftGrid" name="draftBooster">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
|
||||
|
|
@ -550,4 +550,4 @@
|
|||
</Layout>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
</Form>
|
||||
|
|
@ -559,7 +559,7 @@
|
|||
lblPlayer15 = new javax.swing.JLabel();
|
||||
lblPlayer16 = new javax.swing.JLabel();
|
||||
draftPicks = new mage.client.cards.CardsList();
|
||||
draftBooster = new mage.client.cards.DraftGrid(this);
|
||||
draftBooster = new mage.client.draft.DraftGrid();
|
||||
|
||||
draftLeftPane.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
||||
draftLeftPane.setFocusable(false);
|
||||
|
|
@ -879,7 +879,7 @@
|
|||
private javax.swing.JCheckBox chkPack1;
|
||||
private javax.swing.JCheckBox chkPack2;
|
||||
private javax.swing.JCheckBox chkPack3;
|
||||
private mage.client.cards.DraftGrid draftBooster;
|
||||
private mage.client.draft.DraftGrid draftBooster;
|
||||
private javax.swing.JPanel draftLeftPane;
|
||||
private mage.client.cards.CardsList draftPicks;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue