GUI, deck: improved grid padding for better cards selection by mouse

This commit is contained in:
Oleg Agafonov 2025-05-24 01:26:24 +04:00
parent 8b4c722ae2
commit a42a4f7239
2 changed files with 23 additions and 19 deletions

View file

@ -114,12 +114,12 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
int cardWidth = getCardWidth();
int cardHeight = getCardHeight();
int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth);
int dx = x % (cardWidth + GRID_PADDING);
int col = x / (cardWidth + GRID_PADDING);
int dx = x % (cardWidth + getGridPadding());
int col = x / (cardWidth + getGridPadding());
int gridWidth = cardGrid.isEmpty() ? 0 : cardGrid.get(0).size();
int countLabelHeight = getCountLabelHeight();
if (dx < GRID_PADDING && col < gridWidth) {
if (dx < getGridPadding() && col < gridWidth) {
// Which row to add to?
int curY = countLabelHeight;
int rowIndex = 0;
@ -142,7 +142,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
// Insert between two columns
insertArrow.setIcon(INSERT_COL_ICON);
insertArrow.setSize(64, 64);
insertArrow.setLocation((cardWidth + GRID_PADDING) * col + GRID_PADDING / 2 - 32, curY);
insertArrow.setLocation((cardWidth + getGridPadding()) * col + getGridPadding() / 2 - 32, curY);
} else {
// Clamp to a new col one after the current last one
col = Math.min(col, gridWidth);
@ -184,7 +184,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
// Position arrow
insertArrow.setIcon(INSERT_ROW_ICON);
insertArrow.setSize(64, 32);
insertArrow.setLocation((cardWidth + GRID_PADDING) * col + GRID_PADDING + cardWidth / 2 - 32, curY + stackInsertIndex * cardTopHeight - 32);
insertArrow.setLocation((cardWidth + getGridPadding()) * col + getGridPadding() + cardWidth / 2 - 32, curY + stackInsertIndex * cardTopHeight - 32);
}
}
@ -225,12 +225,12 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
int cardWidth = getCardWidth();
int cardHeight = getCardHeight();
int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth);
int dx = x % (cardWidth + GRID_PADDING);
int col = x / (cardWidth + GRID_PADDING);
int dx = x % (cardWidth + getGridPadding());
int col = x / (cardWidth + getGridPadding());
int gridWidth = cardGrid.isEmpty() ? 0 : cardGrid.get(0).size();
int countLabelHeight = getCountLabelHeight();
if (dx < GRID_PADDING && col < gridWidth) {
if (dx < getGridPadding() && col < gridWidth) {
// Which row to add to?
int curY = countLabelHeight;
int rowIndex = 0;
@ -575,7 +575,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
// Constants
private static final int DEFAULT_COUNT_LABEL_HEIGHT = 40; // can contain 1 or 2 lines
public static final int GRID_PADDING = 10;
public static final int GRID_PADDING = 20;
private static final ImageIcon INSERT_ROW_ICON = new ImageIcon(DragCardGrid.class.getClassLoader().getResource("editor_insert_row.png"));
private static final ImageIcon INSERT_COL_ICON = new ImageIcon(DragCardGrid.class.getClassLoader().getResource("editor_insert_col.png"));
@ -1253,10 +1253,10 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
selectionPanel.setSize(x2 - x1, y2 - y1);
// First and last cols
int col1 = x1 / (cardWidth + GRID_PADDING);
int col2 = x2 / (cardWidth + GRID_PADDING);
int offsetIntoCol2 = x2 % (cardWidth + GRID_PADDING);
if (offsetIntoCol2 < GRID_PADDING) {
int col1 = x1 / (cardWidth + getGridPadding());
int col2 = x2 / (cardWidth + getGridPadding());
int offsetIntoCol2 = x2 % (cardWidth + getGridPadding());
if (offsetIntoCol2 < getGridPadding()) {
--col2;
}
@ -2350,7 +2350,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
} else {
String description = cardSort.getComparator().getCategoryName(stack.get(0));
DragCardGrid.updateCountLabel(countLabel, stack.size(), description);
countLabel.setLocation(GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex, currentY - countLabelHeight);
countLabel.setLocation(getGridPadding() + (cardWidth + getGridPadding()) * colIndex, currentY - countLabelHeight);
countLabel.setSize(cardWidth, countLabelHeight);
countLabel.setVisible(true);
}
@ -2362,7 +2362,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
for (int i = 0; i < stack.size(); ++i) {
CardView card = stack.get(i);
MageCard view = cardViews.get(card.getId());
int x = GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex;
int x = getGridPadding() + (cardWidth + getGridPadding()) * colIndex;
int y = currentY + i * cardTopHeight;
view.setCardBounds(x, y, cardWidth, cardHeight);
cardContent.setLayer(view, layerIndex++);
@ -2370,14 +2370,18 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
}
// Update the max stack size for this row and the max width
maxWidth = Math.max(maxWidth, GRID_PADDING + (GRID_PADDING + cardWidth) * gridRow.size());
maxWidth = Math.max(maxWidth, getGridPadding() + (getGridPadding() + cardWidth) * gridRow.size());
maxStackSize.set(rowIndex, rowMaxStackSize);
currentY += (cardTopHeight * (rowMaxStackSize - 1) + cardHeight) + countLabelHeight;
}
// Resize card container
cardContent.setPreferredSize(new Dimension(maxWidth, currentY - countLabelHeight + GRID_PADDING));
//cardContent.setSize(maxWidth, currentY - COUNT_LABEL_HEIGHT + GRID_PADDING);
cardContent.setPreferredSize(new Dimension(maxWidth, currentY - countLabelHeight + getGridPadding()));
//cardContent.setSize(maxWidth, currentY - COUNT_LABEL_HEIGHT + getGridPadding());
}
private int getGridPadding() {
return Math.max(GRID_PADDING, Math.round(cardSizeMod * GRID_PADDING * GUISizeHelper.dialogGuiScale));
}
public static int getCountLabelHeight() {

View file

@ -455,7 +455,7 @@ public class DeckGeneratorPool {
// Check we have exactly the right amount of cards for a deck.
if (deckCards.size() != nonLandSize) {
throw new IllegalStateException("Not enough cards found to generate deck.");
logger.info("Can't generate full deck for selected settings - try again or choose more sets and less colors");
}
// Return the fixed amount
return deckCards;