Refresh skins and fonts list after download them

This commit is contained in:
Lyu Zong-Hong
2021-03-06 09:32:18 +09:00
parent c721bd953b
commit 6ba389149c
5 changed files with 81 additions and 9 deletions

View File

@@ -446,6 +446,15 @@ public class FSkin {
}
public static Iterable<String> getAllSkins() {
if (allSkins != null) {
allSkins.clear();
allSkins.add("Default"); //init default
final Array<String> skinDirectoryNames = getSkinDirectoryNames();
for (final String skinDirectoryName : skinDirectoryNames) {
allSkins.add(WordUtil.capitalize(skinDirectoryName.replace('_', ' ')));
}
allSkins.sort();
}
return allSkins;
}

View File

@@ -24,7 +24,6 @@ import forge.util.LineReader;
import forge.util.TextBounds;
import forge.util.Utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -87,8 +86,13 @@ public class FSkinFont {
//delete all cached font files
public static void deleteCachedFiles() {
FileUtil.deleteDirectory(new File(ForgeConstants.FONTS_DIR));
FileUtil.ensureDirectoryExists(ForgeConstants.FONTS_DIR);
final FileHandle dir = Gdx.files.absolute(ForgeConstants.FONTS_DIR);
for (FileHandle fontFile : dir.list()) {
String name = fontFile.name();
if (name.endsWith(".fnt") || name.endsWith(".png")) {
fontFile.delete();
}
}
}
public static void updateAll() {

View File

@@ -91,6 +91,10 @@ public class FilesPage extends TabPage<SettingsScreen> {
protected GuiDownloadService createService() {
return new GuiDownloadSkins();
}
@Override
protected void finishCallback() {
SettingsScreen.getSettingsScreen().getSettingsPage().refreshSkinsList();
}
}, 0);
lstItems.addItem(new OptionContentDownloader(localizer.getMessage("btnDownloadCJKFonts"),
localizer.getMessage("lblDownloadCJKFonts"),
@@ -112,6 +116,10 @@ public class FilesPage extends TabPage<SettingsScreen> {
}
return categories;
}
@Override
protected void finishCallback() {
SettingsScreen.getSettingsScreen().getSettingsPage().refreshCJKFontsList();
}
}, 0);
//storage locations
final StorageOption cardPicsOption = new StorageOption(localizer.getMessage("lblCardPicsLocation"), ForgeProfileProperties.getCardPicsDir()) {
@@ -201,9 +209,19 @@ public class FilesPage extends TabPage<SettingsScreen> {
@Override
public void select() {
new GuiDownloader(createService()).show();
new GuiDownloader(createService(), new Callback<Boolean>() {
@Override
public void run(Boolean finished) {
if (finished) {
finishCallback();
}
}
}).show();
}
protected abstract GuiDownloadService createService();
protected void finishCallback() {
}
}
private abstract class OptionContentDownloader extends FilesItem {
@@ -222,11 +240,21 @@ public class FilesPage extends TabPage<SettingsScreen> {
public void run(String result) {
final String url = categories.get(result);
final String name = url.substring(url.lastIndexOf("/") + 1);
new GuiDownloader(new GuiDownloadZipService(name, name, url, ForgeConstants.FONTS_DIR, null, null)).show();
new GuiDownloader(new GuiDownloadZipService(name, name, url, ForgeConstants.FONTS_DIR, null, null), new Callback<Boolean>() {
@Override
public void run(Boolean finished) {
if (finished) {
finishCallback();
}
}
}).show();
}
});
}
protected abstract Map<String, String> getCategories();
protected void finishCallback() {
}
}
private abstract class StorageOption extends FilesItem {

View File

@@ -37,6 +37,8 @@ import java.util.List;
public class SettingsPage extends TabPage<SettingsScreen> {
private final FGroupList<Setting> lstSettings = add(new FGroupList<>());
private final CustomSelectSetting settingSkins;
private final CustomSelectSetting settingCJKFonts;
public SettingsPage() {
super(Localizer.getInstance().getMessage("lblSettings"), Forge.hdbuttons ? FSkinImage.HDPREFERENCE : FSkinImage.SETTINGS);
@@ -84,15 +86,16 @@ public class SettingsPage extends TabPage<SettingsScreen> {
});
}
}, 0);
lstSettings.addItem(new CustomSelectSetting(FPref.UI_SKIN, localizer.getMessage("lblTheme"),
settingSkins = new CustomSelectSetting(FPref.UI_SKIN, localizer.getMessage("lblTheme"),
localizer.getMessage("nlTheme"),
FSkin.getAllSkins()) {
@Override
public void valueChanged(String newValue) {
FSkin.changeSkin(newValue);
}
}, 0);
lstSettings.addItem(new CustomSelectSetting(FPref.UI_CJK_FONT, localizer.getMessage("lblCJKFont"),
};
lstSettings.addItem(settingSkins, 0);
settingCJKFonts = new CustomSelectSetting(FPref.UI_CJK_FONT, localizer.getMessage("lblCJKFont"),
localizer.getMessage("nlCJKFont"),
FSkinFont.getAllCJKFonts()) {
@Override
@@ -111,7 +114,8 @@ public class SettingsPage extends TabPage<SettingsScreen> {
}
super.valueChanged(newValue);
}
}, 0);
};
lstSettings.addItem(settingCJKFonts, 0);
lstSettings.addItem(new BooleanSetting(FPref.UI_LANDSCAPE_MODE,
localizer.getMessage("lblLandscapeMode"),
localizer.getMessage("nlLandscapeMode")) {
@@ -549,6 +553,14 @@ public class SettingsPage extends TabPage<SettingsScreen> {
7);*/
}
public void refreshSkinsList() {
settingSkins.updateOptions(FSkin.getAllSkins());
}
public void refreshCJKFontsList() {
settingCJKFonts.updateOptions(FSkinFont.getAllCJKFonts());
}
@Override
protected void doLayout(float width, float height) {
lstSettings.setBounds(0, 0, width, height);
@@ -618,6 +630,15 @@ public class SettingsPage extends TabPage<SettingsScreen> {
FModel.getPreferences().save();
}
public void updateOptions(Iterable<String> options0) {
options.clear();
if (options0 != null) {
for (String option : options0) {
options.add(option);
}
}
}
@Override
public void select() {
Forge.openScreen(new CustomSelectScreen());

View File

@@ -19,6 +19,7 @@ public class SettingsScreen extends TabPageScreen<SettingsScreen> {
private static boolean fromHomeScreen;
private static SettingsScreen settingsScreen; //keep settings screen around so scroll positions maintained
private final SettingsPage settingsPage;
public static void show(boolean fromHomeScreen0) {
if (settingsScreen == null) {
@@ -40,6 +41,14 @@ public class SettingsScreen extends TabPageScreen<SettingsScreen> {
return insets;
}
public SettingsPage getSettingsPage() {
return settingsPage;
}
public static SettingsScreen getSettingsScreen() {
return settingsScreen;
}
@SuppressWarnings("unchecked")
private SettingsScreen() {
super(new TabHeader<SettingsScreen>(new TabPage[] {
@@ -51,6 +60,7 @@ public class SettingsScreen extends TabPageScreen<SettingsScreen> {
return !fromHomeScreen; //don't show back button if launched from home screen
}
});
settingsPage = (SettingsPage) tabPages[0];
}
public FScreen getLandscapeBackdropScreen() {