Gui_DeckEditor - help, please
Hi! I currently try to rework the deck editor to be resizable, and to work with quest and normal mode at once. i know that the code depends on many other parts, and maybe someone who knows the deck editor and related things better could assist me
i have created the class Gui_DeckEditorNew for working, to not break running code, and will commit that soonly to SVN. here's an intro to what i want to do, starting with a code snippet:
the idea is that a card pool or deck has its own implementation of this, so that details are taken out of the deck editor.
for example, a deck or quest card pool would really add/remove a card when add/remove is called, but the constructed card pool would just ignore it, because it has an unlimited number of cards.
The implementation for a deck's model would be backed by the actual deck's card list, so the refresh isn't needed anymore.
once that actually works, the biggest deal is done, i think. maybe making the right menu, but that comes then.
so, if anyone would like to help, or sees some traps in my way, just tell me
i have created the class Gui_DeckEditorNew for working, to not break running code, and will commit that soonly to SVN. here's an intro to what i want to do, starting with a code snippet:
- Code: Select all
public abstract static class CardPoolModel extends AbstractTableModel {
private static final String[] labels = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "R"};
private static final Class<?>[] classes = {Integer.class, String.class, String.class, String.class};
//values taken from TableModel
private static final int[] minWidth = {-1, 190, 85, -1, -1, -1, -1};
private static final int[] prefWidth = {25, 190, 85, 58, 130, 32, 20};
private static final int[] maxWidth = {25, 190, 126, 58, -1, 42, 20};
/**
* Sets the column widths of the table. The table must use a CardPoolModel as its table model.
*/
public static void setColumnWidths(JTable t) {
if(!(t.getModel() instanceof CardPoolModel)) throw new IllegalArgumentException(
"Model is not a CardPoolModel");
TableColumnModel m = t.getColumnModel();
for(int i = 0; i < m.getColumnCount(); i++) {
TableColumn c = m.getColumn(i);
if(minWidth[i] >= 0) c.setMinWidth(minWidth[i]);
if(prefWidth[i] >= 0) c.setPreferredWidth(prefWidth[i]);
if(maxWidth[i] >= 0) c.setMaxWidth(maxWidth[i]);
}
}
public int getColumnCount() {
return labels.length;
}
@Override
public String getColumnName(int column) {
return labels[column];
}
@Override
public Class<?> getColumnClass(int column) {
return classes[column];
}
public Object getValueAt(int rowIndex, int column) {
CardQty cq = getRow(rowIndex);
Card c = cq.getCard();
switch(column) {
case 0: //Qty
return cq.getQty();
case 1: //Name
return cq.getCard().getName();
case 2: //Cost
return cq.getCard().getManaCost();
case 3: //Color
return TableSorter.getColor(c);
case 4: //Type
return GuiDisplayUtil.formatCardType(c);
case 5: //Stats
return c.isCreature()? c.getBaseAttack() + "/" + c.getBaseDefense():"";
case 6: //R
String rarity = c.getRarity();
if(rarity.length() > 0) rarity = rarity.substring(0, 1);
return rarity;
default:
throw new AssertionError();
}
}
/**
* Returns the non-null {@link CardQty} object for the given row index, unsorted
*/
public abstract CardQty getRow(int row);
public abstract int getRowCount();
/**
* Adds the card to the pool. If a CardQty for the specified card exists, its qty should be increased by 1.
* Otherwise, a new {@link CardQty} object should be added to the model, informing all listeners.
*/
public abstract void add(Card c);
/**
* Adds the card to the pool. If a CardQty for the specified card exists and has more than 1 instances, its
* qty should be decreased by 1. Otherwise, the {@link CardQty} should be removed from the model, informing
* all listeners.
*/
public abstract void remove(Card c);
private static interface CardQty {
public Card getCard();
public int getQty();
}
}
the idea is that a card pool or deck has its own implementation of this, so that details are taken out of the deck editor.
for example, a deck or quest card pool would really add/remove a card when add/remove is called, but the constructed card pool would just ignore it, because it has an unlimited number of cards.
The implementation for a deck's model would be backed by the actual deck's card list, so the refresh isn't needed anymore.
once that actually works, the biggest deal is done, i think. maybe making the right menu, but that comes then.
so, if anyone would like to help, or sees some traps in my way, just tell me