Commit 70fb40fa authored by fallenstardust's avatar fallenstardust

添加undo与redo功能

对挪动,删除,添加都存一份历史deckinfo数组
parent 94c7fd18
......@@ -20,9 +20,9 @@ public class DeckInfo {
Side,
}
private final List<Card> mainCards;
private final List<Card> extraCards;
private final List<Card> sideCards;
public List<Card> mainCards;
public List<Card> extraCards;
public List<Card> sideCards;
private final List<Card> allCards;
public File source;//当前打开的ydk文件的file
......
......@@ -40,12 +40,14 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
private final SparseArray<Integer> mCount = new SparseArray<>();
private final Context context;
private final LayoutInflater mLayoutInflater;
private final int Padding = 1;
private final RecyclerView recyclerView;
private final Random mRandom;
private final ImageLoader imageLoader;
private ImageTop mImageTop;
private int mMainCount;
private int mExtraCount;
private int mSideCount;
private int mMainMonsterCount;
private int mMainSpellCount;
private int mMainTrapCount;
......@@ -56,18 +58,13 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
private int mSideMonsterCount;
private int mSideSpellCount;
private int mSideTrapCount;
private int mFullWidth;
private int mWidth;
private int mHeight;
private final int Padding = 1;
private final RecyclerView recyclerView;
private final Random mRandom;
private DeckViewHolder mHeadHolder;
private DeckItem mRemoveItem;
private int mRemoveIndex;
private LimitList mLimitList;
private final ImageLoader imageLoader;
private boolean showHead = false;
private String mDeckMd5;
private DeckInfo mDeckInfo;
......@@ -98,6 +95,46 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
return mCount;
}
/**
* 获取当前卡组状态的副本
*
* @return 当前卡组状态的副本
*/
public DeckInfo getCurrentState() {
// 创建当前状态的深拷贝
DeckInfo currentState = new DeckInfo();
// 从 mItems 中提取不同类型的卡片
List<Card> mainCards = new ArrayList<>();
List<Card> extraCards = new ArrayList<>();
List<Card> sideCards = new ArrayList<>();
for (DeckItem item : mItems) {
if (item != null && item.getCardInfo() != null) {
switch (item.getType()) {
case MainCard:
mainCards.add(item.getCardInfo());
break;
case ExtraCard:
extraCards.add(item.getCardInfo());
break;
case SideCard:
sideCards.add(item.getCardInfo());
break;
}
}
}
currentState.mainCards = mainCards;
currentState.extraCards = extraCards;
currentState.sideCards = sideCards;
// 通过 mDeckInfo 获取 source
if (mDeckInfo != null) {
currentState.source = mDeckInfo.source;
}
return currentState;
}
public boolean AddCard(Card cardInfo, DeckItemType type) {
if (cardInfo == null) return false;
if (cardInfo.isType(CardType.Token)) {
......@@ -151,10 +188,6 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
notifyItemRangeChanged(DeckItem.MainStart, DeckItem.MainStart + getMainCount());
}
public void setLimitList(LimitList limitList) {
mLimitList = limitList;
}
private boolean comp(DeckItem d1, DeckItem d2) {
if (d1.getType() == d2.getType()) {
Card c1 = d1.getCardInfo();
......@@ -386,6 +419,10 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
return mLimitList;
}
public void setLimitList(LimitList limitList) {
mLimitList = limitList;
}
public @Nullable
File getYdkFile() {
if (mDeckInfo != null) {
......
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#91BF03" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M18.4,10.6C16.55,8.99 14.15,8 11.5,8c-4.65,0 -8.58,3.03 -9.96,7.22L3.9,16c1.05,-3.19 4.05,-5.5 7.6,-5.5 1.95,0 3.73,0.72 5.12,1.88L13,16h9V7l-3.6,3.6z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#91BF03" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M12.5,8c-2.65,0 -5.05,0.99 -6.9,2.6L2,7v9h9l-3.62,-3.62c1.39,-1.16 3.16,-1.88 5.12,-1.88 3.54,0 6.55,2.31 7.6,5.5l2.37,-0.78C21.08,11.03 17.15,8 12.5,8z"/>
</vector>
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