Commit ba20b83a authored by fallenstardust's avatar fallenstardust

保存与读取最后选择的禁卡表名称

parent 9d0c306c
......@@ -157,13 +157,19 @@ void DeckBuilder::Terminate() {
BufferIO::CopyWideString(mainGame->cbDBCategory->getItem(catesel), mainGame->gameConf.lastcategory);
BufferIO::EncodeUTF8(mainGame->gameConf.lastcategory, linebuf);
irr::android::setLastCategory(mainGame->appMain, linebuf);
//irr:os::Printer::log("setLastCategory", linebuf);
ALOGD("setLastCategory", linebuf);
int decksel = mainGame->cbDBDecks->getSelected();
if (decksel >= 0)
BufferIO::CopyWideString(mainGame->cbDBDecks->getItem(decksel), mainGame->gameConf.lastdeck);
BufferIO::EncodeUTF8(mainGame->gameConf.lastdeck, linebuf);
irr::android::setLastDeck(mainGame->appMain, linebuf);
//os::Printer::log("setLastDeck", linebuf);
ALOGD("setLastDeck", linebuf);
int Lflistsel = mainGame->cbLFlist->getSelected();
if (Lflistsel >= 0)
BufferIO::CopyWideString(mainGame->cbLFlist->getItem(Lflistsel), mainGame->gameConf.last_limit_list_name);
BufferIO::EncodeUTF8(mainGame->gameConf.last_limit_list_name, linebuf);
irr::android::setLastLimit(mainGame->appMain, linebuf);
ALOGD("setLastLimit", linebuf);
mainGame->SaveConfig();
if(exit_on_return)
mainGame->OnGameClose();
......@@ -375,7 +381,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case BUTTON_MANAGE_DECK: {
if(is_modified && !readonly && !mainGame->chkIgnoreDeckChanges->isChecked()) {
mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stQMessage, 370 * mainGame->xScale, mainGame->guiFont, dataManager.GetSysString(1356));
mainGame->SetStaticText(mainGame->stQMessage, 370 * mainGame->xScale, mainGame->guiFont, dataManager.GetSysString(1356)/*此操作将放弃对当前卡组的修改,是否继续?*/);
mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.unlock();
prev_operation = id;
......@@ -386,7 +392,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
}
case BUTTON_NEW_CATEGORY: {
mainGame->gMutex.lock();
mainGame->stDMMessage->setText(dataManager.GetSysString(1469));
mainGame->stDMMessage->setText(dataManager.GetSysString(1469)/*请输入分类名:*/);
mainGame->ebDMName->setVisible(true);
mainGame->ebDMName->setText(L"");
mainGame->PopupElement(mainGame->wDMQuery);
......
......@@ -2095,8 +2095,28 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
case CHECKBOX_LFLIST: {
mainGame->gameConf.use_lflist = mainGame->chkLFlist->isChecked() ? 1 : 0;
mainGame->cbLFlist->setEnabled(mainGame->gameConf.use_lflist);
// 获取保存的最后禁卡表名称
wchar_t lastLimitName[256];
BufferIO::CopyWideString(mainGame->gameConf.last_limit_list_name, lastLimitName);
// 在禁卡表列表中查找匹配的名称
int selectedIndex = -1;
for (unsigned int i = 0; i < mainGame->cbLFlist->getItemCount(); i++) {
if (!wcscmp(lastLimitName, mainGame->cbLFlist->getItem(i))) {
selectedIndex = i;
break;
}
}
// 如果找到了匹配的名称,则设置选中项,否则使用默认选项
if (selectedIndex >= 0) {
mainGame->cbLFlist->setSelected(selectedIndex);
mainGame->cbHostLFlist->setSelected(selectedIndex);
} else {
// 回退到原来的逻辑
mainGame->cbLFlist->setSelected(mainGame->gameConf.use_lflist ? mainGame->gameConf.default_lflist : mainGame->cbLFlist->getItemCount() - 1);
mainGame->cbHostLFlist->setSelected(mainGame->gameConf.use_lflist ? mainGame->gameConf.default_lflist : mainGame->cbHostLFlist->getItemCount() - 1);
}
mainGame->deckBuilder.filterList = &deckManager._lfList[mainGame->cbLFlist->getSelected()];
return true;
break;
......
......@@ -65,6 +65,7 @@ struct Config {
wchar_t gamename[20]{};
wchar_t roompass[20]{};
//path
wchar_t last_limit_list_name[256]{};
wchar_t lastcategory[256]{};
wchar_t lastdeck[256]{};
wchar_t textfont[256]{};
......
......@@ -415,6 +415,11 @@ irr::io::path getLastDeck(ANDROID_APP app) {
return getSetting(app, "lastdeck");
}
//Retrive last limit list name.
irr::io::path getLastLimit(ANDROID_APP app) {
return getSetting(app, "lastlimit");
}
//Retrive last category name.
irr::io::path getLastCategory(ANDROID_APP app) {
return getSetting(app, "lastcategory");
......@@ -455,6 +460,11 @@ irr::io::path getSetting(ANDROID_APP app, const char* key) {
return ret;
}
//save last limit name.
void setLastLimit(ANDROID_APP app, const char* limitname) {
saveSetting(app, "lastlimit", limitname);
}
//save last deck name.
void setLastDeck(ANDROID_APP app, const char* deckname) {
saveSetting(app, "lastdeck", deckname);
......
......@@ -159,6 +159,9 @@ extern float getYScale(ANDROID_APP app);
//Retrive font path.
extern irr::io::path getFontPath(ANDROID_APP app);
//Retrive last limit name.
extern irr::io::path getLastLimit(ANDROID_APP app);
//Retrive last deck name.
extern irr::io::path getLastDeck(ANDROID_APP app);
......@@ -169,6 +172,9 @@ extern int getIntSetting(ANDROID_APP app, const char* key,int defvalue);
extern irr::io::path getSetting(ANDROID_APP app, const char* key);
//save last limit name.
extern void setLastLimit(ANDROID_APP app, const char* limitname);
//save last deck name.
extern void setLastDeck(ANDROID_APP app, const char* deckname);
......
......@@ -54,6 +54,7 @@ import org.json.JSONArray;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -611,10 +612,24 @@ public class AppsSettings {
return mSharedPreferences.getBoolean(PREF_SENSOR_REFRESH, PREF_DEF_SENSOR_REFRESH);
}
public String getCurLastDeck() {
return mSharedPreferences.getString(Constants.PREF_DEF_LAST_YDK, null);
/**
* 保存最后禁卡表名
*
*/
public void setLastLimit(String limitname) {
mSharedPreferences.putString(Constants.PREF_LAST_LIMIT, limitname);
}
/**
* 获取最后选择的限制条件
*
* @return 返回存储的限制条件字符串,如果未找到则返回默认限制条件
*/
public String getLastLimit() {
return mSharedPreferences.getString(Constants.PREF_LAST_LIMIT, Constants.PREF_DEF_LAST_LIMIT);
}
/**
* 获得(最后)上次打开的卡组的绝对路径
* setCurDeck()方法负责设置上次打开的卡组的路径
......@@ -625,13 +640,13 @@ public class AppsSettings {
String getLastDeckPath() {
String path;
if (TextUtils.equals(context.getString(R.string.category_pack), getLastCategory())) {
path = getResourcePath() + "/" + CORE_PACK_PATH + "/" + getLastDeckName() + YDK_FILE_EX;
path = Paths.get(getResourcePath(), CORE_PACK_PATH, getLastDeckName() + YDK_FILE_EX).toString();
} else if (TextUtils.equals(context.getString(R.string.category_windbot_deck), getLastCategory())) {
path = getResourcePath() + "/" + WINDBOT_PATH + "/" + WINDBOT_DECK_PATH + "/" + getLastDeckName() + YDK_FILE_EX;
path = Paths.get(getResourcePath(), WINDBOT_PATH, WINDBOT_DECK_PATH, getLastDeckName() + YDK_FILE_EX).toString();
} else if (TextUtils.equals(context.getString(R.string.category_Uncategorized), getLastCategory())) {
path = getResourcePath() + "/" + CORE_DECK_PATH + "/" + getLastDeckName() + YDK_FILE_EX;
path = Paths.get(getResourcePath(), CORE_DECK_PATH, getLastDeckName() + YDK_FILE_EX).toString();
} else {
path = getResourcePath() + "/" + CORE_DECK_PATH + "/" + getLastCategory() + "/" + getLastDeckName() + YDK_FILE_EX;
path = Paths.get(getResourcePath(), CORE_DECK_PATH, getLastCategory(), getLastDeckName() + YDK_FILE_EX).toString();
}
Log.e(TAG, "拼接最后路径" + path);
return path;
......
......@@ -8,6 +8,8 @@ import cn.garymb.ygomobile.lite.BuildConfig;
public interface Constants {
boolean DEBUG = BuildConfig.DEBUG;
String PREF_START = "game_pref_";
String PREF_LAST_LIMIT = "pref_last_limit";
String PREF_DEF_LAST_LIMIT = "";
String PREF_LAST_DECK_PATH = "pref_last_deck_path";
String PREF_LAST_YDK = "pref_last_ydk";
String PREF_DEF_LAST_YDK = "new";
......
......@@ -11,10 +11,12 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.CardSort;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.SharedPreferenceUtil;
import ocgcore.CardManager;
import ocgcore.DataManager;
import ocgcore.LimitManager;
......@@ -49,12 +51,16 @@ public class CardLoader implements ICardSearcher {
public CardLoader() {
mLimitManager = DataManager.get().getLimitManager();
mCardManager = DataManager.get().getCardManager();
mLimitList = mLimitManager.getTopLimit();
// 读取上次使用的LimitList,如果有非空值存在且和禁卡表列表中有相同名称对应,则使用,否则设置第一个禁卡表
mLimitList = mLimitManager.getLastLimit();
}
@Override
public void setLimitList(LimitList limitList) {
mLimitList = limitList;
if (limitList != null)
AppsSettings.get().setLastLimit(limitList.getName());
if (mCallBack != null) {
mCallBack.onLimitListChanged(limitList);
}
......
......@@ -74,7 +74,7 @@ public class DeckListAdapter<T extends TextSelect> extends BaseQuickAdapter<T, D
mLimitList = new LimitList();
mDeckLoader = new DeckLoader();
deckInfo = new DeckInfo();
mLimitList = DataManager.get().getLimitManager().getTopLimit();
mLimitList = DataManager.get().getLimitManager().getLastLimit();
mContext = context;
}
......@@ -245,6 +245,7 @@ public class DeckListAdapter<T extends TextSelect> extends BaseQuickAdapter<T, D
public interface OnItemSelectListener<T> {
void onItemSelect(int position, T item);
}
/**
* 从deckList中检索包含keyword的卡组
*
......@@ -261,8 +262,10 @@ public class DeckListAdapter<T extends TextSelect> extends BaseQuickAdapter<T, D
}
return resultList;
}
/**
* 将文本中包含关键词的部分高亮显示
*
* @param text 原始文本
* @param keyword 关键词
* @return 处理后的SpannableString
......
......@@ -109,7 +109,7 @@ public class CardSearchFragment extends BaseFragemnt implements CardLoader.CallB
VUiKit.defer().when(() -> {
DataManager.get().load();
if (activity.getmLimitManager().getCount() > 0) {
mCardLoader.setLimitList(activity.getmLimitManager().getTopLimit());
mCardLoader.setLimitList(activity.getmLimitManager().getLastLimit());
}
}).fail((e) -> {
YGOUtil.showTextToast(getString(R.string.tip_load_cdb_error), Toast.LENGTH_SHORT);
......
......@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.List;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.CardSearchInfo;
import cn.garymb.ygomobile.loader.ICardSearcher;
......@@ -212,6 +213,12 @@ public class CardSearcher implements View.OnClickListener {
if (value <= 0)
reset(limitSpinner);
Log.e("onItemSelected", "position:" + position + " id:" + id+" name:" + getSelectText(limitListSpinner));
LimitList limit = mLimitManager.getLimit(getSelectText(limitListSpinner));
mICardSearcher.setLimitList(limit);
//同时通知整个界面都显示该禁卡表的禁限情况
mCallBack.setLimit(limit);
}
@Override
......@@ -432,20 +439,6 @@ public class CardSearcher implements View.OnClickListener {
if (index >= 0) {
spinner.setSelection(index);
}
// 设置选择监听器
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.e("onItemSelected", "position:" + position + " id:" + id);
//同时通知整个界面都显示该禁卡表的禁限情况
mCallBack.setLimit(mLimitManager.getLimit(SimpleSpinnerAdapter.getSelectText(spinner)));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
private void refreshLimitListSpinnerItems(Spinner spinner) {
......
......@@ -635,7 +635,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
// 设置限制卡表列表,使用第一个可用的限制列表
if (activity.getmLimitManager().getCount() > 0) {
mCardLoader.setLimitList(activity.getmLimitManager().getTopLimit());
mCardLoader.setLimitList(activity.getmLimitManager().getLastLimit());
}
// 处理卡组文件加载逻辑
......
package ocgcore;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.Nullable;
......@@ -17,8 +18,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
......@@ -28,7 +27,6 @@ import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.LogUtil;
import ocgcore.data.CardSet;
import ocgcore.data.LimitList;
public class LimitManager implements Closeable {
......@@ -64,6 +62,15 @@ public class LimitManager implements Closeable {
return mLimitLists.get(name);
}
public LimitList getLastLimit() {
if (mLimitNames.isEmpty()) {
return null;
}
// 读取上次使用的LimitList,如果有非空值存在且和禁卡表列表中有相同名称对应,则使用,否则设置第一个禁卡表
String lastLimitName = AppsSettings.get().getLastLimit();
return TextUtils.isEmpty(lastLimitName) ? getTopLimit() : getLimit(lastLimitName);
}
public LimitList getTopLimit() {
if (mLimitNames.isEmpty()) {
return null;
......
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