mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Refactor so profile props can be loaded for mobile game
This commit is contained in:
@@ -53,8 +53,6 @@ import forge.interfaces.IButton;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.item.PaperCard;
|
||||
import forge.match.input.InputQueue;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.properties.ForgeProfileProperties;
|
||||
import forge.screens.match.CMatchUI;
|
||||
import forge.screens.match.VMatchUI;
|
||||
import forge.screens.match.ViewWinLose;
|
||||
@@ -77,7 +75,12 @@ import forge.util.ITriggerEvent;
|
||||
public class GuiDesktop implements IGuiBase {
|
||||
|
||||
private boolean showOverlay = true;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isRunningOnDesktop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invokeInEdtLater(Runnable proc) {
|
||||
SwingUtilities.invokeLater(proc);
|
||||
@@ -113,11 +116,6 @@ public class GuiDesktop implements IGuiBase {
|
||||
"../forge-gui/" : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeProfileProperties getProfileProps() {
|
||||
return new ForgeProfileProperties(ForgeConstants.PROFILE_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayShowCard(Card card) {
|
||||
return Singletons.getControl().mayShowCard(card);
|
||||
|
||||
@@ -39,7 +39,6 @@ import forge.interfaces.IGuiBase;
|
||||
import forge.item.PaperCard;
|
||||
import forge.match.input.InputQueue;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.properties.ForgeProfileProperties;
|
||||
import forge.screens.match.FControl;
|
||||
import forge.screens.match.views.VPhaseIndicator.PhaseLabel;
|
||||
import forge.screens.match.winlose.ViewWinLose;
|
||||
@@ -60,6 +59,11 @@ public class GuiMobile implements IGuiBase {
|
||||
assetsDir = assetsDir0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunningOnDesktop() {
|
||||
return Gdx.app.getType() == ApplicationType.Desktop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invokeInEdtLater(Runnable proc) {
|
||||
Gdx.app.postRunnable(proc);
|
||||
@@ -90,15 +94,6 @@ public class GuiMobile implements IGuiBase {
|
||||
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
|
||||
public boolean mayShowCard(Card card) {
|
||||
return FControl.mayShowCard(card);
|
||||
|
||||
@@ -24,8 +24,9 @@ public class FilesPage extends TabPage {
|
||||
lstItems.setListItemRenderer(new FilesItemRenderer());
|
||||
|
||||
lstItems.addGroup("Content Downloaders");
|
||||
lstItems.addGroup("Storage Options");
|
||||
//lstItems.addGroup("Data Import");
|
||||
|
||||
|
||||
//content downloaders
|
||||
lstItems.addItem(new ContentDownloader("Download LQ Card Pictures",
|
||||
"Download default card picture for each card.") {
|
||||
@@ -114,4 +115,18 @@ public class FilesPage extends TabPage {
|
||||
}
|
||||
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() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.toolbox;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
@@ -11,20 +12,20 @@ import forge.toolbox.FEvent.FEventHandler;
|
||||
import forge.util.Callback;
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private final boolean forSave;
|
||||
private final File baseDir;
|
||||
private final Callback<File> callback;
|
||||
private final Callback<String> callback;
|
||||
private File currentDir;
|
||||
|
||||
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);
|
||||
forSave = forSave0;
|
||||
baseDir = baseDir0;
|
||||
baseDir = new File(baseDir0);
|
||||
currentDir = baseDir;
|
||||
txtFilename.setText(defaultFilename0);
|
||||
callback = callback0;
|
||||
@@ -69,8 +70,29 @@ public class FFileChooser extends FDialog {
|
||||
|
||||
@Override
|
||||
protected float layoutAndGetHeight(float width, float maxHeight) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
float padding = FOptionPane.PADDING;
|
||||
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() {
|
||||
|
||||
@@ -27,12 +27,12 @@ import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.item.PaperCard;
|
||||
import forge.match.input.InputQueue;
|
||||
import forge.properties.ForgeProfileProperties;
|
||||
import forge.sound.IAudioClip;
|
||||
import forge.util.ITriggerEvent;
|
||||
|
||||
|
||||
public interface IGuiBase {
|
||||
boolean isRunningOnDesktop();
|
||||
void invokeInEdtLater(Runnable runnable);
|
||||
void invokeInEdtAndWait(final Runnable proc);
|
||||
boolean isGuiThread();
|
||||
@@ -86,7 +86,6 @@ public interface IGuiBase {
|
||||
LobbyPlayer createAiPlayer();
|
||||
LobbyPlayer createAiPlayer(String name, int avatarIndex);
|
||||
LobbyPlayer getQuestPlayer();
|
||||
ForgeProfileProperties getProfileProps();
|
||||
IAudioClip createAudioClip(String filename);
|
||||
void startAltSoundSystem(String filename, boolean isSynchronized);
|
||||
void clearImageCache();
|
||||
|
||||
@@ -86,7 +86,7 @@ public final class ForgeConstants {
|
||||
public static final Map<String, String> CACHE_CARD_PICS_SUBDIR;
|
||||
public static final int SERVER_PORT_NUMBER;
|
||||
static {
|
||||
ForgeProfileProperties profileProps = GuiBase.getInterface().getProfileProps();
|
||||
ForgeProfileProperties profileProps = new ForgeProfileProperties();
|
||||
USER_DIR = profileProps.userDir;
|
||||
CACHE_DIR = profileProps.cacheDir;
|
||||
CACHE_CARD_PICS_DIR = profileProps.cardPicsDir;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package forge.properties;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.util.FileSection;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -54,6 +55,26 @@ public class ForgeProfileProperties {
|
||||
cardPicsDir = cacheDir + "pics/cards/";
|
||||
cardPicsSubDir = new HashMap<String, String>();
|
||||
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
|
||||
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) {
|
||||
String strMap = props.getProperty(propertyKey, "").trim();
|
||||
return FileSection.parseToMap(strMap, "->", "|");
|
||||
@@ -113,9 +115,14 @@ public class ForgeProfileProperties {
|
||||
}
|
||||
return retDir + File.separatorChar;
|
||||
}
|
||||
|
||||
|
||||
// returns a pair <userDir, cacheDir>
|
||||
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 homeDir = System.getProperty("user.home");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user