Commit 70fb40fa authored by fallenstardust's avatar fallenstardust

添加undo与redo功能

对挪动,删除,添加都存一份历史deckinfo数组
parent 94c7fd18
...@@ -20,9 +20,9 @@ public class DeckInfo { ...@@ -20,9 +20,9 @@ public class DeckInfo {
Side, Side,
} }
private final List<Card> mainCards; public List<Card> mainCards;
private final List<Card> extraCards; public List<Card> extraCards;
private final List<Card> sideCards; public List<Card> sideCards;
private final List<Card> allCards; private final List<Card> allCards;
public File source;//当前打开的ydk文件的file public File source;//当前打开的ydk文件的file
......
...@@ -40,12 +40,14 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -40,12 +40,14 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
private final SparseArray<Integer> mCount = new SparseArray<>(); private final SparseArray<Integer> mCount = new SparseArray<>();
private final Context context; private final Context context;
private final LayoutInflater mLayoutInflater; 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 ImageTop mImageTop;
private int mMainCount; private int mMainCount;
private int mExtraCount; private int mExtraCount;
private int mSideCount; private int mSideCount;
private int mMainMonsterCount; private int mMainMonsterCount;
private int mMainSpellCount; private int mMainSpellCount;
private int mMainTrapCount; private int mMainTrapCount;
...@@ -56,18 +58,13 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -56,18 +58,13 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
private int mSideMonsterCount; private int mSideMonsterCount;
private int mSideSpellCount; private int mSideSpellCount;
private int mSideTrapCount; private int mSideTrapCount;
private int mFullWidth; private int mFullWidth;
private int mWidth; private int mWidth;
private int mHeight; private int mHeight;
private final int Padding = 1;
private final RecyclerView recyclerView;
private final Random mRandom;
private DeckViewHolder mHeadHolder; private DeckViewHolder mHeadHolder;
private DeckItem mRemoveItem; private DeckItem mRemoveItem;
private int mRemoveIndex; private int mRemoveIndex;
private LimitList mLimitList; private LimitList mLimitList;
private final ImageLoader imageLoader;
private boolean showHead = false; private boolean showHead = false;
private String mDeckMd5; private String mDeckMd5;
private DeckInfo mDeckInfo; private DeckInfo mDeckInfo;
...@@ -98,6 +95,46 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -98,6 +95,46 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
return mCount; 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) { public boolean AddCard(Card cardInfo, DeckItemType type) {
if (cardInfo == null) return false; if (cardInfo == null) return false;
if (cardInfo.isType(CardType.Token)) { if (cardInfo.isType(CardType.Token)) {
...@@ -151,10 +188,6 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -151,10 +188,6 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
notifyItemRangeChanged(DeckItem.MainStart, DeckItem.MainStart + getMainCount()); notifyItemRangeChanged(DeckItem.MainStart, DeckItem.MainStart + getMainCount());
} }
public void setLimitList(LimitList limitList) {
mLimitList = limitList;
}
private boolean comp(DeckItem d1, DeckItem d2) { private boolean comp(DeckItem d1, DeckItem d2) {
if (d1.getType() == d2.getType()) { if (d1.getType() == d2.getType()) {
Card c1 = d1.getCardInfo(); Card c1 = d1.getCardInfo();
...@@ -386,6 +419,10 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -386,6 +419,10 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
return mLimitList; return mLimitList;
} }
public void setLimitList(LimitList limitList) {
mLimitList = limitList;
}
public @Nullable public @Nullable
File getYdkFile() { File getYdkFile() {
if (mDeckInfo != null) { 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>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:orientation="horizontal"> android:orientation="horizontal">
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_weight="1"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
...@@ -81,17 +81,16 @@ ...@@ -81,17 +81,16 @@
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_weight="1" android:layout_weight="1"
android:textSize="10sp"
android:maxLines="1"
android:gravity="center" android:gravity="center"
android:maxLines="1"
android:shadowColor="@color/black" android:shadowColor="@color/black"
android:shadowDx="1" android:shadowDx="1"
android:shadowDy="1" android:shadowDy="1"
android:shadowRadius="2" android:shadowRadius="2"
android:text="@string/like_deck_thumb" android:text="@string/like_deck_thumb"
android:textColor="@color/white" /> android:textColor="@color/white"
android:textSize="10sp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
...@@ -99,8 +98,8 @@ ...@@ -99,8 +98,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_weight="1"
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
android:layout_weight="1"
android:background="@drawable/button_radius_black_transparents" android:background="@drawable/button_radius_black_transparents"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center|left" android:gravity="center|left"
...@@ -125,9 +124,47 @@ ...@@ -125,9 +124,47 @@
android:layout_weight="1" android:layout_weight="1"
android:visibility="gone" /> android:visibility="gone" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- 撤销/重做按钮 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<ImageButton
android:id="@+id/btn_undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:gravity="center"
android:enabled="false"
android:background="@drawable/ic_radius_bg"
android:src="@drawable/ic_undo" />
<ImageButton
android:id="@+id/btn_redo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@drawable/ic_radius_bg"
android:gravity="center"
android:enabled="false"
android:src="@drawable/ic_redo" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout <LinearLayout
android:id="@+id/nav_list" android:id="@+id/nav_list"
android:layout_width="60dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:orientation="vertical"> android:orientation="vertical">
...@@ -141,7 +178,7 @@ ...@@ -141,7 +178,7 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:gravity="bottom|center_horizontal" android:gravity="bottom|center_horizontal"
android:shadowColor="@color/black" android:shadowColor="@color/black"
android:shadowDx="1" android:shadowDx="1"
...@@ -155,8 +192,8 @@ ...@@ -155,8 +192,8 @@
<LinearLayout <LinearLayout
android:id="@+id/nav_search" android:id="@+id/nav_search"
android:layout_width="60dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:orientation="vertical"> android:orientation="vertical">
...@@ -169,7 +206,7 @@ ...@@ -169,7 +206,7 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:gravity="bottom|center_horizontal" android:gravity="bottom|center_horizontal"
android:shadowColor="@color/black" android:shadowColor="@color/black"
android:shadowDx="1" android:shadowDx="1"
...@@ -183,8 +220,8 @@ ...@@ -183,8 +220,8 @@
<LinearLayout <LinearLayout
android:id="@+id/deck_menu" android:id="@+id/deck_menu"
android:layout_width="60dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_marginLeft="2dp" android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
...@@ -212,7 +249,7 @@ ...@@ -212,7 +249,7 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:gravity="bottom|center_horizontal" android:gravity="bottom|center_horizontal"
android:shadowColor="@color/black" android:shadowColor="@color/black"
android:shadowDx="1" android:shadowDx="1"
...@@ -224,6 +261,8 @@ ...@@ -224,6 +261,8 @@
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout> </FrameLayout>
<LinearLayout <LinearLayout
......
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