GUI, deck editor: added gui scale support for sort/order labels, fixed wrong label hints (part of #969, #6887)

This commit is contained in:
Oleg Agafonov 2024-07-27 22:39:29 +04:00
parent 53a072b759
commit f9b59ca411
3 changed files with 55 additions and 26 deletions

View file

@ -62,6 +62,11 @@
} }
private void setGUISize() { private void setGUISize() {
Font countLabelFont = DragCardGrid.getCountLabelFont();
countLabels.stream().forEach(label -> {
label.setFont(countLabelFont);
});
cardDimension = GUISizeHelper.editorCardDimension; cardDimension = GUISizeHelper.editorCardDimension;
} }
@ -188,7 +193,7 @@
String description = comparator.getCategoryName(currentCard.getOriginal()); String description = comparator.getCategoryName(currentCard.getOriginal());
DragCardGrid.updateCountLabel(lastCountLabel, curRow + 1, description); DragCardGrid.updateCountLabel(lastCountLabel, curRow + 1, description);
rectangle.setLocation(curColumn * cardDimension.width, curRow * vertOffsetPerCardInStack + DragCardGrid.COUNT_LABEL_HEIGHT); rectangle.setLocation(curColumn * cardDimension.width, curRow * vertOffsetPerCardInStack + DragCardGrid.getCountLabelHeight());
currentCard.setCardBounds(rectangle.x, rectangle.y, cardDimension.width, cardDimension.height); currentCard.setCardBounds(rectangle.x, rectangle.y, cardDimension.width, cardDimension.height);
moveToFront(currentCard); moveToFront(currentCard);
curRow++; curRow++;
@ -215,7 +220,7 @@
this.countLabels.add(label); this.countLabels.add(label);
this.add(label, (Integer) 0); // draw on background this.add(label, (Integer) 0); // draw on background
label.setLocation(columnNumber * cardDimension.width, 5); label.setLocation(columnNumber * cardDimension.width, 5);
label.setSize(cardDimension.width, DragCardGrid.COUNT_LABEL_HEIGHT); // TODO: add here? label.setSize(cardDimension.width, DragCardGrid.getCountLabelHeight());
label.setVisible(true); label.setVisible(true);
return label; return label;
} }

View file

@ -357,7 +357,7 @@
String description = comparator.getCategoryName(card); String description = comparator.getCategoryName(card);
DragCardGrid.updateCountLabel(lastCountLabel, curRow + 1, description); DragCardGrid.updateCountLabel(lastCountLabel, curRow + 1, description);
rectangle.setLocation(curColumn * cardDimension.width, curRow * cardOffsetInStack + DragCardGrid.COUNT_LABEL_HEIGHT); rectangle.setLocation(curColumn * cardDimension.width, curRow * cardOffsetInStack + DragCardGrid.getCountLabelHeight());
setCardBounds(mageCards.get(card.getId()), rectangle); setCardBounds(mageCards.get(card.getId()), rectangle);
curRow++; curRow++;
@ -389,7 +389,7 @@
this.countLabels.add(label); this.countLabels.add(label);
cardArea.add(label, (Integer) 0); // draw on background cardArea.add(label, (Integer) 0); // draw on background
label.setLocation(columnNumber * cardDimension.width, 5); label.setLocation(columnNumber * cardDimension.width, 5);
label.setSize(cardDimension.width, DragCardGrid.COUNT_LABEL_HEIGHT); label.setSize(cardDimension.width, DragCardGrid.getCountLabelHeight());
label.setVisible(true); label.setVisible(true);
return label; return label;
} }

View file

@ -118,14 +118,15 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
int col = x / (cardWidth + GRID_PADDING); int col = x / (cardWidth + GRID_PADDING);
int gridWidth = cardGrid.isEmpty() ? 0 : cardGrid.get(0).size(); int gridWidth = cardGrid.isEmpty() ? 0 : cardGrid.get(0).size();
int countLabelHeight = getCountLabelHeight();
if (dx < GRID_PADDING && col < gridWidth) { if (dx < GRID_PADDING && col < gridWidth) {
// Which row to add to? // Which row to add to?
int curY = COUNT_LABEL_HEIGHT; int curY = countLabelHeight;
int rowIndex = 0; int rowIndex = 0;
for (int i = 0; i < cardGrid.size(); ++i) { for (int i = 0; i < cardGrid.size(); ++i) {
int maxStack = maxStackSize.get(i); int maxStack = maxStackSize.get(i);
int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight; int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight;
int rowBottom = curY + rowHeight + COUNT_LABEL_HEIGHT; int rowBottom = curY + rowHeight + countLabelHeight;
// Break out if we're in that row // Break out if we're in that row
if (y < rowBottom) { if (y < rowBottom) {
@ -147,13 +148,13 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
col = Math.min(col, gridWidth); col = Math.min(col, gridWidth);
// Determine place in the col // Determine place in the col
int curY = COUNT_LABEL_HEIGHT; int curY = countLabelHeight;
int rowIndex = 0; int rowIndex = 0;
int offsetIntoStack = 0; int offsetIntoStack = 0;
for (int i = 0; i < cardGrid.size(); ++i) { for (int i = 0; i < cardGrid.size(); ++i) {
int maxStack = maxStackSize.get(i); int maxStack = maxStackSize.get(i);
int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight; int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight;
int rowBottom = curY + rowHeight + COUNT_LABEL_HEIGHT; int rowBottom = curY + rowHeight + countLabelHeight;
// Break out if we're in that row // Break out if we're in that row
if (y < rowBottom) { if (y < rowBottom) {
@ -228,14 +229,15 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
int col = x / (cardWidth + GRID_PADDING); int col = x / (cardWidth + GRID_PADDING);
int gridWidth = cardGrid.isEmpty() ? 0 : cardGrid.get(0).size(); int gridWidth = cardGrid.isEmpty() ? 0 : cardGrid.get(0).size();
int countLabelHeight = getCountLabelHeight();
if (dx < GRID_PADDING && col < gridWidth) { if (dx < GRID_PADDING && col < gridWidth) {
// Which row to add to? // Which row to add to?
int curY = COUNT_LABEL_HEIGHT; int curY = countLabelHeight;
int rowIndex = 0; int rowIndex = 0;
for (int i = 0; i < cardGrid.size(); ++i) { for (int i = 0; i < cardGrid.size(); ++i) {
int maxStack = maxStackSize.get(i); int maxStack = maxStackSize.get(i);
int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight; int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight;
int rowBottom = curY + rowHeight + COUNT_LABEL_HEIGHT; int rowBottom = curY + rowHeight + countLabelHeight;
// Break out if we're in that row // Break out if we're in that row
if (y < rowBottom) { if (y < rowBottom) {
@ -272,13 +274,13 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
col = Math.min(col, gridWidth); col = Math.min(col, gridWidth);
// Determine place in the col // Determine place in the col
int curY = COUNT_LABEL_HEIGHT; int curY = countLabelHeight;
int rowIndex = 0; int rowIndex = 0;
int offsetIntoStack = 0; int offsetIntoStack = 0;
for (int i = 0; i < cardGrid.size(); ++i) { for (int i = 0; i < cardGrid.size(); ++i) {
int maxStack = maxStackSize.get(i); int maxStack = maxStackSize.get(i);
int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight; int rowHeight = cardTopHeight * (maxStack - 1) + cardHeight;
int rowBottom = curY + rowHeight + COUNT_LABEL_HEIGHT; int rowBottom = curY + rowHeight + countLabelHeight;
// Break out if we're in that row // Break out if we're in that row
if (y < rowBottom) { if (y < rowBottom) {
@ -341,6 +343,11 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
} }
public void changeGUISize() { public void changeGUISize() {
Font countLabelFont = DragCardGrid.getCountLabelFont();
stackCountLabels.stream().flatMap(Collection::stream).forEach(label -> {
label.setFont(countLabelFont);
});
layoutGrid(); layoutGrid();
cardScroll.getVerticalScrollBar().setUnitIncrement(CardRenderer.getCardTopHeight(getCardWidth())); cardScroll.getVerticalScrollBar().setUnitIncrement(CardRenderer.getCardTopHeight(getCardWidth()));
repaintGrid(); repaintGrid();
@ -567,7 +574,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
} }
// Constants // Constants
public static final int COUNT_LABEL_HEIGHT = 40; // can contains 1 or 2 lines 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 = 10;
private static final ImageIcon INSERT_ROW_ICON = new ImageIcon(DragCardGrid.class.getClassLoader().getResource("editor_insert_row.png")); private static final ImageIcon INSERT_ROW_ICON = new ImageIcon(DragCardGrid.class.getClassLoader().getResource("editor_insert_row.png"));
@ -1253,7 +1260,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
--col2; --col2;
} }
int curY = COUNT_LABEL_HEIGHT; int countLabelHeight = getCountLabelHeight();
int curY = countLabelHeight;
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) { for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
int stackStartIndex; int stackStartIndex;
if (y1 < curY) { if (y1 < curY) {
@ -1290,7 +1298,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
} }
} }
} }
curY += cardTopHeight * (maxStackSize.get(rowIndex) - 1) + cardHeight + COUNT_LABEL_HEIGHT; curY += cardTopHeight * (maxStackSize.get(rowIndex) - 1) + cardHeight + countLabelHeight;
} }
} }
@ -2279,9 +2287,11 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
int cardHeight = getCardHeight(); int cardHeight = getCardHeight();
int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth); int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth);
int countLabelHeight = getCountLabelHeight();
// Layout one at a time // Layout one at a time
int layerIndex = 0; int layerIndex = 0;
int currentY = COUNT_LABEL_HEIGHT; int currentY = countLabelHeight;
int maxWidth = 0; int maxWidth = 0;
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) { for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
int rowMaxStackSize = 0; int rowMaxStackSize = 0;
@ -2326,8 +2336,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
} else { } else {
String description = cardSort.getComparator().getCategoryName(stack.get(0)); String description = cardSort.getComparator().getCategoryName(stack.get(0));
DragCardGrid.updateCountLabel(countLabel, stack.size(), description); DragCardGrid.updateCountLabel(countLabel, stack.size(), description);
countLabel.setLocation(GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex, currentY - COUNT_LABEL_HEIGHT); countLabel.setLocation(GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex, currentY - countLabelHeight);
countLabel.setSize(cardWidth, COUNT_LABEL_HEIGHT); countLabel.setSize(cardWidth, countLabelHeight);
countLabel.setVisible(true); countLabel.setVisible(true);
} }
@ -2348,17 +2358,31 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
// Update the max stack size for this row and the max width // 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, GRID_PADDING + (GRID_PADDING + cardWidth) * gridRow.size());
maxStackSize.set(rowIndex, rowMaxStackSize); maxStackSize.set(rowIndex, rowMaxStackSize);
currentY += (cardTopHeight * (rowMaxStackSize - 1) + cardHeight) + COUNT_LABEL_HEIGHT; currentY += (cardTopHeight * (rowMaxStackSize - 1) + cardHeight) + countLabelHeight;
} }
// Resize card container // Resize card container
cardContent.setPreferredSize(new Dimension(maxWidth, currentY - COUNT_LABEL_HEIGHT + GRID_PADDING)); cardContent.setPreferredSize(new Dimension(maxWidth, currentY - countLabelHeight + GRID_PADDING));
//cardContent.setSize(maxWidth, currentY - COUNT_LABEL_HEIGHT + GRID_PADDING); //cardContent.setSize(maxWidth, currentY - COUNT_LABEL_HEIGHT + GRID_PADDING);
} }
public static int getCountLabelHeight() {
// must allow 2 lines of text
return Math.round(1.3f * 2.0f * getCountLabelFontSize());
}
private static float getCountLabelFontSize() {
return 0.8f * GUISizeHelper.dialogFont.getSize();
}
public static Font getCountLabelFont() {
return GUISizeHelper.dialogFont.deriveFont(Font.BOLD, getCountLabelFontSize());
}
public static JLabel createCountLabel(MouseListener mouseListener) { public static JLabel createCountLabel(MouseListener mouseListener) {
JLabel countLabel = new JLabel("", JLabel.CENTER); JLabel countLabel = new JLabel("", JLabel.CENTER);
countLabel.setForeground(Color.WHITE); // TODO: add theme support countLabel.setFont(getCountLabelFont());
countLabel.setForeground(Color.WHITE); // TODO: add theme support for better visible text?
if (mouseListener != null) { if (mouseListener != null) {
countLabel.addMouseListener(mouseListener); countLabel.addMouseListener(mouseListener);
} }
@ -2369,7 +2393,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
// two modes: // two modes:
// * small: one line with count // * small: one line with count
// * big: two lines with count and description // * big: two lines with count and description
String descHtml = ManaSymbols.replaceSymbolsWithHTML(description, ManaSymbols.Type.TABLE); String labelText = ManaSymbols.replaceSymbolsWithHTML(description, Math.round(getCountLabelFontSize()));
String labelHint = ManaSymbols.replaceSymbolsWithHTML(description, ManaSymbols.Type.TOOLTIP);
boolean smallMode = description.isEmpty(); boolean smallMode = description.isEmpty();
boolean supportCustomClicks = countLabel.getMouseListeners().length > 0 boolean supportCustomClicks = countLabel.getMouseListeners().length > 0
&& !(countLabel.getMouseListeners()[0] instanceof ToolTipManager); // ignore auto-added ToolTipManager for mouse over hints && !(countLabel.getMouseListeners()[0] instanceof ToolTipManager); // ignore auto-added ToolTipManager for mouse over hints
@ -2379,11 +2404,10 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
countLabel.setText("<html>" countLabel.setText("<html>"
+ "<div style='text-align: center;'>" + "<div style='text-align: center;'>"
+ " <div>" + amount + "</div>" + " <div>" + amount + "</div>"
+ (smallMode ? "" : " <div style=''>" + descHtml + "</div>") + (smallMode ? "" : " <div style=''>" + labelText + "</div>")
+ "</div>" + "</div>");
+ "");
countLabel.setToolTipText("<html>" countLabel.setToolTipText("<html>"
+ amount + (smallMode ? "" : " - " + description) + amount + (smallMode ? "" : " - " + labelHint)
+ (supportCustomClicks ? "<br>Click on the count label to select/unselect cards stack." : "") + (supportCustomClicks ? "<br>Click on the count label to select/unselect cards stack." : "")
); );
countLabel.setVerticalAlignment(smallMode ? JLabel.CENTER : JLabel.TOP); countLabel.setVerticalAlignment(smallMode ? JLabel.CENTER : JLabel.TOP);