Commit f1388ae4 authored by fallenstardust's avatar fallenstardust

简化geneSys分值上限的获取和调用

parent b70f6f6a
...@@ -101,7 +101,6 @@ import cn.garymb.ygomobile.ui.cards.deck.DeckLayoutManager; ...@@ -101,7 +101,6 @@ import cn.garymb.ygomobile.ui.cards.deck.DeckLayoutManager;
import cn.garymb.ygomobile.ui.cards.deck_square.DeckManageDialog; import cn.garymb.ygomobile.ui.cards.deck_square.DeckManageDialog;
import cn.garymb.ygomobile.ui.cards.deck_square.DeckSquareApiUtil; import cn.garymb.ygomobile.ui.cards.deck_square.DeckSquareApiUtil;
import cn.garymb.ygomobile.ui.cards.deck_square.DeckSquareFileUtil; import cn.garymb.ygomobile.ui.cards.deck_square.DeckSquareFileUtil;
import cn.garymb.ygomobile.ui.cards.deck_square.api_response.BasicResponse;
import cn.garymb.ygomobile.ui.cards.deck_square.api_response.DownloadDeckResponse; import cn.garymb.ygomobile.ui.cards.deck_square.api_response.DownloadDeckResponse;
import cn.garymb.ygomobile.ui.cards.deck_square.api_response.MyOnlineDeckDetail; import cn.garymb.ygomobile.ui.cards.deck_square.api_response.MyOnlineDeckDetail;
import cn.garymb.ygomobile.ui.home.HomeActivity; import cn.garymb.ygomobile.ui.home.HomeActivity;
...@@ -665,7 +664,9 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -665,7 +664,9 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
// 初始化完成后的处理逻辑 // 初始化完成后的处理逻辑
isLoad = true; isLoad = true;
dlg.dismiss(); dlg.dismiss();
// 初始化卡片搜索器中的项目列表,为卡片搜索功能准备基础数据
mCardSearcher.initItems(); mCardSearcher.initItems();
// 初始化禁卡表列表下拉框,并通知整个卡组界面都显示为当前使用的禁卡表
initLimitListSpinners(mCardSearchLimitSpinner, mCardLoader.getLimitList()); initLimitListSpinners(mCardSearchLimitSpinner, mCardLoader.getLimitList());
// 根据资源路径判断是否进入卡包展示模式 // 根据资源路径判断是否进入卡包展示模式
if (rs != null && rs.source != null) { if (rs != null && rs.source != null) {
...@@ -838,22 +839,9 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -838,22 +839,9 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
LimitList limitList = mDeckAdapater.getLimitList(); LimitList limitList = mDeckAdapater.getLimitList();
int currentCredit = 0; int currentCredit = 0;
int creditLimit = 0; int creditLimit = 0;
int difference = 0;
// 检查是否有有效的信用分限制 // 检查是否有有效的信用分限制
if (limitList.getCreditLimits() != null && !limitList.getCreditLimits().isEmpty()) { if (limitList.getCreditLimits() != null && limitList.getCreditLimits() > 0) {
// 获取信用分上限值 creditLimit = limitList.getCreditLimits();
for (Integer limit : limitList.getCreditLimits().values()) {
if (limit != null) {
creditLimit = limit;
ll_genesys_scoreboard.setVisibility(View.VISIBLE);
} else {
ll_genesys_scoreboard.setVisibility(View.GONE);
}
break;
}
// 仅当信用分上限不为null且不为0时显示信用分信息
if (creditLimit > 0) {
currentCredit = getCreditCount(mDeckAdapater.getCurrentState()); currentCredit = getCreditCount(mDeckAdapater.getCurrentState());
// 当当前信用分超过限制时,设置文本为红色 // 当当前信用分超过限制时,设置文本为红色
if (currentCredit > creditLimit) { if (currentCredit > creditLimit) {
...@@ -864,7 +852,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -864,7 +852,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
tv_credit_count.setTextColor(Color.WHITE); tv_credit_count.setTextColor(Color.WHITE);
tv_credit_remain.setTextColor(Color.WHITE); tv_credit_remain.setTextColor(Color.WHITE);
} }
}
} }
tv_credit_count.setText(String.valueOf(currentCredit)); tv_credit_count.setText(String.valueOf(currentCredit));
...@@ -1213,19 +1201,17 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1213,19 +1201,17 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
Integer cardCreditValue = limitList.getCredits().get(cardInfo.Alias == 0 ? cardInfo.Code : cardInfo.Alias); Integer cardCreditValue = limitList.getCredits().get(cardInfo.Alias == 0 ? cardInfo.Code : cardInfo.Alias);
if (cardCreditValue != null && cardCreditValue > 0) {//genesys表中的卡需要进行检查,否则就是纯普通卡只需遵循最大3的规则 if (cardCreditValue != null && cardCreditValue > 0) {//genesys表中的卡需要进行检查,否则就是纯普通卡只需遵循最大3的规则
// 检查是否超过信用分上限 // 获取当前禁卡表的信用分上限,一般是100,但可能不同genesys禁卡表给的上限分不同
for (Map.Entry<String, Integer> entry : limitList.getCreditLimits().entrySet()) { Integer creditLimit = limitList.getCreditLimits();//
// 计算当前卡组的信用总分
Integer creditLimit = entry.getValue();//获取总分上限数,一般是100,但可能不同genesys表给的上限分不同
int totalCredit = getCreditCount(mDeckAdapater.getCurrentState()) + cardCreditValue;//计算目前卡组信用分合计+当前卡的信用分的和,用于下面和上限值比较 int totalCredit = getCreditCount(mDeckAdapater.getCurrentState()) + cardCreditValue;//计算目前卡组信用分合计+当前卡的信用分的和,用于下面和上限值比较
// 计算当前卡组中所有GeneSys卡片的信用分总和 // 计算该卡片信用分+卡组信用总分的和是否大于上限值,是的话就无法加入卡组,不是就通过,会被加入卡组
if (creditLimit != null && totalCredit > creditLimit) { if (creditLimit != null && totalCredit > creditLimit) {
YGOUtil.showTextToast(getString(R.string.tip_credit_max, creditLimit)); YGOUtil.showTextToast(getString(R.string.tip_credit_max, creditLimit));
return false; return false;
} }
}
} }
} }
return true; return true;
...@@ -1609,7 +1595,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1609,7 +1595,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
* 初始化限制列表下拉框 * 初始化限制列表下拉框
* *
* @param spinner 要初始化的Spinner控件 * @param spinner 要初始化的Spinner控件
* @param cur 当前选中的限制列表对象,用于设置默认选中项 * @param cur 当前选中的禁卡表对象,用于设置默认选中项,同时通知整个界面都显示该禁卡表的禁限情况
*/ */
private void initLimitListSpinners(Spinner spinner, LimitList cur) { private void initLimitListSpinners(Spinner spinner, LimitList cur) {
// 首先清除所有现有的item // 首先清除所有现有的item
...@@ -1630,7 +1616,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1630,7 +1616,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
int j = i + 1; int j = i + 1;
String name = limitLists.get(i); String name = limitLists.get(i);
LogUtil.w(TAG, i + ":" +"卡表名称:" + name); LogUtil.w(TAG, i + ":" + "卡表名称:" + name);
items.add(new SimpleSpinnerItem(j, name)); items.add(new SimpleSpinnerItem(j, name));
if (cur != null && TextUtils.equals(cur.getName(), name)) { if (cur != null && TextUtils.equals(cur.getName(), name)) {
index = j; index = j;
...@@ -1652,6 +1638,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1652,6 +1638,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//同时通知整个界面都显示该禁卡表的禁限情况
setLimitList(activity.getmLimitManager().getLimit(SimpleSpinnerAdapter.getSelectText(spinner))); setLimitList(activity.getmLimitManager().getLimit(SimpleSpinnerAdapter.getSelectText(spinner)));
} }
...@@ -1673,7 +1660,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1673,7 +1660,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
} }
/** /**
* 设置限制列表并更新相关适配器 * 设置传参禁卡表的禁限,并更新相关适配器
* *
* @param limitList 限制列表对象,如果为null则直接返回 * @param limitList 限制列表对象,如果为null则直接返回
*/ */
...@@ -1687,7 +1674,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1687,7 +1674,7 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
// 如果限制列表发生变化,则更新牌组适配器并通知数据变更 // 如果限制列表发生变化,则更新牌组适配器并通知数据变更
if (!nochanged) { if (!nochanged) {
mDeckAdapater.setLimitList(limitList); mDeckAdapater.setLimitList(limitList);
getActivity().runOnUiThread(() -> { Objects.requireNonNull(getActivity()).runOnUiThread(() -> {
mDeckAdapater.notifyItemRangeChanged(DeckItem.MainStart, DeckItem.MainEnd); mDeckAdapater.notifyItemRangeChanged(DeckItem.MainStart, DeckItem.MainEnd);
mDeckAdapater.notifyItemRangeChanged(DeckItem.ExtraStart, DeckItem.ExtraEnd); mDeckAdapater.notifyItemRangeChanged(DeckItem.ExtraStart, DeckItem.ExtraEnd);
mDeckAdapater.notifyItemRangeChanged(DeckItem.SideStart, DeckItem.SideEnd); mDeckAdapater.notifyItemRangeChanged(DeckItem.SideStart, DeckItem.SideEnd);
...@@ -1696,7 +1683,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -1696,7 +1683,8 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
// 更新卡片列表适配器的限制列表并通知数据变更 // 更新卡片列表适配器的限制列表并通知数据变更
mCardListAdapter.setLimitList(limitList); mCardListAdapter.setLimitList(limitList);
getActivity().runOnUiThread(() -> mCardListAdapter.notifyDataSetChanged()); Objects.requireNonNull(getActivity()).runOnUiThread(() -> mCardListAdapter.notifyDataSetChanged());
} }
private void inputDeckName(File oldYdk, String savePath, boolean keepOld) { private void inputDeckName(File oldYdk, String savePath, boolean keepOld) {
......
...@@ -155,12 +155,11 @@ public class LimitManager implements Closeable { ...@@ -155,12 +155,11 @@ public class LimitManager implements Closeable {
} else if (line.startsWith("$")) { } else if (line.startsWith("$")) {
// 去掉$前缀并按空格分割 // 去掉$前缀并按空格分割
String[] words = line.substring(1).trim().split("[\t| ]+"); String[] words = line.substring(1).trim().split("[\t| ]+");
if (words.length >= 2) { if (words[0].equals("genesys")) {//查询到genesys上限分值前缀识别文本
String creditType = words[0]; // 提取"genesys" Integer creditLimit = toNumber(words[1]); // 提取上限值(通常为100)并转换为整数
int creditLimit = toNumber(words[1]); // 提取100并转换为整数
// 将creditType和creditLimit存储到LimitList对象中 // 将creditType和creditLimit存储到LimitList对象中
if (tmp != null) { if (tmp != null) {
tmp.addCreditLimit(creditType, creditLimit); tmp.addCreditLimit(creditLimit);
} }
} }
} else if (tmp != null) { } else if (tmp != null) {
...@@ -234,12 +233,11 @@ public class LimitManager implements Closeable { ...@@ -234,12 +233,11 @@ public class LimitManager implements Closeable {
} else if (line.startsWith("$")) { } else if (line.startsWith("$")) {
// 去掉$前缀并按空格分割 // 去掉$前缀并按空格分割
String[] words = line.substring(1).trim().split("[\t| ]+"); String[] words = line.substring(1).trim().split("[\t| ]+");
if (words.length >= 2) { if (words[0].equals("genesys")) {//查询到genesys上限分值前缀识别文本
String creditType = words[0]; // 提取"genesys" Integer creditLimit = toNumber(words[1]); // 提取上限值(通常为100)并转换为整数
int creditLimit = toNumber(words[1]); // 提取100并转换为整数
// 将creditType和creditLimit存储到LimitList对象中 // 将creditType和creditLimit存储到LimitList对象中
if (tmp != null) { if (tmp != null) {
tmp.addCreditLimit(creditType, creditLimit); tmp.addCreditLimit(creditLimit);
} }
} }
} else if (tmp != null) { } else if (tmp != null) {
......
...@@ -17,7 +17,7 @@ import ocgcore.enums.LimitType; ...@@ -17,7 +17,7 @@ import ocgcore.enums.LimitType;
*/ */
public class LimitList { public class LimitList {
private String name = "?"; private String name = "?";
private Map<String, Integer> credit_limits;//GeneSys模式特有的总分值 private Integer credit_limits;//GeneSys模式特有的总分值
private Map<Integer, Integer> credits;//GeneSys模式特有的单张卡ID和其信用分 private Map<Integer, Integer> credits;//GeneSys模式特有的单张卡ID和其信用分
/** /**
* 0 * 0
...@@ -77,7 +77,7 @@ public class LimitList { ...@@ -77,7 +77,7 @@ public class LimitList {
return strSemiLimit; return strSemiLimit;
} }
public Map<String, Integer> getCreditLimits() { public Integer getCreditLimits() {
return credit_limits; return credit_limits;
} }
...@@ -106,11 +106,8 @@ public class LimitList { ...@@ -106,11 +106,8 @@ public class LimitList {
} }
} }
public void addCreditLimit(String creditType, Integer limit) { public void addCreditLimit(Integer limit) {
if (credit_limits == null) { credit_limits = limit ;
credit_limits = new HashMap<>();
}
credit_limits.put(creditType, limit);
} }
public void addCredits(Integer cardId, Integer creditCost) { public void addCredits(Integer cardId, Integer creditCost) {
......
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