mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Add +/- buttons to Deck Editor Quantity column
This commit is contained in:
@@ -136,6 +136,25 @@ public enum CDeckEditorUI implements ICDoc, IMenuProvider {
|
||||
void move(InventoryItem item, int qty);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void incrementDeckQuantity(InventoryItem item, int delta) {
|
||||
if (item == null || delta == 0) { return; }
|
||||
|
||||
if (delta > 0) { //add items
|
||||
int qty = Math.min(delta, ((ItemManager<InventoryItem>)childController.getCatalogManager()).getItemCount(item));
|
||||
if (qty == 0) { return; }
|
||||
childController.addCard(item, false, qty);
|
||||
}
|
||||
else { //remove items
|
||||
int qty = Math.min(-delta, ((ItemManager<InventoryItem>)childController.getDeckManager()).getItemCount(item));
|
||||
if (qty == 0) { return; }
|
||||
childController.removeCard(item, false, qty);
|
||||
}
|
||||
|
||||
CStatistics.SINGLETON_INSTANCE.update();
|
||||
CProbabilities.SINGLETON_INSTANCE.update();
|
||||
}
|
||||
|
||||
private void moveSelectedCards(ItemManager<InventoryItem> itemManager, _MoveAction moveAction, int maxQty) {
|
||||
List<? extends InventoryItem> items = itemManager.getSelectedItems();
|
||||
if (items.isEmpty()) {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.toolbox.itemmanager.views;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import forge.gui.deckeditor.CDeckEditorUI;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FSkin.JLabelSkin;
|
||||
import forge.gui.toolbox.FSkin.SkinImage;
|
||||
import forge.item.InventoryItem;
|
||||
|
||||
/**
|
||||
* Displays deck quantity with +/- buttons
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DeckQuantityRenderer extends ItemCellRenderer {
|
||||
private static final SkinImage imgAdd = FSkin.getIcon(FSkin.InterfaceIcons.ICO_PLUS);
|
||||
private static final SkinImage imgRemove = FSkin.getIcon(FSkin.InterfaceIcons.ICO_MINUS);
|
||||
private static final int imgSize = 13;
|
||||
|
||||
private final JLabelSkin<DeckQuantityRenderer> skin = FSkin.get(this);
|
||||
|
||||
public DeckQuantityRenderer() {
|
||||
this.setHorizontalAlignment(JLabel.CENTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends InventoryItem> void processMouseEvent(final MouseEvent e, final ItemListView<T> listView, final Object value, final int row, final int column) {
|
||||
if (e.getID() == MouseEvent.MOUSE_PRESSED && e.getButton() == 1) {
|
||||
Rectangle cellBounds = listView.getTable().getCellRect(row, column, false);
|
||||
int delta = 0;
|
||||
int x = e.getX() - cellBounds.x;
|
||||
|
||||
if (x <= imgSize) { //add button
|
||||
delta = 1;
|
||||
}
|
||||
else if (x >= cellBounds.width - imgSize) { //remove button
|
||||
delta = -1;
|
||||
}
|
||||
|
||||
if (delta != 0) {
|
||||
listView.getTable().setRowSelectionInterval(row, row); //must set selection first so scroll doesn't get messed up
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.incrementDeckQuantity(listView.getItemAtIndex(row), delta);
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see javax.swing.JComponent#paint(java.awt.Graphics)
|
||||
*/
|
||||
@Override
|
||||
public final void paint(final Graphics g) {
|
||||
super.paint(g);
|
||||
|
||||
int y = (this.getHeight() - imgSize) / 2;
|
||||
skin.drawImage(g, imgAdd, 0, y, imgSize, imgSize);
|
||||
skin.drawImage(g, imgRemove, this.getWidth() - imgSize, y, imgSize, imgSize);
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,10 @@ package forge.gui.toolbox.itemmanager.views;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
import forge.item.InventoryItem;
|
||||
|
||||
/**
|
||||
* Base cell renderer class for item tables
|
||||
*/
|
||||
@@ -30,6 +31,6 @@ public class ItemCellRenderer extends DefaultTableCellRenderer {
|
||||
public boolean alwaysShowTooltip() {
|
||||
return false;
|
||||
}
|
||||
public void processMouseEvent(final MouseEvent e, final JTable table, final Object value, final int row, final int column) {
|
||||
public <T extends InventoryItem> void processMouseEvent(final MouseEvent e, final ItemListView<T> listView, final Object value, final int row, final int column) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
ItemCellRenderer renderer = (ItemCellRenderer)getCellRenderer(row, col);
|
||||
if (renderer != null) {
|
||||
renderer.processMouseEvent(e, this, val, row, col); //give renderer a chance to process the mouse event
|
||||
renderer.processMouseEvent(e, ItemListView.this, val, row, col); //give renderer a chance to process the mouse event
|
||||
}
|
||||
super.processMouseEvent(e);
|
||||
}
|
||||
|
||||
@@ -175,8 +175,11 @@ public final class SColumnUtil {
|
||||
SColumnUtil.getColumn(ColumnName.CAT_RANKING).setSortAndDisplayFunctions(
|
||||
SColumnUtil.FN_RANKING_COMPARE, SColumnUtil.FN_RANKING_GET, new ItemCellRenderer());
|
||||
|
||||
SColumnUtil.getColumn(ColumnName.DECK_QUANTITY).setSortAndDisplayFunctions(
|
||||
SColumnUtil.FN_QTY_COMPARE, SColumnUtil.FN_QTY_GET, new ItemCellRenderer());
|
||||
TableColumnInfo<InventoryItem> deckQuantityColumn = SColumnUtil.getColumn(ColumnName.DECK_QUANTITY);
|
||||
deckQuantityColumn.setMinWidth(46); //prevent resizing deck quantity column such that there isn't room for both +/- buttons and a 2-digit quantity
|
||||
deckQuantityColumn.setSortAndDisplayFunctions(
|
||||
SColumnUtil.FN_QTY_COMPARE, SColumnUtil.FN_QTY_GET, new DeckQuantityRenderer());
|
||||
|
||||
SColumnUtil.getColumn(ColumnName.DECK_NAME).setSortAndDisplayFunctions(
|
||||
SColumnUtil.FN_NAME_COMPARE, SColumnUtil.FN_NAME_GET, new ItemCellRenderer());
|
||||
SColumnUtil.getColumn(ColumnName.DECK_COST).setSortAndDisplayFunctions(
|
||||
|
||||
@@ -27,6 +27,7 @@ import forge.gui.CardPreferences;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FSkin.SkinImage;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
/**
|
||||
@@ -63,15 +64,15 @@ public class StarRenderer extends ItemCellRenderer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processMouseEvent(final MouseEvent e, final JTable table, final Object value, final int row, final int column) {
|
||||
public <T extends InventoryItem> void processMouseEvent(final MouseEvent e, final ItemListView<T> listView, final Object value, final int row, final int column) {
|
||||
if (e.getID() == MouseEvent.MOUSE_PRESSED && e.getButton() == 1 && value instanceof IPaperCard) {
|
||||
card = (IPaperCard) value;
|
||||
CardPreferences prefs = CardPreferences.getPrefs(card.getName());
|
||||
prefs.setStarCount((prefs.getStarCount() + 1) % 2); //TODO: consider supporting more than 1 star
|
||||
CardPreferences.save(NewConstants.CARD_PREFS_FILE);
|
||||
update();
|
||||
table.setRowSelectionInterval(row, row);
|
||||
table.repaint();
|
||||
listView.getTable().setRowSelectionInterval(row, row);
|
||||
listView.getTable().repaint();
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user