mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Trying to reload default layout after a failure with user preferred one
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14403,6 +14403,7 @@ src/main/java/forge/gui/framework/IDocIdList.java -text
|
|||||||
src/main/java/forge/gui/framework/ILocalRepaint.java -text
|
src/main/java/forge/gui/framework/ILocalRepaint.java -text
|
||||||
src/main/java/forge/gui/framework/IVDoc.java -text
|
src/main/java/forge/gui/framework/IVDoc.java -text
|
||||||
src/main/java/forge/gui/framework/IVTopLevelUI.java -text
|
src/main/java/forge/gui/framework/IVTopLevelUI.java -text
|
||||||
|
src/main/java/forge/gui/framework/InvalidLayoutFileException.java -text
|
||||||
src/main/java/forge/gui/framework/RectangleOfDouble.java -text
|
src/main/java/forge/gui/framework/RectangleOfDouble.java -text
|
||||||
src/main/java/forge/gui/framework/SDisplayUtil.java -text
|
src/main/java/forge/gui/framework/SDisplayUtil.java -text
|
||||||
src/main/java/forge/gui/framework/SLayoutConstants.java -text
|
src/main/java/forge/gui/framework/SLayoutConstants.java -text
|
||||||
|
|||||||
@@ -42,11 +42,14 @@ import forge.game.Game;
|
|||||||
import forge.game.ai.AiProfileUtil;
|
import forge.game.ai.AiProfileUtil;
|
||||||
import forge.game.player.LobbyPlayer;
|
import forge.game.player.LobbyPlayer;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
|
import forge.gui.GuiDialog;
|
||||||
import forge.gui.SOverlayUtils;
|
import forge.gui.SOverlayUtils;
|
||||||
import forge.gui.deckeditor.CDeckEditorUI;
|
import forge.gui.deckeditor.CDeckEditorUI;
|
||||||
import forge.gui.deckeditor.VDeckEditorUI;
|
import forge.gui.deckeditor.VDeckEditorUI;
|
||||||
import forge.gui.framework.EDocID;
|
import forge.gui.framework.EDocID;
|
||||||
|
import forge.gui.framework.InvalidLayoutFileException;
|
||||||
import forge.gui.framework.SDisplayUtil;
|
import forge.gui.framework.SDisplayUtil;
|
||||||
|
import forge.gui.framework.SLayoutIO;
|
||||||
import forge.gui.framework.SOverflowUtil;
|
import forge.gui.framework.SOverflowUtil;
|
||||||
import forge.gui.framework.SResizingUtil;
|
import forge.gui.framework.SResizingUtil;
|
||||||
import forge.gui.home.CHomeUI;
|
import forge.gui.home.CHomeUI;
|
||||||
@@ -406,7 +409,16 @@ public enum FControl {
|
|||||||
|
|
||||||
|
|
||||||
Singletons.getModel().getPreferences().actuateMatchPreferences();
|
Singletons.getModel().getPreferences().actuateMatchPreferences();
|
||||||
Singletons.getControl().changeState(Screens.MATCH_SCREEN);
|
|
||||||
|
try {
|
||||||
|
Singletons.getControl().changeState(Screens.MATCH_SCREEN);
|
||||||
|
} catch (InvalidLayoutFileException ex) {
|
||||||
|
GuiDialog.message("Your match layout file could not be read. It will be deleted after you press OK.\nThe game will proceed with default layout.");
|
||||||
|
File fLayout = new File(SLayoutIO.getFilePreferred(Screens.MATCH_SCREEN));
|
||||||
|
fLayout.delete();
|
||||||
|
// try again
|
||||||
|
Singletons.getControl().changeState(Screens.MATCH_SCREEN);
|
||||||
|
}
|
||||||
SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc());
|
SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc());
|
||||||
|
|
||||||
CMessage.SINGLETON_INSTANCE.getInputControl().setGame(game);
|
CMessage.SINGLETON_INSTANCE.getInputControl().setGame(game);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package forge.gui.framework;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for this type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class InvalidLayoutFileException extends RuntimeException {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package forge.gui.framework;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -136,17 +137,35 @@ public final class SLayoutIO {
|
|||||||
|
|
||||||
// Read a model for new layout
|
// Read a model for new layout
|
||||||
MapOfLists<RectangleOfDouble, EDocID> model = null;
|
MapOfLists<RectangleOfDouble, EDocID> model = null;
|
||||||
|
|
||||||
|
boolean usedCustomPrefsFile = false;
|
||||||
|
|
||||||
|
FileInputStream fis = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileInputStream fis = null;
|
|
||||||
if (f != null && f.exists())
|
if (f != null && f.exists())
|
||||||
fis = new FileInputStream(f);
|
fis = new FileInputStream(f);
|
||||||
else {
|
else {
|
||||||
File userSetting = new File(file.userPrefLoc);
|
File userSetting = new File(file.userPrefLoc);
|
||||||
fis = userSetting.exists() ? new FileInputStream(userSetting) : new FileInputStream(file.defaultLoc);
|
if ( userSetting.exists() ) {
|
||||||
|
usedCustomPrefsFile = true;
|
||||||
|
fis = new FileInputStream(userSetting);
|
||||||
|
} else {
|
||||||
|
fis = new FileInputStream(file.defaultLoc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
model = readLayout(inputFactory.createXMLEventReader(fis));
|
model = readLayout(inputFactory.createXMLEventReader(fis));
|
||||||
} catch (final Exception e) { e.printStackTrace(); }
|
} catch (final XMLStreamException e) {
|
||||||
|
if ( usedCustomPrefsFile ) // the one we can safely delete
|
||||||
|
throw new InvalidLayoutFileException();
|
||||||
|
else
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
// Apply new layout
|
// Apply new layout
|
||||||
DragCell cell = null;
|
DragCell cell = null;
|
||||||
@@ -170,8 +189,8 @@ public final class SLayoutIO {
|
|||||||
SResizingUtil.resizeWindow();
|
SResizingUtil.resizeWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MapOfLists<RectangleOfDouble, EDocID> readLayout(final XMLEventReader reader)
|
private static MapOfLists<RectangleOfDouble, EDocID> readLayout(final XMLEventReader reader) throws XMLStreamException
|
||||||
throws XMLStreamException {
|
{
|
||||||
XMLEvent event;
|
XMLEvent event;
|
||||||
StartElement element;
|
StartElement element;
|
||||||
Iterator<?> attributes;
|
Iterator<?> attributes;
|
||||||
|
|||||||
Reference in New Issue
Block a user