Skip to content

Conversation

@johannes-wolf
Copy link
Contributor

@johannes-wolf johannes-wolf commented Dec 20, 2025

Idea: Have a list of recently used decks when joining/creating a table instead of having to select the file each time you want to change the deck.

Change the filename edit in the NewPlayerPanel to a ComboBox that remembers the last $n$ decks used. Selecting a deck file using the file dialog directly adds it to the list of recent decks; changing the selection moves the selected item to the front of the recent list.

There are multiple ways of accessing preferences and it is not really clear to me, which one is the correct/modern one. @JayDi85

I have not touched the tournament dialog, but if this change gets accepted I would like to also
use the same mechanism there.

The deck editor could also use the path/directory of the recent deck as current path for
the file chooser. What do you think?


For a separate PR: A button to clear preferences (such as this one) in the preferences panel would
be a good addition, I guess.


Here are some screenshots:
Bildschirmfoto vom 2025-12-20 19-44-47
Bildschirmfoto vom 2025-12-20 19-45-11
Bildschirmfoto vom 2025-12-20 21-06-02
Bildschirmfoto vom 2025-12-20 21-06-20
Bildschirmfoto vom 2025-12-20 21-06-33

Also remember a history of the last 5 used decks
to make deck selection faster.
Copy link
Member

@JayDi85 JayDi85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be fine but require some improves:

  1. Make shared code and add same for new tourney and join dialogs;
  2. Test use cases with new app install without recent files (you can remove some settings by regedit, see here);
  3. Increase popup rows count from 5 to 10 and show it all in combobox (if it has scrollbar then find and change property like setMaximumRowCount);
  4. Make sure GUI works fine with very long paths (it's allow to see and select without errors, freeze or GUI blocking);
  5. Add screenshots to the started topic with new GUI elements;

try {
String selection = cbPlayerDeck.getSelectedItem().toString();
MagePreferences.putRecentDeckFile(selection);
} catch (NullPointerException ex) { /* Ignore */ }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to check cbPlayerDeck.getSelectedItem() for null instead catch error

also addActionListener will catch any events so make sure it's will raise 1 event instead multiple times each button/char edit, clicks or other user manipulations;

Use cases example:

  1. Autoload deck file name on open dialog (it's already in old code but maybe broken in last releases -- in normal use cases GUI must load last used deck and insert it to the player deck);
  2. Choose deck by file explorer;
  3. Enter copied deck name by ctrl+v;
  4. Same 1-3 features for tournament dialog;
  5. Same 1-3 features for table join dialog;

fcSelectDeck.addChoosableFileFilter(new DeckFileFilter("dck", "XMage's deck files (*.dck)"));
this.txtPlayerDeck.setText("");
this.txtPlayerName.setText(ClientDefaultSettings.computerName);
cbPlayerDeck.setEditable(true);;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are .form files for some GUI dialogs (old netbean 8 ide, see wiki docs -- it used to auto-generate some java code). So it also must be changed too. If don't have it then it's not critical -- I'll modify it later after merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot get Netbeans 8 to run on my Linux machine; thank you!

@JayDi85
Copy link
Member

JayDi85 commented Dec 20, 2025

MageFrame.getPreferences() is better way to access preferences. Example:

dialog.cbCardRenderImageFallback.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_RENDERING_IMAGE_MODE, CardRenderMode.MTGO.toString()));

@JayDi85
Copy link
Member

JayDi85 commented Dec 20, 2025

The deck editor could also use the path/directory of the recent deck as current path for
the file chooser. What do you think?

Yes, it will be fine to use last recent file's dir instead old way directory

- Support resizing the JoinTable dialog
- Fix re-loading the list of recent decks
- Add tooltips that show the full path
- Add a context menu to clear the list of recent decks
@johannes-wolf
Copy link
Contributor Author

johannes-wolf commented Dec 20, 2025

I added screenshots of the feature. To make the combobox fully show the filenames I did the following:

  • The JoinTable dialog is now resizable (horizontal)
  • The combobox adds tooltips for all items: hovering in a cropped list shows the full path

Also a context menu to clear the list got added.

@johannes-wolf
Copy link
Contributor Author

