mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
Improved new version cleanup and more:
* fixed db cleanup on new version (sets + cards); * fixed empty sets list after update; * fixed NPE errors in sets list on new install/version; * added joke sets filter to deckeditor.
This commit is contained in:
parent
554e8076cf
commit
f01b3d3ca3
11 changed files with 243 additions and 112 deletions
|
|
@ -3,6 +3,7 @@ package mage.client;
|
|||
import mage.cards.action.ActionCallback;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.RepositoryUtil;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.chat.ChatPanelBasic;
|
||||
import mage.client.components.*;
|
||||
|
|
@ -212,6 +213,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
LOGGER.fatal(null, ex);
|
||||
}
|
||||
|
||||
RepositoryUtil.bootstrapLocalDb();
|
||||
ManaSymbols.loadImages();
|
||||
Plugins.instance.loadPlugins();
|
||||
|
||||
|
|
@ -281,7 +283,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
|
||||
if (Plugins.instance.isCounterPluginLoaded()) {
|
||||
int i = Plugins.instance.getGamesPlayed();
|
||||
JLabel label = new JLabel(" Games played: " + String.valueOf(i));
|
||||
JLabel label = new JLabel(" Games played: " + i);
|
||||
desktopPane.add(label, JLayeredPane.DEFAULT_LAYER + 1);
|
||||
label.setVisible(true);
|
||||
label.setForeground(Color.white);
|
||||
|
|
@ -1160,7 +1162,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(final String args[]) {
|
||||
public static void main(final String[] args) {
|
||||
// Workaround for #451
|
||||
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
|
||||
LOGGER.info("Starting MAGE client version " + VERSION);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
package mage.client.util.gui;
|
||||
|
||||
import mage.choices.ChoiceImpl;
|
||||
import mage.client.dialog.CheckBoxList;
|
||||
import mage.client.dialog.PickCheckBoxDialog;
|
||||
import mage.client.dialog.PickChoiceDialog;
|
||||
|
||||
import mage.client.dialog.CheckBoxList;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class FastSearchUtil {
|
||||
|
|
@ -19,27 +17,28 @@ public class FastSearchUtil {
|
|||
public static String DEFAULT_EXPANSION_SEARCH_MESSAGE = "Select set or expansion";
|
||||
public static String DEFAULT_EXPANSION_TOOLTIP_MESSAGE = "Fast search set or expansion";
|
||||
|
||||
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage){
|
||||
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage) {
|
||||
showFastSearchForStringComboBox(combo, chooseMessage, 300, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show fast choice modal dialog with incremental searching for any string combobox components
|
||||
* @param combo combobox control with default data model
|
||||
*
|
||||
* @param combo combobox control with default data model
|
||||
* @param chooseMessage caption message for dialog
|
||||
*/
|
||||
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage, int windowWidth, int windowHeight){
|
||||
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage, int windowWidth, int windowHeight) {
|
||||
// fast search/choice dialog for string combobox
|
||||
|
||||
mage.choices.Choice choice = new ChoiceImpl(false);
|
||||
|
||||
// collect data from expansion combobox (String)
|
||||
DefaultComboBoxModel comboModel = (DefaultComboBoxModel)combo.getModel();
|
||||
DefaultComboBoxModel comboModel = (DefaultComboBoxModel) combo.getModel();
|
||||
Map<String, String> choiceItems = new HashMap<>(comboModel.getSize());
|
||||
Map<String, Integer> choiceSorting = new HashMap<>(comboModel.getSize());
|
||||
String item;
|
||||
|
||||
for(int i = 0; i < comboModel.getSize(); i++){
|
||||
for (int i = 0; i < comboModel.getSize(); i++) {
|
||||
item = comboModel.getElementAt(i).toString();
|
||||
choiceItems.put(item, item);
|
||||
choiceSorting.put(item, i); // need so sorting
|
||||
|
|
@ -57,35 +56,36 @@ public class FastSearchUtil {
|
|||
PickChoiceDialog dlg = new PickChoiceDialog();
|
||||
dlg.setWindowSize(windowWidth, windowHeight);
|
||||
dlg.showDialog(choice, needSelectValue);
|
||||
if(choice.isChosen()){
|
||||
if (choice.isChosen()) {
|
||||
item = choice.getChoiceKey();
|
||||
|
||||
// compatible select for object's models (use setSelectedIndex instead setSelectedObject)
|
||||
for(int i = 0; i < comboModel.getSize(); i++){
|
||||
if(comboModel.getElementAt(i).toString().equals(item)){
|
||||
for (int i = 0; i < comboModel.getSize(); i++) {
|
||||
if (comboModel.getElementAt(i).toString().equals(item)) {
|
||||
combo.setSelectedIndex(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show fast choice modal dialog with incremental searching for any string CheckBoxList components
|
||||
* @param combo CheckBoxList control with default data model
|
||||
*
|
||||
* @param combo CheckBoxList control with default data model
|
||||
* @param chooseMessage caption message for dialog
|
||||
*/
|
||||
public static void showFastSearchForStringComboBox(CheckBoxList combo, String chooseMessage){
|
||||
public static void showFastSearchForStringComboBox(CheckBoxList combo, String chooseMessage) {
|
||||
// fast search/choice dialog for string combobox
|
||||
|
||||
mage.choices.Choice choice = new ChoiceImpl(false);
|
||||
|
||||
// collect data from expansion combobox (String)
|
||||
DefaultListModel comboModel = (DefaultListModel)combo.getModel();
|
||||
DefaultListModel comboModel = (DefaultListModel) combo.getModel();
|
||||
Map<String, String> choiceItems = new HashMap<>(comboModel.getSize());
|
||||
Map<String, Integer> choiceSorting = new HashMap<>(comboModel.getSize());
|
||||
String item;
|
||||
|
||||
for(int i = 0; i < comboModel.size(); i++){
|
||||
for (int i = 0; i < comboModel.size(); i++) {
|
||||
item = comboModel.getElementAt(i).toString();
|
||||
choiceItems.put(item, item);
|
||||
choiceSorting.put(item, i); // need so sorting
|
||||
|
|
@ -96,21 +96,22 @@ public class FastSearchUtil {
|
|||
choice.setMessage(chooseMessage);
|
||||
|
||||
// current selection value restore
|
||||
String needSelectValue;
|
||||
needSelectValue = comboModel.firstElement().toString();
|
||||
String needSelectValue = null;
|
||||
if (comboModel.size() > 0) {
|
||||
needSelectValue = comboModel.firstElement().toString();
|
||||
}
|
||||
|
||||
// ask for new value
|
||||
|
||||
PickCheckBoxDialog dlg = new PickCheckBoxDialog(combo);
|
||||
PickCheckBoxDialog dlg = new PickCheckBoxDialog(combo);
|
||||
|
||||
dlg.setWindowSize(300, 500);
|
||||
dlg.showDialog(choice, needSelectValue);
|
||||
if(choice.isChosen()){
|
||||
if (choice.isChosen()) {
|
||||
item = choice.getChoiceKey();
|
||||
|
||||
// compatible select for object's models (use setSelectedIndex instead setSelectedObject)
|
||||
for(int i = 0; i < comboModel.getSize(); i++){
|
||||
if(comboModel.getElementAt(i).toString().equals(item)){
|
||||
for (int i = 0; i < comboModel.getSize(); i++) {
|
||||
if (comboModel.getElementAt(i).toString().equals(item)) {
|
||||
combo.setSelectedIndex(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,13 @@
|
|||
package mage.client.util.sets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.cards.repository.ExpansionRepository;
|
||||
import mage.cards.repository.RepositoryEvent;
|
||||
import mage.constants.SetType;
|
||||
import static mage.constants.SetType.EXPANSION;
|
||||
import static mage.constants.SetType.SUPPLEMENTAL;
|
||||
import mage.deck.Standard;
|
||||
import mage.game.events.Listener;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Utility class for constructed formats (expansions and other editions).
|
||||
|
|
@ -26,11 +22,36 @@ public final class ConstructedFormats {
|
|||
public static final String FRONTIER = "- Frontier";
|
||||
public static final String MODERN = "- Modern";
|
||||
public static final String VINTAGE_LEGACY = "- Vintage / Legacy";
|
||||
public static final String JOKE = "- Joke Sets";
|
||||
public static final String CUSTOM = "- Custom";
|
||||
public static final Standard STANDARD_CARDS = new Standard();
|
||||
|
||||
// Attention -Month is 0 Based so Feb = 1 for example. //
|
||||
private static final Date extendedDate = new GregorianCalendar(2009, 7, 20).getTime();
|
||||
private static final Date frontierDate = new GregorianCalendar(2014, 6, 17).getTime();
|
||||
private static final Date modernDate = new GregorianCalendar(2003, 6, 20).getTime();
|
||||
|
||||
// for all sets just return empty list
|
||||
private static final List<String> all = new ArrayList<>();
|
||||
|
||||
private static final Map<String, List<String>> underlyingSetCodesPerFormat = new HashMap<>();
|
||||
private static final List<String> formats = new ArrayList<>();
|
||||
private static final Listener<RepositoryEvent> setsDbListener;
|
||||
|
||||
static {
|
||||
buildLists();
|
||||
|
||||
// auto-update sets list on changes
|
||||
setsDbListener = new Listener<RepositoryEvent>() {
|
||||
@Override
|
||||
public void event(RepositoryEvent event) {
|
||||
if (event.getEventType().equals(RepositoryEvent.RepositoryEventType.DB_UPDATED)) {
|
||||
buildLists();
|
||||
}
|
||||
}
|
||||
};
|
||||
ExpansionRepository.instance.subscribe(setsDbListener);
|
||||
}
|
||||
|
||||
private ConstructedFormats() {
|
||||
}
|
||||
|
|
@ -57,12 +78,13 @@ public final class ConstructedFormats {
|
|||
}
|
||||
}
|
||||
|
||||
private static void buildLists() {
|
||||
public static void buildLists() {
|
||||
underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<>());
|
||||
underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList<>());
|
||||
underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList<>());
|
||||
underlyingSetCodesPerFormat.put(MODERN, new ArrayList<>());
|
||||
underlyingSetCodesPerFormat.put(VINTAGE_LEGACY, new ArrayList<>());
|
||||
underlyingSetCodesPerFormat.put(JOKE, new ArrayList<>());
|
||||
underlyingSetCodesPerFormat.put(CUSTOM, new ArrayList<>());
|
||||
final Map<String, ExpansionInfo> expansionInfo = new HashMap<>();
|
||||
formats.clear(); // prevent NPE on sorting if this is not the first try
|
||||
|
|
@ -85,6 +107,10 @@ public final class ConstructedFormats {
|
|||
underlyingSetCodesPerFormat.get(CUSTOM).add(set.getCode());
|
||||
continue;
|
||||
}
|
||||
if (set.getType() == SetType.JOKESET) {
|
||||
underlyingSetCodesPerFormat.get(JOKE).add(set.getCode());
|
||||
continue;
|
||||
}
|
||||
underlyingSetCodesPerFormat.get(VINTAGE_LEGACY).add(set.getCode());
|
||||
if (set.getType() == SetType.CORE || set.getType() == SetType.EXPANSION || set.getType() == SetType.SUPPLEMENTAL_STANDARD_LEGAL) {
|
||||
if (STANDARD_CARDS.getSetCodes().contains(set.getCode())) {
|
||||
|
|
@ -211,12 +237,12 @@ public final class ConstructedFormats {
|
|||
});
|
||||
if (!formats.isEmpty()) {
|
||||
formats.add(0, CUSTOM);
|
||||
formats.add(0, JOKE);
|
||||
formats.add(0, VINTAGE_LEGACY);
|
||||
formats.add(0, MODERN);
|
||||
formats.add(0, EXTENDED);
|
||||
formats.add(0, FRONTIER);
|
||||
formats.add(0, EXTENDED);
|
||||
formats.add(0, STANDARD);
|
||||
|
||||
}
|
||||
formats.add(0, ALL);
|
||||
}
|
||||
|
|
@ -224,15 +250,4 @@ public final class ConstructedFormats {
|
|||
private static String getBlockDisplayName(String blockName) {
|
||||
return "* " + blockName + " Block";
|
||||
}
|
||||
// Attention -Month is 0 Based so Feb = 1 for example.
|
||||
private static final Date extendedDate = new GregorianCalendar(2009, 7, 20).getTime();
|
||||
private static final Date frontierDate = new GregorianCalendar(2014, 6, 17).getTime();
|
||||
private static final Date modernDate = new GregorianCalendar(2003, 6, 20).getTime();
|
||||
|
||||
// for all sets just return empty list
|
||||
private static final List<String> all = new ArrayList<>();
|
||||
|
||||
static {
|
||||
buildLists();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue