It is currently 29 Apr 2024, 05:56
   
Text Size

Gui_DeckEditor - help, please

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Gui_DeckEditor - help, please

Postby silly freak » 24 Oct 2009, 10:33

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

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Gui_DeckEditor - help, please

Postby Chris H. » 24 Oct 2009, 11:00

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.
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: Gui_DeckEditor - help, please

Postby silly freak » 24 Oct 2009, 11:38

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.
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Gui_DeckEditor - help, please

Postby Chris H. » 24 Oct 2009, 12:05

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.
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: Gui_DeckEditor - help, please

Postby silly freak » 24 Oct 2009, 15:42

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.
___

where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times

Re: Gui_DeckEditor - help, please

Postby mtgrares » 24 Oct 2009, 20:05

Sounds good. The deck editor very straightforward but consider the hassle if MTG Forge didn't have a deck editor, oy va.)
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 99 guests


Who is online

In total there are 99 users online :: 0 registered, 0 hidden and 99 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 99 guests

Login Form