I have not yet added the feature to the NewTournamentDialog as I am not sure where shared code should be added :(

@JayDi85
Copy link
Member

JayDi85 commented Dec 20, 2025

You can store shared code in new Mage.Client/src/main/java/mage/client/util/RecentFilesUtil.java or like that (work with recent lists, add, remove, load to combobox, etc — just use combobox param in all methods and work with it).

@johannes-wolf
Copy link
Contributor Author

johannes-wolf commented Dec 21, 2025

I got something wrong… the NewTournamentTable does not really need anything but the last directory logic from the new recent decklist feature.

So I am not 100% happy with having the new RecentDecklistUtil class and would rather move all the logic (back) to the NewPlayerPanel but keep the utility functions to get, set and clear the list in the RecentDecklistUtil. You decide.

I've added just the “Clear list” item to the list and removed the right-click menu.
Or did you mean a real Dropdown button with no option to enter text?

I've tested it a lot and it works very nice!

@johannes-wolf
Copy link
Contributor Author

Another question: Why don't we just remove the form file(s)? Especially for simple panels/dialogs like this, there is no real need for them; those can just be built in code.

@johannes-wolf
Copy link
Contributor Author

Ok… I changed this (again):

  • Moved the combobox and "..." button to its own panel DecklistChooser that handles all the combobox related logic
  • The settings are available as static methods in the RecentDecklistUtil helper class to handle access & validation
  • The NewPlayerPanel just embeds the DecklistChooser instead of doing the logic itself. This way we have a single encapsulated class handling the recent logic.

What I would like to do:

  • Remove the Form-File of DecklistChooser and use a hand coded GridLayout instead of the (verbose) autogenerated layout code.

@JayDi85
Copy link
Member

JayDi85 commented Dec 22, 2025

Why don't we just remove the form file(s)? Especially for simple panels/dialogs like this, there is no real need for them; those can just be built in code.

It's good and must be final destination for all GUI dialogs (there are left only few dialogs like preferences and tables), but it's very hard. NetBean's form files uses xml and generate code with GroupLayout. It's almost impossible to manual modify that code due multiple places (vertical and horizontal groups) and per pixels layout. Also it's not support resizing (well, devs do not add it to original forms). So the best way -- rework dialog structure from scratch. See related commits from #969 with hi-dpi compatible forms rework and BorderLayout usage like 8186b35.

@johannes-wolf
Copy link
Contributor Author

Why don't we just remove the form file(s)? Especially for simple panels/dialogs like this, there is no real need for them; those can just be built in code.

It's good and must be final destination for all GUI dialogs (there are left only few dialogs like preferences and tables), but it's very hard.

Sorry, I did not really understand: Form files should stay or get removed?
Should I remove the form file for the panel and use the BorderLayout?

@JayDi85
Copy link
Member

JayDi85 commented Dec 22, 2025

Form files are netbeans only artifacts... It's not used by real app -- only by ide's visual designer. Every time you modify visual form -- it will save updated form file and generate whole java code between GEN-BEGIN text blocks in java file (components definition, visual structure and events):

shot_251222_165833

So after form file remove -- it still workable, but you can't modify dialog in netbeans anymore. After that you must modify all GUI code manually without any visual designer:

shot_251222_170040

GroupLayout is very hard layout, so it's better to rework for better things like BorderLayout.

P.S. I'll later test your branch for netbeans compatibility.

@JayDi85 JayDi85 self-assigned this Dec 22, 2025
@johannes-wolf johannes-wolf force-pushed the new-player-dialog-deck-history branch from b58a2fd to 0862be5 Compare December 23, 2025 10:00
@johannes-wolf
Copy link
Contributor Author

johannes-wolf commented Dec 23, 2025

Here is also a follow-up branch (based on this one) to remove the Form-File and use a GridBagLayout which actually simplifies the code and improves the overal dialog layout (more efficient use of space).

Let me know if I should merge those changes into this PR.

Here are some updated screenshots:
Bildschirmfoto vom 2025-12-23 11-57-46

Bildschirmfoto vom 2025-12-23 11-57-30

@johannes-wolf
Copy link
Contributor Author

Forgot to mention the form removal PR: johannes-wolf#1

}
});

setLayout(new GridBagLayout());
Copy link
Member

@JayDi85 JayDi85 Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, replace GridBag layout by another one like BorderLayout. gridbag is the most hardest to setup and support layout in whole swing collection -- it's better do not use it at all.

See example with game panel:
https://github.com/magefree/mage/blob/4941e2f19334ae6d9880350b94ec0919c84d3456/Mage.Client/src/main/java/mage/client/game/GamePanel.java#L256C9-L272C73

Copy link
Contributor Author

@johannes-wolf johannes-wolf Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed to BorderLayout. But I don't share the opinion that GridBag is hard to setup/read. BorderLayout is very strange as it seems to be meant for very simple use-cases and therefore needs all this JPanel nesting that GridBag does not need.

Copy link
Contributor Author

@johannes-wolf johannes-wolf Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are ok with removing the form file, I will merge that PR into this one and also change the layout to BorderLayout. Let me know :) (The PR also improves layout, as space is used more efficiently.)

@JayDi85
Copy link
Member

JayDi85 commented Dec 31, 2025

@johannes-wolf what's your current tools for code edition (normal code, GUI)?

@johannes-wolf
Copy link
Contributor Author

@johannes-wolf what's your current tools for code edition (normal code, GUI)?

I've installed IntelliJ for Java but use Emacs for everything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants