Commit 907a7c0a authored by fallenstardust's avatar fallenstardust

设置里可切换资料语言

parent 33b5f64d
......@@ -60,7 +60,7 @@
27204311
27204311
82385847
14532163
20899496
20899496
20899496
69946549
......
package cn.garymb.ygomobile;
import static cn.garymb.ygomobile.Constants.ASSETS_EN;
import static cn.garymb.ygomobile.Constants.ASSETS_KOR;
import static cn.garymb.ygomobile.Constants.BOT_CONF;
import static cn.garymb.ygomobile.Constants.CORE_BOT_CONF_PATH;
import static cn.garymb.ygomobile.Constants.CORE_DECK_PATH;
import static cn.garymb.ygomobile.Constants.CORE_EXPANSIONS;
import static cn.garymb.ygomobile.Constants.CORE_LIMIT_PATH;
import static cn.garymb.ygomobile.Constants.CORE_PACK_PATH;
import static cn.garymb.ygomobile.Constants.CORE_REPLAY_PATH;
import static cn.garymb.ygomobile.Constants.CORE_SINGLE_PATH;
import static cn.garymb.ygomobile.Constants.CORE_STRING_PATH;
import static cn.garymb.ygomobile.Constants.CORE_SYSTEM_PATH;
import static cn.garymb.ygomobile.Constants.DATABASE_NAME;
import static cn.garymb.ygomobile.Constants.DEF_PREF_FONT_SIZE;
import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE;
import static cn.garymb.ygomobile.Constants.DEF_PREF_NOTCH_HEIGHT;
......@@ -24,6 +32,7 @@ import static cn.garymb.ygomobile.Constants.PREF_WINDOW_TOP_BOTTOM;
import static cn.garymb.ygomobile.Constants.WINDBOT_DECK_PATH;
import static cn.garymb.ygomobile.Constants.WINDBOT_PATH;
import static cn.garymb.ygomobile.Constants.YDK_FILE_EX;
import static cn.garymb.ygomobile.ui.home.ResCheckTask.getDatapath;
import android.annotation.SuppressLint;
import android.content.Context;
......@@ -37,6 +46,7 @@ import androidx.annotation.Nullable;
import org.json.JSONArray;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -47,6 +57,7 @@ import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.settings.PreferenceFragmentPlus;
import cn.garymb.ygomobile.utils.DeckUtil;
import cn.garymb.ygomobile.utils.DensityUtils;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
public class AppsSettings {
......@@ -224,10 +235,10 @@ public class AppsSettings {
}
public File[] getExpansionFiles(){
public File[] getExpansionFiles() {
return new File(AppsSettings.get().getResourcePath(), Constants.CORE_EXPANSIONS)
.listFiles((file) -> {
if(!file.isFile()){
if (!file.isFile()) {
return false;
}
String s_name = file.getName().toLowerCase();
......@@ -355,6 +366,23 @@ public class AppsSettings {
mSharedPreferences.putString(Constants.PREF_IMAGE_QUALITY, "" + quality);
}
/***
* 资料语言
*/
public void setDataLanguage(int language) {
mSharedPreferences.putString(Constants.PREF_DATA_LANGUAGE, "" + language);
}
/***
* 资料语言
*/
public int getDataLanguage() {
try {
return Integer.valueOf(mSharedPreferences.getString(Constants.PREF_DATA_LANGUAGE, "" + Constants.PREF_DEF_DATA_LANGUAGE));
} catch (Exception e) {
return Constants.PREF_DEF_DATA_LANGUAGE;
}
}
/**
* 根据卡密获取卡图的路径
......@@ -687,4 +715,68 @@ public class AppsSettings {
// Log.i("kk", "saveTemp:" + array);
mSharedPreferences.putString(Constants.PREF_LAST_ROOM_LIST, array.toString());
}
public void copyCnData() throws IOException {
//复制数据库
copyCdbFile(getDatapath(DATABASE_NAME));
//复制游戏配置文件
IOUtils.copyFilesFromAssets(context, getDatapath("conf") + "/" + CORE_STRING_PATH, getResourcePath(), true);
IOUtils.copyFilesFromAssets(context, getDatapath("conf") + "/" + BOT_CONF, getResourcePath(), true);
//替换换行符
String stringConfPath = new File(AppsSettings.get().getResourcePath(), CORE_STRING_PATH).getAbsolutePath();
String botConfPath = new File(AppsSettings.get().getResourcePath(), BOT_CONF).getAbsolutePath();
fixString(stringConfPath);
fixString(botConfPath);
//设置语言为0=中文
AppsSettings.get().setDataLanguage(0);
}
public void copyKorData() throws IOException {
String korStringConf = ASSETS_KOR + getDatapath("conf") + "/" + CORE_STRING_PATH;
String korBotConf = ASSETS_KOR + getDatapath("conf") + "/" + CORE_BOT_CONF_PATH;
String korCdb = ASSETS_KOR + getDatapath(DATABASE_NAME);
//复制数据库
copyCdbFile(korCdb);
//复制游戏配置文件
IOUtils.copyFilesFromAssets(context, korStringConf, getResourcePath(), true);
IOUtils.copyFilesFromAssets(context, korBotConf, getResourcePath(), true);
//替换换行符
String stringConfPath = new File(AppsSettings.get().getResourcePath(), CORE_STRING_PATH).getAbsolutePath();
String botConfPath = new File(AppsSettings.get().getResourcePath(), BOT_CONF).getAbsolutePath();
fixString(stringConfPath);
fixString(botConfPath);
//设置语言为1=조선말
AppsSettings.get().setDataLanguage(1);
}
public void copyEnData() throws IOException {
String enStringConf = ASSETS_EN + getDatapath("conf") + "/" + CORE_STRING_PATH;
String enBotConf = ASSETS_EN + getDatapath("conf") + "/" + CORE_BOT_CONF_PATH;
String enCdb = ASSETS_EN + getDatapath(DATABASE_NAME);
//复制数据库
copyCdbFile(enCdb);
//复制人机资源
IOUtils.copyFilesFromAssets(context, getDatapath(Constants.WINDBOT_PATH), getResourcePath(), true);
//复制游戏配置文件
IOUtils.copyFilesFromAssets(context, enStringConf, getResourcePath(), true);
IOUtils.copyFilesFromAssets(context, enBotConf, getResourcePath(), true);
//替换换行符
String stringConfPath = new File(AppsSettings.get().getResourcePath(), CORE_STRING_PATH).getAbsolutePath();
String botConfPath = new File(AppsSettings.get().getResourcePath(), BOT_CONF).getAbsolutePath();
fixString(stringConfPath);
fixString(botConfPath);
//设置语言为2=English
AppsSettings.get().setDataLanguage(2);
}
private void fixString(String stringPath) {
List<String> lines = FileUtils.readLines(stringPath, Constants.DEF_ENCODING);
FileUtils.writeLines(stringPath, lines, Constants.DEF_ENCODING, "\n");
}
private void copyCdbFile(String cdbPath) throws IOException {
File dbFile = new File(getDataBasePath(), DATABASE_NAME);
if (dbFile.exists()) dbFile.delete();//如果数据库存在先删除
IOUtils.copyFilesFromAssets(context, cdbPath, getDataBasePath(), true);
}
}
......@@ -20,6 +20,8 @@ public interface Constants {
String PREF_IMAGE_QUALITY = "pref_key_game_image_quality";
int PREF_DEF_IMAGE_QUALITY = 1;
String PREF_DATA_LANGUAGE = "pref_key_game_data_language";
int PREF_DEF_DATA_LANGUAGE = 0;
String PREF_GAME_FONT = "pref_key_game_font_name";
String PREF_USE_EXTRA_CARD_CARDS = "settings_game_diy_card_db";
boolean PREF_DEF_USE_EXTRA_CARD_CARDS = true;
......
......@@ -33,7 +33,6 @@ import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.ourygo.lib.duelassistant.listener.OnDuelAssistantListener;
import com.ourygo.lib.duelassistant.util.DuelAssistantManagement;
import com.ourygo.lib.duelassistant.util.Util;
......@@ -64,8 +63,8 @@ import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.bean.ServerInfo;
import cn.garymb.ygomobile.bean.ServerList;
import cn.garymb.ygomobile.bean.events.ServerInfoEvent;
import cn.garymb.ygomobile.ex_card.ExCardActivity;
import cn.garymb.ygomobile.ex_card.ExCard;
import cn.garymb.ygomobile.ex_card.ExCardActivity;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.ImageLoader;
......
......@@ -274,6 +274,9 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.CORE_PICS_ZIP),
resPath, needsUpdate);
}
//复制人机资源
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH), mSettings.getResourcePath(), needsUpdate);
//根据系统语言复制特定资料文件
String language = mContext.getResources().getConfiguration().locale.getLanguage();
Log.i(BuildConfig.VERSION_NAME,language);
if(!language.isEmpty()){
......@@ -297,22 +300,21 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
return ERROR_NONE;
}
private int copyCnData(Boolean needsUpdate) throws IOException {
public int copyCnData(Boolean needsUpdate) throws IOException {
//复制数据库
copyCdbFile(getDatapath(DATABASE_NAME), needsUpdate);
//复制残局
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.single_lua)));
IOUtils.copyFilesFromAssets(mContext, getDatapath(CORE_SINGLE_PATH), mSettings.getSingleDir(), needsUpdate);
//复制人机资源
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH), mSettings.getResourcePath(), needsUpdate);
//复制游戏配置文件
copyCoreConfig(getDatapath("conf") + "/" + CORE_STRING_PATH,
getDatapath("conf") + "/" + BOT_CONF,
mSettings.getResourcePath(), needsUpdate);
AppsSettings.get().setDataLanguage(0);
return ERROR_NONE;
}
private int copyEnData(Boolean needsUpdate) throws IOException {
public int copyEnData(Boolean needsUpdate) throws IOException {
String enStringConf = ASSETS_EN + getDatapath("conf") + "/" + CORE_STRING_PATH;
String enBotConf = ASSETS_EN + getDatapath("conf") + "/" + CORE_BOT_CONF_PATH;
String enCdb = ASSETS_EN + getDatapath(DATABASE_NAME);
......@@ -322,29 +324,25 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
//复制残局
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.single_lua)));
IOUtils.copyFilesFromAssets(mContext, enSingle, mSettings.getSingleDir(), needsUpdate);
//复制人机资源
IOUtils.copyFilesFromAssets(mContext, getDatapath(Constants.WINDBOT_PATH), mSettings.getResourcePath(), needsUpdate);
//复制游戏配置文件
copyCoreConfig(enStringConf, enBotConf, mSettings.getResourcePath(), needsUpdate);
AppsSettings.get().setDataLanguage(1);
return ERROR_NONE;
}
private int copyKorData(Boolean needsUpdate) throws IOException {
public int copyKorData(Boolean needsUpdate) throws IOException {
String korStringConf = ASSETS_KOR + getDatapath("conf") + "/" + CORE_STRING_PATH;
String korBotConf = ASSETS_KOR + getDatapath("conf") + "/" + CORE_BOT_CONF_PATH;
String korCdb = ASSETS_KOR + getDatapath(DATABASE_NAME);
String korWindbotPath = ASSETS_KOR + getDatapath(WINDBOT_PATH);
String korSingle = ASSETS_EN + getDatapath(CORE_SINGLE_PATH);
//复制数据库
copyCdbFile(korCdb, true);
//复制残局
setMessage(mContext.getString(R.string.check_things, mContext.getString(R.string.single_lua)));
IOUtils.copyFilesFromAssets(mContext, korSingle, mSettings.getSingleDir(), needsUpdate);
//复制人机资源
IOUtils.copyFilesFromAssets(mContext, korWindbotPath, mSettings.getResourcePath(), needsUpdate);
//复制游戏配置文件
copyCoreConfig(korStringConf, korBotConf, mSettings.getResourcePath(), needsUpdate);
AppsSettings.get().setDataLanguage(2);
return ERROR_NONE;
}
......
......@@ -10,6 +10,7 @@ import static cn.garymb.ygomobile.Constants.ORI_REPLAY;
import static cn.garymb.ygomobile.Constants.PERF_TEST_REPLACE_KERNEL;
import static cn.garymb.ygomobile.Constants.PREF_CHANGE_LOG;
import static cn.garymb.ygomobile.Constants.PREF_CHECK_UPDATE;
import static cn.garymb.ygomobile.Constants.PREF_DATA_LANGUAGE;
import static cn.garymb.ygomobile.Constants.PREF_DECK_DELETE_DILAOG;
import static cn.garymb.ygomobile.Constants.PREF_DEL_EX;
import static cn.garymb.ygomobile.Constants.PREF_FONT_ANTIALIAS;
......@@ -39,6 +40,7 @@ import static cn.garymb.ygomobile.ui.home.ResCheckTask.getDatapath;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
......@@ -78,6 +80,7 @@ import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.adapters.SimpleListAdapter;
import cn.garymb.ygomobile.ui.home.MainActivity;
import cn.garymb.ygomobile.ui.home.ResCheckTask;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.FileUtils;
......@@ -165,6 +168,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
bind(PREF_DEL_EX, getString(R.string.about_delete_ex));
bind(PERF_TEST_REPLACE_KERNEL, "需root权限,请在开发者的指导下食用");
bind(PREF_WINDOW_TOP_BOTTOM, "" + mSettings.getScreenPadding());
bind(PREF_DATA_LANGUAGE, "" + mSettings.getDataLanguage());
Preference preference = findPreference(PREF_READ_EX);
if (preference != null) {
preference.setSummary(mSettings.getExpansionsPath().getAbsolutePath());
......@@ -229,6 +233,31 @@ public class SettingFragment extends PreferenceFragmentPlus {
if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference;
mSharedPreferences.edit().putString(preference.getKey(), listPreference.getValue()).apply();
if (preference.getKey().equals(PREF_DATA_LANGUAGE)) {
Log.i(BuildConfig.VERSION_NAME, mSettings.getDataLanguage()+"xxxx");
if (mSettings.getDataLanguage() == 0) {
try {
mSettings.copyCnData();
} catch (IOException e) {
e.printStackTrace();
}
}
if (mSettings.getDataLanguage() == 1) {
try {
mSettings.copyKorData();
} catch (IOException e) {
e.printStackTrace();
}
}
if (mSettings.getDataLanguage() == 2) {
try {
mSettings.copyEnData();
} catch (IOException e) {
e.printStackTrace();
}
}
DataManager.get().load(true);
}
} else {
mSharedPreferences.edit().putString(preference.getKey(), "" + value).apply();
}
......
......@@ -75,6 +75,11 @@
<item>낮음</item>
<item>높음</item>
</string-array>
<string-array name="data_language" translatable="false">
<item>简体中文</item>
<item>조선말</item>
<item>English</item>
</string-array>
<!-- settings -->
<string name="server_list">다이렉트 듀얼</string>
<string name="server_name">이름:</string>
......@@ -334,4 +339,5 @@
<string name="edit_your_message">메시지를 입력하십시오</string>
<string name="login_succeed">채팅 방에 로그인되었습니다</string>
<string name="reChatJoining">다시 로그인 중\.\.\.</string>
<string name="settings_data_language">언어</string>
</resources>
......@@ -75,6 +75,11 @@
<item></item>
<item></item>
</string-array>
<string-array name="data_language" translatable="false">
<item>简体中文</item>
<item>조선말</item>
<item>English</item>
</string-array>
<!-- settings -->
<string name="server_list">直连决斗</string>
<string name="server_name">名称:</string>
......@@ -334,4 +339,5 @@
<string name="edit_your_message">输入聊天内容</string>
<string name="login_succeed">登录成功</string>
<string name="reChatJoining">连接断开,重新登陆中……</string>
<string name="settings_data_language">资料语言</string>
</resources>
......@@ -9,6 +9,11 @@
<item>0</item>
<item>1</item>
</string-array>
<string-array name="data_language_value" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="screen_top_bottom_value" translatable="false">
<item>0</item>
<item>5</item>
......
......@@ -84,6 +84,11 @@
<item>Speed</item>
<item>Quality</item>
</string-array>
<string-array name="data_language" translatable="false">
<item>简体中文</item>
<item>조선말</item>
<item>English</item>
</string-array>
<string-array name="screen_top_bottom_desc" translatable="false">
<item>Disable</item>
<item>5</item>
......@@ -344,4 +349,5 @@
<string name="edit_your_message">Input your message</string>
<string name="login_succeed">Chatroom logined</string>
<string name="reChatJoining">relogining\.\.\.</string>
<string name="settings_data_language">Language</string>
</resources>
......@@ -129,6 +129,13 @@
android:persistent="true"
android:title="@string/settings_game_font_name" />
<ListPreference
android:entries="@array/data_language"
android:entryValues="@array/data_language_value"
android:key="pref_key_game_data_language"
android:persistent="true"
android:title="@string/settings_data_language" />
<!--<CheckBoxPreference
android:key="settings_game_diy_card_db"
android:persistent="true"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment