Page 1 of 1

Gui_DeckEditor - help, please

PostPosted: 24 Oct 2009, 10:33
by silly freak
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:
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();

    }

}

This is an abstarct table model class nested in Gui_DeckEditor which should represent the available card pool, and the contents of a deck. the CardQty interface maps card to number of cards.

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 ;)

Re: Gui_DeckEditor - help, please

PostPosted: 24 Oct 2009, 11:00
by Chris H.
silly freak wrote: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.
so, if anyone would like to help, or sees some traps in my way, just tell me ;)
`
I may not be able to help with the high level coding. I am still learning and there is a lot for us to learn. :wink:

The deck editors also make use of another file, a file which is used by the gui_display. This other file creates the data which is displayed in the card detail panes.

Have you given much thought to the layout? I am not familiar enough with the JSplitPane methods to have a good idea how the tables for the new deck editor would look.

Re: Gui_DeckEditor - help, please

PostPosted: 24 Oct 2009, 11:38
by silly freak
i'm trying to preserve the layout, so the visible differences should be minimal. i'm using MultiSplitPane, like in GuiDisplay3. I think it would be very useful in the deck editor, because you can resize the lists depending on your focus. first, you want to view much of the card pool at once, and then you want to refine your deck.

Re: Gui_DeckEditor - help, please

PostPosted: 24 Oct 2009, 12:05
by Chris H.
silly freak wrote:i'm trying to preserve the layout, so the visible differences should be minimal. i'm using MultiSplitPane, like in GuiDisplay3. I think it would be very useful in the deck editor, because you can resize the lists depending on your focus. first, you want to view much of the card pool at once, and then you want to refine your deck.
`
Sounds good.

Can we make the two tables resizable with a middle row which has a height which can not change?

This middle row would contain the add/remove card buttons, the new filtering check boxes and the numbers for the card pool totals. This middle row would give us a nice area to click and drag as we resized the two tables.

It might be nice to have a new column included in the tables. A column for AI. We have a lot of good people joining our forum and they would like to find a way to help the project.

If they were interested, they could help to find the cards that should be added to the list of cards which do not show up in randomly generated decks for the computer to play against us.

It might be nice to have these cards display an asterisk in a new AI column. I am not sure if this idea is practical or not. I wonder what Dennis thinks about this idea.

Re: Gui_DeckEditor - help, please

PostPosted: 24 Oct 2009, 15:42
by silly freak
Chris H. wrote:Can we make the two tables resizable with a middle row which has a height which can not change?

This middle row would contain the add/remove card buttons, the new filtering check boxes and the numbers for the card pool totals. This middle row would give us a nice area to click and drag as we resized the two tables.
sort of... the middle row keeps its height, but you can't drag anywhere in that area, just directly below it.
Chris H. wrote:It might be nice to have a new column included in the tables. A column for AI. We have a lot of good people joining our forum and they would like to find a way to help the project.

If they were interested, they could help to find the cards that should be added to the list of cards which do not show up in randomly generated decks for the computer to play against us.

It might be nice to have these cards display an asterisk in a new AI column. I am not sure if this idea is practical or not. I wonder what Dennis thinks about this idea.
i have seen something like that in the code... don't know if it would work already, but i'm keeping it out for now. it should be easy to add it in again later.

Re: Gui_DeckEditor - help, please

PostPosted: 24 Oct 2009, 20:05
by mtgrares
Sounds good. The deck editor very straightforward but consider the hassle if MTG Forge didn't have a deck editor, oy va.)