Refactor so profile props can be loaded for mobile game

This commit is contained in:
drdev
2014-06-05 19:21:50 +00:00
parent 8c1bd75c6b
commit 4f15de6639
7 changed files with 86 additions and 50 deletions

View File

@@ -53,8 +53,6 @@ import forge.interfaces.IButton;
import forge.interfaces.IGuiBase; import forge.interfaces.IGuiBase;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.match.input.InputQueue; import forge.match.input.InputQueue;
import forge.properties.ForgeConstants;
import forge.properties.ForgeProfileProperties;
import forge.screens.match.CMatchUI; import forge.screens.match.CMatchUI;
import forge.screens.match.VMatchUI; import forge.screens.match.VMatchUI;
import forge.screens.match.ViewWinLose; import forge.screens.match.ViewWinLose;
@@ -77,7 +75,12 @@ import forge.util.ITriggerEvent;
public class GuiDesktop implements IGuiBase { public class GuiDesktop implements IGuiBase {
private boolean showOverlay = true; private boolean showOverlay = true;
@Override
public boolean isRunningOnDesktop() {
return true;
}
@Override @Override
public void invokeInEdtLater(Runnable proc) { public void invokeInEdtLater(Runnable proc) {
SwingUtilities.invokeLater(proc); SwingUtilities.invokeLater(proc);
@@ -113,11 +116,6 @@ public class GuiDesktop implements IGuiBase {
"../forge-gui/" : ""; "../forge-gui/" : "";
} }
@Override
public ForgeProfileProperties getProfileProps() {
return new ForgeProfileProperties(ForgeConstants.PROFILE_FILE);
}
@Override @Override
public boolean mayShowCard(Card card) { public boolean mayShowCard(Card card) {
return Singletons.getControl().mayShowCard(card); return Singletons.getControl().mayShowCard(card);

View File

@@ -39,7 +39,6 @@ import forge.interfaces.IGuiBase;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.match.input.InputQueue; import forge.match.input.InputQueue;
import forge.properties.ForgeConstants; import forge.properties.ForgeConstants;
import forge.properties.ForgeProfileProperties;
import forge.screens.match.FControl; import forge.screens.match.FControl;
import forge.screens.match.views.VPhaseIndicator.PhaseLabel; import forge.screens.match.views.VPhaseIndicator.PhaseLabel;
import forge.screens.match.winlose.ViewWinLose; import forge.screens.match.winlose.ViewWinLose;
@@ -60,6 +59,11 @@ public class GuiMobile implements IGuiBase {
assetsDir = assetsDir0; assetsDir = assetsDir0;
} }
@Override
public boolean isRunningOnDesktop() {
return Gdx.app.getType() == ApplicationType.Desktop;
}
@Override @Override
public void invokeInEdtLater(Runnable proc) { public void invokeInEdtLater(Runnable proc) {
Gdx.app.postRunnable(proc); Gdx.app.postRunnable(proc);
@@ -90,15 +94,6 @@ public class GuiMobile implements IGuiBase {
return assetsDir; return assetsDir;
} }
@Override
public ForgeProfileProperties getProfileProps() {
if (Gdx.app.getType() == ApplicationType.Desktop) {
return new ForgeProfileProperties(ForgeConstants.PROFILE_FILE);
}
String assetsDir = ForgeConstants.ASSETS_DIR;
return new ForgeProfileProperties(assetsDir + "data/", assetsDir + "cache/");
}
@Override @Override
public boolean mayShowCard(Card card) { public boolean mayShowCard(Card card) {
return FControl.mayShowCard(card); return FControl.mayShowCard(card);

View File

@@ -24,8 +24,9 @@ public class FilesPage extends TabPage {
lstItems.setListItemRenderer(new FilesItemRenderer()); lstItems.setListItemRenderer(new FilesItemRenderer());
lstItems.addGroup("Content Downloaders"); lstItems.addGroup("Content Downloaders");
lstItems.addGroup("Storage Options");
//lstItems.addGroup("Data Import"); //lstItems.addGroup("Data Import");
//content downloaders //content downloaders
lstItems.addItem(new ContentDownloader("Download LQ Card Pictures", lstItems.addItem(new ContentDownloader("Download LQ Card Pictures",
"Download default card picture for each card.") { "Download default card picture for each card.") {
@@ -114,4 +115,18 @@ public class FilesPage extends TabPage {
} }
protected abstract GuiDownloadService createService(); protected abstract GuiDownloadService createService();
} }
private enum StorageOptions {
}
private class StorageOption extends FilesItem {
public StorageOption(String label0, String description0) {
super(label0, description0);
}
@Override
public void select() {
}
}
} }

View File

@@ -1,6 +1,7 @@
package forge.toolbox; package forge.toolbox;
import java.io.File; import java.io.File;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment; import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import forge.Forge.Graphics; import forge.Forge.Graphics;
@@ -11,20 +12,20 @@ import forge.toolbox.FEvent.FEventHandler;
import forge.util.Callback; import forge.util.Callback;
public class FFileChooser extends FDialog { public class FFileChooser extends FDialog {
public static void getFilename(String title0, boolean forSave0, Callback<File> callback0) { public static void getFilename(String title0, boolean forSave0, Callback<String> callback0) {
getFilename(title0, forSave0, null, "", callback0); getFilename(title0, forSave0, null, "", callback0);
} }
public static void getFilename(String title0, boolean forSave0, File baseDir0, Callback<File> callback0) { public static void getFilename(String title0, boolean forSave0, String baseDir0, Callback<String> callback0) {
getFilename(title0, forSave0, baseDir0, "", callback0); getFilename(title0, forSave0, baseDir0, "", callback0);
} }
public static void getFilename(String title0, boolean forSave0, File baseDir0, String defaultFilename0, Callback<File> callback0) { public static void getFilename(String title0, boolean forSave0, String baseDir0, String defaultFilename0, Callback<String> callback0) {
FFileChooser dialog = new FFileChooser(title0, forSave0, baseDir0, defaultFilename0, callback0); FFileChooser dialog = new FFileChooser(title0, forSave0, baseDir0, defaultFilename0, callback0);
dialog.show(); dialog.show();
} }
private final boolean forSave; private final boolean forSave;
private final File baseDir; private final File baseDir;
private final Callback<File> callback; private final Callback<String> callback;
private File currentDir; private File currentDir;
private final FList<File> lstFiles = add(new FileList()); private final FList<File> lstFiles = add(new FileList());
@@ -48,10 +49,10 @@ public class FFileChooser extends FDialog {
} }
})); }));
private FFileChooser(String title0, boolean forSave0, File baseDir0, String defaultFilename0, Callback<File> callback0) { private FFileChooser(String title0, boolean forSave0, String baseDir0, String defaultFilename0, Callback<String> callback0) {
super(title0); super(title0);
forSave = forSave0; forSave = forSave0;
baseDir = baseDir0; baseDir = new File(baseDir0);
currentDir = baseDir; currentDir = baseDir;
txtFilename.setText(defaultFilename0); txtFilename.setText(defaultFilename0);
callback = callback0; callback = callback0;
@@ -69,8 +70,29 @@ public class FFileChooser extends FDialog {
@Override @Override
protected float layoutAndGetHeight(float width, float maxHeight) { protected float layoutAndGetHeight(float width, float maxHeight) {
// TODO Auto-generated method stub float padding = FOptionPane.PADDING;
return 0; float w = width - 2 * padding;
//layout buttons
float gapBetweenButtons = padding / 2;
float buttonWidth = (w - gapBetweenButtons * 2) / 3;
float buttonHeight = FOptionPane.BUTTON_HEIGHT;
float x = padding;
float y = maxHeight - FOptionPane.GAP_BELOW_BUTTONS - buttonHeight;
btnNewFolder.setBounds(x, y, buttonWidth, buttonHeight);
x += buttonWidth + gapBetweenButtons;
btnOK.setBounds(x, y, buttonWidth, buttonHeight);
x += buttonWidth + gapBetweenButtons;
btnCancel.setBounds(x, y, buttonWidth, buttonHeight);
float fieldHeight = txtFilename.getHeight();
float listHeight = y - fieldHeight - 2 * padding;
x = padding;
y = padding;
txtFilename.setBounds(x, y, w, fieldHeight);
y += fieldHeight;
lstFiles.setBounds(x, y, w, listHeight);
return maxHeight;
} }
private void acceptSelectedFile() { private void acceptSelectedFile() {

View File

@@ -27,12 +27,12 @@ import forge.game.spellability.SpellAbility;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.match.input.InputQueue; import forge.match.input.InputQueue;
import forge.properties.ForgeProfileProperties;
import forge.sound.IAudioClip; import forge.sound.IAudioClip;
import forge.util.ITriggerEvent; import forge.util.ITriggerEvent;
public interface IGuiBase { public interface IGuiBase {
boolean isRunningOnDesktop();
void invokeInEdtLater(Runnable runnable); void invokeInEdtLater(Runnable runnable);
void invokeInEdtAndWait(final Runnable proc); void invokeInEdtAndWait(final Runnable proc);
boolean isGuiThread(); boolean isGuiThread();
@@ -86,7 +86,6 @@ public interface IGuiBase {
LobbyPlayer createAiPlayer(); LobbyPlayer createAiPlayer();
LobbyPlayer createAiPlayer(String name, int avatarIndex); LobbyPlayer createAiPlayer(String name, int avatarIndex);
LobbyPlayer getQuestPlayer(); LobbyPlayer getQuestPlayer();
ForgeProfileProperties getProfileProps();
IAudioClip createAudioClip(String filename); IAudioClip createAudioClip(String filename);
void startAltSoundSystem(String filename, boolean isSynchronized); void startAltSoundSystem(String filename, boolean isSynchronized);
void clearImageCache(); void clearImageCache();

View File

@@ -86,7 +86,7 @@ public final class ForgeConstants {
public static final Map<String, String> CACHE_CARD_PICS_SUBDIR; public static final Map<String, String> CACHE_CARD_PICS_SUBDIR;
public static final int SERVER_PORT_NUMBER; public static final int SERVER_PORT_NUMBER;
static { static {
ForgeProfileProperties profileProps = GuiBase.getInterface().getProfileProps(); ForgeProfileProperties profileProps = new ForgeProfileProperties();
USER_DIR = profileProps.userDir; USER_DIR = profileProps.userDir;
CACHE_DIR = profileProps.cacheDir; CACHE_DIR = profileProps.cacheDir;
CACHE_CARD_PICS_DIR = profileProps.cardPicsDir; CACHE_CARD_PICS_DIR = profileProps.cardPicsDir;

View File

@@ -17,6 +17,7 @@
*/ */
package forge.properties; package forge.properties;
import forge.GuiBase;
import forge.util.FileSection; import forge.util.FileSection;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -54,6 +55,26 @@ public class ForgeProfileProperties {
cardPicsDir = cacheDir + "pics/cards/"; cardPicsDir = cacheDir + "pics/cards/";
cardPicsSubDir = new HashMap<String, String>(); cardPicsSubDir = new HashMap<String, String>();
serverPort = 0; serverPort = 0;
}
public ForgeProfileProperties() {
Properties props = new Properties();
File propFile = new File(ForgeConstants.PROFILE_FILE);
try {
if (propFile.canRead()) {
props.load(new FileInputStream(propFile));
}
}
catch (IOException e) {
System.err.println("error while reading from profile properties file");
}
Pair<String, String> defaults = _getDefaultDirs();
userDir = _getDir(props, _USER_DIR_KEY, defaults.getLeft());
cacheDir = _getDir(props, _CACHE_DIR_KEY, defaults.getRight());
cardPicsDir = _getDir(props, _CARD_PICS_DIR_KEY, cacheDir + "pics/cards/");
cardPicsSubDir = _getMap(props, _CARD_PICS_SUB_DIRS_KEY);
serverPort = _getInt(props, _SERVER_PORT, 0);
//ensure directories exist //ensure directories exist
File dir = new File(userDir); File dir = new File(userDir);
@@ -66,25 +87,6 @@ public class ForgeProfileProperties {
} }
} }
public ForgeProfileProperties(String filename) {
Properties props = new Properties();
File propFile = new File(filename);
try {
if (propFile.canRead()) {
props.load(new FileInputStream(propFile));
}
} catch (IOException e) {
System.err.println("error while reading from profile properties file: " + filename);
}
Pair<String, String> defaults = _getDefaultDirs();
userDir = _getDir(props, _USER_DIR_KEY, defaults.getLeft());
cacheDir = _getDir(props, _CACHE_DIR_KEY, defaults.getRight());
cardPicsDir = _getDir(props, _CARD_PICS_DIR_KEY, cacheDir + "pics/cards/");
cardPicsSubDir = _getMap(props, _CARD_PICS_SUB_DIRS_KEY);
serverPort = _getInt(props, _SERVER_PORT, 0);
}
private Map<String,String> _getMap(Properties props, String propertyKey) { private Map<String,String> _getMap(Properties props, String propertyKey) {
String strMap = props.getProperty(propertyKey, "").trim(); String strMap = props.getProperty(propertyKey, "").trim();
return FileSection.parseToMap(strMap, "->", "|"); return FileSection.parseToMap(strMap, "->", "|");
@@ -113,9 +115,14 @@ public class ForgeProfileProperties {
} }
return retDir + File.separatorChar; return retDir + File.separatorChar;
} }
// returns a pair <userDir, cacheDir> // returns a pair <userDir, cacheDir>
private static Pair<String, String> _getDefaultDirs() { private static Pair<String, String> _getDefaultDirs() {
if (!GuiBase.getInterface().isRunningOnDesktop()) { //special case for mobile devices
String assetsDir = ForgeConstants.ASSETS_DIR;
return Pair.of(assetsDir + "data/", assetsDir + "cache/");
}
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
String homeDir = System.getProperty("user.home"); String homeDir = System.getProperty("user.home");